three.js 1.2 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168
  1. // threejs.org/license
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.THREE = {}));
  6. }(this, (function (exports) { 'use strict';
  7. // Polyfills
  8. if (Number.EPSILON === undefined) {
  9. Number.EPSILON = Math.pow(2, -52);
  10. }
  11. if (Number.isInteger === undefined) {
  12. // Missing in IE
  13. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  14. Number.isInteger = function (value) {
  15. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  16. };
  17. } //
  18. if (Math.sign === undefined) {
  19. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  20. Math.sign = function (x) {
  21. return x < 0 ? -1 : x > 0 ? 1 : +x;
  22. };
  23. }
  24. if ('name' in Function.prototype === false) {
  25. // Missing in IE
  26. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  27. Object.defineProperty(Function.prototype, 'name', {
  28. get: function get() {
  29. return this.toString().match(/^\s*function\s*([^\(\s]*)/)[1];
  30. }
  31. });
  32. }
  33. if (Object.assign === undefined) {
  34. // Missing in IE
  35. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  36. Object.assign = function (target) {
  37. if (target === undefined || target === null) {
  38. throw new TypeError('Cannot convert undefined or null to object');
  39. }
  40. var output = Object(target);
  41. for (var index = 1; index < arguments.length; index++) {
  42. var source = arguments[index];
  43. if (source !== undefined && source !== null) {
  44. for (var nextKey in source) {
  45. if (Object.prototype.hasOwnProperty.call(source, nextKey)) {
  46. output[nextKey] = source[nextKey];
  47. }
  48. }
  49. }
  50. }
  51. return output;
  52. };
  53. }
  54. var REVISION = '122dev';
  55. var MOUSE = {
  56. LEFT: 0,
  57. MIDDLE: 1,
  58. RIGHT: 2,
  59. ROTATE: 0,
  60. DOLLY: 1,
  61. PAN: 2
  62. };
  63. var TOUCH = {
  64. ROTATE: 0,
  65. PAN: 1,
  66. DOLLY_PAN: 2,
  67. DOLLY_ROTATE: 3
  68. };
  69. var CullFaceNone = 0;
  70. var CullFaceBack = 1;
  71. var CullFaceFront = 2;
  72. var CullFaceFrontBack = 3;
  73. var BasicShadowMap = 0;
  74. var PCFShadowMap = 1;
  75. var PCFSoftShadowMap = 2;
  76. var VSMShadowMap = 3;
  77. var FrontSide = 0;
  78. var BackSide = 1;
  79. var DoubleSide = 2;
  80. var FlatShading = 1;
  81. var SmoothShading = 2;
  82. var NoBlending = 0;
  83. var NormalBlending = 1;
  84. var AdditiveBlending = 2;
  85. var SubtractiveBlending = 3;
  86. var MultiplyBlending = 4;
  87. var CustomBlending = 5;
  88. var AddEquation = 100;
  89. var SubtractEquation = 101;
  90. var ReverseSubtractEquation = 102;
  91. var MinEquation = 103;
  92. var MaxEquation = 104;
  93. var ZeroFactor = 200;
  94. var OneFactor = 201;
  95. var SrcColorFactor = 202;
  96. var OneMinusSrcColorFactor = 203;
  97. var SrcAlphaFactor = 204;
  98. var OneMinusSrcAlphaFactor = 205;
  99. var DstAlphaFactor = 206;
  100. var OneMinusDstAlphaFactor = 207;
  101. var DstColorFactor = 208;
  102. var OneMinusDstColorFactor = 209;
  103. var SrcAlphaSaturateFactor = 210;
  104. var NeverDepth = 0;
  105. var AlwaysDepth = 1;
  106. var LessDepth = 2;
  107. var LessEqualDepth = 3;
  108. var EqualDepth = 4;
  109. var GreaterEqualDepth = 5;
  110. var GreaterDepth = 6;
  111. var NotEqualDepth = 7;
  112. var MultiplyOperation = 0;
  113. var MixOperation = 1;
  114. var AddOperation = 2;
  115. var NoToneMapping = 0;
  116. var LinearToneMapping = 1;
  117. var ReinhardToneMapping = 2;
  118. var CineonToneMapping = 3;
  119. var ACESFilmicToneMapping = 4;
  120. var CustomToneMapping = 5;
  121. var UVMapping = 300;
  122. var CubeReflectionMapping = 301;
  123. var CubeRefractionMapping = 302;
  124. var EquirectangularReflectionMapping = 303;
  125. var EquirectangularRefractionMapping = 304;
  126. var CubeUVReflectionMapping = 306;
  127. var CubeUVRefractionMapping = 307;
  128. var RepeatWrapping = 1000;
  129. var ClampToEdgeWrapping = 1001;
  130. var MirroredRepeatWrapping = 1002;
  131. var NearestFilter = 1003;
  132. var NearestMipmapNearestFilter = 1004;
  133. var NearestMipMapNearestFilter = 1004;
  134. var NearestMipmapLinearFilter = 1005;
  135. var NearestMipMapLinearFilter = 1005;
  136. var LinearFilter = 1006;
  137. var LinearMipmapNearestFilter = 1007;
  138. var LinearMipMapNearestFilter = 1007;
  139. var LinearMipmapLinearFilter = 1008;
  140. var LinearMipMapLinearFilter = 1008;
  141. var UnsignedByteType = 1009;
  142. var ByteType = 1010;
  143. var ShortType = 1011;
  144. var UnsignedShortType = 1012;
  145. var IntType = 1013;
  146. var UnsignedIntType = 1014;
  147. var FloatType = 1015;
  148. var HalfFloatType = 1016;
  149. var UnsignedShort4444Type = 1017;
  150. var UnsignedShort5551Type = 1018;
  151. var UnsignedShort565Type = 1019;
  152. var UnsignedInt248Type = 1020;
  153. var AlphaFormat = 1021;
  154. var RGBFormat = 1022;
  155. var RGBAFormat = 1023;
  156. var LuminanceFormat = 1024;
  157. var LuminanceAlphaFormat = 1025;
  158. var RGBEFormat = RGBAFormat;
  159. var DepthFormat = 1026;
  160. var DepthStencilFormat = 1027;
  161. var RedFormat = 1028;
  162. var RedIntegerFormat = 1029;
  163. var RGFormat = 1030;
  164. var RGIntegerFormat = 1031;
  165. var RGBIntegerFormat = 1032;
  166. var RGBAIntegerFormat = 1033;
  167. var RGB_S3TC_DXT1_Format = 33776;
  168. var RGBA_S3TC_DXT1_Format = 33777;
  169. var RGBA_S3TC_DXT3_Format = 33778;
  170. var RGBA_S3TC_DXT5_Format = 33779;
  171. var RGB_PVRTC_4BPPV1_Format = 35840;
  172. var RGB_PVRTC_2BPPV1_Format = 35841;
  173. var RGBA_PVRTC_4BPPV1_Format = 35842;
  174. var RGBA_PVRTC_2BPPV1_Format = 35843;
  175. var RGB_ETC1_Format = 36196;
  176. var RGB_ETC2_Format = 37492;
  177. var RGBA_ETC2_EAC_Format = 37496;
  178. var RGBA_ASTC_4x4_Format = 37808;
  179. var RGBA_ASTC_5x4_Format = 37809;
  180. var RGBA_ASTC_5x5_Format = 37810;
  181. var RGBA_ASTC_6x5_Format = 37811;
  182. var RGBA_ASTC_6x6_Format = 37812;
  183. var RGBA_ASTC_8x5_Format = 37813;
  184. var RGBA_ASTC_8x6_Format = 37814;
  185. var RGBA_ASTC_8x8_Format = 37815;
  186. var RGBA_ASTC_10x5_Format = 37816;
  187. var RGBA_ASTC_10x6_Format = 37817;
  188. var RGBA_ASTC_10x8_Format = 37818;
  189. var RGBA_ASTC_10x10_Format = 37819;
  190. var RGBA_ASTC_12x10_Format = 37820;
  191. var RGBA_ASTC_12x12_Format = 37821;
  192. var RGBA_BPTC_Format = 36492;
  193. var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  194. var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  195. var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  196. var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  197. var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  198. var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  199. var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  200. var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  201. var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  202. var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  203. var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  204. var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  205. var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  206. var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  207. var LoopOnce = 2200;
  208. var LoopRepeat = 2201;
  209. var LoopPingPong = 2202;
  210. var InterpolateDiscrete = 2300;
  211. var InterpolateLinear = 2301;
  212. var InterpolateSmooth = 2302;
  213. var ZeroCurvatureEnding = 2400;
  214. var ZeroSlopeEnding = 2401;
  215. var WrapAroundEnding = 2402;
  216. var NormalAnimationBlendMode = 2500;
  217. var AdditiveAnimationBlendMode = 2501;
  218. var TrianglesDrawMode = 0;
  219. var TriangleStripDrawMode = 1;
  220. var TriangleFanDrawMode = 2;
  221. var LinearEncoding = 3000;
  222. var sRGBEncoding = 3001;
  223. var GammaEncoding = 3007;
  224. var RGBEEncoding = 3002;
  225. var LogLuvEncoding = 3003;
  226. var RGBM7Encoding = 3004;
  227. var RGBM16Encoding = 3005;
  228. var RGBDEncoding = 3006;
  229. var BasicDepthPacking = 3200;
  230. var RGBADepthPacking = 3201;
  231. var TangentSpaceNormalMap = 0;
  232. var ObjectSpaceNormalMap = 1;
  233. var ZeroStencilOp = 0;
  234. var KeepStencilOp = 7680;
  235. var ReplaceStencilOp = 7681;
  236. var IncrementStencilOp = 7682;
  237. var DecrementStencilOp = 7683;
  238. var IncrementWrapStencilOp = 34055;
  239. var DecrementWrapStencilOp = 34056;
  240. var InvertStencilOp = 5386;
  241. var NeverStencilFunc = 512;
  242. var LessStencilFunc = 513;
  243. var EqualStencilFunc = 514;
  244. var LessEqualStencilFunc = 515;
  245. var GreaterStencilFunc = 516;
  246. var NotEqualStencilFunc = 517;
  247. var GreaterEqualStencilFunc = 518;
  248. var AlwaysStencilFunc = 519;
  249. var StaticDrawUsage = 35044;
  250. var DynamicDrawUsage = 35048;
  251. var StreamDrawUsage = 35040;
  252. var StaticReadUsage = 35045;
  253. var DynamicReadUsage = 35049;
  254. var StreamReadUsage = 35041;
  255. var StaticCopyUsage = 35046;
  256. var DynamicCopyUsage = 35050;
  257. var StreamCopyUsage = 35042;
  258. var GLSL1 = "100";
  259. var GLSL3 = "300 es";
  260. /**
  261. * https://github.com/mrdoob/eventdispatcher.js/
  262. */
  263. function EventDispatcher() {}
  264. Object.assign(EventDispatcher.prototype, {
  265. addEventListener: function addEventListener(type, listener) {
  266. if (this._listeners === undefined) this._listeners = {};
  267. var listeners = this._listeners;
  268. if (listeners[type] === undefined) {
  269. listeners[type] = [];
  270. }
  271. if (listeners[type].indexOf(listener) === -1) {
  272. listeners[type].push(listener);
  273. }
  274. },
  275. hasEventListener: function hasEventListener(type, listener) {
  276. if (this._listeners === undefined) return false;
  277. var listeners = this._listeners;
  278. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
  279. },
  280. removeEventListener: function removeEventListener(type, listener) {
  281. if (this._listeners === undefined) return;
  282. var listeners = this._listeners;
  283. var listenerArray = listeners[type];
  284. if (listenerArray !== undefined) {
  285. var index = listenerArray.indexOf(listener);
  286. if (index !== -1) {
  287. listenerArray.splice(index, 1);
  288. }
  289. }
  290. },
  291. dispatchEvent: function dispatchEvent(event) {
  292. if (this._listeners === undefined) return;
  293. var listeners = this._listeners;
  294. var listenerArray = listeners[event.type];
  295. if (listenerArray !== undefined) {
  296. event.target = this; // Make a copy, in case listeners are removed while iterating.
  297. var array = listenerArray.slice(0);
  298. for (var i = 0, l = array.length; i < l; i++) {
  299. array[i].call(this, event);
  300. }
  301. }
  302. }
  303. });
  304. var _lut = [];
  305. for (var i = 0; i < 256; i++) {
  306. _lut[i] = (i < 16 ? '0' : '') + i.toString(16);
  307. }
  308. var _seed = 1234567;
  309. var MathUtils = {
  310. DEG2RAD: Math.PI / 180,
  311. RAD2DEG: 180 / Math.PI,
  312. generateUUID: function generateUUID() {
  313. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  314. var d0 = Math.random() * 0xffffffff | 0;
  315. var d1 = Math.random() * 0xffffffff | 0;
  316. var d2 = Math.random() * 0xffffffff | 0;
  317. var d3 = Math.random() * 0xffffffff | 0;
  318. var uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' + _lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' + _lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] + _lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff]; // .toUpperCase() here flattens concatenated strings to save heap memory space.
  319. return uuid.toUpperCase();
  320. },
  321. clamp: function clamp(value, min, max) {
  322. return Math.max(min, Math.min(max, value));
  323. },
  324. // compute euclidian modulo of m % n
  325. // https://en.wikipedia.org/wiki/Modulo_operation
  326. euclideanModulo: function euclideanModulo(n, m) {
  327. return (n % m + m) % m;
  328. },
  329. // Linear mapping from range <a1, a2> to range <b1, b2>
  330. mapLinear: function mapLinear(x, a1, a2, b1, b2) {
  331. return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
  332. },
  333. // https://en.wikipedia.org/wiki/Linear_interpolation
  334. lerp: function lerp(x, y, t) {
  335. return (1 - t) * x + t * y;
  336. },
  337. // http://en.wikipedia.org/wiki/Smoothstep
  338. smoothstep: function smoothstep(x, min, max) {
  339. if (x <= min) return 0;
  340. if (x >= max) return 1;
  341. x = (x - min) / (max - min);
  342. return x * x * (3 - 2 * x);
  343. },
  344. smootherstep: function smootherstep(x, min, max) {
  345. if (x <= min) return 0;
  346. if (x >= max) return 1;
  347. x = (x - min) / (max - min);
  348. return x * x * x * (x * (x * 6 - 15) + 10);
  349. },
  350. // Random integer from <low, high> interval
  351. randInt: function randInt(low, high) {
  352. return low + Math.floor(Math.random() * (high - low + 1));
  353. },
  354. // Random float from <low, high> interval
  355. randFloat: function randFloat(low, high) {
  356. return low + Math.random() * (high - low);
  357. },
  358. // Random float from <-range/2, range/2> interval
  359. randFloatSpread: function randFloatSpread(range) {
  360. return range * (0.5 - Math.random());
  361. },
  362. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  363. seededRandom: function seededRandom(s) {
  364. if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
  365. _seed = _seed * 16807 % 2147483647;
  366. return (_seed - 1) / 2147483646;
  367. },
  368. degToRad: function degToRad(degrees) {
  369. return degrees * MathUtils.DEG2RAD;
  370. },
  371. radToDeg: function radToDeg(radians) {
  372. return radians * MathUtils.RAD2DEG;
  373. },
  374. isPowerOfTwo: function isPowerOfTwo(value) {
  375. return (value & value - 1) === 0 && value !== 0;
  376. },
  377. ceilPowerOfTwo: function ceilPowerOfTwo(value) {
  378. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  379. },
  380. floorPowerOfTwo: function floorPowerOfTwo(value) {
  381. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  382. },
  383. setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
  384. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  385. // rotations are applied to the axes in the order specified by 'order'
  386. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  387. // angles are in radians
  388. var cos = Math.cos;
  389. var sin = Math.sin;
  390. var c2 = cos(b / 2);
  391. var s2 = sin(b / 2);
  392. var c13 = cos((a + c) / 2);
  393. var s13 = sin((a + c) / 2);
  394. var c1_3 = cos((a - c) / 2);
  395. var s1_3 = sin((a - c) / 2);
  396. var c3_1 = cos((c - a) / 2);
  397. var s3_1 = sin((c - a) / 2);
  398. switch (order) {
  399. case 'XYX':
  400. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  401. break;
  402. case 'YZY':
  403. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  404. break;
  405. case 'ZXZ':
  406. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  407. break;
  408. case 'XZX':
  409. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  410. break;
  411. case 'YXY':
  412. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  413. break;
  414. case 'ZYZ':
  415. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  416. break;
  417. default:
  418. console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
  419. }
  420. }
  421. };
  422. function _defineProperties(target, props) {
  423. for (var i = 0; i < props.length; i++) {
  424. var descriptor = props[i];
  425. descriptor.enumerable = descriptor.enumerable || false;
  426. descriptor.configurable = true;
  427. if ("value" in descriptor) descriptor.writable = true;
  428. Object.defineProperty(target, descriptor.key, descriptor);
  429. }
  430. }
  431. function _createClass(Constructor, protoProps, staticProps) {
  432. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  433. if (staticProps) _defineProperties(Constructor, staticProps);
  434. return Constructor;
  435. }
  436. function _inheritsLoose(subClass, superClass) {
  437. subClass.prototype = Object.create(superClass.prototype);
  438. subClass.prototype.constructor = subClass;
  439. subClass.__proto__ = superClass;
  440. }
  441. function _assertThisInitialized(self) {
  442. if (self === void 0) {
  443. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  444. }
  445. return self;
  446. }
  447. var Vector2 = /*#__PURE__*/function () {
  448. function Vector2(x, y) {
  449. if (x === void 0) {
  450. x = 0;
  451. }
  452. if (y === void 0) {
  453. y = 0;
  454. }
  455. Object.defineProperty(this, 'isVector2', {
  456. value: true
  457. });
  458. this.x = x;
  459. this.y = y;
  460. }
  461. var _proto = Vector2.prototype;
  462. _proto.set = function set(x, y) {
  463. this.x = x;
  464. this.y = y;
  465. return this;
  466. };
  467. _proto.setScalar = function setScalar(scalar) {
  468. this.x = scalar;
  469. this.y = scalar;
  470. return this;
  471. };
  472. _proto.setX = function setX(x) {
  473. this.x = x;
  474. return this;
  475. };
  476. _proto.setY = function setY(y) {
  477. this.y = y;
  478. return this;
  479. };
  480. _proto.setComponent = function setComponent(index, value) {
  481. switch (index) {
  482. case 0:
  483. this.x = value;
  484. break;
  485. case 1:
  486. this.y = value;
  487. break;
  488. default:
  489. throw new Error('index is out of range: ' + index);
  490. }
  491. return this;
  492. };
  493. _proto.getComponent = function getComponent(index) {
  494. switch (index) {
  495. case 0:
  496. return this.x;
  497. case 1:
  498. return this.y;
  499. default:
  500. throw new Error('index is out of range: ' + index);
  501. }
  502. };
  503. _proto.clone = function clone() {
  504. return new this.constructor(this.x, this.y);
  505. };
  506. _proto.copy = function copy(v) {
  507. this.x = v.x;
  508. this.y = v.y;
  509. return this;
  510. };
  511. _proto.add = function add(v, w) {
  512. if (w !== undefined) {
  513. console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  514. return this.addVectors(v, w);
  515. }
  516. this.x += v.x;
  517. this.y += v.y;
  518. return this;
  519. };
  520. _proto.addScalar = function addScalar(s) {
  521. this.x += s;
  522. this.y += s;
  523. return this;
  524. };
  525. _proto.addVectors = function addVectors(a, b) {
  526. this.x = a.x + b.x;
  527. this.y = a.y + b.y;
  528. return this;
  529. };
  530. _proto.addScaledVector = function addScaledVector(v, s) {
  531. this.x += v.x * s;
  532. this.y += v.y * s;
  533. return this;
  534. };
  535. _proto.sub = function sub(v, w) {
  536. if (w !== undefined) {
  537. console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  538. return this.subVectors(v, w);
  539. }
  540. this.x -= v.x;
  541. this.y -= v.y;
  542. return this;
  543. };
  544. _proto.subScalar = function subScalar(s) {
  545. this.x -= s;
  546. this.y -= s;
  547. return this;
  548. };
  549. _proto.subVectors = function subVectors(a, b) {
  550. this.x = a.x - b.x;
  551. this.y = a.y - b.y;
  552. return this;
  553. };
  554. _proto.multiply = function multiply(v) {
  555. this.x *= v.x;
  556. this.y *= v.y;
  557. return this;
  558. };
  559. _proto.multiplyScalar = function multiplyScalar(scalar) {
  560. this.x *= scalar;
  561. this.y *= scalar;
  562. return this;
  563. };
  564. _proto.divide = function divide(v) {
  565. this.x /= v.x;
  566. this.y /= v.y;
  567. return this;
  568. };
  569. _proto.divideScalar = function divideScalar(scalar) {
  570. return this.multiplyScalar(1 / scalar);
  571. };
  572. _proto.applyMatrix3 = function applyMatrix3(m) {
  573. var x = this.x,
  574. y = this.y;
  575. var e = m.elements;
  576. this.x = e[0] * x + e[3] * y + e[6];
  577. this.y = e[1] * x + e[4] * y + e[7];
  578. return this;
  579. };
  580. _proto.min = function min(v) {
  581. this.x = Math.min(this.x, v.x);
  582. this.y = Math.min(this.y, v.y);
  583. return this;
  584. };
  585. _proto.max = function max(v) {
  586. this.x = Math.max(this.x, v.x);
  587. this.y = Math.max(this.y, v.y);
  588. return this;
  589. };
  590. _proto.clamp = function clamp(min, max) {
  591. // assumes min < max, componentwise
  592. this.x = Math.max(min.x, Math.min(max.x, this.x));
  593. this.y = Math.max(min.y, Math.min(max.y, this.y));
  594. return this;
  595. };
  596. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  597. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  598. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  599. return this;
  600. };
  601. _proto.clampLength = function clampLength(min, max) {
  602. var length = this.length();
  603. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  604. };
  605. _proto.floor = function floor() {
  606. this.x = Math.floor(this.x);
  607. this.y = Math.floor(this.y);
  608. return this;
  609. };
  610. _proto.ceil = function ceil() {
  611. this.x = Math.ceil(this.x);
  612. this.y = Math.ceil(this.y);
  613. return this;
  614. };
  615. _proto.round = function round() {
  616. this.x = Math.round(this.x);
  617. this.y = Math.round(this.y);
  618. return this;
  619. };
  620. _proto.roundToZero = function roundToZero() {
  621. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  622. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  623. return this;
  624. };
  625. _proto.negate = function negate() {
  626. this.x = -this.x;
  627. this.y = -this.y;
  628. return this;
  629. };
  630. _proto.dot = function dot(v) {
  631. return this.x * v.x + this.y * v.y;
  632. };
  633. _proto.cross = function cross(v) {
  634. return this.x * v.y - this.y * v.x;
  635. };
  636. _proto.lengthSq = function lengthSq() {
  637. return this.x * this.x + this.y * this.y;
  638. };
  639. _proto.length = function length() {
  640. return Math.sqrt(this.x * this.x + this.y * this.y);
  641. };
  642. _proto.manhattanLength = function manhattanLength() {
  643. return Math.abs(this.x) + Math.abs(this.y);
  644. };
  645. _proto.normalize = function normalize() {
  646. return this.divideScalar(this.length() || 1);
  647. };
  648. _proto.angle = function angle() {
  649. // computes the angle in radians with respect to the positive x-axis
  650. var angle = Math.atan2(-this.y, -this.x) + Math.PI;
  651. return angle;
  652. };
  653. _proto.distanceTo = function distanceTo(v) {
  654. return Math.sqrt(this.distanceToSquared(v));
  655. };
  656. _proto.distanceToSquared = function distanceToSquared(v) {
  657. var dx = this.x - v.x,
  658. dy = this.y - v.y;
  659. return dx * dx + dy * dy;
  660. };
  661. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  662. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
  663. };
  664. _proto.setLength = function setLength(length) {
  665. return this.normalize().multiplyScalar(length);
  666. };
  667. _proto.lerp = function lerp(v, alpha) {
  668. this.x += (v.x - this.x) * alpha;
  669. this.y += (v.y - this.y) * alpha;
  670. return this;
  671. };
  672. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  673. this.x = v1.x + (v2.x - v1.x) * alpha;
  674. this.y = v1.y + (v2.y - v1.y) * alpha;
  675. return this;
  676. };
  677. _proto.equals = function equals(v) {
  678. return v.x === this.x && v.y === this.y;
  679. };
  680. _proto.fromArray = function fromArray(array, offset) {
  681. if (offset === undefined) offset = 0;
  682. this.x = array[offset];
  683. this.y = array[offset + 1];
  684. return this;
  685. };
  686. _proto.toArray = function toArray(array, offset) {
  687. if (array === undefined) array = [];
  688. if (offset === undefined) offset = 0;
  689. array[offset] = this.x;
  690. array[offset + 1] = this.y;
  691. return array;
  692. };
  693. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  694. if (offset !== undefined) {
  695. console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
  696. }
  697. this.x = attribute.getX(index);
  698. this.y = attribute.getY(index);
  699. return this;
  700. };
  701. _proto.rotateAround = function rotateAround(center, angle) {
  702. var c = Math.cos(angle),
  703. s = Math.sin(angle);
  704. var x = this.x - center.x;
  705. var y = this.y - center.y;
  706. this.x = x * c - y * s + center.x;
  707. this.y = x * s + y * c + center.y;
  708. return this;
  709. };
  710. _proto.random = function random() {
  711. this.x = Math.random();
  712. this.y = Math.random();
  713. return this;
  714. };
  715. _createClass(Vector2, [{
  716. key: "width",
  717. get: function get() {
  718. return this.x;
  719. },
  720. set: function set(value) {
  721. this.x = value;
  722. }
  723. }, {
  724. key: "height",
  725. get: function get() {
  726. return this.y;
  727. },
  728. set: function set(value) {
  729. this.y = value;
  730. }
  731. }]);
  732. return Vector2;
  733. }();
  734. var Matrix3 = /*#__PURE__*/function () {
  735. function Matrix3() {
  736. Object.defineProperty(this, 'isMatrix3', {
  737. value: true
  738. });
  739. this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  740. if (arguments.length > 0) {
  741. console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
  742. }
  743. }
  744. var _proto = Matrix3.prototype;
  745. _proto.set = function set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
  746. var te = this.elements;
  747. te[0] = n11;
  748. te[1] = n21;
  749. te[2] = n31;
  750. te[3] = n12;
  751. te[4] = n22;
  752. te[5] = n32;
  753. te[6] = n13;
  754. te[7] = n23;
  755. te[8] = n33;
  756. return this;
  757. };
  758. _proto.identity = function identity() {
  759. this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
  760. return this;
  761. };
  762. _proto.clone = function clone() {
  763. return new this.constructor().fromArray(this.elements);
  764. };
  765. _proto.copy = function copy(m) {
  766. var te = this.elements;
  767. var me = m.elements;
  768. te[0] = me[0];
  769. te[1] = me[1];
  770. te[2] = me[2];
  771. te[3] = me[3];
  772. te[4] = me[4];
  773. te[5] = me[5];
  774. te[6] = me[6];
  775. te[7] = me[7];
  776. te[8] = me[8];
  777. return this;
  778. };
  779. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  780. xAxis.setFromMatrix3Column(this, 0);
  781. yAxis.setFromMatrix3Column(this, 1);
  782. zAxis.setFromMatrix3Column(this, 2);
  783. return this;
  784. };
  785. _proto.setFromMatrix4 = function setFromMatrix4(m) {
  786. var me = m.elements;
  787. this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
  788. return this;
  789. };
  790. _proto.multiply = function multiply(m) {
  791. return this.multiplyMatrices(this, m);
  792. };
  793. _proto.premultiply = function premultiply(m) {
  794. return this.multiplyMatrices(m, this);
  795. };
  796. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  797. var ae = a.elements;
  798. var be = b.elements;
  799. var te = this.elements;
  800. var a11 = ae[0],
  801. a12 = ae[3],
  802. a13 = ae[6];
  803. var a21 = ae[1],
  804. a22 = ae[4],
  805. a23 = ae[7];
  806. var a31 = ae[2],
  807. a32 = ae[5],
  808. a33 = ae[8];
  809. var b11 = be[0],
  810. b12 = be[3],
  811. b13 = be[6];
  812. var b21 = be[1],
  813. b22 = be[4],
  814. b23 = be[7];
  815. var b31 = be[2],
  816. b32 = be[5],
  817. b33 = be[8];
  818. te[0] = a11 * b11 + a12 * b21 + a13 * b31;
  819. te[3] = a11 * b12 + a12 * b22 + a13 * b32;
  820. te[6] = a11 * b13 + a12 * b23 + a13 * b33;
  821. te[1] = a21 * b11 + a22 * b21 + a23 * b31;
  822. te[4] = a21 * b12 + a22 * b22 + a23 * b32;
  823. te[7] = a21 * b13 + a22 * b23 + a23 * b33;
  824. te[2] = a31 * b11 + a32 * b21 + a33 * b31;
  825. te[5] = a31 * b12 + a32 * b22 + a33 * b32;
  826. te[8] = a31 * b13 + a32 * b23 + a33 * b33;
  827. return this;
  828. };
  829. _proto.multiplyScalar = function multiplyScalar(s) {
  830. var te = this.elements;
  831. te[0] *= s;
  832. te[3] *= s;
  833. te[6] *= s;
  834. te[1] *= s;
  835. te[4] *= s;
  836. te[7] *= s;
  837. te[2] *= s;
  838. te[5] *= s;
  839. te[8] *= s;
  840. return this;
  841. };
  842. _proto.determinant = function determinant() {
  843. var te = this.elements;
  844. var a = te[0],
  845. b = te[1],
  846. c = te[2],
  847. d = te[3],
  848. e = te[4],
  849. f = te[5],
  850. g = te[6],
  851. h = te[7],
  852. i = te[8];
  853. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  854. };
  855. _proto.getInverse = function getInverse(matrix, throwOnDegenerate) {
  856. if (throwOnDegenerate !== undefined) {
  857. console.warn("THREE.Matrix3: .getInverse() can no longer be configured to throw on degenerate.");
  858. }
  859. var me = matrix.elements,
  860. te = this.elements,
  861. n11 = me[0],
  862. n21 = me[1],
  863. n31 = me[2],
  864. n12 = me[3],
  865. n22 = me[4],
  866. n32 = me[5],
  867. n13 = me[6],
  868. n23 = me[7],
  869. n33 = me[8],
  870. t11 = n33 * n22 - n32 * n23,
  871. t12 = n32 * n13 - n33 * n12,
  872. t13 = n23 * n12 - n22 * n13,
  873. det = n11 * t11 + n21 * t12 + n31 * t13;
  874. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  875. var detInv = 1 / det;
  876. te[0] = t11 * detInv;
  877. te[1] = (n31 * n23 - n33 * n21) * detInv;
  878. te[2] = (n32 * n21 - n31 * n22) * detInv;
  879. te[3] = t12 * detInv;
  880. te[4] = (n33 * n11 - n31 * n13) * detInv;
  881. te[5] = (n31 * n12 - n32 * n11) * detInv;
  882. te[6] = t13 * detInv;
  883. te[7] = (n21 * n13 - n23 * n11) * detInv;
  884. te[8] = (n22 * n11 - n21 * n12) * detInv;
  885. return this;
  886. };
  887. _proto.transpose = function transpose() {
  888. var tmp;
  889. var m = this.elements;
  890. tmp = m[1];
  891. m[1] = m[3];
  892. m[3] = tmp;
  893. tmp = m[2];
  894. m[2] = m[6];
  895. m[6] = tmp;
  896. tmp = m[5];
  897. m[5] = m[7];
  898. m[7] = tmp;
  899. return this;
  900. };
  901. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  902. return this.setFromMatrix4(matrix4).getInverse(this).transpose();
  903. };
  904. _proto.transposeIntoArray = function transposeIntoArray(r) {
  905. var m = this.elements;
  906. r[0] = m[0];
  907. r[1] = m[3];
  908. r[2] = m[6];
  909. r[3] = m[1];
  910. r[4] = m[4];
  911. r[5] = m[7];
  912. r[6] = m[2];
  913. r[7] = m[5];
  914. r[8] = m[8];
  915. return this;
  916. };
  917. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  918. var c = Math.cos(rotation);
  919. var s = Math.sin(rotation);
  920. 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);
  921. };
  922. _proto.scale = function scale(sx, sy) {
  923. var te = this.elements;
  924. te[0] *= sx;
  925. te[3] *= sx;
  926. te[6] *= sx;
  927. te[1] *= sy;
  928. te[4] *= sy;
  929. te[7] *= sy;
  930. return this;
  931. };
  932. _proto.rotate = function rotate(theta) {
  933. var c = Math.cos(theta);
  934. var s = Math.sin(theta);
  935. var te = this.elements;
  936. var a11 = te[0],
  937. a12 = te[3],
  938. a13 = te[6];
  939. var a21 = te[1],
  940. a22 = te[4],
  941. a23 = te[7];
  942. te[0] = c * a11 + s * a21;
  943. te[3] = c * a12 + s * a22;
  944. te[6] = c * a13 + s * a23;
  945. te[1] = -s * a11 + c * a21;
  946. te[4] = -s * a12 + c * a22;
  947. te[7] = -s * a13 + c * a23;
  948. return this;
  949. };
  950. _proto.translate = function translate(tx, ty) {
  951. var te = this.elements;
  952. te[0] += tx * te[2];
  953. te[3] += tx * te[5];
  954. te[6] += tx * te[8];
  955. te[1] += ty * te[2];
  956. te[4] += ty * te[5];
  957. te[7] += ty * te[8];
  958. return this;
  959. };
  960. _proto.equals = function equals(matrix) {
  961. var te = this.elements;
  962. var me = matrix.elements;
  963. for (var i = 0; i < 9; i++) {
  964. if (te[i] !== me[i]) return false;
  965. }
  966. return true;
  967. };
  968. _proto.fromArray = function fromArray(array, offset) {
  969. if (offset === undefined) offset = 0;
  970. for (var i = 0; i < 9; i++) {
  971. this.elements[i] = array[i + offset];
  972. }
  973. return this;
  974. };
  975. _proto.toArray = function toArray(array, offset) {
  976. if (array === undefined) array = [];
  977. if (offset === undefined) offset = 0;
  978. var te = this.elements;
  979. array[offset] = te[0];
  980. array[offset + 1] = te[1];
  981. array[offset + 2] = te[2];
  982. array[offset + 3] = te[3];
  983. array[offset + 4] = te[4];
  984. array[offset + 5] = te[5];
  985. array[offset + 6] = te[6];
  986. array[offset + 7] = te[7];
  987. array[offset + 8] = te[8];
  988. return array;
  989. };
  990. return Matrix3;
  991. }();
  992. var _canvas;
  993. var ImageUtils = {
  994. getDataURL: function getDataURL(image) {
  995. if (/^data:/i.test(image.src)) {
  996. return image.src;
  997. }
  998. if (typeof HTMLCanvasElement == 'undefined') {
  999. return image.src;
  1000. }
  1001. var canvas;
  1002. if (image instanceof HTMLCanvasElement) {
  1003. canvas = image;
  1004. } else {
  1005. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1006. _canvas.width = image.width;
  1007. _canvas.height = image.height;
  1008. var context = _canvas.getContext('2d');
  1009. if (image instanceof ImageData) {
  1010. context.putImageData(image, 0, 0);
  1011. } else {
  1012. context.drawImage(image, 0, 0, image.width, image.height);
  1013. }
  1014. canvas = _canvas;
  1015. }
  1016. if (canvas.width > 2048 || canvas.height > 2048) {
  1017. return canvas.toDataURL('image/jpeg', 0.6);
  1018. } else {
  1019. return canvas.toDataURL('image/png');
  1020. }
  1021. }
  1022. };
  1023. var textureId = 0;
  1024. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1025. Object.defineProperty(this, 'id', {
  1026. value: textureId++
  1027. });
  1028. this.uuid = MathUtils.generateUUID();
  1029. this.name = '';
  1030. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  1031. this.mipmaps = [];
  1032. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  1033. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  1034. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  1035. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  1036. this.minFilter = minFilter !== undefined ? minFilter : LinearMipmapLinearFilter;
  1037. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  1038. this.format = format !== undefined ? format : RGBAFormat;
  1039. this.internalFormat = null;
  1040. this.type = type !== undefined ? type : UnsignedByteType;
  1041. this.offset = new Vector2(0, 0);
  1042. this.repeat = new Vector2(1, 1);
  1043. this.center = new Vector2(0, 0);
  1044. this.rotation = 0;
  1045. this.matrixAutoUpdate = true;
  1046. this.matrix = new Matrix3();
  1047. this.generateMipmaps = true;
  1048. this.premultiplyAlpha = false;
  1049. this.flipY = true;
  1050. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1051. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1052. //
  1053. // Also changing the encoding after already used by a Material will not automatically make the Material
  1054. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1055. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  1056. this.version = 0;
  1057. this.onUpdate = null;
  1058. }
  1059. Texture.DEFAULT_IMAGE = undefined;
  1060. Texture.DEFAULT_MAPPING = UVMapping;
  1061. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1062. constructor: Texture,
  1063. isTexture: true,
  1064. updateMatrix: function updateMatrix() {
  1065. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1066. },
  1067. clone: function clone() {
  1068. return new this.constructor().copy(this);
  1069. },
  1070. copy: function copy(source) {
  1071. this.name = source.name;
  1072. this.image = source.image;
  1073. this.mipmaps = source.mipmaps.slice(0);
  1074. this.mapping = source.mapping;
  1075. this.wrapS = source.wrapS;
  1076. this.wrapT = source.wrapT;
  1077. this.magFilter = source.magFilter;
  1078. this.minFilter = source.minFilter;
  1079. this.anisotropy = source.anisotropy;
  1080. this.format = source.format;
  1081. this.internalFormat = source.internalFormat;
  1082. this.type = source.type;
  1083. this.offset.copy(source.offset);
  1084. this.repeat.copy(source.repeat);
  1085. this.center.copy(source.center);
  1086. this.rotation = source.rotation;
  1087. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1088. this.matrix.copy(source.matrix);
  1089. this.generateMipmaps = source.generateMipmaps;
  1090. this.premultiplyAlpha = source.premultiplyAlpha;
  1091. this.flipY = source.flipY;
  1092. this.unpackAlignment = source.unpackAlignment;
  1093. this.encoding = source.encoding;
  1094. return this;
  1095. },
  1096. toJSON: function toJSON(meta) {
  1097. var isRootObject = meta === undefined || typeof meta === 'string';
  1098. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1099. return meta.textures[this.uuid];
  1100. }
  1101. var output = {
  1102. metadata: {
  1103. version: 4.5,
  1104. type: 'Texture',
  1105. generator: 'Texture.toJSON'
  1106. },
  1107. uuid: this.uuid,
  1108. name: this.name,
  1109. mapping: this.mapping,
  1110. repeat: [this.repeat.x, this.repeat.y],
  1111. offset: [this.offset.x, this.offset.y],
  1112. center: [this.center.x, this.center.y],
  1113. rotation: this.rotation,
  1114. wrap: [this.wrapS, this.wrapT],
  1115. format: this.format,
  1116. type: this.type,
  1117. encoding: this.encoding,
  1118. minFilter: this.minFilter,
  1119. magFilter: this.magFilter,
  1120. anisotropy: this.anisotropy,
  1121. flipY: this.flipY,
  1122. premultiplyAlpha: this.premultiplyAlpha,
  1123. unpackAlignment: this.unpackAlignment
  1124. };
  1125. if (this.image !== undefined) {
  1126. // TODO: Move to THREE.Image
  1127. var image = this.image;
  1128. if (image.uuid === undefined) {
  1129. image.uuid = MathUtils.generateUUID(); // UGH
  1130. }
  1131. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1132. var url;
  1133. if (Array.isArray(image)) {
  1134. // process array of images e.g. CubeTexture
  1135. url = [];
  1136. for (var i = 0, l = image.length; i < l; i++) {
  1137. url.push(ImageUtils.getDataURL(image[i]));
  1138. }
  1139. } else {
  1140. // process single image
  1141. url = ImageUtils.getDataURL(image);
  1142. }
  1143. meta.images[image.uuid] = {
  1144. uuid: image.uuid,
  1145. url: url
  1146. };
  1147. }
  1148. output.image = image.uuid;
  1149. }
  1150. if (!isRootObject) {
  1151. meta.textures[this.uuid] = output;
  1152. }
  1153. return output;
  1154. },
  1155. dispose: function dispose() {
  1156. this.dispatchEvent({
  1157. type: 'dispose'
  1158. });
  1159. },
  1160. transformUv: function transformUv(uv) {
  1161. if (this.mapping !== UVMapping) return uv;
  1162. uv.applyMatrix3(this.matrix);
  1163. if (uv.x < 0 || uv.x > 1) {
  1164. switch (this.wrapS) {
  1165. case RepeatWrapping:
  1166. uv.x = uv.x - Math.floor(uv.x);
  1167. break;
  1168. case ClampToEdgeWrapping:
  1169. uv.x = uv.x < 0 ? 0 : 1;
  1170. break;
  1171. case MirroredRepeatWrapping:
  1172. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1173. uv.x = Math.ceil(uv.x) - uv.x;
  1174. } else {
  1175. uv.x = uv.x - Math.floor(uv.x);
  1176. }
  1177. break;
  1178. }
  1179. }
  1180. if (uv.y < 0 || uv.y > 1) {
  1181. switch (this.wrapT) {
  1182. case RepeatWrapping:
  1183. uv.y = uv.y - Math.floor(uv.y);
  1184. break;
  1185. case ClampToEdgeWrapping:
  1186. uv.y = uv.y < 0 ? 0 : 1;
  1187. break;
  1188. case MirroredRepeatWrapping:
  1189. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1190. uv.y = Math.ceil(uv.y) - uv.y;
  1191. } else {
  1192. uv.y = uv.y - Math.floor(uv.y);
  1193. }
  1194. break;
  1195. }
  1196. }
  1197. if (this.flipY) {
  1198. uv.y = 1 - uv.y;
  1199. }
  1200. return uv;
  1201. }
  1202. });
  1203. Object.defineProperty(Texture.prototype, "needsUpdate", {
  1204. set: function set(value) {
  1205. if (value === true) this.version++;
  1206. }
  1207. });
  1208. var Vector4 = /*#__PURE__*/function () {
  1209. function Vector4(x, y, z, w) {
  1210. if (x === void 0) {
  1211. x = 0;
  1212. }
  1213. if (y === void 0) {
  1214. y = 0;
  1215. }
  1216. if (z === void 0) {
  1217. z = 0;
  1218. }
  1219. if (w === void 0) {
  1220. w = 1;
  1221. }
  1222. Object.defineProperty(this, 'isVector4', {
  1223. value: true
  1224. });
  1225. this.x = x;
  1226. this.y = y;
  1227. this.z = z;
  1228. this.w = w;
  1229. }
  1230. var _proto = Vector4.prototype;
  1231. _proto.set = function set(x, y, z, w) {
  1232. this.x = x;
  1233. this.y = y;
  1234. this.z = z;
  1235. this.w = w;
  1236. return this;
  1237. };
  1238. _proto.setScalar = function setScalar(scalar) {
  1239. this.x = scalar;
  1240. this.y = scalar;
  1241. this.z = scalar;
  1242. this.w = scalar;
  1243. return this;
  1244. };
  1245. _proto.setX = function setX(x) {
  1246. this.x = x;
  1247. return this;
  1248. };
  1249. _proto.setY = function setY(y) {
  1250. this.y = y;
  1251. return this;
  1252. };
  1253. _proto.setZ = function setZ(z) {
  1254. this.z = z;
  1255. return this;
  1256. };
  1257. _proto.setW = function setW(w) {
  1258. this.w = w;
  1259. return this;
  1260. };
  1261. _proto.setComponent = function setComponent(index, value) {
  1262. switch (index) {
  1263. case 0:
  1264. this.x = value;
  1265. break;
  1266. case 1:
  1267. this.y = value;
  1268. break;
  1269. case 2:
  1270. this.z = value;
  1271. break;
  1272. case 3:
  1273. this.w = value;
  1274. break;
  1275. default:
  1276. throw new Error('index is out of range: ' + index);
  1277. }
  1278. return this;
  1279. };
  1280. _proto.getComponent = function getComponent(index) {
  1281. switch (index) {
  1282. case 0:
  1283. return this.x;
  1284. case 1:
  1285. return this.y;
  1286. case 2:
  1287. return this.z;
  1288. case 3:
  1289. return this.w;
  1290. default:
  1291. throw new Error('index is out of range: ' + index);
  1292. }
  1293. };
  1294. _proto.clone = function clone() {
  1295. return new this.constructor(this.x, this.y, this.z, this.w);
  1296. };
  1297. _proto.copy = function copy(v) {
  1298. this.x = v.x;
  1299. this.y = v.y;
  1300. this.z = v.z;
  1301. this.w = v.w !== undefined ? v.w : 1;
  1302. return this;
  1303. };
  1304. _proto.add = function add(v, w) {
  1305. if (w !== undefined) {
  1306. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1307. return this.addVectors(v, w);
  1308. }
  1309. this.x += v.x;
  1310. this.y += v.y;
  1311. this.z += v.z;
  1312. this.w += v.w;
  1313. return this;
  1314. };
  1315. _proto.addScalar = function addScalar(s) {
  1316. this.x += s;
  1317. this.y += s;
  1318. this.z += s;
  1319. this.w += s;
  1320. return this;
  1321. };
  1322. _proto.addVectors = function addVectors(a, b) {
  1323. this.x = a.x + b.x;
  1324. this.y = a.y + b.y;
  1325. this.z = a.z + b.z;
  1326. this.w = a.w + b.w;
  1327. return this;
  1328. };
  1329. _proto.addScaledVector = function addScaledVector(v, s) {
  1330. this.x += v.x * s;
  1331. this.y += v.y * s;
  1332. this.z += v.z * s;
  1333. this.w += v.w * s;
  1334. return this;
  1335. };
  1336. _proto.sub = function sub(v, w) {
  1337. if (w !== undefined) {
  1338. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1339. return this.subVectors(v, w);
  1340. }
  1341. this.x -= v.x;
  1342. this.y -= v.y;
  1343. this.z -= v.z;
  1344. this.w -= v.w;
  1345. return this;
  1346. };
  1347. _proto.subScalar = function subScalar(s) {
  1348. this.x -= s;
  1349. this.y -= s;
  1350. this.z -= s;
  1351. this.w -= s;
  1352. return this;
  1353. };
  1354. _proto.subVectors = function subVectors(a, b) {
  1355. this.x = a.x - b.x;
  1356. this.y = a.y - b.y;
  1357. this.z = a.z - b.z;
  1358. this.w = a.w - b.w;
  1359. return this;
  1360. };
  1361. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1362. this.x *= scalar;
  1363. this.y *= scalar;
  1364. this.z *= scalar;
  1365. this.w *= scalar;
  1366. return this;
  1367. };
  1368. _proto.applyMatrix4 = function applyMatrix4(m) {
  1369. var x = this.x,
  1370. y = this.y,
  1371. z = this.z,
  1372. w = this.w;
  1373. var e = m.elements;
  1374. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  1375. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  1376. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  1377. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  1378. return this;
  1379. };
  1380. _proto.divideScalar = function divideScalar(scalar) {
  1381. return this.multiplyScalar(1 / scalar);
  1382. };
  1383. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  1384. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1385. // q is assumed to be normalized
  1386. this.w = 2 * Math.acos(q.w);
  1387. var s = Math.sqrt(1 - q.w * q.w);
  1388. if (s < 0.0001) {
  1389. this.x = 1;
  1390. this.y = 0;
  1391. this.z = 0;
  1392. } else {
  1393. this.x = q.x / s;
  1394. this.y = q.y / s;
  1395. this.z = q.z / s;
  1396. }
  1397. return this;
  1398. };
  1399. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  1400. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1401. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1402. var angle, x, y, z; // variables for result
  1403. var epsilon = 0.01,
  1404. // margin to allow for rounding errors
  1405. epsilon2 = 0.1,
  1406. // margin to distinguish between 0 and 180 degrees
  1407. te = m.elements,
  1408. m11 = te[0],
  1409. m12 = te[4],
  1410. m13 = te[8],
  1411. m21 = te[1],
  1412. m22 = te[5],
  1413. m23 = te[9],
  1414. m31 = te[2],
  1415. m32 = te[6],
  1416. m33 = te[10];
  1417. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  1418. // singularity found
  1419. // first check for identity matrix which must have +1 for all terms
  1420. // in leading diagonal and zero in other terms
  1421. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  1422. // this singularity is identity matrix so angle = 0
  1423. this.set(1, 0, 0, 0);
  1424. return this; // zero angle, arbitrary axis
  1425. } // otherwise this singularity is angle = 180
  1426. angle = Math.PI;
  1427. var xx = (m11 + 1) / 2;
  1428. var yy = (m22 + 1) / 2;
  1429. var zz = (m33 + 1) / 2;
  1430. var xy = (m12 + m21) / 4;
  1431. var xz = (m13 + m31) / 4;
  1432. var yz = (m23 + m32) / 4;
  1433. if (xx > yy && xx > zz) {
  1434. // m11 is the largest diagonal term
  1435. if (xx < epsilon) {
  1436. x = 0;
  1437. y = 0.707106781;
  1438. z = 0.707106781;
  1439. } else {
  1440. x = Math.sqrt(xx);
  1441. y = xy / x;
  1442. z = xz / x;
  1443. }
  1444. } else if (yy > zz) {
  1445. // m22 is the largest diagonal term
  1446. if (yy < epsilon) {
  1447. x = 0.707106781;
  1448. y = 0;
  1449. z = 0.707106781;
  1450. } else {
  1451. y = Math.sqrt(yy);
  1452. x = xy / y;
  1453. z = yz / y;
  1454. }
  1455. } else {
  1456. // m33 is the largest diagonal term so base result on this
  1457. if (zz < epsilon) {
  1458. x = 0.707106781;
  1459. y = 0.707106781;
  1460. z = 0;
  1461. } else {
  1462. z = Math.sqrt(zz);
  1463. x = xz / z;
  1464. y = yz / z;
  1465. }
  1466. }
  1467. this.set(x, y, z, angle);
  1468. return this; // return 180 deg rotation
  1469. } // as we have reached here there are no singularities so we can handle normally
  1470. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  1471. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1472. // caught by singularity test above, but I've left it in just in case
  1473. this.x = (m32 - m23) / s;
  1474. this.y = (m13 - m31) / s;
  1475. this.z = (m21 - m12) / s;
  1476. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  1477. return this;
  1478. };
  1479. _proto.min = function min(v) {
  1480. this.x = Math.min(this.x, v.x);
  1481. this.y = Math.min(this.y, v.y);
  1482. this.z = Math.min(this.z, v.z);
  1483. this.w = Math.min(this.w, v.w);
  1484. return this;
  1485. };
  1486. _proto.max = function max(v) {
  1487. this.x = Math.max(this.x, v.x);
  1488. this.y = Math.max(this.y, v.y);
  1489. this.z = Math.max(this.z, v.z);
  1490. this.w = Math.max(this.w, v.w);
  1491. return this;
  1492. };
  1493. _proto.clamp = function clamp(min, max) {
  1494. // assumes min < max, componentwise
  1495. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1496. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1497. this.z = Math.max(min.z, Math.min(max.z, this.z));
  1498. this.w = Math.max(min.w, Math.min(max.w, this.w));
  1499. return this;
  1500. };
  1501. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1502. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1503. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1504. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  1505. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  1506. return this;
  1507. };
  1508. _proto.clampLength = function clampLength(min, max) {
  1509. var length = this.length();
  1510. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1511. };
  1512. _proto.floor = function floor() {
  1513. this.x = Math.floor(this.x);
  1514. this.y = Math.floor(this.y);
  1515. this.z = Math.floor(this.z);
  1516. this.w = Math.floor(this.w);
  1517. return this;
  1518. };
  1519. _proto.ceil = function ceil() {
  1520. this.x = Math.ceil(this.x);
  1521. this.y = Math.ceil(this.y);
  1522. this.z = Math.ceil(this.z);
  1523. this.w = Math.ceil(this.w);
  1524. return this;
  1525. };
  1526. _proto.round = function round() {
  1527. this.x = Math.round(this.x);
  1528. this.y = Math.round(this.y);
  1529. this.z = Math.round(this.z);
  1530. this.w = Math.round(this.w);
  1531. return this;
  1532. };
  1533. _proto.roundToZero = function roundToZero() {
  1534. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1535. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1536. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  1537. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  1538. return this;
  1539. };
  1540. _proto.negate = function negate() {
  1541. this.x = -this.x;
  1542. this.y = -this.y;
  1543. this.z = -this.z;
  1544. this.w = -this.w;
  1545. return this;
  1546. };
  1547. _proto.dot = function dot(v) {
  1548. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1549. };
  1550. _proto.lengthSq = function lengthSq() {
  1551. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1552. };
  1553. _proto.length = function length() {
  1554. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  1555. };
  1556. _proto.manhattanLength = function manhattanLength() {
  1557. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  1558. };
  1559. _proto.normalize = function normalize() {
  1560. return this.divideScalar(this.length() || 1);
  1561. };
  1562. _proto.setLength = function setLength(length) {
  1563. return this.normalize().multiplyScalar(length);
  1564. };
  1565. _proto.lerp = function lerp(v, alpha) {
  1566. this.x += (v.x - this.x) * alpha;
  1567. this.y += (v.y - this.y) * alpha;
  1568. this.z += (v.z - this.z) * alpha;
  1569. this.w += (v.w - this.w) * alpha;
  1570. return this;
  1571. };
  1572. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1573. this.x = v1.x + (v2.x - v1.x) * alpha;
  1574. this.y = v1.y + (v2.y - v1.y) * alpha;
  1575. this.z = v1.z + (v2.z - v1.z) * alpha;
  1576. this.w = v1.w + (v2.w - v1.w) * alpha;
  1577. return this;
  1578. };
  1579. _proto.equals = function equals(v) {
  1580. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  1581. };
  1582. _proto.fromArray = function fromArray(array, offset) {
  1583. if (offset === undefined) offset = 0;
  1584. this.x = array[offset];
  1585. this.y = array[offset + 1];
  1586. this.z = array[offset + 2];
  1587. this.w = array[offset + 3];
  1588. return this;
  1589. };
  1590. _proto.toArray = function toArray(array, offset) {
  1591. if (array === undefined) array = [];
  1592. if (offset === undefined) offset = 0;
  1593. array[offset] = this.x;
  1594. array[offset + 1] = this.y;
  1595. array[offset + 2] = this.z;
  1596. array[offset + 3] = this.w;
  1597. return array;
  1598. };
  1599. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1600. if (offset !== undefined) {
  1601. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  1602. }
  1603. this.x = attribute.getX(index);
  1604. this.y = attribute.getY(index);
  1605. this.z = attribute.getZ(index);
  1606. this.w = attribute.getW(index);
  1607. return this;
  1608. };
  1609. _proto.random = function random() {
  1610. this.x = Math.random();
  1611. this.y = Math.random();
  1612. this.z = Math.random();
  1613. this.w = Math.random();
  1614. return this;
  1615. };
  1616. _createClass(Vector4, [{
  1617. key: "width",
  1618. get: function get() {
  1619. return this.z;
  1620. },
  1621. set: function set(value) {
  1622. this.z = value;
  1623. }
  1624. }, {
  1625. key: "height",
  1626. get: function get() {
  1627. return this.w;
  1628. },
  1629. set: function set(value) {
  1630. this.w = value;
  1631. }
  1632. }]);
  1633. return Vector4;
  1634. }();
  1635. /*
  1636. In options, we can specify:
  1637. * Texture parameters for an auto-generated target texture
  1638. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1639. */
  1640. function WebGLRenderTarget(width, height, options) {
  1641. this.width = width;
  1642. this.height = height;
  1643. this.scissor = new Vector4(0, 0, width, height);
  1644. this.scissorTest = false;
  1645. this.viewport = new Vector4(0, 0, width, height);
  1646. options = options || {};
  1647. this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  1648. this.texture.image = {};
  1649. this.texture.image.width = width;
  1650. this.texture.image.height = height;
  1651. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  1652. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  1653. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1654. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  1655. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1656. }
  1657. WebGLRenderTarget.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1658. constructor: WebGLRenderTarget,
  1659. isWebGLRenderTarget: true,
  1660. setSize: function setSize(width, height) {
  1661. if (this.width !== width || this.height !== height) {
  1662. this.width = width;
  1663. this.height = height;
  1664. this.texture.image.width = width;
  1665. this.texture.image.height = height;
  1666. this.dispose();
  1667. }
  1668. this.viewport.set(0, 0, width, height);
  1669. this.scissor.set(0, 0, width, height);
  1670. },
  1671. clone: function clone() {
  1672. return new this.constructor().copy(this);
  1673. },
  1674. copy: function copy(source) {
  1675. this.width = source.width;
  1676. this.height = source.height;
  1677. this.viewport.copy(source.viewport);
  1678. this.texture = source.texture.clone();
  1679. this.depthBuffer = source.depthBuffer;
  1680. this.stencilBuffer = source.stencilBuffer;
  1681. this.depthTexture = source.depthTexture;
  1682. return this;
  1683. },
  1684. dispose: function dispose() {
  1685. this.dispatchEvent({
  1686. type: 'dispose'
  1687. });
  1688. }
  1689. });
  1690. function WebGLMultisampleRenderTarget(width, height, options) {
  1691. WebGLRenderTarget.call(this, width, height, options);
  1692. this.samples = 4;
  1693. }
  1694. WebGLMultisampleRenderTarget.prototype = Object.assign(Object.create(WebGLRenderTarget.prototype), {
  1695. constructor: WebGLMultisampleRenderTarget,
  1696. isWebGLMultisampleRenderTarget: true,
  1697. copy: function copy(source) {
  1698. WebGLRenderTarget.prototype.copy.call(this, source);
  1699. this.samples = source.samples;
  1700. return this;
  1701. }
  1702. });
  1703. var Quaternion = /*#__PURE__*/function () {
  1704. function Quaternion(x, y, z, w) {
  1705. if (x === void 0) {
  1706. x = 0;
  1707. }
  1708. if (y === void 0) {
  1709. y = 0;
  1710. }
  1711. if (z === void 0) {
  1712. z = 0;
  1713. }
  1714. if (w === void 0) {
  1715. w = 1;
  1716. }
  1717. Object.defineProperty(this, 'isQuaternion', {
  1718. value: true
  1719. });
  1720. this._x = x;
  1721. this._y = y;
  1722. this._z = z;
  1723. this._w = w;
  1724. }
  1725. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  1726. return qm.copy(qa).slerp(qb, t);
  1727. };
  1728. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  1729. // fuzz-free, array-based Quaternion SLERP operation
  1730. var x0 = src0[srcOffset0 + 0],
  1731. y0 = src0[srcOffset0 + 1],
  1732. z0 = src0[srcOffset0 + 2],
  1733. w0 = src0[srcOffset0 + 3];
  1734. var x1 = src1[srcOffset1 + 0],
  1735. y1 = src1[srcOffset1 + 1],
  1736. z1 = src1[srcOffset1 + 2],
  1737. w1 = src1[srcOffset1 + 3];
  1738. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  1739. var s = 1 - t;
  1740. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1741. dir = cos >= 0 ? 1 : -1,
  1742. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  1743. if (sqrSin > Number.EPSILON) {
  1744. var sin = Math.sqrt(sqrSin),
  1745. len = Math.atan2(sin, cos * dir);
  1746. s = Math.sin(s * len) / sin;
  1747. t = Math.sin(t * len) / sin;
  1748. }
  1749. var tDir = t * dir;
  1750. x0 = x0 * s + x1 * tDir;
  1751. y0 = y0 * s + y1 * tDir;
  1752. z0 = z0 * s + z1 * tDir;
  1753. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  1754. if (s === 1 - t) {
  1755. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  1756. x0 *= f;
  1757. y0 *= f;
  1758. z0 *= f;
  1759. w0 *= f;
  1760. }
  1761. }
  1762. dst[dstOffset] = x0;
  1763. dst[dstOffset + 1] = y0;
  1764. dst[dstOffset + 2] = z0;
  1765. dst[dstOffset + 3] = w0;
  1766. };
  1767. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  1768. var x0 = src0[srcOffset0];
  1769. var y0 = src0[srcOffset0 + 1];
  1770. var z0 = src0[srcOffset0 + 2];
  1771. var w0 = src0[srcOffset0 + 3];
  1772. var x1 = src1[srcOffset1];
  1773. var y1 = src1[srcOffset1 + 1];
  1774. var z1 = src1[srcOffset1 + 2];
  1775. var w1 = src1[srcOffset1 + 3];
  1776. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  1777. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  1778. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  1779. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  1780. return dst;
  1781. };
  1782. var _proto = Quaternion.prototype;
  1783. _proto.set = function set(x, y, z, w) {
  1784. this._x = x;
  1785. this._y = y;
  1786. this._z = z;
  1787. this._w = w;
  1788. this._onChangeCallback();
  1789. return this;
  1790. };
  1791. _proto.clone = function clone() {
  1792. return new this.constructor(this._x, this._y, this._z, this._w);
  1793. };
  1794. _proto.copy = function copy(quaternion) {
  1795. this._x = quaternion.x;
  1796. this._y = quaternion.y;
  1797. this._z = quaternion.z;
  1798. this._w = quaternion.w;
  1799. this._onChangeCallback();
  1800. return this;
  1801. };
  1802. _proto.setFromEuler = function setFromEuler(euler, update) {
  1803. if (!(euler && euler.isEuler)) {
  1804. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  1805. }
  1806. var x = euler._x,
  1807. y = euler._y,
  1808. z = euler._z,
  1809. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  1810. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1811. // content/SpinCalc.m
  1812. var cos = Math.cos;
  1813. var sin = Math.sin;
  1814. var c1 = cos(x / 2);
  1815. var c2 = cos(y / 2);
  1816. var c3 = cos(z / 2);
  1817. var s1 = sin(x / 2);
  1818. var s2 = sin(y / 2);
  1819. var s3 = sin(z / 2);
  1820. switch (order) {
  1821. case 'XYZ':
  1822. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1823. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1824. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1825. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1826. break;
  1827. case 'YXZ':
  1828. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1829. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1830. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1831. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1832. break;
  1833. case 'ZXY':
  1834. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1835. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1836. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1837. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1838. break;
  1839. case 'ZYX':
  1840. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1841. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1842. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1843. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1844. break;
  1845. case 'YZX':
  1846. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1847. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1848. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1849. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1850. break;
  1851. case 'XZY':
  1852. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1853. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1854. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1855. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1856. break;
  1857. default:
  1858. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  1859. }
  1860. if (update !== false) this._onChangeCallback();
  1861. return this;
  1862. };
  1863. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  1864. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1865. // assumes axis is normalized
  1866. var halfAngle = angle / 2,
  1867. s = Math.sin(halfAngle);
  1868. this._x = axis.x * s;
  1869. this._y = axis.y * s;
  1870. this._z = axis.z * s;
  1871. this._w = Math.cos(halfAngle);
  1872. this._onChangeCallback();
  1873. return this;
  1874. };
  1875. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  1876. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1877. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1878. var te = m.elements,
  1879. m11 = te[0],
  1880. m12 = te[4],
  1881. m13 = te[8],
  1882. m21 = te[1],
  1883. m22 = te[5],
  1884. m23 = te[9],
  1885. m31 = te[2],
  1886. m32 = te[6],
  1887. m33 = te[10],
  1888. trace = m11 + m22 + m33;
  1889. if (trace > 0) {
  1890. var s = 0.5 / Math.sqrt(trace + 1.0);
  1891. this._w = 0.25 / s;
  1892. this._x = (m32 - m23) * s;
  1893. this._y = (m13 - m31) * s;
  1894. this._z = (m21 - m12) * s;
  1895. } else if (m11 > m22 && m11 > m33) {
  1896. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  1897. this._w = (m32 - m23) / _s;
  1898. this._x = 0.25 * _s;
  1899. this._y = (m12 + m21) / _s;
  1900. this._z = (m13 + m31) / _s;
  1901. } else if (m22 > m33) {
  1902. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  1903. this._w = (m13 - m31) / _s2;
  1904. this._x = (m12 + m21) / _s2;
  1905. this._y = 0.25 * _s2;
  1906. this._z = (m23 + m32) / _s2;
  1907. } else {
  1908. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  1909. this._w = (m21 - m12) / _s3;
  1910. this._x = (m13 + m31) / _s3;
  1911. this._y = (m23 + m32) / _s3;
  1912. this._z = 0.25 * _s3;
  1913. }
  1914. this._onChangeCallback();
  1915. return this;
  1916. };
  1917. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  1918. // assumes direction vectors vFrom and vTo are normalized
  1919. var EPS = 0.000001;
  1920. var r = vFrom.dot(vTo) + 1;
  1921. if (r < EPS) {
  1922. r = 0;
  1923. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  1924. this._x = -vFrom.y;
  1925. this._y = vFrom.x;
  1926. this._z = 0;
  1927. this._w = r;
  1928. } else {
  1929. this._x = 0;
  1930. this._y = -vFrom.z;
  1931. this._z = vFrom.y;
  1932. this._w = r;
  1933. }
  1934. } else {
  1935. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  1936. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  1937. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  1938. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  1939. this._w = r;
  1940. }
  1941. return this.normalize();
  1942. };
  1943. _proto.angleTo = function angleTo(q) {
  1944. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  1945. };
  1946. _proto.rotateTowards = function rotateTowards(q, step) {
  1947. var angle = this.angleTo(q);
  1948. if (angle === 0) return this;
  1949. var t = Math.min(1, step / angle);
  1950. this.slerp(q, t);
  1951. return this;
  1952. };
  1953. _proto.identity = function identity() {
  1954. return this.set(0, 0, 0, 1);
  1955. };
  1956. _proto.inverse = function inverse() {
  1957. // quaternion is assumed to have unit length
  1958. return this.conjugate();
  1959. };
  1960. _proto.conjugate = function conjugate() {
  1961. this._x *= -1;
  1962. this._y *= -1;
  1963. this._z *= -1;
  1964. this._onChangeCallback();
  1965. return this;
  1966. };
  1967. _proto.dot = function dot(v) {
  1968. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1969. };
  1970. _proto.lengthSq = function lengthSq() {
  1971. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1972. };
  1973. _proto.length = function length() {
  1974. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  1975. };
  1976. _proto.normalize = function normalize() {
  1977. var l = this.length();
  1978. if (l === 0) {
  1979. this._x = 0;
  1980. this._y = 0;
  1981. this._z = 0;
  1982. this._w = 1;
  1983. } else {
  1984. l = 1 / l;
  1985. this._x = this._x * l;
  1986. this._y = this._y * l;
  1987. this._z = this._z * l;
  1988. this._w = this._w * l;
  1989. }
  1990. this._onChangeCallback();
  1991. return this;
  1992. };
  1993. _proto.multiply = function multiply(q, p) {
  1994. if (p !== undefined) {
  1995. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  1996. return this.multiplyQuaternions(q, p);
  1997. }
  1998. return this.multiplyQuaternions(this, q);
  1999. };
  2000. _proto.premultiply = function premultiply(q) {
  2001. return this.multiplyQuaternions(q, this);
  2002. };
  2003. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2004. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2005. var qax = a._x,
  2006. qay = a._y,
  2007. qaz = a._z,
  2008. qaw = a._w;
  2009. var qbx = b._x,
  2010. qby = b._y,
  2011. qbz = b._z,
  2012. qbw = b._w;
  2013. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2014. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2015. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2016. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2017. this._onChangeCallback();
  2018. return this;
  2019. };
  2020. _proto.slerp = function slerp(qb, t) {
  2021. if (t === 0) return this;
  2022. if (t === 1) return this.copy(qb);
  2023. var x = this._x,
  2024. y = this._y,
  2025. z = this._z,
  2026. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2027. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2028. if (cosHalfTheta < 0) {
  2029. this._w = -qb._w;
  2030. this._x = -qb._x;
  2031. this._y = -qb._y;
  2032. this._z = -qb._z;
  2033. cosHalfTheta = -cosHalfTheta;
  2034. } else {
  2035. this.copy(qb);
  2036. }
  2037. if (cosHalfTheta >= 1.0) {
  2038. this._w = w;
  2039. this._x = x;
  2040. this._y = y;
  2041. this._z = z;
  2042. return this;
  2043. }
  2044. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2045. if (sqrSinHalfTheta <= Number.EPSILON) {
  2046. var s = 1 - t;
  2047. this._w = s * w + t * this._w;
  2048. this._x = s * x + t * this._x;
  2049. this._y = s * y + t * this._y;
  2050. this._z = s * z + t * this._z;
  2051. this.normalize();
  2052. this._onChangeCallback();
  2053. return this;
  2054. }
  2055. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2056. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2057. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2058. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2059. this._w = w * ratioA + this._w * ratioB;
  2060. this._x = x * ratioA + this._x * ratioB;
  2061. this._y = y * ratioA + this._y * ratioB;
  2062. this._z = z * ratioA + this._z * ratioB;
  2063. this._onChangeCallback();
  2064. return this;
  2065. };
  2066. _proto.equals = function equals(quaternion) {
  2067. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2068. };
  2069. _proto.fromArray = function fromArray(array, offset) {
  2070. if (offset === undefined) offset = 0;
  2071. this._x = array[offset];
  2072. this._y = array[offset + 1];
  2073. this._z = array[offset + 2];
  2074. this._w = array[offset + 3];
  2075. this._onChangeCallback();
  2076. return this;
  2077. };
  2078. _proto.toArray = function toArray(array, offset) {
  2079. if (array === undefined) array = [];
  2080. if (offset === undefined) offset = 0;
  2081. array[offset] = this._x;
  2082. array[offset + 1] = this._y;
  2083. array[offset + 2] = this._z;
  2084. array[offset + 3] = this._w;
  2085. return array;
  2086. };
  2087. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2088. this._x = attribute.getX(index);
  2089. this._y = attribute.getY(index);
  2090. this._z = attribute.getZ(index);
  2091. this._w = attribute.getW(index);
  2092. return this;
  2093. };
  2094. _proto._onChange = function _onChange(callback) {
  2095. this._onChangeCallback = callback;
  2096. return this;
  2097. };
  2098. _proto._onChangeCallback = function _onChangeCallback() {};
  2099. _createClass(Quaternion, [{
  2100. key: "x",
  2101. get: function get() {
  2102. return this._x;
  2103. },
  2104. set: function set(value) {
  2105. this._x = value;
  2106. this._onChangeCallback();
  2107. }
  2108. }, {
  2109. key: "y",
  2110. get: function get() {
  2111. return this._y;
  2112. },
  2113. set: function set(value) {
  2114. this._y = value;
  2115. this._onChangeCallback();
  2116. }
  2117. }, {
  2118. key: "z",
  2119. get: function get() {
  2120. return this._z;
  2121. },
  2122. set: function set(value) {
  2123. this._z = value;
  2124. this._onChangeCallback();
  2125. }
  2126. }, {
  2127. key: "w",
  2128. get: function get() {
  2129. return this._w;
  2130. },
  2131. set: function set(value) {
  2132. this._w = value;
  2133. this._onChangeCallback();
  2134. }
  2135. }]);
  2136. return Quaternion;
  2137. }();
  2138. var Vector3 = /*#__PURE__*/function () {
  2139. function Vector3(x, y, z) {
  2140. if (x === void 0) {
  2141. x = 0;
  2142. }
  2143. if (y === void 0) {
  2144. y = 0;
  2145. }
  2146. if (z === void 0) {
  2147. z = 0;
  2148. }
  2149. Object.defineProperty(this, 'isVector3', {
  2150. value: true
  2151. });
  2152. this.x = x;
  2153. this.y = y;
  2154. this.z = z;
  2155. }
  2156. var _proto = Vector3.prototype;
  2157. _proto.set = function set(x, y, z) {
  2158. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2159. this.x = x;
  2160. this.y = y;
  2161. this.z = z;
  2162. return this;
  2163. };
  2164. _proto.setScalar = function setScalar(scalar) {
  2165. this.x = scalar;
  2166. this.y = scalar;
  2167. this.z = scalar;
  2168. return this;
  2169. };
  2170. _proto.setX = function setX(x) {
  2171. this.x = x;
  2172. return this;
  2173. };
  2174. _proto.setY = function setY(y) {
  2175. this.y = y;
  2176. return this;
  2177. };
  2178. _proto.setZ = function setZ(z) {
  2179. this.z = z;
  2180. return this;
  2181. };
  2182. _proto.setComponent = function setComponent(index, value) {
  2183. switch (index) {
  2184. case 0:
  2185. this.x = value;
  2186. break;
  2187. case 1:
  2188. this.y = value;
  2189. break;
  2190. case 2:
  2191. this.z = value;
  2192. break;
  2193. default:
  2194. throw new Error('index is out of range: ' + index);
  2195. }
  2196. return this;
  2197. };
  2198. _proto.getComponent = function getComponent(index) {
  2199. switch (index) {
  2200. case 0:
  2201. return this.x;
  2202. case 1:
  2203. return this.y;
  2204. case 2:
  2205. return this.z;
  2206. default:
  2207. throw new Error('index is out of range: ' + index);
  2208. }
  2209. };
  2210. _proto.clone = function clone() {
  2211. return new this.constructor(this.x, this.y, this.z);
  2212. };
  2213. _proto.copy = function copy(v) {
  2214. this.x = v.x;
  2215. this.y = v.y;
  2216. this.z = v.z;
  2217. return this;
  2218. };
  2219. _proto.add = function add(v, w) {
  2220. if (w !== undefined) {
  2221. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2222. return this.addVectors(v, w);
  2223. }
  2224. this.x += v.x;
  2225. this.y += v.y;
  2226. this.z += v.z;
  2227. return this;
  2228. };
  2229. _proto.addScalar = function addScalar(s) {
  2230. this.x += s;
  2231. this.y += s;
  2232. this.z += s;
  2233. return this;
  2234. };
  2235. _proto.addVectors = function addVectors(a, b) {
  2236. this.x = a.x + b.x;
  2237. this.y = a.y + b.y;
  2238. this.z = a.z + b.z;
  2239. return this;
  2240. };
  2241. _proto.addScaledVector = function addScaledVector(v, s) {
  2242. this.x += v.x * s;
  2243. this.y += v.y * s;
  2244. this.z += v.z * s;
  2245. return this;
  2246. };
  2247. _proto.sub = function sub(v, w) {
  2248. if (w !== undefined) {
  2249. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2250. return this.subVectors(v, w);
  2251. }
  2252. this.x -= v.x;
  2253. this.y -= v.y;
  2254. this.z -= v.z;
  2255. return this;
  2256. };
  2257. _proto.subScalar = function subScalar(s) {
  2258. this.x -= s;
  2259. this.y -= s;
  2260. this.z -= s;
  2261. return this;
  2262. };
  2263. _proto.subVectors = function subVectors(a, b) {
  2264. this.x = a.x - b.x;
  2265. this.y = a.y - b.y;
  2266. this.z = a.z - b.z;
  2267. return this;
  2268. };
  2269. _proto.multiply = function multiply(v, w) {
  2270. if (w !== undefined) {
  2271. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  2272. return this.multiplyVectors(v, w);
  2273. }
  2274. this.x *= v.x;
  2275. this.y *= v.y;
  2276. this.z *= v.z;
  2277. return this;
  2278. };
  2279. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2280. this.x *= scalar;
  2281. this.y *= scalar;
  2282. this.z *= scalar;
  2283. return this;
  2284. };
  2285. _proto.multiplyVectors = function multiplyVectors(a, b) {
  2286. this.x = a.x * b.x;
  2287. this.y = a.y * b.y;
  2288. this.z = a.z * b.z;
  2289. return this;
  2290. };
  2291. _proto.applyEuler = function applyEuler(euler) {
  2292. if (!(euler && euler.isEuler)) {
  2293. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2294. }
  2295. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  2296. };
  2297. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  2298. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  2299. };
  2300. _proto.applyMatrix3 = function applyMatrix3(m) {
  2301. var x = this.x,
  2302. y = this.y,
  2303. z = this.z;
  2304. var e = m.elements;
  2305. this.x = e[0] * x + e[3] * y + e[6] * z;
  2306. this.y = e[1] * x + e[4] * y + e[7] * z;
  2307. this.z = e[2] * x + e[5] * y + e[8] * z;
  2308. return this;
  2309. };
  2310. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  2311. return this.applyMatrix3(m).normalize();
  2312. };
  2313. _proto.applyMatrix4 = function applyMatrix4(m) {
  2314. var x = this.x,
  2315. y = this.y,
  2316. z = this.z;
  2317. var e = m.elements;
  2318. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  2319. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  2320. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  2321. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  2322. return this;
  2323. };
  2324. _proto.applyQuaternion = function applyQuaternion(q) {
  2325. var x = this.x,
  2326. y = this.y,
  2327. z = this.z;
  2328. var qx = q.x,
  2329. qy = q.y,
  2330. qz = q.z,
  2331. qw = q.w; // calculate quat * vector
  2332. var ix = qw * x + qy * z - qz * y;
  2333. var iy = qw * y + qz * x - qx * z;
  2334. var iz = qw * z + qx * y - qy * x;
  2335. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  2336. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  2337. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  2338. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  2339. return this;
  2340. };
  2341. _proto.project = function project(camera) {
  2342. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  2343. };
  2344. _proto.unproject = function unproject(camera) {
  2345. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  2346. };
  2347. _proto.transformDirection = function transformDirection(m) {
  2348. // input: THREE.Matrix4 affine matrix
  2349. // vector interpreted as a direction
  2350. var x = this.x,
  2351. y = this.y,
  2352. z = this.z;
  2353. var e = m.elements;
  2354. this.x = e[0] * x + e[4] * y + e[8] * z;
  2355. this.y = e[1] * x + e[5] * y + e[9] * z;
  2356. this.z = e[2] * x + e[6] * y + e[10] * z;
  2357. return this.normalize();
  2358. };
  2359. _proto.divide = function divide(v) {
  2360. this.x /= v.x;
  2361. this.y /= v.y;
  2362. this.z /= v.z;
  2363. return this;
  2364. };
  2365. _proto.divideScalar = function divideScalar(scalar) {
  2366. return this.multiplyScalar(1 / scalar);
  2367. };
  2368. _proto.min = function min(v) {
  2369. this.x = Math.min(this.x, v.x);
  2370. this.y = Math.min(this.y, v.y);
  2371. this.z = Math.min(this.z, v.z);
  2372. return this;
  2373. };
  2374. _proto.max = function max(v) {
  2375. this.x = Math.max(this.x, v.x);
  2376. this.y = Math.max(this.y, v.y);
  2377. this.z = Math.max(this.z, v.z);
  2378. return this;
  2379. };
  2380. _proto.clamp = function clamp(min, max) {
  2381. // assumes min < max, componentwise
  2382. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2383. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2384. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2385. return this;
  2386. };
  2387. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2388. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2389. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2390. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2391. return this;
  2392. };
  2393. _proto.clampLength = function clampLength(min, max) {
  2394. var length = this.length();
  2395. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2396. };
  2397. _proto.floor = function floor() {
  2398. this.x = Math.floor(this.x);
  2399. this.y = Math.floor(this.y);
  2400. this.z = Math.floor(this.z);
  2401. return this;
  2402. };
  2403. _proto.ceil = function ceil() {
  2404. this.x = Math.ceil(this.x);
  2405. this.y = Math.ceil(this.y);
  2406. this.z = Math.ceil(this.z);
  2407. return this;
  2408. };
  2409. _proto.round = function round() {
  2410. this.x = Math.round(this.x);
  2411. this.y = Math.round(this.y);
  2412. this.z = Math.round(this.z);
  2413. return this;
  2414. };
  2415. _proto.roundToZero = function roundToZero() {
  2416. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2417. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2418. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2419. return this;
  2420. };
  2421. _proto.negate = function negate() {
  2422. this.x = -this.x;
  2423. this.y = -this.y;
  2424. this.z = -this.z;
  2425. return this;
  2426. };
  2427. _proto.dot = function dot(v) {
  2428. return this.x * v.x + this.y * v.y + this.z * v.z;
  2429. } // TODO lengthSquared?
  2430. ;
  2431. _proto.lengthSq = function lengthSq() {
  2432. return this.x * this.x + this.y * this.y + this.z * this.z;
  2433. };
  2434. _proto.length = function length() {
  2435. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  2436. };
  2437. _proto.manhattanLength = function manhattanLength() {
  2438. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  2439. };
  2440. _proto.normalize = function normalize() {
  2441. return this.divideScalar(this.length() || 1);
  2442. };
  2443. _proto.setLength = function setLength(length) {
  2444. return this.normalize().multiplyScalar(length);
  2445. };
  2446. _proto.lerp = function lerp(v, alpha) {
  2447. this.x += (v.x - this.x) * alpha;
  2448. this.y += (v.y - this.y) * alpha;
  2449. this.z += (v.z - this.z) * alpha;
  2450. return this;
  2451. };
  2452. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2453. this.x = v1.x + (v2.x - v1.x) * alpha;
  2454. this.y = v1.y + (v2.y - v1.y) * alpha;
  2455. this.z = v1.z + (v2.z - v1.z) * alpha;
  2456. return this;
  2457. };
  2458. _proto.cross = function cross(v, w) {
  2459. if (w !== undefined) {
  2460. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  2461. return this.crossVectors(v, w);
  2462. }
  2463. return this.crossVectors(this, v);
  2464. };
  2465. _proto.crossVectors = function crossVectors(a, b) {
  2466. var ax = a.x,
  2467. ay = a.y,
  2468. az = a.z;
  2469. var bx = b.x,
  2470. by = b.y,
  2471. bz = b.z;
  2472. this.x = ay * bz - az * by;
  2473. this.y = az * bx - ax * bz;
  2474. this.z = ax * by - ay * bx;
  2475. return this;
  2476. };
  2477. _proto.projectOnVector = function projectOnVector(v) {
  2478. var denominator = v.lengthSq();
  2479. if (denominator === 0) return this.set(0, 0, 0);
  2480. var scalar = v.dot(this) / denominator;
  2481. return this.copy(v).multiplyScalar(scalar);
  2482. };
  2483. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  2484. _vector.copy(this).projectOnVector(planeNormal);
  2485. return this.sub(_vector);
  2486. };
  2487. _proto.reflect = function reflect(normal) {
  2488. // reflect incident vector off plane orthogonal to normal
  2489. // normal is assumed to have unit length
  2490. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  2491. };
  2492. _proto.angleTo = function angleTo(v) {
  2493. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  2494. if (denominator === 0) return Math.PI / 2;
  2495. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  2496. return Math.acos(MathUtils.clamp(theta, -1, 1));
  2497. };
  2498. _proto.distanceTo = function distanceTo(v) {
  2499. return Math.sqrt(this.distanceToSquared(v));
  2500. };
  2501. _proto.distanceToSquared = function distanceToSquared(v) {
  2502. var dx = this.x - v.x,
  2503. dy = this.y - v.y,
  2504. dz = this.z - v.z;
  2505. return dx * dx + dy * dy + dz * dz;
  2506. };
  2507. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  2508. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  2509. };
  2510. _proto.setFromSpherical = function setFromSpherical(s) {
  2511. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  2512. };
  2513. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  2514. var sinPhiRadius = Math.sin(phi) * radius;
  2515. this.x = sinPhiRadius * Math.sin(theta);
  2516. this.y = Math.cos(phi) * radius;
  2517. this.z = sinPhiRadius * Math.cos(theta);
  2518. return this;
  2519. };
  2520. _proto.setFromCylindrical = function setFromCylindrical(c) {
  2521. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  2522. };
  2523. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  2524. this.x = radius * Math.sin(theta);
  2525. this.y = y;
  2526. this.z = radius * Math.cos(theta);
  2527. return this;
  2528. };
  2529. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  2530. var e = m.elements;
  2531. this.x = e[12];
  2532. this.y = e[13];
  2533. this.z = e[14];
  2534. return this;
  2535. };
  2536. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  2537. var sx = this.setFromMatrixColumn(m, 0).length();
  2538. var sy = this.setFromMatrixColumn(m, 1).length();
  2539. var sz = this.setFromMatrixColumn(m, 2).length();
  2540. this.x = sx;
  2541. this.y = sy;
  2542. this.z = sz;
  2543. return this;
  2544. };
  2545. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  2546. return this.fromArray(m.elements, index * 4);
  2547. };
  2548. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  2549. return this.fromArray(m.elements, index * 3);
  2550. };
  2551. _proto.equals = function equals(v) {
  2552. return v.x === this.x && v.y === this.y && v.z === this.z;
  2553. };
  2554. _proto.fromArray = function fromArray(array, offset) {
  2555. if (offset === undefined) offset = 0;
  2556. this.x = array[offset];
  2557. this.y = array[offset + 1];
  2558. this.z = array[offset + 2];
  2559. return this;
  2560. };
  2561. _proto.toArray = function toArray(array, offset) {
  2562. if (array === undefined) array = [];
  2563. if (offset === undefined) offset = 0;
  2564. array[offset] = this.x;
  2565. array[offset + 1] = this.y;
  2566. array[offset + 2] = this.z;
  2567. return array;
  2568. };
  2569. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2570. if (offset !== undefined) {
  2571. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  2572. }
  2573. this.x = attribute.getX(index);
  2574. this.y = attribute.getY(index);
  2575. this.z = attribute.getZ(index);
  2576. return this;
  2577. };
  2578. _proto.random = function random() {
  2579. this.x = Math.random();
  2580. this.y = Math.random();
  2581. this.z = Math.random();
  2582. return this;
  2583. };
  2584. return Vector3;
  2585. }();
  2586. var _vector = /*@__PURE__*/new Vector3();
  2587. var _quaternion = /*@__PURE__*/new Quaternion();
  2588. var Box3 = /*#__PURE__*/function () {
  2589. function Box3(min, max) {
  2590. Object.defineProperty(this, 'isBox3', {
  2591. value: true
  2592. });
  2593. this.min = min !== undefined ? min : new Vector3(+Infinity, +Infinity, +Infinity);
  2594. this.max = max !== undefined ? max : new Vector3(-Infinity, -Infinity, -Infinity);
  2595. }
  2596. var _proto = Box3.prototype;
  2597. _proto.set = function set(min, max) {
  2598. this.min.copy(min);
  2599. this.max.copy(max);
  2600. return this;
  2601. };
  2602. _proto.setFromArray = function setFromArray(array) {
  2603. var minX = +Infinity;
  2604. var minY = +Infinity;
  2605. var minZ = +Infinity;
  2606. var maxX = -Infinity;
  2607. var maxY = -Infinity;
  2608. var maxZ = -Infinity;
  2609. for (var i = 0, l = array.length; i < l; i += 3) {
  2610. var x = array[i];
  2611. var y = array[i + 1];
  2612. var z = array[i + 2];
  2613. if (x < minX) minX = x;
  2614. if (y < minY) minY = y;
  2615. if (z < minZ) minZ = z;
  2616. if (x > maxX) maxX = x;
  2617. if (y > maxY) maxY = y;
  2618. if (z > maxZ) maxZ = z;
  2619. }
  2620. this.min.set(minX, minY, minZ);
  2621. this.max.set(maxX, maxY, maxZ);
  2622. return this;
  2623. };
  2624. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  2625. var minX = +Infinity;
  2626. var minY = +Infinity;
  2627. var minZ = +Infinity;
  2628. var maxX = -Infinity;
  2629. var maxY = -Infinity;
  2630. var maxZ = -Infinity;
  2631. for (var i = 0, l = attribute.count; i < l; i++) {
  2632. var x = attribute.getX(i);
  2633. var y = attribute.getY(i);
  2634. var z = attribute.getZ(i);
  2635. if (x < minX) minX = x;
  2636. if (y < minY) minY = y;
  2637. if (z < minZ) minZ = z;
  2638. if (x > maxX) maxX = x;
  2639. if (y > maxY) maxY = y;
  2640. if (z > maxZ) maxZ = z;
  2641. }
  2642. this.min.set(minX, minY, minZ);
  2643. this.max.set(maxX, maxY, maxZ);
  2644. return this;
  2645. };
  2646. _proto.setFromPoints = function setFromPoints(points) {
  2647. this.makeEmpty();
  2648. for (var i = 0, il = points.length; i < il; i++) {
  2649. this.expandByPoint(points[i]);
  2650. }
  2651. return this;
  2652. };
  2653. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  2654. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  2655. this.min.copy(center).sub(halfSize);
  2656. this.max.copy(center).add(halfSize);
  2657. return this;
  2658. };
  2659. _proto.setFromObject = function setFromObject(object) {
  2660. this.makeEmpty();
  2661. return this.expandByObject(object);
  2662. };
  2663. _proto.clone = function clone() {
  2664. return new this.constructor().copy(this);
  2665. };
  2666. _proto.copy = function copy(box) {
  2667. this.min.copy(box.min);
  2668. this.max.copy(box.max);
  2669. return this;
  2670. };
  2671. _proto.makeEmpty = function makeEmpty() {
  2672. this.min.x = this.min.y = this.min.z = +Infinity;
  2673. this.max.x = this.max.y = this.max.z = -Infinity;
  2674. return this;
  2675. };
  2676. _proto.isEmpty = function isEmpty() {
  2677. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2678. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  2679. };
  2680. _proto.getCenter = function getCenter(target) {
  2681. if (target === undefined) {
  2682. console.warn('THREE.Box3: .getCenter() target is now required');
  2683. target = new Vector3();
  2684. }
  2685. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  2686. };
  2687. _proto.getSize = function getSize(target) {
  2688. if (target === undefined) {
  2689. console.warn('THREE.Box3: .getSize() target is now required');
  2690. target = new Vector3();
  2691. }
  2692. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  2693. };
  2694. _proto.expandByPoint = function expandByPoint(point) {
  2695. this.min.min(point);
  2696. this.max.max(point);
  2697. return this;
  2698. };
  2699. _proto.expandByVector = function expandByVector(vector) {
  2700. this.min.sub(vector);
  2701. this.max.add(vector);
  2702. return this;
  2703. };
  2704. _proto.expandByScalar = function expandByScalar(scalar) {
  2705. this.min.addScalar(-scalar);
  2706. this.max.addScalar(scalar);
  2707. return this;
  2708. };
  2709. _proto.expandByObject = function expandByObject(object) {
  2710. // Computes the world-axis-aligned bounding box of an object (including its children),
  2711. // accounting for both the object's, and children's, world transforms
  2712. object.updateWorldMatrix(false, false);
  2713. var geometry = object.geometry;
  2714. if (geometry !== undefined) {
  2715. if (geometry.boundingBox === null) {
  2716. geometry.computeBoundingBox();
  2717. }
  2718. _box.copy(geometry.boundingBox);
  2719. _box.applyMatrix4(object.matrixWorld);
  2720. this.union(_box);
  2721. }
  2722. var children = object.children;
  2723. for (var i = 0, l = children.length; i < l; i++) {
  2724. this.expandByObject(children[i]);
  2725. }
  2726. return this;
  2727. };
  2728. _proto.containsPoint = function containsPoint(point) {
  2729. 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;
  2730. };
  2731. _proto.containsBox = function containsBox(box) {
  2732. 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;
  2733. };
  2734. _proto.getParameter = function getParameter(point, target) {
  2735. // This can potentially have a divide by zero if the box
  2736. // has a size dimension of 0.
  2737. if (target === undefined) {
  2738. console.warn('THREE.Box3: .getParameter() target is now required');
  2739. target = new Vector3();
  2740. }
  2741. 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));
  2742. };
  2743. _proto.intersectsBox = function intersectsBox(box) {
  2744. // using 6 splitting planes to rule out intersections.
  2745. 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;
  2746. };
  2747. _proto.intersectsSphere = function intersectsSphere(sphere) {
  2748. // Find the point on the AABB closest to the sphere center.
  2749. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  2750. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  2751. };
  2752. _proto.intersectsPlane = function intersectsPlane(plane) {
  2753. // We compute the minimum and maximum dot product values. If those values
  2754. // are on the same side (back or front) of the plane, then there is no intersection.
  2755. var min, max;
  2756. if (plane.normal.x > 0) {
  2757. min = plane.normal.x * this.min.x;
  2758. max = plane.normal.x * this.max.x;
  2759. } else {
  2760. min = plane.normal.x * this.max.x;
  2761. max = plane.normal.x * this.min.x;
  2762. }
  2763. if (plane.normal.y > 0) {
  2764. min += plane.normal.y * this.min.y;
  2765. max += plane.normal.y * this.max.y;
  2766. } else {
  2767. min += plane.normal.y * this.max.y;
  2768. max += plane.normal.y * this.min.y;
  2769. }
  2770. if (plane.normal.z > 0) {
  2771. min += plane.normal.z * this.min.z;
  2772. max += plane.normal.z * this.max.z;
  2773. } else {
  2774. min += plane.normal.z * this.max.z;
  2775. max += plane.normal.z * this.min.z;
  2776. }
  2777. return min <= -plane.constant && max >= -plane.constant;
  2778. };
  2779. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  2780. if (this.isEmpty()) {
  2781. return false;
  2782. } // compute box center and extents
  2783. this.getCenter(_center);
  2784. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  2785. _v0.subVectors(triangle.a, _center);
  2786. _v1.subVectors(triangle.b, _center);
  2787. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  2788. _f0.subVectors(_v1, _v0);
  2789. _f1.subVectors(_v2, _v1);
  2790. _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
  2791. // 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
  2792. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  2793. 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];
  2794. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2795. return false;
  2796. } // test 3 face normals from the aabb
  2797. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  2798. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2799. return false;
  2800. } // finally testing the face normal of the triangle
  2801. // use already existing triangle edge vectors here
  2802. _triangleNormal.crossVectors(_f0, _f1);
  2803. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  2804. return satForAxes(axes, _v0, _v1, _v2, _extents);
  2805. };
  2806. _proto.clampPoint = function clampPoint(point, target) {
  2807. if (target === undefined) {
  2808. console.warn('THREE.Box3: .clampPoint() target is now required');
  2809. target = new Vector3();
  2810. }
  2811. return target.copy(point).clamp(this.min, this.max);
  2812. };
  2813. _proto.distanceToPoint = function distanceToPoint(point) {
  2814. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  2815. return clampedPoint.sub(point).length();
  2816. };
  2817. _proto.getBoundingSphere = function getBoundingSphere(target) {
  2818. if (target === undefined) {
  2819. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  2820. }
  2821. this.getCenter(target.center);
  2822. target.radius = this.getSize(_vector$1).length() * 0.5;
  2823. return target;
  2824. };
  2825. _proto.intersect = function intersect(box) {
  2826. this.min.max(box.min);
  2827. 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.
  2828. if (this.isEmpty()) this.makeEmpty();
  2829. return this;
  2830. };
  2831. _proto.union = function union(box) {
  2832. this.min.min(box.min);
  2833. this.max.max(box.max);
  2834. return this;
  2835. };
  2836. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  2837. // transform of empty box is an empty box.
  2838. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2839. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  2840. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  2841. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  2842. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  2843. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  2844. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  2845. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  2846. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  2847. this.setFromPoints(_points);
  2848. return this;
  2849. };
  2850. _proto.translate = function translate(offset) {
  2851. this.min.add(offset);
  2852. this.max.add(offset);
  2853. return this;
  2854. };
  2855. _proto.equals = function equals(box) {
  2856. return box.min.equals(this.min) && box.max.equals(this.max);
  2857. };
  2858. return Box3;
  2859. }();
  2860. function satForAxes(axes, v0, v1, v2, extents) {
  2861. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  2862. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  2863. 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
  2864. var p0 = v0.dot(_testAxis);
  2865. var p1 = v1.dot(_testAxis);
  2866. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  2867. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  2868. // points of the projected triangle are outside the projected half-length of the aabb
  2869. // the axis is seperating and we can exit
  2870. return false;
  2871. }
  2872. }
  2873. return true;
  2874. }
  2875. 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()];
  2876. var _vector$1 = /*@__PURE__*/new Vector3();
  2877. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  2878. var _v0 = /*@__PURE__*/new Vector3();
  2879. var _v1 = /*@__PURE__*/new Vector3();
  2880. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  2881. var _f0 = /*@__PURE__*/new Vector3();
  2882. var _f1 = /*@__PURE__*/new Vector3();
  2883. var _f2 = /*@__PURE__*/new Vector3();
  2884. var _center = /*@__PURE__*/new Vector3();
  2885. var _extents = /*@__PURE__*/new Vector3();
  2886. var _triangleNormal = /*@__PURE__*/new Vector3();
  2887. var _testAxis = /*@__PURE__*/new Vector3();
  2888. var _box$1 = /*@__PURE__*/new Box3();
  2889. var Sphere = /*#__PURE__*/function () {
  2890. function Sphere(center, radius) {
  2891. this.center = center !== undefined ? center : new Vector3();
  2892. this.radius = radius !== undefined ? radius : -1;
  2893. }
  2894. var _proto = Sphere.prototype;
  2895. _proto.set = function set(center, radius) {
  2896. this.center.copy(center);
  2897. this.radius = radius;
  2898. return this;
  2899. };
  2900. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  2901. var center = this.center;
  2902. if (optionalCenter !== undefined) {
  2903. center.copy(optionalCenter);
  2904. } else {
  2905. _box$1.setFromPoints(points).getCenter(center);
  2906. }
  2907. var maxRadiusSq = 0;
  2908. for (var i = 0, il = points.length; i < il; i++) {
  2909. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  2910. }
  2911. this.radius = Math.sqrt(maxRadiusSq);
  2912. return this;
  2913. };
  2914. _proto.clone = function clone() {
  2915. return new this.constructor().copy(this);
  2916. };
  2917. _proto.copy = function copy(sphere) {
  2918. this.center.copy(sphere.center);
  2919. this.radius = sphere.radius;
  2920. return this;
  2921. };
  2922. _proto.isEmpty = function isEmpty() {
  2923. return this.radius < 0;
  2924. };
  2925. _proto.makeEmpty = function makeEmpty() {
  2926. this.center.set(0, 0, 0);
  2927. this.radius = -1;
  2928. return this;
  2929. };
  2930. _proto.containsPoint = function containsPoint(point) {
  2931. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  2932. };
  2933. _proto.distanceToPoint = function distanceToPoint(point) {
  2934. return point.distanceTo(this.center) - this.radius;
  2935. };
  2936. _proto.intersectsSphere = function intersectsSphere(sphere) {
  2937. var radiusSum = this.radius + sphere.radius;
  2938. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  2939. };
  2940. _proto.intersectsBox = function intersectsBox(box) {
  2941. return box.intersectsSphere(this);
  2942. };
  2943. _proto.intersectsPlane = function intersectsPlane(plane) {
  2944. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  2945. };
  2946. _proto.clampPoint = function clampPoint(point, target) {
  2947. var deltaLengthSq = this.center.distanceToSquared(point);
  2948. if (target === undefined) {
  2949. console.warn('THREE.Sphere: .clampPoint() target is now required');
  2950. target = new Vector3();
  2951. }
  2952. target.copy(point);
  2953. if (deltaLengthSq > this.radius * this.radius) {
  2954. target.sub(this.center).normalize();
  2955. target.multiplyScalar(this.radius).add(this.center);
  2956. }
  2957. return target;
  2958. };
  2959. _proto.getBoundingBox = function getBoundingBox(target) {
  2960. if (target === undefined) {
  2961. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  2962. target = new Box3();
  2963. }
  2964. if (this.isEmpty()) {
  2965. // Empty sphere produces empty bounding box
  2966. target.makeEmpty();
  2967. return target;
  2968. }
  2969. target.set(this.center, this.center);
  2970. target.expandByScalar(this.radius);
  2971. return target;
  2972. };
  2973. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  2974. this.center.applyMatrix4(matrix);
  2975. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  2976. return this;
  2977. };
  2978. _proto.translate = function translate(offset) {
  2979. this.center.add(offset);
  2980. return this;
  2981. };
  2982. _proto.equals = function equals(sphere) {
  2983. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  2984. };
  2985. return Sphere;
  2986. }();
  2987. var _vector$2 = /*@__PURE__*/new Vector3();
  2988. var _segCenter = /*@__PURE__*/new Vector3();
  2989. var _segDir = /*@__PURE__*/new Vector3();
  2990. var _diff = /*@__PURE__*/new Vector3();
  2991. var _edge1 = /*@__PURE__*/new Vector3();
  2992. var _edge2 = /*@__PURE__*/new Vector3();
  2993. var _normal = /*@__PURE__*/new Vector3();
  2994. var Ray = /*#__PURE__*/function () {
  2995. function Ray(origin, direction) {
  2996. this.origin = origin !== undefined ? origin : new Vector3();
  2997. this.direction = direction !== undefined ? direction : new Vector3(0, 0, -1);
  2998. }
  2999. var _proto = Ray.prototype;
  3000. _proto.set = function set(origin, direction) {
  3001. this.origin.copy(origin);
  3002. this.direction.copy(direction);
  3003. return this;
  3004. };
  3005. _proto.clone = function clone() {
  3006. return new this.constructor().copy(this);
  3007. };
  3008. _proto.copy = function copy(ray) {
  3009. this.origin.copy(ray.origin);
  3010. this.direction.copy(ray.direction);
  3011. return this;
  3012. };
  3013. _proto.at = function at(t, target) {
  3014. if (target === undefined) {
  3015. console.warn('THREE.Ray: .at() target is now required');
  3016. target = new Vector3();
  3017. }
  3018. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3019. };
  3020. _proto.lookAt = function lookAt(v) {
  3021. this.direction.copy(v).sub(this.origin).normalize();
  3022. return this;
  3023. };
  3024. _proto.recast = function recast(t) {
  3025. this.origin.copy(this.at(t, _vector$2));
  3026. return this;
  3027. };
  3028. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3029. if (target === undefined) {
  3030. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3031. target = new Vector3();
  3032. }
  3033. target.subVectors(point, this.origin);
  3034. var directionDistance = target.dot(this.direction);
  3035. if (directionDistance < 0) {
  3036. return target.copy(this.origin);
  3037. }
  3038. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3039. };
  3040. _proto.distanceToPoint = function distanceToPoint(point) {
  3041. return Math.sqrt(this.distanceSqToPoint(point));
  3042. };
  3043. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3044. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3045. if (directionDistance < 0) {
  3046. return this.origin.distanceToSquared(point);
  3047. }
  3048. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3049. return _vector$2.distanceToSquared(point);
  3050. };
  3051. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3052. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3053. // It returns the min distance between the ray and the segment
  3054. // defined by v0 and v1
  3055. // It can also set two optional targets :
  3056. // - The closest point on the ray
  3057. // - The closest point on the segment
  3058. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3059. _segDir.copy(v1).sub(v0).normalize();
  3060. _diff.copy(this.origin).sub(_segCenter);
  3061. var segExtent = v0.distanceTo(v1) * 0.5;
  3062. var a01 = -this.direction.dot(_segDir);
  3063. var b0 = _diff.dot(this.direction);
  3064. var b1 = -_diff.dot(_segDir);
  3065. var c = _diff.lengthSq();
  3066. var det = Math.abs(1 - a01 * a01);
  3067. var s0, s1, sqrDist, extDet;
  3068. if (det > 0) {
  3069. // The ray and segment are not parallel.
  3070. s0 = a01 * b1 - b0;
  3071. s1 = a01 * b0 - b1;
  3072. extDet = segExtent * det;
  3073. if (s0 >= 0) {
  3074. if (s1 >= -extDet) {
  3075. if (s1 <= extDet) {
  3076. // region 0
  3077. // Minimum at interior points of ray and segment.
  3078. var invDet = 1 / det;
  3079. s0 *= invDet;
  3080. s1 *= invDet;
  3081. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3082. } else {
  3083. // region 1
  3084. s1 = segExtent;
  3085. s0 = Math.max(0, -(a01 * s1 + b0));
  3086. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3087. }
  3088. } else {
  3089. // region 5
  3090. s1 = -segExtent;
  3091. s0 = Math.max(0, -(a01 * s1 + b0));
  3092. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3093. }
  3094. } else {
  3095. if (s1 <= -extDet) {
  3096. // region 4
  3097. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3098. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3099. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3100. } else if (s1 <= extDet) {
  3101. // region 3
  3102. s0 = 0;
  3103. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3104. sqrDist = s1 * (s1 + 2 * b1) + c;
  3105. } else {
  3106. // region 2
  3107. s0 = Math.max(0, -(a01 * segExtent + b0));
  3108. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3109. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3110. }
  3111. }
  3112. } else {
  3113. // Ray and segment are parallel.
  3114. s1 = a01 > 0 ? -segExtent : segExtent;
  3115. s0 = Math.max(0, -(a01 * s1 + b0));
  3116. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3117. }
  3118. if (optionalPointOnRay) {
  3119. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3120. }
  3121. if (optionalPointOnSegment) {
  3122. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3123. }
  3124. return sqrDist;
  3125. };
  3126. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3127. _vector$2.subVectors(sphere.center, this.origin);
  3128. var tca = _vector$2.dot(this.direction);
  3129. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3130. var radius2 = sphere.radius * sphere.radius;
  3131. if (d2 > radius2) return null;
  3132. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3133. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3134. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3135. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3136. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3137. // in order to always return an intersect point that is in front of the ray.
  3138. 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
  3139. return this.at(t0, target);
  3140. };
  3141. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3142. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3143. };
  3144. _proto.distanceToPlane = function distanceToPlane(plane) {
  3145. var denominator = plane.normal.dot(this.direction);
  3146. if (denominator === 0) {
  3147. // line is coplanar, return origin
  3148. if (plane.distanceToPoint(this.origin) === 0) {
  3149. return 0;
  3150. } // Null is preferable to undefined since undefined means.... it is undefined
  3151. return null;
  3152. }
  3153. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3154. return t >= 0 ? t : null;
  3155. };
  3156. _proto.intersectPlane = function intersectPlane(plane, target) {
  3157. var t = this.distanceToPlane(plane);
  3158. if (t === null) {
  3159. return null;
  3160. }
  3161. return this.at(t, target);
  3162. };
  3163. _proto.intersectsPlane = function intersectsPlane(plane) {
  3164. // check if the ray lies on the plane first
  3165. var distToPoint = plane.distanceToPoint(this.origin);
  3166. if (distToPoint === 0) {
  3167. return true;
  3168. }
  3169. var denominator = plane.normal.dot(this.direction);
  3170. if (denominator * distToPoint < 0) {
  3171. return true;
  3172. } // ray origin is behind the plane (and is pointing behind it)
  3173. return false;
  3174. };
  3175. _proto.intersectBox = function intersectBox(box, target) {
  3176. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3177. var invdirx = 1 / this.direction.x,
  3178. invdiry = 1 / this.direction.y,
  3179. invdirz = 1 / this.direction.z;
  3180. var origin = this.origin;
  3181. if (invdirx >= 0) {
  3182. tmin = (box.min.x - origin.x) * invdirx;
  3183. tmax = (box.max.x - origin.x) * invdirx;
  3184. } else {
  3185. tmin = (box.max.x - origin.x) * invdirx;
  3186. tmax = (box.min.x - origin.x) * invdirx;
  3187. }
  3188. if (invdiry >= 0) {
  3189. tymin = (box.min.y - origin.y) * invdiry;
  3190. tymax = (box.max.y - origin.y) * invdiry;
  3191. } else {
  3192. tymin = (box.max.y - origin.y) * invdiry;
  3193. tymax = (box.min.y - origin.y) * invdiry;
  3194. }
  3195. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  3196. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3197. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  3198. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  3199. if (invdirz >= 0) {
  3200. tzmin = (box.min.z - origin.z) * invdirz;
  3201. tzmax = (box.max.z - origin.z) * invdirz;
  3202. } else {
  3203. tzmin = (box.max.z - origin.z) * invdirz;
  3204. tzmax = (box.min.z - origin.z) * invdirz;
  3205. }
  3206. if (tmin > tzmax || tzmin > tmax) return null;
  3207. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  3208. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  3209. if (tmax < 0) return null;
  3210. return this.at(tmin >= 0 ? tmin : tmax, target);
  3211. };
  3212. _proto.intersectsBox = function intersectsBox(box) {
  3213. return this.intersectBox(box, _vector$2) !== null;
  3214. };
  3215. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  3216. // Compute the offset origin, edges, and normal.
  3217. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3218. _edge1.subVectors(b, a);
  3219. _edge2.subVectors(c, a);
  3220. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3221. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3222. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3223. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3224. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3225. var DdN = this.direction.dot(_normal);
  3226. var sign;
  3227. if (DdN > 0) {
  3228. if (backfaceCulling) return null;
  3229. sign = 1;
  3230. } else if (DdN < 0) {
  3231. sign = -1;
  3232. DdN = -DdN;
  3233. } else {
  3234. return null;
  3235. }
  3236. _diff.subVectors(this.origin, a);
  3237. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  3238. if (DdQxE2 < 0) {
  3239. return null;
  3240. }
  3241. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  3242. if (DdE1xQ < 0) {
  3243. return null;
  3244. } // b1+b2 > 1, no intersection
  3245. if (DdQxE2 + DdE1xQ > DdN) {
  3246. return null;
  3247. } // Line intersects triangle, check if ray does.
  3248. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  3249. if (QdN < 0) {
  3250. return null;
  3251. } // Ray intersects triangle.
  3252. return this.at(QdN / DdN, target);
  3253. };
  3254. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  3255. this.origin.applyMatrix4(matrix4);
  3256. this.direction.transformDirection(matrix4);
  3257. return this;
  3258. };
  3259. _proto.equals = function equals(ray) {
  3260. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  3261. };
  3262. return Ray;
  3263. }();
  3264. var Matrix4 = /*#__PURE__*/function () {
  3265. function Matrix4() {
  3266. Object.defineProperty(this, 'isMatrix4', {
  3267. value: true
  3268. });
  3269. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  3270. if (arguments.length > 0) {
  3271. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  3272. }
  3273. }
  3274. var _proto = Matrix4.prototype;
  3275. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  3276. var te = this.elements;
  3277. te[0] = n11;
  3278. te[4] = n12;
  3279. te[8] = n13;
  3280. te[12] = n14;
  3281. te[1] = n21;
  3282. te[5] = n22;
  3283. te[9] = n23;
  3284. te[13] = n24;
  3285. te[2] = n31;
  3286. te[6] = n32;
  3287. te[10] = n33;
  3288. te[14] = n34;
  3289. te[3] = n41;
  3290. te[7] = n42;
  3291. te[11] = n43;
  3292. te[15] = n44;
  3293. return this;
  3294. };
  3295. _proto.identity = function identity() {
  3296. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3297. return this;
  3298. };
  3299. _proto.clone = function clone() {
  3300. return new Matrix4().fromArray(this.elements);
  3301. };
  3302. _proto.copy = function copy(m) {
  3303. var te = this.elements;
  3304. var me = m.elements;
  3305. te[0] = me[0];
  3306. te[1] = me[1];
  3307. te[2] = me[2];
  3308. te[3] = me[3];
  3309. te[4] = me[4];
  3310. te[5] = me[5];
  3311. te[6] = me[6];
  3312. te[7] = me[7];
  3313. te[8] = me[8];
  3314. te[9] = me[9];
  3315. te[10] = me[10];
  3316. te[11] = me[11];
  3317. te[12] = me[12];
  3318. te[13] = me[13];
  3319. te[14] = me[14];
  3320. te[15] = me[15];
  3321. return this;
  3322. };
  3323. _proto.copyPosition = function copyPosition(m) {
  3324. var te = this.elements,
  3325. me = m.elements;
  3326. te[12] = me[12];
  3327. te[13] = me[13];
  3328. te[14] = me[14];
  3329. return this;
  3330. };
  3331. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  3332. xAxis.setFromMatrixColumn(this, 0);
  3333. yAxis.setFromMatrixColumn(this, 1);
  3334. zAxis.setFromMatrixColumn(this, 2);
  3335. return this;
  3336. };
  3337. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  3338. 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);
  3339. return this;
  3340. };
  3341. _proto.extractRotation = function extractRotation(m) {
  3342. // this method does not support reflection matrices
  3343. var te = this.elements;
  3344. var me = m.elements;
  3345. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  3346. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  3347. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  3348. te[0] = me[0] * scaleX;
  3349. te[1] = me[1] * scaleX;
  3350. te[2] = me[2] * scaleX;
  3351. te[3] = 0;
  3352. te[4] = me[4] * scaleY;
  3353. te[5] = me[5] * scaleY;
  3354. te[6] = me[6] * scaleY;
  3355. te[7] = 0;
  3356. te[8] = me[8] * scaleZ;
  3357. te[9] = me[9] * scaleZ;
  3358. te[10] = me[10] * scaleZ;
  3359. te[11] = 0;
  3360. te[12] = 0;
  3361. te[13] = 0;
  3362. te[14] = 0;
  3363. te[15] = 1;
  3364. return this;
  3365. };
  3366. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  3367. if (!(euler && euler.isEuler)) {
  3368. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  3369. }
  3370. var te = this.elements;
  3371. var x = euler.x,
  3372. y = euler.y,
  3373. z = euler.z;
  3374. var a = Math.cos(x),
  3375. b = Math.sin(x);
  3376. var c = Math.cos(y),
  3377. d = Math.sin(y);
  3378. var e = Math.cos(z),
  3379. f = Math.sin(z);
  3380. if (euler.order === 'XYZ') {
  3381. var ae = a * e,
  3382. af = a * f,
  3383. be = b * e,
  3384. bf = b * f;
  3385. te[0] = c * e;
  3386. te[4] = -c * f;
  3387. te[8] = d;
  3388. te[1] = af + be * d;
  3389. te[5] = ae - bf * d;
  3390. te[9] = -b * c;
  3391. te[2] = bf - ae * d;
  3392. te[6] = be + af * d;
  3393. te[10] = a * c;
  3394. } else if (euler.order === 'YXZ') {
  3395. var ce = c * e,
  3396. cf = c * f,
  3397. de = d * e,
  3398. df = d * f;
  3399. te[0] = ce + df * b;
  3400. te[4] = de * b - cf;
  3401. te[8] = a * d;
  3402. te[1] = a * f;
  3403. te[5] = a * e;
  3404. te[9] = -b;
  3405. te[2] = cf * b - de;
  3406. te[6] = df + ce * b;
  3407. te[10] = a * c;
  3408. } else if (euler.order === 'ZXY') {
  3409. var _ce = c * e,
  3410. _cf = c * f,
  3411. _de = d * e,
  3412. _df = d * f;
  3413. te[0] = _ce - _df * b;
  3414. te[4] = -a * f;
  3415. te[8] = _de + _cf * b;
  3416. te[1] = _cf + _de * b;
  3417. te[5] = a * e;
  3418. te[9] = _df - _ce * b;
  3419. te[2] = -a * d;
  3420. te[6] = b;
  3421. te[10] = a * c;
  3422. } else if (euler.order === 'ZYX') {
  3423. var _ae = a * e,
  3424. _af = a * f,
  3425. _be = b * e,
  3426. _bf = b * f;
  3427. te[0] = c * e;
  3428. te[4] = _be * d - _af;
  3429. te[8] = _ae * d + _bf;
  3430. te[1] = c * f;
  3431. te[5] = _bf * d + _ae;
  3432. te[9] = _af * d - _be;
  3433. te[2] = -d;
  3434. te[6] = b * c;
  3435. te[10] = a * c;
  3436. } else if (euler.order === 'YZX') {
  3437. var ac = a * c,
  3438. ad = a * d,
  3439. bc = b * c,
  3440. bd = b * d;
  3441. te[0] = c * e;
  3442. te[4] = bd - ac * f;
  3443. te[8] = bc * f + ad;
  3444. te[1] = f;
  3445. te[5] = a * e;
  3446. te[9] = -b * e;
  3447. te[2] = -d * e;
  3448. te[6] = ad * f + bc;
  3449. te[10] = ac - bd * f;
  3450. } else if (euler.order === 'XZY') {
  3451. var _ac = a * c,
  3452. _ad = a * d,
  3453. _bc = b * c,
  3454. _bd = b * d;
  3455. te[0] = c * e;
  3456. te[4] = -f;
  3457. te[8] = d * e;
  3458. te[1] = _ac * f + _bd;
  3459. te[5] = a * e;
  3460. te[9] = _ad * f - _bc;
  3461. te[2] = _bc * f - _ad;
  3462. te[6] = b * e;
  3463. te[10] = _bd * f + _ac;
  3464. } // bottom row
  3465. te[3] = 0;
  3466. te[7] = 0;
  3467. te[11] = 0; // last column
  3468. te[12] = 0;
  3469. te[13] = 0;
  3470. te[14] = 0;
  3471. te[15] = 1;
  3472. return this;
  3473. };
  3474. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  3475. return this.compose(_zero, q, _one);
  3476. };
  3477. _proto.lookAt = function lookAt(eye, target, up) {
  3478. var te = this.elements;
  3479. _z.subVectors(eye, target);
  3480. if (_z.lengthSq() === 0) {
  3481. // eye and target are in the same position
  3482. _z.z = 1;
  3483. }
  3484. _z.normalize();
  3485. _x.crossVectors(up, _z);
  3486. if (_x.lengthSq() === 0) {
  3487. // up and z are parallel
  3488. if (Math.abs(up.z) === 1) {
  3489. _z.x += 0.0001;
  3490. } else {
  3491. _z.z += 0.0001;
  3492. }
  3493. _z.normalize();
  3494. _x.crossVectors(up, _z);
  3495. }
  3496. _x.normalize();
  3497. _y.crossVectors(_z, _x);
  3498. te[0] = _x.x;
  3499. te[4] = _y.x;
  3500. te[8] = _z.x;
  3501. te[1] = _x.y;
  3502. te[5] = _y.y;
  3503. te[9] = _z.y;
  3504. te[2] = _x.z;
  3505. te[6] = _y.z;
  3506. te[10] = _z.z;
  3507. return this;
  3508. };
  3509. _proto.multiply = function multiply(m, n) {
  3510. if (n !== undefined) {
  3511. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  3512. return this.multiplyMatrices(m, n);
  3513. }
  3514. return this.multiplyMatrices(this, m);
  3515. };
  3516. _proto.premultiply = function premultiply(m) {
  3517. return this.multiplyMatrices(m, this);
  3518. };
  3519. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  3520. var ae = a.elements;
  3521. var be = b.elements;
  3522. var te = this.elements;
  3523. var a11 = ae[0],
  3524. a12 = ae[4],
  3525. a13 = ae[8],
  3526. a14 = ae[12];
  3527. var a21 = ae[1],
  3528. a22 = ae[5],
  3529. a23 = ae[9],
  3530. a24 = ae[13];
  3531. var a31 = ae[2],
  3532. a32 = ae[6],
  3533. a33 = ae[10],
  3534. a34 = ae[14];
  3535. var a41 = ae[3],
  3536. a42 = ae[7],
  3537. a43 = ae[11],
  3538. a44 = ae[15];
  3539. var b11 = be[0],
  3540. b12 = be[4],
  3541. b13 = be[8],
  3542. b14 = be[12];
  3543. var b21 = be[1],
  3544. b22 = be[5],
  3545. b23 = be[9],
  3546. b24 = be[13];
  3547. var b31 = be[2],
  3548. b32 = be[6],
  3549. b33 = be[10],
  3550. b34 = be[14];
  3551. var b41 = be[3],
  3552. b42 = be[7],
  3553. b43 = be[11],
  3554. b44 = be[15];
  3555. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3556. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3557. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3558. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3559. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3560. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3561. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3562. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3563. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3564. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3565. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3566. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3567. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3568. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3569. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3570. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3571. return this;
  3572. };
  3573. _proto.multiplyScalar = function multiplyScalar(s) {
  3574. var te = this.elements;
  3575. te[0] *= s;
  3576. te[4] *= s;
  3577. te[8] *= s;
  3578. te[12] *= s;
  3579. te[1] *= s;
  3580. te[5] *= s;
  3581. te[9] *= s;
  3582. te[13] *= s;
  3583. te[2] *= s;
  3584. te[6] *= s;
  3585. te[10] *= s;
  3586. te[14] *= s;
  3587. te[3] *= s;
  3588. te[7] *= s;
  3589. te[11] *= s;
  3590. te[15] *= s;
  3591. return this;
  3592. };
  3593. _proto.determinant = function determinant() {
  3594. var te = this.elements;
  3595. var n11 = te[0],
  3596. n12 = te[4],
  3597. n13 = te[8],
  3598. n14 = te[12];
  3599. var n21 = te[1],
  3600. n22 = te[5],
  3601. n23 = te[9],
  3602. n24 = te[13];
  3603. var n31 = te[2],
  3604. n32 = te[6],
  3605. n33 = te[10],
  3606. n34 = te[14];
  3607. var n41 = te[3],
  3608. n42 = te[7],
  3609. n43 = te[11],
  3610. n44 = te[15]; //TODO: make this more efficient
  3611. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3612. 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);
  3613. };
  3614. _proto.transpose = function transpose() {
  3615. var te = this.elements;
  3616. var tmp;
  3617. tmp = te[1];
  3618. te[1] = te[4];
  3619. te[4] = tmp;
  3620. tmp = te[2];
  3621. te[2] = te[8];
  3622. te[8] = tmp;
  3623. tmp = te[6];
  3624. te[6] = te[9];
  3625. te[9] = tmp;
  3626. tmp = te[3];
  3627. te[3] = te[12];
  3628. te[12] = tmp;
  3629. tmp = te[7];
  3630. te[7] = te[13];
  3631. te[13] = tmp;
  3632. tmp = te[11];
  3633. te[11] = te[14];
  3634. te[14] = tmp;
  3635. return this;
  3636. };
  3637. _proto.setPosition = function setPosition(x, y, z) {
  3638. var te = this.elements;
  3639. if (x.isVector3) {
  3640. te[12] = x.x;
  3641. te[13] = x.y;
  3642. te[14] = x.z;
  3643. } else {
  3644. te[12] = x;
  3645. te[13] = y;
  3646. te[14] = z;
  3647. }
  3648. return this;
  3649. };
  3650. _proto.getInverse = function getInverse(m, throwOnDegenerate) {
  3651. if (throwOnDegenerate !== undefined) {
  3652. console.warn("THREE.Matrix4: .getInverse() can no longer be configured to throw on degenerate.");
  3653. } // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3654. var te = this.elements,
  3655. me = m.elements,
  3656. n11 = me[0],
  3657. n21 = me[1],
  3658. n31 = me[2],
  3659. n41 = me[3],
  3660. n12 = me[4],
  3661. n22 = me[5],
  3662. n32 = me[6],
  3663. n42 = me[7],
  3664. n13 = me[8],
  3665. n23 = me[9],
  3666. n33 = me[10],
  3667. n43 = me[11],
  3668. n14 = me[12],
  3669. n24 = me[13],
  3670. n34 = me[14],
  3671. n44 = me[15],
  3672. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3673. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3674. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3675. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3676. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3677. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  3678. var detInv = 1 / det;
  3679. te[0] = t11 * detInv;
  3680. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  3681. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  3682. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  3683. te[4] = t12 * detInv;
  3684. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  3685. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  3686. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  3687. te[8] = t13 * detInv;
  3688. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  3689. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  3690. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  3691. te[12] = t14 * detInv;
  3692. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  3693. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  3694. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  3695. return this;
  3696. };
  3697. _proto.scale = function scale(v) {
  3698. var te = this.elements;
  3699. var x = v.x,
  3700. y = v.y,
  3701. z = v.z;
  3702. te[0] *= x;
  3703. te[4] *= y;
  3704. te[8] *= z;
  3705. te[1] *= x;
  3706. te[5] *= y;
  3707. te[9] *= z;
  3708. te[2] *= x;
  3709. te[6] *= y;
  3710. te[10] *= z;
  3711. te[3] *= x;
  3712. te[7] *= y;
  3713. te[11] *= z;
  3714. return this;
  3715. };
  3716. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  3717. var te = this.elements;
  3718. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  3719. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  3720. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  3721. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  3722. };
  3723. _proto.makeTranslation = function makeTranslation(x, y, z) {
  3724. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  3725. return this;
  3726. };
  3727. _proto.makeRotationX = function makeRotationX(theta) {
  3728. var c = Math.cos(theta),
  3729. s = Math.sin(theta);
  3730. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  3731. return this;
  3732. };
  3733. _proto.makeRotationY = function makeRotationY(theta) {
  3734. var c = Math.cos(theta),
  3735. s = Math.sin(theta);
  3736. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  3737. return this;
  3738. };
  3739. _proto.makeRotationZ = function makeRotationZ(theta) {
  3740. var c = Math.cos(theta),
  3741. s = Math.sin(theta);
  3742. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3743. return this;
  3744. };
  3745. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  3746. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3747. var c = Math.cos(angle);
  3748. var s = Math.sin(angle);
  3749. var t = 1 - c;
  3750. var x = axis.x,
  3751. y = axis.y,
  3752. z = axis.z;
  3753. var tx = t * x,
  3754. ty = t * y;
  3755. 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);
  3756. return this;
  3757. };
  3758. _proto.makeScale = function makeScale(x, y, z) {
  3759. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  3760. return this;
  3761. };
  3762. _proto.makeShear = function makeShear(x, y, z) {
  3763. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  3764. return this;
  3765. };
  3766. _proto.compose = function compose(position, quaternion, scale) {
  3767. var te = this.elements;
  3768. var x = quaternion._x,
  3769. y = quaternion._y,
  3770. z = quaternion._z,
  3771. w = quaternion._w;
  3772. var x2 = x + x,
  3773. y2 = y + y,
  3774. z2 = z + z;
  3775. var xx = x * x2,
  3776. xy = x * y2,
  3777. xz = x * z2;
  3778. var yy = y * y2,
  3779. yz = y * z2,
  3780. zz = z * z2;
  3781. var wx = w * x2,
  3782. wy = w * y2,
  3783. wz = w * z2;
  3784. var sx = scale.x,
  3785. sy = scale.y,
  3786. sz = scale.z;
  3787. te[0] = (1 - (yy + zz)) * sx;
  3788. te[1] = (xy + wz) * sx;
  3789. te[2] = (xz - wy) * sx;
  3790. te[3] = 0;
  3791. te[4] = (xy - wz) * sy;
  3792. te[5] = (1 - (xx + zz)) * sy;
  3793. te[6] = (yz + wx) * sy;
  3794. te[7] = 0;
  3795. te[8] = (xz + wy) * sz;
  3796. te[9] = (yz - wx) * sz;
  3797. te[10] = (1 - (xx + yy)) * sz;
  3798. te[11] = 0;
  3799. te[12] = position.x;
  3800. te[13] = position.y;
  3801. te[14] = position.z;
  3802. te[15] = 1;
  3803. return this;
  3804. };
  3805. _proto.decompose = function decompose(position, quaternion, scale) {
  3806. var te = this.elements;
  3807. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  3808. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  3809. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  3810. var det = this.determinant();
  3811. if (det < 0) sx = -sx;
  3812. position.x = te[12];
  3813. position.y = te[13];
  3814. position.z = te[14]; // scale the rotation part
  3815. _m1.copy(this);
  3816. var invSX = 1 / sx;
  3817. var invSY = 1 / sy;
  3818. var invSZ = 1 / sz;
  3819. _m1.elements[0] *= invSX;
  3820. _m1.elements[1] *= invSX;
  3821. _m1.elements[2] *= invSX;
  3822. _m1.elements[4] *= invSY;
  3823. _m1.elements[5] *= invSY;
  3824. _m1.elements[6] *= invSY;
  3825. _m1.elements[8] *= invSZ;
  3826. _m1.elements[9] *= invSZ;
  3827. _m1.elements[10] *= invSZ;
  3828. quaternion.setFromRotationMatrix(_m1);
  3829. scale.x = sx;
  3830. scale.y = sy;
  3831. scale.z = sz;
  3832. return this;
  3833. };
  3834. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  3835. if (far === undefined) {
  3836. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  3837. }
  3838. var te = this.elements;
  3839. var x = 2 * near / (right - left);
  3840. var y = 2 * near / (top - bottom);
  3841. var a = (right + left) / (right - left);
  3842. var b = (top + bottom) / (top - bottom);
  3843. var c = -(far + near) / (far - near);
  3844. var d = -2 * far * near / (far - near);
  3845. te[0] = x;
  3846. te[4] = 0;
  3847. te[8] = a;
  3848. te[12] = 0;
  3849. te[1] = 0;
  3850. te[5] = y;
  3851. te[9] = b;
  3852. te[13] = 0;
  3853. te[2] = 0;
  3854. te[6] = 0;
  3855. te[10] = c;
  3856. te[14] = d;
  3857. te[3] = 0;
  3858. te[7] = 0;
  3859. te[11] = -1;
  3860. te[15] = 0;
  3861. return this;
  3862. };
  3863. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  3864. var te = this.elements;
  3865. var w = 1.0 / (right - left);
  3866. var h = 1.0 / (top - bottom);
  3867. var p = 1.0 / (far - near);
  3868. var x = (right + left) * w;
  3869. var y = (top + bottom) * h;
  3870. var z = (far + near) * p;
  3871. te[0] = 2 * w;
  3872. te[4] = 0;
  3873. te[8] = 0;
  3874. te[12] = -x;
  3875. te[1] = 0;
  3876. te[5] = 2 * h;
  3877. te[9] = 0;
  3878. te[13] = -y;
  3879. te[2] = 0;
  3880. te[6] = 0;
  3881. te[10] = -2 * p;
  3882. te[14] = -z;
  3883. te[3] = 0;
  3884. te[7] = 0;
  3885. te[11] = 0;
  3886. te[15] = 1;
  3887. return this;
  3888. };
  3889. _proto.equals = function equals(matrix) {
  3890. var te = this.elements;
  3891. var me = matrix.elements;
  3892. for (var i = 0; i < 16; i++) {
  3893. if (te[i] !== me[i]) return false;
  3894. }
  3895. return true;
  3896. };
  3897. _proto.fromArray = function fromArray(array, offset) {
  3898. if (offset === undefined) offset = 0;
  3899. for (var i = 0; i < 16; i++) {
  3900. this.elements[i] = array[i + offset];
  3901. }
  3902. return this;
  3903. };
  3904. _proto.toArray = function toArray(array, offset) {
  3905. if (array === undefined) array = [];
  3906. if (offset === undefined) offset = 0;
  3907. var te = this.elements;
  3908. array[offset] = te[0];
  3909. array[offset + 1] = te[1];
  3910. array[offset + 2] = te[2];
  3911. array[offset + 3] = te[3];
  3912. array[offset + 4] = te[4];
  3913. array[offset + 5] = te[5];
  3914. array[offset + 6] = te[6];
  3915. array[offset + 7] = te[7];
  3916. array[offset + 8] = te[8];
  3917. array[offset + 9] = te[9];
  3918. array[offset + 10] = te[10];
  3919. array[offset + 11] = te[11];
  3920. array[offset + 12] = te[12];
  3921. array[offset + 13] = te[13];
  3922. array[offset + 14] = te[14];
  3923. array[offset + 15] = te[15];
  3924. return array;
  3925. };
  3926. return Matrix4;
  3927. }();
  3928. var _v1$1 = /*@__PURE__*/new Vector3();
  3929. var _m1 = /*@__PURE__*/new Matrix4();
  3930. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  3931. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  3932. var _x = /*@__PURE__*/new Vector3();
  3933. var _y = /*@__PURE__*/new Vector3();
  3934. var _z = /*@__PURE__*/new Vector3();
  3935. var Euler = /*#__PURE__*/function () {
  3936. function Euler(x, y, z, order) {
  3937. if (x === void 0) {
  3938. x = 0;
  3939. }
  3940. if (y === void 0) {
  3941. y = 0;
  3942. }
  3943. if (z === void 0) {
  3944. z = 0;
  3945. }
  3946. if (order === void 0) {
  3947. order = Euler.DefaultOrder;
  3948. }
  3949. Object.defineProperty(this, 'isEuler', {
  3950. value: true
  3951. });
  3952. this._x = x;
  3953. this._y = y;
  3954. this._z = z;
  3955. this._order = order;
  3956. }
  3957. var _proto = Euler.prototype;
  3958. _proto.set = function set(x, y, z, order) {
  3959. this._x = x;
  3960. this._y = y;
  3961. this._z = z;
  3962. this._order = order || this._order;
  3963. this._onChangeCallback();
  3964. return this;
  3965. };
  3966. _proto.clone = function clone() {
  3967. return new this.constructor(this._x, this._y, this._z, this._order);
  3968. };
  3969. _proto.copy = function copy(euler) {
  3970. this._x = euler._x;
  3971. this._y = euler._y;
  3972. this._z = euler._z;
  3973. this._order = euler._order;
  3974. this._onChangeCallback();
  3975. return this;
  3976. };
  3977. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  3978. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3979. var te = m.elements;
  3980. var m11 = te[0],
  3981. m12 = te[4],
  3982. m13 = te[8];
  3983. var m21 = te[1],
  3984. m22 = te[5],
  3985. m23 = te[9];
  3986. var m31 = te[2],
  3987. m32 = te[6],
  3988. m33 = te[10];
  3989. order = order || this._order;
  3990. switch (order) {
  3991. case 'XYZ':
  3992. this._y = Math.asin(clamp(m13, -1, 1));
  3993. if (Math.abs(m13) < 0.9999999) {
  3994. this._x = Math.atan2(-m23, m33);
  3995. this._z = Math.atan2(-m12, m11);
  3996. } else {
  3997. this._x = Math.atan2(m32, m22);
  3998. this._z = 0;
  3999. }
  4000. break;
  4001. case 'YXZ':
  4002. this._x = Math.asin(-clamp(m23, -1, 1));
  4003. if (Math.abs(m23) < 0.9999999) {
  4004. this._y = Math.atan2(m13, m33);
  4005. this._z = Math.atan2(m21, m22);
  4006. } else {
  4007. this._y = Math.atan2(-m31, m11);
  4008. this._z = 0;
  4009. }
  4010. break;
  4011. case 'ZXY':
  4012. this._x = Math.asin(clamp(m32, -1, 1));
  4013. if (Math.abs(m32) < 0.9999999) {
  4014. this._y = Math.atan2(-m31, m33);
  4015. this._z = Math.atan2(-m12, m22);
  4016. } else {
  4017. this._y = 0;
  4018. this._z = Math.atan2(m21, m11);
  4019. }
  4020. break;
  4021. case 'ZYX':
  4022. this._y = Math.asin(-clamp(m31, -1, 1));
  4023. if (Math.abs(m31) < 0.9999999) {
  4024. this._x = Math.atan2(m32, m33);
  4025. this._z = Math.atan2(m21, m11);
  4026. } else {
  4027. this._x = 0;
  4028. this._z = Math.atan2(-m12, m22);
  4029. }
  4030. break;
  4031. case 'YZX':
  4032. this._z = Math.asin(clamp(m21, -1, 1));
  4033. if (Math.abs(m21) < 0.9999999) {
  4034. this._x = Math.atan2(-m23, m22);
  4035. this._y = Math.atan2(-m31, m11);
  4036. } else {
  4037. this._x = 0;
  4038. this._y = Math.atan2(m13, m33);
  4039. }
  4040. break;
  4041. case 'XZY':
  4042. this._z = Math.asin(-clamp(m12, -1, 1));
  4043. if (Math.abs(m12) < 0.9999999) {
  4044. this._x = Math.atan2(m32, m22);
  4045. this._y = Math.atan2(m13, m11);
  4046. } else {
  4047. this._x = Math.atan2(-m23, m33);
  4048. this._y = 0;
  4049. }
  4050. break;
  4051. default:
  4052. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4053. }
  4054. this._order = order;
  4055. if (update !== false) this._onChangeCallback();
  4056. return this;
  4057. };
  4058. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4059. _matrix.makeRotationFromQuaternion(q);
  4060. return this.setFromRotationMatrix(_matrix, order, update);
  4061. };
  4062. _proto.setFromVector3 = function setFromVector3(v, order) {
  4063. return this.set(v.x, v.y, v.z, order || this._order);
  4064. };
  4065. _proto.reorder = function reorder(newOrder) {
  4066. // WARNING: this discards revolution information -bhouston
  4067. _quaternion$1.setFromEuler(this);
  4068. return this.setFromQuaternion(_quaternion$1, newOrder);
  4069. };
  4070. _proto.equals = function equals(euler) {
  4071. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4072. };
  4073. _proto.fromArray = function fromArray(array) {
  4074. this._x = array[0];
  4075. this._y = array[1];
  4076. this._z = array[2];
  4077. if (array[3] !== undefined) this._order = array[3];
  4078. this._onChangeCallback();
  4079. return this;
  4080. };
  4081. _proto.toArray = function toArray(array, offset) {
  4082. if (array === undefined) array = [];
  4083. if (offset === undefined) offset = 0;
  4084. array[offset] = this._x;
  4085. array[offset + 1] = this._y;
  4086. array[offset + 2] = this._z;
  4087. array[offset + 3] = this._order;
  4088. return array;
  4089. };
  4090. _proto.toVector3 = function toVector3(optionalResult) {
  4091. if (optionalResult) {
  4092. return optionalResult.set(this._x, this._y, this._z);
  4093. } else {
  4094. return new Vector3(this._x, this._y, this._z);
  4095. }
  4096. };
  4097. _proto._onChange = function _onChange(callback) {
  4098. this._onChangeCallback = callback;
  4099. return this;
  4100. };
  4101. _proto._onChangeCallback = function _onChangeCallback() {};
  4102. _createClass(Euler, [{
  4103. key: "x",
  4104. get: function get() {
  4105. return this._x;
  4106. },
  4107. set: function set(value) {
  4108. this._x = value;
  4109. this._onChangeCallback();
  4110. }
  4111. }, {
  4112. key: "y",
  4113. get: function get() {
  4114. return this._y;
  4115. },
  4116. set: function set(value) {
  4117. this._y = value;
  4118. this._onChangeCallback();
  4119. }
  4120. }, {
  4121. key: "z",
  4122. get: function get() {
  4123. return this._z;
  4124. },
  4125. set: function set(value) {
  4126. this._z = value;
  4127. this._onChangeCallback();
  4128. }
  4129. }, {
  4130. key: "order",
  4131. get: function get() {
  4132. return this._order;
  4133. },
  4134. set: function set(value) {
  4135. this._order = value;
  4136. this._onChangeCallback();
  4137. }
  4138. }]);
  4139. return Euler;
  4140. }();
  4141. Euler.DefaultOrder = 'XYZ';
  4142. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4143. var _matrix = /*@__PURE__*/new Matrix4();
  4144. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4145. var Layers = /*#__PURE__*/function () {
  4146. function Layers() {
  4147. this.mask = 1 | 0;
  4148. }
  4149. var _proto = Layers.prototype;
  4150. _proto.set = function set(channel) {
  4151. this.mask = 1 << channel | 0;
  4152. };
  4153. _proto.enable = function enable(channel) {
  4154. this.mask |= 1 << channel | 0;
  4155. };
  4156. _proto.enableAll = function enableAll() {
  4157. this.mask = 0xffffffff | 0;
  4158. };
  4159. _proto.toggle = function toggle(channel) {
  4160. this.mask ^= 1 << channel | 0;
  4161. };
  4162. _proto.disable = function disable(channel) {
  4163. this.mask &= ~(1 << channel | 0);
  4164. };
  4165. _proto.disableAll = function disableAll() {
  4166. this.mask = 0;
  4167. };
  4168. _proto.test = function test(layers) {
  4169. return (this.mask & layers.mask) !== 0;
  4170. };
  4171. return Layers;
  4172. }();
  4173. var _object3DId = 0;
  4174. var _v1$2 = new Vector3();
  4175. var _q1 = new Quaternion();
  4176. var _m1$1 = new Matrix4();
  4177. var _target = new Vector3();
  4178. var _position = new Vector3();
  4179. var _scale = new Vector3();
  4180. var _quaternion$2 = new Quaternion();
  4181. var _xAxis = new Vector3(1, 0, 0);
  4182. var _yAxis = new Vector3(0, 1, 0);
  4183. var _zAxis = new Vector3(0, 0, 1);
  4184. var _addedEvent = {
  4185. type: 'added'
  4186. };
  4187. var _removedEvent = {
  4188. type: 'removed'
  4189. };
  4190. function Object3D() {
  4191. Object.defineProperty(this, 'id', {
  4192. value: _object3DId++
  4193. });
  4194. this.uuid = MathUtils.generateUUID();
  4195. this.name = '';
  4196. this.type = 'Object3D';
  4197. this.parent = null;
  4198. this.children = [];
  4199. this.up = Object3D.DefaultUp.clone();
  4200. var position = new Vector3();
  4201. var rotation = new Euler();
  4202. var quaternion = new Quaternion();
  4203. var scale = new Vector3(1, 1, 1);
  4204. function onRotationChange() {
  4205. quaternion.setFromEuler(rotation, false);
  4206. }
  4207. function onQuaternionChange() {
  4208. rotation.setFromQuaternion(quaternion, undefined, false);
  4209. }
  4210. rotation._onChange(onRotationChange);
  4211. quaternion._onChange(onQuaternionChange);
  4212. Object.defineProperties(this, {
  4213. position: {
  4214. configurable: true,
  4215. enumerable: true,
  4216. value: position
  4217. },
  4218. rotation: {
  4219. configurable: true,
  4220. enumerable: true,
  4221. value: rotation
  4222. },
  4223. quaternion: {
  4224. configurable: true,
  4225. enumerable: true,
  4226. value: quaternion
  4227. },
  4228. scale: {
  4229. configurable: true,
  4230. enumerable: true,
  4231. value: scale
  4232. },
  4233. modelViewMatrix: {
  4234. value: new Matrix4()
  4235. },
  4236. normalMatrix: {
  4237. value: new Matrix3()
  4238. }
  4239. });
  4240. this.matrix = new Matrix4();
  4241. this.matrixWorld = new Matrix4();
  4242. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  4243. this.matrixWorldNeedsUpdate = false;
  4244. this.layers = new Layers();
  4245. this.visible = true;
  4246. this.castShadow = false;
  4247. this.receiveShadow = false;
  4248. this.frustumCulled = true;
  4249. this.renderOrder = 0;
  4250. this.userData = {};
  4251. }
  4252. Object3D.DefaultUp = new Vector3(0, 1, 0);
  4253. Object3D.DefaultMatrixAutoUpdate = true;
  4254. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  4255. constructor: Object3D,
  4256. isObject3D: true,
  4257. onBeforeRender: function onBeforeRender() {},
  4258. onAfterRender: function onAfterRender() {},
  4259. applyMatrix4: function applyMatrix4(matrix) {
  4260. if (this.matrixAutoUpdate) this.updateMatrix();
  4261. this.matrix.premultiply(matrix);
  4262. this.matrix.decompose(this.position, this.quaternion, this.scale);
  4263. },
  4264. applyQuaternion: function applyQuaternion(q) {
  4265. this.quaternion.premultiply(q);
  4266. return this;
  4267. },
  4268. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  4269. // assumes axis is normalized
  4270. this.quaternion.setFromAxisAngle(axis, angle);
  4271. },
  4272. setRotationFromEuler: function setRotationFromEuler(euler) {
  4273. this.quaternion.setFromEuler(euler, true);
  4274. },
  4275. setRotationFromMatrix: function setRotationFromMatrix(m) {
  4276. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4277. this.quaternion.setFromRotationMatrix(m);
  4278. },
  4279. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  4280. // assumes q is normalized
  4281. this.quaternion.copy(q);
  4282. },
  4283. rotateOnAxis: function rotateOnAxis(axis, angle) {
  4284. // rotate object on axis in object space
  4285. // axis is assumed to be normalized
  4286. _q1.setFromAxisAngle(axis, angle);
  4287. this.quaternion.multiply(_q1);
  4288. return this;
  4289. },
  4290. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  4291. // rotate object on axis in world space
  4292. // axis is assumed to be normalized
  4293. // method assumes no rotated parent
  4294. _q1.setFromAxisAngle(axis, angle);
  4295. this.quaternion.premultiply(_q1);
  4296. return this;
  4297. },
  4298. rotateX: function rotateX(angle) {
  4299. return this.rotateOnAxis(_xAxis, angle);
  4300. },
  4301. rotateY: function rotateY(angle) {
  4302. return this.rotateOnAxis(_yAxis, angle);
  4303. },
  4304. rotateZ: function rotateZ(angle) {
  4305. return this.rotateOnAxis(_zAxis, angle);
  4306. },
  4307. translateOnAxis: function translateOnAxis(axis, distance) {
  4308. // translate object by distance along axis in object space
  4309. // axis is assumed to be normalized
  4310. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  4311. this.position.add(_v1$2.multiplyScalar(distance));
  4312. return this;
  4313. },
  4314. translateX: function translateX(distance) {
  4315. return this.translateOnAxis(_xAxis, distance);
  4316. },
  4317. translateY: function translateY(distance) {
  4318. return this.translateOnAxis(_yAxis, distance);
  4319. },
  4320. translateZ: function translateZ(distance) {
  4321. return this.translateOnAxis(_zAxis, distance);
  4322. },
  4323. localToWorld: function localToWorld(vector) {
  4324. return vector.applyMatrix4(this.matrixWorld);
  4325. },
  4326. worldToLocal: function worldToLocal(vector) {
  4327. return vector.applyMatrix4(_m1$1.getInverse(this.matrixWorld));
  4328. },
  4329. lookAt: function lookAt(x, y, z) {
  4330. // This method does not support objects having non-uniformly-scaled parent(s)
  4331. if (x.isVector3) {
  4332. _target.copy(x);
  4333. } else {
  4334. _target.set(x, y, z);
  4335. }
  4336. var parent = this.parent;
  4337. this.updateWorldMatrix(true, false);
  4338. _position.setFromMatrixPosition(this.matrixWorld);
  4339. if (this.isCamera || this.isLight) {
  4340. _m1$1.lookAt(_position, _target, this.up);
  4341. } else {
  4342. _m1$1.lookAt(_target, _position, this.up);
  4343. }
  4344. this.quaternion.setFromRotationMatrix(_m1$1);
  4345. if (parent) {
  4346. _m1$1.extractRotation(parent.matrixWorld);
  4347. _q1.setFromRotationMatrix(_m1$1);
  4348. this.quaternion.premultiply(_q1.inverse());
  4349. }
  4350. },
  4351. add: function add(object) {
  4352. if (arguments.length > 1) {
  4353. for (var i = 0; i < arguments.length; i++) {
  4354. this.add(arguments[i]);
  4355. }
  4356. return this;
  4357. }
  4358. if (object === this) {
  4359. console.error("THREE.Object3D.add: object can't be added as a child of itself.", object);
  4360. return this;
  4361. }
  4362. if (object && object.isObject3D) {
  4363. if (object.parent !== null) {
  4364. object.parent.remove(object);
  4365. }
  4366. object.parent = this;
  4367. this.children.push(object);
  4368. object.dispatchEvent(_addedEvent);
  4369. } else {
  4370. console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.", object);
  4371. }
  4372. return this;
  4373. },
  4374. remove: function remove(object) {
  4375. if (arguments.length > 1) {
  4376. for (var i = 0; i < arguments.length; i++) {
  4377. this.remove(arguments[i]);
  4378. }
  4379. return this;
  4380. }
  4381. var index = this.children.indexOf(object);
  4382. if (index !== -1) {
  4383. object.parent = null;
  4384. this.children.splice(index, 1);
  4385. object.dispatchEvent(_removedEvent);
  4386. }
  4387. return this;
  4388. },
  4389. attach: function attach(object) {
  4390. // adds object as a child of this, while maintaining the object's world transform
  4391. this.updateWorldMatrix(true, false);
  4392. _m1$1.getInverse(this.matrixWorld);
  4393. if (object.parent !== null) {
  4394. object.parent.updateWorldMatrix(true, false);
  4395. _m1$1.multiply(object.parent.matrixWorld);
  4396. }
  4397. object.applyMatrix4(_m1$1);
  4398. object.updateWorldMatrix(false, false);
  4399. this.add(object);
  4400. return this;
  4401. },
  4402. getObjectById: function getObjectById(id) {
  4403. return this.getObjectByProperty('id', id);
  4404. },
  4405. getObjectByName: function getObjectByName(name) {
  4406. return this.getObjectByProperty('name', name);
  4407. },
  4408. getObjectByProperty: function getObjectByProperty(name, value) {
  4409. if (this[name] === value) return this;
  4410. for (var i = 0, l = this.children.length; i < l; i++) {
  4411. var child = this.children[i];
  4412. var object = child.getObjectByProperty(name, value);
  4413. if (object !== undefined) {
  4414. return object;
  4415. }
  4416. }
  4417. return undefined;
  4418. },
  4419. getWorldPosition: function getWorldPosition(target) {
  4420. if (target === undefined) {
  4421. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  4422. target = new Vector3();
  4423. }
  4424. this.updateWorldMatrix(true, false);
  4425. return target.setFromMatrixPosition(this.matrixWorld);
  4426. },
  4427. getWorldQuaternion: function getWorldQuaternion(target) {
  4428. if (target === undefined) {
  4429. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  4430. target = new Quaternion();
  4431. }
  4432. this.updateWorldMatrix(true, false);
  4433. this.matrixWorld.decompose(_position, target, _scale);
  4434. return target;
  4435. },
  4436. getWorldScale: function getWorldScale(target) {
  4437. if (target === undefined) {
  4438. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  4439. target = new Vector3();
  4440. }
  4441. this.updateWorldMatrix(true, false);
  4442. this.matrixWorld.decompose(_position, _quaternion$2, target);
  4443. return target;
  4444. },
  4445. getWorldDirection: function getWorldDirection(target) {
  4446. if (target === undefined) {
  4447. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  4448. target = new Vector3();
  4449. }
  4450. this.updateWorldMatrix(true, false);
  4451. var e = this.matrixWorld.elements;
  4452. return target.set(e[8], e[9], e[10]).normalize();
  4453. },
  4454. raycast: function raycast() {},
  4455. traverse: function traverse(callback) {
  4456. callback(this);
  4457. var children = this.children;
  4458. for (var i = 0, l = children.length; i < l; i++) {
  4459. children[i].traverse(callback);
  4460. }
  4461. },
  4462. traverseVisible: function traverseVisible(callback) {
  4463. if (this.visible === false) return;
  4464. callback(this);
  4465. var children = this.children;
  4466. for (var i = 0, l = children.length; i < l; i++) {
  4467. children[i].traverseVisible(callback);
  4468. }
  4469. },
  4470. traverseAncestors: function traverseAncestors(callback) {
  4471. var parent = this.parent;
  4472. if (parent !== null) {
  4473. callback(parent);
  4474. parent.traverseAncestors(callback);
  4475. }
  4476. },
  4477. updateMatrix: function updateMatrix() {
  4478. this.matrix.compose(this.position, this.quaternion, this.scale);
  4479. this.matrixWorldNeedsUpdate = true;
  4480. },
  4481. updateMatrixWorld: function updateMatrixWorld(force) {
  4482. if (this.matrixAutoUpdate) this.updateMatrix();
  4483. if (this.matrixWorldNeedsUpdate || force) {
  4484. if (this.parent === null) {
  4485. this.matrixWorld.copy(this.matrix);
  4486. } else {
  4487. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4488. }
  4489. this.matrixWorldNeedsUpdate = false;
  4490. force = true;
  4491. } // update children
  4492. var children = this.children;
  4493. for (var i = 0, l = children.length; i < l; i++) {
  4494. children[i].updateMatrixWorld(force);
  4495. }
  4496. },
  4497. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  4498. var parent = this.parent;
  4499. if (updateParents === true && parent !== null) {
  4500. parent.updateWorldMatrix(true, false);
  4501. }
  4502. if (this.matrixAutoUpdate) this.updateMatrix();
  4503. if (this.parent === null) {
  4504. this.matrixWorld.copy(this.matrix);
  4505. } else {
  4506. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4507. } // update children
  4508. if (updateChildren === true) {
  4509. var children = this.children;
  4510. for (var i = 0, l = children.length; i < l; i++) {
  4511. children[i].updateWorldMatrix(false, true);
  4512. }
  4513. }
  4514. },
  4515. toJSON: function toJSON(meta) {
  4516. // meta is a string when called from JSON.stringify
  4517. var isRootObject = meta === undefined || typeof meta === 'string';
  4518. var output = {}; // meta is a hash used to collect geometries, materials.
  4519. // not providing it implies that this is the root object
  4520. // being serialized.
  4521. if (isRootObject) {
  4522. // initialize meta obj
  4523. meta = {
  4524. geometries: {},
  4525. materials: {},
  4526. textures: {},
  4527. images: {},
  4528. shapes: {}
  4529. };
  4530. output.metadata = {
  4531. version: 4.5,
  4532. type: 'Object',
  4533. generator: 'Object3D.toJSON'
  4534. };
  4535. } // standard Object3D serialization
  4536. var object = {};
  4537. object.uuid = this.uuid;
  4538. object.type = this.type;
  4539. if (this.name !== '') object.name = this.name;
  4540. if (this.castShadow === true) object.castShadow = true;
  4541. if (this.receiveShadow === true) object.receiveShadow = true;
  4542. if (this.visible === false) object.visible = false;
  4543. if (this.frustumCulled === false) object.frustumCulled = false;
  4544. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  4545. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  4546. object.layers = this.layers.mask;
  4547. object.matrix = this.matrix.toArray();
  4548. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  4549. if (this.isInstancedMesh) {
  4550. object.type = 'InstancedMesh';
  4551. object.count = this.count;
  4552. object.instanceMatrix = this.instanceMatrix.toJSON();
  4553. } //
  4554. function serialize(library, element) {
  4555. if (library[element.uuid] === undefined) {
  4556. library[element.uuid] = element.toJSON(meta);
  4557. }
  4558. return element.uuid;
  4559. }
  4560. if (this.isMesh || this.isLine || this.isPoints) {
  4561. object.geometry = serialize(meta.geometries, this.geometry);
  4562. var parameters = this.geometry.parameters;
  4563. if (parameters !== undefined && parameters.shapes !== undefined) {
  4564. var shapes = parameters.shapes;
  4565. if (Array.isArray(shapes)) {
  4566. for (var i = 0, l = shapes.length; i < l; i++) {
  4567. var shape = shapes[i];
  4568. serialize(meta.shapes, shape);
  4569. }
  4570. } else {
  4571. serialize(meta.shapes, shapes);
  4572. }
  4573. }
  4574. }
  4575. if (this.material !== undefined) {
  4576. if (Array.isArray(this.material)) {
  4577. var uuids = [];
  4578. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  4579. uuids.push(serialize(meta.materials, this.material[_i]));
  4580. }
  4581. object.material = uuids;
  4582. } else {
  4583. object.material = serialize(meta.materials, this.material);
  4584. }
  4585. } //
  4586. if (this.children.length > 0) {
  4587. object.children = [];
  4588. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  4589. object.children.push(this.children[_i2].toJSON(meta).object);
  4590. }
  4591. }
  4592. if (isRootObject) {
  4593. var geometries = extractFromCache(meta.geometries);
  4594. var materials = extractFromCache(meta.materials);
  4595. var textures = extractFromCache(meta.textures);
  4596. var images = extractFromCache(meta.images);
  4597. var _shapes = extractFromCache(meta.shapes);
  4598. if (geometries.length > 0) output.geometries = geometries;
  4599. if (materials.length > 0) output.materials = materials;
  4600. if (textures.length > 0) output.textures = textures;
  4601. if (images.length > 0) output.images = images;
  4602. if (_shapes.length > 0) output.shapes = _shapes;
  4603. }
  4604. output.object = object;
  4605. return output; // extract data from the cache hash
  4606. // remove metadata on each item
  4607. // and return as array
  4608. function extractFromCache(cache) {
  4609. var values = [];
  4610. for (var key in cache) {
  4611. var data = cache[key];
  4612. delete data.metadata;
  4613. values.push(data);
  4614. }
  4615. return values;
  4616. }
  4617. },
  4618. clone: function clone(recursive) {
  4619. return new this.constructor().copy(this, recursive);
  4620. },
  4621. copy: function copy(source, recursive) {
  4622. if (recursive === undefined) recursive = true;
  4623. this.name = source.name;
  4624. this.up.copy(source.up);
  4625. this.position.copy(source.position);
  4626. this.rotation.order = source.rotation.order;
  4627. this.quaternion.copy(source.quaternion);
  4628. this.scale.copy(source.scale);
  4629. this.matrix.copy(source.matrix);
  4630. this.matrixWorld.copy(source.matrixWorld);
  4631. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4632. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4633. this.layers.mask = source.layers.mask;
  4634. this.visible = source.visible;
  4635. this.castShadow = source.castShadow;
  4636. this.receiveShadow = source.receiveShadow;
  4637. this.frustumCulled = source.frustumCulled;
  4638. this.renderOrder = source.renderOrder;
  4639. this.userData = JSON.parse(JSON.stringify(source.userData));
  4640. if (recursive === true) {
  4641. for (var i = 0; i < source.children.length; i++) {
  4642. var child = source.children[i];
  4643. this.add(child.clone());
  4644. }
  4645. }
  4646. return this;
  4647. }
  4648. });
  4649. var _vector1 = /*@__PURE__*/new Vector3();
  4650. var _vector2 = /*@__PURE__*/new Vector3();
  4651. var _normalMatrix = /*@__PURE__*/new Matrix3();
  4652. var Plane = /*#__PURE__*/function () {
  4653. function Plane(normal, constant) {
  4654. Object.defineProperty(this, 'isPlane', {
  4655. value: true
  4656. }); // normal is assumed to be normalized
  4657. this.normal = normal !== undefined ? normal : new Vector3(1, 0, 0);
  4658. this.constant = constant !== undefined ? constant : 0;
  4659. }
  4660. var _proto = Plane.prototype;
  4661. _proto.set = function set(normal, constant) {
  4662. this.normal.copy(normal);
  4663. this.constant = constant;
  4664. return this;
  4665. };
  4666. _proto.setComponents = function setComponents(x, y, z, w) {
  4667. this.normal.set(x, y, z);
  4668. this.constant = w;
  4669. return this;
  4670. };
  4671. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  4672. this.normal.copy(normal);
  4673. this.constant = -point.dot(this.normal);
  4674. return this;
  4675. };
  4676. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  4677. 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)?
  4678. this.setFromNormalAndCoplanarPoint(normal, a);
  4679. return this;
  4680. };
  4681. _proto.clone = function clone() {
  4682. return new this.constructor().copy(this);
  4683. };
  4684. _proto.copy = function copy(plane) {
  4685. this.normal.copy(plane.normal);
  4686. this.constant = plane.constant;
  4687. return this;
  4688. };
  4689. _proto.normalize = function normalize() {
  4690. // Note: will lead to a divide by zero if the plane is invalid.
  4691. var inverseNormalLength = 1.0 / this.normal.length();
  4692. this.normal.multiplyScalar(inverseNormalLength);
  4693. this.constant *= inverseNormalLength;
  4694. return this;
  4695. };
  4696. _proto.negate = function negate() {
  4697. this.constant *= -1;
  4698. this.normal.negate();
  4699. return this;
  4700. };
  4701. _proto.distanceToPoint = function distanceToPoint(point) {
  4702. return this.normal.dot(point) + this.constant;
  4703. };
  4704. _proto.distanceToSphere = function distanceToSphere(sphere) {
  4705. return this.distanceToPoint(sphere.center) - sphere.radius;
  4706. };
  4707. _proto.projectPoint = function projectPoint(point, target) {
  4708. if (target === undefined) {
  4709. console.warn('THREE.Plane: .projectPoint() target is now required');
  4710. target = new Vector3();
  4711. }
  4712. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  4713. };
  4714. _proto.intersectLine = function intersectLine(line, target) {
  4715. if (target === undefined) {
  4716. console.warn('THREE.Plane: .intersectLine() target is now required');
  4717. target = new Vector3();
  4718. }
  4719. var direction = line.delta(_vector1);
  4720. var denominator = this.normal.dot(direction);
  4721. if (denominator === 0) {
  4722. // line is coplanar, return origin
  4723. if (this.distanceToPoint(line.start) === 0) {
  4724. return target.copy(line.start);
  4725. } // Unsure if this is the correct method to handle this case.
  4726. return undefined;
  4727. }
  4728. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  4729. if (t < 0 || t > 1) {
  4730. return undefined;
  4731. }
  4732. return target.copy(direction).multiplyScalar(t).add(line.start);
  4733. };
  4734. _proto.intersectsLine = function intersectsLine(line) {
  4735. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4736. var startSign = this.distanceToPoint(line.start);
  4737. var endSign = this.distanceToPoint(line.end);
  4738. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  4739. };
  4740. _proto.intersectsBox = function intersectsBox(box) {
  4741. return box.intersectsPlane(this);
  4742. };
  4743. _proto.intersectsSphere = function intersectsSphere(sphere) {
  4744. return sphere.intersectsPlane(this);
  4745. };
  4746. _proto.coplanarPoint = function coplanarPoint(target) {
  4747. if (target === undefined) {
  4748. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  4749. target = new Vector3();
  4750. }
  4751. return target.copy(this.normal).multiplyScalar(-this.constant);
  4752. };
  4753. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  4754. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  4755. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  4756. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  4757. this.constant = -referencePoint.dot(normal);
  4758. return this;
  4759. };
  4760. _proto.translate = function translate(offset) {
  4761. this.constant -= offset.dot(this.normal);
  4762. return this;
  4763. };
  4764. _proto.equals = function equals(plane) {
  4765. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  4766. };
  4767. return Plane;
  4768. }();
  4769. var _v0$1 = /*@__PURE__*/new Vector3();
  4770. var _v1$3 = /*@__PURE__*/new Vector3();
  4771. var _v2$1 = /*@__PURE__*/new Vector3();
  4772. var _v3 = /*@__PURE__*/new Vector3();
  4773. var _vab = /*@__PURE__*/new Vector3();
  4774. var _vac = /*@__PURE__*/new Vector3();
  4775. var _vbc = /*@__PURE__*/new Vector3();
  4776. var _vap = /*@__PURE__*/new Vector3();
  4777. var _vbp = /*@__PURE__*/new Vector3();
  4778. var _vcp = /*@__PURE__*/new Vector3();
  4779. var Triangle = /*#__PURE__*/function () {
  4780. function Triangle(a, b, c) {
  4781. this.a = a !== undefined ? a : new Vector3();
  4782. this.b = b !== undefined ? b : new Vector3();
  4783. this.c = c !== undefined ? c : new Vector3();
  4784. }
  4785. Triangle.getNormal = function getNormal(a, b, c, target) {
  4786. if (target === undefined) {
  4787. console.warn('THREE.Triangle: .getNormal() target is now required');
  4788. target = new Vector3();
  4789. }
  4790. target.subVectors(c, b);
  4791. _v0$1.subVectors(a, b);
  4792. target.cross(_v0$1);
  4793. var targetLengthSq = target.lengthSq();
  4794. if (targetLengthSq > 0) {
  4795. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  4796. }
  4797. return target.set(0, 0, 0);
  4798. } // static/instance method to calculate barycentric coordinates
  4799. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4800. ;
  4801. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  4802. _v0$1.subVectors(c, a);
  4803. _v1$3.subVectors(b, a);
  4804. _v2$1.subVectors(point, a);
  4805. var dot00 = _v0$1.dot(_v0$1);
  4806. var dot01 = _v0$1.dot(_v1$3);
  4807. var dot02 = _v0$1.dot(_v2$1);
  4808. var dot11 = _v1$3.dot(_v1$3);
  4809. var dot12 = _v1$3.dot(_v2$1);
  4810. var denom = dot00 * dot11 - dot01 * dot01;
  4811. if (target === undefined) {
  4812. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  4813. target = new Vector3();
  4814. } // collinear or singular triangle
  4815. if (denom === 0) {
  4816. // arbitrary location outside of triangle?
  4817. // not sure if this is the best idea, maybe should be returning undefined
  4818. return target.set(-2, -1, -1);
  4819. }
  4820. var invDenom = 1 / denom;
  4821. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  4822. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  4823. return target.set(1 - u - v, v, u);
  4824. };
  4825. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  4826. this.getBarycoord(point, a, b, c, _v3);
  4827. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  4828. };
  4829. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  4830. this.getBarycoord(point, p1, p2, p3, _v3);
  4831. target.set(0, 0);
  4832. target.addScaledVector(uv1, _v3.x);
  4833. target.addScaledVector(uv2, _v3.y);
  4834. target.addScaledVector(uv3, _v3.z);
  4835. return target;
  4836. };
  4837. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  4838. _v0$1.subVectors(c, b);
  4839. _v1$3.subVectors(a, b); // strictly front facing
  4840. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  4841. };
  4842. var _proto = Triangle.prototype;
  4843. _proto.set = function set(a, b, c) {
  4844. this.a.copy(a);
  4845. this.b.copy(b);
  4846. this.c.copy(c);
  4847. return this;
  4848. };
  4849. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  4850. this.a.copy(points[i0]);
  4851. this.b.copy(points[i1]);
  4852. this.c.copy(points[i2]);
  4853. return this;
  4854. };
  4855. _proto.clone = function clone() {
  4856. return new this.constructor().copy(this);
  4857. };
  4858. _proto.copy = function copy(triangle) {
  4859. this.a.copy(triangle.a);
  4860. this.b.copy(triangle.b);
  4861. this.c.copy(triangle.c);
  4862. return this;
  4863. };
  4864. _proto.getArea = function getArea() {
  4865. _v0$1.subVectors(this.c, this.b);
  4866. _v1$3.subVectors(this.a, this.b);
  4867. return _v0$1.cross(_v1$3).length() * 0.5;
  4868. };
  4869. _proto.getMidpoint = function getMidpoint(target) {
  4870. if (target === undefined) {
  4871. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  4872. target = new Vector3();
  4873. }
  4874. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  4875. };
  4876. _proto.getNormal = function getNormal(target) {
  4877. return Triangle.getNormal(this.a, this.b, this.c, target);
  4878. };
  4879. _proto.getPlane = function getPlane(target) {
  4880. if (target === undefined) {
  4881. console.warn('THREE.Triangle: .getPlane() target is now required');
  4882. target = new Plane();
  4883. }
  4884. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  4885. };
  4886. _proto.getBarycoord = function getBarycoord(point, target) {
  4887. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  4888. };
  4889. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  4890. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  4891. };
  4892. _proto.containsPoint = function containsPoint(point) {
  4893. return Triangle.containsPoint(point, this.a, this.b, this.c);
  4894. };
  4895. _proto.isFrontFacing = function isFrontFacing(direction) {
  4896. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  4897. };
  4898. _proto.intersectsBox = function intersectsBox(box) {
  4899. return box.intersectsTriangle(this);
  4900. };
  4901. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  4902. if (target === undefined) {
  4903. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  4904. target = new Vector3();
  4905. }
  4906. var a = this.a,
  4907. b = this.b,
  4908. c = this.c;
  4909. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4910. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4911. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4912. // basically, we're distinguishing which of the voronoi regions of the triangle
  4913. // the point lies in with the minimum amount of redundant computation.
  4914. _vab.subVectors(b, a);
  4915. _vac.subVectors(c, a);
  4916. _vap.subVectors(p, a);
  4917. var d1 = _vab.dot(_vap);
  4918. var d2 = _vac.dot(_vap);
  4919. if (d1 <= 0 && d2 <= 0) {
  4920. // vertex region of A; barycentric coords (1, 0, 0)
  4921. return target.copy(a);
  4922. }
  4923. _vbp.subVectors(p, b);
  4924. var d3 = _vab.dot(_vbp);
  4925. var d4 = _vac.dot(_vbp);
  4926. if (d3 >= 0 && d4 <= d3) {
  4927. // vertex region of B; barycentric coords (0, 1, 0)
  4928. return target.copy(b);
  4929. }
  4930. var vc = d1 * d4 - d3 * d2;
  4931. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  4932. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  4933. return target.copy(a).addScaledVector(_vab, v);
  4934. }
  4935. _vcp.subVectors(p, c);
  4936. var d5 = _vab.dot(_vcp);
  4937. var d6 = _vac.dot(_vcp);
  4938. if (d6 >= 0 && d5 <= d6) {
  4939. // vertex region of C; barycentric coords (0, 0, 1)
  4940. return target.copy(c);
  4941. }
  4942. var vb = d5 * d2 - d1 * d6;
  4943. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  4944. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  4945. return target.copy(a).addScaledVector(_vac, w);
  4946. }
  4947. var va = d3 * d6 - d5 * d4;
  4948. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  4949. _vbc.subVectors(c, b);
  4950. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  4951. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  4952. } // face region
  4953. var denom = 1 / (va + vb + vc); // u = va * denom
  4954. v = vb * denom;
  4955. w = vc * denom;
  4956. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  4957. };
  4958. _proto.equals = function equals(triangle) {
  4959. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  4960. };
  4961. return Triangle;
  4962. }();
  4963. var _colorKeywords = {
  4964. 'aliceblue': 0xF0F8FF,
  4965. 'antiquewhite': 0xFAEBD7,
  4966. 'aqua': 0x00FFFF,
  4967. 'aquamarine': 0x7FFFD4,
  4968. 'azure': 0xF0FFFF,
  4969. 'beige': 0xF5F5DC,
  4970. 'bisque': 0xFFE4C4,
  4971. 'black': 0x000000,
  4972. 'blanchedalmond': 0xFFEBCD,
  4973. 'blue': 0x0000FF,
  4974. 'blueviolet': 0x8A2BE2,
  4975. 'brown': 0xA52A2A,
  4976. 'burlywood': 0xDEB887,
  4977. 'cadetblue': 0x5F9EA0,
  4978. 'chartreuse': 0x7FFF00,
  4979. 'chocolate': 0xD2691E,
  4980. 'coral': 0xFF7F50,
  4981. 'cornflowerblue': 0x6495ED,
  4982. 'cornsilk': 0xFFF8DC,
  4983. 'crimson': 0xDC143C,
  4984. 'cyan': 0x00FFFF,
  4985. 'darkblue': 0x00008B,
  4986. 'darkcyan': 0x008B8B,
  4987. 'darkgoldenrod': 0xB8860B,
  4988. 'darkgray': 0xA9A9A9,
  4989. 'darkgreen': 0x006400,
  4990. 'darkgrey': 0xA9A9A9,
  4991. 'darkkhaki': 0xBDB76B,
  4992. 'darkmagenta': 0x8B008B,
  4993. 'darkolivegreen': 0x556B2F,
  4994. 'darkorange': 0xFF8C00,
  4995. 'darkorchid': 0x9932CC,
  4996. 'darkred': 0x8B0000,
  4997. 'darksalmon': 0xE9967A,
  4998. 'darkseagreen': 0x8FBC8F,
  4999. 'darkslateblue': 0x483D8B,
  5000. 'darkslategray': 0x2F4F4F,
  5001. 'darkslategrey': 0x2F4F4F,
  5002. 'darkturquoise': 0x00CED1,
  5003. 'darkviolet': 0x9400D3,
  5004. 'deeppink': 0xFF1493,
  5005. 'deepskyblue': 0x00BFFF,
  5006. 'dimgray': 0x696969,
  5007. 'dimgrey': 0x696969,
  5008. 'dodgerblue': 0x1E90FF,
  5009. 'firebrick': 0xB22222,
  5010. 'floralwhite': 0xFFFAF0,
  5011. 'forestgreen': 0x228B22,
  5012. 'fuchsia': 0xFF00FF,
  5013. 'gainsboro': 0xDCDCDC,
  5014. 'ghostwhite': 0xF8F8FF,
  5015. 'gold': 0xFFD700,
  5016. 'goldenrod': 0xDAA520,
  5017. 'gray': 0x808080,
  5018. 'green': 0x008000,
  5019. 'greenyellow': 0xADFF2F,
  5020. 'grey': 0x808080,
  5021. 'honeydew': 0xF0FFF0,
  5022. 'hotpink': 0xFF69B4,
  5023. 'indianred': 0xCD5C5C,
  5024. 'indigo': 0x4B0082,
  5025. 'ivory': 0xFFFFF0,
  5026. 'khaki': 0xF0E68C,
  5027. 'lavender': 0xE6E6FA,
  5028. 'lavenderblush': 0xFFF0F5,
  5029. 'lawngreen': 0x7CFC00,
  5030. 'lemonchiffon': 0xFFFACD,
  5031. 'lightblue': 0xADD8E6,
  5032. 'lightcoral': 0xF08080,
  5033. 'lightcyan': 0xE0FFFF,
  5034. 'lightgoldenrodyellow': 0xFAFAD2,
  5035. 'lightgray': 0xD3D3D3,
  5036. 'lightgreen': 0x90EE90,
  5037. 'lightgrey': 0xD3D3D3,
  5038. 'lightpink': 0xFFB6C1,
  5039. 'lightsalmon': 0xFFA07A,
  5040. 'lightseagreen': 0x20B2AA,
  5041. 'lightskyblue': 0x87CEFA,
  5042. 'lightslategray': 0x778899,
  5043. 'lightslategrey': 0x778899,
  5044. 'lightsteelblue': 0xB0C4DE,
  5045. 'lightyellow': 0xFFFFE0,
  5046. 'lime': 0x00FF00,
  5047. 'limegreen': 0x32CD32,
  5048. 'linen': 0xFAF0E6,
  5049. 'magenta': 0xFF00FF,
  5050. 'maroon': 0x800000,
  5051. 'mediumaquamarine': 0x66CDAA,
  5052. 'mediumblue': 0x0000CD,
  5053. 'mediumorchid': 0xBA55D3,
  5054. 'mediumpurple': 0x9370DB,
  5055. 'mediumseagreen': 0x3CB371,
  5056. 'mediumslateblue': 0x7B68EE,
  5057. 'mediumspringgreen': 0x00FA9A,
  5058. 'mediumturquoise': 0x48D1CC,
  5059. 'mediumvioletred': 0xC71585,
  5060. 'midnightblue': 0x191970,
  5061. 'mintcream': 0xF5FFFA,
  5062. 'mistyrose': 0xFFE4E1,
  5063. 'moccasin': 0xFFE4B5,
  5064. 'navajowhite': 0xFFDEAD,
  5065. 'navy': 0x000080,
  5066. 'oldlace': 0xFDF5E6,
  5067. 'olive': 0x808000,
  5068. 'olivedrab': 0x6B8E23,
  5069. 'orange': 0xFFA500,
  5070. 'orangered': 0xFF4500,
  5071. 'orchid': 0xDA70D6,
  5072. 'palegoldenrod': 0xEEE8AA,
  5073. 'palegreen': 0x98FB98,
  5074. 'paleturquoise': 0xAFEEEE,
  5075. 'palevioletred': 0xDB7093,
  5076. 'papayawhip': 0xFFEFD5,
  5077. 'peachpuff': 0xFFDAB9,
  5078. 'peru': 0xCD853F,
  5079. 'pink': 0xFFC0CB,
  5080. 'plum': 0xDDA0DD,
  5081. 'powderblue': 0xB0E0E6,
  5082. 'purple': 0x800080,
  5083. 'rebeccapurple': 0x663399,
  5084. 'red': 0xFF0000,
  5085. 'rosybrown': 0xBC8F8F,
  5086. 'royalblue': 0x4169E1,
  5087. 'saddlebrown': 0x8B4513,
  5088. 'salmon': 0xFA8072,
  5089. 'sandybrown': 0xF4A460,
  5090. 'seagreen': 0x2E8B57,
  5091. 'seashell': 0xFFF5EE,
  5092. 'sienna': 0xA0522D,
  5093. 'silver': 0xC0C0C0,
  5094. 'skyblue': 0x87CEEB,
  5095. 'slateblue': 0x6A5ACD,
  5096. 'slategray': 0x708090,
  5097. 'slategrey': 0x708090,
  5098. 'snow': 0xFFFAFA,
  5099. 'springgreen': 0x00FF7F,
  5100. 'steelblue': 0x4682B4,
  5101. 'tan': 0xD2B48C,
  5102. 'teal': 0x008080,
  5103. 'thistle': 0xD8BFD8,
  5104. 'tomato': 0xFF6347,
  5105. 'turquoise': 0x40E0D0,
  5106. 'violet': 0xEE82EE,
  5107. 'wheat': 0xF5DEB3,
  5108. 'white': 0xFFFFFF,
  5109. 'whitesmoke': 0xF5F5F5,
  5110. 'yellow': 0xFFFF00,
  5111. 'yellowgreen': 0x9ACD32
  5112. };
  5113. var _hslA = {
  5114. h: 0,
  5115. s: 0,
  5116. l: 0
  5117. };
  5118. var _hslB = {
  5119. h: 0,
  5120. s: 0,
  5121. l: 0
  5122. };
  5123. function hue2rgb(p, q, t) {
  5124. if (t < 0) t += 1;
  5125. if (t > 1) t -= 1;
  5126. if (t < 1 / 6) return p + (q - p) * 6 * t;
  5127. if (t < 1 / 2) return q;
  5128. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  5129. return p;
  5130. }
  5131. function SRGBToLinear(c) {
  5132. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  5133. }
  5134. function LinearToSRGB(c) {
  5135. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  5136. }
  5137. var Color = /*#__PURE__*/function () {
  5138. function Color(r, g, b) {
  5139. Object.defineProperty(this, 'isColor', {
  5140. value: true
  5141. });
  5142. if (g === undefined && b === undefined) {
  5143. // r is THREE.Color, hex or string
  5144. return this.set(r);
  5145. }
  5146. return this.setRGB(r, g, b);
  5147. }
  5148. var _proto = Color.prototype;
  5149. _proto.set = function set(value) {
  5150. if (value && value.isColor) {
  5151. this.copy(value);
  5152. } else if (typeof value === 'number') {
  5153. this.setHex(value);
  5154. } else if (typeof value === 'string') {
  5155. this.setStyle(value);
  5156. }
  5157. return this;
  5158. };
  5159. _proto.setScalar = function setScalar(scalar) {
  5160. this.r = scalar;
  5161. this.g = scalar;
  5162. this.b = scalar;
  5163. return this;
  5164. };
  5165. _proto.setHex = function setHex(hex) {
  5166. hex = Math.floor(hex);
  5167. this.r = (hex >> 16 & 255) / 255;
  5168. this.g = (hex >> 8 & 255) / 255;
  5169. this.b = (hex & 255) / 255;
  5170. return this;
  5171. };
  5172. _proto.setRGB = function setRGB(r, g, b) {
  5173. this.r = r;
  5174. this.g = g;
  5175. this.b = b;
  5176. return this;
  5177. };
  5178. _proto.setHSL = function setHSL(h, s, l) {
  5179. // h,s,l ranges are in 0.0 - 1.0
  5180. h = MathUtils.euclideanModulo(h, 1);
  5181. s = MathUtils.clamp(s, 0, 1);
  5182. l = MathUtils.clamp(l, 0, 1);
  5183. if (s === 0) {
  5184. this.r = this.g = this.b = l;
  5185. } else {
  5186. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  5187. var q = 2 * l - p;
  5188. this.r = hue2rgb(q, p, h + 1 / 3);
  5189. this.g = hue2rgb(q, p, h);
  5190. this.b = hue2rgb(q, p, h - 1 / 3);
  5191. }
  5192. return this;
  5193. };
  5194. _proto.setStyle = function setStyle(style) {
  5195. function handleAlpha(string) {
  5196. if (string === undefined) return;
  5197. if (parseFloat(string) < 1) {
  5198. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  5199. }
  5200. }
  5201. var m;
  5202. if (m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(style)) {
  5203. // rgb / hsl
  5204. var color;
  5205. var name = m[1];
  5206. var components = m[2];
  5207. switch (name) {
  5208. case 'rgb':
  5209. case 'rgba':
  5210. if (color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5211. // rgb(255,0,0) rgba(255,0,0,0.5)
  5212. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  5213. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  5214. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  5215. handleAlpha(color[5]);
  5216. return this;
  5217. }
  5218. if (color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5219. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5220. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  5221. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  5222. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  5223. handleAlpha(color[5]);
  5224. return this;
  5225. }
  5226. break;
  5227. case 'hsl':
  5228. case 'hsla':
  5229. if (color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5230. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  5231. var h = parseFloat(color[1]) / 360;
  5232. var s = parseInt(color[2], 10) / 100;
  5233. var l = parseInt(color[3], 10) / 100;
  5234. handleAlpha(color[5]);
  5235. return this.setHSL(h, s, l);
  5236. }
  5237. break;
  5238. }
  5239. } else if (m = /^\#([A-Fa-f0-9]+)$/.exec(style)) {
  5240. // hex color
  5241. var hex = m[1];
  5242. var size = hex.length;
  5243. if (size === 3) {
  5244. // #ff0
  5245. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  5246. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  5247. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  5248. return this;
  5249. } else if (size === 6) {
  5250. // #ff0000
  5251. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  5252. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  5253. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  5254. return this;
  5255. }
  5256. }
  5257. if (style && style.length > 0) {
  5258. return this.setColorName(style);
  5259. }
  5260. return this;
  5261. };
  5262. _proto.setColorName = function setColorName(style) {
  5263. // color keywords
  5264. var hex = _colorKeywords[style];
  5265. if (hex !== undefined) {
  5266. // red
  5267. this.setHex(hex);
  5268. } else {
  5269. // unknown color
  5270. console.warn('THREE.Color: Unknown color ' + style);
  5271. }
  5272. return this;
  5273. };
  5274. _proto.clone = function clone() {
  5275. return new this.constructor(this.r, this.g, this.b);
  5276. };
  5277. _proto.copy = function copy(color) {
  5278. this.r = color.r;
  5279. this.g = color.g;
  5280. this.b = color.b;
  5281. return this;
  5282. };
  5283. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  5284. if (gammaFactor === undefined) gammaFactor = 2.0;
  5285. this.r = Math.pow(color.r, gammaFactor);
  5286. this.g = Math.pow(color.g, gammaFactor);
  5287. this.b = Math.pow(color.b, gammaFactor);
  5288. return this;
  5289. };
  5290. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  5291. if (gammaFactor === undefined) gammaFactor = 2.0;
  5292. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  5293. this.r = Math.pow(color.r, safeInverse);
  5294. this.g = Math.pow(color.g, safeInverse);
  5295. this.b = Math.pow(color.b, safeInverse);
  5296. return this;
  5297. };
  5298. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  5299. this.copyGammaToLinear(this, gammaFactor);
  5300. return this;
  5301. };
  5302. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  5303. this.copyLinearToGamma(this, gammaFactor);
  5304. return this;
  5305. };
  5306. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  5307. this.r = SRGBToLinear(color.r);
  5308. this.g = SRGBToLinear(color.g);
  5309. this.b = SRGBToLinear(color.b);
  5310. return this;
  5311. };
  5312. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  5313. this.r = LinearToSRGB(color.r);
  5314. this.g = LinearToSRGB(color.g);
  5315. this.b = LinearToSRGB(color.b);
  5316. return this;
  5317. };
  5318. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  5319. this.copySRGBToLinear(this);
  5320. return this;
  5321. };
  5322. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  5323. this.copyLinearToSRGB(this);
  5324. return this;
  5325. };
  5326. _proto.getHex = function getHex() {
  5327. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  5328. };
  5329. _proto.getHexString = function getHexString() {
  5330. return ('000000' + this.getHex().toString(16)).slice(-6);
  5331. };
  5332. _proto.getHSL = function getHSL(target) {
  5333. // h,s,l ranges are in 0.0 - 1.0
  5334. if (target === undefined) {
  5335. console.warn('THREE.Color: .getHSL() target is now required');
  5336. target = {
  5337. h: 0,
  5338. s: 0,
  5339. l: 0
  5340. };
  5341. }
  5342. var r = this.r,
  5343. g = this.g,
  5344. b = this.b;
  5345. var max = Math.max(r, g, b);
  5346. var min = Math.min(r, g, b);
  5347. var hue, saturation;
  5348. var lightness = (min + max) / 2.0;
  5349. if (min === max) {
  5350. hue = 0;
  5351. saturation = 0;
  5352. } else {
  5353. var delta = max - min;
  5354. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  5355. switch (max) {
  5356. case r:
  5357. hue = (g - b) / delta + (g < b ? 6 : 0);
  5358. break;
  5359. case g:
  5360. hue = (b - r) / delta + 2;
  5361. break;
  5362. case b:
  5363. hue = (r - g) / delta + 4;
  5364. break;
  5365. }
  5366. hue /= 6;
  5367. }
  5368. target.h = hue;
  5369. target.s = saturation;
  5370. target.l = lightness;
  5371. return target;
  5372. };
  5373. _proto.getStyle = function getStyle() {
  5374. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  5375. };
  5376. _proto.offsetHSL = function offsetHSL(h, s, l) {
  5377. this.getHSL(_hslA);
  5378. _hslA.h += h;
  5379. _hslA.s += s;
  5380. _hslA.l += l;
  5381. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  5382. return this;
  5383. };
  5384. _proto.add = function add(color) {
  5385. this.r += color.r;
  5386. this.g += color.g;
  5387. this.b += color.b;
  5388. return this;
  5389. };
  5390. _proto.addColors = function addColors(color1, color2) {
  5391. this.r = color1.r + color2.r;
  5392. this.g = color1.g + color2.g;
  5393. this.b = color1.b + color2.b;
  5394. return this;
  5395. };
  5396. _proto.addScalar = function addScalar(s) {
  5397. this.r += s;
  5398. this.g += s;
  5399. this.b += s;
  5400. return this;
  5401. };
  5402. _proto.sub = function sub(color) {
  5403. this.r = Math.max(0, this.r - color.r);
  5404. this.g = Math.max(0, this.g - color.g);
  5405. this.b = Math.max(0, this.b - color.b);
  5406. return this;
  5407. };
  5408. _proto.multiply = function multiply(color) {
  5409. this.r *= color.r;
  5410. this.g *= color.g;
  5411. this.b *= color.b;
  5412. return this;
  5413. };
  5414. _proto.multiplyScalar = function multiplyScalar(s) {
  5415. this.r *= s;
  5416. this.g *= s;
  5417. this.b *= s;
  5418. return this;
  5419. };
  5420. _proto.lerp = function lerp(color, alpha) {
  5421. this.r += (color.r - this.r) * alpha;
  5422. this.g += (color.g - this.g) * alpha;
  5423. this.b += (color.b - this.b) * alpha;
  5424. return this;
  5425. };
  5426. _proto.lerpHSL = function lerpHSL(color, alpha) {
  5427. this.getHSL(_hslA);
  5428. color.getHSL(_hslB);
  5429. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  5430. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  5431. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  5432. this.setHSL(h, s, l);
  5433. return this;
  5434. };
  5435. _proto.equals = function equals(c) {
  5436. return c.r === this.r && c.g === this.g && c.b === this.b;
  5437. };
  5438. _proto.fromArray = function fromArray(array, offset) {
  5439. if (offset === undefined) offset = 0;
  5440. this.r = array[offset];
  5441. this.g = array[offset + 1];
  5442. this.b = array[offset + 2];
  5443. return this;
  5444. };
  5445. _proto.toArray = function toArray(array, offset) {
  5446. if (array === undefined) array = [];
  5447. if (offset === undefined) offset = 0;
  5448. array[offset] = this.r;
  5449. array[offset + 1] = this.g;
  5450. array[offset + 2] = this.b;
  5451. return array;
  5452. };
  5453. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  5454. this.r = attribute.getX(index);
  5455. this.g = attribute.getY(index);
  5456. this.b = attribute.getZ(index);
  5457. if (attribute.normalized === true) {
  5458. // assuming Uint8Array
  5459. this.r /= 255;
  5460. this.g /= 255;
  5461. this.b /= 255;
  5462. }
  5463. return this;
  5464. };
  5465. _proto.toJSON = function toJSON() {
  5466. return this.getHex();
  5467. };
  5468. return Color;
  5469. }();
  5470. Color.NAMES = _colorKeywords;
  5471. Color.prototype.r = 1;
  5472. Color.prototype.g = 1;
  5473. Color.prototype.b = 1;
  5474. var Face3 = /*#__PURE__*/function () {
  5475. function Face3(a, b, c, normal, color, materialIndex) {
  5476. this.a = a;
  5477. this.b = b;
  5478. this.c = c;
  5479. this.normal = normal && normal.isVector3 ? normal : new Vector3();
  5480. this.vertexNormals = Array.isArray(normal) ? normal : [];
  5481. this.color = color && color.isColor ? color : new Color();
  5482. this.vertexColors = Array.isArray(color) ? color : [];
  5483. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5484. }
  5485. var _proto = Face3.prototype;
  5486. _proto.clone = function clone() {
  5487. return new this.constructor().copy(this);
  5488. };
  5489. _proto.copy = function copy(source) {
  5490. this.a = source.a;
  5491. this.b = source.b;
  5492. this.c = source.c;
  5493. this.normal.copy(source.normal);
  5494. this.color.copy(source.color);
  5495. this.materialIndex = source.materialIndex;
  5496. for (var i = 0, il = source.vertexNormals.length; i < il; i++) {
  5497. this.vertexNormals[i] = source.vertexNormals[i].clone();
  5498. }
  5499. for (var _i = 0, _il = source.vertexColors.length; _i < _il; _i++) {
  5500. this.vertexColors[_i] = source.vertexColors[_i].clone();
  5501. }
  5502. return this;
  5503. };
  5504. return Face3;
  5505. }();
  5506. var materialId = 0;
  5507. function Material() {
  5508. Object.defineProperty(this, 'id', {
  5509. value: materialId++
  5510. });
  5511. this.uuid = MathUtils.generateUUID();
  5512. this.name = '';
  5513. this.type = 'Material';
  5514. this.fog = true;
  5515. this.blending = NormalBlending;
  5516. this.side = FrontSide;
  5517. this.flatShading = false;
  5518. this.vertexColors = false;
  5519. this.opacity = 1;
  5520. this.transparent = false;
  5521. this.blendSrc = SrcAlphaFactor;
  5522. this.blendDst = OneMinusSrcAlphaFactor;
  5523. this.blendEquation = AddEquation;
  5524. this.blendSrcAlpha = null;
  5525. this.blendDstAlpha = null;
  5526. this.blendEquationAlpha = null;
  5527. this.depthFunc = LessEqualDepth;
  5528. this.depthTest = true;
  5529. this.depthWrite = true;
  5530. this.stencilWriteMask = 0xff;
  5531. this.stencilFunc = AlwaysStencilFunc;
  5532. this.stencilRef = 0;
  5533. this.stencilFuncMask = 0xff;
  5534. this.stencilFail = KeepStencilOp;
  5535. this.stencilZFail = KeepStencilOp;
  5536. this.stencilZPass = KeepStencilOp;
  5537. this.stencilWrite = false;
  5538. this.clippingPlanes = null;
  5539. this.clipIntersection = false;
  5540. this.clipShadows = false;
  5541. this.shadowSide = null;
  5542. this.colorWrite = true;
  5543. this.precision = null; // override the renderer's default precision for this material
  5544. this.polygonOffset = false;
  5545. this.polygonOffsetFactor = 0;
  5546. this.polygonOffsetUnits = 0;
  5547. this.dithering = false;
  5548. this.alphaTest = 0;
  5549. this.premultipliedAlpha = false;
  5550. this.visible = true;
  5551. this.toneMapped = true;
  5552. this.userData = {};
  5553. this.version = 0;
  5554. }
  5555. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5556. constructor: Material,
  5557. isMaterial: true,
  5558. onBeforeCompile: function onBeforeCompile()
  5559. /* shaderobject, renderer */
  5560. {},
  5561. customProgramCacheKey: function customProgramCacheKey() {
  5562. return this.onBeforeCompile.toString();
  5563. },
  5564. setValues: function setValues(values) {
  5565. if (values === undefined) return;
  5566. for (var key in values) {
  5567. var newValue = values[key];
  5568. if (newValue === undefined) {
  5569. console.warn("THREE.Material: '" + key + "' parameter is undefined.");
  5570. continue;
  5571. } // for backward compatability if shading is set in the constructor
  5572. if (key === 'shading') {
  5573. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  5574. this.flatShading = newValue === FlatShading ? true : false;
  5575. continue;
  5576. }
  5577. var currentValue = this[key];
  5578. if (currentValue === undefined) {
  5579. console.warn("THREE." + this.type + ": '" + key + "' is not a property of this material.");
  5580. continue;
  5581. }
  5582. if (currentValue && currentValue.isColor) {
  5583. currentValue.set(newValue);
  5584. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  5585. currentValue.copy(newValue);
  5586. } else {
  5587. this[key] = newValue;
  5588. }
  5589. }
  5590. },
  5591. toJSON: function toJSON(meta) {
  5592. var isRoot = meta === undefined || typeof meta === 'string';
  5593. if (isRoot) {
  5594. meta = {
  5595. textures: {},
  5596. images: {}
  5597. };
  5598. }
  5599. var data = {
  5600. metadata: {
  5601. version: 4.5,
  5602. type: 'Material',
  5603. generator: 'Material.toJSON'
  5604. }
  5605. }; // standard Material serialization
  5606. data.uuid = this.uuid;
  5607. data.type = this.type;
  5608. if (this.name !== '') data.name = this.name;
  5609. if (this.color && this.color.isColor) data.color = this.color.getHex();
  5610. if (this.roughness !== undefined) data.roughness = this.roughness;
  5611. if (this.metalness !== undefined) data.metalness = this.metalness;
  5612. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  5613. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  5614. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  5615. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  5616. if (this.shininess !== undefined) data.shininess = this.shininess;
  5617. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  5618. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  5619. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  5620. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  5621. }
  5622. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  5623. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  5624. }
  5625. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  5626. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  5627. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5628. }
  5629. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  5630. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  5631. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  5632. if (this.lightMap && this.lightMap.isTexture) data.lightMap = this.lightMap.toJSON(meta).uuid;
  5633. if (this.aoMap && this.aoMap.isTexture) {
  5634. data.aoMap = this.aoMap.toJSON(meta).uuid;
  5635. data.aoMapIntensity = this.aoMapIntensity;
  5636. }
  5637. if (this.bumpMap && this.bumpMap.isTexture) {
  5638. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  5639. data.bumpScale = this.bumpScale;
  5640. }
  5641. if (this.normalMap && this.normalMap.isTexture) {
  5642. data.normalMap = this.normalMap.toJSON(meta).uuid;
  5643. data.normalMapType = this.normalMapType;
  5644. data.normalScale = this.normalScale.toArray();
  5645. }
  5646. if (this.displacementMap && this.displacementMap.isTexture) {
  5647. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  5648. data.displacementScale = this.displacementScale;
  5649. data.displacementBias = this.displacementBias;
  5650. }
  5651. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  5652. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  5653. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  5654. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  5655. if (this.envMap && this.envMap.isTexture) {
  5656. data.envMap = this.envMap.toJSON(meta).uuid;
  5657. data.reflectivity = this.reflectivity; // Scale behind envMap
  5658. data.refractionRatio = this.refractionRatio;
  5659. if (this.combine !== undefined) data.combine = this.combine;
  5660. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  5661. }
  5662. if (this.gradientMap && this.gradientMap.isTexture) {
  5663. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  5664. }
  5665. if (this.size !== undefined) data.size = this.size;
  5666. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  5667. if (this.blending !== NormalBlending) data.blending = this.blending;
  5668. if (this.flatShading === true) data.flatShading = this.flatShading;
  5669. if (this.side !== FrontSide) data.side = this.side;
  5670. if (this.vertexColors) data.vertexColors = true;
  5671. if (this.opacity < 1) data.opacity = this.opacity;
  5672. if (this.transparent === true) data.transparent = this.transparent;
  5673. data.depthFunc = this.depthFunc;
  5674. data.depthTest = this.depthTest;
  5675. data.depthWrite = this.depthWrite;
  5676. data.stencilWrite = this.stencilWrite;
  5677. data.stencilWriteMask = this.stencilWriteMask;
  5678. data.stencilFunc = this.stencilFunc;
  5679. data.stencilRef = this.stencilRef;
  5680. data.stencilFuncMask = this.stencilFuncMask;
  5681. data.stencilFail = this.stencilFail;
  5682. data.stencilZFail = this.stencilZFail;
  5683. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  5684. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  5685. if (this.polygonOffset === true) data.polygonOffset = true;
  5686. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5687. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5688. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  5689. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  5690. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  5691. if (this.scale !== undefined) data.scale = this.scale;
  5692. if (this.dithering === true) data.dithering = true;
  5693. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  5694. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  5695. if (this.wireframe === true) data.wireframe = this.wireframe;
  5696. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  5697. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  5698. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  5699. if (this.morphTargets === true) data.morphTargets = true;
  5700. if (this.morphNormals === true) data.morphNormals = true;
  5701. if (this.skinning === true) data.skinning = true;
  5702. if (this.visible === false) data.visible = false;
  5703. if (this.toneMapped === false) data.toneMapped = false;
  5704. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  5705. function extractFromCache(cache) {
  5706. var values = [];
  5707. for (var key in cache) {
  5708. var _data = cache[key];
  5709. delete _data.metadata;
  5710. values.push(_data);
  5711. }
  5712. return values;
  5713. }
  5714. if (isRoot) {
  5715. var textures = extractFromCache(meta.textures);
  5716. var images = extractFromCache(meta.images);
  5717. if (textures.length > 0) data.textures = textures;
  5718. if (images.length > 0) data.images = images;
  5719. }
  5720. return data;
  5721. },
  5722. clone: function clone() {
  5723. return new this.constructor().copy(this);
  5724. },
  5725. copy: function copy(source) {
  5726. this.name = source.name;
  5727. this.fog = source.fog;
  5728. this.blending = source.blending;
  5729. this.side = source.side;
  5730. this.flatShading = source.flatShading;
  5731. this.vertexColors = source.vertexColors;
  5732. this.opacity = source.opacity;
  5733. this.transparent = source.transparent;
  5734. this.blendSrc = source.blendSrc;
  5735. this.blendDst = source.blendDst;
  5736. this.blendEquation = source.blendEquation;
  5737. this.blendSrcAlpha = source.blendSrcAlpha;
  5738. this.blendDstAlpha = source.blendDstAlpha;
  5739. this.blendEquationAlpha = source.blendEquationAlpha;
  5740. this.depthFunc = source.depthFunc;
  5741. this.depthTest = source.depthTest;
  5742. this.depthWrite = source.depthWrite;
  5743. this.stencilWriteMask = source.stencilWriteMask;
  5744. this.stencilFunc = source.stencilFunc;
  5745. this.stencilRef = source.stencilRef;
  5746. this.stencilFuncMask = source.stencilFuncMask;
  5747. this.stencilFail = source.stencilFail;
  5748. this.stencilZFail = source.stencilZFail;
  5749. this.stencilZPass = source.stencilZPass;
  5750. this.stencilWrite = source.stencilWrite;
  5751. var srcPlanes = source.clippingPlanes;
  5752. var dstPlanes = null;
  5753. if (srcPlanes !== null) {
  5754. var n = srcPlanes.length;
  5755. dstPlanes = new Array(n);
  5756. for (var i = 0; i !== n; ++i) {
  5757. dstPlanes[i] = srcPlanes[i].clone();
  5758. }
  5759. }
  5760. this.clippingPlanes = dstPlanes;
  5761. this.clipIntersection = source.clipIntersection;
  5762. this.clipShadows = source.clipShadows;
  5763. this.shadowSide = source.shadowSide;
  5764. this.colorWrite = source.colorWrite;
  5765. this.precision = source.precision;
  5766. this.polygonOffset = source.polygonOffset;
  5767. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5768. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5769. this.dithering = source.dithering;
  5770. this.alphaTest = source.alphaTest;
  5771. this.premultipliedAlpha = source.premultipliedAlpha;
  5772. this.visible = source.visible;
  5773. this.toneMapped = source.toneMapped;
  5774. this.userData = JSON.parse(JSON.stringify(source.userData));
  5775. return this;
  5776. },
  5777. dispose: function dispose() {
  5778. this.dispatchEvent({
  5779. type: 'dispose'
  5780. });
  5781. }
  5782. });
  5783. Object.defineProperty(Material.prototype, 'needsUpdate', {
  5784. set: function set(value) {
  5785. if (value === true) this.version++;
  5786. }
  5787. });
  5788. /**
  5789. * parameters = {
  5790. * color: <hex>,
  5791. * opacity: <float>,
  5792. * map: new THREE.Texture( <Image> ),
  5793. *
  5794. * lightMap: new THREE.Texture( <Image> ),
  5795. * lightMapIntensity: <float>
  5796. *
  5797. * aoMap: new THREE.Texture( <Image> ),
  5798. * aoMapIntensity: <float>
  5799. *
  5800. * specularMap: new THREE.Texture( <Image> ),
  5801. *
  5802. * alphaMap: new THREE.Texture( <Image> ),
  5803. *
  5804. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5805. * combine: THREE.Multiply,
  5806. * reflectivity: <float>,
  5807. * refractionRatio: <float>,
  5808. *
  5809. * depthTest: <bool>,
  5810. * depthWrite: <bool>,
  5811. *
  5812. * wireframe: <boolean>,
  5813. * wireframeLinewidth: <float>,
  5814. *
  5815. * skinning: <bool>,
  5816. * morphTargets: <bool>
  5817. * }
  5818. */
  5819. function MeshBasicMaterial(parameters) {
  5820. Material.call(this);
  5821. this.type = 'MeshBasicMaterial';
  5822. this.color = new Color(0xffffff); // emissive
  5823. this.map = null;
  5824. this.lightMap = null;
  5825. this.lightMapIntensity = 1.0;
  5826. this.aoMap = null;
  5827. this.aoMapIntensity = 1.0;
  5828. this.specularMap = null;
  5829. this.alphaMap = null;
  5830. this.envMap = null;
  5831. this.combine = MultiplyOperation;
  5832. this.reflectivity = 1;
  5833. this.refractionRatio = 0.98;
  5834. this.wireframe = false;
  5835. this.wireframeLinewidth = 1;
  5836. this.wireframeLinecap = 'round';
  5837. this.wireframeLinejoin = 'round';
  5838. this.skinning = false;
  5839. this.morphTargets = false;
  5840. this.setValues(parameters);
  5841. }
  5842. MeshBasicMaterial.prototype = Object.create(Material.prototype);
  5843. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5844. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5845. MeshBasicMaterial.prototype.copy = function (source) {
  5846. Material.prototype.copy.call(this, source);
  5847. this.color.copy(source.color);
  5848. this.map = source.map;
  5849. this.lightMap = source.lightMap;
  5850. this.lightMapIntensity = source.lightMapIntensity;
  5851. this.aoMap = source.aoMap;
  5852. this.aoMapIntensity = source.aoMapIntensity;
  5853. this.specularMap = source.specularMap;
  5854. this.alphaMap = source.alphaMap;
  5855. this.envMap = source.envMap;
  5856. this.combine = source.combine;
  5857. this.reflectivity = source.reflectivity;
  5858. this.refractionRatio = source.refractionRatio;
  5859. this.wireframe = source.wireframe;
  5860. this.wireframeLinewidth = source.wireframeLinewidth;
  5861. this.wireframeLinecap = source.wireframeLinecap;
  5862. this.wireframeLinejoin = source.wireframeLinejoin;
  5863. this.skinning = source.skinning;
  5864. this.morphTargets = source.morphTargets;
  5865. return this;
  5866. };
  5867. var _vector$3 = new Vector3();
  5868. var _vector2$1 = new Vector2();
  5869. function BufferAttribute(array, itemSize, normalized) {
  5870. if (Array.isArray(array)) {
  5871. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  5872. }
  5873. this.name = '';
  5874. this.array = array;
  5875. this.itemSize = itemSize;
  5876. this.count = array !== undefined ? array.length / itemSize : 0;
  5877. this.normalized = normalized === true;
  5878. this.usage = StaticDrawUsage;
  5879. this.updateRange = {
  5880. offset: 0,
  5881. count: -1
  5882. };
  5883. this.version = 0;
  5884. }
  5885. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  5886. set: function set(value) {
  5887. if (value === true) this.version++;
  5888. }
  5889. });
  5890. Object.assign(BufferAttribute.prototype, {
  5891. isBufferAttribute: true,
  5892. onUploadCallback: function onUploadCallback() {},
  5893. setUsage: function setUsage(value) {
  5894. this.usage = value;
  5895. return this;
  5896. },
  5897. copy: function copy(source) {
  5898. this.name = source.name;
  5899. this.array = new source.array.constructor(source.array);
  5900. this.itemSize = source.itemSize;
  5901. this.count = source.count;
  5902. this.normalized = source.normalized;
  5903. this.usage = source.usage;
  5904. return this;
  5905. },
  5906. copyAt: function copyAt(index1, attribute, index2) {
  5907. index1 *= this.itemSize;
  5908. index2 *= attribute.itemSize;
  5909. for (var i = 0, l = this.itemSize; i < l; i++) {
  5910. this.array[index1 + i] = attribute.array[index2 + i];
  5911. }
  5912. return this;
  5913. },
  5914. copyArray: function copyArray(array) {
  5915. this.array.set(array);
  5916. return this;
  5917. },
  5918. copyColorsArray: function copyColorsArray(colors) {
  5919. var array = this.array;
  5920. var offset = 0;
  5921. for (var i = 0, l = colors.length; i < l; i++) {
  5922. var color = colors[i];
  5923. if (color === undefined) {
  5924. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  5925. color = new Color();
  5926. }
  5927. array[offset++] = color.r;
  5928. array[offset++] = color.g;
  5929. array[offset++] = color.b;
  5930. }
  5931. return this;
  5932. },
  5933. copyVector2sArray: function copyVector2sArray(vectors) {
  5934. var array = this.array;
  5935. var offset = 0;
  5936. for (var i = 0, l = vectors.length; i < l; i++) {
  5937. var vector = vectors[i];
  5938. if (vector === undefined) {
  5939. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  5940. vector = new Vector2();
  5941. }
  5942. array[offset++] = vector.x;
  5943. array[offset++] = vector.y;
  5944. }
  5945. return this;
  5946. },
  5947. copyVector3sArray: function copyVector3sArray(vectors) {
  5948. var array = this.array;
  5949. var offset = 0;
  5950. for (var i = 0, l = vectors.length; i < l; i++) {
  5951. var vector = vectors[i];
  5952. if (vector === undefined) {
  5953. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  5954. vector = new Vector3();
  5955. }
  5956. array[offset++] = vector.x;
  5957. array[offset++] = vector.y;
  5958. array[offset++] = vector.z;
  5959. }
  5960. return this;
  5961. },
  5962. copyVector4sArray: function copyVector4sArray(vectors) {
  5963. var array = this.array;
  5964. var offset = 0;
  5965. for (var i = 0, l = vectors.length; i < l; i++) {
  5966. var vector = vectors[i];
  5967. if (vector === undefined) {
  5968. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  5969. vector = new Vector4();
  5970. }
  5971. array[offset++] = vector.x;
  5972. array[offset++] = vector.y;
  5973. array[offset++] = vector.z;
  5974. array[offset++] = vector.w;
  5975. }
  5976. return this;
  5977. },
  5978. applyMatrix3: function applyMatrix3(m) {
  5979. if (this.itemSize === 2) {
  5980. for (var i = 0, l = this.count; i < l; i++) {
  5981. _vector2$1.fromBufferAttribute(this, i);
  5982. _vector2$1.applyMatrix3(m);
  5983. this.setXY(i, _vector2$1.x, _vector2$1.y);
  5984. }
  5985. } else if (this.itemSize === 3) {
  5986. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  5987. _vector$3.fromBufferAttribute(this, _i);
  5988. _vector$3.applyMatrix3(m);
  5989. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  5990. }
  5991. }
  5992. return this;
  5993. },
  5994. applyMatrix4: function applyMatrix4(m) {
  5995. for (var i = 0, l = this.count; i < l; i++) {
  5996. _vector$3.x = this.getX(i);
  5997. _vector$3.y = this.getY(i);
  5998. _vector$3.z = this.getZ(i);
  5999. _vector$3.applyMatrix4(m);
  6000. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6001. }
  6002. return this;
  6003. },
  6004. applyNormalMatrix: function applyNormalMatrix(m) {
  6005. for (var i = 0, l = this.count; i < l; i++) {
  6006. _vector$3.x = this.getX(i);
  6007. _vector$3.y = this.getY(i);
  6008. _vector$3.z = this.getZ(i);
  6009. _vector$3.applyNormalMatrix(m);
  6010. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6011. }
  6012. return this;
  6013. },
  6014. transformDirection: function transformDirection(m) {
  6015. for (var i = 0, l = this.count; i < l; i++) {
  6016. _vector$3.x = this.getX(i);
  6017. _vector$3.y = this.getY(i);
  6018. _vector$3.z = this.getZ(i);
  6019. _vector$3.transformDirection(m);
  6020. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6021. }
  6022. return this;
  6023. },
  6024. set: function set(value, offset) {
  6025. if (offset === undefined) offset = 0;
  6026. this.array.set(value, offset);
  6027. return this;
  6028. },
  6029. getX: function getX(index) {
  6030. return this.array[index * this.itemSize];
  6031. },
  6032. setX: function setX(index, x) {
  6033. this.array[index * this.itemSize] = x;
  6034. return this;
  6035. },
  6036. getY: function getY(index) {
  6037. return this.array[index * this.itemSize + 1];
  6038. },
  6039. setY: function setY(index, y) {
  6040. this.array[index * this.itemSize + 1] = y;
  6041. return this;
  6042. },
  6043. getZ: function getZ(index) {
  6044. return this.array[index * this.itemSize + 2];
  6045. },
  6046. setZ: function setZ(index, z) {
  6047. this.array[index * this.itemSize + 2] = z;
  6048. return this;
  6049. },
  6050. getW: function getW(index) {
  6051. return this.array[index * this.itemSize + 3];
  6052. },
  6053. setW: function setW(index, w) {
  6054. this.array[index * this.itemSize + 3] = w;
  6055. return this;
  6056. },
  6057. setXY: function setXY(index, x, y) {
  6058. index *= this.itemSize;
  6059. this.array[index + 0] = x;
  6060. this.array[index + 1] = y;
  6061. return this;
  6062. },
  6063. setXYZ: function setXYZ(index, x, y, z) {
  6064. index *= this.itemSize;
  6065. this.array[index + 0] = x;
  6066. this.array[index + 1] = y;
  6067. this.array[index + 2] = z;
  6068. return this;
  6069. },
  6070. setXYZW: function setXYZW(index, x, y, z, w) {
  6071. index *= this.itemSize;
  6072. this.array[index + 0] = x;
  6073. this.array[index + 1] = y;
  6074. this.array[index + 2] = z;
  6075. this.array[index + 3] = w;
  6076. return this;
  6077. },
  6078. onUpload: function onUpload(callback) {
  6079. this.onUploadCallback = callback;
  6080. return this;
  6081. },
  6082. clone: function clone() {
  6083. return new this.constructor(this.array, this.itemSize).copy(this);
  6084. },
  6085. toJSON: function toJSON() {
  6086. return {
  6087. itemSize: this.itemSize,
  6088. type: this.array.constructor.name,
  6089. array: Array.prototype.slice.call(this.array),
  6090. normalized: this.normalized
  6091. };
  6092. }
  6093. }); //
  6094. function Int8BufferAttribute(array, itemSize, normalized) {
  6095. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6096. }
  6097. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6098. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6099. function Uint8BufferAttribute(array, itemSize, normalized) {
  6100. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6101. }
  6102. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6103. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6104. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6105. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6106. }
  6107. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6108. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6109. function Int16BufferAttribute(array, itemSize, normalized) {
  6110. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6111. }
  6112. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6113. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6114. function Uint16BufferAttribute(array, itemSize, normalized) {
  6115. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6116. }
  6117. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6118. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6119. function Int32BufferAttribute(array, itemSize, normalized) {
  6120. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6121. }
  6122. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6123. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6124. function Uint32BufferAttribute(array, itemSize, normalized) {
  6125. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6126. }
  6127. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6128. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6129. function Float32BufferAttribute(array, itemSize, normalized) {
  6130. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6131. }
  6132. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6133. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6134. function Float64BufferAttribute(array, itemSize, normalized) {
  6135. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6136. }
  6137. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6138. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  6139. var DirectGeometry = /*#__PURE__*/function () {
  6140. function DirectGeometry() {
  6141. this.vertices = [];
  6142. this.normals = [];
  6143. this.colors = [];
  6144. this.uvs = [];
  6145. this.uvs2 = [];
  6146. this.groups = [];
  6147. this.morphTargets = {};
  6148. this.skinWeights = [];
  6149. this.skinIndices = []; // this.lineDistances = [];
  6150. this.boundingBox = null;
  6151. this.boundingSphere = null; // update flags
  6152. this.verticesNeedUpdate = false;
  6153. this.normalsNeedUpdate = false;
  6154. this.colorsNeedUpdate = false;
  6155. this.uvsNeedUpdate = false;
  6156. this.groupsNeedUpdate = false;
  6157. }
  6158. var _proto = DirectGeometry.prototype;
  6159. _proto.computeGroups = function computeGroups(geometry) {
  6160. var groups = [];
  6161. var group, i;
  6162. var materialIndex = undefined;
  6163. var faces = geometry.faces;
  6164. for (i = 0; i < faces.length; i++) {
  6165. var face = faces[i]; // materials
  6166. if (face.materialIndex !== materialIndex) {
  6167. materialIndex = face.materialIndex;
  6168. if (group !== undefined) {
  6169. group.count = i * 3 - group.start;
  6170. groups.push(group);
  6171. }
  6172. group = {
  6173. start: i * 3,
  6174. materialIndex: materialIndex
  6175. };
  6176. }
  6177. }
  6178. if (group !== undefined) {
  6179. group.count = i * 3 - group.start;
  6180. groups.push(group);
  6181. }
  6182. this.groups = groups;
  6183. };
  6184. _proto.fromGeometry = function fromGeometry(geometry) {
  6185. var faces = geometry.faces;
  6186. var vertices = geometry.vertices;
  6187. var faceVertexUvs = geometry.faceVertexUvs;
  6188. var hasFaceVertexUv = faceVertexUvs[0] && faceVertexUvs[0].length > 0;
  6189. var hasFaceVertexUv2 = faceVertexUvs[1] && faceVertexUvs[1].length > 0; // morphs
  6190. var morphTargets = geometry.morphTargets;
  6191. var morphTargetsLength = morphTargets.length;
  6192. var morphTargetsPosition;
  6193. if (morphTargetsLength > 0) {
  6194. morphTargetsPosition = [];
  6195. for (var i = 0; i < morphTargetsLength; i++) {
  6196. morphTargetsPosition[i] = {
  6197. name: morphTargets[i].name,
  6198. data: []
  6199. };
  6200. }
  6201. this.morphTargets.position = morphTargetsPosition;
  6202. }
  6203. var morphNormals = geometry.morphNormals;
  6204. var morphNormalsLength = morphNormals.length;
  6205. var morphTargetsNormal;
  6206. if (morphNormalsLength > 0) {
  6207. morphTargetsNormal = [];
  6208. for (var _i = 0; _i < morphNormalsLength; _i++) {
  6209. morphTargetsNormal[_i] = {
  6210. name: morphNormals[_i].name,
  6211. data: []
  6212. };
  6213. }
  6214. this.morphTargets.normal = morphTargetsNormal;
  6215. } // skins
  6216. var skinIndices = geometry.skinIndices;
  6217. var skinWeights = geometry.skinWeights;
  6218. var hasSkinIndices = skinIndices.length === vertices.length;
  6219. var hasSkinWeights = skinWeights.length === vertices.length; //
  6220. if (vertices.length > 0 && faces.length === 0) {
  6221. console.error('THREE.DirectGeometry: Faceless geometries are not supported.');
  6222. }
  6223. for (var _i2 = 0; _i2 < faces.length; _i2++) {
  6224. var face = faces[_i2];
  6225. this.vertices.push(vertices[face.a], vertices[face.b], vertices[face.c]);
  6226. var vertexNormals = face.vertexNormals;
  6227. if (vertexNormals.length === 3) {
  6228. this.normals.push(vertexNormals[0], vertexNormals[1], vertexNormals[2]);
  6229. } else {
  6230. var normal = face.normal;
  6231. this.normals.push(normal, normal, normal);
  6232. }
  6233. var vertexColors = face.vertexColors;
  6234. if (vertexColors.length === 3) {
  6235. this.colors.push(vertexColors[0], vertexColors[1], vertexColors[2]);
  6236. } else {
  6237. var color = face.color;
  6238. this.colors.push(color, color, color);
  6239. }
  6240. if (hasFaceVertexUv === true) {
  6241. var vertexUvs = faceVertexUvs[0][_i2];
  6242. if (vertexUvs !== undefined) {
  6243. this.uvs.push(vertexUvs[0], vertexUvs[1], vertexUvs[2]);
  6244. } else {
  6245. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', _i2);
  6246. this.uvs.push(new Vector2(), new Vector2(), new Vector2());
  6247. }
  6248. }
  6249. if (hasFaceVertexUv2 === true) {
  6250. var _vertexUvs = faceVertexUvs[1][_i2];
  6251. if (_vertexUvs !== undefined) {
  6252. this.uvs2.push(_vertexUvs[0], _vertexUvs[1], _vertexUvs[2]);
  6253. } else {
  6254. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', _i2);
  6255. this.uvs2.push(new Vector2(), new Vector2(), new Vector2());
  6256. }
  6257. } // morphs
  6258. for (var j = 0; j < morphTargetsLength; j++) {
  6259. var morphTarget = morphTargets[j].vertices;
  6260. morphTargetsPosition[j].data.push(morphTarget[face.a], morphTarget[face.b], morphTarget[face.c]);
  6261. }
  6262. for (var _j = 0; _j < morphNormalsLength; _j++) {
  6263. var morphNormal = morphNormals[_j].vertexNormals[_i2];
  6264. morphTargetsNormal[_j].data.push(morphNormal.a, morphNormal.b, morphNormal.c);
  6265. } // skins
  6266. if (hasSkinIndices) {
  6267. this.skinIndices.push(skinIndices[face.a], skinIndices[face.b], skinIndices[face.c]);
  6268. }
  6269. if (hasSkinWeights) {
  6270. this.skinWeights.push(skinWeights[face.a], skinWeights[face.b], skinWeights[face.c]);
  6271. }
  6272. }
  6273. this.computeGroups(geometry);
  6274. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6275. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6276. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6277. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6278. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6279. if (geometry.boundingSphere !== null) {
  6280. this.boundingSphere = geometry.boundingSphere.clone();
  6281. }
  6282. if (geometry.boundingBox !== null) {
  6283. this.boundingBox = geometry.boundingBox.clone();
  6284. }
  6285. return this;
  6286. };
  6287. return DirectGeometry;
  6288. }();
  6289. function arrayMax(array) {
  6290. if (array.length === 0) return -Infinity;
  6291. var max = array[0];
  6292. for (var i = 1, l = array.length; i < l; ++i) {
  6293. if (array[i] > max) max = array[i];
  6294. }
  6295. return max;
  6296. }
  6297. var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6298. var _m1$2 = new Matrix4();
  6299. var _obj = new Object3D();
  6300. var _offset = new Vector3();
  6301. var _box$2 = new Box3();
  6302. var _boxMorphTargets = new Box3();
  6303. var _vector$4 = new Vector3();
  6304. function BufferGeometry() {
  6305. Object.defineProperty(this, 'id', {
  6306. value: _bufferGeometryId += 2
  6307. });
  6308. this.uuid = MathUtils.generateUUID();
  6309. this.name = '';
  6310. this.type = 'BufferGeometry';
  6311. this.index = null;
  6312. this.attributes = {};
  6313. this.morphAttributes = {};
  6314. this.morphTargetsRelative = false;
  6315. this.groups = [];
  6316. this.boundingBox = null;
  6317. this.boundingSphere = null;
  6318. this.drawRange = {
  6319. start: 0,
  6320. count: Infinity
  6321. };
  6322. this.userData = {};
  6323. }
  6324. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  6325. constructor: BufferGeometry,
  6326. isBufferGeometry: true,
  6327. getIndex: function getIndex() {
  6328. return this.index;
  6329. },
  6330. setIndex: function setIndex(index) {
  6331. if (Array.isArray(index)) {
  6332. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  6333. } else {
  6334. this.index = index;
  6335. }
  6336. return this;
  6337. },
  6338. getAttribute: function getAttribute(name) {
  6339. return this.attributes[name];
  6340. },
  6341. setAttribute: function setAttribute(name, attribute) {
  6342. this.attributes[name] = attribute;
  6343. return this;
  6344. },
  6345. deleteAttribute: function deleteAttribute(name) {
  6346. delete this.attributes[name];
  6347. return this;
  6348. },
  6349. addGroup: function addGroup(start, count, materialIndex) {
  6350. this.groups.push({
  6351. start: start,
  6352. count: count,
  6353. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6354. });
  6355. },
  6356. clearGroups: function clearGroups() {
  6357. this.groups = [];
  6358. },
  6359. setDrawRange: function setDrawRange(start, count) {
  6360. this.drawRange.start = start;
  6361. this.drawRange.count = count;
  6362. },
  6363. applyMatrix4: function applyMatrix4(matrix) {
  6364. var position = this.attributes.position;
  6365. if (position !== undefined) {
  6366. position.applyMatrix4(matrix);
  6367. position.needsUpdate = true;
  6368. }
  6369. var normal = this.attributes.normal;
  6370. if (normal !== undefined) {
  6371. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  6372. normal.applyNormalMatrix(normalMatrix);
  6373. normal.needsUpdate = true;
  6374. }
  6375. var tangent = this.attributes.tangent;
  6376. if (tangent !== undefined) {
  6377. tangent.transformDirection(matrix);
  6378. tangent.needsUpdate = true;
  6379. }
  6380. if (this.boundingBox !== null) {
  6381. this.computeBoundingBox();
  6382. }
  6383. if (this.boundingSphere !== null) {
  6384. this.computeBoundingSphere();
  6385. }
  6386. return this;
  6387. },
  6388. rotateX: function rotateX(angle) {
  6389. // rotate geometry around world x-axis
  6390. _m1$2.makeRotationX(angle);
  6391. this.applyMatrix4(_m1$2);
  6392. return this;
  6393. },
  6394. rotateY: function rotateY(angle) {
  6395. // rotate geometry around world y-axis
  6396. _m1$2.makeRotationY(angle);
  6397. this.applyMatrix4(_m1$2);
  6398. return this;
  6399. },
  6400. rotateZ: function rotateZ(angle) {
  6401. // rotate geometry around world z-axis
  6402. _m1$2.makeRotationZ(angle);
  6403. this.applyMatrix4(_m1$2);
  6404. return this;
  6405. },
  6406. translate: function translate(x, y, z) {
  6407. // translate geometry
  6408. _m1$2.makeTranslation(x, y, z);
  6409. this.applyMatrix4(_m1$2);
  6410. return this;
  6411. },
  6412. scale: function scale(x, y, z) {
  6413. // scale geometry
  6414. _m1$2.makeScale(x, y, z);
  6415. this.applyMatrix4(_m1$2);
  6416. return this;
  6417. },
  6418. lookAt: function lookAt(vector) {
  6419. _obj.lookAt(vector);
  6420. _obj.updateMatrix();
  6421. this.applyMatrix4(_obj.matrix);
  6422. return this;
  6423. },
  6424. center: function center() {
  6425. this.computeBoundingBox();
  6426. this.boundingBox.getCenter(_offset).negate();
  6427. this.translate(_offset.x, _offset.y, _offset.z);
  6428. return this;
  6429. },
  6430. setFromObject: function setFromObject(object) {
  6431. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6432. var geometry = object.geometry;
  6433. if (object.isPoints || object.isLine) {
  6434. var positions = new Float32BufferAttribute(geometry.vertices.length * 3, 3);
  6435. var colors = new Float32BufferAttribute(geometry.colors.length * 3, 3);
  6436. this.setAttribute('position', positions.copyVector3sArray(geometry.vertices));
  6437. this.setAttribute('color', colors.copyColorsArray(geometry.colors));
  6438. if (geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length) {
  6439. var lineDistances = new Float32BufferAttribute(geometry.lineDistances.length, 1);
  6440. this.setAttribute('lineDistance', lineDistances.copyArray(geometry.lineDistances));
  6441. }
  6442. if (geometry.boundingSphere !== null) {
  6443. this.boundingSphere = geometry.boundingSphere.clone();
  6444. }
  6445. if (geometry.boundingBox !== null) {
  6446. this.boundingBox = geometry.boundingBox.clone();
  6447. }
  6448. } else if (object.isMesh) {
  6449. if (geometry && geometry.isGeometry) {
  6450. this.fromGeometry(geometry);
  6451. }
  6452. }
  6453. return this;
  6454. },
  6455. setFromPoints: function setFromPoints(points) {
  6456. var position = [];
  6457. for (var i = 0, l = points.length; i < l; i++) {
  6458. var point = points[i];
  6459. position.push(point.x, point.y, point.z || 0);
  6460. }
  6461. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  6462. return this;
  6463. },
  6464. updateFromObject: function updateFromObject(object) {
  6465. var geometry = object.geometry;
  6466. if (object.isMesh) {
  6467. var direct = geometry.__directGeometry;
  6468. if (geometry.elementsNeedUpdate === true) {
  6469. direct = undefined;
  6470. geometry.elementsNeedUpdate = false;
  6471. }
  6472. if (direct === undefined) {
  6473. return this.fromGeometry(geometry);
  6474. }
  6475. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6476. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6477. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6478. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6479. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6480. geometry.verticesNeedUpdate = false;
  6481. geometry.normalsNeedUpdate = false;
  6482. geometry.colorsNeedUpdate = false;
  6483. geometry.uvsNeedUpdate = false;
  6484. geometry.groupsNeedUpdate = false;
  6485. geometry = direct;
  6486. }
  6487. if (geometry.verticesNeedUpdate === true) {
  6488. var attribute = this.attributes.position;
  6489. if (attribute !== undefined) {
  6490. attribute.copyVector3sArray(geometry.vertices);
  6491. attribute.needsUpdate = true;
  6492. }
  6493. geometry.verticesNeedUpdate = false;
  6494. }
  6495. if (geometry.normalsNeedUpdate === true) {
  6496. var _attribute = this.attributes.normal;
  6497. if (_attribute !== undefined) {
  6498. _attribute.copyVector3sArray(geometry.normals);
  6499. _attribute.needsUpdate = true;
  6500. }
  6501. geometry.normalsNeedUpdate = false;
  6502. }
  6503. if (geometry.colorsNeedUpdate === true) {
  6504. var _attribute2 = this.attributes.color;
  6505. if (_attribute2 !== undefined) {
  6506. _attribute2.copyColorsArray(geometry.colors);
  6507. _attribute2.needsUpdate = true;
  6508. }
  6509. geometry.colorsNeedUpdate = false;
  6510. }
  6511. if (geometry.uvsNeedUpdate) {
  6512. var _attribute3 = this.attributes.uv;
  6513. if (_attribute3 !== undefined) {
  6514. _attribute3.copyVector2sArray(geometry.uvs);
  6515. _attribute3.needsUpdate = true;
  6516. }
  6517. geometry.uvsNeedUpdate = false;
  6518. }
  6519. if (geometry.lineDistancesNeedUpdate) {
  6520. var _attribute4 = this.attributes.lineDistance;
  6521. if (_attribute4 !== undefined) {
  6522. _attribute4.copyArray(geometry.lineDistances);
  6523. _attribute4.needsUpdate = true;
  6524. }
  6525. geometry.lineDistancesNeedUpdate = false;
  6526. }
  6527. if (geometry.groupsNeedUpdate) {
  6528. geometry.computeGroups(object.geometry);
  6529. this.groups = geometry.groups;
  6530. geometry.groupsNeedUpdate = false;
  6531. }
  6532. return this;
  6533. },
  6534. fromGeometry: function fromGeometry(geometry) {
  6535. geometry.__directGeometry = new DirectGeometry().fromGeometry(geometry);
  6536. return this.fromDirectGeometry(geometry.__directGeometry);
  6537. },
  6538. fromDirectGeometry: function fromDirectGeometry(geometry) {
  6539. var positions = new Float32Array(geometry.vertices.length * 3);
  6540. this.setAttribute('position', new BufferAttribute(positions, 3).copyVector3sArray(geometry.vertices));
  6541. if (geometry.normals.length > 0) {
  6542. var normals = new Float32Array(geometry.normals.length * 3);
  6543. this.setAttribute('normal', new BufferAttribute(normals, 3).copyVector3sArray(geometry.normals));
  6544. }
  6545. if (geometry.colors.length > 0) {
  6546. var colors = new Float32Array(geometry.colors.length * 3);
  6547. this.setAttribute('color', new BufferAttribute(colors, 3).copyColorsArray(geometry.colors));
  6548. }
  6549. if (geometry.uvs.length > 0) {
  6550. var uvs = new Float32Array(geometry.uvs.length * 2);
  6551. this.setAttribute('uv', new BufferAttribute(uvs, 2).copyVector2sArray(geometry.uvs));
  6552. }
  6553. if (geometry.uvs2.length > 0) {
  6554. var uvs2 = new Float32Array(geometry.uvs2.length * 2);
  6555. this.setAttribute('uv2', new BufferAttribute(uvs2, 2).copyVector2sArray(geometry.uvs2));
  6556. } // groups
  6557. this.groups = geometry.groups; // morphs
  6558. for (var name in geometry.morphTargets) {
  6559. var array = [];
  6560. var morphTargets = geometry.morphTargets[name];
  6561. for (var i = 0, l = morphTargets.length; i < l; i++) {
  6562. var morphTarget = morphTargets[i];
  6563. var attribute = new Float32BufferAttribute(morphTarget.data.length * 3, 3);
  6564. attribute.name = morphTarget.name;
  6565. array.push(attribute.copyVector3sArray(morphTarget.data));
  6566. }
  6567. this.morphAttributes[name] = array;
  6568. } // skinning
  6569. if (geometry.skinIndices.length > 0) {
  6570. var skinIndices = new Float32BufferAttribute(geometry.skinIndices.length * 4, 4);
  6571. this.setAttribute('skinIndex', skinIndices.copyVector4sArray(geometry.skinIndices));
  6572. }
  6573. if (geometry.skinWeights.length > 0) {
  6574. var skinWeights = new Float32BufferAttribute(geometry.skinWeights.length * 4, 4);
  6575. this.setAttribute('skinWeight', skinWeights.copyVector4sArray(geometry.skinWeights));
  6576. } //
  6577. if (geometry.boundingSphere !== null) {
  6578. this.boundingSphere = geometry.boundingSphere.clone();
  6579. }
  6580. if (geometry.boundingBox !== null) {
  6581. this.boundingBox = geometry.boundingBox.clone();
  6582. }
  6583. return this;
  6584. },
  6585. computeBoundingBox: function computeBoundingBox() {
  6586. if (this.boundingBox === null) {
  6587. this.boundingBox = new Box3();
  6588. }
  6589. var position = this.attributes.position;
  6590. var morphAttributesPosition = this.morphAttributes.position;
  6591. if (position && position.isGLBufferAttribute) {
  6592. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  6593. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  6594. return;
  6595. }
  6596. if (position !== undefined) {
  6597. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  6598. if (morphAttributesPosition) {
  6599. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6600. var morphAttribute = morphAttributesPosition[i];
  6601. _box$2.setFromBufferAttribute(morphAttribute);
  6602. if (this.morphTargetsRelative) {
  6603. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  6604. this.boundingBox.expandByPoint(_vector$4);
  6605. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  6606. this.boundingBox.expandByPoint(_vector$4);
  6607. } else {
  6608. this.boundingBox.expandByPoint(_box$2.min);
  6609. this.boundingBox.expandByPoint(_box$2.max);
  6610. }
  6611. }
  6612. }
  6613. } else {
  6614. this.boundingBox.makeEmpty();
  6615. }
  6616. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  6617. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  6618. }
  6619. },
  6620. computeBoundingSphere: function computeBoundingSphere() {
  6621. if (this.boundingSphere === null) {
  6622. this.boundingSphere = new Sphere();
  6623. }
  6624. var position = this.attributes.position;
  6625. var morphAttributesPosition = this.morphAttributes.position;
  6626. if (position && position.isGLBufferAttribute) {
  6627. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  6628. this.boundingSphere.set(new Vector3(), Infinity);
  6629. return;
  6630. }
  6631. if (position) {
  6632. // first, find the center of the bounding sphere
  6633. var center = this.boundingSphere.center;
  6634. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  6635. if (morphAttributesPosition) {
  6636. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6637. var morphAttribute = morphAttributesPosition[i];
  6638. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  6639. if (this.morphTargetsRelative) {
  6640. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  6641. _box$2.expandByPoint(_vector$4);
  6642. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  6643. _box$2.expandByPoint(_vector$4);
  6644. } else {
  6645. _box$2.expandByPoint(_boxMorphTargets.min);
  6646. _box$2.expandByPoint(_boxMorphTargets.max);
  6647. }
  6648. }
  6649. }
  6650. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  6651. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6652. var maxRadiusSq = 0;
  6653. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  6654. _vector$4.fromBufferAttribute(position, _i);
  6655. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6656. } // process morph attributes if present
  6657. if (morphAttributesPosition) {
  6658. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  6659. var _morphAttribute = morphAttributesPosition[_i2];
  6660. var morphTargetsRelative = this.morphTargetsRelative;
  6661. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  6662. _vector$4.fromBufferAttribute(_morphAttribute, j);
  6663. if (morphTargetsRelative) {
  6664. _offset.fromBufferAttribute(position, j);
  6665. _vector$4.add(_offset);
  6666. }
  6667. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6668. }
  6669. }
  6670. }
  6671. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  6672. if (isNaN(this.boundingSphere.radius)) {
  6673. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  6674. }
  6675. }
  6676. },
  6677. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  6678. },
  6679. computeVertexNormals: function computeVertexNormals() {
  6680. var index = this.index;
  6681. var positionAttribute = this.getAttribute('position');
  6682. if (positionAttribute !== undefined) {
  6683. var normalAttribute = this.getAttribute('normal');
  6684. if (normalAttribute === undefined) {
  6685. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  6686. this.setAttribute('normal', normalAttribute);
  6687. } else {
  6688. // reset existing normals to zero
  6689. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  6690. normalAttribute.setXYZ(i, 0, 0, 0);
  6691. }
  6692. }
  6693. var pA = new Vector3(),
  6694. pB = new Vector3(),
  6695. pC = new Vector3();
  6696. var nA = new Vector3(),
  6697. nB = new Vector3(),
  6698. nC = new Vector3();
  6699. var cb = new Vector3(),
  6700. ab = new Vector3(); // indexed elements
  6701. if (index) {
  6702. for (var _i3 = 0, _il3 = index.count; _i3 < _il3; _i3 += 3) {
  6703. var vA = index.getX(_i3 + 0);
  6704. var vB = index.getX(_i3 + 1);
  6705. var vC = index.getX(_i3 + 2);
  6706. pA.fromBufferAttribute(positionAttribute, vA);
  6707. pB.fromBufferAttribute(positionAttribute, vB);
  6708. pC.fromBufferAttribute(positionAttribute, vC);
  6709. cb.subVectors(pC, pB);
  6710. ab.subVectors(pA, pB);
  6711. cb.cross(ab);
  6712. nA.fromBufferAttribute(normalAttribute, vA);
  6713. nB.fromBufferAttribute(normalAttribute, vB);
  6714. nC.fromBufferAttribute(normalAttribute, vC);
  6715. nA.add(cb);
  6716. nB.add(cb);
  6717. nC.add(cb);
  6718. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  6719. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  6720. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  6721. }
  6722. } else {
  6723. // non-indexed elements (unconnected triangle soup)
  6724. for (var _i4 = 0, _il4 = positionAttribute.count; _i4 < _il4; _i4 += 3) {
  6725. pA.fromBufferAttribute(positionAttribute, _i4 + 0);
  6726. pB.fromBufferAttribute(positionAttribute, _i4 + 1);
  6727. pC.fromBufferAttribute(positionAttribute, _i4 + 2);
  6728. cb.subVectors(pC, pB);
  6729. ab.subVectors(pA, pB);
  6730. cb.cross(ab);
  6731. normalAttribute.setXYZ(_i4 + 0, cb.x, cb.y, cb.z);
  6732. normalAttribute.setXYZ(_i4 + 1, cb.x, cb.y, cb.z);
  6733. normalAttribute.setXYZ(_i4 + 2, cb.x, cb.y, cb.z);
  6734. }
  6735. }
  6736. this.normalizeNormals();
  6737. normalAttribute.needsUpdate = true;
  6738. }
  6739. },
  6740. merge: function merge(geometry, offset) {
  6741. if (!(geometry && geometry.isBufferGeometry)) {
  6742. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  6743. return;
  6744. }
  6745. if (offset === undefined) {
  6746. offset = 0;
  6747. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  6748. }
  6749. var attributes = this.attributes;
  6750. for (var key in attributes) {
  6751. if (geometry.attributes[key] === undefined) continue;
  6752. var attribute1 = attributes[key];
  6753. var attributeArray1 = attribute1.array;
  6754. var attribute2 = geometry.attributes[key];
  6755. var attributeArray2 = attribute2.array;
  6756. var attributeOffset = attribute2.itemSize * offset;
  6757. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  6758. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  6759. attributeArray1[j] = attributeArray2[i];
  6760. }
  6761. }
  6762. return this;
  6763. },
  6764. normalizeNormals: function normalizeNormals() {
  6765. var normals = this.attributes.normal;
  6766. for (var i = 0, il = normals.count; i < il; i++) {
  6767. _vector$4.fromBufferAttribute(normals, i);
  6768. _vector$4.normalize();
  6769. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  6770. }
  6771. },
  6772. toNonIndexed: function toNonIndexed() {
  6773. function convertBufferAttribute(attribute, indices) {
  6774. var array = attribute.array;
  6775. var itemSize = attribute.itemSize;
  6776. var normalized = attribute.normalized;
  6777. var array2 = new array.constructor(indices.length * itemSize);
  6778. var index = 0,
  6779. index2 = 0;
  6780. for (var i = 0, l = indices.length; i < l; i++) {
  6781. index = indices[i] * itemSize;
  6782. for (var j = 0; j < itemSize; j++) {
  6783. array2[index2++] = array[index++];
  6784. }
  6785. }
  6786. return new BufferAttribute(array2, itemSize, normalized);
  6787. } //
  6788. if (this.index === null) {
  6789. console.warn('THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.');
  6790. return this;
  6791. }
  6792. var geometry2 = new BufferGeometry();
  6793. var indices = this.index.array;
  6794. var attributes = this.attributes; // attributes
  6795. for (var name in attributes) {
  6796. var attribute = attributes[name];
  6797. var newAttribute = convertBufferAttribute(attribute, indices);
  6798. geometry2.setAttribute(name, newAttribute);
  6799. } // morph attributes
  6800. var morphAttributes = this.morphAttributes;
  6801. for (var _name in morphAttributes) {
  6802. var morphArray = [];
  6803. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  6804. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  6805. var _attribute5 = morphAttribute[i];
  6806. var _newAttribute = convertBufferAttribute(_attribute5, indices);
  6807. morphArray.push(_newAttribute);
  6808. }
  6809. geometry2.morphAttributes[_name] = morphArray;
  6810. }
  6811. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  6812. var groups = this.groups;
  6813. for (var _i5 = 0, l = groups.length; _i5 < l; _i5++) {
  6814. var group = groups[_i5];
  6815. geometry2.addGroup(group.start, group.count, group.materialIndex);
  6816. }
  6817. return geometry2;
  6818. },
  6819. toJSON: function toJSON() {
  6820. var data = {
  6821. metadata: {
  6822. version: 4.5,
  6823. type: 'BufferGeometry',
  6824. generator: 'BufferGeometry.toJSON'
  6825. }
  6826. }; // standard BufferGeometry serialization
  6827. data.uuid = this.uuid;
  6828. data.type = this.type;
  6829. if (this.name !== '') data.name = this.name;
  6830. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  6831. if (this.parameters !== undefined) {
  6832. var parameters = this.parameters;
  6833. for (var key in parameters) {
  6834. if (parameters[key] !== undefined) data[key] = parameters[key];
  6835. }
  6836. return data;
  6837. }
  6838. data.data = {
  6839. attributes: {}
  6840. };
  6841. var index = this.index;
  6842. if (index !== null) {
  6843. data.data.index = {
  6844. type: index.array.constructor.name,
  6845. array: Array.prototype.slice.call(index.array)
  6846. };
  6847. }
  6848. var attributes = this.attributes;
  6849. for (var _key in attributes) {
  6850. var attribute = attributes[_key];
  6851. var attributeData = attribute.toJSON(data.data);
  6852. if (attribute.name !== '') attributeData.name = attribute.name;
  6853. data.data.attributes[_key] = attributeData;
  6854. }
  6855. var morphAttributes = {};
  6856. var hasMorphAttributes = false;
  6857. for (var _key2 in this.morphAttributes) {
  6858. var attributeArray = this.morphAttributes[_key2];
  6859. var array = [];
  6860. for (var i = 0, il = attributeArray.length; i < il; i++) {
  6861. var _attribute6 = attributeArray[i];
  6862. var _attributeData = _attribute6.toJSON(data.data);
  6863. if (_attribute6.name !== '') _attributeData.name = _attribute6.name;
  6864. array.push(_attributeData);
  6865. }
  6866. if (array.length > 0) {
  6867. morphAttributes[_key2] = array;
  6868. hasMorphAttributes = true;
  6869. }
  6870. }
  6871. if (hasMorphAttributes) {
  6872. data.data.morphAttributes = morphAttributes;
  6873. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6874. }
  6875. var groups = this.groups;
  6876. if (groups.length > 0) {
  6877. data.data.groups = JSON.parse(JSON.stringify(groups));
  6878. }
  6879. var boundingSphere = this.boundingSphere;
  6880. if (boundingSphere !== null) {
  6881. data.data.boundingSphere = {
  6882. center: boundingSphere.center.toArray(),
  6883. radius: boundingSphere.radius
  6884. };
  6885. }
  6886. return data;
  6887. },
  6888. clone: function clone() {
  6889. /*
  6890. // Handle primitives
  6891. const parameters = this.parameters;
  6892. if ( parameters !== undefined ) {
  6893. const values = [];
  6894. for ( const key in parameters ) {
  6895. values.push( parameters[ key ] );
  6896. }
  6897. const geometry = Object.create( this.constructor.prototype );
  6898. this.constructor.apply( geometry, values );
  6899. return geometry;
  6900. }
  6901. return new this.constructor().copy( this );
  6902. */
  6903. return new BufferGeometry().copy(this);
  6904. },
  6905. copy: function copy(source) {
  6906. // reset
  6907. this.index = null;
  6908. this.attributes = {};
  6909. this.morphAttributes = {};
  6910. this.groups = [];
  6911. this.boundingBox = null;
  6912. this.boundingSphere = null; // used for storing cloned, shared data
  6913. var data = {}; // name
  6914. this.name = source.name; // index
  6915. var index = source.index;
  6916. if (index !== null) {
  6917. this.setIndex(index.clone(data));
  6918. } // attributes
  6919. var attributes = source.attributes;
  6920. for (var name in attributes) {
  6921. var attribute = attributes[name];
  6922. this.setAttribute(name, attribute.clone(data));
  6923. } // morph attributes
  6924. var morphAttributes = source.morphAttributes;
  6925. for (var _name2 in morphAttributes) {
  6926. var array = [];
  6927. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  6928. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  6929. array.push(morphAttribute[i].clone(data));
  6930. }
  6931. this.morphAttributes[_name2] = array;
  6932. }
  6933. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  6934. var groups = source.groups;
  6935. for (var _i6 = 0, _l = groups.length; _i6 < _l; _i6++) {
  6936. var group = groups[_i6];
  6937. this.addGroup(group.start, group.count, group.materialIndex);
  6938. } // bounding box
  6939. var boundingBox = source.boundingBox;
  6940. if (boundingBox !== null) {
  6941. this.boundingBox = boundingBox.clone();
  6942. } // bounding sphere
  6943. var boundingSphere = source.boundingSphere;
  6944. if (boundingSphere !== null) {
  6945. this.boundingSphere = boundingSphere.clone();
  6946. } // draw range
  6947. this.drawRange.start = source.drawRange.start;
  6948. this.drawRange.count = source.drawRange.count; // user data
  6949. this.userData = source.userData;
  6950. return this;
  6951. },
  6952. dispose: function dispose() {
  6953. this.dispatchEvent({
  6954. type: 'dispose'
  6955. });
  6956. }
  6957. });
  6958. var _inverseMatrix = new Matrix4();
  6959. var _ray = new Ray();
  6960. var _sphere = new Sphere();
  6961. var _vA = new Vector3();
  6962. var _vB = new Vector3();
  6963. var _vC = new Vector3();
  6964. var _tempA = new Vector3();
  6965. var _tempB = new Vector3();
  6966. var _tempC = new Vector3();
  6967. var _morphA = new Vector3();
  6968. var _morphB = new Vector3();
  6969. var _morphC = new Vector3();
  6970. var _uvA = new Vector2();
  6971. var _uvB = new Vector2();
  6972. var _uvC = new Vector2();
  6973. var _intersectionPoint = new Vector3();
  6974. var _intersectionPointWorld = new Vector3();
  6975. function Mesh(geometry, material) {
  6976. Object3D.call(this);
  6977. this.type = 'Mesh';
  6978. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  6979. this.material = material !== undefined ? material : new MeshBasicMaterial();
  6980. this.updateMorphTargets();
  6981. }
  6982. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  6983. constructor: Mesh,
  6984. isMesh: true,
  6985. copy: function copy(source) {
  6986. Object3D.prototype.copy.call(this, source);
  6987. if (source.morphTargetInfluences !== undefined) {
  6988. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6989. }
  6990. if (source.morphTargetDictionary !== undefined) {
  6991. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  6992. }
  6993. this.material = source.material;
  6994. this.geometry = source.geometry;
  6995. return this;
  6996. },
  6997. updateMorphTargets: function updateMorphTargets() {
  6998. var geometry = this.geometry;
  6999. if (geometry.isBufferGeometry) {
  7000. var morphAttributes = geometry.morphAttributes;
  7001. var keys = Object.keys(morphAttributes);
  7002. if (keys.length > 0) {
  7003. var morphAttribute = morphAttributes[keys[0]];
  7004. if (morphAttribute !== undefined) {
  7005. this.morphTargetInfluences = [];
  7006. this.morphTargetDictionary = {};
  7007. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7008. var name = morphAttribute[m].name || String(m);
  7009. this.morphTargetInfluences.push(0);
  7010. this.morphTargetDictionary[name] = m;
  7011. }
  7012. }
  7013. }
  7014. } else {
  7015. var morphTargets = geometry.morphTargets;
  7016. if (morphTargets !== undefined && morphTargets.length > 0) {
  7017. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7018. }
  7019. }
  7020. },
  7021. raycast: function raycast(raycaster, intersects) {
  7022. var geometry = this.geometry;
  7023. var material = this.material;
  7024. var matrixWorld = this.matrixWorld;
  7025. if (material === undefined) return; // Checking boundingSphere distance to ray
  7026. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7027. _sphere.copy(geometry.boundingSphere);
  7028. _sphere.applyMatrix4(matrixWorld);
  7029. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7030. _inverseMatrix.getInverse(matrixWorld);
  7031. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7032. if (geometry.boundingBox !== null) {
  7033. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7034. }
  7035. var intersection;
  7036. if (geometry.isBufferGeometry) {
  7037. var index = geometry.index;
  7038. var position = geometry.attributes.position;
  7039. var morphPosition = geometry.morphAttributes.position;
  7040. var morphTargetsRelative = geometry.morphTargetsRelative;
  7041. var uv = geometry.attributes.uv;
  7042. var uv2 = geometry.attributes.uv2;
  7043. var groups = geometry.groups;
  7044. var drawRange = geometry.drawRange;
  7045. if (index !== null) {
  7046. // indexed buffer geometry
  7047. if (Array.isArray(material)) {
  7048. for (var i = 0, il = groups.length; i < il; i++) {
  7049. var group = groups[i];
  7050. var groupMaterial = material[group.materialIndex];
  7051. var start = Math.max(group.start, drawRange.start);
  7052. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7053. for (var j = start, jl = end; j < jl; j += 3) {
  7054. var a = index.getX(j);
  7055. var b = index.getX(j + 1);
  7056. var c = index.getX(j + 2);
  7057. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7058. if (intersection) {
  7059. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7060. intersection.face.materialIndex = group.materialIndex;
  7061. intersects.push(intersection);
  7062. }
  7063. }
  7064. }
  7065. } else {
  7066. var _start = Math.max(0, drawRange.start);
  7067. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7068. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7069. var _a = index.getX(_i);
  7070. var _b = index.getX(_i + 1);
  7071. var _c = index.getX(_i + 2);
  7072. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7073. if (intersection) {
  7074. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7075. intersects.push(intersection);
  7076. }
  7077. }
  7078. }
  7079. } else if (position !== undefined) {
  7080. // non-indexed buffer geometry
  7081. if (Array.isArray(material)) {
  7082. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7083. var _group = groups[_i2];
  7084. var _groupMaterial = material[_group.materialIndex];
  7085. var _start2 = Math.max(_group.start, drawRange.start);
  7086. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7087. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7088. var _a2 = _j;
  7089. var _b2 = _j + 1;
  7090. var _c2 = _j + 2;
  7091. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7092. if (intersection) {
  7093. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7094. intersection.face.materialIndex = _group.materialIndex;
  7095. intersects.push(intersection);
  7096. }
  7097. }
  7098. }
  7099. } else {
  7100. var _start3 = Math.max(0, drawRange.start);
  7101. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7102. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7103. var _a3 = _i3;
  7104. var _b3 = _i3 + 1;
  7105. var _c3 = _i3 + 2;
  7106. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7107. if (intersection) {
  7108. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7109. intersects.push(intersection);
  7110. }
  7111. }
  7112. }
  7113. }
  7114. } else if (geometry.isGeometry) {
  7115. var isMultiMaterial = Array.isArray(material);
  7116. var vertices = geometry.vertices;
  7117. var faces = geometry.faces;
  7118. var uvs;
  7119. var faceVertexUvs = geometry.faceVertexUvs[0];
  7120. if (faceVertexUvs.length > 0) uvs = faceVertexUvs;
  7121. for (var f = 0, fl = faces.length; f < fl; f++) {
  7122. var face = faces[f];
  7123. var faceMaterial = isMultiMaterial ? material[face.materialIndex] : material;
  7124. if (faceMaterial === undefined) continue;
  7125. var fvA = vertices[face.a];
  7126. var fvB = vertices[face.b];
  7127. var fvC = vertices[face.c];
  7128. intersection = checkIntersection(this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint);
  7129. if (intersection) {
  7130. if (uvs && uvs[f]) {
  7131. var uvs_f = uvs[f];
  7132. _uvA.copy(uvs_f[0]);
  7133. _uvB.copy(uvs_f[1]);
  7134. _uvC.copy(uvs_f[2]);
  7135. intersection.uv = Triangle.getUV(_intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2());
  7136. }
  7137. intersection.face = face;
  7138. intersection.faceIndex = f;
  7139. intersects.push(intersection);
  7140. }
  7141. }
  7142. }
  7143. }
  7144. });
  7145. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7146. var intersect;
  7147. if (material.side === BackSide) {
  7148. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7149. } else {
  7150. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7151. }
  7152. if (intersect === null) return null;
  7153. _intersectionPointWorld.copy(point);
  7154. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7155. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7156. if (distance < raycaster.near || distance > raycaster.far) return null;
  7157. return {
  7158. distance: distance,
  7159. point: _intersectionPointWorld.clone(),
  7160. object: object
  7161. };
  7162. }
  7163. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7164. _vA.fromBufferAttribute(position, a);
  7165. _vB.fromBufferAttribute(position, b);
  7166. _vC.fromBufferAttribute(position, c);
  7167. var morphInfluences = object.morphTargetInfluences;
  7168. if (material.morphTargets && morphPosition && morphInfluences) {
  7169. _morphA.set(0, 0, 0);
  7170. _morphB.set(0, 0, 0);
  7171. _morphC.set(0, 0, 0);
  7172. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7173. var influence = morphInfluences[i];
  7174. var morphAttribute = morphPosition[i];
  7175. if (influence === 0) continue;
  7176. _tempA.fromBufferAttribute(morphAttribute, a);
  7177. _tempB.fromBufferAttribute(morphAttribute, b);
  7178. _tempC.fromBufferAttribute(morphAttribute, c);
  7179. if (morphTargetsRelative) {
  7180. _morphA.addScaledVector(_tempA, influence);
  7181. _morphB.addScaledVector(_tempB, influence);
  7182. _morphC.addScaledVector(_tempC, influence);
  7183. } else {
  7184. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7185. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7186. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7187. }
  7188. }
  7189. _vA.add(_morphA);
  7190. _vB.add(_morphB);
  7191. _vC.add(_morphC);
  7192. }
  7193. if (object.isSkinnedMesh) {
  7194. object.boneTransform(a, _vA);
  7195. object.boneTransform(b, _vB);
  7196. object.boneTransform(c, _vC);
  7197. }
  7198. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7199. if (intersection) {
  7200. if (uv) {
  7201. _uvA.fromBufferAttribute(uv, a);
  7202. _uvB.fromBufferAttribute(uv, b);
  7203. _uvC.fromBufferAttribute(uv, c);
  7204. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7205. }
  7206. if (uv2) {
  7207. _uvA.fromBufferAttribute(uv2, a);
  7208. _uvB.fromBufferAttribute(uv2, b);
  7209. _uvC.fromBufferAttribute(uv2, c);
  7210. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7211. }
  7212. var face = new Face3(a, b, c);
  7213. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7214. intersection.face = face;
  7215. }
  7216. return intersection;
  7217. }
  7218. var BoxBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7219. _inheritsLoose(BoxBufferGeometry, _BufferGeometry);
  7220. function BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7221. var _this;
  7222. if (width === void 0) {
  7223. width = 1;
  7224. }
  7225. if (height === void 0) {
  7226. height = 1;
  7227. }
  7228. if (depth === void 0) {
  7229. depth = 1;
  7230. }
  7231. if (widthSegments === void 0) {
  7232. widthSegments = 1;
  7233. }
  7234. if (heightSegments === void 0) {
  7235. heightSegments = 1;
  7236. }
  7237. if (depthSegments === void 0) {
  7238. depthSegments = 1;
  7239. }
  7240. _this = _BufferGeometry.call(this) || this;
  7241. _this.type = 'BoxBufferGeometry';
  7242. _this.parameters = {
  7243. width: width,
  7244. height: height,
  7245. depth: depth,
  7246. widthSegments: widthSegments,
  7247. heightSegments: heightSegments,
  7248. depthSegments: depthSegments
  7249. };
  7250. var scope = _assertThisInitialized(_this); // segments
  7251. widthSegments = Math.floor(widthSegments);
  7252. heightSegments = Math.floor(heightSegments);
  7253. depthSegments = Math.floor(depthSegments); // buffers
  7254. var indices = [];
  7255. var vertices = [];
  7256. var normals = [];
  7257. var uvs = []; // helper variables
  7258. var numberOfVertices = 0;
  7259. var groupStart = 0; // build each side of the box geometry
  7260. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7261. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7262. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7263. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7264. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7265. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7266. // build geometry
  7267. _this.setIndex(indices);
  7268. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7269. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7270. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7271. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7272. var segmentWidth = width / gridX;
  7273. var segmentHeight = height / gridY;
  7274. var widthHalf = width / 2;
  7275. var heightHalf = height / 2;
  7276. var depthHalf = depth / 2;
  7277. var gridX1 = gridX + 1;
  7278. var gridY1 = gridY + 1;
  7279. var vertexCounter = 0;
  7280. var groupCount = 0;
  7281. var vector = new Vector3(); // generate vertices, normals and uvs
  7282. for (var iy = 0; iy < gridY1; iy++) {
  7283. var y = iy * segmentHeight - heightHalf;
  7284. for (var ix = 0; ix < gridX1; ix++) {
  7285. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7286. vector[u] = x * udir;
  7287. vector[v] = y * vdir;
  7288. vector[w] = depthHalf; // now apply vector to vertex buffer
  7289. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7290. vector[u] = 0;
  7291. vector[v] = 0;
  7292. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7293. normals.push(vector.x, vector.y, vector.z); // uvs
  7294. uvs.push(ix / gridX);
  7295. uvs.push(1 - iy / gridY); // counters
  7296. vertexCounter += 1;
  7297. }
  7298. } // indices
  7299. // 1. you need three indices to draw a single face
  7300. // 2. a single segment consists of two faces
  7301. // 3. so we need to generate six (2*3) indices per segment
  7302. for (var _iy = 0; _iy < gridY; _iy++) {
  7303. for (var _ix = 0; _ix < gridX; _ix++) {
  7304. var a = numberOfVertices + _ix + gridX1 * _iy;
  7305. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7306. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7307. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7308. indices.push(a, b, d);
  7309. indices.push(b, c, d); // increase counter
  7310. groupCount += 6;
  7311. }
  7312. } // add a group to the geometry. this will ensure multi material support
  7313. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7314. groupStart += groupCount; // update total number of vertices
  7315. numberOfVertices += vertexCounter;
  7316. }
  7317. return _this;
  7318. }
  7319. return BoxBufferGeometry;
  7320. }(BufferGeometry);
  7321. /**
  7322. * Uniform Utilities
  7323. */
  7324. function cloneUniforms(src) {
  7325. var dst = {};
  7326. for (var u in src) {
  7327. dst[u] = {};
  7328. for (var p in src[u]) {
  7329. var property = src[u][p];
  7330. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture)) {
  7331. dst[u][p] = property.clone();
  7332. } else if (Array.isArray(property)) {
  7333. dst[u][p] = property.slice();
  7334. } else {
  7335. dst[u][p] = property;
  7336. }
  7337. }
  7338. }
  7339. return dst;
  7340. }
  7341. function mergeUniforms(uniforms) {
  7342. var merged = {};
  7343. for (var u = 0; u < uniforms.length; u++) {
  7344. var tmp = cloneUniforms(uniforms[u]);
  7345. for (var p in tmp) {
  7346. merged[p] = tmp[p];
  7347. }
  7348. }
  7349. return merged;
  7350. } // Legacy
  7351. var UniformsUtils = {
  7352. clone: cloneUniforms,
  7353. merge: mergeUniforms
  7354. };
  7355. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7356. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7357. /**
  7358. * parameters = {
  7359. * defines: { "label" : "value" },
  7360. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7361. *
  7362. * fragmentShader: <string>,
  7363. * vertexShader: <string>,
  7364. *
  7365. * wireframe: <boolean>,
  7366. * wireframeLinewidth: <float>,
  7367. *
  7368. * lights: <bool>,
  7369. *
  7370. * skinning: <bool>,
  7371. * morphTargets: <bool>,
  7372. * morphNormals: <bool>
  7373. * }
  7374. */
  7375. function ShaderMaterial(parameters) {
  7376. Material.call(this);
  7377. this.type = 'ShaderMaterial';
  7378. this.defines = {};
  7379. this.uniforms = {};
  7380. this.vertexShader = default_vertex;
  7381. this.fragmentShader = default_fragment;
  7382. this.linewidth = 1;
  7383. this.wireframe = false;
  7384. this.wireframeLinewidth = 1;
  7385. this.fog = false; // set to use scene fog
  7386. this.lights = false; // set to use scene lights
  7387. this.clipping = false; // set to use user-defined clipping planes
  7388. this.skinning = false; // set to use skinning attribute streams
  7389. this.morphTargets = false; // set to use morph targets
  7390. this.morphNormals = false; // set to use morph normals
  7391. this.extensions = {
  7392. derivatives: false,
  7393. // set to use derivatives
  7394. fragDepth: false,
  7395. // set to use fragment depth values
  7396. drawBuffers: false,
  7397. // set to use draw buffers
  7398. shaderTextureLOD: false // set to use shader texture LOD
  7399. }; // When rendered geometry doesn't include these attributes but the material does,
  7400. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7401. this.defaultAttributeValues = {
  7402. 'color': [1, 1, 1],
  7403. 'uv': [0, 0],
  7404. 'uv2': [0, 0]
  7405. };
  7406. this.index0AttributeName = undefined;
  7407. this.uniformsNeedUpdate = false;
  7408. this.glslVersion = null;
  7409. if (parameters !== undefined) {
  7410. if (parameters.attributes !== undefined) {
  7411. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  7412. }
  7413. this.setValues(parameters);
  7414. }
  7415. }
  7416. ShaderMaterial.prototype = Object.create(Material.prototype);
  7417. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7418. ShaderMaterial.prototype.isShaderMaterial = true;
  7419. ShaderMaterial.prototype.copy = function (source) {
  7420. Material.prototype.copy.call(this, source);
  7421. this.fragmentShader = source.fragmentShader;
  7422. this.vertexShader = source.vertexShader;
  7423. this.uniforms = cloneUniforms(source.uniforms);
  7424. this.defines = Object.assign({}, source.defines);
  7425. this.wireframe = source.wireframe;
  7426. this.wireframeLinewidth = source.wireframeLinewidth;
  7427. this.lights = source.lights;
  7428. this.clipping = source.clipping;
  7429. this.skinning = source.skinning;
  7430. this.morphTargets = source.morphTargets;
  7431. this.morphNormals = source.morphNormals;
  7432. this.extensions = Object.assign({}, source.extensions);
  7433. this.glslVersion = source.glslVersion;
  7434. return this;
  7435. };
  7436. ShaderMaterial.prototype.toJSON = function (meta) {
  7437. var data = Material.prototype.toJSON.call(this, meta);
  7438. data.glslVersion = this.glslVersion;
  7439. data.uniforms = {};
  7440. for (var name in this.uniforms) {
  7441. var uniform = this.uniforms[name];
  7442. var value = uniform.value;
  7443. if (value && value.isTexture) {
  7444. data.uniforms[name] = {
  7445. type: 't',
  7446. value: value.toJSON(meta).uuid
  7447. };
  7448. } else if (value && value.isColor) {
  7449. data.uniforms[name] = {
  7450. type: 'c',
  7451. value: value.getHex()
  7452. };
  7453. } else if (value && value.isVector2) {
  7454. data.uniforms[name] = {
  7455. type: 'v2',
  7456. value: value.toArray()
  7457. };
  7458. } else if (value && value.isVector3) {
  7459. data.uniforms[name] = {
  7460. type: 'v3',
  7461. value: value.toArray()
  7462. };
  7463. } else if (value && value.isVector4) {
  7464. data.uniforms[name] = {
  7465. type: 'v4',
  7466. value: value.toArray()
  7467. };
  7468. } else if (value && value.isMatrix3) {
  7469. data.uniforms[name] = {
  7470. type: 'm3',
  7471. value: value.toArray()
  7472. };
  7473. } else if (value && value.isMatrix4) {
  7474. data.uniforms[name] = {
  7475. type: 'm4',
  7476. value: value.toArray()
  7477. };
  7478. } else {
  7479. data.uniforms[name] = {
  7480. value: value
  7481. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7482. }
  7483. }
  7484. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  7485. data.vertexShader = this.vertexShader;
  7486. data.fragmentShader = this.fragmentShader;
  7487. var extensions = {};
  7488. for (var key in this.extensions) {
  7489. if (this.extensions[key] === true) extensions[key] = true;
  7490. }
  7491. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  7492. return data;
  7493. };
  7494. function Camera() {
  7495. Object3D.call(this);
  7496. this.type = 'Camera';
  7497. this.matrixWorldInverse = new Matrix4();
  7498. this.projectionMatrix = new Matrix4();
  7499. this.projectionMatrixInverse = new Matrix4();
  7500. }
  7501. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  7502. constructor: Camera,
  7503. isCamera: true,
  7504. copy: function copy(source, recursive) {
  7505. Object3D.prototype.copy.call(this, source, recursive);
  7506. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  7507. this.projectionMatrix.copy(source.projectionMatrix);
  7508. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  7509. return this;
  7510. },
  7511. getWorldDirection: function getWorldDirection(target) {
  7512. if (target === undefined) {
  7513. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  7514. target = new Vector3();
  7515. }
  7516. this.updateMatrixWorld(true);
  7517. var e = this.matrixWorld.elements;
  7518. return target.set(-e[8], -e[9], -e[10]).normalize();
  7519. },
  7520. updateMatrixWorld: function updateMatrixWorld(force) {
  7521. Object3D.prototype.updateMatrixWorld.call(this, force);
  7522. this.matrixWorldInverse.getInverse(this.matrixWorld);
  7523. },
  7524. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  7525. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  7526. this.matrixWorldInverse.getInverse(this.matrixWorld);
  7527. },
  7528. clone: function clone() {
  7529. return new this.constructor().copy(this);
  7530. }
  7531. });
  7532. function PerspectiveCamera(fov, aspect, near, far) {
  7533. Camera.call(this);
  7534. this.type = 'PerspectiveCamera';
  7535. this.fov = fov !== undefined ? fov : 50;
  7536. this.zoom = 1;
  7537. this.near = near !== undefined ? near : 0.1;
  7538. this.far = far !== undefined ? far : 2000;
  7539. this.focus = 10;
  7540. this.aspect = aspect !== undefined ? aspect : 1;
  7541. this.view = null;
  7542. this.filmGauge = 35; // width of the film (default in millimeters)
  7543. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7544. this.updateProjectionMatrix();
  7545. }
  7546. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  7547. constructor: PerspectiveCamera,
  7548. isPerspectiveCamera: true,
  7549. copy: function copy(source, recursive) {
  7550. Camera.prototype.copy.call(this, source, recursive);
  7551. this.fov = source.fov;
  7552. this.zoom = source.zoom;
  7553. this.near = source.near;
  7554. this.far = source.far;
  7555. this.focus = source.focus;
  7556. this.aspect = source.aspect;
  7557. this.view = source.view === null ? null : Object.assign({}, source.view);
  7558. this.filmGauge = source.filmGauge;
  7559. this.filmOffset = source.filmOffset;
  7560. return this;
  7561. },
  7562. /**
  7563. * Sets the FOV by focal length in respect to the current .filmGauge.
  7564. *
  7565. * The default film gauge is 35, so that the focal length can be specified for
  7566. * a 35mm (full frame) camera.
  7567. *
  7568. * Values for focal length and film gauge must have the same unit.
  7569. */
  7570. setFocalLength: function setFocalLength(focalLength) {
  7571. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7572. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7573. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  7574. this.updateProjectionMatrix();
  7575. },
  7576. /**
  7577. * Calculates the focal length from the current .fov and .filmGauge.
  7578. */
  7579. getFocalLength: function getFocalLength() {
  7580. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  7581. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7582. },
  7583. getEffectiveFOV: function getEffectiveFOV() {
  7584. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  7585. },
  7586. getFilmWidth: function getFilmWidth() {
  7587. // film not completely covered in portrait format (aspect < 1)
  7588. return this.filmGauge * Math.min(this.aspect, 1);
  7589. },
  7590. getFilmHeight: function getFilmHeight() {
  7591. // film not completely covered in landscape format (aspect > 1)
  7592. return this.filmGauge / Math.max(this.aspect, 1);
  7593. },
  7594. /**
  7595. * Sets an offset in a larger frustum. This is useful for multi-window or
  7596. * multi-monitor/multi-machine setups.
  7597. *
  7598. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7599. * the monitors are in grid like this
  7600. *
  7601. * +---+---+---+
  7602. * | A | B | C |
  7603. * +---+---+---+
  7604. * | D | E | F |
  7605. * +---+---+---+
  7606. *
  7607. * then for each monitor you would call it like this
  7608. *
  7609. * const w = 1920;
  7610. * const h = 1080;
  7611. * const fullWidth = w * 3;
  7612. * const fullHeight = h * 2;
  7613. *
  7614. * --A--
  7615. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7616. * --B--
  7617. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7618. * --C--
  7619. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7620. * --D--
  7621. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7622. * --E--
  7623. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7624. * --F--
  7625. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7626. *
  7627. * Note there is no reason monitors have to be the same size or in a grid.
  7628. */
  7629. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  7630. this.aspect = fullWidth / fullHeight;
  7631. if (this.view === null) {
  7632. this.view = {
  7633. enabled: true,
  7634. fullWidth: 1,
  7635. fullHeight: 1,
  7636. offsetX: 0,
  7637. offsetY: 0,
  7638. width: 1,
  7639. height: 1
  7640. };
  7641. }
  7642. this.view.enabled = true;
  7643. this.view.fullWidth = fullWidth;
  7644. this.view.fullHeight = fullHeight;
  7645. this.view.offsetX = x;
  7646. this.view.offsetY = y;
  7647. this.view.width = width;
  7648. this.view.height = height;
  7649. this.updateProjectionMatrix();
  7650. },
  7651. clearViewOffset: function clearViewOffset() {
  7652. if (this.view !== null) {
  7653. this.view.enabled = false;
  7654. }
  7655. this.updateProjectionMatrix();
  7656. },
  7657. updateProjectionMatrix: function updateProjectionMatrix() {
  7658. var near = this.near;
  7659. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  7660. var height = 2 * top;
  7661. var width = this.aspect * height;
  7662. var left = -0.5 * width;
  7663. var view = this.view;
  7664. if (this.view !== null && this.view.enabled) {
  7665. var fullWidth = view.fullWidth,
  7666. fullHeight = view.fullHeight;
  7667. left += view.offsetX * width / fullWidth;
  7668. top -= view.offsetY * height / fullHeight;
  7669. width *= view.width / fullWidth;
  7670. height *= view.height / fullHeight;
  7671. }
  7672. var skew = this.filmOffset;
  7673. if (skew !== 0) left += near * skew / this.getFilmWidth();
  7674. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  7675. this.projectionMatrixInverse.getInverse(this.projectionMatrix);
  7676. },
  7677. toJSON: function toJSON(meta) {
  7678. var data = Object3D.prototype.toJSON.call(this, meta);
  7679. data.object.fov = this.fov;
  7680. data.object.zoom = this.zoom;
  7681. data.object.near = this.near;
  7682. data.object.far = this.far;
  7683. data.object.focus = this.focus;
  7684. data.object.aspect = this.aspect;
  7685. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  7686. data.object.filmGauge = this.filmGauge;
  7687. data.object.filmOffset = this.filmOffset;
  7688. return data;
  7689. }
  7690. });
  7691. var fov = 90,
  7692. aspect = 1;
  7693. function CubeCamera(near, far, renderTarget) {
  7694. Object3D.call(this);
  7695. this.type = 'CubeCamera';
  7696. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  7697. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  7698. return;
  7699. }
  7700. this.renderTarget = renderTarget;
  7701. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  7702. cameraPX.layers = this.layers;
  7703. cameraPX.up.set(0, -1, 0);
  7704. cameraPX.lookAt(new Vector3(1, 0, 0));
  7705. this.add(cameraPX);
  7706. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  7707. cameraNX.layers = this.layers;
  7708. cameraNX.up.set(0, -1, 0);
  7709. cameraNX.lookAt(new Vector3(-1, 0, 0));
  7710. this.add(cameraNX);
  7711. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  7712. cameraPY.layers = this.layers;
  7713. cameraPY.up.set(0, 0, 1);
  7714. cameraPY.lookAt(new Vector3(0, 1, 0));
  7715. this.add(cameraPY);
  7716. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  7717. cameraNY.layers = this.layers;
  7718. cameraNY.up.set(0, 0, -1);
  7719. cameraNY.lookAt(new Vector3(0, -1, 0));
  7720. this.add(cameraNY);
  7721. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  7722. cameraPZ.layers = this.layers;
  7723. cameraPZ.up.set(0, -1, 0);
  7724. cameraPZ.lookAt(new Vector3(0, 0, 1));
  7725. this.add(cameraPZ);
  7726. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  7727. cameraNZ.layers = this.layers;
  7728. cameraNZ.up.set(0, -1, 0);
  7729. cameraNZ.lookAt(new Vector3(0, 0, -1));
  7730. this.add(cameraNZ);
  7731. this.update = function (renderer, scene) {
  7732. if (this.parent === null) this.updateMatrixWorld();
  7733. var currentXrEnabled = renderer.xr.enabled;
  7734. var currentRenderTarget = renderer.getRenderTarget();
  7735. renderer.xr.enabled = false;
  7736. var generateMipmaps = renderTarget.texture.generateMipmaps;
  7737. renderTarget.texture.generateMipmaps = false;
  7738. renderer.setRenderTarget(renderTarget, 0);
  7739. renderer.render(scene, cameraPX);
  7740. renderer.setRenderTarget(renderTarget, 1);
  7741. renderer.render(scene, cameraNX);
  7742. renderer.setRenderTarget(renderTarget, 2);
  7743. renderer.render(scene, cameraPY);
  7744. renderer.setRenderTarget(renderTarget, 3);
  7745. renderer.render(scene, cameraNY);
  7746. renderer.setRenderTarget(renderTarget, 4);
  7747. renderer.render(scene, cameraPZ);
  7748. renderTarget.texture.generateMipmaps = generateMipmaps;
  7749. renderer.setRenderTarget(renderTarget, 5);
  7750. renderer.render(scene, cameraNZ);
  7751. renderer.setRenderTarget(currentRenderTarget);
  7752. renderer.xr.enabled = currentXrEnabled;
  7753. };
  7754. this.clear = function (renderer, color, depth, stencil) {
  7755. var currentRenderTarget = renderer.getRenderTarget();
  7756. for (var i = 0; i < 6; i++) {
  7757. renderer.setRenderTarget(renderTarget, i);
  7758. renderer.clear(color, depth, stencil);
  7759. }
  7760. renderer.setRenderTarget(currentRenderTarget);
  7761. };
  7762. }
  7763. CubeCamera.prototype = Object.create(Object3D.prototype);
  7764. CubeCamera.prototype.constructor = CubeCamera;
  7765. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  7766. images = images !== undefined ? images : [];
  7767. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7768. format = format !== undefined ? format : RGBFormat;
  7769. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  7770. this.flipY = false;
  7771. this._needsFlipEnvMap = true;
  7772. }
  7773. CubeTexture.prototype = Object.create(Texture.prototype);
  7774. CubeTexture.prototype.constructor = CubeTexture;
  7775. CubeTexture.prototype.isCubeTexture = true;
  7776. Object.defineProperty(CubeTexture.prototype, 'images', {
  7777. get: function get() {
  7778. return this.image;
  7779. },
  7780. set: function set(value) {
  7781. this.image = value;
  7782. }
  7783. });
  7784. function WebGLCubeRenderTarget(size, options, dummy) {
  7785. if (Number.isInteger(options)) {
  7786. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  7787. options = dummy;
  7788. }
  7789. WebGLRenderTarget.call(this, size, size, options);
  7790. options = options || {};
  7791. this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  7792. this.texture._needsFlipEnvMap = false;
  7793. }
  7794. WebGLCubeRenderTarget.prototype = Object.create(WebGLRenderTarget.prototype);
  7795. WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
  7796. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  7797. WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function (renderer, texture) {
  7798. this.texture.type = texture.type;
  7799. this.texture.format = RGBAFormat; // see #18859
  7800. this.texture.encoding = texture.encoding;
  7801. this.texture.generateMipmaps = texture.generateMipmaps;
  7802. this.texture.minFilter = texture.minFilter;
  7803. this.texture.magFilter = texture.magFilter;
  7804. var shader = {
  7805. uniforms: {
  7806. tEquirect: {
  7807. value: null
  7808. }
  7809. },
  7810. vertexShader:
  7811. /* glsl */
  7812. "\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",
  7813. fragmentShader:
  7814. /* glsl */
  7815. "\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"
  7816. };
  7817. var geometry = new BoxBufferGeometry(5, 5, 5);
  7818. var material = new ShaderMaterial({
  7819. name: 'CubemapFromEquirect',
  7820. uniforms: cloneUniforms(shader.uniforms),
  7821. vertexShader: shader.vertexShader,
  7822. fragmentShader: shader.fragmentShader,
  7823. side: BackSide,
  7824. blending: NoBlending
  7825. });
  7826. material.uniforms.tEquirect.value = texture;
  7827. var mesh = new Mesh(geometry, material);
  7828. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  7829. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  7830. var camera = new CubeCamera(1, 10, this);
  7831. camera.update(renderer, mesh);
  7832. texture.minFilter = currentMinFilter;
  7833. mesh.geometry.dispose();
  7834. mesh.material.dispose();
  7835. return this;
  7836. };
  7837. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  7838. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  7839. this.image = {
  7840. data: data || null,
  7841. width: width || 1,
  7842. height: height || 1
  7843. };
  7844. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  7845. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  7846. this.generateMipmaps = false;
  7847. this.flipY = false;
  7848. this.unpackAlignment = 1;
  7849. this.needsUpdate = true;
  7850. }
  7851. DataTexture.prototype = Object.create(Texture.prototype);
  7852. DataTexture.prototype.constructor = DataTexture;
  7853. DataTexture.prototype.isDataTexture = true;
  7854. var _sphere$1 = /*@__PURE__*/new Sphere();
  7855. var _vector$5 = /*@__PURE__*/new Vector3();
  7856. var Frustum = /*#__PURE__*/function () {
  7857. function Frustum(p0, p1, p2, p3, p4, p5) {
  7858. 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()];
  7859. }
  7860. var _proto = Frustum.prototype;
  7861. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  7862. var planes = this.planes;
  7863. planes[0].copy(p0);
  7864. planes[1].copy(p1);
  7865. planes[2].copy(p2);
  7866. planes[3].copy(p3);
  7867. planes[4].copy(p4);
  7868. planes[5].copy(p5);
  7869. return this;
  7870. };
  7871. _proto.clone = function clone() {
  7872. return new this.constructor().copy(this);
  7873. };
  7874. _proto.copy = function copy(frustum) {
  7875. var planes = this.planes;
  7876. for (var i = 0; i < 6; i++) {
  7877. planes[i].copy(frustum.planes[i]);
  7878. }
  7879. return this;
  7880. };
  7881. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  7882. var planes = this.planes;
  7883. var me = m.elements;
  7884. var me0 = me[0],
  7885. me1 = me[1],
  7886. me2 = me[2],
  7887. me3 = me[3];
  7888. var me4 = me[4],
  7889. me5 = me[5],
  7890. me6 = me[6],
  7891. me7 = me[7];
  7892. var me8 = me[8],
  7893. me9 = me[9],
  7894. me10 = me[10],
  7895. me11 = me[11];
  7896. var me12 = me[12],
  7897. me13 = me[13],
  7898. me14 = me[14],
  7899. me15 = me[15];
  7900. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  7901. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  7902. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  7903. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  7904. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  7905. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  7906. return this;
  7907. };
  7908. _proto.intersectsObject = function intersectsObject(object) {
  7909. var geometry = object.geometry;
  7910. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7911. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  7912. return this.intersectsSphere(_sphere$1);
  7913. };
  7914. _proto.intersectsSprite = function intersectsSprite(sprite) {
  7915. _sphere$1.center.set(0, 0, 0);
  7916. _sphere$1.radius = 0.7071067811865476;
  7917. _sphere$1.applyMatrix4(sprite.matrixWorld);
  7918. return this.intersectsSphere(_sphere$1);
  7919. };
  7920. _proto.intersectsSphere = function intersectsSphere(sphere) {
  7921. var planes = this.planes;
  7922. var center = sphere.center;
  7923. var negRadius = -sphere.radius;
  7924. for (var i = 0; i < 6; i++) {
  7925. var distance = planes[i].distanceToPoint(center);
  7926. if (distance < negRadius) {
  7927. return false;
  7928. }
  7929. }
  7930. return true;
  7931. };
  7932. _proto.intersectsBox = function intersectsBox(box) {
  7933. var planes = this.planes;
  7934. for (var i = 0; i < 6; i++) {
  7935. var plane = planes[i]; // corner at max distance
  7936. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  7937. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  7938. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  7939. if (plane.distanceToPoint(_vector$5) < 0) {
  7940. return false;
  7941. }
  7942. }
  7943. return true;
  7944. };
  7945. _proto.containsPoint = function containsPoint(point) {
  7946. var planes = this.planes;
  7947. for (var i = 0; i < 6; i++) {
  7948. if (planes[i].distanceToPoint(point) < 0) {
  7949. return false;
  7950. }
  7951. }
  7952. return true;
  7953. };
  7954. return Frustum;
  7955. }();
  7956. function WebGLAnimation() {
  7957. var context = null;
  7958. var isAnimating = false;
  7959. var animationLoop = null;
  7960. var requestId = null;
  7961. function onAnimationFrame(time, frame) {
  7962. animationLoop(time, frame);
  7963. requestId = context.requestAnimationFrame(onAnimationFrame);
  7964. }
  7965. return {
  7966. start: function start() {
  7967. if (isAnimating === true) return;
  7968. if (animationLoop === null) return;
  7969. requestId = context.requestAnimationFrame(onAnimationFrame);
  7970. isAnimating = true;
  7971. },
  7972. stop: function stop() {
  7973. context.cancelAnimationFrame(requestId);
  7974. isAnimating = false;
  7975. },
  7976. setAnimationLoop: function setAnimationLoop(callback) {
  7977. animationLoop = callback;
  7978. },
  7979. setContext: function setContext(value) {
  7980. context = value;
  7981. }
  7982. };
  7983. }
  7984. function WebGLAttributes(gl, capabilities) {
  7985. var isWebGL2 = capabilities.isWebGL2;
  7986. var buffers = new WeakMap();
  7987. function createBuffer(attribute, bufferType) {
  7988. var array = attribute.array;
  7989. var usage = attribute.usage;
  7990. var buffer = gl.createBuffer();
  7991. gl.bindBuffer(bufferType, buffer);
  7992. gl.bufferData(bufferType, array, usage);
  7993. attribute.onUploadCallback();
  7994. var type = 5126;
  7995. if (array instanceof Float32Array) {
  7996. type = 5126;
  7997. } else if (array instanceof Float64Array) {
  7998. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  7999. } else if (array instanceof Uint16Array) {
  8000. type = 5123;
  8001. } else if (array instanceof Int16Array) {
  8002. type = 5122;
  8003. } else if (array instanceof Uint32Array) {
  8004. type = 5125;
  8005. } else if (array instanceof Int32Array) {
  8006. type = 5124;
  8007. } else if (array instanceof Int8Array) {
  8008. type = 5120;
  8009. } else if (array instanceof Uint8Array) {
  8010. type = 5121;
  8011. }
  8012. return {
  8013. buffer: buffer,
  8014. type: type,
  8015. bytesPerElement: array.BYTES_PER_ELEMENT,
  8016. version: attribute.version
  8017. };
  8018. }
  8019. function updateBuffer(buffer, attribute, bufferType) {
  8020. var array = attribute.array;
  8021. var updateRange = attribute.updateRange;
  8022. gl.bindBuffer(bufferType, buffer);
  8023. if (updateRange.count === -1) {
  8024. // Not using update ranges
  8025. gl.bufferSubData(bufferType, 0, array);
  8026. } else {
  8027. if (isWebGL2) {
  8028. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8029. } else {
  8030. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8031. }
  8032. updateRange.count = -1; // reset range
  8033. }
  8034. } //
  8035. function get(attribute) {
  8036. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8037. return buffers.get(attribute);
  8038. }
  8039. function remove(attribute) {
  8040. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8041. var data = buffers.get(attribute);
  8042. if (data) {
  8043. gl.deleteBuffer(data.buffer);
  8044. buffers.delete(attribute);
  8045. }
  8046. }
  8047. function update(attribute, bufferType) {
  8048. if (attribute.isGLBufferAttribute) {
  8049. var cached = buffers.get(attribute);
  8050. if (!cached || cached.version < attribute.version) {
  8051. buffers.set(attribute, {
  8052. buffer: attribute.buffer,
  8053. type: attribute.type,
  8054. bytesPerElement: attribute.elementSize,
  8055. version: attribute.version
  8056. });
  8057. }
  8058. return;
  8059. }
  8060. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8061. var data = buffers.get(attribute);
  8062. if (data === undefined) {
  8063. buffers.set(attribute, createBuffer(attribute, bufferType));
  8064. } else if (data.version < attribute.version) {
  8065. updateBuffer(data.buffer, attribute, bufferType);
  8066. data.version = attribute.version;
  8067. }
  8068. }
  8069. return {
  8070. get: get,
  8071. remove: remove,
  8072. update: update
  8073. };
  8074. }
  8075. var PlaneBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8076. _inheritsLoose(PlaneBufferGeometry, _BufferGeometry);
  8077. function PlaneBufferGeometry(width, height, widthSegments, heightSegments) {
  8078. var _this;
  8079. _this = _BufferGeometry.call(this) || this;
  8080. _this.type = 'PlaneBufferGeometry';
  8081. _this.parameters = {
  8082. width: width,
  8083. height: height,
  8084. widthSegments: widthSegments,
  8085. heightSegments: heightSegments
  8086. };
  8087. width = width || 1;
  8088. height = height || 1;
  8089. var width_half = width / 2;
  8090. var height_half = height / 2;
  8091. var gridX = Math.floor(widthSegments) || 1;
  8092. var gridY = Math.floor(heightSegments) || 1;
  8093. var gridX1 = gridX + 1;
  8094. var gridY1 = gridY + 1;
  8095. var segment_width = width / gridX;
  8096. var segment_height = height / gridY; // buffers
  8097. var indices = [];
  8098. var vertices = [];
  8099. var normals = [];
  8100. var uvs = []; // generate vertices, normals and uvs
  8101. for (var iy = 0; iy < gridY1; iy++) {
  8102. var y = iy * segment_height - height_half;
  8103. for (var ix = 0; ix < gridX1; ix++) {
  8104. var x = ix * segment_width - width_half;
  8105. vertices.push(x, -y, 0);
  8106. normals.push(0, 0, 1);
  8107. uvs.push(ix / gridX);
  8108. uvs.push(1 - iy / gridY);
  8109. }
  8110. } // indices
  8111. for (var _iy = 0; _iy < gridY; _iy++) {
  8112. for (var _ix = 0; _ix < gridX; _ix++) {
  8113. var a = _ix + gridX1 * _iy;
  8114. var b = _ix + gridX1 * (_iy + 1);
  8115. var c = _ix + 1 + gridX1 * (_iy + 1);
  8116. var d = _ix + 1 + gridX1 * _iy; // faces
  8117. indices.push(a, b, d);
  8118. indices.push(b, c, d);
  8119. }
  8120. } // build geometry
  8121. _this.setIndex(indices);
  8122. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8123. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8124. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8125. return _this;
  8126. }
  8127. return PlaneBufferGeometry;
  8128. }(BufferGeometry);
  8129. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8130. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8131. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8132. 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";
  8133. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8134. var begin_vertex = "vec3 transformed = vec3( position );";
  8135. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8136. 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";
  8137. 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";
  8138. 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";
  8139. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8140. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8141. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8142. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8143. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8144. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8145. 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";
  8146. 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}";
  8147. 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";
  8148. 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";
  8149. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8150. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8151. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8152. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8153. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8154. 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}";
  8155. 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";
  8156. 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";
  8157. 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";
  8158. 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";
  8159. 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";
  8160. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8161. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8162. 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";
  8163. 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";
  8164. 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}";
  8165. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8166. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8167. 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";
  8168. 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";
  8169. 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";
  8170. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8171. 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)";
  8172. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8173. 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)";
  8174. 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";
  8175. 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}";
  8176. 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";
  8177. 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";
  8178. 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";
  8179. 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";
  8180. 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";
  8181. 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";
  8182. 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";
  8183. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8184. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8185. 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";
  8186. 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";
  8187. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8188. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8189. 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";
  8190. 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";
  8191. 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";
  8192. 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;";
  8193. 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";
  8194. 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";
  8195. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8196. 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";
  8197. 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";
  8198. 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}";
  8199. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8200. 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;";
  8201. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8202. 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";
  8203. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8204. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8205. 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";
  8206. 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";
  8207. 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";
  8208. 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}";
  8209. 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";
  8210. 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";
  8211. 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";
  8212. 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";
  8213. 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";
  8214. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8215. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8216. 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; }";
  8217. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8218. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8219. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8220. 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";
  8221. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8222. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8223. 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";
  8224. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8225. 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";
  8226. 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}";
  8227. 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}";
  8228. 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}";
  8229. 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}";
  8230. 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}";
  8231. 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}";
  8232. 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}";
  8233. 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}";
  8234. 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}";
  8235. 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}";
  8236. 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}";
  8237. 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}";
  8238. 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}";
  8239. 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}";
  8240. 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}";
  8241. 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}";
  8242. 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}";
  8243. 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}";
  8244. 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}";
  8245. 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}";
  8246. 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}";
  8247. 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}";
  8248. 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}";
  8249. 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}";
  8250. 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}";
  8251. 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}";
  8252. 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}";
  8253. 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}";
  8254. 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}";
  8255. 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}";
  8256. 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}";
  8257. 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}";
  8258. var ShaderChunk = {
  8259. alphamap_fragment: alphamap_fragment,
  8260. alphamap_pars_fragment: alphamap_pars_fragment,
  8261. alphatest_fragment: alphatest_fragment,
  8262. aomap_fragment: aomap_fragment,
  8263. aomap_pars_fragment: aomap_pars_fragment,
  8264. begin_vertex: begin_vertex,
  8265. beginnormal_vertex: beginnormal_vertex,
  8266. bsdfs: bsdfs,
  8267. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8268. clipping_planes_fragment: clipping_planes_fragment,
  8269. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8270. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8271. clipping_planes_vertex: clipping_planes_vertex,
  8272. color_fragment: color_fragment,
  8273. color_pars_fragment: color_pars_fragment,
  8274. color_pars_vertex: color_pars_vertex,
  8275. color_vertex: color_vertex,
  8276. common: common,
  8277. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8278. defaultnormal_vertex: defaultnormal_vertex,
  8279. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8280. displacementmap_vertex: displacementmap_vertex,
  8281. emissivemap_fragment: emissivemap_fragment,
  8282. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8283. encodings_fragment: encodings_fragment,
  8284. encodings_pars_fragment: encodings_pars_fragment,
  8285. envmap_fragment: envmap_fragment,
  8286. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8287. envmap_pars_fragment: envmap_pars_fragment,
  8288. envmap_pars_vertex: envmap_pars_vertex,
  8289. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8290. envmap_vertex: envmap_vertex,
  8291. fog_vertex: fog_vertex,
  8292. fog_pars_vertex: fog_pars_vertex,
  8293. fog_fragment: fog_fragment,
  8294. fog_pars_fragment: fog_pars_fragment,
  8295. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8296. lightmap_fragment: lightmap_fragment,
  8297. lightmap_pars_fragment: lightmap_pars_fragment,
  8298. lights_lambert_vertex: lights_lambert_vertex,
  8299. lights_pars_begin: lights_pars_begin,
  8300. lights_toon_fragment: lights_toon_fragment,
  8301. lights_toon_pars_fragment: lights_toon_pars_fragment,
  8302. lights_phong_fragment: lights_phong_fragment,
  8303. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8304. lights_physical_fragment: lights_physical_fragment,
  8305. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8306. lights_fragment_begin: lights_fragment_begin,
  8307. lights_fragment_maps: lights_fragment_maps,
  8308. lights_fragment_end: lights_fragment_end,
  8309. logdepthbuf_fragment: logdepthbuf_fragment,
  8310. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8311. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8312. logdepthbuf_vertex: logdepthbuf_vertex,
  8313. map_fragment: map_fragment,
  8314. map_pars_fragment: map_pars_fragment,
  8315. map_particle_fragment: map_particle_fragment,
  8316. map_particle_pars_fragment: map_particle_pars_fragment,
  8317. metalnessmap_fragment: metalnessmap_fragment,
  8318. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  8319. morphnormal_vertex: morphnormal_vertex,
  8320. morphtarget_pars_vertex: morphtarget_pars_vertex,
  8321. morphtarget_vertex: morphtarget_vertex,
  8322. normal_fragment_begin: normal_fragment_begin,
  8323. normal_fragment_maps: normal_fragment_maps,
  8324. normalmap_pars_fragment: normalmap_pars_fragment,
  8325. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  8326. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  8327. clearcoat_pars_fragment: clearcoat_pars_fragment,
  8328. packing: packing,
  8329. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  8330. project_vertex: project_vertex,
  8331. dithering_fragment: dithering_fragment,
  8332. dithering_pars_fragment: dithering_pars_fragment,
  8333. roughnessmap_fragment: roughnessmap_fragment,
  8334. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  8335. shadowmap_pars_fragment: shadowmap_pars_fragment,
  8336. shadowmap_pars_vertex: shadowmap_pars_vertex,
  8337. shadowmap_vertex: shadowmap_vertex,
  8338. shadowmask_pars_fragment: shadowmask_pars_fragment,
  8339. skinbase_vertex: skinbase_vertex,
  8340. skinning_pars_vertex: skinning_pars_vertex,
  8341. skinning_vertex: skinning_vertex,
  8342. skinnormal_vertex: skinnormal_vertex,
  8343. specularmap_fragment: specularmap_fragment,
  8344. specularmap_pars_fragment: specularmap_pars_fragment,
  8345. tonemapping_fragment: tonemapping_fragment,
  8346. tonemapping_pars_fragment: tonemapping_pars_fragment,
  8347. transmissionmap_fragment: transmissionmap_fragment,
  8348. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  8349. uv_pars_fragment: uv_pars_fragment,
  8350. uv_pars_vertex: uv_pars_vertex,
  8351. uv_vertex: uv_vertex,
  8352. uv2_pars_fragment: uv2_pars_fragment,
  8353. uv2_pars_vertex: uv2_pars_vertex,
  8354. uv2_vertex: uv2_vertex,
  8355. worldpos_vertex: worldpos_vertex,
  8356. background_frag: background_frag,
  8357. background_vert: background_vert,
  8358. cube_frag: cube_frag,
  8359. cube_vert: cube_vert,
  8360. depth_frag: depth_frag,
  8361. depth_vert: depth_vert,
  8362. distanceRGBA_frag: distanceRGBA_frag,
  8363. distanceRGBA_vert: distanceRGBA_vert,
  8364. equirect_frag: equirect_frag,
  8365. equirect_vert: equirect_vert,
  8366. linedashed_frag: linedashed_frag,
  8367. linedashed_vert: linedashed_vert,
  8368. meshbasic_frag: meshbasic_frag,
  8369. meshbasic_vert: meshbasic_vert,
  8370. meshlambert_frag: meshlambert_frag,
  8371. meshlambert_vert: meshlambert_vert,
  8372. meshmatcap_frag: meshmatcap_frag,
  8373. meshmatcap_vert: meshmatcap_vert,
  8374. meshtoon_frag: meshtoon_frag,
  8375. meshtoon_vert: meshtoon_vert,
  8376. meshphong_frag: meshphong_frag,
  8377. meshphong_vert: meshphong_vert,
  8378. meshphysical_frag: meshphysical_frag,
  8379. meshphysical_vert: meshphysical_vert,
  8380. normal_frag: normal_frag,
  8381. normal_vert: normal_vert,
  8382. points_frag: points_frag,
  8383. points_vert: points_vert,
  8384. shadow_frag: shadow_frag,
  8385. shadow_vert: shadow_vert,
  8386. sprite_frag: sprite_frag,
  8387. sprite_vert: sprite_vert
  8388. };
  8389. /**
  8390. * Uniforms library for shared webgl shaders
  8391. */
  8392. var UniformsLib = {
  8393. common: {
  8394. diffuse: {
  8395. value: new Color(0xeeeeee)
  8396. },
  8397. opacity: {
  8398. value: 1.0
  8399. },
  8400. map: {
  8401. value: null
  8402. },
  8403. uvTransform: {
  8404. value: new Matrix3()
  8405. },
  8406. uv2Transform: {
  8407. value: new Matrix3()
  8408. },
  8409. alphaMap: {
  8410. value: null
  8411. }
  8412. },
  8413. specularmap: {
  8414. specularMap: {
  8415. value: null
  8416. }
  8417. },
  8418. envmap: {
  8419. envMap: {
  8420. value: null
  8421. },
  8422. flipEnvMap: {
  8423. value: -1
  8424. },
  8425. reflectivity: {
  8426. value: 1.0
  8427. },
  8428. refractionRatio: {
  8429. value: 0.98
  8430. },
  8431. maxMipLevel: {
  8432. value: 0
  8433. }
  8434. },
  8435. aomap: {
  8436. aoMap: {
  8437. value: null
  8438. },
  8439. aoMapIntensity: {
  8440. value: 1
  8441. }
  8442. },
  8443. lightmap: {
  8444. lightMap: {
  8445. value: null
  8446. },
  8447. lightMapIntensity: {
  8448. value: 1
  8449. }
  8450. },
  8451. emissivemap: {
  8452. emissiveMap: {
  8453. value: null
  8454. }
  8455. },
  8456. bumpmap: {
  8457. bumpMap: {
  8458. value: null
  8459. },
  8460. bumpScale: {
  8461. value: 1
  8462. }
  8463. },
  8464. normalmap: {
  8465. normalMap: {
  8466. value: null
  8467. },
  8468. normalScale: {
  8469. value: new Vector2(1, 1)
  8470. }
  8471. },
  8472. displacementmap: {
  8473. displacementMap: {
  8474. value: null
  8475. },
  8476. displacementScale: {
  8477. value: 1
  8478. },
  8479. displacementBias: {
  8480. value: 0
  8481. }
  8482. },
  8483. roughnessmap: {
  8484. roughnessMap: {
  8485. value: null
  8486. }
  8487. },
  8488. metalnessmap: {
  8489. metalnessMap: {
  8490. value: null
  8491. }
  8492. },
  8493. gradientmap: {
  8494. gradientMap: {
  8495. value: null
  8496. }
  8497. },
  8498. fog: {
  8499. fogDensity: {
  8500. value: 0.00025
  8501. },
  8502. fogNear: {
  8503. value: 1
  8504. },
  8505. fogFar: {
  8506. value: 2000
  8507. },
  8508. fogColor: {
  8509. value: new Color(0xffffff)
  8510. }
  8511. },
  8512. lights: {
  8513. ambientLightColor: {
  8514. value: []
  8515. },
  8516. lightProbe: {
  8517. value: []
  8518. },
  8519. directionalLights: {
  8520. value: [],
  8521. properties: {
  8522. direction: {},
  8523. color: {}
  8524. }
  8525. },
  8526. directionalLightShadows: {
  8527. value: [],
  8528. properties: {
  8529. shadowBias: {},
  8530. shadowNormalBias: {},
  8531. shadowRadius: {},
  8532. shadowMapSize: {}
  8533. }
  8534. },
  8535. directionalShadowMap: {
  8536. value: []
  8537. },
  8538. directionalShadowMatrix: {
  8539. value: []
  8540. },
  8541. spotLights: {
  8542. value: [],
  8543. properties: {
  8544. color: {},
  8545. position: {},
  8546. direction: {},
  8547. distance: {},
  8548. coneCos: {},
  8549. penumbraCos: {},
  8550. decay: {}
  8551. }
  8552. },
  8553. spotLightShadows: {
  8554. value: [],
  8555. properties: {
  8556. shadowBias: {},
  8557. shadowNormalBias: {},
  8558. shadowRadius: {},
  8559. shadowMapSize: {}
  8560. }
  8561. },
  8562. spotShadowMap: {
  8563. value: []
  8564. },
  8565. spotShadowMatrix: {
  8566. value: []
  8567. },
  8568. pointLights: {
  8569. value: [],
  8570. properties: {
  8571. color: {},
  8572. position: {},
  8573. decay: {},
  8574. distance: {}
  8575. }
  8576. },
  8577. pointLightShadows: {
  8578. value: [],
  8579. properties: {
  8580. shadowBias: {},
  8581. shadowNormalBias: {},
  8582. shadowRadius: {},
  8583. shadowMapSize: {},
  8584. shadowCameraNear: {},
  8585. shadowCameraFar: {}
  8586. }
  8587. },
  8588. pointShadowMap: {
  8589. value: []
  8590. },
  8591. pointShadowMatrix: {
  8592. value: []
  8593. },
  8594. hemisphereLights: {
  8595. value: [],
  8596. properties: {
  8597. direction: {},
  8598. skyColor: {},
  8599. groundColor: {}
  8600. }
  8601. },
  8602. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8603. rectAreaLights: {
  8604. value: [],
  8605. properties: {
  8606. color: {},
  8607. position: {},
  8608. width: {},
  8609. height: {}
  8610. }
  8611. },
  8612. ltc_1: {
  8613. value: null
  8614. },
  8615. ltc_2: {
  8616. value: null
  8617. }
  8618. },
  8619. points: {
  8620. diffuse: {
  8621. value: new Color(0xeeeeee)
  8622. },
  8623. opacity: {
  8624. value: 1.0
  8625. },
  8626. size: {
  8627. value: 1.0
  8628. },
  8629. scale: {
  8630. value: 1.0
  8631. },
  8632. map: {
  8633. value: null
  8634. },
  8635. alphaMap: {
  8636. value: null
  8637. },
  8638. uvTransform: {
  8639. value: new Matrix3()
  8640. }
  8641. },
  8642. sprite: {
  8643. diffuse: {
  8644. value: new Color(0xeeeeee)
  8645. },
  8646. opacity: {
  8647. value: 1.0
  8648. },
  8649. center: {
  8650. value: new Vector2(0.5, 0.5)
  8651. },
  8652. rotation: {
  8653. value: 0.0
  8654. },
  8655. map: {
  8656. value: null
  8657. },
  8658. alphaMap: {
  8659. value: null
  8660. },
  8661. uvTransform: {
  8662. value: new Matrix3()
  8663. }
  8664. }
  8665. };
  8666. var ShaderLib = {
  8667. basic: {
  8668. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  8669. vertexShader: ShaderChunk.meshbasic_vert,
  8670. fragmentShader: ShaderChunk.meshbasic_frag
  8671. },
  8672. lambert: {
  8673. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  8674. emissive: {
  8675. value: new Color(0x000000)
  8676. }
  8677. }]),
  8678. vertexShader: ShaderChunk.meshlambert_vert,
  8679. fragmentShader: ShaderChunk.meshlambert_frag
  8680. },
  8681. phong: {
  8682. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  8683. emissive: {
  8684. value: new Color(0x000000)
  8685. },
  8686. specular: {
  8687. value: new Color(0x111111)
  8688. },
  8689. shininess: {
  8690. value: 30
  8691. }
  8692. }]),
  8693. vertexShader: ShaderChunk.meshphong_vert,
  8694. fragmentShader: ShaderChunk.meshphong_frag
  8695. },
  8696. standard: {
  8697. 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, {
  8698. emissive: {
  8699. value: new Color(0x000000)
  8700. },
  8701. roughness: {
  8702. value: 1.0
  8703. },
  8704. metalness: {
  8705. value: 0.0
  8706. },
  8707. envMapIntensity: {
  8708. value: 1
  8709. } // temporary
  8710. }]),
  8711. vertexShader: ShaderChunk.meshphysical_vert,
  8712. fragmentShader: ShaderChunk.meshphysical_frag
  8713. },
  8714. toon: {
  8715. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  8716. emissive: {
  8717. value: new Color(0x000000)
  8718. }
  8719. }]),
  8720. vertexShader: ShaderChunk.meshtoon_vert,
  8721. fragmentShader: ShaderChunk.meshtoon_frag
  8722. },
  8723. matcap: {
  8724. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  8725. matcap: {
  8726. value: null
  8727. }
  8728. }]),
  8729. vertexShader: ShaderChunk.meshmatcap_vert,
  8730. fragmentShader: ShaderChunk.meshmatcap_frag
  8731. },
  8732. points: {
  8733. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  8734. vertexShader: ShaderChunk.points_vert,
  8735. fragmentShader: ShaderChunk.points_frag
  8736. },
  8737. dashed: {
  8738. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  8739. scale: {
  8740. value: 1
  8741. },
  8742. dashSize: {
  8743. value: 1
  8744. },
  8745. totalSize: {
  8746. value: 2
  8747. }
  8748. }]),
  8749. vertexShader: ShaderChunk.linedashed_vert,
  8750. fragmentShader: ShaderChunk.linedashed_frag
  8751. },
  8752. depth: {
  8753. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  8754. vertexShader: ShaderChunk.depth_vert,
  8755. fragmentShader: ShaderChunk.depth_frag
  8756. },
  8757. normal: {
  8758. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  8759. opacity: {
  8760. value: 1.0
  8761. }
  8762. }]),
  8763. vertexShader: ShaderChunk.normal_vert,
  8764. fragmentShader: ShaderChunk.normal_frag
  8765. },
  8766. sprite: {
  8767. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  8768. vertexShader: ShaderChunk.sprite_vert,
  8769. fragmentShader: ShaderChunk.sprite_frag
  8770. },
  8771. background: {
  8772. uniforms: {
  8773. uvTransform: {
  8774. value: new Matrix3()
  8775. },
  8776. t2D: {
  8777. value: null
  8778. }
  8779. },
  8780. vertexShader: ShaderChunk.background_vert,
  8781. fragmentShader: ShaderChunk.background_frag
  8782. },
  8783. /* -------------------------------------------------------------------------
  8784. // Cube map shader
  8785. ------------------------------------------------------------------------- */
  8786. cube: {
  8787. uniforms: mergeUniforms([UniformsLib.envmap, {
  8788. opacity: {
  8789. value: 1.0
  8790. }
  8791. }]),
  8792. vertexShader: ShaderChunk.cube_vert,
  8793. fragmentShader: ShaderChunk.cube_frag
  8794. },
  8795. equirect: {
  8796. uniforms: {
  8797. tEquirect: {
  8798. value: null
  8799. }
  8800. },
  8801. vertexShader: ShaderChunk.equirect_vert,
  8802. fragmentShader: ShaderChunk.equirect_frag
  8803. },
  8804. distanceRGBA: {
  8805. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  8806. referencePosition: {
  8807. value: new Vector3()
  8808. },
  8809. nearDistance: {
  8810. value: 1
  8811. },
  8812. farDistance: {
  8813. value: 1000
  8814. }
  8815. }]),
  8816. vertexShader: ShaderChunk.distanceRGBA_vert,
  8817. fragmentShader: ShaderChunk.distanceRGBA_frag
  8818. },
  8819. shadow: {
  8820. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  8821. color: {
  8822. value: new Color(0x00000)
  8823. },
  8824. opacity: {
  8825. value: 1.0
  8826. }
  8827. }]),
  8828. vertexShader: ShaderChunk.shadow_vert,
  8829. fragmentShader: ShaderChunk.shadow_frag
  8830. }
  8831. };
  8832. ShaderLib.physical = {
  8833. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  8834. clearcoat: {
  8835. value: 0
  8836. },
  8837. clearcoatMap: {
  8838. value: null
  8839. },
  8840. clearcoatRoughness: {
  8841. value: 0
  8842. },
  8843. clearcoatRoughnessMap: {
  8844. value: null
  8845. },
  8846. clearcoatNormalScale: {
  8847. value: new Vector2(1, 1)
  8848. },
  8849. clearcoatNormalMap: {
  8850. value: null
  8851. },
  8852. sheen: {
  8853. value: new Color(0x000000)
  8854. },
  8855. transmission: {
  8856. value: 0
  8857. },
  8858. transmissionMap: {
  8859. value: null
  8860. }
  8861. }]),
  8862. vertexShader: ShaderChunk.meshphysical_vert,
  8863. fragmentShader: ShaderChunk.meshphysical_frag
  8864. };
  8865. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  8866. var clearColor = new Color(0x000000);
  8867. var clearAlpha = 0;
  8868. var planeMesh;
  8869. var boxMesh;
  8870. var currentBackground = null;
  8871. var currentBackgroundVersion = 0;
  8872. var currentTonemapping = null;
  8873. function render(renderList, scene, camera, forceClear) {
  8874. var background = scene.isScene === true ? scene.background : null;
  8875. if (background && background.isTexture) {
  8876. background = cubemaps.get(background);
  8877. } // Ignore background in AR
  8878. // TODO: Reconsider this.
  8879. var xr = renderer.xr;
  8880. var session = xr.getSession && xr.getSession();
  8881. if (session && session.environmentBlendMode === 'additive') {
  8882. background = null;
  8883. }
  8884. if (background === null) {
  8885. setClear(clearColor, clearAlpha);
  8886. } else if (background && background.isColor) {
  8887. setClear(background, 1);
  8888. forceClear = true;
  8889. }
  8890. if (renderer.autoClear || forceClear) {
  8891. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  8892. }
  8893. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  8894. if (boxMesh === undefined) {
  8895. boxMesh = new Mesh(new BoxBufferGeometry(1, 1, 1), new ShaderMaterial({
  8896. name: 'BackgroundCubeMaterial',
  8897. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  8898. vertexShader: ShaderLib.cube.vertexShader,
  8899. fragmentShader: ShaderLib.cube.fragmentShader,
  8900. side: BackSide,
  8901. depthTest: false,
  8902. depthWrite: false,
  8903. fog: false
  8904. }));
  8905. boxMesh.geometry.deleteAttribute('normal');
  8906. boxMesh.geometry.deleteAttribute('uv');
  8907. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  8908. this.matrixWorld.copyPosition(camera.matrixWorld);
  8909. }; // enable code injection for non-built-in material
  8910. Object.defineProperty(boxMesh.material, 'envMap', {
  8911. get: function get() {
  8912. return this.uniforms.envMap.value;
  8913. }
  8914. });
  8915. objects.update(boxMesh);
  8916. }
  8917. if (background.isWebGLCubeRenderTarget) {
  8918. // TODO Deprecate
  8919. background = background.texture;
  8920. }
  8921. boxMesh.material.uniforms.envMap.value = background;
  8922. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  8923. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  8924. boxMesh.material.needsUpdate = true;
  8925. currentBackground = background;
  8926. currentBackgroundVersion = background.version;
  8927. currentTonemapping = renderer.toneMapping;
  8928. } // push to the pre-sorted opaque render list
  8929. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  8930. } else if (background && background.isTexture) {
  8931. if (planeMesh === undefined) {
  8932. planeMesh = new Mesh(new PlaneBufferGeometry(2, 2), new ShaderMaterial({
  8933. name: 'BackgroundMaterial',
  8934. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  8935. vertexShader: ShaderLib.background.vertexShader,
  8936. fragmentShader: ShaderLib.background.fragmentShader,
  8937. side: FrontSide,
  8938. depthTest: false,
  8939. depthWrite: false,
  8940. fog: false
  8941. }));
  8942. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  8943. Object.defineProperty(planeMesh.material, 'map', {
  8944. get: function get() {
  8945. return this.uniforms.t2D.value;
  8946. }
  8947. });
  8948. objects.update(planeMesh);
  8949. }
  8950. planeMesh.material.uniforms.t2D.value = background;
  8951. if (background.matrixAutoUpdate === true) {
  8952. background.updateMatrix();
  8953. }
  8954. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  8955. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  8956. planeMesh.material.needsUpdate = true;
  8957. currentBackground = background;
  8958. currentBackgroundVersion = background.version;
  8959. currentTonemapping = renderer.toneMapping;
  8960. } // push to the pre-sorted opaque render list
  8961. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  8962. }
  8963. }
  8964. function setClear(color, alpha) {
  8965. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  8966. }
  8967. return {
  8968. getClearColor: function getClearColor() {
  8969. return clearColor;
  8970. },
  8971. setClearColor: function setClearColor(color, alpha) {
  8972. clearColor.set(color);
  8973. clearAlpha = alpha !== undefined ? alpha : 1;
  8974. setClear(clearColor, clearAlpha);
  8975. },
  8976. getClearAlpha: function getClearAlpha() {
  8977. return clearAlpha;
  8978. },
  8979. setClearAlpha: function setClearAlpha(alpha) {
  8980. clearAlpha = alpha;
  8981. setClear(clearColor, clearAlpha);
  8982. },
  8983. render: render
  8984. };
  8985. }
  8986. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  8987. var maxVertexAttributes = gl.getParameter(34921);
  8988. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  8989. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  8990. var bindingStates = {};
  8991. var defaultState = createBindingState(null);
  8992. var currentState = defaultState;
  8993. function setup(object, material, program, geometry, index) {
  8994. var updateBuffers = false;
  8995. if (vaoAvailable) {
  8996. var state = getBindingState(geometry, program, material);
  8997. if (currentState !== state) {
  8998. currentState = state;
  8999. bindVertexArrayObject(currentState.object);
  9000. }
  9001. updateBuffers = needsUpdate(geometry, index);
  9002. if (updateBuffers) saveCache(geometry, index);
  9003. } else {
  9004. var wireframe = material.wireframe === true;
  9005. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9006. currentState.geometry = geometry.id;
  9007. currentState.program = program.id;
  9008. currentState.wireframe = wireframe;
  9009. updateBuffers = true;
  9010. }
  9011. }
  9012. if (object.isInstancedMesh === true) {
  9013. updateBuffers = true;
  9014. }
  9015. if (index !== null) {
  9016. attributes.update(index, 34963);
  9017. }
  9018. if (updateBuffers) {
  9019. setupVertexAttributes(object, material, program, geometry);
  9020. if (index !== null) {
  9021. gl.bindBuffer(34963, attributes.get(index).buffer);
  9022. }
  9023. }
  9024. }
  9025. function createVertexArrayObject() {
  9026. if (capabilities.isWebGL2) return gl.createVertexArray();
  9027. return extension.createVertexArrayOES();
  9028. }
  9029. function bindVertexArrayObject(vao) {
  9030. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9031. return extension.bindVertexArrayOES(vao);
  9032. }
  9033. function deleteVertexArrayObject(vao) {
  9034. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9035. return extension.deleteVertexArrayOES(vao);
  9036. }
  9037. function getBindingState(geometry, program, material) {
  9038. var wireframe = material.wireframe === true;
  9039. var programMap = bindingStates[geometry.id];
  9040. if (programMap === undefined) {
  9041. programMap = {};
  9042. bindingStates[geometry.id] = programMap;
  9043. }
  9044. var stateMap = programMap[program.id];
  9045. if (stateMap === undefined) {
  9046. stateMap = {};
  9047. programMap[program.id] = stateMap;
  9048. }
  9049. var state = stateMap[wireframe];
  9050. if (state === undefined) {
  9051. state = createBindingState(createVertexArrayObject());
  9052. stateMap[wireframe] = state;
  9053. }
  9054. return state;
  9055. }
  9056. function createBindingState(vao) {
  9057. var newAttributes = [];
  9058. var enabledAttributes = [];
  9059. var attributeDivisors = [];
  9060. for (var i = 0; i < maxVertexAttributes; i++) {
  9061. newAttributes[i] = 0;
  9062. enabledAttributes[i] = 0;
  9063. attributeDivisors[i] = 0;
  9064. }
  9065. return {
  9066. // for backward compatibility on non-VAO support browser
  9067. geometry: null,
  9068. program: null,
  9069. wireframe: false,
  9070. newAttributes: newAttributes,
  9071. enabledAttributes: enabledAttributes,
  9072. attributeDivisors: attributeDivisors,
  9073. object: vao,
  9074. attributes: {},
  9075. index: null
  9076. };
  9077. }
  9078. function needsUpdate(geometry, index) {
  9079. var cachedAttributes = currentState.attributes;
  9080. var geometryAttributes = geometry.attributes;
  9081. if (Object.keys(cachedAttributes).length !== Object.keys(geometryAttributes).length) return true;
  9082. for (var key in geometryAttributes) {
  9083. var cachedAttribute = cachedAttributes[key];
  9084. var geometryAttribute = geometryAttributes[key];
  9085. if (cachedAttribute === undefined) return true;
  9086. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9087. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9088. }
  9089. if (currentState.index !== index) return true;
  9090. return false;
  9091. }
  9092. function saveCache(geometry, index) {
  9093. var cache = {};
  9094. var attributes = geometry.attributes;
  9095. for (var key in attributes) {
  9096. var attribute = attributes[key];
  9097. var data = {};
  9098. data.attribute = attribute;
  9099. if (attribute.data) {
  9100. data.data = attribute.data;
  9101. }
  9102. cache[key] = data;
  9103. }
  9104. currentState.attributes = cache;
  9105. currentState.index = index;
  9106. }
  9107. function initAttributes() {
  9108. var newAttributes = currentState.newAttributes;
  9109. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9110. newAttributes[i] = 0;
  9111. }
  9112. }
  9113. function enableAttribute(attribute) {
  9114. enableAttributeAndDivisor(attribute, 0);
  9115. }
  9116. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9117. var newAttributes = currentState.newAttributes;
  9118. var enabledAttributes = currentState.enabledAttributes;
  9119. var attributeDivisors = currentState.attributeDivisors;
  9120. newAttributes[attribute] = 1;
  9121. if (enabledAttributes[attribute] === 0) {
  9122. gl.enableVertexAttribArray(attribute);
  9123. enabledAttributes[attribute] = 1;
  9124. }
  9125. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9126. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9127. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9128. attributeDivisors[attribute] = meshPerAttribute;
  9129. }
  9130. }
  9131. function disableUnusedAttributes() {
  9132. var newAttributes = currentState.newAttributes;
  9133. var enabledAttributes = currentState.enabledAttributes;
  9134. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9135. if (enabledAttributes[i] !== newAttributes[i]) {
  9136. gl.disableVertexAttribArray(i);
  9137. enabledAttributes[i] = 0;
  9138. }
  9139. }
  9140. }
  9141. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9142. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9143. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9144. } else {
  9145. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9146. }
  9147. }
  9148. function setupVertexAttributes(object, material, program, geometry) {
  9149. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9150. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9151. }
  9152. initAttributes();
  9153. var geometryAttributes = geometry.attributes;
  9154. var programAttributes = program.getAttributes();
  9155. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9156. for (var name in programAttributes) {
  9157. var programAttribute = programAttributes[name];
  9158. if (programAttribute >= 0) {
  9159. var geometryAttribute = geometryAttributes[name];
  9160. if (geometryAttribute !== undefined) {
  9161. var normalized = geometryAttribute.normalized;
  9162. var size = geometryAttribute.itemSize;
  9163. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9164. if (attribute === undefined) continue;
  9165. var buffer = attribute.buffer;
  9166. var type = attribute.type;
  9167. var bytesPerElement = attribute.bytesPerElement;
  9168. if (geometryAttribute.isInterleavedBufferAttribute) {
  9169. var data = geometryAttribute.data;
  9170. var stride = data.stride;
  9171. var offset = geometryAttribute.offset;
  9172. if (data && data.isInstancedInterleavedBuffer) {
  9173. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9174. if (geometry._maxInstanceCount === undefined) {
  9175. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9176. }
  9177. } else {
  9178. enableAttribute(programAttribute);
  9179. }
  9180. gl.bindBuffer(34962, buffer);
  9181. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9182. } else {
  9183. if (geometryAttribute.isInstancedBufferAttribute) {
  9184. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9185. if (geometry._maxInstanceCount === undefined) {
  9186. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9187. }
  9188. } else {
  9189. enableAttribute(programAttribute);
  9190. }
  9191. gl.bindBuffer(34962, buffer);
  9192. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9193. }
  9194. } else if (name === 'instanceMatrix') {
  9195. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9196. if (_attribute === undefined) continue;
  9197. var _buffer = _attribute.buffer;
  9198. var _type = _attribute.type;
  9199. enableAttributeAndDivisor(programAttribute + 0, 1);
  9200. enableAttributeAndDivisor(programAttribute + 1, 1);
  9201. enableAttributeAndDivisor(programAttribute + 2, 1);
  9202. enableAttributeAndDivisor(programAttribute + 3, 1);
  9203. gl.bindBuffer(34962, _buffer);
  9204. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9205. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9206. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9207. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9208. } else if (name === 'instanceColor') {
  9209. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9210. if (_attribute2 === undefined) continue;
  9211. var _buffer2 = _attribute2.buffer;
  9212. var _type2 = _attribute2.type;
  9213. enableAttributeAndDivisor(programAttribute, 1);
  9214. gl.bindBuffer(34962, _buffer2);
  9215. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9216. } else if (materialDefaultAttributeValues !== undefined) {
  9217. var value = materialDefaultAttributeValues[name];
  9218. if (value !== undefined) {
  9219. switch (value.length) {
  9220. case 2:
  9221. gl.vertexAttrib2fv(programAttribute, value);
  9222. break;
  9223. case 3:
  9224. gl.vertexAttrib3fv(programAttribute, value);
  9225. break;
  9226. case 4:
  9227. gl.vertexAttrib4fv(programAttribute, value);
  9228. break;
  9229. default:
  9230. gl.vertexAttrib1fv(programAttribute, value);
  9231. }
  9232. }
  9233. }
  9234. }
  9235. }
  9236. disableUnusedAttributes();
  9237. }
  9238. function dispose() {
  9239. reset();
  9240. for (var geometryId in bindingStates) {
  9241. var programMap = bindingStates[geometryId];
  9242. for (var programId in programMap) {
  9243. var stateMap = programMap[programId];
  9244. for (var wireframe in stateMap) {
  9245. deleteVertexArrayObject(stateMap[wireframe].object);
  9246. delete stateMap[wireframe];
  9247. }
  9248. delete programMap[programId];
  9249. }
  9250. delete bindingStates[geometryId];
  9251. }
  9252. }
  9253. function releaseStatesOfGeometry(geometry) {
  9254. if (bindingStates[geometry.id] === undefined) return;
  9255. var programMap = bindingStates[geometry.id];
  9256. for (var programId in programMap) {
  9257. var stateMap = programMap[programId];
  9258. for (var wireframe in stateMap) {
  9259. deleteVertexArrayObject(stateMap[wireframe].object);
  9260. delete stateMap[wireframe];
  9261. }
  9262. delete programMap[programId];
  9263. }
  9264. delete bindingStates[geometry.id];
  9265. }
  9266. function releaseStatesOfProgram(program) {
  9267. for (var geometryId in bindingStates) {
  9268. var programMap = bindingStates[geometryId];
  9269. if (programMap[program.id] === undefined) continue;
  9270. var stateMap = programMap[program.id];
  9271. for (var wireframe in stateMap) {
  9272. deleteVertexArrayObject(stateMap[wireframe].object);
  9273. delete stateMap[wireframe];
  9274. }
  9275. delete programMap[program.id];
  9276. }
  9277. }
  9278. function reset() {
  9279. resetDefaultState();
  9280. if (currentState === defaultState) return;
  9281. currentState = defaultState;
  9282. bindVertexArrayObject(currentState.object);
  9283. } // for backward-compatilibity
  9284. function resetDefaultState() {
  9285. defaultState.geometry = null;
  9286. defaultState.program = null;
  9287. defaultState.wireframe = false;
  9288. }
  9289. return {
  9290. setup: setup,
  9291. reset: reset,
  9292. resetDefaultState: resetDefaultState,
  9293. dispose: dispose,
  9294. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9295. releaseStatesOfProgram: releaseStatesOfProgram,
  9296. initAttributes: initAttributes,
  9297. enableAttribute: enableAttribute,
  9298. disableUnusedAttributes: disableUnusedAttributes
  9299. };
  9300. }
  9301. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  9302. var isWebGL2 = capabilities.isWebGL2;
  9303. var mode;
  9304. function setMode(value) {
  9305. mode = value;
  9306. }
  9307. function render(start, count) {
  9308. gl.drawArrays(mode, start, count);
  9309. info.update(count, mode, 1);
  9310. }
  9311. function renderInstances(start, count, primcount) {
  9312. if (primcount === 0) return;
  9313. var extension, methodName;
  9314. if (isWebGL2) {
  9315. extension = gl;
  9316. methodName = 'drawArraysInstanced';
  9317. } else {
  9318. extension = extensions.get('ANGLE_instanced_arrays');
  9319. methodName = 'drawArraysInstancedANGLE';
  9320. if (extension === null) {
  9321. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9322. return;
  9323. }
  9324. }
  9325. extension[methodName](mode, start, count, primcount);
  9326. info.update(count, mode, primcount);
  9327. } //
  9328. this.setMode = setMode;
  9329. this.render = render;
  9330. this.renderInstances = renderInstances;
  9331. }
  9332. function WebGLCapabilities(gl, extensions, parameters) {
  9333. var maxAnisotropy;
  9334. function getMaxAnisotropy() {
  9335. if (maxAnisotropy !== undefined) return maxAnisotropy;
  9336. var extension = extensions.get('EXT_texture_filter_anisotropic');
  9337. if (extension !== null) {
  9338. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  9339. } else {
  9340. maxAnisotropy = 0;
  9341. }
  9342. return maxAnisotropy;
  9343. }
  9344. function getMaxPrecision(precision) {
  9345. if (precision === 'highp') {
  9346. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  9347. return 'highp';
  9348. }
  9349. precision = 'mediump';
  9350. }
  9351. if (precision === 'mediump') {
  9352. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  9353. return 'mediump';
  9354. }
  9355. }
  9356. return 'lowp';
  9357. }
  9358. /* eslint-disable no-undef */
  9359. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  9360. /* eslint-enable no-undef */
  9361. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9362. var maxPrecision = getMaxPrecision(precision);
  9363. if (maxPrecision !== precision) {
  9364. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  9365. precision = maxPrecision;
  9366. }
  9367. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9368. var maxTextures = gl.getParameter(34930);
  9369. var maxVertexTextures = gl.getParameter(35660);
  9370. var maxTextureSize = gl.getParameter(3379);
  9371. var maxCubemapSize = gl.getParameter(34076);
  9372. var maxAttributes = gl.getParameter(34921);
  9373. var maxVertexUniforms = gl.getParameter(36347);
  9374. var maxVaryings = gl.getParameter(36348);
  9375. var maxFragmentUniforms = gl.getParameter(36349);
  9376. var vertexTextures = maxVertexTextures > 0;
  9377. var floatFragmentTextures = isWebGL2 || !!extensions.get('OES_texture_float');
  9378. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9379. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  9380. return {
  9381. isWebGL2: isWebGL2,
  9382. getMaxAnisotropy: getMaxAnisotropy,
  9383. getMaxPrecision: getMaxPrecision,
  9384. precision: precision,
  9385. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9386. maxTextures: maxTextures,
  9387. maxVertexTextures: maxVertexTextures,
  9388. maxTextureSize: maxTextureSize,
  9389. maxCubemapSize: maxCubemapSize,
  9390. maxAttributes: maxAttributes,
  9391. maxVertexUniforms: maxVertexUniforms,
  9392. maxVaryings: maxVaryings,
  9393. maxFragmentUniforms: maxFragmentUniforms,
  9394. vertexTextures: vertexTextures,
  9395. floatFragmentTextures: floatFragmentTextures,
  9396. floatVertexTextures: floatVertexTextures,
  9397. maxSamples: maxSamples
  9398. };
  9399. }
  9400. function WebGLClipping(properties) {
  9401. var scope = this;
  9402. var globalState = null,
  9403. numGlobalPlanes = 0,
  9404. localClippingEnabled = false,
  9405. renderingShadows = false;
  9406. var plane = new Plane(),
  9407. viewNormalMatrix = new Matrix3(),
  9408. uniform = {
  9409. value: null,
  9410. needsUpdate: false
  9411. };
  9412. this.uniform = uniform;
  9413. this.numPlanes = 0;
  9414. this.numIntersection = 0;
  9415. this.init = function (planes, enableLocalClipping, camera) {
  9416. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  9417. // run another frame in order to reset the state:
  9418. numGlobalPlanes !== 0 || localClippingEnabled;
  9419. localClippingEnabled = enableLocalClipping;
  9420. globalState = projectPlanes(planes, camera, 0);
  9421. numGlobalPlanes = planes.length;
  9422. return enabled;
  9423. };
  9424. this.beginShadows = function () {
  9425. renderingShadows = true;
  9426. projectPlanes(null);
  9427. };
  9428. this.endShadows = function () {
  9429. renderingShadows = false;
  9430. resetGlobalState();
  9431. };
  9432. this.setState = function (material, camera, useCache) {
  9433. var planes = material.clippingPlanes,
  9434. clipIntersection = material.clipIntersection,
  9435. clipShadows = material.clipShadows;
  9436. var materialProperties = properties.get(material);
  9437. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  9438. // there's no local clipping
  9439. if (renderingShadows) {
  9440. // there's no global clipping
  9441. projectPlanes(null);
  9442. } else {
  9443. resetGlobalState();
  9444. }
  9445. } else {
  9446. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9447. lGlobal = nGlobal * 4;
  9448. var dstArray = materialProperties.clippingState || null;
  9449. uniform.value = dstArray; // ensure unique state
  9450. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  9451. for (var i = 0; i !== lGlobal; ++i) {
  9452. dstArray[i] = globalState[i];
  9453. }
  9454. materialProperties.clippingState = dstArray;
  9455. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9456. this.numPlanes += nGlobal;
  9457. }
  9458. };
  9459. function resetGlobalState() {
  9460. if (uniform.value !== globalState) {
  9461. uniform.value = globalState;
  9462. uniform.needsUpdate = numGlobalPlanes > 0;
  9463. }
  9464. scope.numPlanes = numGlobalPlanes;
  9465. scope.numIntersection = 0;
  9466. }
  9467. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  9468. var nPlanes = planes !== null ? planes.length : 0;
  9469. var dstArray = null;
  9470. if (nPlanes !== 0) {
  9471. dstArray = uniform.value;
  9472. if (skipTransform !== true || dstArray === null) {
  9473. var flatSize = dstOffset + nPlanes * 4,
  9474. viewMatrix = camera.matrixWorldInverse;
  9475. viewNormalMatrix.getNormalMatrix(viewMatrix);
  9476. if (dstArray === null || dstArray.length < flatSize) {
  9477. dstArray = new Float32Array(flatSize);
  9478. }
  9479. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  9480. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  9481. plane.normal.toArray(dstArray, i4);
  9482. dstArray[i4 + 3] = plane.constant;
  9483. }
  9484. }
  9485. uniform.value = dstArray;
  9486. uniform.needsUpdate = true;
  9487. }
  9488. scope.numPlanes = nPlanes;
  9489. scope.numIntersection = 0;
  9490. return dstArray;
  9491. }
  9492. }
  9493. function WebGLCubeMaps(renderer) {
  9494. var cubemaps = new WeakMap();
  9495. function mapTextureMapping(texture, mapping) {
  9496. if (mapping === EquirectangularReflectionMapping) {
  9497. texture.mapping = CubeReflectionMapping;
  9498. } else if (mapping === EquirectangularRefractionMapping) {
  9499. texture.mapping = CubeRefractionMapping;
  9500. }
  9501. return texture;
  9502. }
  9503. function get(texture) {
  9504. if (texture && texture.isTexture) {
  9505. var mapping = texture.mapping;
  9506. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  9507. if (cubemaps.has(texture)) {
  9508. var cubemap = cubemaps.get(texture).texture;
  9509. return mapTextureMapping(cubemap, texture.mapping);
  9510. } else {
  9511. var image = texture.image;
  9512. if (image && image.height > 0) {
  9513. var currentRenderList = renderer.getRenderList();
  9514. var currentRenderTarget = renderer.getRenderTarget();
  9515. var currentRenderState = renderer.getRenderState();
  9516. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  9517. renderTarget.fromEquirectangularTexture(renderer, texture);
  9518. cubemaps.set(texture, renderTarget);
  9519. renderer.setRenderTarget(currentRenderTarget);
  9520. renderer.setRenderList(currentRenderList);
  9521. renderer.setRenderState(currentRenderState);
  9522. texture.addEventListener('dispose', onTextureDispose);
  9523. return mapTextureMapping(renderTarget.texture, texture.mapping);
  9524. } else {
  9525. // image not yet ready. try the conversion next frame
  9526. return null;
  9527. }
  9528. }
  9529. }
  9530. }
  9531. return texture;
  9532. }
  9533. function onTextureDispose(event) {
  9534. var texture = event.target;
  9535. texture.removeEventListener('dispose', onTextureDispose);
  9536. var cubemap = cubemaps.get(texture);
  9537. if (cubemap !== undefined) {
  9538. cubemaps.delete(texture);
  9539. cubemap.dispose();
  9540. }
  9541. }
  9542. function dispose() {
  9543. cubemaps = new WeakMap();
  9544. }
  9545. return {
  9546. get: get,
  9547. dispose: dispose
  9548. };
  9549. }
  9550. function WebGLExtensions(gl) {
  9551. var extensions = {};
  9552. return {
  9553. has: function has(name) {
  9554. if (extensions[name] !== undefined) {
  9555. return extensions[name] !== null;
  9556. }
  9557. var extension;
  9558. switch (name) {
  9559. case 'WEBGL_depth_texture':
  9560. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  9561. break;
  9562. case 'EXT_texture_filter_anisotropic':
  9563. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  9564. break;
  9565. case 'WEBGL_compressed_texture_s3tc':
  9566. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  9567. break;
  9568. case 'WEBGL_compressed_texture_pvrtc':
  9569. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  9570. break;
  9571. default:
  9572. extension = gl.getExtension(name);
  9573. }
  9574. extensions[name] = extension;
  9575. return extension !== null;
  9576. },
  9577. get: function get(name) {
  9578. if (!this.has(name)) {
  9579. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  9580. }
  9581. return extensions[name];
  9582. }
  9583. };
  9584. }
  9585. function WebGLGeometries(gl, attributes, info, bindingStates) {
  9586. var geometries = new WeakMap();
  9587. var wireframeAttributes = new WeakMap();
  9588. function onGeometryDispose(event) {
  9589. var geometry = event.target;
  9590. var buffergeometry = geometries.get(geometry);
  9591. if (buffergeometry.index !== null) {
  9592. attributes.remove(buffergeometry.index);
  9593. }
  9594. for (var name in buffergeometry.attributes) {
  9595. attributes.remove(buffergeometry.attributes[name]);
  9596. }
  9597. geometry.removeEventListener('dispose', onGeometryDispose);
  9598. geometries.delete(geometry);
  9599. var attribute = wireframeAttributes.get(buffergeometry);
  9600. if (attribute) {
  9601. attributes.remove(attribute);
  9602. wireframeAttributes.delete(buffergeometry);
  9603. }
  9604. bindingStates.releaseStatesOfGeometry(geometry);
  9605. if (geometry.isInstancedBufferGeometry === true) {
  9606. delete geometry._maxInstanceCount;
  9607. } //
  9608. info.memory.geometries--;
  9609. }
  9610. function get(object, geometry) {
  9611. var buffergeometry = geometries.get(geometry);
  9612. if (buffergeometry) return buffergeometry;
  9613. geometry.addEventListener('dispose', onGeometryDispose);
  9614. if (geometry.isBufferGeometry) {
  9615. buffergeometry = geometry;
  9616. } else if (geometry.isGeometry) {
  9617. if (geometry._bufferGeometry === undefined) {
  9618. geometry._bufferGeometry = new BufferGeometry().setFromObject(object);
  9619. }
  9620. buffergeometry = geometry._bufferGeometry;
  9621. }
  9622. geometries.set(geometry, buffergeometry);
  9623. info.memory.geometries++;
  9624. return buffergeometry;
  9625. }
  9626. function update(geometry) {
  9627. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  9628. for (var name in geometryAttributes) {
  9629. attributes.update(geometryAttributes[name], 34962);
  9630. } // morph targets
  9631. var morphAttributes = geometry.morphAttributes;
  9632. for (var _name in morphAttributes) {
  9633. var array = morphAttributes[_name];
  9634. for (var i = 0, l = array.length; i < l; i++) {
  9635. attributes.update(array[i], 34962);
  9636. }
  9637. }
  9638. }
  9639. function updateWireframeAttribute(geometry) {
  9640. var indices = [];
  9641. var geometryIndex = geometry.index;
  9642. var geometryPosition = geometry.attributes.position;
  9643. var version = 0;
  9644. if (geometryIndex !== null) {
  9645. var array = geometryIndex.array;
  9646. version = geometryIndex.version;
  9647. for (var i = 0, l = array.length; i < l; i += 3) {
  9648. var a = array[i + 0];
  9649. var b = array[i + 1];
  9650. var c = array[i + 2];
  9651. indices.push(a, b, b, c, c, a);
  9652. }
  9653. } else {
  9654. var _array = geometryPosition.array;
  9655. version = geometryPosition.version;
  9656. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  9657. var _a = _i + 0;
  9658. var _b = _i + 1;
  9659. var _c = _i + 2;
  9660. indices.push(_a, _b, _b, _c, _c, _a);
  9661. }
  9662. }
  9663. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  9664. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  9665. //
  9666. var previousAttribute = wireframeAttributes.get(geometry);
  9667. if (previousAttribute) attributes.remove(previousAttribute); //
  9668. wireframeAttributes.set(geometry, attribute);
  9669. }
  9670. function getWireframeAttribute(geometry) {
  9671. var currentAttribute = wireframeAttributes.get(geometry);
  9672. if (currentAttribute) {
  9673. var geometryIndex = geometry.index;
  9674. if (geometryIndex !== null) {
  9675. // if the attribute is obsolete, create a new one
  9676. if (currentAttribute.version < geometryIndex.version) {
  9677. updateWireframeAttribute(geometry);
  9678. }
  9679. }
  9680. } else {
  9681. updateWireframeAttribute(geometry);
  9682. }
  9683. return wireframeAttributes.get(geometry);
  9684. }
  9685. return {
  9686. get: get,
  9687. update: update,
  9688. getWireframeAttribute: getWireframeAttribute
  9689. };
  9690. }
  9691. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  9692. var isWebGL2 = capabilities.isWebGL2;
  9693. var mode;
  9694. function setMode(value) {
  9695. mode = value;
  9696. }
  9697. var type, bytesPerElement;
  9698. function setIndex(value) {
  9699. type = value.type;
  9700. bytesPerElement = value.bytesPerElement;
  9701. }
  9702. function render(start, count) {
  9703. gl.drawElements(mode, count, type, start * bytesPerElement);
  9704. info.update(count, mode, 1);
  9705. }
  9706. function renderInstances(start, count, primcount) {
  9707. if (primcount === 0) return;
  9708. var extension, methodName;
  9709. if (isWebGL2) {
  9710. extension = gl;
  9711. methodName = 'drawElementsInstanced';
  9712. } else {
  9713. extension = extensions.get('ANGLE_instanced_arrays');
  9714. methodName = 'drawElementsInstancedANGLE';
  9715. if (extension === null) {
  9716. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9717. return;
  9718. }
  9719. }
  9720. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  9721. info.update(count, mode, primcount);
  9722. } //
  9723. this.setMode = setMode;
  9724. this.setIndex = setIndex;
  9725. this.render = render;
  9726. this.renderInstances = renderInstances;
  9727. }
  9728. function WebGLInfo(gl) {
  9729. var memory = {
  9730. geometries: 0,
  9731. textures: 0
  9732. };
  9733. var render = {
  9734. frame: 0,
  9735. calls: 0,
  9736. triangles: 0,
  9737. points: 0,
  9738. lines: 0
  9739. };
  9740. function update(count, mode, instanceCount) {
  9741. render.calls++;
  9742. switch (mode) {
  9743. case 4:
  9744. render.triangles += instanceCount * (count / 3);
  9745. break;
  9746. case 1:
  9747. render.lines += instanceCount * (count / 2);
  9748. break;
  9749. case 3:
  9750. render.lines += instanceCount * (count - 1);
  9751. break;
  9752. case 2:
  9753. render.lines += instanceCount * count;
  9754. break;
  9755. case 0:
  9756. render.points += instanceCount * count;
  9757. break;
  9758. default:
  9759. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  9760. break;
  9761. }
  9762. }
  9763. function reset() {
  9764. render.frame++;
  9765. render.calls = 0;
  9766. render.triangles = 0;
  9767. render.points = 0;
  9768. render.lines = 0;
  9769. }
  9770. return {
  9771. memory: memory,
  9772. render: render,
  9773. programs: null,
  9774. autoReset: true,
  9775. reset: reset,
  9776. update: update
  9777. };
  9778. }
  9779. function numericalSort(a, b) {
  9780. return a[0] - b[0];
  9781. }
  9782. function absNumericalSort(a, b) {
  9783. return Math.abs(b[1]) - Math.abs(a[1]);
  9784. }
  9785. function WebGLMorphtargets(gl) {
  9786. var influencesList = {};
  9787. var morphInfluences = new Float32Array(8);
  9788. var workInfluences = [];
  9789. for (var i = 0; i < 8; i++) {
  9790. workInfluences[i] = [i, 0];
  9791. }
  9792. function update(object, geometry, material, program) {
  9793. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  9794. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  9795. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  9796. var influences = influencesList[geometry.id];
  9797. if (influences === undefined) {
  9798. // initialise list
  9799. influences = [];
  9800. for (var _i = 0; _i < length; _i++) {
  9801. influences[_i] = [_i, 0];
  9802. }
  9803. influencesList[geometry.id] = influences;
  9804. } // Collect influences
  9805. for (var _i2 = 0; _i2 < length; _i2++) {
  9806. var influence = influences[_i2];
  9807. influence[0] = _i2;
  9808. influence[1] = objectInfluences[_i2];
  9809. }
  9810. influences.sort(absNumericalSort);
  9811. for (var _i3 = 0; _i3 < 8; _i3++) {
  9812. if (_i3 < length && influences[_i3][1]) {
  9813. workInfluences[_i3][0] = influences[_i3][0];
  9814. workInfluences[_i3][1] = influences[_i3][1];
  9815. } else {
  9816. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  9817. workInfluences[_i3][1] = 0;
  9818. }
  9819. }
  9820. workInfluences.sort(numericalSort);
  9821. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9822. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9823. var morphInfluencesSum = 0;
  9824. for (var _i4 = 0; _i4 < 8; _i4++) {
  9825. var _influence = workInfluences[_i4];
  9826. var index = _influence[0];
  9827. var value = _influence[1];
  9828. if (index !== Number.MAX_SAFE_INTEGER && value) {
  9829. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  9830. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  9831. }
  9832. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  9833. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  9834. }
  9835. morphInfluences[_i4] = value;
  9836. morphInfluencesSum += value;
  9837. } else {
  9838. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== undefined) {
  9839. geometry.deleteAttribute('morphTarget' + _i4);
  9840. }
  9841. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== undefined) {
  9842. geometry.deleteAttribute('morphNormal' + _i4);
  9843. }
  9844. morphInfluences[_i4] = 0;
  9845. }
  9846. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  9847. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  9848. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  9849. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  9850. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  9851. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  9852. }
  9853. return {
  9854. update: update
  9855. };
  9856. }
  9857. function WebGLObjects(gl, geometries, attributes, info) {
  9858. var updateMap = new WeakMap();
  9859. function update(object) {
  9860. var frame = info.render.frame;
  9861. var geometry = object.geometry;
  9862. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  9863. if (updateMap.get(buffergeometry) !== frame) {
  9864. if (geometry.isGeometry) {
  9865. buffergeometry.updateFromObject(object);
  9866. }
  9867. geometries.update(buffergeometry);
  9868. updateMap.set(buffergeometry, frame);
  9869. }
  9870. if (object.isInstancedMesh) {
  9871. attributes.update(object.instanceMatrix, 34962);
  9872. if (object.instanceColor !== null) {
  9873. attributes.update(object.instanceColor, 34962);
  9874. }
  9875. }
  9876. return buffergeometry;
  9877. }
  9878. function dispose() {
  9879. updateMap = new WeakMap();
  9880. }
  9881. return {
  9882. update: update,
  9883. dispose: dispose
  9884. };
  9885. }
  9886. function DataTexture2DArray(data, width, height, depth) {
  9887. Texture.call(this, null);
  9888. this.image = {
  9889. data: data || null,
  9890. width: width || 1,
  9891. height: height || 1,
  9892. depth: depth || 1
  9893. };
  9894. this.magFilter = NearestFilter;
  9895. this.minFilter = NearestFilter;
  9896. this.wrapR = ClampToEdgeWrapping;
  9897. this.generateMipmaps = false;
  9898. this.flipY = false;
  9899. this.needsUpdate = true;
  9900. }
  9901. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  9902. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  9903. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9904. function DataTexture3D(data, width, height, depth) {
  9905. // We're going to add .setXXX() methods for setting properties later.
  9906. // Users can still set in DataTexture3D directly.
  9907. //
  9908. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  9909. // texture.anisotropy = 16;
  9910. //
  9911. // See #14839
  9912. Texture.call(this, null);
  9913. this.image = {
  9914. data: data || null,
  9915. width: width || 1,
  9916. height: height || 1,
  9917. depth: depth || 1
  9918. };
  9919. this.magFilter = NearestFilter;
  9920. this.minFilter = NearestFilter;
  9921. this.wrapR = ClampToEdgeWrapping;
  9922. this.generateMipmaps = false;
  9923. this.flipY = false;
  9924. this.needsUpdate = true;
  9925. }
  9926. DataTexture3D.prototype = Object.create(Texture.prototype);
  9927. DataTexture3D.prototype.constructor = DataTexture3D;
  9928. DataTexture3D.prototype.isDataTexture3D = true;
  9929. /**
  9930. * Uniforms of a program.
  9931. * Those form a tree structure with a special top-level container for the root,
  9932. * which you get by calling 'new WebGLUniforms( gl, program )'.
  9933. *
  9934. *
  9935. * Properties of inner nodes including the top-level container:
  9936. *
  9937. * .seq - array of nested uniforms
  9938. * .map - nested uniforms by name
  9939. *
  9940. *
  9941. * Methods of all nodes except the top-level container:
  9942. *
  9943. * .setValue( gl, value, [textures] )
  9944. *
  9945. * uploads a uniform value(s)
  9946. * the 'textures' parameter is needed for sampler uniforms
  9947. *
  9948. *
  9949. * Static methods of the top-level container (textures factorizations):
  9950. *
  9951. * .upload( gl, seq, values, textures )
  9952. *
  9953. * sets uniforms in 'seq' to 'values[id].value'
  9954. *
  9955. * .seqWithValue( seq, values ) : filteredSeq
  9956. *
  9957. * filters 'seq' entries with corresponding entry in values
  9958. *
  9959. *
  9960. * Methods of the top-level container (textures factorizations):
  9961. *
  9962. * .setValue( gl, name, value, textures )
  9963. *
  9964. * sets uniform with name 'name' to 'value'
  9965. *
  9966. * .setOptional( gl, obj, prop )
  9967. *
  9968. * like .set for an optional property of the object
  9969. *
  9970. */
  9971. var emptyTexture = new Texture();
  9972. var emptyTexture2dArray = new DataTexture2DArray();
  9973. var emptyTexture3d = new DataTexture3D();
  9974. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  9975. // Array Caches (provide typed arrays for temporary by size)
  9976. var arrayCacheF32 = [];
  9977. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  9978. var mat4array = new Float32Array(16);
  9979. var mat3array = new Float32Array(9);
  9980. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  9981. function flatten(array, nBlocks, blockSize) {
  9982. var firstElem = array[0];
  9983. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  9984. // see http://jacksondunstan.com/articles/983
  9985. var n = nBlocks * blockSize;
  9986. var r = arrayCacheF32[n];
  9987. if (r === undefined) {
  9988. r = new Float32Array(n);
  9989. arrayCacheF32[n] = r;
  9990. }
  9991. if (nBlocks !== 0) {
  9992. firstElem.toArray(r, 0);
  9993. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  9994. offset += blockSize;
  9995. array[i].toArray(r, offset);
  9996. }
  9997. }
  9998. return r;
  9999. }
  10000. function arraysEqual(a, b) {
  10001. if (a.length !== b.length) return false;
  10002. for (var i = 0, l = a.length; i < l; i++) {
  10003. if (a[i] !== b[i]) return false;
  10004. }
  10005. return true;
  10006. }
  10007. function copyArray(a, b) {
  10008. for (var i = 0, l = b.length; i < l; i++) {
  10009. a[i] = b[i];
  10010. }
  10011. } // Texture unit allocation
  10012. function allocTexUnits(textures, n) {
  10013. var r = arrayCacheI32[n];
  10014. if (r === undefined) {
  10015. r = new Int32Array(n);
  10016. arrayCacheI32[n] = r;
  10017. }
  10018. for (var i = 0; i !== n; ++i) {
  10019. r[i] = textures.allocateTextureUnit();
  10020. }
  10021. return r;
  10022. } // --- Setters ---
  10023. // Note: Defining these methods externally, because they come in a bunch
  10024. // and this way their names minify.
  10025. // Single scalar
  10026. function setValueV1f(gl, v) {
  10027. var cache = this.cache;
  10028. if (cache[0] === v) return;
  10029. gl.uniform1f(this.addr, v);
  10030. cache[0] = v;
  10031. } // Single float vector (from flat array or THREE.VectorN)
  10032. function setValueV2f(gl, v) {
  10033. var cache = this.cache;
  10034. if (v.x !== undefined) {
  10035. if (cache[0] !== v.x || cache[1] !== v.y) {
  10036. gl.uniform2f(this.addr, v.x, v.y);
  10037. cache[0] = v.x;
  10038. cache[1] = v.y;
  10039. }
  10040. } else {
  10041. if (arraysEqual(cache, v)) return;
  10042. gl.uniform2fv(this.addr, v);
  10043. copyArray(cache, v);
  10044. }
  10045. }
  10046. function setValueV3f(gl, v) {
  10047. var cache = this.cache;
  10048. if (v.x !== undefined) {
  10049. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10050. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10051. cache[0] = v.x;
  10052. cache[1] = v.y;
  10053. cache[2] = v.z;
  10054. }
  10055. } else if (v.r !== undefined) {
  10056. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10057. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10058. cache[0] = v.r;
  10059. cache[1] = v.g;
  10060. cache[2] = v.b;
  10061. }
  10062. } else {
  10063. if (arraysEqual(cache, v)) return;
  10064. gl.uniform3fv(this.addr, v);
  10065. copyArray(cache, v);
  10066. }
  10067. }
  10068. function setValueV4f(gl, v) {
  10069. var cache = this.cache;
  10070. if (v.x !== undefined) {
  10071. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10072. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10073. cache[0] = v.x;
  10074. cache[1] = v.y;
  10075. cache[2] = v.z;
  10076. cache[3] = v.w;
  10077. }
  10078. } else {
  10079. if (arraysEqual(cache, v)) return;
  10080. gl.uniform4fv(this.addr, v);
  10081. copyArray(cache, v);
  10082. }
  10083. } // Single matrix (from flat array or MatrixN)
  10084. function setValueM2(gl, v) {
  10085. var cache = this.cache;
  10086. var elements = v.elements;
  10087. if (elements === undefined) {
  10088. if (arraysEqual(cache, v)) return;
  10089. gl.uniformMatrix2fv(this.addr, false, v);
  10090. copyArray(cache, v);
  10091. } else {
  10092. if (arraysEqual(cache, elements)) return;
  10093. mat2array.set(elements);
  10094. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10095. copyArray(cache, elements);
  10096. }
  10097. }
  10098. function setValueM3(gl, v) {
  10099. var cache = this.cache;
  10100. var elements = v.elements;
  10101. if (elements === undefined) {
  10102. if (arraysEqual(cache, v)) return;
  10103. gl.uniformMatrix3fv(this.addr, false, v);
  10104. copyArray(cache, v);
  10105. } else {
  10106. if (arraysEqual(cache, elements)) return;
  10107. mat3array.set(elements);
  10108. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10109. copyArray(cache, elements);
  10110. }
  10111. }
  10112. function setValueM4(gl, v) {
  10113. var cache = this.cache;
  10114. var elements = v.elements;
  10115. if (elements === undefined) {
  10116. if (arraysEqual(cache, v)) return;
  10117. gl.uniformMatrix4fv(this.addr, false, v);
  10118. copyArray(cache, v);
  10119. } else {
  10120. if (arraysEqual(cache, elements)) return;
  10121. mat4array.set(elements);
  10122. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10123. copyArray(cache, elements);
  10124. }
  10125. } // Single texture (2D / Cube)
  10126. function setValueT1(gl, v, textures) {
  10127. var cache = this.cache;
  10128. var unit = textures.allocateTextureUnit();
  10129. if (cache[0] !== unit) {
  10130. gl.uniform1i(this.addr, unit);
  10131. cache[0] = unit;
  10132. }
  10133. textures.safeSetTexture2D(v || emptyTexture, unit);
  10134. }
  10135. function setValueT2DArray1(gl, v, textures) {
  10136. var cache = this.cache;
  10137. var unit = textures.allocateTextureUnit();
  10138. if (cache[0] !== unit) {
  10139. gl.uniform1i(this.addr, unit);
  10140. cache[0] = unit;
  10141. }
  10142. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10143. }
  10144. function setValueT3D1(gl, v, textures) {
  10145. var cache = this.cache;
  10146. var unit = textures.allocateTextureUnit();
  10147. if (cache[0] !== unit) {
  10148. gl.uniform1i(this.addr, unit);
  10149. cache[0] = unit;
  10150. }
  10151. textures.setTexture3D(v || emptyTexture3d, unit);
  10152. }
  10153. function setValueT6(gl, v, textures) {
  10154. var cache = this.cache;
  10155. var unit = textures.allocateTextureUnit();
  10156. if (cache[0] !== unit) {
  10157. gl.uniform1i(this.addr, unit);
  10158. cache[0] = unit;
  10159. }
  10160. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10161. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10162. function setValueV1i(gl, v) {
  10163. var cache = this.cache;
  10164. if (cache[0] === v) return;
  10165. gl.uniform1i(this.addr, v);
  10166. cache[0] = v;
  10167. }
  10168. function setValueV2i(gl, v) {
  10169. var cache = this.cache;
  10170. if (arraysEqual(cache, v)) return;
  10171. gl.uniform2iv(this.addr, v);
  10172. copyArray(cache, v);
  10173. }
  10174. function setValueV3i(gl, v) {
  10175. var cache = this.cache;
  10176. if (arraysEqual(cache, v)) return;
  10177. gl.uniform3iv(this.addr, v);
  10178. copyArray(cache, v);
  10179. }
  10180. function setValueV4i(gl, v) {
  10181. var cache = this.cache;
  10182. if (arraysEqual(cache, v)) return;
  10183. gl.uniform4iv(this.addr, v);
  10184. copyArray(cache, v);
  10185. } // uint
  10186. function setValueV1ui(gl, v) {
  10187. var cache = this.cache;
  10188. if (cache[0] === v) return;
  10189. gl.uniform1ui(this.addr, v);
  10190. cache[0] = v;
  10191. } // Helper to pick the right setter for the singular case
  10192. function getSingularSetter(type) {
  10193. switch (type) {
  10194. case 0x1406:
  10195. return setValueV1f;
  10196. // FLOAT
  10197. case 0x8b50:
  10198. return setValueV2f;
  10199. // _VEC2
  10200. case 0x8b51:
  10201. return setValueV3f;
  10202. // _VEC3
  10203. case 0x8b52:
  10204. return setValueV4f;
  10205. // _VEC4
  10206. case 0x8b5a:
  10207. return setValueM2;
  10208. // _MAT2
  10209. case 0x8b5b:
  10210. return setValueM3;
  10211. // _MAT3
  10212. case 0x8b5c:
  10213. return setValueM4;
  10214. // _MAT4
  10215. case 0x1404:
  10216. case 0x8b56:
  10217. return setValueV1i;
  10218. // INT, BOOL
  10219. case 0x8b53:
  10220. case 0x8b57:
  10221. return setValueV2i;
  10222. // _VEC2
  10223. case 0x8b54:
  10224. case 0x8b58:
  10225. return setValueV3i;
  10226. // _VEC3
  10227. case 0x8b55:
  10228. case 0x8b59:
  10229. return setValueV4i;
  10230. // _VEC4
  10231. case 0x1405:
  10232. return setValueV1ui;
  10233. // UINT
  10234. case 0x8b5e: // SAMPLER_2D
  10235. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10236. case 0x8dca: // INT_SAMPLER_2D
  10237. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10238. case 0x8b62:
  10239. // SAMPLER_2D_SHADOW
  10240. return setValueT1;
  10241. case 0x8b5f: // SAMPLER_3D
  10242. case 0x8dcb: // INT_SAMPLER_3D
  10243. case 0x8dd3:
  10244. // UNSIGNED_INT_SAMPLER_3D
  10245. return setValueT3D1;
  10246. case 0x8b60: // SAMPLER_CUBE
  10247. case 0x8dcc: // INT_SAMPLER_CUBE
  10248. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10249. case 0x8dc5:
  10250. // SAMPLER_CUBE_SHADOW
  10251. return setValueT6;
  10252. case 0x8dc1: // SAMPLER_2D_ARRAY
  10253. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10254. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10255. case 0x8dc4:
  10256. // SAMPLER_2D_ARRAY_SHADOW
  10257. return setValueT2DArray1;
  10258. }
  10259. } // Array of scalars
  10260. function setValueV1fArray(gl, v) {
  10261. gl.uniform1fv(this.addr, v);
  10262. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10263. function setValueV1iArray(gl, v) {
  10264. gl.uniform1iv(this.addr, v);
  10265. }
  10266. function setValueV2iArray(gl, v) {
  10267. gl.uniform2iv(this.addr, v);
  10268. }
  10269. function setValueV3iArray(gl, v) {
  10270. gl.uniform3iv(this.addr, v);
  10271. }
  10272. function setValueV4iArray(gl, v) {
  10273. gl.uniform4iv(this.addr, v);
  10274. } // Array of vectors (flat or from THREE classes)
  10275. function setValueV2fArray(gl, v) {
  10276. var data = flatten(v, this.size, 2);
  10277. gl.uniform2fv(this.addr, data);
  10278. }
  10279. function setValueV3fArray(gl, v) {
  10280. var data = flatten(v, this.size, 3);
  10281. gl.uniform3fv(this.addr, data);
  10282. }
  10283. function setValueV4fArray(gl, v) {
  10284. var data = flatten(v, this.size, 4);
  10285. gl.uniform4fv(this.addr, data);
  10286. } // Array of matrices (flat or from THREE clases)
  10287. function setValueM2Array(gl, v) {
  10288. var data = flatten(v, this.size, 4);
  10289. gl.uniformMatrix2fv(this.addr, false, data);
  10290. }
  10291. function setValueM3Array(gl, v) {
  10292. var data = flatten(v, this.size, 9);
  10293. gl.uniformMatrix3fv(this.addr, false, data);
  10294. }
  10295. function setValueM4Array(gl, v) {
  10296. var data = flatten(v, this.size, 16);
  10297. gl.uniformMatrix4fv(this.addr, false, data);
  10298. } // Array of textures (2D / Cube)
  10299. function setValueT1Array(gl, v, textures) {
  10300. var n = v.length;
  10301. var units = allocTexUnits(textures, n);
  10302. gl.uniform1iv(this.addr, units);
  10303. for (var i = 0; i !== n; ++i) {
  10304. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  10305. }
  10306. }
  10307. function setValueT6Array(gl, v, textures) {
  10308. var n = v.length;
  10309. var units = allocTexUnits(textures, n);
  10310. gl.uniform1iv(this.addr, units);
  10311. for (var i = 0; i !== n; ++i) {
  10312. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  10313. }
  10314. } // Helper to pick the right setter for a pure (bottom-level) array
  10315. function getPureArraySetter(type) {
  10316. switch (type) {
  10317. case 0x1406:
  10318. return setValueV1fArray;
  10319. // FLOAT
  10320. case 0x8b50:
  10321. return setValueV2fArray;
  10322. // _VEC2
  10323. case 0x8b51:
  10324. return setValueV3fArray;
  10325. // _VEC3
  10326. case 0x8b52:
  10327. return setValueV4fArray;
  10328. // _VEC4
  10329. case 0x8b5a:
  10330. return setValueM2Array;
  10331. // _MAT2
  10332. case 0x8b5b:
  10333. return setValueM3Array;
  10334. // _MAT3
  10335. case 0x8b5c:
  10336. return setValueM4Array;
  10337. // _MAT4
  10338. case 0x1404:
  10339. case 0x8b56:
  10340. return setValueV1iArray;
  10341. // INT, BOOL
  10342. case 0x8b53:
  10343. case 0x8b57:
  10344. return setValueV2iArray;
  10345. // _VEC2
  10346. case 0x8b54:
  10347. case 0x8b58:
  10348. return setValueV3iArray;
  10349. // _VEC3
  10350. case 0x8b55:
  10351. case 0x8b59:
  10352. return setValueV4iArray;
  10353. // _VEC4
  10354. case 0x8b5e: // SAMPLER_2D
  10355. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10356. case 0x8dca: // INT_SAMPLER_2D
  10357. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10358. case 0x8b62:
  10359. // SAMPLER_2D_SHADOW
  10360. return setValueT1Array;
  10361. case 0x8b60: // SAMPLER_CUBE
  10362. case 0x8dcc: // INT_SAMPLER_CUBE
  10363. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10364. case 0x8dc5:
  10365. // SAMPLER_CUBE_SHADOW
  10366. return setValueT6Array;
  10367. }
  10368. } // --- Uniform Classes ---
  10369. function SingleUniform(id, activeInfo, addr) {
  10370. this.id = id;
  10371. this.addr = addr;
  10372. this.cache = [];
  10373. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10374. }
  10375. function PureArrayUniform(id, activeInfo, addr) {
  10376. this.id = id;
  10377. this.addr = addr;
  10378. this.cache = [];
  10379. this.size = activeInfo.size;
  10380. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10381. }
  10382. PureArrayUniform.prototype.updateCache = function (data) {
  10383. var cache = this.cache;
  10384. if (data instanceof Float32Array && cache.length !== data.length) {
  10385. this.cache = new Float32Array(data.length);
  10386. }
  10387. copyArray(cache, data);
  10388. };
  10389. function StructuredUniform(id) {
  10390. this.id = id;
  10391. this.seq = [];
  10392. this.map = {};
  10393. }
  10394. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  10395. var seq = this.seq;
  10396. for (var i = 0, n = seq.length; i !== n; ++i) {
  10397. var u = seq[i];
  10398. u.setValue(gl, value[u.id], textures);
  10399. }
  10400. }; // --- Top-level ---
  10401. // Parser - builds up the property tree from the path strings
  10402. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g; // extracts
  10403. // - the identifier (member name or array index)
  10404. // - followed by an optional right bracket (found when array index)
  10405. // - followed by an optional left bracket or dot (type of subscript)
  10406. //
  10407. // Note: These portions can be read in a non-overlapping fashion and
  10408. // allow straightforward parsing of the hierarchy that WebGL encodes
  10409. // in the uniform names.
  10410. function addUniform(container, uniformObject) {
  10411. container.seq.push(uniformObject);
  10412. container.map[uniformObject.id] = uniformObject;
  10413. }
  10414. function parseUniform(activeInfo, addr, container) {
  10415. var path = activeInfo.name,
  10416. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  10417. RePathPart.lastIndex = 0;
  10418. while (true) {
  10419. var match = RePathPart.exec(path),
  10420. matchEnd = RePathPart.lastIndex;
  10421. var id = match[1];
  10422. var idIsIndex = match[2] === ']',
  10423. subscript = match[3];
  10424. if (idIsIndex) id = id | 0; // convert to integer
  10425. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  10426. // bare name or "pure" bottom-level array "[0]" suffix
  10427. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  10428. break;
  10429. } else {
  10430. // step into inner node / create it in case it doesn't exist
  10431. var map = container.map;
  10432. var next = map[id];
  10433. if (next === undefined) {
  10434. next = new StructuredUniform(id);
  10435. addUniform(container, next);
  10436. }
  10437. container = next;
  10438. }
  10439. }
  10440. } // Root Container
  10441. function WebGLUniforms(gl, program) {
  10442. this.seq = [];
  10443. this.map = {};
  10444. var n = gl.getProgramParameter(program, 35718);
  10445. for (var i = 0; i < n; ++i) {
  10446. var info = gl.getActiveUniform(program, i),
  10447. addr = gl.getUniformLocation(program, info.name);
  10448. parseUniform(info, addr, this);
  10449. }
  10450. }
  10451. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  10452. var u = this.map[name];
  10453. if (u !== undefined) u.setValue(gl, value, textures);
  10454. };
  10455. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  10456. var v = object[name];
  10457. if (v !== undefined) this.setValue(gl, name, v);
  10458. }; // Static interface
  10459. WebGLUniforms.upload = function (gl, seq, values, textures) {
  10460. for (var i = 0, n = seq.length; i !== n; ++i) {
  10461. var u = seq[i],
  10462. v = values[u.id];
  10463. if (v.needsUpdate !== false) {
  10464. // note: always updating when .needsUpdate is undefined
  10465. u.setValue(gl, v.value, textures);
  10466. }
  10467. }
  10468. };
  10469. WebGLUniforms.seqWithValue = function (seq, values) {
  10470. var r = [];
  10471. for (var i = 0, n = seq.length; i !== n; ++i) {
  10472. var u = seq[i];
  10473. if (u.id in values) r.push(u);
  10474. }
  10475. return r;
  10476. };
  10477. function WebGLShader(gl, type, string) {
  10478. var shader = gl.createShader(type);
  10479. gl.shaderSource(shader, string);
  10480. gl.compileShader(shader);
  10481. return shader;
  10482. }
  10483. var programIdCount = 0;
  10484. function addLineNumbers(string) {
  10485. var lines = string.split('\n');
  10486. for (var i = 0; i < lines.length; i++) {
  10487. lines[i] = i + 1 + ': ' + lines[i];
  10488. }
  10489. return lines.join('\n');
  10490. }
  10491. function getEncodingComponents(encoding) {
  10492. switch (encoding) {
  10493. case LinearEncoding:
  10494. return ['Linear', '( value )'];
  10495. case sRGBEncoding:
  10496. return ['sRGB', '( value )'];
  10497. case RGBEEncoding:
  10498. return ['RGBE', '( value )'];
  10499. case RGBM7Encoding:
  10500. return ['RGBM', '( value, 7.0 )'];
  10501. case RGBM16Encoding:
  10502. return ['RGBM', '( value, 16.0 )'];
  10503. case RGBDEncoding:
  10504. return ['RGBD', '( value, 256.0 )'];
  10505. case GammaEncoding:
  10506. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  10507. case LogLuvEncoding:
  10508. return ['LogLuv', '( value )'];
  10509. default:
  10510. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  10511. return ['Linear', '( value )'];
  10512. }
  10513. }
  10514. function getShaderErrors(gl, shader, type) {
  10515. var status = gl.getShaderParameter(shader, 35713);
  10516. var log = gl.getShaderInfoLog(shader).trim();
  10517. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  10518. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10519. var source = gl.getShaderSource(shader);
  10520. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  10521. }
  10522. function getTexelDecodingFunction(functionName, encoding) {
  10523. var components = getEncodingComponents(encoding);
  10524. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  10525. }
  10526. function getTexelEncodingFunction(functionName, encoding) {
  10527. var components = getEncodingComponents(encoding);
  10528. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  10529. }
  10530. function getToneMappingFunction(functionName, toneMapping) {
  10531. var toneMappingName;
  10532. switch (toneMapping) {
  10533. case LinearToneMapping:
  10534. toneMappingName = 'Linear';
  10535. break;
  10536. case ReinhardToneMapping:
  10537. toneMappingName = 'Reinhard';
  10538. break;
  10539. case CineonToneMapping:
  10540. toneMappingName = 'OptimizedCineon';
  10541. break;
  10542. case ACESFilmicToneMapping:
  10543. toneMappingName = 'ACESFilmic';
  10544. break;
  10545. case CustomToneMapping:
  10546. toneMappingName = 'Custom';
  10547. break;
  10548. default:
  10549. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  10550. toneMappingName = 'Linear';
  10551. }
  10552. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10553. }
  10554. function generateExtensions(parameters) {
  10555. 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' : ''];
  10556. return chunks.filter(filterEmptyLine).join('\n');
  10557. }
  10558. function generateDefines(defines) {
  10559. var chunks = [];
  10560. for (var name in defines) {
  10561. var value = defines[name];
  10562. if (value === false) continue;
  10563. chunks.push('#define ' + name + ' ' + value);
  10564. }
  10565. return chunks.join('\n');
  10566. }
  10567. function fetchAttributeLocations(gl, program) {
  10568. var attributes = {};
  10569. var n = gl.getProgramParameter(program, 35721);
  10570. for (var i = 0; i < n; i++) {
  10571. var info = gl.getActiveAttrib(program, i);
  10572. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10573. attributes[name] = gl.getAttribLocation(program, name);
  10574. }
  10575. return attributes;
  10576. }
  10577. function filterEmptyLine(string) {
  10578. return string !== '';
  10579. }
  10580. function replaceLightNums(string, parameters) {
  10581. 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);
  10582. }
  10583. function replaceClippingPlaneNums(string, parameters) {
  10584. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  10585. } // Resolve Includes
  10586. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10587. function resolveIncludes(string) {
  10588. return string.replace(includePattern, includeReplacer);
  10589. }
  10590. function includeReplacer(match, include) {
  10591. var string = ShaderChunk[include];
  10592. if (string === undefined) {
  10593. throw new Error('Can not resolve #include <' + include + '>');
  10594. }
  10595. return resolveIncludes(string);
  10596. } // Unroll Loops
  10597. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10598. 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;
  10599. function unrollLoops(string) {
  10600. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  10601. }
  10602. function deprecatedLoopReplacer(match, start, end, snippet) {
  10603. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  10604. return loopReplacer(match, start, end, snippet);
  10605. }
  10606. function loopReplacer(match, start, end, snippet) {
  10607. var string = '';
  10608. for (var i = parseInt(start); i < parseInt(end); i++) {
  10609. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  10610. }
  10611. return string;
  10612. } //
  10613. function generatePrecision(parameters) {
  10614. var precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;";
  10615. if (parameters.precision === "highp") {
  10616. precisionstring += "\n#define HIGH_PRECISION";
  10617. } else if (parameters.precision === "mediump") {
  10618. precisionstring += "\n#define MEDIUM_PRECISION";
  10619. } else if (parameters.precision === "lowp") {
  10620. precisionstring += "\n#define LOW_PRECISION";
  10621. }
  10622. return precisionstring;
  10623. }
  10624. function generateShadowMapTypeDefine(parameters) {
  10625. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10626. if (parameters.shadowMapType === PCFShadowMap) {
  10627. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10628. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  10629. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10630. } else if (parameters.shadowMapType === VSMShadowMap) {
  10631. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  10632. }
  10633. return shadowMapTypeDefine;
  10634. }
  10635. function generateEnvMapTypeDefine(parameters) {
  10636. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10637. if (parameters.envMap) {
  10638. switch (parameters.envMapMode) {
  10639. case CubeReflectionMapping:
  10640. case CubeRefractionMapping:
  10641. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10642. break;
  10643. case CubeUVReflectionMapping:
  10644. case CubeUVRefractionMapping:
  10645. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10646. break;
  10647. }
  10648. }
  10649. return envMapTypeDefine;
  10650. }
  10651. function generateEnvMapModeDefine(parameters) {
  10652. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10653. if (parameters.envMap) {
  10654. switch (parameters.envMapMode) {
  10655. case CubeRefractionMapping:
  10656. case CubeUVRefractionMapping:
  10657. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10658. break;
  10659. }
  10660. }
  10661. return envMapModeDefine;
  10662. }
  10663. function generateEnvMapBlendingDefine(parameters) {
  10664. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  10665. if (parameters.envMap) {
  10666. switch (parameters.combine) {
  10667. case MultiplyOperation:
  10668. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10669. break;
  10670. case MixOperation:
  10671. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10672. break;
  10673. case AddOperation:
  10674. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10675. break;
  10676. }
  10677. }
  10678. return envMapBlendingDefine;
  10679. }
  10680. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  10681. var gl = renderer.getContext();
  10682. var defines = parameters.defines;
  10683. var vertexShader = parameters.vertexShader;
  10684. var fragmentShader = parameters.fragmentShader;
  10685. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  10686. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  10687. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  10688. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  10689. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  10690. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  10691. var customDefines = generateDefines(defines);
  10692. var program = gl.createProgram();
  10693. var prefixVertex, prefixFragment;
  10694. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + "\n" : '';
  10695. if (parameters.isRawShaderMaterial) {
  10696. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  10697. if (prefixVertex.length > 0) {
  10698. prefixVertex += '\n';
  10699. }
  10700. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  10701. if (prefixFragment.length > 0) {
  10702. prefixFragment += '\n';
  10703. }
  10704. } else {
  10705. 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');
  10706. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  10707. '#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
  10708. 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
  10709. 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');
  10710. }
  10711. vertexShader = resolveIncludes(vertexShader);
  10712. vertexShader = replaceLightNums(vertexShader, parameters);
  10713. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  10714. fragmentShader = resolveIncludes(fragmentShader);
  10715. fragmentShader = replaceLightNums(fragmentShader, parameters);
  10716. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  10717. vertexShader = unrollLoops(vertexShader);
  10718. fragmentShader = unrollLoops(fragmentShader);
  10719. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  10720. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  10721. versionString = '#version 300 es\n';
  10722. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  10723. 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;
  10724. }
  10725. var vertexGlsl = versionString + prefixVertex + vertexShader;
  10726. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  10727. // console.log( '*FRAGMENT*', fragmentGlsl );
  10728. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  10729. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  10730. gl.attachShader(program, glVertexShader);
  10731. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  10732. if (parameters.index0AttributeName !== undefined) {
  10733. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  10734. } else if (parameters.morphTargets === true) {
  10735. // programs with morphTargets displace position out of attribute 0
  10736. gl.bindAttribLocation(program, 0, 'position');
  10737. }
  10738. gl.linkProgram(program); // check for link errors
  10739. if (renderer.debug.checkShaderErrors) {
  10740. var programLog = gl.getProgramInfoLog(program).trim();
  10741. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  10742. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  10743. var runnable = true;
  10744. var haveDiagnostics = true;
  10745. if (gl.getProgramParameter(program, 35714) === false) {
  10746. runnable = false;
  10747. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  10748. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  10749. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  10750. } else if (programLog !== '') {
  10751. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  10752. } else if (vertexLog === '' || fragmentLog === '') {
  10753. haveDiagnostics = false;
  10754. }
  10755. if (haveDiagnostics) {
  10756. this.diagnostics = {
  10757. runnable: runnable,
  10758. programLog: programLog,
  10759. vertexShader: {
  10760. log: vertexLog,
  10761. prefix: prefixVertex
  10762. },
  10763. fragmentShader: {
  10764. log: fragmentLog,
  10765. prefix: prefixFragment
  10766. }
  10767. };
  10768. }
  10769. } // Clean up
  10770. // Crashes in iOS9 and iOS10. #18402
  10771. // gl.detachShader( program, glVertexShader );
  10772. // gl.detachShader( program, glFragmentShader );
  10773. gl.deleteShader(glVertexShader);
  10774. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  10775. var cachedUniforms;
  10776. this.getUniforms = function () {
  10777. if (cachedUniforms === undefined) {
  10778. cachedUniforms = new WebGLUniforms(gl, program);
  10779. }
  10780. return cachedUniforms;
  10781. }; // set up caching for attribute locations
  10782. var cachedAttributes;
  10783. this.getAttributes = function () {
  10784. if (cachedAttributes === undefined) {
  10785. cachedAttributes = fetchAttributeLocations(gl, program);
  10786. }
  10787. return cachedAttributes;
  10788. }; // free resource
  10789. this.destroy = function () {
  10790. bindingStates.releaseStatesOfProgram(this);
  10791. gl.deleteProgram(program);
  10792. this.program = undefined;
  10793. }; //
  10794. this.name = parameters.shaderName;
  10795. this.id = programIdCount++;
  10796. this.cacheKey = cacheKey;
  10797. this.usedTimes = 1;
  10798. this.program = program;
  10799. this.vertexShader = glVertexShader;
  10800. this.fragmentShader = glFragmentShader;
  10801. return this;
  10802. }
  10803. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  10804. var programs = [];
  10805. var isWebGL2 = capabilities.isWebGL2;
  10806. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  10807. var floatVertexTextures = capabilities.floatVertexTextures;
  10808. var maxVertexUniforms = capabilities.maxVertexUniforms;
  10809. var vertexTextures = capabilities.vertexTextures;
  10810. var precision = capabilities.precision;
  10811. var shaderIDs = {
  10812. MeshDepthMaterial: 'depth',
  10813. MeshDistanceMaterial: 'distanceRGBA',
  10814. MeshNormalMaterial: 'normal',
  10815. MeshBasicMaterial: 'basic',
  10816. MeshLambertMaterial: 'lambert',
  10817. MeshPhongMaterial: 'phong',
  10818. MeshToonMaterial: 'toon',
  10819. MeshStandardMaterial: 'physical',
  10820. MeshPhysicalMaterial: 'physical',
  10821. MeshMatcapMaterial: 'matcap',
  10822. LineBasicMaterial: 'basic',
  10823. LineDashedMaterial: 'dashed',
  10824. PointsMaterial: 'points',
  10825. ShadowMaterial: 'shadow',
  10826. SpriteMaterial: 'sprite'
  10827. };
  10828. 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"];
  10829. function getMaxBones(object) {
  10830. var skeleton = object.skeleton;
  10831. var bones = skeleton.bones;
  10832. if (floatVertexTextures) {
  10833. return 1024;
  10834. } else {
  10835. // default for when object is not specified
  10836. // ( for example when prebuilding shader to be used with multiple objects )
  10837. //
  10838. // - leave some extra space for other uniforms
  10839. // - limit here is ANGLE's 254 max uniform vectors
  10840. // (up to 54 should be safe)
  10841. var nVertexUniforms = maxVertexUniforms;
  10842. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  10843. var maxBones = Math.min(nVertexMatrices, bones.length);
  10844. if (maxBones < bones.length) {
  10845. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  10846. return 0;
  10847. }
  10848. return maxBones;
  10849. }
  10850. }
  10851. function getTextureEncodingFromMap(map) {
  10852. var encoding;
  10853. if (!map) {
  10854. encoding = LinearEncoding;
  10855. } else if (map.isTexture) {
  10856. encoding = map.encoding;
  10857. } else if (map.isWebGLRenderTarget) {
  10858. console.warn("THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead.");
  10859. encoding = map.texture.encoding;
  10860. }
  10861. return encoding;
  10862. }
  10863. function getParameters(material, lights, shadows, scene, object) {
  10864. var fog = scene.fog;
  10865. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  10866. var envMap = cubemaps.get(material.envMap || environment);
  10867. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  10868. // (not to blow over maxLights budget)
  10869. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  10870. if (material.precision !== null) {
  10871. precision = capabilities.getMaxPrecision(material.precision);
  10872. if (precision !== material.precision) {
  10873. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  10874. }
  10875. }
  10876. var vertexShader, fragmentShader;
  10877. if (shaderID) {
  10878. var shader = ShaderLib[shaderID];
  10879. vertexShader = shader.vertexShader;
  10880. fragmentShader = shader.fragmentShader;
  10881. } else {
  10882. vertexShader = material.vertexShader;
  10883. fragmentShader = material.fragmentShader;
  10884. }
  10885. var currentRenderTarget = renderer.getRenderTarget();
  10886. var parameters = {
  10887. isWebGL2: isWebGL2,
  10888. shaderID: shaderID,
  10889. shaderName: material.type,
  10890. vertexShader: vertexShader,
  10891. fragmentShader: fragmentShader,
  10892. defines: material.defines,
  10893. isRawShaderMaterial: material.isRawShaderMaterial === true,
  10894. glslVersion: material.glslVersion,
  10895. precision: precision,
  10896. instancing: object.isInstancedMesh === true,
  10897. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  10898. supportsVertexTextures: vertexTextures,
  10899. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  10900. map: !!material.map,
  10901. mapEncoding: getTextureEncodingFromMap(material.map),
  10902. matcap: !!material.matcap,
  10903. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  10904. envMap: !!envMap,
  10905. envMapMode: envMap && envMap.mapping,
  10906. envMapEncoding: getTextureEncodingFromMap(envMap),
  10907. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  10908. lightMap: !!material.lightMap,
  10909. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  10910. aoMap: !!material.aoMap,
  10911. emissiveMap: !!material.emissiveMap,
  10912. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  10913. bumpMap: !!material.bumpMap,
  10914. normalMap: !!material.normalMap,
  10915. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  10916. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  10917. clearcoatMap: !!material.clearcoatMap,
  10918. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  10919. clearcoatNormalMap: !!material.clearcoatNormalMap,
  10920. displacementMap: !!material.displacementMap,
  10921. roughnessMap: !!material.roughnessMap,
  10922. metalnessMap: !!material.metalnessMap,
  10923. specularMap: !!material.specularMap,
  10924. alphaMap: !!material.alphaMap,
  10925. gradientMap: !!material.gradientMap,
  10926. sheen: !!material.sheen,
  10927. transmissionMap: !!material.transmissionMap,
  10928. combine: material.combine,
  10929. vertexTangents: material.normalMap && material.vertexTangents,
  10930. vertexColors: material.vertexColors,
  10931. 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,
  10932. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  10933. fog: !!fog,
  10934. useFog: material.fog,
  10935. fogExp2: fog && fog.isFogExp2,
  10936. flatShading: material.flatShading,
  10937. sizeAttenuation: material.sizeAttenuation,
  10938. logarithmicDepthBuffer: logarithmicDepthBuffer,
  10939. skinning: material.skinning && maxBones > 0,
  10940. maxBones: maxBones,
  10941. useVertexTexture: floatVertexTextures,
  10942. morphTargets: material.morphTargets,
  10943. morphNormals: material.morphNormals,
  10944. maxMorphTargets: renderer.maxMorphTargets,
  10945. maxMorphNormals: renderer.maxMorphNormals,
  10946. numDirLights: lights.directional.length,
  10947. numPointLights: lights.point.length,
  10948. numSpotLights: lights.spot.length,
  10949. numRectAreaLights: lights.rectArea.length,
  10950. numHemiLights: lights.hemi.length,
  10951. numDirLightShadows: lights.directionalShadowMap.length,
  10952. numPointLightShadows: lights.pointShadowMap.length,
  10953. numSpotLightShadows: lights.spotShadowMap.length,
  10954. numClippingPlanes: clipping.numPlanes,
  10955. numClipIntersection: clipping.numIntersection,
  10956. dithering: material.dithering,
  10957. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  10958. shadowMapType: renderer.shadowMap.type,
  10959. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  10960. physicallyCorrectLights: renderer.physicallyCorrectLights,
  10961. premultipliedAlpha: material.premultipliedAlpha,
  10962. alphaTest: material.alphaTest,
  10963. doubleSided: material.side === DoubleSide,
  10964. flipSided: material.side === BackSide,
  10965. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  10966. index0AttributeName: material.index0AttributeName,
  10967. extensionDerivatives: material.extensions && material.extensions.derivatives,
  10968. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  10969. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  10970. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  10971. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  10972. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  10973. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  10974. customProgramCacheKey: material.customProgramCacheKey()
  10975. };
  10976. return parameters;
  10977. }
  10978. function getProgramCacheKey(parameters) {
  10979. var array = [];
  10980. if (parameters.shaderID) {
  10981. array.push(parameters.shaderID);
  10982. } else {
  10983. array.push(parameters.fragmentShader);
  10984. array.push(parameters.vertexShader);
  10985. }
  10986. if (parameters.defines !== undefined) {
  10987. for (var name in parameters.defines) {
  10988. array.push(name);
  10989. array.push(parameters.defines[name]);
  10990. }
  10991. }
  10992. if (parameters.isRawShaderMaterial === false) {
  10993. for (var i = 0; i < parameterNames.length; i++) {
  10994. array.push(parameters[parameterNames[i]]);
  10995. }
  10996. array.push(renderer.outputEncoding);
  10997. array.push(renderer.gammaFactor);
  10998. }
  10999. array.push(parameters.customProgramCacheKey);
  11000. return array.join();
  11001. }
  11002. function getUniforms(material) {
  11003. var shaderID = shaderIDs[material.type];
  11004. var uniforms;
  11005. if (shaderID) {
  11006. var shader = ShaderLib[shaderID];
  11007. uniforms = UniformsUtils.clone(shader.uniforms);
  11008. } else {
  11009. uniforms = material.uniforms;
  11010. }
  11011. return uniforms;
  11012. }
  11013. function acquireProgram(parameters, cacheKey) {
  11014. var program; // Check if code has been already compiled
  11015. for (var p = 0, pl = programs.length; p < pl; p++) {
  11016. var preexistingProgram = programs[p];
  11017. if (preexistingProgram.cacheKey === cacheKey) {
  11018. program = preexistingProgram;
  11019. ++program.usedTimes;
  11020. break;
  11021. }
  11022. }
  11023. if (program === undefined) {
  11024. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11025. programs.push(program);
  11026. }
  11027. return program;
  11028. }
  11029. function releaseProgram(program) {
  11030. if (--program.usedTimes === 0) {
  11031. // Remove from unordered set
  11032. var i = programs.indexOf(program);
  11033. programs[i] = programs[programs.length - 1];
  11034. programs.pop(); // Free WebGL resources
  11035. program.destroy();
  11036. }
  11037. }
  11038. return {
  11039. getParameters: getParameters,
  11040. getProgramCacheKey: getProgramCacheKey,
  11041. getUniforms: getUniforms,
  11042. acquireProgram: acquireProgram,
  11043. releaseProgram: releaseProgram,
  11044. // Exposed for resource monitoring & error feedback via renderer.info:
  11045. programs: programs
  11046. };
  11047. }
  11048. function WebGLProperties() {
  11049. var properties = new WeakMap();
  11050. function get(object) {
  11051. var map = properties.get(object);
  11052. if (map === undefined) {
  11053. map = {};
  11054. properties.set(object, map);
  11055. }
  11056. return map;
  11057. }
  11058. function remove(object) {
  11059. properties.delete(object);
  11060. }
  11061. function update(object, key, value) {
  11062. properties.get(object)[key] = value;
  11063. }
  11064. function dispose() {
  11065. properties = new WeakMap();
  11066. }
  11067. return {
  11068. get: get,
  11069. remove: remove,
  11070. update: update,
  11071. dispose: dispose
  11072. };
  11073. }
  11074. function painterSortStable(a, b) {
  11075. if (a.groupOrder !== b.groupOrder) {
  11076. return a.groupOrder - b.groupOrder;
  11077. } else if (a.renderOrder !== b.renderOrder) {
  11078. return a.renderOrder - b.renderOrder;
  11079. } else if (a.program !== b.program) {
  11080. return a.program.id - b.program.id;
  11081. } else if (a.material.id !== b.material.id) {
  11082. return a.material.id - b.material.id;
  11083. } else if (a.z !== b.z) {
  11084. return a.z - b.z;
  11085. } else {
  11086. return a.id - b.id;
  11087. }
  11088. }
  11089. function reversePainterSortStable(a, b) {
  11090. if (a.groupOrder !== b.groupOrder) {
  11091. return a.groupOrder - b.groupOrder;
  11092. } else if (a.renderOrder !== b.renderOrder) {
  11093. return a.renderOrder - b.renderOrder;
  11094. } else if (a.z !== b.z) {
  11095. return b.z - a.z;
  11096. } else {
  11097. return a.id - b.id;
  11098. }
  11099. }
  11100. function WebGLRenderList(properties) {
  11101. var renderItems = [];
  11102. var renderItemsIndex = 0;
  11103. var opaque = [];
  11104. var transparent = [];
  11105. var defaultProgram = {
  11106. id: -1
  11107. };
  11108. function init() {
  11109. renderItemsIndex = 0;
  11110. opaque.length = 0;
  11111. transparent.length = 0;
  11112. }
  11113. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11114. var renderItem = renderItems[renderItemsIndex];
  11115. var materialProperties = properties.get(material);
  11116. if (renderItem === undefined) {
  11117. renderItem = {
  11118. id: object.id,
  11119. object: object,
  11120. geometry: geometry,
  11121. material: material,
  11122. program: materialProperties.program || defaultProgram,
  11123. groupOrder: groupOrder,
  11124. renderOrder: object.renderOrder,
  11125. z: z,
  11126. group: group
  11127. };
  11128. renderItems[renderItemsIndex] = renderItem;
  11129. } else {
  11130. renderItem.id = object.id;
  11131. renderItem.object = object;
  11132. renderItem.geometry = geometry;
  11133. renderItem.material = material;
  11134. renderItem.program = materialProperties.program || defaultProgram;
  11135. renderItem.groupOrder = groupOrder;
  11136. renderItem.renderOrder = object.renderOrder;
  11137. renderItem.z = z;
  11138. renderItem.group = group;
  11139. }
  11140. renderItemsIndex++;
  11141. return renderItem;
  11142. }
  11143. function push(object, geometry, material, groupOrder, z, group) {
  11144. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11145. (material.transparent === true ? transparent : opaque).push(renderItem);
  11146. }
  11147. function unshift(object, geometry, material, groupOrder, z, group) {
  11148. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11149. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11150. }
  11151. function sort(customOpaqueSort, customTransparentSort) {
  11152. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11153. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11154. }
  11155. function finish() {
  11156. // Clear references from inactive renderItems in the list
  11157. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11158. var renderItem = renderItems[i];
  11159. if (renderItem.id === null) break;
  11160. renderItem.id = null;
  11161. renderItem.object = null;
  11162. renderItem.geometry = null;
  11163. renderItem.material = null;
  11164. renderItem.program = null;
  11165. renderItem.group = null;
  11166. }
  11167. }
  11168. return {
  11169. opaque: opaque,
  11170. transparent: transparent,
  11171. init: init,
  11172. push: push,
  11173. unshift: unshift,
  11174. finish: finish,
  11175. sort: sort
  11176. };
  11177. }
  11178. function WebGLRenderLists(properties) {
  11179. var lists = new WeakMap();
  11180. function get(scene, camera) {
  11181. var cameras = lists.get(scene);
  11182. var list;
  11183. if (cameras === undefined) {
  11184. list = new WebGLRenderList(properties);
  11185. lists.set(scene, new WeakMap());
  11186. lists.get(scene).set(camera, list);
  11187. } else {
  11188. list = cameras.get(camera);
  11189. if (list === undefined) {
  11190. list = new WebGLRenderList(properties);
  11191. cameras.set(camera, list);
  11192. }
  11193. }
  11194. return list;
  11195. }
  11196. function dispose() {
  11197. lists = new WeakMap();
  11198. }
  11199. return {
  11200. get: get,
  11201. dispose: dispose
  11202. };
  11203. }
  11204. function UniformsCache() {
  11205. var lights = {};
  11206. return {
  11207. get: function get(light) {
  11208. if (lights[light.id] !== undefined) {
  11209. return lights[light.id];
  11210. }
  11211. var uniforms;
  11212. switch (light.type) {
  11213. case 'DirectionalLight':
  11214. uniforms = {
  11215. direction: new Vector3(),
  11216. color: new Color()
  11217. };
  11218. break;
  11219. case 'SpotLight':
  11220. uniforms = {
  11221. position: new Vector3(),
  11222. direction: new Vector3(),
  11223. color: new Color(),
  11224. distance: 0,
  11225. coneCos: 0,
  11226. penumbraCos: 0,
  11227. decay: 0
  11228. };
  11229. break;
  11230. case 'PointLight':
  11231. uniforms = {
  11232. position: new Vector3(),
  11233. color: new Color(),
  11234. distance: 0,
  11235. decay: 0
  11236. };
  11237. break;
  11238. case 'HemisphereLight':
  11239. uniforms = {
  11240. direction: new Vector3(),
  11241. skyColor: new Color(),
  11242. groundColor: new Color()
  11243. };
  11244. break;
  11245. case 'RectAreaLight':
  11246. uniforms = {
  11247. color: new Color(),
  11248. position: new Vector3(),
  11249. halfWidth: new Vector3(),
  11250. halfHeight: new Vector3()
  11251. };
  11252. break;
  11253. }
  11254. lights[light.id] = uniforms;
  11255. return uniforms;
  11256. }
  11257. };
  11258. }
  11259. function ShadowUniformsCache() {
  11260. var lights = {};
  11261. return {
  11262. get: function get(light) {
  11263. if (lights[light.id] !== undefined) {
  11264. return lights[light.id];
  11265. }
  11266. var uniforms;
  11267. switch (light.type) {
  11268. case 'DirectionalLight':
  11269. uniforms = {
  11270. shadowBias: 0,
  11271. shadowNormalBias: 0,
  11272. shadowRadius: 1,
  11273. shadowMapSize: new Vector2()
  11274. };
  11275. break;
  11276. case 'SpotLight':
  11277. uniforms = {
  11278. shadowBias: 0,
  11279. shadowNormalBias: 0,
  11280. shadowRadius: 1,
  11281. shadowMapSize: new Vector2()
  11282. };
  11283. break;
  11284. case 'PointLight':
  11285. uniforms = {
  11286. shadowBias: 0,
  11287. shadowNormalBias: 0,
  11288. shadowRadius: 1,
  11289. shadowMapSize: new Vector2(),
  11290. shadowCameraNear: 1,
  11291. shadowCameraFar: 1000
  11292. };
  11293. break;
  11294. // TODO (abelnation): set RectAreaLight shadow uniforms
  11295. }
  11296. lights[light.id] = uniforms;
  11297. return uniforms;
  11298. }
  11299. };
  11300. }
  11301. var nextVersion = 0;
  11302. function shadowCastingLightsFirst(lightA, lightB) {
  11303. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  11304. }
  11305. function WebGLLights() {
  11306. var cache = new UniformsCache();
  11307. var shadowCache = ShadowUniformsCache();
  11308. var state = {
  11309. version: 0,
  11310. hash: {
  11311. directionalLength: -1,
  11312. pointLength: -1,
  11313. spotLength: -1,
  11314. rectAreaLength: -1,
  11315. hemiLength: -1,
  11316. numDirectionalShadows: -1,
  11317. numPointShadows: -1,
  11318. numSpotShadows: -1
  11319. },
  11320. ambient: [0, 0, 0],
  11321. probe: [],
  11322. directional: [],
  11323. directionalShadow: [],
  11324. directionalShadowMap: [],
  11325. directionalShadowMatrix: [],
  11326. spot: [],
  11327. spotShadow: [],
  11328. spotShadowMap: [],
  11329. spotShadowMatrix: [],
  11330. rectArea: [],
  11331. rectAreaLTC1: null,
  11332. rectAreaLTC2: null,
  11333. point: [],
  11334. pointShadow: [],
  11335. pointShadowMap: [],
  11336. pointShadowMatrix: [],
  11337. hemi: []
  11338. };
  11339. for (var i = 0; i < 9; i++) {
  11340. state.probe.push(new Vector3());
  11341. }
  11342. var vector3 = new Vector3();
  11343. var matrix4 = new Matrix4();
  11344. var matrix42 = new Matrix4();
  11345. function setup(lights, shadows, camera) {
  11346. var r = 0,
  11347. g = 0,
  11348. b = 0;
  11349. for (var _i = 0; _i < 9; _i++) {
  11350. state.probe[_i].set(0, 0, 0);
  11351. }
  11352. var directionalLength = 0;
  11353. var pointLength = 0;
  11354. var spotLength = 0;
  11355. var rectAreaLength = 0;
  11356. var hemiLength = 0;
  11357. var numDirectionalShadows = 0;
  11358. var numPointShadows = 0;
  11359. var numSpotShadows = 0;
  11360. var viewMatrix = camera.matrixWorldInverse;
  11361. lights.sort(shadowCastingLightsFirst);
  11362. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  11363. var light = lights[_i2];
  11364. var color = light.color;
  11365. var intensity = light.intensity;
  11366. var distance = light.distance;
  11367. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  11368. if (light.isAmbientLight) {
  11369. r += color.r * intensity;
  11370. g += color.g * intensity;
  11371. b += color.b * intensity;
  11372. } else if (light.isLightProbe) {
  11373. for (var j = 0; j < 9; j++) {
  11374. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  11375. }
  11376. } else if (light.isDirectionalLight) {
  11377. var uniforms = cache.get(light);
  11378. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  11379. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11380. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11381. uniforms.direction.sub(vector3);
  11382. uniforms.direction.transformDirection(viewMatrix);
  11383. if (light.castShadow) {
  11384. var shadow = light.shadow;
  11385. var shadowUniforms = shadowCache.get(light);
  11386. shadowUniforms.shadowBias = shadow.bias;
  11387. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11388. shadowUniforms.shadowRadius = shadow.radius;
  11389. shadowUniforms.shadowMapSize = shadow.mapSize;
  11390. state.directionalShadow[directionalLength] = shadowUniforms;
  11391. state.directionalShadowMap[directionalLength] = shadowMap;
  11392. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  11393. numDirectionalShadows++;
  11394. }
  11395. state.directional[directionalLength] = uniforms;
  11396. directionalLength++;
  11397. } else if (light.isSpotLight) {
  11398. var _uniforms = cache.get(light);
  11399. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  11400. _uniforms.position.applyMatrix4(viewMatrix);
  11401. _uniforms.color.copy(color).multiplyScalar(intensity);
  11402. _uniforms.distance = distance;
  11403. _uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11404. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11405. _uniforms.direction.sub(vector3);
  11406. _uniforms.direction.transformDirection(viewMatrix);
  11407. _uniforms.coneCos = Math.cos(light.angle);
  11408. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  11409. _uniforms.decay = light.decay;
  11410. if (light.castShadow) {
  11411. var _shadow = light.shadow;
  11412. var _shadowUniforms = shadowCache.get(light);
  11413. _shadowUniforms.shadowBias = _shadow.bias;
  11414. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  11415. _shadowUniforms.shadowRadius = _shadow.radius;
  11416. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  11417. state.spotShadow[spotLength] = _shadowUniforms;
  11418. state.spotShadowMap[spotLength] = shadowMap;
  11419. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  11420. numSpotShadows++;
  11421. }
  11422. state.spot[spotLength] = _uniforms;
  11423. spotLength++;
  11424. } else if (light.isRectAreaLight) {
  11425. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  11426. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11427. // (b) intensity is the brightness of the light
  11428. _uniforms2.color.copy(color).multiplyScalar(intensity);
  11429. _uniforms2.position.setFromMatrixPosition(light.matrixWorld);
  11430. _uniforms2.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  11431. matrix42.identity();
  11432. matrix4.copy(light.matrixWorld);
  11433. matrix4.premultiply(viewMatrix);
  11434. matrix42.extractRotation(matrix4);
  11435. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  11436. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  11437. _uniforms2.halfWidth.applyMatrix4(matrix42);
  11438. _uniforms2.halfHeight.applyMatrix4(matrix42); // TODO (abelnation): RectAreaLight distance?
  11439. // uniforms.distance = distance;
  11440. state.rectArea[rectAreaLength] = _uniforms2;
  11441. rectAreaLength++;
  11442. } else if (light.isPointLight) {
  11443. var _uniforms3 = cache.get(light);
  11444. _uniforms3.position.setFromMatrixPosition(light.matrixWorld);
  11445. _uniforms3.position.applyMatrix4(viewMatrix);
  11446. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  11447. _uniforms3.distance = light.distance;
  11448. _uniforms3.decay = light.decay;
  11449. if (light.castShadow) {
  11450. var _shadow2 = light.shadow;
  11451. var _shadowUniforms2 = shadowCache.get(light);
  11452. _shadowUniforms2.shadowBias = _shadow2.bias;
  11453. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  11454. _shadowUniforms2.shadowRadius = _shadow2.radius;
  11455. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  11456. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  11457. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  11458. state.pointShadow[pointLength] = _shadowUniforms2;
  11459. state.pointShadowMap[pointLength] = shadowMap;
  11460. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  11461. numPointShadows++;
  11462. }
  11463. state.point[pointLength] = _uniforms3;
  11464. pointLength++;
  11465. } else if (light.isHemisphereLight) {
  11466. var _uniforms4 = cache.get(light);
  11467. _uniforms4.direction.setFromMatrixPosition(light.matrixWorld);
  11468. _uniforms4.direction.transformDirection(viewMatrix);
  11469. _uniforms4.direction.normalize();
  11470. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  11471. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  11472. state.hemi[hemiLength] = _uniforms4;
  11473. hemiLength++;
  11474. }
  11475. }
  11476. if (rectAreaLength > 0) {
  11477. state.rectAreaLTC1 = UniformsLib.LTC_1;
  11478. state.rectAreaLTC2 = UniformsLib.LTC_2;
  11479. }
  11480. state.ambient[0] = r;
  11481. state.ambient[1] = g;
  11482. state.ambient[2] = b;
  11483. var hash = state.hash;
  11484. 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) {
  11485. state.directional.length = directionalLength;
  11486. state.spot.length = spotLength;
  11487. state.rectArea.length = rectAreaLength;
  11488. state.point.length = pointLength;
  11489. state.hemi.length = hemiLength;
  11490. state.directionalShadow.length = numDirectionalShadows;
  11491. state.directionalShadowMap.length = numDirectionalShadows;
  11492. state.pointShadow.length = numPointShadows;
  11493. state.pointShadowMap.length = numPointShadows;
  11494. state.spotShadow.length = numSpotShadows;
  11495. state.spotShadowMap.length = numSpotShadows;
  11496. state.directionalShadowMatrix.length = numDirectionalShadows;
  11497. state.pointShadowMatrix.length = numPointShadows;
  11498. state.spotShadowMatrix.length = numSpotShadows;
  11499. hash.directionalLength = directionalLength;
  11500. hash.pointLength = pointLength;
  11501. hash.spotLength = spotLength;
  11502. hash.rectAreaLength = rectAreaLength;
  11503. hash.hemiLength = hemiLength;
  11504. hash.numDirectionalShadows = numDirectionalShadows;
  11505. hash.numPointShadows = numPointShadows;
  11506. hash.numSpotShadows = numSpotShadows;
  11507. state.version = nextVersion++;
  11508. }
  11509. }
  11510. return {
  11511. setup: setup,
  11512. state: state
  11513. };
  11514. }
  11515. function WebGLRenderState() {
  11516. var lights = new WebGLLights();
  11517. var lightsArray = [];
  11518. var shadowsArray = [];
  11519. function init() {
  11520. lightsArray.length = 0;
  11521. shadowsArray.length = 0;
  11522. }
  11523. function pushLight(light) {
  11524. lightsArray.push(light);
  11525. }
  11526. function pushShadow(shadowLight) {
  11527. shadowsArray.push(shadowLight);
  11528. }
  11529. function setupLights(camera) {
  11530. lights.setup(lightsArray, shadowsArray, camera);
  11531. }
  11532. var state = {
  11533. lightsArray: lightsArray,
  11534. shadowsArray: shadowsArray,
  11535. lights: lights
  11536. };
  11537. return {
  11538. init: init,
  11539. state: state,
  11540. setupLights: setupLights,
  11541. pushLight: pushLight,
  11542. pushShadow: pushShadow
  11543. };
  11544. }
  11545. function WebGLRenderStates() {
  11546. var renderStates = new WeakMap();
  11547. function get(scene, camera) {
  11548. var renderState;
  11549. if (renderStates.has(scene) === false) {
  11550. renderState = new WebGLRenderState();
  11551. renderStates.set(scene, new WeakMap());
  11552. renderStates.get(scene).set(camera, renderState);
  11553. } else {
  11554. if (renderStates.get(scene).has(camera) === false) {
  11555. renderState = new WebGLRenderState();
  11556. renderStates.get(scene).set(camera, renderState);
  11557. } else {
  11558. renderState = renderStates.get(scene).get(camera);
  11559. }
  11560. }
  11561. return renderState;
  11562. }
  11563. function dispose() {
  11564. renderStates = new WeakMap();
  11565. }
  11566. return {
  11567. get: get,
  11568. dispose: dispose
  11569. };
  11570. }
  11571. /**
  11572. * parameters = {
  11573. *
  11574. * opacity: <float>,
  11575. *
  11576. * map: new THREE.Texture( <Image> ),
  11577. *
  11578. * alphaMap: new THREE.Texture( <Image> ),
  11579. *
  11580. * displacementMap: new THREE.Texture( <Image> ),
  11581. * displacementScale: <float>,
  11582. * displacementBias: <float>,
  11583. *
  11584. * wireframe: <boolean>,
  11585. * wireframeLinewidth: <float>
  11586. * }
  11587. */
  11588. function MeshDepthMaterial(parameters) {
  11589. Material.call(this);
  11590. this.type = 'MeshDepthMaterial';
  11591. this.depthPacking = BasicDepthPacking;
  11592. this.skinning = false;
  11593. this.morphTargets = false;
  11594. this.map = null;
  11595. this.alphaMap = null;
  11596. this.displacementMap = null;
  11597. this.displacementScale = 1;
  11598. this.displacementBias = 0;
  11599. this.wireframe = false;
  11600. this.wireframeLinewidth = 1;
  11601. this.fog = false;
  11602. this.setValues(parameters);
  11603. }
  11604. MeshDepthMaterial.prototype = Object.create(Material.prototype);
  11605. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11606. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11607. MeshDepthMaterial.prototype.copy = function (source) {
  11608. Material.prototype.copy.call(this, source);
  11609. this.depthPacking = source.depthPacking;
  11610. this.skinning = source.skinning;
  11611. this.morphTargets = source.morphTargets;
  11612. this.map = source.map;
  11613. this.alphaMap = source.alphaMap;
  11614. this.displacementMap = source.displacementMap;
  11615. this.displacementScale = source.displacementScale;
  11616. this.displacementBias = source.displacementBias;
  11617. this.wireframe = source.wireframe;
  11618. this.wireframeLinewidth = source.wireframeLinewidth;
  11619. return this;
  11620. };
  11621. /**
  11622. * parameters = {
  11623. *
  11624. * referencePosition: <float>,
  11625. * nearDistance: <float>,
  11626. * farDistance: <float>,
  11627. *
  11628. * skinning: <bool>,
  11629. * morphTargets: <bool>,
  11630. *
  11631. * map: new THREE.Texture( <Image> ),
  11632. *
  11633. * alphaMap: new THREE.Texture( <Image> ),
  11634. *
  11635. * displacementMap: new THREE.Texture( <Image> ),
  11636. * displacementScale: <float>,
  11637. * displacementBias: <float>
  11638. *
  11639. * }
  11640. */
  11641. function MeshDistanceMaterial(parameters) {
  11642. Material.call(this);
  11643. this.type = 'MeshDistanceMaterial';
  11644. this.referencePosition = new Vector3();
  11645. this.nearDistance = 1;
  11646. this.farDistance = 1000;
  11647. this.skinning = false;
  11648. this.morphTargets = false;
  11649. this.map = null;
  11650. this.alphaMap = null;
  11651. this.displacementMap = null;
  11652. this.displacementScale = 1;
  11653. this.displacementBias = 0;
  11654. this.fog = false;
  11655. this.setValues(parameters);
  11656. }
  11657. MeshDistanceMaterial.prototype = Object.create(Material.prototype);
  11658. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11659. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11660. MeshDistanceMaterial.prototype.copy = function (source) {
  11661. Material.prototype.copy.call(this, source);
  11662. this.referencePosition.copy(source.referencePosition);
  11663. this.nearDistance = source.nearDistance;
  11664. this.farDistance = source.farDistance;
  11665. this.skinning = source.skinning;
  11666. this.morphTargets = source.morphTargets;
  11667. this.map = source.map;
  11668. this.alphaMap = source.alphaMap;
  11669. this.displacementMap = source.displacementMap;
  11670. this.displacementScale = source.displacementScale;
  11671. this.displacementBias = source.displacementBias;
  11672. return this;
  11673. };
  11674. var vsm_frag = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n\tfor ( float i = -1.0; i < 1.0 ; i += SAMPLE_RATE) {\n\t\t#ifdef HORIZONAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, i ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean * HALF_SAMPLE_RATE;\n\tsquared_mean = squared_mean * HALF_SAMPLE_RATE;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";
  11675. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  11676. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  11677. var _frustum = new Frustum();
  11678. var _shadowMapSize = new Vector2(),
  11679. _viewportSize = new Vector2(),
  11680. _viewport = new Vector4(),
  11681. _depthMaterials = [],
  11682. _distanceMaterials = [],
  11683. _materialCache = {};
  11684. var shadowSide = {
  11685. 0: BackSide,
  11686. 1: FrontSide,
  11687. 2: DoubleSide
  11688. };
  11689. var shadowMaterialVertical = new ShaderMaterial({
  11690. defines: {
  11691. SAMPLE_RATE: 2.0 / 8.0,
  11692. HALF_SAMPLE_RATE: 1.0 / 8.0
  11693. },
  11694. uniforms: {
  11695. shadow_pass: {
  11696. value: null
  11697. },
  11698. resolution: {
  11699. value: new Vector2()
  11700. },
  11701. radius: {
  11702. value: 4.0
  11703. }
  11704. },
  11705. vertexShader: vsm_vert,
  11706. fragmentShader: vsm_frag
  11707. });
  11708. var shadowMaterialHorizonal = shadowMaterialVertical.clone();
  11709. shadowMaterialHorizonal.defines.HORIZONAL_PASS = 1;
  11710. var fullScreenTri = new BufferGeometry();
  11711. fullScreenTri.setAttribute("position", new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  11712. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  11713. var scope = this;
  11714. this.enabled = false;
  11715. this.autoUpdate = true;
  11716. this.needsUpdate = false;
  11717. this.type = PCFShadowMap;
  11718. this.render = function (lights, scene, camera) {
  11719. if (scope.enabled === false) return;
  11720. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  11721. if (lights.length === 0) return;
  11722. var currentRenderTarget = _renderer.getRenderTarget();
  11723. var activeCubeFace = _renderer.getActiveCubeFace();
  11724. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  11725. var _state = _renderer.state; // Set GL state for depth map.
  11726. _state.setBlending(NoBlending);
  11727. _state.buffers.color.setClear(1, 1, 1, 1);
  11728. _state.buffers.depth.setTest(true);
  11729. _state.setScissorTest(false); // render depth map
  11730. for (var i = 0, il = lights.length; i < il; i++) {
  11731. var light = lights[i];
  11732. var shadow = light.shadow;
  11733. if (shadow === undefined) {
  11734. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  11735. continue;
  11736. }
  11737. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  11738. _shadowMapSize.copy(shadow.mapSize);
  11739. var shadowFrameExtents = shadow.getFrameExtents();
  11740. _shadowMapSize.multiply(shadowFrameExtents);
  11741. _viewportSize.copy(shadow.mapSize);
  11742. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  11743. if (_shadowMapSize.x > maxTextureSize) {
  11744. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  11745. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  11746. shadow.mapSize.x = _viewportSize.x;
  11747. }
  11748. if (_shadowMapSize.y > maxTextureSize) {
  11749. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  11750. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  11751. shadow.mapSize.y = _viewportSize.y;
  11752. }
  11753. }
  11754. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  11755. var pars = {
  11756. minFilter: LinearFilter,
  11757. magFilter: LinearFilter,
  11758. format: RGBAFormat
  11759. };
  11760. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  11761. shadow.map.texture.name = light.name + ".shadowMap";
  11762. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  11763. shadow.camera.updateProjectionMatrix();
  11764. }
  11765. if (shadow.map === null) {
  11766. var _pars = {
  11767. minFilter: NearestFilter,
  11768. magFilter: NearestFilter,
  11769. format: RGBAFormat
  11770. };
  11771. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  11772. shadow.map.texture.name = light.name + ".shadowMap";
  11773. shadow.camera.updateProjectionMatrix();
  11774. }
  11775. _renderer.setRenderTarget(shadow.map);
  11776. _renderer.clear();
  11777. var viewportCount = shadow.getViewportCount();
  11778. for (var vp = 0; vp < viewportCount; vp++) {
  11779. var viewport = shadow.getViewport(vp);
  11780. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  11781. _state.viewport(_viewport);
  11782. shadow.updateMatrices(light, vp);
  11783. _frustum = shadow.getFrustum();
  11784. renderObject(scene, camera, shadow.camera, light, this.type);
  11785. } // do blur pass for VSM
  11786. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  11787. VSMPass(shadow, camera);
  11788. }
  11789. shadow.needsUpdate = false;
  11790. }
  11791. scope.needsUpdate = false;
  11792. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  11793. };
  11794. function VSMPass(shadow, camera) {
  11795. var geometry = _objects.update(fullScreenMesh); // vertical pass
  11796. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  11797. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  11798. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  11799. _renderer.setRenderTarget(shadow.mapPass);
  11800. _renderer.clear();
  11801. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizonal pass
  11802. shadowMaterialHorizonal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  11803. shadowMaterialHorizonal.uniforms.resolution.value = shadow.mapSize;
  11804. shadowMaterialHorizonal.uniforms.radius.value = shadow.radius;
  11805. _renderer.setRenderTarget(shadow.map);
  11806. _renderer.clear();
  11807. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizonal, fullScreenMesh, null);
  11808. }
  11809. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  11810. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11811. var material = _depthMaterials[index];
  11812. if (material === undefined) {
  11813. material = new MeshDepthMaterial({
  11814. depthPacking: RGBADepthPacking,
  11815. morphTargets: useMorphing,
  11816. skinning: useSkinning
  11817. });
  11818. _depthMaterials[index] = material;
  11819. }
  11820. return material;
  11821. }
  11822. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  11823. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11824. var material = _distanceMaterials[index];
  11825. if (material === undefined) {
  11826. material = new MeshDistanceMaterial({
  11827. morphTargets: useMorphing,
  11828. skinning: useSkinning
  11829. });
  11830. _distanceMaterials[index] = material;
  11831. }
  11832. return material;
  11833. }
  11834. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  11835. var result = null;
  11836. var getMaterialVariant = getDepthMaterialVariant;
  11837. var customMaterial = object.customDepthMaterial;
  11838. if (light.isPointLight === true) {
  11839. getMaterialVariant = getDistanceMaterialVariant;
  11840. customMaterial = object.customDistanceMaterial;
  11841. }
  11842. if (customMaterial === undefined) {
  11843. var useMorphing = false;
  11844. if (material.morphTargets === true) {
  11845. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11846. }
  11847. var useSkinning = false;
  11848. if (object.isSkinnedMesh === true) {
  11849. if (material.skinning === true) {
  11850. useSkinning = true;
  11851. } else {
  11852. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  11853. }
  11854. }
  11855. var useInstancing = object.isInstancedMesh === true;
  11856. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  11857. } else {
  11858. result = customMaterial;
  11859. }
  11860. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  11861. // in this case we need a unique material instance reflecting the
  11862. // appropriate state
  11863. var keyA = result.uuid,
  11864. keyB = material.uuid;
  11865. var materialsForVariant = _materialCache[keyA];
  11866. if (materialsForVariant === undefined) {
  11867. materialsForVariant = {};
  11868. _materialCache[keyA] = materialsForVariant;
  11869. }
  11870. var cachedMaterial = materialsForVariant[keyB];
  11871. if (cachedMaterial === undefined) {
  11872. cachedMaterial = result.clone();
  11873. materialsForVariant[keyB] = cachedMaterial;
  11874. }
  11875. result = cachedMaterial;
  11876. }
  11877. result.visible = material.visible;
  11878. result.wireframe = material.wireframe;
  11879. if (type === VSMShadowMap) {
  11880. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  11881. } else {
  11882. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  11883. }
  11884. result.clipShadows = material.clipShadows;
  11885. result.clippingPlanes = material.clippingPlanes;
  11886. result.clipIntersection = material.clipIntersection;
  11887. result.wireframeLinewidth = material.wireframeLinewidth;
  11888. result.linewidth = material.linewidth;
  11889. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  11890. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  11891. result.nearDistance = shadowCameraNear;
  11892. result.farDistance = shadowCameraFar;
  11893. }
  11894. return result;
  11895. }
  11896. function renderObject(object, camera, shadowCamera, light, type) {
  11897. if (object.visible === false) return;
  11898. var visible = object.layers.test(camera.layers);
  11899. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  11900. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  11901. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  11902. var geometry = _objects.update(object);
  11903. var material = object.material;
  11904. if (Array.isArray(material)) {
  11905. var groups = geometry.groups;
  11906. for (var k = 0, kl = groups.length; k < kl; k++) {
  11907. var group = groups[k];
  11908. var groupMaterial = material[group.materialIndex];
  11909. if (groupMaterial && groupMaterial.visible) {
  11910. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  11911. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  11912. }
  11913. }
  11914. } else if (material.visible) {
  11915. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  11916. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  11917. }
  11918. }
  11919. }
  11920. var children = object.children;
  11921. for (var i = 0, l = children.length; i < l; i++) {
  11922. renderObject(children[i], camera, shadowCamera, light, type);
  11923. }
  11924. }
  11925. }
  11926. function WebGLState(gl, extensions, capabilities) {
  11927. var _equationToGL, _factorToGL;
  11928. var isWebGL2 = capabilities.isWebGL2;
  11929. function ColorBuffer() {
  11930. var locked = false;
  11931. var color = new Vector4();
  11932. var currentColorMask = null;
  11933. var currentColorClear = new Vector4(0, 0, 0, 0);
  11934. return {
  11935. setMask: function setMask(colorMask) {
  11936. if (currentColorMask !== colorMask && !locked) {
  11937. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  11938. currentColorMask = colorMask;
  11939. }
  11940. },
  11941. setLocked: function setLocked(lock) {
  11942. locked = lock;
  11943. },
  11944. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  11945. if (premultipliedAlpha === true) {
  11946. r *= a;
  11947. g *= a;
  11948. b *= a;
  11949. }
  11950. color.set(r, g, b, a);
  11951. if (currentColorClear.equals(color) === false) {
  11952. gl.clearColor(r, g, b, a);
  11953. currentColorClear.copy(color);
  11954. }
  11955. },
  11956. reset: function reset() {
  11957. locked = false;
  11958. currentColorMask = null;
  11959. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  11960. }
  11961. };
  11962. }
  11963. function DepthBuffer() {
  11964. var locked = false;
  11965. var currentDepthMask = null;
  11966. var currentDepthFunc = null;
  11967. var currentDepthClear = null;
  11968. return {
  11969. setTest: function setTest(depthTest) {
  11970. if (depthTest) {
  11971. enable(2929);
  11972. } else {
  11973. disable(2929);
  11974. }
  11975. },
  11976. setMask: function setMask(depthMask) {
  11977. if (currentDepthMask !== depthMask && !locked) {
  11978. gl.depthMask(depthMask);
  11979. currentDepthMask = depthMask;
  11980. }
  11981. },
  11982. setFunc: function setFunc(depthFunc) {
  11983. if (currentDepthFunc !== depthFunc) {
  11984. if (depthFunc) {
  11985. switch (depthFunc) {
  11986. case NeverDepth:
  11987. gl.depthFunc(512);
  11988. break;
  11989. case AlwaysDepth:
  11990. gl.depthFunc(519);
  11991. break;
  11992. case LessDepth:
  11993. gl.depthFunc(513);
  11994. break;
  11995. case LessEqualDepth:
  11996. gl.depthFunc(515);
  11997. break;
  11998. case EqualDepth:
  11999. gl.depthFunc(514);
  12000. break;
  12001. case GreaterEqualDepth:
  12002. gl.depthFunc(518);
  12003. break;
  12004. case GreaterDepth:
  12005. gl.depthFunc(516);
  12006. break;
  12007. case NotEqualDepth:
  12008. gl.depthFunc(517);
  12009. break;
  12010. default:
  12011. gl.depthFunc(515);
  12012. }
  12013. } else {
  12014. gl.depthFunc(515);
  12015. }
  12016. currentDepthFunc = depthFunc;
  12017. }
  12018. },
  12019. setLocked: function setLocked(lock) {
  12020. locked = lock;
  12021. },
  12022. setClear: function setClear(depth) {
  12023. if (currentDepthClear !== depth) {
  12024. gl.clearDepth(depth);
  12025. currentDepthClear = depth;
  12026. }
  12027. },
  12028. reset: function reset() {
  12029. locked = false;
  12030. currentDepthMask = null;
  12031. currentDepthFunc = null;
  12032. currentDepthClear = null;
  12033. }
  12034. };
  12035. }
  12036. function StencilBuffer() {
  12037. var locked = false;
  12038. var currentStencilMask = null;
  12039. var currentStencilFunc = null;
  12040. var currentStencilRef = null;
  12041. var currentStencilFuncMask = null;
  12042. var currentStencilFail = null;
  12043. var currentStencilZFail = null;
  12044. var currentStencilZPass = null;
  12045. var currentStencilClear = null;
  12046. return {
  12047. setTest: function setTest(stencilTest) {
  12048. if (!locked) {
  12049. if (stencilTest) {
  12050. enable(2960);
  12051. } else {
  12052. disable(2960);
  12053. }
  12054. }
  12055. },
  12056. setMask: function setMask(stencilMask) {
  12057. if (currentStencilMask !== stencilMask && !locked) {
  12058. gl.stencilMask(stencilMask);
  12059. currentStencilMask = stencilMask;
  12060. }
  12061. },
  12062. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12063. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12064. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12065. currentStencilFunc = stencilFunc;
  12066. currentStencilRef = stencilRef;
  12067. currentStencilFuncMask = stencilMask;
  12068. }
  12069. },
  12070. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12071. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12072. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12073. currentStencilFail = stencilFail;
  12074. currentStencilZFail = stencilZFail;
  12075. currentStencilZPass = stencilZPass;
  12076. }
  12077. },
  12078. setLocked: function setLocked(lock) {
  12079. locked = lock;
  12080. },
  12081. setClear: function setClear(stencil) {
  12082. if (currentStencilClear !== stencil) {
  12083. gl.clearStencil(stencil);
  12084. currentStencilClear = stencil;
  12085. }
  12086. },
  12087. reset: function reset() {
  12088. locked = false;
  12089. currentStencilMask = null;
  12090. currentStencilFunc = null;
  12091. currentStencilRef = null;
  12092. currentStencilFuncMask = null;
  12093. currentStencilFail = null;
  12094. currentStencilZFail = null;
  12095. currentStencilZPass = null;
  12096. currentStencilClear = null;
  12097. }
  12098. };
  12099. } //
  12100. var colorBuffer = new ColorBuffer();
  12101. var depthBuffer = new DepthBuffer();
  12102. var stencilBuffer = new StencilBuffer();
  12103. var enabledCapabilities = {};
  12104. var currentProgram = null;
  12105. var currentBlendingEnabled = null;
  12106. var currentBlending = null;
  12107. var currentBlendEquation = null;
  12108. var currentBlendSrc = null;
  12109. var currentBlendDst = null;
  12110. var currentBlendEquationAlpha = null;
  12111. var currentBlendSrcAlpha = null;
  12112. var currentBlendDstAlpha = null;
  12113. var currentPremultipledAlpha = false;
  12114. var currentFlipSided = null;
  12115. var currentCullFace = null;
  12116. var currentLineWidth = null;
  12117. var currentPolygonOffsetFactor = null;
  12118. var currentPolygonOffsetUnits = null;
  12119. var maxTextures = gl.getParameter(35661);
  12120. var lineWidthAvailable = false;
  12121. var version = 0;
  12122. var glVersion = gl.getParameter(7938);
  12123. if (glVersion.indexOf('WebGL') !== -1) {
  12124. version = parseFloat(/^WebGL\ ([0-9])/.exec(glVersion)[1]);
  12125. lineWidthAvailable = version >= 1.0;
  12126. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12127. version = parseFloat(/^OpenGL\ ES\ ([0-9])/.exec(glVersion)[1]);
  12128. lineWidthAvailable = version >= 2.0;
  12129. }
  12130. var currentTextureSlot = null;
  12131. var currentBoundTextures = {};
  12132. var currentScissor = new Vector4();
  12133. var currentViewport = new Vector4();
  12134. function createTexture(type, target, count) {
  12135. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12136. var texture = gl.createTexture();
  12137. gl.bindTexture(type, texture);
  12138. gl.texParameteri(type, 10241, 9728);
  12139. gl.texParameteri(type, 10240, 9728);
  12140. for (var i = 0; i < count; i++) {
  12141. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12142. }
  12143. return texture;
  12144. }
  12145. var emptyTextures = {};
  12146. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12147. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12148. colorBuffer.setClear(0, 0, 0, 1);
  12149. depthBuffer.setClear(1);
  12150. stencilBuffer.setClear(0);
  12151. enable(2929);
  12152. depthBuffer.setFunc(LessEqualDepth);
  12153. setFlipSided(false);
  12154. setCullFace(CullFaceBack);
  12155. enable(2884);
  12156. setBlending(NoBlending); //
  12157. function enable(id) {
  12158. if (enabledCapabilities[id] !== true) {
  12159. gl.enable(id);
  12160. enabledCapabilities[id] = true;
  12161. }
  12162. }
  12163. function disable(id) {
  12164. if (enabledCapabilities[id] !== false) {
  12165. gl.disable(id);
  12166. enabledCapabilities[id] = false;
  12167. }
  12168. }
  12169. function useProgram(program) {
  12170. if (currentProgram !== program) {
  12171. gl.useProgram(program);
  12172. currentProgram = program;
  12173. return true;
  12174. }
  12175. return false;
  12176. }
  12177. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12178. if (isWebGL2) {
  12179. equationToGL[MinEquation] = 32775;
  12180. equationToGL[MaxEquation] = 32776;
  12181. } else {
  12182. var extension = extensions.get('EXT_blend_minmax');
  12183. if (extension !== null) {
  12184. equationToGL[MinEquation] = extension.MIN_EXT;
  12185. equationToGL[MaxEquation] = extension.MAX_EXT;
  12186. }
  12187. }
  12188. 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);
  12189. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  12190. if (blending === NoBlending) {
  12191. if (currentBlendingEnabled) {
  12192. disable(3042);
  12193. currentBlendingEnabled = false;
  12194. }
  12195. return;
  12196. }
  12197. if (!currentBlendingEnabled) {
  12198. enable(3042);
  12199. currentBlendingEnabled = true;
  12200. }
  12201. if (blending !== CustomBlending) {
  12202. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  12203. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  12204. gl.blendEquation(32774);
  12205. currentBlendEquation = AddEquation;
  12206. currentBlendEquationAlpha = AddEquation;
  12207. }
  12208. if (premultipliedAlpha) {
  12209. switch (blending) {
  12210. case NormalBlending:
  12211. gl.blendFuncSeparate(1, 771, 1, 771);
  12212. break;
  12213. case AdditiveBlending:
  12214. gl.blendFunc(1, 1);
  12215. break;
  12216. case SubtractiveBlending:
  12217. gl.blendFuncSeparate(0, 0, 769, 771);
  12218. break;
  12219. case MultiplyBlending:
  12220. gl.blendFuncSeparate(0, 768, 0, 770);
  12221. break;
  12222. default:
  12223. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12224. break;
  12225. }
  12226. } else {
  12227. switch (blending) {
  12228. case NormalBlending:
  12229. gl.blendFuncSeparate(770, 771, 1, 771);
  12230. break;
  12231. case AdditiveBlending:
  12232. gl.blendFunc(770, 1);
  12233. break;
  12234. case SubtractiveBlending:
  12235. gl.blendFunc(0, 769);
  12236. break;
  12237. case MultiplyBlending:
  12238. gl.blendFunc(0, 768);
  12239. break;
  12240. default:
  12241. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12242. break;
  12243. }
  12244. }
  12245. currentBlendSrc = null;
  12246. currentBlendDst = null;
  12247. currentBlendSrcAlpha = null;
  12248. currentBlendDstAlpha = null;
  12249. currentBlending = blending;
  12250. currentPremultipledAlpha = premultipliedAlpha;
  12251. }
  12252. return;
  12253. } // custom blending
  12254. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12255. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12256. blendDstAlpha = blendDstAlpha || blendDst;
  12257. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  12258. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  12259. currentBlendEquation = blendEquation;
  12260. currentBlendEquationAlpha = blendEquationAlpha;
  12261. }
  12262. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  12263. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  12264. currentBlendSrc = blendSrc;
  12265. currentBlendDst = blendDst;
  12266. currentBlendSrcAlpha = blendSrcAlpha;
  12267. currentBlendDstAlpha = blendDstAlpha;
  12268. }
  12269. currentBlending = blending;
  12270. currentPremultipledAlpha = null;
  12271. }
  12272. function setMaterial(material, frontFaceCW) {
  12273. material.side === DoubleSide ? disable(2884) : enable(2884);
  12274. var flipSided = material.side === BackSide;
  12275. if (frontFaceCW) flipSided = !flipSided;
  12276. setFlipSided(flipSided);
  12277. 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);
  12278. depthBuffer.setFunc(material.depthFunc);
  12279. depthBuffer.setTest(material.depthTest);
  12280. depthBuffer.setMask(material.depthWrite);
  12281. colorBuffer.setMask(material.colorWrite);
  12282. var stencilWrite = material.stencilWrite;
  12283. stencilBuffer.setTest(stencilWrite);
  12284. if (stencilWrite) {
  12285. stencilBuffer.setMask(material.stencilWriteMask);
  12286. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  12287. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  12288. }
  12289. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  12290. } //
  12291. function setFlipSided(flipSided) {
  12292. if (currentFlipSided !== flipSided) {
  12293. if (flipSided) {
  12294. gl.frontFace(2304);
  12295. } else {
  12296. gl.frontFace(2305);
  12297. }
  12298. currentFlipSided = flipSided;
  12299. }
  12300. }
  12301. function setCullFace(cullFace) {
  12302. if (cullFace !== CullFaceNone) {
  12303. enable(2884);
  12304. if (cullFace !== currentCullFace) {
  12305. if (cullFace === CullFaceBack) {
  12306. gl.cullFace(1029);
  12307. } else if (cullFace === CullFaceFront) {
  12308. gl.cullFace(1028);
  12309. } else {
  12310. gl.cullFace(1032);
  12311. }
  12312. }
  12313. } else {
  12314. disable(2884);
  12315. }
  12316. currentCullFace = cullFace;
  12317. }
  12318. function setLineWidth(width) {
  12319. if (width !== currentLineWidth) {
  12320. if (lineWidthAvailable) gl.lineWidth(width);
  12321. currentLineWidth = width;
  12322. }
  12323. }
  12324. function setPolygonOffset(polygonOffset, factor, units) {
  12325. if (polygonOffset) {
  12326. enable(32823);
  12327. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  12328. gl.polygonOffset(factor, units);
  12329. currentPolygonOffsetFactor = factor;
  12330. currentPolygonOffsetUnits = units;
  12331. }
  12332. } else {
  12333. disable(32823);
  12334. }
  12335. }
  12336. function setScissorTest(scissorTest) {
  12337. if (scissorTest) {
  12338. enable(3089);
  12339. } else {
  12340. disable(3089);
  12341. }
  12342. } // texture
  12343. function activeTexture(webglSlot) {
  12344. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  12345. if (currentTextureSlot !== webglSlot) {
  12346. gl.activeTexture(webglSlot);
  12347. currentTextureSlot = webglSlot;
  12348. }
  12349. }
  12350. function bindTexture(webglType, webglTexture) {
  12351. if (currentTextureSlot === null) {
  12352. activeTexture();
  12353. }
  12354. var boundTexture = currentBoundTextures[currentTextureSlot];
  12355. if (boundTexture === undefined) {
  12356. boundTexture = {
  12357. type: undefined,
  12358. texture: undefined
  12359. };
  12360. currentBoundTextures[currentTextureSlot] = boundTexture;
  12361. }
  12362. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  12363. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  12364. boundTexture.type = webglType;
  12365. boundTexture.texture = webglTexture;
  12366. }
  12367. }
  12368. function unbindTexture() {
  12369. var boundTexture = currentBoundTextures[currentTextureSlot];
  12370. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  12371. gl.bindTexture(boundTexture.type, null);
  12372. boundTexture.type = undefined;
  12373. boundTexture.texture = undefined;
  12374. }
  12375. }
  12376. function compressedTexImage2D() {
  12377. try {
  12378. gl.compressedTexImage2D.apply(gl, arguments);
  12379. } catch (error) {
  12380. console.error('THREE.WebGLState:', error);
  12381. }
  12382. }
  12383. function texImage2D() {
  12384. try {
  12385. gl.texImage2D.apply(gl, arguments);
  12386. } catch (error) {
  12387. console.error('THREE.WebGLState:', error);
  12388. }
  12389. }
  12390. function texImage3D() {
  12391. try {
  12392. gl.texImage3D.apply(gl, arguments);
  12393. } catch (error) {
  12394. console.error('THREE.WebGLState:', error);
  12395. }
  12396. } //
  12397. function scissor(scissor) {
  12398. if (currentScissor.equals(scissor) === false) {
  12399. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  12400. currentScissor.copy(scissor);
  12401. }
  12402. }
  12403. function viewport(viewport) {
  12404. if (currentViewport.equals(viewport) === false) {
  12405. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  12406. currentViewport.copy(viewport);
  12407. }
  12408. } //
  12409. function reset() {
  12410. enabledCapabilities = {};
  12411. currentTextureSlot = null;
  12412. currentBoundTextures = {};
  12413. currentProgram = null;
  12414. currentBlending = null;
  12415. currentFlipSided = null;
  12416. currentCullFace = null;
  12417. colorBuffer.reset();
  12418. depthBuffer.reset();
  12419. stencilBuffer.reset();
  12420. }
  12421. return {
  12422. buffers: {
  12423. color: colorBuffer,
  12424. depth: depthBuffer,
  12425. stencil: stencilBuffer
  12426. },
  12427. enable: enable,
  12428. disable: disable,
  12429. useProgram: useProgram,
  12430. setBlending: setBlending,
  12431. setMaterial: setMaterial,
  12432. setFlipSided: setFlipSided,
  12433. setCullFace: setCullFace,
  12434. setLineWidth: setLineWidth,
  12435. setPolygonOffset: setPolygonOffset,
  12436. setScissorTest: setScissorTest,
  12437. activeTexture: activeTexture,
  12438. bindTexture: bindTexture,
  12439. unbindTexture: unbindTexture,
  12440. compressedTexImage2D: compressedTexImage2D,
  12441. texImage2D: texImage2D,
  12442. texImage3D: texImage3D,
  12443. scissor: scissor,
  12444. viewport: viewport,
  12445. reset: reset
  12446. };
  12447. }
  12448. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  12449. var _wrappingToGL, _filterToGL;
  12450. var isWebGL2 = capabilities.isWebGL2;
  12451. var maxTextures = capabilities.maxTextures;
  12452. var maxCubemapSize = capabilities.maxCubemapSize;
  12453. var maxTextureSize = capabilities.maxTextureSize;
  12454. var maxSamples = capabilities.maxSamples;
  12455. var _videoTextures = new WeakMap();
  12456. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  12457. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  12458. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  12459. var useOffscreenCanvas = false;
  12460. try {
  12461. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext("2d") !== null;
  12462. } catch (err) {// Ignore any errors
  12463. }
  12464. function createCanvas(width, height) {
  12465. // Use OffscreenCanvas when available. Specially needed in web workers
  12466. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  12467. }
  12468. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  12469. var scale = 1; // handle case if texture exceeds max size
  12470. if (image.width > maxSize || image.height > maxSize) {
  12471. scale = maxSize / Math.max(image.width, image.height);
  12472. } // only perform resize if necessary
  12473. if (scale < 1 || needsPowerOfTwo === true) {
  12474. // only perform resize for certain image types
  12475. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  12476. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  12477. var width = floor(scale * image.width);
  12478. var height = floor(scale * image.height);
  12479. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  12480. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  12481. canvas.width = width;
  12482. canvas.height = height;
  12483. var context = canvas.getContext('2d');
  12484. context.drawImage(image, 0, 0, width, height);
  12485. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  12486. return canvas;
  12487. } else {
  12488. if ('data' in image) {
  12489. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  12490. }
  12491. return image;
  12492. }
  12493. }
  12494. return image;
  12495. }
  12496. function isPowerOfTwo(image) {
  12497. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  12498. }
  12499. function textureNeedsPowerOfTwo(texture) {
  12500. if (isWebGL2) return false;
  12501. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12502. }
  12503. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  12504. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12505. }
  12506. function generateMipmap(target, texture, width, height) {
  12507. _gl.generateMipmap(target);
  12508. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12509. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  12510. }
  12511. function getInternalFormat(internalFormatName, glFormat, glType) {
  12512. if (isWebGL2 === false) return glFormat;
  12513. if (internalFormatName !== null) {
  12514. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  12515. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  12516. }
  12517. var internalFormat = glFormat;
  12518. if (glFormat === 6403) {
  12519. if (glType === 5126) internalFormat = 33326;
  12520. if (glType === 5131) internalFormat = 33325;
  12521. if (glType === 5121) internalFormat = 33321;
  12522. }
  12523. if (glFormat === 6407) {
  12524. if (glType === 5126) internalFormat = 34837;
  12525. if (glType === 5131) internalFormat = 34843;
  12526. if (glType === 5121) internalFormat = 32849;
  12527. }
  12528. if (glFormat === 6408) {
  12529. if (glType === 5126) internalFormat = 34836;
  12530. if (glType === 5131) internalFormat = 34842;
  12531. if (glType === 5121) internalFormat = 32856;
  12532. }
  12533. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  12534. extensions.get('EXT_color_buffer_float');
  12535. }
  12536. return internalFormat;
  12537. } // Fallback filters for non-power-of-2 textures
  12538. function filterFallback(f) {
  12539. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  12540. return 9728;
  12541. }
  12542. return 9729;
  12543. } //
  12544. function onTextureDispose(event) {
  12545. var texture = event.target;
  12546. texture.removeEventListener('dispose', onTextureDispose);
  12547. deallocateTexture(texture);
  12548. if (texture.isVideoTexture) {
  12549. _videoTextures.delete(texture);
  12550. }
  12551. info.memory.textures--;
  12552. }
  12553. function onRenderTargetDispose(event) {
  12554. var renderTarget = event.target;
  12555. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  12556. deallocateRenderTarget(renderTarget);
  12557. info.memory.textures--;
  12558. } //
  12559. function deallocateTexture(texture) {
  12560. var textureProperties = properties.get(texture);
  12561. if (textureProperties.__webglInit === undefined) return;
  12562. _gl.deleteTexture(textureProperties.__webglTexture);
  12563. properties.remove(texture);
  12564. }
  12565. function deallocateRenderTarget(renderTarget) {
  12566. var renderTargetProperties = properties.get(renderTarget);
  12567. var textureProperties = properties.get(renderTarget.texture);
  12568. if (!renderTarget) return;
  12569. if (textureProperties.__webglTexture !== undefined) {
  12570. _gl.deleteTexture(textureProperties.__webglTexture);
  12571. }
  12572. if (renderTarget.depthTexture) {
  12573. renderTarget.depthTexture.dispose();
  12574. }
  12575. if (renderTarget.isWebGLCubeRenderTarget) {
  12576. for (var i = 0; i < 6; i++) {
  12577. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  12578. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  12579. }
  12580. } else {
  12581. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  12582. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  12583. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  12584. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  12585. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  12586. }
  12587. properties.remove(renderTarget.texture);
  12588. properties.remove(renderTarget);
  12589. } //
  12590. var textureUnits = 0;
  12591. function resetTextureUnits() {
  12592. textureUnits = 0;
  12593. }
  12594. function allocateTextureUnit() {
  12595. var textureUnit = textureUnits;
  12596. if (textureUnit >= maxTextures) {
  12597. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  12598. }
  12599. textureUnits += 1;
  12600. return textureUnit;
  12601. } //
  12602. function setTexture2D(texture, slot) {
  12603. var textureProperties = properties.get(texture);
  12604. if (texture.isVideoTexture) updateVideoTexture(texture);
  12605. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12606. var image = texture.image;
  12607. if (image === undefined) {
  12608. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  12609. } else if (image.complete === false) {
  12610. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  12611. } else {
  12612. uploadTexture(textureProperties, texture, slot);
  12613. return;
  12614. }
  12615. }
  12616. state.activeTexture(33984 + slot);
  12617. state.bindTexture(3553, textureProperties.__webglTexture);
  12618. }
  12619. function setTexture2DArray(texture, slot) {
  12620. var textureProperties = properties.get(texture);
  12621. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12622. uploadTexture(textureProperties, texture, slot);
  12623. return;
  12624. }
  12625. state.activeTexture(33984 + slot);
  12626. state.bindTexture(35866, textureProperties.__webglTexture);
  12627. }
  12628. function setTexture3D(texture, slot) {
  12629. var textureProperties = properties.get(texture);
  12630. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12631. uploadTexture(textureProperties, texture, slot);
  12632. return;
  12633. }
  12634. state.activeTexture(33984 + slot);
  12635. state.bindTexture(32879, textureProperties.__webglTexture);
  12636. }
  12637. function setTextureCube(texture, slot) {
  12638. var textureProperties = properties.get(texture);
  12639. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12640. uploadCubeTexture(textureProperties, texture, slot);
  12641. return;
  12642. }
  12643. state.activeTexture(33984 + slot);
  12644. state.bindTexture(34067, textureProperties.__webglTexture);
  12645. }
  12646. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  12647. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  12648. function setTextureParameters(textureType, texture, supportsMips) {
  12649. if (supportsMips) {
  12650. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  12651. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  12652. if (textureType === 32879 || textureType === 35866) {
  12653. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  12654. }
  12655. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  12656. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  12657. } else {
  12658. _gl.texParameteri(textureType, 10242, 33071);
  12659. _gl.texParameteri(textureType, 10243, 33071);
  12660. if (textureType === 32879 || textureType === 35866) {
  12661. _gl.texParameteri(textureType, 32882, 33071);
  12662. }
  12663. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  12664. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  12665. }
  12666. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  12667. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  12668. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  12669. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  12670. }
  12671. }
  12672. var extension = extensions.get('EXT_texture_filter_anisotropic');
  12673. if (extension) {
  12674. if (texture.type === FloatType && extensions.get('OES_texture_float_linear') === null) return;
  12675. if (texture.type === HalfFloatType && (isWebGL2 || extensions.get('OES_texture_half_float_linear')) === null) return;
  12676. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  12677. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  12678. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  12679. }
  12680. }
  12681. }
  12682. function initTexture(textureProperties, texture) {
  12683. if (textureProperties.__webglInit === undefined) {
  12684. textureProperties.__webglInit = true;
  12685. texture.addEventListener('dispose', onTextureDispose);
  12686. textureProperties.__webglTexture = _gl.createTexture();
  12687. info.memory.textures++;
  12688. }
  12689. }
  12690. function uploadTexture(textureProperties, texture, slot) {
  12691. var textureType = 3553;
  12692. if (texture.isDataTexture2DArray) textureType = 35866;
  12693. if (texture.isDataTexture3D) textureType = 32879;
  12694. initTexture(textureProperties, texture);
  12695. state.activeTexture(33984 + slot);
  12696. state.bindTexture(textureType, textureProperties.__webglTexture);
  12697. _gl.pixelStorei(37440, texture.flipY);
  12698. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  12699. _gl.pixelStorei(3317, texture.unpackAlignment);
  12700. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  12701. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  12702. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  12703. glFormat = utils.convert(texture.format);
  12704. var glType = utils.convert(texture.type),
  12705. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  12706. setTextureParameters(textureType, texture, supportsMips);
  12707. var mipmap;
  12708. var mipmaps = texture.mipmaps;
  12709. if (texture.isDepthTexture) {
  12710. // populate depth texture with dummy data
  12711. glInternalFormat = 6402;
  12712. if (isWebGL2) {
  12713. if (texture.type === FloatType) {
  12714. glInternalFormat = 36012;
  12715. } else if (texture.type === UnsignedIntType) {
  12716. glInternalFormat = 33190;
  12717. } else if (texture.type === UnsignedInt248Type) {
  12718. glInternalFormat = 35056;
  12719. } else {
  12720. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  12721. }
  12722. } else {
  12723. if (texture.type === FloatType) {
  12724. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  12725. }
  12726. } // validation checks for WebGL 1
  12727. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  12728. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12729. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12730. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12731. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  12732. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  12733. texture.type = UnsignedShortType;
  12734. glType = utils.convert(texture.type);
  12735. }
  12736. }
  12737. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  12738. // Depth stencil textures need the DEPTH_STENCIL internal format
  12739. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12740. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12741. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12742. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12743. if (texture.type !== UnsignedInt248Type) {
  12744. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  12745. texture.type = UnsignedInt248Type;
  12746. glType = utils.convert(texture.type);
  12747. }
  12748. } //
  12749. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  12750. } else if (texture.isDataTexture) {
  12751. // use manually created mipmaps if available
  12752. // if there are no manual mipmaps
  12753. // set 0 level mipmap and then use GL to generate other mipmap levels
  12754. if (mipmaps.length > 0 && supportsMips) {
  12755. for (var i = 0, il = mipmaps.length; i < il; i++) {
  12756. mipmap = mipmaps[i];
  12757. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  12758. }
  12759. texture.generateMipmaps = false;
  12760. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12761. } else {
  12762. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  12763. textureProperties.__maxMipLevel = 0;
  12764. }
  12765. } else if (texture.isCompressedTexture) {
  12766. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  12767. mipmap = mipmaps[_i];
  12768. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  12769. if (glFormat !== null) {
  12770. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  12771. } else {
  12772. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  12773. }
  12774. } else {
  12775. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  12776. }
  12777. }
  12778. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12779. } else if (texture.isDataTexture2DArray) {
  12780. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  12781. textureProperties.__maxMipLevel = 0;
  12782. } else if (texture.isDataTexture3D) {
  12783. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  12784. textureProperties.__maxMipLevel = 0;
  12785. } else {
  12786. // regular Texture (image, video, canvas)
  12787. // use manually created mipmaps if available
  12788. // if there are no manual mipmaps
  12789. // set 0 level mipmap and then use GL to generate other mipmap levels
  12790. if (mipmaps.length > 0 && supportsMips) {
  12791. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  12792. mipmap = mipmaps[_i2];
  12793. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  12794. }
  12795. texture.generateMipmaps = false;
  12796. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12797. } else {
  12798. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  12799. textureProperties.__maxMipLevel = 0;
  12800. }
  12801. }
  12802. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  12803. generateMipmap(textureType, texture, image.width, image.height);
  12804. }
  12805. textureProperties.__version = texture.version;
  12806. if (texture.onUpdate) texture.onUpdate(texture);
  12807. }
  12808. function uploadCubeTexture(textureProperties, texture, slot) {
  12809. if (texture.image.length !== 6) return;
  12810. initTexture(textureProperties, texture);
  12811. state.activeTexture(33984 + slot);
  12812. state.bindTexture(34067, textureProperties.__webglTexture);
  12813. _gl.pixelStorei(37440, texture.flipY);
  12814. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  12815. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  12816. var cubeImage = [];
  12817. for (var i = 0; i < 6; i++) {
  12818. if (!isCompressed && !isDataTexture) {
  12819. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  12820. } else {
  12821. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  12822. }
  12823. }
  12824. var image = cubeImage[0],
  12825. supportsMips = isPowerOfTwo(image) || isWebGL2,
  12826. glFormat = utils.convert(texture.format),
  12827. glType = utils.convert(texture.type),
  12828. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  12829. setTextureParameters(34067, texture, supportsMips);
  12830. var mipmaps;
  12831. if (isCompressed) {
  12832. for (var _i3 = 0; _i3 < 6; _i3++) {
  12833. mipmaps = cubeImage[_i3].mipmaps;
  12834. for (var j = 0; j < mipmaps.length; j++) {
  12835. var mipmap = mipmaps[j];
  12836. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  12837. if (glFormat !== null) {
  12838. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  12839. } else {
  12840. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  12841. }
  12842. } else {
  12843. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  12844. }
  12845. }
  12846. }
  12847. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12848. } else {
  12849. mipmaps = texture.mipmaps;
  12850. for (var _i4 = 0; _i4 < 6; _i4++) {
  12851. if (isDataTexture) {
  12852. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  12853. for (var _j = 0; _j < mipmaps.length; _j++) {
  12854. var _mipmap = mipmaps[_j];
  12855. var mipmapImage = _mipmap.image[_i4].image;
  12856. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  12857. }
  12858. } else {
  12859. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  12860. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  12861. var _mipmap2 = mipmaps[_j2];
  12862. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  12863. }
  12864. }
  12865. }
  12866. textureProperties.__maxMipLevel = mipmaps.length;
  12867. }
  12868. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  12869. // We assume images for cube map have the same size.
  12870. generateMipmap(34067, texture, image.width, image.height);
  12871. }
  12872. textureProperties.__version = texture.version;
  12873. if (texture.onUpdate) texture.onUpdate(texture);
  12874. } // Render targets
  12875. // Setup storage for target texture and bind it to correct framebuffer
  12876. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  12877. var glFormat = utils.convert(renderTarget.texture.format);
  12878. var glType = utils.convert(renderTarget.texture.type);
  12879. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  12880. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  12881. _gl.bindFramebuffer(36160, framebuffer);
  12882. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(renderTarget.texture).__webglTexture, 0);
  12883. _gl.bindFramebuffer(36160, null);
  12884. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12885. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  12886. _gl.bindRenderbuffer(36161, renderbuffer);
  12887. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  12888. var glInternalFormat = 33189;
  12889. if (isMultisample) {
  12890. var depthTexture = renderTarget.depthTexture;
  12891. if (depthTexture && depthTexture.isDepthTexture) {
  12892. if (depthTexture.type === FloatType) {
  12893. glInternalFormat = 36012;
  12894. } else if (depthTexture.type === UnsignedIntType) {
  12895. glInternalFormat = 33190;
  12896. }
  12897. }
  12898. var samples = getRenderTargetSamples(renderTarget);
  12899. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  12900. } else {
  12901. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  12902. }
  12903. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  12904. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  12905. if (isMultisample) {
  12906. var _samples = getRenderTargetSamples(renderTarget);
  12907. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  12908. } else {
  12909. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  12910. }
  12911. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  12912. } else {
  12913. var glFormat = utils.convert(renderTarget.texture.format);
  12914. var glType = utils.convert(renderTarget.texture.type);
  12915. var _glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  12916. if (isMultisample) {
  12917. var _samples2 = getRenderTargetSamples(renderTarget);
  12918. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  12919. } else {
  12920. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  12921. }
  12922. }
  12923. _gl.bindRenderbuffer(36161, null);
  12924. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  12925. function setupDepthTexture(framebuffer, renderTarget) {
  12926. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  12927. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  12928. _gl.bindFramebuffer(36160, framebuffer);
  12929. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  12930. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  12931. } // upload an empty depth texture with framebuffer size
  12932. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  12933. renderTarget.depthTexture.image.width = renderTarget.width;
  12934. renderTarget.depthTexture.image.height = renderTarget.height;
  12935. renderTarget.depthTexture.needsUpdate = true;
  12936. }
  12937. setTexture2D(renderTarget.depthTexture, 0);
  12938. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  12939. if (renderTarget.depthTexture.format === DepthFormat) {
  12940. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  12941. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  12942. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  12943. } else {
  12944. throw new Error('Unknown depthTexture format');
  12945. }
  12946. } // Setup GL resources for a non-texture depth buffer
  12947. function setupDepthRenderbuffer(renderTarget) {
  12948. var renderTargetProperties = properties.get(renderTarget);
  12949. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  12950. if (renderTarget.depthTexture) {
  12951. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  12952. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  12953. } else {
  12954. if (isCube) {
  12955. renderTargetProperties.__webglDepthbuffer = [];
  12956. for (var i = 0; i < 6; i++) {
  12957. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  12958. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  12959. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  12960. }
  12961. } else {
  12962. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  12963. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  12964. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  12965. }
  12966. }
  12967. _gl.bindFramebuffer(36160, null);
  12968. } // Set up GL resources for the render target
  12969. function setupRenderTarget(renderTarget) {
  12970. var renderTargetProperties = properties.get(renderTarget);
  12971. var textureProperties = properties.get(renderTarget.texture);
  12972. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  12973. textureProperties.__webglTexture = _gl.createTexture();
  12974. info.memory.textures++;
  12975. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  12976. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  12977. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  12978. if (isWebGL2 && renderTarget.texture.format === RGBFormat && (renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType)) {
  12979. renderTarget.texture.format = RGBAFormat;
  12980. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  12981. } // Setup framebuffer
  12982. if (isCube) {
  12983. renderTargetProperties.__webglFramebuffer = [];
  12984. for (var i = 0; i < 6; i++) {
  12985. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  12986. }
  12987. } else {
  12988. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  12989. if (isMultisample) {
  12990. if (isWebGL2) {
  12991. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  12992. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  12993. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  12994. var glFormat = utils.convert(renderTarget.texture.format);
  12995. var glType = utils.convert(renderTarget.texture.type);
  12996. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  12997. var samples = getRenderTargetSamples(renderTarget);
  12998. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  12999. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13000. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13001. _gl.bindRenderbuffer(36161, null);
  13002. if (renderTarget.depthBuffer) {
  13003. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13004. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13005. }
  13006. _gl.bindFramebuffer(36160, null);
  13007. } else {
  13008. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13009. }
  13010. }
  13011. } // Setup color buffer
  13012. if (isCube) {
  13013. state.bindTexture(34067, textureProperties.__webglTexture);
  13014. setTextureParameters(34067, renderTarget.texture, supportsMips);
  13015. for (var _i5 = 0; _i5 < 6; _i5++) {
  13016. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13017. }
  13018. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13019. generateMipmap(34067, renderTarget.texture, renderTarget.width, renderTarget.height);
  13020. }
  13021. state.bindTexture(34067, null);
  13022. } else {
  13023. state.bindTexture(3553, textureProperties.__webglTexture);
  13024. setTextureParameters(3553, renderTarget.texture, supportsMips);
  13025. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553);
  13026. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13027. generateMipmap(3553, renderTarget.texture, renderTarget.width, renderTarget.height);
  13028. }
  13029. state.bindTexture(3553, null);
  13030. } // Setup depth and stencil buffers
  13031. if (renderTarget.depthBuffer) {
  13032. setupDepthRenderbuffer(renderTarget);
  13033. }
  13034. }
  13035. function updateRenderTargetMipmap(renderTarget) {
  13036. var texture = renderTarget.texture;
  13037. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13038. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13039. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13040. var webglTexture = properties.get(texture).__webglTexture;
  13041. state.bindTexture(target, webglTexture);
  13042. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13043. state.bindTexture(target, null);
  13044. }
  13045. }
  13046. function updateMultisampleRenderTarget(renderTarget) {
  13047. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13048. if (isWebGL2) {
  13049. var renderTargetProperties = properties.get(renderTarget);
  13050. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13051. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13052. var width = renderTarget.width;
  13053. var height = renderTarget.height;
  13054. var mask = 16384;
  13055. if (renderTarget.depthBuffer) mask |= 256;
  13056. if (renderTarget.stencilBuffer) mask |= 1024;
  13057. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13058. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13059. } else {
  13060. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13061. }
  13062. }
  13063. }
  13064. function getRenderTargetSamples(renderTarget) {
  13065. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13066. }
  13067. function updateVideoTexture(texture) {
  13068. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13069. if (_videoTextures.get(texture) !== frame) {
  13070. _videoTextures.set(texture, frame);
  13071. texture.update();
  13072. }
  13073. } // backwards compatibility
  13074. var warnedTexture2D = false;
  13075. var warnedTextureCube = false;
  13076. function safeSetTexture2D(texture, slot) {
  13077. if (texture && texture.isWebGLRenderTarget) {
  13078. if (warnedTexture2D === false) {
  13079. console.warn("THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead.");
  13080. warnedTexture2D = true;
  13081. }
  13082. texture = texture.texture;
  13083. }
  13084. setTexture2D(texture, slot);
  13085. }
  13086. function safeSetTextureCube(texture, slot) {
  13087. if (texture && texture.isWebGLCubeRenderTarget) {
  13088. if (warnedTextureCube === false) {
  13089. console.warn("THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead.");
  13090. warnedTextureCube = true;
  13091. }
  13092. texture = texture.texture;
  13093. }
  13094. setTextureCube(texture, slot);
  13095. } //
  13096. this.allocateTextureUnit = allocateTextureUnit;
  13097. this.resetTextureUnits = resetTextureUnits;
  13098. this.setTexture2D = setTexture2D;
  13099. this.setTexture2DArray = setTexture2DArray;
  13100. this.setTexture3D = setTexture3D;
  13101. this.setTextureCube = setTextureCube;
  13102. this.setupRenderTarget = setupRenderTarget;
  13103. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13104. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13105. this.safeSetTexture2D = safeSetTexture2D;
  13106. this.safeSetTextureCube = safeSetTextureCube;
  13107. }
  13108. function WebGLUtils(gl, extensions, capabilities) {
  13109. var isWebGL2 = capabilities.isWebGL2;
  13110. function convert(p) {
  13111. var extension;
  13112. if (p === UnsignedByteType) return 5121;
  13113. if (p === UnsignedShort4444Type) return 32819;
  13114. if (p === UnsignedShort5551Type) return 32820;
  13115. if (p === UnsignedShort565Type) return 33635;
  13116. if (p === ByteType) return 5120;
  13117. if (p === ShortType) return 5122;
  13118. if (p === UnsignedShortType) return 5123;
  13119. if (p === IntType) return 5124;
  13120. if (p === UnsignedIntType) return 5125;
  13121. if (p === FloatType) return 5126;
  13122. if (p === HalfFloatType) {
  13123. if (isWebGL2) return 5131;
  13124. extension = extensions.get('OES_texture_half_float');
  13125. if (extension !== null) {
  13126. return extension.HALF_FLOAT_OES;
  13127. } else {
  13128. return null;
  13129. }
  13130. }
  13131. if (p === AlphaFormat) return 6406;
  13132. if (p === RGBFormat) return 6407;
  13133. if (p === RGBAFormat) return 6408;
  13134. if (p === LuminanceFormat) return 6409;
  13135. if (p === LuminanceAlphaFormat) return 6410;
  13136. if (p === DepthFormat) return 6402;
  13137. if (p === DepthStencilFormat) return 34041;
  13138. if (p === RedFormat) return 6403; // WebGL2 formats.
  13139. if (p === RedIntegerFormat) return 36244;
  13140. if (p === RGFormat) return 33319;
  13141. if (p === RGIntegerFormat) return 33320;
  13142. if (p === RGBIntegerFormat) return 36248;
  13143. if (p === RGBAIntegerFormat) return 36249;
  13144. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13145. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13146. if (extension !== null) {
  13147. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13148. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13149. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13150. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13151. } else {
  13152. return null;
  13153. }
  13154. }
  13155. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13156. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13157. if (extension !== null) {
  13158. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13159. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13160. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13161. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13162. } else {
  13163. return null;
  13164. }
  13165. }
  13166. if (p === RGB_ETC1_Format) {
  13167. extension = extensions.get('WEBGL_compressed_texture_etc1');
  13168. if (extension !== null) {
  13169. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13170. } else {
  13171. return null;
  13172. }
  13173. }
  13174. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  13175. extension = extensions.get('WEBGL_compressed_texture_etc');
  13176. if (extension !== null) {
  13177. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  13178. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13179. }
  13180. }
  13181. 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) {
  13182. extension = extensions.get('WEBGL_compressed_texture_astc');
  13183. if (extension !== null) {
  13184. // TODO Complete?
  13185. return p;
  13186. } else {
  13187. return null;
  13188. }
  13189. }
  13190. if (p === RGBA_BPTC_Format) {
  13191. extension = extensions.get('EXT_texture_compression_bptc');
  13192. if (extension !== null) {
  13193. // TODO Complete?
  13194. return p;
  13195. } else {
  13196. return null;
  13197. }
  13198. }
  13199. if (p === UnsignedInt248Type) {
  13200. if (isWebGL2) return 34042;
  13201. extension = extensions.get('WEBGL_depth_texture');
  13202. if (extension !== null) {
  13203. return extension.UNSIGNED_INT_24_8_WEBGL;
  13204. } else {
  13205. return null;
  13206. }
  13207. }
  13208. }
  13209. return {
  13210. convert: convert
  13211. };
  13212. }
  13213. function ArrayCamera(array) {
  13214. PerspectiveCamera.call(this);
  13215. this.cameras = array || [];
  13216. }
  13217. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  13218. constructor: ArrayCamera,
  13219. isArrayCamera: true
  13220. });
  13221. function Group() {
  13222. Object3D.call(this);
  13223. this.type = 'Group';
  13224. }
  13225. Group.prototype = Object.assign(Object.create(Object3D.prototype), {
  13226. constructor: Group,
  13227. isGroup: true
  13228. });
  13229. function WebXRController() {
  13230. this._targetRay = null;
  13231. this._grip = null;
  13232. this._hand = null;
  13233. }
  13234. Object.assign(WebXRController.prototype, {
  13235. constructor: WebXRController,
  13236. getHandSpace: function getHandSpace() {
  13237. if (this._hand === null) {
  13238. this._hand = new Group();
  13239. this._hand.matrixAutoUpdate = false;
  13240. this._hand.visible = false;
  13241. this._hand.joints = [];
  13242. this._hand.inputState = {
  13243. pinching: false
  13244. };
  13245. if (window.XRHand) {
  13246. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13247. // The transform of this joint will be updated with the joint pose on each frame
  13248. var joint = new Group();
  13249. joint.matrixAutoUpdate = false;
  13250. joint.visible = false;
  13251. this._hand.joints.push(joint); // ??
  13252. this._hand.add(joint);
  13253. }
  13254. }
  13255. }
  13256. return this._hand;
  13257. },
  13258. getTargetRaySpace: function getTargetRaySpace() {
  13259. if (this._targetRay === null) {
  13260. this._targetRay = new Group();
  13261. this._targetRay.matrixAutoUpdate = false;
  13262. this._targetRay.visible = false;
  13263. }
  13264. return this._targetRay;
  13265. },
  13266. getGripSpace: function getGripSpace() {
  13267. if (this._grip === null) {
  13268. this._grip = new Group();
  13269. this._grip.matrixAutoUpdate = false;
  13270. this._grip.visible = false;
  13271. }
  13272. return this._grip;
  13273. },
  13274. dispatchEvent: function dispatchEvent(event) {
  13275. if (this._targetRay !== null) {
  13276. this._targetRay.dispatchEvent(event);
  13277. }
  13278. if (this._grip !== null) {
  13279. this._grip.dispatchEvent(event);
  13280. }
  13281. if (this._hand !== null) {
  13282. this._hand.dispatchEvent(event);
  13283. }
  13284. return this;
  13285. },
  13286. disconnect: function disconnect(inputSource) {
  13287. this.dispatchEvent({
  13288. type: 'disconnected',
  13289. data: inputSource
  13290. });
  13291. if (this._targetRay !== null) {
  13292. this._targetRay.visible = false;
  13293. }
  13294. if (this._grip !== null) {
  13295. this._grip.visible = false;
  13296. }
  13297. if (this._hand !== null) {
  13298. this._hand.visible = false;
  13299. }
  13300. return this;
  13301. },
  13302. update: function update(inputSource, frame, referenceSpace) {
  13303. var inputPose = null;
  13304. var gripPose = null;
  13305. var handPose = null;
  13306. var targetRay = this._targetRay;
  13307. var grip = this._grip;
  13308. var hand = this._hand;
  13309. if (inputSource) {
  13310. if (hand && inputSource.hand) {
  13311. handPose = true;
  13312. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13313. if (inputSource.hand[i]) {
  13314. // Update the joints groups with the XRJoint poses
  13315. var jointPose = frame.getJointPose(inputSource.hand[i], referenceSpace);
  13316. var joint = hand.joints[i];
  13317. if (jointPose !== null) {
  13318. joint.matrix.fromArray(jointPose.transform.matrix);
  13319. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  13320. joint.jointRadius = jointPose.radius;
  13321. }
  13322. joint.visible = jointPose !== null; // Custom events
  13323. // Check pinch
  13324. var indexTip = hand.joints[window.XRHand.INDEX_PHALANX_TIP];
  13325. var thumbTip = hand.joints[window.XRHand.THUMB_PHALANX_TIP];
  13326. var distance = indexTip.position.distanceTo(thumbTip.position);
  13327. var distanceToPinch = 0.02;
  13328. var threshold = 0.005;
  13329. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  13330. hand.inputState.pinching = false;
  13331. this.dispatchEvent({
  13332. type: "pinchend",
  13333. handedness: inputSource.handedness,
  13334. target: this
  13335. });
  13336. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  13337. hand.inputState.pinching = true;
  13338. this.dispatchEvent({
  13339. type: "pinchstart",
  13340. handedness: inputSource.handedness,
  13341. target: this
  13342. });
  13343. }
  13344. }
  13345. }
  13346. } else {
  13347. if (targetRay !== null) {
  13348. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  13349. if (inputPose !== null) {
  13350. targetRay.matrix.fromArray(inputPose.transform.matrix);
  13351. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  13352. }
  13353. }
  13354. if (grip !== null && inputSource.gripSpace) {
  13355. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  13356. if (gripPose !== null) {
  13357. grip.matrix.fromArray(gripPose.transform.matrix);
  13358. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  13359. }
  13360. }
  13361. }
  13362. }
  13363. if (targetRay !== null) {
  13364. targetRay.visible = inputPose !== null;
  13365. }
  13366. if (grip !== null) {
  13367. grip.visible = gripPose !== null;
  13368. }
  13369. if (hand !== null) {
  13370. hand.visible = handPose !== null;
  13371. }
  13372. return this;
  13373. }
  13374. });
  13375. function WebXRManager(renderer, gl) {
  13376. var scope = this;
  13377. var session = null;
  13378. var framebufferScaleFactor = 1.0;
  13379. var referenceSpace = null;
  13380. var referenceSpaceType = 'local-floor';
  13381. var pose = null;
  13382. var controllers = [];
  13383. var inputSourcesMap = new Map(); //
  13384. var cameraL = new PerspectiveCamera();
  13385. cameraL.layers.enable(1);
  13386. cameraL.viewport = new Vector4();
  13387. var cameraR = new PerspectiveCamera();
  13388. cameraR.layers.enable(2);
  13389. cameraR.viewport = new Vector4();
  13390. var cameras = [cameraL, cameraR];
  13391. var cameraVR = new ArrayCamera();
  13392. cameraVR.layers.enable(1);
  13393. cameraVR.layers.enable(2);
  13394. var _currentDepthNear = null;
  13395. var _currentDepthFar = null; //
  13396. this.enabled = false;
  13397. this.isPresenting = false;
  13398. this.getController = function (index) {
  13399. var controller = controllers[index];
  13400. if (controller === undefined) {
  13401. controller = new WebXRController();
  13402. controllers[index] = controller;
  13403. }
  13404. return controller.getTargetRaySpace();
  13405. };
  13406. this.getControllerGrip = function (index) {
  13407. var controller = controllers[index];
  13408. if (controller === undefined) {
  13409. controller = new WebXRController();
  13410. controllers[index] = controller;
  13411. }
  13412. return controller.getGripSpace();
  13413. };
  13414. this.getHand = function (index) {
  13415. var controller = controllers[index];
  13416. if (controller === undefined) {
  13417. controller = new WebXRController();
  13418. controllers[index] = controller;
  13419. }
  13420. return controller.getHandSpace();
  13421. }; //
  13422. function onSessionEvent(event) {
  13423. var controller = inputSourcesMap.get(event.inputSource);
  13424. if (controller) {
  13425. controller.dispatchEvent({
  13426. type: event.type,
  13427. data: event.inputSource
  13428. });
  13429. }
  13430. }
  13431. function onSessionEnd() {
  13432. inputSourcesMap.forEach(function (controller, inputSource) {
  13433. controller.disconnect(inputSource);
  13434. });
  13435. inputSourcesMap.clear(); //
  13436. renderer.setFramebuffer(null);
  13437. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  13438. animation.stop();
  13439. scope.isPresenting = false;
  13440. scope.dispatchEvent({
  13441. type: 'sessionend'
  13442. });
  13443. }
  13444. function onRequestReferenceSpace(value) {
  13445. referenceSpace = value;
  13446. animation.setContext(session);
  13447. animation.start();
  13448. scope.isPresenting = true;
  13449. scope.dispatchEvent({
  13450. type: 'sessionstart'
  13451. });
  13452. }
  13453. this.setFramebufferScaleFactor = function (value) {
  13454. framebufferScaleFactor = value;
  13455. if (scope.isPresenting === true) {
  13456. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  13457. }
  13458. };
  13459. this.setReferenceSpaceType = function (value) {
  13460. referenceSpaceType = value;
  13461. if (scope.isPresenting === true) {
  13462. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  13463. }
  13464. };
  13465. this.getReferenceSpace = function () {
  13466. return referenceSpace;
  13467. };
  13468. this.getSession = function () {
  13469. return session;
  13470. };
  13471. this.setSession = function (value) {
  13472. session = value;
  13473. if (session !== null) {
  13474. session.addEventListener('select', onSessionEvent);
  13475. session.addEventListener('selectstart', onSessionEvent);
  13476. session.addEventListener('selectend', onSessionEvent);
  13477. session.addEventListener('squeeze', onSessionEvent);
  13478. session.addEventListener('squeezestart', onSessionEvent);
  13479. session.addEventListener('squeezeend', onSessionEvent);
  13480. session.addEventListener('end', onSessionEnd);
  13481. var attributes = gl.getContextAttributes();
  13482. if (attributes.xrCompatible !== true) {
  13483. gl.makeXRCompatible();
  13484. }
  13485. var layerInit = {
  13486. antialias: attributes.antialias,
  13487. alpha: attributes.alpha,
  13488. depth: attributes.depth,
  13489. stencil: attributes.stencil,
  13490. framebufferScaleFactor: framebufferScaleFactor
  13491. }; // eslint-disable-next-line no-undef
  13492. var baseLayer = new XRWebGLLayer(session, gl, layerInit);
  13493. session.updateRenderState({
  13494. baseLayer: baseLayer
  13495. });
  13496. session.requestReferenceSpace(referenceSpaceType).then(onRequestReferenceSpace); //
  13497. session.addEventListener('inputsourceschange', updateInputSources);
  13498. }
  13499. };
  13500. function updateInputSources(event) {
  13501. var inputSources = session.inputSources; // Assign inputSources to available controllers
  13502. for (var i = 0; i < controllers.length; i++) {
  13503. inputSourcesMap.set(inputSources[i], controllers[i]);
  13504. } // Notify disconnected
  13505. for (var _i = 0; _i < event.removed.length; _i++) {
  13506. var inputSource = event.removed[_i];
  13507. var controller = inputSourcesMap.get(inputSource);
  13508. if (controller) {
  13509. controller.dispatchEvent({
  13510. type: 'disconnected',
  13511. data: inputSource
  13512. });
  13513. inputSourcesMap.delete(inputSource);
  13514. }
  13515. } // Notify connected
  13516. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  13517. var _inputSource = event.added[_i2];
  13518. var _controller = inputSourcesMap.get(_inputSource);
  13519. if (_controller) {
  13520. _controller.dispatchEvent({
  13521. type: 'connected',
  13522. data: _inputSource
  13523. });
  13524. }
  13525. }
  13526. } //
  13527. var cameraLPos = new Vector3();
  13528. var cameraRPos = new Vector3();
  13529. /**
  13530. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13531. * the cameras' projection and world matrices have already been set.
  13532. * And that near and far planes are identical for both cameras.
  13533. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13534. */
  13535. function setProjectionFromUnion(camera, cameraL, cameraR) {
  13536. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  13537. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  13538. var ipd = cameraLPos.distanceTo(cameraRPos);
  13539. var projL = cameraL.projectionMatrix.elements;
  13540. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  13541. // most likely identical top and bottom frustum extents.
  13542. // Use the left camera for these values.
  13543. var near = projL[14] / (projL[10] - 1);
  13544. var far = projL[14] / (projL[10] + 1);
  13545. var topFov = (projL[9] + 1) / projL[5];
  13546. var bottomFov = (projL[9] - 1) / projL[5];
  13547. var leftFov = (projL[8] - 1) / projL[0];
  13548. var rightFov = (projR[8] + 1) / projR[0];
  13549. var left = near * leftFov;
  13550. var right = near * rightFov; // Calculate the new camera's position offset from the
  13551. // left camera. xOffset should be roughly half `ipd`.
  13552. var zOffset = ipd / (-leftFov + rightFov);
  13553. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  13554. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  13555. camera.translateX(xOffset);
  13556. camera.translateZ(zOffset);
  13557. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  13558. camera.matrixWorldInverse.getInverse(camera.matrixWorld); // Find the union of the frustum values of the cameras and scale
  13559. // the values so that the near plane's position does not change in world space,
  13560. // although must now be relative to the new union camera.
  13561. var near2 = near + zOffset;
  13562. var far2 = far + zOffset;
  13563. var left2 = left - xOffset;
  13564. var right2 = right + (ipd - xOffset);
  13565. var top2 = topFov * far / far2 * near2;
  13566. var bottom2 = bottomFov * far / far2 * near2;
  13567. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  13568. }
  13569. function updateCamera(camera, parent) {
  13570. if (parent === null) {
  13571. camera.matrixWorld.copy(camera.matrix);
  13572. } else {
  13573. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  13574. }
  13575. camera.matrixWorldInverse.getInverse(camera.matrixWorld);
  13576. }
  13577. this.getCamera = function (camera) {
  13578. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  13579. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  13580. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  13581. // Note that the new renderState won't apply until the next frame. See #18320
  13582. session.updateRenderState({
  13583. depthNear: cameraVR.near,
  13584. depthFar: cameraVR.far
  13585. });
  13586. _currentDepthNear = cameraVR.near;
  13587. _currentDepthFar = cameraVR.far;
  13588. }
  13589. var parent = camera.parent;
  13590. var cameras = cameraVR.cameras;
  13591. updateCamera(cameraVR, parent);
  13592. for (var i = 0; i < cameras.length; i++) {
  13593. updateCamera(cameras[i], parent);
  13594. } // update camera and its children
  13595. camera.matrixWorld.copy(cameraVR.matrixWorld);
  13596. var children = camera.children;
  13597. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  13598. children[_i3].updateMatrixWorld(true);
  13599. } // update projection matrix for proper view frustum culling
  13600. if (cameras.length === 2) {
  13601. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  13602. } else {
  13603. // assume single camera setup (AR)
  13604. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  13605. }
  13606. return cameraVR;
  13607. }; // Animation Loop
  13608. var onAnimationFrameCallback = null;
  13609. function onAnimationFrame(time, frame) {
  13610. pose = frame.getViewerPose(referenceSpace);
  13611. if (pose !== null) {
  13612. var views = pose.views;
  13613. var baseLayer = session.renderState.baseLayer;
  13614. renderer.setFramebuffer(baseLayer.framebuffer);
  13615. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  13616. if (views.length !== cameraVR.cameras.length) {
  13617. cameraVR.cameras.length = 0;
  13618. cameraVRNeedsUpdate = true;
  13619. }
  13620. for (var i = 0; i < views.length; i++) {
  13621. var view = views[i];
  13622. var viewport = baseLayer.getViewport(view);
  13623. var camera = cameras[i];
  13624. camera.matrix.fromArray(view.transform.matrix);
  13625. camera.projectionMatrix.fromArray(view.projectionMatrix);
  13626. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  13627. if (i === 0) {
  13628. cameraVR.matrix.copy(camera.matrix);
  13629. }
  13630. if (cameraVRNeedsUpdate === true) {
  13631. cameraVR.cameras.push(camera);
  13632. }
  13633. }
  13634. } //
  13635. var inputSources = session.inputSources;
  13636. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  13637. var controller = controllers[_i4];
  13638. var inputSource = inputSources[_i4];
  13639. controller.update(inputSource, frame, referenceSpace);
  13640. }
  13641. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  13642. }
  13643. var animation = new WebGLAnimation();
  13644. animation.setAnimationLoop(onAnimationFrame);
  13645. this.setAnimationLoop = function (callback) {
  13646. onAnimationFrameCallback = callback;
  13647. };
  13648. this.dispose = function () {};
  13649. }
  13650. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  13651. function WebGLMaterials(properties) {
  13652. function refreshFogUniforms(uniforms, fog) {
  13653. uniforms.fogColor.value.copy(fog.color);
  13654. if (fog.isFog) {
  13655. uniforms.fogNear.value = fog.near;
  13656. uniforms.fogFar.value = fog.far;
  13657. } else if (fog.isFogExp2) {
  13658. uniforms.fogDensity.value = fog.density;
  13659. }
  13660. }
  13661. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  13662. if (material.isMeshBasicMaterial) {
  13663. refreshUniformsCommon(uniforms, material);
  13664. } else if (material.isMeshLambertMaterial) {
  13665. refreshUniformsCommon(uniforms, material);
  13666. refreshUniformsLambert(uniforms, material);
  13667. } else if (material.isMeshToonMaterial) {
  13668. refreshUniformsCommon(uniforms, material);
  13669. refreshUniformsToon(uniforms, material);
  13670. } else if (material.isMeshPhongMaterial) {
  13671. refreshUniformsCommon(uniforms, material);
  13672. refreshUniformsPhong(uniforms, material);
  13673. } else if (material.isMeshStandardMaterial) {
  13674. refreshUniformsCommon(uniforms, material);
  13675. if (material.isMeshPhysicalMaterial) {
  13676. refreshUniformsPhysical(uniforms, material);
  13677. } else {
  13678. refreshUniformsStandard(uniforms, material);
  13679. }
  13680. } else if (material.isMeshMatcapMaterial) {
  13681. refreshUniformsCommon(uniforms, material);
  13682. refreshUniformsMatcap(uniforms, material);
  13683. } else if (material.isMeshDepthMaterial) {
  13684. refreshUniformsCommon(uniforms, material);
  13685. refreshUniformsDepth(uniforms, material);
  13686. } else if (material.isMeshDistanceMaterial) {
  13687. refreshUniformsCommon(uniforms, material);
  13688. refreshUniformsDistance(uniforms, material);
  13689. } else if (material.isMeshNormalMaterial) {
  13690. refreshUniformsCommon(uniforms, material);
  13691. refreshUniformsNormal(uniforms, material);
  13692. } else if (material.isLineBasicMaterial) {
  13693. refreshUniformsLine(uniforms, material);
  13694. if (material.isLineDashedMaterial) {
  13695. refreshUniformsDash(uniforms, material);
  13696. }
  13697. } else if (material.isPointsMaterial) {
  13698. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  13699. } else if (material.isSpriteMaterial) {
  13700. refreshUniformsSprites(uniforms, material);
  13701. } else if (material.isShadowMaterial) {
  13702. uniforms.color.value.copy(material.color);
  13703. uniforms.opacity.value = material.opacity;
  13704. } else if (material.isShaderMaterial) {
  13705. material.uniformsNeedUpdate = false; // #15581
  13706. }
  13707. }
  13708. function refreshUniformsCommon(uniforms, material) {
  13709. uniforms.opacity.value = material.opacity;
  13710. if (material.color) {
  13711. uniforms.diffuse.value.copy(material.color);
  13712. }
  13713. if (material.emissive) {
  13714. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  13715. }
  13716. if (material.map) {
  13717. uniforms.map.value = material.map;
  13718. }
  13719. if (material.alphaMap) {
  13720. uniforms.alphaMap.value = material.alphaMap;
  13721. }
  13722. if (material.specularMap) {
  13723. uniforms.specularMap.value = material.specularMap;
  13724. }
  13725. var envMap = properties.get(material).envMap;
  13726. if (envMap) {
  13727. uniforms.envMap.value = envMap;
  13728. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  13729. uniforms.reflectivity.value = material.reflectivity;
  13730. uniforms.refractionRatio.value = material.refractionRatio;
  13731. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  13732. if (maxMipLevel !== undefined) {
  13733. uniforms.maxMipLevel.value = maxMipLevel;
  13734. }
  13735. }
  13736. if (material.lightMap) {
  13737. uniforms.lightMap.value = material.lightMap;
  13738. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13739. }
  13740. if (material.aoMap) {
  13741. uniforms.aoMap.value = material.aoMap;
  13742. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13743. } // uv repeat and offset setting priorities
  13744. // 1. color map
  13745. // 2. specular map
  13746. // 3. displacementMap map
  13747. // 4. normal map
  13748. // 5. bump map
  13749. // 6. roughnessMap map
  13750. // 7. metalnessMap map
  13751. // 8. alphaMap map
  13752. // 9. emissiveMap map
  13753. // 10. clearcoat map
  13754. // 11. clearcoat normal map
  13755. // 12. clearcoat roughnessMap map
  13756. var uvScaleMap;
  13757. if (material.map) {
  13758. uvScaleMap = material.map;
  13759. } else if (material.specularMap) {
  13760. uvScaleMap = material.specularMap;
  13761. } else if (material.displacementMap) {
  13762. uvScaleMap = material.displacementMap;
  13763. } else if (material.normalMap) {
  13764. uvScaleMap = material.normalMap;
  13765. } else if (material.bumpMap) {
  13766. uvScaleMap = material.bumpMap;
  13767. } else if (material.roughnessMap) {
  13768. uvScaleMap = material.roughnessMap;
  13769. } else if (material.metalnessMap) {
  13770. uvScaleMap = material.metalnessMap;
  13771. } else if (material.alphaMap) {
  13772. uvScaleMap = material.alphaMap;
  13773. } else if (material.emissiveMap) {
  13774. uvScaleMap = material.emissiveMap;
  13775. } else if (material.clearcoatMap) {
  13776. uvScaleMap = material.clearcoatMap;
  13777. } else if (material.clearcoatNormalMap) {
  13778. uvScaleMap = material.clearcoatNormalMap;
  13779. } else if (material.clearcoatRoughnessMap) {
  13780. uvScaleMap = material.clearcoatRoughnessMap;
  13781. }
  13782. if (uvScaleMap !== undefined) {
  13783. // backwards compatibility
  13784. if (uvScaleMap.isWebGLRenderTarget) {
  13785. uvScaleMap = uvScaleMap.texture;
  13786. }
  13787. if (uvScaleMap.matrixAutoUpdate === true) {
  13788. uvScaleMap.updateMatrix();
  13789. }
  13790. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  13791. } // uv repeat and offset setting priorities for uv2
  13792. // 1. ao map
  13793. // 2. light map
  13794. var uv2ScaleMap;
  13795. if (material.aoMap) {
  13796. uv2ScaleMap = material.aoMap;
  13797. } else if (material.lightMap) {
  13798. uv2ScaleMap = material.lightMap;
  13799. }
  13800. if (uv2ScaleMap !== undefined) {
  13801. // backwards compatibility
  13802. if (uv2ScaleMap.isWebGLRenderTarget) {
  13803. uv2ScaleMap = uv2ScaleMap.texture;
  13804. }
  13805. if (uv2ScaleMap.matrixAutoUpdate === true) {
  13806. uv2ScaleMap.updateMatrix();
  13807. }
  13808. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  13809. }
  13810. }
  13811. function refreshUniformsLine(uniforms, material) {
  13812. uniforms.diffuse.value.copy(material.color);
  13813. uniforms.opacity.value = material.opacity;
  13814. }
  13815. function refreshUniformsDash(uniforms, material) {
  13816. uniforms.dashSize.value = material.dashSize;
  13817. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13818. uniforms.scale.value = material.scale;
  13819. }
  13820. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  13821. uniforms.diffuse.value.copy(material.color);
  13822. uniforms.opacity.value = material.opacity;
  13823. uniforms.size.value = material.size * pixelRatio;
  13824. uniforms.scale.value = height * 0.5;
  13825. if (material.map) {
  13826. uniforms.map.value = material.map;
  13827. }
  13828. if (material.alphaMap) {
  13829. uniforms.alphaMap.value = material.alphaMap;
  13830. } // uv repeat and offset setting priorities
  13831. // 1. color map
  13832. // 2. alpha map
  13833. var uvScaleMap;
  13834. if (material.map) {
  13835. uvScaleMap = material.map;
  13836. } else if (material.alphaMap) {
  13837. uvScaleMap = material.alphaMap;
  13838. }
  13839. if (uvScaleMap !== undefined) {
  13840. if (uvScaleMap.matrixAutoUpdate === true) {
  13841. uvScaleMap.updateMatrix();
  13842. }
  13843. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  13844. }
  13845. }
  13846. function refreshUniformsSprites(uniforms, material) {
  13847. uniforms.diffuse.value.copy(material.color);
  13848. uniforms.opacity.value = material.opacity;
  13849. uniforms.rotation.value = material.rotation;
  13850. if (material.map) {
  13851. uniforms.map.value = material.map;
  13852. }
  13853. if (material.alphaMap) {
  13854. uniforms.alphaMap.value = material.alphaMap;
  13855. } // uv repeat and offset setting priorities
  13856. // 1. color map
  13857. // 2. alpha map
  13858. var uvScaleMap;
  13859. if (material.map) {
  13860. uvScaleMap = material.map;
  13861. } else if (material.alphaMap) {
  13862. uvScaleMap = material.alphaMap;
  13863. }
  13864. if (uvScaleMap !== undefined) {
  13865. if (uvScaleMap.matrixAutoUpdate === true) {
  13866. uvScaleMap.updateMatrix();
  13867. }
  13868. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  13869. }
  13870. }
  13871. function refreshUniformsLambert(uniforms, material) {
  13872. if (material.emissiveMap) {
  13873. uniforms.emissiveMap.value = material.emissiveMap;
  13874. }
  13875. }
  13876. function refreshUniformsPhong(uniforms, material) {
  13877. uniforms.specular.value.copy(material.specular);
  13878. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  13879. if (material.emissiveMap) {
  13880. uniforms.emissiveMap.value = material.emissiveMap;
  13881. }
  13882. if (material.bumpMap) {
  13883. uniforms.bumpMap.value = material.bumpMap;
  13884. uniforms.bumpScale.value = material.bumpScale;
  13885. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  13886. }
  13887. if (material.normalMap) {
  13888. uniforms.normalMap.value = material.normalMap;
  13889. uniforms.normalScale.value.copy(material.normalScale);
  13890. if (material.side === BackSide) uniforms.normalScale.value.negate();
  13891. }
  13892. if (material.displacementMap) {
  13893. uniforms.displacementMap.value = material.displacementMap;
  13894. uniforms.displacementScale.value = material.displacementScale;
  13895. uniforms.displacementBias.value = material.displacementBias;
  13896. }
  13897. }
  13898. function refreshUniformsToon(uniforms, material) {
  13899. if (material.gradientMap) {
  13900. uniforms.gradientMap.value = material.gradientMap;
  13901. }
  13902. if (material.emissiveMap) {
  13903. uniforms.emissiveMap.value = material.emissiveMap;
  13904. }
  13905. if (material.bumpMap) {
  13906. uniforms.bumpMap.value = material.bumpMap;
  13907. uniforms.bumpScale.value = material.bumpScale;
  13908. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  13909. }
  13910. if (material.normalMap) {
  13911. uniforms.normalMap.value = material.normalMap;
  13912. uniforms.normalScale.value.copy(material.normalScale);
  13913. if (material.side === BackSide) uniforms.normalScale.value.negate();
  13914. }
  13915. if (material.displacementMap) {
  13916. uniforms.displacementMap.value = material.displacementMap;
  13917. uniforms.displacementScale.value = material.displacementScale;
  13918. uniforms.displacementBias.value = material.displacementBias;
  13919. }
  13920. }
  13921. function refreshUniformsStandard(uniforms, material) {
  13922. uniforms.roughness.value = material.roughness;
  13923. uniforms.metalness.value = material.metalness;
  13924. if (material.roughnessMap) {
  13925. uniforms.roughnessMap.value = material.roughnessMap;
  13926. }
  13927. if (material.metalnessMap) {
  13928. uniforms.metalnessMap.value = material.metalnessMap;
  13929. }
  13930. if (material.emissiveMap) {
  13931. uniforms.emissiveMap.value = material.emissiveMap;
  13932. }
  13933. if (material.bumpMap) {
  13934. uniforms.bumpMap.value = material.bumpMap;
  13935. uniforms.bumpScale.value = material.bumpScale;
  13936. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  13937. }
  13938. if (material.normalMap) {
  13939. uniforms.normalMap.value = material.normalMap;
  13940. uniforms.normalScale.value.copy(material.normalScale);
  13941. if (material.side === BackSide) uniforms.normalScale.value.negate();
  13942. }
  13943. if (material.displacementMap) {
  13944. uniforms.displacementMap.value = material.displacementMap;
  13945. uniforms.displacementScale.value = material.displacementScale;
  13946. uniforms.displacementBias.value = material.displacementBias;
  13947. }
  13948. var envMap = properties.get(material).envMap;
  13949. if (envMap) {
  13950. //uniforms.envMap.value = material.envMap; // part of uniforms common
  13951. uniforms.envMapIntensity.value = material.envMapIntensity;
  13952. }
  13953. }
  13954. function refreshUniformsPhysical(uniforms, material) {
  13955. refreshUniformsStandard(uniforms, material);
  13956. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  13957. uniforms.clearcoat.value = material.clearcoat;
  13958. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  13959. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  13960. if (material.clearcoatMap) {
  13961. uniforms.clearcoatMap.value = material.clearcoatMap;
  13962. }
  13963. if (material.clearcoatRoughnessMap) {
  13964. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  13965. }
  13966. if (material.clearcoatNormalMap) {
  13967. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  13968. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  13969. if (material.side === BackSide) {
  13970. uniforms.clearcoatNormalScale.value.negate();
  13971. }
  13972. }
  13973. uniforms.transmission.value = material.transmission;
  13974. if (material.transmissionMap) {
  13975. uniforms.transmissionMap.value = material.transmissionMap;
  13976. }
  13977. }
  13978. function refreshUniformsMatcap(uniforms, material) {
  13979. if (material.matcap) {
  13980. uniforms.matcap.value = material.matcap;
  13981. }
  13982. if (material.bumpMap) {
  13983. uniforms.bumpMap.value = material.bumpMap;
  13984. uniforms.bumpScale.value = material.bumpScale;
  13985. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  13986. }
  13987. if (material.normalMap) {
  13988. uniforms.normalMap.value = material.normalMap;
  13989. uniforms.normalScale.value.copy(material.normalScale);
  13990. if (material.side === BackSide) uniforms.normalScale.value.negate();
  13991. }
  13992. if (material.displacementMap) {
  13993. uniforms.displacementMap.value = material.displacementMap;
  13994. uniforms.displacementScale.value = material.displacementScale;
  13995. uniforms.displacementBias.value = material.displacementBias;
  13996. }
  13997. }
  13998. function refreshUniformsDepth(uniforms, material) {
  13999. if (material.displacementMap) {
  14000. uniforms.displacementMap.value = material.displacementMap;
  14001. uniforms.displacementScale.value = material.displacementScale;
  14002. uniforms.displacementBias.value = material.displacementBias;
  14003. }
  14004. }
  14005. function refreshUniformsDistance(uniforms, material) {
  14006. if (material.displacementMap) {
  14007. uniforms.displacementMap.value = material.displacementMap;
  14008. uniforms.displacementScale.value = material.displacementScale;
  14009. uniforms.displacementBias.value = material.displacementBias;
  14010. }
  14011. uniforms.referencePosition.value.copy(material.referencePosition);
  14012. uniforms.nearDistance.value = material.nearDistance;
  14013. uniforms.farDistance.value = material.farDistance;
  14014. }
  14015. function refreshUniformsNormal(uniforms, material) {
  14016. if (material.bumpMap) {
  14017. uniforms.bumpMap.value = material.bumpMap;
  14018. uniforms.bumpScale.value = material.bumpScale;
  14019. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14020. }
  14021. if (material.normalMap) {
  14022. uniforms.normalMap.value = material.normalMap;
  14023. uniforms.normalScale.value.copy(material.normalScale);
  14024. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14025. }
  14026. if (material.displacementMap) {
  14027. uniforms.displacementMap.value = material.displacementMap;
  14028. uniforms.displacementScale.value = material.displacementScale;
  14029. uniforms.displacementBias.value = material.displacementBias;
  14030. }
  14031. }
  14032. return {
  14033. refreshFogUniforms: refreshFogUniforms,
  14034. refreshMaterialUniforms: refreshMaterialUniforms
  14035. };
  14036. }
  14037. function WebGLRenderer(parameters) {
  14038. parameters = parameters || {};
  14039. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas'),
  14040. _context = parameters.context !== undefined ? parameters.context : null,
  14041. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14042. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14043. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14044. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14045. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14046. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14047. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14048. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14049. var currentRenderList = null;
  14050. var currentRenderState = null; // public properties
  14051. this.domElement = _canvas; // Debug configuration container
  14052. this.debug = {
  14053. /**
  14054. * Enables error checking and reporting when shader programs are being compiled
  14055. * @type {boolean}
  14056. */
  14057. checkShaderErrors: true
  14058. }; // clearing
  14059. this.autoClear = true;
  14060. this.autoClearColor = true;
  14061. this.autoClearDepth = true;
  14062. this.autoClearStencil = true; // scene graph
  14063. this.sortObjects = true; // user-defined clipping
  14064. this.clippingPlanes = [];
  14065. this.localClippingEnabled = false; // physically based shading
  14066. this.gammaFactor = 2.0; // for backwards compatibility
  14067. this.outputEncoding = LinearEncoding; // physical lights
  14068. this.physicallyCorrectLights = false; // tone mapping
  14069. this.toneMapping = NoToneMapping;
  14070. this.toneMappingExposure = 1.0; // morphs
  14071. this.maxMorphTargets = 8;
  14072. this.maxMorphNormals = 4; // internal properties
  14073. var _this = this;
  14074. var _isContextLost = false; // internal state cache
  14075. var _framebuffer = null;
  14076. var _currentActiveCubeFace = 0;
  14077. var _currentActiveMipmapLevel = 0;
  14078. var _currentRenderTarget = null;
  14079. var _currentFramebuffer = null;
  14080. var _currentMaterialId = -1;
  14081. var _currentCamera = null;
  14082. var _currentArrayCamera = null;
  14083. var _currentViewport = new Vector4();
  14084. var _currentScissor = new Vector4();
  14085. var _currentScissorTest = null; //
  14086. var _width = _canvas.width;
  14087. var _height = _canvas.height;
  14088. var _pixelRatio = 1;
  14089. var _opaqueSort = null;
  14090. var _transparentSort = null;
  14091. var _viewport = new Vector4(0, 0, _width, _height);
  14092. var _scissor = new Vector4(0, 0, _width, _height);
  14093. var _scissorTest = false; // frustum
  14094. var _frustum = new Frustum(); // clipping
  14095. var _clippingEnabled = false;
  14096. var _localClippingEnabled = false; // camera matrices cache
  14097. var _projScreenMatrix = new Matrix4();
  14098. var _vector3 = new Vector3();
  14099. var _emptyScene = {
  14100. background: null,
  14101. fog: null,
  14102. environment: null,
  14103. overrideMaterial: null,
  14104. isScene: true
  14105. };
  14106. function getTargetPixelRatio() {
  14107. return _currentRenderTarget === null ? _pixelRatio : 1;
  14108. } // initialize
  14109. var _gl = _context;
  14110. function getContext(contextNames, contextAttributes) {
  14111. for (var i = 0; i < contextNames.length; i++) {
  14112. var contextName = contextNames[i];
  14113. var context = _canvas.getContext(contextName, contextAttributes);
  14114. if (context !== null) return context;
  14115. }
  14116. return null;
  14117. }
  14118. try {
  14119. var contextAttributes = {
  14120. alpha: _alpha,
  14121. depth: _depth,
  14122. stencil: _stencil,
  14123. antialias: _antialias,
  14124. premultipliedAlpha: _premultipliedAlpha,
  14125. preserveDrawingBuffer: _preserveDrawingBuffer,
  14126. powerPreference: _powerPreference,
  14127. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14128. }; // event listeners must be registered before WebGL context is created, see #12753
  14129. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  14130. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  14131. if (_gl === null) {
  14132. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  14133. if (_this.isWebGL1Renderer === true) {
  14134. contextNames.shift();
  14135. }
  14136. _gl = getContext(contextNames, contextAttributes);
  14137. if (_gl === null) {
  14138. if (getContext(contextNames)) {
  14139. throw new Error('Error creating WebGL context with your selected attributes.');
  14140. } else {
  14141. throw new Error('Error creating WebGL context.');
  14142. }
  14143. }
  14144. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14145. if (_gl.getShaderPrecisionFormat === undefined) {
  14146. _gl.getShaderPrecisionFormat = function () {
  14147. return {
  14148. 'rangeMin': 1,
  14149. 'rangeMax': 1,
  14150. 'precision': 1
  14151. };
  14152. };
  14153. }
  14154. } catch (error) {
  14155. console.error('THREE.WebGLRenderer: ' + error.message);
  14156. throw error;
  14157. }
  14158. var extensions, capabilities, state, info;
  14159. var properties, textures, cubemaps, attributes, geometries, objects;
  14160. var programCache, materials, renderLists, renderStates, clipping;
  14161. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14162. var utils, bindingStates;
  14163. function initGLContext() {
  14164. extensions = new WebGLExtensions(_gl);
  14165. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  14166. if (capabilities.isWebGL2 === false) {
  14167. extensions.get('WEBGL_depth_texture');
  14168. extensions.get('OES_texture_float');
  14169. extensions.get('OES_texture_half_float');
  14170. extensions.get('OES_texture_half_float_linear');
  14171. extensions.get('OES_standard_derivatives');
  14172. extensions.get('OES_element_index_uint');
  14173. extensions.get('OES_vertex_array_object');
  14174. extensions.get('ANGLE_instanced_arrays');
  14175. }
  14176. extensions.get('OES_texture_float_linear');
  14177. utils = new WebGLUtils(_gl, extensions, capabilities);
  14178. state = new WebGLState(_gl, extensions, capabilities);
  14179. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14180. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14181. info = new WebGLInfo(_gl);
  14182. properties = new WebGLProperties();
  14183. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  14184. cubemaps = new WebGLCubeMaps(_this);
  14185. attributes = new WebGLAttributes(_gl, capabilities);
  14186. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  14187. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  14188. objects = new WebGLObjects(_gl, geometries, attributes, info);
  14189. morphtargets = new WebGLMorphtargets(_gl);
  14190. clipping = new WebGLClipping(properties);
  14191. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  14192. materials = new WebGLMaterials(properties);
  14193. renderLists = new WebGLRenderLists(properties);
  14194. renderStates = new WebGLRenderStates();
  14195. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  14196. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  14197. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  14198. info.programs = programCache.programs;
  14199. _this.capabilities = capabilities;
  14200. _this.extensions = extensions;
  14201. _this.properties = properties;
  14202. _this.renderLists = renderLists;
  14203. _this.state = state;
  14204. _this.info = info;
  14205. }
  14206. initGLContext(); // xr
  14207. var xr = new WebXRManager(_this, _gl);
  14208. this.xr = xr; // shadow map
  14209. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  14210. this.shadowMap = shadowMap; // API
  14211. this.getContext = function () {
  14212. return _gl;
  14213. };
  14214. this.getContextAttributes = function () {
  14215. return _gl.getContextAttributes();
  14216. };
  14217. this.forceContextLoss = function () {
  14218. var extension = extensions.get('WEBGL_lose_context');
  14219. if (extension) extension.loseContext();
  14220. };
  14221. this.forceContextRestore = function () {
  14222. var extension = extensions.get('WEBGL_lose_context');
  14223. if (extension) extension.restoreContext();
  14224. };
  14225. this.getPixelRatio = function () {
  14226. return _pixelRatio;
  14227. };
  14228. this.setPixelRatio = function (value) {
  14229. if (value === undefined) return;
  14230. _pixelRatio = value;
  14231. this.setSize(_width, _height, false);
  14232. };
  14233. this.getSize = function (target) {
  14234. if (target === undefined) {
  14235. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  14236. target = new Vector2();
  14237. }
  14238. return target.set(_width, _height);
  14239. };
  14240. this.setSize = function (width, height, updateStyle) {
  14241. if (xr.isPresenting) {
  14242. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  14243. return;
  14244. }
  14245. _width = width;
  14246. _height = height;
  14247. _canvas.width = Math.floor(width * _pixelRatio);
  14248. _canvas.height = Math.floor(height * _pixelRatio);
  14249. if (updateStyle !== false) {
  14250. _canvas.style.width = width + 'px';
  14251. _canvas.style.height = height + 'px';
  14252. }
  14253. this.setViewport(0, 0, width, height);
  14254. };
  14255. this.getDrawingBufferSize = function (target) {
  14256. if (target === undefined) {
  14257. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  14258. target = new Vector2();
  14259. }
  14260. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  14261. };
  14262. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  14263. _width = width;
  14264. _height = height;
  14265. _pixelRatio = pixelRatio;
  14266. _canvas.width = Math.floor(width * pixelRatio);
  14267. _canvas.height = Math.floor(height * pixelRatio);
  14268. this.setViewport(0, 0, width, height);
  14269. };
  14270. this.getCurrentViewport = function (target) {
  14271. if (target === undefined) {
  14272. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  14273. target = new Vector4();
  14274. }
  14275. return target.copy(_currentViewport);
  14276. };
  14277. this.getViewport = function (target) {
  14278. return target.copy(_viewport);
  14279. };
  14280. this.setViewport = function (x, y, width, height) {
  14281. if (x.isVector4) {
  14282. _viewport.set(x.x, x.y, x.z, x.w);
  14283. } else {
  14284. _viewport.set(x, y, width, height);
  14285. }
  14286. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14287. };
  14288. this.getScissor = function (target) {
  14289. return target.copy(_scissor);
  14290. };
  14291. this.setScissor = function (x, y, width, height) {
  14292. if (x.isVector4) {
  14293. _scissor.set(x.x, x.y, x.z, x.w);
  14294. } else {
  14295. _scissor.set(x, y, width, height);
  14296. }
  14297. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14298. };
  14299. this.getScissorTest = function () {
  14300. return _scissorTest;
  14301. };
  14302. this.setScissorTest = function (boolean) {
  14303. state.setScissorTest(_scissorTest = boolean);
  14304. };
  14305. this.setOpaqueSort = function (method) {
  14306. _opaqueSort = method;
  14307. };
  14308. this.setTransparentSort = function (method) {
  14309. _transparentSort = method;
  14310. }; // Clearing
  14311. this.getClearColor = function () {
  14312. return background.getClearColor();
  14313. };
  14314. this.setClearColor = function () {
  14315. background.setClearColor.apply(background, arguments);
  14316. };
  14317. this.getClearAlpha = function () {
  14318. return background.getClearAlpha();
  14319. };
  14320. this.setClearAlpha = function () {
  14321. background.setClearAlpha.apply(background, arguments);
  14322. };
  14323. this.clear = function (color, depth, stencil) {
  14324. var bits = 0;
  14325. if (color === undefined || color) bits |= 16384;
  14326. if (depth === undefined || depth) bits |= 256;
  14327. if (stencil === undefined || stencil) bits |= 1024;
  14328. _gl.clear(bits);
  14329. };
  14330. this.clearColor = function () {
  14331. this.clear(true, false, false);
  14332. };
  14333. this.clearDepth = function () {
  14334. this.clear(false, true, false);
  14335. };
  14336. this.clearStencil = function () {
  14337. this.clear(false, false, true);
  14338. }; //
  14339. this.dispose = function () {
  14340. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  14341. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  14342. renderLists.dispose();
  14343. renderStates.dispose();
  14344. properties.dispose();
  14345. cubemaps.dispose();
  14346. objects.dispose();
  14347. bindingStates.dispose();
  14348. xr.dispose();
  14349. animation.stop();
  14350. }; // Events
  14351. function onContextLost(event) {
  14352. event.preventDefault();
  14353. console.log('THREE.WebGLRenderer: Context Lost.');
  14354. _isContextLost = true;
  14355. }
  14356. function onContextRestore()
  14357. /* event */
  14358. {
  14359. console.log('THREE.WebGLRenderer: Context Restored.');
  14360. _isContextLost = false;
  14361. initGLContext();
  14362. }
  14363. function onMaterialDispose(event) {
  14364. var material = event.target;
  14365. material.removeEventListener('dispose', onMaterialDispose);
  14366. deallocateMaterial(material);
  14367. } // Buffer deallocation
  14368. function deallocateMaterial(material) {
  14369. releaseMaterialProgramReference(material);
  14370. properties.remove(material);
  14371. }
  14372. function releaseMaterialProgramReference(material) {
  14373. var programInfo = properties.get(material).program;
  14374. if (programInfo !== undefined) {
  14375. programCache.releaseProgram(programInfo);
  14376. }
  14377. } // Buffer rendering
  14378. function renderObjectImmediate(object, program) {
  14379. object.render(function (object) {
  14380. _this.renderBufferImmediate(object, program);
  14381. });
  14382. }
  14383. this.renderBufferImmediate = function (object, program) {
  14384. bindingStates.initAttributes();
  14385. var buffers = properties.get(object);
  14386. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  14387. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  14388. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  14389. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  14390. var programAttributes = program.getAttributes();
  14391. if (object.hasPositions) {
  14392. _gl.bindBuffer(34962, buffers.position);
  14393. _gl.bufferData(34962, object.positionArray, 35048);
  14394. bindingStates.enableAttribute(programAttributes.position);
  14395. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  14396. }
  14397. if (object.hasNormals) {
  14398. _gl.bindBuffer(34962, buffers.normal);
  14399. _gl.bufferData(34962, object.normalArray, 35048);
  14400. bindingStates.enableAttribute(programAttributes.normal);
  14401. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  14402. }
  14403. if (object.hasUvs) {
  14404. _gl.bindBuffer(34962, buffers.uv);
  14405. _gl.bufferData(34962, object.uvArray, 35048);
  14406. bindingStates.enableAttribute(programAttributes.uv);
  14407. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  14408. }
  14409. if (object.hasColors) {
  14410. _gl.bindBuffer(34962, buffers.color);
  14411. _gl.bufferData(34962, object.colorArray, 35048);
  14412. bindingStates.enableAttribute(programAttributes.color);
  14413. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  14414. }
  14415. bindingStates.disableUnusedAttributes();
  14416. _gl.drawArrays(4, 0, object.count);
  14417. object.count = 0;
  14418. };
  14419. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  14420. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  14421. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  14422. var program = setProgram(camera, scene, material, object);
  14423. state.setMaterial(material, frontFaceCW); //
  14424. var index = geometry.index;
  14425. var position = geometry.attributes.position; //
  14426. if (index === null) {
  14427. if (position === undefined || position.count === 0) return;
  14428. } else if (index.count === 0) {
  14429. return;
  14430. } //
  14431. var rangeFactor = 1;
  14432. if (material.wireframe === true) {
  14433. index = geometries.getWireframeAttribute(geometry);
  14434. rangeFactor = 2;
  14435. }
  14436. if (material.morphTargets || material.morphNormals) {
  14437. morphtargets.update(object, geometry, material, program);
  14438. }
  14439. bindingStates.setup(object, material, program, geometry, index);
  14440. var attribute;
  14441. var renderer = bufferRenderer;
  14442. if (index !== null) {
  14443. attribute = attributes.get(index);
  14444. renderer = indexedBufferRenderer;
  14445. renderer.setIndex(attribute);
  14446. } //
  14447. var dataCount = index !== null ? index.count : position.count;
  14448. var rangeStart = geometry.drawRange.start * rangeFactor;
  14449. var rangeCount = geometry.drawRange.count * rangeFactor;
  14450. var groupStart = group !== null ? group.start * rangeFactor : 0;
  14451. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14452. var drawStart = Math.max(rangeStart, groupStart);
  14453. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  14454. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  14455. if (drawCount === 0) return; //
  14456. if (object.isMesh) {
  14457. if (material.wireframe === true) {
  14458. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  14459. renderer.setMode(1);
  14460. } else {
  14461. renderer.setMode(4);
  14462. }
  14463. } else if (object.isLine) {
  14464. var lineWidth = material.linewidth;
  14465. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  14466. state.setLineWidth(lineWidth * getTargetPixelRatio());
  14467. if (object.isLineSegments) {
  14468. renderer.setMode(1);
  14469. } else if (object.isLineLoop) {
  14470. renderer.setMode(2);
  14471. } else {
  14472. renderer.setMode(3);
  14473. }
  14474. } else if (object.isPoints) {
  14475. renderer.setMode(0);
  14476. } else if (object.isSprite) {
  14477. renderer.setMode(4);
  14478. }
  14479. if (object.isInstancedMesh) {
  14480. renderer.renderInstances(drawStart, drawCount, object.count);
  14481. } else if (geometry.isInstancedBufferGeometry) {
  14482. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  14483. renderer.renderInstances(drawStart, drawCount, instanceCount);
  14484. } else {
  14485. renderer.render(drawStart, drawCount);
  14486. }
  14487. }; // Compile
  14488. this.compile = function (scene, camera) {
  14489. currentRenderState = renderStates.get(scene, camera);
  14490. currentRenderState.init();
  14491. scene.traverseVisible(function (object) {
  14492. if (object.isLight && object.layers.test(camera.layers)) {
  14493. currentRenderState.pushLight(object);
  14494. if (object.castShadow) {
  14495. currentRenderState.pushShadow(object);
  14496. }
  14497. }
  14498. });
  14499. currentRenderState.setupLights(camera);
  14500. var compiled = new WeakMap();
  14501. scene.traverse(function (object) {
  14502. var material = object.material;
  14503. if (material) {
  14504. if (Array.isArray(material)) {
  14505. for (var i = 0; i < material.length; i++) {
  14506. var material2 = material[i];
  14507. if (compiled.has(material2) === false) {
  14508. initMaterial(material2, scene, object);
  14509. compiled.set(material2);
  14510. }
  14511. }
  14512. } else if (compiled.has(material) === false) {
  14513. initMaterial(material, scene, object);
  14514. compiled.set(material);
  14515. }
  14516. }
  14517. });
  14518. }; // Animation Loop
  14519. var onAnimationFrameCallback = null;
  14520. function onAnimationFrame(time) {
  14521. if (xr.isPresenting) return;
  14522. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  14523. }
  14524. var animation = new WebGLAnimation();
  14525. animation.setAnimationLoop(onAnimationFrame);
  14526. if (typeof window !== 'undefined') animation.setContext(window);
  14527. this.setAnimationLoop = function (callback) {
  14528. onAnimationFrameCallback = callback;
  14529. xr.setAnimationLoop(callback);
  14530. callback === null ? animation.stop() : animation.start();
  14531. }; // Rendering
  14532. this.render = function (scene, camera) {
  14533. var renderTarget, forceClear;
  14534. if (arguments[2] !== undefined) {
  14535. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  14536. renderTarget = arguments[2];
  14537. }
  14538. if (arguments[3] !== undefined) {
  14539. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  14540. forceClear = arguments[3];
  14541. }
  14542. if (camera !== undefined && camera.isCamera !== true) {
  14543. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  14544. return;
  14545. }
  14546. if (_isContextLost === true) return; // reset caching for this frame
  14547. bindingStates.resetDefaultState();
  14548. _currentMaterialId = -1;
  14549. _currentCamera = null; // update scene graph
  14550. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  14551. if (camera.parent === null) camera.updateMatrixWorld();
  14552. if (xr.enabled === true && xr.isPresenting === true) {
  14553. camera = xr.getCamera(camera);
  14554. } //
  14555. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  14556. currentRenderState = renderStates.get(scene, camera);
  14557. currentRenderState.init();
  14558. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  14559. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  14560. _localClippingEnabled = this.localClippingEnabled;
  14561. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  14562. currentRenderList = renderLists.get(scene, camera);
  14563. currentRenderList.init();
  14564. projectObject(scene, camera, 0, _this.sortObjects);
  14565. currentRenderList.finish();
  14566. if (_this.sortObjects === true) {
  14567. currentRenderList.sort(_opaqueSort, _transparentSort);
  14568. } //
  14569. if (_clippingEnabled === true) clipping.beginShadows();
  14570. var shadowsArray = currentRenderState.state.shadowsArray;
  14571. shadowMap.render(shadowsArray, scene, camera);
  14572. currentRenderState.setupLights(camera);
  14573. if (_clippingEnabled === true) clipping.endShadows(); //
  14574. if (this.info.autoReset === true) this.info.reset();
  14575. if (renderTarget !== undefined) {
  14576. this.setRenderTarget(renderTarget);
  14577. } //
  14578. background.render(currentRenderList, scene, camera, forceClear); // render scene
  14579. var opaqueObjects = currentRenderList.opaque;
  14580. var transparentObjects = currentRenderList.transparent;
  14581. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  14582. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  14583. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  14584. if (_currentRenderTarget !== null) {
  14585. // Generate mipmap if we're using any kind of mipmap filtering
  14586. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  14587. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  14588. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  14589. state.buffers.depth.setTest(true);
  14590. state.buffers.depth.setMask(true);
  14591. state.buffers.color.setMask(true);
  14592. state.setPolygonOffset(false); // _gl.finish();
  14593. currentRenderList = null;
  14594. currentRenderState = null;
  14595. };
  14596. function projectObject(object, camera, groupOrder, sortObjects) {
  14597. if (object.visible === false) return;
  14598. var visible = object.layers.test(camera.layers);
  14599. if (visible) {
  14600. if (object.isGroup) {
  14601. groupOrder = object.renderOrder;
  14602. } else if (object.isLOD) {
  14603. if (object.autoUpdate === true) object.update(camera);
  14604. } else if (object.isLight) {
  14605. currentRenderState.pushLight(object);
  14606. if (object.castShadow) {
  14607. currentRenderState.pushShadow(object);
  14608. }
  14609. } else if (object.isSprite) {
  14610. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  14611. if (sortObjects) {
  14612. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14613. }
  14614. var geometry = objects.update(object);
  14615. var material = object.material;
  14616. if (material.visible) {
  14617. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  14618. }
  14619. }
  14620. } else if (object.isImmediateRenderObject) {
  14621. if (sortObjects) {
  14622. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14623. }
  14624. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  14625. } else if (object.isMesh || object.isLine || object.isPoints) {
  14626. if (object.isSkinnedMesh) {
  14627. // update skeleton only once in a frame
  14628. if (object.skeleton.frame !== info.render.frame) {
  14629. object.skeleton.update();
  14630. object.skeleton.frame = info.render.frame;
  14631. }
  14632. }
  14633. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  14634. if (sortObjects) {
  14635. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14636. }
  14637. var _geometry = objects.update(object);
  14638. var _material = object.material;
  14639. if (Array.isArray(_material)) {
  14640. var groups = _geometry.groups;
  14641. for (var i = 0, l = groups.length; i < l; i++) {
  14642. var group = groups[i];
  14643. var groupMaterial = _material[group.materialIndex];
  14644. if (groupMaterial && groupMaterial.visible) {
  14645. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  14646. }
  14647. }
  14648. } else if (_material.visible) {
  14649. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  14650. }
  14651. }
  14652. }
  14653. }
  14654. var children = object.children;
  14655. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  14656. projectObject(children[_i], camera, groupOrder, sortObjects);
  14657. }
  14658. }
  14659. function renderObjects(renderList, scene, camera) {
  14660. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  14661. for (var i = 0, l = renderList.length; i < l; i++) {
  14662. var renderItem = renderList[i];
  14663. var object = renderItem.object;
  14664. var geometry = renderItem.geometry;
  14665. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  14666. var group = renderItem.group;
  14667. if (camera.isArrayCamera) {
  14668. _currentArrayCamera = camera;
  14669. var cameras = camera.cameras;
  14670. for (var j = 0, jl = cameras.length; j < jl; j++) {
  14671. var camera2 = cameras[j];
  14672. if (object.layers.test(camera2.layers)) {
  14673. state.viewport(_currentViewport.copy(camera2.viewport));
  14674. currentRenderState.setupLights(camera2);
  14675. renderObject(object, scene, camera2, geometry, material, group);
  14676. }
  14677. }
  14678. } else {
  14679. _currentArrayCamera = null;
  14680. renderObject(object, scene, camera, geometry, material, group);
  14681. }
  14682. }
  14683. }
  14684. function renderObject(object, scene, camera, geometry, material, group) {
  14685. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  14686. currentRenderState = renderStates.get(scene, _currentArrayCamera || camera);
  14687. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  14688. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  14689. if (object.isImmediateRenderObject) {
  14690. var program = setProgram(camera, scene, material, object);
  14691. state.setMaterial(material);
  14692. bindingStates.reset();
  14693. renderObjectImmediate(object, program);
  14694. } else {
  14695. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  14696. }
  14697. object.onAfterRender(_this, scene, camera, geometry, material, group);
  14698. currentRenderState = renderStates.get(scene, _currentArrayCamera || camera);
  14699. }
  14700. function initMaterial(material, scene, object) {
  14701. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14702. var materialProperties = properties.get(material);
  14703. var lights = currentRenderState.state.lights;
  14704. var shadowsArray = currentRenderState.state.shadowsArray;
  14705. var lightsStateVersion = lights.state.version;
  14706. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  14707. var programCacheKey = programCache.getProgramCacheKey(parameters);
  14708. var program = materialProperties.program;
  14709. var programChange = true;
  14710. if (program === undefined) {
  14711. // new material
  14712. material.addEventListener('dispose', onMaterialDispose);
  14713. } else if (program.cacheKey !== programCacheKey) {
  14714. // changed glsl or parameters
  14715. releaseMaterialProgramReference(material);
  14716. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  14717. programChange = false;
  14718. } else if (parameters.shaderID !== undefined) {
  14719. // same glsl and uniform list, envMap still needs the update here to avoid a frame-late effect
  14720. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  14721. materialProperties.envMap = cubemaps.get(material.envMap || environment);
  14722. return;
  14723. } else {
  14724. // only rebuild uniform list
  14725. programChange = false;
  14726. }
  14727. if (programChange) {
  14728. parameters.uniforms = programCache.getUniforms(material);
  14729. material.onBeforeCompile(parameters, _this);
  14730. program = programCache.acquireProgram(parameters, programCacheKey);
  14731. materialProperties.program = program;
  14732. materialProperties.uniforms = parameters.uniforms;
  14733. materialProperties.outputEncoding = parameters.outputEncoding;
  14734. }
  14735. var uniforms = materialProperties.uniforms;
  14736. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  14737. materialProperties.numClippingPlanes = clipping.numPlanes;
  14738. materialProperties.numIntersection = clipping.numIntersection;
  14739. uniforms.clippingPlanes = clipping.uniform;
  14740. }
  14741. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  14742. materialProperties.fog = scene.fog;
  14743. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment); // store the light setup it was created for
  14744. materialProperties.needsLights = materialNeedsLights(material);
  14745. materialProperties.lightsStateVersion = lightsStateVersion;
  14746. if (materialProperties.needsLights) {
  14747. // wire up the material to this renderer's lighting state
  14748. uniforms.ambientLightColor.value = lights.state.ambient;
  14749. uniforms.lightProbe.value = lights.state.probe;
  14750. uniforms.directionalLights.value = lights.state.directional;
  14751. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  14752. uniforms.spotLights.value = lights.state.spot;
  14753. uniforms.spotLightShadows.value = lights.state.spotShadow;
  14754. uniforms.rectAreaLights.value = lights.state.rectArea;
  14755. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  14756. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  14757. uniforms.pointLights.value = lights.state.point;
  14758. uniforms.pointLightShadows.value = lights.state.pointShadow;
  14759. uniforms.hemisphereLights.value = lights.state.hemi;
  14760. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14761. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14762. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14763. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14764. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14765. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  14766. }
  14767. var progUniforms = materialProperties.program.getUniforms();
  14768. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  14769. materialProperties.uniformsList = uniformsList;
  14770. }
  14771. function setProgram(camera, scene, material, object) {
  14772. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14773. textures.resetTextureUnits();
  14774. var fog = scene.fog;
  14775. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  14776. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  14777. var envMap = cubemaps.get(material.envMap || environment);
  14778. var materialProperties = properties.get(material);
  14779. var lights = currentRenderState.state.lights;
  14780. if (_clippingEnabled === true) {
  14781. if (_localClippingEnabled === true || camera !== _currentCamera) {
  14782. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  14783. // object instead of the material, once it becomes feasible
  14784. // (#8465, #8379)
  14785. clipping.setState(material, camera, useCache);
  14786. }
  14787. }
  14788. if (material.version === materialProperties.__version) {
  14789. if (material.fog && materialProperties.fog !== fog) {
  14790. initMaterial(material, scene, object);
  14791. } else if (materialProperties.environment !== environment) {
  14792. initMaterial(material, scene, object);
  14793. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  14794. initMaterial(material, scene, object);
  14795. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  14796. initMaterial(material, scene, object);
  14797. } else if (materialProperties.outputEncoding !== encoding) {
  14798. initMaterial(material, scene, object);
  14799. } else if (materialProperties.envMap !== envMap) {
  14800. initMaterial(material, scene, object);
  14801. }
  14802. } else {
  14803. initMaterial(material, scene, object);
  14804. materialProperties.__version = material.version;
  14805. }
  14806. var refreshProgram = false;
  14807. var refreshMaterial = false;
  14808. var refreshLights = false;
  14809. var program = materialProperties.program,
  14810. p_uniforms = program.getUniforms(),
  14811. m_uniforms = materialProperties.uniforms;
  14812. if (state.useProgram(program.program)) {
  14813. refreshProgram = true;
  14814. refreshMaterial = true;
  14815. refreshLights = true;
  14816. }
  14817. if (material.id !== _currentMaterialId) {
  14818. _currentMaterialId = material.id;
  14819. refreshMaterial = true;
  14820. }
  14821. if (refreshProgram || _currentCamera !== camera) {
  14822. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  14823. if (capabilities.logarithmicDepthBuffer) {
  14824. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  14825. }
  14826. if (_currentCamera !== camera) {
  14827. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  14828. // now, in case this material supports lights - or later, when
  14829. // the next material that does gets activated:
  14830. refreshMaterial = true; // set to true on material change
  14831. refreshLights = true; // remains set until update done
  14832. } // load material specific uniforms
  14833. // (shader material also gets them for the sake of genericity)
  14834. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  14835. var uCamPos = p_uniforms.map.cameraPosition;
  14836. if (uCamPos !== undefined) {
  14837. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  14838. }
  14839. }
  14840. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  14841. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  14842. }
  14843. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  14844. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  14845. }
  14846. } // skinning uniforms must be set even if material didn't change
  14847. // auto-setting of texture unit for bone texture must go before other textures
  14848. // otherwise textures used for skinning can take over texture units reserved for other material textures
  14849. if (material.skinning) {
  14850. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  14851. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  14852. var skeleton = object.skeleton;
  14853. if (skeleton) {
  14854. var bones = skeleton.bones;
  14855. if (capabilities.floatVertexTextures) {
  14856. if (skeleton.boneTexture === undefined) {
  14857. // layout (1 matrix = 4 pixels)
  14858. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14859. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14860. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14861. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14862. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14863. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  14864. size = MathUtils.ceilPowerOfTwo(size);
  14865. size = Math.max(size, 4);
  14866. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  14867. boneMatrices.set(skeleton.boneMatrices); // copy current values
  14868. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  14869. skeleton.boneMatrices = boneMatrices;
  14870. skeleton.boneTexture = boneTexture;
  14871. skeleton.boneTextureSize = size;
  14872. }
  14873. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  14874. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  14875. } else {
  14876. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  14877. }
  14878. }
  14879. }
  14880. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  14881. materialProperties.receiveShadow = object.receiveShadow;
  14882. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  14883. }
  14884. if (refreshMaterial) {
  14885. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  14886. if (materialProperties.needsLights) {
  14887. // the current material requires lighting info
  14888. // note: all lighting uniforms are always set correctly
  14889. // they simply reference the renderer's state for their
  14890. // values
  14891. //
  14892. // use the current material's .needsUpdate flags to set
  14893. // the GL state when required
  14894. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  14895. } // refresh uniforms common to several materials
  14896. if (fog && material.fog) {
  14897. materials.refreshFogUniforms(m_uniforms, fog);
  14898. }
  14899. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  14900. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  14901. }
  14902. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  14903. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  14904. material.uniformsNeedUpdate = false;
  14905. }
  14906. if (material.isSpriteMaterial) {
  14907. p_uniforms.setValue(_gl, 'center', object.center);
  14908. } // common matrices
  14909. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  14910. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  14911. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  14912. return program;
  14913. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  14914. function markUniformsLightsNeedsUpdate(uniforms, value) {
  14915. uniforms.ambientLightColor.needsUpdate = value;
  14916. uniforms.lightProbe.needsUpdate = value;
  14917. uniforms.directionalLights.needsUpdate = value;
  14918. uniforms.directionalLightShadows.needsUpdate = value;
  14919. uniforms.pointLights.needsUpdate = value;
  14920. uniforms.pointLightShadows.needsUpdate = value;
  14921. uniforms.spotLights.needsUpdate = value;
  14922. uniforms.spotLightShadows.needsUpdate = value;
  14923. uniforms.rectAreaLights.needsUpdate = value;
  14924. uniforms.hemisphereLights.needsUpdate = value;
  14925. }
  14926. function materialNeedsLights(material) {
  14927. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  14928. } //
  14929. this.setFramebuffer = function (value) {
  14930. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  14931. _framebuffer = value;
  14932. };
  14933. this.getActiveCubeFace = function () {
  14934. return _currentActiveCubeFace;
  14935. };
  14936. this.getActiveMipmapLevel = function () {
  14937. return _currentActiveMipmapLevel;
  14938. };
  14939. this.getRenderList = function () {
  14940. return currentRenderList;
  14941. };
  14942. this.setRenderList = function (renderList) {
  14943. currentRenderList = renderList;
  14944. };
  14945. this.getRenderState = function () {
  14946. return currentRenderState;
  14947. };
  14948. this.setRenderState = function (renderState) {
  14949. currentRenderState = renderState;
  14950. };
  14951. this.getRenderTarget = function () {
  14952. return _currentRenderTarget;
  14953. };
  14954. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  14955. if (activeCubeFace === void 0) {
  14956. activeCubeFace = 0;
  14957. }
  14958. if (activeMipmapLevel === void 0) {
  14959. activeMipmapLevel = 0;
  14960. }
  14961. _currentRenderTarget = renderTarget;
  14962. _currentActiveCubeFace = activeCubeFace;
  14963. _currentActiveMipmapLevel = activeMipmapLevel;
  14964. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  14965. textures.setupRenderTarget(renderTarget);
  14966. }
  14967. var framebuffer = _framebuffer;
  14968. var isCube = false;
  14969. if (renderTarget) {
  14970. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  14971. if (renderTarget.isWebGLCubeRenderTarget) {
  14972. framebuffer = __webglFramebuffer[activeCubeFace];
  14973. isCube = true;
  14974. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  14975. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  14976. } else {
  14977. framebuffer = __webglFramebuffer;
  14978. }
  14979. _currentViewport.copy(renderTarget.viewport);
  14980. _currentScissor.copy(renderTarget.scissor);
  14981. _currentScissorTest = renderTarget.scissorTest;
  14982. } else {
  14983. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  14984. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  14985. _currentScissorTest = _scissorTest;
  14986. }
  14987. if (_currentFramebuffer !== framebuffer) {
  14988. _gl.bindFramebuffer(36160, framebuffer);
  14989. _currentFramebuffer = framebuffer;
  14990. }
  14991. state.viewport(_currentViewport);
  14992. state.scissor(_currentScissor);
  14993. state.setScissorTest(_currentScissorTest);
  14994. if (isCube) {
  14995. var textureProperties = properties.get(renderTarget.texture);
  14996. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  14997. }
  14998. };
  14999. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15000. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15001. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15002. return;
  15003. }
  15004. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15005. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15006. framebuffer = framebuffer[activeCubeFaceIndex];
  15007. }
  15008. if (framebuffer) {
  15009. var restore = false;
  15010. if (framebuffer !== _currentFramebuffer) {
  15011. _gl.bindFramebuffer(36160, framebuffer);
  15012. restore = true;
  15013. }
  15014. try {
  15015. var texture = renderTarget.texture;
  15016. var textureFormat = texture.format;
  15017. var textureType = texture.type;
  15018. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15019. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15020. return;
  15021. }
  15022. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15023. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.get('OES_texture_float') || extensions.get('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15024. !(textureType === HalfFloatType && (capabilities.isWebGL2 ? extensions.get('EXT_color_buffer_float') : extensions.get('EXT_color_buffer_half_float')))) {
  15025. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15026. return;
  15027. }
  15028. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15029. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15030. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15031. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15032. }
  15033. } else {
  15034. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15035. }
  15036. } finally {
  15037. if (restore) {
  15038. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15039. }
  15040. }
  15041. }
  15042. };
  15043. this.copyFramebufferToTexture = function (position, texture, level) {
  15044. if (level === undefined) level = 0;
  15045. var levelScale = Math.pow(2, -level);
  15046. var width = Math.floor(texture.image.width * levelScale);
  15047. var height = Math.floor(texture.image.height * levelScale);
  15048. var glFormat = utils.convert(texture.format);
  15049. textures.setTexture2D(texture, 0);
  15050. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15051. state.unbindTexture();
  15052. };
  15053. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15054. if (level === undefined) level = 0;
  15055. var width = srcTexture.image.width;
  15056. var height = srcTexture.image.height;
  15057. var glFormat = utils.convert(dstTexture.format);
  15058. var glType = utils.convert(dstTexture.type);
  15059. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15060. // parameters, make sure they are correct for the dstTexture
  15061. _gl.pixelStorei(37440, dstTexture.flipY);
  15062. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15063. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15064. if (srcTexture.isDataTexture) {
  15065. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15066. } else {
  15067. if (srcTexture.isCompressedTexture) {
  15068. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15069. } else {
  15070. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15071. }
  15072. } // Generate mipmaps only when copying level 0
  15073. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15074. state.unbindTexture();
  15075. };
  15076. this.initTexture = function (texture) {
  15077. textures.setTexture2D(texture, 0);
  15078. state.unbindTexture();
  15079. };
  15080. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15081. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15082. detail: this
  15083. })); // eslint-disable-line no-undef
  15084. }
  15085. }
  15086. function WebGL1Renderer(parameters) {
  15087. WebGLRenderer.call(this, parameters);
  15088. }
  15089. WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
  15090. constructor: WebGL1Renderer,
  15091. isWebGL1Renderer: true
  15092. });
  15093. var FogExp2 = /*#__PURE__*/function () {
  15094. function FogExp2(color, density) {
  15095. Object.defineProperty(this, 'isFogExp2', {
  15096. value: true
  15097. });
  15098. this.name = '';
  15099. this.color = new Color(color);
  15100. this.density = density !== undefined ? density : 0.00025;
  15101. }
  15102. var _proto = FogExp2.prototype;
  15103. _proto.clone = function clone() {
  15104. return new FogExp2(this.color, this.density);
  15105. };
  15106. _proto.toJSON = function toJSON()
  15107. /* meta */
  15108. {
  15109. return {
  15110. type: 'FogExp2',
  15111. color: this.color.getHex(),
  15112. density: this.density
  15113. };
  15114. };
  15115. return FogExp2;
  15116. }();
  15117. var Fog = /*#__PURE__*/function () {
  15118. function Fog(color, near, far) {
  15119. Object.defineProperty(this, 'isFog', {
  15120. value: true
  15121. });
  15122. this.name = '';
  15123. this.color = new Color(color);
  15124. this.near = near !== undefined ? near : 1;
  15125. this.far = far !== undefined ? far : 1000;
  15126. }
  15127. var _proto = Fog.prototype;
  15128. _proto.clone = function clone() {
  15129. return new Fog(this.color, this.near, this.far);
  15130. };
  15131. _proto.toJSON = function toJSON()
  15132. /* meta */
  15133. {
  15134. return {
  15135. type: 'Fog',
  15136. color: this.color.getHex(),
  15137. near: this.near,
  15138. far: this.far
  15139. };
  15140. };
  15141. return Fog;
  15142. }();
  15143. var Scene = /*#__PURE__*/function (_Object3D) {
  15144. _inheritsLoose(Scene, _Object3D);
  15145. function Scene() {
  15146. var _this;
  15147. _this = _Object3D.call(this) || this;
  15148. Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
  15149. value: true
  15150. });
  15151. _this.type = 'Scene';
  15152. _this.background = null;
  15153. _this.environment = null;
  15154. _this.fog = null;
  15155. _this.overrideMaterial = null;
  15156. _this.autoUpdate = true; // checked by the renderer
  15157. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15158. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15159. detail: _assertThisInitialized(_this)
  15160. })); // eslint-disable-line no-undef
  15161. }
  15162. return _this;
  15163. }
  15164. var _proto = Scene.prototype;
  15165. _proto.copy = function copy(source, recursive) {
  15166. _Object3D.prototype.copy.call(this, source, recursive);
  15167. if (source.background !== null) this.background = source.background.clone();
  15168. if (source.environment !== null) this.environment = source.environment.clone();
  15169. if (source.fog !== null) this.fog = source.fog.clone();
  15170. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  15171. this.autoUpdate = source.autoUpdate;
  15172. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15173. return this;
  15174. };
  15175. _proto.toJSON = function toJSON(meta) {
  15176. var data = _Object3D.prototype.toJSON.call(this, meta);
  15177. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  15178. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  15179. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  15180. return data;
  15181. };
  15182. return Scene;
  15183. }(Object3D);
  15184. function InterleavedBuffer(array, stride) {
  15185. this.array = array;
  15186. this.stride = stride;
  15187. this.count = array !== undefined ? array.length / stride : 0;
  15188. this.usage = StaticDrawUsage;
  15189. this.updateRange = {
  15190. offset: 0,
  15191. count: -1
  15192. };
  15193. this.version = 0;
  15194. this.uuid = MathUtils.generateUUID();
  15195. }
  15196. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  15197. set: function set(value) {
  15198. if (value === true) this.version++;
  15199. }
  15200. });
  15201. Object.assign(InterleavedBuffer.prototype, {
  15202. isInterleavedBuffer: true,
  15203. onUploadCallback: function onUploadCallback() {},
  15204. setUsage: function setUsage(value) {
  15205. this.usage = value;
  15206. return this;
  15207. },
  15208. copy: function copy(source) {
  15209. this.array = new source.array.constructor(source.array);
  15210. this.count = source.count;
  15211. this.stride = source.stride;
  15212. this.usage = source.usage;
  15213. return this;
  15214. },
  15215. copyAt: function copyAt(index1, attribute, index2) {
  15216. index1 *= this.stride;
  15217. index2 *= attribute.stride;
  15218. for (var i = 0, l = this.stride; i < l; i++) {
  15219. this.array[index1 + i] = attribute.array[index2 + i];
  15220. }
  15221. return this;
  15222. },
  15223. set: function set(value, offset) {
  15224. if (offset === undefined) offset = 0;
  15225. this.array.set(value, offset);
  15226. return this;
  15227. },
  15228. clone: function clone(data) {
  15229. if (data.arrayBuffers === undefined) {
  15230. data.arrayBuffers = {};
  15231. }
  15232. if (this.array.buffer._uuid === undefined) {
  15233. this.array.buffer._uuid = MathUtils.generateUUID();
  15234. }
  15235. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15236. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  15237. }
  15238. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  15239. var ib = new InterleavedBuffer(array, this.stride);
  15240. ib.setUsage(this.usage);
  15241. return ib;
  15242. },
  15243. onUpload: function onUpload(callback) {
  15244. this.onUploadCallback = callback;
  15245. return this;
  15246. },
  15247. toJSON: function toJSON(data) {
  15248. if (data.arrayBuffers === undefined) {
  15249. data.arrayBuffers = {};
  15250. } // generate UUID for array buffer if necessary
  15251. if (this.array.buffer._uuid === undefined) {
  15252. this.array.buffer._uuid = MathUtils.generateUUID();
  15253. }
  15254. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15255. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  15256. } //
  15257. return {
  15258. uuid: this.uuid,
  15259. buffer: this.array.buffer._uuid,
  15260. type: this.array.constructor.name,
  15261. stride: this.stride
  15262. };
  15263. }
  15264. });
  15265. var _vector$6 = new Vector3();
  15266. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  15267. this.name = '';
  15268. this.data = interleavedBuffer;
  15269. this.itemSize = itemSize;
  15270. this.offset = offset;
  15271. this.normalized = normalized === true;
  15272. }
  15273. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  15274. count: {
  15275. get: function get() {
  15276. return this.data.count;
  15277. }
  15278. },
  15279. array: {
  15280. get: function get() {
  15281. return this.data.array;
  15282. }
  15283. },
  15284. needsUpdate: {
  15285. set: function set(value) {
  15286. this.data.needsUpdate = value;
  15287. }
  15288. }
  15289. });
  15290. Object.assign(InterleavedBufferAttribute.prototype, {
  15291. isInterleavedBufferAttribute: true,
  15292. applyMatrix4: function applyMatrix4(m) {
  15293. for (var i = 0, l = this.data.count; i < l; i++) {
  15294. _vector$6.x = this.getX(i);
  15295. _vector$6.y = this.getY(i);
  15296. _vector$6.z = this.getZ(i);
  15297. _vector$6.applyMatrix4(m);
  15298. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  15299. }
  15300. return this;
  15301. },
  15302. setX: function setX(index, x) {
  15303. this.data.array[index * this.data.stride + this.offset] = x;
  15304. return this;
  15305. },
  15306. setY: function setY(index, y) {
  15307. this.data.array[index * this.data.stride + this.offset + 1] = y;
  15308. return this;
  15309. },
  15310. setZ: function setZ(index, z) {
  15311. this.data.array[index * this.data.stride + this.offset + 2] = z;
  15312. return this;
  15313. },
  15314. setW: function setW(index, w) {
  15315. this.data.array[index * this.data.stride + this.offset + 3] = w;
  15316. return this;
  15317. },
  15318. getX: function getX(index) {
  15319. return this.data.array[index * this.data.stride + this.offset];
  15320. },
  15321. getY: function getY(index) {
  15322. return this.data.array[index * this.data.stride + this.offset + 1];
  15323. },
  15324. getZ: function getZ(index) {
  15325. return this.data.array[index * this.data.stride + this.offset + 2];
  15326. },
  15327. getW: function getW(index) {
  15328. return this.data.array[index * this.data.stride + this.offset + 3];
  15329. },
  15330. setXY: function setXY(index, x, y) {
  15331. index = index * this.data.stride + this.offset;
  15332. this.data.array[index + 0] = x;
  15333. this.data.array[index + 1] = y;
  15334. return this;
  15335. },
  15336. setXYZ: function setXYZ(index, x, y, z) {
  15337. index = index * this.data.stride + this.offset;
  15338. this.data.array[index + 0] = x;
  15339. this.data.array[index + 1] = y;
  15340. this.data.array[index + 2] = z;
  15341. return this;
  15342. },
  15343. setXYZW: function setXYZW(index, x, y, z, w) {
  15344. index = index * this.data.stride + this.offset;
  15345. this.data.array[index + 0] = x;
  15346. this.data.array[index + 1] = y;
  15347. this.data.array[index + 2] = z;
  15348. this.data.array[index + 3] = w;
  15349. return this;
  15350. },
  15351. clone: function clone(data) {
  15352. if (data === undefined) {
  15353. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  15354. var array = [];
  15355. for (var i = 0; i < this.count; i++) {
  15356. var index = i * this.data.stride + this.offset;
  15357. for (var j = 0; j < this.itemSize; j++) {
  15358. array.push(this.data.array[index + j]);
  15359. }
  15360. }
  15361. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  15362. } else {
  15363. if (data.interleavedBuffers === undefined) {
  15364. data.interleavedBuffers = {};
  15365. }
  15366. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15367. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  15368. }
  15369. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  15370. }
  15371. },
  15372. toJSON: function toJSON(data) {
  15373. if (data === undefined) {
  15374. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  15375. var array = [];
  15376. for (var i = 0; i < this.count; i++) {
  15377. var index = i * this.data.stride + this.offset;
  15378. for (var j = 0; j < this.itemSize; j++) {
  15379. array.push(this.data.array[index + j]);
  15380. }
  15381. } // deinterleave data and save it as an ordinary buffer attribute for now
  15382. return {
  15383. itemSize: this.itemSize,
  15384. type: this.array.constructor.name,
  15385. array: array,
  15386. normalized: this.normalized
  15387. };
  15388. } else {
  15389. // save as true interlaved attribtue
  15390. if (data.interleavedBuffers === undefined) {
  15391. data.interleavedBuffers = {};
  15392. }
  15393. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15394. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  15395. }
  15396. return {
  15397. isInterleavedBufferAttribute: true,
  15398. itemSize: this.itemSize,
  15399. data: this.data.uuid,
  15400. offset: this.offset,
  15401. normalized: this.normalized
  15402. };
  15403. }
  15404. }
  15405. });
  15406. /**
  15407. * parameters = {
  15408. * color: <hex>,
  15409. * map: new THREE.Texture( <Image> ),
  15410. * alphaMap: new THREE.Texture( <Image> ),
  15411. * rotation: <float>,
  15412. * sizeAttenuation: <bool>
  15413. * }
  15414. */
  15415. function SpriteMaterial(parameters) {
  15416. Material.call(this);
  15417. this.type = 'SpriteMaterial';
  15418. this.color = new Color(0xffffff);
  15419. this.map = null;
  15420. this.alphaMap = null;
  15421. this.rotation = 0;
  15422. this.sizeAttenuation = true;
  15423. this.transparent = true;
  15424. this.setValues(parameters);
  15425. }
  15426. SpriteMaterial.prototype = Object.create(Material.prototype);
  15427. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15428. SpriteMaterial.prototype.isSpriteMaterial = true;
  15429. SpriteMaterial.prototype.copy = function (source) {
  15430. Material.prototype.copy.call(this, source);
  15431. this.color.copy(source.color);
  15432. this.map = source.map;
  15433. this.alphaMap = source.alphaMap;
  15434. this.rotation = source.rotation;
  15435. this.sizeAttenuation = source.sizeAttenuation;
  15436. return this;
  15437. };
  15438. var _geometry;
  15439. var _intersectPoint = new Vector3();
  15440. var _worldScale = new Vector3();
  15441. var _mvPosition = new Vector3();
  15442. var _alignedPosition = new Vector2();
  15443. var _rotatedPosition = new Vector2();
  15444. var _viewWorldMatrix = new Matrix4();
  15445. var _vA$1 = new Vector3();
  15446. var _vB$1 = new Vector3();
  15447. var _vC$1 = new Vector3();
  15448. var _uvA$1 = new Vector2();
  15449. var _uvB$1 = new Vector2();
  15450. var _uvC$1 = new Vector2();
  15451. function Sprite(material) {
  15452. Object3D.call(this);
  15453. this.type = 'Sprite';
  15454. if (_geometry === undefined) {
  15455. _geometry = new BufferGeometry();
  15456. 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]);
  15457. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  15458. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  15459. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  15460. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  15461. }
  15462. this.geometry = _geometry;
  15463. this.material = material !== undefined ? material : new SpriteMaterial();
  15464. this.center = new Vector2(0.5, 0.5);
  15465. }
  15466. Sprite.prototype = Object.assign(Object.create(Object3D.prototype), {
  15467. constructor: Sprite,
  15468. isSprite: true,
  15469. raycast: function raycast(raycaster, intersects) {
  15470. if (raycaster.camera === null) {
  15471. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  15472. }
  15473. _worldScale.setFromMatrixScale(this.matrixWorld);
  15474. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  15475. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  15476. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  15477. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  15478. _worldScale.multiplyScalar(-_mvPosition.z);
  15479. }
  15480. var rotation = this.material.rotation;
  15481. var sin, cos;
  15482. if (rotation !== 0) {
  15483. cos = Math.cos(rotation);
  15484. sin = Math.sin(rotation);
  15485. }
  15486. var center = this.center;
  15487. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15488. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15489. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15490. _uvA$1.set(0, 0);
  15491. _uvB$1.set(1, 0);
  15492. _uvC$1.set(1, 1); // check first triangle
  15493. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  15494. if (intersect === null) {
  15495. // check second triangle
  15496. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15497. _uvB$1.set(0, 1);
  15498. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  15499. if (intersect === null) {
  15500. return;
  15501. }
  15502. }
  15503. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  15504. if (distance < raycaster.near || distance > raycaster.far) return;
  15505. intersects.push({
  15506. distance: distance,
  15507. point: _intersectPoint.clone(),
  15508. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  15509. face: null,
  15510. object: this
  15511. });
  15512. },
  15513. copy: function copy(source) {
  15514. Object3D.prototype.copy.call(this, source);
  15515. if (source.center !== undefined) this.center.copy(source.center);
  15516. this.material = source.material;
  15517. return this;
  15518. }
  15519. });
  15520. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  15521. // compute position in camera space
  15522. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  15523. if (sin !== undefined) {
  15524. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  15525. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  15526. } else {
  15527. _rotatedPosition.copy(_alignedPosition);
  15528. }
  15529. vertexPosition.copy(mvPosition);
  15530. vertexPosition.x += _rotatedPosition.x;
  15531. vertexPosition.y += _rotatedPosition.y; // transform to world space
  15532. vertexPosition.applyMatrix4(_viewWorldMatrix);
  15533. }
  15534. var _v1$4 = new Vector3();
  15535. var _v2$2 = new Vector3();
  15536. function LOD() {
  15537. Object3D.call(this);
  15538. this._currentLevel = 0;
  15539. this.type = 'LOD';
  15540. Object.defineProperties(this, {
  15541. levels: {
  15542. enumerable: true,
  15543. value: []
  15544. }
  15545. });
  15546. this.autoUpdate = true;
  15547. }
  15548. LOD.prototype = Object.assign(Object.create(Object3D.prototype), {
  15549. constructor: LOD,
  15550. isLOD: true,
  15551. copy: function copy(source) {
  15552. Object3D.prototype.copy.call(this, source, false);
  15553. var levels = source.levels;
  15554. for (var i = 0, l = levels.length; i < l; i++) {
  15555. var level = levels[i];
  15556. this.addLevel(level.object.clone(), level.distance);
  15557. }
  15558. this.autoUpdate = source.autoUpdate;
  15559. return this;
  15560. },
  15561. addLevel: function addLevel(object, distance) {
  15562. if (distance === undefined) distance = 0;
  15563. distance = Math.abs(distance);
  15564. var levels = this.levels;
  15565. var l;
  15566. for (l = 0; l < levels.length; l++) {
  15567. if (distance < levels[l].distance) {
  15568. break;
  15569. }
  15570. }
  15571. levels.splice(l, 0, {
  15572. distance: distance,
  15573. object: object
  15574. });
  15575. this.add(object);
  15576. return this;
  15577. },
  15578. getCurrentLevel: function getCurrentLevel() {
  15579. return this._currentLevel;
  15580. },
  15581. getObjectForDistance: function getObjectForDistance(distance) {
  15582. var levels = this.levels;
  15583. if (levels.length > 0) {
  15584. var i, l;
  15585. for (i = 1, l = levels.length; i < l; i++) {
  15586. if (distance < levels[i].distance) {
  15587. break;
  15588. }
  15589. }
  15590. return levels[i - 1].object;
  15591. }
  15592. return null;
  15593. },
  15594. raycast: function raycast(raycaster, intersects) {
  15595. var levels = this.levels;
  15596. if (levels.length > 0) {
  15597. _v1$4.setFromMatrixPosition(this.matrixWorld);
  15598. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  15599. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  15600. }
  15601. },
  15602. update: function update(camera) {
  15603. var levels = this.levels;
  15604. if (levels.length > 1) {
  15605. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  15606. _v2$2.setFromMatrixPosition(this.matrixWorld);
  15607. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  15608. levels[0].object.visible = true;
  15609. var i, l;
  15610. for (i = 1, l = levels.length; i < l; i++) {
  15611. if (distance >= levels[i].distance) {
  15612. levels[i - 1].object.visible = false;
  15613. levels[i].object.visible = true;
  15614. } else {
  15615. break;
  15616. }
  15617. }
  15618. this._currentLevel = i - 1;
  15619. for (; i < l; i++) {
  15620. levels[i].object.visible = false;
  15621. }
  15622. }
  15623. },
  15624. toJSON: function toJSON(meta) {
  15625. var data = Object3D.prototype.toJSON.call(this, meta);
  15626. if (this.autoUpdate === false) data.object.autoUpdate = false;
  15627. data.object.levels = [];
  15628. var levels = this.levels;
  15629. for (var i = 0, l = levels.length; i < l; i++) {
  15630. var level = levels[i];
  15631. data.object.levels.push({
  15632. object: level.object.uuid,
  15633. distance: level.distance
  15634. });
  15635. }
  15636. return data;
  15637. }
  15638. });
  15639. function SkinnedMesh(geometry, material) {
  15640. if (geometry && geometry.isGeometry) {
  15641. console.error('THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  15642. }
  15643. Mesh.call(this, geometry, material);
  15644. this.type = 'SkinnedMesh';
  15645. this.bindMode = 'attached';
  15646. this.bindMatrix = new Matrix4();
  15647. this.bindMatrixInverse = new Matrix4();
  15648. }
  15649. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  15650. constructor: SkinnedMesh,
  15651. isSkinnedMesh: true,
  15652. copy: function copy(source) {
  15653. Mesh.prototype.copy.call(this, source);
  15654. this.bindMode = source.bindMode;
  15655. this.bindMatrix.copy(source.bindMatrix);
  15656. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  15657. this.skeleton = source.skeleton;
  15658. return this;
  15659. },
  15660. bind: function bind(skeleton, bindMatrix) {
  15661. this.skeleton = skeleton;
  15662. if (bindMatrix === undefined) {
  15663. this.updateMatrixWorld(true);
  15664. this.skeleton.calculateInverses();
  15665. bindMatrix = this.matrixWorld;
  15666. }
  15667. this.bindMatrix.copy(bindMatrix);
  15668. this.bindMatrixInverse.getInverse(bindMatrix);
  15669. },
  15670. pose: function pose() {
  15671. this.skeleton.pose();
  15672. },
  15673. normalizeSkinWeights: function normalizeSkinWeights() {
  15674. var vector = new Vector4();
  15675. var skinWeight = this.geometry.attributes.skinWeight;
  15676. for (var i = 0, l = skinWeight.count; i < l; i++) {
  15677. vector.x = skinWeight.getX(i);
  15678. vector.y = skinWeight.getY(i);
  15679. vector.z = skinWeight.getZ(i);
  15680. vector.w = skinWeight.getW(i);
  15681. var scale = 1.0 / vector.manhattanLength();
  15682. if (scale !== Infinity) {
  15683. vector.multiplyScalar(scale);
  15684. } else {
  15685. vector.set(1, 0, 0, 0); // do something reasonable
  15686. }
  15687. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  15688. }
  15689. },
  15690. updateMatrixWorld: function updateMatrixWorld(force) {
  15691. Mesh.prototype.updateMatrixWorld.call(this, force);
  15692. if (this.bindMode === 'attached') {
  15693. this.bindMatrixInverse.getInverse(this.matrixWorld);
  15694. } else if (this.bindMode === 'detached') {
  15695. this.bindMatrixInverse.getInverse(this.bindMatrix);
  15696. } else {
  15697. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  15698. }
  15699. },
  15700. boneTransform: function () {
  15701. var basePosition = new Vector3();
  15702. var skinIndex = new Vector4();
  15703. var skinWeight = new Vector4();
  15704. var vector = new Vector3();
  15705. var matrix = new Matrix4();
  15706. return function (index, target) {
  15707. var skeleton = this.skeleton;
  15708. var geometry = this.geometry;
  15709. skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  15710. skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  15711. basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  15712. target.set(0, 0, 0);
  15713. for (var i = 0; i < 4; i++) {
  15714. var weight = skinWeight.getComponent(i);
  15715. if (weight !== 0) {
  15716. var boneIndex = skinIndex.getComponent(i);
  15717. matrix.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  15718. target.addScaledVector(vector.copy(basePosition).applyMatrix4(matrix), weight);
  15719. }
  15720. }
  15721. return target.applyMatrix4(this.bindMatrixInverse);
  15722. };
  15723. }()
  15724. });
  15725. var _offsetMatrix = new Matrix4();
  15726. var _identityMatrix = new Matrix4();
  15727. function Skeleton(bones, boneInverses) {
  15728. // copy the bone array
  15729. bones = bones || [];
  15730. this.bones = bones.slice(0);
  15731. this.boneMatrices = new Float32Array(this.bones.length * 16);
  15732. this.frame = -1; // use the supplied bone inverses or calculate the inverses
  15733. if (boneInverses === undefined) {
  15734. this.calculateInverses();
  15735. } else {
  15736. if (this.bones.length === boneInverses.length) {
  15737. this.boneInverses = boneInverses.slice(0);
  15738. } else {
  15739. console.warn('THREE.Skeleton boneInverses is the wrong length.');
  15740. this.boneInverses = [];
  15741. for (var i = 0, il = this.bones.length; i < il; i++) {
  15742. this.boneInverses.push(new Matrix4());
  15743. }
  15744. }
  15745. }
  15746. }
  15747. Object.assign(Skeleton.prototype, {
  15748. calculateInverses: function calculateInverses() {
  15749. this.boneInverses = [];
  15750. for (var i = 0, il = this.bones.length; i < il; i++) {
  15751. var inverse = new Matrix4();
  15752. if (this.bones[i]) {
  15753. inverse.getInverse(this.bones[i].matrixWorld);
  15754. }
  15755. this.boneInverses.push(inverse);
  15756. }
  15757. },
  15758. pose: function pose() {
  15759. // recover the bind-time world matrices
  15760. for (var i = 0, il = this.bones.length; i < il; i++) {
  15761. var bone = this.bones[i];
  15762. if (bone) {
  15763. bone.matrixWorld.getInverse(this.boneInverses[i]);
  15764. }
  15765. } // compute the local matrices, positions, rotations and scales
  15766. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  15767. var _bone = this.bones[_i];
  15768. if (_bone) {
  15769. if (_bone.parent && _bone.parent.isBone) {
  15770. _bone.matrix.getInverse(_bone.parent.matrixWorld);
  15771. _bone.matrix.multiply(_bone.matrixWorld);
  15772. } else {
  15773. _bone.matrix.copy(_bone.matrixWorld);
  15774. }
  15775. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  15776. }
  15777. }
  15778. },
  15779. update: function update() {
  15780. var bones = this.bones;
  15781. var boneInverses = this.boneInverses;
  15782. var boneMatrices = this.boneMatrices;
  15783. var boneTexture = this.boneTexture; // flatten bone matrices to array
  15784. for (var i = 0, il = bones.length; i < il; i++) {
  15785. // compute the offset between the current and the original transform
  15786. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  15787. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  15788. _offsetMatrix.toArray(boneMatrices, i * 16);
  15789. }
  15790. if (boneTexture !== undefined) {
  15791. boneTexture.needsUpdate = true;
  15792. }
  15793. },
  15794. clone: function clone() {
  15795. return new Skeleton(this.bones, this.boneInverses);
  15796. },
  15797. getBoneByName: function getBoneByName(name) {
  15798. for (var i = 0, il = this.bones.length; i < il; i++) {
  15799. var bone = this.bones[i];
  15800. if (bone.name === name) {
  15801. return bone;
  15802. }
  15803. }
  15804. return undefined;
  15805. },
  15806. dispose: function dispose() {
  15807. if (this.boneTexture) {
  15808. this.boneTexture.dispose();
  15809. this.boneTexture = undefined;
  15810. }
  15811. }
  15812. });
  15813. function Bone() {
  15814. Object3D.call(this);
  15815. this.type = 'Bone';
  15816. }
  15817. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  15818. constructor: Bone,
  15819. isBone: true
  15820. });
  15821. var _instanceLocalMatrix = new Matrix4();
  15822. var _instanceWorldMatrix = new Matrix4();
  15823. var _instanceIntersects = [];
  15824. var _mesh = new Mesh();
  15825. function InstancedMesh(geometry, material, count) {
  15826. Mesh.call(this, geometry, material);
  15827. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  15828. this.instanceColor = null;
  15829. this.count = count;
  15830. this.frustumCulled = false;
  15831. }
  15832. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  15833. constructor: InstancedMesh,
  15834. isInstancedMesh: true,
  15835. copy: function copy(source) {
  15836. Mesh.prototype.copy.call(this, source);
  15837. this.instanceMatrix.copy(source.instanceMatrix);
  15838. this.count = source.count;
  15839. return this;
  15840. },
  15841. setColorAt: function setColorAt(index, color) {
  15842. if (this.instanceColor === null) {
  15843. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  15844. }
  15845. color.toArray(this.instanceColor.array, index * 3);
  15846. },
  15847. getMatrixAt: function getMatrixAt(index, matrix) {
  15848. matrix.fromArray(this.instanceMatrix.array, index * 16);
  15849. },
  15850. raycast: function raycast(raycaster, intersects) {
  15851. var matrixWorld = this.matrixWorld;
  15852. var raycastTimes = this.count;
  15853. _mesh.geometry = this.geometry;
  15854. _mesh.material = this.material;
  15855. if (_mesh.material === undefined) return;
  15856. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  15857. // calculate the world matrix for each instance
  15858. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  15859. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  15860. _mesh.matrixWorld = _instanceWorldMatrix;
  15861. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  15862. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  15863. var intersect = _instanceIntersects[i];
  15864. intersect.instanceId = instanceId;
  15865. intersect.object = this;
  15866. intersects.push(intersect);
  15867. }
  15868. _instanceIntersects.length = 0;
  15869. }
  15870. },
  15871. setMatrixAt: function setMatrixAt(index, matrix) {
  15872. matrix.toArray(this.instanceMatrix.array, index * 16);
  15873. },
  15874. updateMorphTargets: function updateMorphTargets() {}
  15875. });
  15876. /**
  15877. * parameters = {
  15878. * color: <hex>,
  15879. * opacity: <float>,
  15880. *
  15881. * linewidth: <float>,
  15882. * linecap: "round",
  15883. * linejoin: "round"
  15884. * }
  15885. */
  15886. function LineBasicMaterial(parameters) {
  15887. Material.call(this);
  15888. this.type = 'LineBasicMaterial';
  15889. this.color = new Color(0xffffff);
  15890. this.linewidth = 1;
  15891. this.linecap = 'round';
  15892. this.linejoin = 'round';
  15893. this.morphTargets = false;
  15894. this.setValues(parameters);
  15895. }
  15896. LineBasicMaterial.prototype = Object.create(Material.prototype);
  15897. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  15898. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15899. LineBasicMaterial.prototype.copy = function (source) {
  15900. Material.prototype.copy.call(this, source);
  15901. this.color.copy(source.color);
  15902. this.linewidth = source.linewidth;
  15903. this.linecap = source.linecap;
  15904. this.linejoin = source.linejoin;
  15905. this.morphTargets = source.morphTargets;
  15906. return this;
  15907. };
  15908. var _start = new Vector3();
  15909. var _end = new Vector3();
  15910. var _inverseMatrix$1 = new Matrix4();
  15911. var _ray$1 = new Ray();
  15912. var _sphere$2 = new Sphere();
  15913. function Line(geometry, material, mode) {
  15914. if (mode === 1) {
  15915. console.error('THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.');
  15916. }
  15917. Object3D.call(this);
  15918. this.type = 'Line';
  15919. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15920. this.material = material !== undefined ? material : new LineBasicMaterial();
  15921. this.updateMorphTargets();
  15922. }
  15923. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  15924. constructor: Line,
  15925. isLine: true,
  15926. copy: function copy(source) {
  15927. Object3D.prototype.copy.call(this, source);
  15928. this.material = source.material;
  15929. this.geometry = source.geometry;
  15930. return this;
  15931. },
  15932. computeLineDistances: function computeLineDistances() {
  15933. var geometry = this.geometry;
  15934. if (geometry.isBufferGeometry) {
  15935. // we assume non-indexed geometry
  15936. if (geometry.index === null) {
  15937. var positionAttribute = geometry.attributes.position;
  15938. var lineDistances = [0];
  15939. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  15940. _start.fromBufferAttribute(positionAttribute, i - 1);
  15941. _end.fromBufferAttribute(positionAttribute, i);
  15942. lineDistances[i] = lineDistances[i - 1];
  15943. lineDistances[i] += _start.distanceTo(_end);
  15944. }
  15945. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  15946. } else {
  15947. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  15948. }
  15949. } else if (geometry.isGeometry) {
  15950. var vertices = geometry.vertices;
  15951. var _lineDistances = geometry.lineDistances;
  15952. _lineDistances[0] = 0;
  15953. for (var _i = 1, _l = vertices.length; _i < _l; _i++) {
  15954. _lineDistances[_i] = _lineDistances[_i - 1];
  15955. _lineDistances[_i] += vertices[_i - 1].distanceTo(vertices[_i]);
  15956. }
  15957. }
  15958. return this;
  15959. },
  15960. raycast: function raycast(raycaster, intersects) {
  15961. var geometry = this.geometry;
  15962. var matrixWorld = this.matrixWorld;
  15963. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  15964. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  15965. _sphere$2.copy(geometry.boundingSphere);
  15966. _sphere$2.applyMatrix4(matrixWorld);
  15967. _sphere$2.radius += threshold;
  15968. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  15969. _inverseMatrix$1.getInverse(matrixWorld);
  15970. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  15971. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  15972. var localThresholdSq = localThreshold * localThreshold;
  15973. var vStart = new Vector3();
  15974. var vEnd = new Vector3();
  15975. var interSegment = new Vector3();
  15976. var interRay = new Vector3();
  15977. var step = this.isLineSegments ? 2 : 1;
  15978. if (geometry.isBufferGeometry) {
  15979. var index = geometry.index;
  15980. var attributes = geometry.attributes;
  15981. var positionAttribute = attributes.position;
  15982. if (index !== null) {
  15983. var indices = index.array;
  15984. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  15985. var a = indices[i];
  15986. var b = indices[i + 1];
  15987. vStart.fromBufferAttribute(positionAttribute, a);
  15988. vEnd.fromBufferAttribute(positionAttribute, b);
  15989. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  15990. if (distSq > localThresholdSq) continue;
  15991. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  15992. var distance = raycaster.ray.origin.distanceTo(interRay);
  15993. if (distance < raycaster.near || distance > raycaster.far) continue;
  15994. intersects.push({
  15995. distance: distance,
  15996. // What do we want? intersection point on the ray or on the segment??
  15997. // point: raycaster.ray.at( distance ),
  15998. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  15999. index: i,
  16000. face: null,
  16001. faceIndex: null,
  16002. object: this
  16003. });
  16004. }
  16005. } else {
  16006. for (var _i2 = 0, _l2 = positionAttribute.count - 1; _i2 < _l2; _i2 += step) {
  16007. vStart.fromBufferAttribute(positionAttribute, _i2);
  16008. vEnd.fromBufferAttribute(positionAttribute, _i2 + 1);
  16009. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16010. if (_distSq > localThresholdSq) continue;
  16011. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16012. var _distance = raycaster.ray.origin.distanceTo(interRay);
  16013. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  16014. intersects.push({
  16015. distance: _distance,
  16016. // What do we want? intersection point on the ray or on the segment??
  16017. // point: raycaster.ray.at( distance ),
  16018. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16019. index: _i2,
  16020. face: null,
  16021. faceIndex: null,
  16022. object: this
  16023. });
  16024. }
  16025. }
  16026. } else if (geometry.isGeometry) {
  16027. var vertices = geometry.vertices;
  16028. var nbVertices = vertices.length;
  16029. for (var _i3 = 0; _i3 < nbVertices - 1; _i3 += step) {
  16030. var _distSq2 = _ray$1.distanceSqToSegment(vertices[_i3], vertices[_i3 + 1], interRay, interSegment);
  16031. if (_distSq2 > localThresholdSq) continue;
  16032. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16033. var _distance2 = raycaster.ray.origin.distanceTo(interRay);
  16034. if (_distance2 < raycaster.near || _distance2 > raycaster.far) continue;
  16035. intersects.push({
  16036. distance: _distance2,
  16037. // What do we want? intersection point on the ray or on the segment??
  16038. // point: raycaster.ray.at( distance ),
  16039. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16040. index: _i3,
  16041. face: null,
  16042. faceIndex: null,
  16043. object: this
  16044. });
  16045. }
  16046. }
  16047. },
  16048. updateMorphTargets: function updateMorphTargets() {
  16049. var geometry = this.geometry;
  16050. if (geometry.isBufferGeometry) {
  16051. var morphAttributes = geometry.morphAttributes;
  16052. var keys = Object.keys(morphAttributes);
  16053. if (keys.length > 0) {
  16054. var morphAttribute = morphAttributes[keys[0]];
  16055. if (morphAttribute !== undefined) {
  16056. this.morphTargetInfluences = [];
  16057. this.morphTargetDictionary = {};
  16058. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16059. var name = morphAttribute[m].name || String(m);
  16060. this.morphTargetInfluences.push(0);
  16061. this.morphTargetDictionary[name] = m;
  16062. }
  16063. }
  16064. }
  16065. } else {
  16066. var morphTargets = geometry.morphTargets;
  16067. if (morphTargets !== undefined && morphTargets.length > 0) {
  16068. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16069. }
  16070. }
  16071. }
  16072. });
  16073. var _start$1 = new Vector3();
  16074. var _end$1 = new Vector3();
  16075. function LineSegments(geometry, material) {
  16076. Line.call(this, geometry, material);
  16077. this.type = 'LineSegments';
  16078. }
  16079. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  16080. constructor: LineSegments,
  16081. isLineSegments: true,
  16082. computeLineDistances: function computeLineDistances() {
  16083. var geometry = this.geometry;
  16084. if (geometry.isBufferGeometry) {
  16085. // we assume non-indexed geometry
  16086. if (geometry.index === null) {
  16087. var positionAttribute = geometry.attributes.position;
  16088. var lineDistances = [];
  16089. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  16090. _start$1.fromBufferAttribute(positionAttribute, i);
  16091. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  16092. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  16093. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  16094. }
  16095. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16096. } else {
  16097. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16098. }
  16099. } else if (geometry.isGeometry) {
  16100. var vertices = geometry.vertices;
  16101. var _lineDistances = geometry.lineDistances;
  16102. for (var _i = 0, _l = vertices.length; _i < _l; _i += 2) {
  16103. _start$1.copy(vertices[_i]);
  16104. _end$1.copy(vertices[_i + 1]);
  16105. _lineDistances[_i] = _i === 0 ? 0 : _lineDistances[_i - 1];
  16106. _lineDistances[_i + 1] = _lineDistances[_i] + _start$1.distanceTo(_end$1);
  16107. }
  16108. }
  16109. return this;
  16110. }
  16111. });
  16112. function LineLoop(geometry, material) {
  16113. Line.call(this, geometry, material);
  16114. this.type = 'LineLoop';
  16115. }
  16116. LineLoop.prototype = Object.assign(Object.create(Line.prototype), {
  16117. constructor: LineLoop,
  16118. isLineLoop: true
  16119. });
  16120. /**
  16121. * parameters = {
  16122. * color: <hex>,
  16123. * opacity: <float>,
  16124. * map: new THREE.Texture( <Image> ),
  16125. * alphaMap: new THREE.Texture( <Image> ),
  16126. *
  16127. * size: <float>,
  16128. * sizeAttenuation: <bool>
  16129. *
  16130. * morphTargets: <bool>
  16131. * }
  16132. */
  16133. function PointsMaterial(parameters) {
  16134. Material.call(this);
  16135. this.type = 'PointsMaterial';
  16136. this.color = new Color(0xffffff);
  16137. this.map = null;
  16138. this.alphaMap = null;
  16139. this.size = 1;
  16140. this.sizeAttenuation = true;
  16141. this.morphTargets = false;
  16142. this.setValues(parameters);
  16143. }
  16144. PointsMaterial.prototype = Object.create(Material.prototype);
  16145. PointsMaterial.prototype.constructor = PointsMaterial;
  16146. PointsMaterial.prototype.isPointsMaterial = true;
  16147. PointsMaterial.prototype.copy = function (source) {
  16148. Material.prototype.copy.call(this, source);
  16149. this.color.copy(source.color);
  16150. this.map = source.map;
  16151. this.alphaMap = source.alphaMap;
  16152. this.size = source.size;
  16153. this.sizeAttenuation = source.sizeAttenuation;
  16154. this.morphTargets = source.morphTargets;
  16155. return this;
  16156. };
  16157. var _inverseMatrix$2 = new Matrix4();
  16158. var _ray$2 = new Ray();
  16159. var _sphere$3 = new Sphere();
  16160. var _position$1 = new Vector3();
  16161. function Points(geometry, material) {
  16162. Object3D.call(this);
  16163. this.type = 'Points';
  16164. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16165. this.material = material !== undefined ? material : new PointsMaterial();
  16166. this.updateMorphTargets();
  16167. }
  16168. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  16169. constructor: Points,
  16170. isPoints: true,
  16171. copy: function copy(source) {
  16172. Object3D.prototype.copy.call(this, source);
  16173. this.material = source.material;
  16174. this.geometry = source.geometry;
  16175. return this;
  16176. },
  16177. raycast: function raycast(raycaster, intersects) {
  16178. var geometry = this.geometry;
  16179. var matrixWorld = this.matrixWorld;
  16180. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  16181. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16182. _sphere$3.copy(geometry.boundingSphere);
  16183. _sphere$3.applyMatrix4(matrixWorld);
  16184. _sphere$3.radius += threshold;
  16185. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  16186. _inverseMatrix$2.getInverse(matrixWorld);
  16187. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  16188. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16189. var localThresholdSq = localThreshold * localThreshold;
  16190. if (geometry.isBufferGeometry) {
  16191. var index = geometry.index;
  16192. var attributes = geometry.attributes;
  16193. var positionAttribute = attributes.position;
  16194. if (index !== null) {
  16195. var indices = index.array;
  16196. for (var i = 0, il = indices.length; i < il; i++) {
  16197. var a = indices[i];
  16198. _position$1.fromBufferAttribute(positionAttribute, a);
  16199. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16200. }
  16201. } else {
  16202. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  16203. _position$1.fromBufferAttribute(positionAttribute, _i);
  16204. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16205. }
  16206. }
  16207. } else {
  16208. var vertices = geometry.vertices;
  16209. for (var _i2 = 0, _l = vertices.length; _i2 < _l; _i2++) {
  16210. testPoint(vertices[_i2], _i2, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16211. }
  16212. }
  16213. },
  16214. updateMorphTargets: function updateMorphTargets() {
  16215. var geometry = this.geometry;
  16216. if (geometry.isBufferGeometry) {
  16217. var morphAttributes = geometry.morphAttributes;
  16218. var keys = Object.keys(morphAttributes);
  16219. if (keys.length > 0) {
  16220. var morphAttribute = morphAttributes[keys[0]];
  16221. if (morphAttribute !== undefined) {
  16222. this.morphTargetInfluences = [];
  16223. this.morphTargetDictionary = {};
  16224. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16225. var name = morphAttribute[m].name || String(m);
  16226. this.morphTargetInfluences.push(0);
  16227. this.morphTargetDictionary[name] = m;
  16228. }
  16229. }
  16230. }
  16231. } else {
  16232. var morphTargets = geometry.morphTargets;
  16233. if (morphTargets !== undefined && morphTargets.length > 0) {
  16234. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16235. }
  16236. }
  16237. }
  16238. });
  16239. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  16240. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  16241. if (rayPointDistanceSq < localThresholdSq) {
  16242. var intersectPoint = new Vector3();
  16243. _ray$2.closestPointToPoint(point, intersectPoint);
  16244. intersectPoint.applyMatrix4(matrixWorld);
  16245. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  16246. if (distance < raycaster.near || distance > raycaster.far) return;
  16247. intersects.push({
  16248. distance: distance,
  16249. distanceToRay: Math.sqrt(rayPointDistanceSq),
  16250. point: intersectPoint,
  16251. index: index,
  16252. face: null,
  16253. object: object
  16254. });
  16255. }
  16256. }
  16257. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16258. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16259. this.format = format !== undefined ? format : RGBFormat;
  16260. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16261. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16262. this.generateMipmaps = false;
  16263. var scope = this;
  16264. function updateVideo() {
  16265. scope.needsUpdate = true;
  16266. video.requestVideoFrameCallback(updateVideo);
  16267. }
  16268. if ('requestVideoFrameCallback' in video) {
  16269. video.requestVideoFrameCallback(updateVideo);
  16270. }
  16271. }
  16272. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  16273. constructor: VideoTexture,
  16274. isVideoTexture: true,
  16275. update: function update() {
  16276. var video = this.image;
  16277. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  16278. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  16279. this.needsUpdate = true;
  16280. }
  16281. }
  16282. });
  16283. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  16284. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  16285. this.image = {
  16286. width: width,
  16287. height: height
  16288. };
  16289. this.mipmaps = mipmaps; // no flipping for cube textures
  16290. // (also flipping doesn't work for compressed textures )
  16291. this.flipY = false; // can't generate mipmaps for compressed textures
  16292. // mips must be embedded in DDS files
  16293. this.generateMipmaps = false;
  16294. }
  16295. CompressedTexture.prototype = Object.create(Texture.prototype);
  16296. CompressedTexture.prototype.constructor = CompressedTexture;
  16297. CompressedTexture.prototype.isCompressedTexture = true;
  16298. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16299. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16300. this.needsUpdate = true;
  16301. }
  16302. CanvasTexture.prototype = Object.create(Texture.prototype);
  16303. CanvasTexture.prototype.constructor = CanvasTexture;
  16304. CanvasTexture.prototype.isCanvasTexture = true;
  16305. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  16306. format = format !== undefined ? format : DepthFormat;
  16307. if (format !== DepthFormat && format !== DepthStencilFormat) {
  16308. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  16309. }
  16310. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  16311. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  16312. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16313. this.image = {
  16314. width: width,
  16315. height: height
  16316. };
  16317. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16318. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16319. this.flipY = false;
  16320. this.generateMipmaps = false;
  16321. }
  16322. DepthTexture.prototype = Object.create(Texture.prototype);
  16323. DepthTexture.prototype.constructor = DepthTexture;
  16324. DepthTexture.prototype.isDepthTexture = true;
  16325. var _geometryId = 0; // Geometry uses even numbers as Id
  16326. var _m1$3 = new Matrix4();
  16327. var _obj$1 = new Object3D();
  16328. var _offset$1 = new Vector3();
  16329. function Geometry() {
  16330. Object.defineProperty(this, 'id', {
  16331. value: _geometryId += 2
  16332. });
  16333. this.uuid = MathUtils.generateUUID();
  16334. this.name = '';
  16335. this.type = 'Geometry';
  16336. this.vertices = [];
  16337. this.colors = [];
  16338. this.faces = [];
  16339. this.faceVertexUvs = [[]];
  16340. this.morphTargets = [];
  16341. this.morphNormals = [];
  16342. this.skinWeights = [];
  16343. this.skinIndices = [];
  16344. this.lineDistances = [];
  16345. this.boundingBox = null;
  16346. this.boundingSphere = null; // update flags
  16347. this.elementsNeedUpdate = false;
  16348. this.verticesNeedUpdate = false;
  16349. this.uvsNeedUpdate = false;
  16350. this.normalsNeedUpdate = false;
  16351. this.colorsNeedUpdate = false;
  16352. this.lineDistancesNeedUpdate = false;
  16353. this.groupsNeedUpdate = false;
  16354. }
  16355. Geometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  16356. constructor: Geometry,
  16357. isGeometry: true,
  16358. applyMatrix4: function applyMatrix4(matrix) {
  16359. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  16360. for (var i = 0, il = this.vertices.length; i < il; i++) {
  16361. var vertex = this.vertices[i];
  16362. vertex.applyMatrix4(matrix);
  16363. }
  16364. for (var _i = 0, _il = this.faces.length; _i < _il; _i++) {
  16365. var face = this.faces[_i];
  16366. face.normal.applyMatrix3(normalMatrix).normalize();
  16367. for (var j = 0, jl = face.vertexNormals.length; j < jl; j++) {
  16368. face.vertexNormals[j].applyMatrix3(normalMatrix).normalize();
  16369. }
  16370. }
  16371. if (this.boundingBox !== null) {
  16372. this.computeBoundingBox();
  16373. }
  16374. if (this.boundingSphere !== null) {
  16375. this.computeBoundingSphere();
  16376. }
  16377. this.verticesNeedUpdate = true;
  16378. this.normalsNeedUpdate = true;
  16379. return this;
  16380. },
  16381. rotateX: function rotateX(angle) {
  16382. // rotate geometry around world x-axis
  16383. _m1$3.makeRotationX(angle);
  16384. this.applyMatrix4(_m1$3);
  16385. return this;
  16386. },
  16387. rotateY: function rotateY(angle) {
  16388. // rotate geometry around world y-axis
  16389. _m1$3.makeRotationY(angle);
  16390. this.applyMatrix4(_m1$3);
  16391. return this;
  16392. },
  16393. rotateZ: function rotateZ(angle) {
  16394. // rotate geometry around world z-axis
  16395. _m1$3.makeRotationZ(angle);
  16396. this.applyMatrix4(_m1$3);
  16397. return this;
  16398. },
  16399. translate: function translate(x, y, z) {
  16400. // translate geometry
  16401. _m1$3.makeTranslation(x, y, z);
  16402. this.applyMatrix4(_m1$3);
  16403. return this;
  16404. },
  16405. scale: function scale(x, y, z) {
  16406. // scale geometry
  16407. _m1$3.makeScale(x, y, z);
  16408. this.applyMatrix4(_m1$3);
  16409. return this;
  16410. },
  16411. lookAt: function lookAt(vector) {
  16412. _obj$1.lookAt(vector);
  16413. _obj$1.updateMatrix();
  16414. this.applyMatrix4(_obj$1.matrix);
  16415. return this;
  16416. },
  16417. fromBufferGeometry: function fromBufferGeometry(geometry) {
  16418. var scope = this;
  16419. var index = geometry.index !== null ? geometry.index : undefined;
  16420. var attributes = geometry.attributes;
  16421. if (attributes.position === undefined) {
  16422. console.error('THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.');
  16423. return this;
  16424. }
  16425. var position = attributes.position;
  16426. var normal = attributes.normal;
  16427. var color = attributes.color;
  16428. var uv = attributes.uv;
  16429. var uv2 = attributes.uv2;
  16430. if (uv2 !== undefined) this.faceVertexUvs[1] = [];
  16431. for (var i = 0; i < position.count; i++) {
  16432. scope.vertices.push(new Vector3().fromBufferAttribute(position, i));
  16433. if (color !== undefined) {
  16434. scope.colors.push(new Color().fromBufferAttribute(color, i));
  16435. }
  16436. }
  16437. function addFace(a, b, c, materialIndex) {
  16438. var vertexColors = color === undefined ? [] : [scope.colors[a].clone(), scope.colors[b].clone(), scope.colors[c].clone()];
  16439. var vertexNormals = normal === undefined ? [] : [new Vector3().fromBufferAttribute(normal, a), new Vector3().fromBufferAttribute(normal, b), new Vector3().fromBufferAttribute(normal, c)];
  16440. var face = new Face3(a, b, c, vertexNormals, vertexColors, materialIndex);
  16441. scope.faces.push(face);
  16442. if (uv !== undefined) {
  16443. scope.faceVertexUvs[0].push([new Vector2().fromBufferAttribute(uv, a), new Vector2().fromBufferAttribute(uv, b), new Vector2().fromBufferAttribute(uv, c)]);
  16444. }
  16445. if (uv2 !== undefined) {
  16446. scope.faceVertexUvs[1].push([new Vector2().fromBufferAttribute(uv2, a), new Vector2().fromBufferAttribute(uv2, b), new Vector2().fromBufferAttribute(uv2, c)]);
  16447. }
  16448. }
  16449. var groups = geometry.groups;
  16450. if (groups.length > 0) {
  16451. for (var _i2 = 0; _i2 < groups.length; _i2++) {
  16452. var group = groups[_i2];
  16453. var start = group.start;
  16454. var count = group.count;
  16455. for (var j = start, jl = start + count; j < jl; j += 3) {
  16456. if (index !== undefined) {
  16457. addFace(index.getX(j), index.getX(j + 1), index.getX(j + 2), group.materialIndex);
  16458. } else {
  16459. addFace(j, j + 1, j + 2, group.materialIndex);
  16460. }
  16461. }
  16462. }
  16463. } else {
  16464. if (index !== undefined) {
  16465. for (var _i3 = 0; _i3 < index.count; _i3 += 3) {
  16466. addFace(index.getX(_i3), index.getX(_i3 + 1), index.getX(_i3 + 2));
  16467. }
  16468. } else {
  16469. for (var _i4 = 0; _i4 < position.count; _i4 += 3) {
  16470. addFace(_i4, _i4 + 1, _i4 + 2);
  16471. }
  16472. }
  16473. }
  16474. this.computeFaceNormals();
  16475. if (geometry.boundingBox !== null) {
  16476. this.boundingBox = geometry.boundingBox.clone();
  16477. }
  16478. if (geometry.boundingSphere !== null) {
  16479. this.boundingSphere = geometry.boundingSphere.clone();
  16480. }
  16481. return this;
  16482. },
  16483. center: function center() {
  16484. this.computeBoundingBox();
  16485. this.boundingBox.getCenter(_offset$1).negate();
  16486. this.translate(_offset$1.x, _offset$1.y, _offset$1.z);
  16487. return this;
  16488. },
  16489. normalize: function normalize() {
  16490. this.computeBoundingSphere();
  16491. var center = this.boundingSphere.center;
  16492. var radius = this.boundingSphere.radius;
  16493. var s = radius === 0 ? 1 : 1.0 / radius;
  16494. var matrix = new Matrix4();
  16495. matrix.set(s, 0, 0, -s * center.x, 0, s, 0, -s * center.y, 0, 0, s, -s * center.z, 0, 0, 0, 1);
  16496. this.applyMatrix4(matrix);
  16497. return this;
  16498. },
  16499. computeFaceNormals: function computeFaceNormals() {
  16500. var cb = new Vector3(),
  16501. ab = new Vector3();
  16502. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16503. var face = this.faces[f];
  16504. var vA = this.vertices[face.a];
  16505. var vB = this.vertices[face.b];
  16506. var vC = this.vertices[face.c];
  16507. cb.subVectors(vC, vB);
  16508. ab.subVectors(vA, vB);
  16509. cb.cross(ab);
  16510. cb.normalize();
  16511. face.normal.copy(cb);
  16512. }
  16513. },
  16514. computeVertexNormals: function computeVertexNormals(areaWeighted) {
  16515. if (areaWeighted === undefined) areaWeighted = true;
  16516. var vertices = new Array(this.vertices.length);
  16517. for (var v = 0, vl = this.vertices.length; v < vl; v++) {
  16518. vertices[v] = new Vector3();
  16519. }
  16520. if (areaWeighted) {
  16521. // vertex normals weighted by triangle areas
  16522. // http://www.iquilezles.org/www/articles/normals/normals.htm
  16523. var cb = new Vector3(),
  16524. ab = new Vector3();
  16525. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16526. var face = this.faces[f];
  16527. var vA = this.vertices[face.a];
  16528. var vB = this.vertices[face.b];
  16529. var vC = this.vertices[face.c];
  16530. cb.subVectors(vC, vB);
  16531. ab.subVectors(vA, vB);
  16532. cb.cross(ab);
  16533. vertices[face.a].add(cb);
  16534. vertices[face.b].add(cb);
  16535. vertices[face.c].add(cb);
  16536. }
  16537. } else {
  16538. this.computeFaceNormals();
  16539. for (var _f = 0, _fl = this.faces.length; _f < _fl; _f++) {
  16540. var _face = this.faces[_f];
  16541. vertices[_face.a].add(_face.normal);
  16542. vertices[_face.b].add(_face.normal);
  16543. vertices[_face.c].add(_face.normal);
  16544. }
  16545. }
  16546. for (var _v = 0, _vl = this.vertices.length; _v < _vl; _v++) {
  16547. vertices[_v].normalize();
  16548. }
  16549. for (var _f2 = 0, _fl2 = this.faces.length; _f2 < _fl2; _f2++) {
  16550. var _face2 = this.faces[_f2];
  16551. var vertexNormals = _face2.vertexNormals;
  16552. if (vertexNormals.length === 3) {
  16553. vertexNormals[0].copy(vertices[_face2.a]);
  16554. vertexNormals[1].copy(vertices[_face2.b]);
  16555. vertexNormals[2].copy(vertices[_face2.c]);
  16556. } else {
  16557. vertexNormals[0] = vertices[_face2.a].clone();
  16558. vertexNormals[1] = vertices[_face2.b].clone();
  16559. vertexNormals[2] = vertices[_face2.c].clone();
  16560. }
  16561. }
  16562. if (this.faces.length > 0) {
  16563. this.normalsNeedUpdate = true;
  16564. }
  16565. },
  16566. computeFlatVertexNormals: function computeFlatVertexNormals() {
  16567. this.computeFaceNormals();
  16568. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16569. var face = this.faces[f];
  16570. var vertexNormals = face.vertexNormals;
  16571. if (vertexNormals.length === 3) {
  16572. vertexNormals[0].copy(face.normal);
  16573. vertexNormals[1].copy(face.normal);
  16574. vertexNormals[2].copy(face.normal);
  16575. } else {
  16576. vertexNormals[0] = face.normal.clone();
  16577. vertexNormals[1] = face.normal.clone();
  16578. vertexNormals[2] = face.normal.clone();
  16579. }
  16580. }
  16581. if (this.faces.length > 0) {
  16582. this.normalsNeedUpdate = true;
  16583. }
  16584. },
  16585. computeMorphNormals: function computeMorphNormals() {
  16586. // save original normals
  16587. // - create temp variables on first access
  16588. // otherwise just copy (for faster repeated calls)
  16589. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16590. var face = this.faces[f];
  16591. if (!face.__originalFaceNormal) {
  16592. face.__originalFaceNormal = face.normal.clone();
  16593. } else {
  16594. face.__originalFaceNormal.copy(face.normal);
  16595. }
  16596. if (!face.__originalVertexNormals) face.__originalVertexNormals = [];
  16597. for (var i = 0, il = face.vertexNormals.length; i < il; i++) {
  16598. if (!face.__originalVertexNormals[i]) {
  16599. face.__originalVertexNormals[i] = face.vertexNormals[i].clone();
  16600. } else {
  16601. face.__originalVertexNormals[i].copy(face.vertexNormals[i]);
  16602. }
  16603. }
  16604. } // use temp geometry to compute face and vertex normals for each morph
  16605. var tmpGeo = new Geometry();
  16606. tmpGeo.faces = this.faces;
  16607. for (var _i5 = 0, _il2 = this.morphTargets.length; _i5 < _il2; _i5++) {
  16608. // create on first access
  16609. if (!this.morphNormals[_i5]) {
  16610. this.morphNormals[_i5] = {};
  16611. this.morphNormals[_i5].faceNormals = [];
  16612. this.morphNormals[_i5].vertexNormals = [];
  16613. var dstNormalsFace = this.morphNormals[_i5].faceNormals;
  16614. var dstNormalsVertex = this.morphNormals[_i5].vertexNormals;
  16615. for (var _f3 = 0, _fl3 = this.faces.length; _f3 < _fl3; _f3++) {
  16616. var faceNormal = new Vector3();
  16617. var vertexNormals = {
  16618. a: new Vector3(),
  16619. b: new Vector3(),
  16620. c: new Vector3()
  16621. };
  16622. dstNormalsFace.push(faceNormal);
  16623. dstNormalsVertex.push(vertexNormals);
  16624. }
  16625. }
  16626. var morphNormals = this.morphNormals[_i5]; // set vertices to morph target
  16627. tmpGeo.vertices = this.morphTargets[_i5].vertices; // compute morph normals
  16628. tmpGeo.computeFaceNormals();
  16629. tmpGeo.computeVertexNormals(); // store morph normals
  16630. for (var _f4 = 0, _fl4 = this.faces.length; _f4 < _fl4; _f4++) {
  16631. var _face3 = this.faces[_f4];
  16632. var _faceNormal = morphNormals.faceNormals[_f4];
  16633. var _vertexNormals = morphNormals.vertexNormals[_f4];
  16634. _faceNormal.copy(_face3.normal);
  16635. _vertexNormals.a.copy(_face3.vertexNormals[0]);
  16636. _vertexNormals.b.copy(_face3.vertexNormals[1]);
  16637. _vertexNormals.c.copy(_face3.vertexNormals[2]);
  16638. }
  16639. } // restore original normals
  16640. for (var _f5 = 0, _fl5 = this.faces.length; _f5 < _fl5; _f5++) {
  16641. var _face4 = this.faces[_f5];
  16642. _face4.normal = _face4.__originalFaceNormal;
  16643. _face4.vertexNormals = _face4.__originalVertexNormals;
  16644. }
  16645. },
  16646. computeBoundingBox: function computeBoundingBox() {
  16647. if (this.boundingBox === null) {
  16648. this.boundingBox = new Box3();
  16649. }
  16650. this.boundingBox.setFromPoints(this.vertices);
  16651. },
  16652. computeBoundingSphere: function computeBoundingSphere() {
  16653. if (this.boundingSphere === null) {
  16654. this.boundingSphere = new Sphere();
  16655. }
  16656. this.boundingSphere.setFromPoints(this.vertices);
  16657. },
  16658. merge: function merge(geometry, matrix, materialIndexOffset) {
  16659. if (!(geometry && geometry.isGeometry)) {
  16660. console.error('THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry);
  16661. return;
  16662. }
  16663. var normalMatrix;
  16664. var vertexOffset = this.vertices.length,
  16665. vertices1 = this.vertices,
  16666. vertices2 = geometry.vertices,
  16667. faces1 = this.faces,
  16668. faces2 = geometry.faces,
  16669. colors1 = this.colors,
  16670. colors2 = geometry.colors;
  16671. if (materialIndexOffset === undefined) materialIndexOffset = 0;
  16672. if (matrix !== undefined) {
  16673. normalMatrix = new Matrix3().getNormalMatrix(matrix);
  16674. } // vertices
  16675. for (var i = 0, il = vertices2.length; i < il; i++) {
  16676. var vertex = vertices2[i];
  16677. var vertexCopy = vertex.clone();
  16678. if (matrix !== undefined) vertexCopy.applyMatrix4(matrix);
  16679. vertices1.push(vertexCopy);
  16680. } // colors
  16681. for (var _i6 = 0, _il3 = colors2.length; _i6 < _il3; _i6++) {
  16682. colors1.push(colors2[_i6].clone());
  16683. } // faces
  16684. for (var _i7 = 0, _il4 = faces2.length; _i7 < _il4; _i7++) {
  16685. var face = faces2[_i7];
  16686. var normal = void 0,
  16687. color = void 0;
  16688. var faceVertexNormals = face.vertexNormals,
  16689. faceVertexColors = face.vertexColors;
  16690. var faceCopy = new Face3(face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset);
  16691. faceCopy.normal.copy(face.normal);
  16692. if (normalMatrix !== undefined) {
  16693. faceCopy.normal.applyMatrix3(normalMatrix).normalize();
  16694. }
  16695. for (var j = 0, jl = faceVertexNormals.length; j < jl; j++) {
  16696. normal = faceVertexNormals[j].clone();
  16697. if (normalMatrix !== undefined) {
  16698. normal.applyMatrix3(normalMatrix).normalize();
  16699. }
  16700. faceCopy.vertexNormals.push(normal);
  16701. }
  16702. faceCopy.color.copy(face.color);
  16703. for (var _j = 0, _jl = faceVertexColors.length; _j < _jl; _j++) {
  16704. color = faceVertexColors[_j];
  16705. faceCopy.vertexColors.push(color.clone());
  16706. }
  16707. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  16708. faces1.push(faceCopy);
  16709. } // uvs
  16710. for (var _i8 = 0, _il5 = geometry.faceVertexUvs.length; _i8 < _il5; _i8++) {
  16711. var faceVertexUvs2 = geometry.faceVertexUvs[_i8];
  16712. if (this.faceVertexUvs[_i8] === undefined) this.faceVertexUvs[_i8] = [];
  16713. for (var _j2 = 0, _jl2 = faceVertexUvs2.length; _j2 < _jl2; _j2++) {
  16714. var uvs2 = faceVertexUvs2[_j2],
  16715. uvsCopy = [];
  16716. for (var k = 0, kl = uvs2.length; k < kl; k++) {
  16717. uvsCopy.push(uvs2[k].clone());
  16718. }
  16719. this.faceVertexUvs[_i8].push(uvsCopy);
  16720. }
  16721. }
  16722. },
  16723. mergeMesh: function mergeMesh(mesh) {
  16724. if (!(mesh && mesh.isMesh)) {
  16725. console.error('THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh);
  16726. return;
  16727. }
  16728. if (mesh.matrixAutoUpdate) mesh.updateMatrix();
  16729. this.merge(mesh.geometry, mesh.matrix);
  16730. },
  16731. /*
  16732. * Checks for duplicate vertices with hashmap.
  16733. * Duplicated vertices are removed
  16734. * and faces' vertices are updated.
  16735. */
  16736. mergeVertices: function mergeVertices() {
  16737. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  16738. var unique = [],
  16739. changes = [];
  16740. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  16741. var precision = Math.pow(10, precisionPoints);
  16742. for (var i = 0, il = this.vertices.length; i < il; i++) {
  16743. var v = this.vertices[i];
  16744. var key = Math.round(v.x * precision) + '_' + Math.round(v.y * precision) + '_' + Math.round(v.z * precision);
  16745. if (verticesMap[key] === undefined) {
  16746. verticesMap[key] = i;
  16747. unique.push(this.vertices[i]);
  16748. changes[i] = unique.length - 1;
  16749. } else {
  16750. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  16751. changes[i] = changes[verticesMap[key]];
  16752. }
  16753. } // if faces are completely degenerate after merging vertices, we
  16754. // have to remove them from the geometry.
  16755. var faceIndicesToRemove = [];
  16756. for (var _i9 = 0, _il6 = this.faces.length; _i9 < _il6; _i9++) {
  16757. var face = this.faces[_i9];
  16758. face.a = changes[face.a];
  16759. face.b = changes[face.b];
  16760. face.c = changes[face.c];
  16761. var indices = [face.a, face.b, face.c]; // if any duplicate vertices are found in a Face3
  16762. // we have to remove the face as nothing can be saved
  16763. for (var n = 0; n < 3; n++) {
  16764. if (indices[n] === indices[(n + 1) % 3]) {
  16765. faceIndicesToRemove.push(_i9);
  16766. break;
  16767. }
  16768. }
  16769. }
  16770. for (var _i10 = faceIndicesToRemove.length - 1; _i10 >= 0; _i10--) {
  16771. var idx = faceIndicesToRemove[_i10];
  16772. this.faces.splice(idx, 1);
  16773. for (var j = 0, jl = this.faceVertexUvs.length; j < jl; j++) {
  16774. this.faceVertexUvs[j].splice(idx, 1);
  16775. }
  16776. } // Use unique set of vertices
  16777. var diff = this.vertices.length - unique.length;
  16778. this.vertices = unique;
  16779. return diff;
  16780. },
  16781. setFromPoints: function setFromPoints(points) {
  16782. this.vertices = [];
  16783. for (var i = 0, l = points.length; i < l; i++) {
  16784. var point = points[i];
  16785. this.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  16786. }
  16787. return this;
  16788. },
  16789. sortFacesByMaterialIndex: function sortFacesByMaterialIndex() {
  16790. var faces = this.faces;
  16791. var length = faces.length; // tag faces
  16792. for (var i = 0; i < length; i++) {
  16793. faces[i]._id = i;
  16794. } // sort faces
  16795. function materialIndexSort(a, b) {
  16796. return a.materialIndex - b.materialIndex;
  16797. }
  16798. faces.sort(materialIndexSort); // sort uvs
  16799. var uvs1 = this.faceVertexUvs[0];
  16800. var uvs2 = this.faceVertexUvs[1];
  16801. var newUvs1, newUvs2;
  16802. if (uvs1 && uvs1.length === length) newUvs1 = [];
  16803. if (uvs2 && uvs2.length === length) newUvs2 = [];
  16804. for (var _i11 = 0; _i11 < length; _i11++) {
  16805. var id = faces[_i11]._id;
  16806. if (newUvs1) newUvs1.push(uvs1[id]);
  16807. if (newUvs2) newUvs2.push(uvs2[id]);
  16808. }
  16809. if (newUvs1) this.faceVertexUvs[0] = newUvs1;
  16810. if (newUvs2) this.faceVertexUvs[1] = newUvs2;
  16811. },
  16812. toJSON: function toJSON() {
  16813. var data = {
  16814. metadata: {
  16815. version: 4.5,
  16816. type: 'Geometry',
  16817. generator: 'Geometry.toJSON'
  16818. }
  16819. }; // standard Geometry serialization
  16820. data.uuid = this.uuid;
  16821. data.type = this.type;
  16822. if (this.name !== '') data.name = this.name;
  16823. if (this.parameters !== undefined) {
  16824. var parameters = this.parameters;
  16825. for (var key in parameters) {
  16826. if (parameters[key] !== undefined) data[key] = parameters[key];
  16827. }
  16828. return data;
  16829. }
  16830. var vertices = [];
  16831. for (var i = 0; i < this.vertices.length; i++) {
  16832. var vertex = this.vertices[i];
  16833. vertices.push(vertex.x, vertex.y, vertex.z);
  16834. }
  16835. var faces = [];
  16836. var normals = [];
  16837. var normalsHash = {};
  16838. var colors = [];
  16839. var colorsHash = {};
  16840. var uvs = [];
  16841. var uvsHash = {};
  16842. for (var _i12 = 0; _i12 < this.faces.length; _i12++) {
  16843. var face = this.faces[_i12];
  16844. var hasMaterial = true;
  16845. var hasFaceUv = false; // deprecated
  16846. var hasFaceVertexUv = this.faceVertexUvs[0][_i12] !== undefined;
  16847. var hasFaceNormal = face.normal.length() > 0;
  16848. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  16849. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  16850. var hasFaceVertexColor = face.vertexColors.length > 0;
  16851. var faceType = 0;
  16852. faceType = setBit(faceType, 0, 0); // isQuad
  16853. faceType = setBit(faceType, 1, hasMaterial);
  16854. faceType = setBit(faceType, 2, hasFaceUv);
  16855. faceType = setBit(faceType, 3, hasFaceVertexUv);
  16856. faceType = setBit(faceType, 4, hasFaceNormal);
  16857. faceType = setBit(faceType, 5, hasFaceVertexNormal);
  16858. faceType = setBit(faceType, 6, hasFaceColor);
  16859. faceType = setBit(faceType, 7, hasFaceVertexColor);
  16860. faces.push(faceType);
  16861. faces.push(face.a, face.b, face.c);
  16862. faces.push(face.materialIndex);
  16863. if (hasFaceVertexUv) {
  16864. var faceVertexUvs = this.faceVertexUvs[0][_i12];
  16865. faces.push(getUvIndex(faceVertexUvs[0]), getUvIndex(faceVertexUvs[1]), getUvIndex(faceVertexUvs[2]));
  16866. }
  16867. if (hasFaceNormal) {
  16868. faces.push(getNormalIndex(face.normal));
  16869. }
  16870. if (hasFaceVertexNormal) {
  16871. var vertexNormals = face.vertexNormals;
  16872. faces.push(getNormalIndex(vertexNormals[0]), getNormalIndex(vertexNormals[1]), getNormalIndex(vertexNormals[2]));
  16873. }
  16874. if (hasFaceColor) {
  16875. faces.push(getColorIndex(face.color));
  16876. }
  16877. if (hasFaceVertexColor) {
  16878. var vertexColors = face.vertexColors;
  16879. faces.push(getColorIndex(vertexColors[0]), getColorIndex(vertexColors[1]), getColorIndex(vertexColors[2]));
  16880. }
  16881. }
  16882. function setBit(value, position, enabled) {
  16883. return enabled ? value | 1 << position : value & ~(1 << position);
  16884. }
  16885. function getNormalIndex(normal) {
  16886. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  16887. if (normalsHash[hash] !== undefined) {
  16888. return normalsHash[hash];
  16889. }
  16890. normalsHash[hash] = normals.length / 3;
  16891. normals.push(normal.x, normal.y, normal.z);
  16892. return normalsHash[hash];
  16893. }
  16894. function getColorIndex(color) {
  16895. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  16896. if (colorsHash[hash] !== undefined) {
  16897. return colorsHash[hash];
  16898. }
  16899. colorsHash[hash] = colors.length;
  16900. colors.push(color.getHex());
  16901. return colorsHash[hash];
  16902. }
  16903. function getUvIndex(uv) {
  16904. var hash = uv.x.toString() + uv.y.toString();
  16905. if (uvsHash[hash] !== undefined) {
  16906. return uvsHash[hash];
  16907. }
  16908. uvsHash[hash] = uvs.length / 2;
  16909. uvs.push(uv.x, uv.y);
  16910. return uvsHash[hash];
  16911. }
  16912. data.data = {};
  16913. data.data.vertices = vertices;
  16914. data.data.normals = normals;
  16915. if (colors.length > 0) data.data.colors = colors;
  16916. if (uvs.length > 0) data.data.uvs = [uvs]; // temporal backward compatibility
  16917. data.data.faces = faces;
  16918. return data;
  16919. },
  16920. clone: function clone() {
  16921. /*
  16922. // Handle primitives
  16923. const parameters = this.parameters;
  16924. if ( parameters !== undefined ) {
  16925. const values = [];
  16926. for ( const key in parameters ) {
  16927. values.push( parameters[ key ] );
  16928. }
  16929. const geometry = Object.create( this.constructor.prototype );
  16930. this.constructor.apply( geometry, values );
  16931. return geometry;
  16932. }
  16933. return new this.constructor().copy( this );
  16934. */
  16935. return new Geometry().copy(this);
  16936. },
  16937. copy: function copy(source) {
  16938. // reset
  16939. this.vertices = [];
  16940. this.colors = [];
  16941. this.faces = [];
  16942. this.faceVertexUvs = [[]];
  16943. this.morphTargets = [];
  16944. this.morphNormals = [];
  16945. this.skinWeights = [];
  16946. this.skinIndices = [];
  16947. this.lineDistances = [];
  16948. this.boundingBox = null;
  16949. this.boundingSphere = null; // name
  16950. this.name = source.name; // vertices
  16951. var vertices = source.vertices;
  16952. for (var i = 0, il = vertices.length; i < il; i++) {
  16953. this.vertices.push(vertices[i].clone());
  16954. } // colors
  16955. var colors = source.colors;
  16956. for (var _i13 = 0, _il7 = colors.length; _i13 < _il7; _i13++) {
  16957. this.colors.push(colors[_i13].clone());
  16958. } // faces
  16959. var faces = source.faces;
  16960. for (var _i14 = 0, _il8 = faces.length; _i14 < _il8; _i14++) {
  16961. this.faces.push(faces[_i14].clone());
  16962. } // face vertex uvs
  16963. for (var _i15 = 0, _il9 = source.faceVertexUvs.length; _i15 < _il9; _i15++) {
  16964. var faceVertexUvs = source.faceVertexUvs[_i15];
  16965. if (this.faceVertexUvs[_i15] === undefined) {
  16966. this.faceVertexUvs[_i15] = [];
  16967. }
  16968. for (var j = 0, jl = faceVertexUvs.length; j < jl; j++) {
  16969. var uvs = faceVertexUvs[j],
  16970. uvsCopy = [];
  16971. for (var k = 0, kl = uvs.length; k < kl; k++) {
  16972. var uv = uvs[k];
  16973. uvsCopy.push(uv.clone());
  16974. }
  16975. this.faceVertexUvs[_i15].push(uvsCopy);
  16976. }
  16977. } // morph targets
  16978. var morphTargets = source.morphTargets;
  16979. for (var _i16 = 0, _il10 = morphTargets.length; _i16 < _il10; _i16++) {
  16980. var morphTarget = {};
  16981. morphTarget.name = morphTargets[_i16].name; // vertices
  16982. if (morphTargets[_i16].vertices !== undefined) {
  16983. morphTarget.vertices = [];
  16984. for (var _j3 = 0, _jl3 = morphTargets[_i16].vertices.length; _j3 < _jl3; _j3++) {
  16985. morphTarget.vertices.push(morphTargets[_i16].vertices[_j3].clone());
  16986. }
  16987. } // normals
  16988. if (morphTargets[_i16].normals !== undefined) {
  16989. morphTarget.normals = [];
  16990. for (var _j4 = 0, _jl4 = morphTargets[_i16].normals.length; _j4 < _jl4; _j4++) {
  16991. morphTarget.normals.push(morphTargets[_i16].normals[_j4].clone());
  16992. }
  16993. }
  16994. this.morphTargets.push(morphTarget);
  16995. } // morph normals
  16996. var morphNormals = source.morphNormals;
  16997. for (var _i17 = 0, _il11 = morphNormals.length; _i17 < _il11; _i17++) {
  16998. var morphNormal = {}; // vertex normals
  16999. if (morphNormals[_i17].vertexNormals !== undefined) {
  17000. morphNormal.vertexNormals = [];
  17001. for (var _j5 = 0, _jl5 = morphNormals[_i17].vertexNormals.length; _j5 < _jl5; _j5++) {
  17002. var srcVertexNormal = morphNormals[_i17].vertexNormals[_j5];
  17003. var destVertexNormal = {};
  17004. destVertexNormal.a = srcVertexNormal.a.clone();
  17005. destVertexNormal.b = srcVertexNormal.b.clone();
  17006. destVertexNormal.c = srcVertexNormal.c.clone();
  17007. morphNormal.vertexNormals.push(destVertexNormal);
  17008. }
  17009. } // face normals
  17010. if (morphNormals[_i17].faceNormals !== undefined) {
  17011. morphNormal.faceNormals = [];
  17012. for (var _j6 = 0, _jl6 = morphNormals[_i17].faceNormals.length; _j6 < _jl6; _j6++) {
  17013. morphNormal.faceNormals.push(morphNormals[_i17].faceNormals[_j6].clone());
  17014. }
  17015. }
  17016. this.morphNormals.push(morphNormal);
  17017. } // skin weights
  17018. var skinWeights = source.skinWeights;
  17019. for (var _i18 = 0, _il12 = skinWeights.length; _i18 < _il12; _i18++) {
  17020. this.skinWeights.push(skinWeights[_i18].clone());
  17021. } // skin indices
  17022. var skinIndices = source.skinIndices;
  17023. for (var _i19 = 0, _il13 = skinIndices.length; _i19 < _il13; _i19++) {
  17024. this.skinIndices.push(skinIndices[_i19].clone());
  17025. } // line distances
  17026. var lineDistances = source.lineDistances;
  17027. for (var _i20 = 0, _il14 = lineDistances.length; _i20 < _il14; _i20++) {
  17028. this.lineDistances.push(lineDistances[_i20]);
  17029. } // bounding box
  17030. var boundingBox = source.boundingBox;
  17031. if (boundingBox !== null) {
  17032. this.boundingBox = boundingBox.clone();
  17033. } // bounding sphere
  17034. var boundingSphere = source.boundingSphere;
  17035. if (boundingSphere !== null) {
  17036. this.boundingSphere = boundingSphere.clone();
  17037. } // update flags
  17038. this.elementsNeedUpdate = source.elementsNeedUpdate;
  17039. this.verticesNeedUpdate = source.verticesNeedUpdate;
  17040. this.uvsNeedUpdate = source.uvsNeedUpdate;
  17041. this.normalsNeedUpdate = source.normalsNeedUpdate;
  17042. this.colorsNeedUpdate = source.colorsNeedUpdate;
  17043. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  17044. this.groupsNeedUpdate = source.groupsNeedUpdate;
  17045. return this;
  17046. },
  17047. dispose: function dispose() {
  17048. this.dispatchEvent({
  17049. type: 'dispose'
  17050. });
  17051. }
  17052. });
  17053. var BoxGeometry = /*#__PURE__*/function (_Geometry) {
  17054. _inheritsLoose(BoxGeometry, _Geometry);
  17055. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  17056. var _this;
  17057. _this = _Geometry.call(this) || this;
  17058. _this.type = 'BoxGeometry';
  17059. _this.parameters = {
  17060. width: width,
  17061. height: height,
  17062. depth: depth,
  17063. widthSegments: widthSegments,
  17064. heightSegments: heightSegments,
  17065. depthSegments: depthSegments
  17066. };
  17067. _this.fromBufferGeometry(new BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments));
  17068. _this.mergeVertices();
  17069. return _this;
  17070. }
  17071. return BoxGeometry;
  17072. }(Geometry);
  17073. var CircleBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17074. _inheritsLoose(CircleBufferGeometry, _BufferGeometry);
  17075. function CircleBufferGeometry(radius, segments, thetaStart, thetaLength) {
  17076. var _this;
  17077. _this = _BufferGeometry.call(this) || this;
  17078. _this.type = 'CircleBufferGeometry';
  17079. _this.parameters = {
  17080. radius: radius,
  17081. segments: segments,
  17082. thetaStart: thetaStart,
  17083. thetaLength: thetaLength
  17084. };
  17085. radius = radius || 1;
  17086. segments = segments !== undefined ? Math.max(3, segments) : 8;
  17087. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17088. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2; // buffers
  17089. var indices = [];
  17090. var vertices = [];
  17091. var normals = [];
  17092. var uvs = []; // helper variables
  17093. var vertex = new Vector3();
  17094. var uv = new Vector2(); // center point
  17095. vertices.push(0, 0, 0);
  17096. normals.push(0, 0, 1);
  17097. uvs.push(0.5, 0.5);
  17098. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17099. var segment = thetaStart + s / segments * thetaLength; // vertex
  17100. vertex.x = radius * Math.cos(segment);
  17101. vertex.y = radius * Math.sin(segment);
  17102. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17103. normals.push(0, 0, 1); // uvs
  17104. uv.x = (vertices[i] / radius + 1) / 2;
  17105. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17106. uvs.push(uv.x, uv.y);
  17107. } // indices
  17108. for (var _i = 1; _i <= segments; _i++) {
  17109. indices.push(_i, _i + 1, 0);
  17110. } // build geometry
  17111. _this.setIndex(indices);
  17112. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17113. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17114. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17115. return _this;
  17116. }
  17117. return CircleBufferGeometry;
  17118. }(BufferGeometry);
  17119. var CircleGeometry = /*#__PURE__*/function (_Geometry) {
  17120. _inheritsLoose(CircleGeometry, _Geometry);
  17121. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17122. var _this;
  17123. _this = _Geometry.call(this) || this;
  17124. _this.type = 'CircleGeometry';
  17125. _this.parameters = {
  17126. radius: radius,
  17127. segments: segments,
  17128. thetaStart: thetaStart,
  17129. thetaLength: thetaLength
  17130. };
  17131. _this.fromBufferGeometry(new CircleBufferGeometry(radius, segments, thetaStart, thetaLength));
  17132. _this.mergeVertices();
  17133. return _this;
  17134. }
  17135. return CircleGeometry;
  17136. }(Geometry);
  17137. var CylinderBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17138. _inheritsLoose(CylinderBufferGeometry, _BufferGeometry);
  17139. function CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17140. var _this;
  17141. _this = _BufferGeometry.call(this) || this;
  17142. _this.type = 'CylinderBufferGeometry';
  17143. _this.parameters = {
  17144. radiusTop: radiusTop,
  17145. radiusBottom: radiusBottom,
  17146. height: height,
  17147. radialSegments: radialSegments,
  17148. heightSegments: heightSegments,
  17149. openEnded: openEnded,
  17150. thetaStart: thetaStart,
  17151. thetaLength: thetaLength
  17152. };
  17153. var scope = _assertThisInitialized(_this);
  17154. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  17155. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  17156. height = height || 1;
  17157. radialSegments = Math.floor(radialSegments) || 8;
  17158. heightSegments = Math.floor(heightSegments) || 1;
  17159. openEnded = openEnded !== undefined ? openEnded : false;
  17160. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  17161. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2; // buffers
  17162. var indices = [];
  17163. var vertices = [];
  17164. var normals = [];
  17165. var uvs = []; // helper variables
  17166. var index = 0;
  17167. var indexArray = [];
  17168. var halfHeight = height / 2;
  17169. var groupStart = 0; // generate geometry
  17170. generateTorso();
  17171. if (openEnded === false) {
  17172. if (radiusTop > 0) generateCap(true);
  17173. if (radiusBottom > 0) generateCap(false);
  17174. } // build geometry
  17175. _this.setIndex(indices);
  17176. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17177. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17178. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17179. function generateTorso() {
  17180. var normal = new Vector3();
  17181. var vertex = new Vector3();
  17182. var groupCount = 0; // this will be used to calculate the normal
  17183. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17184. for (var y = 0; y <= heightSegments; y++) {
  17185. var indexRow = [];
  17186. var v = y / heightSegments; // calculate the radius of the current row
  17187. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17188. for (var x = 0; x <= radialSegments; x++) {
  17189. var u = x / radialSegments;
  17190. var theta = u * thetaLength + thetaStart;
  17191. var sinTheta = Math.sin(theta);
  17192. var cosTheta = Math.cos(theta); // vertex
  17193. vertex.x = radius * sinTheta;
  17194. vertex.y = -v * height + halfHeight;
  17195. vertex.z = radius * cosTheta;
  17196. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17197. normal.set(sinTheta, slope, cosTheta).normalize();
  17198. normals.push(normal.x, normal.y, normal.z); // uv
  17199. uvs.push(u, 1 - v); // save index of vertex in respective row
  17200. indexRow.push(index++);
  17201. } // now save vertices of the row in our index array
  17202. indexArray.push(indexRow);
  17203. } // generate indices
  17204. for (var _x = 0; _x < radialSegments; _x++) {
  17205. for (var _y = 0; _y < heightSegments; _y++) {
  17206. // we use the index array to access the correct indices
  17207. var a = indexArray[_y][_x];
  17208. var b = indexArray[_y + 1][_x];
  17209. var c = indexArray[_y + 1][_x + 1];
  17210. var d = indexArray[_y][_x + 1]; // faces
  17211. indices.push(a, b, d);
  17212. indices.push(b, c, d); // update group counter
  17213. groupCount += 6;
  17214. }
  17215. } // add a group to the geometry. this will ensure multi material support
  17216. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17217. groupStart += groupCount;
  17218. }
  17219. function generateCap(top) {
  17220. // save the index of the first center vertex
  17221. var centerIndexStart = index;
  17222. var uv = new Vector2();
  17223. var vertex = new Vector3();
  17224. var groupCount = 0;
  17225. var radius = top === true ? radiusTop : radiusBottom;
  17226. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17227. // because the geometry needs one set of uvs per face,
  17228. // we must generate a center vertex per face/segment
  17229. for (var x = 1; x <= radialSegments; x++) {
  17230. // vertex
  17231. vertices.push(0, halfHeight * sign, 0); // normal
  17232. normals.push(0, sign, 0); // uv
  17233. uvs.push(0.5, 0.5); // increase index
  17234. index++;
  17235. } // save the index of the last center vertex
  17236. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17237. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17238. var u = _x2 / radialSegments;
  17239. var theta = u * thetaLength + thetaStart;
  17240. var cosTheta = Math.cos(theta);
  17241. var sinTheta = Math.sin(theta); // vertex
  17242. vertex.x = radius * sinTheta;
  17243. vertex.y = halfHeight * sign;
  17244. vertex.z = radius * cosTheta;
  17245. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17246. normals.push(0, sign, 0); // uv
  17247. uv.x = cosTheta * 0.5 + 0.5;
  17248. uv.y = sinTheta * 0.5 * sign + 0.5;
  17249. uvs.push(uv.x, uv.y); // increase index
  17250. index++;
  17251. } // generate indices
  17252. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17253. var c = centerIndexStart + _x3;
  17254. var i = centerIndexEnd + _x3;
  17255. if (top === true) {
  17256. // face top
  17257. indices.push(i, i + 1, c);
  17258. } else {
  17259. // face bottom
  17260. indices.push(i + 1, i, c);
  17261. }
  17262. groupCount += 3;
  17263. } // add a group to the geometry. this will ensure multi material support
  17264. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17265. groupStart += groupCount;
  17266. }
  17267. return _this;
  17268. }
  17269. return CylinderBufferGeometry;
  17270. }(BufferGeometry);
  17271. var CylinderGeometry = /*#__PURE__*/function (_Geometry) {
  17272. _inheritsLoose(CylinderGeometry, _Geometry);
  17273. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17274. var _this;
  17275. _this = _Geometry.call(this) || this;
  17276. _this.type = 'CylinderGeometry';
  17277. _this.parameters = {
  17278. radiusTop: radiusTop,
  17279. radiusBottom: radiusBottom,
  17280. height: height,
  17281. radialSegments: radialSegments,
  17282. heightSegments: heightSegments,
  17283. openEnded: openEnded,
  17284. thetaStart: thetaStart,
  17285. thetaLength: thetaLength
  17286. };
  17287. _this.fromBufferGeometry(new CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength));
  17288. _this.mergeVertices();
  17289. return _this;
  17290. }
  17291. return CylinderGeometry;
  17292. }(Geometry);
  17293. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17294. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17295. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17296. var _this;
  17297. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17298. _this.type = 'ConeGeometry';
  17299. _this.parameters = {
  17300. radius: radius,
  17301. height: height,
  17302. radialSegments: radialSegments,
  17303. heightSegments: heightSegments,
  17304. openEnded: openEnded,
  17305. thetaStart: thetaStart,
  17306. thetaLength: thetaLength
  17307. };
  17308. return _this;
  17309. }
  17310. return ConeGeometry;
  17311. }(CylinderGeometry);
  17312. var ConeBufferGeometry = /*#__PURE__*/function (_CylinderBufferGeomet) {
  17313. _inheritsLoose(ConeBufferGeometry, _CylinderBufferGeomet);
  17314. function ConeBufferGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17315. var _this;
  17316. _this = _CylinderBufferGeomet.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17317. _this.type = 'ConeBufferGeometry';
  17318. _this.parameters = {
  17319. radius: radius,
  17320. height: height,
  17321. radialSegments: radialSegments,
  17322. heightSegments: heightSegments,
  17323. openEnded: openEnded,
  17324. thetaStart: thetaStart,
  17325. thetaLength: thetaLength
  17326. };
  17327. return _this;
  17328. }
  17329. return ConeBufferGeometry;
  17330. }(CylinderBufferGeometry);
  17331. var PolyhedronBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17332. _inheritsLoose(PolyhedronBufferGeometry, _BufferGeometry);
  17333. function PolyhedronBufferGeometry(vertices, indices, radius, detail) {
  17334. var _this;
  17335. _this = _BufferGeometry.call(this) || this;
  17336. _this.type = 'PolyhedronBufferGeometry';
  17337. _this.parameters = {
  17338. vertices: vertices,
  17339. indices: indices,
  17340. radius: radius,
  17341. detail: detail
  17342. };
  17343. radius = radius || 1;
  17344. detail = detail || 0; // default buffer data
  17345. var vertexBuffer = [];
  17346. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17347. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17348. applyRadius(radius); // finally, create the uv data
  17349. generateUVs(); // build non-indexed geometry
  17350. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17351. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17352. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17353. if (detail === 0) {
  17354. _this.computeVertexNormals(); // flat normals
  17355. } else {
  17356. _this.normalizeNormals(); // smooth normals
  17357. } // helper functions
  17358. function subdivide(detail) {
  17359. var a = new Vector3();
  17360. var b = new Vector3();
  17361. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17362. for (var i = 0; i < indices.length; i += 3) {
  17363. // get the vertices of the face
  17364. getVertexByIndex(indices[i + 0], a);
  17365. getVertexByIndex(indices[i + 1], b);
  17366. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17367. subdivideFace(a, b, c, detail);
  17368. }
  17369. }
  17370. function subdivideFace(a, b, c, detail) {
  17371. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17372. var v = []; // construct all of the vertices for this subdivision
  17373. for (var i = 0; i <= cols; i++) {
  17374. v[i] = [];
  17375. var aj = a.clone().lerp(c, i / cols);
  17376. var bj = b.clone().lerp(c, i / cols);
  17377. var rows = cols - i;
  17378. for (var j = 0; j <= rows; j++) {
  17379. if (j === 0 && i === cols) {
  17380. v[i][j] = aj;
  17381. } else {
  17382. v[i][j] = aj.clone().lerp(bj, j / rows);
  17383. }
  17384. }
  17385. } // construct all of the faces
  17386. for (var _i = 0; _i < cols; _i++) {
  17387. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17388. var k = Math.floor(_j / 2);
  17389. if (_j % 2 === 0) {
  17390. pushVertex(v[_i][k + 1]);
  17391. pushVertex(v[_i + 1][k]);
  17392. pushVertex(v[_i][k]);
  17393. } else {
  17394. pushVertex(v[_i][k + 1]);
  17395. pushVertex(v[_i + 1][k + 1]);
  17396. pushVertex(v[_i + 1][k]);
  17397. }
  17398. }
  17399. }
  17400. }
  17401. function applyRadius(radius) {
  17402. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17403. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17404. vertex.x = vertexBuffer[i + 0];
  17405. vertex.y = vertexBuffer[i + 1];
  17406. vertex.z = vertexBuffer[i + 2];
  17407. vertex.normalize().multiplyScalar(radius);
  17408. vertexBuffer[i + 0] = vertex.x;
  17409. vertexBuffer[i + 1] = vertex.y;
  17410. vertexBuffer[i + 2] = vertex.z;
  17411. }
  17412. }
  17413. function generateUVs() {
  17414. var vertex = new Vector3();
  17415. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17416. vertex.x = vertexBuffer[i + 0];
  17417. vertex.y = vertexBuffer[i + 1];
  17418. vertex.z = vertexBuffer[i + 2];
  17419. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17420. var v = inclination(vertex) / Math.PI + 0.5;
  17421. uvBuffer.push(u, 1 - v);
  17422. }
  17423. correctUVs();
  17424. correctSeam();
  17425. }
  17426. function correctSeam() {
  17427. // handle case when face straddles the seam, see #3269
  17428. for (var i = 0; i < uvBuffer.length; i += 6) {
  17429. // uv data of a single face
  17430. var x0 = uvBuffer[i + 0];
  17431. var x1 = uvBuffer[i + 2];
  17432. var x2 = uvBuffer[i + 4];
  17433. var max = Math.max(x0, x1, x2);
  17434. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17435. if (max > 0.9 && min < 0.1) {
  17436. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17437. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17438. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17439. }
  17440. }
  17441. }
  17442. function pushVertex(vertex) {
  17443. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17444. }
  17445. function getVertexByIndex(index, vertex) {
  17446. var stride = index * 3;
  17447. vertex.x = vertices[stride + 0];
  17448. vertex.y = vertices[stride + 1];
  17449. vertex.z = vertices[stride + 2];
  17450. }
  17451. function correctUVs() {
  17452. var a = new Vector3();
  17453. var b = new Vector3();
  17454. var c = new Vector3();
  17455. var centroid = new Vector3();
  17456. var uvA = new Vector2();
  17457. var uvB = new Vector2();
  17458. var uvC = new Vector2();
  17459. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17460. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17461. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17462. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17463. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17464. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17465. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17466. centroid.copy(a).add(b).add(c).divideScalar(3);
  17467. var azi = azimuth(centroid);
  17468. correctUV(uvA, j + 0, a, azi);
  17469. correctUV(uvB, j + 2, b, azi);
  17470. correctUV(uvC, j + 4, c, azi);
  17471. }
  17472. }
  17473. function correctUV(uv, stride, vector, azimuth) {
  17474. if (azimuth < 0 && uv.x === 1) {
  17475. uvBuffer[stride] = uv.x - 1;
  17476. }
  17477. if (vector.x === 0 && vector.z === 0) {
  17478. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17479. }
  17480. } // Angle around the Y axis, counter-clockwise when looking from above.
  17481. function azimuth(vector) {
  17482. return Math.atan2(vector.z, -vector.x);
  17483. } // Angle above the XZ plane.
  17484. function inclination(vector) {
  17485. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17486. }
  17487. return _this;
  17488. }
  17489. return PolyhedronBufferGeometry;
  17490. }(BufferGeometry);
  17491. var DodecahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  17492. _inheritsLoose(DodecahedronBufferGeometry, _PolyhedronBufferGeom);
  17493. function DodecahedronBufferGeometry(radius, detail) {
  17494. var _this;
  17495. var t = (1 + Math.sqrt(5)) / 2;
  17496. var r = 1 / t;
  17497. var vertices = [// (±1, ±1, ±1)
  17498. -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/φ, ±φ)
  17499. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17500. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17501. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17502. 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];
  17503. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  17504. _this.type = 'DodecahedronBufferGeometry';
  17505. _this.parameters = {
  17506. radius: radius,
  17507. detail: detail
  17508. };
  17509. return _this;
  17510. }
  17511. return DodecahedronBufferGeometry;
  17512. }(PolyhedronBufferGeometry);
  17513. var DodecahedronGeometry = /*#__PURE__*/function (_Geometry) {
  17514. _inheritsLoose(DodecahedronGeometry, _Geometry);
  17515. function DodecahedronGeometry(radius, detail) {
  17516. var _this;
  17517. _this = _Geometry.call(this) || this;
  17518. _this.type = 'DodecahedronGeometry';
  17519. _this.parameters = {
  17520. radius: radius,
  17521. detail: detail
  17522. };
  17523. _this.fromBufferGeometry(new DodecahedronBufferGeometry(radius, detail));
  17524. _this.mergeVertices();
  17525. return _this;
  17526. }
  17527. return DodecahedronGeometry;
  17528. }(Geometry);
  17529. var _v0$2 = new Vector3();
  17530. var _v1$5 = new Vector3();
  17531. var _normal$1 = new Vector3();
  17532. var _triangle = new Triangle();
  17533. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17534. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17535. function EdgesGeometry(geometry, thresholdAngle) {
  17536. var _this;
  17537. _this = _BufferGeometry.call(this) || this;
  17538. _this.type = 'EdgesGeometry';
  17539. _this.parameters = {
  17540. thresholdAngle: thresholdAngle
  17541. };
  17542. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17543. if (geometry.isGeometry) {
  17544. geometry = new BufferGeometry().fromGeometry(geometry);
  17545. }
  17546. var precisionPoints = 4;
  17547. var precision = Math.pow(10, precisionPoints);
  17548. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17549. var indexAttr = geometry.getIndex();
  17550. var positionAttr = geometry.getAttribute('position');
  17551. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17552. var indexArr = [0, 0, 0];
  17553. var vertKeys = ['a', 'b', 'c'];
  17554. var hashes = new Array(3);
  17555. var edgeData = {};
  17556. var vertices = [];
  17557. for (var i = 0; i < indexCount; i += 3) {
  17558. if (indexAttr) {
  17559. indexArr[0] = indexAttr.getX(i);
  17560. indexArr[1] = indexAttr.getX(i + 1);
  17561. indexArr[2] = indexAttr.getX(i + 2);
  17562. } else {
  17563. indexArr[0] = i;
  17564. indexArr[1] = i + 1;
  17565. indexArr[2] = i + 2;
  17566. }
  17567. var a = _triangle.a,
  17568. b = _triangle.b,
  17569. c = _triangle.c;
  17570. a.fromBufferAttribute(positionAttr, indexArr[0]);
  17571. b.fromBufferAttribute(positionAttr, indexArr[1]);
  17572. c.fromBufferAttribute(positionAttr, indexArr[2]);
  17573. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  17574. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  17575. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  17576. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  17577. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  17578. continue;
  17579. } // iterate over every edge
  17580. for (var j = 0; j < 3; j++) {
  17581. // get the first and next vertex making up the edge
  17582. var jNext = (j + 1) % 3;
  17583. var vecHash0 = hashes[j];
  17584. var vecHash1 = hashes[jNext];
  17585. var v0 = _triangle[vertKeys[j]];
  17586. var v1 = _triangle[vertKeys[jNext]];
  17587. var hash = vecHash0 + "_" + vecHash1;
  17588. var reverseHash = vecHash1 + "_" + vecHash0;
  17589. if (reverseHash in edgeData && edgeData[reverseHash]) {
  17590. // if we found a sibling edge add it into the vertex array if
  17591. // it meets the angle threshold and delete the edge from the map.
  17592. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  17593. vertices.push(v0.x, v0.y, v0.z);
  17594. vertices.push(v1.x, v1.y, v1.z);
  17595. }
  17596. edgeData[reverseHash] = null;
  17597. } else if (!(hash in edgeData)) {
  17598. // if we've already got an edge here then skip adding a new one
  17599. edgeData[hash] = {
  17600. index0: indexArr[j],
  17601. index1: indexArr[jNext],
  17602. normal: _normal$1.clone()
  17603. };
  17604. }
  17605. }
  17606. } // iterate over all remaining, unmatched edges and add them to the vertex array
  17607. for (var key in edgeData) {
  17608. if (edgeData[key]) {
  17609. var _edgeData$key = edgeData[key],
  17610. index0 = _edgeData$key.index0,
  17611. index1 = _edgeData$key.index1;
  17612. _v0$2.fromBufferAttribute(positionAttr, index0);
  17613. _v1$5.fromBufferAttribute(positionAttr, index1);
  17614. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  17615. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  17616. }
  17617. }
  17618. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17619. return _this;
  17620. }
  17621. return EdgesGeometry;
  17622. }(BufferGeometry);
  17623. /**
  17624. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17625. */
  17626. var Earcut = {
  17627. triangulate: function triangulate(data, holeIndices, dim) {
  17628. dim = dim || 2;
  17629. var hasHoles = holeIndices && holeIndices.length;
  17630. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  17631. var outerNode = linkedList(data, 0, outerLen, dim, true);
  17632. var triangles = [];
  17633. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  17634. var minX, minY, maxX, maxY, x, y, invSize;
  17635. 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
  17636. if (data.length > 80 * dim) {
  17637. minX = maxX = data[0];
  17638. minY = maxY = data[1];
  17639. for (var i = dim; i < outerLen; i += dim) {
  17640. x = data[i];
  17641. y = data[i + 1];
  17642. if (x < minX) minX = x;
  17643. if (y < minY) minY = y;
  17644. if (x > maxX) maxX = x;
  17645. if (y > maxY) maxY = y;
  17646. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17647. invSize = Math.max(maxX - minX, maxY - minY);
  17648. invSize = invSize !== 0 ? 1 / invSize : 0;
  17649. }
  17650. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  17651. return triangles;
  17652. }
  17653. }; // create a circular doubly linked list from polygon points in the specified winding order
  17654. function linkedList(data, start, end, dim, clockwise) {
  17655. var i, last;
  17656. if (clockwise === signedArea(data, start, end, dim) > 0) {
  17657. for (i = start; i < end; i += dim) {
  17658. last = insertNode(i, data[i], data[i + 1], last);
  17659. }
  17660. } else {
  17661. for (i = end - dim; i >= start; i -= dim) {
  17662. last = insertNode(i, data[i], data[i + 1], last);
  17663. }
  17664. }
  17665. if (last && equals(last, last.next)) {
  17666. removeNode(last);
  17667. last = last.next;
  17668. }
  17669. return last;
  17670. } // eliminate colinear or duplicate points
  17671. function filterPoints(start, end) {
  17672. if (!start) return start;
  17673. if (!end) end = start;
  17674. var p = start,
  17675. again;
  17676. do {
  17677. again = false;
  17678. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  17679. removeNode(p);
  17680. p = end = p.prev;
  17681. if (p === p.next) break;
  17682. again = true;
  17683. } else {
  17684. p = p.next;
  17685. }
  17686. } while (again || p !== end);
  17687. return end;
  17688. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  17689. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  17690. if (!ear) return; // interlink polygon nodes in z-order
  17691. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  17692. var stop = ear,
  17693. prev,
  17694. next; // iterate through ears, slicing them one by one
  17695. while (ear.prev !== ear.next) {
  17696. prev = ear.prev;
  17697. next = ear.next;
  17698. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  17699. // cut off the triangle
  17700. triangles.push(prev.i / dim);
  17701. triangles.push(ear.i / dim);
  17702. triangles.push(next.i / dim);
  17703. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  17704. ear = next.next;
  17705. stop = next.next;
  17706. continue;
  17707. }
  17708. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  17709. if (ear === stop) {
  17710. // try filtering points and slicing again
  17711. if (!pass) {
  17712. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  17713. } else if (pass === 1) {
  17714. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  17715. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  17716. } else if (pass === 2) {
  17717. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  17718. }
  17719. break;
  17720. }
  17721. }
  17722. } // check whether a polygon node forms a valid ear with adjacent nodes
  17723. function isEar(ear) {
  17724. var a = ear.prev,
  17725. b = ear,
  17726. c = ear.next;
  17727. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17728. // now make sure we don't have other points inside the potential ear
  17729. var p = ear.next.next;
  17730. while (p !== ear.prev) {
  17731. 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;
  17732. p = p.next;
  17733. }
  17734. return true;
  17735. }
  17736. function isEarHashed(ear, minX, minY, invSize) {
  17737. var a = ear.prev,
  17738. b = ear,
  17739. c = ear.next;
  17740. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17741. // triangle bbox; min & max are calculated like this for speed
  17742. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  17743. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  17744. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  17745. 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;
  17746. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  17747. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  17748. var p = ear.prevZ,
  17749. n = ear.nextZ; // look for points inside the triangle in both directions
  17750. while (p && p.z >= minZ && n && n.z <= maxZ) {
  17751. 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;
  17752. p = p.prevZ;
  17753. 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;
  17754. n = n.nextZ;
  17755. } // look for remaining points in decreasing z-order
  17756. while (p && p.z >= minZ) {
  17757. 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;
  17758. p = p.prevZ;
  17759. } // look for remaining points in increasing z-order
  17760. while (n && n.z <= maxZ) {
  17761. 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;
  17762. n = n.nextZ;
  17763. }
  17764. return true;
  17765. } // go through all polygon nodes and cure small local self-intersections
  17766. function cureLocalIntersections(start, triangles, dim) {
  17767. var p = start;
  17768. do {
  17769. var a = p.prev,
  17770. b = p.next.next;
  17771. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  17772. triangles.push(a.i / dim);
  17773. triangles.push(p.i / dim);
  17774. triangles.push(b.i / dim); // remove two nodes involved
  17775. removeNode(p);
  17776. removeNode(p.next);
  17777. p = start = b;
  17778. }
  17779. p = p.next;
  17780. } while (p !== start);
  17781. return filterPoints(p);
  17782. } // try splitting polygon into two and triangulate them independently
  17783. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  17784. // look for a valid diagonal that divides the polygon into two
  17785. var a = start;
  17786. do {
  17787. var b = a.next.next;
  17788. while (b !== a.prev) {
  17789. if (a.i !== b.i && isValidDiagonal(a, b)) {
  17790. // split the polygon in two by the diagonal
  17791. var c = splitPolygon(a, b); // filter colinear points around the cuts
  17792. a = filterPoints(a, a.next);
  17793. c = filterPoints(c, c.next); // run earcut on each half
  17794. earcutLinked(a, triangles, dim, minX, minY, invSize);
  17795. earcutLinked(c, triangles, dim, minX, minY, invSize);
  17796. return;
  17797. }
  17798. b = b.next;
  17799. }
  17800. a = a.next;
  17801. } while (a !== start);
  17802. } // link every hole into the outer loop, producing a single-ring polygon without holes
  17803. function eliminateHoles(data, holeIndices, outerNode, dim) {
  17804. var queue = [];
  17805. var i, len, start, end, list;
  17806. for (i = 0, len = holeIndices.length; i < len; i++) {
  17807. start = holeIndices[i] * dim;
  17808. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  17809. list = linkedList(data, start, end, dim, false);
  17810. if (list === list.next) list.steiner = true;
  17811. queue.push(getLeftmost(list));
  17812. }
  17813. queue.sort(compareX); // process holes from left to right
  17814. for (i = 0; i < queue.length; i++) {
  17815. eliminateHole(queue[i], outerNode);
  17816. outerNode = filterPoints(outerNode, outerNode.next);
  17817. }
  17818. return outerNode;
  17819. }
  17820. function compareX(a, b) {
  17821. return a.x - b.x;
  17822. } // find a bridge between vertices that connects hole with an outer ring and and link it
  17823. function eliminateHole(hole, outerNode) {
  17824. outerNode = findHoleBridge(hole, outerNode);
  17825. if (outerNode) {
  17826. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  17827. filterPoints(outerNode, outerNode.next);
  17828. filterPoints(b, b.next);
  17829. }
  17830. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17831. function findHoleBridge(hole, outerNode) {
  17832. var p = outerNode;
  17833. var hx = hole.x;
  17834. var hy = hole.y;
  17835. var qx = -Infinity,
  17836. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  17837. // segment's endpoint with lesser x will be potential connection point
  17838. do {
  17839. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  17840. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  17841. if (x <= hx && x > qx) {
  17842. qx = x;
  17843. if (x === hx) {
  17844. if (hy === p.y) return p;
  17845. if (hy === p.next.y) return p.next;
  17846. }
  17847. m = p.x < p.next.x ? p : p.next;
  17848. }
  17849. }
  17850. p = p.next;
  17851. } while (p !== outerNode);
  17852. if (!m) return null;
  17853. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  17854. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17855. // if there are no points found, we have a valid connection;
  17856. // otherwise choose the point of the minimum angle with the ray as connection point
  17857. var stop = m,
  17858. mx = m.x,
  17859. my = m.y;
  17860. var tanMin = Infinity,
  17861. tan;
  17862. p = m;
  17863. do {
  17864. 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)) {
  17865. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  17866. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  17867. m = p;
  17868. tanMin = tan;
  17869. }
  17870. }
  17871. p = p.next;
  17872. } while (p !== stop);
  17873. return m;
  17874. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  17875. function sectorContainsSector(m, p) {
  17876. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  17877. } // interlink polygon nodes in z-order
  17878. function indexCurve(start, minX, minY, invSize) {
  17879. var p = start;
  17880. do {
  17881. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  17882. p.prevZ = p.prev;
  17883. p.nextZ = p.next;
  17884. p = p.next;
  17885. } while (p !== start);
  17886. p.prevZ.nextZ = null;
  17887. p.prevZ = null;
  17888. sortLinked(p);
  17889. } // Simon Tatham's linked list merge sort algorithm
  17890. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17891. function sortLinked(list) {
  17892. var i,
  17893. p,
  17894. q,
  17895. e,
  17896. tail,
  17897. numMerges,
  17898. pSize,
  17899. qSize,
  17900. inSize = 1;
  17901. do {
  17902. p = list;
  17903. list = null;
  17904. tail = null;
  17905. numMerges = 0;
  17906. while (p) {
  17907. numMerges++;
  17908. q = p;
  17909. pSize = 0;
  17910. for (i = 0; i < inSize; i++) {
  17911. pSize++;
  17912. q = q.nextZ;
  17913. if (!q) break;
  17914. }
  17915. qSize = inSize;
  17916. while (pSize > 0 || qSize > 0 && q) {
  17917. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  17918. e = p;
  17919. p = p.nextZ;
  17920. pSize--;
  17921. } else {
  17922. e = q;
  17923. q = q.nextZ;
  17924. qSize--;
  17925. }
  17926. if (tail) tail.nextZ = e;else list = e;
  17927. e.prevZ = tail;
  17928. tail = e;
  17929. }
  17930. p = q;
  17931. }
  17932. tail.nextZ = null;
  17933. inSize *= 2;
  17934. } while (numMerges > 1);
  17935. return list;
  17936. } // z-order of a point given coords and inverse of the longer side of data bbox
  17937. function zOrder(x, y, minX, minY, invSize) {
  17938. // coords are transformed into non-negative 15-bit integer range
  17939. x = 32767 * (x - minX) * invSize;
  17940. y = 32767 * (y - minY) * invSize;
  17941. x = (x | x << 8) & 0x00FF00FF;
  17942. x = (x | x << 4) & 0x0F0F0F0F;
  17943. x = (x | x << 2) & 0x33333333;
  17944. x = (x | x << 1) & 0x55555555;
  17945. y = (y | y << 8) & 0x00FF00FF;
  17946. y = (y | y << 4) & 0x0F0F0F0F;
  17947. y = (y | y << 2) & 0x33333333;
  17948. y = (y | y << 1) & 0x55555555;
  17949. return x | y << 1;
  17950. } // find the leftmost node of a polygon ring
  17951. function getLeftmost(start) {
  17952. var p = start,
  17953. leftmost = start;
  17954. do {
  17955. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  17956. p = p.next;
  17957. } while (p !== start);
  17958. return leftmost;
  17959. } // check if a point lies within a convex triangle
  17960. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  17961. 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;
  17962. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  17963. function isValidDiagonal(a, b) {
  17964. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  17965. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  17966. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  17967. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  17968. } // signed area of a triangle
  17969. function area(p, q, r) {
  17970. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  17971. } // check if two points are equal
  17972. function equals(p1, p2) {
  17973. return p1.x === p2.x && p1.y === p2.y;
  17974. } // check if two segments intersect
  17975. function intersects(p1, q1, p2, q2) {
  17976. var o1 = sign(area(p1, q1, p2));
  17977. var o2 = sign(area(p1, q1, q2));
  17978. var o3 = sign(area(p2, q2, p1));
  17979. var o4 = sign(area(p2, q2, q1));
  17980. if (o1 !== o2 && o3 !== o4) return true; // general case
  17981. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  17982. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  17983. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  17984. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  17985. return false;
  17986. } // for collinear points p, q, r, check if point q lies on segment pr
  17987. function onSegment(p, q, r) {
  17988. 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);
  17989. }
  17990. function sign(num) {
  17991. return num > 0 ? 1 : num < 0 ? -1 : 0;
  17992. } // check if a polygon diagonal intersects any polygon segments
  17993. function intersectsPolygon(a, b) {
  17994. var p = a;
  17995. do {
  17996. 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;
  17997. p = p.next;
  17998. } while (p !== a);
  17999. return false;
  18000. } // check if a polygon diagonal is locally inside the polygon
  18001. function locallyInside(a, b) {
  18002. 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;
  18003. } // check if the middle point of a polygon diagonal is inside the polygon
  18004. function middleInside(a, b) {
  18005. var p = a,
  18006. inside = false;
  18007. var px = (a.x + b.x) / 2,
  18008. py = (a.y + b.y) / 2;
  18009. do {
  18010. 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;
  18011. p = p.next;
  18012. } while (p !== a);
  18013. return inside;
  18014. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18015. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18016. function splitPolygon(a, b) {
  18017. var a2 = new Node(a.i, a.x, a.y),
  18018. b2 = new Node(b.i, b.x, b.y),
  18019. an = a.next,
  18020. bp = b.prev;
  18021. a.next = b;
  18022. b.prev = a;
  18023. a2.next = an;
  18024. an.prev = a2;
  18025. b2.next = a2;
  18026. a2.prev = b2;
  18027. bp.next = b2;
  18028. b2.prev = bp;
  18029. return b2;
  18030. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18031. function insertNode(i, x, y, last) {
  18032. var p = new Node(i, x, y);
  18033. if (!last) {
  18034. p.prev = p;
  18035. p.next = p;
  18036. } else {
  18037. p.next = last.next;
  18038. p.prev = last;
  18039. last.next.prev = p;
  18040. last.next = p;
  18041. }
  18042. return p;
  18043. }
  18044. function removeNode(p) {
  18045. p.next.prev = p.prev;
  18046. p.prev.next = p.next;
  18047. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18048. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18049. }
  18050. function Node(i, x, y) {
  18051. // vertex index in coordinates array
  18052. this.i = i; // vertex coordinates
  18053. this.x = x;
  18054. this.y = y; // previous and next vertex nodes in a polygon ring
  18055. this.prev = null;
  18056. this.next = null; // z-order curve value
  18057. this.z = null; // previous and next nodes in z-order
  18058. this.prevZ = null;
  18059. this.nextZ = null; // indicates whether this is a steiner point
  18060. this.steiner = false;
  18061. }
  18062. function signedArea(data, start, end, dim) {
  18063. var sum = 0;
  18064. for (var i = start, j = end - dim; i < end; i += dim) {
  18065. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18066. j = i;
  18067. }
  18068. return sum;
  18069. }
  18070. var ShapeUtils = {
  18071. // calculate area of the contour polygon
  18072. area: function area(contour) {
  18073. var n = contour.length;
  18074. var a = 0.0;
  18075. for (var p = n - 1, q = 0; q < n; p = q++) {
  18076. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18077. }
  18078. return a * 0.5;
  18079. },
  18080. isClockWise: function isClockWise(pts) {
  18081. return ShapeUtils.area(pts) < 0;
  18082. },
  18083. triangulateShape: function triangulateShape(contour, holes) {
  18084. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18085. var holeIndices = []; // array of hole indices
  18086. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18087. removeDupEndPts(contour);
  18088. addContour(vertices, contour); //
  18089. var holeIndex = contour.length;
  18090. holes.forEach(removeDupEndPts);
  18091. for (var i = 0; i < holes.length; i++) {
  18092. holeIndices.push(holeIndex);
  18093. holeIndex += holes[i].length;
  18094. addContour(vertices, holes[i]);
  18095. } //
  18096. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18097. for (var _i = 0; _i < triangles.length; _i += 3) {
  18098. faces.push(triangles.slice(_i, _i + 3));
  18099. }
  18100. return faces;
  18101. }
  18102. };
  18103. function removeDupEndPts(points) {
  18104. var l = points.length;
  18105. if (l > 2 && points[l - 1].equals(points[0])) {
  18106. points.pop();
  18107. }
  18108. }
  18109. function addContour(vertices, contour) {
  18110. for (var i = 0; i < contour.length; i++) {
  18111. vertices.push(contour[i].x);
  18112. vertices.push(contour[i].y);
  18113. }
  18114. }
  18115. var ExtrudeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18116. _inheritsLoose(ExtrudeBufferGeometry, _BufferGeometry);
  18117. function ExtrudeBufferGeometry(shapes, options) {
  18118. var _this;
  18119. _this = _BufferGeometry.call(this) || this;
  18120. _this.type = 'ExtrudeBufferGeometry';
  18121. _this.parameters = {
  18122. shapes: shapes,
  18123. options: options
  18124. };
  18125. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18126. var scope = _assertThisInitialized(_this);
  18127. var verticesArray = [];
  18128. var uvArray = [];
  18129. for (var i = 0, l = shapes.length; i < l; i++) {
  18130. var shape = shapes[i];
  18131. addShape(shape);
  18132. } // build geometry
  18133. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18134. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18135. _this.computeVertexNormals(); // functions
  18136. function addShape(shape) {
  18137. var placeholder = []; // options
  18138. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18139. var steps = options.steps !== undefined ? options.steps : 1;
  18140. var depth = options.depth !== undefined ? options.depth : 100;
  18141. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18142. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18143. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18144. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18145. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18146. var extrudePath = options.extrudePath;
  18147. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18148. if (options.amount !== undefined) {
  18149. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18150. depth = options.amount;
  18151. } //
  18152. var extrudePts,
  18153. extrudeByPath = false;
  18154. var splineTube, binormal, normal, position2;
  18155. if (extrudePath) {
  18156. extrudePts = extrudePath.getSpacedPoints(steps);
  18157. extrudeByPath = true;
  18158. bevelEnabled = false; // bevels not supported for path extrusion
  18159. // SETUP TNB variables
  18160. // TODO1 - have a .isClosed in spline?
  18161. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18162. binormal = new Vector3();
  18163. normal = new Vector3();
  18164. position2 = new Vector3();
  18165. } // Safeguards if bevels are not enabled
  18166. if (!bevelEnabled) {
  18167. bevelSegments = 0;
  18168. bevelThickness = 0;
  18169. bevelSize = 0;
  18170. bevelOffset = 0;
  18171. } // Variables initialization
  18172. var shapePoints = shape.extractPoints(curveSegments);
  18173. var vertices = shapePoints.shape;
  18174. var holes = shapePoints.holes;
  18175. var reverse = !ShapeUtils.isClockWise(vertices);
  18176. if (reverse) {
  18177. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18178. for (var h = 0, hl = holes.length; h < hl; h++) {
  18179. var ahole = holes[h];
  18180. if (ShapeUtils.isClockWise(ahole)) {
  18181. holes[h] = ahole.reverse();
  18182. }
  18183. }
  18184. }
  18185. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18186. /* Vertices */
  18187. var contour = vertices; // vertices has all points but contour has only points of circumference
  18188. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18189. var _ahole = holes[_h];
  18190. vertices = vertices.concat(_ahole);
  18191. }
  18192. function scalePt2(pt, vec, size) {
  18193. if (!vec) console.error("THREE.ExtrudeGeometry: vec does not exist");
  18194. return vec.clone().multiplyScalar(size).add(pt);
  18195. }
  18196. var vlen = vertices.length,
  18197. flen = faces.length; // Find directions for point movement
  18198. function getBevelVec(inPt, inPrev, inNext) {
  18199. // computes for inPt the corresponding point inPt' on a new contour
  18200. // shifted by 1 unit (length of normalized vector) to the left
  18201. // if we walk along contour clockwise, this new contour is outside the old one
  18202. //
  18203. // inPt' is the intersection of the two lines parallel to the two
  18204. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18205. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18206. // good reading for geometry algorithms (here: line-line intersection)
  18207. // http://geomalgorithms.com/a05-_intersect-1.html
  18208. var v_prev_x = inPt.x - inPrev.x,
  18209. v_prev_y = inPt.y - inPrev.y;
  18210. var v_next_x = inNext.x - inPt.x,
  18211. v_next_y = inNext.y - inPt.y;
  18212. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18213. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18214. if (Math.abs(collinear0) > Number.EPSILON) {
  18215. // not collinear
  18216. // length of vectors for normalizing
  18217. var v_prev_len = Math.sqrt(v_prev_lensq);
  18218. 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
  18219. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18220. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18221. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18222. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18223. 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
  18224. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18225. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18226. // but prevent crazy spikes
  18227. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18228. if (v_trans_lensq <= 2) {
  18229. return new Vector2(v_trans_x, v_trans_y);
  18230. } else {
  18231. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18232. }
  18233. } else {
  18234. // handle special case of collinear edges
  18235. var direction_eq = false; // assumes: opposite
  18236. if (v_prev_x > Number.EPSILON) {
  18237. if (v_next_x > Number.EPSILON) {
  18238. direction_eq = true;
  18239. }
  18240. } else {
  18241. if (v_prev_x < -Number.EPSILON) {
  18242. if (v_next_x < -Number.EPSILON) {
  18243. direction_eq = true;
  18244. }
  18245. } else {
  18246. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18247. direction_eq = true;
  18248. }
  18249. }
  18250. }
  18251. if (direction_eq) {
  18252. // console.log("Warning: lines are a straight sequence");
  18253. v_trans_x = -v_prev_y;
  18254. v_trans_y = v_prev_x;
  18255. shrink_by = Math.sqrt(v_prev_lensq);
  18256. } else {
  18257. // console.log("Warning: lines are a straight spike");
  18258. v_trans_x = v_prev_x;
  18259. v_trans_y = v_prev_y;
  18260. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18261. }
  18262. }
  18263. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18264. }
  18265. var contourMovements = [];
  18266. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18267. if (j === il) j = 0;
  18268. if (k === il) k = 0; // (j)---(i)---(k)
  18269. // console.log('i,j,k', i, j , k)
  18270. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18271. }
  18272. var holesMovements = [];
  18273. var oneHoleMovements,
  18274. verticesMovements = contourMovements.concat();
  18275. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18276. var _ahole2 = holes[_h2];
  18277. oneHoleMovements = [];
  18278. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18279. if (_j === _il) _j = 0;
  18280. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18281. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18282. }
  18283. holesMovements.push(oneHoleMovements);
  18284. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18285. } // Loop bevelSegments, 1 for the front, 1 for the back
  18286. for (var b = 0; b < bevelSegments; b++) {
  18287. //for ( b = bevelSegments; b > 0; b -- ) {
  18288. var t = b / bevelSegments;
  18289. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18290. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18291. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18292. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18293. v(vert.x, vert.y, -z);
  18294. } // expand holes
  18295. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18296. var _ahole3 = holes[_h3];
  18297. oneHoleMovements = holesMovements[_h3];
  18298. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18299. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18300. v(_vert.x, _vert.y, -z);
  18301. }
  18302. }
  18303. }
  18304. var bs = bevelSize + bevelOffset; // Back facing vertices
  18305. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18306. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18307. if (!extrudeByPath) {
  18308. v(_vert2.x, _vert2.y, 0);
  18309. } else {
  18310. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18311. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18312. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18313. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18314. v(position2.x, position2.y, position2.z);
  18315. }
  18316. } // Add stepped vertices...
  18317. // Including front facing vertices
  18318. for (var s = 1; s <= steps; s++) {
  18319. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18320. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18321. if (!extrudeByPath) {
  18322. v(_vert3.x, _vert3.y, depth / steps * s);
  18323. } else {
  18324. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18325. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18326. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18327. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18328. v(position2.x, position2.y, position2.z);
  18329. }
  18330. }
  18331. } // Add bevel segments planes
  18332. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18333. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18334. var _t = _b / bevelSegments;
  18335. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18336. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18337. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18338. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18339. v(_vert4.x, _vert4.y, depth + _z);
  18340. } // expand holes
  18341. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18342. var _ahole4 = holes[_h4];
  18343. oneHoleMovements = holesMovements[_h4];
  18344. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18345. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18346. if (!extrudeByPath) {
  18347. v(_vert5.x, _vert5.y, depth + _z);
  18348. } else {
  18349. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18350. }
  18351. }
  18352. }
  18353. }
  18354. /* Faces */
  18355. // Top and bottom faces
  18356. buildLidFaces(); // Sides faces
  18357. buildSideFaces(); ///// Internal functions
  18358. function buildLidFaces() {
  18359. var start = verticesArray.length / 3;
  18360. if (bevelEnabled) {
  18361. var layer = 0; // steps + 1
  18362. var offset = vlen * layer; // Bottom faces
  18363. for (var _i9 = 0; _i9 < flen; _i9++) {
  18364. var face = faces[_i9];
  18365. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18366. }
  18367. layer = steps + bevelSegments * 2;
  18368. offset = vlen * layer; // Top faces
  18369. for (var _i10 = 0; _i10 < flen; _i10++) {
  18370. var _face = faces[_i10];
  18371. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18372. }
  18373. } else {
  18374. // Bottom faces
  18375. for (var _i11 = 0; _i11 < flen; _i11++) {
  18376. var _face2 = faces[_i11];
  18377. f3(_face2[2], _face2[1], _face2[0]);
  18378. } // Top faces
  18379. for (var _i12 = 0; _i12 < flen; _i12++) {
  18380. var _face3 = faces[_i12];
  18381. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18382. }
  18383. }
  18384. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18385. } // Create faces for the z-sides of the shape
  18386. function buildSideFaces() {
  18387. var start = verticesArray.length / 3;
  18388. var layeroffset = 0;
  18389. sidewalls(contour, layeroffset);
  18390. layeroffset += contour.length;
  18391. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18392. var _ahole5 = holes[_h5];
  18393. sidewalls(_ahole5, layeroffset); //, true
  18394. layeroffset += _ahole5.length;
  18395. }
  18396. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18397. }
  18398. function sidewalls(contour, layeroffset) {
  18399. var i = contour.length;
  18400. while (--i >= 0) {
  18401. var _j2 = i;
  18402. var _k2 = i - 1;
  18403. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18404. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18405. var slen1 = vlen * _s;
  18406. var slen2 = vlen * (_s + 1);
  18407. var a = layeroffset + _j2 + slen1,
  18408. _b2 = layeroffset + _k2 + slen1,
  18409. c = layeroffset + _k2 + slen2,
  18410. d = layeroffset + _j2 + slen2;
  18411. f4(a, _b2, c, d);
  18412. }
  18413. }
  18414. }
  18415. function v(x, y, z) {
  18416. placeholder.push(x);
  18417. placeholder.push(y);
  18418. placeholder.push(z);
  18419. }
  18420. function f3(a, b, c) {
  18421. addVertex(a);
  18422. addVertex(b);
  18423. addVertex(c);
  18424. var nextIndex = verticesArray.length / 3;
  18425. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18426. addUV(uvs[0]);
  18427. addUV(uvs[1]);
  18428. addUV(uvs[2]);
  18429. }
  18430. function f4(a, b, c, d) {
  18431. addVertex(a);
  18432. addVertex(b);
  18433. addVertex(d);
  18434. addVertex(b);
  18435. addVertex(c);
  18436. addVertex(d);
  18437. var nextIndex = verticesArray.length / 3;
  18438. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18439. addUV(uvs[0]);
  18440. addUV(uvs[1]);
  18441. addUV(uvs[3]);
  18442. addUV(uvs[1]);
  18443. addUV(uvs[2]);
  18444. addUV(uvs[3]);
  18445. }
  18446. function addVertex(index) {
  18447. verticesArray.push(placeholder[index * 3 + 0]);
  18448. verticesArray.push(placeholder[index * 3 + 1]);
  18449. verticesArray.push(placeholder[index * 3 + 2]);
  18450. }
  18451. function addUV(vector2) {
  18452. uvArray.push(vector2.x);
  18453. uvArray.push(vector2.y);
  18454. }
  18455. }
  18456. return _this;
  18457. }
  18458. var _proto = ExtrudeBufferGeometry.prototype;
  18459. _proto.toJSON = function toJSON() {
  18460. var data = BufferGeometry.prototype.toJSON.call(this);
  18461. var shapes = this.parameters.shapes;
  18462. var options = this.parameters.options;
  18463. return _toJSON(shapes, options, data);
  18464. };
  18465. return ExtrudeBufferGeometry;
  18466. }(BufferGeometry);
  18467. var WorldUVGenerator = {
  18468. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18469. var a_x = vertices[indexA * 3];
  18470. var a_y = vertices[indexA * 3 + 1];
  18471. var b_x = vertices[indexB * 3];
  18472. var b_y = vertices[indexB * 3 + 1];
  18473. var c_x = vertices[indexC * 3];
  18474. var c_y = vertices[indexC * 3 + 1];
  18475. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18476. },
  18477. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18478. var a_x = vertices[indexA * 3];
  18479. var a_y = vertices[indexA * 3 + 1];
  18480. var a_z = vertices[indexA * 3 + 2];
  18481. var b_x = vertices[indexB * 3];
  18482. var b_y = vertices[indexB * 3 + 1];
  18483. var b_z = vertices[indexB * 3 + 2];
  18484. var c_x = vertices[indexC * 3];
  18485. var c_y = vertices[indexC * 3 + 1];
  18486. var c_z = vertices[indexC * 3 + 2];
  18487. var d_x = vertices[indexD * 3];
  18488. var d_y = vertices[indexD * 3 + 1];
  18489. var d_z = vertices[indexD * 3 + 2];
  18490. if (Math.abs(a_y - b_y) < 0.01) {
  18491. 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)];
  18492. } else {
  18493. 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)];
  18494. }
  18495. }
  18496. };
  18497. function _toJSON(shapes, options, data) {
  18498. data.shapes = [];
  18499. if (Array.isArray(shapes)) {
  18500. for (var i = 0, l = shapes.length; i < l; i++) {
  18501. var shape = shapes[i];
  18502. data.shapes.push(shape.uuid);
  18503. }
  18504. } else {
  18505. data.shapes.push(shapes.uuid);
  18506. }
  18507. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18508. return data;
  18509. }
  18510. var ExtrudeGeometry = /*#__PURE__*/function (_Geometry) {
  18511. _inheritsLoose(ExtrudeGeometry, _Geometry);
  18512. function ExtrudeGeometry(shapes, options) {
  18513. var _this;
  18514. _this = _Geometry.call(this) || this;
  18515. _this.type = 'ExtrudeGeometry';
  18516. _this.parameters = {
  18517. shapes: shapes,
  18518. options: options
  18519. };
  18520. _this.fromBufferGeometry(new ExtrudeBufferGeometry(shapes, options));
  18521. _this.mergeVertices();
  18522. return _this;
  18523. }
  18524. var _proto = ExtrudeGeometry.prototype;
  18525. _proto.toJSON = function toJSON() {
  18526. var data = _Geometry.prototype.toJSON.call(this);
  18527. var shapes = this.parameters.shapes;
  18528. var options = this.parameters.options;
  18529. return _toJSON$1(shapes, options, data);
  18530. };
  18531. return ExtrudeGeometry;
  18532. }(Geometry);
  18533. function _toJSON$1(shapes, options, data) {
  18534. data.shapes = [];
  18535. if (Array.isArray(shapes)) {
  18536. for (var i = 0, l = shapes.length; i < l; i++) {
  18537. var shape = shapes[i];
  18538. data.shapes.push(shape.uuid);
  18539. }
  18540. } else {
  18541. data.shapes.push(shapes.uuid);
  18542. }
  18543. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18544. return data;
  18545. }
  18546. var IcosahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  18547. _inheritsLoose(IcosahedronBufferGeometry, _PolyhedronBufferGeom);
  18548. function IcosahedronBufferGeometry(radius, detail) {
  18549. var _this;
  18550. var t = (1 + Math.sqrt(5)) / 2;
  18551. 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];
  18552. 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];
  18553. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  18554. _this.type = 'IcosahedronBufferGeometry';
  18555. _this.parameters = {
  18556. radius: radius,
  18557. detail: detail
  18558. };
  18559. return _this;
  18560. }
  18561. return IcosahedronBufferGeometry;
  18562. }(PolyhedronBufferGeometry);
  18563. var IcosahedronGeometry = /*#__PURE__*/function (_Geometry) {
  18564. _inheritsLoose(IcosahedronGeometry, _Geometry);
  18565. function IcosahedronGeometry(radius, detail) {
  18566. var _this;
  18567. _this = _Geometry.call(this) || this;
  18568. _this.type = 'IcosahedronGeometry';
  18569. _this.parameters = {
  18570. radius: radius,
  18571. detail: detail
  18572. };
  18573. _this.fromBufferGeometry(new IcosahedronBufferGeometry(radius, detail));
  18574. _this.mergeVertices();
  18575. return _this;
  18576. }
  18577. return IcosahedronGeometry;
  18578. }(Geometry);
  18579. var LatheBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18580. _inheritsLoose(LatheBufferGeometry, _BufferGeometry);
  18581. function LatheBufferGeometry(points, segments, phiStart, phiLength) {
  18582. var _this;
  18583. _this = _BufferGeometry.call(this) || this;
  18584. _this.type = 'LatheBufferGeometry';
  18585. _this.parameters = {
  18586. points: points,
  18587. segments: segments,
  18588. phiStart: phiStart,
  18589. phiLength: phiLength
  18590. };
  18591. segments = Math.floor(segments) || 12;
  18592. phiStart = phiStart || 0;
  18593. phiLength = phiLength || Math.PI * 2; // clamp phiLength so it's in range of [ 0, 2PI ]
  18594. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  18595. var indices = [];
  18596. var vertices = [];
  18597. var uvs = []; // helper variables
  18598. var inverseSegments = 1.0 / segments;
  18599. var vertex = new Vector3();
  18600. var uv = new Vector2(); // generate vertices and uvs
  18601. for (var i = 0; i <= segments; i++) {
  18602. var phi = phiStart + i * inverseSegments * phiLength;
  18603. var sin = Math.sin(phi);
  18604. var cos = Math.cos(phi);
  18605. for (var j = 0; j <= points.length - 1; j++) {
  18606. // vertex
  18607. vertex.x = points[j].x * sin;
  18608. vertex.y = points[j].y;
  18609. vertex.z = points[j].x * cos;
  18610. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  18611. uv.x = i / segments;
  18612. uv.y = j / (points.length - 1);
  18613. uvs.push(uv.x, uv.y);
  18614. }
  18615. } // indices
  18616. for (var _i = 0; _i < segments; _i++) {
  18617. for (var _j = 0; _j < points.length - 1; _j++) {
  18618. var base = _j + _i * points.length;
  18619. var a = base;
  18620. var b = base + points.length;
  18621. var c = base + points.length + 1;
  18622. var d = base + 1; // faces
  18623. indices.push(a, b, d);
  18624. indices.push(b, c, d);
  18625. }
  18626. } // build geometry
  18627. _this.setIndex(indices);
  18628. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18629. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  18630. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  18631. // because the corresponding vertices are identical (but still have different UVs).
  18632. if (phiLength === Math.PI * 2) {
  18633. var normals = _this.attributes.normal.array;
  18634. var n1 = new Vector3();
  18635. var n2 = new Vector3();
  18636. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  18637. var _base = segments * points.length * 3;
  18638. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  18639. // select the normal of the vertex in the first line
  18640. n1.x = normals[_j2 + 0];
  18641. n1.y = normals[_j2 + 1];
  18642. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  18643. n2.x = normals[_base + _j2 + 0];
  18644. n2.y = normals[_base + _j2 + 1];
  18645. n2.z = normals[_base + _j2 + 2]; // average normals
  18646. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  18647. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  18648. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  18649. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  18650. }
  18651. }
  18652. return _this;
  18653. }
  18654. return LatheBufferGeometry;
  18655. }(BufferGeometry);
  18656. var LatheGeometry = /*#__PURE__*/function (_Geometry) {
  18657. _inheritsLoose(LatheGeometry, _Geometry);
  18658. function LatheGeometry(points, segments, phiStart, phiLength) {
  18659. var _this;
  18660. _this = _Geometry.call(this) || this;
  18661. _this.type = 'LatheGeometry';
  18662. _this.parameters = {
  18663. points: points,
  18664. segments: segments,
  18665. phiStart: phiStart,
  18666. phiLength: phiLength
  18667. };
  18668. _this.fromBufferGeometry(new LatheBufferGeometry(points, segments, phiStart, phiLength));
  18669. _this.mergeVertices();
  18670. return _this;
  18671. }
  18672. return LatheGeometry;
  18673. }(Geometry);
  18674. var OctahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  18675. _inheritsLoose(OctahedronBufferGeometry, _PolyhedronBufferGeom);
  18676. function OctahedronBufferGeometry(radius, detail) {
  18677. var _this;
  18678. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  18679. 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];
  18680. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  18681. _this.type = 'OctahedronBufferGeometry';
  18682. _this.parameters = {
  18683. radius: radius,
  18684. detail: detail
  18685. };
  18686. return _this;
  18687. }
  18688. return OctahedronBufferGeometry;
  18689. }(PolyhedronBufferGeometry);
  18690. var OctahedronGeometry = /*#__PURE__*/function (_Geometry) {
  18691. _inheritsLoose(OctahedronGeometry, _Geometry);
  18692. function OctahedronGeometry(radius, detail) {
  18693. var _this;
  18694. _this = _Geometry.call(this) || this;
  18695. _this.type = 'OctahedronGeometry';
  18696. _this.parameters = {
  18697. radius: radius,
  18698. detail: detail
  18699. };
  18700. _this.fromBufferGeometry(new OctahedronBufferGeometry(radius, detail));
  18701. _this.mergeVertices();
  18702. return _this;
  18703. }
  18704. return OctahedronGeometry;
  18705. }(Geometry);
  18706. /**
  18707. * Parametric Surfaces Geometry
  18708. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18709. */
  18710. function ParametricBufferGeometry(func, slices, stacks) {
  18711. BufferGeometry.call(this);
  18712. this.type = 'ParametricBufferGeometry';
  18713. this.parameters = {
  18714. func: func,
  18715. slices: slices,
  18716. stacks: stacks
  18717. }; // buffers
  18718. var indices = [];
  18719. var vertices = [];
  18720. var normals = [];
  18721. var uvs = [];
  18722. var EPS = 0.00001;
  18723. var normal = new Vector3();
  18724. var p0 = new Vector3(),
  18725. p1 = new Vector3();
  18726. var pu = new Vector3(),
  18727. pv = new Vector3();
  18728. if (func.length < 3) {
  18729. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  18730. } // generate vertices, normals and uvs
  18731. var sliceCount = slices + 1;
  18732. for (var i = 0; i <= stacks; i++) {
  18733. var v = i / stacks;
  18734. for (var j = 0; j <= slices; j++) {
  18735. var u = j / slices; // vertex
  18736. func(u, v, p0);
  18737. vertices.push(p0.x, p0.y, p0.z); // normal
  18738. // approximate tangent vectors via finite differences
  18739. if (u - EPS >= 0) {
  18740. func(u - EPS, v, p1);
  18741. pu.subVectors(p0, p1);
  18742. } else {
  18743. func(u + EPS, v, p1);
  18744. pu.subVectors(p1, p0);
  18745. }
  18746. if (v - EPS >= 0) {
  18747. func(u, v - EPS, p1);
  18748. pv.subVectors(p0, p1);
  18749. } else {
  18750. func(u, v + EPS, p1);
  18751. pv.subVectors(p1, p0);
  18752. } // cross product of tangent vectors returns surface normal
  18753. normal.crossVectors(pu, pv).normalize();
  18754. normals.push(normal.x, normal.y, normal.z); // uv
  18755. uvs.push(u, v);
  18756. }
  18757. } // generate indices
  18758. for (var _i = 0; _i < stacks; _i++) {
  18759. for (var _j = 0; _j < slices; _j++) {
  18760. var a = _i * sliceCount + _j;
  18761. var b = _i * sliceCount + _j + 1;
  18762. var c = (_i + 1) * sliceCount + _j + 1;
  18763. var d = (_i + 1) * sliceCount + _j; // faces one and two
  18764. indices.push(a, b, d);
  18765. indices.push(b, c, d);
  18766. }
  18767. } // build geometry
  18768. this.setIndex(indices);
  18769. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18770. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18771. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18772. }
  18773. ParametricBufferGeometry.prototype = Object.create(BufferGeometry.prototype);
  18774. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  18775. /**
  18776. * Parametric Surfaces Geometry
  18777. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18778. */
  18779. function ParametricGeometry(func, slices, stacks) {
  18780. Geometry.call(this);
  18781. this.type = 'ParametricGeometry';
  18782. this.parameters = {
  18783. func: func,
  18784. slices: slices,
  18785. stacks: stacks
  18786. };
  18787. this.fromBufferGeometry(new ParametricBufferGeometry(func, slices, stacks));
  18788. this.mergeVertices();
  18789. }
  18790. ParametricGeometry.prototype = Object.create(Geometry.prototype);
  18791. ParametricGeometry.prototype.constructor = ParametricGeometry;
  18792. var PlaneGeometry = /*#__PURE__*/function (_Geometry) {
  18793. _inheritsLoose(PlaneGeometry, _Geometry);
  18794. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  18795. var _this;
  18796. _this = _Geometry.call(this) || this;
  18797. _this.type = 'PlaneGeometry';
  18798. _this.parameters = {
  18799. width: width,
  18800. height: height,
  18801. widthSegments: widthSegments,
  18802. heightSegments: heightSegments
  18803. };
  18804. _this.fromBufferGeometry(new PlaneBufferGeometry(width, height, widthSegments, heightSegments));
  18805. _this.mergeVertices();
  18806. return _this;
  18807. }
  18808. return PlaneGeometry;
  18809. }(Geometry);
  18810. var PolyhedronGeometry = /*#__PURE__*/function (_Geometry) {
  18811. _inheritsLoose(PolyhedronGeometry, _Geometry);
  18812. function PolyhedronGeometry(vertices, indices, radius, detail) {
  18813. var _this;
  18814. _this = _Geometry.call(this) || this;
  18815. _this.type = 'PolyhedronGeometry';
  18816. _this.parameters = {
  18817. vertices: vertices,
  18818. indices: indices,
  18819. radius: radius,
  18820. detail: detail
  18821. };
  18822. _this.fromBufferGeometry(new PolyhedronBufferGeometry(vertices, indices, radius, detail));
  18823. _this.mergeVertices();
  18824. return _this;
  18825. }
  18826. return PolyhedronGeometry;
  18827. }(Geometry);
  18828. var RingBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18829. _inheritsLoose(RingBufferGeometry, _BufferGeometry);
  18830. function RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18831. var _this;
  18832. _this = _BufferGeometry.call(this) || this;
  18833. _this.type = 'RingBufferGeometry';
  18834. _this.parameters = {
  18835. innerRadius: innerRadius,
  18836. outerRadius: outerRadius,
  18837. thetaSegments: thetaSegments,
  18838. phiSegments: phiSegments,
  18839. thetaStart: thetaStart,
  18840. thetaLength: thetaLength
  18841. };
  18842. innerRadius = innerRadius || 0.5;
  18843. outerRadius = outerRadius || 1;
  18844. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18845. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18846. thetaSegments = thetaSegments !== undefined ? Math.max(3, thetaSegments) : 8;
  18847. phiSegments = phiSegments !== undefined ? Math.max(1, phiSegments) : 1; // buffers
  18848. var indices = [];
  18849. var vertices = [];
  18850. var normals = [];
  18851. var uvs = []; // some helper variables
  18852. var radius = innerRadius;
  18853. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  18854. var vertex = new Vector3();
  18855. var uv = new Vector2(); // generate vertices, normals and uvs
  18856. for (var j = 0; j <= phiSegments; j++) {
  18857. for (var i = 0; i <= thetaSegments; i++) {
  18858. // values are generate from the inside of the ring to the outside
  18859. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  18860. vertex.x = radius * Math.cos(segment);
  18861. vertex.y = radius * Math.sin(segment);
  18862. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  18863. normals.push(0, 0, 1); // uv
  18864. uv.x = (vertex.x / outerRadius + 1) / 2;
  18865. uv.y = (vertex.y / outerRadius + 1) / 2;
  18866. uvs.push(uv.x, uv.y);
  18867. } // increase the radius for next row of vertices
  18868. radius += radiusStep;
  18869. } // indices
  18870. for (var _j = 0; _j < phiSegments; _j++) {
  18871. var thetaSegmentLevel = _j * (thetaSegments + 1);
  18872. for (var _i = 0; _i < thetaSegments; _i++) {
  18873. var _segment = _i + thetaSegmentLevel;
  18874. var a = _segment;
  18875. var b = _segment + thetaSegments + 1;
  18876. var c = _segment + thetaSegments + 2;
  18877. var d = _segment + 1; // faces
  18878. indices.push(a, b, d);
  18879. indices.push(b, c, d);
  18880. }
  18881. } // build geometry
  18882. _this.setIndex(indices);
  18883. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18884. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18885. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18886. return _this;
  18887. }
  18888. return RingBufferGeometry;
  18889. }(BufferGeometry);
  18890. var RingGeometry = /*#__PURE__*/function (_Geometry) {
  18891. _inheritsLoose(RingGeometry, _Geometry);
  18892. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18893. var _this;
  18894. _this = _Geometry.call(this) || this;
  18895. _this.type = 'RingGeometry';
  18896. _this.parameters = {
  18897. innerRadius: innerRadius,
  18898. outerRadius: outerRadius,
  18899. thetaSegments: thetaSegments,
  18900. phiSegments: phiSegments,
  18901. thetaStart: thetaStart,
  18902. thetaLength: thetaLength
  18903. };
  18904. _this.fromBufferGeometry(new RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength));
  18905. _this.mergeVertices();
  18906. return _this;
  18907. }
  18908. return RingGeometry;
  18909. }(Geometry);
  18910. var ShapeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18911. _inheritsLoose(ShapeBufferGeometry, _BufferGeometry);
  18912. function ShapeBufferGeometry(shapes, curveSegments) {
  18913. var _this;
  18914. _this = _BufferGeometry.call(this) || this;
  18915. _this.type = 'ShapeBufferGeometry';
  18916. _this.parameters = {
  18917. shapes: shapes,
  18918. curveSegments: curveSegments
  18919. };
  18920. curveSegments = curveSegments || 12; // buffers
  18921. var indices = [];
  18922. var vertices = [];
  18923. var normals = [];
  18924. var uvs = []; // helper variables
  18925. var groupStart = 0;
  18926. var groupCount = 0; // allow single and array values for "shapes" parameter
  18927. if (Array.isArray(shapes) === false) {
  18928. addShape(shapes);
  18929. } else {
  18930. for (var i = 0; i < shapes.length; i++) {
  18931. addShape(shapes[i]);
  18932. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  18933. groupStart += groupCount;
  18934. groupCount = 0;
  18935. }
  18936. } // build geometry
  18937. _this.setIndex(indices);
  18938. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18939. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18940. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  18941. function addShape(shape) {
  18942. var indexOffset = vertices.length / 3;
  18943. var points = shape.extractPoints(curveSegments);
  18944. var shapeVertices = points.shape;
  18945. var shapeHoles = points.holes; // check direction of vertices
  18946. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  18947. shapeVertices = shapeVertices.reverse();
  18948. }
  18949. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  18950. var shapeHole = shapeHoles[_i];
  18951. if (ShapeUtils.isClockWise(shapeHole) === true) {
  18952. shapeHoles[_i] = shapeHole.reverse();
  18953. }
  18954. }
  18955. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  18956. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  18957. var _shapeHole = shapeHoles[_i2];
  18958. shapeVertices = shapeVertices.concat(_shapeHole);
  18959. } // vertices, normals, uvs
  18960. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  18961. var vertex = shapeVertices[_i3];
  18962. vertices.push(vertex.x, vertex.y, 0);
  18963. normals.push(0, 0, 1);
  18964. uvs.push(vertex.x, vertex.y); // world uvs
  18965. } // incides
  18966. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  18967. var face = faces[_i4];
  18968. var a = face[0] + indexOffset;
  18969. var b = face[1] + indexOffset;
  18970. var c = face[2] + indexOffset;
  18971. indices.push(a, b, c);
  18972. groupCount += 3;
  18973. }
  18974. }
  18975. return _this;
  18976. }
  18977. var _proto = ShapeBufferGeometry.prototype;
  18978. _proto.toJSON = function toJSON() {
  18979. var data = BufferGeometry.prototype.toJSON.call(this);
  18980. var shapes = this.parameters.shapes;
  18981. return _toJSON$2(shapes, data);
  18982. };
  18983. return ShapeBufferGeometry;
  18984. }(BufferGeometry);
  18985. function _toJSON$2(shapes, data) {
  18986. data.shapes = [];
  18987. if (Array.isArray(shapes)) {
  18988. for (var i = 0, l = shapes.length; i < l; i++) {
  18989. var shape = shapes[i];
  18990. data.shapes.push(shape.uuid);
  18991. }
  18992. } else {
  18993. data.shapes.push(shapes.uuid);
  18994. }
  18995. return data;
  18996. }
  18997. var ShapeGeometry = /*#__PURE__*/function (_Geometry) {
  18998. _inheritsLoose(ShapeGeometry, _Geometry);
  18999. function ShapeGeometry(shapes, curveSegments) {
  19000. var _this;
  19001. _this = _Geometry.call(this) || this;
  19002. _this.type = 'ShapeGeometry';
  19003. if (typeof curveSegments === 'object') {
  19004. console.warn('THREE.ShapeGeometry: Options parameter has been removed.');
  19005. curveSegments = curveSegments.curveSegments;
  19006. }
  19007. _this.parameters = {
  19008. shapes: shapes,
  19009. curveSegments: curveSegments
  19010. };
  19011. _this.fromBufferGeometry(new ShapeBufferGeometry(shapes, curveSegments));
  19012. _this.mergeVertices();
  19013. return _this;
  19014. }
  19015. var _proto = ShapeGeometry.prototype;
  19016. _proto.toJSON = function toJSON() {
  19017. var data = Geometry.prototype.toJSON.call(this);
  19018. var shapes = this.parameters.shapes;
  19019. return _toJSON$3(shapes, data);
  19020. };
  19021. return ShapeGeometry;
  19022. }(Geometry);
  19023. function _toJSON$3(shapes, data) {
  19024. data.shapes = [];
  19025. if (Array.isArray(shapes)) {
  19026. for (var i = 0, l = shapes.length; i < l; i++) {
  19027. var shape = shapes[i];
  19028. data.shapes.push(shape.uuid);
  19029. }
  19030. } else {
  19031. data.shapes.push(shapes.uuid);
  19032. }
  19033. return data;
  19034. }
  19035. var SphereBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19036. _inheritsLoose(SphereBufferGeometry, _BufferGeometry);
  19037. function SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19038. var _this;
  19039. _this = _BufferGeometry.call(this) || this;
  19040. _this.type = 'SphereBufferGeometry';
  19041. _this.parameters = {
  19042. radius: radius,
  19043. widthSegments: widthSegments,
  19044. heightSegments: heightSegments,
  19045. phiStart: phiStart,
  19046. phiLength: phiLength,
  19047. thetaStart: thetaStart,
  19048. thetaLength: thetaLength
  19049. };
  19050. radius = radius || 1;
  19051. widthSegments = Math.max(3, Math.floor(widthSegments) || 8);
  19052. heightSegments = Math.max(2, Math.floor(heightSegments) || 6);
  19053. phiStart = phiStart !== undefined ? phiStart : 0;
  19054. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19055. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19056. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19057. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19058. var index = 0;
  19059. var grid = [];
  19060. var vertex = new Vector3();
  19061. var normal = new Vector3(); // buffers
  19062. var indices = [];
  19063. var vertices = [];
  19064. var normals = [];
  19065. var uvs = []; // generate vertices, normals and uvs
  19066. for (var iy = 0; iy <= heightSegments; iy++) {
  19067. var verticesRow = [];
  19068. var v = iy / heightSegments; // special case for the poles
  19069. var uOffset = 0;
  19070. if (iy == 0 && thetaStart == 0) {
  19071. uOffset = 0.5 / widthSegments;
  19072. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19073. uOffset = -0.5 / widthSegments;
  19074. }
  19075. for (var ix = 0; ix <= widthSegments; ix++) {
  19076. var u = ix / widthSegments; // vertex
  19077. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19078. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19079. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19080. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19081. normal.copy(vertex).normalize();
  19082. normals.push(normal.x, normal.y, normal.z); // uv
  19083. uvs.push(u + uOffset, 1 - v);
  19084. verticesRow.push(index++);
  19085. }
  19086. grid.push(verticesRow);
  19087. } // indices
  19088. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19089. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19090. var a = grid[_iy][_ix + 1];
  19091. var b = grid[_iy][_ix];
  19092. var c = grid[_iy + 1][_ix];
  19093. var d = grid[_iy + 1][_ix + 1];
  19094. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19095. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19096. }
  19097. } // build geometry
  19098. _this.setIndex(indices);
  19099. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19100. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19101. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19102. return _this;
  19103. }
  19104. return SphereBufferGeometry;
  19105. }(BufferGeometry);
  19106. var SphereGeometry = /*#__PURE__*/function (_Geometry) {
  19107. _inheritsLoose(SphereGeometry, _Geometry);
  19108. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19109. var _this;
  19110. _this = _Geometry.call(this) || this;
  19111. _this.type = 'SphereGeometry';
  19112. _this.parameters = {
  19113. radius: radius,
  19114. widthSegments: widthSegments,
  19115. heightSegments: heightSegments,
  19116. phiStart: phiStart,
  19117. phiLength: phiLength,
  19118. thetaStart: thetaStart,
  19119. thetaLength: thetaLength
  19120. };
  19121. _this.fromBufferGeometry(new SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength));
  19122. _this.mergeVertices();
  19123. return _this;
  19124. }
  19125. return SphereGeometry;
  19126. }(Geometry);
  19127. var TetrahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  19128. _inheritsLoose(TetrahedronBufferGeometry, _PolyhedronBufferGeom);
  19129. function TetrahedronBufferGeometry(radius, detail) {
  19130. var _this;
  19131. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19132. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19133. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  19134. _this.type = 'TetrahedronBufferGeometry';
  19135. _this.parameters = {
  19136. radius: radius,
  19137. detail: detail
  19138. };
  19139. return _this;
  19140. }
  19141. return TetrahedronBufferGeometry;
  19142. }(PolyhedronBufferGeometry);
  19143. var TetrahedronGeometry = /*#__PURE__*/function (_Geometry) {
  19144. _inheritsLoose(TetrahedronGeometry, _Geometry);
  19145. function TetrahedronGeometry(radius, detail) {
  19146. var _this;
  19147. _this = _Geometry.call(this) || this;
  19148. _this.type = 'TetrahedronGeometry';
  19149. _this.parameters = {
  19150. radius: radius,
  19151. detail: detail
  19152. };
  19153. _this.fromBufferGeometry(new TetrahedronBufferGeometry(radius, detail));
  19154. _this.mergeVertices();
  19155. return _this;
  19156. }
  19157. return TetrahedronGeometry;
  19158. }(Geometry);
  19159. var TextBufferGeometry = /*#__PURE__*/function (_ExtrudeBufferGeometr) {
  19160. _inheritsLoose(TextBufferGeometry, _ExtrudeBufferGeometr);
  19161. function TextBufferGeometry(text, parameters) {
  19162. var _this;
  19163. parameters = parameters || {};
  19164. var font = parameters.font;
  19165. if (!(font && font.isFont)) {
  19166. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19167. return new BufferGeometry() || _assertThisInitialized(_this);
  19168. }
  19169. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19170. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19171. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19172. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19173. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19174. _this = _ExtrudeBufferGeometr.call(this, shapes, parameters) || this;
  19175. _this.type = 'TextBufferGeometry';
  19176. return _this;
  19177. }
  19178. return TextBufferGeometry;
  19179. }(ExtrudeBufferGeometry);
  19180. var TextGeometry = /*#__PURE__*/function (_Geometry) {
  19181. _inheritsLoose(TextGeometry, _Geometry);
  19182. function TextGeometry(text, parameters) {
  19183. var _this;
  19184. _this = _Geometry.call(this) || this;
  19185. _this.type = 'TextGeometry';
  19186. _this.parameters = {
  19187. text: text,
  19188. parameters: parameters
  19189. };
  19190. _this.fromBufferGeometry(new TextBufferGeometry(text, parameters));
  19191. _this.mergeVertices();
  19192. return _this;
  19193. }
  19194. return TextGeometry;
  19195. }(Geometry);
  19196. var TorusBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19197. _inheritsLoose(TorusBufferGeometry, _BufferGeometry);
  19198. function TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19199. var _this;
  19200. _this = _BufferGeometry.call(this) || this;
  19201. _this.type = 'TorusBufferGeometry';
  19202. _this.parameters = {
  19203. radius: radius,
  19204. tube: tube,
  19205. radialSegments: radialSegments,
  19206. tubularSegments: tubularSegments,
  19207. arc: arc
  19208. };
  19209. radius = radius || 1;
  19210. tube = tube || 0.4;
  19211. radialSegments = Math.floor(radialSegments) || 8;
  19212. tubularSegments = Math.floor(tubularSegments) || 6;
  19213. arc = arc || Math.PI * 2; // buffers
  19214. var indices = [];
  19215. var vertices = [];
  19216. var normals = [];
  19217. var uvs = []; // helper variables
  19218. var center = new Vector3();
  19219. var vertex = new Vector3();
  19220. var normal = new Vector3(); // generate vertices, normals and uvs
  19221. for (var j = 0; j <= radialSegments; j++) {
  19222. for (var i = 0; i <= tubularSegments; i++) {
  19223. var u = i / tubularSegments * arc;
  19224. var v = j / radialSegments * Math.PI * 2; // vertex
  19225. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19226. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19227. vertex.z = tube * Math.sin(v);
  19228. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19229. center.x = radius * Math.cos(u);
  19230. center.y = radius * Math.sin(u);
  19231. normal.subVectors(vertex, center).normalize();
  19232. normals.push(normal.x, normal.y, normal.z); // uv
  19233. uvs.push(i / tubularSegments);
  19234. uvs.push(j / radialSegments);
  19235. }
  19236. } // generate indices
  19237. for (var _j = 1; _j <= radialSegments; _j++) {
  19238. for (var _i = 1; _i <= tubularSegments; _i++) {
  19239. // indices
  19240. var a = (tubularSegments + 1) * _j + _i - 1;
  19241. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19242. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19243. var d = (tubularSegments + 1) * _j + _i; // faces
  19244. indices.push(a, b, d);
  19245. indices.push(b, c, d);
  19246. }
  19247. } // build geometry
  19248. _this.setIndex(indices);
  19249. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19250. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19251. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19252. return _this;
  19253. }
  19254. return TorusBufferGeometry;
  19255. }(BufferGeometry);
  19256. var TorusGeometry = /*#__PURE__*/function (_Geometry) {
  19257. _inheritsLoose(TorusGeometry, _Geometry);
  19258. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19259. var _this;
  19260. _this = _Geometry.call(this) || this;
  19261. _this.type = 'TorusGeometry';
  19262. _this.parameters = {
  19263. radius: radius,
  19264. tube: tube,
  19265. radialSegments: radialSegments,
  19266. tubularSegments: tubularSegments,
  19267. arc: arc
  19268. };
  19269. _this.fromBufferGeometry(new TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc));
  19270. _this.mergeVertices();
  19271. return _this;
  19272. }
  19273. return TorusGeometry;
  19274. }(Geometry);
  19275. var TorusKnotBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19276. _inheritsLoose(TorusKnotBufferGeometry, _BufferGeometry);
  19277. function TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19278. var _this;
  19279. _this = _BufferGeometry.call(this) || this;
  19280. _this.type = 'TorusKnotBufferGeometry';
  19281. _this.parameters = {
  19282. radius: radius,
  19283. tube: tube,
  19284. tubularSegments: tubularSegments,
  19285. radialSegments: radialSegments,
  19286. p: p,
  19287. q: q
  19288. };
  19289. radius = radius || 1;
  19290. tube = tube || 0.4;
  19291. tubularSegments = Math.floor(tubularSegments) || 64;
  19292. radialSegments = Math.floor(radialSegments) || 8;
  19293. p = p || 2;
  19294. q = q || 3; // buffers
  19295. var indices = [];
  19296. var vertices = [];
  19297. var normals = [];
  19298. var uvs = []; // helper variables
  19299. var vertex = new Vector3();
  19300. var normal = new Vector3();
  19301. var P1 = new Vector3();
  19302. var P2 = new Vector3();
  19303. var B = new Vector3();
  19304. var T = new Vector3();
  19305. var N = new Vector3(); // generate vertices, normals and uvs
  19306. for (var i = 0; i <= tubularSegments; ++i) {
  19307. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19308. 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.
  19309. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19310. calculatePositionOnCurve(u, p, q, radius, P1);
  19311. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19312. T.subVectors(P2, P1);
  19313. N.addVectors(P2, P1);
  19314. B.crossVectors(T, N);
  19315. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19316. B.normalize();
  19317. N.normalize();
  19318. for (var j = 0; j <= radialSegments; ++j) {
  19319. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19320. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19321. var v = j / radialSegments * Math.PI * 2;
  19322. var cx = -tube * Math.cos(v);
  19323. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19324. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19325. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19326. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19327. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19328. 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)
  19329. normal.subVectors(vertex, P1).normalize();
  19330. normals.push(normal.x, normal.y, normal.z); // uv
  19331. uvs.push(i / tubularSegments);
  19332. uvs.push(j / radialSegments);
  19333. }
  19334. } // generate indices
  19335. for (var _j = 1; _j <= tubularSegments; _j++) {
  19336. for (var _i = 1; _i <= radialSegments; _i++) {
  19337. // indices
  19338. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19339. var b = (radialSegments + 1) * _j + (_i - 1);
  19340. var c = (radialSegments + 1) * _j + _i;
  19341. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19342. indices.push(a, b, d);
  19343. indices.push(b, c, d);
  19344. }
  19345. } // build geometry
  19346. _this.setIndex(indices);
  19347. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19348. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19349. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19350. function calculatePositionOnCurve(u, p, q, radius, position) {
  19351. var cu = Math.cos(u);
  19352. var su = Math.sin(u);
  19353. var quOverP = q / p * u;
  19354. var cs = Math.cos(quOverP);
  19355. position.x = radius * (2 + cs) * 0.5 * cu;
  19356. position.y = radius * (2 + cs) * su * 0.5;
  19357. position.z = radius * Math.sin(quOverP) * 0.5;
  19358. }
  19359. return _this;
  19360. }
  19361. return TorusKnotBufferGeometry;
  19362. }(BufferGeometry);
  19363. var TorusKnotGeometry = /*#__PURE__*/function (_Geometry) {
  19364. _inheritsLoose(TorusKnotGeometry, _Geometry);
  19365. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q, heightScale) {
  19366. var _this;
  19367. _this = _Geometry.call(this) || this;
  19368. _this.type = 'TorusKnotGeometry';
  19369. _this.parameters = {
  19370. radius: radius,
  19371. tube: tube,
  19372. tubularSegments: tubularSegments,
  19373. radialSegments: radialSegments,
  19374. p: p,
  19375. q: q
  19376. };
  19377. if (heightScale !== undefined) console.warn('THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.');
  19378. _this.fromBufferGeometry(new TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q));
  19379. _this.mergeVertices();
  19380. return _this;
  19381. }
  19382. return TorusKnotGeometry;
  19383. }(Geometry);
  19384. var TubeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19385. _inheritsLoose(TubeBufferGeometry, _BufferGeometry);
  19386. function TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19387. var _this;
  19388. _this = _BufferGeometry.call(this) || this;
  19389. _this.type = 'TubeBufferGeometry';
  19390. _this.parameters = {
  19391. path: path,
  19392. tubularSegments: tubularSegments,
  19393. radius: radius,
  19394. radialSegments: radialSegments,
  19395. closed: closed
  19396. };
  19397. tubularSegments = tubularSegments || 64;
  19398. radius = radius || 1;
  19399. radialSegments = radialSegments || 8;
  19400. closed = closed || false;
  19401. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19402. _this.tangents = frames.tangents;
  19403. _this.normals = frames.normals;
  19404. _this.binormals = frames.binormals; // helper variables
  19405. var vertex = new Vector3();
  19406. var normal = new Vector3();
  19407. var uv = new Vector2();
  19408. var P = new Vector3(); // buffer
  19409. var vertices = [];
  19410. var normals = [];
  19411. var uvs = [];
  19412. var indices = []; // create buffer data
  19413. generateBufferData(); // build geometry
  19414. _this.setIndex(indices);
  19415. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19416. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19417. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19418. function generateBufferData() {
  19419. for (var i = 0; i < tubularSegments; i++) {
  19420. generateSegment(i);
  19421. } // if the geometry is not closed, generate the last row of vertices and normals
  19422. // at the regular position on the given path
  19423. //
  19424. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19425. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19426. // this makes it easy compute correct values for closed geometries
  19427. generateUVs(); // finally create faces
  19428. generateIndices();
  19429. }
  19430. function generateSegment(i) {
  19431. // we use getPointAt to sample evenly distributed points from the given path
  19432. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19433. var N = frames.normals[i];
  19434. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19435. for (var j = 0; j <= radialSegments; j++) {
  19436. var v = j / radialSegments * Math.PI * 2;
  19437. var sin = Math.sin(v);
  19438. var cos = -Math.cos(v); // normal
  19439. normal.x = cos * N.x + sin * B.x;
  19440. normal.y = cos * N.y + sin * B.y;
  19441. normal.z = cos * N.z + sin * B.z;
  19442. normal.normalize();
  19443. normals.push(normal.x, normal.y, normal.z); // vertex
  19444. vertex.x = P.x + radius * normal.x;
  19445. vertex.y = P.y + radius * normal.y;
  19446. vertex.z = P.z + radius * normal.z;
  19447. vertices.push(vertex.x, vertex.y, vertex.z);
  19448. }
  19449. }
  19450. function generateIndices() {
  19451. for (var j = 1; j <= tubularSegments; j++) {
  19452. for (var i = 1; i <= radialSegments; i++) {
  19453. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  19454. var b = (radialSegments + 1) * j + (i - 1);
  19455. var c = (radialSegments + 1) * j + i;
  19456. var d = (radialSegments + 1) * (j - 1) + i; // faces
  19457. indices.push(a, b, d);
  19458. indices.push(b, c, d);
  19459. }
  19460. }
  19461. }
  19462. function generateUVs() {
  19463. for (var i = 0; i <= tubularSegments; i++) {
  19464. for (var j = 0; j <= radialSegments; j++) {
  19465. uv.x = i / tubularSegments;
  19466. uv.y = j / radialSegments;
  19467. uvs.push(uv.x, uv.y);
  19468. }
  19469. }
  19470. }
  19471. return _this;
  19472. }
  19473. var _proto = TubeBufferGeometry.prototype;
  19474. _proto.toJSON = function toJSON() {
  19475. var data = BufferGeometry.prototype.toJSON.call(this);
  19476. data.path = this.parameters.path.toJSON();
  19477. return data;
  19478. };
  19479. return TubeBufferGeometry;
  19480. }(BufferGeometry);
  19481. var TubeGeometry = /*#__PURE__*/function (_Geometry) {
  19482. _inheritsLoose(TubeGeometry, _Geometry);
  19483. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed, taper) {
  19484. var _this;
  19485. _this = _Geometry.call(this) || this;
  19486. _this.type = 'TubeGeometry';
  19487. _this.parameters = {
  19488. path: path,
  19489. tubularSegments: tubularSegments,
  19490. radius: radius,
  19491. radialSegments: radialSegments,
  19492. closed: closed
  19493. };
  19494. if (taper !== undefined) console.warn('THREE.TubeGeometry: taper has been removed.');
  19495. var bufferGeometry = new TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed); // expose internals
  19496. _this.tangents = bufferGeometry.tangents;
  19497. _this.normals = bufferGeometry.normals;
  19498. _this.binormals = bufferGeometry.binormals; // create geometry
  19499. _this.fromBufferGeometry(bufferGeometry);
  19500. _this.mergeVertices();
  19501. return _this;
  19502. }
  19503. return TubeGeometry;
  19504. }(Geometry);
  19505. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19506. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  19507. function WireframeGeometry(geometry) {
  19508. var _this;
  19509. _this = _BufferGeometry.call(this) || this;
  19510. _this.type = 'WireframeGeometry'; // buffer
  19511. var vertices = []; // helper variables
  19512. var edge = [0, 0],
  19513. edges = {};
  19514. var keys = ['a', 'b', 'c']; // different logic for Geometry and BufferGeometry
  19515. if (geometry && geometry.isGeometry) {
  19516. // create a data structure that contains all edges without duplicates
  19517. var faces = geometry.faces;
  19518. for (var i = 0, l = faces.length; i < l; i++) {
  19519. var face = faces[i];
  19520. for (var j = 0; j < 3; j++) {
  19521. var edge1 = face[keys[j]];
  19522. var edge2 = face[keys[(j + 1) % 3]];
  19523. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  19524. edge[1] = Math.max(edge1, edge2);
  19525. var key = edge[0] + ',' + edge[1];
  19526. if (edges[key] === undefined) {
  19527. edges[key] = {
  19528. index1: edge[0],
  19529. index2: edge[1]
  19530. };
  19531. }
  19532. }
  19533. } // generate vertices
  19534. for (var _key in edges) {
  19535. var e = edges[_key];
  19536. var vertex = geometry.vertices[e.index1];
  19537. vertices.push(vertex.x, vertex.y, vertex.z);
  19538. vertex = geometry.vertices[e.index2];
  19539. vertices.push(vertex.x, vertex.y, vertex.z);
  19540. }
  19541. } else if (geometry && geometry.isBufferGeometry) {
  19542. var _vertex = new Vector3();
  19543. if (geometry.index !== null) {
  19544. // indexed BufferGeometry
  19545. var position = geometry.attributes.position;
  19546. var indices = geometry.index;
  19547. var groups = geometry.groups;
  19548. if (groups.length === 0) {
  19549. groups = [{
  19550. start: 0,
  19551. count: indices.count,
  19552. materialIndex: 0
  19553. }];
  19554. } // create a data structure that contains all eges without duplicates
  19555. for (var o = 0, ol = groups.length; o < ol; ++o) {
  19556. var group = groups[o];
  19557. var start = group.start;
  19558. var count = group.count;
  19559. for (var _i = start, _l = start + count; _i < _l; _i += 3) {
  19560. for (var _j = 0; _j < 3; _j++) {
  19561. var _edge = indices.getX(_i + _j);
  19562. var _edge2 = indices.getX(_i + (_j + 1) % 3);
  19563. edge[0] = Math.min(_edge, _edge2); // sorting prevents duplicates
  19564. edge[1] = Math.max(_edge, _edge2);
  19565. var _key2 = edge[0] + ',' + edge[1];
  19566. if (edges[_key2] === undefined) {
  19567. edges[_key2] = {
  19568. index1: edge[0],
  19569. index2: edge[1]
  19570. };
  19571. }
  19572. }
  19573. }
  19574. } // generate vertices
  19575. for (var _key3 in edges) {
  19576. var _e = edges[_key3];
  19577. _vertex.fromBufferAttribute(position, _e.index1);
  19578. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19579. _vertex.fromBufferAttribute(position, _e.index2);
  19580. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19581. }
  19582. } else {
  19583. // non-indexed BufferGeometry
  19584. var _position = geometry.attributes.position;
  19585. for (var _i2 = 0, _l2 = _position.count / 3; _i2 < _l2; _i2++) {
  19586. for (var _j2 = 0; _j2 < 3; _j2++) {
  19587. // three edges per triangle, an edge is represented as (index1, index2)
  19588. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  19589. var index1 = 3 * _i2 + _j2;
  19590. _vertex.fromBufferAttribute(_position, index1);
  19591. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19592. var index2 = 3 * _i2 + (_j2 + 1) % 3;
  19593. _vertex.fromBufferAttribute(_position, index2);
  19594. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19595. }
  19596. }
  19597. }
  19598. } // build geometry
  19599. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19600. return _this;
  19601. }
  19602. return WireframeGeometry;
  19603. }(BufferGeometry);
  19604. var Geometries = /*#__PURE__*/Object.freeze({
  19605. __proto__: null,
  19606. BoxGeometry: BoxGeometry,
  19607. BoxBufferGeometry: BoxBufferGeometry,
  19608. CircleGeometry: CircleGeometry,
  19609. CircleBufferGeometry: CircleBufferGeometry,
  19610. ConeGeometry: ConeGeometry,
  19611. ConeBufferGeometry: ConeBufferGeometry,
  19612. CylinderGeometry: CylinderGeometry,
  19613. CylinderBufferGeometry: CylinderBufferGeometry,
  19614. DodecahedronGeometry: DodecahedronGeometry,
  19615. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  19616. EdgesGeometry: EdgesGeometry,
  19617. ExtrudeGeometry: ExtrudeGeometry,
  19618. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  19619. IcosahedronGeometry: IcosahedronGeometry,
  19620. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  19621. LatheGeometry: LatheGeometry,
  19622. LatheBufferGeometry: LatheBufferGeometry,
  19623. OctahedronGeometry: OctahedronGeometry,
  19624. OctahedronBufferGeometry: OctahedronBufferGeometry,
  19625. ParametricGeometry: ParametricGeometry,
  19626. ParametricBufferGeometry: ParametricBufferGeometry,
  19627. PlaneGeometry: PlaneGeometry,
  19628. PlaneBufferGeometry: PlaneBufferGeometry,
  19629. PolyhedronGeometry: PolyhedronGeometry,
  19630. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  19631. RingGeometry: RingGeometry,
  19632. RingBufferGeometry: RingBufferGeometry,
  19633. ShapeGeometry: ShapeGeometry,
  19634. ShapeBufferGeometry: ShapeBufferGeometry,
  19635. SphereGeometry: SphereGeometry,
  19636. SphereBufferGeometry: SphereBufferGeometry,
  19637. TetrahedronGeometry: TetrahedronGeometry,
  19638. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  19639. TextGeometry: TextGeometry,
  19640. TextBufferGeometry: TextBufferGeometry,
  19641. TorusGeometry: TorusGeometry,
  19642. TorusBufferGeometry: TorusBufferGeometry,
  19643. TorusKnotGeometry: TorusKnotGeometry,
  19644. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  19645. TubeGeometry: TubeGeometry,
  19646. TubeBufferGeometry: TubeBufferGeometry,
  19647. WireframeGeometry: WireframeGeometry
  19648. });
  19649. /**
  19650. * parameters = {
  19651. * color: <THREE.Color>
  19652. * }
  19653. */
  19654. function ShadowMaterial(parameters) {
  19655. Material.call(this);
  19656. this.type = 'ShadowMaterial';
  19657. this.color = new Color(0x000000);
  19658. this.transparent = true;
  19659. this.setValues(parameters);
  19660. }
  19661. ShadowMaterial.prototype = Object.create(Material.prototype);
  19662. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19663. ShadowMaterial.prototype.isShadowMaterial = true;
  19664. ShadowMaterial.prototype.copy = function (source) {
  19665. Material.prototype.copy.call(this, source);
  19666. this.color.copy(source.color);
  19667. return this;
  19668. };
  19669. function RawShaderMaterial(parameters) {
  19670. ShaderMaterial.call(this, parameters);
  19671. this.type = 'RawShaderMaterial';
  19672. }
  19673. RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
  19674. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19675. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19676. /**
  19677. * parameters = {
  19678. * color: <hex>,
  19679. * roughness: <float>,
  19680. * metalness: <float>,
  19681. * opacity: <float>,
  19682. *
  19683. * map: new THREE.Texture( <Image> ),
  19684. *
  19685. * lightMap: new THREE.Texture( <Image> ),
  19686. * lightMapIntensity: <float>
  19687. *
  19688. * aoMap: new THREE.Texture( <Image> ),
  19689. * aoMapIntensity: <float>
  19690. *
  19691. * emissive: <hex>,
  19692. * emissiveIntensity: <float>
  19693. * emissiveMap: new THREE.Texture( <Image> ),
  19694. *
  19695. * bumpMap: new THREE.Texture( <Image> ),
  19696. * bumpScale: <float>,
  19697. *
  19698. * normalMap: new THREE.Texture( <Image> ),
  19699. * normalMapType: THREE.TangentSpaceNormalMap,
  19700. * normalScale: <Vector2>,
  19701. *
  19702. * displacementMap: new THREE.Texture( <Image> ),
  19703. * displacementScale: <float>,
  19704. * displacementBias: <float>,
  19705. *
  19706. * roughnessMap: new THREE.Texture( <Image> ),
  19707. *
  19708. * metalnessMap: new THREE.Texture( <Image> ),
  19709. *
  19710. * alphaMap: new THREE.Texture( <Image> ),
  19711. *
  19712. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19713. * envMapIntensity: <float>
  19714. *
  19715. * refractionRatio: <float>,
  19716. *
  19717. * wireframe: <boolean>,
  19718. * wireframeLinewidth: <float>,
  19719. *
  19720. * skinning: <bool>,
  19721. * morphTargets: <bool>,
  19722. * morphNormals: <bool>
  19723. * }
  19724. */
  19725. function MeshStandardMaterial(parameters) {
  19726. Material.call(this);
  19727. this.defines = {
  19728. 'STANDARD': ''
  19729. };
  19730. this.type = 'MeshStandardMaterial';
  19731. this.color = new Color(0xffffff); // diffuse
  19732. this.roughness = 1.0;
  19733. this.metalness = 0.0;
  19734. this.map = null;
  19735. this.lightMap = null;
  19736. this.lightMapIntensity = 1.0;
  19737. this.aoMap = null;
  19738. this.aoMapIntensity = 1.0;
  19739. this.emissive = new Color(0x000000);
  19740. this.emissiveIntensity = 1.0;
  19741. this.emissiveMap = null;
  19742. this.bumpMap = null;
  19743. this.bumpScale = 1;
  19744. this.normalMap = null;
  19745. this.normalMapType = TangentSpaceNormalMap;
  19746. this.normalScale = new Vector2(1, 1);
  19747. this.displacementMap = null;
  19748. this.displacementScale = 1;
  19749. this.displacementBias = 0;
  19750. this.roughnessMap = null;
  19751. this.metalnessMap = null;
  19752. this.alphaMap = null;
  19753. this.envMap = null;
  19754. this.envMapIntensity = 1.0;
  19755. this.refractionRatio = 0.98;
  19756. this.wireframe = false;
  19757. this.wireframeLinewidth = 1;
  19758. this.wireframeLinecap = 'round';
  19759. this.wireframeLinejoin = 'round';
  19760. this.skinning = false;
  19761. this.morphTargets = false;
  19762. this.morphNormals = false;
  19763. this.vertexTangents = false;
  19764. this.setValues(parameters);
  19765. }
  19766. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  19767. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19768. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19769. MeshStandardMaterial.prototype.copy = function (source) {
  19770. Material.prototype.copy.call(this, source);
  19771. this.defines = {
  19772. 'STANDARD': ''
  19773. };
  19774. this.color.copy(source.color);
  19775. this.roughness = source.roughness;
  19776. this.metalness = source.metalness;
  19777. this.map = source.map;
  19778. this.lightMap = source.lightMap;
  19779. this.lightMapIntensity = source.lightMapIntensity;
  19780. this.aoMap = source.aoMap;
  19781. this.aoMapIntensity = source.aoMapIntensity;
  19782. this.emissive.copy(source.emissive);
  19783. this.emissiveMap = source.emissiveMap;
  19784. this.emissiveIntensity = source.emissiveIntensity;
  19785. this.bumpMap = source.bumpMap;
  19786. this.bumpScale = source.bumpScale;
  19787. this.normalMap = source.normalMap;
  19788. this.normalMapType = source.normalMapType;
  19789. this.normalScale.copy(source.normalScale);
  19790. this.displacementMap = source.displacementMap;
  19791. this.displacementScale = source.displacementScale;
  19792. this.displacementBias = source.displacementBias;
  19793. this.roughnessMap = source.roughnessMap;
  19794. this.metalnessMap = source.metalnessMap;
  19795. this.alphaMap = source.alphaMap;
  19796. this.envMap = source.envMap;
  19797. this.envMapIntensity = source.envMapIntensity;
  19798. this.refractionRatio = source.refractionRatio;
  19799. this.wireframe = source.wireframe;
  19800. this.wireframeLinewidth = source.wireframeLinewidth;
  19801. this.wireframeLinecap = source.wireframeLinecap;
  19802. this.wireframeLinejoin = source.wireframeLinejoin;
  19803. this.skinning = source.skinning;
  19804. this.morphTargets = source.morphTargets;
  19805. this.morphNormals = source.morphNormals;
  19806. this.vertexTangents = source.vertexTangents;
  19807. return this;
  19808. };
  19809. /**
  19810. * parameters = {
  19811. * clearcoat: <float>,
  19812. * clearcoatMap: new THREE.Texture( <Image> ),
  19813. * clearcoatRoughness: <float>,
  19814. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  19815. * clearcoatNormalScale: <Vector2>,
  19816. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19817. *
  19818. * reflectivity: <float>,
  19819. * ior: <float>,
  19820. *
  19821. * sheen: <Color>,
  19822. *
  19823. * transmission: <float>,
  19824. * transmissionMap: new THREE.Texture( <Image> )
  19825. * }
  19826. */
  19827. function MeshPhysicalMaterial(parameters) {
  19828. MeshStandardMaterial.call(this);
  19829. this.defines = {
  19830. 'STANDARD': '',
  19831. 'PHYSICAL': ''
  19832. };
  19833. this.type = 'MeshPhysicalMaterial';
  19834. this.clearcoat = 0.0;
  19835. this.clearcoatMap = null;
  19836. this.clearcoatRoughness = 0.0;
  19837. this.clearcoatRoughnessMap = null;
  19838. this.clearcoatNormalScale = new Vector2(1, 1);
  19839. this.clearcoatNormalMap = null;
  19840. this.reflectivity = 0.5; // maps to F0 = 0.04
  19841. Object.defineProperty(this, 'ior', {
  19842. get: function get() {
  19843. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  19844. },
  19845. set: function set(ior) {
  19846. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  19847. }
  19848. });
  19849. this.sheen = null; // null will disable sheen bsdf
  19850. this.transmission = 0.0;
  19851. this.transmissionMap = null;
  19852. this.setValues(parameters);
  19853. }
  19854. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  19855. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19856. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19857. MeshPhysicalMaterial.prototype.copy = function (source) {
  19858. MeshStandardMaterial.prototype.copy.call(this, source);
  19859. this.defines = {
  19860. 'STANDARD': '',
  19861. 'PHYSICAL': ''
  19862. };
  19863. this.clearcoat = source.clearcoat;
  19864. this.clearcoatMap = source.clearcoatMap;
  19865. this.clearcoatRoughness = source.clearcoatRoughness;
  19866. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  19867. this.clearcoatNormalMap = source.clearcoatNormalMap;
  19868. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  19869. this.reflectivity = source.reflectivity;
  19870. if (source.sheen) {
  19871. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  19872. } else {
  19873. this.sheen = null;
  19874. }
  19875. this.transmission = source.transmission;
  19876. this.transmissionMap = source.transmissionMap;
  19877. return this;
  19878. };
  19879. /**
  19880. * parameters = {
  19881. * color: <hex>,
  19882. * specular: <hex>,
  19883. * shininess: <float>,
  19884. * opacity: <float>,
  19885. *
  19886. * map: new THREE.Texture( <Image> ),
  19887. *
  19888. * lightMap: new THREE.Texture( <Image> ),
  19889. * lightMapIntensity: <float>
  19890. *
  19891. * aoMap: new THREE.Texture( <Image> ),
  19892. * aoMapIntensity: <float>
  19893. *
  19894. * emissive: <hex>,
  19895. * emissiveIntensity: <float>
  19896. * emissiveMap: new THREE.Texture( <Image> ),
  19897. *
  19898. * bumpMap: new THREE.Texture( <Image> ),
  19899. * bumpScale: <float>,
  19900. *
  19901. * normalMap: new THREE.Texture( <Image> ),
  19902. * normalMapType: THREE.TangentSpaceNormalMap,
  19903. * normalScale: <Vector2>,
  19904. *
  19905. * displacementMap: new THREE.Texture( <Image> ),
  19906. * displacementScale: <float>,
  19907. * displacementBias: <float>,
  19908. *
  19909. * specularMap: new THREE.Texture( <Image> ),
  19910. *
  19911. * alphaMap: new THREE.Texture( <Image> ),
  19912. *
  19913. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19914. * combine: THREE.MultiplyOperation,
  19915. * reflectivity: <float>,
  19916. * refractionRatio: <float>,
  19917. *
  19918. * wireframe: <boolean>,
  19919. * wireframeLinewidth: <float>,
  19920. *
  19921. * skinning: <bool>,
  19922. * morphTargets: <bool>,
  19923. * morphNormals: <bool>
  19924. * }
  19925. */
  19926. function MeshPhongMaterial(parameters) {
  19927. Material.call(this);
  19928. this.type = 'MeshPhongMaterial';
  19929. this.color = new Color(0xffffff); // diffuse
  19930. this.specular = new Color(0x111111);
  19931. this.shininess = 30;
  19932. this.map = null;
  19933. this.lightMap = null;
  19934. this.lightMapIntensity = 1.0;
  19935. this.aoMap = null;
  19936. this.aoMapIntensity = 1.0;
  19937. this.emissive = new Color(0x000000);
  19938. this.emissiveIntensity = 1.0;
  19939. this.emissiveMap = null;
  19940. this.bumpMap = null;
  19941. this.bumpScale = 1;
  19942. this.normalMap = null;
  19943. this.normalMapType = TangentSpaceNormalMap;
  19944. this.normalScale = new Vector2(1, 1);
  19945. this.displacementMap = null;
  19946. this.displacementScale = 1;
  19947. this.displacementBias = 0;
  19948. this.specularMap = null;
  19949. this.alphaMap = null;
  19950. this.envMap = null;
  19951. this.combine = MultiplyOperation;
  19952. this.reflectivity = 1;
  19953. this.refractionRatio = 0.98;
  19954. this.wireframe = false;
  19955. this.wireframeLinewidth = 1;
  19956. this.wireframeLinecap = 'round';
  19957. this.wireframeLinejoin = 'round';
  19958. this.skinning = false;
  19959. this.morphTargets = false;
  19960. this.morphNormals = false;
  19961. this.setValues(parameters);
  19962. }
  19963. MeshPhongMaterial.prototype = Object.create(Material.prototype);
  19964. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  19965. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  19966. MeshPhongMaterial.prototype.copy = function (source) {
  19967. Material.prototype.copy.call(this, source);
  19968. this.color.copy(source.color);
  19969. this.specular.copy(source.specular);
  19970. this.shininess = source.shininess;
  19971. this.map = source.map;
  19972. this.lightMap = source.lightMap;
  19973. this.lightMapIntensity = source.lightMapIntensity;
  19974. this.aoMap = source.aoMap;
  19975. this.aoMapIntensity = source.aoMapIntensity;
  19976. this.emissive.copy(source.emissive);
  19977. this.emissiveMap = source.emissiveMap;
  19978. this.emissiveIntensity = source.emissiveIntensity;
  19979. this.bumpMap = source.bumpMap;
  19980. this.bumpScale = source.bumpScale;
  19981. this.normalMap = source.normalMap;
  19982. this.normalMapType = source.normalMapType;
  19983. this.normalScale.copy(source.normalScale);
  19984. this.displacementMap = source.displacementMap;
  19985. this.displacementScale = source.displacementScale;
  19986. this.displacementBias = source.displacementBias;
  19987. this.specularMap = source.specularMap;
  19988. this.alphaMap = source.alphaMap;
  19989. this.envMap = source.envMap;
  19990. this.combine = source.combine;
  19991. this.reflectivity = source.reflectivity;
  19992. this.refractionRatio = source.refractionRatio;
  19993. this.wireframe = source.wireframe;
  19994. this.wireframeLinewidth = source.wireframeLinewidth;
  19995. this.wireframeLinecap = source.wireframeLinecap;
  19996. this.wireframeLinejoin = source.wireframeLinejoin;
  19997. this.skinning = source.skinning;
  19998. this.morphTargets = source.morphTargets;
  19999. this.morphNormals = source.morphNormals;
  20000. return this;
  20001. };
  20002. /**
  20003. * parameters = {
  20004. * color: <hex>,
  20005. *
  20006. * map: new THREE.Texture( <Image> ),
  20007. * gradientMap: new THREE.Texture( <Image> ),
  20008. *
  20009. * lightMap: new THREE.Texture( <Image> ),
  20010. * lightMapIntensity: <float>
  20011. *
  20012. * aoMap: new THREE.Texture( <Image> ),
  20013. * aoMapIntensity: <float>
  20014. *
  20015. * emissive: <hex>,
  20016. * emissiveIntensity: <float>
  20017. * emissiveMap: new THREE.Texture( <Image> ),
  20018. *
  20019. * bumpMap: new THREE.Texture( <Image> ),
  20020. * bumpScale: <float>,
  20021. *
  20022. * normalMap: new THREE.Texture( <Image> ),
  20023. * normalMapType: THREE.TangentSpaceNormalMap,
  20024. * normalScale: <Vector2>,
  20025. *
  20026. * displacementMap: new THREE.Texture( <Image> ),
  20027. * displacementScale: <float>,
  20028. * displacementBias: <float>,
  20029. *
  20030. * alphaMap: new THREE.Texture( <Image> ),
  20031. *
  20032. * wireframe: <boolean>,
  20033. * wireframeLinewidth: <float>,
  20034. *
  20035. * skinning: <bool>,
  20036. * morphTargets: <bool>,
  20037. * morphNormals: <bool>
  20038. * }
  20039. */
  20040. function MeshToonMaterial(parameters) {
  20041. Material.call(this);
  20042. this.defines = {
  20043. 'TOON': ''
  20044. };
  20045. this.type = 'MeshToonMaterial';
  20046. this.color = new Color(0xffffff);
  20047. this.map = null;
  20048. this.gradientMap = null;
  20049. this.lightMap = null;
  20050. this.lightMapIntensity = 1.0;
  20051. this.aoMap = null;
  20052. this.aoMapIntensity = 1.0;
  20053. this.emissive = new Color(0x000000);
  20054. this.emissiveIntensity = 1.0;
  20055. this.emissiveMap = null;
  20056. this.bumpMap = null;
  20057. this.bumpScale = 1;
  20058. this.normalMap = null;
  20059. this.normalMapType = TangentSpaceNormalMap;
  20060. this.normalScale = new Vector2(1, 1);
  20061. this.displacementMap = null;
  20062. this.displacementScale = 1;
  20063. this.displacementBias = 0;
  20064. this.alphaMap = null;
  20065. this.wireframe = false;
  20066. this.wireframeLinewidth = 1;
  20067. this.wireframeLinecap = 'round';
  20068. this.wireframeLinejoin = 'round';
  20069. this.skinning = false;
  20070. this.morphTargets = false;
  20071. this.morphNormals = false;
  20072. this.setValues(parameters);
  20073. }
  20074. MeshToonMaterial.prototype = Object.create(Material.prototype);
  20075. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  20076. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20077. MeshToonMaterial.prototype.copy = function (source) {
  20078. Material.prototype.copy.call(this, source);
  20079. this.color.copy(source.color);
  20080. this.map = source.map;
  20081. this.gradientMap = source.gradientMap;
  20082. this.lightMap = source.lightMap;
  20083. this.lightMapIntensity = source.lightMapIntensity;
  20084. this.aoMap = source.aoMap;
  20085. this.aoMapIntensity = source.aoMapIntensity;
  20086. this.emissive.copy(source.emissive);
  20087. this.emissiveMap = source.emissiveMap;
  20088. this.emissiveIntensity = source.emissiveIntensity;
  20089. this.bumpMap = source.bumpMap;
  20090. this.bumpScale = source.bumpScale;
  20091. this.normalMap = source.normalMap;
  20092. this.normalMapType = source.normalMapType;
  20093. this.normalScale.copy(source.normalScale);
  20094. this.displacementMap = source.displacementMap;
  20095. this.displacementScale = source.displacementScale;
  20096. this.displacementBias = source.displacementBias;
  20097. this.alphaMap = source.alphaMap;
  20098. this.wireframe = source.wireframe;
  20099. this.wireframeLinewidth = source.wireframeLinewidth;
  20100. this.wireframeLinecap = source.wireframeLinecap;
  20101. this.wireframeLinejoin = source.wireframeLinejoin;
  20102. this.skinning = source.skinning;
  20103. this.morphTargets = source.morphTargets;
  20104. this.morphNormals = source.morphNormals;
  20105. return this;
  20106. };
  20107. /**
  20108. * parameters = {
  20109. * opacity: <float>,
  20110. *
  20111. * bumpMap: new THREE.Texture( <Image> ),
  20112. * bumpScale: <float>,
  20113. *
  20114. * normalMap: new THREE.Texture( <Image> ),
  20115. * normalMapType: THREE.TangentSpaceNormalMap,
  20116. * normalScale: <Vector2>,
  20117. *
  20118. * displacementMap: new THREE.Texture( <Image> ),
  20119. * displacementScale: <float>,
  20120. * displacementBias: <float>,
  20121. *
  20122. * wireframe: <boolean>,
  20123. * wireframeLinewidth: <float>
  20124. *
  20125. * skinning: <bool>,
  20126. * morphTargets: <bool>,
  20127. * morphNormals: <bool>
  20128. * }
  20129. */
  20130. function MeshNormalMaterial(parameters) {
  20131. Material.call(this);
  20132. this.type = 'MeshNormalMaterial';
  20133. this.bumpMap = null;
  20134. this.bumpScale = 1;
  20135. this.normalMap = null;
  20136. this.normalMapType = TangentSpaceNormalMap;
  20137. this.normalScale = new Vector2(1, 1);
  20138. this.displacementMap = null;
  20139. this.displacementScale = 1;
  20140. this.displacementBias = 0;
  20141. this.wireframe = false;
  20142. this.wireframeLinewidth = 1;
  20143. this.fog = false;
  20144. this.skinning = false;
  20145. this.morphTargets = false;
  20146. this.morphNormals = false;
  20147. this.setValues(parameters);
  20148. }
  20149. MeshNormalMaterial.prototype = Object.create(Material.prototype);
  20150. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20151. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20152. MeshNormalMaterial.prototype.copy = function (source) {
  20153. Material.prototype.copy.call(this, source);
  20154. this.bumpMap = source.bumpMap;
  20155. this.bumpScale = source.bumpScale;
  20156. this.normalMap = source.normalMap;
  20157. this.normalMapType = source.normalMapType;
  20158. this.normalScale.copy(source.normalScale);
  20159. this.displacementMap = source.displacementMap;
  20160. this.displacementScale = source.displacementScale;
  20161. this.displacementBias = source.displacementBias;
  20162. this.wireframe = source.wireframe;
  20163. this.wireframeLinewidth = source.wireframeLinewidth;
  20164. this.skinning = source.skinning;
  20165. this.morphTargets = source.morphTargets;
  20166. this.morphNormals = source.morphNormals;
  20167. return this;
  20168. };
  20169. /**
  20170. * parameters = {
  20171. * color: <hex>,
  20172. * opacity: <float>,
  20173. *
  20174. * map: new THREE.Texture( <Image> ),
  20175. *
  20176. * lightMap: new THREE.Texture( <Image> ),
  20177. * lightMapIntensity: <float>
  20178. *
  20179. * aoMap: new THREE.Texture( <Image> ),
  20180. * aoMapIntensity: <float>
  20181. *
  20182. * emissive: <hex>,
  20183. * emissiveIntensity: <float>
  20184. * emissiveMap: new THREE.Texture( <Image> ),
  20185. *
  20186. * specularMap: new THREE.Texture( <Image> ),
  20187. *
  20188. * alphaMap: new THREE.Texture( <Image> ),
  20189. *
  20190. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20191. * combine: THREE.Multiply,
  20192. * reflectivity: <float>,
  20193. * refractionRatio: <float>,
  20194. *
  20195. * wireframe: <boolean>,
  20196. * wireframeLinewidth: <float>,
  20197. *
  20198. * skinning: <bool>,
  20199. * morphTargets: <bool>,
  20200. * morphNormals: <bool>
  20201. * }
  20202. */
  20203. function MeshLambertMaterial(parameters) {
  20204. Material.call(this);
  20205. this.type = 'MeshLambertMaterial';
  20206. this.color = new Color(0xffffff); // diffuse
  20207. this.map = null;
  20208. this.lightMap = null;
  20209. this.lightMapIntensity = 1.0;
  20210. this.aoMap = null;
  20211. this.aoMapIntensity = 1.0;
  20212. this.emissive = new Color(0x000000);
  20213. this.emissiveIntensity = 1.0;
  20214. this.emissiveMap = null;
  20215. this.specularMap = null;
  20216. this.alphaMap = null;
  20217. this.envMap = null;
  20218. this.combine = MultiplyOperation;
  20219. this.reflectivity = 1;
  20220. this.refractionRatio = 0.98;
  20221. this.wireframe = false;
  20222. this.wireframeLinewidth = 1;
  20223. this.wireframeLinecap = 'round';
  20224. this.wireframeLinejoin = 'round';
  20225. this.skinning = false;
  20226. this.morphTargets = false;
  20227. this.morphNormals = false;
  20228. this.setValues(parameters);
  20229. }
  20230. MeshLambertMaterial.prototype = Object.create(Material.prototype);
  20231. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20232. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20233. MeshLambertMaterial.prototype.copy = function (source) {
  20234. Material.prototype.copy.call(this, source);
  20235. this.color.copy(source.color);
  20236. this.map = source.map;
  20237. this.lightMap = source.lightMap;
  20238. this.lightMapIntensity = source.lightMapIntensity;
  20239. this.aoMap = source.aoMap;
  20240. this.aoMapIntensity = source.aoMapIntensity;
  20241. this.emissive.copy(source.emissive);
  20242. this.emissiveMap = source.emissiveMap;
  20243. this.emissiveIntensity = source.emissiveIntensity;
  20244. this.specularMap = source.specularMap;
  20245. this.alphaMap = source.alphaMap;
  20246. this.envMap = source.envMap;
  20247. this.combine = source.combine;
  20248. this.reflectivity = source.reflectivity;
  20249. this.refractionRatio = source.refractionRatio;
  20250. this.wireframe = source.wireframe;
  20251. this.wireframeLinewidth = source.wireframeLinewidth;
  20252. this.wireframeLinecap = source.wireframeLinecap;
  20253. this.wireframeLinejoin = source.wireframeLinejoin;
  20254. this.skinning = source.skinning;
  20255. this.morphTargets = source.morphTargets;
  20256. this.morphNormals = source.morphNormals;
  20257. return this;
  20258. };
  20259. /**
  20260. * parameters = {
  20261. * color: <hex>,
  20262. * opacity: <float>,
  20263. *
  20264. * matcap: new THREE.Texture( <Image> ),
  20265. *
  20266. * map: new THREE.Texture( <Image> ),
  20267. *
  20268. * bumpMap: new THREE.Texture( <Image> ),
  20269. * bumpScale: <float>,
  20270. *
  20271. * normalMap: new THREE.Texture( <Image> ),
  20272. * normalMapType: THREE.TangentSpaceNormalMap,
  20273. * normalScale: <Vector2>,
  20274. *
  20275. * displacementMap: new THREE.Texture( <Image> ),
  20276. * displacementScale: <float>,
  20277. * displacementBias: <float>,
  20278. *
  20279. * alphaMap: new THREE.Texture( <Image> ),
  20280. *
  20281. * skinning: <bool>,
  20282. * morphTargets: <bool>,
  20283. * morphNormals: <bool>
  20284. * }
  20285. */
  20286. function MeshMatcapMaterial(parameters) {
  20287. Material.call(this);
  20288. this.defines = {
  20289. 'MATCAP': ''
  20290. };
  20291. this.type = 'MeshMatcapMaterial';
  20292. this.color = new Color(0xffffff); // diffuse
  20293. this.matcap = null;
  20294. this.map = null;
  20295. this.bumpMap = null;
  20296. this.bumpScale = 1;
  20297. this.normalMap = null;
  20298. this.normalMapType = TangentSpaceNormalMap;
  20299. this.normalScale = new Vector2(1, 1);
  20300. this.displacementMap = null;
  20301. this.displacementScale = 1;
  20302. this.displacementBias = 0;
  20303. this.alphaMap = null;
  20304. this.skinning = false;
  20305. this.morphTargets = false;
  20306. this.morphNormals = false;
  20307. this.setValues(parameters);
  20308. }
  20309. MeshMatcapMaterial.prototype = Object.create(Material.prototype);
  20310. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20311. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20312. MeshMatcapMaterial.prototype.copy = function (source) {
  20313. Material.prototype.copy.call(this, source);
  20314. this.defines = {
  20315. 'MATCAP': ''
  20316. };
  20317. this.color.copy(source.color);
  20318. this.matcap = source.matcap;
  20319. this.map = source.map;
  20320. this.bumpMap = source.bumpMap;
  20321. this.bumpScale = source.bumpScale;
  20322. this.normalMap = source.normalMap;
  20323. this.normalMapType = source.normalMapType;
  20324. this.normalScale.copy(source.normalScale);
  20325. this.displacementMap = source.displacementMap;
  20326. this.displacementScale = source.displacementScale;
  20327. this.displacementBias = source.displacementBias;
  20328. this.alphaMap = source.alphaMap;
  20329. this.skinning = source.skinning;
  20330. this.morphTargets = source.morphTargets;
  20331. this.morphNormals = source.morphNormals;
  20332. return this;
  20333. };
  20334. /**
  20335. * parameters = {
  20336. * color: <hex>,
  20337. * opacity: <float>,
  20338. *
  20339. * linewidth: <float>,
  20340. *
  20341. * scale: <float>,
  20342. * dashSize: <float>,
  20343. * gapSize: <float>
  20344. * }
  20345. */
  20346. function LineDashedMaterial(parameters) {
  20347. LineBasicMaterial.call(this);
  20348. this.type = 'LineDashedMaterial';
  20349. this.scale = 1;
  20350. this.dashSize = 3;
  20351. this.gapSize = 1;
  20352. this.setValues(parameters);
  20353. }
  20354. LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
  20355. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20356. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20357. LineDashedMaterial.prototype.copy = function (source) {
  20358. LineBasicMaterial.prototype.copy.call(this, source);
  20359. this.scale = source.scale;
  20360. this.dashSize = source.dashSize;
  20361. this.gapSize = source.gapSize;
  20362. return this;
  20363. };
  20364. var Materials = /*#__PURE__*/Object.freeze({
  20365. __proto__: null,
  20366. ShadowMaterial: ShadowMaterial,
  20367. SpriteMaterial: SpriteMaterial,
  20368. RawShaderMaterial: RawShaderMaterial,
  20369. ShaderMaterial: ShaderMaterial,
  20370. PointsMaterial: PointsMaterial,
  20371. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20372. MeshStandardMaterial: MeshStandardMaterial,
  20373. MeshPhongMaterial: MeshPhongMaterial,
  20374. MeshToonMaterial: MeshToonMaterial,
  20375. MeshNormalMaterial: MeshNormalMaterial,
  20376. MeshLambertMaterial: MeshLambertMaterial,
  20377. MeshDepthMaterial: MeshDepthMaterial,
  20378. MeshDistanceMaterial: MeshDistanceMaterial,
  20379. MeshBasicMaterial: MeshBasicMaterial,
  20380. MeshMatcapMaterial: MeshMatcapMaterial,
  20381. LineDashedMaterial: LineDashedMaterial,
  20382. LineBasicMaterial: LineBasicMaterial,
  20383. Material: Material
  20384. });
  20385. var AnimationUtils = {
  20386. // same as Array.prototype.slice, but also works on typed arrays
  20387. arraySlice: function arraySlice(array, from, to) {
  20388. if (AnimationUtils.isTypedArray(array)) {
  20389. // in ios9 array.subarray(from, undefined) will return empty array
  20390. // but array.subarray(from) or array.subarray(from, len) is correct
  20391. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20392. }
  20393. return array.slice(from, to);
  20394. },
  20395. // converts an array to a specific type
  20396. convertArray: function convertArray(array, type, forceClone) {
  20397. if (!array || // let 'undefined' and 'null' pass
  20398. !forceClone && array.constructor === type) return array;
  20399. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20400. return new type(array); // create typed array
  20401. }
  20402. return Array.prototype.slice.call(array); // create Array
  20403. },
  20404. isTypedArray: function isTypedArray(object) {
  20405. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20406. },
  20407. // returns an array by which times and values can be sorted
  20408. getKeyframeOrder: function getKeyframeOrder(times) {
  20409. function compareTime(i, j) {
  20410. return times[i] - times[j];
  20411. }
  20412. var n = times.length;
  20413. var result = new Array(n);
  20414. for (var i = 0; i !== n; ++i) {
  20415. result[i] = i;
  20416. }
  20417. result.sort(compareTime);
  20418. return result;
  20419. },
  20420. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20421. sortedArray: function sortedArray(values, stride, order) {
  20422. var nValues = values.length;
  20423. var result = new values.constructor(nValues);
  20424. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20425. var srcOffset = order[i] * stride;
  20426. for (var j = 0; j !== stride; ++j) {
  20427. result[dstOffset++] = values[srcOffset + j];
  20428. }
  20429. }
  20430. return result;
  20431. },
  20432. // function for parsing AOS keyframe formats
  20433. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20434. var i = 1,
  20435. key = jsonKeys[0];
  20436. while (key !== undefined && key[valuePropertyName] === undefined) {
  20437. key = jsonKeys[i++];
  20438. }
  20439. if (key === undefined) return; // no data
  20440. var value = key[valuePropertyName];
  20441. if (value === undefined) return; // no data
  20442. if (Array.isArray(value)) {
  20443. do {
  20444. value = key[valuePropertyName];
  20445. if (value !== undefined) {
  20446. times.push(key.time);
  20447. values.push.apply(values, value); // push all elements
  20448. }
  20449. key = jsonKeys[i++];
  20450. } while (key !== undefined);
  20451. } else if (value.toArray !== undefined) {
  20452. // ...assume THREE.Math-ish
  20453. do {
  20454. value = key[valuePropertyName];
  20455. if (value !== undefined) {
  20456. times.push(key.time);
  20457. value.toArray(values, values.length);
  20458. }
  20459. key = jsonKeys[i++];
  20460. } while (key !== undefined);
  20461. } else {
  20462. // otherwise push as-is
  20463. do {
  20464. value = key[valuePropertyName];
  20465. if (value !== undefined) {
  20466. times.push(key.time);
  20467. values.push(value);
  20468. }
  20469. key = jsonKeys[i++];
  20470. } while (key !== undefined);
  20471. }
  20472. },
  20473. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  20474. fps = fps || 30;
  20475. var clip = sourceClip.clone();
  20476. clip.name = name;
  20477. var tracks = [];
  20478. for (var i = 0; i < clip.tracks.length; ++i) {
  20479. var track = clip.tracks[i];
  20480. var valueSize = track.getValueSize();
  20481. var times = [];
  20482. var values = [];
  20483. for (var j = 0; j < track.times.length; ++j) {
  20484. var frame = track.times[j] * fps;
  20485. if (frame < startFrame || frame >= endFrame) continue;
  20486. times.push(track.times[j]);
  20487. for (var k = 0; k < valueSize; ++k) {
  20488. values.push(track.values[j * valueSize + k]);
  20489. }
  20490. }
  20491. if (times.length === 0) continue;
  20492. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  20493. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  20494. tracks.push(track);
  20495. }
  20496. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  20497. var minStartTime = Infinity;
  20498. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  20499. if (minStartTime > clip.tracks[_i].times[0]) {
  20500. minStartTime = clip.tracks[_i].times[0];
  20501. }
  20502. } // shift all tracks such that clip begins at t=0
  20503. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  20504. clip.tracks[_i2].shift(-1 * minStartTime);
  20505. }
  20506. clip.resetDuration();
  20507. return clip;
  20508. },
  20509. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  20510. if (referenceFrame === undefined) referenceFrame = 0;
  20511. if (referenceClip === undefined) referenceClip = targetClip;
  20512. if (fps === undefined || fps <= 0) fps = 30;
  20513. var numTracks = referenceClip.tracks.length;
  20514. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  20515. var _loop = function _loop(i) {
  20516. var referenceTrack = referenceClip.tracks[i];
  20517. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  20518. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  20519. var targetTrack = targetClip.tracks.find(function (track) {
  20520. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  20521. });
  20522. if (targetTrack === undefined) return "continue";
  20523. var referenceOffset = 0;
  20524. var referenceValueSize = referenceTrack.getValueSize();
  20525. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20526. referenceOffset = referenceValueSize / 3;
  20527. }
  20528. var targetOffset = 0;
  20529. var targetValueSize = targetTrack.getValueSize();
  20530. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20531. targetOffset = targetValueSize / 3;
  20532. }
  20533. var lastIndex = referenceTrack.times.length - 1;
  20534. var referenceValue = void 0; // Find the value to subtract out of the track
  20535. if (referenceTime <= referenceTrack.times[0]) {
  20536. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20537. var startIndex = referenceOffset;
  20538. var endIndex = referenceValueSize - referenceOffset;
  20539. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  20540. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  20541. // Reference frame is after the last keyframe, so just use the last keyframe
  20542. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  20543. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  20544. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  20545. } else {
  20546. // Interpolate to the reference value
  20547. var interpolant = referenceTrack.createInterpolant();
  20548. var _startIndex2 = referenceOffset;
  20549. var _endIndex2 = referenceValueSize - referenceOffset;
  20550. interpolant.evaluate(referenceTime);
  20551. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  20552. } // Conjugate the quaternion
  20553. if (referenceTrackType === 'quaternion') {
  20554. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  20555. referenceQuat.toArray(referenceValue);
  20556. } // Subtract the reference value from all of the track values
  20557. var numTimes = targetTrack.times.length;
  20558. for (var j = 0; j < numTimes; ++j) {
  20559. var valueStart = j * targetValueSize + targetOffset;
  20560. if (referenceTrackType === 'quaternion') {
  20561. // Multiply the conjugate for quaternion track types
  20562. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  20563. } else {
  20564. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  20565. for (var k = 0; k < valueEnd; ++k) {
  20566. targetTrack.values[valueStart + k] -= referenceValue[k];
  20567. }
  20568. }
  20569. }
  20570. };
  20571. for (var i = 0; i < numTracks; ++i) {
  20572. var _ret = _loop(i);
  20573. if (_ret === "continue") continue;
  20574. }
  20575. targetClip.blendMode = AdditiveAnimationBlendMode;
  20576. return targetClip;
  20577. }
  20578. };
  20579. /**
  20580. * Abstract base class of interpolants over parametric samples.
  20581. *
  20582. * The parameter domain is one dimensional, typically the time or a path
  20583. * along a curve defined by the data.
  20584. *
  20585. * The sample values can have any dimensionality and derived classes may
  20586. * apply special interpretations to the data.
  20587. *
  20588. * This class provides the interval seek in a Template Method, deferring
  20589. * the actual interpolation to derived classes.
  20590. *
  20591. * Time complexity is O(1) for linear access crossing at most two points
  20592. * and O(log N) for random access, where N is the number of positions.
  20593. *
  20594. * References:
  20595. *
  20596. * http://www.oodesign.com/template-method-pattern.html
  20597. *
  20598. */
  20599. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20600. this.parameterPositions = parameterPositions;
  20601. this._cachedIndex = 0;
  20602. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  20603. this.sampleValues = sampleValues;
  20604. this.valueSize = sampleSize;
  20605. }
  20606. Object.assign(Interpolant.prototype, {
  20607. evaluate: function evaluate(t) {
  20608. var pp = this.parameterPositions;
  20609. var i1 = this._cachedIndex,
  20610. t1 = pp[i1],
  20611. t0 = pp[i1 - 1];
  20612. validate_interval: {
  20613. seek: {
  20614. var right;
  20615. linear_scan: {
  20616. //- See http://jsperf.com/comparison-to-undefined/3
  20617. //- slower code:
  20618. //-
  20619. //- if ( t >= t1 || t1 === undefined ) {
  20620. forward_scan: if (!(t < t1)) {
  20621. for (var giveUpAt = i1 + 2;;) {
  20622. if (t1 === undefined) {
  20623. if (t < t0) break forward_scan; // after end
  20624. i1 = pp.length;
  20625. this._cachedIndex = i1;
  20626. return this.afterEnd_(i1 - 1, t, t0);
  20627. }
  20628. if (i1 === giveUpAt) break; // this loop
  20629. t0 = t1;
  20630. t1 = pp[++i1];
  20631. if (t < t1) {
  20632. // we have arrived at the sought interval
  20633. break seek;
  20634. }
  20635. } // prepare binary search on the right side of the index
  20636. right = pp.length;
  20637. break linear_scan;
  20638. } //- slower code:
  20639. //- if ( t < t0 || t0 === undefined ) {
  20640. if (!(t >= t0)) {
  20641. // looping?
  20642. var t1global = pp[1];
  20643. if (t < t1global) {
  20644. i1 = 2; // + 1, using the scan for the details
  20645. t0 = t1global;
  20646. } // linear reverse scan
  20647. for (var _giveUpAt = i1 - 2;;) {
  20648. if (t0 === undefined) {
  20649. // before start
  20650. this._cachedIndex = 0;
  20651. return this.beforeStart_(0, t, t1);
  20652. }
  20653. if (i1 === _giveUpAt) break; // this loop
  20654. t1 = t0;
  20655. t0 = pp[--i1 - 1];
  20656. if (t >= t0) {
  20657. // we have arrived at the sought interval
  20658. break seek;
  20659. }
  20660. } // prepare binary search on the left side of the index
  20661. right = i1;
  20662. i1 = 0;
  20663. break linear_scan;
  20664. } // the interval is valid
  20665. break validate_interval;
  20666. } // linear scan
  20667. // binary search
  20668. while (i1 < right) {
  20669. var mid = i1 + right >>> 1;
  20670. if (t < pp[mid]) {
  20671. right = mid;
  20672. } else {
  20673. i1 = mid + 1;
  20674. }
  20675. }
  20676. t1 = pp[i1];
  20677. t0 = pp[i1 - 1]; // check boundary cases, again
  20678. if (t0 === undefined) {
  20679. this._cachedIndex = 0;
  20680. return this.beforeStart_(0, t, t1);
  20681. }
  20682. if (t1 === undefined) {
  20683. i1 = pp.length;
  20684. this._cachedIndex = i1;
  20685. return this.afterEnd_(i1 - 1, t0, t);
  20686. }
  20687. } // seek
  20688. this._cachedIndex = i1;
  20689. this.intervalChanged_(i1, t0, t1);
  20690. } // validate_interval
  20691. return this.interpolate_(i1, t0, t, t1);
  20692. },
  20693. settings: null,
  20694. // optional, subclass-specific settings structure
  20695. // Note: The indirection allows central control of many interpolants.
  20696. // --- Protected interface
  20697. DefaultSettings_: {},
  20698. getSettings_: function getSettings_() {
  20699. return this.settings || this.DefaultSettings_;
  20700. },
  20701. copySampleValue_: function copySampleValue_(index) {
  20702. // copies a sample value to the result buffer
  20703. var result = this.resultBuffer,
  20704. values = this.sampleValues,
  20705. stride = this.valueSize,
  20706. offset = index * stride;
  20707. for (var i = 0; i !== stride; ++i) {
  20708. result[i] = values[offset + i];
  20709. }
  20710. return result;
  20711. },
  20712. // Template methods for derived classes:
  20713. interpolate_: function interpolate_()
  20714. /* i1, t0, t, t1 */
  20715. {
  20716. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  20717. },
  20718. intervalChanged_: function intervalChanged_()
  20719. /* i1, t0, t1 */
  20720. {// empty
  20721. }
  20722. }); // DECLARE ALIAS AFTER assign prototype
  20723. Object.assign(Interpolant.prototype, {
  20724. //( 0, t, t0 ), returns this.resultBuffer
  20725. beforeStart_: Interpolant.prototype.copySampleValue_,
  20726. //( N-1, tN-1, t ), returns this.resultBuffer
  20727. afterEnd_: Interpolant.prototype.copySampleValue_
  20728. });
  20729. /**
  20730. * Fast and simple cubic spline interpolant.
  20731. *
  20732. * It was derived from a Hermitian construction setting the first derivative
  20733. * at each sample position to the linear slope between neighboring positions
  20734. * over their parameter interval.
  20735. */
  20736. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20737. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20738. this._weightPrev = -0;
  20739. this._offsetPrev = -0;
  20740. this._weightNext = -0;
  20741. this._offsetNext = -0;
  20742. }
  20743. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20744. constructor: CubicInterpolant,
  20745. DefaultSettings_: {
  20746. endingStart: ZeroCurvatureEnding,
  20747. endingEnd: ZeroCurvatureEnding
  20748. },
  20749. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  20750. var pp = this.parameterPositions;
  20751. var iPrev = i1 - 2,
  20752. iNext = i1 + 1,
  20753. tPrev = pp[iPrev],
  20754. tNext = pp[iNext];
  20755. if (tPrev === undefined) {
  20756. switch (this.getSettings_().endingStart) {
  20757. case ZeroSlopeEnding:
  20758. // f'(t0) = 0
  20759. iPrev = i1;
  20760. tPrev = 2 * t0 - t1;
  20761. break;
  20762. case WrapAroundEnding:
  20763. // use the other end of the curve
  20764. iPrev = pp.length - 2;
  20765. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  20766. break;
  20767. default:
  20768. // ZeroCurvatureEnding
  20769. // f''(t0) = 0 a.k.a. Natural Spline
  20770. iPrev = i1;
  20771. tPrev = t1;
  20772. }
  20773. }
  20774. if (tNext === undefined) {
  20775. switch (this.getSettings_().endingEnd) {
  20776. case ZeroSlopeEnding:
  20777. // f'(tN) = 0
  20778. iNext = i1;
  20779. tNext = 2 * t1 - t0;
  20780. break;
  20781. case WrapAroundEnding:
  20782. // use the other end of the curve
  20783. iNext = 1;
  20784. tNext = t1 + pp[1] - pp[0];
  20785. break;
  20786. default:
  20787. // ZeroCurvatureEnding
  20788. // f''(tN) = 0, a.k.a. Natural Spline
  20789. iNext = i1 - 1;
  20790. tNext = t0;
  20791. }
  20792. }
  20793. var halfDt = (t1 - t0) * 0.5,
  20794. stride = this.valueSize;
  20795. this._weightPrev = halfDt / (t0 - tPrev);
  20796. this._weightNext = halfDt / (tNext - t1);
  20797. this._offsetPrev = iPrev * stride;
  20798. this._offsetNext = iNext * stride;
  20799. },
  20800. interpolate_: function interpolate_(i1, t0, t, t1) {
  20801. var result = this.resultBuffer,
  20802. values = this.sampleValues,
  20803. stride = this.valueSize,
  20804. o1 = i1 * stride,
  20805. o0 = o1 - stride,
  20806. oP = this._offsetPrev,
  20807. oN = this._offsetNext,
  20808. wP = this._weightPrev,
  20809. wN = this._weightNext,
  20810. p = (t - t0) / (t1 - t0),
  20811. pp = p * p,
  20812. ppp = pp * p; // evaluate polynomials
  20813. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  20814. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  20815. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  20816. var sN = wN * ppp - wN * pp; // combine data linearly
  20817. for (var i = 0; i !== stride; ++i) {
  20818. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  20819. }
  20820. return result;
  20821. }
  20822. });
  20823. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20824. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20825. }
  20826. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20827. constructor: LinearInterpolant,
  20828. interpolate_: function interpolate_(i1, t0, t, t1) {
  20829. var result = this.resultBuffer,
  20830. values = this.sampleValues,
  20831. stride = this.valueSize,
  20832. offset1 = i1 * stride,
  20833. offset0 = offset1 - stride,
  20834. weight1 = (t - t0) / (t1 - t0),
  20835. weight0 = 1 - weight1;
  20836. for (var i = 0; i !== stride; ++i) {
  20837. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  20838. }
  20839. return result;
  20840. }
  20841. });
  20842. /**
  20843. *
  20844. * Interpolant that evaluates to the sample value at the position preceeding
  20845. * the parameter.
  20846. */
  20847. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20848. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20849. }
  20850. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20851. constructor: DiscreteInterpolant,
  20852. interpolate_: function interpolate_(i1
  20853. /*, t0, t, t1 */
  20854. ) {
  20855. return this.copySampleValue_(i1 - 1);
  20856. }
  20857. });
  20858. function KeyframeTrack(name, times, values, interpolation) {
  20859. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  20860. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  20861. this.name = name;
  20862. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  20863. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  20864. this.setInterpolation(interpolation || this.DefaultInterpolation);
  20865. } // Static methods
  20866. Object.assign(KeyframeTrack, {
  20867. // Serialization (in static context, because of constructor invocation
  20868. // and automatic invocation of .toJSON):
  20869. toJSON: function toJSON(track) {
  20870. var trackType = track.constructor;
  20871. var json; // derived classes can define a static toJSON method
  20872. if (trackType.toJSON !== undefined) {
  20873. json = trackType.toJSON(track);
  20874. } else {
  20875. // by default, we assume the data can be serialized as-is
  20876. json = {
  20877. 'name': track.name,
  20878. 'times': AnimationUtils.convertArray(track.times, Array),
  20879. 'values': AnimationUtils.convertArray(track.values, Array)
  20880. };
  20881. var interpolation = track.getInterpolation();
  20882. if (interpolation !== track.DefaultInterpolation) {
  20883. json.interpolation = interpolation;
  20884. }
  20885. }
  20886. json.type = track.ValueTypeName; // mandatory
  20887. return json;
  20888. }
  20889. });
  20890. Object.assign(KeyframeTrack.prototype, {
  20891. constructor: KeyframeTrack,
  20892. TimeBufferType: Float32Array,
  20893. ValueBufferType: Float32Array,
  20894. DefaultInterpolation: InterpolateLinear,
  20895. InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
  20896. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  20897. },
  20898. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  20899. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  20900. },
  20901. InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
  20902. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  20903. },
  20904. setInterpolation: function setInterpolation(interpolation) {
  20905. var factoryMethod;
  20906. switch (interpolation) {
  20907. case InterpolateDiscrete:
  20908. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20909. break;
  20910. case InterpolateLinear:
  20911. factoryMethod = this.InterpolantFactoryMethodLinear;
  20912. break;
  20913. case InterpolateSmooth:
  20914. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20915. break;
  20916. }
  20917. if (factoryMethod === undefined) {
  20918. var message = "unsupported interpolation for " + this.ValueTypeName + " keyframe track named " + this.name;
  20919. if (this.createInterpolant === undefined) {
  20920. // fall back to default, unless the default itself is messed up
  20921. if (interpolation !== this.DefaultInterpolation) {
  20922. this.setInterpolation(this.DefaultInterpolation);
  20923. } else {
  20924. throw new Error(message); // fatal, in this case
  20925. }
  20926. }
  20927. console.warn('THREE.KeyframeTrack:', message);
  20928. return this;
  20929. }
  20930. this.createInterpolant = factoryMethod;
  20931. return this;
  20932. },
  20933. getInterpolation: function getInterpolation() {
  20934. switch (this.createInterpolant) {
  20935. case this.InterpolantFactoryMethodDiscrete:
  20936. return InterpolateDiscrete;
  20937. case this.InterpolantFactoryMethodLinear:
  20938. return InterpolateLinear;
  20939. case this.InterpolantFactoryMethodSmooth:
  20940. return InterpolateSmooth;
  20941. }
  20942. },
  20943. getValueSize: function getValueSize() {
  20944. return this.values.length / this.times.length;
  20945. },
  20946. // move all keyframes either forwards or backwards in time
  20947. shift: function shift(timeOffset) {
  20948. if (timeOffset !== 0.0) {
  20949. var times = this.times;
  20950. for (var i = 0, n = times.length; i !== n; ++i) {
  20951. times[i] += timeOffset;
  20952. }
  20953. }
  20954. return this;
  20955. },
  20956. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  20957. scale: function scale(timeScale) {
  20958. if (timeScale !== 1.0) {
  20959. var times = this.times;
  20960. for (var i = 0, n = times.length; i !== n; ++i) {
  20961. times[i] *= timeScale;
  20962. }
  20963. }
  20964. return this;
  20965. },
  20966. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  20967. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  20968. trim: function trim(startTime, endTime) {
  20969. var times = this.times,
  20970. nKeys = times.length;
  20971. var from = 0,
  20972. to = nKeys - 1;
  20973. while (from !== nKeys && times[from] < startTime) {
  20974. ++from;
  20975. }
  20976. while (to !== -1 && times[to] > endTime) {
  20977. --to;
  20978. }
  20979. ++to; // inclusive -> exclusive bound
  20980. if (from !== 0 || to !== nKeys) {
  20981. // empty tracks are forbidden, so keep at least one keyframe
  20982. if (from >= to) {
  20983. to = Math.max(to, 1);
  20984. from = to - 1;
  20985. }
  20986. var stride = this.getValueSize();
  20987. this.times = AnimationUtils.arraySlice(times, from, to);
  20988. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  20989. }
  20990. return this;
  20991. },
  20992. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  20993. validate: function validate() {
  20994. var valid = true;
  20995. var valueSize = this.getValueSize();
  20996. if (valueSize - Math.floor(valueSize) !== 0) {
  20997. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  20998. valid = false;
  20999. }
  21000. var times = this.times,
  21001. values = this.values,
  21002. nKeys = times.length;
  21003. if (nKeys === 0) {
  21004. console.error('THREE.KeyframeTrack: Track is empty.', this);
  21005. valid = false;
  21006. }
  21007. var prevTime = null;
  21008. for (var i = 0; i !== nKeys; i++) {
  21009. var currTime = times[i];
  21010. if (typeof currTime === 'number' && isNaN(currTime)) {
  21011. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  21012. valid = false;
  21013. break;
  21014. }
  21015. if (prevTime !== null && prevTime > currTime) {
  21016. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  21017. valid = false;
  21018. break;
  21019. }
  21020. prevTime = currTime;
  21021. }
  21022. if (values !== undefined) {
  21023. if (AnimationUtils.isTypedArray(values)) {
  21024. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  21025. var value = values[_i];
  21026. if (isNaN(value)) {
  21027. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  21028. valid = false;
  21029. break;
  21030. }
  21031. }
  21032. }
  21033. }
  21034. return valid;
  21035. },
  21036. // removes equivalent sequential keys as common in morph target sequences
  21037. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21038. optimize: function optimize() {
  21039. // times or values may be shared with other tracks, so overwriting is unsafe
  21040. var times = AnimationUtils.arraySlice(this.times),
  21041. values = AnimationUtils.arraySlice(this.values),
  21042. stride = this.getValueSize(),
  21043. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21044. lastIndex = times.length - 1;
  21045. var writeIndex = 1;
  21046. for (var i = 1; i < lastIndex; ++i) {
  21047. var keep = false;
  21048. var time = times[i];
  21049. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  21050. if (time !== timeNext && (i !== 1 || time !== time[0])) {
  21051. if (!smoothInterpolation) {
  21052. // remove unnecessary keyframes same as their neighbors
  21053. var offset = i * stride,
  21054. offsetP = offset - stride,
  21055. offsetN = offset + stride;
  21056. for (var j = 0; j !== stride; ++j) {
  21057. var value = values[offset + j];
  21058. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  21059. keep = true;
  21060. break;
  21061. }
  21062. }
  21063. } else {
  21064. keep = true;
  21065. }
  21066. } // in-place compaction
  21067. if (keep) {
  21068. if (i !== writeIndex) {
  21069. times[writeIndex] = times[i];
  21070. var readOffset = i * stride,
  21071. writeOffset = writeIndex * stride;
  21072. for (var _j = 0; _j !== stride; ++_j) {
  21073. values[writeOffset + _j] = values[readOffset + _j];
  21074. }
  21075. }
  21076. ++writeIndex;
  21077. }
  21078. } // flush last keyframe (compaction looks ahead)
  21079. if (lastIndex > 0) {
  21080. times[writeIndex] = times[lastIndex];
  21081. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  21082. values[_writeOffset + _j2] = values[_readOffset + _j2];
  21083. }
  21084. ++writeIndex;
  21085. }
  21086. if (writeIndex !== times.length) {
  21087. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  21088. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  21089. } else {
  21090. this.times = times;
  21091. this.values = values;
  21092. }
  21093. return this;
  21094. },
  21095. clone: function clone() {
  21096. var times = AnimationUtils.arraySlice(this.times, 0);
  21097. var values = AnimationUtils.arraySlice(this.values, 0);
  21098. var TypedKeyframeTrack = this.constructor;
  21099. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21100. track.createInterpolant = this.createInterpolant;
  21101. return track;
  21102. }
  21103. });
  21104. /**
  21105. * A Track of Boolean keyframe values.
  21106. */
  21107. function BooleanKeyframeTrack(name, times, values) {
  21108. KeyframeTrack.call(this, name, times, values);
  21109. }
  21110. BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21111. constructor: BooleanKeyframeTrack,
  21112. ValueTypeName: 'bool',
  21113. ValueBufferType: Array,
  21114. DefaultInterpolation: InterpolateDiscrete,
  21115. InterpolantFactoryMethodLinear: undefined,
  21116. InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
  21117. // representation of a single value and a custom interpolant that
  21118. // computes "firstValue ^ isOdd( index )".
  21119. });
  21120. /**
  21121. * A Track of keyframe values that represent color.
  21122. */
  21123. function ColorKeyframeTrack(name, times, values, interpolation) {
  21124. KeyframeTrack.call(this, name, times, values, interpolation);
  21125. }
  21126. ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21127. constructor: ColorKeyframeTrack,
  21128. ValueTypeName: 'color' // ValueBufferType is inherited
  21129. // DefaultInterpolation is inherited
  21130. // Note: Very basic implementation and nothing special yet.
  21131. // However, this is the place for color space parameterization.
  21132. });
  21133. /**
  21134. * A Track of numeric keyframe values.
  21135. */
  21136. function NumberKeyframeTrack(name, times, values, interpolation) {
  21137. KeyframeTrack.call(this, name, times, values, interpolation);
  21138. }
  21139. NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21140. constructor: NumberKeyframeTrack,
  21141. ValueTypeName: 'number' // ValueBufferType is inherited
  21142. // DefaultInterpolation is inherited
  21143. });
  21144. /**
  21145. * Spherical linear unit quaternion interpolant.
  21146. */
  21147. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21148. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21149. }
  21150. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21151. constructor: QuaternionLinearInterpolant,
  21152. interpolate_: function interpolate_(i1, t0, t, t1) {
  21153. var result = this.resultBuffer,
  21154. values = this.sampleValues,
  21155. stride = this.valueSize,
  21156. alpha = (t - t0) / (t1 - t0);
  21157. var offset = i1 * stride;
  21158. for (var end = offset + stride; offset !== end; offset += 4) {
  21159. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21160. }
  21161. return result;
  21162. }
  21163. });
  21164. /**
  21165. * A Track of quaternion keyframe values.
  21166. */
  21167. function QuaternionKeyframeTrack(name, times, values, interpolation) {
  21168. KeyframeTrack.call(this, name, times, values, interpolation);
  21169. }
  21170. QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21171. constructor: QuaternionKeyframeTrack,
  21172. ValueTypeName: 'quaternion',
  21173. // ValueBufferType is inherited
  21174. DefaultInterpolation: InterpolateLinear,
  21175. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21176. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21177. },
  21178. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21179. });
  21180. /**
  21181. * A Track that interpolates Strings
  21182. */
  21183. function StringKeyframeTrack(name, times, values, interpolation) {
  21184. KeyframeTrack.call(this, name, times, values, interpolation);
  21185. }
  21186. StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21187. constructor: StringKeyframeTrack,
  21188. ValueTypeName: 'string',
  21189. ValueBufferType: Array,
  21190. DefaultInterpolation: InterpolateDiscrete,
  21191. InterpolantFactoryMethodLinear: undefined,
  21192. InterpolantFactoryMethodSmooth: undefined
  21193. });
  21194. /**
  21195. * A Track of vectored keyframe values.
  21196. */
  21197. function VectorKeyframeTrack(name, times, values, interpolation) {
  21198. KeyframeTrack.call(this, name, times, values, interpolation);
  21199. }
  21200. VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21201. constructor: VectorKeyframeTrack,
  21202. ValueTypeName: 'vector' // ValueBufferType is inherited
  21203. // DefaultInterpolation is inherited
  21204. });
  21205. function AnimationClip(name, duration, tracks, blendMode) {
  21206. this.name = name;
  21207. this.tracks = tracks;
  21208. this.duration = duration !== undefined ? duration : -1;
  21209. this.blendMode = blendMode !== undefined ? blendMode : NormalAnimationBlendMode;
  21210. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21211. if (this.duration < 0) {
  21212. this.resetDuration();
  21213. }
  21214. }
  21215. function getTrackTypeForValueTypeName(typeName) {
  21216. switch (typeName.toLowerCase()) {
  21217. case 'scalar':
  21218. case 'double':
  21219. case 'float':
  21220. case 'number':
  21221. case 'integer':
  21222. return NumberKeyframeTrack;
  21223. case 'vector':
  21224. case 'vector2':
  21225. case 'vector3':
  21226. case 'vector4':
  21227. return VectorKeyframeTrack;
  21228. case 'color':
  21229. return ColorKeyframeTrack;
  21230. case 'quaternion':
  21231. return QuaternionKeyframeTrack;
  21232. case 'bool':
  21233. case 'boolean':
  21234. return BooleanKeyframeTrack;
  21235. case 'string':
  21236. return StringKeyframeTrack;
  21237. }
  21238. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21239. }
  21240. function parseKeyframeTrack(json) {
  21241. if (json.type === undefined) {
  21242. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21243. }
  21244. var trackType = getTrackTypeForValueTypeName(json.type);
  21245. if (json.times === undefined) {
  21246. var times = [],
  21247. values = [];
  21248. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21249. json.times = times;
  21250. json.values = values;
  21251. } // derived classes can define a static parse method
  21252. if (trackType.parse !== undefined) {
  21253. return trackType.parse(json);
  21254. } else {
  21255. // by default, we assume a constructor compatible with the base
  21256. return new trackType(json.name, json.times, json.values, json.interpolation);
  21257. }
  21258. }
  21259. Object.assign(AnimationClip, {
  21260. parse: function parse(json) {
  21261. var tracks = [],
  21262. jsonTracks = json.tracks,
  21263. frameTime = 1.0 / (json.fps || 1.0);
  21264. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21265. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21266. }
  21267. return new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21268. },
  21269. toJSON: function toJSON(clip) {
  21270. var tracks = [],
  21271. clipTracks = clip.tracks;
  21272. var json = {
  21273. 'name': clip.name,
  21274. 'duration': clip.duration,
  21275. 'tracks': tracks,
  21276. 'uuid': clip.uuid,
  21277. 'blendMode': clip.blendMode
  21278. };
  21279. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21280. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21281. }
  21282. return json;
  21283. },
  21284. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21285. var numMorphTargets = morphTargetSequence.length;
  21286. var tracks = [];
  21287. for (var i = 0; i < numMorphTargets; i++) {
  21288. var times = [];
  21289. var values = [];
  21290. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21291. values.push(0, 1, 0);
  21292. var order = AnimationUtils.getKeyframeOrder(times);
  21293. times = AnimationUtils.sortedArray(times, 1, order);
  21294. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21295. // last frame as well for perfect loop.
  21296. if (!noLoop && times[0] === 0) {
  21297. times.push(numMorphTargets);
  21298. values.push(values[0]);
  21299. }
  21300. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21301. }
  21302. return new AnimationClip(name, -1, tracks);
  21303. },
  21304. findByName: function findByName(objectOrClipArray, name) {
  21305. var clipArray = objectOrClipArray;
  21306. if (!Array.isArray(objectOrClipArray)) {
  21307. var o = objectOrClipArray;
  21308. clipArray = o.geometry && o.geometry.animations || o.animations;
  21309. }
  21310. for (var i = 0; i < clipArray.length; i++) {
  21311. if (clipArray[i].name === name) {
  21312. return clipArray[i];
  21313. }
  21314. }
  21315. return null;
  21316. },
  21317. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21318. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21319. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21320. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21321. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21322. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21323. var morphTarget = morphTargets[i];
  21324. var parts = morphTarget.name.match(pattern);
  21325. if (parts && parts.length > 1) {
  21326. var name = parts[1];
  21327. var animationMorphTargets = animationToMorphTargets[name];
  21328. if (!animationMorphTargets) {
  21329. animationToMorphTargets[name] = animationMorphTargets = [];
  21330. }
  21331. animationMorphTargets.push(morphTarget);
  21332. }
  21333. }
  21334. var clips = [];
  21335. for (var _name in animationToMorphTargets) {
  21336. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21337. }
  21338. return clips;
  21339. },
  21340. // parse the animation.hierarchy format
  21341. parseAnimation: function parseAnimation(animation, bones) {
  21342. if (!animation) {
  21343. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21344. return null;
  21345. }
  21346. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21347. // only return track if there are actually keys.
  21348. if (animationKeys.length !== 0) {
  21349. var times = [];
  21350. var values = [];
  21351. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21352. if (times.length !== 0) {
  21353. destTracks.push(new trackType(trackName, times, values));
  21354. }
  21355. }
  21356. };
  21357. var tracks = [];
  21358. var clipName = animation.name || 'default';
  21359. var fps = animation.fps || 30;
  21360. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21361. var duration = animation.length || -1;
  21362. var hierarchyTracks = animation.hierarchy || [];
  21363. for (var h = 0; h < hierarchyTracks.length; h++) {
  21364. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21365. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21366. if (animationKeys[0].morphTargets) {
  21367. // figure out all morph targets used in this track
  21368. var morphTargetNames = {};
  21369. var k = void 0;
  21370. for (k = 0; k < animationKeys.length; k++) {
  21371. if (animationKeys[k].morphTargets) {
  21372. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21373. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21374. }
  21375. }
  21376. } // create a track for each morph target with all zero
  21377. // morphTargetInfluences except for the keys in which
  21378. // the morphTarget is named.
  21379. for (var morphTargetName in morphTargetNames) {
  21380. var times = [];
  21381. var values = [];
  21382. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21383. var animationKey = animationKeys[k];
  21384. times.push(animationKey.time);
  21385. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21386. }
  21387. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21388. }
  21389. duration = morphTargetNames.length * (fps || 1.0);
  21390. } else {
  21391. // ...assume skeletal animation
  21392. var boneName = '.bones[' + bones[h].name + ']';
  21393. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21394. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21395. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21396. }
  21397. }
  21398. if (tracks.length === 0) {
  21399. return null;
  21400. }
  21401. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21402. return clip;
  21403. }
  21404. });
  21405. Object.assign(AnimationClip.prototype, {
  21406. resetDuration: function resetDuration() {
  21407. var tracks = this.tracks;
  21408. var duration = 0;
  21409. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21410. var track = this.tracks[i];
  21411. duration = Math.max(duration, track.times[track.times.length - 1]);
  21412. }
  21413. this.duration = duration;
  21414. return this;
  21415. },
  21416. trim: function trim() {
  21417. for (var i = 0; i < this.tracks.length; i++) {
  21418. this.tracks[i].trim(0, this.duration);
  21419. }
  21420. return this;
  21421. },
  21422. validate: function validate() {
  21423. var valid = true;
  21424. for (var i = 0; i < this.tracks.length; i++) {
  21425. valid = valid && this.tracks[i].validate();
  21426. }
  21427. return valid;
  21428. },
  21429. optimize: function optimize() {
  21430. for (var i = 0; i < this.tracks.length; i++) {
  21431. this.tracks[i].optimize();
  21432. }
  21433. return this;
  21434. },
  21435. clone: function clone() {
  21436. var tracks = [];
  21437. for (var i = 0; i < this.tracks.length; i++) {
  21438. tracks.push(this.tracks[i].clone());
  21439. }
  21440. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  21441. }
  21442. });
  21443. var Cache = {
  21444. enabled: false,
  21445. files: {},
  21446. add: function add(key, file) {
  21447. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  21448. this.files[key] = file;
  21449. },
  21450. get: function get(key) {
  21451. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  21452. return this.files[key];
  21453. },
  21454. remove: function remove(key) {
  21455. delete this.files[key];
  21456. },
  21457. clear: function clear() {
  21458. this.files = {};
  21459. }
  21460. };
  21461. function LoadingManager(onLoad, onProgress, onError) {
  21462. var scope = this;
  21463. var isLoading = false;
  21464. var itemsLoaded = 0;
  21465. var itemsTotal = 0;
  21466. var urlModifier = undefined;
  21467. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  21468. // in the constructor
  21469. this.onStart = undefined;
  21470. this.onLoad = onLoad;
  21471. this.onProgress = onProgress;
  21472. this.onError = onError;
  21473. this.itemStart = function (url) {
  21474. itemsTotal++;
  21475. if (isLoading === false) {
  21476. if (scope.onStart !== undefined) {
  21477. scope.onStart(url, itemsLoaded, itemsTotal);
  21478. }
  21479. }
  21480. isLoading = true;
  21481. };
  21482. this.itemEnd = function (url) {
  21483. itemsLoaded++;
  21484. if (scope.onProgress !== undefined) {
  21485. scope.onProgress(url, itemsLoaded, itemsTotal);
  21486. }
  21487. if (itemsLoaded === itemsTotal) {
  21488. isLoading = false;
  21489. if (scope.onLoad !== undefined) {
  21490. scope.onLoad();
  21491. }
  21492. }
  21493. };
  21494. this.itemError = function (url) {
  21495. if (scope.onError !== undefined) {
  21496. scope.onError(url);
  21497. }
  21498. };
  21499. this.resolveURL = function (url) {
  21500. if (urlModifier) {
  21501. return urlModifier(url);
  21502. }
  21503. return url;
  21504. };
  21505. this.setURLModifier = function (transform) {
  21506. urlModifier = transform;
  21507. return this;
  21508. };
  21509. this.addHandler = function (regex, loader) {
  21510. handlers.push(regex, loader);
  21511. return this;
  21512. };
  21513. this.removeHandler = function (regex) {
  21514. var index = handlers.indexOf(regex);
  21515. if (index !== -1) {
  21516. handlers.splice(index, 2);
  21517. }
  21518. return this;
  21519. };
  21520. this.getHandler = function (file) {
  21521. for (var i = 0, l = handlers.length; i < l; i += 2) {
  21522. var regex = handlers[i];
  21523. var loader = handlers[i + 1];
  21524. if (regex.global) regex.lastIndex = 0; // see #17920
  21525. if (regex.test(file)) {
  21526. return loader;
  21527. }
  21528. }
  21529. return null;
  21530. };
  21531. }
  21532. var DefaultLoadingManager = new LoadingManager();
  21533. function Loader(manager) {
  21534. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  21535. this.crossOrigin = 'anonymous';
  21536. this.withCredentials = false;
  21537. this.path = '';
  21538. this.resourcePath = '';
  21539. this.requestHeader = {};
  21540. }
  21541. Object.assign(Loader.prototype, {
  21542. load: function load()
  21543. /* url, onLoad, onProgress, onError */
  21544. {},
  21545. loadAsync: function loadAsync(url, onProgress) {
  21546. var scope = this;
  21547. return new Promise(function (resolve, reject) {
  21548. scope.load(url, resolve, onProgress, reject);
  21549. });
  21550. },
  21551. parse: function parse()
  21552. /* data */
  21553. {},
  21554. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  21555. this.crossOrigin = crossOrigin;
  21556. return this;
  21557. },
  21558. setWithCredentials: function setWithCredentials(value) {
  21559. this.withCredentials = value;
  21560. return this;
  21561. },
  21562. setPath: function setPath(path) {
  21563. this.path = path;
  21564. return this;
  21565. },
  21566. setResourcePath: function setResourcePath(resourcePath) {
  21567. this.resourcePath = resourcePath;
  21568. return this;
  21569. },
  21570. setRequestHeader: function setRequestHeader(requestHeader) {
  21571. this.requestHeader = requestHeader;
  21572. return this;
  21573. }
  21574. });
  21575. var loading = {};
  21576. function FileLoader(manager) {
  21577. Loader.call(this, manager);
  21578. }
  21579. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21580. constructor: FileLoader,
  21581. load: function load(url, onLoad, onProgress, onError) {
  21582. if (url === undefined) url = '';
  21583. if (this.path !== undefined) url = this.path + url;
  21584. url = this.manager.resolveURL(url);
  21585. var scope = this;
  21586. var cached = Cache.get(url);
  21587. if (cached !== undefined) {
  21588. scope.manager.itemStart(url);
  21589. setTimeout(function () {
  21590. if (onLoad) onLoad(cached);
  21591. scope.manager.itemEnd(url);
  21592. }, 0);
  21593. return cached;
  21594. } // Check if request is duplicate
  21595. if (loading[url] !== undefined) {
  21596. loading[url].push({
  21597. onLoad: onLoad,
  21598. onProgress: onProgress,
  21599. onError: onError
  21600. });
  21601. return;
  21602. } // Check for data: URI
  21603. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21604. var dataUriRegexResult = url.match(dataUriRegex);
  21605. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21606. if (dataUriRegexResult) {
  21607. var mimeType = dataUriRegexResult[1];
  21608. var isBase64 = !!dataUriRegexResult[2];
  21609. var data = dataUriRegexResult[3];
  21610. data = decodeURIComponent(data);
  21611. if (isBase64) data = atob(data);
  21612. try {
  21613. var response;
  21614. var responseType = (this.responseType || '').toLowerCase();
  21615. switch (responseType) {
  21616. case 'arraybuffer':
  21617. case 'blob':
  21618. var view = new Uint8Array(data.length);
  21619. for (var i = 0; i < data.length; i++) {
  21620. view[i] = data.charCodeAt(i);
  21621. }
  21622. if (responseType === 'blob') {
  21623. response = new Blob([view.buffer], {
  21624. type: mimeType
  21625. });
  21626. } else {
  21627. response = view.buffer;
  21628. }
  21629. break;
  21630. case 'document':
  21631. var parser = new DOMParser();
  21632. response = parser.parseFromString(data, mimeType);
  21633. break;
  21634. case 'json':
  21635. response = JSON.parse(data);
  21636. break;
  21637. default:
  21638. // 'text' or other
  21639. response = data;
  21640. break;
  21641. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21642. setTimeout(function () {
  21643. if (onLoad) onLoad(response);
  21644. scope.manager.itemEnd(url);
  21645. }, 0);
  21646. } catch (error) {
  21647. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21648. setTimeout(function () {
  21649. if (onError) onError(error);
  21650. scope.manager.itemError(url);
  21651. scope.manager.itemEnd(url);
  21652. }, 0);
  21653. }
  21654. } else {
  21655. // Initialise array for duplicate requests
  21656. loading[url] = [];
  21657. loading[url].push({
  21658. onLoad: onLoad,
  21659. onProgress: onProgress,
  21660. onError: onError
  21661. });
  21662. request = new XMLHttpRequest();
  21663. request.open('GET', url, true);
  21664. request.addEventListener('load', function (event) {
  21665. var response = this.response;
  21666. var callbacks = loading[url];
  21667. delete loading[url];
  21668. if (this.status === 200 || this.status === 0) {
  21669. // Some browsers return HTTP Status 0 when using non-http protocol
  21670. // e.g. 'file://' or 'data://'. Handle as success.
  21671. 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
  21672. // error response bodies as proper responses to requests.
  21673. Cache.add(url, response);
  21674. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  21675. var callback = callbacks[_i];
  21676. if (callback.onLoad) callback.onLoad(response);
  21677. }
  21678. scope.manager.itemEnd(url);
  21679. } else {
  21680. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  21681. var _callback = callbacks[_i2];
  21682. if (_callback.onError) _callback.onError(event);
  21683. }
  21684. scope.manager.itemError(url);
  21685. scope.manager.itemEnd(url);
  21686. }
  21687. }, false);
  21688. request.addEventListener('progress', function (event) {
  21689. var callbacks = loading[url];
  21690. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  21691. var callback = callbacks[_i3];
  21692. if (callback.onProgress) callback.onProgress(event);
  21693. }
  21694. }, false);
  21695. request.addEventListener('error', function (event) {
  21696. var callbacks = loading[url];
  21697. delete loading[url];
  21698. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  21699. var callback = callbacks[_i4];
  21700. if (callback.onError) callback.onError(event);
  21701. }
  21702. scope.manager.itemError(url);
  21703. scope.manager.itemEnd(url);
  21704. }, false);
  21705. request.addEventListener('abort', function (event) {
  21706. var callbacks = loading[url];
  21707. delete loading[url];
  21708. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  21709. var callback = callbacks[_i5];
  21710. if (callback.onError) callback.onError(event);
  21711. }
  21712. scope.manager.itemError(url);
  21713. scope.manager.itemEnd(url);
  21714. }, false);
  21715. if (this.responseType !== undefined) request.responseType = this.responseType;
  21716. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  21717. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  21718. for (var header in this.requestHeader) {
  21719. request.setRequestHeader(header, this.requestHeader[header]);
  21720. }
  21721. request.send(null);
  21722. }
  21723. scope.manager.itemStart(url);
  21724. return request;
  21725. },
  21726. setResponseType: function setResponseType(value) {
  21727. this.responseType = value;
  21728. return this;
  21729. },
  21730. setMimeType: function setMimeType(value) {
  21731. this.mimeType = value;
  21732. return this;
  21733. }
  21734. });
  21735. function AnimationLoader(manager) {
  21736. Loader.call(this, manager);
  21737. }
  21738. AnimationLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21739. constructor: AnimationLoader,
  21740. load: function load(url, onLoad, onProgress, onError) {
  21741. var scope = this;
  21742. var loader = new FileLoader(scope.manager);
  21743. loader.setPath(scope.path);
  21744. loader.setRequestHeader(scope.requestHeader);
  21745. loader.setWithCredentials(scope.withCredentials);
  21746. loader.load(url, function (text) {
  21747. try {
  21748. onLoad(scope.parse(JSON.parse(text)));
  21749. } catch (e) {
  21750. if (onError) {
  21751. onError(e);
  21752. } else {
  21753. console.error(e);
  21754. }
  21755. scope.manager.itemError(url);
  21756. }
  21757. }, onProgress, onError);
  21758. },
  21759. parse: function parse(json) {
  21760. var animations = [];
  21761. for (var i = 0; i < json.length; i++) {
  21762. var clip = AnimationClip.parse(json[i]);
  21763. animations.push(clip);
  21764. }
  21765. return animations;
  21766. }
  21767. });
  21768. /**
  21769. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21770. *
  21771. * Sub classes have to implement the parse() method which will be used in load().
  21772. */
  21773. function CompressedTextureLoader(manager) {
  21774. Loader.call(this, manager);
  21775. }
  21776. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21777. constructor: CompressedTextureLoader,
  21778. load: function load(url, onLoad, onProgress, onError) {
  21779. var scope = this;
  21780. var images = [];
  21781. var texture = new CompressedTexture();
  21782. texture.image = images;
  21783. var loader = new FileLoader(this.manager);
  21784. loader.setPath(this.path);
  21785. loader.setResponseType('arraybuffer');
  21786. loader.setRequestHeader(this.requestHeader);
  21787. loader.setWithCredentials(scope.withCredentials);
  21788. var loaded = 0;
  21789. function loadTexture(i) {
  21790. loader.load(url[i], function (buffer) {
  21791. var texDatas = scope.parse(buffer, true);
  21792. images[i] = {
  21793. width: texDatas.width,
  21794. height: texDatas.height,
  21795. format: texDatas.format,
  21796. mipmaps: texDatas.mipmaps
  21797. };
  21798. loaded += 1;
  21799. if (loaded === 6) {
  21800. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  21801. texture.format = texDatas.format;
  21802. texture.needsUpdate = true;
  21803. if (onLoad) onLoad(texture);
  21804. }
  21805. }, onProgress, onError);
  21806. }
  21807. if (Array.isArray(url)) {
  21808. for (var i = 0, il = url.length; i < il; ++i) {
  21809. loadTexture(i);
  21810. }
  21811. } else {
  21812. // compressed cubemap texture stored in a single DDS file
  21813. loader.load(url, function (buffer) {
  21814. var texDatas = scope.parse(buffer, true);
  21815. if (texDatas.isCubemap) {
  21816. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21817. for (var f = 0; f < faces; f++) {
  21818. images[f] = {
  21819. mipmaps: []
  21820. };
  21821. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  21822. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  21823. images[f].format = texDatas.format;
  21824. images[f].width = texDatas.width;
  21825. images[f].height = texDatas.height;
  21826. }
  21827. }
  21828. } else {
  21829. texture.image.width = texDatas.width;
  21830. texture.image.height = texDatas.height;
  21831. texture.mipmaps = texDatas.mipmaps;
  21832. }
  21833. if (texDatas.mipmapCount === 1) {
  21834. texture.minFilter = LinearFilter;
  21835. }
  21836. texture.format = texDatas.format;
  21837. texture.needsUpdate = true;
  21838. if (onLoad) onLoad(texture);
  21839. }, onProgress, onError);
  21840. }
  21841. return texture;
  21842. }
  21843. });
  21844. function ImageLoader(manager) {
  21845. Loader.call(this, manager);
  21846. }
  21847. ImageLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21848. constructor: ImageLoader,
  21849. load: function load(url, onLoad, onProgress, onError) {
  21850. if (this.path !== undefined) url = this.path + url;
  21851. url = this.manager.resolveURL(url);
  21852. var scope = this;
  21853. var cached = Cache.get(url);
  21854. if (cached !== undefined) {
  21855. scope.manager.itemStart(url);
  21856. setTimeout(function () {
  21857. if (onLoad) onLoad(cached);
  21858. scope.manager.itemEnd(url);
  21859. }, 0);
  21860. return cached;
  21861. }
  21862. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  21863. function onImageLoad() {
  21864. image.removeEventListener('load', onImageLoad, false);
  21865. image.removeEventListener('error', onImageError, false);
  21866. Cache.add(url, this);
  21867. if (onLoad) onLoad(this);
  21868. scope.manager.itemEnd(url);
  21869. }
  21870. function onImageError(event) {
  21871. image.removeEventListener('load', onImageLoad, false);
  21872. image.removeEventListener('error', onImageError, false);
  21873. if (onError) onError(event);
  21874. scope.manager.itemError(url);
  21875. scope.manager.itemEnd(url);
  21876. }
  21877. image.addEventListener('load', onImageLoad, false);
  21878. image.addEventListener('error', onImageError, false);
  21879. if (url.substr(0, 5) !== 'data:') {
  21880. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  21881. }
  21882. scope.manager.itemStart(url);
  21883. image.src = url;
  21884. return image;
  21885. }
  21886. });
  21887. function CubeTextureLoader(manager) {
  21888. Loader.call(this, manager);
  21889. }
  21890. CubeTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21891. constructor: CubeTextureLoader,
  21892. load: function load(urls, onLoad, onProgress, onError) {
  21893. var texture = new CubeTexture();
  21894. var loader = new ImageLoader(this.manager);
  21895. loader.setCrossOrigin(this.crossOrigin);
  21896. loader.setPath(this.path);
  21897. var loaded = 0;
  21898. function loadTexture(i) {
  21899. loader.load(urls[i], function (image) {
  21900. texture.images[i] = image;
  21901. loaded++;
  21902. if (loaded === 6) {
  21903. texture.needsUpdate = true;
  21904. if (onLoad) onLoad(texture);
  21905. }
  21906. }, undefined, onError);
  21907. }
  21908. for (var i = 0; i < urls.length; ++i) {
  21909. loadTexture(i);
  21910. }
  21911. return texture;
  21912. }
  21913. });
  21914. /**
  21915. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  21916. *
  21917. * Sub classes have to implement the parse() method which will be used in load().
  21918. */
  21919. function DataTextureLoader(manager) {
  21920. Loader.call(this, manager);
  21921. }
  21922. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21923. constructor: DataTextureLoader,
  21924. load: function load(url, onLoad, onProgress, onError) {
  21925. var scope = this;
  21926. var texture = new DataTexture();
  21927. var loader = new FileLoader(this.manager);
  21928. loader.setResponseType('arraybuffer');
  21929. loader.setRequestHeader(this.requestHeader);
  21930. loader.setPath(this.path);
  21931. loader.setWithCredentials(scope.withCredentials);
  21932. loader.load(url, function (buffer) {
  21933. var texData = scope.parse(buffer);
  21934. if (!texData) return;
  21935. if (texData.image !== undefined) {
  21936. texture.image = texData.image;
  21937. } else if (texData.data !== undefined) {
  21938. texture.image.width = texData.width;
  21939. texture.image.height = texData.height;
  21940. texture.image.data = texData.data;
  21941. }
  21942. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  21943. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  21944. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  21945. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  21946. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  21947. if (texData.format !== undefined) {
  21948. texture.format = texData.format;
  21949. }
  21950. if (texData.type !== undefined) {
  21951. texture.type = texData.type;
  21952. }
  21953. if (texData.mipmaps !== undefined) {
  21954. texture.mipmaps = texData.mipmaps;
  21955. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  21956. }
  21957. if (texData.mipmapCount === 1) {
  21958. texture.minFilter = LinearFilter;
  21959. }
  21960. texture.needsUpdate = true;
  21961. if (onLoad) onLoad(texture, texData);
  21962. }, onProgress, onError);
  21963. return texture;
  21964. }
  21965. });
  21966. function TextureLoader(manager) {
  21967. Loader.call(this, manager);
  21968. }
  21969. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21970. constructor: TextureLoader,
  21971. load: function load(url, onLoad, onProgress, onError) {
  21972. var texture = new Texture();
  21973. var loader = new ImageLoader(this.manager);
  21974. loader.setCrossOrigin(this.crossOrigin);
  21975. loader.setPath(this.path);
  21976. loader.load(url, function (image) {
  21977. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  21978. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  21979. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  21980. texture.needsUpdate = true;
  21981. if (onLoad !== undefined) {
  21982. onLoad(texture);
  21983. }
  21984. }, onProgress, onError);
  21985. return texture;
  21986. }
  21987. });
  21988. /**
  21989. * Extensible curve object.
  21990. *
  21991. * Some common of curve methods:
  21992. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  21993. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  21994. * .getPoints(), .getSpacedPoints()
  21995. * .getLength()
  21996. * .updateArcLengths()
  21997. *
  21998. * This following curves inherit from THREE.Curve:
  21999. *
  22000. * -- 2D curves --
  22001. * THREE.ArcCurve
  22002. * THREE.CubicBezierCurve
  22003. * THREE.EllipseCurve
  22004. * THREE.LineCurve
  22005. * THREE.QuadraticBezierCurve
  22006. * THREE.SplineCurve
  22007. *
  22008. * -- 3D curves --
  22009. * THREE.CatmullRomCurve3
  22010. * THREE.CubicBezierCurve3
  22011. * THREE.LineCurve3
  22012. * THREE.QuadraticBezierCurve3
  22013. *
  22014. * A series of curves can be represented as a THREE.CurvePath.
  22015. *
  22016. **/
  22017. function Curve() {
  22018. this.type = 'Curve';
  22019. this.arcLengthDivisions = 200;
  22020. }
  22021. Object.assign(Curve.prototype, {
  22022. // Virtual base class method to overwrite and implement in subclasses
  22023. // - t [0 .. 1]
  22024. getPoint: function getPoint()
  22025. /* t, optionalTarget */
  22026. {
  22027. console.warn('THREE.Curve: .getPoint() not implemented.');
  22028. return null;
  22029. },
  22030. // Get point at relative position in curve according to arc length
  22031. // - u [0 .. 1]
  22032. getPointAt: function getPointAt(u, optionalTarget) {
  22033. var t = this.getUtoTmapping(u);
  22034. return this.getPoint(t, optionalTarget);
  22035. },
  22036. // Get sequence of points using getPoint( t )
  22037. getPoints: function getPoints(divisions) {
  22038. if (divisions === undefined) divisions = 5;
  22039. var points = [];
  22040. for (var d = 0; d <= divisions; d++) {
  22041. points.push(this.getPoint(d / divisions));
  22042. }
  22043. return points;
  22044. },
  22045. // Get sequence of points using getPointAt( u )
  22046. getSpacedPoints: function getSpacedPoints(divisions) {
  22047. if (divisions === undefined) divisions = 5;
  22048. var points = [];
  22049. for (var d = 0; d <= divisions; d++) {
  22050. points.push(this.getPointAt(d / divisions));
  22051. }
  22052. return points;
  22053. },
  22054. // Get total curve arc length
  22055. getLength: function getLength() {
  22056. var lengths = this.getLengths();
  22057. return lengths[lengths.length - 1];
  22058. },
  22059. // Get list of cumulative segment lengths
  22060. getLengths: function getLengths(divisions) {
  22061. if (divisions === undefined) divisions = this.arcLengthDivisions;
  22062. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  22063. return this.cacheArcLengths;
  22064. }
  22065. this.needsUpdate = false;
  22066. var cache = [];
  22067. var current,
  22068. last = this.getPoint(0);
  22069. var sum = 0;
  22070. cache.push(0);
  22071. for (var p = 1; p <= divisions; p++) {
  22072. current = this.getPoint(p / divisions);
  22073. sum += current.distanceTo(last);
  22074. cache.push(sum);
  22075. last = current;
  22076. }
  22077. this.cacheArcLengths = cache;
  22078. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22079. },
  22080. updateArcLengths: function updateArcLengths() {
  22081. this.needsUpdate = true;
  22082. this.getLengths();
  22083. },
  22084. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22085. getUtoTmapping: function getUtoTmapping(u, distance) {
  22086. var arcLengths = this.getLengths();
  22087. var i = 0;
  22088. var il = arcLengths.length;
  22089. var targetArcLength; // The targeted u distance value to get
  22090. if (distance) {
  22091. targetArcLength = distance;
  22092. } else {
  22093. targetArcLength = u * arcLengths[il - 1];
  22094. } // binary search for the index with largest value smaller than target u distance
  22095. var low = 0,
  22096. high = il - 1,
  22097. comparison;
  22098. while (low <= high) {
  22099. 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
  22100. comparison = arcLengths[i] - targetArcLength;
  22101. if (comparison < 0) {
  22102. low = i + 1;
  22103. } else if (comparison > 0) {
  22104. high = i - 1;
  22105. } else {
  22106. high = i;
  22107. break; // DONE
  22108. }
  22109. }
  22110. i = high;
  22111. if (arcLengths[i] === targetArcLength) {
  22112. return i / (il - 1);
  22113. } // we could get finer grain at lengths, or use simple interpolation between two points
  22114. var lengthBefore = arcLengths[i];
  22115. var lengthAfter = arcLengths[i + 1];
  22116. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  22117. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  22118. var t = (i + segmentFraction) / (il - 1);
  22119. return t;
  22120. },
  22121. // Returns a unit vector tangent at t
  22122. // In case any sub curve does not implement its tangent derivation,
  22123. // 2 points a small delta apart will be used to find its gradient
  22124. // which seems to give a reasonable approximation
  22125. getTangent: function getTangent(t, optionalTarget) {
  22126. var delta = 0.0001;
  22127. var t1 = t - delta;
  22128. var t2 = t + delta; // Capping in case of danger
  22129. if (t1 < 0) t1 = 0;
  22130. if (t2 > 1) t2 = 1;
  22131. var pt1 = this.getPoint(t1);
  22132. var pt2 = this.getPoint(t2);
  22133. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22134. tangent.copy(pt2).sub(pt1).normalize();
  22135. return tangent;
  22136. },
  22137. getTangentAt: function getTangentAt(u, optionalTarget) {
  22138. var t = this.getUtoTmapping(u);
  22139. return this.getTangent(t, optionalTarget);
  22140. },
  22141. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22142. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22143. var normal = new Vector3();
  22144. var tangents = [];
  22145. var normals = [];
  22146. var binormals = [];
  22147. var vec = new Vector3();
  22148. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22149. for (var i = 0; i <= segments; i++) {
  22150. var u = i / segments;
  22151. tangents[i] = this.getTangentAt(u, new Vector3());
  22152. tangents[i].normalize();
  22153. } // select an initial normal vector perpendicular to the first tangent vector,
  22154. // and in the direction of the minimum tangent xyz component
  22155. normals[0] = new Vector3();
  22156. binormals[0] = new Vector3();
  22157. var min = Number.MAX_VALUE;
  22158. var tx = Math.abs(tangents[0].x);
  22159. var ty = Math.abs(tangents[0].y);
  22160. var tz = Math.abs(tangents[0].z);
  22161. if (tx <= min) {
  22162. min = tx;
  22163. normal.set(1, 0, 0);
  22164. }
  22165. if (ty <= min) {
  22166. min = ty;
  22167. normal.set(0, 1, 0);
  22168. }
  22169. if (tz <= min) {
  22170. normal.set(0, 0, 1);
  22171. }
  22172. vec.crossVectors(tangents[0], normal).normalize();
  22173. normals[0].crossVectors(tangents[0], vec);
  22174. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22175. for (var _i = 1; _i <= segments; _i++) {
  22176. normals[_i] = normals[_i - 1].clone();
  22177. binormals[_i] = binormals[_i - 1].clone();
  22178. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22179. if (vec.length() > Number.EPSILON) {
  22180. vec.normalize();
  22181. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22182. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22183. }
  22184. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22185. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22186. if (closed === true) {
  22187. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22188. _theta /= segments;
  22189. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22190. _theta = -_theta;
  22191. }
  22192. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22193. // twist a little...
  22194. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22195. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22196. }
  22197. }
  22198. return {
  22199. tangents: tangents,
  22200. normals: normals,
  22201. binormals: binormals
  22202. };
  22203. },
  22204. clone: function clone() {
  22205. return new this.constructor().copy(this);
  22206. },
  22207. copy: function copy(source) {
  22208. this.arcLengthDivisions = source.arcLengthDivisions;
  22209. return this;
  22210. },
  22211. toJSON: function toJSON() {
  22212. var data = {
  22213. metadata: {
  22214. version: 4.5,
  22215. type: 'Curve',
  22216. generator: 'Curve.toJSON'
  22217. }
  22218. };
  22219. data.arcLengthDivisions = this.arcLengthDivisions;
  22220. data.type = this.type;
  22221. return data;
  22222. },
  22223. fromJSON: function fromJSON(json) {
  22224. this.arcLengthDivisions = json.arcLengthDivisions;
  22225. return this;
  22226. }
  22227. });
  22228. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22229. Curve.call(this);
  22230. this.type = 'EllipseCurve';
  22231. this.aX = aX || 0;
  22232. this.aY = aY || 0;
  22233. this.xRadius = xRadius || 1;
  22234. this.yRadius = yRadius || 1;
  22235. this.aStartAngle = aStartAngle || 0;
  22236. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22237. this.aClockwise = aClockwise || false;
  22238. this.aRotation = aRotation || 0;
  22239. }
  22240. EllipseCurve.prototype = Object.create(Curve.prototype);
  22241. EllipseCurve.prototype.constructor = EllipseCurve;
  22242. EllipseCurve.prototype.isEllipseCurve = true;
  22243. EllipseCurve.prototype.getPoint = function (t, optionalTarget) {
  22244. var point = optionalTarget || new Vector2();
  22245. var twoPi = Math.PI * 2;
  22246. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22247. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22248. while (deltaAngle < 0) {
  22249. deltaAngle += twoPi;
  22250. }
  22251. while (deltaAngle > twoPi) {
  22252. deltaAngle -= twoPi;
  22253. }
  22254. if (deltaAngle < Number.EPSILON) {
  22255. if (samePoints) {
  22256. deltaAngle = 0;
  22257. } else {
  22258. deltaAngle = twoPi;
  22259. }
  22260. }
  22261. if (this.aClockwise === true && !samePoints) {
  22262. if (deltaAngle === twoPi) {
  22263. deltaAngle = -twoPi;
  22264. } else {
  22265. deltaAngle = deltaAngle - twoPi;
  22266. }
  22267. }
  22268. var angle = this.aStartAngle + t * deltaAngle;
  22269. var x = this.aX + this.xRadius * Math.cos(angle);
  22270. var y = this.aY + this.yRadius * Math.sin(angle);
  22271. if (this.aRotation !== 0) {
  22272. var cos = Math.cos(this.aRotation);
  22273. var sin = Math.sin(this.aRotation);
  22274. var tx = x - this.aX;
  22275. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22276. x = tx * cos - ty * sin + this.aX;
  22277. y = tx * sin + ty * cos + this.aY;
  22278. }
  22279. return point.set(x, y);
  22280. };
  22281. EllipseCurve.prototype.copy = function (source) {
  22282. Curve.prototype.copy.call(this, source);
  22283. this.aX = source.aX;
  22284. this.aY = source.aY;
  22285. this.xRadius = source.xRadius;
  22286. this.yRadius = source.yRadius;
  22287. this.aStartAngle = source.aStartAngle;
  22288. this.aEndAngle = source.aEndAngle;
  22289. this.aClockwise = source.aClockwise;
  22290. this.aRotation = source.aRotation;
  22291. return this;
  22292. };
  22293. EllipseCurve.prototype.toJSON = function () {
  22294. var data = Curve.prototype.toJSON.call(this);
  22295. data.aX = this.aX;
  22296. data.aY = this.aY;
  22297. data.xRadius = this.xRadius;
  22298. data.yRadius = this.yRadius;
  22299. data.aStartAngle = this.aStartAngle;
  22300. data.aEndAngle = this.aEndAngle;
  22301. data.aClockwise = this.aClockwise;
  22302. data.aRotation = this.aRotation;
  22303. return data;
  22304. };
  22305. EllipseCurve.prototype.fromJSON = function (json) {
  22306. Curve.prototype.fromJSON.call(this, json);
  22307. this.aX = json.aX;
  22308. this.aY = json.aY;
  22309. this.xRadius = json.xRadius;
  22310. this.yRadius = json.yRadius;
  22311. this.aStartAngle = json.aStartAngle;
  22312. this.aEndAngle = json.aEndAngle;
  22313. this.aClockwise = json.aClockwise;
  22314. this.aRotation = json.aRotation;
  22315. return this;
  22316. };
  22317. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22318. EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  22319. this.type = 'ArcCurve';
  22320. }
  22321. ArcCurve.prototype = Object.create(EllipseCurve.prototype);
  22322. ArcCurve.prototype.constructor = ArcCurve;
  22323. ArcCurve.prototype.isArcCurve = true;
  22324. /**
  22325. * Centripetal CatmullRom Curve - which is useful for avoiding
  22326. * cusps and self-intersections in non-uniform catmull rom curves.
  22327. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22328. *
  22329. * curve.type accepts centripetal(default), chordal and catmullrom
  22330. * curve.tension is used for catmullrom which defaults to 0.5
  22331. */
  22332. /*
  22333. Based on an optimized c++ solution in
  22334. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22335. - http://ideone.com/NoEbVM
  22336. This CubicPoly class could be used for reusing some variables and calculations,
  22337. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22338. which can be placed in CurveUtils.
  22339. */
  22340. function CubicPoly() {
  22341. var c0 = 0,
  22342. c1 = 0,
  22343. c2 = 0,
  22344. c3 = 0;
  22345. /*
  22346. * Compute coefficients for a cubic polynomial
  22347. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22348. * such that
  22349. * p(0) = x0, p(1) = x1
  22350. * and
  22351. * p'(0) = t0, p'(1) = t1.
  22352. */
  22353. function init(x0, x1, t0, t1) {
  22354. c0 = x0;
  22355. c1 = t0;
  22356. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22357. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22358. }
  22359. return {
  22360. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22361. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22362. },
  22363. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22364. // compute tangents when parameterized in [t1,t2]
  22365. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22366. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22367. t1 *= dt1;
  22368. t2 *= dt1;
  22369. init(x1, x2, t1, t2);
  22370. },
  22371. calc: function calc(t) {
  22372. var t2 = t * t;
  22373. var t3 = t2 * t;
  22374. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22375. }
  22376. };
  22377. } //
  22378. var tmp = new Vector3();
  22379. var px = new CubicPoly(),
  22380. py = new CubicPoly(),
  22381. pz = new CubicPoly();
  22382. function CatmullRomCurve3(points, closed, curveType, tension) {
  22383. Curve.call(this);
  22384. this.type = 'CatmullRomCurve3';
  22385. this.points = points || [];
  22386. this.closed = closed || false;
  22387. this.curveType = curveType || 'centripetal';
  22388. this.tension = tension !== undefined ? tension : 0.5;
  22389. }
  22390. CatmullRomCurve3.prototype = Object.create(Curve.prototype);
  22391. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22392. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22393. CatmullRomCurve3.prototype.getPoint = function (t, optionalTarget) {
  22394. var point = optionalTarget || new Vector3();
  22395. var points = this.points;
  22396. var l = points.length;
  22397. var p = (l - (this.closed ? 0 : 1)) * t;
  22398. var intPoint = Math.floor(p);
  22399. var weight = p - intPoint;
  22400. if (this.closed) {
  22401. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22402. } else if (weight === 0 && intPoint === l - 1) {
  22403. intPoint = l - 2;
  22404. weight = 1;
  22405. }
  22406. var p0, p3; // 4 points (p1 & p2 defined below)
  22407. if (this.closed || intPoint > 0) {
  22408. p0 = points[(intPoint - 1) % l];
  22409. } else {
  22410. // extrapolate first point
  22411. tmp.subVectors(points[0], points[1]).add(points[0]);
  22412. p0 = tmp;
  22413. }
  22414. var p1 = points[intPoint % l];
  22415. var p2 = points[(intPoint + 1) % l];
  22416. if (this.closed || intPoint + 2 < l) {
  22417. p3 = points[(intPoint + 2) % l];
  22418. } else {
  22419. // extrapolate last point
  22420. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  22421. p3 = tmp;
  22422. }
  22423. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  22424. // init Centripetal / Chordal Catmull-Rom
  22425. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22426. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  22427. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  22428. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  22429. if (dt1 < 1e-4) dt1 = 1.0;
  22430. if (dt0 < 1e-4) dt0 = dt1;
  22431. if (dt2 < 1e-4) dt2 = dt1;
  22432. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  22433. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  22434. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  22435. } else if (this.curveType === 'catmullrom') {
  22436. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  22437. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  22438. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  22439. }
  22440. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  22441. return point;
  22442. };
  22443. CatmullRomCurve3.prototype.copy = function (source) {
  22444. Curve.prototype.copy.call(this, source);
  22445. this.points = [];
  22446. for (var i = 0, l = source.points.length; i < l; i++) {
  22447. var point = source.points[i];
  22448. this.points.push(point.clone());
  22449. }
  22450. this.closed = source.closed;
  22451. this.curveType = source.curveType;
  22452. this.tension = source.tension;
  22453. return this;
  22454. };
  22455. CatmullRomCurve3.prototype.toJSON = function () {
  22456. var data = Curve.prototype.toJSON.call(this);
  22457. data.points = [];
  22458. for (var i = 0, l = this.points.length; i < l; i++) {
  22459. var point = this.points[i];
  22460. data.points.push(point.toArray());
  22461. }
  22462. data.closed = this.closed;
  22463. data.curveType = this.curveType;
  22464. data.tension = this.tension;
  22465. return data;
  22466. };
  22467. CatmullRomCurve3.prototype.fromJSON = function (json) {
  22468. Curve.prototype.fromJSON.call(this, json);
  22469. this.points = [];
  22470. for (var i = 0, l = json.points.length; i < l; i++) {
  22471. var point = json.points[i];
  22472. this.points.push(new Vector3().fromArray(point));
  22473. }
  22474. this.closed = json.closed;
  22475. this.curveType = json.curveType;
  22476. this.tension = json.tension;
  22477. return this;
  22478. };
  22479. /**
  22480. * Bezier Curves formulas obtained from
  22481. * http://en.wikipedia.org/wiki/Bézier_curve
  22482. */
  22483. function CatmullRom(t, p0, p1, p2, p3) {
  22484. var v0 = (p2 - p0) * 0.5;
  22485. var v1 = (p3 - p1) * 0.5;
  22486. var t2 = t * t;
  22487. var t3 = t * t2;
  22488. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  22489. } //
  22490. function QuadraticBezierP0(t, p) {
  22491. var k = 1 - t;
  22492. return k * k * p;
  22493. }
  22494. function QuadraticBezierP1(t, p) {
  22495. return 2 * (1 - t) * t * p;
  22496. }
  22497. function QuadraticBezierP2(t, p) {
  22498. return t * t * p;
  22499. }
  22500. function QuadraticBezier(t, p0, p1, p2) {
  22501. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  22502. } //
  22503. function CubicBezierP0(t, p) {
  22504. var k = 1 - t;
  22505. return k * k * k * p;
  22506. }
  22507. function CubicBezierP1(t, p) {
  22508. var k = 1 - t;
  22509. return 3 * k * k * t * p;
  22510. }
  22511. function CubicBezierP2(t, p) {
  22512. return 3 * (1 - t) * t * t * p;
  22513. }
  22514. function CubicBezierP3(t, p) {
  22515. return t * t * t * p;
  22516. }
  22517. function CubicBezier(t, p0, p1, p2, p3) {
  22518. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  22519. }
  22520. function CubicBezierCurve(v0, v1, v2, v3) {
  22521. Curve.call(this);
  22522. this.type = 'CubicBezierCurve';
  22523. this.v0 = v0 || new Vector2();
  22524. this.v1 = v1 || new Vector2();
  22525. this.v2 = v2 || new Vector2();
  22526. this.v3 = v3 || new Vector2();
  22527. }
  22528. CubicBezierCurve.prototype = Object.create(Curve.prototype);
  22529. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  22530. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  22531. CubicBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22532. var point = optionalTarget || new Vector2();
  22533. var v0 = this.v0,
  22534. v1 = this.v1,
  22535. v2 = this.v2,
  22536. v3 = this.v3;
  22537. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  22538. return point;
  22539. };
  22540. CubicBezierCurve.prototype.copy = function (source) {
  22541. Curve.prototype.copy.call(this, source);
  22542. this.v0.copy(source.v0);
  22543. this.v1.copy(source.v1);
  22544. this.v2.copy(source.v2);
  22545. this.v3.copy(source.v3);
  22546. return this;
  22547. };
  22548. CubicBezierCurve.prototype.toJSON = function () {
  22549. var data = Curve.prototype.toJSON.call(this);
  22550. data.v0 = this.v0.toArray();
  22551. data.v1 = this.v1.toArray();
  22552. data.v2 = this.v2.toArray();
  22553. data.v3 = this.v3.toArray();
  22554. return data;
  22555. };
  22556. CubicBezierCurve.prototype.fromJSON = function (json) {
  22557. Curve.prototype.fromJSON.call(this, json);
  22558. this.v0.fromArray(json.v0);
  22559. this.v1.fromArray(json.v1);
  22560. this.v2.fromArray(json.v2);
  22561. this.v3.fromArray(json.v3);
  22562. return this;
  22563. };
  22564. function CubicBezierCurve3(v0, v1, v2, v3) {
  22565. Curve.call(this);
  22566. this.type = 'CubicBezierCurve3';
  22567. this.v0 = v0 || new Vector3();
  22568. this.v1 = v1 || new Vector3();
  22569. this.v2 = v2 || new Vector3();
  22570. this.v3 = v3 || new Vector3();
  22571. }
  22572. CubicBezierCurve3.prototype = Object.create(Curve.prototype);
  22573. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  22574. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  22575. CubicBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22576. var point = optionalTarget || new Vector3();
  22577. var v0 = this.v0,
  22578. v1 = this.v1,
  22579. v2 = this.v2,
  22580. v3 = this.v3;
  22581. 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));
  22582. return point;
  22583. };
  22584. CubicBezierCurve3.prototype.copy = function (source) {
  22585. Curve.prototype.copy.call(this, source);
  22586. this.v0.copy(source.v0);
  22587. this.v1.copy(source.v1);
  22588. this.v2.copy(source.v2);
  22589. this.v3.copy(source.v3);
  22590. return this;
  22591. };
  22592. CubicBezierCurve3.prototype.toJSON = function () {
  22593. var data = Curve.prototype.toJSON.call(this);
  22594. data.v0 = this.v0.toArray();
  22595. data.v1 = this.v1.toArray();
  22596. data.v2 = this.v2.toArray();
  22597. data.v3 = this.v3.toArray();
  22598. return data;
  22599. };
  22600. CubicBezierCurve3.prototype.fromJSON = function (json) {
  22601. Curve.prototype.fromJSON.call(this, json);
  22602. this.v0.fromArray(json.v0);
  22603. this.v1.fromArray(json.v1);
  22604. this.v2.fromArray(json.v2);
  22605. this.v3.fromArray(json.v3);
  22606. return this;
  22607. };
  22608. function LineCurve(v1, v2) {
  22609. Curve.call(this);
  22610. this.type = 'LineCurve';
  22611. this.v1 = v1 || new Vector2();
  22612. this.v2 = v2 || new Vector2();
  22613. }
  22614. LineCurve.prototype = Object.create(Curve.prototype);
  22615. LineCurve.prototype.constructor = LineCurve;
  22616. LineCurve.prototype.isLineCurve = true;
  22617. LineCurve.prototype.getPoint = function (t, optionalTarget) {
  22618. var point = optionalTarget || new Vector2();
  22619. if (t === 1) {
  22620. point.copy(this.v2);
  22621. } else {
  22622. point.copy(this.v2).sub(this.v1);
  22623. point.multiplyScalar(t).add(this.v1);
  22624. }
  22625. return point;
  22626. }; // Line curve is linear, so we can overwrite default getPointAt
  22627. LineCurve.prototype.getPointAt = function (u, optionalTarget) {
  22628. return this.getPoint(u, optionalTarget);
  22629. };
  22630. LineCurve.prototype.getTangent = function (t, optionalTarget) {
  22631. var tangent = optionalTarget || new Vector2();
  22632. tangent.copy(this.v2).sub(this.v1).normalize();
  22633. return tangent;
  22634. };
  22635. LineCurve.prototype.copy = function (source) {
  22636. Curve.prototype.copy.call(this, source);
  22637. this.v1.copy(source.v1);
  22638. this.v2.copy(source.v2);
  22639. return this;
  22640. };
  22641. LineCurve.prototype.toJSON = function () {
  22642. var data = Curve.prototype.toJSON.call(this);
  22643. data.v1 = this.v1.toArray();
  22644. data.v2 = this.v2.toArray();
  22645. return data;
  22646. };
  22647. LineCurve.prototype.fromJSON = function (json) {
  22648. Curve.prototype.fromJSON.call(this, json);
  22649. this.v1.fromArray(json.v1);
  22650. this.v2.fromArray(json.v2);
  22651. return this;
  22652. };
  22653. function LineCurve3(v1, v2) {
  22654. Curve.call(this);
  22655. this.type = 'LineCurve3';
  22656. this.v1 = v1 || new Vector3();
  22657. this.v2 = v2 || new Vector3();
  22658. }
  22659. LineCurve3.prototype = Object.create(Curve.prototype);
  22660. LineCurve3.prototype.constructor = LineCurve3;
  22661. LineCurve3.prototype.isLineCurve3 = true;
  22662. LineCurve3.prototype.getPoint = function (t, optionalTarget) {
  22663. var point = optionalTarget || new Vector3();
  22664. if (t === 1) {
  22665. point.copy(this.v2);
  22666. } else {
  22667. point.copy(this.v2).sub(this.v1);
  22668. point.multiplyScalar(t).add(this.v1);
  22669. }
  22670. return point;
  22671. }; // Line curve is linear, so we can overwrite default getPointAt
  22672. LineCurve3.prototype.getPointAt = function (u, optionalTarget) {
  22673. return this.getPoint(u, optionalTarget);
  22674. };
  22675. LineCurve3.prototype.copy = function (source) {
  22676. Curve.prototype.copy.call(this, source);
  22677. this.v1.copy(source.v1);
  22678. this.v2.copy(source.v2);
  22679. return this;
  22680. };
  22681. LineCurve3.prototype.toJSON = function () {
  22682. var data = Curve.prototype.toJSON.call(this);
  22683. data.v1 = this.v1.toArray();
  22684. data.v2 = this.v2.toArray();
  22685. return data;
  22686. };
  22687. LineCurve3.prototype.fromJSON = function (json) {
  22688. Curve.prototype.fromJSON.call(this, json);
  22689. this.v1.fromArray(json.v1);
  22690. this.v2.fromArray(json.v2);
  22691. return this;
  22692. };
  22693. function QuadraticBezierCurve(v0, v1, v2) {
  22694. Curve.call(this);
  22695. this.type = 'QuadraticBezierCurve';
  22696. this.v0 = v0 || new Vector2();
  22697. this.v1 = v1 || new Vector2();
  22698. this.v2 = v2 || new Vector2();
  22699. }
  22700. QuadraticBezierCurve.prototype = Object.create(Curve.prototype);
  22701. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  22702. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22703. QuadraticBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22704. var point = optionalTarget || new Vector2();
  22705. var v0 = this.v0,
  22706. v1 = this.v1,
  22707. v2 = this.v2;
  22708. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  22709. return point;
  22710. };
  22711. QuadraticBezierCurve.prototype.copy = function (source) {
  22712. Curve.prototype.copy.call(this, source);
  22713. this.v0.copy(source.v0);
  22714. this.v1.copy(source.v1);
  22715. this.v2.copy(source.v2);
  22716. return this;
  22717. };
  22718. QuadraticBezierCurve.prototype.toJSON = function () {
  22719. var data = Curve.prototype.toJSON.call(this);
  22720. data.v0 = this.v0.toArray();
  22721. data.v1 = this.v1.toArray();
  22722. data.v2 = this.v2.toArray();
  22723. return data;
  22724. };
  22725. QuadraticBezierCurve.prototype.fromJSON = function (json) {
  22726. Curve.prototype.fromJSON.call(this, json);
  22727. this.v0.fromArray(json.v0);
  22728. this.v1.fromArray(json.v1);
  22729. this.v2.fromArray(json.v2);
  22730. return this;
  22731. };
  22732. function QuadraticBezierCurve3(v0, v1, v2) {
  22733. Curve.call(this);
  22734. this.type = 'QuadraticBezierCurve3';
  22735. this.v0 = v0 || new Vector3();
  22736. this.v1 = v1 || new Vector3();
  22737. this.v2 = v2 || new Vector3();
  22738. }
  22739. QuadraticBezierCurve3.prototype = Object.create(Curve.prototype);
  22740. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22741. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22742. QuadraticBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22743. var point = optionalTarget || new Vector3();
  22744. var v0 = this.v0,
  22745. v1 = this.v1,
  22746. v2 = this.v2;
  22747. 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));
  22748. return point;
  22749. };
  22750. QuadraticBezierCurve3.prototype.copy = function (source) {
  22751. Curve.prototype.copy.call(this, source);
  22752. this.v0.copy(source.v0);
  22753. this.v1.copy(source.v1);
  22754. this.v2.copy(source.v2);
  22755. return this;
  22756. };
  22757. QuadraticBezierCurve3.prototype.toJSON = function () {
  22758. var data = Curve.prototype.toJSON.call(this);
  22759. data.v0 = this.v0.toArray();
  22760. data.v1 = this.v1.toArray();
  22761. data.v2 = this.v2.toArray();
  22762. return data;
  22763. };
  22764. QuadraticBezierCurve3.prototype.fromJSON = function (json) {
  22765. Curve.prototype.fromJSON.call(this, json);
  22766. this.v0.fromArray(json.v0);
  22767. this.v1.fromArray(json.v1);
  22768. this.v2.fromArray(json.v2);
  22769. return this;
  22770. };
  22771. function SplineCurve(points) {
  22772. Curve.call(this);
  22773. this.type = 'SplineCurve';
  22774. this.points = points || [];
  22775. }
  22776. SplineCurve.prototype = Object.create(Curve.prototype);
  22777. SplineCurve.prototype.constructor = SplineCurve;
  22778. SplineCurve.prototype.isSplineCurve = true;
  22779. SplineCurve.prototype.getPoint = function (t, optionalTarget) {
  22780. var point = optionalTarget || new Vector2();
  22781. var points = this.points;
  22782. var p = (points.length - 1) * t;
  22783. var intPoint = Math.floor(p);
  22784. var weight = p - intPoint;
  22785. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  22786. var p1 = points[intPoint];
  22787. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  22788. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  22789. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  22790. return point;
  22791. };
  22792. SplineCurve.prototype.copy = function (source) {
  22793. Curve.prototype.copy.call(this, source);
  22794. this.points = [];
  22795. for (var i = 0, l = source.points.length; i < l; i++) {
  22796. var point = source.points[i];
  22797. this.points.push(point.clone());
  22798. }
  22799. return this;
  22800. };
  22801. SplineCurve.prototype.toJSON = function () {
  22802. var data = Curve.prototype.toJSON.call(this);
  22803. data.points = [];
  22804. for (var i = 0, l = this.points.length; i < l; i++) {
  22805. var point = this.points[i];
  22806. data.points.push(point.toArray());
  22807. }
  22808. return data;
  22809. };
  22810. SplineCurve.prototype.fromJSON = function (json) {
  22811. Curve.prototype.fromJSON.call(this, json);
  22812. this.points = [];
  22813. for (var i = 0, l = json.points.length; i < l; i++) {
  22814. var point = json.points[i];
  22815. this.points.push(new Vector2().fromArray(point));
  22816. }
  22817. return this;
  22818. };
  22819. var Curves = /*#__PURE__*/Object.freeze({
  22820. __proto__: null,
  22821. ArcCurve: ArcCurve,
  22822. CatmullRomCurve3: CatmullRomCurve3,
  22823. CubicBezierCurve: CubicBezierCurve,
  22824. CubicBezierCurve3: CubicBezierCurve3,
  22825. EllipseCurve: EllipseCurve,
  22826. LineCurve: LineCurve,
  22827. LineCurve3: LineCurve3,
  22828. QuadraticBezierCurve: QuadraticBezierCurve,
  22829. QuadraticBezierCurve3: QuadraticBezierCurve3,
  22830. SplineCurve: SplineCurve
  22831. });
  22832. /**************************************************************
  22833. * Curved Path - a curve path is simply a array of connected
  22834. * curves, but retains the api of a curve
  22835. **************************************************************/
  22836. function CurvePath() {
  22837. Curve.call(this);
  22838. this.type = 'CurvePath';
  22839. this.curves = [];
  22840. this.autoClose = false; // Automatically closes the path
  22841. }
  22842. CurvePath.prototype = Object.assign(Object.create(Curve.prototype), {
  22843. constructor: CurvePath,
  22844. add: function add(curve) {
  22845. this.curves.push(curve);
  22846. },
  22847. closePath: function closePath() {
  22848. // Add a line curve if start and end of lines are not connected
  22849. var startPoint = this.curves[0].getPoint(0);
  22850. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  22851. if (!startPoint.equals(endPoint)) {
  22852. this.curves.push(new LineCurve(endPoint, startPoint));
  22853. }
  22854. },
  22855. // To get accurate point with reference to
  22856. // entire path distance at time t,
  22857. // following has to be done:
  22858. // 1. Length of each sub path have to be known
  22859. // 2. Locate and identify type of curve
  22860. // 3. Get t for the curve
  22861. // 4. Return curve.getPointAt(t')
  22862. getPoint: function getPoint(t) {
  22863. var d = t * this.getLength();
  22864. var curveLengths = this.getCurveLengths();
  22865. var i = 0; // To think about boundaries points.
  22866. while (i < curveLengths.length) {
  22867. if (curveLengths[i] >= d) {
  22868. var diff = curveLengths[i] - d;
  22869. var curve = this.curves[i];
  22870. var segmentLength = curve.getLength();
  22871. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  22872. return curve.getPointAt(u);
  22873. }
  22874. i++;
  22875. }
  22876. return null; // loop where sum != 0, sum > d , sum+1 <d
  22877. },
  22878. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  22879. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  22880. // getPoint() depends on getLength
  22881. getLength: function getLength() {
  22882. var lens = this.getCurveLengths();
  22883. return lens[lens.length - 1];
  22884. },
  22885. // cacheLengths must be recalculated.
  22886. updateArcLengths: function updateArcLengths() {
  22887. this.needsUpdate = true;
  22888. this.cacheLengths = null;
  22889. this.getCurveLengths();
  22890. },
  22891. // Compute lengths and cache them
  22892. // We cannot overwrite getLengths() because UtoT mapping uses it.
  22893. getCurveLengths: function getCurveLengths() {
  22894. // We use cache values if curves and cache array are same length
  22895. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  22896. return this.cacheLengths;
  22897. } // Get length of sub-curve
  22898. // Push sums into cached array
  22899. var lengths = [];
  22900. var sums = 0;
  22901. for (var i = 0, l = this.curves.length; i < l; i++) {
  22902. sums += this.curves[i].getLength();
  22903. lengths.push(sums);
  22904. }
  22905. this.cacheLengths = lengths;
  22906. return lengths;
  22907. },
  22908. getSpacedPoints: function getSpacedPoints(divisions) {
  22909. if (divisions === undefined) divisions = 40;
  22910. var points = [];
  22911. for (var i = 0; i <= divisions; i++) {
  22912. points.push(this.getPoint(i / divisions));
  22913. }
  22914. if (this.autoClose) {
  22915. points.push(points[0]);
  22916. }
  22917. return points;
  22918. },
  22919. getPoints: function getPoints(divisions) {
  22920. divisions = divisions || 12;
  22921. var points = [];
  22922. var last;
  22923. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  22924. var curve = curves[i];
  22925. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  22926. var pts = curve.getPoints(resolution);
  22927. for (var j = 0; j < pts.length; j++) {
  22928. var point = pts[j];
  22929. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  22930. points.push(point);
  22931. last = point;
  22932. }
  22933. }
  22934. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  22935. points.push(points[0]);
  22936. }
  22937. return points;
  22938. },
  22939. copy: function copy(source) {
  22940. Curve.prototype.copy.call(this, source);
  22941. this.curves = [];
  22942. for (var i = 0, l = source.curves.length; i < l; i++) {
  22943. var curve = source.curves[i];
  22944. this.curves.push(curve.clone());
  22945. }
  22946. this.autoClose = source.autoClose;
  22947. return this;
  22948. },
  22949. toJSON: function toJSON() {
  22950. var data = Curve.prototype.toJSON.call(this);
  22951. data.autoClose = this.autoClose;
  22952. data.curves = [];
  22953. for (var i = 0, l = this.curves.length; i < l; i++) {
  22954. var curve = this.curves[i];
  22955. data.curves.push(curve.toJSON());
  22956. }
  22957. return data;
  22958. },
  22959. fromJSON: function fromJSON(json) {
  22960. Curve.prototype.fromJSON.call(this, json);
  22961. this.autoClose = json.autoClose;
  22962. this.curves = [];
  22963. for (var i = 0, l = json.curves.length; i < l; i++) {
  22964. var curve = json.curves[i];
  22965. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  22966. }
  22967. return this;
  22968. }
  22969. });
  22970. function Path(points) {
  22971. CurvePath.call(this);
  22972. this.type = 'Path';
  22973. this.currentPoint = new Vector2();
  22974. if (points) {
  22975. this.setFromPoints(points);
  22976. }
  22977. }
  22978. Path.prototype = Object.assign(Object.create(CurvePath.prototype), {
  22979. constructor: Path,
  22980. setFromPoints: function setFromPoints(points) {
  22981. this.moveTo(points[0].x, points[0].y);
  22982. for (var i = 1, l = points.length; i < l; i++) {
  22983. this.lineTo(points[i].x, points[i].y);
  22984. }
  22985. return this;
  22986. },
  22987. moveTo: function moveTo(x, y) {
  22988. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  22989. return this;
  22990. },
  22991. lineTo: function lineTo(x, y) {
  22992. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  22993. this.curves.push(curve);
  22994. this.currentPoint.set(x, y);
  22995. return this;
  22996. },
  22997. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  22998. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  22999. this.curves.push(curve);
  23000. this.currentPoint.set(aX, aY);
  23001. return this;
  23002. },
  23003. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  23004. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  23005. this.curves.push(curve);
  23006. this.currentPoint.set(aX, aY);
  23007. return this;
  23008. },
  23009. splineThru: function splineThru(pts
  23010. /*Array of Vector*/
  23011. ) {
  23012. var npts = [this.currentPoint.clone()].concat(pts);
  23013. var curve = new SplineCurve(npts);
  23014. this.curves.push(curve);
  23015. this.currentPoint.copy(pts[pts.length - 1]);
  23016. return this;
  23017. },
  23018. arc: function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23019. var x0 = this.currentPoint.x;
  23020. var y0 = this.currentPoint.y;
  23021. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  23022. return this;
  23023. },
  23024. absarc: function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23025. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  23026. return this;
  23027. },
  23028. ellipse: function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23029. var x0 = this.currentPoint.x;
  23030. var y0 = this.currentPoint.y;
  23031. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23032. return this;
  23033. },
  23034. absellipse: function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23035. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23036. if (this.curves.length > 0) {
  23037. // if a previous curve is present, attempt to join
  23038. var firstPoint = curve.getPoint(0);
  23039. if (!firstPoint.equals(this.currentPoint)) {
  23040. this.lineTo(firstPoint.x, firstPoint.y);
  23041. }
  23042. }
  23043. this.curves.push(curve);
  23044. var lastPoint = curve.getPoint(1);
  23045. this.currentPoint.copy(lastPoint);
  23046. return this;
  23047. },
  23048. copy: function copy(source) {
  23049. CurvePath.prototype.copy.call(this, source);
  23050. this.currentPoint.copy(source.currentPoint);
  23051. return this;
  23052. },
  23053. toJSON: function toJSON() {
  23054. var data = CurvePath.prototype.toJSON.call(this);
  23055. data.currentPoint = this.currentPoint.toArray();
  23056. return data;
  23057. },
  23058. fromJSON: function fromJSON(json) {
  23059. CurvePath.prototype.fromJSON.call(this, json);
  23060. this.currentPoint.fromArray(json.currentPoint);
  23061. return this;
  23062. }
  23063. });
  23064. function Shape(points) {
  23065. Path.call(this, points);
  23066. this.uuid = MathUtils.generateUUID();
  23067. this.type = 'Shape';
  23068. this.holes = [];
  23069. }
  23070. Shape.prototype = Object.assign(Object.create(Path.prototype), {
  23071. constructor: Shape,
  23072. getPointsHoles: function getPointsHoles(divisions) {
  23073. var holesPts = [];
  23074. for (var i = 0, l = this.holes.length; i < l; i++) {
  23075. holesPts[i] = this.holes[i].getPoints(divisions);
  23076. }
  23077. return holesPts;
  23078. },
  23079. // get points of shape and holes (keypoints based on segments parameter)
  23080. extractPoints: function extractPoints(divisions) {
  23081. return {
  23082. shape: this.getPoints(divisions),
  23083. holes: this.getPointsHoles(divisions)
  23084. };
  23085. },
  23086. copy: function copy(source) {
  23087. Path.prototype.copy.call(this, source);
  23088. this.holes = [];
  23089. for (var i = 0, l = source.holes.length; i < l; i++) {
  23090. var hole = source.holes[i];
  23091. this.holes.push(hole.clone());
  23092. }
  23093. return this;
  23094. },
  23095. toJSON: function toJSON() {
  23096. var data = Path.prototype.toJSON.call(this);
  23097. data.uuid = this.uuid;
  23098. data.holes = [];
  23099. for (var i = 0, l = this.holes.length; i < l; i++) {
  23100. var hole = this.holes[i];
  23101. data.holes.push(hole.toJSON());
  23102. }
  23103. return data;
  23104. },
  23105. fromJSON: function fromJSON(json) {
  23106. Path.prototype.fromJSON.call(this, json);
  23107. this.uuid = json.uuid;
  23108. this.holes = [];
  23109. for (var i = 0, l = json.holes.length; i < l; i++) {
  23110. var hole = json.holes[i];
  23111. this.holes.push(new Path().fromJSON(hole));
  23112. }
  23113. return this;
  23114. }
  23115. });
  23116. function Light(color, intensity) {
  23117. Object3D.call(this);
  23118. this.type = 'Light';
  23119. this.color = new Color(color);
  23120. this.intensity = intensity !== undefined ? intensity : 1;
  23121. }
  23122. Light.prototype = Object.assign(Object.create(Object3D.prototype), {
  23123. constructor: Light,
  23124. isLight: true,
  23125. copy: function copy(source) {
  23126. Object3D.prototype.copy.call(this, source);
  23127. this.color.copy(source.color);
  23128. this.intensity = source.intensity;
  23129. return this;
  23130. },
  23131. toJSON: function toJSON(meta) {
  23132. var data = Object3D.prototype.toJSON.call(this, meta);
  23133. data.object.color = this.color.getHex();
  23134. data.object.intensity = this.intensity;
  23135. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23136. if (this.distance !== undefined) data.object.distance = this.distance;
  23137. if (this.angle !== undefined) data.object.angle = this.angle;
  23138. if (this.decay !== undefined) data.object.decay = this.decay;
  23139. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23140. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23141. return data;
  23142. }
  23143. });
  23144. function HemisphereLight(skyColor, groundColor, intensity) {
  23145. Light.call(this, skyColor, intensity);
  23146. this.type = 'HemisphereLight';
  23147. this.position.copy(Object3D.DefaultUp);
  23148. this.updateMatrix();
  23149. this.groundColor = new Color(groundColor);
  23150. }
  23151. HemisphereLight.prototype = Object.assign(Object.create(Light.prototype), {
  23152. constructor: HemisphereLight,
  23153. isHemisphereLight: true,
  23154. copy: function copy(source) {
  23155. Light.prototype.copy.call(this, source);
  23156. this.groundColor.copy(source.groundColor);
  23157. return this;
  23158. }
  23159. });
  23160. function LightShadow(camera) {
  23161. this.camera = camera;
  23162. this.bias = 0;
  23163. this.normalBias = 0;
  23164. this.radius = 1;
  23165. this.mapSize = new Vector2(512, 512);
  23166. this.map = null;
  23167. this.mapPass = null;
  23168. this.matrix = new Matrix4();
  23169. this.autoUpdate = true;
  23170. this.needsUpdate = false;
  23171. this._frustum = new Frustum();
  23172. this._frameExtents = new Vector2(1, 1);
  23173. this._viewportCount = 1;
  23174. this._viewports = [new Vector4(0, 0, 1, 1)];
  23175. }
  23176. Object.assign(LightShadow.prototype, {
  23177. _projScreenMatrix: new Matrix4(),
  23178. _lightPositionWorld: new Vector3(),
  23179. _lookTarget: new Vector3(),
  23180. getViewportCount: function getViewportCount() {
  23181. return this._viewportCount;
  23182. },
  23183. getFrustum: function getFrustum() {
  23184. return this._frustum;
  23185. },
  23186. updateMatrices: function updateMatrices(light) {
  23187. var shadowCamera = this.camera,
  23188. shadowMatrix = this.matrix,
  23189. projScreenMatrix = this._projScreenMatrix,
  23190. lookTarget = this._lookTarget,
  23191. lightPositionWorld = this._lightPositionWorld;
  23192. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23193. shadowCamera.position.copy(lightPositionWorld);
  23194. lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23195. shadowCamera.lookAt(lookTarget);
  23196. shadowCamera.updateMatrixWorld();
  23197. projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23198. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23199. 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);
  23200. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23201. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23202. },
  23203. getViewport: function getViewport(viewportIndex) {
  23204. return this._viewports[viewportIndex];
  23205. },
  23206. getFrameExtents: function getFrameExtents() {
  23207. return this._frameExtents;
  23208. },
  23209. copy: function copy(source) {
  23210. this.camera = source.camera.clone();
  23211. this.bias = source.bias;
  23212. this.radius = source.radius;
  23213. this.mapSize.copy(source.mapSize);
  23214. return this;
  23215. },
  23216. clone: function clone() {
  23217. return new this.constructor().copy(this);
  23218. },
  23219. toJSON: function toJSON() {
  23220. var object = {};
  23221. if (this.bias !== 0) object.bias = this.bias;
  23222. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23223. if (this.radius !== 1) object.radius = this.radius;
  23224. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23225. object.camera = this.camera.toJSON(false).object;
  23226. delete object.camera.matrix;
  23227. return object;
  23228. }
  23229. });
  23230. function SpotLightShadow() {
  23231. LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500));
  23232. this.focus = 1;
  23233. }
  23234. SpotLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23235. constructor: SpotLightShadow,
  23236. isSpotLightShadow: true,
  23237. updateMatrices: function updateMatrices(light) {
  23238. var camera = this.camera;
  23239. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23240. var aspect = this.mapSize.width / this.mapSize.height;
  23241. var far = light.distance || camera.far;
  23242. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23243. camera.fov = fov;
  23244. camera.aspect = aspect;
  23245. camera.far = far;
  23246. camera.updateProjectionMatrix();
  23247. }
  23248. LightShadow.prototype.updateMatrices.call(this, light);
  23249. }
  23250. });
  23251. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23252. Light.call(this, color, intensity);
  23253. this.type = 'SpotLight';
  23254. this.position.copy(Object3D.DefaultUp);
  23255. this.updateMatrix();
  23256. this.target = new Object3D();
  23257. Object.defineProperty(this, 'power', {
  23258. get: function get() {
  23259. // intensity = power per solid angle.
  23260. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23261. return this.intensity * Math.PI;
  23262. },
  23263. set: function set(power) {
  23264. // intensity = power per solid angle.
  23265. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23266. this.intensity = power / Math.PI;
  23267. }
  23268. });
  23269. this.distance = distance !== undefined ? distance : 0;
  23270. this.angle = angle !== undefined ? angle : Math.PI / 3;
  23271. this.penumbra = penumbra !== undefined ? penumbra : 0;
  23272. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23273. this.shadow = new SpotLightShadow();
  23274. }
  23275. SpotLight.prototype = Object.assign(Object.create(Light.prototype), {
  23276. constructor: SpotLight,
  23277. isSpotLight: true,
  23278. copy: function copy(source) {
  23279. Light.prototype.copy.call(this, source);
  23280. this.distance = source.distance;
  23281. this.angle = source.angle;
  23282. this.penumbra = source.penumbra;
  23283. this.decay = source.decay;
  23284. this.target = source.target.clone();
  23285. this.shadow = source.shadow.clone();
  23286. return this;
  23287. }
  23288. });
  23289. function PointLightShadow() {
  23290. LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500));
  23291. this._frameExtents = new Vector2(4, 2);
  23292. this._viewportCount = 6;
  23293. this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23294. // following orientation:
  23295. //
  23296. // xzXZ
  23297. // y Y
  23298. //
  23299. // X - Positive x direction
  23300. // x - Negative x direction
  23301. // Y - Positive y direction
  23302. // y - Negative y direction
  23303. // Z - Positive z direction
  23304. // z - Negative z direction
  23305. // positive X
  23306. new Vector4(2, 1, 1, 1), // negative X
  23307. new Vector4(0, 1, 1, 1), // positive Z
  23308. new Vector4(3, 1, 1, 1), // negative Z
  23309. new Vector4(1, 1, 1, 1), // positive Y
  23310. new Vector4(3, 0, 1, 1), // negative Y
  23311. new Vector4(1, 0, 1, 1)];
  23312. 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)];
  23313. 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)];
  23314. }
  23315. PointLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23316. constructor: PointLightShadow,
  23317. isPointLightShadow: true,
  23318. updateMatrices: function updateMatrices(light, viewportIndex) {
  23319. if (viewportIndex === undefined) viewportIndex = 0;
  23320. var camera = this.camera,
  23321. shadowMatrix = this.matrix,
  23322. lightPositionWorld = this._lightPositionWorld,
  23323. lookTarget = this._lookTarget,
  23324. projScreenMatrix = this._projScreenMatrix;
  23325. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23326. camera.position.copy(lightPositionWorld);
  23327. lookTarget.copy(camera.position);
  23328. lookTarget.add(this._cubeDirections[viewportIndex]);
  23329. camera.up.copy(this._cubeUps[viewportIndex]);
  23330. camera.lookAt(lookTarget);
  23331. camera.updateMatrixWorld();
  23332. shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
  23333. projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  23334. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23335. }
  23336. });
  23337. function PointLight(color, intensity, distance, decay) {
  23338. Light.call(this, color, intensity);
  23339. this.type = 'PointLight';
  23340. Object.defineProperty(this, 'power', {
  23341. get: function get() {
  23342. // intensity = power per solid angle.
  23343. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23344. return this.intensity * 4 * Math.PI;
  23345. },
  23346. set: function set(power) {
  23347. // intensity = power per solid angle.
  23348. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23349. this.intensity = power / (4 * Math.PI);
  23350. }
  23351. });
  23352. this.distance = distance !== undefined ? distance : 0;
  23353. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23354. this.shadow = new PointLightShadow();
  23355. }
  23356. PointLight.prototype = Object.assign(Object.create(Light.prototype), {
  23357. constructor: PointLight,
  23358. isPointLight: true,
  23359. copy: function copy(source) {
  23360. Light.prototype.copy.call(this, source);
  23361. this.distance = source.distance;
  23362. this.decay = source.decay;
  23363. this.shadow = source.shadow.clone();
  23364. return this;
  23365. }
  23366. });
  23367. function OrthographicCamera(left, right, top, bottom, near, far) {
  23368. Camera.call(this);
  23369. this.type = 'OrthographicCamera';
  23370. this.zoom = 1;
  23371. this.view = null;
  23372. this.left = left !== undefined ? left : -1;
  23373. this.right = right !== undefined ? right : 1;
  23374. this.top = top !== undefined ? top : 1;
  23375. this.bottom = bottom !== undefined ? bottom : -1;
  23376. this.near = near !== undefined ? near : 0.1;
  23377. this.far = far !== undefined ? far : 2000;
  23378. this.updateProjectionMatrix();
  23379. }
  23380. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  23381. constructor: OrthographicCamera,
  23382. isOrthographicCamera: true,
  23383. copy: function copy(source, recursive) {
  23384. Camera.prototype.copy.call(this, source, recursive);
  23385. this.left = source.left;
  23386. this.right = source.right;
  23387. this.top = source.top;
  23388. this.bottom = source.bottom;
  23389. this.near = source.near;
  23390. this.far = source.far;
  23391. this.zoom = source.zoom;
  23392. this.view = source.view === null ? null : Object.assign({}, source.view);
  23393. return this;
  23394. },
  23395. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  23396. if (this.view === null) {
  23397. this.view = {
  23398. enabled: true,
  23399. fullWidth: 1,
  23400. fullHeight: 1,
  23401. offsetX: 0,
  23402. offsetY: 0,
  23403. width: 1,
  23404. height: 1
  23405. };
  23406. }
  23407. this.view.enabled = true;
  23408. this.view.fullWidth = fullWidth;
  23409. this.view.fullHeight = fullHeight;
  23410. this.view.offsetX = x;
  23411. this.view.offsetY = y;
  23412. this.view.width = width;
  23413. this.view.height = height;
  23414. this.updateProjectionMatrix();
  23415. },
  23416. clearViewOffset: function clearViewOffset() {
  23417. if (this.view !== null) {
  23418. this.view.enabled = false;
  23419. }
  23420. this.updateProjectionMatrix();
  23421. },
  23422. updateProjectionMatrix: function updateProjectionMatrix() {
  23423. var dx = (this.right - this.left) / (2 * this.zoom);
  23424. var dy = (this.top - this.bottom) / (2 * this.zoom);
  23425. var cx = (this.right + this.left) / 2;
  23426. var cy = (this.top + this.bottom) / 2;
  23427. var left = cx - dx;
  23428. var right = cx + dx;
  23429. var top = cy + dy;
  23430. var bottom = cy - dy;
  23431. if (this.view !== null && this.view.enabled) {
  23432. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  23433. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  23434. left += scaleW * this.view.offsetX;
  23435. right = left + scaleW * this.view.width;
  23436. top -= scaleH * this.view.offsetY;
  23437. bottom = top - scaleH * this.view.height;
  23438. }
  23439. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  23440. this.projectionMatrixInverse.getInverse(this.projectionMatrix);
  23441. },
  23442. toJSON: function toJSON(meta) {
  23443. var data = Object3D.prototype.toJSON.call(this, meta);
  23444. data.object.zoom = this.zoom;
  23445. data.object.left = this.left;
  23446. data.object.right = this.right;
  23447. data.object.top = this.top;
  23448. data.object.bottom = this.bottom;
  23449. data.object.near = this.near;
  23450. data.object.far = this.far;
  23451. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  23452. return data;
  23453. }
  23454. });
  23455. function DirectionalLightShadow() {
  23456. LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
  23457. }
  23458. DirectionalLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23459. constructor: DirectionalLightShadow,
  23460. isDirectionalLightShadow: true,
  23461. updateMatrices: function updateMatrices(light) {
  23462. LightShadow.prototype.updateMatrices.call(this, light);
  23463. }
  23464. });
  23465. function DirectionalLight(color, intensity) {
  23466. Light.call(this, color, intensity);
  23467. this.type = 'DirectionalLight';
  23468. this.position.copy(Object3D.DefaultUp);
  23469. this.updateMatrix();
  23470. this.target = new Object3D();
  23471. this.shadow = new DirectionalLightShadow();
  23472. }
  23473. DirectionalLight.prototype = Object.assign(Object.create(Light.prototype), {
  23474. constructor: DirectionalLight,
  23475. isDirectionalLight: true,
  23476. copy: function copy(source) {
  23477. Light.prototype.copy.call(this, source);
  23478. this.target = source.target.clone();
  23479. this.shadow = source.shadow.clone();
  23480. return this;
  23481. }
  23482. });
  23483. function AmbientLight(color, intensity) {
  23484. Light.call(this, color, intensity);
  23485. this.type = 'AmbientLight';
  23486. }
  23487. AmbientLight.prototype = Object.assign(Object.create(Light.prototype), {
  23488. constructor: AmbientLight,
  23489. isAmbientLight: true
  23490. });
  23491. function RectAreaLight(color, intensity, width, height) {
  23492. Light.call(this, color, intensity);
  23493. this.type = 'RectAreaLight';
  23494. this.width = width !== undefined ? width : 10;
  23495. this.height = height !== undefined ? height : 10;
  23496. }
  23497. RectAreaLight.prototype = Object.assign(Object.create(Light.prototype), {
  23498. constructor: RectAreaLight,
  23499. isRectAreaLight: true,
  23500. copy: function copy(source) {
  23501. Light.prototype.copy.call(this, source);
  23502. this.width = source.width;
  23503. this.height = source.height;
  23504. return this;
  23505. },
  23506. toJSON: function toJSON(meta) {
  23507. var data = Light.prototype.toJSON.call(this, meta);
  23508. data.object.width = this.width;
  23509. data.object.height = this.height;
  23510. return data;
  23511. }
  23512. });
  23513. /**
  23514. * Primary reference:
  23515. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23516. *
  23517. * Secondary reference:
  23518. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23519. */
  23520. // 3-band SH defined by 9 coefficients
  23521. var SphericalHarmonics3 = /*#__PURE__*/function () {
  23522. function SphericalHarmonics3() {
  23523. Object.defineProperty(this, 'isSphericalHarmonics3', {
  23524. value: true
  23525. });
  23526. this.coefficients = [];
  23527. for (var i = 0; i < 9; i++) {
  23528. this.coefficients.push(new Vector3());
  23529. }
  23530. }
  23531. var _proto = SphericalHarmonics3.prototype;
  23532. _proto.set = function set(coefficients) {
  23533. for (var i = 0; i < 9; i++) {
  23534. this.coefficients[i].copy(coefficients[i]);
  23535. }
  23536. return this;
  23537. };
  23538. _proto.zero = function zero() {
  23539. for (var i = 0; i < 9; i++) {
  23540. this.coefficients[i].set(0, 0, 0);
  23541. }
  23542. return this;
  23543. } // get the radiance in the direction of the normal
  23544. // target is a Vector3
  23545. ;
  23546. _proto.getAt = function getAt(normal, target) {
  23547. // normal is assumed to be unit length
  23548. var x = normal.x,
  23549. y = normal.y,
  23550. z = normal.z;
  23551. var coeff = this.coefficients; // band 0
  23552. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  23553. target.addScaledVector(coeff[1], 0.488603 * y);
  23554. target.addScaledVector(coeff[2], 0.488603 * z);
  23555. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  23556. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  23557. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  23558. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  23559. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  23560. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  23561. return target;
  23562. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23563. // target is a Vector3
  23564. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23565. ;
  23566. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  23567. // normal is assumed to be unit length
  23568. var x = normal.x,
  23569. y = normal.y,
  23570. z = normal.z;
  23571. var coeff = this.coefficients; // band 0
  23572. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  23573. // band 1
  23574. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  23575. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  23576. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  23577. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  23578. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  23579. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  23580. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  23581. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  23582. return target;
  23583. };
  23584. _proto.add = function add(sh) {
  23585. for (var i = 0; i < 9; i++) {
  23586. this.coefficients[i].add(sh.coefficients[i]);
  23587. }
  23588. return this;
  23589. };
  23590. _proto.addScaledSH = function addScaledSH(sh, s) {
  23591. for (var i = 0; i < 9; i++) {
  23592. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  23593. }
  23594. return this;
  23595. };
  23596. _proto.scale = function scale(s) {
  23597. for (var i = 0; i < 9; i++) {
  23598. this.coefficients[i].multiplyScalar(s);
  23599. }
  23600. return this;
  23601. };
  23602. _proto.lerp = function lerp(sh, alpha) {
  23603. for (var i = 0; i < 9; i++) {
  23604. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  23605. }
  23606. return this;
  23607. };
  23608. _proto.equals = function equals(sh) {
  23609. for (var i = 0; i < 9; i++) {
  23610. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  23611. return false;
  23612. }
  23613. }
  23614. return true;
  23615. };
  23616. _proto.copy = function copy(sh) {
  23617. return this.set(sh.coefficients);
  23618. };
  23619. _proto.clone = function clone() {
  23620. return new this.constructor().copy(this);
  23621. };
  23622. _proto.fromArray = function fromArray(array, offset) {
  23623. if (offset === undefined) offset = 0;
  23624. var coefficients = this.coefficients;
  23625. for (var i = 0; i < 9; i++) {
  23626. coefficients[i].fromArray(array, offset + i * 3);
  23627. }
  23628. return this;
  23629. };
  23630. _proto.toArray = function toArray(array, offset) {
  23631. if (array === undefined) array = [];
  23632. if (offset === undefined) offset = 0;
  23633. var coefficients = this.coefficients;
  23634. for (var i = 0; i < 9; i++) {
  23635. coefficients[i].toArray(array, offset + i * 3);
  23636. }
  23637. return array;
  23638. } // evaluate the basis functions
  23639. // shBasis is an Array[ 9 ]
  23640. ;
  23641. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  23642. // normal is assumed to be unit length
  23643. var x = normal.x,
  23644. y = normal.y,
  23645. z = normal.z; // band 0
  23646. shBasis[0] = 0.282095; // band 1
  23647. shBasis[1] = 0.488603 * y;
  23648. shBasis[2] = 0.488603 * z;
  23649. shBasis[3] = 0.488603 * x; // band 2
  23650. shBasis[4] = 1.092548 * x * y;
  23651. shBasis[5] = 1.092548 * y * z;
  23652. shBasis[6] = 0.315392 * (3 * z * z - 1);
  23653. shBasis[7] = 1.092548 * x * z;
  23654. shBasis[8] = 0.546274 * (x * x - y * y);
  23655. };
  23656. return SphericalHarmonics3;
  23657. }();
  23658. function LightProbe(sh, intensity) {
  23659. Light.call(this, undefined, intensity);
  23660. this.type = 'LightProbe';
  23661. this.sh = sh !== undefined ? sh : new SphericalHarmonics3();
  23662. }
  23663. LightProbe.prototype = Object.assign(Object.create(Light.prototype), {
  23664. constructor: LightProbe,
  23665. isLightProbe: true,
  23666. copy: function copy(source) {
  23667. Light.prototype.copy.call(this, source);
  23668. this.sh.copy(source.sh);
  23669. return this;
  23670. },
  23671. fromJSON: function fromJSON(json) {
  23672. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  23673. this.sh.fromArray(json.sh);
  23674. return this;
  23675. },
  23676. toJSON: function toJSON(meta) {
  23677. var data = Light.prototype.toJSON.call(this, meta);
  23678. data.object.sh = this.sh.toArray();
  23679. return data;
  23680. }
  23681. });
  23682. function MaterialLoader(manager) {
  23683. Loader.call(this, manager);
  23684. this.textures = {};
  23685. }
  23686. MaterialLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  23687. constructor: MaterialLoader,
  23688. load: function load(url, onLoad, onProgress, onError) {
  23689. var scope = this;
  23690. var loader = new FileLoader(scope.manager);
  23691. loader.setPath(scope.path);
  23692. loader.setRequestHeader(scope.requestHeader);
  23693. loader.setWithCredentials(scope.withCredentials);
  23694. loader.load(url, function (text) {
  23695. try {
  23696. onLoad(scope.parse(JSON.parse(text)));
  23697. } catch (e) {
  23698. if (onError) {
  23699. onError(e);
  23700. } else {
  23701. console.error(e);
  23702. }
  23703. scope.manager.itemError(url);
  23704. }
  23705. }, onProgress, onError);
  23706. },
  23707. parse: function parse(json) {
  23708. var textures = this.textures;
  23709. function getTexture(name) {
  23710. if (textures[name] === undefined) {
  23711. console.warn('THREE.MaterialLoader: Undefined texture', name);
  23712. }
  23713. return textures[name];
  23714. }
  23715. var material = new Materials[json.type]();
  23716. if (json.uuid !== undefined) material.uuid = json.uuid;
  23717. if (json.name !== undefined) material.name = json.name;
  23718. if (json.color !== undefined) material.color.setHex(json.color);
  23719. if (json.roughness !== undefined) material.roughness = json.roughness;
  23720. if (json.metalness !== undefined) material.metalness = json.metalness;
  23721. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  23722. if (json.emissive !== undefined) material.emissive.setHex(json.emissive);
  23723. if (json.specular !== undefined) material.specular.setHex(json.specular);
  23724. if (json.shininess !== undefined) material.shininess = json.shininess;
  23725. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  23726. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  23727. if (json.fog !== undefined) material.fog = json.fog;
  23728. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  23729. if (json.blending !== undefined) material.blending = json.blending;
  23730. if (json.combine !== undefined) material.combine = json.combine;
  23731. if (json.side !== undefined) material.side = json.side;
  23732. if (json.opacity !== undefined) material.opacity = json.opacity;
  23733. if (json.transparent !== undefined) material.transparent = json.transparent;
  23734. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  23735. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  23736. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  23737. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  23738. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  23739. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  23740. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  23741. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  23742. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  23743. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  23744. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  23745. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  23746. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  23747. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  23748. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  23749. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  23750. if (json.rotation !== undefined) material.rotation = json.rotation;
  23751. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  23752. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  23753. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  23754. if (json.scale !== undefined) material.scale = json.scale;
  23755. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  23756. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  23757. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  23758. if (json.skinning !== undefined) material.skinning = json.skinning;
  23759. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  23760. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  23761. if (json.dithering !== undefined) material.dithering = json.dithering;
  23762. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  23763. if (json.visible !== undefined) material.visible = json.visible;
  23764. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  23765. if (json.userData !== undefined) material.userData = json.userData;
  23766. if (json.vertexColors !== undefined) {
  23767. if (typeof json.vertexColors === 'number') {
  23768. material.vertexColors = json.vertexColors > 0 ? true : false;
  23769. } else {
  23770. material.vertexColors = json.vertexColors;
  23771. }
  23772. } // Shader Material
  23773. if (json.uniforms !== undefined) {
  23774. for (var name in json.uniforms) {
  23775. var uniform = json.uniforms[name];
  23776. material.uniforms[name] = {};
  23777. switch (uniform.type) {
  23778. case 't':
  23779. material.uniforms[name].value = getTexture(uniform.value);
  23780. break;
  23781. case 'c':
  23782. material.uniforms[name].value = new Color().setHex(uniform.value);
  23783. break;
  23784. case 'v2':
  23785. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  23786. break;
  23787. case 'v3':
  23788. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  23789. break;
  23790. case 'v4':
  23791. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  23792. break;
  23793. case 'm3':
  23794. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  23795. break;
  23796. case 'm4':
  23797. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  23798. break;
  23799. default:
  23800. material.uniforms[name].value = uniform.value;
  23801. }
  23802. }
  23803. }
  23804. if (json.defines !== undefined) material.defines = json.defines;
  23805. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  23806. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  23807. if (json.extensions !== undefined) {
  23808. for (var key in json.extensions) {
  23809. material.extensions[key] = json.extensions[key];
  23810. }
  23811. } // Deprecated
  23812. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  23813. // for PointsMaterial
  23814. if (json.size !== undefined) material.size = json.size;
  23815. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  23816. if (json.map !== undefined) material.map = getTexture(json.map);
  23817. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  23818. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  23819. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  23820. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  23821. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  23822. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  23823. if (json.normalScale !== undefined) {
  23824. var normalScale = json.normalScale;
  23825. if (Array.isArray(normalScale) === false) {
  23826. // Blender exporter used to export a scalar. See #7459
  23827. normalScale = [normalScale, normalScale];
  23828. }
  23829. material.normalScale = new Vector2().fromArray(normalScale);
  23830. }
  23831. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  23832. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  23833. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  23834. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  23835. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  23836. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  23837. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  23838. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  23839. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  23840. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  23841. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  23842. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  23843. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  23844. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  23845. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  23846. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  23847. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  23848. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  23849. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  23850. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  23851. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  23852. if (json.transmission !== undefined) material.transmission = json.transmission;
  23853. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  23854. return material;
  23855. },
  23856. setTextures: function setTextures(value) {
  23857. this.textures = value;
  23858. return this;
  23859. }
  23860. });
  23861. var LoaderUtils = {
  23862. decodeText: function decodeText(array) {
  23863. if (typeof TextDecoder !== 'undefined') {
  23864. return new TextDecoder().decode(array);
  23865. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  23866. // throws a "maximum call stack size exceeded" error for large arrays.
  23867. var s = '';
  23868. for (var i = 0, il = array.length; i < il; i++) {
  23869. // Implicitly assumes little-endian.
  23870. s += String.fromCharCode(array[i]);
  23871. }
  23872. try {
  23873. // merges multi-byte utf-8 characters.
  23874. return decodeURIComponent(escape(s));
  23875. } catch (e) {
  23876. // see #16358
  23877. return s;
  23878. }
  23879. },
  23880. extractUrlBase: function extractUrlBase(url) {
  23881. var index = url.lastIndexOf('/');
  23882. if (index === -1) return './';
  23883. return url.substr(0, index + 1);
  23884. }
  23885. };
  23886. function InstancedBufferGeometry() {
  23887. BufferGeometry.call(this);
  23888. this.type = 'InstancedBufferGeometry';
  23889. this.instanceCount = Infinity;
  23890. }
  23891. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  23892. constructor: InstancedBufferGeometry,
  23893. isInstancedBufferGeometry: true,
  23894. copy: function copy(source) {
  23895. BufferGeometry.prototype.copy.call(this, source);
  23896. this.instanceCount = source.instanceCount;
  23897. return this;
  23898. },
  23899. clone: function clone() {
  23900. return new this.constructor().copy(this);
  23901. },
  23902. toJSON: function toJSON() {
  23903. var data = BufferGeometry.prototype.toJSON.call(this);
  23904. data.instanceCount = this.instanceCount;
  23905. data.isInstancedBufferGeometry = true;
  23906. return data;
  23907. }
  23908. });
  23909. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  23910. if (typeof normalized === 'number') {
  23911. meshPerAttribute = normalized;
  23912. normalized = false;
  23913. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  23914. }
  23915. BufferAttribute.call(this, array, itemSize, normalized);
  23916. this.meshPerAttribute = meshPerAttribute || 1;
  23917. }
  23918. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  23919. constructor: InstancedBufferAttribute,
  23920. isInstancedBufferAttribute: true,
  23921. copy: function copy(source) {
  23922. BufferAttribute.prototype.copy.call(this, source);
  23923. this.meshPerAttribute = source.meshPerAttribute;
  23924. return this;
  23925. },
  23926. toJSON: function toJSON() {
  23927. var data = BufferAttribute.prototype.toJSON.call(this);
  23928. data.meshPerAttribute = this.meshPerAttribute;
  23929. data.isInstancedBufferAttribute = true;
  23930. return data;
  23931. }
  23932. });
  23933. function BufferGeometryLoader(manager) {
  23934. Loader.call(this, manager);
  23935. }
  23936. BufferGeometryLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  23937. constructor: BufferGeometryLoader,
  23938. load: function load(url, onLoad, onProgress, onError) {
  23939. var scope = this;
  23940. var loader = new FileLoader(scope.manager);
  23941. loader.setPath(scope.path);
  23942. loader.setRequestHeader(scope.requestHeader);
  23943. loader.setWithCredentials(scope.withCredentials);
  23944. loader.load(url, function (text) {
  23945. try {
  23946. onLoad(scope.parse(JSON.parse(text)));
  23947. } catch (e) {
  23948. if (onError) {
  23949. onError(e);
  23950. } else {
  23951. console.error(e);
  23952. }
  23953. scope.manager.itemError(url);
  23954. }
  23955. }, onProgress, onError);
  23956. },
  23957. parse: function parse(json) {
  23958. var interleavedBufferMap = {};
  23959. var arrayBufferMap = {};
  23960. function getInterleavedBuffer(json, uuid) {
  23961. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  23962. var interleavedBuffers = json.interleavedBuffers;
  23963. var interleavedBuffer = interleavedBuffers[uuid];
  23964. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  23965. var array = new TYPED_ARRAYS[interleavedBuffer.type](buffer);
  23966. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  23967. ib.uuid = interleavedBuffer.uuid;
  23968. interleavedBufferMap[uuid] = ib;
  23969. return ib;
  23970. }
  23971. function getArrayBuffer(json, uuid) {
  23972. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  23973. var arrayBuffers = json.arrayBuffers;
  23974. var arrayBuffer = arrayBuffers[uuid];
  23975. var ab = new Uint32Array(arrayBuffer).buffer;
  23976. arrayBufferMap[uuid] = ab;
  23977. return ab;
  23978. }
  23979. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  23980. var index = json.data.index;
  23981. if (index !== undefined) {
  23982. var typedArray = new TYPED_ARRAYS[index.type](index.array);
  23983. geometry.setIndex(new BufferAttribute(typedArray, 1));
  23984. }
  23985. var attributes = json.data.attributes;
  23986. for (var key in attributes) {
  23987. var attribute = attributes[key];
  23988. var bufferAttribute = void 0;
  23989. if (attribute.isInterleavedBufferAttribute) {
  23990. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  23991. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  23992. } else {
  23993. var _typedArray = new TYPED_ARRAYS[attribute.type](attribute.array);
  23994. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  23995. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  23996. }
  23997. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  23998. geometry.setAttribute(key, bufferAttribute);
  23999. }
  24000. var morphAttributes = json.data.morphAttributes;
  24001. if (morphAttributes) {
  24002. for (var _key in morphAttributes) {
  24003. var attributeArray = morphAttributes[_key];
  24004. var array = [];
  24005. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24006. var _attribute = attributeArray[i];
  24007. var _bufferAttribute = void 0;
  24008. if (_attribute.isInterleavedBufferAttribute) {
  24009. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24010. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24011. } else {
  24012. var _typedArray2 = new TYPED_ARRAYS[_attribute.type](_attribute.array);
  24013. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24014. }
  24015. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24016. array.push(_bufferAttribute);
  24017. }
  24018. geometry.morphAttributes[_key] = array;
  24019. }
  24020. }
  24021. var morphTargetsRelative = json.data.morphTargetsRelative;
  24022. if (morphTargetsRelative) {
  24023. geometry.morphTargetsRelative = true;
  24024. }
  24025. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24026. if (groups !== undefined) {
  24027. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24028. var group = groups[_i];
  24029. geometry.addGroup(group.start, group.count, group.materialIndex);
  24030. }
  24031. }
  24032. var boundingSphere = json.data.boundingSphere;
  24033. if (boundingSphere !== undefined) {
  24034. var center = new Vector3();
  24035. if (boundingSphere.center !== undefined) {
  24036. center.fromArray(boundingSphere.center);
  24037. }
  24038. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24039. }
  24040. if (json.name) geometry.name = json.name;
  24041. if (json.userData) geometry.userData = json.userData;
  24042. return geometry;
  24043. }
  24044. });
  24045. var TYPED_ARRAYS = {
  24046. Int8Array: Int8Array,
  24047. Uint8Array: Uint8Array,
  24048. // Workaround for IE11 pre KB2929437. See #11440
  24049. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  24050. Int16Array: Int16Array,
  24051. Uint16Array: Uint16Array,
  24052. Int32Array: Int32Array,
  24053. Uint32Array: Uint32Array,
  24054. Float32Array: Float32Array,
  24055. Float64Array: Float64Array
  24056. };
  24057. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24058. _inheritsLoose(ObjectLoader, _Loader);
  24059. function ObjectLoader(manager) {
  24060. return _Loader.call(this, manager) || this;
  24061. }
  24062. var _proto = ObjectLoader.prototype;
  24063. _proto.load = function load(url, onLoad, onProgress, onError) {
  24064. var scope = this;
  24065. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24066. this.resourcePath = this.resourcePath || path;
  24067. var loader = new FileLoader(this.manager);
  24068. loader.setPath(this.path);
  24069. loader.setRequestHeader(this.requestHeader);
  24070. loader.setWithCredentials(this.withCredentials);
  24071. loader.load(url, function (text) {
  24072. var json = null;
  24073. try {
  24074. json = JSON.parse(text);
  24075. } catch (error) {
  24076. if (onError !== undefined) onError(error);
  24077. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24078. return;
  24079. }
  24080. var metadata = json.metadata;
  24081. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24082. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24083. return;
  24084. }
  24085. scope.parse(json, onLoad);
  24086. }, onProgress, onError);
  24087. };
  24088. _proto.parse = function parse(json, onLoad) {
  24089. var shapes = this.parseShape(json.shapes);
  24090. var geometries = this.parseGeometries(json.geometries, shapes);
  24091. var images = this.parseImages(json.images, function () {
  24092. if (onLoad !== undefined) onLoad(object);
  24093. });
  24094. var textures = this.parseTextures(json.textures, images);
  24095. var materials = this.parseMaterials(json.materials, textures);
  24096. var object = this.parseObject(json.object, geometries, materials);
  24097. if (json.animations) {
  24098. object.animations = this.parseAnimations(json.animations);
  24099. }
  24100. if (json.images === undefined || json.images.length === 0) {
  24101. if (onLoad !== undefined) onLoad(object);
  24102. }
  24103. return object;
  24104. };
  24105. _proto.parseShape = function parseShape(json) {
  24106. var shapes = {};
  24107. if (json !== undefined) {
  24108. for (var i = 0, l = json.length; i < l; i++) {
  24109. var shape = new Shape().fromJSON(json[i]);
  24110. shapes[shape.uuid] = shape;
  24111. }
  24112. }
  24113. return shapes;
  24114. };
  24115. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24116. var geometries = {};
  24117. var geometryShapes;
  24118. if (json !== undefined) {
  24119. var bufferGeometryLoader = new BufferGeometryLoader();
  24120. for (var i = 0, l = json.length; i < l; i++) {
  24121. var geometry = void 0;
  24122. var data = json[i];
  24123. switch (data.type) {
  24124. case 'PlaneGeometry':
  24125. case 'PlaneBufferGeometry':
  24126. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24127. break;
  24128. case 'BoxGeometry':
  24129. case 'BoxBufferGeometry':
  24130. case 'CubeGeometry':
  24131. // backwards compatible
  24132. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24133. break;
  24134. case 'CircleGeometry':
  24135. case 'CircleBufferGeometry':
  24136. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24137. break;
  24138. case 'CylinderGeometry':
  24139. case 'CylinderBufferGeometry':
  24140. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24141. break;
  24142. case 'ConeGeometry':
  24143. case 'ConeBufferGeometry':
  24144. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24145. break;
  24146. case 'SphereGeometry':
  24147. case 'SphereBufferGeometry':
  24148. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24149. break;
  24150. case 'DodecahedronGeometry':
  24151. case 'DodecahedronBufferGeometry':
  24152. case 'IcosahedronGeometry':
  24153. case 'IcosahedronBufferGeometry':
  24154. case 'OctahedronGeometry':
  24155. case 'OctahedronBufferGeometry':
  24156. case 'TetrahedronGeometry':
  24157. case 'TetrahedronBufferGeometry':
  24158. geometry = new Geometries[data.type](data.radius, data.detail);
  24159. break;
  24160. case 'RingGeometry':
  24161. case 'RingBufferGeometry':
  24162. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24163. break;
  24164. case 'TorusGeometry':
  24165. case 'TorusBufferGeometry':
  24166. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24167. break;
  24168. case 'TorusKnotGeometry':
  24169. case 'TorusKnotBufferGeometry':
  24170. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24171. break;
  24172. case 'TubeGeometry':
  24173. case 'TubeBufferGeometry':
  24174. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24175. // User defined curves or instances of CurvePath will not be deserialized.
  24176. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24177. break;
  24178. case 'LatheGeometry':
  24179. case 'LatheBufferGeometry':
  24180. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24181. break;
  24182. case 'PolyhedronGeometry':
  24183. case 'PolyhedronBufferGeometry':
  24184. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24185. break;
  24186. case 'ShapeGeometry':
  24187. case 'ShapeBufferGeometry':
  24188. geometryShapes = [];
  24189. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24190. var shape = shapes[data.shapes[j]];
  24191. geometryShapes.push(shape);
  24192. }
  24193. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24194. break;
  24195. case 'ExtrudeGeometry':
  24196. case 'ExtrudeBufferGeometry':
  24197. geometryShapes = [];
  24198. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24199. var _shape = shapes[data.shapes[_j]];
  24200. geometryShapes.push(_shape);
  24201. }
  24202. var extrudePath = data.options.extrudePath;
  24203. if (extrudePath !== undefined) {
  24204. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24205. }
  24206. geometry = new Geometries[data.type](geometryShapes, data.options);
  24207. break;
  24208. case 'BufferGeometry':
  24209. case 'InstancedBufferGeometry':
  24210. geometry = bufferGeometryLoader.parse(data);
  24211. break;
  24212. case 'Geometry':
  24213. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24214. break;
  24215. default:
  24216. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24217. continue;
  24218. }
  24219. geometry.uuid = data.uuid;
  24220. if (data.name !== undefined) geometry.name = data.name;
  24221. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24222. geometries[data.uuid] = geometry;
  24223. }
  24224. }
  24225. return geometries;
  24226. };
  24227. _proto.parseMaterials = function parseMaterials(json, textures) {
  24228. var cache = {}; // MultiMaterial
  24229. var materials = {};
  24230. if (json !== undefined) {
  24231. var loader = new MaterialLoader();
  24232. loader.setTextures(textures);
  24233. for (var i = 0, l = json.length; i < l; i++) {
  24234. var data = json[i];
  24235. if (data.type === 'MultiMaterial') {
  24236. // Deprecated
  24237. var array = [];
  24238. for (var j = 0; j < data.materials.length; j++) {
  24239. var material = data.materials[j];
  24240. if (cache[material.uuid] === undefined) {
  24241. cache[material.uuid] = loader.parse(material);
  24242. }
  24243. array.push(cache[material.uuid]);
  24244. }
  24245. materials[data.uuid] = array;
  24246. } else {
  24247. if (cache[data.uuid] === undefined) {
  24248. cache[data.uuid] = loader.parse(data);
  24249. }
  24250. materials[data.uuid] = cache[data.uuid];
  24251. }
  24252. }
  24253. }
  24254. return materials;
  24255. };
  24256. _proto.parseAnimations = function parseAnimations(json) {
  24257. var animations = [];
  24258. for (var i = 0; i < json.length; i++) {
  24259. var data = json[i];
  24260. var clip = AnimationClip.parse(data);
  24261. if (data.uuid !== undefined) clip.uuid = data.uuid;
  24262. animations.push(clip);
  24263. }
  24264. return animations;
  24265. };
  24266. _proto.parseImages = function parseImages(json, onLoad) {
  24267. var scope = this;
  24268. var images = {};
  24269. var loader;
  24270. function loadImage(url) {
  24271. scope.manager.itemStart(url);
  24272. return loader.load(url, function () {
  24273. scope.manager.itemEnd(url);
  24274. }, undefined, function () {
  24275. scope.manager.itemError(url);
  24276. scope.manager.itemEnd(url);
  24277. });
  24278. }
  24279. if (json !== undefined && json.length > 0) {
  24280. var manager = new LoadingManager(onLoad);
  24281. loader = new ImageLoader(manager);
  24282. loader.setCrossOrigin(this.crossOrigin);
  24283. for (var i = 0, il = json.length; i < il; i++) {
  24284. var image = json[i];
  24285. var url = image.url;
  24286. if (Array.isArray(url)) {
  24287. // load array of images e.g CubeTexture
  24288. images[image.uuid] = [];
  24289. for (var j = 0, jl = url.length; j < jl; j++) {
  24290. var currentUrl = url[j];
  24291. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(currentUrl) ? currentUrl : scope.resourcePath + currentUrl;
  24292. images[image.uuid].push(loadImage(path));
  24293. }
  24294. } else {
  24295. // load single image
  24296. var _path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(image.url) ? image.url : scope.resourcePath + image.url;
  24297. images[image.uuid] = loadImage(_path);
  24298. }
  24299. }
  24300. }
  24301. return images;
  24302. };
  24303. _proto.parseTextures = function parseTextures(json, images) {
  24304. function parseConstant(value, type) {
  24305. if (typeof value === 'number') return value;
  24306. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  24307. return type[value];
  24308. }
  24309. var textures = {};
  24310. if (json !== undefined) {
  24311. for (var i = 0, l = json.length; i < l; i++) {
  24312. var data = json[i];
  24313. if (data.image === undefined) {
  24314. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  24315. }
  24316. if (images[data.image] === undefined) {
  24317. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  24318. }
  24319. var texture = void 0;
  24320. if (Array.isArray(images[data.image])) {
  24321. texture = new CubeTexture(images[data.image]);
  24322. } else {
  24323. texture = new Texture(images[data.image]);
  24324. }
  24325. texture.needsUpdate = true;
  24326. texture.uuid = data.uuid;
  24327. if (data.name !== undefined) texture.name = data.name;
  24328. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  24329. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  24330. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  24331. if (data.center !== undefined) texture.center.fromArray(data.center);
  24332. if (data.rotation !== undefined) texture.rotation = data.rotation;
  24333. if (data.wrap !== undefined) {
  24334. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  24335. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  24336. }
  24337. if (data.format !== undefined) texture.format = data.format;
  24338. if (data.type !== undefined) texture.type = data.type;
  24339. if (data.encoding !== undefined) texture.encoding = data.encoding;
  24340. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  24341. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  24342. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  24343. if (data.flipY !== undefined) texture.flipY = data.flipY;
  24344. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  24345. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  24346. textures[data.uuid] = texture;
  24347. }
  24348. }
  24349. return textures;
  24350. };
  24351. _proto.parseObject = function parseObject(data, geometries, materials) {
  24352. var object;
  24353. function getGeometry(name) {
  24354. if (geometries[name] === undefined) {
  24355. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  24356. }
  24357. return geometries[name];
  24358. }
  24359. function getMaterial(name) {
  24360. if (name === undefined) return undefined;
  24361. if (Array.isArray(name)) {
  24362. var array = [];
  24363. for (var i = 0, l = name.length; i < l; i++) {
  24364. var uuid = name[i];
  24365. if (materials[uuid] === undefined) {
  24366. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  24367. }
  24368. array.push(materials[uuid]);
  24369. }
  24370. return array;
  24371. }
  24372. if (materials[name] === undefined) {
  24373. console.warn('THREE.ObjectLoader: Undefined material', name);
  24374. }
  24375. return materials[name];
  24376. }
  24377. var geometry, material;
  24378. switch (data.type) {
  24379. case 'Scene':
  24380. object = new Scene();
  24381. if (data.background !== undefined) {
  24382. if (Number.isInteger(data.background)) {
  24383. object.background = new Color(data.background);
  24384. }
  24385. }
  24386. if (data.fog !== undefined) {
  24387. if (data.fog.type === 'Fog') {
  24388. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  24389. } else if (data.fog.type === 'FogExp2') {
  24390. object.fog = new FogExp2(data.fog.color, data.fog.density);
  24391. }
  24392. }
  24393. break;
  24394. case 'PerspectiveCamera':
  24395. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  24396. if (data.focus !== undefined) object.focus = data.focus;
  24397. if (data.zoom !== undefined) object.zoom = data.zoom;
  24398. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  24399. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  24400. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24401. break;
  24402. case 'OrthographicCamera':
  24403. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  24404. if (data.zoom !== undefined) object.zoom = data.zoom;
  24405. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24406. break;
  24407. case 'AmbientLight':
  24408. object = new AmbientLight(data.color, data.intensity);
  24409. break;
  24410. case 'DirectionalLight':
  24411. object = new DirectionalLight(data.color, data.intensity);
  24412. break;
  24413. case 'PointLight':
  24414. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  24415. break;
  24416. case 'RectAreaLight':
  24417. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  24418. break;
  24419. case 'SpotLight':
  24420. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  24421. break;
  24422. case 'HemisphereLight':
  24423. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  24424. break;
  24425. case 'LightProbe':
  24426. object = new LightProbe().fromJSON(data);
  24427. break;
  24428. case 'SkinnedMesh':
  24429. console.warn('THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.');
  24430. case 'Mesh':
  24431. geometry = getGeometry(data.geometry);
  24432. material = getMaterial(data.material);
  24433. object = new Mesh(geometry, material);
  24434. break;
  24435. case 'InstancedMesh':
  24436. geometry = getGeometry(data.geometry);
  24437. material = getMaterial(data.material);
  24438. var count = data.count;
  24439. var instanceMatrix = data.instanceMatrix;
  24440. object = new InstancedMesh(geometry, material, count);
  24441. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  24442. break;
  24443. case 'LOD':
  24444. object = new LOD();
  24445. break;
  24446. case 'Line':
  24447. object = new Line(getGeometry(data.geometry), getMaterial(data.material), data.mode);
  24448. break;
  24449. case 'LineLoop':
  24450. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  24451. break;
  24452. case 'LineSegments':
  24453. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  24454. break;
  24455. case 'PointCloud':
  24456. case 'Points':
  24457. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  24458. break;
  24459. case 'Sprite':
  24460. object = new Sprite(getMaterial(data.material));
  24461. break;
  24462. case 'Group':
  24463. object = new Group();
  24464. break;
  24465. default:
  24466. object = new Object3D();
  24467. }
  24468. object.uuid = data.uuid;
  24469. if (data.name !== undefined) object.name = data.name;
  24470. if (data.matrix !== undefined) {
  24471. object.matrix.fromArray(data.matrix);
  24472. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24473. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  24474. } else {
  24475. if (data.position !== undefined) object.position.fromArray(data.position);
  24476. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  24477. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  24478. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  24479. }
  24480. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  24481. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  24482. if (data.shadow) {
  24483. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  24484. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  24485. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  24486. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  24487. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  24488. }
  24489. if (data.visible !== undefined) object.visible = data.visible;
  24490. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  24491. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  24492. if (data.userData !== undefined) object.userData = data.userData;
  24493. if (data.layers !== undefined) object.layers.mask = data.layers;
  24494. if (data.children !== undefined) {
  24495. var children = data.children;
  24496. for (var i = 0; i < children.length; i++) {
  24497. object.add(this.parseObject(children[i], geometries, materials));
  24498. }
  24499. }
  24500. if (data.type === 'LOD') {
  24501. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  24502. var levels = data.levels;
  24503. for (var l = 0; l < levels.length; l++) {
  24504. var level = levels[l];
  24505. var child = object.getObjectByProperty('uuid', level.object);
  24506. if (child !== undefined) {
  24507. object.addLevel(child, level.distance);
  24508. }
  24509. }
  24510. }
  24511. return object;
  24512. }
  24513. /* DEPRECATED */
  24514. ;
  24515. _proto.setTexturePath = function setTexturePath(value) {
  24516. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  24517. return this.setResourcePath(value);
  24518. };
  24519. return ObjectLoader;
  24520. }(Loader);
  24521. var TEXTURE_MAPPING = {
  24522. UVMapping: UVMapping,
  24523. CubeReflectionMapping: CubeReflectionMapping,
  24524. CubeRefractionMapping: CubeRefractionMapping,
  24525. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24526. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24527. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24528. CubeUVRefractionMapping: CubeUVRefractionMapping
  24529. };
  24530. var TEXTURE_WRAPPING = {
  24531. RepeatWrapping: RepeatWrapping,
  24532. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24533. MirroredRepeatWrapping: MirroredRepeatWrapping
  24534. };
  24535. var TEXTURE_FILTER = {
  24536. NearestFilter: NearestFilter,
  24537. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24538. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24539. LinearFilter: LinearFilter,
  24540. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24541. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24542. };
  24543. function ImageBitmapLoader(manager) {
  24544. if (typeof createImageBitmap === 'undefined') {
  24545. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  24546. }
  24547. if (typeof fetch === 'undefined') {
  24548. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  24549. }
  24550. Loader.call(this, manager);
  24551. this.options = {
  24552. premultiplyAlpha: 'none'
  24553. };
  24554. }
  24555. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24556. constructor: ImageBitmapLoader,
  24557. isImageBitmapLoader: true,
  24558. setOptions: function setOptions(options) {
  24559. this.options = options;
  24560. return this;
  24561. },
  24562. load: function load(url, onLoad, onProgress, onError) {
  24563. if (url === undefined) url = '';
  24564. if (this.path !== undefined) url = this.path + url;
  24565. url = this.manager.resolveURL(url);
  24566. var scope = this;
  24567. var cached = Cache.get(url);
  24568. if (cached !== undefined) {
  24569. scope.manager.itemStart(url);
  24570. setTimeout(function () {
  24571. if (onLoad) onLoad(cached);
  24572. scope.manager.itemEnd(url);
  24573. }, 0);
  24574. return cached;
  24575. }
  24576. var fetchOptions = {};
  24577. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  24578. fetch(url, fetchOptions).then(function (res) {
  24579. return res.blob();
  24580. }).then(function (blob) {
  24581. return createImageBitmap(blob, scope.options);
  24582. }).then(function (imageBitmap) {
  24583. Cache.add(url, imageBitmap);
  24584. if (onLoad) onLoad(imageBitmap);
  24585. scope.manager.itemEnd(url);
  24586. }).catch(function (e) {
  24587. if (onError) onError(e);
  24588. scope.manager.itemError(url);
  24589. scope.manager.itemEnd(url);
  24590. });
  24591. scope.manager.itemStart(url);
  24592. }
  24593. });
  24594. function ShapePath() {
  24595. this.type = 'ShapePath';
  24596. this.color = new Color();
  24597. this.subPaths = [];
  24598. this.currentPath = null;
  24599. }
  24600. Object.assign(ShapePath.prototype, {
  24601. moveTo: function moveTo(x, y) {
  24602. this.currentPath = new Path();
  24603. this.subPaths.push(this.currentPath);
  24604. this.currentPath.moveTo(x, y);
  24605. return this;
  24606. },
  24607. lineTo: function lineTo(x, y) {
  24608. this.currentPath.lineTo(x, y);
  24609. return this;
  24610. },
  24611. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  24612. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  24613. return this;
  24614. },
  24615. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  24616. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  24617. return this;
  24618. },
  24619. splineThru: function splineThru(pts) {
  24620. this.currentPath.splineThru(pts);
  24621. return this;
  24622. },
  24623. toShapes: function toShapes(isCCW, noHoles) {
  24624. function toShapesNoHoles(inSubpaths) {
  24625. var shapes = [];
  24626. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  24627. var _tmpPath = inSubpaths[i];
  24628. var _tmpShape = new Shape();
  24629. _tmpShape.curves = _tmpPath.curves;
  24630. shapes.push(_tmpShape);
  24631. }
  24632. return shapes;
  24633. }
  24634. function isPointInsidePolygon(inPt, inPolygon) {
  24635. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  24636. // toggling of inside/outside at every single! intersection point of an edge
  24637. // with the horizontal line through inPt, left of inPt
  24638. // not counting lowerY endpoints of edges and whole edges on that line
  24639. var inside = false;
  24640. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  24641. var edgeLowPt = inPolygon[p];
  24642. var edgeHighPt = inPolygon[q];
  24643. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  24644. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  24645. if (Math.abs(edgeDy) > Number.EPSILON) {
  24646. // not parallel
  24647. if (edgeDy < 0) {
  24648. edgeLowPt = inPolygon[q];
  24649. edgeDx = -edgeDx;
  24650. edgeHighPt = inPolygon[p];
  24651. edgeDy = -edgeDy;
  24652. }
  24653. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  24654. if (inPt.y === edgeLowPt.y) {
  24655. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  24656. // continue; // no intersection or edgeLowPt => doesn't count !!!
  24657. } else {
  24658. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  24659. if (perpEdge === 0) return true; // inPt is on contour ?
  24660. if (perpEdge < 0) continue;
  24661. inside = !inside; // true intersection left of inPt
  24662. }
  24663. } else {
  24664. // parallel or collinear
  24665. if (inPt.y !== edgeLowPt.y) continue; // parallel
  24666. // edge lies on the same horizontal line as inPt
  24667. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  24668. // continue;
  24669. }
  24670. }
  24671. return inside;
  24672. }
  24673. var isClockWise = ShapeUtils.isClockWise;
  24674. var subPaths = this.subPaths;
  24675. if (subPaths.length === 0) return [];
  24676. if (noHoles === true) return toShapesNoHoles(subPaths);
  24677. var solid, tmpPath, tmpShape;
  24678. var shapes = [];
  24679. if (subPaths.length === 1) {
  24680. tmpPath = subPaths[0];
  24681. tmpShape = new Shape();
  24682. tmpShape.curves = tmpPath.curves;
  24683. shapes.push(tmpShape);
  24684. return shapes;
  24685. }
  24686. var holesFirst = !isClockWise(subPaths[0].getPoints());
  24687. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  24688. var betterShapeHoles = [];
  24689. var newShapes = [];
  24690. var newShapeHoles = [];
  24691. var mainIdx = 0;
  24692. var tmpPoints;
  24693. newShapes[mainIdx] = undefined;
  24694. newShapeHoles[mainIdx] = [];
  24695. for (var i = 0, l = subPaths.length; i < l; i++) {
  24696. tmpPath = subPaths[i];
  24697. tmpPoints = tmpPath.getPoints();
  24698. solid = isClockWise(tmpPoints);
  24699. solid = isCCW ? !solid : solid;
  24700. if (solid) {
  24701. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  24702. newShapes[mainIdx] = {
  24703. s: new Shape(),
  24704. p: tmpPoints
  24705. };
  24706. newShapes[mainIdx].s.curves = tmpPath.curves;
  24707. if (holesFirst) mainIdx++;
  24708. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  24709. } else {
  24710. newShapeHoles[mainIdx].push({
  24711. h: tmpPath,
  24712. p: tmpPoints[0]
  24713. }); //console.log('ccw', i);
  24714. }
  24715. } // only Holes? -> probably all Shapes with wrong orientation
  24716. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  24717. if (newShapes.length > 1) {
  24718. var ambiguous = false;
  24719. var toChange = [];
  24720. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  24721. betterShapeHoles[sIdx] = [];
  24722. }
  24723. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  24724. var sho = newShapeHoles[_sIdx];
  24725. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  24726. var ho = sho[hIdx];
  24727. var hole_unassigned = true;
  24728. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  24729. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  24730. if (_sIdx !== s2Idx) toChange.push({
  24731. froms: _sIdx,
  24732. tos: s2Idx,
  24733. hole: hIdx
  24734. });
  24735. if (hole_unassigned) {
  24736. hole_unassigned = false;
  24737. betterShapeHoles[s2Idx].push(ho);
  24738. } else {
  24739. ambiguous = true;
  24740. }
  24741. }
  24742. }
  24743. if (hole_unassigned) {
  24744. betterShapeHoles[_sIdx].push(ho);
  24745. }
  24746. }
  24747. } // console.log("ambiguous: ", ambiguous);
  24748. if (toChange.length > 0) {
  24749. // console.log("to change: ", toChange);
  24750. if (!ambiguous) newShapeHoles = betterShapeHoles;
  24751. }
  24752. }
  24753. var tmpHoles;
  24754. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  24755. tmpShape = newShapes[_i].s;
  24756. shapes.push(tmpShape);
  24757. tmpHoles = newShapeHoles[_i];
  24758. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  24759. tmpShape.holes.push(tmpHoles[j].h);
  24760. }
  24761. } //console.log("shape", shapes);
  24762. return shapes;
  24763. }
  24764. });
  24765. function Font(data) {
  24766. this.type = 'Font';
  24767. this.data = data;
  24768. }
  24769. Object.assign(Font.prototype, {
  24770. isFont: true,
  24771. generateShapes: function generateShapes(text, size) {
  24772. if (size === undefined) size = 100;
  24773. var shapes = [];
  24774. var paths = createPaths(text, size, this.data);
  24775. for (var p = 0, pl = paths.length; p < pl; p++) {
  24776. Array.prototype.push.apply(shapes, paths[p].toShapes());
  24777. }
  24778. return shapes;
  24779. }
  24780. });
  24781. function createPaths(text, size, data) {
  24782. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  24783. var scale = size / data.resolution;
  24784. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  24785. var paths = [];
  24786. var offsetX = 0,
  24787. offsetY = 0;
  24788. for (var i = 0; i < chars.length; i++) {
  24789. var char = chars[i];
  24790. if (char === '\n') {
  24791. offsetX = 0;
  24792. offsetY -= line_height;
  24793. } else {
  24794. var ret = createPath(char, scale, offsetX, offsetY, data);
  24795. offsetX += ret.offsetX;
  24796. paths.push(ret.path);
  24797. }
  24798. }
  24799. return paths;
  24800. }
  24801. function createPath(char, scale, offsetX, offsetY, data) {
  24802. var glyph = data.glyphs[char] || data.glyphs['?'];
  24803. if (!glyph) {
  24804. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  24805. return;
  24806. }
  24807. var path = new ShapePath();
  24808. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  24809. if (glyph.o) {
  24810. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  24811. for (var i = 0, l = outline.length; i < l;) {
  24812. var action = outline[i++];
  24813. switch (action) {
  24814. case 'm':
  24815. // moveTo
  24816. x = outline[i++] * scale + offsetX;
  24817. y = outline[i++] * scale + offsetY;
  24818. path.moveTo(x, y);
  24819. break;
  24820. case 'l':
  24821. // lineTo
  24822. x = outline[i++] * scale + offsetX;
  24823. y = outline[i++] * scale + offsetY;
  24824. path.lineTo(x, y);
  24825. break;
  24826. case 'q':
  24827. // quadraticCurveTo
  24828. cpx = outline[i++] * scale + offsetX;
  24829. cpy = outline[i++] * scale + offsetY;
  24830. cpx1 = outline[i++] * scale + offsetX;
  24831. cpy1 = outline[i++] * scale + offsetY;
  24832. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  24833. break;
  24834. case 'b':
  24835. // bezierCurveTo
  24836. cpx = outline[i++] * scale + offsetX;
  24837. cpy = outline[i++] * scale + offsetY;
  24838. cpx1 = outline[i++] * scale + offsetX;
  24839. cpy1 = outline[i++] * scale + offsetY;
  24840. cpx2 = outline[i++] * scale + offsetX;
  24841. cpy2 = outline[i++] * scale + offsetY;
  24842. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  24843. break;
  24844. }
  24845. }
  24846. }
  24847. return {
  24848. offsetX: glyph.ha * scale,
  24849. path: path
  24850. };
  24851. }
  24852. function FontLoader(manager) {
  24853. Loader.call(this, manager);
  24854. }
  24855. FontLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24856. constructor: FontLoader,
  24857. load: function load(url, onLoad, onProgress, onError) {
  24858. var scope = this;
  24859. var loader = new FileLoader(this.manager);
  24860. loader.setPath(this.path);
  24861. loader.setRequestHeader(this.requestHeader);
  24862. loader.setWithCredentials(scope.withCredentials);
  24863. loader.load(url, function (text) {
  24864. var json;
  24865. try {
  24866. json = JSON.parse(text);
  24867. } catch (e) {
  24868. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  24869. json = JSON.parse(text.substring(65, text.length - 2));
  24870. }
  24871. var font = scope.parse(json);
  24872. if (onLoad) onLoad(font);
  24873. }, onProgress, onError);
  24874. },
  24875. parse: function parse(json) {
  24876. return new Font(json);
  24877. }
  24878. });
  24879. var _context;
  24880. var AudioContext = {
  24881. getContext: function getContext() {
  24882. if (_context === undefined) {
  24883. _context = new (window.AudioContext || window.webkitAudioContext)();
  24884. }
  24885. return _context;
  24886. },
  24887. setContext: function setContext(value) {
  24888. _context = value;
  24889. }
  24890. };
  24891. function AudioLoader(manager) {
  24892. Loader.call(this, manager);
  24893. }
  24894. AudioLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24895. constructor: AudioLoader,
  24896. load: function load(url, onLoad, onProgress, onError) {
  24897. var scope = this;
  24898. var loader = new FileLoader(scope.manager);
  24899. loader.setResponseType('arraybuffer');
  24900. loader.setPath(scope.path);
  24901. loader.setRequestHeader(scope.requestHeader);
  24902. loader.setWithCredentials(scope.withCredentials);
  24903. loader.load(url, function (buffer) {
  24904. try {
  24905. // Create a copy of the buffer. The `decodeAudioData` method
  24906. // detaches the buffer when complete, preventing reuse.
  24907. var bufferCopy = buffer.slice(0);
  24908. var context = AudioContext.getContext();
  24909. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  24910. onLoad(audioBuffer);
  24911. });
  24912. } catch (e) {
  24913. if (onError) {
  24914. onError(e);
  24915. } else {
  24916. console.error(e);
  24917. }
  24918. scope.manager.itemError(url);
  24919. }
  24920. }, onProgress, onError);
  24921. }
  24922. });
  24923. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  24924. LightProbe.call(this, undefined, intensity);
  24925. var color1 = new Color().set(skyColor);
  24926. var color2 = new Color().set(groundColor);
  24927. var sky = new Vector3(color1.r, color1.g, color1.b);
  24928. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  24929. var c0 = Math.sqrt(Math.PI);
  24930. var c1 = c0 * Math.sqrt(0.75);
  24931. this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  24932. this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  24933. }
  24934. HemisphereLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  24935. constructor: HemisphereLightProbe,
  24936. isHemisphereLightProbe: true,
  24937. copy: function copy(source) {
  24938. // modifying colors not currently supported
  24939. LightProbe.prototype.copy.call(this, source);
  24940. return this;
  24941. },
  24942. toJSON: function toJSON(meta) {
  24943. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  24944. return data;
  24945. }
  24946. });
  24947. function AmbientLightProbe(color, intensity) {
  24948. LightProbe.call(this, undefined, intensity);
  24949. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  24950. this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  24951. }
  24952. AmbientLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  24953. constructor: AmbientLightProbe,
  24954. isAmbientLightProbe: true,
  24955. copy: function copy(source) {
  24956. // modifying color not currently supported
  24957. LightProbe.prototype.copy.call(this, source);
  24958. return this;
  24959. },
  24960. toJSON: function toJSON(meta) {
  24961. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  24962. return data;
  24963. }
  24964. });
  24965. var _eyeRight = new Matrix4();
  24966. var _eyeLeft = new Matrix4();
  24967. function StereoCamera() {
  24968. this.type = 'StereoCamera';
  24969. this.aspect = 1;
  24970. this.eyeSep = 0.064;
  24971. this.cameraL = new PerspectiveCamera();
  24972. this.cameraL.layers.enable(1);
  24973. this.cameraL.matrixAutoUpdate = false;
  24974. this.cameraR = new PerspectiveCamera();
  24975. this.cameraR.layers.enable(2);
  24976. this.cameraR.matrixAutoUpdate = false;
  24977. this._cache = {
  24978. focus: null,
  24979. fov: null,
  24980. aspect: null,
  24981. near: null,
  24982. far: null,
  24983. zoom: null,
  24984. eyeSep: null
  24985. };
  24986. }
  24987. Object.assign(StereoCamera.prototype, {
  24988. update: function update(camera) {
  24989. var cache = this._cache;
  24990. 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;
  24991. if (needsUpdate) {
  24992. cache.focus = camera.focus;
  24993. cache.fov = camera.fov;
  24994. cache.aspect = camera.aspect * this.aspect;
  24995. cache.near = camera.near;
  24996. cache.far = camera.far;
  24997. cache.zoom = camera.zoom;
  24998. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  24999. // http://paulbourke.net/stereographics/stereorender/
  25000. var projectionMatrix = camera.projectionMatrix.clone();
  25001. var eyeSepHalf = cache.eyeSep / 2;
  25002. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25003. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25004. var xmin, xmax; // translate xOffset
  25005. _eyeLeft.elements[12] = -eyeSepHalf;
  25006. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25007. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25008. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25009. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25010. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25011. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25012. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25013. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25014. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25015. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25016. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25017. }
  25018. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25019. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25020. }
  25021. });
  25022. var Clock = /*#__PURE__*/function () {
  25023. function Clock(autoStart) {
  25024. this.autoStart = autoStart !== undefined ? autoStart : true;
  25025. this.startTime = 0;
  25026. this.oldTime = 0;
  25027. this.elapsedTime = 0;
  25028. this.running = false;
  25029. }
  25030. var _proto = Clock.prototype;
  25031. _proto.start = function start() {
  25032. this.startTime = (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25033. this.oldTime = this.startTime;
  25034. this.elapsedTime = 0;
  25035. this.running = true;
  25036. };
  25037. _proto.stop = function stop() {
  25038. this.getElapsedTime();
  25039. this.running = false;
  25040. this.autoStart = false;
  25041. };
  25042. _proto.getElapsedTime = function getElapsedTime() {
  25043. this.getDelta();
  25044. return this.elapsedTime;
  25045. };
  25046. _proto.getDelta = function getDelta() {
  25047. var diff = 0;
  25048. if (this.autoStart && !this.running) {
  25049. this.start();
  25050. return 0;
  25051. }
  25052. if (this.running) {
  25053. var newTime = (typeof performance === 'undefined' ? Date : performance).now();
  25054. diff = (newTime - this.oldTime) / 1000;
  25055. this.oldTime = newTime;
  25056. this.elapsedTime += diff;
  25057. }
  25058. return diff;
  25059. };
  25060. return Clock;
  25061. }();
  25062. var _position$2 = /*@__PURE__*/new Vector3();
  25063. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25064. var _scale$1 = /*@__PURE__*/new Vector3();
  25065. var _orientation = /*@__PURE__*/new Vector3();
  25066. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25067. _inheritsLoose(AudioListener, _Object3D);
  25068. function AudioListener() {
  25069. var _this;
  25070. _this = _Object3D.call(this) || this;
  25071. _this.type = 'AudioListener';
  25072. _this.context = AudioContext.getContext();
  25073. _this.gain = _this.context.createGain();
  25074. _this.gain.connect(_this.context.destination);
  25075. _this.filter = null;
  25076. _this.timeDelta = 0; // private
  25077. _this._clock = new Clock();
  25078. return _this;
  25079. }
  25080. var _proto = AudioListener.prototype;
  25081. _proto.getInput = function getInput() {
  25082. return this.gain;
  25083. };
  25084. _proto.removeFilter = function removeFilter() {
  25085. if (this.filter !== null) {
  25086. this.gain.disconnect(this.filter);
  25087. this.filter.disconnect(this.context.destination);
  25088. this.gain.connect(this.context.destination);
  25089. this.filter = null;
  25090. }
  25091. return this;
  25092. };
  25093. _proto.getFilter = function getFilter() {
  25094. return this.filter;
  25095. };
  25096. _proto.setFilter = function setFilter(value) {
  25097. if (this.filter !== null) {
  25098. this.gain.disconnect(this.filter);
  25099. this.filter.disconnect(this.context.destination);
  25100. } else {
  25101. this.gain.disconnect(this.context.destination);
  25102. }
  25103. this.filter = value;
  25104. this.gain.connect(this.filter);
  25105. this.filter.connect(this.context.destination);
  25106. return this;
  25107. };
  25108. _proto.getMasterVolume = function getMasterVolume() {
  25109. return this.gain.gain.value;
  25110. };
  25111. _proto.setMasterVolume = function setMasterVolume(value) {
  25112. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25113. return this;
  25114. };
  25115. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25116. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25117. var listener = this.context.listener;
  25118. var up = this.up;
  25119. this.timeDelta = this._clock.getDelta();
  25120. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25121. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25122. if (listener.positionX) {
  25123. // code path for Chrome (see #14393)
  25124. var endTime = this.context.currentTime + this.timeDelta;
  25125. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25126. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25127. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25128. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25129. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25130. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25131. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25132. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25133. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25134. } else {
  25135. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25136. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25137. }
  25138. };
  25139. return AudioListener;
  25140. }(Object3D);
  25141. var Audio = /*#__PURE__*/function (_Object3D) {
  25142. _inheritsLoose(Audio, _Object3D);
  25143. function Audio(listener) {
  25144. var _this;
  25145. _this = _Object3D.call(this) || this;
  25146. _this.type = 'Audio';
  25147. _this.listener = listener;
  25148. _this.context = listener.context;
  25149. _this.gain = _this.context.createGain();
  25150. _this.gain.connect(listener.getInput());
  25151. _this.autoplay = false;
  25152. _this.buffer = null;
  25153. _this.detune = 0;
  25154. _this.loop = false;
  25155. _this.loopStart = 0;
  25156. _this.loopEnd = 0;
  25157. _this.offset = 0;
  25158. _this.duration = undefined;
  25159. _this.playbackRate = 1;
  25160. _this.isPlaying = false;
  25161. _this.hasPlaybackControl = true;
  25162. _this.source = null;
  25163. _this.sourceType = 'empty';
  25164. _this._startedAt = 0;
  25165. _this._progress = 0;
  25166. _this._connected = false;
  25167. _this.filters = [];
  25168. return _this;
  25169. }
  25170. var _proto = Audio.prototype;
  25171. _proto.getOutput = function getOutput() {
  25172. return this.gain;
  25173. };
  25174. _proto.setNodeSource = function setNodeSource(audioNode) {
  25175. this.hasPlaybackControl = false;
  25176. this.sourceType = 'audioNode';
  25177. this.source = audioNode;
  25178. this.connect();
  25179. return this;
  25180. };
  25181. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25182. this.hasPlaybackControl = false;
  25183. this.sourceType = 'mediaNode';
  25184. this.source = this.context.createMediaElementSource(mediaElement);
  25185. this.connect();
  25186. return this;
  25187. };
  25188. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25189. this.hasPlaybackControl = false;
  25190. this.sourceType = 'mediaStreamNode';
  25191. this.source = this.context.createMediaStreamSource(mediaStream);
  25192. this.connect();
  25193. return this;
  25194. };
  25195. _proto.setBuffer = function setBuffer(audioBuffer) {
  25196. this.buffer = audioBuffer;
  25197. this.sourceType = 'buffer';
  25198. if (this.autoplay) this.play();
  25199. return this;
  25200. };
  25201. _proto.play = function play(delay) {
  25202. if (delay === undefined) delay = 0;
  25203. if (this.isPlaying === true) {
  25204. console.warn('THREE.Audio: Audio is already playing.');
  25205. return;
  25206. }
  25207. if (this.hasPlaybackControl === false) {
  25208. console.warn('THREE.Audio: this Audio has no playback control.');
  25209. return;
  25210. }
  25211. this._startedAt = this.context.currentTime + delay;
  25212. var source = this.context.createBufferSource();
  25213. source.buffer = this.buffer;
  25214. source.loop = this.loop;
  25215. source.loopStart = this.loopStart;
  25216. source.loopEnd = this.loopEnd;
  25217. source.onended = this.onEnded.bind(this);
  25218. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25219. this.isPlaying = true;
  25220. this.source = source;
  25221. this.setDetune(this.detune);
  25222. this.setPlaybackRate(this.playbackRate);
  25223. return this.connect();
  25224. };
  25225. _proto.pause = function pause() {
  25226. if (this.hasPlaybackControl === false) {
  25227. console.warn('THREE.Audio: this Audio has no playback control.');
  25228. return;
  25229. }
  25230. if (this.isPlaying === true) {
  25231. // update current progress
  25232. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  25233. if (this.loop === true) {
  25234. // ensure _progress does not exceed duration with looped audios
  25235. this._progress = this._progress % (this.duration || this.buffer.duration);
  25236. }
  25237. this.source.stop();
  25238. this.source.onended = null;
  25239. this.isPlaying = false;
  25240. }
  25241. return this;
  25242. };
  25243. _proto.stop = function stop() {
  25244. if (this.hasPlaybackControl === false) {
  25245. console.warn('THREE.Audio: this Audio has no playback control.');
  25246. return;
  25247. }
  25248. this._progress = 0;
  25249. this.source.stop();
  25250. this.source.onended = null;
  25251. this.isPlaying = false;
  25252. return this;
  25253. };
  25254. _proto.connect = function connect() {
  25255. if (this.filters.length > 0) {
  25256. this.source.connect(this.filters[0]);
  25257. for (var i = 1, l = this.filters.length; i < l; i++) {
  25258. this.filters[i - 1].connect(this.filters[i]);
  25259. }
  25260. this.filters[this.filters.length - 1].connect(this.getOutput());
  25261. } else {
  25262. this.source.connect(this.getOutput());
  25263. }
  25264. this._connected = true;
  25265. return this;
  25266. };
  25267. _proto.disconnect = function disconnect() {
  25268. if (this.filters.length > 0) {
  25269. this.source.disconnect(this.filters[0]);
  25270. for (var i = 1, l = this.filters.length; i < l; i++) {
  25271. this.filters[i - 1].disconnect(this.filters[i]);
  25272. }
  25273. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  25274. } else {
  25275. this.source.disconnect(this.getOutput());
  25276. }
  25277. this._connected = false;
  25278. return this;
  25279. };
  25280. _proto.getFilters = function getFilters() {
  25281. return this.filters;
  25282. };
  25283. _proto.setFilters = function setFilters(value) {
  25284. if (!value) value = [];
  25285. if (this._connected === true) {
  25286. this.disconnect();
  25287. this.filters = value;
  25288. this.connect();
  25289. } else {
  25290. this.filters = value;
  25291. }
  25292. return this;
  25293. };
  25294. _proto.setDetune = function setDetune(value) {
  25295. this.detune = value;
  25296. if (this.source.detune === undefined) return; // only set detune when available
  25297. if (this.isPlaying === true) {
  25298. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  25299. }
  25300. return this;
  25301. };
  25302. _proto.getDetune = function getDetune() {
  25303. return this.detune;
  25304. };
  25305. _proto.getFilter = function getFilter() {
  25306. return this.getFilters()[0];
  25307. };
  25308. _proto.setFilter = function setFilter(filter) {
  25309. return this.setFilters(filter ? [filter] : []);
  25310. };
  25311. _proto.setPlaybackRate = function setPlaybackRate(value) {
  25312. if (this.hasPlaybackControl === false) {
  25313. console.warn('THREE.Audio: this Audio has no playback control.');
  25314. return;
  25315. }
  25316. this.playbackRate = value;
  25317. if (this.isPlaying === true) {
  25318. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  25319. }
  25320. return this;
  25321. };
  25322. _proto.getPlaybackRate = function getPlaybackRate() {
  25323. return this.playbackRate;
  25324. };
  25325. _proto.onEnded = function onEnded() {
  25326. this.isPlaying = false;
  25327. };
  25328. _proto.getLoop = function getLoop() {
  25329. if (this.hasPlaybackControl === false) {
  25330. console.warn('THREE.Audio: this Audio has no playback control.');
  25331. return false;
  25332. }
  25333. return this.loop;
  25334. };
  25335. _proto.setLoop = function setLoop(value) {
  25336. if (this.hasPlaybackControl === false) {
  25337. console.warn('THREE.Audio: this Audio has no playback control.');
  25338. return;
  25339. }
  25340. this.loop = value;
  25341. if (this.isPlaying === true) {
  25342. this.source.loop = this.loop;
  25343. }
  25344. return this;
  25345. };
  25346. _proto.setLoopStart = function setLoopStart(value) {
  25347. this.loopStart = value;
  25348. return this;
  25349. };
  25350. _proto.setLoopEnd = function setLoopEnd(value) {
  25351. this.loopEnd = value;
  25352. return this;
  25353. };
  25354. _proto.getVolume = function getVolume() {
  25355. return this.gain.gain.value;
  25356. };
  25357. _proto.setVolume = function setVolume(value) {
  25358. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25359. return this;
  25360. };
  25361. return Audio;
  25362. }(Object3D);
  25363. var _position$3 = /*@__PURE__*/new Vector3();
  25364. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  25365. var _scale$2 = /*@__PURE__*/new Vector3();
  25366. var _orientation$1 = /*@__PURE__*/new Vector3();
  25367. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  25368. _inheritsLoose(PositionalAudio, _Audio);
  25369. function PositionalAudio(listener) {
  25370. var _this;
  25371. _this = _Audio.call(this, listener) || this;
  25372. _this.panner = _this.context.createPanner();
  25373. _this.panner.panningModel = 'HRTF';
  25374. _this.panner.connect(_this.gain);
  25375. return _this;
  25376. }
  25377. var _proto = PositionalAudio.prototype;
  25378. _proto.getOutput = function getOutput() {
  25379. return this.panner;
  25380. };
  25381. _proto.getRefDistance = function getRefDistance() {
  25382. return this.panner.refDistance;
  25383. };
  25384. _proto.setRefDistance = function setRefDistance(value) {
  25385. this.panner.refDistance = value;
  25386. return this;
  25387. };
  25388. _proto.getRolloffFactor = function getRolloffFactor() {
  25389. return this.panner.rolloffFactor;
  25390. };
  25391. _proto.setRolloffFactor = function setRolloffFactor(value) {
  25392. this.panner.rolloffFactor = value;
  25393. return this;
  25394. };
  25395. _proto.getDistanceModel = function getDistanceModel() {
  25396. return this.panner.distanceModel;
  25397. };
  25398. _proto.setDistanceModel = function setDistanceModel(value) {
  25399. this.panner.distanceModel = value;
  25400. return this;
  25401. };
  25402. _proto.getMaxDistance = function getMaxDistance() {
  25403. return this.panner.maxDistance;
  25404. };
  25405. _proto.setMaxDistance = function setMaxDistance(value) {
  25406. this.panner.maxDistance = value;
  25407. return this;
  25408. };
  25409. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  25410. this.panner.coneInnerAngle = coneInnerAngle;
  25411. this.panner.coneOuterAngle = coneOuterAngle;
  25412. this.panner.coneOuterGain = coneOuterGain;
  25413. return this;
  25414. };
  25415. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25416. _Audio.prototype.updateMatrixWorld.call(this, force);
  25417. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  25418. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  25419. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  25420. var panner = this.panner;
  25421. if (panner.positionX) {
  25422. // code path for Chrome and Firefox (see #14393)
  25423. var endTime = this.context.currentTime + this.listener.timeDelta;
  25424. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  25425. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  25426. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  25427. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  25428. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  25429. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  25430. } else {
  25431. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  25432. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  25433. }
  25434. };
  25435. return PositionalAudio;
  25436. }(Audio);
  25437. var AudioAnalyser = /*#__PURE__*/function () {
  25438. function AudioAnalyser(audio, fftSize) {
  25439. this.analyser = audio.context.createAnalyser();
  25440. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  25441. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  25442. audio.getOutput().connect(this.analyser);
  25443. }
  25444. var _proto = AudioAnalyser.prototype;
  25445. _proto.getFrequencyData = function getFrequencyData() {
  25446. this.analyser.getByteFrequencyData(this.data);
  25447. return this.data;
  25448. };
  25449. _proto.getAverageFrequency = function getAverageFrequency() {
  25450. var value = 0;
  25451. var data = this.getFrequencyData();
  25452. for (var i = 0; i < data.length; i++) {
  25453. value += data[i];
  25454. }
  25455. return value / data.length;
  25456. };
  25457. return AudioAnalyser;
  25458. }();
  25459. function PropertyMixer(binding, typeName, valueSize) {
  25460. this.binding = binding;
  25461. this.valueSize = valueSize;
  25462. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25463. //
  25464. // interpolators can use .buffer as their .result
  25465. // the data then goes to 'incoming'
  25466. //
  25467. // 'accu0' and 'accu1' are used frame-interleaved for
  25468. // the cumulative result and are compared to detect
  25469. // changes
  25470. //
  25471. // 'orig' stores the original state of the property
  25472. //
  25473. // 'add' is used for additive cumulative results
  25474. //
  25475. // 'work' is optional and is only present for quaternion types. It is used
  25476. // to store intermediate quaternion multiplication results
  25477. switch (typeName) {
  25478. case 'quaternion':
  25479. mixFunction = this._slerp;
  25480. mixFunctionAdditive = this._slerpAdditive;
  25481. setIdentity = this._setAdditiveIdentityQuaternion;
  25482. this.buffer = new Float64Array(valueSize * 6);
  25483. this._workIndex = 5;
  25484. break;
  25485. case 'string':
  25486. case 'bool':
  25487. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  25488. // additive is not relevant for non-numeric types
  25489. mixFunctionAdditive = this._select;
  25490. setIdentity = this._setAdditiveIdentityOther;
  25491. this.buffer = new Array(valueSize * 5);
  25492. break;
  25493. default:
  25494. mixFunction = this._lerp;
  25495. mixFunctionAdditive = this._lerpAdditive;
  25496. setIdentity = this._setAdditiveIdentityNumeric;
  25497. this.buffer = new Float64Array(valueSize * 5);
  25498. }
  25499. this._mixBufferRegion = mixFunction;
  25500. this._mixBufferRegionAdditive = mixFunctionAdditive;
  25501. this._setIdentity = setIdentity;
  25502. this._origIndex = 3;
  25503. this._addIndex = 4;
  25504. this.cumulativeWeight = 0;
  25505. this.cumulativeWeightAdditive = 0;
  25506. this.useCount = 0;
  25507. this.referenceCount = 0;
  25508. }
  25509. Object.assign(PropertyMixer.prototype, {
  25510. // accumulate data in the 'incoming' region into 'accu<i>'
  25511. accumulate: function accumulate(accuIndex, weight) {
  25512. // note: happily accumulating nothing when weight = 0, the caller knows
  25513. // the weight and shouldn't have made the call in the first place
  25514. var buffer = this.buffer,
  25515. stride = this.valueSize,
  25516. offset = accuIndex * stride + stride;
  25517. var currentWeight = this.cumulativeWeight;
  25518. if (currentWeight === 0) {
  25519. // accuN := incoming * weight
  25520. for (var i = 0; i !== stride; ++i) {
  25521. buffer[offset + i] = buffer[i];
  25522. }
  25523. currentWeight = weight;
  25524. } else {
  25525. // accuN := accuN + incoming * weight
  25526. currentWeight += weight;
  25527. var mix = weight / currentWeight;
  25528. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  25529. }
  25530. this.cumulativeWeight = currentWeight;
  25531. },
  25532. // accumulate data in the 'incoming' region into 'add'
  25533. accumulateAdditive: function accumulateAdditive(weight) {
  25534. var buffer = this.buffer,
  25535. stride = this.valueSize,
  25536. offset = stride * this._addIndex;
  25537. if (this.cumulativeWeightAdditive === 0) {
  25538. // add = identity
  25539. this._setIdentity();
  25540. } // add := add + incoming * weight
  25541. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  25542. this.cumulativeWeightAdditive += weight;
  25543. },
  25544. // apply the state of 'accu<i>' to the binding when accus differ
  25545. apply: function apply(accuIndex) {
  25546. var stride = this.valueSize,
  25547. buffer = this.buffer,
  25548. offset = accuIndex * stride + stride,
  25549. weight = this.cumulativeWeight,
  25550. weightAdditive = this.cumulativeWeightAdditive,
  25551. binding = this.binding;
  25552. this.cumulativeWeight = 0;
  25553. this.cumulativeWeightAdditive = 0;
  25554. if (weight < 1) {
  25555. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25556. var originalValueOffset = stride * this._origIndex;
  25557. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  25558. }
  25559. if (weightAdditive > 0) {
  25560. // accuN := accuN + additive accuN
  25561. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  25562. }
  25563. for (var i = stride, e = stride + stride; i !== e; ++i) {
  25564. if (buffer[i] !== buffer[i + stride]) {
  25565. // value has changed -> update scene graph
  25566. binding.setValue(buffer, offset);
  25567. break;
  25568. }
  25569. }
  25570. },
  25571. // remember the state of the bound property and copy it to both accus
  25572. saveOriginalState: function saveOriginalState() {
  25573. var binding = this.binding;
  25574. var buffer = this.buffer,
  25575. stride = this.valueSize,
  25576. originalValueOffset = stride * this._origIndex;
  25577. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  25578. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  25579. buffer[i] = buffer[originalValueOffset + i % stride];
  25580. } // Add to identity for additive
  25581. this._setIdentity();
  25582. this.cumulativeWeight = 0;
  25583. this.cumulativeWeightAdditive = 0;
  25584. },
  25585. // apply the state previously taken via 'saveOriginalState' to the binding
  25586. restoreOriginalState: function restoreOriginalState() {
  25587. var originalValueOffset = this.valueSize * 3;
  25588. this.binding.setValue(this.buffer, originalValueOffset);
  25589. },
  25590. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  25591. var startIndex = this._addIndex * this.valueSize;
  25592. var endIndex = startIndex + this.valueSize;
  25593. for (var i = startIndex; i < endIndex; i++) {
  25594. this.buffer[i] = 0;
  25595. }
  25596. },
  25597. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  25598. this._setAdditiveIdentityNumeric();
  25599. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  25600. },
  25601. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  25602. var startIndex = this._origIndex * this.valueSize;
  25603. var targetIndex = this._addIndex * this.valueSize;
  25604. for (var i = 0; i < this.valueSize; i++) {
  25605. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  25606. }
  25607. },
  25608. // mix functions
  25609. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  25610. if (t >= 0.5) {
  25611. for (var i = 0; i !== stride; ++i) {
  25612. buffer[dstOffset + i] = buffer[srcOffset + i];
  25613. }
  25614. }
  25615. },
  25616. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  25617. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  25618. },
  25619. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25620. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  25621. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  25622. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  25623. },
  25624. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  25625. var s = 1 - t;
  25626. for (var i = 0; i !== stride; ++i) {
  25627. var j = dstOffset + i;
  25628. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  25629. }
  25630. },
  25631. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25632. for (var i = 0; i !== stride; ++i) {
  25633. var j = dstOffset + i;
  25634. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  25635. }
  25636. }
  25637. });
  25638. // Characters [].:/ are reserved for track binding syntax.
  25639. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25640. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25641. // only latin characters, and the unicode \p{L} is not yet supported. So
  25642. // instead, we exclude reserved characters and match everything else.
  25643. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  25644. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25645. // be matched to parse the rest of the track name.
  25646. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25647. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  25648. // characters. Accessor may contain any character except closing bracket.
  25649. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  25650. // contain any non-bracket characters.
  25651. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  25652. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  25653. var _supportedObjectNames = ['material', 'materials', 'bones'];
  25654. function Composite(targetGroup, path, optionalParsedPath) {
  25655. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  25656. this._targetGroup = targetGroup;
  25657. this._bindings = targetGroup.subscribe_(path, parsedPath);
  25658. }
  25659. Object.assign(Composite.prototype, {
  25660. getValue: function getValue(array, offset) {
  25661. this.bind(); // bind all binding
  25662. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25663. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  25664. if (binding !== undefined) binding.getValue(array, offset);
  25665. },
  25666. setValue: function setValue(array, offset) {
  25667. var bindings = this._bindings;
  25668. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25669. bindings[i].setValue(array, offset);
  25670. }
  25671. },
  25672. bind: function bind() {
  25673. var bindings = this._bindings;
  25674. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25675. bindings[i].bind();
  25676. }
  25677. },
  25678. unbind: function unbind() {
  25679. var bindings = this._bindings;
  25680. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25681. bindings[i].unbind();
  25682. }
  25683. }
  25684. });
  25685. function PropertyBinding(rootNode, path, parsedPath) {
  25686. this.path = path;
  25687. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  25688. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  25689. this.rootNode = rootNode;
  25690. }
  25691. Object.assign(PropertyBinding, {
  25692. Composite: Composite,
  25693. create: function create(root, path, parsedPath) {
  25694. if (!(root && root.isAnimationObjectGroup)) {
  25695. return new PropertyBinding(root, path, parsedPath);
  25696. } else {
  25697. return new PropertyBinding.Composite(root, path, parsedPath);
  25698. }
  25699. },
  25700. /**
  25701. * Replaces spaces with underscores and removes unsupported characters from
  25702. * node names, to ensure compatibility with parseTrackName().
  25703. *
  25704. * @param {string} name Node name to be sanitized.
  25705. * @return {string}
  25706. */
  25707. sanitizeNodeName: function sanitizeNodeName(name) {
  25708. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  25709. },
  25710. parseTrackName: function parseTrackName(trackName) {
  25711. var matches = _trackRe.exec(trackName);
  25712. if (!matches) {
  25713. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  25714. }
  25715. var results = {
  25716. // directoryName: matches[ 1 ], // (tschw) currently unused
  25717. nodeName: matches[2],
  25718. objectName: matches[3],
  25719. objectIndex: matches[4],
  25720. propertyName: matches[5],
  25721. // required
  25722. propertyIndex: matches[6]
  25723. };
  25724. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  25725. if (lastDot !== undefined && lastDot !== -1) {
  25726. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  25727. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  25728. // 'bar' could be the objectName, or part of a nodeName (which can
  25729. // include '.' characters).
  25730. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  25731. results.nodeName = results.nodeName.substring(0, lastDot);
  25732. results.objectName = objectName;
  25733. }
  25734. }
  25735. if (results.propertyName === null || results.propertyName.length === 0) {
  25736. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  25737. }
  25738. return results;
  25739. },
  25740. findNode: function findNode(root, nodeName) {
  25741. if (!nodeName || nodeName === "" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  25742. return root;
  25743. } // search into skeleton bones.
  25744. if (root.skeleton) {
  25745. var bone = root.skeleton.getBoneByName(nodeName);
  25746. if (bone !== undefined) {
  25747. return bone;
  25748. }
  25749. } // search into node subtree.
  25750. if (root.children) {
  25751. var searchNodeSubtree = function searchNodeSubtree(children) {
  25752. for (var i = 0; i < children.length; i++) {
  25753. var childNode = children[i];
  25754. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  25755. return childNode;
  25756. }
  25757. var result = searchNodeSubtree(childNode.children);
  25758. if (result) return result;
  25759. }
  25760. return null;
  25761. };
  25762. var subTreeNode = searchNodeSubtree(root.children);
  25763. if (subTreeNode) {
  25764. return subTreeNode;
  25765. }
  25766. }
  25767. return null;
  25768. }
  25769. });
  25770. Object.assign(PropertyBinding.prototype, {
  25771. // prototype, continued
  25772. // these are used to "bind" a nonexistent property
  25773. _getValue_unavailable: function _getValue_unavailable() {},
  25774. _setValue_unavailable: function _setValue_unavailable() {},
  25775. BindingType: {
  25776. Direct: 0,
  25777. EntireArray: 1,
  25778. ArrayElement: 2,
  25779. HasFromToArray: 3
  25780. },
  25781. Versioning: {
  25782. None: 0,
  25783. NeedsUpdate: 1,
  25784. MatrixWorldNeedsUpdate: 2
  25785. },
  25786. GetterByBindingType: [function getValue_direct(buffer, offset) {
  25787. buffer[offset] = this.node[this.propertyName];
  25788. }, function getValue_array(buffer, offset) {
  25789. var source = this.resolvedProperty;
  25790. for (var i = 0, n = source.length; i !== n; ++i) {
  25791. buffer[offset++] = source[i];
  25792. }
  25793. }, function getValue_arrayElement(buffer, offset) {
  25794. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  25795. }, function getValue_toArray(buffer, offset) {
  25796. this.resolvedProperty.toArray(buffer, offset);
  25797. }],
  25798. SetterByBindingTypeAndVersioning: [[// Direct
  25799. function setValue_direct(buffer, offset) {
  25800. this.targetObject[this.propertyName] = buffer[offset];
  25801. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  25802. this.targetObject[this.propertyName] = buffer[offset];
  25803. this.targetObject.needsUpdate = true;
  25804. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  25805. this.targetObject[this.propertyName] = buffer[offset];
  25806. this.targetObject.matrixWorldNeedsUpdate = true;
  25807. }], [// EntireArray
  25808. function setValue_array(buffer, offset) {
  25809. var dest = this.resolvedProperty;
  25810. for (var i = 0, n = dest.length; i !== n; ++i) {
  25811. dest[i] = buffer[offset++];
  25812. }
  25813. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  25814. var dest = this.resolvedProperty;
  25815. for (var i = 0, n = dest.length; i !== n; ++i) {
  25816. dest[i] = buffer[offset++];
  25817. }
  25818. this.targetObject.needsUpdate = true;
  25819. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  25820. var dest = this.resolvedProperty;
  25821. for (var i = 0, n = dest.length; i !== n; ++i) {
  25822. dest[i] = buffer[offset++];
  25823. }
  25824. this.targetObject.matrixWorldNeedsUpdate = true;
  25825. }], [// ArrayElement
  25826. function setValue_arrayElement(buffer, offset) {
  25827. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25828. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  25829. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25830. this.targetObject.needsUpdate = true;
  25831. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  25832. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25833. this.targetObject.matrixWorldNeedsUpdate = true;
  25834. }], [// HasToFromArray
  25835. function setValue_fromArray(buffer, offset) {
  25836. this.resolvedProperty.fromArray(buffer, offset);
  25837. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  25838. this.resolvedProperty.fromArray(buffer, offset);
  25839. this.targetObject.needsUpdate = true;
  25840. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  25841. this.resolvedProperty.fromArray(buffer, offset);
  25842. this.targetObject.matrixWorldNeedsUpdate = true;
  25843. }]],
  25844. getValue: function getValue_unbound(targetArray, offset) {
  25845. this.bind();
  25846. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  25847. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  25848. // prototype version of these methods with one that represents
  25849. // the bound state. When the property is not found, the methods
  25850. // become no-ops.
  25851. },
  25852. setValue: function getValue_unbound(sourceArray, offset) {
  25853. this.bind();
  25854. this.setValue(sourceArray, offset);
  25855. },
  25856. // create getter / setter pair for a property in the scene graph
  25857. bind: function bind() {
  25858. var targetObject = this.node;
  25859. var parsedPath = this.parsedPath;
  25860. var objectName = parsedPath.objectName;
  25861. var propertyName = parsedPath.propertyName;
  25862. var propertyIndex = parsedPath.propertyIndex;
  25863. if (!targetObject) {
  25864. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  25865. this.node = targetObject;
  25866. } // set fail state so we can just 'return' on error
  25867. this.getValue = this._getValue_unavailable;
  25868. this.setValue = this._setValue_unavailable; // ensure there is a value node
  25869. if (!targetObject) {
  25870. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  25871. return;
  25872. }
  25873. if (objectName) {
  25874. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  25875. switch (objectName) {
  25876. case 'materials':
  25877. if (!targetObject.material) {
  25878. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  25879. return;
  25880. }
  25881. if (!targetObject.material.materials) {
  25882. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  25883. return;
  25884. }
  25885. targetObject = targetObject.material.materials;
  25886. break;
  25887. case 'bones':
  25888. if (!targetObject.skeleton) {
  25889. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  25890. return;
  25891. } // potential future optimization: skip this if propertyIndex is already an integer
  25892. // and convert the integer string to a true integer.
  25893. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  25894. for (var i = 0; i < targetObject.length; i++) {
  25895. if (targetObject[i].name === objectIndex) {
  25896. objectIndex = i;
  25897. break;
  25898. }
  25899. }
  25900. break;
  25901. default:
  25902. if (targetObject[objectName] === undefined) {
  25903. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  25904. return;
  25905. }
  25906. targetObject = targetObject[objectName];
  25907. }
  25908. if (objectIndex !== undefined) {
  25909. if (targetObject[objectIndex] === undefined) {
  25910. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  25911. return;
  25912. }
  25913. targetObject = targetObject[objectIndex];
  25914. }
  25915. } // resolve property
  25916. var nodeProperty = targetObject[propertyName];
  25917. if (nodeProperty === undefined) {
  25918. var nodeName = parsedPath.nodeName;
  25919. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  25920. return;
  25921. } // determine versioning scheme
  25922. var versioning = this.Versioning.None;
  25923. this.targetObject = targetObject;
  25924. if (targetObject.needsUpdate !== undefined) {
  25925. // material
  25926. versioning = this.Versioning.NeedsUpdate;
  25927. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  25928. // node transform
  25929. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  25930. } // determine how the property gets bound
  25931. var bindingType = this.BindingType.Direct;
  25932. if (propertyIndex !== undefined) {
  25933. // access a sub element of the property array (only primitives are supported right now)
  25934. if (propertyName === "morphTargetInfluences") {
  25935. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  25936. // support resolving morphTarget names into indices.
  25937. if (!targetObject.geometry) {
  25938. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  25939. return;
  25940. }
  25941. if (targetObject.geometry.isBufferGeometry) {
  25942. if (!targetObject.geometry.morphAttributes) {
  25943. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  25944. return;
  25945. }
  25946. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  25947. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  25948. }
  25949. } else {
  25950. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  25951. return;
  25952. }
  25953. }
  25954. bindingType = this.BindingType.ArrayElement;
  25955. this.resolvedProperty = nodeProperty;
  25956. this.propertyIndex = propertyIndex;
  25957. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  25958. // must use copy for Object3D.Euler/Quaternion
  25959. bindingType = this.BindingType.HasFromToArray;
  25960. this.resolvedProperty = nodeProperty;
  25961. } else if (Array.isArray(nodeProperty)) {
  25962. bindingType = this.BindingType.EntireArray;
  25963. this.resolvedProperty = nodeProperty;
  25964. } else {
  25965. this.propertyName = propertyName;
  25966. } // select getter / setter
  25967. this.getValue = this.GetterByBindingType[bindingType];
  25968. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  25969. },
  25970. unbind: function unbind() {
  25971. this.node = null; // back to the prototype version of getValue / setValue
  25972. // note: avoiding to mutate the shape of 'this' via 'delete'
  25973. this.getValue = this._getValue_unbound;
  25974. this.setValue = this._setValue_unbound;
  25975. }
  25976. }); // DECLARE ALIAS AFTER assign prototype
  25977. Object.assign(PropertyBinding.prototype, {
  25978. // initial state of these methods that calls 'bind'
  25979. _getValue_unbound: PropertyBinding.prototype.getValue,
  25980. _setValue_unbound: PropertyBinding.prototype.setValue
  25981. });
  25982. /**
  25983. *
  25984. * A group of objects that receives a shared animation state.
  25985. *
  25986. * Usage:
  25987. *
  25988. * - Add objects you would otherwise pass as 'root' to the
  25989. * constructor or the .clipAction method of AnimationMixer.
  25990. *
  25991. * - Instead pass this object as 'root'.
  25992. *
  25993. * - You can also add and remove objects later when the mixer
  25994. * is running.
  25995. *
  25996. * Note:
  25997. *
  25998. * Objects of this class appear as one object to the mixer,
  25999. * so cache control of the individual objects must be done
  26000. * on the group.
  26001. *
  26002. * Limitation:
  26003. *
  26004. * - The animated properties must be compatible among the
  26005. * all objects in the group.
  26006. *
  26007. * - A single property can either be controlled through a
  26008. * target group or directly, but not both.
  26009. */
  26010. function AnimationObjectGroup() {
  26011. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26012. this._objects = Array.prototype.slice.call(arguments);
  26013. this.nCachedObjects_ = 0; // threshold
  26014. // note: read by PropertyBinding.Composite
  26015. var indices = {};
  26016. this._indicesByUUID = indices; // for bookkeeping
  26017. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26018. indices[arguments[i].uuid] = i;
  26019. }
  26020. this._paths = []; // inside: string
  26021. this._parsedPaths = []; // inside: { we don't care, here }
  26022. this._bindings = []; // inside: Array< PropertyBinding >
  26023. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26024. var scope = this;
  26025. this.stats = {
  26026. objects: {
  26027. get total() {
  26028. return scope._objects.length;
  26029. },
  26030. get inUse() {
  26031. return this.total - scope.nCachedObjects_;
  26032. }
  26033. },
  26034. get bindingsPerObject() {
  26035. return scope._bindings.length;
  26036. }
  26037. };
  26038. }
  26039. Object.assign(AnimationObjectGroup.prototype, {
  26040. isAnimationObjectGroup: true,
  26041. add: function add() {
  26042. var objects = this._objects,
  26043. indicesByUUID = this._indicesByUUID,
  26044. paths = this._paths,
  26045. parsedPaths = this._parsedPaths,
  26046. bindings = this._bindings,
  26047. nBindings = bindings.length;
  26048. var knownObject = undefined,
  26049. nObjects = objects.length,
  26050. nCachedObjects = this.nCachedObjects_;
  26051. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26052. var object = arguments[i],
  26053. uuid = object.uuid;
  26054. var index = indicesByUUID[uuid];
  26055. if (index === undefined) {
  26056. // unknown object -> add it to the ACTIVE region
  26057. index = nObjects++;
  26058. indicesByUUID[uuid] = index;
  26059. objects.push(object); // accounting is done, now do the same for all bindings
  26060. for (var j = 0, m = nBindings; j !== m; ++j) {
  26061. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26062. }
  26063. } else if (index < nCachedObjects) {
  26064. knownObject = objects[index]; // move existing object to the ACTIVE region
  26065. var firstActiveIndex = --nCachedObjects,
  26066. lastCachedObject = objects[firstActiveIndex];
  26067. indicesByUUID[lastCachedObject.uuid] = index;
  26068. objects[index] = lastCachedObject;
  26069. indicesByUUID[uuid] = firstActiveIndex;
  26070. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26071. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26072. var bindingsForPath = bindings[_j],
  26073. lastCached = bindingsForPath[firstActiveIndex];
  26074. var binding = bindingsForPath[index];
  26075. bindingsForPath[index] = lastCached;
  26076. if (binding === undefined) {
  26077. // since we do not bother to create new bindings
  26078. // for objects that are cached, the binding may
  26079. // or may not exist
  26080. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26081. }
  26082. bindingsForPath[firstActiveIndex] = binding;
  26083. }
  26084. } else if (objects[index] !== knownObject) {
  26085. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26086. } // else the object is already where we want it to be
  26087. } // for arguments
  26088. this.nCachedObjects_ = nCachedObjects;
  26089. },
  26090. remove: function remove() {
  26091. var objects = this._objects,
  26092. indicesByUUID = this._indicesByUUID,
  26093. bindings = this._bindings,
  26094. nBindings = bindings.length;
  26095. var nCachedObjects = this.nCachedObjects_;
  26096. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26097. var object = arguments[i],
  26098. uuid = object.uuid,
  26099. index = indicesByUUID[uuid];
  26100. if (index !== undefined && index >= nCachedObjects) {
  26101. // move existing object into the CACHED region
  26102. var lastCachedIndex = nCachedObjects++,
  26103. firstActiveObject = objects[lastCachedIndex];
  26104. indicesByUUID[firstActiveObject.uuid] = index;
  26105. objects[index] = firstActiveObject;
  26106. indicesByUUID[uuid] = lastCachedIndex;
  26107. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26108. for (var j = 0, m = nBindings; j !== m; ++j) {
  26109. var bindingsForPath = bindings[j],
  26110. firstActive = bindingsForPath[lastCachedIndex],
  26111. binding = bindingsForPath[index];
  26112. bindingsForPath[index] = firstActive;
  26113. bindingsForPath[lastCachedIndex] = binding;
  26114. }
  26115. }
  26116. } // for arguments
  26117. this.nCachedObjects_ = nCachedObjects;
  26118. },
  26119. // remove & forget
  26120. uncache: function uncache() {
  26121. var objects = this._objects,
  26122. indicesByUUID = this._indicesByUUID,
  26123. bindings = this._bindings,
  26124. nBindings = bindings.length;
  26125. var nCachedObjects = this.nCachedObjects_,
  26126. nObjects = objects.length;
  26127. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26128. var object = arguments[i],
  26129. uuid = object.uuid,
  26130. index = indicesByUUID[uuid];
  26131. if (index !== undefined) {
  26132. delete indicesByUUID[uuid];
  26133. if (index < nCachedObjects) {
  26134. // object is cached, shrink the CACHED region
  26135. var firstActiveIndex = --nCachedObjects,
  26136. lastCachedObject = objects[firstActiveIndex],
  26137. lastIndex = --nObjects,
  26138. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26139. indicesByUUID[lastCachedObject.uuid] = index;
  26140. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26141. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26142. objects[firstActiveIndex] = lastObject;
  26143. objects.pop(); // accounting is done, now do the same for all bindings
  26144. for (var j = 0, m = nBindings; j !== m; ++j) {
  26145. var bindingsForPath = bindings[j],
  26146. lastCached = bindingsForPath[firstActiveIndex],
  26147. last = bindingsForPath[lastIndex];
  26148. bindingsForPath[index] = lastCached;
  26149. bindingsForPath[firstActiveIndex] = last;
  26150. bindingsForPath.pop();
  26151. }
  26152. } else {
  26153. // object is active, just swap with the last and pop
  26154. var _lastIndex = --nObjects,
  26155. _lastObject = objects[_lastIndex];
  26156. indicesByUUID[_lastObject.uuid] = index;
  26157. objects[index] = _lastObject;
  26158. objects.pop(); // accounting is done, now do the same for all bindings
  26159. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26160. var _bindingsForPath = bindings[_j2];
  26161. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26162. _bindingsForPath.pop();
  26163. }
  26164. } // cached or active
  26165. } // if object is known
  26166. } // for arguments
  26167. this.nCachedObjects_ = nCachedObjects;
  26168. },
  26169. // Internal interface used by befriended PropertyBinding.Composite:
  26170. subscribe_: function subscribe_(path, parsedPath) {
  26171. // returns an array of bindings for the given path that is changed
  26172. // according to the contained objects in the group
  26173. var indicesByPath = this._bindingsIndicesByPath;
  26174. var index = indicesByPath[path];
  26175. var bindings = this._bindings;
  26176. if (index !== undefined) return bindings[index];
  26177. var paths = this._paths,
  26178. parsedPaths = this._parsedPaths,
  26179. objects = this._objects,
  26180. nObjects = objects.length,
  26181. nCachedObjects = this.nCachedObjects_,
  26182. bindingsForPath = new Array(nObjects);
  26183. index = bindings.length;
  26184. indicesByPath[path] = index;
  26185. paths.push(path);
  26186. parsedPaths.push(parsedPath);
  26187. bindings.push(bindingsForPath);
  26188. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26189. var object = objects[i];
  26190. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26191. }
  26192. return bindingsForPath;
  26193. },
  26194. unsubscribe_: function unsubscribe_(path) {
  26195. // tells the group to forget about a property path and no longer
  26196. // update the array previously obtained with 'subscribe_'
  26197. var indicesByPath = this._bindingsIndicesByPath,
  26198. index = indicesByPath[path];
  26199. if (index !== undefined) {
  26200. var paths = this._paths,
  26201. parsedPaths = this._parsedPaths,
  26202. bindings = this._bindings,
  26203. lastBindingsIndex = bindings.length - 1,
  26204. lastBindings = bindings[lastBindingsIndex],
  26205. lastBindingsPath = path[lastBindingsIndex];
  26206. indicesByPath[lastBindingsPath] = index;
  26207. bindings[index] = lastBindings;
  26208. bindings.pop();
  26209. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26210. parsedPaths.pop();
  26211. paths[index] = paths[lastBindingsIndex];
  26212. paths.pop();
  26213. }
  26214. }
  26215. });
  26216. var AnimationAction = /*#__PURE__*/function () {
  26217. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26218. this._mixer = mixer;
  26219. this._clip = clip;
  26220. this._localRoot = localRoot || null;
  26221. this.blendMode = blendMode || clip.blendMode;
  26222. var tracks = clip.tracks,
  26223. nTracks = tracks.length,
  26224. interpolants = new Array(nTracks);
  26225. var interpolantSettings = {
  26226. endingStart: ZeroCurvatureEnding,
  26227. endingEnd: ZeroCurvatureEnding
  26228. };
  26229. for (var i = 0; i !== nTracks; ++i) {
  26230. var interpolant = tracks[i].createInterpolant(null);
  26231. interpolants[i] = interpolant;
  26232. interpolant.settings = interpolantSettings;
  26233. }
  26234. this._interpolantSettings = interpolantSettings;
  26235. this._interpolants = interpolants; // bound by the mixer
  26236. // inside: PropertyMixer (managed by the mixer)
  26237. this._propertyBindings = new Array(nTracks);
  26238. this._cacheIndex = null; // for the memory manager
  26239. this._byClipCacheIndex = null; // for the memory manager
  26240. this._timeScaleInterpolant = null;
  26241. this._weightInterpolant = null;
  26242. this.loop = LoopRepeat;
  26243. this._loopCount = -1; // global mixer time when the action is to be started
  26244. // it's set back to 'null' upon start of the action
  26245. this._startTime = null; // scaled local time of the action
  26246. // gets clamped or wrapped to 0..clip.duration according to loop
  26247. this.time = 0;
  26248. this.timeScale = 1;
  26249. this._effectiveTimeScale = 1;
  26250. this.weight = 1;
  26251. this._effectiveWeight = 1;
  26252. this.repetitions = Infinity; // no. of repetitions when looping
  26253. this.paused = false; // true -> zero effective time scale
  26254. this.enabled = true; // false -> zero effective weight
  26255. this.clampWhenFinished = false; // keep feeding the last frame?
  26256. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  26257. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  26258. } // State & Scheduling
  26259. var _proto = AnimationAction.prototype;
  26260. _proto.play = function play() {
  26261. this._mixer._activateAction(this);
  26262. return this;
  26263. };
  26264. _proto.stop = function stop() {
  26265. this._mixer._deactivateAction(this);
  26266. return this.reset();
  26267. };
  26268. _proto.reset = function reset() {
  26269. this.paused = false;
  26270. this.enabled = true;
  26271. this.time = 0; // restart clip
  26272. this._loopCount = -1; // forget previous loops
  26273. this._startTime = null; // forget scheduling
  26274. return this.stopFading().stopWarping();
  26275. };
  26276. _proto.isRunning = function isRunning() {
  26277. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  26278. } // return true when play has been called
  26279. ;
  26280. _proto.isScheduled = function isScheduled() {
  26281. return this._mixer._isActiveAction(this);
  26282. };
  26283. _proto.startAt = function startAt(time) {
  26284. this._startTime = time;
  26285. return this;
  26286. };
  26287. _proto.setLoop = function setLoop(mode, repetitions) {
  26288. this.loop = mode;
  26289. this.repetitions = repetitions;
  26290. return this;
  26291. } // Weight
  26292. // set the weight stopping any scheduled fading
  26293. // although .enabled = false yields an effective weight of zero, this
  26294. // method does *not* change .enabled, because it would be confusing
  26295. ;
  26296. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  26297. this.weight = weight; // note: same logic as when updated at runtime
  26298. this._effectiveWeight = this.enabled ? weight : 0;
  26299. return this.stopFading();
  26300. } // return the weight considering fading and .enabled
  26301. ;
  26302. _proto.getEffectiveWeight = function getEffectiveWeight() {
  26303. return this._effectiveWeight;
  26304. };
  26305. _proto.fadeIn = function fadeIn(duration) {
  26306. return this._scheduleFading(duration, 0, 1);
  26307. };
  26308. _proto.fadeOut = function fadeOut(duration) {
  26309. return this._scheduleFading(duration, 1, 0);
  26310. };
  26311. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  26312. fadeOutAction.fadeOut(duration);
  26313. this.fadeIn(duration);
  26314. if (warp) {
  26315. var fadeInDuration = this._clip.duration,
  26316. fadeOutDuration = fadeOutAction._clip.duration,
  26317. startEndRatio = fadeOutDuration / fadeInDuration,
  26318. endStartRatio = fadeInDuration / fadeOutDuration;
  26319. fadeOutAction.warp(1.0, startEndRatio, duration);
  26320. this.warp(endStartRatio, 1.0, duration);
  26321. }
  26322. return this;
  26323. };
  26324. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  26325. return fadeInAction.crossFadeFrom(this, duration, warp);
  26326. };
  26327. _proto.stopFading = function stopFading() {
  26328. var weightInterpolant = this._weightInterpolant;
  26329. if (weightInterpolant !== null) {
  26330. this._weightInterpolant = null;
  26331. this._mixer._takeBackControlInterpolant(weightInterpolant);
  26332. }
  26333. return this;
  26334. } // Time Scale Control
  26335. // set the time scale stopping any scheduled warping
  26336. // although .paused = true yields an effective time scale of zero, this
  26337. // method does *not* change .paused, because it would be confusing
  26338. ;
  26339. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  26340. this.timeScale = timeScale;
  26341. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26342. return this.stopWarping();
  26343. } // return the time scale considering warping and .paused
  26344. ;
  26345. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  26346. return this._effectiveTimeScale;
  26347. };
  26348. _proto.setDuration = function setDuration(duration) {
  26349. this.timeScale = this._clip.duration / duration;
  26350. return this.stopWarping();
  26351. };
  26352. _proto.syncWith = function syncWith(action) {
  26353. this.time = action.time;
  26354. this.timeScale = action.timeScale;
  26355. return this.stopWarping();
  26356. };
  26357. _proto.halt = function halt(duration) {
  26358. return this.warp(this._effectiveTimeScale, 0, duration);
  26359. };
  26360. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  26361. var mixer = this._mixer,
  26362. now = mixer.time,
  26363. timeScale = this.timeScale;
  26364. var interpolant = this._timeScaleInterpolant;
  26365. if (interpolant === null) {
  26366. interpolant = mixer._lendControlInterpolant();
  26367. this._timeScaleInterpolant = interpolant;
  26368. }
  26369. var times = interpolant.parameterPositions,
  26370. values = interpolant.sampleValues;
  26371. times[0] = now;
  26372. times[1] = now + duration;
  26373. values[0] = startTimeScale / timeScale;
  26374. values[1] = endTimeScale / timeScale;
  26375. return this;
  26376. };
  26377. _proto.stopWarping = function stopWarping() {
  26378. var timeScaleInterpolant = this._timeScaleInterpolant;
  26379. if (timeScaleInterpolant !== null) {
  26380. this._timeScaleInterpolant = null;
  26381. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  26382. }
  26383. return this;
  26384. } // Object Accessors
  26385. ;
  26386. _proto.getMixer = function getMixer() {
  26387. return this._mixer;
  26388. };
  26389. _proto.getClip = function getClip() {
  26390. return this._clip;
  26391. };
  26392. _proto.getRoot = function getRoot() {
  26393. return this._localRoot || this._mixer._root;
  26394. } // Interna
  26395. ;
  26396. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  26397. // called by the mixer
  26398. if (!this.enabled) {
  26399. // call ._updateWeight() to update ._effectiveWeight
  26400. this._updateWeight(time);
  26401. return;
  26402. }
  26403. var startTime = this._startTime;
  26404. if (startTime !== null) {
  26405. // check for scheduled start of action
  26406. var timeRunning = (time - startTime) * timeDirection;
  26407. if (timeRunning < 0 || timeDirection === 0) {
  26408. return; // yet to come / don't decide when delta = 0
  26409. } // start
  26410. this._startTime = null; // unschedule
  26411. deltaTime = timeDirection * timeRunning;
  26412. } // apply time scale and advance time
  26413. deltaTime *= this._updateTimeScale(time);
  26414. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  26415. // an effective weight of 0
  26416. var weight = this._updateWeight(time);
  26417. if (weight > 0) {
  26418. var _interpolants = this._interpolants;
  26419. var propertyMixers = this._propertyBindings;
  26420. switch (this.blendMode) {
  26421. case AdditiveAnimationBlendMode:
  26422. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  26423. _interpolants[j].evaluate(clipTime);
  26424. propertyMixers[j].accumulateAdditive(weight);
  26425. }
  26426. break;
  26427. case NormalAnimationBlendMode:
  26428. default:
  26429. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  26430. _interpolants[_j].evaluate(clipTime);
  26431. propertyMixers[_j].accumulate(accuIndex, weight);
  26432. }
  26433. }
  26434. }
  26435. };
  26436. _proto._updateWeight = function _updateWeight(time) {
  26437. var weight = 0;
  26438. if (this.enabled) {
  26439. weight = this.weight;
  26440. var interpolant = this._weightInterpolant;
  26441. if (interpolant !== null) {
  26442. var interpolantValue = interpolant.evaluate(time)[0];
  26443. weight *= interpolantValue;
  26444. if (time > interpolant.parameterPositions[1]) {
  26445. this.stopFading();
  26446. if (interpolantValue === 0) {
  26447. // faded out, disable
  26448. this.enabled = false;
  26449. }
  26450. }
  26451. }
  26452. }
  26453. this._effectiveWeight = weight;
  26454. return weight;
  26455. };
  26456. _proto._updateTimeScale = function _updateTimeScale(time) {
  26457. var timeScale = 0;
  26458. if (!this.paused) {
  26459. timeScale = this.timeScale;
  26460. var interpolant = this._timeScaleInterpolant;
  26461. if (interpolant !== null) {
  26462. var interpolantValue = interpolant.evaluate(time)[0];
  26463. timeScale *= interpolantValue;
  26464. if (time > interpolant.parameterPositions[1]) {
  26465. this.stopWarping();
  26466. if (timeScale === 0) {
  26467. // motion has halted, pause
  26468. this.paused = true;
  26469. } else {
  26470. // warp done - apply final time scale
  26471. this.timeScale = timeScale;
  26472. }
  26473. }
  26474. }
  26475. }
  26476. this._effectiveTimeScale = timeScale;
  26477. return timeScale;
  26478. };
  26479. _proto._updateTime = function _updateTime(deltaTime) {
  26480. var duration = this._clip.duration;
  26481. var loop = this.loop;
  26482. var time = this.time + deltaTime;
  26483. var loopCount = this._loopCount;
  26484. var pingPong = loop === LoopPingPong;
  26485. if (deltaTime === 0) {
  26486. if (loopCount === -1) return time;
  26487. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  26488. }
  26489. if (loop === LoopOnce) {
  26490. if (loopCount === -1) {
  26491. // just started
  26492. this._loopCount = 0;
  26493. this._setEndings(true, true, false);
  26494. }
  26495. handle_stop: {
  26496. if (time >= duration) {
  26497. time = duration;
  26498. } else if (time < 0) {
  26499. time = 0;
  26500. } else {
  26501. this.time = time;
  26502. break handle_stop;
  26503. }
  26504. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26505. this.time = time;
  26506. this._mixer.dispatchEvent({
  26507. type: 'finished',
  26508. action: this,
  26509. direction: deltaTime < 0 ? -1 : 1
  26510. });
  26511. }
  26512. } else {
  26513. // repetitive Repeat or PingPong
  26514. if (loopCount === -1) {
  26515. // just started
  26516. if (deltaTime >= 0) {
  26517. loopCount = 0;
  26518. this._setEndings(true, this.repetitions === 0, pingPong);
  26519. } else {
  26520. // when looping in reverse direction, the initial
  26521. // transition through zero counts as a repetition,
  26522. // so leave loopCount at -1
  26523. this._setEndings(this.repetitions === 0, true, pingPong);
  26524. }
  26525. }
  26526. if (time >= duration || time < 0) {
  26527. // wrap around
  26528. var loopDelta = Math.floor(time / duration); // signed
  26529. time -= duration * loopDelta;
  26530. loopCount += Math.abs(loopDelta);
  26531. var pending = this.repetitions - loopCount;
  26532. if (pending <= 0) {
  26533. // have to stop (switch state, clamp time, fire event)
  26534. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26535. time = deltaTime > 0 ? duration : 0;
  26536. this.time = time;
  26537. this._mixer.dispatchEvent({
  26538. type: 'finished',
  26539. action: this,
  26540. direction: deltaTime > 0 ? 1 : -1
  26541. });
  26542. } else {
  26543. // keep running
  26544. if (pending === 1) {
  26545. // entering the last round
  26546. var atStart = deltaTime < 0;
  26547. this._setEndings(atStart, !atStart, pingPong);
  26548. } else {
  26549. this._setEndings(false, false, pingPong);
  26550. }
  26551. this._loopCount = loopCount;
  26552. this.time = time;
  26553. this._mixer.dispatchEvent({
  26554. type: 'loop',
  26555. action: this,
  26556. loopDelta: loopDelta
  26557. });
  26558. }
  26559. } else {
  26560. this.time = time;
  26561. }
  26562. if (pingPong && (loopCount & 1) === 1) {
  26563. // invert time for the "pong round"
  26564. return duration - time;
  26565. }
  26566. }
  26567. return time;
  26568. };
  26569. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  26570. var settings = this._interpolantSettings;
  26571. if (pingPong) {
  26572. settings.endingStart = ZeroSlopeEnding;
  26573. settings.endingEnd = ZeroSlopeEnding;
  26574. } else {
  26575. // assuming for LoopOnce atStart == atEnd == true
  26576. if (atStart) {
  26577. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26578. } else {
  26579. settings.endingStart = WrapAroundEnding;
  26580. }
  26581. if (atEnd) {
  26582. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26583. } else {
  26584. settings.endingEnd = WrapAroundEnding;
  26585. }
  26586. }
  26587. };
  26588. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  26589. var mixer = this._mixer,
  26590. now = mixer.time;
  26591. var interpolant = this._weightInterpolant;
  26592. if (interpolant === null) {
  26593. interpolant = mixer._lendControlInterpolant();
  26594. this._weightInterpolant = interpolant;
  26595. }
  26596. var times = interpolant.parameterPositions,
  26597. values = interpolant.sampleValues;
  26598. times[0] = now;
  26599. values[0] = weightNow;
  26600. times[1] = now + duration;
  26601. values[1] = weightThen;
  26602. return this;
  26603. };
  26604. return AnimationAction;
  26605. }();
  26606. function AnimationMixer(root) {
  26607. this._root = root;
  26608. this._initMemoryManager();
  26609. this._accuIndex = 0;
  26610. this.time = 0;
  26611. this.timeScale = 1.0;
  26612. }
  26613. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  26614. constructor: AnimationMixer,
  26615. _bindAction: function _bindAction(action, prototypeAction) {
  26616. var root = action._localRoot || this._root,
  26617. tracks = action._clip.tracks,
  26618. nTracks = tracks.length,
  26619. bindings = action._propertyBindings,
  26620. interpolants = action._interpolants,
  26621. rootUuid = root.uuid,
  26622. bindingsByRoot = this._bindingsByRootAndName;
  26623. var bindingsByName = bindingsByRoot[rootUuid];
  26624. if (bindingsByName === undefined) {
  26625. bindingsByName = {};
  26626. bindingsByRoot[rootUuid] = bindingsByName;
  26627. }
  26628. for (var i = 0; i !== nTracks; ++i) {
  26629. var track = tracks[i],
  26630. trackName = track.name;
  26631. var binding = bindingsByName[trackName];
  26632. if (binding !== undefined) {
  26633. bindings[i] = binding;
  26634. } else {
  26635. binding = bindings[i];
  26636. if (binding !== undefined) {
  26637. // existing binding, make sure the cache knows
  26638. if (binding._cacheIndex === null) {
  26639. ++binding.referenceCount;
  26640. this._addInactiveBinding(binding, rootUuid, trackName);
  26641. }
  26642. continue;
  26643. }
  26644. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  26645. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  26646. ++binding.referenceCount;
  26647. this._addInactiveBinding(binding, rootUuid, trackName);
  26648. bindings[i] = binding;
  26649. }
  26650. interpolants[i].resultBuffer = binding.buffer;
  26651. }
  26652. },
  26653. _activateAction: function _activateAction(action) {
  26654. if (!this._isActiveAction(action)) {
  26655. if (action._cacheIndex === null) {
  26656. // this action has been forgotten by the cache, but the user
  26657. // appears to be still using it -> rebind
  26658. var rootUuid = (action._localRoot || this._root).uuid,
  26659. clipUuid = action._clip.uuid,
  26660. actionsForClip = this._actionsByClip[clipUuid];
  26661. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  26662. this._addInactiveAction(action, clipUuid, rootUuid);
  26663. }
  26664. var bindings = action._propertyBindings; // increment reference counts / sort out state
  26665. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26666. var binding = bindings[i];
  26667. if (binding.useCount++ === 0) {
  26668. this._lendBinding(binding);
  26669. binding.saveOriginalState();
  26670. }
  26671. }
  26672. this._lendAction(action);
  26673. }
  26674. },
  26675. _deactivateAction: function _deactivateAction(action) {
  26676. if (this._isActiveAction(action)) {
  26677. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  26678. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26679. var binding = bindings[i];
  26680. if (--binding.useCount === 0) {
  26681. binding.restoreOriginalState();
  26682. this._takeBackBinding(binding);
  26683. }
  26684. }
  26685. this._takeBackAction(action);
  26686. }
  26687. },
  26688. // Memory manager
  26689. _initMemoryManager: function _initMemoryManager() {
  26690. this._actions = []; // 'nActiveActions' followed by inactive ones
  26691. this._nActiveActions = 0;
  26692. this._actionsByClip = {}; // inside:
  26693. // {
  26694. // knownActions: Array< AnimationAction > - used as prototypes
  26695. // actionByRoot: AnimationAction - lookup
  26696. // }
  26697. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  26698. this._nActiveBindings = 0;
  26699. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  26700. this._controlInterpolants = []; // same game as above
  26701. this._nActiveControlInterpolants = 0;
  26702. var scope = this;
  26703. this.stats = {
  26704. actions: {
  26705. get total() {
  26706. return scope._actions.length;
  26707. },
  26708. get inUse() {
  26709. return scope._nActiveActions;
  26710. }
  26711. },
  26712. bindings: {
  26713. get total() {
  26714. return scope._bindings.length;
  26715. },
  26716. get inUse() {
  26717. return scope._nActiveBindings;
  26718. }
  26719. },
  26720. controlInterpolants: {
  26721. get total() {
  26722. return scope._controlInterpolants.length;
  26723. },
  26724. get inUse() {
  26725. return scope._nActiveControlInterpolants;
  26726. }
  26727. }
  26728. };
  26729. },
  26730. // Memory management for AnimationAction objects
  26731. _isActiveAction: function _isActiveAction(action) {
  26732. var index = action._cacheIndex;
  26733. return index !== null && index < this._nActiveActions;
  26734. },
  26735. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  26736. var actions = this._actions,
  26737. actionsByClip = this._actionsByClip;
  26738. var actionsForClip = actionsByClip[clipUuid];
  26739. if (actionsForClip === undefined) {
  26740. actionsForClip = {
  26741. knownActions: [action],
  26742. actionByRoot: {}
  26743. };
  26744. action._byClipCacheIndex = 0;
  26745. actionsByClip[clipUuid] = actionsForClip;
  26746. } else {
  26747. var knownActions = actionsForClip.knownActions;
  26748. action._byClipCacheIndex = knownActions.length;
  26749. knownActions.push(action);
  26750. }
  26751. action._cacheIndex = actions.length;
  26752. actions.push(action);
  26753. actionsForClip.actionByRoot[rootUuid] = action;
  26754. },
  26755. _removeInactiveAction: function _removeInactiveAction(action) {
  26756. var actions = this._actions,
  26757. lastInactiveAction = actions[actions.length - 1],
  26758. cacheIndex = action._cacheIndex;
  26759. lastInactiveAction._cacheIndex = cacheIndex;
  26760. actions[cacheIndex] = lastInactiveAction;
  26761. actions.pop();
  26762. action._cacheIndex = null;
  26763. var clipUuid = action._clip.uuid,
  26764. actionsByClip = this._actionsByClip,
  26765. actionsForClip = actionsByClip[clipUuid],
  26766. knownActionsForClip = actionsForClip.knownActions,
  26767. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  26768. byClipCacheIndex = action._byClipCacheIndex;
  26769. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26770. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  26771. knownActionsForClip.pop();
  26772. action._byClipCacheIndex = null;
  26773. var actionByRoot = actionsForClip.actionByRoot,
  26774. rootUuid = (action._localRoot || this._root).uuid;
  26775. delete actionByRoot[rootUuid];
  26776. if (knownActionsForClip.length === 0) {
  26777. delete actionsByClip[clipUuid];
  26778. }
  26779. this._removeInactiveBindingsForAction(action);
  26780. },
  26781. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  26782. var bindings = action._propertyBindings;
  26783. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26784. var binding = bindings[i];
  26785. if (--binding.referenceCount === 0) {
  26786. this._removeInactiveBinding(binding);
  26787. }
  26788. }
  26789. },
  26790. _lendAction: function _lendAction(action) {
  26791. // [ active actions | inactive actions ]
  26792. // [ active actions >| inactive actions ]
  26793. // s a
  26794. // <-swap->
  26795. // a s
  26796. var actions = this._actions,
  26797. prevIndex = action._cacheIndex,
  26798. lastActiveIndex = this._nActiveActions++,
  26799. firstInactiveAction = actions[lastActiveIndex];
  26800. action._cacheIndex = lastActiveIndex;
  26801. actions[lastActiveIndex] = action;
  26802. firstInactiveAction._cacheIndex = prevIndex;
  26803. actions[prevIndex] = firstInactiveAction;
  26804. },
  26805. _takeBackAction: function _takeBackAction(action) {
  26806. // [ active actions | inactive actions ]
  26807. // [ active actions |< inactive actions ]
  26808. // a s
  26809. // <-swap->
  26810. // s a
  26811. var actions = this._actions,
  26812. prevIndex = action._cacheIndex,
  26813. firstInactiveIndex = --this._nActiveActions,
  26814. lastActiveAction = actions[firstInactiveIndex];
  26815. action._cacheIndex = firstInactiveIndex;
  26816. actions[firstInactiveIndex] = action;
  26817. lastActiveAction._cacheIndex = prevIndex;
  26818. actions[prevIndex] = lastActiveAction;
  26819. },
  26820. // Memory management for PropertyMixer objects
  26821. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  26822. var bindingsByRoot = this._bindingsByRootAndName,
  26823. bindings = this._bindings;
  26824. var bindingByName = bindingsByRoot[rootUuid];
  26825. if (bindingByName === undefined) {
  26826. bindingByName = {};
  26827. bindingsByRoot[rootUuid] = bindingByName;
  26828. }
  26829. bindingByName[trackName] = binding;
  26830. binding._cacheIndex = bindings.length;
  26831. bindings.push(binding);
  26832. },
  26833. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  26834. var bindings = this._bindings,
  26835. propBinding = binding.binding,
  26836. rootUuid = propBinding.rootNode.uuid,
  26837. trackName = propBinding.path,
  26838. bindingsByRoot = this._bindingsByRootAndName,
  26839. bindingByName = bindingsByRoot[rootUuid],
  26840. lastInactiveBinding = bindings[bindings.length - 1],
  26841. cacheIndex = binding._cacheIndex;
  26842. lastInactiveBinding._cacheIndex = cacheIndex;
  26843. bindings[cacheIndex] = lastInactiveBinding;
  26844. bindings.pop();
  26845. delete bindingByName[trackName];
  26846. if (Object.keys(bindingByName).length === 0) {
  26847. delete bindingsByRoot[rootUuid];
  26848. }
  26849. },
  26850. _lendBinding: function _lendBinding(binding) {
  26851. var bindings = this._bindings,
  26852. prevIndex = binding._cacheIndex,
  26853. lastActiveIndex = this._nActiveBindings++,
  26854. firstInactiveBinding = bindings[lastActiveIndex];
  26855. binding._cacheIndex = lastActiveIndex;
  26856. bindings[lastActiveIndex] = binding;
  26857. firstInactiveBinding._cacheIndex = prevIndex;
  26858. bindings[prevIndex] = firstInactiveBinding;
  26859. },
  26860. _takeBackBinding: function _takeBackBinding(binding) {
  26861. var bindings = this._bindings,
  26862. prevIndex = binding._cacheIndex,
  26863. firstInactiveIndex = --this._nActiveBindings,
  26864. lastActiveBinding = bindings[firstInactiveIndex];
  26865. binding._cacheIndex = firstInactiveIndex;
  26866. bindings[firstInactiveIndex] = binding;
  26867. lastActiveBinding._cacheIndex = prevIndex;
  26868. bindings[prevIndex] = lastActiveBinding;
  26869. },
  26870. // Memory management of Interpolants for weight and time scale
  26871. _lendControlInterpolant: function _lendControlInterpolant() {
  26872. var interpolants = this._controlInterpolants,
  26873. lastActiveIndex = this._nActiveControlInterpolants++;
  26874. var interpolant = interpolants[lastActiveIndex];
  26875. if (interpolant === undefined) {
  26876. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  26877. interpolant.__cacheIndex = lastActiveIndex;
  26878. interpolants[lastActiveIndex] = interpolant;
  26879. }
  26880. return interpolant;
  26881. },
  26882. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  26883. var interpolants = this._controlInterpolants,
  26884. prevIndex = interpolant.__cacheIndex,
  26885. firstInactiveIndex = --this._nActiveControlInterpolants,
  26886. lastActiveInterpolant = interpolants[firstInactiveIndex];
  26887. interpolant.__cacheIndex = firstInactiveIndex;
  26888. interpolants[firstInactiveIndex] = interpolant;
  26889. lastActiveInterpolant.__cacheIndex = prevIndex;
  26890. interpolants[prevIndex] = lastActiveInterpolant;
  26891. },
  26892. _controlInterpolantsResultBuffer: new Float32Array(1),
  26893. // return an action for a clip optionally using a custom root target
  26894. // object (this method allocates a lot of dynamic memory in case a
  26895. // previously unknown clip/root combination is specified)
  26896. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  26897. var root = optionalRoot || this._root,
  26898. rootUuid = root.uuid;
  26899. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  26900. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  26901. var actionsForClip = this._actionsByClip[clipUuid];
  26902. var prototypeAction = null;
  26903. if (blendMode === undefined) {
  26904. if (clipObject !== null) {
  26905. blendMode = clipObject.blendMode;
  26906. } else {
  26907. blendMode = NormalAnimationBlendMode;
  26908. }
  26909. }
  26910. if (actionsForClip !== undefined) {
  26911. var existingAction = actionsForClip.actionByRoot[rootUuid];
  26912. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  26913. return existingAction;
  26914. } // we know the clip, so we don't have to parse all
  26915. // the bindings again but can just copy
  26916. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  26917. if (clipObject === null) clipObject = prototypeAction._clip;
  26918. } // clip must be known when specified via string
  26919. if (clipObject === null) return null; // allocate all resources required to run it
  26920. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  26921. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  26922. this._addInactiveAction(newAction, clipUuid, rootUuid);
  26923. return newAction;
  26924. },
  26925. // get an existing action
  26926. existingAction: function existingAction(clip, optionalRoot) {
  26927. var root = optionalRoot || this._root,
  26928. rootUuid = root.uuid,
  26929. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  26930. clipUuid = clipObject ? clipObject.uuid : clip,
  26931. actionsForClip = this._actionsByClip[clipUuid];
  26932. if (actionsForClip !== undefined) {
  26933. return actionsForClip.actionByRoot[rootUuid] || null;
  26934. }
  26935. return null;
  26936. },
  26937. // deactivates all previously scheduled actions
  26938. stopAllAction: function stopAllAction() {
  26939. var actions = this._actions,
  26940. nActions = this._nActiveActions;
  26941. for (var i = nActions - 1; i >= 0; --i) {
  26942. actions[i].stop();
  26943. }
  26944. return this;
  26945. },
  26946. // advance the time and update apply the animation
  26947. update: function update(deltaTime) {
  26948. deltaTime *= this.timeScale;
  26949. var actions = this._actions,
  26950. nActions = this._nActiveActions,
  26951. time = this.time += deltaTime,
  26952. timeDirection = Math.sign(deltaTime),
  26953. accuIndex = this._accuIndex ^= 1; // run active actions
  26954. for (var i = 0; i !== nActions; ++i) {
  26955. var action = actions[i];
  26956. action._update(time, deltaTime, timeDirection, accuIndex);
  26957. } // update scene graph
  26958. var bindings = this._bindings,
  26959. nBindings = this._nActiveBindings;
  26960. for (var _i = 0; _i !== nBindings; ++_i) {
  26961. bindings[_i].apply(accuIndex);
  26962. }
  26963. return this;
  26964. },
  26965. // Allows you to seek to a specific time in an animation.
  26966. setTime: function setTime(timeInSeconds) {
  26967. this.time = 0; // Zero out time attribute for AnimationMixer object;
  26968. for (var i = 0; i < this._actions.length; i++) {
  26969. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  26970. }
  26971. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  26972. },
  26973. // return this mixer's root target object
  26974. getRoot: function getRoot() {
  26975. return this._root;
  26976. },
  26977. // free all resources specific to a particular clip
  26978. uncacheClip: function uncacheClip(clip) {
  26979. var actions = this._actions,
  26980. clipUuid = clip.uuid,
  26981. actionsByClip = this._actionsByClip,
  26982. actionsForClip = actionsByClip[clipUuid];
  26983. if (actionsForClip !== undefined) {
  26984. // note: just calling _removeInactiveAction would mess up the
  26985. // iteration state and also require updating the state we can
  26986. // just throw away
  26987. var actionsToRemove = actionsForClip.knownActions;
  26988. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  26989. var action = actionsToRemove[i];
  26990. this._deactivateAction(action);
  26991. var cacheIndex = action._cacheIndex,
  26992. lastInactiveAction = actions[actions.length - 1];
  26993. action._cacheIndex = null;
  26994. action._byClipCacheIndex = null;
  26995. lastInactiveAction._cacheIndex = cacheIndex;
  26996. actions[cacheIndex] = lastInactiveAction;
  26997. actions.pop();
  26998. this._removeInactiveBindingsForAction(action);
  26999. }
  27000. delete actionsByClip[clipUuid];
  27001. }
  27002. },
  27003. // free all resources specific to a particular root target object
  27004. uncacheRoot: function uncacheRoot(root) {
  27005. var rootUuid = root.uuid,
  27006. actionsByClip = this._actionsByClip;
  27007. for (var clipUuid in actionsByClip) {
  27008. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27009. action = actionByRoot[rootUuid];
  27010. if (action !== undefined) {
  27011. this._deactivateAction(action);
  27012. this._removeInactiveAction(action);
  27013. }
  27014. }
  27015. var bindingsByRoot = this._bindingsByRootAndName,
  27016. bindingByName = bindingsByRoot[rootUuid];
  27017. if (bindingByName !== undefined) {
  27018. for (var trackName in bindingByName) {
  27019. var binding = bindingByName[trackName];
  27020. binding.restoreOriginalState();
  27021. this._removeInactiveBinding(binding);
  27022. }
  27023. }
  27024. },
  27025. // remove a targeted clip from the cache
  27026. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27027. var action = this.existingAction(clip, optionalRoot);
  27028. if (action !== null) {
  27029. this._deactivateAction(action);
  27030. this._removeInactiveAction(action);
  27031. }
  27032. }
  27033. });
  27034. var Uniform = /*#__PURE__*/function () {
  27035. function Uniform(value) {
  27036. if (typeof value === 'string') {
  27037. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27038. value = arguments[1];
  27039. }
  27040. this.value = value;
  27041. }
  27042. var _proto = Uniform.prototype;
  27043. _proto.clone = function clone() {
  27044. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27045. };
  27046. return Uniform;
  27047. }();
  27048. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27049. InterleavedBuffer.call(this, array, stride);
  27050. this.meshPerAttribute = meshPerAttribute || 1;
  27051. }
  27052. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27053. constructor: InstancedInterleavedBuffer,
  27054. isInstancedInterleavedBuffer: true,
  27055. copy: function copy(source) {
  27056. InterleavedBuffer.prototype.copy.call(this, source);
  27057. this.meshPerAttribute = source.meshPerAttribute;
  27058. return this;
  27059. },
  27060. clone: function clone(data) {
  27061. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27062. ib.meshPerAttribute = this.meshPerAttribute;
  27063. return ib;
  27064. },
  27065. toJSON: function toJSON(data) {
  27066. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27067. json.isInstancedInterleavedBuffer = true;
  27068. json.meshPerAttribute = this.meshPerAttribute;
  27069. return json;
  27070. }
  27071. });
  27072. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27073. this.buffer = buffer;
  27074. this.type = type;
  27075. this.itemSize = itemSize;
  27076. this.elementSize = elementSize;
  27077. this.count = count;
  27078. this.version = 0;
  27079. }
  27080. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27081. set: function set(value) {
  27082. if (value === true) this.version++;
  27083. }
  27084. });
  27085. Object.assign(GLBufferAttribute.prototype, {
  27086. isGLBufferAttribute: true,
  27087. setBuffer: function setBuffer(buffer) {
  27088. this.buffer = buffer;
  27089. return this;
  27090. },
  27091. setType: function setType(type, elementSize) {
  27092. this.type = type;
  27093. this.elementSize = elementSize;
  27094. return this;
  27095. },
  27096. setItemSize: function setItemSize(itemSize) {
  27097. this.itemSize = itemSize;
  27098. return this;
  27099. },
  27100. setCount: function setCount(count) {
  27101. this.count = count;
  27102. return this;
  27103. }
  27104. });
  27105. function Raycaster(origin, direction, near, far) {
  27106. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27107. this.near = near || 0;
  27108. this.far = far || Infinity;
  27109. this.camera = null;
  27110. this.layers = new Layers();
  27111. this.params = {
  27112. Mesh: {},
  27113. Line: {
  27114. threshold: 1
  27115. },
  27116. LOD: {},
  27117. Points: {
  27118. threshold: 1
  27119. },
  27120. Sprite: {}
  27121. };
  27122. Object.defineProperties(this.params, {
  27123. PointCloud: {
  27124. get: function get() {
  27125. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27126. return this.Points;
  27127. }
  27128. }
  27129. });
  27130. }
  27131. function ascSort(a, b) {
  27132. return a.distance - b.distance;
  27133. }
  27134. function _intersectObject(object, raycaster, intersects, recursive) {
  27135. if (object.layers.test(raycaster.layers)) {
  27136. object.raycast(raycaster, intersects);
  27137. }
  27138. if (recursive === true) {
  27139. var children = object.children;
  27140. for (var i = 0, l = children.length; i < l; i++) {
  27141. _intersectObject(children[i], raycaster, intersects, true);
  27142. }
  27143. }
  27144. }
  27145. Object.assign(Raycaster.prototype, {
  27146. set: function set(origin, direction) {
  27147. // direction is assumed to be normalized (for accurate distance calculations)
  27148. this.ray.set(origin, direction);
  27149. },
  27150. setFromCamera: function setFromCamera(coords, camera) {
  27151. if (camera && camera.isPerspectiveCamera) {
  27152. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27153. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27154. this.camera = camera;
  27155. } else if (camera && camera.isOrthographicCamera) {
  27156. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27157. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27158. this.camera = camera;
  27159. } else {
  27160. console.error('THREE.Raycaster: Unsupported camera type.');
  27161. }
  27162. },
  27163. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27164. var intersects = optionalTarget || [];
  27165. _intersectObject(object, this, intersects, recursive);
  27166. intersects.sort(ascSort);
  27167. return intersects;
  27168. },
  27169. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27170. var intersects = optionalTarget || [];
  27171. if (Array.isArray(objects) === false) {
  27172. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27173. return intersects;
  27174. }
  27175. for (var i = 0, l = objects.length; i < l; i++) {
  27176. _intersectObject(objects[i], this, intersects, recursive);
  27177. }
  27178. intersects.sort(ascSort);
  27179. return intersects;
  27180. }
  27181. });
  27182. /**
  27183. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27184. *
  27185. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27186. * The azimuthal angle (theta) is measured from the positive z-axis.
  27187. */
  27188. var Spherical = /*#__PURE__*/function () {
  27189. function Spherical(radius, phi, theta) {
  27190. if (radius === void 0) {
  27191. radius = 1;
  27192. }
  27193. if (phi === void 0) {
  27194. phi = 0;
  27195. }
  27196. if (theta === void 0) {
  27197. theta = 0;
  27198. }
  27199. this.radius = radius;
  27200. this.phi = phi; // polar angle
  27201. this.theta = theta; // azimuthal angle
  27202. return this;
  27203. }
  27204. var _proto = Spherical.prototype;
  27205. _proto.set = function set(radius, phi, theta) {
  27206. this.radius = radius;
  27207. this.phi = phi;
  27208. this.theta = theta;
  27209. return this;
  27210. };
  27211. _proto.clone = function clone() {
  27212. return new this.constructor().copy(this);
  27213. };
  27214. _proto.copy = function copy(other) {
  27215. this.radius = other.radius;
  27216. this.phi = other.phi;
  27217. this.theta = other.theta;
  27218. return this;
  27219. } // restrict phi to be betwee EPS and PI-EPS
  27220. ;
  27221. _proto.makeSafe = function makeSafe() {
  27222. var EPS = 0.000001;
  27223. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27224. return this;
  27225. };
  27226. _proto.setFromVector3 = function setFromVector3(v) {
  27227. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27228. };
  27229. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27230. this.radius = Math.sqrt(x * x + y * y + z * z);
  27231. if (this.radius === 0) {
  27232. this.theta = 0;
  27233. this.phi = 0;
  27234. } else {
  27235. this.theta = Math.atan2(x, z);
  27236. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27237. }
  27238. return this;
  27239. };
  27240. return Spherical;
  27241. }();
  27242. /**
  27243. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27244. */
  27245. var Cylindrical = /*#__PURE__*/function () {
  27246. function Cylindrical(radius, theta, y) {
  27247. this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27248. this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27249. this.y = y !== undefined ? y : 0; // height above the x-z plane
  27250. return this;
  27251. }
  27252. var _proto = Cylindrical.prototype;
  27253. _proto.set = function set(radius, theta, y) {
  27254. this.radius = radius;
  27255. this.theta = theta;
  27256. this.y = y;
  27257. return this;
  27258. };
  27259. _proto.clone = function clone() {
  27260. return new this.constructor().copy(this);
  27261. };
  27262. _proto.copy = function copy(other) {
  27263. this.radius = other.radius;
  27264. this.theta = other.theta;
  27265. this.y = other.y;
  27266. return this;
  27267. };
  27268. _proto.setFromVector3 = function setFromVector3(v) {
  27269. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27270. };
  27271. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27272. this.radius = Math.sqrt(x * x + z * z);
  27273. this.theta = Math.atan2(x, z);
  27274. this.y = y;
  27275. return this;
  27276. };
  27277. return Cylindrical;
  27278. }();
  27279. var _vector$7 = /*@__PURE__*/new Vector2();
  27280. var Box2 = /*#__PURE__*/function () {
  27281. function Box2(min, max) {
  27282. Object.defineProperty(this, 'isBox2', {
  27283. value: true
  27284. });
  27285. this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
  27286. this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
  27287. }
  27288. var _proto = Box2.prototype;
  27289. _proto.set = function set(min, max) {
  27290. this.min.copy(min);
  27291. this.max.copy(max);
  27292. return this;
  27293. };
  27294. _proto.setFromPoints = function setFromPoints(points) {
  27295. this.makeEmpty();
  27296. for (var i = 0, il = points.length; i < il; i++) {
  27297. this.expandByPoint(points[i]);
  27298. }
  27299. return this;
  27300. };
  27301. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  27302. var halfSize = _vector$7.copy(size).multiplyScalar(0.5);
  27303. this.min.copy(center).sub(halfSize);
  27304. this.max.copy(center).add(halfSize);
  27305. return this;
  27306. };
  27307. _proto.clone = function clone() {
  27308. return new this.constructor().copy(this);
  27309. };
  27310. _proto.copy = function copy(box) {
  27311. this.min.copy(box.min);
  27312. this.max.copy(box.max);
  27313. return this;
  27314. };
  27315. _proto.makeEmpty = function makeEmpty() {
  27316. this.min.x = this.min.y = +Infinity;
  27317. this.max.x = this.max.y = -Infinity;
  27318. return this;
  27319. };
  27320. _proto.isEmpty = function isEmpty() {
  27321. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27322. return this.max.x < this.min.x || this.max.y < this.min.y;
  27323. };
  27324. _proto.getCenter = function getCenter(target) {
  27325. if (target === undefined) {
  27326. console.warn('THREE.Box2: .getCenter() target is now required');
  27327. target = new Vector2();
  27328. }
  27329. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  27330. };
  27331. _proto.getSize = function getSize(target) {
  27332. if (target === undefined) {
  27333. console.warn('THREE.Box2: .getSize() target is now required');
  27334. target = new Vector2();
  27335. }
  27336. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  27337. };
  27338. _proto.expandByPoint = function expandByPoint(point) {
  27339. this.min.min(point);
  27340. this.max.max(point);
  27341. return this;
  27342. };
  27343. _proto.expandByVector = function expandByVector(vector) {
  27344. this.min.sub(vector);
  27345. this.max.add(vector);
  27346. return this;
  27347. };
  27348. _proto.expandByScalar = function expandByScalar(scalar) {
  27349. this.min.addScalar(-scalar);
  27350. this.max.addScalar(scalar);
  27351. return this;
  27352. };
  27353. _proto.containsPoint = function containsPoint(point) {
  27354. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  27355. };
  27356. _proto.containsBox = function containsBox(box) {
  27357. 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;
  27358. };
  27359. _proto.getParameter = function getParameter(point, target) {
  27360. // This can potentially have a divide by zero if the box
  27361. // has a size dimension of 0.
  27362. if (target === undefined) {
  27363. console.warn('THREE.Box2: .getParameter() target is now required');
  27364. target = new Vector2();
  27365. }
  27366. 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));
  27367. };
  27368. _proto.intersectsBox = function intersectsBox(box) {
  27369. // using 4 splitting planes to rule out intersections
  27370. 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;
  27371. };
  27372. _proto.clampPoint = function clampPoint(point, target) {
  27373. if (target === undefined) {
  27374. console.warn('THREE.Box2: .clampPoint() target is now required');
  27375. target = new Vector2();
  27376. }
  27377. return target.copy(point).clamp(this.min, this.max);
  27378. };
  27379. _proto.distanceToPoint = function distanceToPoint(point) {
  27380. var clampedPoint = _vector$7.copy(point).clamp(this.min, this.max);
  27381. return clampedPoint.sub(point).length();
  27382. };
  27383. _proto.intersect = function intersect(box) {
  27384. this.min.max(box.min);
  27385. this.max.min(box.max);
  27386. return this;
  27387. };
  27388. _proto.union = function union(box) {
  27389. this.min.min(box.min);
  27390. this.max.max(box.max);
  27391. return this;
  27392. };
  27393. _proto.translate = function translate(offset) {
  27394. this.min.add(offset);
  27395. this.max.add(offset);
  27396. return this;
  27397. };
  27398. _proto.equals = function equals(box) {
  27399. return box.min.equals(this.min) && box.max.equals(this.max);
  27400. };
  27401. return Box2;
  27402. }();
  27403. var _startP = /*@__PURE__*/new Vector3();
  27404. var _startEnd = /*@__PURE__*/new Vector3();
  27405. var Line3 = /*#__PURE__*/function () {
  27406. function Line3(start, end) {
  27407. this.start = start !== undefined ? start : new Vector3();
  27408. this.end = end !== undefined ? end : new Vector3();
  27409. }
  27410. var _proto = Line3.prototype;
  27411. _proto.set = function set(start, end) {
  27412. this.start.copy(start);
  27413. this.end.copy(end);
  27414. return this;
  27415. };
  27416. _proto.clone = function clone() {
  27417. return new this.constructor().copy(this);
  27418. };
  27419. _proto.copy = function copy(line) {
  27420. this.start.copy(line.start);
  27421. this.end.copy(line.end);
  27422. return this;
  27423. };
  27424. _proto.getCenter = function getCenter(target) {
  27425. if (target === undefined) {
  27426. console.warn('THREE.Line3: .getCenter() target is now required');
  27427. target = new Vector3();
  27428. }
  27429. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  27430. };
  27431. _proto.delta = function delta(target) {
  27432. if (target === undefined) {
  27433. console.warn('THREE.Line3: .delta() target is now required');
  27434. target = new Vector3();
  27435. }
  27436. return target.subVectors(this.end, this.start);
  27437. };
  27438. _proto.distanceSq = function distanceSq() {
  27439. return this.start.distanceToSquared(this.end);
  27440. };
  27441. _proto.distance = function distance() {
  27442. return this.start.distanceTo(this.end);
  27443. };
  27444. _proto.at = function at(t, target) {
  27445. if (target === undefined) {
  27446. console.warn('THREE.Line3: .at() target is now required');
  27447. target = new Vector3();
  27448. }
  27449. return this.delta(target).multiplyScalar(t).add(this.start);
  27450. };
  27451. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  27452. _startP.subVectors(point, this.start);
  27453. _startEnd.subVectors(this.end, this.start);
  27454. var startEnd2 = _startEnd.dot(_startEnd);
  27455. var startEnd_startP = _startEnd.dot(_startP);
  27456. var t = startEnd_startP / startEnd2;
  27457. if (clampToLine) {
  27458. t = MathUtils.clamp(t, 0, 1);
  27459. }
  27460. return t;
  27461. };
  27462. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  27463. var t = this.closestPointToPointParameter(point, clampToLine);
  27464. if (target === undefined) {
  27465. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  27466. target = new Vector3();
  27467. }
  27468. return this.delta(target).multiplyScalar(t).add(this.start);
  27469. };
  27470. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  27471. this.start.applyMatrix4(matrix);
  27472. this.end.applyMatrix4(matrix);
  27473. return this;
  27474. };
  27475. _proto.equals = function equals(line) {
  27476. return line.start.equals(this.start) && line.end.equals(this.end);
  27477. };
  27478. return Line3;
  27479. }();
  27480. function ImmediateRenderObject(material) {
  27481. Object3D.call(this);
  27482. this.material = material;
  27483. this.render = function ()
  27484. /* renderCallback */
  27485. {};
  27486. this.hasPositions = false;
  27487. this.hasNormals = false;
  27488. this.hasColors = false;
  27489. this.hasUvs = false;
  27490. this.positionArray = null;
  27491. this.normalArray = null;
  27492. this.colorArray = null;
  27493. this.uvArray = null;
  27494. this.count = 0;
  27495. }
  27496. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  27497. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27498. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27499. var _vector$8 = /*@__PURE__*/new Vector3();
  27500. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  27501. _inheritsLoose(SpotLightHelper, _Object3D);
  27502. function SpotLightHelper(light, color) {
  27503. var _this;
  27504. _this = _Object3D.call(this) || this;
  27505. _this.light = light;
  27506. _this.light.updateMatrixWorld();
  27507. _this.matrix = light.matrixWorld;
  27508. _this.matrixAutoUpdate = false;
  27509. _this.color = color;
  27510. var geometry = new BufferGeometry();
  27511. 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];
  27512. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  27513. var p1 = i / l * Math.PI * 2;
  27514. var p2 = j / l * Math.PI * 2;
  27515. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  27516. }
  27517. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  27518. var material = new LineBasicMaterial({
  27519. fog: false,
  27520. toneMapped: false
  27521. });
  27522. _this.cone = new LineSegments(geometry, material);
  27523. _this.add(_this.cone);
  27524. _this.update();
  27525. return _this;
  27526. }
  27527. var _proto = SpotLightHelper.prototype;
  27528. _proto.dispose = function dispose() {
  27529. this.cone.geometry.dispose();
  27530. this.cone.material.dispose();
  27531. };
  27532. _proto.update = function update() {
  27533. this.light.updateMatrixWorld();
  27534. var coneLength = this.light.distance ? this.light.distance : 1000;
  27535. var coneWidth = coneLength * Math.tan(this.light.angle);
  27536. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  27537. _vector$8.setFromMatrixPosition(this.light.target.matrixWorld);
  27538. this.cone.lookAt(_vector$8);
  27539. if (this.color !== undefined) {
  27540. this.cone.material.color.set(this.color);
  27541. } else {
  27542. this.cone.material.color.copy(this.light.color);
  27543. }
  27544. };
  27545. return SpotLightHelper;
  27546. }(Object3D);
  27547. var _vector$9 = /*@__PURE__*/new Vector3();
  27548. var _boneMatrix = /*@__PURE__*/new Matrix4();
  27549. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  27550. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  27551. _inheritsLoose(SkeletonHelper, _LineSegments);
  27552. function SkeletonHelper(object) {
  27553. var _this;
  27554. var bones = getBoneList(object);
  27555. var geometry = new BufferGeometry();
  27556. var vertices = [];
  27557. var colors = [];
  27558. var color1 = new Color(0, 0, 1);
  27559. var color2 = new Color(0, 1, 0);
  27560. for (var i = 0; i < bones.length; i++) {
  27561. var bone = bones[i];
  27562. if (bone.parent && bone.parent.isBone) {
  27563. vertices.push(0, 0, 0);
  27564. vertices.push(0, 0, 0);
  27565. colors.push(color1.r, color1.g, color1.b);
  27566. colors.push(color2.r, color2.g, color2.b);
  27567. }
  27568. }
  27569. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27570. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27571. var material = new LineBasicMaterial({
  27572. vertexColors: true,
  27573. depthTest: false,
  27574. depthWrite: false,
  27575. toneMapped: false,
  27576. transparent: true
  27577. });
  27578. _this = _LineSegments.call(this, geometry, material) || this;
  27579. _this.type = 'SkeletonHelper';
  27580. _this.isSkeletonHelper = true;
  27581. _this.root = object;
  27582. _this.bones = bones;
  27583. _this.matrix = object.matrixWorld;
  27584. _this.matrixAutoUpdate = false;
  27585. return _this;
  27586. }
  27587. var _proto = SkeletonHelper.prototype;
  27588. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  27589. var bones = this.bones;
  27590. var geometry = this.geometry;
  27591. var position = geometry.getAttribute('position');
  27592. _matrixWorldInv.getInverse(this.root.matrixWorld);
  27593. for (var i = 0, j = 0; i < bones.length; i++) {
  27594. var bone = bones[i];
  27595. if (bone.parent && bone.parent.isBone) {
  27596. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  27597. _vector$9.setFromMatrixPosition(_boneMatrix);
  27598. position.setXYZ(j, _vector$9.x, _vector$9.y, _vector$9.z);
  27599. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  27600. _vector$9.setFromMatrixPosition(_boneMatrix);
  27601. position.setXYZ(j + 1, _vector$9.x, _vector$9.y, _vector$9.z);
  27602. j += 2;
  27603. }
  27604. }
  27605. geometry.getAttribute('position').needsUpdate = true;
  27606. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  27607. };
  27608. return SkeletonHelper;
  27609. }(LineSegments);
  27610. function getBoneList(object) {
  27611. var boneList = [];
  27612. if (object && object.isBone) {
  27613. boneList.push(object);
  27614. }
  27615. for (var i = 0; i < object.children.length; i++) {
  27616. boneList.push.apply(boneList, getBoneList(object.children[i]));
  27617. }
  27618. return boneList;
  27619. }
  27620. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  27621. _inheritsLoose(PointLightHelper, _Mesh);
  27622. function PointLightHelper(light, sphereSize, color) {
  27623. var _this;
  27624. var geometry = new SphereBufferGeometry(sphereSize, 4, 2);
  27625. var material = new MeshBasicMaterial({
  27626. wireframe: true,
  27627. fog: false,
  27628. toneMapped: false
  27629. });
  27630. _this = _Mesh.call(this, geometry, material) || this;
  27631. _this.light = light;
  27632. _this.light.updateMatrixWorld();
  27633. _this.color = color;
  27634. _this.type = 'PointLightHelper';
  27635. _this.matrix = _this.light.matrixWorld;
  27636. _this.matrixAutoUpdate = false;
  27637. _this.update();
  27638. /*
  27639. // TODO: delete this comment?
  27640. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27641. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27642. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27643. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27644. const d = light.distance;
  27645. if ( d === 0.0 ) {
  27646. this.lightDistance.visible = false;
  27647. } else {
  27648. this.lightDistance.scale.set( d, d, d );
  27649. }
  27650. this.add( this.lightDistance );
  27651. */
  27652. return _this;
  27653. }
  27654. var _proto = PointLightHelper.prototype;
  27655. _proto.dispose = function dispose() {
  27656. this.geometry.dispose();
  27657. this.material.dispose();
  27658. };
  27659. _proto.update = function update() {
  27660. if (this.color !== undefined) {
  27661. this.material.color.set(this.color);
  27662. } else {
  27663. this.material.color.copy(this.light.color);
  27664. }
  27665. /*
  27666. const d = this.light.distance;
  27667. if ( d === 0.0 ) {
  27668. this.lightDistance.visible = false;
  27669. } else {
  27670. this.lightDistance.visible = true;
  27671. this.lightDistance.scale.set( d, d, d );
  27672. }
  27673. */
  27674. };
  27675. return PointLightHelper;
  27676. }(Mesh);
  27677. var _vector$a = /*@__PURE__*/new Vector3();
  27678. var _color1 = /*@__PURE__*/new Color();
  27679. var _color2 = /*@__PURE__*/new Color();
  27680. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  27681. _inheritsLoose(HemisphereLightHelper, _Object3D);
  27682. function HemisphereLightHelper(light, size, color) {
  27683. var _this;
  27684. _this = _Object3D.call(this) || this;
  27685. _this.light = light;
  27686. _this.light.updateMatrixWorld();
  27687. _this.matrix = light.matrixWorld;
  27688. _this.matrixAutoUpdate = false;
  27689. _this.color = color;
  27690. var geometry = new OctahedronBufferGeometry(size);
  27691. geometry.rotateY(Math.PI * 0.5);
  27692. _this.material = new MeshBasicMaterial({
  27693. wireframe: true,
  27694. fog: false,
  27695. toneMapped: false
  27696. });
  27697. if (_this.color === undefined) _this.material.vertexColors = true;
  27698. var position = geometry.getAttribute('position');
  27699. var colors = new Float32Array(position.count * 3);
  27700. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  27701. _this.add(new Mesh(geometry, _this.material));
  27702. _this.update();
  27703. return _this;
  27704. }
  27705. var _proto = HemisphereLightHelper.prototype;
  27706. _proto.dispose = function dispose() {
  27707. this.children[0].geometry.dispose();
  27708. this.children[0].material.dispose();
  27709. };
  27710. _proto.update = function update() {
  27711. var mesh = this.children[0];
  27712. if (this.color !== undefined) {
  27713. this.material.color.set(this.color);
  27714. } else {
  27715. var colors = mesh.geometry.getAttribute('color');
  27716. _color1.copy(this.light.color);
  27717. _color2.copy(this.light.groundColor);
  27718. for (var i = 0, l = colors.count; i < l; i++) {
  27719. var color = i < l / 2 ? _color1 : _color2;
  27720. colors.setXYZ(i, color.r, color.g, color.b);
  27721. }
  27722. colors.needsUpdate = true;
  27723. }
  27724. mesh.lookAt(_vector$a.setFromMatrixPosition(this.light.matrixWorld).negate());
  27725. };
  27726. return HemisphereLightHelper;
  27727. }(Object3D);
  27728. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  27729. _inheritsLoose(GridHelper, _LineSegments);
  27730. function GridHelper(size, divisions, color1, color2) {
  27731. var _this;
  27732. size = size || 10;
  27733. divisions = divisions || 10;
  27734. color1 = new Color(color1 !== undefined ? color1 : 0x444444);
  27735. color2 = new Color(color2 !== undefined ? color2 : 0x888888);
  27736. var center = divisions / 2;
  27737. var step = size / divisions;
  27738. var halfSize = size / 2;
  27739. var vertices = [],
  27740. colors = [];
  27741. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  27742. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  27743. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  27744. var color = i === center ? color1 : color2;
  27745. color.toArray(colors, j);
  27746. j += 3;
  27747. color.toArray(colors, j);
  27748. j += 3;
  27749. color.toArray(colors, j);
  27750. j += 3;
  27751. color.toArray(colors, j);
  27752. j += 3;
  27753. }
  27754. var geometry = new BufferGeometry();
  27755. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27756. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27757. var material = new LineBasicMaterial({
  27758. vertexColors: true,
  27759. toneMapped: false
  27760. });
  27761. _this = _LineSegments.call(this, geometry, material) || this;
  27762. _this.type = 'GridHelper';
  27763. return _this;
  27764. }
  27765. return GridHelper;
  27766. }(LineSegments);
  27767. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  27768. _inheritsLoose(PolarGridHelper, _LineSegments);
  27769. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  27770. var _this;
  27771. radius = radius || 10;
  27772. radials = radials || 16;
  27773. circles = circles || 8;
  27774. divisions = divisions || 64;
  27775. color1 = new Color(color1 !== undefined ? color1 : 0x444444);
  27776. color2 = new Color(color2 !== undefined ? color2 : 0x888888);
  27777. var vertices = [];
  27778. var colors = []; // create the radials
  27779. for (var i = 0; i <= radials; i++) {
  27780. var v = i / radials * (Math.PI * 2);
  27781. var x = Math.sin(v) * radius;
  27782. var z = Math.cos(v) * radius;
  27783. vertices.push(0, 0, 0);
  27784. vertices.push(x, 0, z);
  27785. var color = i & 1 ? color1 : color2;
  27786. colors.push(color.r, color.g, color.b);
  27787. colors.push(color.r, color.g, color.b);
  27788. } // create the circles
  27789. for (var _i = 0; _i <= circles; _i++) {
  27790. var _color = _i & 1 ? color1 : color2;
  27791. var r = radius - radius / circles * _i;
  27792. for (var j = 0; j < divisions; j++) {
  27793. // first vertex
  27794. var _v = j / divisions * (Math.PI * 2);
  27795. var _x = Math.sin(_v) * r;
  27796. var _z = Math.cos(_v) * r;
  27797. vertices.push(_x, 0, _z);
  27798. colors.push(_color.r, _color.g, _color.b); // second vertex
  27799. _v = (j + 1) / divisions * (Math.PI * 2);
  27800. _x = Math.sin(_v) * r;
  27801. _z = Math.cos(_v) * r;
  27802. vertices.push(_x, 0, _z);
  27803. colors.push(_color.r, _color.g, _color.b);
  27804. }
  27805. }
  27806. var geometry = new BufferGeometry();
  27807. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27808. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27809. var material = new LineBasicMaterial({
  27810. vertexColors: true,
  27811. toneMapped: false
  27812. });
  27813. _this = _LineSegments.call(this, geometry, material) || this;
  27814. _this.type = 'PolarGridHelper';
  27815. return _this;
  27816. }
  27817. return PolarGridHelper;
  27818. }(LineSegments);
  27819. var _v1$6 = /*@__PURE__*/new Vector3();
  27820. var _v2$3 = /*@__PURE__*/new Vector3();
  27821. var _v3$1 = /*@__PURE__*/new Vector3();
  27822. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  27823. _inheritsLoose(DirectionalLightHelper, _Object3D);
  27824. function DirectionalLightHelper(light, size, color) {
  27825. var _this;
  27826. _this = _Object3D.call(this) || this;
  27827. _this.light = light;
  27828. _this.light.updateMatrixWorld();
  27829. _this.matrix = light.matrixWorld;
  27830. _this.matrixAutoUpdate = false;
  27831. _this.color = color;
  27832. if (size === undefined) size = 1;
  27833. var geometry = new BufferGeometry();
  27834. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  27835. var material = new LineBasicMaterial({
  27836. fog: false,
  27837. toneMapped: false
  27838. });
  27839. _this.lightPlane = new Line(geometry, material);
  27840. _this.add(_this.lightPlane);
  27841. geometry = new BufferGeometry();
  27842. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  27843. _this.targetLine = new Line(geometry, material);
  27844. _this.add(_this.targetLine);
  27845. _this.update();
  27846. return _this;
  27847. }
  27848. var _proto = DirectionalLightHelper.prototype;
  27849. _proto.dispose = function dispose() {
  27850. this.lightPlane.geometry.dispose();
  27851. this.lightPlane.material.dispose();
  27852. this.targetLine.geometry.dispose();
  27853. this.targetLine.material.dispose();
  27854. };
  27855. _proto.update = function update() {
  27856. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  27857. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  27858. _v3$1.subVectors(_v2$3, _v1$6);
  27859. this.lightPlane.lookAt(_v2$3);
  27860. if (this.color !== undefined) {
  27861. this.lightPlane.material.color.set(this.color);
  27862. this.targetLine.material.color.set(this.color);
  27863. } else {
  27864. this.lightPlane.material.color.copy(this.light.color);
  27865. this.targetLine.material.color.copy(this.light.color);
  27866. }
  27867. this.targetLine.lookAt(_v2$3);
  27868. this.targetLine.scale.z = _v3$1.length();
  27869. };
  27870. return DirectionalLightHelper;
  27871. }(Object3D);
  27872. var _vector$b = /*@__PURE__*/new Vector3();
  27873. var _camera = /*@__PURE__*/new Camera();
  27874. /**
  27875. * - shows frustum, line of sight and up of the camera
  27876. * - suitable for fast updates
  27877. * - based on frustum visualization in lightgl.js shadowmap example
  27878. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  27879. */
  27880. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  27881. _inheritsLoose(CameraHelper, _LineSegments);
  27882. function CameraHelper(camera) {
  27883. var _this;
  27884. var geometry = new BufferGeometry();
  27885. var material = new LineBasicMaterial({
  27886. color: 0xffffff,
  27887. vertexColors: true,
  27888. toneMapped: false
  27889. });
  27890. var vertices = [];
  27891. var colors = [];
  27892. var pointMap = {}; // colors
  27893. var colorFrustum = new Color(0xffaa00);
  27894. var colorCone = new Color(0xff0000);
  27895. var colorUp = new Color(0x00aaff);
  27896. var colorTarget = new Color(0xffffff);
  27897. var colorCross = new Color(0x333333); // near
  27898. addLine('n1', 'n2', colorFrustum);
  27899. addLine('n2', 'n4', colorFrustum);
  27900. addLine('n4', 'n3', colorFrustum);
  27901. addLine('n3', 'n1', colorFrustum); // far
  27902. addLine('f1', 'f2', colorFrustum);
  27903. addLine('f2', 'f4', colorFrustum);
  27904. addLine('f4', 'f3', colorFrustum);
  27905. addLine('f3', 'f1', colorFrustum); // sides
  27906. addLine('n1', 'f1', colorFrustum);
  27907. addLine('n2', 'f2', colorFrustum);
  27908. addLine('n3', 'f3', colorFrustum);
  27909. addLine('n4', 'f4', colorFrustum); // cone
  27910. addLine('p', 'n1', colorCone);
  27911. addLine('p', 'n2', colorCone);
  27912. addLine('p', 'n3', colorCone);
  27913. addLine('p', 'n4', colorCone); // up
  27914. addLine('u1', 'u2', colorUp);
  27915. addLine('u2', 'u3', colorUp);
  27916. addLine('u3', 'u1', colorUp); // target
  27917. addLine('c', 't', colorTarget);
  27918. addLine('p', 'c', colorCross); // cross
  27919. addLine('cn1', 'cn2', colorCross);
  27920. addLine('cn3', 'cn4', colorCross);
  27921. addLine('cf1', 'cf2', colorCross);
  27922. addLine('cf3', 'cf4', colorCross);
  27923. function addLine(a, b, color) {
  27924. addPoint(a, color);
  27925. addPoint(b, color);
  27926. }
  27927. function addPoint(id, color) {
  27928. vertices.push(0, 0, 0);
  27929. colors.push(color.r, color.g, color.b);
  27930. if (pointMap[id] === undefined) {
  27931. pointMap[id] = [];
  27932. }
  27933. pointMap[id].push(vertices.length / 3 - 1);
  27934. }
  27935. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27936. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27937. _this = _LineSegments.call(this, geometry, material) || this;
  27938. _this.type = 'CameraHelper';
  27939. _this.camera = camera;
  27940. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  27941. _this.matrix = camera.matrixWorld;
  27942. _this.matrixAutoUpdate = false;
  27943. _this.pointMap = pointMap;
  27944. _this.update();
  27945. return _this;
  27946. }
  27947. var _proto = CameraHelper.prototype;
  27948. _proto.update = function update() {
  27949. var geometry = this.geometry;
  27950. var pointMap = this.pointMap;
  27951. var w = 1,
  27952. h = 1; // we need just camera projection matrix inverse
  27953. // world matrix must be identity
  27954. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  27955. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  27956. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  27957. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  27958. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  27959. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  27960. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  27961. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  27962. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  27963. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  27964. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  27965. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  27966. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  27967. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  27968. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  27969. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  27970. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  27971. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  27972. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  27973. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  27974. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  27975. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  27976. geometry.getAttribute('position').needsUpdate = true;
  27977. };
  27978. return CameraHelper;
  27979. }(LineSegments);
  27980. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  27981. _vector$b.set(x, y, z).unproject(camera);
  27982. var points = pointMap[point];
  27983. if (points !== undefined) {
  27984. var position = geometry.getAttribute('position');
  27985. for (var i = 0, l = points.length; i < l; i++) {
  27986. position.setXYZ(points[i], _vector$b.x, _vector$b.y, _vector$b.z);
  27987. }
  27988. }
  27989. }
  27990. var _box$3 = /*@__PURE__*/new Box3();
  27991. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  27992. _inheritsLoose(BoxHelper, _LineSegments);
  27993. function BoxHelper(object, color) {
  27994. var _this;
  27995. if (color === void 0) {
  27996. color = 0xffff00;
  27997. }
  27998. 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]);
  27999. var positions = new Float32Array(8 * 3);
  28000. var geometry = new BufferGeometry();
  28001. geometry.setIndex(new BufferAttribute(indices, 1));
  28002. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28003. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28004. color: color,
  28005. toneMapped: false
  28006. })) || this;
  28007. _this.object = object;
  28008. _this.type = 'BoxHelper';
  28009. _this.matrixAutoUpdate = false;
  28010. _this.update();
  28011. return _this;
  28012. }
  28013. var _proto = BoxHelper.prototype;
  28014. _proto.update = function update(object) {
  28015. if (object !== undefined) {
  28016. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28017. }
  28018. if (this.object !== undefined) {
  28019. _box$3.setFromObject(this.object);
  28020. }
  28021. if (_box$3.isEmpty()) return;
  28022. var min = _box$3.min;
  28023. var max = _box$3.max;
  28024. /*
  28025. 5____4
  28026. 1/___0/|
  28027. | 6__|_7
  28028. 2/___3/
  28029. 0: max.x, max.y, max.z
  28030. 1: min.x, max.y, max.z
  28031. 2: min.x, min.y, max.z
  28032. 3: max.x, min.y, max.z
  28033. 4: max.x, max.y, min.z
  28034. 5: min.x, max.y, min.z
  28035. 6: min.x, min.y, min.z
  28036. 7: max.x, min.y, min.z
  28037. */
  28038. var position = this.geometry.attributes.position;
  28039. var array = position.array;
  28040. array[0] = max.x;
  28041. array[1] = max.y;
  28042. array[2] = max.z;
  28043. array[3] = min.x;
  28044. array[4] = max.y;
  28045. array[5] = max.z;
  28046. array[6] = min.x;
  28047. array[7] = min.y;
  28048. array[8] = max.z;
  28049. array[9] = max.x;
  28050. array[10] = min.y;
  28051. array[11] = max.z;
  28052. array[12] = max.x;
  28053. array[13] = max.y;
  28054. array[14] = min.z;
  28055. array[15] = min.x;
  28056. array[16] = max.y;
  28057. array[17] = min.z;
  28058. array[18] = min.x;
  28059. array[19] = min.y;
  28060. array[20] = min.z;
  28061. array[21] = max.x;
  28062. array[22] = min.y;
  28063. array[23] = min.z;
  28064. position.needsUpdate = true;
  28065. this.geometry.computeBoundingSphere();
  28066. };
  28067. _proto.setFromObject = function setFromObject(object) {
  28068. this.object = object;
  28069. this.update();
  28070. return this;
  28071. };
  28072. _proto.copy = function copy(source) {
  28073. LineSegments.prototype.copy.call(this, source);
  28074. this.object = source.object;
  28075. return this;
  28076. };
  28077. return BoxHelper;
  28078. }(LineSegments);
  28079. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28080. _inheritsLoose(Box3Helper, _LineSegments);
  28081. function Box3Helper(box, color) {
  28082. var _this;
  28083. if (color === void 0) {
  28084. color = 0xffff00;
  28085. }
  28086. 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]);
  28087. 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];
  28088. var geometry = new BufferGeometry();
  28089. geometry.setIndex(new BufferAttribute(indices, 1));
  28090. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28091. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28092. color: color,
  28093. toneMapped: false
  28094. })) || this;
  28095. _this.box = box;
  28096. _this.type = 'Box3Helper';
  28097. _this.geometry.computeBoundingSphere();
  28098. return _this;
  28099. }
  28100. var _proto = Box3Helper.prototype;
  28101. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28102. var box = this.box;
  28103. if (box.isEmpty()) return;
  28104. box.getCenter(this.position);
  28105. box.getSize(this.scale);
  28106. this.scale.multiplyScalar(0.5);
  28107. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28108. };
  28109. return Box3Helper;
  28110. }(LineSegments);
  28111. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28112. _inheritsLoose(PlaneHelper, _Line);
  28113. function PlaneHelper(plane, size, hex) {
  28114. var _this;
  28115. var color = hex !== undefined ? hex : 0xffff00;
  28116. 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];
  28117. var geometry = new BufferGeometry();
  28118. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28119. geometry.computeBoundingSphere();
  28120. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28121. color: color,
  28122. toneMapped: false
  28123. })) || this;
  28124. _this.type = 'PlaneHelper';
  28125. _this.plane = plane;
  28126. _this.size = size === undefined ? 1 : size;
  28127. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28128. var geometry2 = new BufferGeometry();
  28129. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28130. geometry2.computeBoundingSphere();
  28131. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28132. color: color,
  28133. opacity: 0.2,
  28134. transparent: true,
  28135. depthWrite: false,
  28136. toneMapped: false
  28137. })));
  28138. return _this;
  28139. }
  28140. var _proto = PlaneHelper.prototype;
  28141. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28142. var scale = -this.plane.constant;
  28143. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28144. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28145. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28146. this.lookAt(this.plane.normal);
  28147. _Line.prototype.updateMatrixWorld.call(this, force);
  28148. };
  28149. return PlaneHelper;
  28150. }(Line);
  28151. var _axis = /*@__PURE__*/new Vector3();
  28152. var _lineGeometry, _coneGeometry;
  28153. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28154. _inheritsLoose(ArrowHelper, _Object3D);
  28155. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28156. var _this;
  28157. _this = _Object3D.call(this) || this; // dir is assumed to be normalized
  28158. _this.type = 'ArrowHelper';
  28159. if (dir === undefined) dir = new Vector3(0, 0, 1);
  28160. if (origin === undefined) origin = new Vector3(0, 0, 0);
  28161. if (length === undefined) length = 1;
  28162. if (color === undefined) color = 0xffff00;
  28163. if (headLength === undefined) headLength = 0.2 * length;
  28164. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28165. if (_lineGeometry === undefined) {
  28166. _lineGeometry = new BufferGeometry();
  28167. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28168. _coneGeometry = new CylinderBufferGeometry(0, 0.5, 1, 5, 1);
  28169. _coneGeometry.translate(0, -0.5, 0);
  28170. }
  28171. _this.position.copy(origin);
  28172. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28173. color: color,
  28174. toneMapped: false
  28175. }));
  28176. _this.line.matrixAutoUpdate = false;
  28177. _this.add(_this.line);
  28178. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28179. color: color,
  28180. toneMapped: false
  28181. }));
  28182. _this.cone.matrixAutoUpdate = false;
  28183. _this.add(_this.cone);
  28184. _this.setDirection(dir);
  28185. _this.setLength(length, headLength, headWidth);
  28186. return _this;
  28187. }
  28188. var _proto = ArrowHelper.prototype;
  28189. _proto.setDirection = function setDirection(dir) {
  28190. // dir is assumed to be normalized
  28191. if (dir.y > 0.99999) {
  28192. this.quaternion.set(0, 0, 0, 1);
  28193. } else if (dir.y < -0.99999) {
  28194. this.quaternion.set(1, 0, 0, 0);
  28195. } else {
  28196. _axis.set(dir.z, 0, -dir.x).normalize();
  28197. var radians = Math.acos(dir.y);
  28198. this.quaternion.setFromAxisAngle(_axis, radians);
  28199. }
  28200. };
  28201. _proto.setLength = function setLength(length, headLength, headWidth) {
  28202. if (headLength === undefined) headLength = 0.2 * length;
  28203. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28204. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28205. this.line.updateMatrix();
  28206. this.cone.scale.set(headWidth, headLength, headWidth);
  28207. this.cone.position.y = length;
  28208. this.cone.updateMatrix();
  28209. };
  28210. _proto.setColor = function setColor(color) {
  28211. this.line.material.color.set(color);
  28212. this.cone.material.color.set(color);
  28213. };
  28214. _proto.copy = function copy(source) {
  28215. _Object3D.prototype.copy.call(this, source, false);
  28216. this.line.copy(source.line);
  28217. this.cone.copy(source.cone);
  28218. return this;
  28219. };
  28220. return ArrowHelper;
  28221. }(Object3D);
  28222. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  28223. _inheritsLoose(AxesHelper, _LineSegments);
  28224. function AxesHelper(size) {
  28225. var _this;
  28226. if (size === void 0) {
  28227. size = 1;
  28228. }
  28229. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  28230. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  28231. var geometry = new BufferGeometry();
  28232. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28233. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28234. var material = new LineBasicMaterial({
  28235. vertexColors: true,
  28236. toneMapped: false
  28237. });
  28238. _this = _LineSegments.call(this, geometry, material) || this;
  28239. _this.type = 'AxesHelper';
  28240. return _this;
  28241. }
  28242. return AxesHelper;
  28243. }(LineSegments);
  28244. var _ENCODINGS;
  28245. var LOD_MIN = 4;
  28246. var LOD_MAX = 8;
  28247. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  28248. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28249. // geometric shadowing function. These sigma values squared must match the
  28250. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28251. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  28252. 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
  28253. // samples and exit early, but not recompile the shader.
  28254. var MAX_SAMPLES = 20;
  28255. 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);
  28256. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  28257. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  28258. _lodPlanes = _createPlanes2._lodPlanes,
  28259. _sizeLods = _createPlanes2._sizeLods,
  28260. _sigmas = _createPlanes2._sigmas;
  28261. var _oldTarget = null; // Golden Ratio
  28262. var PHI = (1 + Math.sqrt(5)) / 2;
  28263. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  28264. // same axis), used as axis directions evenly spread on a sphere.
  28265. 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)];
  28266. /**
  28267. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28268. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28269. * blur to be quickly accessed based on material roughness. It is packed into a
  28270. * special CubeUV format that allows us to perform custom interpolation so that
  28271. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28272. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28273. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28274. * higher roughness levels. In this way we maintain resolution to smoothly
  28275. * interpolate diffuse lighting while limiting sampling computation.
  28276. */
  28277. var PMREMGenerator = /*#__PURE__*/function () {
  28278. function PMREMGenerator(renderer) {
  28279. this._renderer = renderer;
  28280. this._pingPongRenderTarget = null;
  28281. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  28282. this._equirectShader = null;
  28283. this._cubemapShader = null;
  28284. this._compileMaterial(this._blurMaterial);
  28285. }
  28286. /**
  28287. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28288. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28289. * in radians to be applied to the scene before PMREM generation. Optional near
  28290. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28291. * is placed at the origin).
  28292. */
  28293. var _proto = PMREMGenerator.prototype;
  28294. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  28295. if (sigma === void 0) {
  28296. sigma = 0;
  28297. }
  28298. if (near === void 0) {
  28299. near = 0.1;
  28300. }
  28301. if (far === void 0) {
  28302. far = 100;
  28303. }
  28304. _oldTarget = this._renderer.getRenderTarget();
  28305. var cubeUVRenderTarget = this._allocateTargets();
  28306. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  28307. if (sigma > 0) {
  28308. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  28309. }
  28310. this._applyPMREM(cubeUVRenderTarget);
  28311. this._cleanup(cubeUVRenderTarget);
  28312. return cubeUVRenderTarget;
  28313. }
  28314. /**
  28315. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28316. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28317. * as this matches best with the 256 x 256 cubemap output.
  28318. */
  28319. ;
  28320. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  28321. return this._fromTexture(equirectangular);
  28322. }
  28323. /**
  28324. * Generates a PMREM from an cubemap texture, which can be either LDR
  28325. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28326. * as this matches best with the 256 x 256 cubemap output.
  28327. */
  28328. ;
  28329. _proto.fromCubemap = function fromCubemap(cubemap) {
  28330. return this._fromTexture(cubemap);
  28331. }
  28332. /**
  28333. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28334. * your texture's network fetch for increased concurrency.
  28335. */
  28336. ;
  28337. _proto.compileCubemapShader = function compileCubemapShader() {
  28338. if (this._cubemapShader === null) {
  28339. this._cubemapShader = _getCubemapShader();
  28340. this._compileMaterial(this._cubemapShader);
  28341. }
  28342. }
  28343. /**
  28344. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28345. * your texture's network fetch for increased concurrency.
  28346. */
  28347. ;
  28348. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  28349. if (this._equirectShader === null) {
  28350. this._equirectShader = _getEquirectShader();
  28351. this._compileMaterial(this._equirectShader);
  28352. }
  28353. }
  28354. /**
  28355. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  28356. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  28357. * one of them will cause any others to also become unusable.
  28358. */
  28359. ;
  28360. _proto.dispose = function dispose() {
  28361. this._blurMaterial.dispose();
  28362. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  28363. if (this._equirectShader !== null) this._equirectShader.dispose();
  28364. for (var i = 0; i < _lodPlanes.length; i++) {
  28365. _lodPlanes[i].dispose();
  28366. }
  28367. } // private interface
  28368. ;
  28369. _proto._cleanup = function _cleanup(outputTarget) {
  28370. this._pingPongRenderTarget.dispose();
  28371. this._renderer.setRenderTarget(_oldTarget);
  28372. outputTarget.scissorTest = false;
  28373. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  28374. };
  28375. _proto._fromTexture = function _fromTexture(texture) {
  28376. _oldTarget = this._renderer.getRenderTarget();
  28377. var cubeUVRenderTarget = this._allocateTargets(texture);
  28378. this._textureToCubeUV(texture, cubeUVRenderTarget);
  28379. this._applyPMREM(cubeUVRenderTarget);
  28380. this._cleanup(cubeUVRenderTarget);
  28381. return cubeUVRenderTarget;
  28382. };
  28383. _proto._allocateTargets = function _allocateTargets(texture) {
  28384. // warning: null texture is valid
  28385. var params = {
  28386. magFilter: NearestFilter,
  28387. minFilter: NearestFilter,
  28388. generateMipmaps: false,
  28389. type: UnsignedByteType,
  28390. format: RGBEFormat,
  28391. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  28392. depthBuffer: false
  28393. };
  28394. var cubeUVRenderTarget = _createRenderTarget(params);
  28395. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  28396. this._pingPongRenderTarget = _createRenderTarget(params);
  28397. return cubeUVRenderTarget;
  28398. };
  28399. _proto._compileMaterial = function _compileMaterial(material) {
  28400. var tmpMesh = new Mesh(_lodPlanes[0], material);
  28401. this._renderer.compile(tmpMesh, _flatCamera);
  28402. };
  28403. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  28404. var fov = 90;
  28405. var aspect = 1;
  28406. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  28407. var upSign = [1, -1, 1, 1, 1, 1];
  28408. var forwardSign = [1, 1, 1, -1, -1, -1];
  28409. var renderer = this._renderer;
  28410. var outputEncoding = renderer.outputEncoding;
  28411. var toneMapping = renderer.toneMapping;
  28412. var clearColor = renderer.getClearColor();
  28413. var clearAlpha = renderer.getClearAlpha();
  28414. renderer.toneMapping = NoToneMapping;
  28415. renderer.outputEncoding = LinearEncoding;
  28416. var background = scene.background;
  28417. if (background && background.isColor) {
  28418. background.convertSRGBToLinear(); // Convert linear to RGBE
  28419. var maxComponent = Math.max(background.r, background.g, background.b);
  28420. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  28421. background = background.multiplyScalar(Math.pow(2.0, -fExp));
  28422. var alpha = (fExp + 128.0) / 255.0;
  28423. renderer.setClearColor(background, alpha);
  28424. scene.background = null;
  28425. }
  28426. for (var i = 0; i < 6; i++) {
  28427. var col = i % 3;
  28428. if (col == 0) {
  28429. cubeCamera.up.set(0, upSign[i], 0);
  28430. cubeCamera.lookAt(forwardSign[i], 0, 0);
  28431. } else if (col == 1) {
  28432. cubeCamera.up.set(0, 0, upSign[i]);
  28433. cubeCamera.lookAt(0, forwardSign[i], 0);
  28434. } else {
  28435. cubeCamera.up.set(0, upSign[i], 0);
  28436. cubeCamera.lookAt(0, 0, forwardSign[i]);
  28437. }
  28438. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  28439. renderer.setRenderTarget(cubeUVRenderTarget);
  28440. renderer.render(scene, cubeCamera);
  28441. }
  28442. renderer.toneMapping = toneMapping;
  28443. renderer.outputEncoding = outputEncoding;
  28444. renderer.setClearColor(clearColor, clearAlpha);
  28445. };
  28446. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  28447. var renderer = this._renderer;
  28448. if (texture.isCubeTexture) {
  28449. if (this._cubemapShader == null) {
  28450. this._cubemapShader = _getCubemapShader();
  28451. }
  28452. } else {
  28453. if (this._equirectShader == null) {
  28454. this._equirectShader = _getEquirectShader();
  28455. }
  28456. }
  28457. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  28458. var mesh = new Mesh(_lodPlanes[0], material);
  28459. var uniforms = material.uniforms;
  28460. uniforms['envMap'].value = texture;
  28461. if (!texture.isCubeTexture) {
  28462. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  28463. }
  28464. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  28465. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  28466. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  28467. renderer.setRenderTarget(cubeUVRenderTarget);
  28468. renderer.render(mesh, _flatCamera);
  28469. };
  28470. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  28471. var renderer = this._renderer;
  28472. var autoClear = renderer.autoClear;
  28473. renderer.autoClear = false;
  28474. for (var i = 1; i < TOTAL_LODS; i++) {
  28475. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  28476. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  28477. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  28478. }
  28479. renderer.autoClear = autoClear;
  28480. }
  28481. /**
  28482. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  28483. * vertically and horizontally, but this breaks down on a cube. Here we apply
  28484. * the blur latitudinally (around the poles), and then longitudinally (towards
  28485. * the poles) to approximate the orthogonally-separable blur. It is least
  28486. * accurate at the poles, but still does a decent job.
  28487. */
  28488. ;
  28489. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  28490. var pingPongRenderTarget = this._pingPongRenderTarget;
  28491. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  28492. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  28493. };
  28494. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  28495. var renderer = this._renderer;
  28496. var blurMaterial = this._blurMaterial;
  28497. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  28498. console.error('blur direction must be either latitudinal or longitudinal!');
  28499. } // Number of standard deviations at which to cut off the discrete approximation.
  28500. var STANDARD_DEVIATIONS = 3;
  28501. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  28502. var blurUniforms = blurMaterial.uniforms;
  28503. var pixels = _sizeLods[lodIn] - 1;
  28504. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  28505. var sigmaPixels = sigmaRadians / radiansPerPixel;
  28506. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  28507. if (samples > MAX_SAMPLES) {
  28508. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  28509. }
  28510. var weights = [];
  28511. var sum = 0;
  28512. for (var i = 0; i < MAX_SAMPLES; ++i) {
  28513. var _x = i / sigmaPixels;
  28514. var weight = Math.exp(-_x * _x / 2);
  28515. weights.push(weight);
  28516. if (i == 0) {
  28517. sum += weight;
  28518. } else if (i < samples) {
  28519. sum += 2 * weight;
  28520. }
  28521. }
  28522. for (var _i = 0; _i < weights.length; _i++) {
  28523. weights[_i] = weights[_i] / sum;
  28524. }
  28525. blurUniforms['envMap'].value = targetIn.texture;
  28526. blurUniforms['samples'].value = samples;
  28527. blurUniforms['weights'].value = weights;
  28528. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  28529. if (poleAxis) {
  28530. blurUniforms['poleAxis'].value = poleAxis;
  28531. }
  28532. blurUniforms['dTheta'].value = radiansPerPixel;
  28533. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  28534. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28535. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28536. var outputSize = _sizeLods[lodOut];
  28537. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  28538. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  28539. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  28540. renderer.setRenderTarget(targetOut);
  28541. renderer.render(blurMesh, _flatCamera);
  28542. };
  28543. return PMREMGenerator;
  28544. }();
  28545. function _isLDR(texture) {
  28546. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  28547. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  28548. }
  28549. function _createPlanes() {
  28550. var _lodPlanes = [];
  28551. var _sizeLods = [];
  28552. var _sigmas = [];
  28553. var lod = LOD_MAX;
  28554. for (var i = 0; i < TOTAL_LODS; i++) {
  28555. var sizeLod = Math.pow(2, lod);
  28556. _sizeLods.push(sizeLod);
  28557. var sigma = 1.0 / sizeLod;
  28558. if (i > LOD_MAX - LOD_MIN) {
  28559. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  28560. } else if (i == 0) {
  28561. sigma = 0;
  28562. }
  28563. _sigmas.push(sigma);
  28564. var texelSize = 1.0 / (sizeLod - 1);
  28565. var min = -texelSize / 2;
  28566. var max = 1 + texelSize / 2;
  28567. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  28568. var cubeFaces = 6;
  28569. var vertices = 6;
  28570. var positionSize = 3;
  28571. var uvSize = 2;
  28572. var faceIndexSize = 1;
  28573. var position = new Float32Array(positionSize * vertices * cubeFaces);
  28574. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  28575. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  28576. for (var face = 0; face < cubeFaces; face++) {
  28577. var x = face % 3 * 2 / 3 - 1;
  28578. var y = face > 2 ? 0 : -1;
  28579. 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];
  28580. position.set(coordinates, positionSize * vertices * face);
  28581. uv.set(uv1, uvSize * vertices * face);
  28582. var fill = [face, face, face, face, face, face];
  28583. faceIndex.set(fill, faceIndexSize * vertices * face);
  28584. }
  28585. var planes = new BufferGeometry();
  28586. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  28587. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  28588. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  28589. _lodPlanes.push(planes);
  28590. if (lod > LOD_MIN) {
  28591. lod--;
  28592. }
  28593. }
  28594. return {
  28595. _lodPlanes: _lodPlanes,
  28596. _sizeLods: _sizeLods,
  28597. _sigmas: _sigmas
  28598. };
  28599. }
  28600. function _createRenderTarget(params) {
  28601. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  28602. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  28603. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  28604. cubeUVRenderTarget.scissorTest = true;
  28605. return cubeUVRenderTarget;
  28606. }
  28607. function _setViewport(target, x, y, width, height) {
  28608. target.viewport.set(x, y, width, height);
  28609. target.scissor.set(x, y, width, height);
  28610. }
  28611. function _getBlurShader(maxSamples) {
  28612. var weights = new Float32Array(maxSamples);
  28613. var poleAxis = new Vector3(0, 1, 0);
  28614. var shaderMaterial = new RawShaderMaterial({
  28615. name: 'SphericalGaussianBlur',
  28616. defines: {
  28617. 'n': maxSamples
  28618. },
  28619. uniforms: {
  28620. 'envMap': {
  28621. value: null
  28622. },
  28623. 'samples': {
  28624. value: 1
  28625. },
  28626. 'weights': {
  28627. value: weights
  28628. },
  28629. 'latitudinal': {
  28630. value: false
  28631. },
  28632. 'dTheta': {
  28633. value: 0
  28634. },
  28635. 'mipInt': {
  28636. value: 0
  28637. },
  28638. 'poleAxis': {
  28639. value: poleAxis
  28640. },
  28641. 'inputEncoding': {
  28642. value: ENCODINGS[LinearEncoding]
  28643. },
  28644. 'outputEncoding': {
  28645. value: ENCODINGS[LinearEncoding]
  28646. }
  28647. },
  28648. vertexShader: _getCommonVertexShader(),
  28649. fragmentShader:
  28650. /* glsl */
  28651. "\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",
  28652. blending: NoBlending,
  28653. depthTest: false,
  28654. depthWrite: false
  28655. });
  28656. return shaderMaterial;
  28657. }
  28658. function _getEquirectShader() {
  28659. var texelSize = new Vector2(1, 1);
  28660. var shaderMaterial = new RawShaderMaterial({
  28661. name: 'EquirectangularToCubeUV',
  28662. uniforms: {
  28663. 'envMap': {
  28664. value: null
  28665. },
  28666. 'texelSize': {
  28667. value: texelSize
  28668. },
  28669. 'inputEncoding': {
  28670. value: ENCODINGS[LinearEncoding]
  28671. },
  28672. 'outputEncoding': {
  28673. value: ENCODINGS[LinearEncoding]
  28674. }
  28675. },
  28676. vertexShader: _getCommonVertexShader(),
  28677. fragmentShader:
  28678. /* glsl */
  28679. "\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",
  28680. blending: NoBlending,
  28681. depthTest: false,
  28682. depthWrite: false
  28683. });
  28684. return shaderMaterial;
  28685. }
  28686. function _getCubemapShader() {
  28687. var shaderMaterial = new RawShaderMaterial({
  28688. name: 'CubemapToCubeUV',
  28689. uniforms: {
  28690. 'envMap': {
  28691. value: null
  28692. },
  28693. 'inputEncoding': {
  28694. value: ENCODINGS[LinearEncoding]
  28695. },
  28696. 'outputEncoding': {
  28697. value: ENCODINGS[LinearEncoding]
  28698. }
  28699. },
  28700. vertexShader: _getCommonVertexShader(),
  28701. fragmentShader:
  28702. /* glsl */
  28703. "\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",
  28704. blending: NoBlending,
  28705. depthTest: false,
  28706. depthWrite: false
  28707. });
  28708. return shaderMaterial;
  28709. }
  28710. function _getCommonVertexShader() {
  28711. return (
  28712. /* glsl */
  28713. "\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"
  28714. );
  28715. }
  28716. function _getEncodings() {
  28717. return (
  28718. /* glsl */
  28719. "\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"
  28720. );
  28721. }
  28722. function Face4(a, b, c, d, normal, color, materialIndex) {
  28723. console.warn('THREE.Face4 has been removed. A THREE.Face3 will be created instead.');
  28724. return new Face3(a, b, c, normal, color, materialIndex);
  28725. }
  28726. var LineStrip = 0;
  28727. var LinePieces = 1;
  28728. var NoColors = 0;
  28729. var FaceColors = 1;
  28730. var VertexColors = 2;
  28731. function MeshFaceMaterial(materials) {
  28732. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  28733. return materials;
  28734. }
  28735. function MultiMaterial(materials) {
  28736. if (materials === undefined) materials = [];
  28737. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  28738. materials.isMultiMaterial = true;
  28739. materials.materials = materials;
  28740. materials.clone = function () {
  28741. return materials.slice();
  28742. };
  28743. return materials;
  28744. }
  28745. function PointCloud(geometry, material) {
  28746. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  28747. return new Points(geometry, material);
  28748. }
  28749. function Particle(material) {
  28750. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  28751. return new Sprite(material);
  28752. }
  28753. function ParticleSystem(geometry, material) {
  28754. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  28755. return new Points(geometry, material);
  28756. }
  28757. function PointCloudMaterial(parameters) {
  28758. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  28759. return new PointsMaterial(parameters);
  28760. }
  28761. function ParticleBasicMaterial(parameters) {
  28762. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  28763. return new PointsMaterial(parameters);
  28764. }
  28765. function ParticleSystemMaterial(parameters) {
  28766. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  28767. return new PointsMaterial(parameters);
  28768. }
  28769. function Vertex(x, y, z) {
  28770. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  28771. return new Vector3(x, y, z);
  28772. } //
  28773. function DynamicBufferAttribute(array, itemSize) {
  28774. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  28775. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  28776. }
  28777. function Int8Attribute(array, itemSize) {
  28778. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  28779. return new Int8BufferAttribute(array, itemSize);
  28780. }
  28781. function Uint8Attribute(array, itemSize) {
  28782. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  28783. return new Uint8BufferAttribute(array, itemSize);
  28784. }
  28785. function Uint8ClampedAttribute(array, itemSize) {
  28786. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  28787. return new Uint8ClampedBufferAttribute(array, itemSize);
  28788. }
  28789. function Int16Attribute(array, itemSize) {
  28790. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  28791. return new Int16BufferAttribute(array, itemSize);
  28792. }
  28793. function Uint16Attribute(array, itemSize) {
  28794. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  28795. return new Uint16BufferAttribute(array, itemSize);
  28796. }
  28797. function Int32Attribute(array, itemSize) {
  28798. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  28799. return new Int32BufferAttribute(array, itemSize);
  28800. }
  28801. function Uint32Attribute(array, itemSize) {
  28802. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  28803. return new Uint32BufferAttribute(array, itemSize);
  28804. }
  28805. function Float32Attribute(array, itemSize) {
  28806. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  28807. return new Float32BufferAttribute(array, itemSize);
  28808. }
  28809. function Float64Attribute(array, itemSize) {
  28810. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  28811. return new Float64BufferAttribute(array, itemSize);
  28812. } //
  28813. Curve.create = function (construct, getPoint) {
  28814. console.log('THREE.Curve.create() has been deprecated');
  28815. construct.prototype = Object.create(Curve.prototype);
  28816. construct.prototype.constructor = construct;
  28817. construct.prototype.getPoint = getPoint;
  28818. return construct;
  28819. }; //
  28820. Object.assign(CurvePath.prototype, {
  28821. createPointsGeometry: function createPointsGeometry(divisions) {
  28822. 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)
  28823. var pts = this.getPoints(divisions);
  28824. return this.createGeometry(pts);
  28825. },
  28826. createSpacedPointsGeometry: function createSpacedPointsGeometry(divisions) {
  28827. console.warn('THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.'); // generate geometry from equidistant sampling along the path
  28828. var pts = this.getSpacedPoints(divisions);
  28829. return this.createGeometry(pts);
  28830. },
  28831. createGeometry: function createGeometry(points) {
  28832. console.warn('THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');
  28833. var geometry = new Geometry();
  28834. for (var i = 0, l = points.length; i < l; i++) {
  28835. var point = points[i];
  28836. geometry.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  28837. }
  28838. return geometry;
  28839. }
  28840. }); //
  28841. Object.assign(Path.prototype, {
  28842. fromPoints: function fromPoints(points) {
  28843. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  28844. return this.setFromPoints(points);
  28845. }
  28846. }); //
  28847. function ClosedSplineCurve3(points) {
  28848. console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  28849. CatmullRomCurve3.call(this, points);
  28850. this.type = 'catmullrom';
  28851. this.closed = true;
  28852. }
  28853. ClosedSplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  28854. function SplineCurve3(points) {
  28855. console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  28856. CatmullRomCurve3.call(this, points);
  28857. this.type = 'catmullrom';
  28858. }
  28859. SplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  28860. function Spline(points) {
  28861. console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');
  28862. CatmullRomCurve3.call(this, points);
  28863. this.type = 'catmullrom';
  28864. }
  28865. Spline.prototype = Object.create(CatmullRomCurve3.prototype);
  28866. Object.assign(Spline.prototype, {
  28867. initFromArray: function initFromArray()
  28868. /* a */
  28869. {
  28870. console.error('THREE.Spline: .initFromArray() has been removed.');
  28871. },
  28872. getControlPointsArray: function getControlPointsArray()
  28873. /* optionalTarget */
  28874. {
  28875. console.error('THREE.Spline: .getControlPointsArray() has been removed.');
  28876. },
  28877. reparametrizeByArcLength: function reparametrizeByArcLength()
  28878. /* samplingCoef */
  28879. {
  28880. console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');
  28881. }
  28882. }); //
  28883. function AxisHelper(size) {
  28884. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  28885. return new AxesHelper(size);
  28886. }
  28887. function BoundingBoxHelper(object, color) {
  28888. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  28889. return new BoxHelper(object, color);
  28890. }
  28891. function EdgesHelper(object, hex) {
  28892. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  28893. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  28894. color: hex !== undefined ? hex : 0xffffff
  28895. }));
  28896. }
  28897. GridHelper.prototype.setColors = function () {
  28898. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  28899. };
  28900. SkeletonHelper.prototype.update = function () {
  28901. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  28902. };
  28903. function WireframeHelper(object, hex) {
  28904. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  28905. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  28906. color: hex !== undefined ? hex : 0xffffff
  28907. }));
  28908. } //
  28909. Object.assign(Loader.prototype, {
  28910. extractUrlBase: function extractUrlBase(url) {
  28911. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  28912. return LoaderUtils.extractUrlBase(url);
  28913. }
  28914. });
  28915. Loader.Handlers = {
  28916. add: function add()
  28917. /* regex, loader */
  28918. {
  28919. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  28920. },
  28921. get: function get()
  28922. /* file */
  28923. {
  28924. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  28925. }
  28926. };
  28927. function XHRLoader(manager) {
  28928. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  28929. return new FileLoader(manager);
  28930. }
  28931. function BinaryTextureLoader(manager) {
  28932. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  28933. return new DataTextureLoader(manager);
  28934. } //
  28935. Object.assign(Box2.prototype, {
  28936. center: function center(optionalTarget) {
  28937. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  28938. return this.getCenter(optionalTarget);
  28939. },
  28940. empty: function empty() {
  28941. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  28942. return this.isEmpty();
  28943. },
  28944. isIntersectionBox: function isIntersectionBox(box) {
  28945. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  28946. return this.intersectsBox(box);
  28947. },
  28948. size: function size(optionalTarget) {
  28949. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  28950. return this.getSize(optionalTarget);
  28951. }
  28952. });
  28953. Object.assign(Box3.prototype, {
  28954. center: function center(optionalTarget) {
  28955. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  28956. return this.getCenter(optionalTarget);
  28957. },
  28958. empty: function empty() {
  28959. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  28960. return this.isEmpty();
  28961. },
  28962. isIntersectionBox: function isIntersectionBox(box) {
  28963. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  28964. return this.intersectsBox(box);
  28965. },
  28966. isIntersectionSphere: function isIntersectionSphere(sphere) {
  28967. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  28968. return this.intersectsSphere(sphere);
  28969. },
  28970. size: function size(optionalTarget) {
  28971. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  28972. return this.getSize(optionalTarget);
  28973. }
  28974. });
  28975. Object.assign(Sphere.prototype, {
  28976. empty: function empty() {
  28977. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  28978. return this.isEmpty();
  28979. }
  28980. });
  28981. Frustum.prototype.setFromMatrix = function (m) {
  28982. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  28983. return this.setFromProjectionMatrix(m);
  28984. };
  28985. Line3.prototype.center = function (optionalTarget) {
  28986. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  28987. return this.getCenter(optionalTarget);
  28988. };
  28989. Object.assign(MathUtils, {
  28990. random16: function random16() {
  28991. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  28992. return Math.random();
  28993. },
  28994. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  28995. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  28996. return MathUtils.floorPowerOfTwo(value);
  28997. },
  28998. nextPowerOfTwo: function nextPowerOfTwo(value) {
  28999. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29000. return MathUtils.ceilPowerOfTwo(value);
  29001. }
  29002. });
  29003. Object.assign(Matrix3.prototype, {
  29004. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29005. console.warn("THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");
  29006. return this.toArray(array, offset);
  29007. },
  29008. multiplyVector3: function multiplyVector3(vector) {
  29009. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29010. return vector.applyMatrix3(this);
  29011. },
  29012. multiplyVector3Array: function multiplyVector3Array()
  29013. /* a */
  29014. {
  29015. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29016. },
  29017. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29018. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29019. return attribute.applyMatrix3(this);
  29020. },
  29021. applyToVector3Array: function applyToVector3Array()
  29022. /* array, offset, length */
  29023. {
  29024. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29025. }
  29026. });
  29027. Object.assign(Matrix4.prototype, {
  29028. extractPosition: function extractPosition(m) {
  29029. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29030. return this.copyPosition(m);
  29031. },
  29032. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29033. console.warn("THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");
  29034. return this.toArray(array, offset);
  29035. },
  29036. getPosition: function getPosition() {
  29037. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29038. return new Vector3().setFromMatrixColumn(this, 3);
  29039. },
  29040. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29041. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29042. return this.makeRotationFromQuaternion(q);
  29043. },
  29044. multiplyToArray: function multiplyToArray() {
  29045. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29046. },
  29047. multiplyVector3: function multiplyVector3(vector) {
  29048. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29049. return vector.applyMatrix4(this);
  29050. },
  29051. multiplyVector4: function multiplyVector4(vector) {
  29052. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29053. return vector.applyMatrix4(this);
  29054. },
  29055. multiplyVector3Array: function multiplyVector3Array()
  29056. /* a */
  29057. {
  29058. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29059. },
  29060. rotateAxis: function rotateAxis(v) {
  29061. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29062. v.transformDirection(this);
  29063. },
  29064. crossVector: function crossVector(vector) {
  29065. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29066. return vector.applyMatrix4(this);
  29067. },
  29068. translate: function translate() {
  29069. console.error('THREE.Matrix4: .translate() has been removed.');
  29070. },
  29071. rotateX: function rotateX() {
  29072. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29073. },
  29074. rotateY: function rotateY() {
  29075. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29076. },
  29077. rotateZ: function rotateZ() {
  29078. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29079. },
  29080. rotateByAxis: function rotateByAxis() {
  29081. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29082. },
  29083. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29084. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29085. return attribute.applyMatrix4(this);
  29086. },
  29087. applyToVector3Array: function applyToVector3Array()
  29088. /* array, offset, length */
  29089. {
  29090. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29091. },
  29092. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29093. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29094. return this.makePerspective(left, right, top, bottom, near, far);
  29095. }
  29096. });
  29097. Plane.prototype.isIntersectionLine = function (line) {
  29098. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29099. return this.intersectsLine(line);
  29100. };
  29101. Quaternion.prototype.multiplyVector3 = function (vector) {
  29102. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29103. return vector.applyQuaternion(this);
  29104. };
  29105. Object.assign(Ray.prototype, {
  29106. isIntersectionBox: function isIntersectionBox(box) {
  29107. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29108. return this.intersectsBox(box);
  29109. },
  29110. isIntersectionPlane: function isIntersectionPlane(plane) {
  29111. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29112. return this.intersectsPlane(plane);
  29113. },
  29114. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29115. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29116. return this.intersectsSphere(sphere);
  29117. }
  29118. });
  29119. Object.assign(Triangle.prototype, {
  29120. area: function area() {
  29121. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29122. return this.getArea();
  29123. },
  29124. barycoordFromPoint: function barycoordFromPoint(point, target) {
  29125. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29126. return this.getBarycoord(point, target);
  29127. },
  29128. midpoint: function midpoint(target) {
  29129. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29130. return this.getMidpoint(target);
  29131. },
  29132. normal: function normal(target) {
  29133. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29134. return this.getNormal(target);
  29135. },
  29136. plane: function plane(target) {
  29137. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29138. return this.getPlane(target);
  29139. }
  29140. });
  29141. Object.assign(Triangle, {
  29142. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  29143. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29144. return Triangle.getBarycoord(point, a, b, c, target);
  29145. },
  29146. normal: function normal(a, b, c, target) {
  29147. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29148. return Triangle.getNormal(a, b, c, target);
  29149. }
  29150. });
  29151. Object.assign(Shape.prototype, {
  29152. extractAllPoints: function extractAllPoints(divisions) {
  29153. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29154. return this.extractPoints(divisions);
  29155. },
  29156. extrude: function extrude(options) {
  29157. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  29158. return new ExtrudeGeometry(this, options);
  29159. },
  29160. makeGeometry: function makeGeometry(options) {
  29161. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  29162. return new ShapeGeometry(this, options);
  29163. }
  29164. });
  29165. Object.assign(Vector2.prototype, {
  29166. fromAttribute: function fromAttribute(attribute, index, offset) {
  29167. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29168. return this.fromBufferAttribute(attribute, index, offset);
  29169. },
  29170. distanceToManhattan: function distanceToManhattan(v) {
  29171. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29172. return this.manhattanDistanceTo(v);
  29173. },
  29174. lengthManhattan: function lengthManhattan() {
  29175. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  29176. return this.manhattanLength();
  29177. }
  29178. });
  29179. Object.assign(Vector3.prototype, {
  29180. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  29181. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  29182. },
  29183. setEulerFromQuaternion: function setEulerFromQuaternion() {
  29184. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  29185. },
  29186. getPositionFromMatrix: function getPositionFromMatrix(m) {
  29187. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  29188. return this.setFromMatrixPosition(m);
  29189. },
  29190. getScaleFromMatrix: function getScaleFromMatrix(m) {
  29191. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  29192. return this.setFromMatrixScale(m);
  29193. },
  29194. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  29195. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  29196. return this.setFromMatrixColumn(matrix, index);
  29197. },
  29198. applyProjection: function applyProjection(m) {
  29199. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  29200. return this.applyMatrix4(m);
  29201. },
  29202. fromAttribute: function fromAttribute(attribute, index, offset) {
  29203. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29204. return this.fromBufferAttribute(attribute, index, offset);
  29205. },
  29206. distanceToManhattan: function distanceToManhattan(v) {
  29207. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29208. return this.manhattanDistanceTo(v);
  29209. },
  29210. lengthManhattan: function lengthManhattan() {
  29211. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  29212. return this.manhattanLength();
  29213. }
  29214. });
  29215. Object.assign(Vector4.prototype, {
  29216. fromAttribute: function fromAttribute(attribute, index, offset) {
  29217. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29218. return this.fromBufferAttribute(attribute, index, offset);
  29219. },
  29220. lengthManhattan: function lengthManhattan() {
  29221. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  29222. return this.manhattanLength();
  29223. }
  29224. }); //
  29225. Object.assign(Geometry.prototype, {
  29226. computeTangents: function computeTangents() {
  29227. console.error('THREE.Geometry: .computeTangents() has been removed.');
  29228. },
  29229. computeLineDistances: function computeLineDistances() {
  29230. console.error('THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.');
  29231. },
  29232. applyMatrix: function applyMatrix(matrix) {
  29233. console.warn('THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29234. return this.applyMatrix4(matrix);
  29235. }
  29236. });
  29237. Object.assign(Object3D.prototype, {
  29238. getChildByName: function getChildByName(name) {
  29239. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  29240. return this.getObjectByName(name);
  29241. },
  29242. renderDepth: function renderDepth() {
  29243. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  29244. },
  29245. translate: function translate(distance, axis) {
  29246. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  29247. return this.translateOnAxis(axis, distance);
  29248. },
  29249. getWorldRotation: function getWorldRotation() {
  29250. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  29251. },
  29252. applyMatrix: function applyMatrix(matrix) {
  29253. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  29254. return this.applyMatrix4(matrix);
  29255. }
  29256. });
  29257. Object.defineProperties(Object3D.prototype, {
  29258. eulerOrder: {
  29259. get: function get() {
  29260. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29261. return this.rotation.order;
  29262. },
  29263. set: function set(value) {
  29264. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29265. this.rotation.order = value;
  29266. }
  29267. },
  29268. useQuaternion: {
  29269. get: function get() {
  29270. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29271. },
  29272. set: function set() {
  29273. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29274. }
  29275. }
  29276. });
  29277. Object.assign(Mesh.prototype, {
  29278. setDrawMode: function setDrawMode() {
  29279. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29280. }
  29281. });
  29282. Object.defineProperties(Mesh.prototype, {
  29283. drawMode: {
  29284. get: function get() {
  29285. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  29286. return TrianglesDrawMode;
  29287. },
  29288. set: function set() {
  29289. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29290. }
  29291. }
  29292. });
  29293. Object.defineProperties(LOD.prototype, {
  29294. objects: {
  29295. get: function get() {
  29296. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  29297. return this.levels;
  29298. }
  29299. }
  29300. });
  29301. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  29302. get: function get() {
  29303. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29304. },
  29305. set: function set() {
  29306. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29307. }
  29308. });
  29309. SkinnedMesh.prototype.initBones = function () {
  29310. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  29311. };
  29312. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  29313. get: function get() {
  29314. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29315. return this.arcLengthDivisions;
  29316. },
  29317. set: function set(value) {
  29318. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29319. this.arcLengthDivisions = value;
  29320. }
  29321. }); //
  29322. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  29323. console.warn("THREE.PerspectiveCamera.setLens is deprecated. " + "Use .setFocalLength and .filmGauge for a photographic setup.");
  29324. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  29325. this.setFocalLength(focalLength);
  29326. }; //
  29327. Object.defineProperties(Light.prototype, {
  29328. onlyShadow: {
  29329. set: function set() {
  29330. console.warn('THREE.Light: .onlyShadow has been removed.');
  29331. }
  29332. },
  29333. shadowCameraFov: {
  29334. set: function set(value) {
  29335. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  29336. this.shadow.camera.fov = value;
  29337. }
  29338. },
  29339. shadowCameraLeft: {
  29340. set: function set(value) {
  29341. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  29342. this.shadow.camera.left = value;
  29343. }
  29344. },
  29345. shadowCameraRight: {
  29346. set: function set(value) {
  29347. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  29348. this.shadow.camera.right = value;
  29349. }
  29350. },
  29351. shadowCameraTop: {
  29352. set: function set(value) {
  29353. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  29354. this.shadow.camera.top = value;
  29355. }
  29356. },
  29357. shadowCameraBottom: {
  29358. set: function set(value) {
  29359. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  29360. this.shadow.camera.bottom = value;
  29361. }
  29362. },
  29363. shadowCameraNear: {
  29364. set: function set(value) {
  29365. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  29366. this.shadow.camera.near = value;
  29367. }
  29368. },
  29369. shadowCameraFar: {
  29370. set: function set(value) {
  29371. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  29372. this.shadow.camera.far = value;
  29373. }
  29374. },
  29375. shadowCameraVisible: {
  29376. set: function set() {
  29377. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  29378. }
  29379. },
  29380. shadowBias: {
  29381. set: function set(value) {
  29382. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  29383. this.shadow.bias = value;
  29384. }
  29385. },
  29386. shadowDarkness: {
  29387. set: function set() {
  29388. console.warn('THREE.Light: .shadowDarkness has been removed.');
  29389. }
  29390. },
  29391. shadowMapWidth: {
  29392. set: function set(value) {
  29393. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  29394. this.shadow.mapSize.width = value;
  29395. }
  29396. },
  29397. shadowMapHeight: {
  29398. set: function set(value) {
  29399. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  29400. this.shadow.mapSize.height = value;
  29401. }
  29402. }
  29403. }); //
  29404. Object.defineProperties(BufferAttribute.prototype, {
  29405. length: {
  29406. get: function get() {
  29407. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  29408. return this.array.length;
  29409. }
  29410. },
  29411. dynamic: {
  29412. get: function get() {
  29413. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29414. return this.usage === DynamicDrawUsage;
  29415. },
  29416. set: function set()
  29417. /* value */
  29418. {
  29419. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29420. this.setUsage(DynamicDrawUsage);
  29421. }
  29422. }
  29423. });
  29424. Object.assign(BufferAttribute.prototype, {
  29425. setDynamic: function setDynamic(value) {
  29426. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29427. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29428. return this;
  29429. },
  29430. copyIndicesArray: function copyIndicesArray()
  29431. /* indices */
  29432. {
  29433. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  29434. },
  29435. setArray: function setArray()
  29436. /* array */
  29437. {
  29438. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29439. }
  29440. });
  29441. Object.assign(BufferGeometry.prototype, {
  29442. addIndex: function addIndex(index) {
  29443. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  29444. this.setIndex(index);
  29445. },
  29446. addAttribute: function addAttribute(name, attribute) {
  29447. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  29448. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  29449. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  29450. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  29451. }
  29452. if (name === 'index') {
  29453. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  29454. this.setIndex(attribute);
  29455. return this;
  29456. }
  29457. return this.setAttribute(name, attribute);
  29458. },
  29459. addDrawCall: function addDrawCall(start, count, indexOffset) {
  29460. if (indexOffset !== undefined) {
  29461. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  29462. }
  29463. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  29464. this.addGroup(start, count);
  29465. },
  29466. clearDrawCalls: function clearDrawCalls() {
  29467. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  29468. this.clearGroups();
  29469. },
  29470. computeTangents: function computeTangents() {
  29471. console.warn('THREE.BufferGeometry: .computeTangents() has been removed.');
  29472. },
  29473. computeOffsets: function computeOffsets() {
  29474. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  29475. },
  29476. removeAttribute: function removeAttribute(name) {
  29477. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  29478. return this.deleteAttribute(name);
  29479. },
  29480. applyMatrix: function applyMatrix(matrix) {
  29481. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29482. return this.applyMatrix4(matrix);
  29483. }
  29484. });
  29485. Object.defineProperties(BufferGeometry.prototype, {
  29486. drawcalls: {
  29487. get: function get() {
  29488. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  29489. return this.groups;
  29490. }
  29491. },
  29492. offsets: {
  29493. get: function get() {
  29494. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  29495. return this.groups;
  29496. }
  29497. }
  29498. });
  29499. Object.defineProperties(InstancedBufferGeometry.prototype, {
  29500. maxInstancedCount: {
  29501. get: function get() {
  29502. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29503. return this.instanceCount;
  29504. },
  29505. set: function set(value) {
  29506. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29507. this.instanceCount = value;
  29508. }
  29509. }
  29510. });
  29511. Object.defineProperties(Raycaster.prototype, {
  29512. linePrecision: {
  29513. get: function get() {
  29514. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29515. return this.params.Line.threshold;
  29516. },
  29517. set: function set(value) {
  29518. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29519. this.params.Line.threshold = value;
  29520. }
  29521. }
  29522. });
  29523. Object.defineProperties(InterleavedBuffer.prototype, {
  29524. dynamic: {
  29525. get: function get() {
  29526. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29527. return this.usage === DynamicDrawUsage;
  29528. },
  29529. set: function set(value) {
  29530. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29531. this.setUsage(value);
  29532. }
  29533. }
  29534. });
  29535. Object.assign(InterleavedBuffer.prototype, {
  29536. setDynamic: function setDynamic(value) {
  29537. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29538. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29539. return this;
  29540. },
  29541. setArray: function setArray()
  29542. /* array */
  29543. {
  29544. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29545. }
  29546. }); //
  29547. Object.assign(ExtrudeBufferGeometry.prototype, {
  29548. getArrays: function getArrays() {
  29549. console.error('THREE.ExtrudeBufferGeometry: .getArrays() has been removed.');
  29550. },
  29551. addShapeList: function addShapeList() {
  29552. console.error('THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.');
  29553. },
  29554. addShape: function addShape() {
  29555. console.error('THREE.ExtrudeBufferGeometry: .addShape() has been removed.');
  29556. }
  29557. }); //
  29558. Object.assign(Scene.prototype, {
  29559. dispose: function dispose() {
  29560. console.error('THREE.Scene: .dispose() has been removed.');
  29561. }
  29562. }); //
  29563. Object.defineProperties(Uniform.prototype, {
  29564. dynamic: {
  29565. set: function set() {
  29566. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  29567. }
  29568. },
  29569. onUpdate: {
  29570. value: function value() {
  29571. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  29572. return this;
  29573. }
  29574. }
  29575. }); //
  29576. Object.defineProperties(Material.prototype, {
  29577. wrapAround: {
  29578. get: function get() {
  29579. console.warn('THREE.Material: .wrapAround has been removed.');
  29580. },
  29581. set: function set() {
  29582. console.warn('THREE.Material: .wrapAround has been removed.');
  29583. }
  29584. },
  29585. overdraw: {
  29586. get: function get() {
  29587. console.warn('THREE.Material: .overdraw has been removed.');
  29588. },
  29589. set: function set() {
  29590. console.warn('THREE.Material: .overdraw has been removed.');
  29591. }
  29592. },
  29593. wrapRGB: {
  29594. get: function get() {
  29595. console.warn('THREE.Material: .wrapRGB has been removed.');
  29596. return new Color();
  29597. }
  29598. },
  29599. shading: {
  29600. get: function get() {
  29601. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29602. },
  29603. set: function set(value) {
  29604. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29605. this.flatShading = value === FlatShading;
  29606. }
  29607. },
  29608. stencilMask: {
  29609. get: function get() {
  29610. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29611. return this.stencilFuncMask;
  29612. },
  29613. set: function set(value) {
  29614. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29615. this.stencilFuncMask = value;
  29616. }
  29617. }
  29618. });
  29619. Object.defineProperties(MeshPhongMaterial.prototype, {
  29620. metal: {
  29621. get: function get() {
  29622. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  29623. return false;
  29624. },
  29625. set: function set() {
  29626. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  29627. }
  29628. }
  29629. });
  29630. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  29631. transparency: {
  29632. get: function get() {
  29633. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29634. return this.transmission;
  29635. },
  29636. set: function set(value) {
  29637. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29638. this.transmission = value;
  29639. }
  29640. }
  29641. });
  29642. Object.defineProperties(ShaderMaterial.prototype, {
  29643. derivatives: {
  29644. get: function get() {
  29645. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29646. return this.extensions.derivatives;
  29647. },
  29648. set: function set(value) {
  29649. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29650. this.extensions.derivatives = value;
  29651. }
  29652. }
  29653. }); //
  29654. Object.assign(WebGLRenderer.prototype, {
  29655. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  29656. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  29657. this.setRenderTarget(renderTarget);
  29658. this.clear(color, depth, stencil);
  29659. },
  29660. animate: function animate(callback) {
  29661. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  29662. this.setAnimationLoop(callback);
  29663. },
  29664. getCurrentRenderTarget: function getCurrentRenderTarget() {
  29665. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  29666. return this.getRenderTarget();
  29667. },
  29668. getMaxAnisotropy: function getMaxAnisotropy() {
  29669. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  29670. return this.capabilities.getMaxAnisotropy();
  29671. },
  29672. getPrecision: function getPrecision() {
  29673. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  29674. return this.capabilities.precision;
  29675. },
  29676. resetGLState: function resetGLState() {
  29677. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  29678. return this.state.reset();
  29679. },
  29680. supportsFloatTextures: function supportsFloatTextures() {
  29681. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  29682. return this.extensions.get('OES_texture_float');
  29683. },
  29684. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  29685. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  29686. return this.extensions.get('OES_texture_half_float');
  29687. },
  29688. supportsStandardDerivatives: function supportsStandardDerivatives() {
  29689. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  29690. return this.extensions.get('OES_standard_derivatives');
  29691. },
  29692. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  29693. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  29694. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  29695. },
  29696. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  29697. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  29698. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  29699. },
  29700. supportsBlendMinMax: function supportsBlendMinMax() {
  29701. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  29702. return this.extensions.get('EXT_blend_minmax');
  29703. },
  29704. supportsVertexTextures: function supportsVertexTextures() {
  29705. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  29706. return this.capabilities.vertexTextures;
  29707. },
  29708. supportsInstancedArrays: function supportsInstancedArrays() {
  29709. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  29710. return this.extensions.get('ANGLE_instanced_arrays');
  29711. },
  29712. enableScissorTest: function enableScissorTest(boolean) {
  29713. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  29714. this.setScissorTest(boolean);
  29715. },
  29716. initMaterial: function initMaterial() {
  29717. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  29718. },
  29719. addPrePlugin: function addPrePlugin() {
  29720. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  29721. },
  29722. addPostPlugin: function addPostPlugin() {
  29723. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  29724. },
  29725. updateShadowMap: function updateShadowMap() {
  29726. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  29727. },
  29728. setFaceCulling: function setFaceCulling() {
  29729. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  29730. },
  29731. allocTextureUnit: function allocTextureUnit() {
  29732. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  29733. },
  29734. setTexture: function setTexture() {
  29735. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  29736. },
  29737. setTexture2D: function setTexture2D() {
  29738. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  29739. },
  29740. setTextureCube: function setTextureCube() {
  29741. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  29742. },
  29743. getActiveMipMapLevel: function getActiveMipMapLevel() {
  29744. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  29745. return this.getActiveMipmapLevel();
  29746. }
  29747. });
  29748. Object.defineProperties(WebGLRenderer.prototype, {
  29749. shadowMapEnabled: {
  29750. get: function get() {
  29751. return this.shadowMap.enabled;
  29752. },
  29753. set: function set(value) {
  29754. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  29755. this.shadowMap.enabled = value;
  29756. }
  29757. },
  29758. shadowMapType: {
  29759. get: function get() {
  29760. return this.shadowMap.type;
  29761. },
  29762. set: function set(value) {
  29763. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  29764. this.shadowMap.type = value;
  29765. }
  29766. },
  29767. shadowMapCullFace: {
  29768. get: function get() {
  29769. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  29770. return undefined;
  29771. },
  29772. set: function set()
  29773. /* value */
  29774. {
  29775. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  29776. }
  29777. },
  29778. context: {
  29779. get: function get() {
  29780. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  29781. return this.getContext();
  29782. }
  29783. },
  29784. vr: {
  29785. get: function get() {
  29786. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  29787. return this.xr;
  29788. }
  29789. },
  29790. gammaInput: {
  29791. get: function get() {
  29792. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  29793. return false;
  29794. },
  29795. set: function set() {
  29796. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  29797. }
  29798. },
  29799. gammaOutput: {
  29800. get: function get() {
  29801. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  29802. return false;
  29803. },
  29804. set: function set(value) {
  29805. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  29806. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  29807. }
  29808. },
  29809. toneMappingWhitePoint: {
  29810. get: function get() {
  29811. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  29812. return 1.0;
  29813. },
  29814. set: function set() {
  29815. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  29816. }
  29817. }
  29818. });
  29819. Object.defineProperties(WebGLShadowMap.prototype, {
  29820. cullFace: {
  29821. get: function get() {
  29822. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  29823. return undefined;
  29824. },
  29825. set: function set()
  29826. /* cullFace */
  29827. {
  29828. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  29829. }
  29830. },
  29831. renderReverseSided: {
  29832. get: function get() {
  29833. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  29834. return undefined;
  29835. },
  29836. set: function set() {
  29837. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  29838. }
  29839. },
  29840. renderSingleSided: {
  29841. get: function get() {
  29842. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  29843. return undefined;
  29844. },
  29845. set: function set() {
  29846. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  29847. }
  29848. }
  29849. });
  29850. function WebGLRenderTargetCube(width, height, options) {
  29851. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  29852. return new WebGLCubeRenderTarget(width, options);
  29853. } //
  29854. Object.defineProperties(WebGLRenderTarget.prototype, {
  29855. wrapS: {
  29856. get: function get() {
  29857. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  29858. return this.texture.wrapS;
  29859. },
  29860. set: function set(value) {
  29861. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  29862. this.texture.wrapS = value;
  29863. }
  29864. },
  29865. wrapT: {
  29866. get: function get() {
  29867. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  29868. return this.texture.wrapT;
  29869. },
  29870. set: function set(value) {
  29871. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  29872. this.texture.wrapT = value;
  29873. }
  29874. },
  29875. magFilter: {
  29876. get: function get() {
  29877. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  29878. return this.texture.magFilter;
  29879. },
  29880. set: function set(value) {
  29881. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  29882. this.texture.magFilter = value;
  29883. }
  29884. },
  29885. minFilter: {
  29886. get: function get() {
  29887. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  29888. return this.texture.minFilter;
  29889. },
  29890. set: function set(value) {
  29891. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  29892. this.texture.minFilter = value;
  29893. }
  29894. },
  29895. anisotropy: {
  29896. get: function get() {
  29897. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  29898. return this.texture.anisotropy;
  29899. },
  29900. set: function set(value) {
  29901. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  29902. this.texture.anisotropy = value;
  29903. }
  29904. },
  29905. offset: {
  29906. get: function get() {
  29907. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  29908. return this.texture.offset;
  29909. },
  29910. set: function set(value) {
  29911. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  29912. this.texture.offset = value;
  29913. }
  29914. },
  29915. repeat: {
  29916. get: function get() {
  29917. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  29918. return this.texture.repeat;
  29919. },
  29920. set: function set(value) {
  29921. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  29922. this.texture.repeat = value;
  29923. }
  29924. },
  29925. format: {
  29926. get: function get() {
  29927. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  29928. return this.texture.format;
  29929. },
  29930. set: function set(value) {
  29931. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  29932. this.texture.format = value;
  29933. }
  29934. },
  29935. type: {
  29936. get: function get() {
  29937. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  29938. return this.texture.type;
  29939. },
  29940. set: function set(value) {
  29941. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  29942. this.texture.type = value;
  29943. }
  29944. },
  29945. generateMipmaps: {
  29946. get: function get() {
  29947. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  29948. return this.texture.generateMipmaps;
  29949. },
  29950. set: function set(value) {
  29951. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  29952. this.texture.generateMipmaps = value;
  29953. }
  29954. }
  29955. }); //
  29956. Object.defineProperties(Audio.prototype, {
  29957. load: {
  29958. value: function value(file) {
  29959. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  29960. var scope = this;
  29961. var audioLoader = new AudioLoader();
  29962. audioLoader.load(file, function (buffer) {
  29963. scope.setBuffer(buffer);
  29964. });
  29965. return this;
  29966. }
  29967. },
  29968. startTime: {
  29969. set: function set() {
  29970. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  29971. }
  29972. }
  29973. });
  29974. AudioAnalyser.prototype.getData = function () {
  29975. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  29976. return this.getFrequencyData();
  29977. }; //
  29978. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  29979. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  29980. return this.update(renderer, scene);
  29981. }; //
  29982. var GeometryUtils = {
  29983. merge: function merge(geometry1, geometry2, materialIndexOffset) {
  29984. console.warn('THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.');
  29985. var matrix;
  29986. if (geometry2.isMesh) {
  29987. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  29988. matrix = geometry2.matrix;
  29989. geometry2 = geometry2.geometry;
  29990. }
  29991. geometry1.merge(geometry2, matrix, materialIndexOffset);
  29992. },
  29993. center: function center(geometry) {
  29994. console.warn('THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.');
  29995. return geometry.center();
  29996. }
  29997. };
  29998. ImageUtils.crossOrigin = undefined;
  29999. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30000. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30001. var loader = new TextureLoader();
  30002. loader.setCrossOrigin(this.crossOrigin);
  30003. var texture = loader.load(url, onLoad, undefined, onError);
  30004. if (mapping) texture.mapping = mapping;
  30005. return texture;
  30006. };
  30007. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30008. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30009. var loader = new CubeTextureLoader();
  30010. loader.setCrossOrigin(this.crossOrigin);
  30011. var texture = loader.load(urls, onLoad, undefined, onError);
  30012. if (mapping) texture.mapping = mapping;
  30013. return texture;
  30014. };
  30015. ImageUtils.loadCompressedTexture = function () {
  30016. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30017. };
  30018. ImageUtils.loadCompressedTextureCube = function () {
  30019. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30020. }; //
  30021. function CanvasRenderer() {
  30022. console.error('THREE.CanvasRenderer has been removed');
  30023. } //
  30024. function JSONLoader() {
  30025. console.error('THREE.JSONLoader has been removed.');
  30026. } //
  30027. var SceneUtils = {
  30028. createMultiMaterialObject: function createMultiMaterialObject()
  30029. /* geometry, materials */
  30030. {
  30031. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30032. },
  30033. detach: function detach()
  30034. /* child, parent, scene */
  30035. {
  30036. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30037. },
  30038. attach: function attach()
  30039. /* child, scene, parent */
  30040. {
  30041. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30042. }
  30043. }; //
  30044. function LensFlare() {
  30045. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30046. }
  30047. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30048. /* eslint-disable no-undef */
  30049. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30050. detail: {
  30051. revision: REVISION
  30052. }
  30053. }));
  30054. /* eslint-enable no-undef */
  30055. }
  30056. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30057. exports.AddEquation = AddEquation;
  30058. exports.AddOperation = AddOperation;
  30059. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30060. exports.AdditiveBlending = AdditiveBlending;
  30061. exports.AlphaFormat = AlphaFormat;
  30062. exports.AlwaysDepth = AlwaysDepth;
  30063. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30064. exports.AmbientLight = AmbientLight;
  30065. exports.AmbientLightProbe = AmbientLightProbe;
  30066. exports.AnimationClip = AnimationClip;
  30067. exports.AnimationLoader = AnimationLoader;
  30068. exports.AnimationMixer = AnimationMixer;
  30069. exports.AnimationObjectGroup = AnimationObjectGroup;
  30070. exports.AnimationUtils = AnimationUtils;
  30071. exports.ArcCurve = ArcCurve;
  30072. exports.ArrayCamera = ArrayCamera;
  30073. exports.ArrowHelper = ArrowHelper;
  30074. exports.Audio = Audio;
  30075. exports.AudioAnalyser = AudioAnalyser;
  30076. exports.AudioContext = AudioContext;
  30077. exports.AudioListener = AudioListener;
  30078. exports.AudioLoader = AudioLoader;
  30079. exports.AxesHelper = AxesHelper;
  30080. exports.AxisHelper = AxisHelper;
  30081. exports.BackSide = BackSide;
  30082. exports.BasicDepthPacking = BasicDepthPacking;
  30083. exports.BasicShadowMap = BasicShadowMap;
  30084. exports.BinaryTextureLoader = BinaryTextureLoader;
  30085. exports.Bone = Bone;
  30086. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30087. exports.BoundingBoxHelper = BoundingBoxHelper;
  30088. exports.Box2 = Box2;
  30089. exports.Box3 = Box3;
  30090. exports.Box3Helper = Box3Helper;
  30091. exports.BoxBufferGeometry = BoxBufferGeometry;
  30092. exports.BoxGeometry = BoxGeometry;
  30093. exports.BoxHelper = BoxHelper;
  30094. exports.BufferAttribute = BufferAttribute;
  30095. exports.BufferGeometry = BufferGeometry;
  30096. exports.BufferGeometryLoader = BufferGeometryLoader;
  30097. exports.ByteType = ByteType;
  30098. exports.Cache = Cache;
  30099. exports.Camera = Camera;
  30100. exports.CameraHelper = CameraHelper;
  30101. exports.CanvasRenderer = CanvasRenderer;
  30102. exports.CanvasTexture = CanvasTexture;
  30103. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30104. exports.CineonToneMapping = CineonToneMapping;
  30105. exports.CircleBufferGeometry = CircleBufferGeometry;
  30106. exports.CircleGeometry = CircleGeometry;
  30107. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30108. exports.Clock = Clock;
  30109. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  30110. exports.Color = Color;
  30111. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30112. exports.CompressedTexture = CompressedTexture;
  30113. exports.CompressedTextureLoader = CompressedTextureLoader;
  30114. exports.ConeBufferGeometry = ConeBufferGeometry;
  30115. exports.ConeGeometry = ConeGeometry;
  30116. exports.CubeCamera = CubeCamera;
  30117. exports.CubeGeometry = BoxGeometry;
  30118. exports.CubeReflectionMapping = CubeReflectionMapping;
  30119. exports.CubeRefractionMapping = CubeRefractionMapping;
  30120. exports.CubeTexture = CubeTexture;
  30121. exports.CubeTextureLoader = CubeTextureLoader;
  30122. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30123. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30124. exports.CubicBezierCurve = CubicBezierCurve;
  30125. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30126. exports.CubicInterpolant = CubicInterpolant;
  30127. exports.CullFaceBack = CullFaceBack;
  30128. exports.CullFaceFront = CullFaceFront;
  30129. exports.CullFaceFrontBack = CullFaceFrontBack;
  30130. exports.CullFaceNone = CullFaceNone;
  30131. exports.Curve = Curve;
  30132. exports.CurvePath = CurvePath;
  30133. exports.CustomBlending = CustomBlending;
  30134. exports.CustomToneMapping = CustomToneMapping;
  30135. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  30136. exports.CylinderGeometry = CylinderGeometry;
  30137. exports.Cylindrical = Cylindrical;
  30138. exports.DataTexture = DataTexture;
  30139. exports.DataTexture2DArray = DataTexture2DArray;
  30140. exports.DataTexture3D = DataTexture3D;
  30141. exports.DataTextureLoader = DataTextureLoader;
  30142. exports.DecrementStencilOp = DecrementStencilOp;
  30143. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30144. exports.DefaultLoadingManager = DefaultLoadingManager;
  30145. exports.DepthFormat = DepthFormat;
  30146. exports.DepthStencilFormat = DepthStencilFormat;
  30147. exports.DepthTexture = DepthTexture;
  30148. exports.DirectionalLight = DirectionalLight;
  30149. exports.DirectionalLightHelper = DirectionalLightHelper;
  30150. exports.DiscreteInterpolant = DiscreteInterpolant;
  30151. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  30152. exports.DodecahedronGeometry = DodecahedronGeometry;
  30153. exports.DoubleSide = DoubleSide;
  30154. exports.DstAlphaFactor = DstAlphaFactor;
  30155. exports.DstColorFactor = DstColorFactor;
  30156. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30157. exports.DynamicCopyUsage = DynamicCopyUsage;
  30158. exports.DynamicDrawUsage = DynamicDrawUsage;
  30159. exports.DynamicReadUsage = DynamicReadUsage;
  30160. exports.EdgesGeometry = EdgesGeometry;
  30161. exports.EdgesHelper = EdgesHelper;
  30162. exports.EllipseCurve = EllipseCurve;
  30163. exports.EqualDepth = EqualDepth;
  30164. exports.EqualStencilFunc = EqualStencilFunc;
  30165. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30166. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30167. exports.Euler = Euler;
  30168. exports.EventDispatcher = EventDispatcher;
  30169. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  30170. exports.ExtrudeGeometry = ExtrudeGeometry;
  30171. exports.Face3 = Face3;
  30172. exports.Face4 = Face4;
  30173. exports.FaceColors = FaceColors;
  30174. exports.FileLoader = FileLoader;
  30175. exports.FlatShading = FlatShading;
  30176. exports.Float32Attribute = Float32Attribute;
  30177. exports.Float32BufferAttribute = Float32BufferAttribute;
  30178. exports.Float64Attribute = Float64Attribute;
  30179. exports.Float64BufferAttribute = Float64BufferAttribute;
  30180. exports.FloatType = FloatType;
  30181. exports.Fog = Fog;
  30182. exports.FogExp2 = FogExp2;
  30183. exports.Font = Font;
  30184. exports.FontLoader = FontLoader;
  30185. exports.FrontSide = FrontSide;
  30186. exports.Frustum = Frustum;
  30187. exports.GLBufferAttribute = GLBufferAttribute;
  30188. exports.GLSL1 = GLSL1;
  30189. exports.GLSL3 = GLSL3;
  30190. exports.GammaEncoding = GammaEncoding;
  30191. exports.Geometry = Geometry;
  30192. exports.GeometryUtils = GeometryUtils;
  30193. exports.GreaterDepth = GreaterDepth;
  30194. exports.GreaterEqualDepth = GreaterEqualDepth;
  30195. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30196. exports.GreaterStencilFunc = GreaterStencilFunc;
  30197. exports.GridHelper = GridHelper;
  30198. exports.Group = Group;
  30199. exports.HalfFloatType = HalfFloatType;
  30200. exports.HemisphereLight = HemisphereLight;
  30201. exports.HemisphereLightHelper = HemisphereLightHelper;
  30202. exports.HemisphereLightProbe = HemisphereLightProbe;
  30203. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  30204. exports.IcosahedronGeometry = IcosahedronGeometry;
  30205. exports.ImageBitmapLoader = ImageBitmapLoader;
  30206. exports.ImageLoader = ImageLoader;
  30207. exports.ImageUtils = ImageUtils;
  30208. exports.ImmediateRenderObject = ImmediateRenderObject;
  30209. exports.IncrementStencilOp = IncrementStencilOp;
  30210. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  30211. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  30212. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  30213. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  30214. exports.InstancedMesh = InstancedMesh;
  30215. exports.Int16Attribute = Int16Attribute;
  30216. exports.Int16BufferAttribute = Int16BufferAttribute;
  30217. exports.Int32Attribute = Int32Attribute;
  30218. exports.Int32BufferAttribute = Int32BufferAttribute;
  30219. exports.Int8Attribute = Int8Attribute;
  30220. exports.Int8BufferAttribute = Int8BufferAttribute;
  30221. exports.IntType = IntType;
  30222. exports.InterleavedBuffer = InterleavedBuffer;
  30223. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  30224. exports.Interpolant = Interpolant;
  30225. exports.InterpolateDiscrete = InterpolateDiscrete;
  30226. exports.InterpolateLinear = InterpolateLinear;
  30227. exports.InterpolateSmooth = InterpolateSmooth;
  30228. exports.InvertStencilOp = InvertStencilOp;
  30229. exports.JSONLoader = JSONLoader;
  30230. exports.KeepStencilOp = KeepStencilOp;
  30231. exports.KeyframeTrack = KeyframeTrack;
  30232. exports.LOD = LOD;
  30233. exports.LatheBufferGeometry = LatheBufferGeometry;
  30234. exports.LatheGeometry = LatheGeometry;
  30235. exports.Layers = Layers;
  30236. exports.LensFlare = LensFlare;
  30237. exports.LessDepth = LessDepth;
  30238. exports.LessEqualDepth = LessEqualDepth;
  30239. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  30240. exports.LessStencilFunc = LessStencilFunc;
  30241. exports.Light = Light;
  30242. exports.LightProbe = LightProbe;
  30243. exports.Line = Line;
  30244. exports.Line3 = Line3;
  30245. exports.LineBasicMaterial = LineBasicMaterial;
  30246. exports.LineCurve = LineCurve;
  30247. exports.LineCurve3 = LineCurve3;
  30248. exports.LineDashedMaterial = LineDashedMaterial;
  30249. exports.LineLoop = LineLoop;
  30250. exports.LinePieces = LinePieces;
  30251. exports.LineSegments = LineSegments;
  30252. exports.LineStrip = LineStrip;
  30253. exports.LinearEncoding = LinearEncoding;
  30254. exports.LinearFilter = LinearFilter;
  30255. exports.LinearInterpolant = LinearInterpolant;
  30256. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  30257. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  30258. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  30259. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  30260. exports.LinearToneMapping = LinearToneMapping;
  30261. exports.Loader = Loader;
  30262. exports.LoaderUtils = LoaderUtils;
  30263. exports.LoadingManager = LoadingManager;
  30264. exports.LogLuvEncoding = LogLuvEncoding;
  30265. exports.LoopOnce = LoopOnce;
  30266. exports.LoopPingPong = LoopPingPong;
  30267. exports.LoopRepeat = LoopRepeat;
  30268. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  30269. exports.LuminanceFormat = LuminanceFormat;
  30270. exports.MOUSE = MOUSE;
  30271. exports.Material = Material;
  30272. exports.MaterialLoader = MaterialLoader;
  30273. exports.Math = MathUtils;
  30274. exports.MathUtils = MathUtils;
  30275. exports.Matrix3 = Matrix3;
  30276. exports.Matrix4 = Matrix4;
  30277. exports.MaxEquation = MaxEquation;
  30278. exports.Mesh = Mesh;
  30279. exports.MeshBasicMaterial = MeshBasicMaterial;
  30280. exports.MeshDepthMaterial = MeshDepthMaterial;
  30281. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  30282. exports.MeshFaceMaterial = MeshFaceMaterial;
  30283. exports.MeshLambertMaterial = MeshLambertMaterial;
  30284. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  30285. exports.MeshNormalMaterial = MeshNormalMaterial;
  30286. exports.MeshPhongMaterial = MeshPhongMaterial;
  30287. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  30288. exports.MeshStandardMaterial = MeshStandardMaterial;
  30289. exports.MeshToonMaterial = MeshToonMaterial;
  30290. exports.MinEquation = MinEquation;
  30291. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  30292. exports.MixOperation = MixOperation;
  30293. exports.MultiMaterial = MultiMaterial;
  30294. exports.MultiplyBlending = MultiplyBlending;
  30295. exports.MultiplyOperation = MultiplyOperation;
  30296. exports.NearestFilter = NearestFilter;
  30297. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  30298. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  30299. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  30300. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  30301. exports.NeverDepth = NeverDepth;
  30302. exports.NeverStencilFunc = NeverStencilFunc;
  30303. exports.NoBlending = NoBlending;
  30304. exports.NoColors = NoColors;
  30305. exports.NoToneMapping = NoToneMapping;
  30306. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  30307. exports.NormalBlending = NormalBlending;
  30308. exports.NotEqualDepth = NotEqualDepth;
  30309. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  30310. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  30311. exports.Object3D = Object3D;
  30312. exports.ObjectLoader = ObjectLoader;
  30313. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  30314. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  30315. exports.OctahedronGeometry = OctahedronGeometry;
  30316. exports.OneFactor = OneFactor;
  30317. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  30318. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  30319. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  30320. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  30321. exports.OrthographicCamera = OrthographicCamera;
  30322. exports.PCFShadowMap = PCFShadowMap;
  30323. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  30324. exports.PMREMGenerator = PMREMGenerator;
  30325. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  30326. exports.ParametricGeometry = ParametricGeometry;
  30327. exports.Particle = Particle;
  30328. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  30329. exports.ParticleSystem = ParticleSystem;
  30330. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  30331. exports.Path = Path;
  30332. exports.PerspectiveCamera = PerspectiveCamera;
  30333. exports.Plane = Plane;
  30334. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  30335. exports.PlaneGeometry = PlaneGeometry;
  30336. exports.PlaneHelper = PlaneHelper;
  30337. exports.PointCloud = PointCloud;
  30338. exports.PointCloudMaterial = PointCloudMaterial;
  30339. exports.PointLight = PointLight;
  30340. exports.PointLightHelper = PointLightHelper;
  30341. exports.Points = Points;
  30342. exports.PointsMaterial = PointsMaterial;
  30343. exports.PolarGridHelper = PolarGridHelper;
  30344. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  30345. exports.PolyhedronGeometry = PolyhedronGeometry;
  30346. exports.PositionalAudio = PositionalAudio;
  30347. exports.PropertyBinding = PropertyBinding;
  30348. exports.PropertyMixer = PropertyMixer;
  30349. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  30350. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  30351. exports.Quaternion = Quaternion;
  30352. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  30353. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  30354. exports.REVISION = REVISION;
  30355. exports.RGBADepthPacking = RGBADepthPacking;
  30356. exports.RGBAFormat = RGBAFormat;
  30357. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  30358. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  30359. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  30360. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  30361. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  30362. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  30363. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  30364. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  30365. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  30366. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  30367. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  30368. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  30369. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  30370. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  30371. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  30372. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  30373. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  30374. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  30375. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  30376. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  30377. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  30378. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  30379. exports.RGBDEncoding = RGBDEncoding;
  30380. exports.RGBEEncoding = RGBEEncoding;
  30381. exports.RGBEFormat = RGBEFormat;
  30382. exports.RGBFormat = RGBFormat;
  30383. exports.RGBIntegerFormat = RGBIntegerFormat;
  30384. exports.RGBM16Encoding = RGBM16Encoding;
  30385. exports.RGBM7Encoding = RGBM7Encoding;
  30386. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  30387. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  30388. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  30389. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  30390. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  30391. exports.RGFormat = RGFormat;
  30392. exports.RGIntegerFormat = RGIntegerFormat;
  30393. exports.RawShaderMaterial = RawShaderMaterial;
  30394. exports.Ray = Ray;
  30395. exports.Raycaster = Raycaster;
  30396. exports.RectAreaLight = RectAreaLight;
  30397. exports.RedFormat = RedFormat;
  30398. exports.RedIntegerFormat = RedIntegerFormat;
  30399. exports.ReinhardToneMapping = ReinhardToneMapping;
  30400. exports.RepeatWrapping = RepeatWrapping;
  30401. exports.ReplaceStencilOp = ReplaceStencilOp;
  30402. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  30403. exports.RingBufferGeometry = RingBufferGeometry;
  30404. exports.RingGeometry = RingGeometry;
  30405. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  30406. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  30407. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  30408. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  30409. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  30410. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  30411. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  30412. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  30413. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  30414. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  30415. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  30416. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  30417. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  30418. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  30419. exports.Scene = Scene;
  30420. exports.SceneUtils = SceneUtils;
  30421. exports.ShaderChunk = ShaderChunk;
  30422. exports.ShaderLib = ShaderLib;
  30423. exports.ShaderMaterial = ShaderMaterial;
  30424. exports.ShadowMaterial = ShadowMaterial;
  30425. exports.Shape = Shape;
  30426. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  30427. exports.ShapeGeometry = ShapeGeometry;
  30428. exports.ShapePath = ShapePath;
  30429. exports.ShapeUtils = ShapeUtils;
  30430. exports.ShortType = ShortType;
  30431. exports.Skeleton = Skeleton;
  30432. exports.SkeletonHelper = SkeletonHelper;
  30433. exports.SkinnedMesh = SkinnedMesh;
  30434. exports.SmoothShading = SmoothShading;
  30435. exports.Sphere = Sphere;
  30436. exports.SphereBufferGeometry = SphereBufferGeometry;
  30437. exports.SphereGeometry = SphereGeometry;
  30438. exports.Spherical = Spherical;
  30439. exports.SphericalHarmonics3 = SphericalHarmonics3;
  30440. exports.Spline = Spline;
  30441. exports.SplineCurve = SplineCurve;
  30442. exports.SplineCurve3 = SplineCurve3;
  30443. exports.SpotLight = SpotLight;
  30444. exports.SpotLightHelper = SpotLightHelper;
  30445. exports.Sprite = Sprite;
  30446. exports.SpriteMaterial = SpriteMaterial;
  30447. exports.SrcAlphaFactor = SrcAlphaFactor;
  30448. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  30449. exports.SrcColorFactor = SrcColorFactor;
  30450. exports.StaticCopyUsage = StaticCopyUsage;
  30451. exports.StaticDrawUsage = StaticDrawUsage;
  30452. exports.StaticReadUsage = StaticReadUsage;
  30453. exports.StereoCamera = StereoCamera;
  30454. exports.StreamCopyUsage = StreamCopyUsage;
  30455. exports.StreamDrawUsage = StreamDrawUsage;
  30456. exports.StreamReadUsage = StreamReadUsage;
  30457. exports.StringKeyframeTrack = StringKeyframeTrack;
  30458. exports.SubtractEquation = SubtractEquation;
  30459. exports.SubtractiveBlending = SubtractiveBlending;
  30460. exports.TOUCH = TOUCH;
  30461. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  30462. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  30463. exports.TetrahedronGeometry = TetrahedronGeometry;
  30464. exports.TextBufferGeometry = TextBufferGeometry;
  30465. exports.TextGeometry = TextGeometry;
  30466. exports.Texture = Texture;
  30467. exports.TextureLoader = TextureLoader;
  30468. exports.TorusBufferGeometry = TorusBufferGeometry;
  30469. exports.TorusGeometry = TorusGeometry;
  30470. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  30471. exports.TorusKnotGeometry = TorusKnotGeometry;
  30472. exports.Triangle = Triangle;
  30473. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  30474. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  30475. exports.TrianglesDrawMode = TrianglesDrawMode;
  30476. exports.TubeBufferGeometry = TubeBufferGeometry;
  30477. exports.TubeGeometry = TubeGeometry;
  30478. exports.UVMapping = UVMapping;
  30479. exports.Uint16Attribute = Uint16Attribute;
  30480. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  30481. exports.Uint32Attribute = Uint32Attribute;
  30482. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  30483. exports.Uint8Attribute = Uint8Attribute;
  30484. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  30485. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  30486. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  30487. exports.Uniform = Uniform;
  30488. exports.UniformsLib = UniformsLib;
  30489. exports.UniformsUtils = UniformsUtils;
  30490. exports.UnsignedByteType = UnsignedByteType;
  30491. exports.UnsignedInt248Type = UnsignedInt248Type;
  30492. exports.UnsignedIntType = UnsignedIntType;
  30493. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  30494. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  30495. exports.UnsignedShort565Type = UnsignedShort565Type;
  30496. exports.UnsignedShortType = UnsignedShortType;
  30497. exports.VSMShadowMap = VSMShadowMap;
  30498. exports.Vector2 = Vector2;
  30499. exports.Vector3 = Vector3;
  30500. exports.Vector4 = Vector4;
  30501. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  30502. exports.Vertex = Vertex;
  30503. exports.VertexColors = VertexColors;
  30504. exports.VideoTexture = VideoTexture;
  30505. exports.WebGL1Renderer = WebGL1Renderer;
  30506. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  30507. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  30508. exports.WebGLRenderTarget = WebGLRenderTarget;
  30509. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  30510. exports.WebGLRenderer = WebGLRenderer;
  30511. exports.WebGLUtils = WebGLUtils;
  30512. exports.WireframeGeometry = WireframeGeometry;
  30513. exports.WireframeHelper = WireframeHelper;
  30514. exports.WrapAroundEnding = WrapAroundEnding;
  30515. exports.XHRLoader = XHRLoader;
  30516. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  30517. exports.ZeroFactor = ZeroFactor;
  30518. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  30519. exports.ZeroStencilOp = ZeroStencilOp;
  30520. exports.sRGBEncoding = sRGBEncoding;
  30521. Object.defineProperty(exports, '__esModule', { value: true });
  30522. })));