three.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325
  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 = '124';
  55. var MOUSE = {
  56. LEFT: 0,
  57. MIDDLE: 1,
  58. RIGHT: 2,
  59. ROTATE: 0,
  60. DOLLY: 1,
  61. PAN: 2
  62. };
  63. var TOUCH = {
  64. ROTATE: 0,
  65. PAN: 1,
  66. DOLLY_PAN: 2,
  67. DOLLY_ROTATE: 3
  68. };
  69. var CullFaceNone = 0;
  70. var CullFaceBack = 1;
  71. var CullFaceFront = 2;
  72. var CullFaceFrontBack = 3;
  73. var BasicShadowMap = 0;
  74. var PCFShadowMap = 1;
  75. var PCFSoftShadowMap = 2;
  76. var VSMShadowMap = 3;
  77. var FrontSide = 0;
  78. var BackSide = 1;
  79. var DoubleSide = 2;
  80. var FlatShading = 1;
  81. var SmoothShading = 2;
  82. var NoBlending = 0;
  83. var NormalBlending = 1;
  84. var AdditiveBlending = 2;
  85. var SubtractiveBlending = 3;
  86. var MultiplyBlending = 4;
  87. var CustomBlending = 5;
  88. var AddEquation = 100;
  89. var SubtractEquation = 101;
  90. var ReverseSubtractEquation = 102;
  91. var MinEquation = 103;
  92. var MaxEquation = 104;
  93. var ZeroFactor = 200;
  94. var OneFactor = 201;
  95. var SrcColorFactor = 202;
  96. var OneMinusSrcColorFactor = 203;
  97. var SrcAlphaFactor = 204;
  98. var OneMinusSrcAlphaFactor = 205;
  99. var DstAlphaFactor = 206;
  100. var OneMinusDstAlphaFactor = 207;
  101. var DstColorFactor = 208;
  102. var OneMinusDstColorFactor = 209;
  103. var SrcAlphaSaturateFactor = 210;
  104. var NeverDepth = 0;
  105. var AlwaysDepth = 1;
  106. var LessDepth = 2;
  107. var LessEqualDepth = 3;
  108. var EqualDepth = 4;
  109. var GreaterEqualDepth = 5;
  110. var GreaterDepth = 6;
  111. var NotEqualDepth = 7;
  112. var MultiplyOperation = 0;
  113. var MixOperation = 1;
  114. var AddOperation = 2;
  115. var NoToneMapping = 0;
  116. var LinearToneMapping = 1;
  117. var ReinhardToneMapping = 2;
  118. var CineonToneMapping = 3;
  119. var ACESFilmicToneMapping = 4;
  120. var CustomToneMapping = 5;
  121. var UVMapping = 300;
  122. var CubeReflectionMapping = 301;
  123. var CubeRefractionMapping = 302;
  124. var EquirectangularReflectionMapping = 303;
  125. var EquirectangularRefractionMapping = 304;
  126. var CubeUVReflectionMapping = 306;
  127. var CubeUVRefractionMapping = 307;
  128. var RepeatWrapping = 1000;
  129. var ClampToEdgeWrapping = 1001;
  130. var MirroredRepeatWrapping = 1002;
  131. var NearestFilter = 1003;
  132. var NearestMipmapNearestFilter = 1004;
  133. var NearestMipMapNearestFilter = 1004;
  134. var NearestMipmapLinearFilter = 1005;
  135. var NearestMipMapLinearFilter = 1005;
  136. var LinearFilter = 1006;
  137. var LinearMipmapNearestFilter = 1007;
  138. var LinearMipMapNearestFilter = 1007;
  139. var LinearMipmapLinearFilter = 1008;
  140. var LinearMipMapLinearFilter = 1008;
  141. var UnsignedByteType = 1009;
  142. var ByteType = 1010;
  143. var ShortType = 1011;
  144. var UnsignedShortType = 1012;
  145. var IntType = 1013;
  146. var UnsignedIntType = 1014;
  147. var FloatType = 1015;
  148. var HalfFloatType = 1016;
  149. var UnsignedShort4444Type = 1017;
  150. var UnsignedShort5551Type = 1018;
  151. var UnsignedShort565Type = 1019;
  152. var UnsignedInt248Type = 1020;
  153. var AlphaFormat = 1021;
  154. var RGBFormat = 1022;
  155. var RGBAFormat = 1023;
  156. var LuminanceFormat = 1024;
  157. var LuminanceAlphaFormat = 1025;
  158. var RGBEFormat = RGBAFormat;
  159. var DepthFormat = 1026;
  160. var DepthStencilFormat = 1027;
  161. var RedFormat = 1028;
  162. var RedIntegerFormat = 1029;
  163. var RGFormat = 1030;
  164. var RGIntegerFormat = 1031;
  165. var RGBIntegerFormat = 1032;
  166. var RGBAIntegerFormat = 1033;
  167. var RGB_S3TC_DXT1_Format = 33776;
  168. var RGBA_S3TC_DXT1_Format = 33777;
  169. var RGBA_S3TC_DXT3_Format = 33778;
  170. var RGBA_S3TC_DXT5_Format = 33779;
  171. var RGB_PVRTC_4BPPV1_Format = 35840;
  172. var RGB_PVRTC_2BPPV1_Format = 35841;
  173. var RGBA_PVRTC_4BPPV1_Format = 35842;
  174. var RGBA_PVRTC_2BPPV1_Format = 35843;
  175. var RGB_ETC1_Format = 36196;
  176. var RGB_ETC2_Format = 37492;
  177. var RGBA_ETC2_EAC_Format = 37496;
  178. var RGBA_ASTC_4x4_Format = 37808;
  179. var RGBA_ASTC_5x4_Format = 37809;
  180. var RGBA_ASTC_5x5_Format = 37810;
  181. var RGBA_ASTC_6x5_Format = 37811;
  182. var RGBA_ASTC_6x6_Format = 37812;
  183. var RGBA_ASTC_8x5_Format = 37813;
  184. var RGBA_ASTC_8x6_Format = 37814;
  185. var RGBA_ASTC_8x8_Format = 37815;
  186. var RGBA_ASTC_10x5_Format = 37816;
  187. var RGBA_ASTC_10x6_Format = 37817;
  188. var RGBA_ASTC_10x8_Format = 37818;
  189. var RGBA_ASTC_10x10_Format = 37819;
  190. var RGBA_ASTC_12x10_Format = 37820;
  191. var RGBA_ASTC_12x12_Format = 37821;
  192. var RGBA_BPTC_Format = 36492;
  193. var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  194. var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  195. var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  196. var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  197. var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  198. var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  199. var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  200. var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  201. var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  202. var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  203. var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  204. var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  205. var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  206. var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  207. var LoopOnce = 2200;
  208. var LoopRepeat = 2201;
  209. var LoopPingPong = 2202;
  210. var InterpolateDiscrete = 2300;
  211. var InterpolateLinear = 2301;
  212. var InterpolateSmooth = 2302;
  213. var ZeroCurvatureEnding = 2400;
  214. var ZeroSlopeEnding = 2401;
  215. var WrapAroundEnding = 2402;
  216. var NormalAnimationBlendMode = 2500;
  217. var AdditiveAnimationBlendMode = 2501;
  218. var TrianglesDrawMode = 0;
  219. var TriangleStripDrawMode = 1;
  220. var TriangleFanDrawMode = 2;
  221. var LinearEncoding = 3000;
  222. var sRGBEncoding = 3001;
  223. var GammaEncoding = 3007;
  224. var RGBEEncoding = 3002;
  225. var LogLuvEncoding = 3003;
  226. var RGBM7Encoding = 3004;
  227. var RGBM16Encoding = 3005;
  228. var RGBDEncoding = 3006;
  229. var BasicDepthPacking = 3200;
  230. var RGBADepthPacking = 3201;
  231. var TangentSpaceNormalMap = 0;
  232. var ObjectSpaceNormalMap = 1;
  233. var ZeroStencilOp = 0;
  234. var KeepStencilOp = 7680;
  235. var ReplaceStencilOp = 7681;
  236. var IncrementStencilOp = 7682;
  237. var DecrementStencilOp = 7683;
  238. var IncrementWrapStencilOp = 34055;
  239. var DecrementWrapStencilOp = 34056;
  240. var InvertStencilOp = 5386;
  241. var NeverStencilFunc = 512;
  242. var LessStencilFunc = 513;
  243. var EqualStencilFunc = 514;
  244. var LessEqualStencilFunc = 515;
  245. var GreaterStencilFunc = 516;
  246. var NotEqualStencilFunc = 517;
  247. var GreaterEqualStencilFunc = 518;
  248. var AlwaysStencilFunc = 519;
  249. var StaticDrawUsage = 35044;
  250. var DynamicDrawUsage = 35048;
  251. var StreamDrawUsage = 35040;
  252. var StaticReadUsage = 35045;
  253. var DynamicReadUsage = 35049;
  254. var StreamReadUsage = 35041;
  255. var StaticCopyUsage = 35046;
  256. var DynamicCopyUsage = 35050;
  257. var StreamCopyUsage = 35042;
  258. var GLSL1 = '100';
  259. var GLSL3 = '300 es';
  260. /**
  261. * https://github.com/mrdoob/eventdispatcher.js/
  262. */
  263. function EventDispatcher() {}
  264. Object.assign(EventDispatcher.prototype, {
  265. addEventListener: function addEventListener(type, listener) {
  266. if (this._listeners === undefined) this._listeners = {};
  267. var listeners = this._listeners;
  268. if (listeners[type] === undefined) {
  269. listeners[type] = [];
  270. }
  271. if (listeners[type].indexOf(listener) === -1) {
  272. listeners[type].push(listener);
  273. }
  274. },
  275. hasEventListener: function hasEventListener(type, listener) {
  276. if (this._listeners === undefined) return false;
  277. var listeners = this._listeners;
  278. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
  279. },
  280. removeEventListener: function removeEventListener(type, listener) {
  281. if (this._listeners === undefined) return;
  282. var listeners = this._listeners;
  283. var listenerArray = listeners[type];
  284. if (listenerArray !== undefined) {
  285. var index = listenerArray.indexOf(listener);
  286. if (index !== -1) {
  287. listenerArray.splice(index, 1);
  288. }
  289. }
  290. },
  291. dispatchEvent: function dispatchEvent(event) {
  292. if (this._listeners === undefined) return;
  293. var listeners = this._listeners;
  294. var listenerArray = listeners[event.type];
  295. if (listenerArray !== undefined) {
  296. event.target = this; // Make a copy, in case listeners are removed while iterating.
  297. var array = listenerArray.slice(0);
  298. for (var i = 0, l = array.length; i < l; i++) {
  299. array[i].call(this, event);
  300. }
  301. }
  302. }
  303. });
  304. var _lut = [];
  305. for (var i = 0; i < 256; i++) {
  306. _lut[i] = (i < 16 ? '0' : '') + i.toString(16);
  307. }
  308. var _seed = 1234567;
  309. var MathUtils = {
  310. DEG2RAD: Math.PI / 180,
  311. RAD2DEG: 180 / Math.PI,
  312. generateUUID: function generateUUID() {
  313. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  314. var d0 = Math.random() * 0xffffffff | 0;
  315. var d1 = Math.random() * 0xffffffff | 0;
  316. var d2 = Math.random() * 0xffffffff | 0;
  317. var d3 = Math.random() * 0xffffffff | 0;
  318. var uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' + _lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' + _lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] + _lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff]; // .toUpperCase() here flattens concatenated strings to save heap memory space.
  319. return uuid.toUpperCase();
  320. },
  321. clamp: function clamp(value, min, max) {
  322. return Math.max(min, Math.min(max, value));
  323. },
  324. // compute euclidian modulo of m % n
  325. // https://en.wikipedia.org/wiki/Modulo_operation
  326. euclideanModulo: function euclideanModulo(n, m) {
  327. return (n % m + m) % m;
  328. },
  329. // Linear mapping from range <a1, a2> to range <b1, b2>
  330. mapLinear: function mapLinear(x, a1, a2, b1, b2) {
  331. return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
  332. },
  333. // https://en.wikipedia.org/wiki/Linear_interpolation
  334. lerp: function lerp(x, y, t) {
  335. return (1 - t) * x + t * y;
  336. },
  337. // http://en.wikipedia.org/wiki/Smoothstep
  338. smoothstep: function smoothstep(x, min, max) {
  339. if (x <= min) return 0;
  340. if (x >= max) return 1;
  341. x = (x - min) / (max - min);
  342. return x * x * (3 - 2 * x);
  343. },
  344. smootherstep: function smootherstep(x, min, max) {
  345. if (x <= min) return 0;
  346. if (x >= max) return 1;
  347. x = (x - min) / (max - min);
  348. return x * x * x * (x * (x * 6 - 15) + 10);
  349. },
  350. // Random integer from <low, high> interval
  351. randInt: function randInt(low, high) {
  352. return low + Math.floor(Math.random() * (high - low + 1));
  353. },
  354. // Random float from <low, high> interval
  355. randFloat: function randFloat(low, high) {
  356. return low + Math.random() * (high - low);
  357. },
  358. // Random float from <-range/2, range/2> interval
  359. randFloatSpread: function randFloatSpread(range) {
  360. return range * (0.5 - Math.random());
  361. },
  362. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  363. seededRandom: function seededRandom(s) {
  364. if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
  365. _seed = _seed * 16807 % 2147483647;
  366. return (_seed - 1) / 2147483646;
  367. },
  368. degToRad: function degToRad(degrees) {
  369. return degrees * MathUtils.DEG2RAD;
  370. },
  371. radToDeg: function radToDeg(radians) {
  372. return radians * MathUtils.RAD2DEG;
  373. },
  374. isPowerOfTwo: function isPowerOfTwo(value) {
  375. return (value & value - 1) === 0 && value !== 0;
  376. },
  377. ceilPowerOfTwo: function ceilPowerOfTwo(value) {
  378. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  379. },
  380. floorPowerOfTwo: function floorPowerOfTwo(value) {
  381. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  382. },
  383. setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
  384. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  385. // rotations are applied to the axes in the order specified by 'order'
  386. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  387. // angles are in radians
  388. var cos = Math.cos;
  389. var sin = Math.sin;
  390. var c2 = cos(b / 2);
  391. var s2 = sin(b / 2);
  392. var c13 = cos((a + c) / 2);
  393. var s13 = sin((a + c) / 2);
  394. var c1_3 = cos((a - c) / 2);
  395. var s1_3 = sin((a - c) / 2);
  396. var c3_1 = cos((c - a) / 2);
  397. var s3_1 = sin((c - a) / 2);
  398. switch (order) {
  399. case 'XYX':
  400. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  401. break;
  402. case 'YZY':
  403. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  404. break;
  405. case 'ZXZ':
  406. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  407. break;
  408. case 'XZX':
  409. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  410. break;
  411. case 'YXY':
  412. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  413. break;
  414. case 'ZYZ':
  415. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  416. break;
  417. default:
  418. console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
  419. }
  420. }
  421. };
  422. function _defineProperties(target, props) {
  423. for (var i = 0; i < props.length; i++) {
  424. var descriptor = props[i];
  425. descriptor.enumerable = descriptor.enumerable || false;
  426. descriptor.configurable = true;
  427. if ("value" in descriptor) descriptor.writable = true;
  428. Object.defineProperty(target, descriptor.key, descriptor);
  429. }
  430. }
  431. function _createClass(Constructor, protoProps, staticProps) {
  432. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  433. if (staticProps) _defineProperties(Constructor, staticProps);
  434. return Constructor;
  435. }
  436. function _inheritsLoose(subClass, superClass) {
  437. subClass.prototype = Object.create(superClass.prototype);
  438. subClass.prototype.constructor = subClass;
  439. subClass.__proto__ = superClass;
  440. }
  441. function _assertThisInitialized(self) {
  442. if (self === void 0) {
  443. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  444. }
  445. return self;
  446. }
  447. var Vector2 = /*#__PURE__*/function () {
  448. function Vector2(x, y) {
  449. if (x === void 0) {
  450. x = 0;
  451. }
  452. if (y === void 0) {
  453. y = 0;
  454. }
  455. Object.defineProperty(this, 'isVector2', {
  456. value: true
  457. });
  458. this.x = x;
  459. this.y = y;
  460. }
  461. var _proto = Vector2.prototype;
  462. _proto.set = function set(x, y) {
  463. this.x = x;
  464. this.y = y;
  465. return this;
  466. };
  467. _proto.setScalar = function setScalar(scalar) {
  468. this.x = scalar;
  469. this.y = scalar;
  470. return this;
  471. };
  472. _proto.setX = function setX(x) {
  473. this.x = x;
  474. return this;
  475. };
  476. _proto.setY = function setY(y) {
  477. this.y = y;
  478. return this;
  479. };
  480. _proto.setComponent = function setComponent(index, value) {
  481. switch (index) {
  482. case 0:
  483. this.x = value;
  484. break;
  485. case 1:
  486. this.y = value;
  487. break;
  488. default:
  489. throw new Error('index is out of range: ' + index);
  490. }
  491. return this;
  492. };
  493. _proto.getComponent = function getComponent(index) {
  494. switch (index) {
  495. case 0:
  496. return this.x;
  497. case 1:
  498. return this.y;
  499. default:
  500. throw new Error('index is out of range: ' + index);
  501. }
  502. };
  503. _proto.clone = function clone() {
  504. return new this.constructor(this.x, this.y);
  505. };
  506. _proto.copy = function copy(v) {
  507. this.x = v.x;
  508. this.y = v.y;
  509. return this;
  510. };
  511. _proto.add = function add(v, w) {
  512. if (w !== undefined) {
  513. console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  514. return this.addVectors(v, w);
  515. }
  516. this.x += v.x;
  517. this.y += v.y;
  518. return this;
  519. };
  520. _proto.addScalar = function addScalar(s) {
  521. this.x += s;
  522. this.y += s;
  523. return this;
  524. };
  525. _proto.addVectors = function addVectors(a, b) {
  526. this.x = a.x + b.x;
  527. this.y = a.y + b.y;
  528. return this;
  529. };
  530. _proto.addScaledVector = function addScaledVector(v, s) {
  531. this.x += v.x * s;
  532. this.y += v.y * s;
  533. return this;
  534. };
  535. _proto.sub = function sub(v, w) {
  536. if (w !== undefined) {
  537. console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  538. return this.subVectors(v, w);
  539. }
  540. this.x -= v.x;
  541. this.y -= v.y;
  542. return this;
  543. };
  544. _proto.subScalar = function subScalar(s) {
  545. this.x -= s;
  546. this.y -= s;
  547. return this;
  548. };
  549. _proto.subVectors = function subVectors(a, b) {
  550. this.x = a.x - b.x;
  551. this.y = a.y - b.y;
  552. return this;
  553. };
  554. _proto.multiply = function multiply(v) {
  555. this.x *= v.x;
  556. this.y *= v.y;
  557. return this;
  558. };
  559. _proto.multiplyScalar = function multiplyScalar(scalar) {
  560. this.x *= scalar;
  561. this.y *= scalar;
  562. return this;
  563. };
  564. _proto.divide = function divide(v) {
  565. this.x /= v.x;
  566. this.y /= v.y;
  567. return this;
  568. };
  569. _proto.divideScalar = function divideScalar(scalar) {
  570. return this.multiplyScalar(1 / scalar);
  571. };
  572. _proto.applyMatrix3 = function applyMatrix3(m) {
  573. var x = this.x,
  574. y = this.y;
  575. var e = m.elements;
  576. this.x = e[0] * x + e[3] * y + e[6];
  577. this.y = e[1] * x + e[4] * y + e[7];
  578. return this;
  579. };
  580. _proto.min = function min(v) {
  581. this.x = Math.min(this.x, v.x);
  582. this.y = Math.min(this.y, v.y);
  583. return this;
  584. };
  585. _proto.max = function max(v) {
  586. this.x = Math.max(this.x, v.x);
  587. this.y = Math.max(this.y, v.y);
  588. return this;
  589. };
  590. _proto.clamp = function clamp(min, max) {
  591. // assumes min < max, componentwise
  592. this.x = Math.max(min.x, Math.min(max.x, this.x));
  593. this.y = Math.max(min.y, Math.min(max.y, this.y));
  594. return this;
  595. };
  596. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  597. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  598. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  599. return this;
  600. };
  601. _proto.clampLength = function clampLength(min, max) {
  602. var length = this.length();
  603. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  604. };
  605. _proto.floor = function floor() {
  606. this.x = Math.floor(this.x);
  607. this.y = Math.floor(this.y);
  608. return this;
  609. };
  610. _proto.ceil = function ceil() {
  611. this.x = Math.ceil(this.x);
  612. this.y = Math.ceil(this.y);
  613. return this;
  614. };
  615. _proto.round = function round() {
  616. this.x = Math.round(this.x);
  617. this.y = Math.round(this.y);
  618. return this;
  619. };
  620. _proto.roundToZero = function roundToZero() {
  621. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  622. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  623. return this;
  624. };
  625. _proto.negate = function negate() {
  626. this.x = -this.x;
  627. this.y = -this.y;
  628. return this;
  629. };
  630. _proto.dot = function dot(v) {
  631. return this.x * v.x + this.y * v.y;
  632. };
  633. _proto.cross = function cross(v) {
  634. return this.x * v.y - this.y * v.x;
  635. };
  636. _proto.lengthSq = function lengthSq() {
  637. return this.x * this.x + this.y * this.y;
  638. };
  639. _proto.length = function length() {
  640. return Math.sqrt(this.x * this.x + this.y * this.y);
  641. };
  642. _proto.manhattanLength = function manhattanLength() {
  643. return Math.abs(this.x) + Math.abs(this.y);
  644. };
  645. _proto.normalize = function normalize() {
  646. return this.divideScalar(this.length() || 1);
  647. };
  648. _proto.angle = function angle() {
  649. // computes the angle in radians with respect to the positive x-axis
  650. var angle = Math.atan2(-this.y, -this.x) + Math.PI;
  651. return angle;
  652. };
  653. _proto.distanceTo = function distanceTo(v) {
  654. return Math.sqrt(this.distanceToSquared(v));
  655. };
  656. _proto.distanceToSquared = function distanceToSquared(v) {
  657. var dx = this.x - v.x,
  658. dy = this.y - v.y;
  659. return dx * dx + dy * dy;
  660. };
  661. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  662. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
  663. };
  664. _proto.setLength = function setLength(length) {
  665. return this.normalize().multiplyScalar(length);
  666. };
  667. _proto.lerp = function lerp(v, alpha) {
  668. this.x += (v.x - this.x) * alpha;
  669. this.y += (v.y - this.y) * alpha;
  670. return this;
  671. };
  672. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  673. this.x = v1.x + (v2.x - v1.x) * alpha;
  674. this.y = v1.y + (v2.y - v1.y) * alpha;
  675. return this;
  676. };
  677. _proto.equals = function equals(v) {
  678. return v.x === this.x && v.y === this.y;
  679. };
  680. _proto.fromArray = function fromArray(array, offset) {
  681. if (offset === void 0) {
  682. offset = 0;
  683. }
  684. this.x = array[offset];
  685. this.y = array[offset + 1];
  686. return this;
  687. };
  688. _proto.toArray = function toArray(array, offset) {
  689. if (array === void 0) {
  690. array = [];
  691. }
  692. if (offset === void 0) {
  693. offset = 0;
  694. }
  695. array[offset] = this.x;
  696. array[offset + 1] = this.y;
  697. return array;
  698. };
  699. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  700. if (offset !== undefined) {
  701. console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
  702. }
  703. this.x = attribute.getX(index);
  704. this.y = attribute.getY(index);
  705. return this;
  706. };
  707. _proto.rotateAround = function rotateAround(center, angle) {
  708. var c = Math.cos(angle),
  709. s = Math.sin(angle);
  710. var x = this.x - center.x;
  711. var y = this.y - center.y;
  712. this.x = x * c - y * s + center.x;
  713. this.y = x * s + y * c + center.y;
  714. return this;
  715. };
  716. _proto.random = function random() {
  717. this.x = Math.random();
  718. this.y = Math.random();
  719. return this;
  720. };
  721. _createClass(Vector2, [{
  722. key: "width",
  723. get: function get() {
  724. return this.x;
  725. },
  726. set: function set(value) {
  727. this.x = value;
  728. }
  729. }, {
  730. key: "height",
  731. get: function get() {
  732. return this.y;
  733. },
  734. set: function set(value) {
  735. this.y = value;
  736. }
  737. }]);
  738. return Vector2;
  739. }();
  740. var Matrix3 = /*#__PURE__*/function () {
  741. function Matrix3() {
  742. Object.defineProperty(this, 'isMatrix3', {
  743. value: true
  744. });
  745. this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  746. if (arguments.length > 0) {
  747. console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
  748. }
  749. }
  750. var _proto = Matrix3.prototype;
  751. _proto.set = function set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
  752. var te = this.elements;
  753. te[0] = n11;
  754. te[1] = n21;
  755. te[2] = n31;
  756. te[3] = n12;
  757. te[4] = n22;
  758. te[5] = n32;
  759. te[6] = n13;
  760. te[7] = n23;
  761. te[8] = n33;
  762. return this;
  763. };
  764. _proto.identity = function identity() {
  765. this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
  766. return this;
  767. };
  768. _proto.clone = function clone() {
  769. return new this.constructor().fromArray(this.elements);
  770. };
  771. _proto.copy = function copy(m) {
  772. var te = this.elements;
  773. var me = m.elements;
  774. te[0] = me[0];
  775. te[1] = me[1];
  776. te[2] = me[2];
  777. te[3] = me[3];
  778. te[4] = me[4];
  779. te[5] = me[5];
  780. te[6] = me[6];
  781. te[7] = me[7];
  782. te[8] = me[8];
  783. return this;
  784. };
  785. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  786. xAxis.setFromMatrix3Column(this, 0);
  787. yAxis.setFromMatrix3Column(this, 1);
  788. zAxis.setFromMatrix3Column(this, 2);
  789. return this;
  790. };
  791. _proto.setFromMatrix4 = function setFromMatrix4(m) {
  792. var me = m.elements;
  793. this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
  794. return this;
  795. };
  796. _proto.multiply = function multiply(m) {
  797. return this.multiplyMatrices(this, m);
  798. };
  799. _proto.premultiply = function premultiply(m) {
  800. return this.multiplyMatrices(m, this);
  801. };
  802. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  803. var ae = a.elements;
  804. var be = b.elements;
  805. var te = this.elements;
  806. var a11 = ae[0],
  807. a12 = ae[3],
  808. a13 = ae[6];
  809. var a21 = ae[1],
  810. a22 = ae[4],
  811. a23 = ae[7];
  812. var a31 = ae[2],
  813. a32 = ae[5],
  814. a33 = ae[8];
  815. var b11 = be[0],
  816. b12 = be[3],
  817. b13 = be[6];
  818. var b21 = be[1],
  819. b22 = be[4],
  820. b23 = be[7];
  821. var b31 = be[2],
  822. b32 = be[5],
  823. b33 = be[8];
  824. te[0] = a11 * b11 + a12 * b21 + a13 * b31;
  825. te[3] = a11 * b12 + a12 * b22 + a13 * b32;
  826. te[6] = a11 * b13 + a12 * b23 + a13 * b33;
  827. te[1] = a21 * b11 + a22 * b21 + a23 * b31;
  828. te[4] = a21 * b12 + a22 * b22 + a23 * b32;
  829. te[7] = a21 * b13 + a22 * b23 + a23 * b33;
  830. te[2] = a31 * b11 + a32 * b21 + a33 * b31;
  831. te[5] = a31 * b12 + a32 * b22 + a33 * b32;
  832. te[8] = a31 * b13 + a32 * b23 + a33 * b33;
  833. return this;
  834. };
  835. _proto.multiplyScalar = function multiplyScalar(s) {
  836. var te = this.elements;
  837. te[0] *= s;
  838. te[3] *= s;
  839. te[6] *= s;
  840. te[1] *= s;
  841. te[4] *= s;
  842. te[7] *= s;
  843. te[2] *= s;
  844. te[5] *= s;
  845. te[8] *= s;
  846. return this;
  847. };
  848. _proto.determinant = function determinant() {
  849. var te = this.elements;
  850. var a = te[0],
  851. b = te[1],
  852. c = te[2],
  853. d = te[3],
  854. e = te[4],
  855. f = te[5],
  856. g = te[6],
  857. h = te[7],
  858. i = te[8];
  859. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  860. };
  861. _proto.invert = function invert() {
  862. var te = this.elements,
  863. n11 = te[0],
  864. n21 = te[1],
  865. n31 = te[2],
  866. n12 = te[3],
  867. n22 = te[4],
  868. n32 = te[5],
  869. n13 = te[6],
  870. n23 = te[7],
  871. n33 = te[8],
  872. t11 = n33 * n22 - n32 * n23,
  873. t12 = n32 * n13 - n33 * n12,
  874. t13 = n23 * n12 - n22 * n13,
  875. det = n11 * t11 + n21 * t12 + n31 * t13;
  876. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  877. var detInv = 1 / det;
  878. te[0] = t11 * detInv;
  879. te[1] = (n31 * n23 - n33 * n21) * detInv;
  880. te[2] = (n32 * n21 - n31 * n22) * detInv;
  881. te[3] = t12 * detInv;
  882. te[4] = (n33 * n11 - n31 * n13) * detInv;
  883. te[5] = (n31 * n12 - n32 * n11) * detInv;
  884. te[6] = t13 * detInv;
  885. te[7] = (n21 * n13 - n23 * n11) * detInv;
  886. te[8] = (n22 * n11 - n21 * n12) * detInv;
  887. return this;
  888. };
  889. _proto.transpose = function transpose() {
  890. var tmp;
  891. var m = this.elements;
  892. tmp = m[1];
  893. m[1] = m[3];
  894. m[3] = tmp;
  895. tmp = m[2];
  896. m[2] = m[6];
  897. m[6] = tmp;
  898. tmp = m[5];
  899. m[5] = m[7];
  900. m[7] = tmp;
  901. return this;
  902. };
  903. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  904. return this.setFromMatrix4(matrix4).copy(this).invert().transpose();
  905. };
  906. _proto.transposeIntoArray = function transposeIntoArray(r) {
  907. var m = this.elements;
  908. r[0] = m[0];
  909. r[1] = m[3];
  910. r[2] = m[6];
  911. r[3] = m[1];
  912. r[4] = m[4];
  913. r[5] = m[7];
  914. r[6] = m[2];
  915. r[7] = m[5];
  916. r[8] = m[8];
  917. return this;
  918. };
  919. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  920. var c = Math.cos(rotation);
  921. var s = Math.sin(rotation);
  922. this.set(sx * c, sx * s, -sx * (c * cx + s * cy) + cx + tx, -sy * s, sy * c, -sy * (-s * cx + c * cy) + cy + ty, 0, 0, 1);
  923. return this;
  924. };
  925. _proto.scale = function scale(sx, sy) {
  926. var te = this.elements;
  927. te[0] *= sx;
  928. te[3] *= sx;
  929. te[6] *= sx;
  930. te[1] *= sy;
  931. te[4] *= sy;
  932. te[7] *= sy;
  933. return this;
  934. };
  935. _proto.rotate = function rotate(theta) {
  936. var c = Math.cos(theta);
  937. var s = Math.sin(theta);
  938. var te = this.elements;
  939. var a11 = te[0],
  940. a12 = te[3],
  941. a13 = te[6];
  942. var a21 = te[1],
  943. a22 = te[4],
  944. a23 = te[7];
  945. te[0] = c * a11 + s * a21;
  946. te[3] = c * a12 + s * a22;
  947. te[6] = c * a13 + s * a23;
  948. te[1] = -s * a11 + c * a21;
  949. te[4] = -s * a12 + c * a22;
  950. te[7] = -s * a13 + c * a23;
  951. return this;
  952. };
  953. _proto.translate = function translate(tx, ty) {
  954. var te = this.elements;
  955. te[0] += tx * te[2];
  956. te[3] += tx * te[5];
  957. te[6] += tx * te[8];
  958. te[1] += ty * te[2];
  959. te[4] += ty * te[5];
  960. te[7] += ty * te[8];
  961. return this;
  962. };
  963. _proto.equals = function equals(matrix) {
  964. var te = this.elements;
  965. var me = matrix.elements;
  966. for (var i = 0; i < 9; i++) {
  967. if (te[i] !== me[i]) return false;
  968. }
  969. return true;
  970. };
  971. _proto.fromArray = function fromArray(array, offset) {
  972. if (offset === void 0) {
  973. offset = 0;
  974. }
  975. for (var i = 0; i < 9; i++) {
  976. this.elements[i] = array[i + offset];
  977. }
  978. return this;
  979. };
  980. _proto.toArray = function toArray(array, offset) {
  981. if (array === void 0) {
  982. array = [];
  983. }
  984. if (offset === void 0) {
  985. offset = 0;
  986. }
  987. var te = this.elements;
  988. array[offset] = te[0];
  989. array[offset + 1] = te[1];
  990. array[offset + 2] = te[2];
  991. array[offset + 3] = te[3];
  992. array[offset + 4] = te[4];
  993. array[offset + 5] = te[5];
  994. array[offset + 6] = te[6];
  995. array[offset + 7] = te[7];
  996. array[offset + 8] = te[8];
  997. return array;
  998. };
  999. return Matrix3;
  1000. }();
  1001. var _canvas;
  1002. var ImageUtils = {
  1003. getDataURL: function getDataURL(image) {
  1004. if (/^data:/i.test(image.src)) {
  1005. return image.src;
  1006. }
  1007. if (typeof HTMLCanvasElement == 'undefined') {
  1008. return image.src;
  1009. }
  1010. var canvas;
  1011. if (image instanceof HTMLCanvasElement) {
  1012. canvas = image;
  1013. } else {
  1014. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1015. _canvas.width = image.width;
  1016. _canvas.height = image.height;
  1017. var context = _canvas.getContext('2d');
  1018. if (image instanceof ImageData) {
  1019. context.putImageData(image, 0, 0);
  1020. } else {
  1021. context.drawImage(image, 0, 0, image.width, image.height);
  1022. }
  1023. canvas = _canvas;
  1024. }
  1025. if (canvas.width > 2048 || canvas.height > 2048) {
  1026. return canvas.toDataURL('image/jpeg', 0.6);
  1027. } else {
  1028. return canvas.toDataURL('image/png');
  1029. }
  1030. }
  1031. };
  1032. var textureId = 0;
  1033. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1034. if (image === void 0) {
  1035. image = Texture.DEFAULT_IMAGE;
  1036. }
  1037. if (mapping === void 0) {
  1038. mapping = Texture.DEFAULT_MAPPING;
  1039. }
  1040. if (wrapS === void 0) {
  1041. wrapS = ClampToEdgeWrapping;
  1042. }
  1043. if (wrapT === void 0) {
  1044. wrapT = ClampToEdgeWrapping;
  1045. }
  1046. if (magFilter === void 0) {
  1047. magFilter = LinearFilter;
  1048. }
  1049. if (minFilter === void 0) {
  1050. minFilter = LinearMipmapLinearFilter;
  1051. }
  1052. if (format === void 0) {
  1053. format = RGBAFormat;
  1054. }
  1055. if (type === void 0) {
  1056. type = UnsignedByteType;
  1057. }
  1058. if (anisotropy === void 0) {
  1059. anisotropy = 1;
  1060. }
  1061. if (encoding === void 0) {
  1062. encoding = LinearEncoding;
  1063. }
  1064. Object.defineProperty(this, 'id', {
  1065. value: textureId++
  1066. });
  1067. this.uuid = MathUtils.generateUUID();
  1068. this.name = '';
  1069. this.image = image;
  1070. this.mipmaps = [];
  1071. this.mapping = mapping;
  1072. this.wrapS = wrapS;
  1073. this.wrapT = wrapT;
  1074. this.magFilter = magFilter;
  1075. this.minFilter = minFilter;
  1076. this.anisotropy = anisotropy;
  1077. this.format = format;
  1078. this.internalFormat = null;
  1079. this.type = type;
  1080. this.offset = new Vector2(0, 0);
  1081. this.repeat = new Vector2(1, 1);
  1082. this.center = new Vector2(0, 0);
  1083. this.rotation = 0;
  1084. this.matrixAutoUpdate = true;
  1085. this.matrix = new Matrix3();
  1086. this.generateMipmaps = true;
  1087. this.premultiplyAlpha = false;
  1088. this.flipY = true;
  1089. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1090. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1091. //
  1092. // Also changing the encoding after already used by a Material will not automatically make the Material
  1093. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1094. this.encoding = encoding;
  1095. this.version = 0;
  1096. this.onUpdate = null;
  1097. }
  1098. Texture.DEFAULT_IMAGE = undefined;
  1099. Texture.DEFAULT_MAPPING = UVMapping;
  1100. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1101. constructor: Texture,
  1102. isTexture: true,
  1103. updateMatrix: function updateMatrix() {
  1104. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1105. },
  1106. clone: function clone() {
  1107. return new this.constructor().copy(this);
  1108. },
  1109. copy: function copy(source) {
  1110. this.name = source.name;
  1111. this.image = source.image;
  1112. this.mipmaps = source.mipmaps.slice(0);
  1113. this.mapping = source.mapping;
  1114. this.wrapS = source.wrapS;
  1115. this.wrapT = source.wrapT;
  1116. this.magFilter = source.magFilter;
  1117. this.minFilter = source.minFilter;
  1118. this.anisotropy = source.anisotropy;
  1119. this.format = source.format;
  1120. this.internalFormat = source.internalFormat;
  1121. this.type = source.type;
  1122. this.offset.copy(source.offset);
  1123. this.repeat.copy(source.repeat);
  1124. this.center.copy(source.center);
  1125. this.rotation = source.rotation;
  1126. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1127. this.matrix.copy(source.matrix);
  1128. this.generateMipmaps = source.generateMipmaps;
  1129. this.premultiplyAlpha = source.premultiplyAlpha;
  1130. this.flipY = source.flipY;
  1131. this.unpackAlignment = source.unpackAlignment;
  1132. this.encoding = source.encoding;
  1133. return this;
  1134. },
  1135. toJSON: function toJSON(meta) {
  1136. var isRootObject = meta === undefined || typeof meta === 'string';
  1137. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1138. return meta.textures[this.uuid];
  1139. }
  1140. var output = {
  1141. metadata: {
  1142. version: 4.5,
  1143. type: 'Texture',
  1144. generator: 'Texture.toJSON'
  1145. },
  1146. uuid: this.uuid,
  1147. name: this.name,
  1148. mapping: this.mapping,
  1149. repeat: [this.repeat.x, this.repeat.y],
  1150. offset: [this.offset.x, this.offset.y],
  1151. center: [this.center.x, this.center.y],
  1152. rotation: this.rotation,
  1153. wrap: [this.wrapS, this.wrapT],
  1154. format: this.format,
  1155. type: this.type,
  1156. encoding: this.encoding,
  1157. minFilter: this.minFilter,
  1158. magFilter: this.magFilter,
  1159. anisotropy: this.anisotropy,
  1160. flipY: this.flipY,
  1161. premultiplyAlpha: this.premultiplyAlpha,
  1162. unpackAlignment: this.unpackAlignment
  1163. };
  1164. if (this.image !== undefined) {
  1165. // TODO: Move to THREE.Image
  1166. var image = this.image;
  1167. if (image.uuid === undefined) {
  1168. image.uuid = MathUtils.generateUUID(); // UGH
  1169. }
  1170. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1171. var url;
  1172. if (Array.isArray(image)) {
  1173. // process array of images e.g. CubeTexture
  1174. url = [];
  1175. for (var i = 0, l = image.length; i < l; i++) {
  1176. // check cube texture with data textures
  1177. if (image[i].isDataTexture) {
  1178. url.push(serializeImage(image[i].image));
  1179. } else {
  1180. url.push(serializeImage(image[i]));
  1181. }
  1182. }
  1183. } else {
  1184. // process single image
  1185. url = serializeImage(image);
  1186. }
  1187. meta.images[image.uuid] = {
  1188. uuid: image.uuid,
  1189. url: url
  1190. };
  1191. }
  1192. output.image = image.uuid;
  1193. }
  1194. if (!isRootObject) {
  1195. meta.textures[this.uuid] = output;
  1196. }
  1197. return output;
  1198. },
  1199. dispose: function dispose() {
  1200. this.dispatchEvent({
  1201. type: 'dispose'
  1202. });
  1203. },
  1204. transformUv: function transformUv(uv) {
  1205. if (this.mapping !== UVMapping) return uv;
  1206. uv.applyMatrix3(this.matrix);
  1207. if (uv.x < 0 || uv.x > 1) {
  1208. switch (this.wrapS) {
  1209. case RepeatWrapping:
  1210. uv.x = uv.x - Math.floor(uv.x);
  1211. break;
  1212. case ClampToEdgeWrapping:
  1213. uv.x = uv.x < 0 ? 0 : 1;
  1214. break;
  1215. case MirroredRepeatWrapping:
  1216. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1217. uv.x = Math.ceil(uv.x) - uv.x;
  1218. } else {
  1219. uv.x = uv.x - Math.floor(uv.x);
  1220. }
  1221. break;
  1222. }
  1223. }
  1224. if (uv.y < 0 || uv.y > 1) {
  1225. switch (this.wrapT) {
  1226. case RepeatWrapping:
  1227. uv.y = uv.y - Math.floor(uv.y);
  1228. break;
  1229. case ClampToEdgeWrapping:
  1230. uv.y = uv.y < 0 ? 0 : 1;
  1231. break;
  1232. case MirroredRepeatWrapping:
  1233. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1234. uv.y = Math.ceil(uv.y) - uv.y;
  1235. } else {
  1236. uv.y = uv.y - Math.floor(uv.y);
  1237. }
  1238. break;
  1239. }
  1240. }
  1241. if (this.flipY) {
  1242. uv.y = 1 - uv.y;
  1243. }
  1244. return uv;
  1245. }
  1246. });
  1247. Object.defineProperty(Texture.prototype, 'needsUpdate', {
  1248. set: function set(value) {
  1249. if (value === true) this.version++;
  1250. }
  1251. });
  1252. function serializeImage(image) {
  1253. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  1254. // default images
  1255. return ImageUtils.getDataURL(image);
  1256. } else {
  1257. if (image.data) {
  1258. // images of DataTexture
  1259. return {
  1260. data: Array.prototype.slice.call(image.data),
  1261. width: image.width,
  1262. height: image.height,
  1263. type: image.data.constructor.name
  1264. };
  1265. } else {
  1266. console.warn('THREE.Texture: Unable to serialize Texture.');
  1267. return {};
  1268. }
  1269. }
  1270. }
  1271. var Vector4 = /*#__PURE__*/function () {
  1272. function Vector4(x, y, z, w) {
  1273. if (x === void 0) {
  1274. x = 0;
  1275. }
  1276. if (y === void 0) {
  1277. y = 0;
  1278. }
  1279. if (z === void 0) {
  1280. z = 0;
  1281. }
  1282. if (w === void 0) {
  1283. w = 1;
  1284. }
  1285. Object.defineProperty(this, 'isVector4', {
  1286. value: true
  1287. });
  1288. this.x = x;
  1289. this.y = y;
  1290. this.z = z;
  1291. this.w = w;
  1292. }
  1293. var _proto = Vector4.prototype;
  1294. _proto.set = function set(x, y, z, w) {
  1295. this.x = x;
  1296. this.y = y;
  1297. this.z = z;
  1298. this.w = w;
  1299. return this;
  1300. };
  1301. _proto.setScalar = function setScalar(scalar) {
  1302. this.x = scalar;
  1303. this.y = scalar;
  1304. this.z = scalar;
  1305. this.w = scalar;
  1306. return this;
  1307. };
  1308. _proto.setX = function setX(x) {
  1309. this.x = x;
  1310. return this;
  1311. };
  1312. _proto.setY = function setY(y) {
  1313. this.y = y;
  1314. return this;
  1315. };
  1316. _proto.setZ = function setZ(z) {
  1317. this.z = z;
  1318. return this;
  1319. };
  1320. _proto.setW = function setW(w) {
  1321. this.w = w;
  1322. return this;
  1323. };
  1324. _proto.setComponent = function setComponent(index, value) {
  1325. switch (index) {
  1326. case 0:
  1327. this.x = value;
  1328. break;
  1329. case 1:
  1330. this.y = value;
  1331. break;
  1332. case 2:
  1333. this.z = value;
  1334. break;
  1335. case 3:
  1336. this.w = value;
  1337. break;
  1338. default:
  1339. throw new Error('index is out of range: ' + index);
  1340. }
  1341. return this;
  1342. };
  1343. _proto.getComponent = function getComponent(index) {
  1344. switch (index) {
  1345. case 0:
  1346. return this.x;
  1347. case 1:
  1348. return this.y;
  1349. case 2:
  1350. return this.z;
  1351. case 3:
  1352. return this.w;
  1353. default:
  1354. throw new Error('index is out of range: ' + index);
  1355. }
  1356. };
  1357. _proto.clone = function clone() {
  1358. return new this.constructor(this.x, this.y, this.z, this.w);
  1359. };
  1360. _proto.copy = function copy(v) {
  1361. this.x = v.x;
  1362. this.y = v.y;
  1363. this.z = v.z;
  1364. this.w = v.w !== undefined ? v.w : 1;
  1365. return this;
  1366. };
  1367. _proto.add = function add(v, w) {
  1368. if (w !== undefined) {
  1369. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1370. return this.addVectors(v, w);
  1371. }
  1372. this.x += v.x;
  1373. this.y += v.y;
  1374. this.z += v.z;
  1375. this.w += v.w;
  1376. return this;
  1377. };
  1378. _proto.addScalar = function addScalar(s) {
  1379. this.x += s;
  1380. this.y += s;
  1381. this.z += s;
  1382. this.w += s;
  1383. return this;
  1384. };
  1385. _proto.addVectors = function addVectors(a, b) {
  1386. this.x = a.x + b.x;
  1387. this.y = a.y + b.y;
  1388. this.z = a.z + b.z;
  1389. this.w = a.w + b.w;
  1390. return this;
  1391. };
  1392. _proto.addScaledVector = function addScaledVector(v, s) {
  1393. this.x += v.x * s;
  1394. this.y += v.y * s;
  1395. this.z += v.z * s;
  1396. this.w += v.w * s;
  1397. return this;
  1398. };
  1399. _proto.sub = function sub(v, w) {
  1400. if (w !== undefined) {
  1401. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1402. return this.subVectors(v, w);
  1403. }
  1404. this.x -= v.x;
  1405. this.y -= v.y;
  1406. this.z -= v.z;
  1407. this.w -= v.w;
  1408. return this;
  1409. };
  1410. _proto.subScalar = function subScalar(s) {
  1411. this.x -= s;
  1412. this.y -= s;
  1413. this.z -= s;
  1414. this.w -= s;
  1415. return this;
  1416. };
  1417. _proto.subVectors = function subVectors(a, b) {
  1418. this.x = a.x - b.x;
  1419. this.y = a.y - b.y;
  1420. this.z = a.z - b.z;
  1421. this.w = a.w - b.w;
  1422. return this;
  1423. };
  1424. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1425. this.x *= scalar;
  1426. this.y *= scalar;
  1427. this.z *= scalar;
  1428. this.w *= scalar;
  1429. return this;
  1430. };
  1431. _proto.applyMatrix4 = function applyMatrix4(m) {
  1432. var x = this.x,
  1433. y = this.y,
  1434. z = this.z,
  1435. w = this.w;
  1436. var e = m.elements;
  1437. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  1438. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  1439. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  1440. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  1441. return this;
  1442. };
  1443. _proto.divideScalar = function divideScalar(scalar) {
  1444. return this.multiplyScalar(1 / scalar);
  1445. };
  1446. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  1447. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1448. // q is assumed to be normalized
  1449. this.w = 2 * Math.acos(q.w);
  1450. var s = Math.sqrt(1 - q.w * q.w);
  1451. if (s < 0.0001) {
  1452. this.x = 1;
  1453. this.y = 0;
  1454. this.z = 0;
  1455. } else {
  1456. this.x = q.x / s;
  1457. this.y = q.y / s;
  1458. this.z = q.z / s;
  1459. }
  1460. return this;
  1461. };
  1462. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  1463. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1464. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1465. var angle, x, y, z; // variables for result
  1466. var epsilon = 0.01,
  1467. // margin to allow for rounding errors
  1468. epsilon2 = 0.1,
  1469. // margin to distinguish between 0 and 180 degrees
  1470. te = m.elements,
  1471. m11 = te[0],
  1472. m12 = te[4],
  1473. m13 = te[8],
  1474. m21 = te[1],
  1475. m22 = te[5],
  1476. m23 = te[9],
  1477. m31 = te[2],
  1478. m32 = te[6],
  1479. m33 = te[10];
  1480. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  1481. // singularity found
  1482. // first check for identity matrix which must have +1 for all terms
  1483. // in leading diagonal and zero in other terms
  1484. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  1485. // this singularity is identity matrix so angle = 0
  1486. this.set(1, 0, 0, 0);
  1487. return this; // zero angle, arbitrary axis
  1488. } // otherwise this singularity is angle = 180
  1489. angle = Math.PI;
  1490. var xx = (m11 + 1) / 2;
  1491. var yy = (m22 + 1) / 2;
  1492. var zz = (m33 + 1) / 2;
  1493. var xy = (m12 + m21) / 4;
  1494. var xz = (m13 + m31) / 4;
  1495. var yz = (m23 + m32) / 4;
  1496. if (xx > yy && xx > zz) {
  1497. // m11 is the largest diagonal term
  1498. if (xx < epsilon) {
  1499. x = 0;
  1500. y = 0.707106781;
  1501. z = 0.707106781;
  1502. } else {
  1503. x = Math.sqrt(xx);
  1504. y = xy / x;
  1505. z = xz / x;
  1506. }
  1507. } else if (yy > zz) {
  1508. // m22 is the largest diagonal term
  1509. if (yy < epsilon) {
  1510. x = 0.707106781;
  1511. y = 0;
  1512. z = 0.707106781;
  1513. } else {
  1514. y = Math.sqrt(yy);
  1515. x = xy / y;
  1516. z = yz / y;
  1517. }
  1518. } else {
  1519. // m33 is the largest diagonal term so base result on this
  1520. if (zz < epsilon) {
  1521. x = 0.707106781;
  1522. y = 0.707106781;
  1523. z = 0;
  1524. } else {
  1525. z = Math.sqrt(zz);
  1526. x = xz / z;
  1527. y = yz / z;
  1528. }
  1529. }
  1530. this.set(x, y, z, angle);
  1531. return this; // return 180 deg rotation
  1532. } // as we have reached here there are no singularities so we can handle normally
  1533. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  1534. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1535. // caught by singularity test above, but I've left it in just in case
  1536. this.x = (m32 - m23) / s;
  1537. this.y = (m13 - m31) / s;
  1538. this.z = (m21 - m12) / s;
  1539. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  1540. return this;
  1541. };
  1542. _proto.min = function min(v) {
  1543. this.x = Math.min(this.x, v.x);
  1544. this.y = Math.min(this.y, v.y);
  1545. this.z = Math.min(this.z, v.z);
  1546. this.w = Math.min(this.w, v.w);
  1547. return this;
  1548. };
  1549. _proto.max = function max(v) {
  1550. this.x = Math.max(this.x, v.x);
  1551. this.y = Math.max(this.y, v.y);
  1552. this.z = Math.max(this.z, v.z);
  1553. this.w = Math.max(this.w, v.w);
  1554. return this;
  1555. };
  1556. _proto.clamp = function clamp(min, max) {
  1557. // assumes min < max, componentwise
  1558. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1559. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1560. this.z = Math.max(min.z, Math.min(max.z, this.z));
  1561. this.w = Math.max(min.w, Math.min(max.w, this.w));
  1562. return this;
  1563. };
  1564. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1565. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1566. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1567. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  1568. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  1569. return this;
  1570. };
  1571. _proto.clampLength = function clampLength(min, max) {
  1572. var length = this.length();
  1573. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1574. };
  1575. _proto.floor = function floor() {
  1576. this.x = Math.floor(this.x);
  1577. this.y = Math.floor(this.y);
  1578. this.z = Math.floor(this.z);
  1579. this.w = Math.floor(this.w);
  1580. return this;
  1581. };
  1582. _proto.ceil = function ceil() {
  1583. this.x = Math.ceil(this.x);
  1584. this.y = Math.ceil(this.y);
  1585. this.z = Math.ceil(this.z);
  1586. this.w = Math.ceil(this.w);
  1587. return this;
  1588. };
  1589. _proto.round = function round() {
  1590. this.x = Math.round(this.x);
  1591. this.y = Math.round(this.y);
  1592. this.z = Math.round(this.z);
  1593. this.w = Math.round(this.w);
  1594. return this;
  1595. };
  1596. _proto.roundToZero = function roundToZero() {
  1597. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1598. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1599. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  1600. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  1601. return this;
  1602. };
  1603. _proto.negate = function negate() {
  1604. this.x = -this.x;
  1605. this.y = -this.y;
  1606. this.z = -this.z;
  1607. this.w = -this.w;
  1608. return this;
  1609. };
  1610. _proto.dot = function dot(v) {
  1611. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1612. };
  1613. _proto.lengthSq = function lengthSq() {
  1614. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1615. };
  1616. _proto.length = function length() {
  1617. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  1618. };
  1619. _proto.manhattanLength = function manhattanLength() {
  1620. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  1621. };
  1622. _proto.normalize = function normalize() {
  1623. return this.divideScalar(this.length() || 1);
  1624. };
  1625. _proto.setLength = function setLength(length) {
  1626. return this.normalize().multiplyScalar(length);
  1627. };
  1628. _proto.lerp = function lerp(v, alpha) {
  1629. this.x += (v.x - this.x) * alpha;
  1630. this.y += (v.y - this.y) * alpha;
  1631. this.z += (v.z - this.z) * alpha;
  1632. this.w += (v.w - this.w) * alpha;
  1633. return this;
  1634. };
  1635. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1636. this.x = v1.x + (v2.x - v1.x) * alpha;
  1637. this.y = v1.y + (v2.y - v1.y) * alpha;
  1638. this.z = v1.z + (v2.z - v1.z) * alpha;
  1639. this.w = v1.w + (v2.w - v1.w) * alpha;
  1640. return this;
  1641. };
  1642. _proto.equals = function equals(v) {
  1643. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  1644. };
  1645. _proto.fromArray = function fromArray(array, offset) {
  1646. if (offset === void 0) {
  1647. offset = 0;
  1648. }
  1649. this.x = array[offset];
  1650. this.y = array[offset + 1];
  1651. this.z = array[offset + 2];
  1652. this.w = array[offset + 3];
  1653. return this;
  1654. };
  1655. _proto.toArray = function toArray(array, offset) {
  1656. if (array === void 0) {
  1657. array = [];
  1658. }
  1659. if (offset === void 0) {
  1660. offset = 0;
  1661. }
  1662. array[offset] = this.x;
  1663. array[offset + 1] = this.y;
  1664. array[offset + 2] = this.z;
  1665. array[offset + 3] = this.w;
  1666. return array;
  1667. };
  1668. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1669. if (offset !== undefined) {
  1670. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  1671. }
  1672. this.x = attribute.getX(index);
  1673. this.y = attribute.getY(index);
  1674. this.z = attribute.getZ(index);
  1675. this.w = attribute.getW(index);
  1676. return this;
  1677. };
  1678. _proto.random = function random() {
  1679. this.x = Math.random();
  1680. this.y = Math.random();
  1681. this.z = Math.random();
  1682. this.w = Math.random();
  1683. return this;
  1684. };
  1685. _createClass(Vector4, [{
  1686. key: "width",
  1687. get: function get() {
  1688. return this.z;
  1689. },
  1690. set: function set(value) {
  1691. this.z = value;
  1692. }
  1693. }, {
  1694. key: "height",
  1695. get: function get() {
  1696. return this.w;
  1697. },
  1698. set: function set(value) {
  1699. this.w = value;
  1700. }
  1701. }]);
  1702. return Vector4;
  1703. }();
  1704. /*
  1705. In options, we can specify:
  1706. * Texture parameters for an auto-generated target texture
  1707. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1708. */
  1709. function WebGLRenderTarget(width, height, options) {
  1710. this.width = width;
  1711. this.height = height;
  1712. this.scissor = new Vector4(0, 0, width, height);
  1713. this.scissorTest = false;
  1714. this.viewport = new Vector4(0, 0, width, height);
  1715. options = options || {};
  1716. this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  1717. this.texture.image = {};
  1718. this.texture.image.width = width;
  1719. this.texture.image.height = height;
  1720. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  1721. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  1722. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1723. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  1724. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1725. }
  1726. WebGLRenderTarget.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1727. constructor: WebGLRenderTarget,
  1728. isWebGLRenderTarget: true,
  1729. setSize: function setSize(width, height) {
  1730. if (this.width !== width || this.height !== height) {
  1731. this.width = width;
  1732. this.height = height;
  1733. this.texture.image.width = width;
  1734. this.texture.image.height = height;
  1735. this.dispose();
  1736. }
  1737. this.viewport.set(0, 0, width, height);
  1738. this.scissor.set(0, 0, width, height);
  1739. },
  1740. clone: function clone() {
  1741. return new this.constructor().copy(this);
  1742. },
  1743. copy: function copy(source) {
  1744. this.width = source.width;
  1745. this.height = source.height;
  1746. this.viewport.copy(source.viewport);
  1747. this.texture = source.texture.clone();
  1748. this.depthBuffer = source.depthBuffer;
  1749. this.stencilBuffer = source.stencilBuffer;
  1750. this.depthTexture = source.depthTexture;
  1751. return this;
  1752. },
  1753. dispose: function dispose() {
  1754. this.dispatchEvent({
  1755. type: 'dispose'
  1756. });
  1757. }
  1758. });
  1759. function WebGLMultisampleRenderTarget(width, height, options) {
  1760. WebGLRenderTarget.call(this, width, height, options);
  1761. this.samples = 4;
  1762. }
  1763. WebGLMultisampleRenderTarget.prototype = Object.assign(Object.create(WebGLRenderTarget.prototype), {
  1764. constructor: WebGLMultisampleRenderTarget,
  1765. isWebGLMultisampleRenderTarget: true,
  1766. copy: function copy(source) {
  1767. WebGLRenderTarget.prototype.copy.call(this, source);
  1768. this.samples = source.samples;
  1769. return this;
  1770. }
  1771. });
  1772. var Quaternion = /*#__PURE__*/function () {
  1773. function Quaternion(x, y, z, w) {
  1774. if (x === void 0) {
  1775. x = 0;
  1776. }
  1777. if (y === void 0) {
  1778. y = 0;
  1779. }
  1780. if (z === void 0) {
  1781. z = 0;
  1782. }
  1783. if (w === void 0) {
  1784. w = 1;
  1785. }
  1786. Object.defineProperty(this, 'isQuaternion', {
  1787. value: true
  1788. });
  1789. this._x = x;
  1790. this._y = y;
  1791. this._z = z;
  1792. this._w = w;
  1793. }
  1794. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  1795. return qm.copy(qa).slerp(qb, t);
  1796. };
  1797. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  1798. // fuzz-free, array-based Quaternion SLERP operation
  1799. var x0 = src0[srcOffset0 + 0],
  1800. y0 = src0[srcOffset0 + 1],
  1801. z0 = src0[srcOffset0 + 2],
  1802. w0 = src0[srcOffset0 + 3];
  1803. var x1 = src1[srcOffset1 + 0],
  1804. y1 = src1[srcOffset1 + 1],
  1805. z1 = src1[srcOffset1 + 2],
  1806. w1 = src1[srcOffset1 + 3];
  1807. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  1808. var s = 1 - t;
  1809. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1810. dir = cos >= 0 ? 1 : -1,
  1811. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  1812. if (sqrSin > Number.EPSILON) {
  1813. var sin = Math.sqrt(sqrSin),
  1814. len = Math.atan2(sin, cos * dir);
  1815. s = Math.sin(s * len) / sin;
  1816. t = Math.sin(t * len) / sin;
  1817. }
  1818. var tDir = t * dir;
  1819. x0 = x0 * s + x1 * tDir;
  1820. y0 = y0 * s + y1 * tDir;
  1821. z0 = z0 * s + z1 * tDir;
  1822. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  1823. if (s === 1 - t) {
  1824. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  1825. x0 *= f;
  1826. y0 *= f;
  1827. z0 *= f;
  1828. w0 *= f;
  1829. }
  1830. }
  1831. dst[dstOffset] = x0;
  1832. dst[dstOffset + 1] = y0;
  1833. dst[dstOffset + 2] = z0;
  1834. dst[dstOffset + 3] = w0;
  1835. };
  1836. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  1837. var x0 = src0[srcOffset0];
  1838. var y0 = src0[srcOffset0 + 1];
  1839. var z0 = src0[srcOffset0 + 2];
  1840. var w0 = src0[srcOffset0 + 3];
  1841. var x1 = src1[srcOffset1];
  1842. var y1 = src1[srcOffset1 + 1];
  1843. var z1 = src1[srcOffset1 + 2];
  1844. var w1 = src1[srcOffset1 + 3];
  1845. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  1846. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  1847. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  1848. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  1849. return dst;
  1850. };
  1851. var _proto = Quaternion.prototype;
  1852. _proto.set = function set(x, y, z, w) {
  1853. this._x = x;
  1854. this._y = y;
  1855. this._z = z;
  1856. this._w = w;
  1857. this._onChangeCallback();
  1858. return this;
  1859. };
  1860. _proto.clone = function clone() {
  1861. return new this.constructor(this._x, this._y, this._z, this._w);
  1862. };
  1863. _proto.copy = function copy(quaternion) {
  1864. this._x = quaternion.x;
  1865. this._y = quaternion.y;
  1866. this._z = quaternion.z;
  1867. this._w = quaternion.w;
  1868. this._onChangeCallback();
  1869. return this;
  1870. };
  1871. _proto.setFromEuler = function setFromEuler(euler, update) {
  1872. if (!(euler && euler.isEuler)) {
  1873. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  1874. }
  1875. var x = euler._x,
  1876. y = euler._y,
  1877. z = euler._z,
  1878. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  1879. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1880. // content/SpinCalc.m
  1881. var cos = Math.cos;
  1882. var sin = Math.sin;
  1883. var c1 = cos(x / 2);
  1884. var c2 = cos(y / 2);
  1885. var c3 = cos(z / 2);
  1886. var s1 = sin(x / 2);
  1887. var s2 = sin(y / 2);
  1888. var s3 = sin(z / 2);
  1889. switch (order) {
  1890. case 'XYZ':
  1891. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1892. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1893. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1894. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1895. break;
  1896. case 'YXZ':
  1897. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1898. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1899. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1900. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1901. break;
  1902. case 'ZXY':
  1903. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1904. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1905. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1906. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1907. break;
  1908. case 'ZYX':
  1909. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1910. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1911. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1912. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1913. break;
  1914. case 'YZX':
  1915. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1916. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1917. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1918. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1919. break;
  1920. case 'XZY':
  1921. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1922. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1923. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1924. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1925. break;
  1926. default:
  1927. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  1928. }
  1929. if (update !== false) this._onChangeCallback();
  1930. return this;
  1931. };
  1932. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  1933. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1934. // assumes axis is normalized
  1935. var halfAngle = angle / 2,
  1936. s = Math.sin(halfAngle);
  1937. this._x = axis.x * s;
  1938. this._y = axis.y * s;
  1939. this._z = axis.z * s;
  1940. this._w = Math.cos(halfAngle);
  1941. this._onChangeCallback();
  1942. return this;
  1943. };
  1944. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  1945. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1946. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1947. var te = m.elements,
  1948. m11 = te[0],
  1949. m12 = te[4],
  1950. m13 = te[8],
  1951. m21 = te[1],
  1952. m22 = te[5],
  1953. m23 = te[9],
  1954. m31 = te[2],
  1955. m32 = te[6],
  1956. m33 = te[10],
  1957. trace = m11 + m22 + m33;
  1958. if (trace > 0) {
  1959. var s = 0.5 / Math.sqrt(trace + 1.0);
  1960. this._w = 0.25 / s;
  1961. this._x = (m32 - m23) * s;
  1962. this._y = (m13 - m31) * s;
  1963. this._z = (m21 - m12) * s;
  1964. } else if (m11 > m22 && m11 > m33) {
  1965. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  1966. this._w = (m32 - m23) / _s;
  1967. this._x = 0.25 * _s;
  1968. this._y = (m12 + m21) / _s;
  1969. this._z = (m13 + m31) / _s;
  1970. } else if (m22 > m33) {
  1971. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  1972. this._w = (m13 - m31) / _s2;
  1973. this._x = (m12 + m21) / _s2;
  1974. this._y = 0.25 * _s2;
  1975. this._z = (m23 + m32) / _s2;
  1976. } else {
  1977. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  1978. this._w = (m21 - m12) / _s3;
  1979. this._x = (m13 + m31) / _s3;
  1980. this._y = (m23 + m32) / _s3;
  1981. this._z = 0.25 * _s3;
  1982. }
  1983. this._onChangeCallback();
  1984. return this;
  1985. };
  1986. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  1987. // assumes direction vectors vFrom and vTo are normalized
  1988. var EPS = 0.000001;
  1989. var r = vFrom.dot(vTo) + 1;
  1990. if (r < EPS) {
  1991. r = 0;
  1992. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  1993. this._x = -vFrom.y;
  1994. this._y = vFrom.x;
  1995. this._z = 0;
  1996. this._w = r;
  1997. } else {
  1998. this._x = 0;
  1999. this._y = -vFrom.z;
  2000. this._z = vFrom.y;
  2001. this._w = r;
  2002. }
  2003. } else {
  2004. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  2005. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  2006. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  2007. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  2008. this._w = r;
  2009. }
  2010. return this.normalize();
  2011. };
  2012. _proto.angleTo = function angleTo(q) {
  2013. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  2014. };
  2015. _proto.rotateTowards = function rotateTowards(q, step) {
  2016. var angle = this.angleTo(q);
  2017. if (angle === 0) return this;
  2018. var t = Math.min(1, step / angle);
  2019. this.slerp(q, t);
  2020. return this;
  2021. };
  2022. _proto.identity = function identity() {
  2023. return this.set(0, 0, 0, 1);
  2024. };
  2025. _proto.invert = function invert() {
  2026. // quaternion is assumed to have unit length
  2027. return this.conjugate();
  2028. };
  2029. _proto.conjugate = function conjugate() {
  2030. this._x *= -1;
  2031. this._y *= -1;
  2032. this._z *= -1;
  2033. this._onChangeCallback();
  2034. return this;
  2035. };
  2036. _proto.dot = function dot(v) {
  2037. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2038. };
  2039. _proto.lengthSq = function lengthSq() {
  2040. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2041. };
  2042. _proto.length = function length() {
  2043. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  2044. };
  2045. _proto.normalize = function normalize() {
  2046. var l = this.length();
  2047. if (l === 0) {
  2048. this._x = 0;
  2049. this._y = 0;
  2050. this._z = 0;
  2051. this._w = 1;
  2052. } else {
  2053. l = 1 / l;
  2054. this._x = this._x * l;
  2055. this._y = this._y * l;
  2056. this._z = this._z * l;
  2057. this._w = this._w * l;
  2058. }
  2059. this._onChangeCallback();
  2060. return this;
  2061. };
  2062. _proto.multiply = function multiply(q, p) {
  2063. if (p !== undefined) {
  2064. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2065. return this.multiplyQuaternions(q, p);
  2066. }
  2067. return this.multiplyQuaternions(this, q);
  2068. };
  2069. _proto.premultiply = function premultiply(q) {
  2070. return this.multiplyQuaternions(q, this);
  2071. };
  2072. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2073. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2074. var qax = a._x,
  2075. qay = a._y,
  2076. qaz = a._z,
  2077. qaw = a._w;
  2078. var qbx = b._x,
  2079. qby = b._y,
  2080. qbz = b._z,
  2081. qbw = b._w;
  2082. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2083. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2084. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2085. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2086. this._onChangeCallback();
  2087. return this;
  2088. };
  2089. _proto.slerp = function slerp(qb, t) {
  2090. if (t === 0) return this;
  2091. if (t === 1) return this.copy(qb);
  2092. var x = this._x,
  2093. y = this._y,
  2094. z = this._z,
  2095. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2096. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2097. if (cosHalfTheta < 0) {
  2098. this._w = -qb._w;
  2099. this._x = -qb._x;
  2100. this._y = -qb._y;
  2101. this._z = -qb._z;
  2102. cosHalfTheta = -cosHalfTheta;
  2103. } else {
  2104. this.copy(qb);
  2105. }
  2106. if (cosHalfTheta >= 1.0) {
  2107. this._w = w;
  2108. this._x = x;
  2109. this._y = y;
  2110. this._z = z;
  2111. return this;
  2112. }
  2113. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2114. if (sqrSinHalfTheta <= Number.EPSILON) {
  2115. var s = 1 - t;
  2116. this._w = s * w + t * this._w;
  2117. this._x = s * x + t * this._x;
  2118. this._y = s * y + t * this._y;
  2119. this._z = s * z + t * this._z;
  2120. this.normalize();
  2121. this._onChangeCallback();
  2122. return this;
  2123. }
  2124. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2125. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2126. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2127. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2128. this._w = w * ratioA + this._w * ratioB;
  2129. this._x = x * ratioA + this._x * ratioB;
  2130. this._y = y * ratioA + this._y * ratioB;
  2131. this._z = z * ratioA + this._z * ratioB;
  2132. this._onChangeCallback();
  2133. return this;
  2134. };
  2135. _proto.equals = function equals(quaternion) {
  2136. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2137. };
  2138. _proto.fromArray = function fromArray(array, offset) {
  2139. if (offset === void 0) {
  2140. offset = 0;
  2141. }
  2142. this._x = array[offset];
  2143. this._y = array[offset + 1];
  2144. this._z = array[offset + 2];
  2145. this._w = array[offset + 3];
  2146. this._onChangeCallback();
  2147. return this;
  2148. };
  2149. _proto.toArray = function toArray(array, offset) {
  2150. if (array === void 0) {
  2151. array = [];
  2152. }
  2153. if (offset === void 0) {
  2154. offset = 0;
  2155. }
  2156. array[offset] = this._x;
  2157. array[offset + 1] = this._y;
  2158. array[offset + 2] = this._z;
  2159. array[offset + 3] = this._w;
  2160. return array;
  2161. };
  2162. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2163. this._x = attribute.getX(index);
  2164. this._y = attribute.getY(index);
  2165. this._z = attribute.getZ(index);
  2166. this._w = attribute.getW(index);
  2167. return this;
  2168. };
  2169. _proto._onChange = function _onChange(callback) {
  2170. this._onChangeCallback = callback;
  2171. return this;
  2172. };
  2173. _proto._onChangeCallback = function _onChangeCallback() {};
  2174. _createClass(Quaternion, [{
  2175. key: "x",
  2176. get: function get() {
  2177. return this._x;
  2178. },
  2179. set: function set(value) {
  2180. this._x = value;
  2181. this._onChangeCallback();
  2182. }
  2183. }, {
  2184. key: "y",
  2185. get: function get() {
  2186. return this._y;
  2187. },
  2188. set: function set(value) {
  2189. this._y = value;
  2190. this._onChangeCallback();
  2191. }
  2192. }, {
  2193. key: "z",
  2194. get: function get() {
  2195. return this._z;
  2196. },
  2197. set: function set(value) {
  2198. this._z = value;
  2199. this._onChangeCallback();
  2200. }
  2201. }, {
  2202. key: "w",
  2203. get: function get() {
  2204. return this._w;
  2205. },
  2206. set: function set(value) {
  2207. this._w = value;
  2208. this._onChangeCallback();
  2209. }
  2210. }]);
  2211. return Quaternion;
  2212. }();
  2213. var Vector3 = /*#__PURE__*/function () {
  2214. function Vector3(x, y, z) {
  2215. if (x === void 0) {
  2216. x = 0;
  2217. }
  2218. if (y === void 0) {
  2219. y = 0;
  2220. }
  2221. if (z === void 0) {
  2222. z = 0;
  2223. }
  2224. Object.defineProperty(this, 'isVector3', {
  2225. value: true
  2226. });
  2227. this.x = x;
  2228. this.y = y;
  2229. this.z = z;
  2230. }
  2231. var _proto = Vector3.prototype;
  2232. _proto.set = function set(x, y, z) {
  2233. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2234. this.x = x;
  2235. this.y = y;
  2236. this.z = z;
  2237. return this;
  2238. };
  2239. _proto.setScalar = function setScalar(scalar) {
  2240. this.x = scalar;
  2241. this.y = scalar;
  2242. this.z = scalar;
  2243. return this;
  2244. };
  2245. _proto.setX = function setX(x) {
  2246. this.x = x;
  2247. return this;
  2248. };
  2249. _proto.setY = function setY(y) {
  2250. this.y = y;
  2251. return this;
  2252. };
  2253. _proto.setZ = function setZ(z) {
  2254. this.z = z;
  2255. return this;
  2256. };
  2257. _proto.setComponent = function setComponent(index, value) {
  2258. switch (index) {
  2259. case 0:
  2260. this.x = value;
  2261. break;
  2262. case 1:
  2263. this.y = value;
  2264. break;
  2265. case 2:
  2266. this.z = value;
  2267. break;
  2268. default:
  2269. throw new Error('index is out of range: ' + index);
  2270. }
  2271. return this;
  2272. };
  2273. _proto.getComponent = function getComponent(index) {
  2274. switch (index) {
  2275. case 0:
  2276. return this.x;
  2277. case 1:
  2278. return this.y;
  2279. case 2:
  2280. return this.z;
  2281. default:
  2282. throw new Error('index is out of range: ' + index);
  2283. }
  2284. };
  2285. _proto.clone = function clone() {
  2286. return new this.constructor(this.x, this.y, this.z);
  2287. };
  2288. _proto.copy = function copy(v) {
  2289. this.x = v.x;
  2290. this.y = v.y;
  2291. this.z = v.z;
  2292. return this;
  2293. };
  2294. _proto.add = function add(v, w) {
  2295. if (w !== undefined) {
  2296. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2297. return this.addVectors(v, w);
  2298. }
  2299. this.x += v.x;
  2300. this.y += v.y;
  2301. this.z += v.z;
  2302. return this;
  2303. };
  2304. _proto.addScalar = function addScalar(s) {
  2305. this.x += s;
  2306. this.y += s;
  2307. this.z += s;
  2308. return this;
  2309. };
  2310. _proto.addVectors = function addVectors(a, b) {
  2311. this.x = a.x + b.x;
  2312. this.y = a.y + b.y;
  2313. this.z = a.z + b.z;
  2314. return this;
  2315. };
  2316. _proto.addScaledVector = function addScaledVector(v, s) {
  2317. this.x += v.x * s;
  2318. this.y += v.y * s;
  2319. this.z += v.z * s;
  2320. return this;
  2321. };
  2322. _proto.sub = function sub(v, w) {
  2323. if (w !== undefined) {
  2324. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2325. return this.subVectors(v, w);
  2326. }
  2327. this.x -= v.x;
  2328. this.y -= v.y;
  2329. this.z -= v.z;
  2330. return this;
  2331. };
  2332. _proto.subScalar = function subScalar(s) {
  2333. this.x -= s;
  2334. this.y -= s;
  2335. this.z -= s;
  2336. return this;
  2337. };
  2338. _proto.subVectors = function subVectors(a, b) {
  2339. this.x = a.x - b.x;
  2340. this.y = a.y - b.y;
  2341. this.z = a.z - b.z;
  2342. return this;
  2343. };
  2344. _proto.multiply = function multiply(v, w) {
  2345. if (w !== undefined) {
  2346. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  2347. return this.multiplyVectors(v, w);
  2348. }
  2349. this.x *= v.x;
  2350. this.y *= v.y;
  2351. this.z *= v.z;
  2352. return this;
  2353. };
  2354. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2355. this.x *= scalar;
  2356. this.y *= scalar;
  2357. this.z *= scalar;
  2358. return this;
  2359. };
  2360. _proto.multiplyVectors = function multiplyVectors(a, b) {
  2361. this.x = a.x * b.x;
  2362. this.y = a.y * b.y;
  2363. this.z = a.z * b.z;
  2364. return this;
  2365. };
  2366. _proto.applyEuler = function applyEuler(euler) {
  2367. if (!(euler && euler.isEuler)) {
  2368. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2369. }
  2370. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  2371. };
  2372. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  2373. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  2374. };
  2375. _proto.applyMatrix3 = function applyMatrix3(m) {
  2376. var x = this.x,
  2377. y = this.y,
  2378. z = this.z;
  2379. var e = m.elements;
  2380. this.x = e[0] * x + e[3] * y + e[6] * z;
  2381. this.y = e[1] * x + e[4] * y + e[7] * z;
  2382. this.z = e[2] * x + e[5] * y + e[8] * z;
  2383. return this;
  2384. };
  2385. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  2386. return this.applyMatrix3(m).normalize();
  2387. };
  2388. _proto.applyMatrix4 = function applyMatrix4(m) {
  2389. var x = this.x,
  2390. y = this.y,
  2391. z = this.z;
  2392. var e = m.elements;
  2393. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  2394. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  2395. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  2396. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  2397. return this;
  2398. };
  2399. _proto.applyQuaternion = function applyQuaternion(q) {
  2400. var x = this.x,
  2401. y = this.y,
  2402. z = this.z;
  2403. var qx = q.x,
  2404. qy = q.y,
  2405. qz = q.z,
  2406. qw = q.w; // calculate quat * vector
  2407. var ix = qw * x + qy * z - qz * y;
  2408. var iy = qw * y + qz * x - qx * z;
  2409. var iz = qw * z + qx * y - qy * x;
  2410. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  2411. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  2412. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  2413. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  2414. return this;
  2415. };
  2416. _proto.project = function project(camera) {
  2417. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  2418. };
  2419. _proto.unproject = function unproject(camera) {
  2420. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  2421. };
  2422. _proto.transformDirection = function transformDirection(m) {
  2423. // input: THREE.Matrix4 affine matrix
  2424. // vector interpreted as a direction
  2425. var x = this.x,
  2426. y = this.y,
  2427. z = this.z;
  2428. var e = m.elements;
  2429. this.x = e[0] * x + e[4] * y + e[8] * z;
  2430. this.y = e[1] * x + e[5] * y + e[9] * z;
  2431. this.z = e[2] * x + e[6] * y + e[10] * z;
  2432. return this.normalize();
  2433. };
  2434. _proto.divide = function divide(v) {
  2435. this.x /= v.x;
  2436. this.y /= v.y;
  2437. this.z /= v.z;
  2438. return this;
  2439. };
  2440. _proto.divideScalar = function divideScalar(scalar) {
  2441. return this.multiplyScalar(1 / scalar);
  2442. };
  2443. _proto.min = function min(v) {
  2444. this.x = Math.min(this.x, v.x);
  2445. this.y = Math.min(this.y, v.y);
  2446. this.z = Math.min(this.z, v.z);
  2447. return this;
  2448. };
  2449. _proto.max = function max(v) {
  2450. this.x = Math.max(this.x, v.x);
  2451. this.y = Math.max(this.y, v.y);
  2452. this.z = Math.max(this.z, v.z);
  2453. return this;
  2454. };
  2455. _proto.clamp = function clamp(min, max) {
  2456. // assumes min < max, componentwise
  2457. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2458. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2459. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2460. return this;
  2461. };
  2462. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2463. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2464. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2465. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2466. return this;
  2467. };
  2468. _proto.clampLength = function clampLength(min, max) {
  2469. var length = this.length();
  2470. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2471. };
  2472. _proto.floor = function floor() {
  2473. this.x = Math.floor(this.x);
  2474. this.y = Math.floor(this.y);
  2475. this.z = Math.floor(this.z);
  2476. return this;
  2477. };
  2478. _proto.ceil = function ceil() {
  2479. this.x = Math.ceil(this.x);
  2480. this.y = Math.ceil(this.y);
  2481. this.z = Math.ceil(this.z);
  2482. return this;
  2483. };
  2484. _proto.round = function round() {
  2485. this.x = Math.round(this.x);
  2486. this.y = Math.round(this.y);
  2487. this.z = Math.round(this.z);
  2488. return this;
  2489. };
  2490. _proto.roundToZero = function roundToZero() {
  2491. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2492. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2493. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2494. return this;
  2495. };
  2496. _proto.negate = function negate() {
  2497. this.x = -this.x;
  2498. this.y = -this.y;
  2499. this.z = -this.z;
  2500. return this;
  2501. };
  2502. _proto.dot = function dot(v) {
  2503. return this.x * v.x + this.y * v.y + this.z * v.z;
  2504. } // TODO lengthSquared?
  2505. ;
  2506. _proto.lengthSq = function lengthSq() {
  2507. return this.x * this.x + this.y * this.y + this.z * this.z;
  2508. };
  2509. _proto.length = function length() {
  2510. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  2511. };
  2512. _proto.manhattanLength = function manhattanLength() {
  2513. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  2514. };
  2515. _proto.normalize = function normalize() {
  2516. return this.divideScalar(this.length() || 1);
  2517. };
  2518. _proto.setLength = function setLength(length) {
  2519. return this.normalize().multiplyScalar(length);
  2520. };
  2521. _proto.lerp = function lerp(v, alpha) {
  2522. this.x += (v.x - this.x) * alpha;
  2523. this.y += (v.y - this.y) * alpha;
  2524. this.z += (v.z - this.z) * alpha;
  2525. return this;
  2526. };
  2527. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2528. this.x = v1.x + (v2.x - v1.x) * alpha;
  2529. this.y = v1.y + (v2.y - v1.y) * alpha;
  2530. this.z = v1.z + (v2.z - v1.z) * alpha;
  2531. return this;
  2532. };
  2533. _proto.cross = function cross(v, w) {
  2534. if (w !== undefined) {
  2535. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  2536. return this.crossVectors(v, w);
  2537. }
  2538. return this.crossVectors(this, v);
  2539. };
  2540. _proto.crossVectors = function crossVectors(a, b) {
  2541. var ax = a.x,
  2542. ay = a.y,
  2543. az = a.z;
  2544. var bx = b.x,
  2545. by = b.y,
  2546. bz = b.z;
  2547. this.x = ay * bz - az * by;
  2548. this.y = az * bx - ax * bz;
  2549. this.z = ax * by - ay * bx;
  2550. return this;
  2551. };
  2552. _proto.projectOnVector = function projectOnVector(v) {
  2553. var denominator = v.lengthSq();
  2554. if (denominator === 0) return this.set(0, 0, 0);
  2555. var scalar = v.dot(this) / denominator;
  2556. return this.copy(v).multiplyScalar(scalar);
  2557. };
  2558. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  2559. _vector.copy(this).projectOnVector(planeNormal);
  2560. return this.sub(_vector);
  2561. };
  2562. _proto.reflect = function reflect(normal) {
  2563. // reflect incident vector off plane orthogonal to normal
  2564. // normal is assumed to have unit length
  2565. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  2566. };
  2567. _proto.angleTo = function angleTo(v) {
  2568. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  2569. if (denominator === 0) return Math.PI / 2;
  2570. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  2571. return Math.acos(MathUtils.clamp(theta, -1, 1));
  2572. };
  2573. _proto.distanceTo = function distanceTo(v) {
  2574. return Math.sqrt(this.distanceToSquared(v));
  2575. };
  2576. _proto.distanceToSquared = function distanceToSquared(v) {
  2577. var dx = this.x - v.x,
  2578. dy = this.y - v.y,
  2579. dz = this.z - v.z;
  2580. return dx * dx + dy * dy + dz * dz;
  2581. };
  2582. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  2583. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  2584. };
  2585. _proto.setFromSpherical = function setFromSpherical(s) {
  2586. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  2587. };
  2588. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  2589. var sinPhiRadius = Math.sin(phi) * radius;
  2590. this.x = sinPhiRadius * Math.sin(theta);
  2591. this.y = Math.cos(phi) * radius;
  2592. this.z = sinPhiRadius * Math.cos(theta);
  2593. return this;
  2594. };
  2595. _proto.setFromCylindrical = function setFromCylindrical(c) {
  2596. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  2597. };
  2598. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  2599. this.x = radius * Math.sin(theta);
  2600. this.y = y;
  2601. this.z = radius * Math.cos(theta);
  2602. return this;
  2603. };
  2604. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  2605. var e = m.elements;
  2606. this.x = e[12];
  2607. this.y = e[13];
  2608. this.z = e[14];
  2609. return this;
  2610. };
  2611. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  2612. var sx = this.setFromMatrixColumn(m, 0).length();
  2613. var sy = this.setFromMatrixColumn(m, 1).length();
  2614. var sz = this.setFromMatrixColumn(m, 2).length();
  2615. this.x = sx;
  2616. this.y = sy;
  2617. this.z = sz;
  2618. return this;
  2619. };
  2620. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  2621. return this.fromArray(m.elements, index * 4);
  2622. };
  2623. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  2624. return this.fromArray(m.elements, index * 3);
  2625. };
  2626. _proto.equals = function equals(v) {
  2627. return v.x === this.x && v.y === this.y && v.z === this.z;
  2628. };
  2629. _proto.fromArray = function fromArray(array, offset) {
  2630. if (offset === void 0) {
  2631. offset = 0;
  2632. }
  2633. this.x = array[offset];
  2634. this.y = array[offset + 1];
  2635. this.z = array[offset + 2];
  2636. return this;
  2637. };
  2638. _proto.toArray = function toArray(array, offset) {
  2639. if (array === void 0) {
  2640. array = [];
  2641. }
  2642. if (offset === void 0) {
  2643. offset = 0;
  2644. }
  2645. array[offset] = this.x;
  2646. array[offset + 1] = this.y;
  2647. array[offset + 2] = this.z;
  2648. return array;
  2649. };
  2650. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2651. if (offset !== undefined) {
  2652. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  2653. }
  2654. this.x = attribute.getX(index);
  2655. this.y = attribute.getY(index);
  2656. this.z = attribute.getZ(index);
  2657. return this;
  2658. };
  2659. _proto.random = function random() {
  2660. this.x = Math.random();
  2661. this.y = Math.random();
  2662. this.z = Math.random();
  2663. return this;
  2664. };
  2665. return Vector3;
  2666. }();
  2667. var _vector = /*@__PURE__*/new Vector3();
  2668. var _quaternion = /*@__PURE__*/new Quaternion();
  2669. var Box3 = /*#__PURE__*/function () {
  2670. function Box3(min, max) {
  2671. Object.defineProperty(this, 'isBox3', {
  2672. value: true
  2673. });
  2674. this.min = min !== undefined ? min : new Vector3(+Infinity, +Infinity, +Infinity);
  2675. this.max = max !== undefined ? max : new Vector3(-Infinity, -Infinity, -Infinity);
  2676. }
  2677. var _proto = Box3.prototype;
  2678. _proto.set = function set(min, max) {
  2679. this.min.copy(min);
  2680. this.max.copy(max);
  2681. return this;
  2682. };
  2683. _proto.setFromArray = function setFromArray(array) {
  2684. var minX = +Infinity;
  2685. var minY = +Infinity;
  2686. var minZ = +Infinity;
  2687. var maxX = -Infinity;
  2688. var maxY = -Infinity;
  2689. var maxZ = -Infinity;
  2690. for (var i = 0, l = array.length; i < l; i += 3) {
  2691. var x = array[i];
  2692. var y = array[i + 1];
  2693. var z = array[i + 2];
  2694. if (x < minX) minX = x;
  2695. if (y < minY) minY = y;
  2696. if (z < minZ) minZ = z;
  2697. if (x > maxX) maxX = x;
  2698. if (y > maxY) maxY = y;
  2699. if (z > maxZ) maxZ = z;
  2700. }
  2701. this.min.set(minX, minY, minZ);
  2702. this.max.set(maxX, maxY, maxZ);
  2703. return this;
  2704. };
  2705. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  2706. var minX = +Infinity;
  2707. var minY = +Infinity;
  2708. var minZ = +Infinity;
  2709. var maxX = -Infinity;
  2710. var maxY = -Infinity;
  2711. var maxZ = -Infinity;
  2712. for (var i = 0, l = attribute.count; i < l; i++) {
  2713. var x = attribute.getX(i);
  2714. var y = attribute.getY(i);
  2715. var z = attribute.getZ(i);
  2716. if (x < minX) minX = x;
  2717. if (y < minY) minY = y;
  2718. if (z < minZ) minZ = z;
  2719. if (x > maxX) maxX = x;
  2720. if (y > maxY) maxY = y;
  2721. if (z > maxZ) maxZ = z;
  2722. }
  2723. this.min.set(minX, minY, minZ);
  2724. this.max.set(maxX, maxY, maxZ);
  2725. return this;
  2726. };
  2727. _proto.setFromPoints = function setFromPoints(points) {
  2728. this.makeEmpty();
  2729. for (var i = 0, il = points.length; i < il; i++) {
  2730. this.expandByPoint(points[i]);
  2731. }
  2732. return this;
  2733. };
  2734. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  2735. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  2736. this.min.copy(center).sub(halfSize);
  2737. this.max.copy(center).add(halfSize);
  2738. return this;
  2739. };
  2740. _proto.setFromObject = function setFromObject(object) {
  2741. this.makeEmpty();
  2742. return this.expandByObject(object);
  2743. };
  2744. _proto.clone = function clone() {
  2745. return new this.constructor().copy(this);
  2746. };
  2747. _proto.copy = function copy(box) {
  2748. this.min.copy(box.min);
  2749. this.max.copy(box.max);
  2750. return this;
  2751. };
  2752. _proto.makeEmpty = function makeEmpty() {
  2753. this.min.x = this.min.y = this.min.z = +Infinity;
  2754. this.max.x = this.max.y = this.max.z = -Infinity;
  2755. return this;
  2756. };
  2757. _proto.isEmpty = function isEmpty() {
  2758. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2759. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  2760. };
  2761. _proto.getCenter = function getCenter(target) {
  2762. if (target === undefined) {
  2763. console.warn('THREE.Box3: .getCenter() target is now required');
  2764. target = new Vector3();
  2765. }
  2766. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  2767. };
  2768. _proto.getSize = function getSize(target) {
  2769. if (target === undefined) {
  2770. console.warn('THREE.Box3: .getSize() target is now required');
  2771. target = new Vector3();
  2772. }
  2773. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  2774. };
  2775. _proto.expandByPoint = function expandByPoint(point) {
  2776. this.min.min(point);
  2777. this.max.max(point);
  2778. return this;
  2779. };
  2780. _proto.expandByVector = function expandByVector(vector) {
  2781. this.min.sub(vector);
  2782. this.max.add(vector);
  2783. return this;
  2784. };
  2785. _proto.expandByScalar = function expandByScalar(scalar) {
  2786. this.min.addScalar(-scalar);
  2787. this.max.addScalar(scalar);
  2788. return this;
  2789. };
  2790. _proto.expandByObject = function expandByObject(object) {
  2791. // Computes the world-axis-aligned bounding box of an object (including its children),
  2792. // accounting for both the object's, and children's, world transforms
  2793. object.updateWorldMatrix(false, false);
  2794. var geometry = object.geometry;
  2795. if (geometry !== undefined) {
  2796. if (geometry.boundingBox === null) {
  2797. geometry.computeBoundingBox();
  2798. }
  2799. _box.copy(geometry.boundingBox);
  2800. _box.applyMatrix4(object.matrixWorld);
  2801. this.union(_box);
  2802. }
  2803. var children = object.children;
  2804. for (var i = 0, l = children.length; i < l; i++) {
  2805. this.expandByObject(children[i]);
  2806. }
  2807. return this;
  2808. };
  2809. _proto.containsPoint = function containsPoint(point) {
  2810. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y || point.z < this.min.z || point.z > this.max.z ? false : true;
  2811. };
  2812. _proto.containsBox = function containsBox(box) {
  2813. return this.min.x <= box.min.x && box.max.x <= this.max.x && this.min.y <= box.min.y && box.max.y <= this.max.y && this.min.z <= box.min.z && box.max.z <= this.max.z;
  2814. };
  2815. _proto.getParameter = function getParameter(point, target) {
  2816. // This can potentially have a divide by zero if the box
  2817. // has a size dimension of 0.
  2818. if (target === undefined) {
  2819. console.warn('THREE.Box3: .getParameter() target is now required');
  2820. target = new Vector3();
  2821. }
  2822. return target.set((point.x - this.min.x) / (this.max.x - this.min.x), (point.y - this.min.y) / (this.max.y - this.min.y), (point.z - this.min.z) / (this.max.z - this.min.z));
  2823. };
  2824. _proto.intersectsBox = function intersectsBox(box) {
  2825. // using 6 splitting planes to rule out intersections.
  2826. return box.max.x < this.min.x || box.min.x > this.max.x || box.max.y < this.min.y || box.min.y > this.max.y || box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  2827. };
  2828. _proto.intersectsSphere = function intersectsSphere(sphere) {
  2829. // Find the point on the AABB closest to the sphere center.
  2830. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  2831. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  2832. };
  2833. _proto.intersectsPlane = function intersectsPlane(plane) {
  2834. // We compute the minimum and maximum dot product values. If those values
  2835. // are on the same side (back or front) of the plane, then there is no intersection.
  2836. var min, max;
  2837. if (plane.normal.x > 0) {
  2838. min = plane.normal.x * this.min.x;
  2839. max = plane.normal.x * this.max.x;
  2840. } else {
  2841. min = plane.normal.x * this.max.x;
  2842. max = plane.normal.x * this.min.x;
  2843. }
  2844. if (plane.normal.y > 0) {
  2845. min += plane.normal.y * this.min.y;
  2846. max += plane.normal.y * this.max.y;
  2847. } else {
  2848. min += plane.normal.y * this.max.y;
  2849. max += plane.normal.y * this.min.y;
  2850. }
  2851. if (plane.normal.z > 0) {
  2852. min += plane.normal.z * this.min.z;
  2853. max += plane.normal.z * this.max.z;
  2854. } else {
  2855. min += plane.normal.z * this.max.z;
  2856. max += plane.normal.z * this.min.z;
  2857. }
  2858. return min <= -plane.constant && max >= -plane.constant;
  2859. };
  2860. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  2861. if (this.isEmpty()) {
  2862. return false;
  2863. } // compute box center and extents
  2864. this.getCenter(_center);
  2865. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  2866. _v0.subVectors(triangle.a, _center);
  2867. _v1.subVectors(triangle.b, _center);
  2868. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  2869. _f0.subVectors(_v1, _v0);
  2870. _f1.subVectors(_v2, _v1);
  2871. _f2.subVectors(_v0, _v2); // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  2872. // make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation
  2873. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  2874. var axes = [0, -_f0.z, _f0.y, 0, -_f1.z, _f1.y, 0, -_f2.z, _f2.y, _f0.z, 0, -_f0.x, _f1.z, 0, -_f1.x, _f2.z, 0, -_f2.x, -_f0.y, _f0.x, 0, -_f1.y, _f1.x, 0, -_f2.y, _f2.x, 0];
  2875. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2876. return false;
  2877. } // test 3 face normals from the aabb
  2878. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  2879. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2880. return false;
  2881. } // finally testing the face normal of the triangle
  2882. // use already existing triangle edge vectors here
  2883. _triangleNormal.crossVectors(_f0, _f1);
  2884. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  2885. return satForAxes(axes, _v0, _v1, _v2, _extents);
  2886. };
  2887. _proto.clampPoint = function clampPoint(point, target) {
  2888. if (target === undefined) {
  2889. console.warn('THREE.Box3: .clampPoint() target is now required');
  2890. target = new Vector3();
  2891. }
  2892. return target.copy(point).clamp(this.min, this.max);
  2893. };
  2894. _proto.distanceToPoint = function distanceToPoint(point) {
  2895. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  2896. return clampedPoint.sub(point).length();
  2897. };
  2898. _proto.getBoundingSphere = function getBoundingSphere(target) {
  2899. if (target === undefined) {
  2900. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  2901. }
  2902. this.getCenter(target.center);
  2903. target.radius = this.getSize(_vector$1).length() * 0.5;
  2904. return target;
  2905. };
  2906. _proto.intersect = function intersect(box) {
  2907. this.min.max(box.min);
  2908. this.max.min(box.max); // ensure that if there is no overlap, the result is fully empty, not slightly empty with non-inf/+inf values that will cause subsequence intersects to erroneously return valid values.
  2909. if (this.isEmpty()) this.makeEmpty();
  2910. return this;
  2911. };
  2912. _proto.union = function union(box) {
  2913. this.min.min(box.min);
  2914. this.max.max(box.max);
  2915. return this;
  2916. };
  2917. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  2918. // transform of empty box is an empty box.
  2919. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2920. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  2921. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  2922. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  2923. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  2924. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  2925. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  2926. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  2927. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  2928. this.setFromPoints(_points);
  2929. return this;
  2930. };
  2931. _proto.translate = function translate(offset) {
  2932. this.min.add(offset);
  2933. this.max.add(offset);
  2934. return this;
  2935. };
  2936. _proto.equals = function equals(box) {
  2937. return box.min.equals(this.min) && box.max.equals(this.max);
  2938. };
  2939. return Box3;
  2940. }();
  2941. function satForAxes(axes, v0, v1, v2, extents) {
  2942. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  2943. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  2944. var r = extents.x * Math.abs(_testAxis.x) + extents.y * Math.abs(_testAxis.y) + extents.z * Math.abs(_testAxis.z); // project all 3 vertices of the triangle onto the seperating axis
  2945. var p0 = v0.dot(_testAxis);
  2946. var p1 = v1.dot(_testAxis);
  2947. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  2948. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  2949. // points of the projected triangle are outside the projected half-length of the aabb
  2950. // the axis is seperating and we can exit
  2951. return false;
  2952. }
  2953. }
  2954. return true;
  2955. }
  2956. var _points = [/*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3()];
  2957. var _vector$1 = /*@__PURE__*/new Vector3();
  2958. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  2959. var _v0 = /*@__PURE__*/new Vector3();
  2960. var _v1 = /*@__PURE__*/new Vector3();
  2961. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  2962. var _f0 = /*@__PURE__*/new Vector3();
  2963. var _f1 = /*@__PURE__*/new Vector3();
  2964. var _f2 = /*@__PURE__*/new Vector3();
  2965. var _center = /*@__PURE__*/new Vector3();
  2966. var _extents = /*@__PURE__*/new Vector3();
  2967. var _triangleNormal = /*@__PURE__*/new Vector3();
  2968. var _testAxis = /*@__PURE__*/new Vector3();
  2969. var _box$1 = /*@__PURE__*/new Box3();
  2970. var Sphere = /*#__PURE__*/function () {
  2971. function Sphere(center, radius) {
  2972. this.center = center !== undefined ? center : new Vector3();
  2973. this.radius = radius !== undefined ? radius : -1;
  2974. }
  2975. var _proto = Sphere.prototype;
  2976. _proto.set = function set(center, radius) {
  2977. this.center.copy(center);
  2978. this.radius = radius;
  2979. return this;
  2980. };
  2981. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  2982. var center = this.center;
  2983. if (optionalCenter !== undefined) {
  2984. center.copy(optionalCenter);
  2985. } else {
  2986. _box$1.setFromPoints(points).getCenter(center);
  2987. }
  2988. var maxRadiusSq = 0;
  2989. for (var i = 0, il = points.length; i < il; i++) {
  2990. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  2991. }
  2992. this.radius = Math.sqrt(maxRadiusSq);
  2993. return this;
  2994. };
  2995. _proto.clone = function clone() {
  2996. return new this.constructor().copy(this);
  2997. };
  2998. _proto.copy = function copy(sphere) {
  2999. this.center.copy(sphere.center);
  3000. this.radius = sphere.radius;
  3001. return this;
  3002. };
  3003. _proto.isEmpty = function isEmpty() {
  3004. return this.radius < 0;
  3005. };
  3006. _proto.makeEmpty = function makeEmpty() {
  3007. this.center.set(0, 0, 0);
  3008. this.radius = -1;
  3009. return this;
  3010. };
  3011. _proto.containsPoint = function containsPoint(point) {
  3012. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  3013. };
  3014. _proto.distanceToPoint = function distanceToPoint(point) {
  3015. return point.distanceTo(this.center) - this.radius;
  3016. };
  3017. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3018. var radiusSum = this.radius + sphere.radius;
  3019. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  3020. };
  3021. _proto.intersectsBox = function intersectsBox(box) {
  3022. return box.intersectsSphere(this);
  3023. };
  3024. _proto.intersectsPlane = function intersectsPlane(plane) {
  3025. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  3026. };
  3027. _proto.clampPoint = function clampPoint(point, target) {
  3028. var deltaLengthSq = this.center.distanceToSquared(point);
  3029. if (target === undefined) {
  3030. console.warn('THREE.Sphere: .clampPoint() target is now required');
  3031. target = new Vector3();
  3032. }
  3033. target.copy(point);
  3034. if (deltaLengthSq > this.radius * this.radius) {
  3035. target.sub(this.center).normalize();
  3036. target.multiplyScalar(this.radius).add(this.center);
  3037. }
  3038. return target;
  3039. };
  3040. _proto.getBoundingBox = function getBoundingBox(target) {
  3041. if (target === undefined) {
  3042. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  3043. target = new Box3();
  3044. }
  3045. if (this.isEmpty()) {
  3046. // Empty sphere produces empty bounding box
  3047. target.makeEmpty();
  3048. return target;
  3049. }
  3050. target.set(this.center, this.center);
  3051. target.expandByScalar(this.radius);
  3052. return target;
  3053. };
  3054. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3055. this.center.applyMatrix4(matrix);
  3056. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3057. return this;
  3058. };
  3059. _proto.translate = function translate(offset) {
  3060. this.center.add(offset);
  3061. return this;
  3062. };
  3063. _proto.equals = function equals(sphere) {
  3064. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3065. };
  3066. return Sphere;
  3067. }();
  3068. var _vector$2 = /*@__PURE__*/new Vector3();
  3069. var _segCenter = /*@__PURE__*/new Vector3();
  3070. var _segDir = /*@__PURE__*/new Vector3();
  3071. var _diff = /*@__PURE__*/new Vector3();
  3072. var _edge1 = /*@__PURE__*/new Vector3();
  3073. var _edge2 = /*@__PURE__*/new Vector3();
  3074. var _normal = /*@__PURE__*/new Vector3();
  3075. var Ray = /*#__PURE__*/function () {
  3076. function Ray(origin, direction) {
  3077. this.origin = origin !== undefined ? origin : new Vector3();
  3078. this.direction = direction !== undefined ? direction : new Vector3(0, 0, -1);
  3079. }
  3080. var _proto = Ray.prototype;
  3081. _proto.set = function set(origin, direction) {
  3082. this.origin.copy(origin);
  3083. this.direction.copy(direction);
  3084. return this;
  3085. };
  3086. _proto.clone = function clone() {
  3087. return new this.constructor().copy(this);
  3088. };
  3089. _proto.copy = function copy(ray) {
  3090. this.origin.copy(ray.origin);
  3091. this.direction.copy(ray.direction);
  3092. return this;
  3093. };
  3094. _proto.at = function at(t, target) {
  3095. if (target === undefined) {
  3096. console.warn('THREE.Ray: .at() target is now required');
  3097. target = new Vector3();
  3098. }
  3099. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3100. };
  3101. _proto.lookAt = function lookAt(v) {
  3102. this.direction.copy(v).sub(this.origin).normalize();
  3103. return this;
  3104. };
  3105. _proto.recast = function recast(t) {
  3106. this.origin.copy(this.at(t, _vector$2));
  3107. return this;
  3108. };
  3109. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3110. if (target === undefined) {
  3111. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3112. target = new Vector3();
  3113. }
  3114. target.subVectors(point, this.origin);
  3115. var directionDistance = target.dot(this.direction);
  3116. if (directionDistance < 0) {
  3117. return target.copy(this.origin);
  3118. }
  3119. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3120. };
  3121. _proto.distanceToPoint = function distanceToPoint(point) {
  3122. return Math.sqrt(this.distanceSqToPoint(point));
  3123. };
  3124. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3125. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3126. if (directionDistance < 0) {
  3127. return this.origin.distanceToSquared(point);
  3128. }
  3129. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3130. return _vector$2.distanceToSquared(point);
  3131. };
  3132. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3133. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3134. // It returns the min distance between the ray and the segment
  3135. // defined by v0 and v1
  3136. // It can also set two optional targets :
  3137. // - The closest point on the ray
  3138. // - The closest point on the segment
  3139. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3140. _segDir.copy(v1).sub(v0).normalize();
  3141. _diff.copy(this.origin).sub(_segCenter);
  3142. var segExtent = v0.distanceTo(v1) * 0.5;
  3143. var a01 = -this.direction.dot(_segDir);
  3144. var b0 = _diff.dot(this.direction);
  3145. var b1 = -_diff.dot(_segDir);
  3146. var c = _diff.lengthSq();
  3147. var det = Math.abs(1 - a01 * a01);
  3148. var s0, s1, sqrDist, extDet;
  3149. if (det > 0) {
  3150. // The ray and segment are not parallel.
  3151. s0 = a01 * b1 - b0;
  3152. s1 = a01 * b0 - b1;
  3153. extDet = segExtent * det;
  3154. if (s0 >= 0) {
  3155. if (s1 >= -extDet) {
  3156. if (s1 <= extDet) {
  3157. // region 0
  3158. // Minimum at interior points of ray and segment.
  3159. var invDet = 1 / det;
  3160. s0 *= invDet;
  3161. s1 *= invDet;
  3162. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3163. } else {
  3164. // region 1
  3165. s1 = segExtent;
  3166. s0 = Math.max(0, -(a01 * s1 + b0));
  3167. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3168. }
  3169. } else {
  3170. // region 5
  3171. s1 = -segExtent;
  3172. s0 = Math.max(0, -(a01 * s1 + b0));
  3173. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3174. }
  3175. } else {
  3176. if (s1 <= -extDet) {
  3177. // region 4
  3178. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3179. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3180. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3181. } else if (s1 <= extDet) {
  3182. // region 3
  3183. s0 = 0;
  3184. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3185. sqrDist = s1 * (s1 + 2 * b1) + c;
  3186. } else {
  3187. // region 2
  3188. s0 = Math.max(0, -(a01 * segExtent + b0));
  3189. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3190. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3191. }
  3192. }
  3193. } else {
  3194. // Ray and segment are parallel.
  3195. s1 = a01 > 0 ? -segExtent : segExtent;
  3196. s0 = Math.max(0, -(a01 * s1 + b0));
  3197. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3198. }
  3199. if (optionalPointOnRay) {
  3200. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3201. }
  3202. if (optionalPointOnSegment) {
  3203. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3204. }
  3205. return sqrDist;
  3206. };
  3207. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3208. _vector$2.subVectors(sphere.center, this.origin);
  3209. var tca = _vector$2.dot(this.direction);
  3210. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3211. var radius2 = sphere.radius * sphere.radius;
  3212. if (d2 > radius2) return null;
  3213. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3214. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3215. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3216. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3217. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3218. // in order to always return an intersect point that is in front of the ray.
  3219. if (t0 < 0) return this.at(t1, target); // else t0 is in front of the ray, so return the first collision point scaled by t0
  3220. return this.at(t0, target);
  3221. };
  3222. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3223. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3224. };
  3225. _proto.distanceToPlane = function distanceToPlane(plane) {
  3226. var denominator = plane.normal.dot(this.direction);
  3227. if (denominator === 0) {
  3228. // line is coplanar, return origin
  3229. if (plane.distanceToPoint(this.origin) === 0) {
  3230. return 0;
  3231. } // Null is preferable to undefined since undefined means.... it is undefined
  3232. return null;
  3233. }
  3234. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3235. return t >= 0 ? t : null;
  3236. };
  3237. _proto.intersectPlane = function intersectPlane(plane, target) {
  3238. var t = this.distanceToPlane(plane);
  3239. if (t === null) {
  3240. return null;
  3241. }
  3242. return this.at(t, target);
  3243. };
  3244. _proto.intersectsPlane = function intersectsPlane(plane) {
  3245. // check if the ray lies on the plane first
  3246. var distToPoint = plane.distanceToPoint(this.origin);
  3247. if (distToPoint === 0) {
  3248. return true;
  3249. }
  3250. var denominator = plane.normal.dot(this.direction);
  3251. if (denominator * distToPoint < 0) {
  3252. return true;
  3253. } // ray origin is behind the plane (and is pointing behind it)
  3254. return false;
  3255. };
  3256. _proto.intersectBox = function intersectBox(box, target) {
  3257. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3258. var invdirx = 1 / this.direction.x,
  3259. invdiry = 1 / this.direction.y,
  3260. invdirz = 1 / this.direction.z;
  3261. var origin = this.origin;
  3262. if (invdirx >= 0) {
  3263. tmin = (box.min.x - origin.x) * invdirx;
  3264. tmax = (box.max.x - origin.x) * invdirx;
  3265. } else {
  3266. tmin = (box.max.x - origin.x) * invdirx;
  3267. tmax = (box.min.x - origin.x) * invdirx;
  3268. }
  3269. if (invdiry >= 0) {
  3270. tymin = (box.min.y - origin.y) * invdiry;
  3271. tymax = (box.max.y - origin.y) * invdiry;
  3272. } else {
  3273. tymin = (box.max.y - origin.y) * invdiry;
  3274. tymax = (box.min.y - origin.y) * invdiry;
  3275. }
  3276. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  3277. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3278. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  3279. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  3280. if (invdirz >= 0) {
  3281. tzmin = (box.min.z - origin.z) * invdirz;
  3282. tzmax = (box.max.z - origin.z) * invdirz;
  3283. } else {
  3284. tzmin = (box.max.z - origin.z) * invdirz;
  3285. tzmax = (box.min.z - origin.z) * invdirz;
  3286. }
  3287. if (tmin > tzmax || tzmin > tmax) return null;
  3288. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  3289. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  3290. if (tmax < 0) return null;
  3291. return this.at(tmin >= 0 ? tmin : tmax, target);
  3292. };
  3293. _proto.intersectsBox = function intersectsBox(box) {
  3294. return this.intersectBox(box, _vector$2) !== null;
  3295. };
  3296. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  3297. // Compute the offset origin, edges, and normal.
  3298. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3299. _edge1.subVectors(b, a);
  3300. _edge2.subVectors(c, a);
  3301. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3302. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3303. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3304. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3305. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3306. var DdN = this.direction.dot(_normal);
  3307. var sign;
  3308. if (DdN > 0) {
  3309. if (backfaceCulling) return null;
  3310. sign = 1;
  3311. } else if (DdN < 0) {
  3312. sign = -1;
  3313. DdN = -DdN;
  3314. } else {
  3315. return null;
  3316. }
  3317. _diff.subVectors(this.origin, a);
  3318. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  3319. if (DdQxE2 < 0) {
  3320. return null;
  3321. }
  3322. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  3323. if (DdE1xQ < 0) {
  3324. return null;
  3325. } // b1+b2 > 1, no intersection
  3326. if (DdQxE2 + DdE1xQ > DdN) {
  3327. return null;
  3328. } // Line intersects triangle, check if ray does.
  3329. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  3330. if (QdN < 0) {
  3331. return null;
  3332. } // Ray intersects triangle.
  3333. return this.at(QdN / DdN, target);
  3334. };
  3335. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  3336. this.origin.applyMatrix4(matrix4);
  3337. this.direction.transformDirection(matrix4);
  3338. return this;
  3339. };
  3340. _proto.equals = function equals(ray) {
  3341. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  3342. };
  3343. return Ray;
  3344. }();
  3345. var Matrix4 = /*#__PURE__*/function () {
  3346. function Matrix4() {
  3347. Object.defineProperty(this, 'isMatrix4', {
  3348. value: true
  3349. });
  3350. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  3351. if (arguments.length > 0) {
  3352. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  3353. }
  3354. }
  3355. var _proto = Matrix4.prototype;
  3356. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  3357. var te = this.elements;
  3358. te[0] = n11;
  3359. te[4] = n12;
  3360. te[8] = n13;
  3361. te[12] = n14;
  3362. te[1] = n21;
  3363. te[5] = n22;
  3364. te[9] = n23;
  3365. te[13] = n24;
  3366. te[2] = n31;
  3367. te[6] = n32;
  3368. te[10] = n33;
  3369. te[14] = n34;
  3370. te[3] = n41;
  3371. te[7] = n42;
  3372. te[11] = n43;
  3373. te[15] = n44;
  3374. return this;
  3375. };
  3376. _proto.identity = function identity() {
  3377. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3378. return this;
  3379. };
  3380. _proto.clone = function clone() {
  3381. return new Matrix4().fromArray(this.elements);
  3382. };
  3383. _proto.copy = function copy(m) {
  3384. var te = this.elements;
  3385. var me = m.elements;
  3386. te[0] = me[0];
  3387. te[1] = me[1];
  3388. te[2] = me[2];
  3389. te[3] = me[3];
  3390. te[4] = me[4];
  3391. te[5] = me[5];
  3392. te[6] = me[6];
  3393. te[7] = me[7];
  3394. te[8] = me[8];
  3395. te[9] = me[9];
  3396. te[10] = me[10];
  3397. te[11] = me[11];
  3398. te[12] = me[12];
  3399. te[13] = me[13];
  3400. te[14] = me[14];
  3401. te[15] = me[15];
  3402. return this;
  3403. };
  3404. _proto.copyPosition = function copyPosition(m) {
  3405. var te = this.elements,
  3406. me = m.elements;
  3407. te[12] = me[12];
  3408. te[13] = me[13];
  3409. te[14] = me[14];
  3410. return this;
  3411. };
  3412. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  3413. xAxis.setFromMatrixColumn(this, 0);
  3414. yAxis.setFromMatrixColumn(this, 1);
  3415. zAxis.setFromMatrixColumn(this, 2);
  3416. return this;
  3417. };
  3418. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  3419. 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);
  3420. return this;
  3421. };
  3422. _proto.extractRotation = function extractRotation(m) {
  3423. // this method does not support reflection matrices
  3424. var te = this.elements;
  3425. var me = m.elements;
  3426. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  3427. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  3428. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  3429. te[0] = me[0] * scaleX;
  3430. te[1] = me[1] * scaleX;
  3431. te[2] = me[2] * scaleX;
  3432. te[3] = 0;
  3433. te[4] = me[4] * scaleY;
  3434. te[5] = me[5] * scaleY;
  3435. te[6] = me[6] * scaleY;
  3436. te[7] = 0;
  3437. te[8] = me[8] * scaleZ;
  3438. te[9] = me[9] * scaleZ;
  3439. te[10] = me[10] * scaleZ;
  3440. te[11] = 0;
  3441. te[12] = 0;
  3442. te[13] = 0;
  3443. te[14] = 0;
  3444. te[15] = 1;
  3445. return this;
  3446. };
  3447. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  3448. if (!(euler && euler.isEuler)) {
  3449. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  3450. }
  3451. var te = this.elements;
  3452. var x = euler.x,
  3453. y = euler.y,
  3454. z = euler.z;
  3455. var a = Math.cos(x),
  3456. b = Math.sin(x);
  3457. var c = Math.cos(y),
  3458. d = Math.sin(y);
  3459. var e = Math.cos(z),
  3460. f = Math.sin(z);
  3461. if (euler.order === 'XYZ') {
  3462. var ae = a * e,
  3463. af = a * f,
  3464. be = b * e,
  3465. bf = b * f;
  3466. te[0] = c * e;
  3467. te[4] = -c * f;
  3468. te[8] = d;
  3469. te[1] = af + be * d;
  3470. te[5] = ae - bf * d;
  3471. te[9] = -b * c;
  3472. te[2] = bf - ae * d;
  3473. te[6] = be + af * d;
  3474. te[10] = a * c;
  3475. } else if (euler.order === 'YXZ') {
  3476. var ce = c * e,
  3477. cf = c * f,
  3478. de = d * e,
  3479. df = d * f;
  3480. te[0] = ce + df * b;
  3481. te[4] = de * b - cf;
  3482. te[8] = a * d;
  3483. te[1] = a * f;
  3484. te[5] = a * e;
  3485. te[9] = -b;
  3486. te[2] = cf * b - de;
  3487. te[6] = df + ce * b;
  3488. te[10] = a * c;
  3489. } else if (euler.order === 'ZXY') {
  3490. var _ce = c * e,
  3491. _cf = c * f,
  3492. _de = d * e,
  3493. _df = d * f;
  3494. te[0] = _ce - _df * b;
  3495. te[4] = -a * f;
  3496. te[8] = _de + _cf * b;
  3497. te[1] = _cf + _de * b;
  3498. te[5] = a * e;
  3499. te[9] = _df - _ce * b;
  3500. te[2] = -a * d;
  3501. te[6] = b;
  3502. te[10] = a * c;
  3503. } else if (euler.order === 'ZYX') {
  3504. var _ae = a * e,
  3505. _af = a * f,
  3506. _be = b * e,
  3507. _bf = b * f;
  3508. te[0] = c * e;
  3509. te[4] = _be * d - _af;
  3510. te[8] = _ae * d + _bf;
  3511. te[1] = c * f;
  3512. te[5] = _bf * d + _ae;
  3513. te[9] = _af * d - _be;
  3514. te[2] = -d;
  3515. te[6] = b * c;
  3516. te[10] = a * c;
  3517. } else if (euler.order === 'YZX') {
  3518. var ac = a * c,
  3519. ad = a * d,
  3520. bc = b * c,
  3521. bd = b * d;
  3522. te[0] = c * e;
  3523. te[4] = bd - ac * f;
  3524. te[8] = bc * f + ad;
  3525. te[1] = f;
  3526. te[5] = a * e;
  3527. te[9] = -b * e;
  3528. te[2] = -d * e;
  3529. te[6] = ad * f + bc;
  3530. te[10] = ac - bd * f;
  3531. } else if (euler.order === 'XZY') {
  3532. var _ac = a * c,
  3533. _ad = a * d,
  3534. _bc = b * c,
  3535. _bd = b * d;
  3536. te[0] = c * e;
  3537. te[4] = -f;
  3538. te[8] = d * e;
  3539. te[1] = _ac * f + _bd;
  3540. te[5] = a * e;
  3541. te[9] = _ad * f - _bc;
  3542. te[2] = _bc * f - _ad;
  3543. te[6] = b * e;
  3544. te[10] = _bd * f + _ac;
  3545. } // bottom row
  3546. te[3] = 0;
  3547. te[7] = 0;
  3548. te[11] = 0; // last column
  3549. te[12] = 0;
  3550. te[13] = 0;
  3551. te[14] = 0;
  3552. te[15] = 1;
  3553. return this;
  3554. };
  3555. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  3556. return this.compose(_zero, q, _one);
  3557. };
  3558. _proto.lookAt = function lookAt(eye, target, up) {
  3559. var te = this.elements;
  3560. _z.subVectors(eye, target);
  3561. if (_z.lengthSq() === 0) {
  3562. // eye and target are in the same position
  3563. _z.z = 1;
  3564. }
  3565. _z.normalize();
  3566. _x.crossVectors(up, _z);
  3567. if (_x.lengthSq() === 0) {
  3568. // up and z are parallel
  3569. if (Math.abs(up.z) === 1) {
  3570. _z.x += 0.0001;
  3571. } else {
  3572. _z.z += 0.0001;
  3573. }
  3574. _z.normalize();
  3575. _x.crossVectors(up, _z);
  3576. }
  3577. _x.normalize();
  3578. _y.crossVectors(_z, _x);
  3579. te[0] = _x.x;
  3580. te[4] = _y.x;
  3581. te[8] = _z.x;
  3582. te[1] = _x.y;
  3583. te[5] = _y.y;
  3584. te[9] = _z.y;
  3585. te[2] = _x.z;
  3586. te[6] = _y.z;
  3587. te[10] = _z.z;
  3588. return this;
  3589. };
  3590. _proto.multiply = function multiply(m, n) {
  3591. if (n !== undefined) {
  3592. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  3593. return this.multiplyMatrices(m, n);
  3594. }
  3595. return this.multiplyMatrices(this, m);
  3596. };
  3597. _proto.premultiply = function premultiply(m) {
  3598. return this.multiplyMatrices(m, this);
  3599. };
  3600. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  3601. var ae = a.elements;
  3602. var be = b.elements;
  3603. var te = this.elements;
  3604. var a11 = ae[0],
  3605. a12 = ae[4],
  3606. a13 = ae[8],
  3607. a14 = ae[12];
  3608. var a21 = ae[1],
  3609. a22 = ae[5],
  3610. a23 = ae[9],
  3611. a24 = ae[13];
  3612. var a31 = ae[2],
  3613. a32 = ae[6],
  3614. a33 = ae[10],
  3615. a34 = ae[14];
  3616. var a41 = ae[3],
  3617. a42 = ae[7],
  3618. a43 = ae[11],
  3619. a44 = ae[15];
  3620. var b11 = be[0],
  3621. b12 = be[4],
  3622. b13 = be[8],
  3623. b14 = be[12];
  3624. var b21 = be[1],
  3625. b22 = be[5],
  3626. b23 = be[9],
  3627. b24 = be[13];
  3628. var b31 = be[2],
  3629. b32 = be[6],
  3630. b33 = be[10],
  3631. b34 = be[14];
  3632. var b41 = be[3],
  3633. b42 = be[7],
  3634. b43 = be[11],
  3635. b44 = be[15];
  3636. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3637. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3638. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3639. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3640. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3641. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3642. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3643. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3644. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3645. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3646. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3647. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3648. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3649. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3650. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3651. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3652. return this;
  3653. };
  3654. _proto.multiplyScalar = function multiplyScalar(s) {
  3655. var te = this.elements;
  3656. te[0] *= s;
  3657. te[4] *= s;
  3658. te[8] *= s;
  3659. te[12] *= s;
  3660. te[1] *= s;
  3661. te[5] *= s;
  3662. te[9] *= s;
  3663. te[13] *= s;
  3664. te[2] *= s;
  3665. te[6] *= s;
  3666. te[10] *= s;
  3667. te[14] *= s;
  3668. te[3] *= s;
  3669. te[7] *= s;
  3670. te[11] *= s;
  3671. te[15] *= s;
  3672. return this;
  3673. };
  3674. _proto.determinant = function determinant() {
  3675. var te = this.elements;
  3676. var n11 = te[0],
  3677. n12 = te[4],
  3678. n13 = te[8],
  3679. n14 = te[12];
  3680. var n21 = te[1],
  3681. n22 = te[5],
  3682. n23 = te[9],
  3683. n24 = te[13];
  3684. var n31 = te[2],
  3685. n32 = te[6],
  3686. n33 = te[10],
  3687. n34 = te[14];
  3688. var n41 = te[3],
  3689. n42 = te[7],
  3690. n43 = te[11],
  3691. n44 = te[15]; //TODO: make this more efficient
  3692. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3693. 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);
  3694. };
  3695. _proto.transpose = function transpose() {
  3696. var te = this.elements;
  3697. var tmp;
  3698. tmp = te[1];
  3699. te[1] = te[4];
  3700. te[4] = tmp;
  3701. tmp = te[2];
  3702. te[2] = te[8];
  3703. te[8] = tmp;
  3704. tmp = te[6];
  3705. te[6] = te[9];
  3706. te[9] = tmp;
  3707. tmp = te[3];
  3708. te[3] = te[12];
  3709. te[12] = tmp;
  3710. tmp = te[7];
  3711. te[7] = te[13];
  3712. te[13] = tmp;
  3713. tmp = te[11];
  3714. te[11] = te[14];
  3715. te[14] = tmp;
  3716. return this;
  3717. };
  3718. _proto.setPosition = function setPosition(x, y, z) {
  3719. var te = this.elements;
  3720. if (x.isVector3) {
  3721. te[12] = x.x;
  3722. te[13] = x.y;
  3723. te[14] = x.z;
  3724. } else {
  3725. te[12] = x;
  3726. te[13] = y;
  3727. te[14] = z;
  3728. }
  3729. return this;
  3730. };
  3731. _proto.invert = function invert() {
  3732. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3733. var te = this.elements,
  3734. n11 = te[0],
  3735. n21 = te[1],
  3736. n31 = te[2],
  3737. n41 = te[3],
  3738. n12 = te[4],
  3739. n22 = te[5],
  3740. n32 = te[6],
  3741. n42 = te[7],
  3742. n13 = te[8],
  3743. n23 = te[9],
  3744. n33 = te[10],
  3745. n43 = te[11],
  3746. n14 = te[12],
  3747. n24 = te[13],
  3748. n34 = te[14],
  3749. n44 = te[15],
  3750. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3751. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3752. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3753. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3754. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3755. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  3756. var detInv = 1 / det;
  3757. te[0] = t11 * detInv;
  3758. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  3759. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  3760. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  3761. te[4] = t12 * detInv;
  3762. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  3763. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  3764. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  3765. te[8] = t13 * detInv;
  3766. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  3767. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  3768. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  3769. te[12] = t14 * detInv;
  3770. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  3771. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  3772. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  3773. return this;
  3774. };
  3775. _proto.scale = function scale(v) {
  3776. var te = this.elements;
  3777. var x = v.x,
  3778. y = v.y,
  3779. z = v.z;
  3780. te[0] *= x;
  3781. te[4] *= y;
  3782. te[8] *= z;
  3783. te[1] *= x;
  3784. te[5] *= y;
  3785. te[9] *= z;
  3786. te[2] *= x;
  3787. te[6] *= y;
  3788. te[10] *= z;
  3789. te[3] *= x;
  3790. te[7] *= y;
  3791. te[11] *= z;
  3792. return this;
  3793. };
  3794. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  3795. var te = this.elements;
  3796. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  3797. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  3798. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  3799. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  3800. };
  3801. _proto.makeTranslation = function makeTranslation(x, y, z) {
  3802. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  3803. return this;
  3804. };
  3805. _proto.makeRotationX = function makeRotationX(theta) {
  3806. var c = Math.cos(theta),
  3807. s = Math.sin(theta);
  3808. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  3809. return this;
  3810. };
  3811. _proto.makeRotationY = function makeRotationY(theta) {
  3812. var c = Math.cos(theta),
  3813. s = Math.sin(theta);
  3814. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  3815. return this;
  3816. };
  3817. _proto.makeRotationZ = function makeRotationZ(theta) {
  3818. var c = Math.cos(theta),
  3819. s = Math.sin(theta);
  3820. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3821. return this;
  3822. };
  3823. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  3824. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3825. var c = Math.cos(angle);
  3826. var s = Math.sin(angle);
  3827. var t = 1 - c;
  3828. var x = axis.x,
  3829. y = axis.y,
  3830. z = axis.z;
  3831. var tx = t * x,
  3832. ty = t * y;
  3833. 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);
  3834. return this;
  3835. };
  3836. _proto.makeScale = function makeScale(x, y, z) {
  3837. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  3838. return this;
  3839. };
  3840. _proto.makeShear = function makeShear(x, y, z) {
  3841. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  3842. return this;
  3843. };
  3844. _proto.compose = function compose(position, quaternion, scale) {
  3845. var te = this.elements;
  3846. var x = quaternion._x,
  3847. y = quaternion._y,
  3848. z = quaternion._z,
  3849. w = quaternion._w;
  3850. var x2 = x + x,
  3851. y2 = y + y,
  3852. z2 = z + z;
  3853. var xx = x * x2,
  3854. xy = x * y2,
  3855. xz = x * z2;
  3856. var yy = y * y2,
  3857. yz = y * z2,
  3858. zz = z * z2;
  3859. var wx = w * x2,
  3860. wy = w * y2,
  3861. wz = w * z2;
  3862. var sx = scale.x,
  3863. sy = scale.y,
  3864. sz = scale.z;
  3865. te[0] = (1 - (yy + zz)) * sx;
  3866. te[1] = (xy + wz) * sx;
  3867. te[2] = (xz - wy) * sx;
  3868. te[3] = 0;
  3869. te[4] = (xy - wz) * sy;
  3870. te[5] = (1 - (xx + zz)) * sy;
  3871. te[6] = (yz + wx) * sy;
  3872. te[7] = 0;
  3873. te[8] = (xz + wy) * sz;
  3874. te[9] = (yz - wx) * sz;
  3875. te[10] = (1 - (xx + yy)) * sz;
  3876. te[11] = 0;
  3877. te[12] = position.x;
  3878. te[13] = position.y;
  3879. te[14] = position.z;
  3880. te[15] = 1;
  3881. return this;
  3882. };
  3883. _proto.decompose = function decompose(position, quaternion, scale) {
  3884. var te = this.elements;
  3885. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  3886. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  3887. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  3888. var det = this.determinant();
  3889. if (det < 0) sx = -sx;
  3890. position.x = te[12];
  3891. position.y = te[13];
  3892. position.z = te[14]; // scale the rotation part
  3893. _m1.copy(this);
  3894. var invSX = 1 / sx;
  3895. var invSY = 1 / sy;
  3896. var invSZ = 1 / sz;
  3897. _m1.elements[0] *= invSX;
  3898. _m1.elements[1] *= invSX;
  3899. _m1.elements[2] *= invSX;
  3900. _m1.elements[4] *= invSY;
  3901. _m1.elements[5] *= invSY;
  3902. _m1.elements[6] *= invSY;
  3903. _m1.elements[8] *= invSZ;
  3904. _m1.elements[9] *= invSZ;
  3905. _m1.elements[10] *= invSZ;
  3906. quaternion.setFromRotationMatrix(_m1);
  3907. scale.x = sx;
  3908. scale.y = sy;
  3909. scale.z = sz;
  3910. return this;
  3911. };
  3912. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  3913. if (far === undefined) {
  3914. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  3915. }
  3916. var te = this.elements;
  3917. var x = 2 * near / (right - left);
  3918. var y = 2 * near / (top - bottom);
  3919. var a = (right + left) / (right - left);
  3920. var b = (top + bottom) / (top - bottom);
  3921. var c = -(far + near) / (far - near);
  3922. var d = -2 * far * near / (far - near);
  3923. te[0] = x;
  3924. te[4] = 0;
  3925. te[8] = a;
  3926. te[12] = 0;
  3927. te[1] = 0;
  3928. te[5] = y;
  3929. te[9] = b;
  3930. te[13] = 0;
  3931. te[2] = 0;
  3932. te[6] = 0;
  3933. te[10] = c;
  3934. te[14] = d;
  3935. te[3] = 0;
  3936. te[7] = 0;
  3937. te[11] = -1;
  3938. te[15] = 0;
  3939. return this;
  3940. };
  3941. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  3942. var te = this.elements;
  3943. var w = 1.0 / (right - left);
  3944. var h = 1.0 / (top - bottom);
  3945. var p = 1.0 / (far - near);
  3946. var x = (right + left) * w;
  3947. var y = (top + bottom) * h;
  3948. var z = (far + near) * p;
  3949. te[0] = 2 * w;
  3950. te[4] = 0;
  3951. te[8] = 0;
  3952. te[12] = -x;
  3953. te[1] = 0;
  3954. te[5] = 2 * h;
  3955. te[9] = 0;
  3956. te[13] = -y;
  3957. te[2] = 0;
  3958. te[6] = 0;
  3959. te[10] = -2 * p;
  3960. te[14] = -z;
  3961. te[3] = 0;
  3962. te[7] = 0;
  3963. te[11] = 0;
  3964. te[15] = 1;
  3965. return this;
  3966. };
  3967. _proto.equals = function equals(matrix) {
  3968. var te = this.elements;
  3969. var me = matrix.elements;
  3970. for (var i = 0; i < 16; i++) {
  3971. if (te[i] !== me[i]) return false;
  3972. }
  3973. return true;
  3974. };
  3975. _proto.fromArray = function fromArray(array, offset) {
  3976. if (offset === void 0) {
  3977. offset = 0;
  3978. }
  3979. for (var i = 0; i < 16; i++) {
  3980. this.elements[i] = array[i + offset];
  3981. }
  3982. return this;
  3983. };
  3984. _proto.toArray = function toArray(array, offset) {
  3985. if (array === void 0) {
  3986. array = [];
  3987. }
  3988. if (offset === void 0) {
  3989. offset = 0;
  3990. }
  3991. var te = this.elements;
  3992. array[offset] = te[0];
  3993. array[offset + 1] = te[1];
  3994. array[offset + 2] = te[2];
  3995. array[offset + 3] = te[3];
  3996. array[offset + 4] = te[4];
  3997. array[offset + 5] = te[5];
  3998. array[offset + 6] = te[6];
  3999. array[offset + 7] = te[7];
  4000. array[offset + 8] = te[8];
  4001. array[offset + 9] = te[9];
  4002. array[offset + 10] = te[10];
  4003. array[offset + 11] = te[11];
  4004. array[offset + 12] = te[12];
  4005. array[offset + 13] = te[13];
  4006. array[offset + 14] = te[14];
  4007. array[offset + 15] = te[15];
  4008. return array;
  4009. };
  4010. return Matrix4;
  4011. }();
  4012. var _v1$1 = /*@__PURE__*/new Vector3();
  4013. var _m1 = /*@__PURE__*/new Matrix4();
  4014. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  4015. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  4016. var _x = /*@__PURE__*/new Vector3();
  4017. var _y = /*@__PURE__*/new Vector3();
  4018. var _z = /*@__PURE__*/new Vector3();
  4019. var Euler = /*#__PURE__*/function () {
  4020. function Euler(x, y, z, order) {
  4021. if (x === void 0) {
  4022. x = 0;
  4023. }
  4024. if (y === void 0) {
  4025. y = 0;
  4026. }
  4027. if (z === void 0) {
  4028. z = 0;
  4029. }
  4030. if (order === void 0) {
  4031. order = Euler.DefaultOrder;
  4032. }
  4033. Object.defineProperty(this, 'isEuler', {
  4034. value: true
  4035. });
  4036. this._x = x;
  4037. this._y = y;
  4038. this._z = z;
  4039. this._order = order;
  4040. }
  4041. var _proto = Euler.prototype;
  4042. _proto.set = function set(x, y, z, order) {
  4043. this._x = x;
  4044. this._y = y;
  4045. this._z = z;
  4046. this._order = order || this._order;
  4047. this._onChangeCallback();
  4048. return this;
  4049. };
  4050. _proto.clone = function clone() {
  4051. return new this.constructor(this._x, this._y, this._z, this._order);
  4052. };
  4053. _proto.copy = function copy(euler) {
  4054. this._x = euler._x;
  4055. this._y = euler._y;
  4056. this._z = euler._z;
  4057. this._order = euler._order;
  4058. this._onChangeCallback();
  4059. return this;
  4060. };
  4061. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4062. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4063. var te = m.elements;
  4064. var m11 = te[0],
  4065. m12 = te[4],
  4066. m13 = te[8];
  4067. var m21 = te[1],
  4068. m22 = te[5],
  4069. m23 = te[9];
  4070. var m31 = te[2],
  4071. m32 = te[6],
  4072. m33 = te[10];
  4073. order = order || this._order;
  4074. switch (order) {
  4075. case 'XYZ':
  4076. this._y = Math.asin(clamp(m13, -1, 1));
  4077. if (Math.abs(m13) < 0.9999999) {
  4078. this._x = Math.atan2(-m23, m33);
  4079. this._z = Math.atan2(-m12, m11);
  4080. } else {
  4081. this._x = Math.atan2(m32, m22);
  4082. this._z = 0;
  4083. }
  4084. break;
  4085. case 'YXZ':
  4086. this._x = Math.asin(-clamp(m23, -1, 1));
  4087. if (Math.abs(m23) < 0.9999999) {
  4088. this._y = Math.atan2(m13, m33);
  4089. this._z = Math.atan2(m21, m22);
  4090. } else {
  4091. this._y = Math.atan2(-m31, m11);
  4092. this._z = 0;
  4093. }
  4094. break;
  4095. case 'ZXY':
  4096. this._x = Math.asin(clamp(m32, -1, 1));
  4097. if (Math.abs(m32) < 0.9999999) {
  4098. this._y = Math.atan2(-m31, m33);
  4099. this._z = Math.atan2(-m12, m22);
  4100. } else {
  4101. this._y = 0;
  4102. this._z = Math.atan2(m21, m11);
  4103. }
  4104. break;
  4105. case 'ZYX':
  4106. this._y = Math.asin(-clamp(m31, -1, 1));
  4107. if (Math.abs(m31) < 0.9999999) {
  4108. this._x = Math.atan2(m32, m33);
  4109. this._z = Math.atan2(m21, m11);
  4110. } else {
  4111. this._x = 0;
  4112. this._z = Math.atan2(-m12, m22);
  4113. }
  4114. break;
  4115. case 'YZX':
  4116. this._z = Math.asin(clamp(m21, -1, 1));
  4117. if (Math.abs(m21) < 0.9999999) {
  4118. this._x = Math.atan2(-m23, m22);
  4119. this._y = Math.atan2(-m31, m11);
  4120. } else {
  4121. this._x = 0;
  4122. this._y = Math.atan2(m13, m33);
  4123. }
  4124. break;
  4125. case 'XZY':
  4126. this._z = Math.asin(-clamp(m12, -1, 1));
  4127. if (Math.abs(m12) < 0.9999999) {
  4128. this._x = Math.atan2(m32, m22);
  4129. this._y = Math.atan2(m13, m11);
  4130. } else {
  4131. this._x = Math.atan2(-m23, m33);
  4132. this._y = 0;
  4133. }
  4134. break;
  4135. default:
  4136. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4137. }
  4138. this._order = order;
  4139. if (update !== false) this._onChangeCallback();
  4140. return this;
  4141. };
  4142. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4143. _matrix.makeRotationFromQuaternion(q);
  4144. return this.setFromRotationMatrix(_matrix, order, update);
  4145. };
  4146. _proto.setFromVector3 = function setFromVector3(v, order) {
  4147. return this.set(v.x, v.y, v.z, order || this._order);
  4148. };
  4149. _proto.reorder = function reorder(newOrder) {
  4150. // WARNING: this discards revolution information -bhouston
  4151. _quaternion$1.setFromEuler(this);
  4152. return this.setFromQuaternion(_quaternion$1, newOrder);
  4153. };
  4154. _proto.equals = function equals(euler) {
  4155. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4156. };
  4157. _proto.fromArray = function fromArray(array) {
  4158. this._x = array[0];
  4159. this._y = array[1];
  4160. this._z = array[2];
  4161. if (array[3] !== undefined) this._order = array[3];
  4162. this._onChangeCallback();
  4163. return this;
  4164. };
  4165. _proto.toArray = function toArray(array, offset) {
  4166. if (array === void 0) {
  4167. array = [];
  4168. }
  4169. if (offset === void 0) {
  4170. offset = 0;
  4171. }
  4172. array[offset] = this._x;
  4173. array[offset + 1] = this._y;
  4174. array[offset + 2] = this._z;
  4175. array[offset + 3] = this._order;
  4176. return array;
  4177. };
  4178. _proto.toVector3 = function toVector3(optionalResult) {
  4179. if (optionalResult) {
  4180. return optionalResult.set(this._x, this._y, this._z);
  4181. } else {
  4182. return new Vector3(this._x, this._y, this._z);
  4183. }
  4184. };
  4185. _proto._onChange = function _onChange(callback) {
  4186. this._onChangeCallback = callback;
  4187. return this;
  4188. };
  4189. _proto._onChangeCallback = function _onChangeCallback() {};
  4190. _createClass(Euler, [{
  4191. key: "x",
  4192. get: function get() {
  4193. return this._x;
  4194. },
  4195. set: function set(value) {
  4196. this._x = value;
  4197. this._onChangeCallback();
  4198. }
  4199. }, {
  4200. key: "y",
  4201. get: function get() {
  4202. return this._y;
  4203. },
  4204. set: function set(value) {
  4205. this._y = value;
  4206. this._onChangeCallback();
  4207. }
  4208. }, {
  4209. key: "z",
  4210. get: function get() {
  4211. return this._z;
  4212. },
  4213. set: function set(value) {
  4214. this._z = value;
  4215. this._onChangeCallback();
  4216. }
  4217. }, {
  4218. key: "order",
  4219. get: function get() {
  4220. return this._order;
  4221. },
  4222. set: function set(value) {
  4223. this._order = value;
  4224. this._onChangeCallback();
  4225. }
  4226. }]);
  4227. return Euler;
  4228. }();
  4229. Euler.DefaultOrder = 'XYZ';
  4230. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4231. var _matrix = /*@__PURE__*/new Matrix4();
  4232. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4233. var Layers = /*#__PURE__*/function () {
  4234. function Layers() {
  4235. this.mask = 1 | 0;
  4236. }
  4237. var _proto = Layers.prototype;
  4238. _proto.set = function set(channel) {
  4239. this.mask = 1 << channel | 0;
  4240. };
  4241. _proto.enable = function enable(channel) {
  4242. this.mask |= 1 << channel | 0;
  4243. };
  4244. _proto.enableAll = function enableAll() {
  4245. this.mask = 0xffffffff | 0;
  4246. };
  4247. _proto.toggle = function toggle(channel) {
  4248. this.mask ^= 1 << channel | 0;
  4249. };
  4250. _proto.disable = function disable(channel) {
  4251. this.mask &= ~(1 << channel | 0);
  4252. };
  4253. _proto.disableAll = function disableAll() {
  4254. this.mask = 0;
  4255. };
  4256. _proto.test = function test(layers) {
  4257. return (this.mask & layers.mask) !== 0;
  4258. };
  4259. return Layers;
  4260. }();
  4261. var _object3DId = 0;
  4262. var _v1$2 = new Vector3();
  4263. var _q1 = new Quaternion();
  4264. var _m1$1 = new Matrix4();
  4265. var _target = new Vector3();
  4266. var _position = new Vector3();
  4267. var _scale = new Vector3();
  4268. var _quaternion$2 = new Quaternion();
  4269. var _xAxis = new Vector3(1, 0, 0);
  4270. var _yAxis = new Vector3(0, 1, 0);
  4271. var _zAxis = new Vector3(0, 0, 1);
  4272. var _addedEvent = {
  4273. type: 'added'
  4274. };
  4275. var _removedEvent = {
  4276. type: 'removed'
  4277. };
  4278. function Object3D() {
  4279. Object.defineProperty(this, 'id', {
  4280. value: _object3DId++
  4281. });
  4282. this.uuid = MathUtils.generateUUID();
  4283. this.name = '';
  4284. this.type = 'Object3D';
  4285. this.parent = null;
  4286. this.children = [];
  4287. this.up = Object3D.DefaultUp.clone();
  4288. var position = new Vector3();
  4289. var rotation = new Euler();
  4290. var quaternion = new Quaternion();
  4291. var scale = new Vector3(1, 1, 1);
  4292. function onRotationChange() {
  4293. quaternion.setFromEuler(rotation, false);
  4294. }
  4295. function onQuaternionChange() {
  4296. rotation.setFromQuaternion(quaternion, undefined, false);
  4297. }
  4298. rotation._onChange(onRotationChange);
  4299. quaternion._onChange(onQuaternionChange);
  4300. Object.defineProperties(this, {
  4301. position: {
  4302. configurable: true,
  4303. enumerable: true,
  4304. value: position
  4305. },
  4306. rotation: {
  4307. configurable: true,
  4308. enumerable: true,
  4309. value: rotation
  4310. },
  4311. quaternion: {
  4312. configurable: true,
  4313. enumerable: true,
  4314. value: quaternion
  4315. },
  4316. scale: {
  4317. configurable: true,
  4318. enumerable: true,
  4319. value: scale
  4320. },
  4321. modelViewMatrix: {
  4322. value: new Matrix4()
  4323. },
  4324. normalMatrix: {
  4325. value: new Matrix3()
  4326. }
  4327. });
  4328. this.matrix = new Matrix4();
  4329. this.matrixWorld = new Matrix4();
  4330. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  4331. this.matrixWorldNeedsUpdate = false;
  4332. this.layers = new Layers();
  4333. this.visible = true;
  4334. this.castShadow = false;
  4335. this.receiveShadow = false;
  4336. this.frustumCulled = true;
  4337. this.renderOrder = 0;
  4338. this.animations = [];
  4339. this.userData = {};
  4340. }
  4341. Object3D.DefaultUp = new Vector3(0, 1, 0);
  4342. Object3D.DefaultMatrixAutoUpdate = true;
  4343. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  4344. constructor: Object3D,
  4345. isObject3D: true,
  4346. onBeforeRender: function onBeforeRender() {},
  4347. onAfterRender: function onAfterRender() {},
  4348. applyMatrix4: function applyMatrix4(matrix) {
  4349. if (this.matrixAutoUpdate) this.updateMatrix();
  4350. this.matrix.premultiply(matrix);
  4351. this.matrix.decompose(this.position, this.quaternion, this.scale);
  4352. },
  4353. applyQuaternion: function applyQuaternion(q) {
  4354. this.quaternion.premultiply(q);
  4355. return this;
  4356. },
  4357. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  4358. // assumes axis is normalized
  4359. this.quaternion.setFromAxisAngle(axis, angle);
  4360. },
  4361. setRotationFromEuler: function setRotationFromEuler(euler) {
  4362. this.quaternion.setFromEuler(euler, true);
  4363. },
  4364. setRotationFromMatrix: function setRotationFromMatrix(m) {
  4365. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4366. this.quaternion.setFromRotationMatrix(m);
  4367. },
  4368. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  4369. // assumes q is normalized
  4370. this.quaternion.copy(q);
  4371. },
  4372. rotateOnAxis: function rotateOnAxis(axis, angle) {
  4373. // rotate object on axis in object space
  4374. // axis is assumed to be normalized
  4375. _q1.setFromAxisAngle(axis, angle);
  4376. this.quaternion.multiply(_q1);
  4377. return this;
  4378. },
  4379. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  4380. // rotate object on axis in world space
  4381. // axis is assumed to be normalized
  4382. // method assumes no rotated parent
  4383. _q1.setFromAxisAngle(axis, angle);
  4384. this.quaternion.premultiply(_q1);
  4385. return this;
  4386. },
  4387. rotateX: function rotateX(angle) {
  4388. return this.rotateOnAxis(_xAxis, angle);
  4389. },
  4390. rotateY: function rotateY(angle) {
  4391. return this.rotateOnAxis(_yAxis, angle);
  4392. },
  4393. rotateZ: function rotateZ(angle) {
  4394. return this.rotateOnAxis(_zAxis, angle);
  4395. },
  4396. translateOnAxis: function translateOnAxis(axis, distance) {
  4397. // translate object by distance along axis in object space
  4398. // axis is assumed to be normalized
  4399. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  4400. this.position.add(_v1$2.multiplyScalar(distance));
  4401. return this;
  4402. },
  4403. translateX: function translateX(distance) {
  4404. return this.translateOnAxis(_xAxis, distance);
  4405. },
  4406. translateY: function translateY(distance) {
  4407. return this.translateOnAxis(_yAxis, distance);
  4408. },
  4409. translateZ: function translateZ(distance) {
  4410. return this.translateOnAxis(_zAxis, distance);
  4411. },
  4412. localToWorld: function localToWorld(vector) {
  4413. return vector.applyMatrix4(this.matrixWorld);
  4414. },
  4415. worldToLocal: function worldToLocal(vector) {
  4416. return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());
  4417. },
  4418. lookAt: function lookAt(x, y, z) {
  4419. // This method does not support objects having non-uniformly-scaled parent(s)
  4420. if (x.isVector3) {
  4421. _target.copy(x);
  4422. } else {
  4423. _target.set(x, y, z);
  4424. }
  4425. var parent = this.parent;
  4426. this.updateWorldMatrix(true, false);
  4427. _position.setFromMatrixPosition(this.matrixWorld);
  4428. if (this.isCamera || this.isLight) {
  4429. _m1$1.lookAt(_position, _target, this.up);
  4430. } else {
  4431. _m1$1.lookAt(_target, _position, this.up);
  4432. }
  4433. this.quaternion.setFromRotationMatrix(_m1$1);
  4434. if (parent) {
  4435. _m1$1.extractRotation(parent.matrixWorld);
  4436. _q1.setFromRotationMatrix(_m1$1);
  4437. this.quaternion.premultiply(_q1.invert());
  4438. }
  4439. },
  4440. add: function add(object) {
  4441. if (arguments.length > 1) {
  4442. for (var i = 0; i < arguments.length; i++) {
  4443. this.add(arguments[i]);
  4444. }
  4445. return this;
  4446. }
  4447. if (object === this) {
  4448. console.error('THREE.Object3D.add: object can\'t be added as a child of itself.', object);
  4449. return this;
  4450. }
  4451. if (object && object.isObject3D) {
  4452. if (object.parent !== null) {
  4453. object.parent.remove(object);
  4454. }
  4455. object.parent = this;
  4456. this.children.push(object);
  4457. object.dispatchEvent(_addedEvent);
  4458. } else {
  4459. console.error('THREE.Object3D.add: object not an instance of THREE.Object3D.', object);
  4460. }
  4461. return this;
  4462. },
  4463. remove: function remove(object) {
  4464. if (arguments.length > 1) {
  4465. for (var i = 0; i < arguments.length; i++) {
  4466. this.remove(arguments[i]);
  4467. }
  4468. return this;
  4469. }
  4470. var index = this.children.indexOf(object);
  4471. if (index !== -1) {
  4472. object.parent = null;
  4473. this.children.splice(index, 1);
  4474. object.dispatchEvent(_removedEvent);
  4475. }
  4476. return this;
  4477. },
  4478. clear: function clear() {
  4479. for (var i = 0; i < this.children.length; i++) {
  4480. var object = this.children[i];
  4481. object.parent = null;
  4482. object.dispatchEvent(_removedEvent);
  4483. }
  4484. this.children.length = 0;
  4485. return this;
  4486. },
  4487. attach: function attach(object) {
  4488. // adds object as a child of this, while maintaining the object's world transform
  4489. this.updateWorldMatrix(true, false);
  4490. _m1$1.copy(this.matrixWorld).invert();
  4491. if (object.parent !== null) {
  4492. object.parent.updateWorldMatrix(true, false);
  4493. _m1$1.multiply(object.parent.matrixWorld);
  4494. }
  4495. object.applyMatrix4(_m1$1);
  4496. object.updateWorldMatrix(false, false);
  4497. this.add(object);
  4498. return this;
  4499. },
  4500. getObjectById: function getObjectById(id) {
  4501. return this.getObjectByProperty('id', id);
  4502. },
  4503. getObjectByName: function getObjectByName(name) {
  4504. return this.getObjectByProperty('name', name);
  4505. },
  4506. getObjectByProperty: function getObjectByProperty(name, value) {
  4507. if (this[name] === value) return this;
  4508. for (var i = 0, l = this.children.length; i < l; i++) {
  4509. var child = this.children[i];
  4510. var object = child.getObjectByProperty(name, value);
  4511. if (object !== undefined) {
  4512. return object;
  4513. }
  4514. }
  4515. return undefined;
  4516. },
  4517. getWorldPosition: function getWorldPosition(target) {
  4518. if (target === undefined) {
  4519. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  4520. target = new Vector3();
  4521. }
  4522. this.updateWorldMatrix(true, false);
  4523. return target.setFromMatrixPosition(this.matrixWorld);
  4524. },
  4525. getWorldQuaternion: function getWorldQuaternion(target) {
  4526. if (target === undefined) {
  4527. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  4528. target = new Quaternion();
  4529. }
  4530. this.updateWorldMatrix(true, false);
  4531. this.matrixWorld.decompose(_position, target, _scale);
  4532. return target;
  4533. },
  4534. getWorldScale: function getWorldScale(target) {
  4535. if (target === undefined) {
  4536. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  4537. target = new Vector3();
  4538. }
  4539. this.updateWorldMatrix(true, false);
  4540. this.matrixWorld.decompose(_position, _quaternion$2, target);
  4541. return target;
  4542. },
  4543. getWorldDirection: function getWorldDirection(target) {
  4544. if (target === undefined) {
  4545. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  4546. target = new Vector3();
  4547. }
  4548. this.updateWorldMatrix(true, false);
  4549. var e = this.matrixWorld.elements;
  4550. return target.set(e[8], e[9], e[10]).normalize();
  4551. },
  4552. raycast: function raycast() {},
  4553. traverse: function traverse(callback) {
  4554. callback(this);
  4555. var children = this.children;
  4556. for (var i = 0, l = children.length; i < l; i++) {
  4557. children[i].traverse(callback);
  4558. }
  4559. },
  4560. traverseVisible: function traverseVisible(callback) {
  4561. if (this.visible === false) return;
  4562. callback(this);
  4563. var children = this.children;
  4564. for (var i = 0, l = children.length; i < l; i++) {
  4565. children[i].traverseVisible(callback);
  4566. }
  4567. },
  4568. traverseAncestors: function traverseAncestors(callback) {
  4569. var parent = this.parent;
  4570. if (parent !== null) {
  4571. callback(parent);
  4572. parent.traverseAncestors(callback);
  4573. }
  4574. },
  4575. updateMatrix: function updateMatrix() {
  4576. this.matrix.compose(this.position, this.quaternion, this.scale);
  4577. this.matrixWorldNeedsUpdate = true;
  4578. },
  4579. updateMatrixWorld: function updateMatrixWorld(force) {
  4580. if (this.matrixAutoUpdate) this.updateMatrix();
  4581. if (this.matrixWorldNeedsUpdate || force) {
  4582. if (this.parent === null) {
  4583. this.matrixWorld.copy(this.matrix);
  4584. } else {
  4585. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4586. }
  4587. this.matrixWorldNeedsUpdate = false;
  4588. force = true;
  4589. } // update children
  4590. var children = this.children;
  4591. for (var i = 0, l = children.length; i < l; i++) {
  4592. children[i].updateMatrixWorld(force);
  4593. }
  4594. },
  4595. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  4596. var parent = this.parent;
  4597. if (updateParents === true && parent !== null) {
  4598. parent.updateWorldMatrix(true, false);
  4599. }
  4600. if (this.matrixAutoUpdate) this.updateMatrix();
  4601. if (this.parent === null) {
  4602. this.matrixWorld.copy(this.matrix);
  4603. } else {
  4604. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4605. } // update children
  4606. if (updateChildren === true) {
  4607. var children = this.children;
  4608. for (var i = 0, l = children.length; i < l; i++) {
  4609. children[i].updateWorldMatrix(false, true);
  4610. }
  4611. }
  4612. },
  4613. toJSON: function toJSON(meta) {
  4614. // meta is a string when called from JSON.stringify
  4615. var isRootObject = meta === undefined || typeof meta === 'string';
  4616. var output = {}; // meta is a hash used to collect geometries, materials.
  4617. // not providing it implies that this is the root object
  4618. // being serialized.
  4619. if (isRootObject) {
  4620. // initialize meta obj
  4621. meta = {
  4622. geometries: {},
  4623. materials: {},
  4624. textures: {},
  4625. images: {},
  4626. shapes: {},
  4627. skeletons: {},
  4628. animations: {}
  4629. };
  4630. output.metadata = {
  4631. version: 4.5,
  4632. type: 'Object',
  4633. generator: 'Object3D.toJSON'
  4634. };
  4635. } // standard Object3D serialization
  4636. var object = {};
  4637. object.uuid = this.uuid;
  4638. object.type = this.type;
  4639. if (this.name !== '') object.name = this.name;
  4640. if (this.castShadow === true) object.castShadow = true;
  4641. if (this.receiveShadow === true) object.receiveShadow = true;
  4642. if (this.visible === false) object.visible = false;
  4643. if (this.frustumCulled === false) object.frustumCulled = false;
  4644. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  4645. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  4646. object.layers = this.layers.mask;
  4647. object.matrix = this.matrix.toArray();
  4648. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  4649. if (this.isInstancedMesh) {
  4650. object.type = 'InstancedMesh';
  4651. object.count = this.count;
  4652. object.instanceMatrix = this.instanceMatrix.toJSON();
  4653. } //
  4654. function serialize(library, element) {
  4655. if (library[element.uuid] === undefined) {
  4656. library[element.uuid] = element.toJSON(meta);
  4657. }
  4658. return element.uuid;
  4659. }
  4660. if (this.isMesh || this.isLine || this.isPoints) {
  4661. object.geometry = serialize(meta.geometries, this.geometry);
  4662. var parameters = this.geometry.parameters;
  4663. if (parameters !== undefined && parameters.shapes !== undefined) {
  4664. var shapes = parameters.shapes;
  4665. if (Array.isArray(shapes)) {
  4666. for (var i = 0, l = shapes.length; i < l; i++) {
  4667. var shape = shapes[i];
  4668. serialize(meta.shapes, shape);
  4669. }
  4670. } else {
  4671. serialize(meta.shapes, shapes);
  4672. }
  4673. }
  4674. }
  4675. if (this.isSkinnedMesh) {
  4676. object.bindMode = this.bindMode;
  4677. object.bindMatrix = this.bindMatrix.toArray();
  4678. if (this.skeleton !== undefined) {
  4679. serialize(meta.skeletons, this.skeleton);
  4680. object.skeleton = this.skeleton.uuid;
  4681. }
  4682. }
  4683. if (this.material !== undefined) {
  4684. if (Array.isArray(this.material)) {
  4685. var uuids = [];
  4686. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  4687. uuids.push(serialize(meta.materials, this.material[_i]));
  4688. }
  4689. object.material = uuids;
  4690. } else {
  4691. object.material = serialize(meta.materials, this.material);
  4692. }
  4693. } //
  4694. if (this.children.length > 0) {
  4695. object.children = [];
  4696. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  4697. object.children.push(this.children[_i2].toJSON(meta).object);
  4698. }
  4699. } //
  4700. if (this.animations.length > 0) {
  4701. object.animations = [];
  4702. for (var _i3 = 0; _i3 < this.animations.length; _i3++) {
  4703. var animation = this.animations[_i3];
  4704. object.animations.push(serialize(meta.animations, animation));
  4705. }
  4706. }
  4707. if (isRootObject) {
  4708. var geometries = extractFromCache(meta.geometries);
  4709. var materials = extractFromCache(meta.materials);
  4710. var textures = extractFromCache(meta.textures);
  4711. var images = extractFromCache(meta.images);
  4712. var _shapes = extractFromCache(meta.shapes);
  4713. var skeletons = extractFromCache(meta.skeletons);
  4714. var animations = extractFromCache(meta.animations);
  4715. if (geometries.length > 0) output.geometries = geometries;
  4716. if (materials.length > 0) output.materials = materials;
  4717. if (textures.length > 0) output.textures = textures;
  4718. if (images.length > 0) output.images = images;
  4719. if (_shapes.length > 0) output.shapes = _shapes;
  4720. if (skeletons.length > 0) output.skeletons = skeletons;
  4721. if (animations.length > 0) output.animations = animations;
  4722. }
  4723. output.object = object;
  4724. return output; // extract data from the cache hash
  4725. // remove metadata on each item
  4726. // and return as array
  4727. function extractFromCache(cache) {
  4728. var values = [];
  4729. for (var key in cache) {
  4730. var data = cache[key];
  4731. delete data.metadata;
  4732. values.push(data);
  4733. }
  4734. return values;
  4735. }
  4736. },
  4737. clone: function clone(recursive) {
  4738. return new this.constructor().copy(this, recursive);
  4739. },
  4740. copy: function copy(source, recursive) {
  4741. if (recursive === void 0) {
  4742. recursive = true;
  4743. }
  4744. this.name = source.name;
  4745. this.up.copy(source.up);
  4746. this.position.copy(source.position);
  4747. this.rotation.order = source.rotation.order;
  4748. this.quaternion.copy(source.quaternion);
  4749. this.scale.copy(source.scale);
  4750. this.matrix.copy(source.matrix);
  4751. this.matrixWorld.copy(source.matrixWorld);
  4752. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4753. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4754. this.layers.mask = source.layers.mask;
  4755. this.visible = source.visible;
  4756. this.castShadow = source.castShadow;
  4757. this.receiveShadow = source.receiveShadow;
  4758. this.frustumCulled = source.frustumCulled;
  4759. this.renderOrder = source.renderOrder;
  4760. this.userData = JSON.parse(JSON.stringify(source.userData));
  4761. if (recursive === true) {
  4762. for (var i = 0; i < source.children.length; i++) {
  4763. var child = source.children[i];
  4764. this.add(child.clone());
  4765. }
  4766. }
  4767. return this;
  4768. }
  4769. });
  4770. var _vector1 = /*@__PURE__*/new Vector3();
  4771. var _vector2 = /*@__PURE__*/new Vector3();
  4772. var _normalMatrix = /*@__PURE__*/new Matrix3();
  4773. var Plane = /*#__PURE__*/function () {
  4774. function Plane(normal, constant) {
  4775. Object.defineProperty(this, 'isPlane', {
  4776. value: true
  4777. }); // normal is assumed to be normalized
  4778. this.normal = normal !== undefined ? normal : new Vector3(1, 0, 0);
  4779. this.constant = constant !== undefined ? constant : 0;
  4780. }
  4781. var _proto = Plane.prototype;
  4782. _proto.set = function set(normal, constant) {
  4783. this.normal.copy(normal);
  4784. this.constant = constant;
  4785. return this;
  4786. };
  4787. _proto.setComponents = function setComponents(x, y, z, w) {
  4788. this.normal.set(x, y, z);
  4789. this.constant = w;
  4790. return this;
  4791. };
  4792. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  4793. this.normal.copy(normal);
  4794. this.constant = -point.dot(this.normal);
  4795. return this;
  4796. };
  4797. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  4798. 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)?
  4799. this.setFromNormalAndCoplanarPoint(normal, a);
  4800. return this;
  4801. };
  4802. _proto.clone = function clone() {
  4803. return new this.constructor().copy(this);
  4804. };
  4805. _proto.copy = function copy(plane) {
  4806. this.normal.copy(plane.normal);
  4807. this.constant = plane.constant;
  4808. return this;
  4809. };
  4810. _proto.normalize = function normalize() {
  4811. // Note: will lead to a divide by zero if the plane is invalid.
  4812. var inverseNormalLength = 1.0 / this.normal.length();
  4813. this.normal.multiplyScalar(inverseNormalLength);
  4814. this.constant *= inverseNormalLength;
  4815. return this;
  4816. };
  4817. _proto.negate = function negate() {
  4818. this.constant *= -1;
  4819. this.normal.negate();
  4820. return this;
  4821. };
  4822. _proto.distanceToPoint = function distanceToPoint(point) {
  4823. return this.normal.dot(point) + this.constant;
  4824. };
  4825. _proto.distanceToSphere = function distanceToSphere(sphere) {
  4826. return this.distanceToPoint(sphere.center) - sphere.radius;
  4827. };
  4828. _proto.projectPoint = function projectPoint(point, target) {
  4829. if (target === undefined) {
  4830. console.warn('THREE.Plane: .projectPoint() target is now required');
  4831. target = new Vector3();
  4832. }
  4833. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  4834. };
  4835. _proto.intersectLine = function intersectLine(line, target) {
  4836. if (target === undefined) {
  4837. console.warn('THREE.Plane: .intersectLine() target is now required');
  4838. target = new Vector3();
  4839. }
  4840. var direction = line.delta(_vector1);
  4841. var denominator = this.normal.dot(direction);
  4842. if (denominator === 0) {
  4843. // line is coplanar, return origin
  4844. if (this.distanceToPoint(line.start) === 0) {
  4845. return target.copy(line.start);
  4846. } // Unsure if this is the correct method to handle this case.
  4847. return undefined;
  4848. }
  4849. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  4850. if (t < 0 || t > 1) {
  4851. return undefined;
  4852. }
  4853. return target.copy(direction).multiplyScalar(t).add(line.start);
  4854. };
  4855. _proto.intersectsLine = function intersectsLine(line) {
  4856. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4857. var startSign = this.distanceToPoint(line.start);
  4858. var endSign = this.distanceToPoint(line.end);
  4859. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  4860. };
  4861. _proto.intersectsBox = function intersectsBox(box) {
  4862. return box.intersectsPlane(this);
  4863. };
  4864. _proto.intersectsSphere = function intersectsSphere(sphere) {
  4865. return sphere.intersectsPlane(this);
  4866. };
  4867. _proto.coplanarPoint = function coplanarPoint(target) {
  4868. if (target === undefined) {
  4869. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  4870. target = new Vector3();
  4871. }
  4872. return target.copy(this.normal).multiplyScalar(-this.constant);
  4873. };
  4874. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  4875. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  4876. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  4877. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  4878. this.constant = -referencePoint.dot(normal);
  4879. return this;
  4880. };
  4881. _proto.translate = function translate(offset) {
  4882. this.constant -= offset.dot(this.normal);
  4883. return this;
  4884. };
  4885. _proto.equals = function equals(plane) {
  4886. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  4887. };
  4888. return Plane;
  4889. }();
  4890. var _v0$1 = /*@__PURE__*/new Vector3();
  4891. var _v1$3 = /*@__PURE__*/new Vector3();
  4892. var _v2$1 = /*@__PURE__*/new Vector3();
  4893. var _v3 = /*@__PURE__*/new Vector3();
  4894. var _vab = /*@__PURE__*/new Vector3();
  4895. var _vac = /*@__PURE__*/new Vector3();
  4896. var _vbc = /*@__PURE__*/new Vector3();
  4897. var _vap = /*@__PURE__*/new Vector3();
  4898. var _vbp = /*@__PURE__*/new Vector3();
  4899. var _vcp = /*@__PURE__*/new Vector3();
  4900. var Triangle = /*#__PURE__*/function () {
  4901. function Triangle(a, b, c) {
  4902. this.a = a !== undefined ? a : new Vector3();
  4903. this.b = b !== undefined ? b : new Vector3();
  4904. this.c = c !== undefined ? c : new Vector3();
  4905. }
  4906. Triangle.getNormal = function getNormal(a, b, c, target) {
  4907. if (target === undefined) {
  4908. console.warn('THREE.Triangle: .getNormal() target is now required');
  4909. target = new Vector3();
  4910. }
  4911. target.subVectors(c, b);
  4912. _v0$1.subVectors(a, b);
  4913. target.cross(_v0$1);
  4914. var targetLengthSq = target.lengthSq();
  4915. if (targetLengthSq > 0) {
  4916. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  4917. }
  4918. return target.set(0, 0, 0);
  4919. } // static/instance method to calculate barycentric coordinates
  4920. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4921. ;
  4922. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  4923. _v0$1.subVectors(c, a);
  4924. _v1$3.subVectors(b, a);
  4925. _v2$1.subVectors(point, a);
  4926. var dot00 = _v0$1.dot(_v0$1);
  4927. var dot01 = _v0$1.dot(_v1$3);
  4928. var dot02 = _v0$1.dot(_v2$1);
  4929. var dot11 = _v1$3.dot(_v1$3);
  4930. var dot12 = _v1$3.dot(_v2$1);
  4931. var denom = dot00 * dot11 - dot01 * dot01;
  4932. if (target === undefined) {
  4933. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  4934. target = new Vector3();
  4935. } // collinear or singular triangle
  4936. if (denom === 0) {
  4937. // arbitrary location outside of triangle?
  4938. // not sure if this is the best idea, maybe should be returning undefined
  4939. return target.set(-2, -1, -1);
  4940. }
  4941. var invDenom = 1 / denom;
  4942. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  4943. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  4944. return target.set(1 - u - v, v, u);
  4945. };
  4946. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  4947. this.getBarycoord(point, a, b, c, _v3);
  4948. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  4949. };
  4950. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  4951. this.getBarycoord(point, p1, p2, p3, _v3);
  4952. target.set(0, 0);
  4953. target.addScaledVector(uv1, _v3.x);
  4954. target.addScaledVector(uv2, _v3.y);
  4955. target.addScaledVector(uv3, _v3.z);
  4956. return target;
  4957. };
  4958. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  4959. _v0$1.subVectors(c, b);
  4960. _v1$3.subVectors(a, b); // strictly front facing
  4961. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  4962. };
  4963. var _proto = Triangle.prototype;
  4964. _proto.set = function set(a, b, c) {
  4965. this.a.copy(a);
  4966. this.b.copy(b);
  4967. this.c.copy(c);
  4968. return this;
  4969. };
  4970. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  4971. this.a.copy(points[i0]);
  4972. this.b.copy(points[i1]);
  4973. this.c.copy(points[i2]);
  4974. return this;
  4975. };
  4976. _proto.clone = function clone() {
  4977. return new this.constructor().copy(this);
  4978. };
  4979. _proto.copy = function copy(triangle) {
  4980. this.a.copy(triangle.a);
  4981. this.b.copy(triangle.b);
  4982. this.c.copy(triangle.c);
  4983. return this;
  4984. };
  4985. _proto.getArea = function getArea() {
  4986. _v0$1.subVectors(this.c, this.b);
  4987. _v1$3.subVectors(this.a, this.b);
  4988. return _v0$1.cross(_v1$3).length() * 0.5;
  4989. };
  4990. _proto.getMidpoint = function getMidpoint(target) {
  4991. if (target === undefined) {
  4992. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  4993. target = new Vector3();
  4994. }
  4995. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  4996. };
  4997. _proto.getNormal = function getNormal(target) {
  4998. return Triangle.getNormal(this.a, this.b, this.c, target);
  4999. };
  5000. _proto.getPlane = function getPlane(target) {
  5001. if (target === undefined) {
  5002. console.warn('THREE.Triangle: .getPlane() target is now required');
  5003. target = new Plane();
  5004. }
  5005. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  5006. };
  5007. _proto.getBarycoord = function getBarycoord(point, target) {
  5008. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  5009. };
  5010. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  5011. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  5012. };
  5013. _proto.containsPoint = function containsPoint(point) {
  5014. return Triangle.containsPoint(point, this.a, this.b, this.c);
  5015. };
  5016. _proto.isFrontFacing = function isFrontFacing(direction) {
  5017. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  5018. };
  5019. _proto.intersectsBox = function intersectsBox(box) {
  5020. return box.intersectsTriangle(this);
  5021. };
  5022. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  5023. if (target === undefined) {
  5024. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  5025. target = new Vector3();
  5026. }
  5027. var a = this.a,
  5028. b = this.b,
  5029. c = this.c;
  5030. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  5031. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  5032. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  5033. // basically, we're distinguishing which of the voronoi regions of the triangle
  5034. // the point lies in with the minimum amount of redundant computation.
  5035. _vab.subVectors(b, a);
  5036. _vac.subVectors(c, a);
  5037. _vap.subVectors(p, a);
  5038. var d1 = _vab.dot(_vap);
  5039. var d2 = _vac.dot(_vap);
  5040. if (d1 <= 0 && d2 <= 0) {
  5041. // vertex region of A; barycentric coords (1, 0, 0)
  5042. return target.copy(a);
  5043. }
  5044. _vbp.subVectors(p, b);
  5045. var d3 = _vab.dot(_vbp);
  5046. var d4 = _vac.dot(_vbp);
  5047. if (d3 >= 0 && d4 <= d3) {
  5048. // vertex region of B; barycentric coords (0, 1, 0)
  5049. return target.copy(b);
  5050. }
  5051. var vc = d1 * d4 - d3 * d2;
  5052. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  5053. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  5054. return target.copy(a).addScaledVector(_vab, v);
  5055. }
  5056. _vcp.subVectors(p, c);
  5057. var d5 = _vab.dot(_vcp);
  5058. var d6 = _vac.dot(_vcp);
  5059. if (d6 >= 0 && d5 <= d6) {
  5060. // vertex region of C; barycentric coords (0, 0, 1)
  5061. return target.copy(c);
  5062. }
  5063. var vb = d5 * d2 - d1 * d6;
  5064. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  5065. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  5066. return target.copy(a).addScaledVector(_vac, w);
  5067. }
  5068. var va = d3 * d6 - d5 * d4;
  5069. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  5070. _vbc.subVectors(c, b);
  5071. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5072. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5073. } // face region
  5074. var denom = 1 / (va + vb + vc); // u = va * denom
  5075. v = vb * denom;
  5076. w = vc * denom;
  5077. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5078. };
  5079. _proto.equals = function equals(triangle) {
  5080. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5081. };
  5082. return Triangle;
  5083. }();
  5084. var _colorKeywords = {
  5085. 'aliceblue': 0xF0F8FF,
  5086. 'antiquewhite': 0xFAEBD7,
  5087. 'aqua': 0x00FFFF,
  5088. 'aquamarine': 0x7FFFD4,
  5089. 'azure': 0xF0FFFF,
  5090. 'beige': 0xF5F5DC,
  5091. 'bisque': 0xFFE4C4,
  5092. 'black': 0x000000,
  5093. 'blanchedalmond': 0xFFEBCD,
  5094. 'blue': 0x0000FF,
  5095. 'blueviolet': 0x8A2BE2,
  5096. 'brown': 0xA52A2A,
  5097. 'burlywood': 0xDEB887,
  5098. 'cadetblue': 0x5F9EA0,
  5099. 'chartreuse': 0x7FFF00,
  5100. 'chocolate': 0xD2691E,
  5101. 'coral': 0xFF7F50,
  5102. 'cornflowerblue': 0x6495ED,
  5103. 'cornsilk': 0xFFF8DC,
  5104. 'crimson': 0xDC143C,
  5105. 'cyan': 0x00FFFF,
  5106. 'darkblue': 0x00008B,
  5107. 'darkcyan': 0x008B8B,
  5108. 'darkgoldenrod': 0xB8860B,
  5109. 'darkgray': 0xA9A9A9,
  5110. 'darkgreen': 0x006400,
  5111. 'darkgrey': 0xA9A9A9,
  5112. 'darkkhaki': 0xBDB76B,
  5113. 'darkmagenta': 0x8B008B,
  5114. 'darkolivegreen': 0x556B2F,
  5115. 'darkorange': 0xFF8C00,
  5116. 'darkorchid': 0x9932CC,
  5117. 'darkred': 0x8B0000,
  5118. 'darksalmon': 0xE9967A,
  5119. 'darkseagreen': 0x8FBC8F,
  5120. 'darkslateblue': 0x483D8B,
  5121. 'darkslategray': 0x2F4F4F,
  5122. 'darkslategrey': 0x2F4F4F,
  5123. 'darkturquoise': 0x00CED1,
  5124. 'darkviolet': 0x9400D3,
  5125. 'deeppink': 0xFF1493,
  5126. 'deepskyblue': 0x00BFFF,
  5127. 'dimgray': 0x696969,
  5128. 'dimgrey': 0x696969,
  5129. 'dodgerblue': 0x1E90FF,
  5130. 'firebrick': 0xB22222,
  5131. 'floralwhite': 0xFFFAF0,
  5132. 'forestgreen': 0x228B22,
  5133. 'fuchsia': 0xFF00FF,
  5134. 'gainsboro': 0xDCDCDC,
  5135. 'ghostwhite': 0xF8F8FF,
  5136. 'gold': 0xFFD700,
  5137. 'goldenrod': 0xDAA520,
  5138. 'gray': 0x808080,
  5139. 'green': 0x008000,
  5140. 'greenyellow': 0xADFF2F,
  5141. 'grey': 0x808080,
  5142. 'honeydew': 0xF0FFF0,
  5143. 'hotpink': 0xFF69B4,
  5144. 'indianred': 0xCD5C5C,
  5145. 'indigo': 0x4B0082,
  5146. 'ivory': 0xFFFFF0,
  5147. 'khaki': 0xF0E68C,
  5148. 'lavender': 0xE6E6FA,
  5149. 'lavenderblush': 0xFFF0F5,
  5150. 'lawngreen': 0x7CFC00,
  5151. 'lemonchiffon': 0xFFFACD,
  5152. 'lightblue': 0xADD8E6,
  5153. 'lightcoral': 0xF08080,
  5154. 'lightcyan': 0xE0FFFF,
  5155. 'lightgoldenrodyellow': 0xFAFAD2,
  5156. 'lightgray': 0xD3D3D3,
  5157. 'lightgreen': 0x90EE90,
  5158. 'lightgrey': 0xD3D3D3,
  5159. 'lightpink': 0xFFB6C1,
  5160. 'lightsalmon': 0xFFA07A,
  5161. 'lightseagreen': 0x20B2AA,
  5162. 'lightskyblue': 0x87CEFA,
  5163. 'lightslategray': 0x778899,
  5164. 'lightslategrey': 0x778899,
  5165. 'lightsteelblue': 0xB0C4DE,
  5166. 'lightyellow': 0xFFFFE0,
  5167. 'lime': 0x00FF00,
  5168. 'limegreen': 0x32CD32,
  5169. 'linen': 0xFAF0E6,
  5170. 'magenta': 0xFF00FF,
  5171. 'maroon': 0x800000,
  5172. 'mediumaquamarine': 0x66CDAA,
  5173. 'mediumblue': 0x0000CD,
  5174. 'mediumorchid': 0xBA55D3,
  5175. 'mediumpurple': 0x9370DB,
  5176. 'mediumseagreen': 0x3CB371,
  5177. 'mediumslateblue': 0x7B68EE,
  5178. 'mediumspringgreen': 0x00FA9A,
  5179. 'mediumturquoise': 0x48D1CC,
  5180. 'mediumvioletred': 0xC71585,
  5181. 'midnightblue': 0x191970,
  5182. 'mintcream': 0xF5FFFA,
  5183. 'mistyrose': 0xFFE4E1,
  5184. 'moccasin': 0xFFE4B5,
  5185. 'navajowhite': 0xFFDEAD,
  5186. 'navy': 0x000080,
  5187. 'oldlace': 0xFDF5E6,
  5188. 'olive': 0x808000,
  5189. 'olivedrab': 0x6B8E23,
  5190. 'orange': 0xFFA500,
  5191. 'orangered': 0xFF4500,
  5192. 'orchid': 0xDA70D6,
  5193. 'palegoldenrod': 0xEEE8AA,
  5194. 'palegreen': 0x98FB98,
  5195. 'paleturquoise': 0xAFEEEE,
  5196. 'palevioletred': 0xDB7093,
  5197. 'papayawhip': 0xFFEFD5,
  5198. 'peachpuff': 0xFFDAB9,
  5199. 'peru': 0xCD853F,
  5200. 'pink': 0xFFC0CB,
  5201. 'plum': 0xDDA0DD,
  5202. 'powderblue': 0xB0E0E6,
  5203. 'purple': 0x800080,
  5204. 'rebeccapurple': 0x663399,
  5205. 'red': 0xFF0000,
  5206. 'rosybrown': 0xBC8F8F,
  5207. 'royalblue': 0x4169E1,
  5208. 'saddlebrown': 0x8B4513,
  5209. 'salmon': 0xFA8072,
  5210. 'sandybrown': 0xF4A460,
  5211. 'seagreen': 0x2E8B57,
  5212. 'seashell': 0xFFF5EE,
  5213. 'sienna': 0xA0522D,
  5214. 'silver': 0xC0C0C0,
  5215. 'skyblue': 0x87CEEB,
  5216. 'slateblue': 0x6A5ACD,
  5217. 'slategray': 0x708090,
  5218. 'slategrey': 0x708090,
  5219. 'snow': 0xFFFAFA,
  5220. 'springgreen': 0x00FF7F,
  5221. 'steelblue': 0x4682B4,
  5222. 'tan': 0xD2B48C,
  5223. 'teal': 0x008080,
  5224. 'thistle': 0xD8BFD8,
  5225. 'tomato': 0xFF6347,
  5226. 'turquoise': 0x40E0D0,
  5227. 'violet': 0xEE82EE,
  5228. 'wheat': 0xF5DEB3,
  5229. 'white': 0xFFFFFF,
  5230. 'whitesmoke': 0xF5F5F5,
  5231. 'yellow': 0xFFFF00,
  5232. 'yellowgreen': 0x9ACD32
  5233. };
  5234. var _hslA = {
  5235. h: 0,
  5236. s: 0,
  5237. l: 0
  5238. };
  5239. var _hslB = {
  5240. h: 0,
  5241. s: 0,
  5242. l: 0
  5243. };
  5244. function hue2rgb(p, q, t) {
  5245. if (t < 0) t += 1;
  5246. if (t > 1) t -= 1;
  5247. if (t < 1 / 6) return p + (q - p) * 6 * t;
  5248. if (t < 1 / 2) return q;
  5249. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  5250. return p;
  5251. }
  5252. function SRGBToLinear(c) {
  5253. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  5254. }
  5255. function LinearToSRGB(c) {
  5256. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  5257. }
  5258. var Color = /*#__PURE__*/function () {
  5259. function Color(r, g, b) {
  5260. Object.defineProperty(this, 'isColor', {
  5261. value: true
  5262. });
  5263. if (g === undefined && b === undefined) {
  5264. // r is THREE.Color, hex or string
  5265. return this.set(r);
  5266. }
  5267. return this.setRGB(r, g, b);
  5268. }
  5269. var _proto = Color.prototype;
  5270. _proto.set = function set(value) {
  5271. if (value && value.isColor) {
  5272. this.copy(value);
  5273. } else if (typeof value === 'number') {
  5274. this.setHex(value);
  5275. } else if (typeof value === 'string') {
  5276. this.setStyle(value);
  5277. }
  5278. return this;
  5279. };
  5280. _proto.setScalar = function setScalar(scalar) {
  5281. this.r = scalar;
  5282. this.g = scalar;
  5283. this.b = scalar;
  5284. return this;
  5285. };
  5286. _proto.setHex = function setHex(hex) {
  5287. hex = Math.floor(hex);
  5288. this.r = (hex >> 16 & 255) / 255;
  5289. this.g = (hex >> 8 & 255) / 255;
  5290. this.b = (hex & 255) / 255;
  5291. return this;
  5292. };
  5293. _proto.setRGB = function setRGB(r, g, b) {
  5294. this.r = r;
  5295. this.g = g;
  5296. this.b = b;
  5297. return this;
  5298. };
  5299. _proto.setHSL = function setHSL(h, s, l) {
  5300. // h,s,l ranges are in 0.0 - 1.0
  5301. h = MathUtils.euclideanModulo(h, 1);
  5302. s = MathUtils.clamp(s, 0, 1);
  5303. l = MathUtils.clamp(l, 0, 1);
  5304. if (s === 0) {
  5305. this.r = this.g = this.b = l;
  5306. } else {
  5307. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  5308. var q = 2 * l - p;
  5309. this.r = hue2rgb(q, p, h + 1 / 3);
  5310. this.g = hue2rgb(q, p, h);
  5311. this.b = hue2rgb(q, p, h - 1 / 3);
  5312. }
  5313. return this;
  5314. };
  5315. _proto.setStyle = function setStyle(style) {
  5316. function handleAlpha(string) {
  5317. if (string === undefined) return;
  5318. if (parseFloat(string) < 1) {
  5319. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  5320. }
  5321. }
  5322. var m;
  5323. if (m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(style)) {
  5324. // rgb / hsl
  5325. var color;
  5326. var name = m[1];
  5327. var components = m[2];
  5328. switch (name) {
  5329. case 'rgb':
  5330. case 'rgba':
  5331. if (color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  5332. // rgb(255,0,0) rgba(255,0,0,0.5)
  5333. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  5334. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  5335. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  5336. handleAlpha(color[4]);
  5337. return this;
  5338. }
  5339. if (color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  5340. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5341. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  5342. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  5343. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  5344. handleAlpha(color[4]);
  5345. return this;
  5346. }
  5347. break;
  5348. case 'hsl':
  5349. case 'hsla':
  5350. if (color = /^(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  5351. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  5352. var h = parseFloat(color[1]) / 360;
  5353. var s = parseInt(color[2], 10) / 100;
  5354. var l = parseInt(color[3], 10) / 100;
  5355. handleAlpha(color[4]);
  5356. return this.setHSL(h, s, l);
  5357. }
  5358. break;
  5359. }
  5360. } else if (m = /^\#([A-Fa-f\d]+)$/.exec(style)) {
  5361. // hex color
  5362. var hex = m[1];
  5363. var size = hex.length;
  5364. if (size === 3) {
  5365. // #ff0
  5366. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  5367. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  5368. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  5369. return this;
  5370. } else if (size === 6) {
  5371. // #ff0000
  5372. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  5373. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  5374. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  5375. return this;
  5376. }
  5377. }
  5378. if (style && style.length > 0) {
  5379. return this.setColorName(style);
  5380. }
  5381. return this;
  5382. };
  5383. _proto.setColorName = function setColorName(style) {
  5384. // color keywords
  5385. var hex = _colorKeywords[style];
  5386. if (hex !== undefined) {
  5387. // red
  5388. this.setHex(hex);
  5389. } else {
  5390. // unknown color
  5391. console.warn('THREE.Color: Unknown color ' + style);
  5392. }
  5393. return this;
  5394. };
  5395. _proto.clone = function clone() {
  5396. return new this.constructor(this.r, this.g, this.b);
  5397. };
  5398. _proto.copy = function copy(color) {
  5399. this.r = color.r;
  5400. this.g = color.g;
  5401. this.b = color.b;
  5402. return this;
  5403. };
  5404. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  5405. if (gammaFactor === void 0) {
  5406. gammaFactor = 2.0;
  5407. }
  5408. this.r = Math.pow(color.r, gammaFactor);
  5409. this.g = Math.pow(color.g, gammaFactor);
  5410. this.b = Math.pow(color.b, gammaFactor);
  5411. return this;
  5412. };
  5413. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  5414. if (gammaFactor === void 0) {
  5415. gammaFactor = 2.0;
  5416. }
  5417. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  5418. this.r = Math.pow(color.r, safeInverse);
  5419. this.g = Math.pow(color.g, safeInverse);
  5420. this.b = Math.pow(color.b, safeInverse);
  5421. return this;
  5422. };
  5423. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  5424. this.copyGammaToLinear(this, gammaFactor);
  5425. return this;
  5426. };
  5427. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  5428. this.copyLinearToGamma(this, gammaFactor);
  5429. return this;
  5430. };
  5431. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  5432. this.r = SRGBToLinear(color.r);
  5433. this.g = SRGBToLinear(color.g);
  5434. this.b = SRGBToLinear(color.b);
  5435. return this;
  5436. };
  5437. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  5438. this.r = LinearToSRGB(color.r);
  5439. this.g = LinearToSRGB(color.g);
  5440. this.b = LinearToSRGB(color.b);
  5441. return this;
  5442. };
  5443. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  5444. this.copySRGBToLinear(this);
  5445. return this;
  5446. };
  5447. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  5448. this.copyLinearToSRGB(this);
  5449. return this;
  5450. };
  5451. _proto.getHex = function getHex() {
  5452. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  5453. };
  5454. _proto.getHexString = function getHexString() {
  5455. return ('000000' + this.getHex().toString(16)).slice(-6);
  5456. };
  5457. _proto.getHSL = function getHSL(target) {
  5458. // h,s,l ranges are in 0.0 - 1.0
  5459. if (target === undefined) {
  5460. console.warn('THREE.Color: .getHSL() target is now required');
  5461. target = {
  5462. h: 0,
  5463. s: 0,
  5464. l: 0
  5465. };
  5466. }
  5467. var r = this.r,
  5468. g = this.g,
  5469. b = this.b;
  5470. var max = Math.max(r, g, b);
  5471. var min = Math.min(r, g, b);
  5472. var hue, saturation;
  5473. var lightness = (min + max) / 2.0;
  5474. if (min === max) {
  5475. hue = 0;
  5476. saturation = 0;
  5477. } else {
  5478. var delta = max - min;
  5479. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  5480. switch (max) {
  5481. case r:
  5482. hue = (g - b) / delta + (g < b ? 6 : 0);
  5483. break;
  5484. case g:
  5485. hue = (b - r) / delta + 2;
  5486. break;
  5487. case b:
  5488. hue = (r - g) / delta + 4;
  5489. break;
  5490. }
  5491. hue /= 6;
  5492. }
  5493. target.h = hue;
  5494. target.s = saturation;
  5495. target.l = lightness;
  5496. return target;
  5497. };
  5498. _proto.getStyle = function getStyle() {
  5499. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  5500. };
  5501. _proto.offsetHSL = function offsetHSL(h, s, l) {
  5502. this.getHSL(_hslA);
  5503. _hslA.h += h;
  5504. _hslA.s += s;
  5505. _hslA.l += l;
  5506. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  5507. return this;
  5508. };
  5509. _proto.add = function add(color) {
  5510. this.r += color.r;
  5511. this.g += color.g;
  5512. this.b += color.b;
  5513. return this;
  5514. };
  5515. _proto.addColors = function addColors(color1, color2) {
  5516. this.r = color1.r + color2.r;
  5517. this.g = color1.g + color2.g;
  5518. this.b = color1.b + color2.b;
  5519. return this;
  5520. };
  5521. _proto.addScalar = function addScalar(s) {
  5522. this.r += s;
  5523. this.g += s;
  5524. this.b += s;
  5525. return this;
  5526. };
  5527. _proto.sub = function sub(color) {
  5528. this.r = Math.max(0, this.r - color.r);
  5529. this.g = Math.max(0, this.g - color.g);
  5530. this.b = Math.max(0, this.b - color.b);
  5531. return this;
  5532. };
  5533. _proto.multiply = function multiply(color) {
  5534. this.r *= color.r;
  5535. this.g *= color.g;
  5536. this.b *= color.b;
  5537. return this;
  5538. };
  5539. _proto.multiplyScalar = function multiplyScalar(s) {
  5540. this.r *= s;
  5541. this.g *= s;
  5542. this.b *= s;
  5543. return this;
  5544. };
  5545. _proto.lerp = function lerp(color, alpha) {
  5546. this.r += (color.r - this.r) * alpha;
  5547. this.g += (color.g - this.g) * alpha;
  5548. this.b += (color.b - this.b) * alpha;
  5549. return this;
  5550. };
  5551. _proto.lerpHSL = function lerpHSL(color, alpha) {
  5552. this.getHSL(_hslA);
  5553. color.getHSL(_hslB);
  5554. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  5555. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  5556. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  5557. this.setHSL(h, s, l);
  5558. return this;
  5559. };
  5560. _proto.equals = function equals(c) {
  5561. return c.r === this.r && c.g === this.g && c.b === this.b;
  5562. };
  5563. _proto.fromArray = function fromArray(array, offset) {
  5564. if (offset === void 0) {
  5565. offset = 0;
  5566. }
  5567. this.r = array[offset];
  5568. this.g = array[offset + 1];
  5569. this.b = array[offset + 2];
  5570. return this;
  5571. };
  5572. _proto.toArray = function toArray(array, offset) {
  5573. if (array === void 0) {
  5574. array = [];
  5575. }
  5576. if (offset === void 0) {
  5577. offset = 0;
  5578. }
  5579. array[offset] = this.r;
  5580. array[offset + 1] = this.g;
  5581. array[offset + 2] = this.b;
  5582. return array;
  5583. };
  5584. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  5585. this.r = attribute.getX(index);
  5586. this.g = attribute.getY(index);
  5587. this.b = attribute.getZ(index);
  5588. if (attribute.normalized === true) {
  5589. // assuming Uint8Array
  5590. this.r /= 255;
  5591. this.g /= 255;
  5592. this.b /= 255;
  5593. }
  5594. return this;
  5595. };
  5596. _proto.toJSON = function toJSON() {
  5597. return this.getHex();
  5598. };
  5599. return Color;
  5600. }();
  5601. Color.NAMES = _colorKeywords;
  5602. Color.prototype.r = 1;
  5603. Color.prototype.g = 1;
  5604. Color.prototype.b = 1;
  5605. var Face3 = /*#__PURE__*/function () {
  5606. function Face3(a, b, c, normal, color, materialIndex) {
  5607. if (materialIndex === void 0) {
  5608. materialIndex = 0;
  5609. }
  5610. this.a = a;
  5611. this.b = b;
  5612. this.c = c;
  5613. this.normal = normal && normal.isVector3 ? normal : new Vector3();
  5614. this.vertexNormals = Array.isArray(normal) ? normal : [];
  5615. this.color = color && color.isColor ? color : new Color();
  5616. this.vertexColors = Array.isArray(color) ? color : [];
  5617. this.materialIndex = materialIndex;
  5618. }
  5619. var _proto = Face3.prototype;
  5620. _proto.clone = function clone() {
  5621. return new this.constructor().copy(this);
  5622. };
  5623. _proto.copy = function copy(source) {
  5624. this.a = source.a;
  5625. this.b = source.b;
  5626. this.c = source.c;
  5627. this.normal.copy(source.normal);
  5628. this.color.copy(source.color);
  5629. this.materialIndex = source.materialIndex;
  5630. for (var i = 0, il = source.vertexNormals.length; i < il; i++) {
  5631. this.vertexNormals[i] = source.vertexNormals[i].clone();
  5632. }
  5633. for (var _i = 0, _il = source.vertexColors.length; _i < _il; _i++) {
  5634. this.vertexColors[_i] = source.vertexColors[_i].clone();
  5635. }
  5636. return this;
  5637. };
  5638. return Face3;
  5639. }();
  5640. var materialId = 0;
  5641. function Material() {
  5642. Object.defineProperty(this, 'id', {
  5643. value: materialId++
  5644. });
  5645. this.uuid = MathUtils.generateUUID();
  5646. this.name = '';
  5647. this.type = 'Material';
  5648. this.fog = true;
  5649. this.blending = NormalBlending;
  5650. this.side = FrontSide;
  5651. this.flatShading = false;
  5652. this.vertexColors = false;
  5653. this.opacity = 1;
  5654. this.transparent = false;
  5655. this.blendSrc = SrcAlphaFactor;
  5656. this.blendDst = OneMinusSrcAlphaFactor;
  5657. this.blendEquation = AddEquation;
  5658. this.blendSrcAlpha = null;
  5659. this.blendDstAlpha = null;
  5660. this.blendEquationAlpha = null;
  5661. this.depthFunc = LessEqualDepth;
  5662. this.depthTest = true;
  5663. this.depthWrite = true;
  5664. this.stencilWriteMask = 0xff;
  5665. this.stencilFunc = AlwaysStencilFunc;
  5666. this.stencilRef = 0;
  5667. this.stencilFuncMask = 0xff;
  5668. this.stencilFail = KeepStencilOp;
  5669. this.stencilZFail = KeepStencilOp;
  5670. this.stencilZPass = KeepStencilOp;
  5671. this.stencilWrite = false;
  5672. this.clippingPlanes = null;
  5673. this.clipIntersection = false;
  5674. this.clipShadows = false;
  5675. this.shadowSide = null;
  5676. this.colorWrite = true;
  5677. this.precision = null; // override the renderer's default precision for this material
  5678. this.polygonOffset = false;
  5679. this.polygonOffsetFactor = 0;
  5680. this.polygonOffsetUnits = 0;
  5681. this.dithering = false;
  5682. this.alphaTest = 0;
  5683. this.premultipliedAlpha = false;
  5684. this.visible = true;
  5685. this.toneMapped = true;
  5686. this.userData = {};
  5687. this.version = 0;
  5688. }
  5689. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5690. constructor: Material,
  5691. isMaterial: true,
  5692. onBeforeCompile: function onBeforeCompile()
  5693. /* shaderobject, renderer */
  5694. {},
  5695. customProgramCacheKey: function customProgramCacheKey() {
  5696. return this.onBeforeCompile.toString();
  5697. },
  5698. setValues: function setValues(values) {
  5699. if (values === undefined) return;
  5700. for (var key in values) {
  5701. var newValue = values[key];
  5702. if (newValue === undefined) {
  5703. console.warn('THREE.Material: \'' + key + '\' parameter is undefined.');
  5704. continue;
  5705. } // for backward compatability if shading is set in the constructor
  5706. if (key === 'shading') {
  5707. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  5708. this.flatShading = newValue === FlatShading ? true : false;
  5709. continue;
  5710. }
  5711. var currentValue = this[key];
  5712. if (currentValue === undefined) {
  5713. console.warn('THREE.' + this.type + ': \'' + key + '\' is not a property of this material.');
  5714. continue;
  5715. }
  5716. if (currentValue && currentValue.isColor) {
  5717. currentValue.set(newValue);
  5718. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  5719. currentValue.copy(newValue);
  5720. } else {
  5721. this[key] = newValue;
  5722. }
  5723. }
  5724. },
  5725. toJSON: function toJSON(meta) {
  5726. var isRoot = meta === undefined || typeof meta === 'string';
  5727. if (isRoot) {
  5728. meta = {
  5729. textures: {},
  5730. images: {}
  5731. };
  5732. }
  5733. var data = {
  5734. metadata: {
  5735. version: 4.5,
  5736. type: 'Material',
  5737. generator: 'Material.toJSON'
  5738. }
  5739. }; // standard Material serialization
  5740. data.uuid = this.uuid;
  5741. data.type = this.type;
  5742. if (this.name !== '') data.name = this.name;
  5743. if (this.color && this.color.isColor) data.color = this.color.getHex();
  5744. if (this.roughness !== undefined) data.roughness = this.roughness;
  5745. if (this.metalness !== undefined) data.metalness = this.metalness;
  5746. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  5747. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  5748. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  5749. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  5750. if (this.shininess !== undefined) data.shininess = this.shininess;
  5751. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  5752. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  5753. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  5754. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  5755. }
  5756. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  5757. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  5758. }
  5759. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  5760. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  5761. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5762. }
  5763. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  5764. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  5765. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  5766. if (this.lightMap && this.lightMap.isTexture) data.lightMap = this.lightMap.toJSON(meta).uuid;
  5767. if (this.aoMap && this.aoMap.isTexture) {
  5768. data.aoMap = this.aoMap.toJSON(meta).uuid;
  5769. data.aoMapIntensity = this.aoMapIntensity;
  5770. }
  5771. if (this.bumpMap && this.bumpMap.isTexture) {
  5772. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  5773. data.bumpScale = this.bumpScale;
  5774. }
  5775. if (this.normalMap && this.normalMap.isTexture) {
  5776. data.normalMap = this.normalMap.toJSON(meta).uuid;
  5777. data.normalMapType = this.normalMapType;
  5778. data.normalScale = this.normalScale.toArray();
  5779. }
  5780. if (this.displacementMap && this.displacementMap.isTexture) {
  5781. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  5782. data.displacementScale = this.displacementScale;
  5783. data.displacementBias = this.displacementBias;
  5784. }
  5785. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  5786. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  5787. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  5788. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  5789. if (this.envMap && this.envMap.isTexture) {
  5790. data.envMap = this.envMap.toJSON(meta).uuid;
  5791. data.reflectivity = this.reflectivity; // Scale behind envMap
  5792. data.refractionRatio = this.refractionRatio;
  5793. if (this.combine !== undefined) data.combine = this.combine;
  5794. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  5795. }
  5796. if (this.gradientMap && this.gradientMap.isTexture) {
  5797. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  5798. }
  5799. if (this.size !== undefined) data.size = this.size;
  5800. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  5801. if (this.blending !== NormalBlending) data.blending = this.blending;
  5802. if (this.flatShading === true) data.flatShading = this.flatShading;
  5803. if (this.side !== FrontSide) data.side = this.side;
  5804. if (this.vertexColors) data.vertexColors = true;
  5805. if (this.opacity < 1) data.opacity = this.opacity;
  5806. if (this.transparent === true) data.transparent = this.transparent;
  5807. data.depthFunc = this.depthFunc;
  5808. data.depthTest = this.depthTest;
  5809. data.depthWrite = this.depthWrite;
  5810. data.stencilWrite = this.stencilWrite;
  5811. data.stencilWriteMask = this.stencilWriteMask;
  5812. data.stencilFunc = this.stencilFunc;
  5813. data.stencilRef = this.stencilRef;
  5814. data.stencilFuncMask = this.stencilFuncMask;
  5815. data.stencilFail = this.stencilFail;
  5816. data.stencilZFail = this.stencilZFail;
  5817. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  5818. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  5819. if (this.polygonOffset === true) data.polygonOffset = true;
  5820. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5821. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5822. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  5823. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  5824. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  5825. if (this.scale !== undefined) data.scale = this.scale;
  5826. if (this.dithering === true) data.dithering = true;
  5827. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  5828. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  5829. if (this.wireframe === true) data.wireframe = this.wireframe;
  5830. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  5831. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  5832. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  5833. if (this.morphTargets === true) data.morphTargets = true;
  5834. if (this.morphNormals === true) data.morphNormals = true;
  5835. if (this.skinning === true) data.skinning = true;
  5836. if (this.visible === false) data.visible = false;
  5837. if (this.toneMapped === false) data.toneMapped = false;
  5838. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  5839. function extractFromCache(cache) {
  5840. var values = [];
  5841. for (var key in cache) {
  5842. var _data = cache[key];
  5843. delete _data.metadata;
  5844. values.push(_data);
  5845. }
  5846. return values;
  5847. }
  5848. if (isRoot) {
  5849. var textures = extractFromCache(meta.textures);
  5850. var images = extractFromCache(meta.images);
  5851. if (textures.length > 0) data.textures = textures;
  5852. if (images.length > 0) data.images = images;
  5853. }
  5854. return data;
  5855. },
  5856. clone: function clone() {
  5857. return new this.constructor().copy(this);
  5858. },
  5859. copy: function copy(source) {
  5860. this.name = source.name;
  5861. this.fog = source.fog;
  5862. this.blending = source.blending;
  5863. this.side = source.side;
  5864. this.flatShading = source.flatShading;
  5865. this.vertexColors = source.vertexColors;
  5866. this.opacity = source.opacity;
  5867. this.transparent = source.transparent;
  5868. this.blendSrc = source.blendSrc;
  5869. this.blendDst = source.blendDst;
  5870. this.blendEquation = source.blendEquation;
  5871. this.blendSrcAlpha = source.blendSrcAlpha;
  5872. this.blendDstAlpha = source.blendDstAlpha;
  5873. this.blendEquationAlpha = source.blendEquationAlpha;
  5874. this.depthFunc = source.depthFunc;
  5875. this.depthTest = source.depthTest;
  5876. this.depthWrite = source.depthWrite;
  5877. this.stencilWriteMask = source.stencilWriteMask;
  5878. this.stencilFunc = source.stencilFunc;
  5879. this.stencilRef = source.stencilRef;
  5880. this.stencilFuncMask = source.stencilFuncMask;
  5881. this.stencilFail = source.stencilFail;
  5882. this.stencilZFail = source.stencilZFail;
  5883. this.stencilZPass = source.stencilZPass;
  5884. this.stencilWrite = source.stencilWrite;
  5885. var srcPlanes = source.clippingPlanes;
  5886. var dstPlanes = null;
  5887. if (srcPlanes !== null) {
  5888. var n = srcPlanes.length;
  5889. dstPlanes = new Array(n);
  5890. for (var i = 0; i !== n; ++i) {
  5891. dstPlanes[i] = srcPlanes[i].clone();
  5892. }
  5893. }
  5894. this.clippingPlanes = dstPlanes;
  5895. this.clipIntersection = source.clipIntersection;
  5896. this.clipShadows = source.clipShadows;
  5897. this.shadowSide = source.shadowSide;
  5898. this.colorWrite = source.colorWrite;
  5899. this.precision = source.precision;
  5900. this.polygonOffset = source.polygonOffset;
  5901. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5902. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5903. this.dithering = source.dithering;
  5904. this.alphaTest = source.alphaTest;
  5905. this.premultipliedAlpha = source.premultipliedAlpha;
  5906. this.visible = source.visible;
  5907. this.toneMapped = source.toneMapped;
  5908. this.userData = JSON.parse(JSON.stringify(source.userData));
  5909. return this;
  5910. },
  5911. dispose: function dispose() {
  5912. this.dispatchEvent({
  5913. type: 'dispose'
  5914. });
  5915. }
  5916. });
  5917. Object.defineProperty(Material.prototype, 'needsUpdate', {
  5918. set: function set(value) {
  5919. if (value === true) this.version++;
  5920. }
  5921. });
  5922. /**
  5923. * parameters = {
  5924. * color: <hex>,
  5925. * opacity: <float>,
  5926. * map: new THREE.Texture( <Image> ),
  5927. *
  5928. * lightMap: new THREE.Texture( <Image> ),
  5929. * lightMapIntensity: <float>
  5930. *
  5931. * aoMap: new THREE.Texture( <Image> ),
  5932. * aoMapIntensity: <float>
  5933. *
  5934. * specularMap: new THREE.Texture( <Image> ),
  5935. *
  5936. * alphaMap: new THREE.Texture( <Image> ),
  5937. *
  5938. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5939. * combine: THREE.Multiply,
  5940. * reflectivity: <float>,
  5941. * refractionRatio: <float>,
  5942. *
  5943. * depthTest: <bool>,
  5944. * depthWrite: <bool>,
  5945. *
  5946. * wireframe: <boolean>,
  5947. * wireframeLinewidth: <float>,
  5948. *
  5949. * skinning: <bool>,
  5950. * morphTargets: <bool>
  5951. * }
  5952. */
  5953. function MeshBasicMaterial(parameters) {
  5954. Material.call(this);
  5955. this.type = 'MeshBasicMaterial';
  5956. this.color = new Color(0xffffff); // emissive
  5957. this.map = null;
  5958. this.lightMap = null;
  5959. this.lightMapIntensity = 1.0;
  5960. this.aoMap = null;
  5961. this.aoMapIntensity = 1.0;
  5962. this.specularMap = null;
  5963. this.alphaMap = null;
  5964. this.envMap = null;
  5965. this.combine = MultiplyOperation;
  5966. this.reflectivity = 1;
  5967. this.refractionRatio = 0.98;
  5968. this.wireframe = false;
  5969. this.wireframeLinewidth = 1;
  5970. this.wireframeLinecap = 'round';
  5971. this.wireframeLinejoin = 'round';
  5972. this.skinning = false;
  5973. this.morphTargets = false;
  5974. this.setValues(parameters);
  5975. }
  5976. MeshBasicMaterial.prototype = Object.create(Material.prototype);
  5977. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5978. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5979. MeshBasicMaterial.prototype.copy = function (source) {
  5980. Material.prototype.copy.call(this, source);
  5981. this.color.copy(source.color);
  5982. this.map = source.map;
  5983. this.lightMap = source.lightMap;
  5984. this.lightMapIntensity = source.lightMapIntensity;
  5985. this.aoMap = source.aoMap;
  5986. this.aoMapIntensity = source.aoMapIntensity;
  5987. this.specularMap = source.specularMap;
  5988. this.alphaMap = source.alphaMap;
  5989. this.envMap = source.envMap;
  5990. this.combine = source.combine;
  5991. this.reflectivity = source.reflectivity;
  5992. this.refractionRatio = source.refractionRatio;
  5993. this.wireframe = source.wireframe;
  5994. this.wireframeLinewidth = source.wireframeLinewidth;
  5995. this.wireframeLinecap = source.wireframeLinecap;
  5996. this.wireframeLinejoin = source.wireframeLinejoin;
  5997. this.skinning = source.skinning;
  5998. this.morphTargets = source.morphTargets;
  5999. return this;
  6000. };
  6001. var _vector$3 = new Vector3();
  6002. var _vector2$1 = new Vector2();
  6003. function BufferAttribute(array, itemSize, normalized) {
  6004. if (Array.isArray(array)) {
  6005. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  6006. }
  6007. this.name = '';
  6008. this.array = array;
  6009. this.itemSize = itemSize;
  6010. this.count = array !== undefined ? array.length / itemSize : 0;
  6011. this.normalized = normalized === true;
  6012. this.usage = StaticDrawUsage;
  6013. this.updateRange = {
  6014. offset: 0,
  6015. count: -1
  6016. };
  6017. this.version = 0;
  6018. }
  6019. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  6020. set: function set(value) {
  6021. if (value === true) this.version++;
  6022. }
  6023. });
  6024. Object.assign(BufferAttribute.prototype, {
  6025. isBufferAttribute: true,
  6026. onUploadCallback: function onUploadCallback() {},
  6027. setUsage: function setUsage(value) {
  6028. this.usage = value;
  6029. return this;
  6030. },
  6031. copy: function copy(source) {
  6032. this.name = source.name;
  6033. this.array = new source.array.constructor(source.array);
  6034. this.itemSize = source.itemSize;
  6035. this.count = source.count;
  6036. this.normalized = source.normalized;
  6037. this.usage = source.usage;
  6038. return this;
  6039. },
  6040. copyAt: function copyAt(index1, attribute, index2) {
  6041. index1 *= this.itemSize;
  6042. index2 *= attribute.itemSize;
  6043. for (var i = 0, l = this.itemSize; i < l; i++) {
  6044. this.array[index1 + i] = attribute.array[index2 + i];
  6045. }
  6046. return this;
  6047. },
  6048. copyArray: function copyArray(array) {
  6049. this.array.set(array);
  6050. return this;
  6051. },
  6052. copyColorsArray: function copyColorsArray(colors) {
  6053. var array = this.array;
  6054. var offset = 0;
  6055. for (var i = 0, l = colors.length; i < l; i++) {
  6056. var color = colors[i];
  6057. if (color === undefined) {
  6058. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  6059. color = new Color();
  6060. }
  6061. array[offset++] = color.r;
  6062. array[offset++] = color.g;
  6063. array[offset++] = color.b;
  6064. }
  6065. return this;
  6066. },
  6067. copyVector2sArray: function copyVector2sArray(vectors) {
  6068. var array = this.array;
  6069. var offset = 0;
  6070. for (var i = 0, l = vectors.length; i < l; i++) {
  6071. var vector = vectors[i];
  6072. if (vector === undefined) {
  6073. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  6074. vector = new Vector2();
  6075. }
  6076. array[offset++] = vector.x;
  6077. array[offset++] = vector.y;
  6078. }
  6079. return this;
  6080. },
  6081. copyVector3sArray: function copyVector3sArray(vectors) {
  6082. var array = this.array;
  6083. var offset = 0;
  6084. for (var i = 0, l = vectors.length; i < l; i++) {
  6085. var vector = vectors[i];
  6086. if (vector === undefined) {
  6087. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  6088. vector = new Vector3();
  6089. }
  6090. array[offset++] = vector.x;
  6091. array[offset++] = vector.y;
  6092. array[offset++] = vector.z;
  6093. }
  6094. return this;
  6095. },
  6096. copyVector4sArray: function copyVector4sArray(vectors) {
  6097. var array = this.array;
  6098. var offset = 0;
  6099. for (var i = 0, l = vectors.length; i < l; i++) {
  6100. var vector = vectors[i];
  6101. if (vector === undefined) {
  6102. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  6103. vector = new Vector4();
  6104. }
  6105. array[offset++] = vector.x;
  6106. array[offset++] = vector.y;
  6107. array[offset++] = vector.z;
  6108. array[offset++] = vector.w;
  6109. }
  6110. return this;
  6111. },
  6112. applyMatrix3: function applyMatrix3(m) {
  6113. if (this.itemSize === 2) {
  6114. for (var i = 0, l = this.count; i < l; i++) {
  6115. _vector2$1.fromBufferAttribute(this, i);
  6116. _vector2$1.applyMatrix3(m);
  6117. this.setXY(i, _vector2$1.x, _vector2$1.y);
  6118. }
  6119. } else if (this.itemSize === 3) {
  6120. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  6121. _vector$3.fromBufferAttribute(this, _i);
  6122. _vector$3.applyMatrix3(m);
  6123. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  6124. }
  6125. }
  6126. return this;
  6127. },
  6128. applyMatrix4: function applyMatrix4(m) {
  6129. for (var i = 0, l = this.count; i < l; i++) {
  6130. _vector$3.x = this.getX(i);
  6131. _vector$3.y = this.getY(i);
  6132. _vector$3.z = this.getZ(i);
  6133. _vector$3.applyMatrix4(m);
  6134. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6135. }
  6136. return this;
  6137. },
  6138. applyNormalMatrix: function applyNormalMatrix(m) {
  6139. for (var i = 0, l = this.count; i < l; i++) {
  6140. _vector$3.x = this.getX(i);
  6141. _vector$3.y = this.getY(i);
  6142. _vector$3.z = this.getZ(i);
  6143. _vector$3.applyNormalMatrix(m);
  6144. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6145. }
  6146. return this;
  6147. },
  6148. transformDirection: function transformDirection(m) {
  6149. for (var i = 0, l = this.count; i < l; i++) {
  6150. _vector$3.x = this.getX(i);
  6151. _vector$3.y = this.getY(i);
  6152. _vector$3.z = this.getZ(i);
  6153. _vector$3.transformDirection(m);
  6154. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6155. }
  6156. return this;
  6157. },
  6158. set: function set(value, offset) {
  6159. if (offset === void 0) {
  6160. offset = 0;
  6161. }
  6162. this.array.set(value, offset);
  6163. return this;
  6164. },
  6165. getX: function getX(index) {
  6166. return this.array[index * this.itemSize];
  6167. },
  6168. setX: function setX(index, x) {
  6169. this.array[index * this.itemSize] = x;
  6170. return this;
  6171. },
  6172. getY: function getY(index) {
  6173. return this.array[index * this.itemSize + 1];
  6174. },
  6175. setY: function setY(index, y) {
  6176. this.array[index * this.itemSize + 1] = y;
  6177. return this;
  6178. },
  6179. getZ: function getZ(index) {
  6180. return this.array[index * this.itemSize + 2];
  6181. },
  6182. setZ: function setZ(index, z) {
  6183. this.array[index * this.itemSize + 2] = z;
  6184. return this;
  6185. },
  6186. getW: function getW(index) {
  6187. return this.array[index * this.itemSize + 3];
  6188. },
  6189. setW: function setW(index, w) {
  6190. this.array[index * this.itemSize + 3] = w;
  6191. return this;
  6192. },
  6193. setXY: function setXY(index, x, y) {
  6194. index *= this.itemSize;
  6195. this.array[index + 0] = x;
  6196. this.array[index + 1] = y;
  6197. return this;
  6198. },
  6199. setXYZ: function setXYZ(index, x, y, z) {
  6200. index *= this.itemSize;
  6201. this.array[index + 0] = x;
  6202. this.array[index + 1] = y;
  6203. this.array[index + 2] = z;
  6204. return this;
  6205. },
  6206. setXYZW: function setXYZW(index, x, y, z, w) {
  6207. index *= this.itemSize;
  6208. this.array[index + 0] = x;
  6209. this.array[index + 1] = y;
  6210. this.array[index + 2] = z;
  6211. this.array[index + 3] = w;
  6212. return this;
  6213. },
  6214. onUpload: function onUpload(callback) {
  6215. this.onUploadCallback = callback;
  6216. return this;
  6217. },
  6218. clone: function clone() {
  6219. return new this.constructor(this.array, this.itemSize).copy(this);
  6220. },
  6221. toJSON: function toJSON() {
  6222. return {
  6223. itemSize: this.itemSize,
  6224. type: this.array.constructor.name,
  6225. array: Array.prototype.slice.call(this.array),
  6226. normalized: this.normalized
  6227. };
  6228. }
  6229. }); //
  6230. function Int8BufferAttribute(array, itemSize, normalized) {
  6231. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6232. }
  6233. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6234. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6235. function Uint8BufferAttribute(array, itemSize, normalized) {
  6236. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6237. }
  6238. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6239. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6240. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6241. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6242. }
  6243. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6244. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6245. function Int16BufferAttribute(array, itemSize, normalized) {
  6246. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6247. }
  6248. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6249. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6250. function Uint16BufferAttribute(array, itemSize, normalized) {
  6251. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6252. }
  6253. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6254. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6255. function Int32BufferAttribute(array, itemSize, normalized) {
  6256. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6257. }
  6258. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6259. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6260. function Uint32BufferAttribute(array, itemSize, normalized) {
  6261. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6262. }
  6263. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6264. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6265. function Float16BufferAttribute(array, itemSize, normalized) {
  6266. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6267. }
  6268. Float16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6269. Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
  6270. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  6271. function Float32BufferAttribute(array, itemSize, normalized) {
  6272. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6273. }
  6274. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6275. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6276. function Float64BufferAttribute(array, itemSize, normalized) {
  6277. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6278. }
  6279. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6280. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  6281. var DirectGeometry = /*#__PURE__*/function () {
  6282. function DirectGeometry() {
  6283. this.vertices = [];
  6284. this.normals = [];
  6285. this.colors = [];
  6286. this.uvs = [];
  6287. this.uvs2 = [];
  6288. this.groups = [];
  6289. this.morphTargets = {};
  6290. this.skinWeights = [];
  6291. this.skinIndices = []; // this.lineDistances = [];
  6292. this.boundingBox = null;
  6293. this.boundingSphere = null; // update flags
  6294. this.verticesNeedUpdate = false;
  6295. this.normalsNeedUpdate = false;
  6296. this.colorsNeedUpdate = false;
  6297. this.uvsNeedUpdate = false;
  6298. this.groupsNeedUpdate = false;
  6299. }
  6300. var _proto = DirectGeometry.prototype;
  6301. _proto.computeGroups = function computeGroups(geometry) {
  6302. var groups = [];
  6303. var group, i;
  6304. var materialIndex = undefined;
  6305. var faces = geometry.faces;
  6306. for (i = 0; i < faces.length; i++) {
  6307. var face = faces[i]; // materials
  6308. if (face.materialIndex !== materialIndex) {
  6309. materialIndex = face.materialIndex;
  6310. if (group !== undefined) {
  6311. group.count = i * 3 - group.start;
  6312. groups.push(group);
  6313. }
  6314. group = {
  6315. start: i * 3,
  6316. materialIndex: materialIndex
  6317. };
  6318. }
  6319. }
  6320. if (group !== undefined) {
  6321. group.count = i * 3 - group.start;
  6322. groups.push(group);
  6323. }
  6324. this.groups = groups;
  6325. };
  6326. _proto.fromGeometry = function fromGeometry(geometry) {
  6327. var faces = geometry.faces;
  6328. var vertices = geometry.vertices;
  6329. var faceVertexUvs = geometry.faceVertexUvs;
  6330. var hasFaceVertexUv = faceVertexUvs[0] && faceVertexUvs[0].length > 0;
  6331. var hasFaceVertexUv2 = faceVertexUvs[1] && faceVertexUvs[1].length > 0; // morphs
  6332. var morphTargets = geometry.morphTargets;
  6333. var morphTargetsLength = morphTargets.length;
  6334. var morphTargetsPosition;
  6335. if (morphTargetsLength > 0) {
  6336. morphTargetsPosition = [];
  6337. for (var i = 0; i < morphTargetsLength; i++) {
  6338. morphTargetsPosition[i] = {
  6339. name: morphTargets[i].name,
  6340. data: []
  6341. };
  6342. }
  6343. this.morphTargets.position = morphTargetsPosition;
  6344. }
  6345. var morphNormals = geometry.morphNormals;
  6346. var morphNormalsLength = morphNormals.length;
  6347. var morphTargetsNormal;
  6348. if (morphNormalsLength > 0) {
  6349. morphTargetsNormal = [];
  6350. for (var _i = 0; _i < morphNormalsLength; _i++) {
  6351. morphTargetsNormal[_i] = {
  6352. name: morphNormals[_i].name,
  6353. data: []
  6354. };
  6355. }
  6356. this.morphTargets.normal = morphTargetsNormal;
  6357. } // skins
  6358. var skinIndices = geometry.skinIndices;
  6359. var skinWeights = geometry.skinWeights;
  6360. var hasSkinIndices = skinIndices.length === vertices.length;
  6361. var hasSkinWeights = skinWeights.length === vertices.length; //
  6362. if (vertices.length > 0 && faces.length === 0) {
  6363. console.error('THREE.DirectGeometry: Faceless geometries are not supported.');
  6364. }
  6365. for (var _i2 = 0; _i2 < faces.length; _i2++) {
  6366. var face = faces[_i2];
  6367. this.vertices.push(vertices[face.a], vertices[face.b], vertices[face.c]);
  6368. var vertexNormals = face.vertexNormals;
  6369. if (vertexNormals.length === 3) {
  6370. this.normals.push(vertexNormals[0], vertexNormals[1], vertexNormals[2]);
  6371. } else {
  6372. var normal = face.normal;
  6373. this.normals.push(normal, normal, normal);
  6374. }
  6375. var vertexColors = face.vertexColors;
  6376. if (vertexColors.length === 3) {
  6377. this.colors.push(vertexColors[0], vertexColors[1], vertexColors[2]);
  6378. } else {
  6379. var color = face.color;
  6380. this.colors.push(color, color, color);
  6381. }
  6382. if (hasFaceVertexUv === true) {
  6383. var vertexUvs = faceVertexUvs[0][_i2];
  6384. if (vertexUvs !== undefined) {
  6385. this.uvs.push(vertexUvs[0], vertexUvs[1], vertexUvs[2]);
  6386. } else {
  6387. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', _i2);
  6388. this.uvs.push(new Vector2(), new Vector2(), new Vector2());
  6389. }
  6390. }
  6391. if (hasFaceVertexUv2 === true) {
  6392. var _vertexUvs = faceVertexUvs[1][_i2];
  6393. if (_vertexUvs !== undefined) {
  6394. this.uvs2.push(_vertexUvs[0], _vertexUvs[1], _vertexUvs[2]);
  6395. } else {
  6396. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', _i2);
  6397. this.uvs2.push(new Vector2(), new Vector2(), new Vector2());
  6398. }
  6399. } // morphs
  6400. for (var j = 0; j < morphTargetsLength; j++) {
  6401. var morphTarget = morphTargets[j].vertices;
  6402. morphTargetsPosition[j].data.push(morphTarget[face.a], morphTarget[face.b], morphTarget[face.c]);
  6403. }
  6404. for (var _j = 0; _j < morphNormalsLength; _j++) {
  6405. var morphNormal = morphNormals[_j].vertexNormals[_i2];
  6406. morphTargetsNormal[_j].data.push(morphNormal.a, morphNormal.b, morphNormal.c);
  6407. } // skins
  6408. if (hasSkinIndices) {
  6409. this.skinIndices.push(skinIndices[face.a], skinIndices[face.b], skinIndices[face.c]);
  6410. }
  6411. if (hasSkinWeights) {
  6412. this.skinWeights.push(skinWeights[face.a], skinWeights[face.b], skinWeights[face.c]);
  6413. }
  6414. }
  6415. this.computeGroups(geometry);
  6416. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6417. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6418. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6419. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6420. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6421. if (geometry.boundingSphere !== null) {
  6422. this.boundingSphere = geometry.boundingSphere.clone();
  6423. }
  6424. if (geometry.boundingBox !== null) {
  6425. this.boundingBox = geometry.boundingBox.clone();
  6426. }
  6427. return this;
  6428. };
  6429. return DirectGeometry;
  6430. }();
  6431. function arrayMax(array) {
  6432. if (array.length === 0) return -Infinity;
  6433. var max = array[0];
  6434. for (var i = 1, l = array.length; i < l; ++i) {
  6435. if (array[i] > max) max = array[i];
  6436. }
  6437. return max;
  6438. }
  6439. var TYPED_ARRAYS = {
  6440. Int8Array: Int8Array,
  6441. Uint8Array: Uint8Array,
  6442. // Workaround for IE11 pre KB2929437. See #11440
  6443. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  6444. Int16Array: Int16Array,
  6445. Uint16Array: Uint16Array,
  6446. Int32Array: Int32Array,
  6447. Uint32Array: Uint32Array,
  6448. Float32Array: Float32Array,
  6449. Float64Array: Float64Array
  6450. };
  6451. function getTypedArray(type, buffer) {
  6452. return new TYPED_ARRAYS[type](buffer);
  6453. }
  6454. var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6455. var _m1$2 = new Matrix4();
  6456. var _obj = new Object3D();
  6457. var _offset = new Vector3();
  6458. var _box$2 = new Box3();
  6459. var _boxMorphTargets = new Box3();
  6460. var _vector$4 = new Vector3();
  6461. function BufferGeometry() {
  6462. Object.defineProperty(this, 'id', {
  6463. value: _bufferGeometryId += 2
  6464. });
  6465. this.uuid = MathUtils.generateUUID();
  6466. this.name = '';
  6467. this.type = 'BufferGeometry';
  6468. this.index = null;
  6469. this.attributes = {};
  6470. this.morphAttributes = {};
  6471. this.morphTargetsRelative = false;
  6472. this.groups = [];
  6473. this.boundingBox = null;
  6474. this.boundingSphere = null;
  6475. this.drawRange = {
  6476. start: 0,
  6477. count: Infinity
  6478. };
  6479. this.userData = {};
  6480. }
  6481. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  6482. constructor: BufferGeometry,
  6483. isBufferGeometry: true,
  6484. getIndex: function getIndex() {
  6485. return this.index;
  6486. },
  6487. setIndex: function setIndex(index) {
  6488. if (Array.isArray(index)) {
  6489. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  6490. } else {
  6491. this.index = index;
  6492. }
  6493. return this;
  6494. },
  6495. getAttribute: function getAttribute(name) {
  6496. return this.attributes[name];
  6497. },
  6498. setAttribute: function setAttribute(name, attribute) {
  6499. this.attributes[name] = attribute;
  6500. return this;
  6501. },
  6502. deleteAttribute: function deleteAttribute(name) {
  6503. delete this.attributes[name];
  6504. return this;
  6505. },
  6506. hasAttribute: function hasAttribute(name) {
  6507. return this.attributes[name] !== undefined;
  6508. },
  6509. addGroup: function addGroup(start, count, materialIndex) {
  6510. if (materialIndex === void 0) {
  6511. materialIndex = 0;
  6512. }
  6513. this.groups.push({
  6514. start: start,
  6515. count: count,
  6516. materialIndex: materialIndex
  6517. });
  6518. },
  6519. clearGroups: function clearGroups() {
  6520. this.groups = [];
  6521. },
  6522. setDrawRange: function setDrawRange(start, count) {
  6523. this.drawRange.start = start;
  6524. this.drawRange.count = count;
  6525. },
  6526. applyMatrix4: function applyMatrix4(matrix) {
  6527. var position = this.attributes.position;
  6528. if (position !== undefined) {
  6529. position.applyMatrix4(matrix);
  6530. position.needsUpdate = true;
  6531. }
  6532. var normal = this.attributes.normal;
  6533. if (normal !== undefined) {
  6534. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  6535. normal.applyNormalMatrix(normalMatrix);
  6536. normal.needsUpdate = true;
  6537. }
  6538. var tangent = this.attributes.tangent;
  6539. if (tangent !== undefined) {
  6540. tangent.transformDirection(matrix);
  6541. tangent.needsUpdate = true;
  6542. }
  6543. if (this.boundingBox !== null) {
  6544. this.computeBoundingBox();
  6545. }
  6546. if (this.boundingSphere !== null) {
  6547. this.computeBoundingSphere();
  6548. }
  6549. return this;
  6550. },
  6551. rotateX: function rotateX(angle) {
  6552. // rotate geometry around world x-axis
  6553. _m1$2.makeRotationX(angle);
  6554. this.applyMatrix4(_m1$2);
  6555. return this;
  6556. },
  6557. rotateY: function rotateY(angle) {
  6558. // rotate geometry around world y-axis
  6559. _m1$2.makeRotationY(angle);
  6560. this.applyMatrix4(_m1$2);
  6561. return this;
  6562. },
  6563. rotateZ: function rotateZ(angle) {
  6564. // rotate geometry around world z-axis
  6565. _m1$2.makeRotationZ(angle);
  6566. this.applyMatrix4(_m1$2);
  6567. return this;
  6568. },
  6569. translate: function translate(x, y, z) {
  6570. // translate geometry
  6571. _m1$2.makeTranslation(x, y, z);
  6572. this.applyMatrix4(_m1$2);
  6573. return this;
  6574. },
  6575. scale: function scale(x, y, z) {
  6576. // scale geometry
  6577. _m1$2.makeScale(x, y, z);
  6578. this.applyMatrix4(_m1$2);
  6579. return this;
  6580. },
  6581. lookAt: function lookAt(vector) {
  6582. _obj.lookAt(vector);
  6583. _obj.updateMatrix();
  6584. this.applyMatrix4(_obj.matrix);
  6585. return this;
  6586. },
  6587. center: function center() {
  6588. this.computeBoundingBox();
  6589. this.boundingBox.getCenter(_offset).negate();
  6590. this.translate(_offset.x, _offset.y, _offset.z);
  6591. return this;
  6592. },
  6593. setFromObject: function setFromObject(object) {
  6594. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6595. var geometry = object.geometry;
  6596. if (object.isPoints || object.isLine) {
  6597. var positions = new Float32BufferAttribute(geometry.vertices.length * 3, 3);
  6598. var colors = new Float32BufferAttribute(geometry.colors.length * 3, 3);
  6599. this.setAttribute('position', positions.copyVector3sArray(geometry.vertices));
  6600. this.setAttribute('color', colors.copyColorsArray(geometry.colors));
  6601. if (geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length) {
  6602. var lineDistances = new Float32BufferAttribute(geometry.lineDistances.length, 1);
  6603. this.setAttribute('lineDistance', lineDistances.copyArray(geometry.lineDistances));
  6604. }
  6605. if (geometry.boundingSphere !== null) {
  6606. this.boundingSphere = geometry.boundingSphere.clone();
  6607. }
  6608. if (geometry.boundingBox !== null) {
  6609. this.boundingBox = geometry.boundingBox.clone();
  6610. }
  6611. } else if (object.isMesh) {
  6612. if (geometry && geometry.isGeometry) {
  6613. this.fromGeometry(geometry);
  6614. }
  6615. }
  6616. return this;
  6617. },
  6618. setFromPoints: function setFromPoints(points) {
  6619. var position = [];
  6620. for (var i = 0, l = points.length; i < l; i++) {
  6621. var point = points[i];
  6622. position.push(point.x, point.y, point.z || 0);
  6623. }
  6624. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  6625. return this;
  6626. },
  6627. updateFromObject: function updateFromObject(object) {
  6628. var geometry = object.geometry;
  6629. if (object.isMesh) {
  6630. var direct = geometry.__directGeometry;
  6631. if (geometry.elementsNeedUpdate === true) {
  6632. direct = undefined;
  6633. geometry.elementsNeedUpdate = false;
  6634. }
  6635. if (direct === undefined) {
  6636. return this.fromGeometry(geometry);
  6637. }
  6638. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6639. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6640. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6641. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6642. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6643. geometry.verticesNeedUpdate = false;
  6644. geometry.normalsNeedUpdate = false;
  6645. geometry.colorsNeedUpdate = false;
  6646. geometry.uvsNeedUpdate = false;
  6647. geometry.groupsNeedUpdate = false;
  6648. geometry = direct;
  6649. }
  6650. if (geometry.verticesNeedUpdate === true) {
  6651. var attribute = this.attributes.position;
  6652. if (attribute !== undefined) {
  6653. attribute.copyVector3sArray(geometry.vertices);
  6654. attribute.needsUpdate = true;
  6655. }
  6656. geometry.verticesNeedUpdate = false;
  6657. }
  6658. if (geometry.normalsNeedUpdate === true) {
  6659. var _attribute = this.attributes.normal;
  6660. if (_attribute !== undefined) {
  6661. _attribute.copyVector3sArray(geometry.normals);
  6662. _attribute.needsUpdate = true;
  6663. }
  6664. geometry.normalsNeedUpdate = false;
  6665. }
  6666. if (geometry.colorsNeedUpdate === true) {
  6667. var _attribute2 = this.attributes.color;
  6668. if (_attribute2 !== undefined) {
  6669. _attribute2.copyColorsArray(geometry.colors);
  6670. _attribute2.needsUpdate = true;
  6671. }
  6672. geometry.colorsNeedUpdate = false;
  6673. }
  6674. if (geometry.uvsNeedUpdate) {
  6675. var _attribute3 = this.attributes.uv;
  6676. if (_attribute3 !== undefined) {
  6677. _attribute3.copyVector2sArray(geometry.uvs);
  6678. _attribute3.needsUpdate = true;
  6679. }
  6680. geometry.uvsNeedUpdate = false;
  6681. }
  6682. if (geometry.lineDistancesNeedUpdate) {
  6683. var _attribute4 = this.attributes.lineDistance;
  6684. if (_attribute4 !== undefined) {
  6685. _attribute4.copyArray(geometry.lineDistances);
  6686. _attribute4.needsUpdate = true;
  6687. }
  6688. geometry.lineDistancesNeedUpdate = false;
  6689. }
  6690. if (geometry.groupsNeedUpdate) {
  6691. geometry.computeGroups(object.geometry);
  6692. this.groups = geometry.groups;
  6693. geometry.groupsNeedUpdate = false;
  6694. }
  6695. return this;
  6696. },
  6697. fromGeometry: function fromGeometry(geometry) {
  6698. geometry.__directGeometry = new DirectGeometry().fromGeometry(geometry);
  6699. return this.fromDirectGeometry(geometry.__directGeometry);
  6700. },
  6701. fromDirectGeometry: function fromDirectGeometry(geometry) {
  6702. var positions = new Float32Array(geometry.vertices.length * 3);
  6703. this.setAttribute('position', new BufferAttribute(positions, 3).copyVector3sArray(geometry.vertices));
  6704. if (geometry.normals.length > 0) {
  6705. var normals = new Float32Array(geometry.normals.length * 3);
  6706. this.setAttribute('normal', new BufferAttribute(normals, 3).copyVector3sArray(geometry.normals));
  6707. }
  6708. if (geometry.colors.length > 0) {
  6709. var colors = new Float32Array(geometry.colors.length * 3);
  6710. this.setAttribute('color', new BufferAttribute(colors, 3).copyColorsArray(geometry.colors));
  6711. }
  6712. if (geometry.uvs.length > 0) {
  6713. var uvs = new Float32Array(geometry.uvs.length * 2);
  6714. this.setAttribute('uv', new BufferAttribute(uvs, 2).copyVector2sArray(geometry.uvs));
  6715. }
  6716. if (geometry.uvs2.length > 0) {
  6717. var uvs2 = new Float32Array(geometry.uvs2.length * 2);
  6718. this.setAttribute('uv2', new BufferAttribute(uvs2, 2).copyVector2sArray(geometry.uvs2));
  6719. } // groups
  6720. this.groups = geometry.groups; // morphs
  6721. for (var name in geometry.morphTargets) {
  6722. var array = [];
  6723. var morphTargets = geometry.morphTargets[name];
  6724. for (var i = 0, l = morphTargets.length; i < l; i++) {
  6725. var morphTarget = morphTargets[i];
  6726. var attribute = new Float32BufferAttribute(morphTarget.data.length * 3, 3);
  6727. attribute.name = morphTarget.name;
  6728. array.push(attribute.copyVector3sArray(morphTarget.data));
  6729. }
  6730. this.morphAttributes[name] = array;
  6731. } // skinning
  6732. if (geometry.skinIndices.length > 0) {
  6733. var skinIndices = new Float32BufferAttribute(geometry.skinIndices.length * 4, 4);
  6734. this.setAttribute('skinIndex', skinIndices.copyVector4sArray(geometry.skinIndices));
  6735. }
  6736. if (geometry.skinWeights.length > 0) {
  6737. var skinWeights = new Float32BufferAttribute(geometry.skinWeights.length * 4, 4);
  6738. this.setAttribute('skinWeight', skinWeights.copyVector4sArray(geometry.skinWeights));
  6739. } //
  6740. if (geometry.boundingSphere !== null) {
  6741. this.boundingSphere = geometry.boundingSphere.clone();
  6742. }
  6743. if (geometry.boundingBox !== null) {
  6744. this.boundingBox = geometry.boundingBox.clone();
  6745. }
  6746. return this;
  6747. },
  6748. computeBoundingBox: function computeBoundingBox() {
  6749. if (this.boundingBox === null) {
  6750. this.boundingBox = new Box3();
  6751. }
  6752. var position = this.attributes.position;
  6753. var morphAttributesPosition = this.morphAttributes.position;
  6754. if (position && position.isGLBufferAttribute) {
  6755. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  6756. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  6757. return;
  6758. }
  6759. if (position !== undefined) {
  6760. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  6761. if (morphAttributesPosition) {
  6762. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6763. var morphAttribute = morphAttributesPosition[i];
  6764. _box$2.setFromBufferAttribute(morphAttribute);
  6765. if (this.morphTargetsRelative) {
  6766. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  6767. this.boundingBox.expandByPoint(_vector$4);
  6768. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  6769. this.boundingBox.expandByPoint(_vector$4);
  6770. } else {
  6771. this.boundingBox.expandByPoint(_box$2.min);
  6772. this.boundingBox.expandByPoint(_box$2.max);
  6773. }
  6774. }
  6775. }
  6776. } else {
  6777. this.boundingBox.makeEmpty();
  6778. }
  6779. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  6780. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  6781. }
  6782. },
  6783. computeBoundingSphere: function computeBoundingSphere() {
  6784. if (this.boundingSphere === null) {
  6785. this.boundingSphere = new Sphere();
  6786. }
  6787. var position = this.attributes.position;
  6788. var morphAttributesPosition = this.morphAttributes.position;
  6789. if (position && position.isGLBufferAttribute) {
  6790. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  6791. this.boundingSphere.set(new Vector3(), Infinity);
  6792. return;
  6793. }
  6794. if (position) {
  6795. // first, find the center of the bounding sphere
  6796. var center = this.boundingSphere.center;
  6797. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  6798. if (morphAttributesPosition) {
  6799. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6800. var morphAttribute = morphAttributesPosition[i];
  6801. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  6802. if (this.morphTargetsRelative) {
  6803. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  6804. _box$2.expandByPoint(_vector$4);
  6805. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  6806. _box$2.expandByPoint(_vector$4);
  6807. } else {
  6808. _box$2.expandByPoint(_boxMorphTargets.min);
  6809. _box$2.expandByPoint(_boxMorphTargets.max);
  6810. }
  6811. }
  6812. }
  6813. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  6814. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6815. var maxRadiusSq = 0;
  6816. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  6817. _vector$4.fromBufferAttribute(position, _i);
  6818. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6819. } // process morph attributes if present
  6820. if (morphAttributesPosition) {
  6821. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  6822. var _morphAttribute = morphAttributesPosition[_i2];
  6823. var morphTargetsRelative = this.morphTargetsRelative;
  6824. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  6825. _vector$4.fromBufferAttribute(_morphAttribute, j);
  6826. if (morphTargetsRelative) {
  6827. _offset.fromBufferAttribute(position, j);
  6828. _vector$4.add(_offset);
  6829. }
  6830. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6831. }
  6832. }
  6833. }
  6834. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  6835. if (isNaN(this.boundingSphere.radius)) {
  6836. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  6837. }
  6838. }
  6839. },
  6840. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  6841. },
  6842. computeVertexNormals: function computeVertexNormals() {
  6843. var index = this.index;
  6844. var positionAttribute = this.getAttribute('position');
  6845. if (positionAttribute !== undefined) {
  6846. var normalAttribute = this.getAttribute('normal');
  6847. if (normalAttribute === undefined) {
  6848. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  6849. this.setAttribute('normal', normalAttribute);
  6850. } else {
  6851. // reset existing normals to zero
  6852. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  6853. normalAttribute.setXYZ(i, 0, 0, 0);
  6854. }
  6855. }
  6856. var pA = new Vector3(),
  6857. pB = new Vector3(),
  6858. pC = new Vector3();
  6859. var nA = new Vector3(),
  6860. nB = new Vector3(),
  6861. nC = new Vector3();
  6862. var cb = new Vector3(),
  6863. ab = new Vector3(); // indexed elements
  6864. if (index) {
  6865. for (var _i3 = 0, _il3 = index.count; _i3 < _il3; _i3 += 3) {
  6866. var vA = index.getX(_i3 + 0);
  6867. var vB = index.getX(_i3 + 1);
  6868. var vC = index.getX(_i3 + 2);
  6869. pA.fromBufferAttribute(positionAttribute, vA);
  6870. pB.fromBufferAttribute(positionAttribute, vB);
  6871. pC.fromBufferAttribute(positionAttribute, vC);
  6872. cb.subVectors(pC, pB);
  6873. ab.subVectors(pA, pB);
  6874. cb.cross(ab);
  6875. nA.fromBufferAttribute(normalAttribute, vA);
  6876. nB.fromBufferAttribute(normalAttribute, vB);
  6877. nC.fromBufferAttribute(normalAttribute, vC);
  6878. nA.add(cb);
  6879. nB.add(cb);
  6880. nC.add(cb);
  6881. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  6882. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  6883. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  6884. }
  6885. } else {
  6886. // non-indexed elements (unconnected triangle soup)
  6887. for (var _i4 = 0, _il4 = positionAttribute.count; _i4 < _il4; _i4 += 3) {
  6888. pA.fromBufferAttribute(positionAttribute, _i4 + 0);
  6889. pB.fromBufferAttribute(positionAttribute, _i4 + 1);
  6890. pC.fromBufferAttribute(positionAttribute, _i4 + 2);
  6891. cb.subVectors(pC, pB);
  6892. ab.subVectors(pA, pB);
  6893. cb.cross(ab);
  6894. normalAttribute.setXYZ(_i4 + 0, cb.x, cb.y, cb.z);
  6895. normalAttribute.setXYZ(_i4 + 1, cb.x, cb.y, cb.z);
  6896. normalAttribute.setXYZ(_i4 + 2, cb.x, cb.y, cb.z);
  6897. }
  6898. }
  6899. this.normalizeNormals();
  6900. normalAttribute.needsUpdate = true;
  6901. }
  6902. },
  6903. merge: function merge(geometry, offset) {
  6904. if (!(geometry && geometry.isBufferGeometry)) {
  6905. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  6906. return;
  6907. }
  6908. if (offset === undefined) {
  6909. offset = 0;
  6910. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  6911. }
  6912. var attributes = this.attributes;
  6913. for (var key in attributes) {
  6914. if (geometry.attributes[key] === undefined) continue;
  6915. var attribute1 = attributes[key];
  6916. var attributeArray1 = attribute1.array;
  6917. var attribute2 = geometry.attributes[key];
  6918. var attributeArray2 = attribute2.array;
  6919. var attributeOffset = attribute2.itemSize * offset;
  6920. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  6921. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  6922. attributeArray1[j] = attributeArray2[i];
  6923. }
  6924. }
  6925. return this;
  6926. },
  6927. normalizeNormals: function normalizeNormals() {
  6928. var normals = this.attributes.normal;
  6929. for (var i = 0, il = normals.count; i < il; i++) {
  6930. _vector$4.fromBufferAttribute(normals, i);
  6931. _vector$4.normalize();
  6932. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  6933. }
  6934. },
  6935. toNonIndexed: function toNonIndexed() {
  6936. function convertBufferAttribute(attribute, indices) {
  6937. var array = attribute.array;
  6938. var itemSize = attribute.itemSize;
  6939. var normalized = attribute.normalized;
  6940. var array2 = new array.constructor(indices.length * itemSize);
  6941. var index = 0,
  6942. index2 = 0;
  6943. for (var i = 0, l = indices.length; i < l; i++) {
  6944. index = indices[i] * itemSize;
  6945. for (var j = 0; j < itemSize; j++) {
  6946. array2[index2++] = array[index++];
  6947. }
  6948. }
  6949. return new BufferAttribute(array2, itemSize, normalized);
  6950. } //
  6951. if (this.index === null) {
  6952. console.warn('THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.');
  6953. return this;
  6954. }
  6955. var geometry2 = new BufferGeometry();
  6956. var indices = this.index.array;
  6957. var attributes = this.attributes; // attributes
  6958. for (var name in attributes) {
  6959. var attribute = attributes[name];
  6960. var newAttribute = convertBufferAttribute(attribute, indices);
  6961. geometry2.setAttribute(name, newAttribute);
  6962. } // morph attributes
  6963. var morphAttributes = this.morphAttributes;
  6964. for (var _name in morphAttributes) {
  6965. var morphArray = [];
  6966. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  6967. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  6968. var _attribute5 = morphAttribute[i];
  6969. var _newAttribute = convertBufferAttribute(_attribute5, indices);
  6970. morphArray.push(_newAttribute);
  6971. }
  6972. geometry2.morphAttributes[_name] = morphArray;
  6973. }
  6974. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  6975. var groups = this.groups;
  6976. for (var _i5 = 0, l = groups.length; _i5 < l; _i5++) {
  6977. var group = groups[_i5];
  6978. geometry2.addGroup(group.start, group.count, group.materialIndex);
  6979. }
  6980. return geometry2;
  6981. },
  6982. toJSON: function toJSON() {
  6983. var data = {
  6984. metadata: {
  6985. version: 4.5,
  6986. type: 'BufferGeometry',
  6987. generator: 'BufferGeometry.toJSON'
  6988. }
  6989. }; // standard BufferGeometry serialization
  6990. data.uuid = this.uuid;
  6991. data.type = this.type;
  6992. if (this.name !== '') data.name = this.name;
  6993. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  6994. if (this.parameters !== undefined) {
  6995. var parameters = this.parameters;
  6996. for (var key in parameters) {
  6997. if (parameters[key] !== undefined) data[key] = parameters[key];
  6998. }
  6999. return data;
  7000. }
  7001. data.data = {
  7002. attributes: {}
  7003. };
  7004. var index = this.index;
  7005. if (index !== null) {
  7006. data.data.index = {
  7007. type: index.array.constructor.name,
  7008. array: Array.prototype.slice.call(index.array)
  7009. };
  7010. }
  7011. var attributes = this.attributes;
  7012. for (var _key in attributes) {
  7013. var attribute = attributes[_key];
  7014. var attributeData = attribute.toJSON(data.data);
  7015. if (attribute.name !== '') attributeData.name = attribute.name;
  7016. data.data.attributes[_key] = attributeData;
  7017. }
  7018. var morphAttributes = {};
  7019. var hasMorphAttributes = false;
  7020. for (var _key2 in this.morphAttributes) {
  7021. var attributeArray = this.morphAttributes[_key2];
  7022. var array = [];
  7023. for (var i = 0, il = attributeArray.length; i < il; i++) {
  7024. var _attribute6 = attributeArray[i];
  7025. var _attributeData = _attribute6.toJSON(data.data);
  7026. if (_attribute6.name !== '') _attributeData.name = _attribute6.name;
  7027. array.push(_attributeData);
  7028. }
  7029. if (array.length > 0) {
  7030. morphAttributes[_key2] = array;
  7031. hasMorphAttributes = true;
  7032. }
  7033. }
  7034. if (hasMorphAttributes) {
  7035. data.data.morphAttributes = morphAttributes;
  7036. data.data.morphTargetsRelative = this.morphTargetsRelative;
  7037. }
  7038. var groups = this.groups;
  7039. if (groups.length > 0) {
  7040. data.data.groups = JSON.parse(JSON.stringify(groups));
  7041. }
  7042. var boundingSphere = this.boundingSphere;
  7043. if (boundingSphere !== null) {
  7044. data.data.boundingSphere = {
  7045. center: boundingSphere.center.toArray(),
  7046. radius: boundingSphere.radius
  7047. };
  7048. }
  7049. return data;
  7050. },
  7051. clone: function clone() {
  7052. /*
  7053. // Handle primitives
  7054. const parameters = this.parameters;
  7055. if ( parameters !== undefined ) {
  7056. const values = [];
  7057. for ( const key in parameters ) {
  7058. values.push( parameters[ key ] );
  7059. }
  7060. const geometry = Object.create( this.constructor.prototype );
  7061. this.constructor.apply( geometry, values );
  7062. return geometry;
  7063. }
  7064. return new this.constructor().copy( this );
  7065. */
  7066. return new BufferGeometry().copy(this);
  7067. },
  7068. copy: function copy(source) {
  7069. // reset
  7070. this.index = null;
  7071. this.attributes = {};
  7072. this.morphAttributes = {};
  7073. this.groups = [];
  7074. this.boundingBox = null;
  7075. this.boundingSphere = null; // used for storing cloned, shared data
  7076. var data = {}; // name
  7077. this.name = source.name; // index
  7078. var index = source.index;
  7079. if (index !== null) {
  7080. this.setIndex(index.clone(data));
  7081. } // attributes
  7082. var attributes = source.attributes;
  7083. for (var name in attributes) {
  7084. var attribute = attributes[name];
  7085. this.setAttribute(name, attribute.clone(data));
  7086. } // morph attributes
  7087. var morphAttributes = source.morphAttributes;
  7088. for (var _name2 in morphAttributes) {
  7089. var array = [];
  7090. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  7091. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  7092. array.push(morphAttribute[i].clone(data));
  7093. }
  7094. this.morphAttributes[_name2] = array;
  7095. }
  7096. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  7097. var groups = source.groups;
  7098. for (var _i6 = 0, _l = groups.length; _i6 < _l; _i6++) {
  7099. var group = groups[_i6];
  7100. this.addGroup(group.start, group.count, group.materialIndex);
  7101. } // bounding box
  7102. var boundingBox = source.boundingBox;
  7103. if (boundingBox !== null) {
  7104. this.boundingBox = boundingBox.clone();
  7105. } // bounding sphere
  7106. var boundingSphere = source.boundingSphere;
  7107. if (boundingSphere !== null) {
  7108. this.boundingSphere = boundingSphere.clone();
  7109. } // draw range
  7110. this.drawRange.start = source.drawRange.start;
  7111. this.drawRange.count = source.drawRange.count; // user data
  7112. this.userData = source.userData;
  7113. return this;
  7114. },
  7115. dispose: function dispose() {
  7116. this.dispatchEvent({
  7117. type: 'dispose'
  7118. });
  7119. }
  7120. });
  7121. var _inverseMatrix = new Matrix4();
  7122. var _ray = new Ray();
  7123. var _sphere = new Sphere();
  7124. var _vA = new Vector3();
  7125. var _vB = new Vector3();
  7126. var _vC = new Vector3();
  7127. var _tempA = new Vector3();
  7128. var _tempB = new Vector3();
  7129. var _tempC = new Vector3();
  7130. var _morphA = new Vector3();
  7131. var _morphB = new Vector3();
  7132. var _morphC = new Vector3();
  7133. var _uvA = new Vector2();
  7134. var _uvB = new Vector2();
  7135. var _uvC = new Vector2();
  7136. var _intersectionPoint = new Vector3();
  7137. var _intersectionPointWorld = new Vector3();
  7138. function Mesh(geometry, material) {
  7139. if (geometry === void 0) {
  7140. geometry = new BufferGeometry();
  7141. }
  7142. if (material === void 0) {
  7143. material = new MeshBasicMaterial();
  7144. }
  7145. Object3D.call(this);
  7146. this.type = 'Mesh';
  7147. this.geometry = geometry;
  7148. this.material = material;
  7149. this.updateMorphTargets();
  7150. }
  7151. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7152. constructor: Mesh,
  7153. isMesh: true,
  7154. copy: function copy(source) {
  7155. Object3D.prototype.copy.call(this, source);
  7156. if (source.morphTargetInfluences !== undefined) {
  7157. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7158. }
  7159. if (source.morphTargetDictionary !== undefined) {
  7160. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7161. }
  7162. this.material = source.material;
  7163. this.geometry = source.geometry;
  7164. return this;
  7165. },
  7166. updateMorphTargets: function updateMorphTargets() {
  7167. var geometry = this.geometry;
  7168. if (geometry.isBufferGeometry) {
  7169. var morphAttributes = geometry.morphAttributes;
  7170. var keys = Object.keys(morphAttributes);
  7171. if (keys.length > 0) {
  7172. var morphAttribute = morphAttributes[keys[0]];
  7173. if (morphAttribute !== undefined) {
  7174. this.morphTargetInfluences = [];
  7175. this.morphTargetDictionary = {};
  7176. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7177. var name = morphAttribute[m].name || String(m);
  7178. this.morphTargetInfluences.push(0);
  7179. this.morphTargetDictionary[name] = m;
  7180. }
  7181. }
  7182. }
  7183. } else {
  7184. var morphTargets = geometry.morphTargets;
  7185. if (morphTargets !== undefined && morphTargets.length > 0) {
  7186. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7187. }
  7188. }
  7189. },
  7190. raycast: function raycast(raycaster, intersects) {
  7191. var geometry = this.geometry;
  7192. var material = this.material;
  7193. var matrixWorld = this.matrixWorld;
  7194. if (material === undefined) return; // Checking boundingSphere distance to ray
  7195. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7196. _sphere.copy(geometry.boundingSphere);
  7197. _sphere.applyMatrix4(matrixWorld);
  7198. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7199. _inverseMatrix.copy(matrixWorld).invert();
  7200. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7201. if (geometry.boundingBox !== null) {
  7202. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7203. }
  7204. var intersection;
  7205. if (geometry.isBufferGeometry) {
  7206. var index = geometry.index;
  7207. var position = geometry.attributes.position;
  7208. var morphPosition = geometry.morphAttributes.position;
  7209. var morphTargetsRelative = geometry.morphTargetsRelative;
  7210. var uv = geometry.attributes.uv;
  7211. var uv2 = geometry.attributes.uv2;
  7212. var groups = geometry.groups;
  7213. var drawRange = geometry.drawRange;
  7214. if (index !== null) {
  7215. // indexed buffer geometry
  7216. if (Array.isArray(material)) {
  7217. for (var i = 0, il = groups.length; i < il; i++) {
  7218. var group = groups[i];
  7219. var groupMaterial = material[group.materialIndex];
  7220. var start = Math.max(group.start, drawRange.start);
  7221. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7222. for (var j = start, jl = end; j < jl; j += 3) {
  7223. var a = index.getX(j);
  7224. var b = index.getX(j + 1);
  7225. var c = index.getX(j + 2);
  7226. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7227. if (intersection) {
  7228. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7229. intersection.face.materialIndex = group.materialIndex;
  7230. intersects.push(intersection);
  7231. }
  7232. }
  7233. }
  7234. } else {
  7235. var _start = Math.max(0, drawRange.start);
  7236. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7237. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7238. var _a = index.getX(_i);
  7239. var _b = index.getX(_i + 1);
  7240. var _c = index.getX(_i + 2);
  7241. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7242. if (intersection) {
  7243. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7244. intersects.push(intersection);
  7245. }
  7246. }
  7247. }
  7248. } else if (position !== undefined) {
  7249. // non-indexed buffer geometry
  7250. if (Array.isArray(material)) {
  7251. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7252. var _group = groups[_i2];
  7253. var _groupMaterial = material[_group.materialIndex];
  7254. var _start2 = Math.max(_group.start, drawRange.start);
  7255. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7256. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7257. var _a2 = _j;
  7258. var _b2 = _j + 1;
  7259. var _c2 = _j + 2;
  7260. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7261. if (intersection) {
  7262. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7263. intersection.face.materialIndex = _group.materialIndex;
  7264. intersects.push(intersection);
  7265. }
  7266. }
  7267. }
  7268. } else {
  7269. var _start3 = Math.max(0, drawRange.start);
  7270. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7271. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7272. var _a3 = _i3;
  7273. var _b3 = _i3 + 1;
  7274. var _c3 = _i3 + 2;
  7275. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7276. if (intersection) {
  7277. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7278. intersects.push(intersection);
  7279. }
  7280. }
  7281. }
  7282. }
  7283. } else if (geometry.isGeometry) {
  7284. var isMultiMaterial = Array.isArray(material);
  7285. var vertices = geometry.vertices;
  7286. var faces = geometry.faces;
  7287. var uvs;
  7288. var faceVertexUvs = geometry.faceVertexUvs[0];
  7289. if (faceVertexUvs.length > 0) uvs = faceVertexUvs;
  7290. for (var f = 0, fl = faces.length; f < fl; f++) {
  7291. var face = faces[f];
  7292. var faceMaterial = isMultiMaterial ? material[face.materialIndex] : material;
  7293. if (faceMaterial === undefined) continue;
  7294. var fvA = vertices[face.a];
  7295. var fvB = vertices[face.b];
  7296. var fvC = vertices[face.c];
  7297. intersection = checkIntersection(this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint);
  7298. if (intersection) {
  7299. if (uvs && uvs[f]) {
  7300. var uvs_f = uvs[f];
  7301. _uvA.copy(uvs_f[0]);
  7302. _uvB.copy(uvs_f[1]);
  7303. _uvC.copy(uvs_f[2]);
  7304. intersection.uv = Triangle.getUV(_intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2());
  7305. }
  7306. intersection.face = face;
  7307. intersection.faceIndex = f;
  7308. intersects.push(intersection);
  7309. }
  7310. }
  7311. }
  7312. }
  7313. });
  7314. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7315. var intersect;
  7316. if (material.side === BackSide) {
  7317. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7318. } else {
  7319. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7320. }
  7321. if (intersect === null) return null;
  7322. _intersectionPointWorld.copy(point);
  7323. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7324. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7325. if (distance < raycaster.near || distance > raycaster.far) return null;
  7326. return {
  7327. distance: distance,
  7328. point: _intersectionPointWorld.clone(),
  7329. object: object
  7330. };
  7331. }
  7332. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7333. _vA.fromBufferAttribute(position, a);
  7334. _vB.fromBufferAttribute(position, b);
  7335. _vC.fromBufferAttribute(position, c);
  7336. var morphInfluences = object.morphTargetInfluences;
  7337. if (material.morphTargets && morphPosition && morphInfluences) {
  7338. _morphA.set(0, 0, 0);
  7339. _morphB.set(0, 0, 0);
  7340. _morphC.set(0, 0, 0);
  7341. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7342. var influence = morphInfluences[i];
  7343. var morphAttribute = morphPosition[i];
  7344. if (influence === 0) continue;
  7345. _tempA.fromBufferAttribute(morphAttribute, a);
  7346. _tempB.fromBufferAttribute(morphAttribute, b);
  7347. _tempC.fromBufferAttribute(morphAttribute, c);
  7348. if (morphTargetsRelative) {
  7349. _morphA.addScaledVector(_tempA, influence);
  7350. _morphB.addScaledVector(_tempB, influence);
  7351. _morphC.addScaledVector(_tempC, influence);
  7352. } else {
  7353. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7354. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7355. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7356. }
  7357. }
  7358. _vA.add(_morphA);
  7359. _vB.add(_morphB);
  7360. _vC.add(_morphC);
  7361. }
  7362. if (object.isSkinnedMesh) {
  7363. object.boneTransform(a, _vA);
  7364. object.boneTransform(b, _vB);
  7365. object.boneTransform(c, _vC);
  7366. }
  7367. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7368. if (intersection) {
  7369. if (uv) {
  7370. _uvA.fromBufferAttribute(uv, a);
  7371. _uvB.fromBufferAttribute(uv, b);
  7372. _uvC.fromBufferAttribute(uv, c);
  7373. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7374. }
  7375. if (uv2) {
  7376. _uvA.fromBufferAttribute(uv2, a);
  7377. _uvB.fromBufferAttribute(uv2, b);
  7378. _uvC.fromBufferAttribute(uv2, c);
  7379. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7380. }
  7381. var face = new Face3(a, b, c);
  7382. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7383. intersection.face = face;
  7384. }
  7385. return intersection;
  7386. }
  7387. var BoxBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7388. _inheritsLoose(BoxBufferGeometry, _BufferGeometry);
  7389. function BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7390. var _this;
  7391. if (width === void 0) {
  7392. width = 1;
  7393. }
  7394. if (height === void 0) {
  7395. height = 1;
  7396. }
  7397. if (depth === void 0) {
  7398. depth = 1;
  7399. }
  7400. if (widthSegments === void 0) {
  7401. widthSegments = 1;
  7402. }
  7403. if (heightSegments === void 0) {
  7404. heightSegments = 1;
  7405. }
  7406. if (depthSegments === void 0) {
  7407. depthSegments = 1;
  7408. }
  7409. _this = _BufferGeometry.call(this) || this;
  7410. _this.type = 'BoxBufferGeometry';
  7411. _this.parameters = {
  7412. width: width,
  7413. height: height,
  7414. depth: depth,
  7415. widthSegments: widthSegments,
  7416. heightSegments: heightSegments,
  7417. depthSegments: depthSegments
  7418. };
  7419. var scope = _assertThisInitialized(_this); // segments
  7420. widthSegments = Math.floor(widthSegments);
  7421. heightSegments = Math.floor(heightSegments);
  7422. depthSegments = Math.floor(depthSegments); // buffers
  7423. var indices = [];
  7424. var vertices = [];
  7425. var normals = [];
  7426. var uvs = []; // helper variables
  7427. var numberOfVertices = 0;
  7428. var groupStart = 0; // build each side of the box geometry
  7429. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7430. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7431. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7432. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7433. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7434. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7435. // build geometry
  7436. _this.setIndex(indices);
  7437. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7438. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7439. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7440. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7441. var segmentWidth = width / gridX;
  7442. var segmentHeight = height / gridY;
  7443. var widthHalf = width / 2;
  7444. var heightHalf = height / 2;
  7445. var depthHalf = depth / 2;
  7446. var gridX1 = gridX + 1;
  7447. var gridY1 = gridY + 1;
  7448. var vertexCounter = 0;
  7449. var groupCount = 0;
  7450. var vector = new Vector3(); // generate vertices, normals and uvs
  7451. for (var iy = 0; iy < gridY1; iy++) {
  7452. var y = iy * segmentHeight - heightHalf;
  7453. for (var ix = 0; ix < gridX1; ix++) {
  7454. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7455. vector[u] = x * udir;
  7456. vector[v] = y * vdir;
  7457. vector[w] = depthHalf; // now apply vector to vertex buffer
  7458. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7459. vector[u] = 0;
  7460. vector[v] = 0;
  7461. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7462. normals.push(vector.x, vector.y, vector.z); // uvs
  7463. uvs.push(ix / gridX);
  7464. uvs.push(1 - iy / gridY); // counters
  7465. vertexCounter += 1;
  7466. }
  7467. } // indices
  7468. // 1. you need three indices to draw a single face
  7469. // 2. a single segment consists of two faces
  7470. // 3. so we need to generate six (2*3) indices per segment
  7471. for (var _iy = 0; _iy < gridY; _iy++) {
  7472. for (var _ix = 0; _ix < gridX; _ix++) {
  7473. var a = numberOfVertices + _ix + gridX1 * _iy;
  7474. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7475. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7476. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7477. indices.push(a, b, d);
  7478. indices.push(b, c, d); // increase counter
  7479. groupCount += 6;
  7480. }
  7481. } // add a group to the geometry. this will ensure multi material support
  7482. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7483. groupStart += groupCount; // update total number of vertices
  7484. numberOfVertices += vertexCounter;
  7485. }
  7486. return _this;
  7487. }
  7488. return BoxBufferGeometry;
  7489. }(BufferGeometry);
  7490. /**
  7491. * Uniform Utilities
  7492. */
  7493. function cloneUniforms(src) {
  7494. var dst = {};
  7495. for (var u in src) {
  7496. dst[u] = {};
  7497. for (var p in src[u]) {
  7498. var property = src[u][p];
  7499. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture)) {
  7500. dst[u][p] = property.clone();
  7501. } else if (Array.isArray(property)) {
  7502. dst[u][p] = property.slice();
  7503. } else {
  7504. dst[u][p] = property;
  7505. }
  7506. }
  7507. }
  7508. return dst;
  7509. }
  7510. function mergeUniforms(uniforms) {
  7511. var merged = {};
  7512. for (var u = 0; u < uniforms.length; u++) {
  7513. var tmp = cloneUniforms(uniforms[u]);
  7514. for (var p in tmp) {
  7515. merged[p] = tmp[p];
  7516. }
  7517. }
  7518. return merged;
  7519. } // Legacy
  7520. var UniformsUtils = {
  7521. clone: cloneUniforms,
  7522. merge: mergeUniforms
  7523. };
  7524. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7525. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7526. /**
  7527. * parameters = {
  7528. * defines: { "label" : "value" },
  7529. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7530. *
  7531. * fragmentShader: <string>,
  7532. * vertexShader: <string>,
  7533. *
  7534. * wireframe: <boolean>,
  7535. * wireframeLinewidth: <float>,
  7536. *
  7537. * lights: <bool>,
  7538. *
  7539. * skinning: <bool>,
  7540. * morphTargets: <bool>,
  7541. * morphNormals: <bool>
  7542. * }
  7543. */
  7544. function ShaderMaterial(parameters) {
  7545. Material.call(this);
  7546. this.type = 'ShaderMaterial';
  7547. this.defines = {};
  7548. this.uniforms = {};
  7549. this.vertexShader = default_vertex;
  7550. this.fragmentShader = default_fragment;
  7551. this.linewidth = 1;
  7552. this.wireframe = false;
  7553. this.wireframeLinewidth = 1;
  7554. this.fog = false; // set to use scene fog
  7555. this.lights = false; // set to use scene lights
  7556. this.clipping = false; // set to use user-defined clipping planes
  7557. this.skinning = false; // set to use skinning attribute streams
  7558. this.morphTargets = false; // set to use morph targets
  7559. this.morphNormals = false; // set to use morph normals
  7560. this.extensions = {
  7561. derivatives: false,
  7562. // set to use derivatives
  7563. fragDepth: false,
  7564. // set to use fragment depth values
  7565. drawBuffers: false,
  7566. // set to use draw buffers
  7567. shaderTextureLOD: false // set to use shader texture LOD
  7568. }; // When rendered geometry doesn't include these attributes but the material does,
  7569. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7570. this.defaultAttributeValues = {
  7571. 'color': [1, 1, 1],
  7572. 'uv': [0, 0],
  7573. 'uv2': [0, 0]
  7574. };
  7575. this.index0AttributeName = undefined;
  7576. this.uniformsNeedUpdate = false;
  7577. this.glslVersion = null;
  7578. if (parameters !== undefined) {
  7579. if (parameters.attributes !== undefined) {
  7580. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  7581. }
  7582. this.setValues(parameters);
  7583. }
  7584. }
  7585. ShaderMaterial.prototype = Object.create(Material.prototype);
  7586. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7587. ShaderMaterial.prototype.isShaderMaterial = true;
  7588. ShaderMaterial.prototype.copy = function (source) {
  7589. Material.prototype.copy.call(this, source);
  7590. this.fragmentShader = source.fragmentShader;
  7591. this.vertexShader = source.vertexShader;
  7592. this.uniforms = cloneUniforms(source.uniforms);
  7593. this.defines = Object.assign({}, source.defines);
  7594. this.wireframe = source.wireframe;
  7595. this.wireframeLinewidth = source.wireframeLinewidth;
  7596. this.lights = source.lights;
  7597. this.clipping = source.clipping;
  7598. this.skinning = source.skinning;
  7599. this.morphTargets = source.morphTargets;
  7600. this.morphNormals = source.morphNormals;
  7601. this.extensions = Object.assign({}, source.extensions);
  7602. this.glslVersion = source.glslVersion;
  7603. return this;
  7604. };
  7605. ShaderMaterial.prototype.toJSON = function (meta) {
  7606. var data = Material.prototype.toJSON.call(this, meta);
  7607. data.glslVersion = this.glslVersion;
  7608. data.uniforms = {};
  7609. for (var name in this.uniforms) {
  7610. var uniform = this.uniforms[name];
  7611. var value = uniform.value;
  7612. if (value && value.isTexture) {
  7613. data.uniforms[name] = {
  7614. type: 't',
  7615. value: value.toJSON(meta).uuid
  7616. };
  7617. } else if (value && value.isColor) {
  7618. data.uniforms[name] = {
  7619. type: 'c',
  7620. value: value.getHex()
  7621. };
  7622. } else if (value && value.isVector2) {
  7623. data.uniforms[name] = {
  7624. type: 'v2',
  7625. value: value.toArray()
  7626. };
  7627. } else if (value && value.isVector3) {
  7628. data.uniforms[name] = {
  7629. type: 'v3',
  7630. value: value.toArray()
  7631. };
  7632. } else if (value && value.isVector4) {
  7633. data.uniforms[name] = {
  7634. type: 'v4',
  7635. value: value.toArray()
  7636. };
  7637. } else if (value && value.isMatrix3) {
  7638. data.uniforms[name] = {
  7639. type: 'm3',
  7640. value: value.toArray()
  7641. };
  7642. } else if (value && value.isMatrix4) {
  7643. data.uniforms[name] = {
  7644. type: 'm4',
  7645. value: value.toArray()
  7646. };
  7647. } else {
  7648. data.uniforms[name] = {
  7649. value: value
  7650. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7651. }
  7652. }
  7653. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  7654. data.vertexShader = this.vertexShader;
  7655. data.fragmentShader = this.fragmentShader;
  7656. var extensions = {};
  7657. for (var key in this.extensions) {
  7658. if (this.extensions[key] === true) extensions[key] = true;
  7659. }
  7660. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  7661. return data;
  7662. };
  7663. function Camera() {
  7664. Object3D.call(this);
  7665. this.type = 'Camera';
  7666. this.matrixWorldInverse = new Matrix4();
  7667. this.projectionMatrix = new Matrix4();
  7668. this.projectionMatrixInverse = new Matrix4();
  7669. }
  7670. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  7671. constructor: Camera,
  7672. isCamera: true,
  7673. copy: function copy(source, recursive) {
  7674. Object3D.prototype.copy.call(this, source, recursive);
  7675. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  7676. this.projectionMatrix.copy(source.projectionMatrix);
  7677. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  7678. return this;
  7679. },
  7680. getWorldDirection: function getWorldDirection(target) {
  7681. if (target === undefined) {
  7682. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  7683. target = new Vector3();
  7684. }
  7685. this.updateWorldMatrix(true, false);
  7686. var e = this.matrixWorld.elements;
  7687. return target.set(-e[8], -e[9], -e[10]).normalize();
  7688. },
  7689. updateMatrixWorld: function updateMatrixWorld(force) {
  7690. Object3D.prototype.updateMatrixWorld.call(this, force);
  7691. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  7692. },
  7693. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  7694. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  7695. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  7696. },
  7697. clone: function clone() {
  7698. return new this.constructor().copy(this);
  7699. }
  7700. });
  7701. function PerspectiveCamera(fov, aspect, near, far) {
  7702. if (fov === void 0) {
  7703. fov = 50;
  7704. }
  7705. if (aspect === void 0) {
  7706. aspect = 1;
  7707. }
  7708. if (near === void 0) {
  7709. near = 0.1;
  7710. }
  7711. if (far === void 0) {
  7712. far = 2000;
  7713. }
  7714. Camera.call(this);
  7715. this.type = 'PerspectiveCamera';
  7716. this.fov = fov;
  7717. this.zoom = 1;
  7718. this.near = near;
  7719. this.far = far;
  7720. this.focus = 10;
  7721. this.aspect = aspect;
  7722. this.view = null;
  7723. this.filmGauge = 35; // width of the film (default in millimeters)
  7724. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7725. this.updateProjectionMatrix();
  7726. }
  7727. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  7728. constructor: PerspectiveCamera,
  7729. isPerspectiveCamera: true,
  7730. copy: function copy(source, recursive) {
  7731. Camera.prototype.copy.call(this, source, recursive);
  7732. this.fov = source.fov;
  7733. this.zoom = source.zoom;
  7734. this.near = source.near;
  7735. this.far = source.far;
  7736. this.focus = source.focus;
  7737. this.aspect = source.aspect;
  7738. this.view = source.view === null ? null : Object.assign({}, source.view);
  7739. this.filmGauge = source.filmGauge;
  7740. this.filmOffset = source.filmOffset;
  7741. return this;
  7742. },
  7743. /**
  7744. * Sets the FOV by focal length in respect to the current .filmGauge.
  7745. *
  7746. * The default film gauge is 35, so that the focal length can be specified for
  7747. * a 35mm (full frame) camera.
  7748. *
  7749. * Values for focal length and film gauge must have the same unit.
  7750. */
  7751. setFocalLength: function setFocalLength(focalLength) {
  7752. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7753. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7754. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  7755. this.updateProjectionMatrix();
  7756. },
  7757. /**
  7758. * Calculates the focal length from the current .fov and .filmGauge.
  7759. */
  7760. getFocalLength: function getFocalLength() {
  7761. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  7762. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7763. },
  7764. getEffectiveFOV: function getEffectiveFOV() {
  7765. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  7766. },
  7767. getFilmWidth: function getFilmWidth() {
  7768. // film not completely covered in portrait format (aspect < 1)
  7769. return this.filmGauge * Math.min(this.aspect, 1);
  7770. },
  7771. getFilmHeight: function getFilmHeight() {
  7772. // film not completely covered in landscape format (aspect > 1)
  7773. return this.filmGauge / Math.max(this.aspect, 1);
  7774. },
  7775. /**
  7776. * Sets an offset in a larger frustum. This is useful for multi-window or
  7777. * multi-monitor/multi-machine setups.
  7778. *
  7779. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7780. * the monitors are in grid like this
  7781. *
  7782. * +---+---+---+
  7783. * | A | B | C |
  7784. * +---+---+---+
  7785. * | D | E | F |
  7786. * +---+---+---+
  7787. *
  7788. * then for each monitor you would call it like this
  7789. *
  7790. * const w = 1920;
  7791. * const h = 1080;
  7792. * const fullWidth = w * 3;
  7793. * const fullHeight = h * 2;
  7794. *
  7795. * --A--
  7796. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7797. * --B--
  7798. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7799. * --C--
  7800. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7801. * --D--
  7802. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7803. * --E--
  7804. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7805. * --F--
  7806. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7807. *
  7808. * Note there is no reason monitors have to be the same size or in a grid.
  7809. */
  7810. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  7811. this.aspect = fullWidth / fullHeight;
  7812. if (this.view === null) {
  7813. this.view = {
  7814. enabled: true,
  7815. fullWidth: 1,
  7816. fullHeight: 1,
  7817. offsetX: 0,
  7818. offsetY: 0,
  7819. width: 1,
  7820. height: 1
  7821. };
  7822. }
  7823. this.view.enabled = true;
  7824. this.view.fullWidth = fullWidth;
  7825. this.view.fullHeight = fullHeight;
  7826. this.view.offsetX = x;
  7827. this.view.offsetY = y;
  7828. this.view.width = width;
  7829. this.view.height = height;
  7830. this.updateProjectionMatrix();
  7831. },
  7832. clearViewOffset: function clearViewOffset() {
  7833. if (this.view !== null) {
  7834. this.view.enabled = false;
  7835. }
  7836. this.updateProjectionMatrix();
  7837. },
  7838. updateProjectionMatrix: function updateProjectionMatrix() {
  7839. var near = this.near;
  7840. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  7841. var height = 2 * top;
  7842. var width = this.aspect * height;
  7843. var left = -0.5 * width;
  7844. var view = this.view;
  7845. if (this.view !== null && this.view.enabled) {
  7846. var fullWidth = view.fullWidth,
  7847. fullHeight = view.fullHeight;
  7848. left += view.offsetX * width / fullWidth;
  7849. top -= view.offsetY * height / fullHeight;
  7850. width *= view.width / fullWidth;
  7851. height *= view.height / fullHeight;
  7852. }
  7853. var skew = this.filmOffset;
  7854. if (skew !== 0) left += near * skew / this.getFilmWidth();
  7855. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  7856. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  7857. },
  7858. toJSON: function toJSON(meta) {
  7859. var data = Object3D.prototype.toJSON.call(this, meta);
  7860. data.object.fov = this.fov;
  7861. data.object.zoom = this.zoom;
  7862. data.object.near = this.near;
  7863. data.object.far = this.far;
  7864. data.object.focus = this.focus;
  7865. data.object.aspect = this.aspect;
  7866. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  7867. data.object.filmGauge = this.filmGauge;
  7868. data.object.filmOffset = this.filmOffset;
  7869. return data;
  7870. }
  7871. });
  7872. var fov = 90,
  7873. aspect = 1;
  7874. function CubeCamera(near, far, renderTarget) {
  7875. Object3D.call(this);
  7876. this.type = 'CubeCamera';
  7877. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  7878. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  7879. return;
  7880. }
  7881. this.renderTarget = renderTarget;
  7882. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  7883. cameraPX.layers = this.layers;
  7884. cameraPX.up.set(0, -1, 0);
  7885. cameraPX.lookAt(new Vector3(1, 0, 0));
  7886. this.add(cameraPX);
  7887. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  7888. cameraNX.layers = this.layers;
  7889. cameraNX.up.set(0, -1, 0);
  7890. cameraNX.lookAt(new Vector3(-1, 0, 0));
  7891. this.add(cameraNX);
  7892. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  7893. cameraPY.layers = this.layers;
  7894. cameraPY.up.set(0, 0, 1);
  7895. cameraPY.lookAt(new Vector3(0, 1, 0));
  7896. this.add(cameraPY);
  7897. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  7898. cameraNY.layers = this.layers;
  7899. cameraNY.up.set(0, 0, -1);
  7900. cameraNY.lookAt(new Vector3(0, -1, 0));
  7901. this.add(cameraNY);
  7902. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  7903. cameraPZ.layers = this.layers;
  7904. cameraPZ.up.set(0, -1, 0);
  7905. cameraPZ.lookAt(new Vector3(0, 0, 1));
  7906. this.add(cameraPZ);
  7907. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  7908. cameraNZ.layers = this.layers;
  7909. cameraNZ.up.set(0, -1, 0);
  7910. cameraNZ.lookAt(new Vector3(0, 0, -1));
  7911. this.add(cameraNZ);
  7912. this.update = function (renderer, scene) {
  7913. if (this.parent === null) this.updateMatrixWorld();
  7914. var currentXrEnabled = renderer.xr.enabled;
  7915. var currentRenderTarget = renderer.getRenderTarget();
  7916. renderer.xr.enabled = false;
  7917. var generateMipmaps = renderTarget.texture.generateMipmaps;
  7918. renderTarget.texture.generateMipmaps = false;
  7919. renderer.setRenderTarget(renderTarget, 0);
  7920. renderer.render(scene, cameraPX);
  7921. renderer.setRenderTarget(renderTarget, 1);
  7922. renderer.render(scene, cameraNX);
  7923. renderer.setRenderTarget(renderTarget, 2);
  7924. renderer.render(scene, cameraPY);
  7925. renderer.setRenderTarget(renderTarget, 3);
  7926. renderer.render(scene, cameraNY);
  7927. renderer.setRenderTarget(renderTarget, 4);
  7928. renderer.render(scene, cameraPZ);
  7929. renderTarget.texture.generateMipmaps = generateMipmaps;
  7930. renderer.setRenderTarget(renderTarget, 5);
  7931. renderer.render(scene, cameraNZ);
  7932. renderer.setRenderTarget(currentRenderTarget);
  7933. renderer.xr.enabled = currentXrEnabled;
  7934. };
  7935. }
  7936. CubeCamera.prototype = Object.create(Object3D.prototype);
  7937. CubeCamera.prototype.constructor = CubeCamera;
  7938. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  7939. images = images !== undefined ? images : [];
  7940. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7941. format = format !== undefined ? format : RGBFormat;
  7942. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  7943. this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
  7944. //
  7945. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7946. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7947. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7948. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7949. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  7950. // when using WebGLCubeRenderTarget.texture as a cube texture.
  7951. this._needsFlipEnvMap = true;
  7952. }
  7953. CubeTexture.prototype = Object.create(Texture.prototype);
  7954. CubeTexture.prototype.constructor = CubeTexture;
  7955. CubeTexture.prototype.isCubeTexture = true;
  7956. Object.defineProperty(CubeTexture.prototype, 'images', {
  7957. get: function get() {
  7958. return this.image;
  7959. },
  7960. set: function set(value) {
  7961. this.image = value;
  7962. }
  7963. });
  7964. function WebGLCubeRenderTarget(size, options, dummy) {
  7965. if (Number.isInteger(options)) {
  7966. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  7967. options = dummy;
  7968. }
  7969. WebGLRenderTarget.call(this, size, size, options);
  7970. options = options || {};
  7971. this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  7972. this.texture._needsFlipEnvMap = false;
  7973. }
  7974. WebGLCubeRenderTarget.prototype = Object.create(WebGLRenderTarget.prototype);
  7975. WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
  7976. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  7977. WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function (renderer, texture) {
  7978. this.texture.type = texture.type;
  7979. this.texture.format = RGBAFormat; // see #18859
  7980. this.texture.encoding = texture.encoding;
  7981. this.texture.generateMipmaps = texture.generateMipmaps;
  7982. this.texture.minFilter = texture.minFilter;
  7983. this.texture.magFilter = texture.magFilter;
  7984. var shader = {
  7985. uniforms: {
  7986. tEquirect: {
  7987. value: null
  7988. }
  7989. },
  7990. vertexShader:
  7991. /* glsl */
  7992. "\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",
  7993. fragmentShader:
  7994. /* glsl */
  7995. "\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"
  7996. };
  7997. var geometry = new BoxBufferGeometry(5, 5, 5);
  7998. var material = new ShaderMaterial({
  7999. name: 'CubemapFromEquirect',
  8000. uniforms: cloneUniforms(shader.uniforms),
  8001. vertexShader: shader.vertexShader,
  8002. fragmentShader: shader.fragmentShader,
  8003. side: BackSide,
  8004. blending: NoBlending
  8005. });
  8006. material.uniforms.tEquirect.value = texture;
  8007. var mesh = new Mesh(geometry, material);
  8008. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  8009. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  8010. var camera = new CubeCamera(1, 10, this);
  8011. camera.update(renderer, mesh);
  8012. texture.minFilter = currentMinFilter;
  8013. mesh.geometry.dispose();
  8014. mesh.material.dispose();
  8015. return this;
  8016. };
  8017. WebGLCubeRenderTarget.prototype.clear = function (renderer, color, depth, stencil) {
  8018. var currentRenderTarget = renderer.getRenderTarget();
  8019. for (var i = 0; i < 6; i++) {
  8020. renderer.setRenderTarget(this, i);
  8021. renderer.clear(color, depth, stencil);
  8022. }
  8023. renderer.setRenderTarget(currentRenderTarget);
  8024. };
  8025. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  8026. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8027. this.image = {
  8028. data: data || null,
  8029. width: width || 1,
  8030. height: height || 1
  8031. };
  8032. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8033. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8034. this.generateMipmaps = false;
  8035. this.flipY = false;
  8036. this.unpackAlignment = 1;
  8037. this.needsUpdate = true;
  8038. }
  8039. DataTexture.prototype = Object.create(Texture.prototype);
  8040. DataTexture.prototype.constructor = DataTexture;
  8041. DataTexture.prototype.isDataTexture = true;
  8042. var _sphere$1 = /*@__PURE__*/new Sphere();
  8043. var _vector$5 = /*@__PURE__*/new Vector3();
  8044. var Frustum = /*#__PURE__*/function () {
  8045. function Frustum(p0, p1, p2, p3, p4, p5) {
  8046. 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()];
  8047. }
  8048. var _proto = Frustum.prototype;
  8049. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  8050. var planes = this.planes;
  8051. planes[0].copy(p0);
  8052. planes[1].copy(p1);
  8053. planes[2].copy(p2);
  8054. planes[3].copy(p3);
  8055. planes[4].copy(p4);
  8056. planes[5].copy(p5);
  8057. return this;
  8058. };
  8059. _proto.clone = function clone() {
  8060. return new this.constructor().copy(this);
  8061. };
  8062. _proto.copy = function copy(frustum) {
  8063. var planes = this.planes;
  8064. for (var i = 0; i < 6; i++) {
  8065. planes[i].copy(frustum.planes[i]);
  8066. }
  8067. return this;
  8068. };
  8069. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  8070. var planes = this.planes;
  8071. var me = m.elements;
  8072. var me0 = me[0],
  8073. me1 = me[1],
  8074. me2 = me[2],
  8075. me3 = me[3];
  8076. var me4 = me[4],
  8077. me5 = me[5],
  8078. me6 = me[6],
  8079. me7 = me[7];
  8080. var me8 = me[8],
  8081. me9 = me[9],
  8082. me10 = me[10],
  8083. me11 = me[11];
  8084. var me12 = me[12],
  8085. me13 = me[13],
  8086. me14 = me[14],
  8087. me15 = me[15];
  8088. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  8089. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  8090. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  8091. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  8092. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  8093. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  8094. return this;
  8095. };
  8096. _proto.intersectsObject = function intersectsObject(object) {
  8097. var geometry = object.geometry;
  8098. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  8099. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  8100. return this.intersectsSphere(_sphere$1);
  8101. };
  8102. _proto.intersectsSprite = function intersectsSprite(sprite) {
  8103. _sphere$1.center.set(0, 0, 0);
  8104. _sphere$1.radius = 0.7071067811865476;
  8105. _sphere$1.applyMatrix4(sprite.matrixWorld);
  8106. return this.intersectsSphere(_sphere$1);
  8107. };
  8108. _proto.intersectsSphere = function intersectsSphere(sphere) {
  8109. var planes = this.planes;
  8110. var center = sphere.center;
  8111. var negRadius = -sphere.radius;
  8112. for (var i = 0; i < 6; i++) {
  8113. var distance = planes[i].distanceToPoint(center);
  8114. if (distance < negRadius) {
  8115. return false;
  8116. }
  8117. }
  8118. return true;
  8119. };
  8120. _proto.intersectsBox = function intersectsBox(box) {
  8121. var planes = this.planes;
  8122. for (var i = 0; i < 6; i++) {
  8123. var plane = planes[i]; // corner at max distance
  8124. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8125. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8126. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8127. if (plane.distanceToPoint(_vector$5) < 0) {
  8128. return false;
  8129. }
  8130. }
  8131. return true;
  8132. };
  8133. _proto.containsPoint = function containsPoint(point) {
  8134. var planes = this.planes;
  8135. for (var i = 0; i < 6; i++) {
  8136. if (planes[i].distanceToPoint(point) < 0) {
  8137. return false;
  8138. }
  8139. }
  8140. return true;
  8141. };
  8142. return Frustum;
  8143. }();
  8144. function WebGLAnimation() {
  8145. var context = null;
  8146. var isAnimating = false;
  8147. var animationLoop = null;
  8148. var requestId = null;
  8149. function onAnimationFrame(time, frame) {
  8150. animationLoop(time, frame);
  8151. requestId = context.requestAnimationFrame(onAnimationFrame);
  8152. }
  8153. return {
  8154. start: function start() {
  8155. if (isAnimating === true) return;
  8156. if (animationLoop === null) return;
  8157. requestId = context.requestAnimationFrame(onAnimationFrame);
  8158. isAnimating = true;
  8159. },
  8160. stop: function stop() {
  8161. context.cancelAnimationFrame(requestId);
  8162. isAnimating = false;
  8163. },
  8164. setAnimationLoop: function setAnimationLoop(callback) {
  8165. animationLoop = callback;
  8166. },
  8167. setContext: function setContext(value) {
  8168. context = value;
  8169. }
  8170. };
  8171. }
  8172. function WebGLAttributes(gl, capabilities) {
  8173. var isWebGL2 = capabilities.isWebGL2;
  8174. var buffers = new WeakMap();
  8175. function createBuffer(attribute, bufferType) {
  8176. var array = attribute.array;
  8177. var usage = attribute.usage;
  8178. var buffer = gl.createBuffer();
  8179. gl.bindBuffer(bufferType, buffer);
  8180. gl.bufferData(bufferType, array, usage);
  8181. attribute.onUploadCallback();
  8182. var type = 5126;
  8183. if (array instanceof Float32Array) {
  8184. type = 5126;
  8185. } else if (array instanceof Float64Array) {
  8186. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8187. } else if (array instanceof Uint16Array) {
  8188. if (attribute.isFloat16BufferAttribute) {
  8189. if (isWebGL2) {
  8190. type = 5131;
  8191. } else {
  8192. console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
  8193. }
  8194. } else {
  8195. type = 5123;
  8196. }
  8197. } else if (array instanceof Int16Array) {
  8198. type = 5122;
  8199. } else if (array instanceof Uint32Array) {
  8200. type = 5125;
  8201. } else if (array instanceof Int32Array) {
  8202. type = 5124;
  8203. } else if (array instanceof Int8Array) {
  8204. type = 5120;
  8205. } else if (array instanceof Uint8Array) {
  8206. type = 5121;
  8207. }
  8208. return {
  8209. buffer: buffer,
  8210. type: type,
  8211. bytesPerElement: array.BYTES_PER_ELEMENT,
  8212. version: attribute.version
  8213. };
  8214. }
  8215. function updateBuffer(buffer, attribute, bufferType) {
  8216. var array = attribute.array;
  8217. var updateRange = attribute.updateRange;
  8218. gl.bindBuffer(bufferType, buffer);
  8219. if (updateRange.count === -1) {
  8220. // Not using update ranges
  8221. gl.bufferSubData(bufferType, 0, array);
  8222. } else {
  8223. if (isWebGL2) {
  8224. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8225. } else {
  8226. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8227. }
  8228. updateRange.count = -1; // reset range
  8229. }
  8230. } //
  8231. function get(attribute) {
  8232. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8233. return buffers.get(attribute);
  8234. }
  8235. function remove(attribute) {
  8236. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8237. var data = buffers.get(attribute);
  8238. if (data) {
  8239. gl.deleteBuffer(data.buffer);
  8240. buffers.delete(attribute);
  8241. }
  8242. }
  8243. function update(attribute, bufferType) {
  8244. if (attribute.isGLBufferAttribute) {
  8245. var cached = buffers.get(attribute);
  8246. if (!cached || cached.version < attribute.version) {
  8247. buffers.set(attribute, {
  8248. buffer: attribute.buffer,
  8249. type: attribute.type,
  8250. bytesPerElement: attribute.elementSize,
  8251. version: attribute.version
  8252. });
  8253. }
  8254. return;
  8255. }
  8256. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8257. var data = buffers.get(attribute);
  8258. if (data === undefined) {
  8259. buffers.set(attribute, createBuffer(attribute, bufferType));
  8260. } else if (data.version < attribute.version) {
  8261. updateBuffer(data.buffer, attribute, bufferType);
  8262. data.version = attribute.version;
  8263. }
  8264. }
  8265. return {
  8266. get: get,
  8267. remove: remove,
  8268. update: update
  8269. };
  8270. }
  8271. var PlaneBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8272. _inheritsLoose(PlaneBufferGeometry, _BufferGeometry);
  8273. function PlaneBufferGeometry(width, height, widthSegments, heightSegments) {
  8274. var _this;
  8275. if (width === void 0) {
  8276. width = 1;
  8277. }
  8278. if (height === void 0) {
  8279. height = 1;
  8280. }
  8281. if (widthSegments === void 0) {
  8282. widthSegments = 1;
  8283. }
  8284. if (heightSegments === void 0) {
  8285. heightSegments = 1;
  8286. }
  8287. _this = _BufferGeometry.call(this) || this;
  8288. _this.type = 'PlaneBufferGeometry';
  8289. _this.parameters = {
  8290. width: width,
  8291. height: height,
  8292. widthSegments: widthSegments,
  8293. heightSegments: heightSegments
  8294. };
  8295. var width_half = width / 2;
  8296. var height_half = height / 2;
  8297. var gridX = Math.floor(widthSegments);
  8298. var gridY = Math.floor(heightSegments);
  8299. var gridX1 = gridX + 1;
  8300. var gridY1 = gridY + 1;
  8301. var segment_width = width / gridX;
  8302. var segment_height = height / gridY; //
  8303. var indices = [];
  8304. var vertices = [];
  8305. var normals = [];
  8306. var uvs = [];
  8307. for (var iy = 0; iy < gridY1; iy++) {
  8308. var y = iy * segment_height - height_half;
  8309. for (var ix = 0; ix < gridX1; ix++) {
  8310. var x = ix * segment_width - width_half;
  8311. vertices.push(x, -y, 0);
  8312. normals.push(0, 0, 1);
  8313. uvs.push(ix / gridX);
  8314. uvs.push(1 - iy / gridY);
  8315. }
  8316. }
  8317. for (var _iy = 0; _iy < gridY; _iy++) {
  8318. for (var _ix = 0; _ix < gridX; _ix++) {
  8319. var a = _ix + gridX1 * _iy;
  8320. var b = _ix + gridX1 * (_iy + 1);
  8321. var c = _ix + 1 + gridX1 * (_iy + 1);
  8322. var d = _ix + 1 + gridX1 * _iy;
  8323. indices.push(a, b, d);
  8324. indices.push(b, c, d);
  8325. }
  8326. }
  8327. _this.setIndex(indices);
  8328. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8329. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8330. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8331. return _this;
  8332. }
  8333. return PlaneBufferGeometry;
  8334. }(BufferGeometry);
  8335. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8336. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8337. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8338. 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";
  8339. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8340. var begin_vertex = "vec3 transformed = vec3( position );";
  8341. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8342. 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";
  8343. 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";
  8344. 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";
  8345. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8346. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8347. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8348. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8349. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8350. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8351. 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";
  8352. 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}";
  8353. 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";
  8354. 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";
  8355. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8356. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8357. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8358. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8359. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8360. 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}";
  8361. 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";
  8362. 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";
  8363. 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";
  8364. 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";
  8365. 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";
  8366. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8367. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8368. 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";
  8369. 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";
  8370. 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}";
  8371. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8372. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8373. 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";
  8374. 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";
  8375. 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";
  8376. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8377. 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)";
  8378. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8379. 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)";
  8380. 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";
  8381. 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}";
  8382. 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";
  8383. 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";
  8384. 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";
  8385. 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";
  8386. 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";
  8387. 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";
  8388. 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";
  8389. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8390. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8391. 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";
  8392. 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";
  8393. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8394. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8395. 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";
  8396. 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";
  8397. 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";
  8398. 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;";
  8399. 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";
  8400. 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";
  8401. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8402. 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";
  8403. 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";
  8404. 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}";
  8405. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8406. 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;";
  8407. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8408. 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";
  8409. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8410. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8411. 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";
  8412. 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";
  8413. 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";
  8414. 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}";
  8415. 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";
  8416. 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";
  8417. 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";
  8418. 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";
  8419. 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";
  8420. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8421. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8422. 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; }";
  8423. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8424. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8425. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8426. 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";
  8427. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8428. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8429. 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";
  8430. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8431. 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";
  8432. 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}";
  8433. 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}";
  8434. 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}";
  8435. 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}";
  8436. 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}";
  8437. 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}";
  8438. 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}";
  8439. 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}";
  8440. 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}";
  8441. 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}";
  8442. 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}";
  8443. 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}";
  8444. 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}";
  8445. 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}";
  8446. 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}";
  8447. 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}";
  8448. 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}";
  8449. 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}";
  8450. 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}";
  8451. 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}";
  8452. 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}";
  8453. 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}";
  8454. 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}";
  8455. 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}";
  8456. 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}";
  8457. 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}";
  8458. 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}";
  8459. 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}";
  8460. 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}";
  8461. 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}";
  8462. 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}";
  8463. 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}";
  8464. var ShaderChunk = {
  8465. alphamap_fragment: alphamap_fragment,
  8466. alphamap_pars_fragment: alphamap_pars_fragment,
  8467. alphatest_fragment: alphatest_fragment,
  8468. aomap_fragment: aomap_fragment,
  8469. aomap_pars_fragment: aomap_pars_fragment,
  8470. begin_vertex: begin_vertex,
  8471. beginnormal_vertex: beginnormal_vertex,
  8472. bsdfs: bsdfs,
  8473. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8474. clipping_planes_fragment: clipping_planes_fragment,
  8475. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8476. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8477. clipping_planes_vertex: clipping_planes_vertex,
  8478. color_fragment: color_fragment,
  8479. color_pars_fragment: color_pars_fragment,
  8480. color_pars_vertex: color_pars_vertex,
  8481. color_vertex: color_vertex,
  8482. common: common,
  8483. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8484. defaultnormal_vertex: defaultnormal_vertex,
  8485. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8486. displacementmap_vertex: displacementmap_vertex,
  8487. emissivemap_fragment: emissivemap_fragment,
  8488. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8489. encodings_fragment: encodings_fragment,
  8490. encodings_pars_fragment: encodings_pars_fragment,
  8491. envmap_fragment: envmap_fragment,
  8492. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8493. envmap_pars_fragment: envmap_pars_fragment,
  8494. envmap_pars_vertex: envmap_pars_vertex,
  8495. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8496. envmap_vertex: envmap_vertex,
  8497. fog_vertex: fog_vertex,
  8498. fog_pars_vertex: fog_pars_vertex,
  8499. fog_fragment: fog_fragment,
  8500. fog_pars_fragment: fog_pars_fragment,
  8501. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8502. lightmap_fragment: lightmap_fragment,
  8503. lightmap_pars_fragment: lightmap_pars_fragment,
  8504. lights_lambert_vertex: lights_lambert_vertex,
  8505. lights_pars_begin: lights_pars_begin,
  8506. lights_toon_fragment: lights_toon_fragment,
  8507. lights_toon_pars_fragment: lights_toon_pars_fragment,
  8508. lights_phong_fragment: lights_phong_fragment,
  8509. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8510. lights_physical_fragment: lights_physical_fragment,
  8511. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8512. lights_fragment_begin: lights_fragment_begin,
  8513. lights_fragment_maps: lights_fragment_maps,
  8514. lights_fragment_end: lights_fragment_end,
  8515. logdepthbuf_fragment: logdepthbuf_fragment,
  8516. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8517. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8518. logdepthbuf_vertex: logdepthbuf_vertex,
  8519. map_fragment: map_fragment,
  8520. map_pars_fragment: map_pars_fragment,
  8521. map_particle_fragment: map_particle_fragment,
  8522. map_particle_pars_fragment: map_particle_pars_fragment,
  8523. metalnessmap_fragment: metalnessmap_fragment,
  8524. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  8525. morphnormal_vertex: morphnormal_vertex,
  8526. morphtarget_pars_vertex: morphtarget_pars_vertex,
  8527. morphtarget_vertex: morphtarget_vertex,
  8528. normal_fragment_begin: normal_fragment_begin,
  8529. normal_fragment_maps: normal_fragment_maps,
  8530. normalmap_pars_fragment: normalmap_pars_fragment,
  8531. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  8532. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  8533. clearcoat_pars_fragment: clearcoat_pars_fragment,
  8534. packing: packing,
  8535. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  8536. project_vertex: project_vertex,
  8537. dithering_fragment: dithering_fragment,
  8538. dithering_pars_fragment: dithering_pars_fragment,
  8539. roughnessmap_fragment: roughnessmap_fragment,
  8540. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  8541. shadowmap_pars_fragment: shadowmap_pars_fragment,
  8542. shadowmap_pars_vertex: shadowmap_pars_vertex,
  8543. shadowmap_vertex: shadowmap_vertex,
  8544. shadowmask_pars_fragment: shadowmask_pars_fragment,
  8545. skinbase_vertex: skinbase_vertex,
  8546. skinning_pars_vertex: skinning_pars_vertex,
  8547. skinning_vertex: skinning_vertex,
  8548. skinnormal_vertex: skinnormal_vertex,
  8549. specularmap_fragment: specularmap_fragment,
  8550. specularmap_pars_fragment: specularmap_pars_fragment,
  8551. tonemapping_fragment: tonemapping_fragment,
  8552. tonemapping_pars_fragment: tonemapping_pars_fragment,
  8553. transmissionmap_fragment: transmissionmap_fragment,
  8554. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  8555. uv_pars_fragment: uv_pars_fragment,
  8556. uv_pars_vertex: uv_pars_vertex,
  8557. uv_vertex: uv_vertex,
  8558. uv2_pars_fragment: uv2_pars_fragment,
  8559. uv2_pars_vertex: uv2_pars_vertex,
  8560. uv2_vertex: uv2_vertex,
  8561. worldpos_vertex: worldpos_vertex,
  8562. background_frag: background_frag,
  8563. background_vert: background_vert,
  8564. cube_frag: cube_frag,
  8565. cube_vert: cube_vert,
  8566. depth_frag: depth_frag,
  8567. depth_vert: depth_vert,
  8568. distanceRGBA_frag: distanceRGBA_frag,
  8569. distanceRGBA_vert: distanceRGBA_vert,
  8570. equirect_frag: equirect_frag,
  8571. equirect_vert: equirect_vert,
  8572. linedashed_frag: linedashed_frag,
  8573. linedashed_vert: linedashed_vert,
  8574. meshbasic_frag: meshbasic_frag,
  8575. meshbasic_vert: meshbasic_vert,
  8576. meshlambert_frag: meshlambert_frag,
  8577. meshlambert_vert: meshlambert_vert,
  8578. meshmatcap_frag: meshmatcap_frag,
  8579. meshmatcap_vert: meshmatcap_vert,
  8580. meshtoon_frag: meshtoon_frag,
  8581. meshtoon_vert: meshtoon_vert,
  8582. meshphong_frag: meshphong_frag,
  8583. meshphong_vert: meshphong_vert,
  8584. meshphysical_frag: meshphysical_frag,
  8585. meshphysical_vert: meshphysical_vert,
  8586. normal_frag: normal_frag,
  8587. normal_vert: normal_vert,
  8588. points_frag: points_frag,
  8589. points_vert: points_vert,
  8590. shadow_frag: shadow_frag,
  8591. shadow_vert: shadow_vert,
  8592. sprite_frag: sprite_frag,
  8593. sprite_vert: sprite_vert
  8594. };
  8595. /**
  8596. * Uniforms library for shared webgl shaders
  8597. */
  8598. var UniformsLib = {
  8599. common: {
  8600. diffuse: {
  8601. value: new Color(0xeeeeee)
  8602. },
  8603. opacity: {
  8604. value: 1.0
  8605. },
  8606. map: {
  8607. value: null
  8608. },
  8609. uvTransform: {
  8610. value: new Matrix3()
  8611. },
  8612. uv2Transform: {
  8613. value: new Matrix3()
  8614. },
  8615. alphaMap: {
  8616. value: null
  8617. }
  8618. },
  8619. specularmap: {
  8620. specularMap: {
  8621. value: null
  8622. }
  8623. },
  8624. envmap: {
  8625. envMap: {
  8626. value: null
  8627. },
  8628. flipEnvMap: {
  8629. value: -1
  8630. },
  8631. reflectivity: {
  8632. value: 1.0
  8633. },
  8634. refractionRatio: {
  8635. value: 0.98
  8636. },
  8637. maxMipLevel: {
  8638. value: 0
  8639. }
  8640. },
  8641. aomap: {
  8642. aoMap: {
  8643. value: null
  8644. },
  8645. aoMapIntensity: {
  8646. value: 1
  8647. }
  8648. },
  8649. lightmap: {
  8650. lightMap: {
  8651. value: null
  8652. },
  8653. lightMapIntensity: {
  8654. value: 1
  8655. }
  8656. },
  8657. emissivemap: {
  8658. emissiveMap: {
  8659. value: null
  8660. }
  8661. },
  8662. bumpmap: {
  8663. bumpMap: {
  8664. value: null
  8665. },
  8666. bumpScale: {
  8667. value: 1
  8668. }
  8669. },
  8670. normalmap: {
  8671. normalMap: {
  8672. value: null
  8673. },
  8674. normalScale: {
  8675. value: new Vector2(1, 1)
  8676. }
  8677. },
  8678. displacementmap: {
  8679. displacementMap: {
  8680. value: null
  8681. },
  8682. displacementScale: {
  8683. value: 1
  8684. },
  8685. displacementBias: {
  8686. value: 0
  8687. }
  8688. },
  8689. roughnessmap: {
  8690. roughnessMap: {
  8691. value: null
  8692. }
  8693. },
  8694. metalnessmap: {
  8695. metalnessMap: {
  8696. value: null
  8697. }
  8698. },
  8699. gradientmap: {
  8700. gradientMap: {
  8701. value: null
  8702. }
  8703. },
  8704. fog: {
  8705. fogDensity: {
  8706. value: 0.00025
  8707. },
  8708. fogNear: {
  8709. value: 1
  8710. },
  8711. fogFar: {
  8712. value: 2000
  8713. },
  8714. fogColor: {
  8715. value: new Color(0xffffff)
  8716. }
  8717. },
  8718. lights: {
  8719. ambientLightColor: {
  8720. value: []
  8721. },
  8722. lightProbe: {
  8723. value: []
  8724. },
  8725. directionalLights: {
  8726. value: [],
  8727. properties: {
  8728. direction: {},
  8729. color: {}
  8730. }
  8731. },
  8732. directionalLightShadows: {
  8733. value: [],
  8734. properties: {
  8735. shadowBias: {},
  8736. shadowNormalBias: {},
  8737. shadowRadius: {},
  8738. shadowMapSize: {}
  8739. }
  8740. },
  8741. directionalShadowMap: {
  8742. value: []
  8743. },
  8744. directionalShadowMatrix: {
  8745. value: []
  8746. },
  8747. spotLights: {
  8748. value: [],
  8749. properties: {
  8750. color: {},
  8751. position: {},
  8752. direction: {},
  8753. distance: {},
  8754. coneCos: {},
  8755. penumbraCos: {},
  8756. decay: {}
  8757. }
  8758. },
  8759. spotLightShadows: {
  8760. value: [],
  8761. properties: {
  8762. shadowBias: {},
  8763. shadowNormalBias: {},
  8764. shadowRadius: {},
  8765. shadowMapSize: {}
  8766. }
  8767. },
  8768. spotShadowMap: {
  8769. value: []
  8770. },
  8771. spotShadowMatrix: {
  8772. value: []
  8773. },
  8774. pointLights: {
  8775. value: [],
  8776. properties: {
  8777. color: {},
  8778. position: {},
  8779. decay: {},
  8780. distance: {}
  8781. }
  8782. },
  8783. pointLightShadows: {
  8784. value: [],
  8785. properties: {
  8786. shadowBias: {},
  8787. shadowNormalBias: {},
  8788. shadowRadius: {},
  8789. shadowMapSize: {},
  8790. shadowCameraNear: {},
  8791. shadowCameraFar: {}
  8792. }
  8793. },
  8794. pointShadowMap: {
  8795. value: []
  8796. },
  8797. pointShadowMatrix: {
  8798. value: []
  8799. },
  8800. hemisphereLights: {
  8801. value: [],
  8802. properties: {
  8803. direction: {},
  8804. skyColor: {},
  8805. groundColor: {}
  8806. }
  8807. },
  8808. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8809. rectAreaLights: {
  8810. value: [],
  8811. properties: {
  8812. color: {},
  8813. position: {},
  8814. width: {},
  8815. height: {}
  8816. }
  8817. },
  8818. ltc_1: {
  8819. value: null
  8820. },
  8821. ltc_2: {
  8822. value: null
  8823. }
  8824. },
  8825. points: {
  8826. diffuse: {
  8827. value: new Color(0xeeeeee)
  8828. },
  8829. opacity: {
  8830. value: 1.0
  8831. },
  8832. size: {
  8833. value: 1.0
  8834. },
  8835. scale: {
  8836. value: 1.0
  8837. },
  8838. map: {
  8839. value: null
  8840. },
  8841. alphaMap: {
  8842. value: null
  8843. },
  8844. uvTransform: {
  8845. value: new Matrix3()
  8846. }
  8847. },
  8848. sprite: {
  8849. diffuse: {
  8850. value: new Color(0xeeeeee)
  8851. },
  8852. opacity: {
  8853. value: 1.0
  8854. },
  8855. center: {
  8856. value: new Vector2(0.5, 0.5)
  8857. },
  8858. rotation: {
  8859. value: 0.0
  8860. },
  8861. map: {
  8862. value: null
  8863. },
  8864. alphaMap: {
  8865. value: null
  8866. },
  8867. uvTransform: {
  8868. value: new Matrix3()
  8869. }
  8870. }
  8871. };
  8872. var ShaderLib = {
  8873. basic: {
  8874. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  8875. vertexShader: ShaderChunk.meshbasic_vert,
  8876. fragmentShader: ShaderChunk.meshbasic_frag
  8877. },
  8878. lambert: {
  8879. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  8880. emissive: {
  8881. value: new Color(0x000000)
  8882. }
  8883. }]),
  8884. vertexShader: ShaderChunk.meshlambert_vert,
  8885. fragmentShader: ShaderChunk.meshlambert_frag
  8886. },
  8887. phong: {
  8888. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  8889. emissive: {
  8890. value: new Color(0x000000)
  8891. },
  8892. specular: {
  8893. value: new Color(0x111111)
  8894. },
  8895. shininess: {
  8896. value: 30
  8897. }
  8898. }]),
  8899. vertexShader: ShaderChunk.meshphong_vert,
  8900. fragmentShader: ShaderChunk.meshphong_frag
  8901. },
  8902. standard: {
  8903. 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, {
  8904. emissive: {
  8905. value: new Color(0x000000)
  8906. },
  8907. roughness: {
  8908. value: 1.0
  8909. },
  8910. metalness: {
  8911. value: 0.0
  8912. },
  8913. envMapIntensity: {
  8914. value: 1
  8915. } // temporary
  8916. }]),
  8917. vertexShader: ShaderChunk.meshphysical_vert,
  8918. fragmentShader: ShaderChunk.meshphysical_frag
  8919. },
  8920. toon: {
  8921. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  8922. emissive: {
  8923. value: new Color(0x000000)
  8924. }
  8925. }]),
  8926. vertexShader: ShaderChunk.meshtoon_vert,
  8927. fragmentShader: ShaderChunk.meshtoon_frag
  8928. },
  8929. matcap: {
  8930. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  8931. matcap: {
  8932. value: null
  8933. }
  8934. }]),
  8935. vertexShader: ShaderChunk.meshmatcap_vert,
  8936. fragmentShader: ShaderChunk.meshmatcap_frag
  8937. },
  8938. points: {
  8939. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  8940. vertexShader: ShaderChunk.points_vert,
  8941. fragmentShader: ShaderChunk.points_frag
  8942. },
  8943. dashed: {
  8944. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  8945. scale: {
  8946. value: 1
  8947. },
  8948. dashSize: {
  8949. value: 1
  8950. },
  8951. totalSize: {
  8952. value: 2
  8953. }
  8954. }]),
  8955. vertexShader: ShaderChunk.linedashed_vert,
  8956. fragmentShader: ShaderChunk.linedashed_frag
  8957. },
  8958. depth: {
  8959. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  8960. vertexShader: ShaderChunk.depth_vert,
  8961. fragmentShader: ShaderChunk.depth_frag
  8962. },
  8963. normal: {
  8964. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  8965. opacity: {
  8966. value: 1.0
  8967. }
  8968. }]),
  8969. vertexShader: ShaderChunk.normal_vert,
  8970. fragmentShader: ShaderChunk.normal_frag
  8971. },
  8972. sprite: {
  8973. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  8974. vertexShader: ShaderChunk.sprite_vert,
  8975. fragmentShader: ShaderChunk.sprite_frag
  8976. },
  8977. background: {
  8978. uniforms: {
  8979. uvTransform: {
  8980. value: new Matrix3()
  8981. },
  8982. t2D: {
  8983. value: null
  8984. }
  8985. },
  8986. vertexShader: ShaderChunk.background_vert,
  8987. fragmentShader: ShaderChunk.background_frag
  8988. },
  8989. /* -------------------------------------------------------------------------
  8990. // Cube map shader
  8991. ------------------------------------------------------------------------- */
  8992. cube: {
  8993. uniforms: mergeUniforms([UniformsLib.envmap, {
  8994. opacity: {
  8995. value: 1.0
  8996. }
  8997. }]),
  8998. vertexShader: ShaderChunk.cube_vert,
  8999. fragmentShader: ShaderChunk.cube_frag
  9000. },
  9001. equirect: {
  9002. uniforms: {
  9003. tEquirect: {
  9004. value: null
  9005. }
  9006. },
  9007. vertexShader: ShaderChunk.equirect_vert,
  9008. fragmentShader: ShaderChunk.equirect_frag
  9009. },
  9010. distanceRGBA: {
  9011. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  9012. referencePosition: {
  9013. value: new Vector3()
  9014. },
  9015. nearDistance: {
  9016. value: 1
  9017. },
  9018. farDistance: {
  9019. value: 1000
  9020. }
  9021. }]),
  9022. vertexShader: ShaderChunk.distanceRGBA_vert,
  9023. fragmentShader: ShaderChunk.distanceRGBA_frag
  9024. },
  9025. shadow: {
  9026. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  9027. color: {
  9028. value: new Color(0x00000)
  9029. },
  9030. opacity: {
  9031. value: 1.0
  9032. }
  9033. }]),
  9034. vertexShader: ShaderChunk.shadow_vert,
  9035. fragmentShader: ShaderChunk.shadow_frag
  9036. }
  9037. };
  9038. ShaderLib.physical = {
  9039. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  9040. clearcoat: {
  9041. value: 0
  9042. },
  9043. clearcoatMap: {
  9044. value: null
  9045. },
  9046. clearcoatRoughness: {
  9047. value: 0
  9048. },
  9049. clearcoatRoughnessMap: {
  9050. value: null
  9051. },
  9052. clearcoatNormalScale: {
  9053. value: new Vector2(1, 1)
  9054. },
  9055. clearcoatNormalMap: {
  9056. value: null
  9057. },
  9058. sheen: {
  9059. value: new Color(0x000000)
  9060. },
  9061. transmission: {
  9062. value: 0
  9063. },
  9064. transmissionMap: {
  9065. value: null
  9066. }
  9067. }]),
  9068. vertexShader: ShaderChunk.meshphysical_vert,
  9069. fragmentShader: ShaderChunk.meshphysical_frag
  9070. };
  9071. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  9072. var clearColor = new Color(0x000000);
  9073. var clearAlpha = 0;
  9074. var planeMesh;
  9075. var boxMesh;
  9076. var currentBackground = null;
  9077. var currentBackgroundVersion = 0;
  9078. var currentTonemapping = null;
  9079. function render(renderList, scene, camera, forceClear) {
  9080. var background = scene.isScene === true ? scene.background : null;
  9081. if (background && background.isTexture) {
  9082. background = cubemaps.get(background);
  9083. } // Ignore background in AR
  9084. // TODO: Reconsider this.
  9085. var xr = renderer.xr;
  9086. var session = xr.getSession && xr.getSession();
  9087. if (session && session.environmentBlendMode === 'additive') {
  9088. background = null;
  9089. }
  9090. if (background === null) {
  9091. setClear(clearColor, clearAlpha);
  9092. } else if (background && background.isColor) {
  9093. setClear(background, 1);
  9094. forceClear = true;
  9095. }
  9096. if (renderer.autoClear || forceClear) {
  9097. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  9098. }
  9099. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  9100. if (boxMesh === undefined) {
  9101. boxMesh = new Mesh(new BoxBufferGeometry(1, 1, 1), new ShaderMaterial({
  9102. name: 'BackgroundCubeMaterial',
  9103. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  9104. vertexShader: ShaderLib.cube.vertexShader,
  9105. fragmentShader: ShaderLib.cube.fragmentShader,
  9106. side: BackSide,
  9107. depthTest: false,
  9108. depthWrite: false,
  9109. fog: false
  9110. }));
  9111. boxMesh.geometry.deleteAttribute('normal');
  9112. boxMesh.geometry.deleteAttribute('uv');
  9113. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  9114. this.matrixWorld.copyPosition(camera.matrixWorld);
  9115. }; // enable code injection for non-built-in material
  9116. Object.defineProperty(boxMesh.material, 'envMap', {
  9117. get: function get() {
  9118. return this.uniforms.envMap.value;
  9119. }
  9120. });
  9121. objects.update(boxMesh);
  9122. }
  9123. if (background.isWebGLCubeRenderTarget) {
  9124. // TODO Deprecate
  9125. background = background.texture;
  9126. }
  9127. boxMesh.material.uniforms.envMap.value = background;
  9128. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  9129. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9130. boxMesh.material.needsUpdate = true;
  9131. currentBackground = background;
  9132. currentBackgroundVersion = background.version;
  9133. currentTonemapping = renderer.toneMapping;
  9134. } // push to the pre-sorted opaque render list
  9135. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  9136. } else if (background && background.isTexture) {
  9137. if (planeMesh === undefined) {
  9138. planeMesh = new Mesh(new PlaneBufferGeometry(2, 2), new ShaderMaterial({
  9139. name: 'BackgroundMaterial',
  9140. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  9141. vertexShader: ShaderLib.background.vertexShader,
  9142. fragmentShader: ShaderLib.background.fragmentShader,
  9143. side: FrontSide,
  9144. depthTest: false,
  9145. depthWrite: false,
  9146. fog: false
  9147. }));
  9148. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9149. Object.defineProperty(planeMesh.material, 'map', {
  9150. get: function get() {
  9151. return this.uniforms.t2D.value;
  9152. }
  9153. });
  9154. objects.update(planeMesh);
  9155. }
  9156. planeMesh.material.uniforms.t2D.value = background;
  9157. if (background.matrixAutoUpdate === true) {
  9158. background.updateMatrix();
  9159. }
  9160. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9161. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9162. planeMesh.material.needsUpdate = true;
  9163. currentBackground = background;
  9164. currentBackgroundVersion = background.version;
  9165. currentTonemapping = renderer.toneMapping;
  9166. } // push to the pre-sorted opaque render list
  9167. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9168. }
  9169. }
  9170. function setClear(color, alpha) {
  9171. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9172. }
  9173. return {
  9174. getClearColor: function getClearColor() {
  9175. return clearColor;
  9176. },
  9177. setClearColor: function setClearColor(color, alpha) {
  9178. if (alpha === void 0) {
  9179. alpha = 1;
  9180. }
  9181. clearColor.set(color);
  9182. clearAlpha = alpha;
  9183. setClear(clearColor, clearAlpha);
  9184. },
  9185. getClearAlpha: function getClearAlpha() {
  9186. return clearAlpha;
  9187. },
  9188. setClearAlpha: function setClearAlpha(alpha) {
  9189. clearAlpha = alpha;
  9190. setClear(clearColor, clearAlpha);
  9191. },
  9192. render: render
  9193. };
  9194. }
  9195. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9196. var maxVertexAttributes = gl.getParameter(34921);
  9197. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9198. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9199. var bindingStates = {};
  9200. var defaultState = createBindingState(null);
  9201. var currentState = defaultState;
  9202. function setup(object, material, program, geometry, index) {
  9203. var updateBuffers = false;
  9204. if (vaoAvailable) {
  9205. var state = getBindingState(geometry, program, material);
  9206. if (currentState !== state) {
  9207. currentState = state;
  9208. bindVertexArrayObject(currentState.object);
  9209. }
  9210. updateBuffers = needsUpdate(geometry, index);
  9211. if (updateBuffers) saveCache(geometry, index);
  9212. } else {
  9213. var wireframe = material.wireframe === true;
  9214. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9215. currentState.geometry = geometry.id;
  9216. currentState.program = program.id;
  9217. currentState.wireframe = wireframe;
  9218. updateBuffers = true;
  9219. }
  9220. }
  9221. if (object.isInstancedMesh === true) {
  9222. updateBuffers = true;
  9223. }
  9224. if (index !== null) {
  9225. attributes.update(index, 34963);
  9226. }
  9227. if (updateBuffers) {
  9228. setupVertexAttributes(object, material, program, geometry);
  9229. if (index !== null) {
  9230. gl.bindBuffer(34963, attributes.get(index).buffer);
  9231. }
  9232. }
  9233. }
  9234. function createVertexArrayObject() {
  9235. if (capabilities.isWebGL2) return gl.createVertexArray();
  9236. return extension.createVertexArrayOES();
  9237. }
  9238. function bindVertexArrayObject(vao) {
  9239. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9240. return extension.bindVertexArrayOES(vao);
  9241. }
  9242. function deleteVertexArrayObject(vao) {
  9243. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9244. return extension.deleteVertexArrayOES(vao);
  9245. }
  9246. function getBindingState(geometry, program, material) {
  9247. var wireframe = material.wireframe === true;
  9248. var programMap = bindingStates[geometry.id];
  9249. if (programMap === undefined) {
  9250. programMap = {};
  9251. bindingStates[geometry.id] = programMap;
  9252. }
  9253. var stateMap = programMap[program.id];
  9254. if (stateMap === undefined) {
  9255. stateMap = {};
  9256. programMap[program.id] = stateMap;
  9257. }
  9258. var state = stateMap[wireframe];
  9259. if (state === undefined) {
  9260. state = createBindingState(createVertexArrayObject());
  9261. stateMap[wireframe] = state;
  9262. }
  9263. return state;
  9264. }
  9265. function createBindingState(vao) {
  9266. var newAttributes = [];
  9267. var enabledAttributes = [];
  9268. var attributeDivisors = [];
  9269. for (var i = 0; i < maxVertexAttributes; i++) {
  9270. newAttributes[i] = 0;
  9271. enabledAttributes[i] = 0;
  9272. attributeDivisors[i] = 0;
  9273. }
  9274. return {
  9275. // for backward compatibility on non-VAO support browser
  9276. geometry: null,
  9277. program: null,
  9278. wireframe: false,
  9279. newAttributes: newAttributes,
  9280. enabledAttributes: enabledAttributes,
  9281. attributeDivisors: attributeDivisors,
  9282. object: vao,
  9283. attributes: {},
  9284. index: null
  9285. };
  9286. }
  9287. function needsUpdate(geometry, index) {
  9288. var cachedAttributes = currentState.attributes;
  9289. var geometryAttributes = geometry.attributes;
  9290. var attributesNum = 0;
  9291. for (var key in geometryAttributes) {
  9292. var cachedAttribute = cachedAttributes[key];
  9293. var geometryAttribute = geometryAttributes[key];
  9294. if (cachedAttribute === undefined) return true;
  9295. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9296. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9297. attributesNum++;
  9298. }
  9299. if (currentState.attributesNum !== attributesNum) return true;
  9300. if (currentState.index !== index) return true;
  9301. return false;
  9302. }
  9303. function saveCache(geometry, index) {
  9304. var cache = {};
  9305. var attributes = geometry.attributes;
  9306. var attributesNum = 0;
  9307. for (var key in attributes) {
  9308. var attribute = attributes[key];
  9309. var data = {};
  9310. data.attribute = attribute;
  9311. if (attribute.data) {
  9312. data.data = attribute.data;
  9313. }
  9314. cache[key] = data;
  9315. attributesNum++;
  9316. }
  9317. currentState.attributes = cache;
  9318. currentState.attributesNum = attributesNum;
  9319. currentState.index = index;
  9320. }
  9321. function initAttributes() {
  9322. var newAttributes = currentState.newAttributes;
  9323. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9324. newAttributes[i] = 0;
  9325. }
  9326. }
  9327. function enableAttribute(attribute) {
  9328. enableAttributeAndDivisor(attribute, 0);
  9329. }
  9330. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9331. var newAttributes = currentState.newAttributes;
  9332. var enabledAttributes = currentState.enabledAttributes;
  9333. var attributeDivisors = currentState.attributeDivisors;
  9334. newAttributes[attribute] = 1;
  9335. if (enabledAttributes[attribute] === 0) {
  9336. gl.enableVertexAttribArray(attribute);
  9337. enabledAttributes[attribute] = 1;
  9338. }
  9339. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9340. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9341. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9342. attributeDivisors[attribute] = meshPerAttribute;
  9343. }
  9344. }
  9345. function disableUnusedAttributes() {
  9346. var newAttributes = currentState.newAttributes;
  9347. var enabledAttributes = currentState.enabledAttributes;
  9348. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9349. if (enabledAttributes[i] !== newAttributes[i]) {
  9350. gl.disableVertexAttribArray(i);
  9351. enabledAttributes[i] = 0;
  9352. }
  9353. }
  9354. }
  9355. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9356. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9357. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9358. } else {
  9359. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9360. }
  9361. }
  9362. function setupVertexAttributes(object, material, program, geometry) {
  9363. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9364. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9365. }
  9366. initAttributes();
  9367. var geometryAttributes = geometry.attributes;
  9368. var programAttributes = program.getAttributes();
  9369. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9370. for (var name in programAttributes) {
  9371. var programAttribute = programAttributes[name];
  9372. if (programAttribute >= 0) {
  9373. var geometryAttribute = geometryAttributes[name];
  9374. if (geometryAttribute !== undefined) {
  9375. var normalized = geometryAttribute.normalized;
  9376. var size = geometryAttribute.itemSize;
  9377. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9378. if (attribute === undefined) continue;
  9379. var buffer = attribute.buffer;
  9380. var type = attribute.type;
  9381. var bytesPerElement = attribute.bytesPerElement;
  9382. if (geometryAttribute.isInterleavedBufferAttribute) {
  9383. var data = geometryAttribute.data;
  9384. var stride = data.stride;
  9385. var offset = geometryAttribute.offset;
  9386. if (data && data.isInstancedInterleavedBuffer) {
  9387. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9388. if (geometry._maxInstanceCount === undefined) {
  9389. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9390. }
  9391. } else {
  9392. enableAttribute(programAttribute);
  9393. }
  9394. gl.bindBuffer(34962, buffer);
  9395. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9396. } else {
  9397. if (geometryAttribute.isInstancedBufferAttribute) {
  9398. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9399. if (geometry._maxInstanceCount === undefined) {
  9400. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9401. }
  9402. } else {
  9403. enableAttribute(programAttribute);
  9404. }
  9405. gl.bindBuffer(34962, buffer);
  9406. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9407. }
  9408. } else if (name === 'instanceMatrix') {
  9409. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9410. if (_attribute === undefined) continue;
  9411. var _buffer = _attribute.buffer;
  9412. var _type = _attribute.type;
  9413. enableAttributeAndDivisor(programAttribute + 0, 1);
  9414. enableAttributeAndDivisor(programAttribute + 1, 1);
  9415. enableAttributeAndDivisor(programAttribute + 2, 1);
  9416. enableAttributeAndDivisor(programAttribute + 3, 1);
  9417. gl.bindBuffer(34962, _buffer);
  9418. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9419. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9420. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9421. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9422. } else if (name === 'instanceColor') {
  9423. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9424. if (_attribute2 === undefined) continue;
  9425. var _buffer2 = _attribute2.buffer;
  9426. var _type2 = _attribute2.type;
  9427. enableAttributeAndDivisor(programAttribute, 1);
  9428. gl.bindBuffer(34962, _buffer2);
  9429. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9430. } else if (materialDefaultAttributeValues !== undefined) {
  9431. var value = materialDefaultAttributeValues[name];
  9432. if (value !== undefined) {
  9433. switch (value.length) {
  9434. case 2:
  9435. gl.vertexAttrib2fv(programAttribute, value);
  9436. break;
  9437. case 3:
  9438. gl.vertexAttrib3fv(programAttribute, value);
  9439. break;
  9440. case 4:
  9441. gl.vertexAttrib4fv(programAttribute, value);
  9442. break;
  9443. default:
  9444. gl.vertexAttrib1fv(programAttribute, value);
  9445. }
  9446. }
  9447. }
  9448. }
  9449. }
  9450. disableUnusedAttributes();
  9451. }
  9452. function dispose() {
  9453. reset();
  9454. for (var geometryId in bindingStates) {
  9455. var programMap = bindingStates[geometryId];
  9456. for (var programId in programMap) {
  9457. var stateMap = programMap[programId];
  9458. for (var wireframe in stateMap) {
  9459. deleteVertexArrayObject(stateMap[wireframe].object);
  9460. delete stateMap[wireframe];
  9461. }
  9462. delete programMap[programId];
  9463. }
  9464. delete bindingStates[geometryId];
  9465. }
  9466. }
  9467. function releaseStatesOfGeometry(geometry) {
  9468. if (bindingStates[geometry.id] === undefined) return;
  9469. var programMap = bindingStates[geometry.id];
  9470. for (var programId in programMap) {
  9471. var stateMap = programMap[programId];
  9472. for (var wireframe in stateMap) {
  9473. deleteVertexArrayObject(stateMap[wireframe].object);
  9474. delete stateMap[wireframe];
  9475. }
  9476. delete programMap[programId];
  9477. }
  9478. delete bindingStates[geometry.id];
  9479. }
  9480. function releaseStatesOfProgram(program) {
  9481. for (var geometryId in bindingStates) {
  9482. var programMap = bindingStates[geometryId];
  9483. if (programMap[program.id] === undefined) continue;
  9484. var stateMap = programMap[program.id];
  9485. for (var wireframe in stateMap) {
  9486. deleteVertexArrayObject(stateMap[wireframe].object);
  9487. delete stateMap[wireframe];
  9488. }
  9489. delete programMap[program.id];
  9490. }
  9491. }
  9492. function reset() {
  9493. resetDefaultState();
  9494. if (currentState === defaultState) return;
  9495. currentState = defaultState;
  9496. bindVertexArrayObject(currentState.object);
  9497. } // for backward-compatilibity
  9498. function resetDefaultState() {
  9499. defaultState.geometry = null;
  9500. defaultState.program = null;
  9501. defaultState.wireframe = false;
  9502. }
  9503. return {
  9504. setup: setup,
  9505. reset: reset,
  9506. resetDefaultState: resetDefaultState,
  9507. dispose: dispose,
  9508. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9509. releaseStatesOfProgram: releaseStatesOfProgram,
  9510. initAttributes: initAttributes,
  9511. enableAttribute: enableAttribute,
  9512. disableUnusedAttributes: disableUnusedAttributes
  9513. };
  9514. }
  9515. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  9516. var isWebGL2 = capabilities.isWebGL2;
  9517. var mode;
  9518. function setMode(value) {
  9519. mode = value;
  9520. }
  9521. function render(start, count) {
  9522. gl.drawArrays(mode, start, count);
  9523. info.update(count, mode, 1);
  9524. }
  9525. function renderInstances(start, count, primcount) {
  9526. if (primcount === 0) return;
  9527. var extension, methodName;
  9528. if (isWebGL2) {
  9529. extension = gl;
  9530. methodName = 'drawArraysInstanced';
  9531. } else {
  9532. extension = extensions.get('ANGLE_instanced_arrays');
  9533. methodName = 'drawArraysInstancedANGLE';
  9534. if (extension === null) {
  9535. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9536. return;
  9537. }
  9538. }
  9539. extension[methodName](mode, start, count, primcount);
  9540. info.update(count, mode, primcount);
  9541. } //
  9542. this.setMode = setMode;
  9543. this.render = render;
  9544. this.renderInstances = renderInstances;
  9545. }
  9546. function WebGLCapabilities(gl, extensions, parameters) {
  9547. var maxAnisotropy;
  9548. function getMaxAnisotropy() {
  9549. if (maxAnisotropy !== undefined) return maxAnisotropy;
  9550. var extension = extensions.get('EXT_texture_filter_anisotropic');
  9551. if (extension !== null) {
  9552. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  9553. } else {
  9554. maxAnisotropy = 0;
  9555. }
  9556. return maxAnisotropy;
  9557. }
  9558. function getMaxPrecision(precision) {
  9559. if (precision === 'highp') {
  9560. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  9561. return 'highp';
  9562. }
  9563. precision = 'mediump';
  9564. }
  9565. if (precision === 'mediump') {
  9566. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  9567. return 'mediump';
  9568. }
  9569. }
  9570. return 'lowp';
  9571. }
  9572. /* eslint-disable no-undef */
  9573. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  9574. /* eslint-enable no-undef */
  9575. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9576. var maxPrecision = getMaxPrecision(precision);
  9577. if (maxPrecision !== precision) {
  9578. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  9579. precision = maxPrecision;
  9580. }
  9581. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9582. var maxTextures = gl.getParameter(34930);
  9583. var maxVertexTextures = gl.getParameter(35660);
  9584. var maxTextureSize = gl.getParameter(3379);
  9585. var maxCubemapSize = gl.getParameter(34076);
  9586. var maxAttributes = gl.getParameter(34921);
  9587. var maxVertexUniforms = gl.getParameter(36347);
  9588. var maxVaryings = gl.getParameter(36348);
  9589. var maxFragmentUniforms = gl.getParameter(36349);
  9590. var vertexTextures = maxVertexTextures > 0;
  9591. var floatFragmentTextures = isWebGL2 || !!extensions.get('OES_texture_float');
  9592. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9593. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  9594. return {
  9595. isWebGL2: isWebGL2,
  9596. getMaxAnisotropy: getMaxAnisotropy,
  9597. getMaxPrecision: getMaxPrecision,
  9598. precision: precision,
  9599. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9600. maxTextures: maxTextures,
  9601. maxVertexTextures: maxVertexTextures,
  9602. maxTextureSize: maxTextureSize,
  9603. maxCubemapSize: maxCubemapSize,
  9604. maxAttributes: maxAttributes,
  9605. maxVertexUniforms: maxVertexUniforms,
  9606. maxVaryings: maxVaryings,
  9607. maxFragmentUniforms: maxFragmentUniforms,
  9608. vertexTextures: vertexTextures,
  9609. floatFragmentTextures: floatFragmentTextures,
  9610. floatVertexTextures: floatVertexTextures,
  9611. maxSamples: maxSamples
  9612. };
  9613. }
  9614. function WebGLClipping(properties) {
  9615. var scope = this;
  9616. var globalState = null,
  9617. numGlobalPlanes = 0,
  9618. localClippingEnabled = false,
  9619. renderingShadows = false;
  9620. var plane = new Plane(),
  9621. viewNormalMatrix = new Matrix3(),
  9622. uniform = {
  9623. value: null,
  9624. needsUpdate: false
  9625. };
  9626. this.uniform = uniform;
  9627. this.numPlanes = 0;
  9628. this.numIntersection = 0;
  9629. this.init = function (planes, enableLocalClipping, camera) {
  9630. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  9631. // run another frame in order to reset the state:
  9632. numGlobalPlanes !== 0 || localClippingEnabled;
  9633. localClippingEnabled = enableLocalClipping;
  9634. globalState = projectPlanes(planes, camera, 0);
  9635. numGlobalPlanes = planes.length;
  9636. return enabled;
  9637. };
  9638. this.beginShadows = function () {
  9639. renderingShadows = true;
  9640. projectPlanes(null);
  9641. };
  9642. this.endShadows = function () {
  9643. renderingShadows = false;
  9644. resetGlobalState();
  9645. };
  9646. this.setState = function (material, camera, useCache) {
  9647. var planes = material.clippingPlanes,
  9648. clipIntersection = material.clipIntersection,
  9649. clipShadows = material.clipShadows;
  9650. var materialProperties = properties.get(material);
  9651. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  9652. // there's no local clipping
  9653. if (renderingShadows) {
  9654. // there's no global clipping
  9655. projectPlanes(null);
  9656. } else {
  9657. resetGlobalState();
  9658. }
  9659. } else {
  9660. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9661. lGlobal = nGlobal * 4;
  9662. var dstArray = materialProperties.clippingState || null;
  9663. uniform.value = dstArray; // ensure unique state
  9664. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  9665. for (var i = 0; i !== lGlobal; ++i) {
  9666. dstArray[i] = globalState[i];
  9667. }
  9668. materialProperties.clippingState = dstArray;
  9669. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9670. this.numPlanes += nGlobal;
  9671. }
  9672. };
  9673. function resetGlobalState() {
  9674. if (uniform.value !== globalState) {
  9675. uniform.value = globalState;
  9676. uniform.needsUpdate = numGlobalPlanes > 0;
  9677. }
  9678. scope.numPlanes = numGlobalPlanes;
  9679. scope.numIntersection = 0;
  9680. }
  9681. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  9682. var nPlanes = planes !== null ? planes.length : 0;
  9683. var dstArray = null;
  9684. if (nPlanes !== 0) {
  9685. dstArray = uniform.value;
  9686. if (skipTransform !== true || dstArray === null) {
  9687. var flatSize = dstOffset + nPlanes * 4,
  9688. viewMatrix = camera.matrixWorldInverse;
  9689. viewNormalMatrix.getNormalMatrix(viewMatrix);
  9690. if (dstArray === null || dstArray.length < flatSize) {
  9691. dstArray = new Float32Array(flatSize);
  9692. }
  9693. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  9694. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  9695. plane.normal.toArray(dstArray, i4);
  9696. dstArray[i4 + 3] = plane.constant;
  9697. }
  9698. }
  9699. uniform.value = dstArray;
  9700. uniform.needsUpdate = true;
  9701. }
  9702. scope.numPlanes = nPlanes;
  9703. scope.numIntersection = 0;
  9704. return dstArray;
  9705. }
  9706. }
  9707. function WebGLCubeMaps(renderer) {
  9708. var cubemaps = new WeakMap();
  9709. function mapTextureMapping(texture, mapping) {
  9710. if (mapping === EquirectangularReflectionMapping) {
  9711. texture.mapping = CubeReflectionMapping;
  9712. } else if (mapping === EquirectangularRefractionMapping) {
  9713. texture.mapping = CubeRefractionMapping;
  9714. }
  9715. return texture;
  9716. }
  9717. function get(texture) {
  9718. if (texture && texture.isTexture) {
  9719. var mapping = texture.mapping;
  9720. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  9721. if (cubemaps.has(texture)) {
  9722. var cubemap = cubemaps.get(texture).texture;
  9723. return mapTextureMapping(cubemap, texture.mapping);
  9724. } else {
  9725. var image = texture.image;
  9726. if (image && image.height > 0) {
  9727. var currentRenderList = renderer.getRenderList();
  9728. var currentRenderTarget = renderer.getRenderTarget();
  9729. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  9730. renderTarget.fromEquirectangularTexture(renderer, texture);
  9731. cubemaps.set(texture, renderTarget);
  9732. renderer.setRenderTarget(currentRenderTarget);
  9733. renderer.setRenderList(currentRenderList);
  9734. texture.addEventListener('dispose', onTextureDispose);
  9735. return mapTextureMapping(renderTarget.texture, texture.mapping);
  9736. } else {
  9737. // image not yet ready. try the conversion next frame
  9738. return null;
  9739. }
  9740. }
  9741. }
  9742. }
  9743. return texture;
  9744. }
  9745. function onTextureDispose(event) {
  9746. var texture = event.target;
  9747. texture.removeEventListener('dispose', onTextureDispose);
  9748. var cubemap = cubemaps.get(texture);
  9749. if (cubemap !== undefined) {
  9750. cubemaps.delete(texture);
  9751. cubemap.dispose();
  9752. }
  9753. }
  9754. function dispose() {
  9755. cubemaps = new WeakMap();
  9756. }
  9757. return {
  9758. get: get,
  9759. dispose: dispose
  9760. };
  9761. }
  9762. function WebGLExtensions(gl) {
  9763. var extensions = {};
  9764. return {
  9765. has: function has(name) {
  9766. if (extensions[name] !== undefined) {
  9767. return extensions[name] !== null;
  9768. }
  9769. var extension;
  9770. switch (name) {
  9771. case 'WEBGL_depth_texture':
  9772. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  9773. break;
  9774. case 'EXT_texture_filter_anisotropic':
  9775. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  9776. break;
  9777. case 'WEBGL_compressed_texture_s3tc':
  9778. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  9779. break;
  9780. case 'WEBGL_compressed_texture_pvrtc':
  9781. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  9782. break;
  9783. default:
  9784. extension = gl.getExtension(name);
  9785. }
  9786. extensions[name] = extension;
  9787. return extension !== null;
  9788. },
  9789. get: function get(name) {
  9790. if (!this.has(name)) {
  9791. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  9792. }
  9793. return extensions[name];
  9794. }
  9795. };
  9796. }
  9797. function WebGLGeometries(gl, attributes, info, bindingStates) {
  9798. var geometries = new WeakMap();
  9799. var wireframeAttributes = new WeakMap();
  9800. function onGeometryDispose(event) {
  9801. var geometry = event.target;
  9802. var buffergeometry = geometries.get(geometry);
  9803. if (buffergeometry.index !== null) {
  9804. attributes.remove(buffergeometry.index);
  9805. }
  9806. for (var name in buffergeometry.attributes) {
  9807. attributes.remove(buffergeometry.attributes[name]);
  9808. }
  9809. geometry.removeEventListener('dispose', onGeometryDispose);
  9810. geometries.delete(geometry);
  9811. var attribute = wireframeAttributes.get(buffergeometry);
  9812. if (attribute) {
  9813. attributes.remove(attribute);
  9814. wireframeAttributes.delete(buffergeometry);
  9815. }
  9816. bindingStates.releaseStatesOfGeometry(buffergeometry);
  9817. if (geometry.isInstancedBufferGeometry === true) {
  9818. delete geometry._maxInstanceCount;
  9819. } //
  9820. info.memory.geometries--;
  9821. }
  9822. function get(object, geometry) {
  9823. var buffergeometry = geometries.get(geometry);
  9824. if (buffergeometry) return buffergeometry;
  9825. geometry.addEventListener('dispose', onGeometryDispose);
  9826. if (geometry.isBufferGeometry) {
  9827. buffergeometry = geometry;
  9828. } else if (geometry.isGeometry) {
  9829. if (geometry._bufferGeometry === undefined) {
  9830. geometry._bufferGeometry = new BufferGeometry().setFromObject(object);
  9831. }
  9832. buffergeometry = geometry._bufferGeometry;
  9833. }
  9834. geometries.set(geometry, buffergeometry);
  9835. info.memory.geometries++;
  9836. return buffergeometry;
  9837. }
  9838. function update(geometry) {
  9839. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  9840. for (var name in geometryAttributes) {
  9841. attributes.update(geometryAttributes[name], 34962);
  9842. } // morph targets
  9843. var morphAttributes = geometry.morphAttributes;
  9844. for (var _name in morphAttributes) {
  9845. var array = morphAttributes[_name];
  9846. for (var i = 0, l = array.length; i < l; i++) {
  9847. attributes.update(array[i], 34962);
  9848. }
  9849. }
  9850. }
  9851. function updateWireframeAttribute(geometry) {
  9852. var indices = [];
  9853. var geometryIndex = geometry.index;
  9854. var geometryPosition = geometry.attributes.position;
  9855. var version = 0;
  9856. if (geometryIndex !== null) {
  9857. var array = geometryIndex.array;
  9858. version = geometryIndex.version;
  9859. for (var i = 0, l = array.length; i < l; i += 3) {
  9860. var a = array[i + 0];
  9861. var b = array[i + 1];
  9862. var c = array[i + 2];
  9863. indices.push(a, b, b, c, c, a);
  9864. }
  9865. } else {
  9866. var _array = geometryPosition.array;
  9867. version = geometryPosition.version;
  9868. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  9869. var _a = _i + 0;
  9870. var _b = _i + 1;
  9871. var _c = _i + 2;
  9872. indices.push(_a, _b, _b, _c, _c, _a);
  9873. }
  9874. }
  9875. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  9876. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  9877. //
  9878. var previousAttribute = wireframeAttributes.get(geometry);
  9879. if (previousAttribute) attributes.remove(previousAttribute); //
  9880. wireframeAttributes.set(geometry, attribute);
  9881. }
  9882. function getWireframeAttribute(geometry) {
  9883. var currentAttribute = wireframeAttributes.get(geometry);
  9884. if (currentAttribute) {
  9885. var geometryIndex = geometry.index;
  9886. if (geometryIndex !== null) {
  9887. // if the attribute is obsolete, create a new one
  9888. if (currentAttribute.version < geometryIndex.version) {
  9889. updateWireframeAttribute(geometry);
  9890. }
  9891. }
  9892. } else {
  9893. updateWireframeAttribute(geometry);
  9894. }
  9895. return wireframeAttributes.get(geometry);
  9896. }
  9897. return {
  9898. get: get,
  9899. update: update,
  9900. getWireframeAttribute: getWireframeAttribute
  9901. };
  9902. }
  9903. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  9904. var isWebGL2 = capabilities.isWebGL2;
  9905. var mode;
  9906. function setMode(value) {
  9907. mode = value;
  9908. }
  9909. var type, bytesPerElement;
  9910. function setIndex(value) {
  9911. type = value.type;
  9912. bytesPerElement = value.bytesPerElement;
  9913. }
  9914. function render(start, count) {
  9915. gl.drawElements(mode, count, type, start * bytesPerElement);
  9916. info.update(count, mode, 1);
  9917. }
  9918. function renderInstances(start, count, primcount) {
  9919. if (primcount === 0) return;
  9920. var extension, methodName;
  9921. if (isWebGL2) {
  9922. extension = gl;
  9923. methodName = 'drawElementsInstanced';
  9924. } else {
  9925. extension = extensions.get('ANGLE_instanced_arrays');
  9926. methodName = 'drawElementsInstancedANGLE';
  9927. if (extension === null) {
  9928. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9929. return;
  9930. }
  9931. }
  9932. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  9933. info.update(count, mode, primcount);
  9934. } //
  9935. this.setMode = setMode;
  9936. this.setIndex = setIndex;
  9937. this.render = render;
  9938. this.renderInstances = renderInstances;
  9939. }
  9940. function WebGLInfo(gl) {
  9941. var memory = {
  9942. geometries: 0,
  9943. textures: 0
  9944. };
  9945. var render = {
  9946. frame: 0,
  9947. calls: 0,
  9948. triangles: 0,
  9949. points: 0,
  9950. lines: 0
  9951. };
  9952. function update(count, mode, instanceCount) {
  9953. render.calls++;
  9954. switch (mode) {
  9955. case 4:
  9956. render.triangles += instanceCount * (count / 3);
  9957. break;
  9958. case 1:
  9959. render.lines += instanceCount * (count / 2);
  9960. break;
  9961. case 3:
  9962. render.lines += instanceCount * (count - 1);
  9963. break;
  9964. case 2:
  9965. render.lines += instanceCount * count;
  9966. break;
  9967. case 0:
  9968. render.points += instanceCount * count;
  9969. break;
  9970. default:
  9971. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  9972. break;
  9973. }
  9974. }
  9975. function reset() {
  9976. render.frame++;
  9977. render.calls = 0;
  9978. render.triangles = 0;
  9979. render.points = 0;
  9980. render.lines = 0;
  9981. }
  9982. return {
  9983. memory: memory,
  9984. render: render,
  9985. programs: null,
  9986. autoReset: true,
  9987. reset: reset,
  9988. update: update
  9989. };
  9990. }
  9991. function numericalSort(a, b) {
  9992. return a[0] - b[0];
  9993. }
  9994. function absNumericalSort(a, b) {
  9995. return Math.abs(b[1]) - Math.abs(a[1]);
  9996. }
  9997. function WebGLMorphtargets(gl) {
  9998. var influencesList = {};
  9999. var morphInfluences = new Float32Array(8);
  10000. var workInfluences = [];
  10001. for (var i = 0; i < 8; i++) {
  10002. workInfluences[i] = [i, 0];
  10003. }
  10004. function update(object, geometry, material, program) {
  10005. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  10006. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  10007. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  10008. var influences = influencesList[geometry.id];
  10009. if (influences === undefined) {
  10010. // initialise list
  10011. influences = [];
  10012. for (var _i = 0; _i < length; _i++) {
  10013. influences[_i] = [_i, 0];
  10014. }
  10015. influencesList[geometry.id] = influences;
  10016. } // Collect influences
  10017. for (var _i2 = 0; _i2 < length; _i2++) {
  10018. var influence = influences[_i2];
  10019. influence[0] = _i2;
  10020. influence[1] = objectInfluences[_i2];
  10021. }
  10022. influences.sort(absNumericalSort);
  10023. for (var _i3 = 0; _i3 < 8; _i3++) {
  10024. if (_i3 < length && influences[_i3][1]) {
  10025. workInfluences[_i3][0] = influences[_i3][0];
  10026. workInfluences[_i3][1] = influences[_i3][1];
  10027. } else {
  10028. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  10029. workInfluences[_i3][1] = 0;
  10030. }
  10031. }
  10032. workInfluences.sort(numericalSort);
  10033. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  10034. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  10035. var morphInfluencesSum = 0;
  10036. for (var _i4 = 0; _i4 < 8; _i4++) {
  10037. var _influence = workInfluences[_i4];
  10038. var index = _influence[0];
  10039. var value = _influence[1];
  10040. if (index !== Number.MAX_SAFE_INTEGER && value) {
  10041. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  10042. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  10043. }
  10044. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  10045. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  10046. }
  10047. morphInfluences[_i4] = value;
  10048. morphInfluencesSum += value;
  10049. } else {
  10050. if (morphTargets && geometry.hasAttribute('morphTarget' + _i4) === true) {
  10051. geometry.deleteAttribute('morphTarget' + _i4);
  10052. }
  10053. if (morphNormals && geometry.hasAttribute('morphNormal' + _i4) === true) {
  10054. geometry.deleteAttribute('morphNormal' + _i4);
  10055. }
  10056. morphInfluences[_i4] = 0;
  10057. }
  10058. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  10059. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  10060. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  10061. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10062. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  10063. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  10064. }
  10065. return {
  10066. update: update
  10067. };
  10068. }
  10069. function WebGLObjects(gl, geometries, attributes, info) {
  10070. var updateMap = new WeakMap();
  10071. function update(object) {
  10072. var frame = info.render.frame;
  10073. var geometry = object.geometry;
  10074. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  10075. if (updateMap.get(buffergeometry) !== frame) {
  10076. if (geometry.isGeometry) {
  10077. buffergeometry.updateFromObject(object);
  10078. }
  10079. geometries.update(buffergeometry);
  10080. updateMap.set(buffergeometry, frame);
  10081. }
  10082. if (object.isInstancedMesh) {
  10083. if (object.hasEventListener('dispose', onInstancedMeshDispose) === false) {
  10084. object.addEventListener('dispose', onInstancedMeshDispose);
  10085. }
  10086. attributes.update(object.instanceMatrix, 34962);
  10087. if (object.instanceColor !== null) {
  10088. attributes.update(object.instanceColor, 34962);
  10089. }
  10090. }
  10091. return buffergeometry;
  10092. }
  10093. function dispose() {
  10094. updateMap = new WeakMap();
  10095. }
  10096. function onInstancedMeshDispose(event) {
  10097. var instancedMesh = event.target;
  10098. instancedMesh.removeEventListener('dispose', onInstancedMeshDispose);
  10099. attributes.remove(instancedMesh.instanceMatrix);
  10100. if (instancedMesh.instanceColor !== null) attributes.remove(instancedMesh.instanceColor);
  10101. }
  10102. return {
  10103. update: update,
  10104. dispose: dispose
  10105. };
  10106. }
  10107. function DataTexture2DArray(data, width, height, depth) {
  10108. if (data === void 0) {
  10109. data = null;
  10110. }
  10111. if (width === void 0) {
  10112. width = 1;
  10113. }
  10114. if (height === void 0) {
  10115. height = 1;
  10116. }
  10117. if (depth === void 0) {
  10118. depth = 1;
  10119. }
  10120. Texture.call(this, null);
  10121. this.image = {
  10122. data: data,
  10123. width: width,
  10124. height: height,
  10125. depth: depth
  10126. };
  10127. this.magFilter = NearestFilter;
  10128. this.minFilter = NearestFilter;
  10129. this.wrapR = ClampToEdgeWrapping;
  10130. this.generateMipmaps = false;
  10131. this.flipY = false;
  10132. this.needsUpdate = true;
  10133. }
  10134. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  10135. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10136. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10137. function DataTexture3D(data, width, height, depth) {
  10138. if (data === void 0) {
  10139. data = null;
  10140. }
  10141. if (width === void 0) {
  10142. width = 1;
  10143. }
  10144. if (height === void 0) {
  10145. height = 1;
  10146. }
  10147. if (depth === void 0) {
  10148. depth = 1;
  10149. }
  10150. // We're going to add .setXXX() methods for setting properties later.
  10151. // Users can still set in DataTexture3D directly.
  10152. //
  10153. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10154. // texture.anisotropy = 16;
  10155. //
  10156. // See #14839
  10157. Texture.call(this, null);
  10158. this.image = {
  10159. data: data,
  10160. width: width,
  10161. height: height,
  10162. depth: depth
  10163. };
  10164. this.magFilter = NearestFilter;
  10165. this.minFilter = NearestFilter;
  10166. this.wrapR = ClampToEdgeWrapping;
  10167. this.generateMipmaps = false;
  10168. this.flipY = false;
  10169. this.needsUpdate = true;
  10170. }
  10171. DataTexture3D.prototype = Object.create(Texture.prototype);
  10172. DataTexture3D.prototype.constructor = DataTexture3D;
  10173. DataTexture3D.prototype.isDataTexture3D = true;
  10174. /**
  10175. * Uniforms of a program.
  10176. * Those form a tree structure with a special top-level container for the root,
  10177. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10178. *
  10179. *
  10180. * Properties of inner nodes including the top-level container:
  10181. *
  10182. * .seq - array of nested uniforms
  10183. * .map - nested uniforms by name
  10184. *
  10185. *
  10186. * Methods of all nodes except the top-level container:
  10187. *
  10188. * .setValue( gl, value, [textures] )
  10189. *
  10190. * uploads a uniform value(s)
  10191. * the 'textures' parameter is needed for sampler uniforms
  10192. *
  10193. *
  10194. * Static methods of the top-level container (textures factorizations):
  10195. *
  10196. * .upload( gl, seq, values, textures )
  10197. *
  10198. * sets uniforms in 'seq' to 'values[id].value'
  10199. *
  10200. * .seqWithValue( seq, values ) : filteredSeq
  10201. *
  10202. * filters 'seq' entries with corresponding entry in values
  10203. *
  10204. *
  10205. * Methods of the top-level container (textures factorizations):
  10206. *
  10207. * .setValue( gl, name, value, textures )
  10208. *
  10209. * sets uniform with name 'name' to 'value'
  10210. *
  10211. * .setOptional( gl, obj, prop )
  10212. *
  10213. * like .set for an optional property of the object
  10214. *
  10215. */
  10216. var emptyTexture = new Texture();
  10217. var emptyTexture2dArray = new DataTexture2DArray();
  10218. var emptyTexture3d = new DataTexture3D();
  10219. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10220. // Array Caches (provide typed arrays for temporary by size)
  10221. var arrayCacheF32 = [];
  10222. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10223. var mat4array = new Float32Array(16);
  10224. var mat3array = new Float32Array(9);
  10225. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10226. function flatten(array, nBlocks, blockSize) {
  10227. var firstElem = array[0];
  10228. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10229. // see http://jacksondunstan.com/articles/983
  10230. var n = nBlocks * blockSize;
  10231. var r = arrayCacheF32[n];
  10232. if (r === undefined) {
  10233. r = new Float32Array(n);
  10234. arrayCacheF32[n] = r;
  10235. }
  10236. if (nBlocks !== 0) {
  10237. firstElem.toArray(r, 0);
  10238. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10239. offset += blockSize;
  10240. array[i].toArray(r, offset);
  10241. }
  10242. }
  10243. return r;
  10244. }
  10245. function arraysEqual(a, b) {
  10246. if (a.length !== b.length) return false;
  10247. for (var i = 0, l = a.length; i < l; i++) {
  10248. if (a[i] !== b[i]) return false;
  10249. }
  10250. return true;
  10251. }
  10252. function copyArray(a, b) {
  10253. for (var i = 0, l = b.length; i < l; i++) {
  10254. a[i] = b[i];
  10255. }
  10256. } // Texture unit allocation
  10257. function allocTexUnits(textures, n) {
  10258. var r = arrayCacheI32[n];
  10259. if (r === undefined) {
  10260. r = new Int32Array(n);
  10261. arrayCacheI32[n] = r;
  10262. }
  10263. for (var i = 0; i !== n; ++i) {
  10264. r[i] = textures.allocateTextureUnit();
  10265. }
  10266. return r;
  10267. } // --- Setters ---
  10268. // Note: Defining these methods externally, because they come in a bunch
  10269. // and this way their names minify.
  10270. // Single scalar
  10271. function setValueV1f(gl, v) {
  10272. var cache = this.cache;
  10273. if (cache[0] === v) return;
  10274. gl.uniform1f(this.addr, v);
  10275. cache[0] = v;
  10276. } // Single float vector (from flat array or THREE.VectorN)
  10277. function setValueV2f(gl, v) {
  10278. var cache = this.cache;
  10279. if (v.x !== undefined) {
  10280. if (cache[0] !== v.x || cache[1] !== v.y) {
  10281. gl.uniform2f(this.addr, v.x, v.y);
  10282. cache[0] = v.x;
  10283. cache[1] = v.y;
  10284. }
  10285. } else {
  10286. if (arraysEqual(cache, v)) return;
  10287. gl.uniform2fv(this.addr, v);
  10288. copyArray(cache, v);
  10289. }
  10290. }
  10291. function setValueV3f(gl, v) {
  10292. var cache = this.cache;
  10293. if (v.x !== undefined) {
  10294. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10295. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10296. cache[0] = v.x;
  10297. cache[1] = v.y;
  10298. cache[2] = v.z;
  10299. }
  10300. } else if (v.r !== undefined) {
  10301. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10302. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10303. cache[0] = v.r;
  10304. cache[1] = v.g;
  10305. cache[2] = v.b;
  10306. }
  10307. } else {
  10308. if (arraysEqual(cache, v)) return;
  10309. gl.uniform3fv(this.addr, v);
  10310. copyArray(cache, v);
  10311. }
  10312. }
  10313. function setValueV4f(gl, v) {
  10314. var cache = this.cache;
  10315. if (v.x !== undefined) {
  10316. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10317. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10318. cache[0] = v.x;
  10319. cache[1] = v.y;
  10320. cache[2] = v.z;
  10321. cache[3] = v.w;
  10322. }
  10323. } else {
  10324. if (arraysEqual(cache, v)) return;
  10325. gl.uniform4fv(this.addr, v);
  10326. copyArray(cache, v);
  10327. }
  10328. } // Single matrix (from flat array or MatrixN)
  10329. function setValueM2(gl, v) {
  10330. var cache = this.cache;
  10331. var elements = v.elements;
  10332. if (elements === undefined) {
  10333. if (arraysEqual(cache, v)) return;
  10334. gl.uniformMatrix2fv(this.addr, false, v);
  10335. copyArray(cache, v);
  10336. } else {
  10337. if (arraysEqual(cache, elements)) return;
  10338. mat2array.set(elements);
  10339. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10340. copyArray(cache, elements);
  10341. }
  10342. }
  10343. function setValueM3(gl, v) {
  10344. var cache = this.cache;
  10345. var elements = v.elements;
  10346. if (elements === undefined) {
  10347. if (arraysEqual(cache, v)) return;
  10348. gl.uniformMatrix3fv(this.addr, false, v);
  10349. copyArray(cache, v);
  10350. } else {
  10351. if (arraysEqual(cache, elements)) return;
  10352. mat3array.set(elements);
  10353. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10354. copyArray(cache, elements);
  10355. }
  10356. }
  10357. function setValueM4(gl, v) {
  10358. var cache = this.cache;
  10359. var elements = v.elements;
  10360. if (elements === undefined) {
  10361. if (arraysEqual(cache, v)) return;
  10362. gl.uniformMatrix4fv(this.addr, false, v);
  10363. copyArray(cache, v);
  10364. } else {
  10365. if (arraysEqual(cache, elements)) return;
  10366. mat4array.set(elements);
  10367. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10368. copyArray(cache, elements);
  10369. }
  10370. } // Single texture (2D / Cube)
  10371. function setValueT1(gl, v, textures) {
  10372. var cache = this.cache;
  10373. var unit = textures.allocateTextureUnit();
  10374. if (cache[0] !== unit) {
  10375. gl.uniform1i(this.addr, unit);
  10376. cache[0] = unit;
  10377. }
  10378. textures.safeSetTexture2D(v || emptyTexture, unit);
  10379. }
  10380. function setValueT2DArray1(gl, v, textures) {
  10381. var cache = this.cache;
  10382. var unit = textures.allocateTextureUnit();
  10383. if (cache[0] !== unit) {
  10384. gl.uniform1i(this.addr, unit);
  10385. cache[0] = unit;
  10386. }
  10387. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10388. }
  10389. function setValueT3D1(gl, v, textures) {
  10390. var cache = this.cache;
  10391. var unit = textures.allocateTextureUnit();
  10392. if (cache[0] !== unit) {
  10393. gl.uniform1i(this.addr, unit);
  10394. cache[0] = unit;
  10395. }
  10396. textures.setTexture3D(v || emptyTexture3d, unit);
  10397. }
  10398. function setValueT6(gl, v, textures) {
  10399. var cache = this.cache;
  10400. var unit = textures.allocateTextureUnit();
  10401. if (cache[0] !== unit) {
  10402. gl.uniform1i(this.addr, unit);
  10403. cache[0] = unit;
  10404. }
  10405. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10406. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10407. function setValueV1i(gl, v) {
  10408. var cache = this.cache;
  10409. if (cache[0] === v) return;
  10410. gl.uniform1i(this.addr, v);
  10411. cache[0] = v;
  10412. }
  10413. function setValueV2i(gl, v) {
  10414. var cache = this.cache;
  10415. if (arraysEqual(cache, v)) return;
  10416. gl.uniform2iv(this.addr, v);
  10417. copyArray(cache, v);
  10418. }
  10419. function setValueV3i(gl, v) {
  10420. var cache = this.cache;
  10421. if (arraysEqual(cache, v)) return;
  10422. gl.uniform3iv(this.addr, v);
  10423. copyArray(cache, v);
  10424. }
  10425. function setValueV4i(gl, v) {
  10426. var cache = this.cache;
  10427. if (arraysEqual(cache, v)) return;
  10428. gl.uniform4iv(this.addr, v);
  10429. copyArray(cache, v);
  10430. } // uint
  10431. function setValueV1ui(gl, v) {
  10432. var cache = this.cache;
  10433. if (cache[0] === v) return;
  10434. gl.uniform1ui(this.addr, v);
  10435. cache[0] = v;
  10436. } // Helper to pick the right setter for the singular case
  10437. function getSingularSetter(type) {
  10438. switch (type) {
  10439. case 0x1406:
  10440. return setValueV1f;
  10441. // FLOAT
  10442. case 0x8b50:
  10443. return setValueV2f;
  10444. // _VEC2
  10445. case 0x8b51:
  10446. return setValueV3f;
  10447. // _VEC3
  10448. case 0x8b52:
  10449. return setValueV4f;
  10450. // _VEC4
  10451. case 0x8b5a:
  10452. return setValueM2;
  10453. // _MAT2
  10454. case 0x8b5b:
  10455. return setValueM3;
  10456. // _MAT3
  10457. case 0x8b5c:
  10458. return setValueM4;
  10459. // _MAT4
  10460. case 0x1404:
  10461. case 0x8b56:
  10462. return setValueV1i;
  10463. // INT, BOOL
  10464. case 0x8b53:
  10465. case 0x8b57:
  10466. return setValueV2i;
  10467. // _VEC2
  10468. case 0x8b54:
  10469. case 0x8b58:
  10470. return setValueV3i;
  10471. // _VEC3
  10472. case 0x8b55:
  10473. case 0x8b59:
  10474. return setValueV4i;
  10475. // _VEC4
  10476. case 0x1405:
  10477. return setValueV1ui;
  10478. // UINT
  10479. case 0x8b5e: // SAMPLER_2D
  10480. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10481. case 0x8dca: // INT_SAMPLER_2D
  10482. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10483. case 0x8b62:
  10484. // SAMPLER_2D_SHADOW
  10485. return setValueT1;
  10486. case 0x8b5f: // SAMPLER_3D
  10487. case 0x8dcb: // INT_SAMPLER_3D
  10488. case 0x8dd3:
  10489. // UNSIGNED_INT_SAMPLER_3D
  10490. return setValueT3D1;
  10491. case 0x8b60: // SAMPLER_CUBE
  10492. case 0x8dcc: // INT_SAMPLER_CUBE
  10493. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10494. case 0x8dc5:
  10495. // SAMPLER_CUBE_SHADOW
  10496. return setValueT6;
  10497. case 0x8dc1: // SAMPLER_2D_ARRAY
  10498. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10499. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10500. case 0x8dc4:
  10501. // SAMPLER_2D_ARRAY_SHADOW
  10502. return setValueT2DArray1;
  10503. }
  10504. } // Array of scalars
  10505. function setValueV1fArray(gl, v) {
  10506. gl.uniform1fv(this.addr, v);
  10507. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10508. function setValueV1iArray(gl, v) {
  10509. gl.uniform1iv(this.addr, v);
  10510. }
  10511. function setValueV2iArray(gl, v) {
  10512. gl.uniform2iv(this.addr, v);
  10513. }
  10514. function setValueV3iArray(gl, v) {
  10515. gl.uniform3iv(this.addr, v);
  10516. }
  10517. function setValueV4iArray(gl, v) {
  10518. gl.uniform4iv(this.addr, v);
  10519. } // Array of vectors (flat or from THREE classes)
  10520. function setValueV2fArray(gl, v) {
  10521. var data = flatten(v, this.size, 2);
  10522. gl.uniform2fv(this.addr, data);
  10523. }
  10524. function setValueV3fArray(gl, v) {
  10525. var data = flatten(v, this.size, 3);
  10526. gl.uniform3fv(this.addr, data);
  10527. }
  10528. function setValueV4fArray(gl, v) {
  10529. var data = flatten(v, this.size, 4);
  10530. gl.uniform4fv(this.addr, data);
  10531. } // Array of matrices (flat or from THREE clases)
  10532. function setValueM2Array(gl, v) {
  10533. var data = flatten(v, this.size, 4);
  10534. gl.uniformMatrix2fv(this.addr, false, data);
  10535. }
  10536. function setValueM3Array(gl, v) {
  10537. var data = flatten(v, this.size, 9);
  10538. gl.uniformMatrix3fv(this.addr, false, data);
  10539. }
  10540. function setValueM4Array(gl, v) {
  10541. var data = flatten(v, this.size, 16);
  10542. gl.uniformMatrix4fv(this.addr, false, data);
  10543. } // Array of textures (2D / Cube)
  10544. function setValueT1Array(gl, v, textures) {
  10545. var n = v.length;
  10546. var units = allocTexUnits(textures, n);
  10547. gl.uniform1iv(this.addr, units);
  10548. for (var i = 0; i !== n; ++i) {
  10549. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  10550. }
  10551. }
  10552. function setValueT6Array(gl, v, textures) {
  10553. var n = v.length;
  10554. var units = allocTexUnits(textures, n);
  10555. gl.uniform1iv(this.addr, units);
  10556. for (var i = 0; i !== n; ++i) {
  10557. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  10558. }
  10559. } // Helper to pick the right setter for a pure (bottom-level) array
  10560. function getPureArraySetter(type) {
  10561. switch (type) {
  10562. case 0x1406:
  10563. return setValueV1fArray;
  10564. // FLOAT
  10565. case 0x8b50:
  10566. return setValueV2fArray;
  10567. // _VEC2
  10568. case 0x8b51:
  10569. return setValueV3fArray;
  10570. // _VEC3
  10571. case 0x8b52:
  10572. return setValueV4fArray;
  10573. // _VEC4
  10574. case 0x8b5a:
  10575. return setValueM2Array;
  10576. // _MAT2
  10577. case 0x8b5b:
  10578. return setValueM3Array;
  10579. // _MAT3
  10580. case 0x8b5c:
  10581. return setValueM4Array;
  10582. // _MAT4
  10583. case 0x1404:
  10584. case 0x8b56:
  10585. return setValueV1iArray;
  10586. // INT, BOOL
  10587. case 0x8b53:
  10588. case 0x8b57:
  10589. return setValueV2iArray;
  10590. // _VEC2
  10591. case 0x8b54:
  10592. case 0x8b58:
  10593. return setValueV3iArray;
  10594. // _VEC3
  10595. case 0x8b55:
  10596. case 0x8b59:
  10597. return setValueV4iArray;
  10598. // _VEC4
  10599. case 0x8b5e: // SAMPLER_2D
  10600. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10601. case 0x8dca: // INT_SAMPLER_2D
  10602. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10603. case 0x8b62:
  10604. // SAMPLER_2D_SHADOW
  10605. return setValueT1Array;
  10606. case 0x8b60: // SAMPLER_CUBE
  10607. case 0x8dcc: // INT_SAMPLER_CUBE
  10608. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10609. case 0x8dc5:
  10610. // SAMPLER_CUBE_SHADOW
  10611. return setValueT6Array;
  10612. }
  10613. } // --- Uniform Classes ---
  10614. function SingleUniform(id, activeInfo, addr) {
  10615. this.id = id;
  10616. this.addr = addr;
  10617. this.cache = [];
  10618. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10619. }
  10620. function PureArrayUniform(id, activeInfo, addr) {
  10621. this.id = id;
  10622. this.addr = addr;
  10623. this.cache = [];
  10624. this.size = activeInfo.size;
  10625. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10626. }
  10627. PureArrayUniform.prototype.updateCache = function (data) {
  10628. var cache = this.cache;
  10629. if (data instanceof Float32Array && cache.length !== data.length) {
  10630. this.cache = new Float32Array(data.length);
  10631. }
  10632. copyArray(cache, data);
  10633. };
  10634. function StructuredUniform(id) {
  10635. this.id = id;
  10636. this.seq = [];
  10637. this.map = {};
  10638. }
  10639. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  10640. var seq = this.seq;
  10641. for (var i = 0, n = seq.length; i !== n; ++i) {
  10642. var u = seq[i];
  10643. u.setValue(gl, value[u.id], textures);
  10644. }
  10645. }; // --- Top-level ---
  10646. // Parser - builds up the property tree from the path strings
  10647. var RePathPart = /(\w+)(\])?(\[|\.)?/g; // extracts
  10648. // - the identifier (member name or array index)
  10649. // - followed by an optional right bracket (found when array index)
  10650. // - followed by an optional left bracket or dot (type of subscript)
  10651. //
  10652. // Note: These portions can be read in a non-overlapping fashion and
  10653. // allow straightforward parsing of the hierarchy that WebGL encodes
  10654. // in the uniform names.
  10655. function addUniform(container, uniformObject) {
  10656. container.seq.push(uniformObject);
  10657. container.map[uniformObject.id] = uniformObject;
  10658. }
  10659. function parseUniform(activeInfo, addr, container) {
  10660. var path = activeInfo.name,
  10661. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  10662. RePathPart.lastIndex = 0;
  10663. while (true) {
  10664. var match = RePathPart.exec(path),
  10665. matchEnd = RePathPart.lastIndex;
  10666. var id = match[1];
  10667. var idIsIndex = match[2] === ']',
  10668. subscript = match[3];
  10669. if (idIsIndex) id = id | 0; // convert to integer
  10670. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  10671. // bare name or "pure" bottom-level array "[0]" suffix
  10672. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  10673. break;
  10674. } else {
  10675. // step into inner node / create it in case it doesn't exist
  10676. var map = container.map;
  10677. var next = map[id];
  10678. if (next === undefined) {
  10679. next = new StructuredUniform(id);
  10680. addUniform(container, next);
  10681. }
  10682. container = next;
  10683. }
  10684. }
  10685. } // Root Container
  10686. function WebGLUniforms(gl, program) {
  10687. this.seq = [];
  10688. this.map = {};
  10689. var n = gl.getProgramParameter(program, 35718);
  10690. for (var i = 0; i < n; ++i) {
  10691. var info = gl.getActiveUniform(program, i),
  10692. addr = gl.getUniformLocation(program, info.name);
  10693. parseUniform(info, addr, this);
  10694. }
  10695. }
  10696. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  10697. var u = this.map[name];
  10698. if (u !== undefined) u.setValue(gl, value, textures);
  10699. };
  10700. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  10701. var v = object[name];
  10702. if (v !== undefined) this.setValue(gl, name, v);
  10703. }; // Static interface
  10704. WebGLUniforms.upload = function (gl, seq, values, textures) {
  10705. for (var i = 0, n = seq.length; i !== n; ++i) {
  10706. var u = seq[i],
  10707. v = values[u.id];
  10708. if (v.needsUpdate !== false) {
  10709. // note: always updating when .needsUpdate is undefined
  10710. u.setValue(gl, v.value, textures);
  10711. }
  10712. }
  10713. };
  10714. WebGLUniforms.seqWithValue = function (seq, values) {
  10715. var r = [];
  10716. for (var i = 0, n = seq.length; i !== n; ++i) {
  10717. var u = seq[i];
  10718. if (u.id in values) r.push(u);
  10719. }
  10720. return r;
  10721. };
  10722. function WebGLShader(gl, type, string) {
  10723. var shader = gl.createShader(type);
  10724. gl.shaderSource(shader, string);
  10725. gl.compileShader(shader);
  10726. return shader;
  10727. }
  10728. var programIdCount = 0;
  10729. function addLineNumbers(string) {
  10730. var lines = string.split('\n');
  10731. for (var i = 0; i < lines.length; i++) {
  10732. lines[i] = i + 1 + ': ' + lines[i];
  10733. }
  10734. return lines.join('\n');
  10735. }
  10736. function getEncodingComponents(encoding) {
  10737. switch (encoding) {
  10738. case LinearEncoding:
  10739. return ['Linear', '( value )'];
  10740. case sRGBEncoding:
  10741. return ['sRGB', '( value )'];
  10742. case RGBEEncoding:
  10743. return ['RGBE', '( value )'];
  10744. case RGBM7Encoding:
  10745. return ['RGBM', '( value, 7.0 )'];
  10746. case RGBM16Encoding:
  10747. return ['RGBM', '( value, 16.0 )'];
  10748. case RGBDEncoding:
  10749. return ['RGBD', '( value, 256.0 )'];
  10750. case GammaEncoding:
  10751. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  10752. case LogLuvEncoding:
  10753. return ['LogLuv', '( value )'];
  10754. default:
  10755. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  10756. return ['Linear', '( value )'];
  10757. }
  10758. }
  10759. function getShaderErrors(gl, shader, type) {
  10760. var status = gl.getShaderParameter(shader, 35713);
  10761. var log = gl.getShaderInfoLog(shader).trim();
  10762. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  10763. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10764. var source = gl.getShaderSource(shader);
  10765. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  10766. }
  10767. function getTexelDecodingFunction(functionName, encoding) {
  10768. var components = getEncodingComponents(encoding);
  10769. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  10770. }
  10771. function getTexelEncodingFunction(functionName, encoding) {
  10772. var components = getEncodingComponents(encoding);
  10773. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  10774. }
  10775. function getToneMappingFunction(functionName, toneMapping) {
  10776. var toneMappingName;
  10777. switch (toneMapping) {
  10778. case LinearToneMapping:
  10779. toneMappingName = 'Linear';
  10780. break;
  10781. case ReinhardToneMapping:
  10782. toneMappingName = 'Reinhard';
  10783. break;
  10784. case CineonToneMapping:
  10785. toneMappingName = 'OptimizedCineon';
  10786. break;
  10787. case ACESFilmicToneMapping:
  10788. toneMappingName = 'ACESFilmic';
  10789. break;
  10790. case CustomToneMapping:
  10791. toneMappingName = 'Custom';
  10792. break;
  10793. default:
  10794. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  10795. toneMappingName = 'Linear';
  10796. }
  10797. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10798. }
  10799. function generateExtensions(parameters) {
  10800. 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' : ''];
  10801. return chunks.filter(filterEmptyLine).join('\n');
  10802. }
  10803. function generateDefines(defines) {
  10804. var chunks = [];
  10805. for (var name in defines) {
  10806. var value = defines[name];
  10807. if (value === false) continue;
  10808. chunks.push('#define ' + name + ' ' + value);
  10809. }
  10810. return chunks.join('\n');
  10811. }
  10812. function fetchAttributeLocations(gl, program) {
  10813. var attributes = {};
  10814. var n = gl.getProgramParameter(program, 35721);
  10815. for (var i = 0; i < n; i++) {
  10816. var info = gl.getActiveAttrib(program, i);
  10817. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10818. attributes[name] = gl.getAttribLocation(program, name);
  10819. }
  10820. return attributes;
  10821. }
  10822. function filterEmptyLine(string) {
  10823. return string !== '';
  10824. }
  10825. function replaceLightNums(string, parameters) {
  10826. 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);
  10827. }
  10828. function replaceClippingPlaneNums(string, parameters) {
  10829. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  10830. } // Resolve Includes
  10831. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10832. function resolveIncludes(string) {
  10833. return string.replace(includePattern, includeReplacer);
  10834. }
  10835. function includeReplacer(match, include) {
  10836. var string = ShaderChunk[include];
  10837. if (string === undefined) {
  10838. throw new Error('Can not resolve #include <' + include + '>');
  10839. }
  10840. return resolveIncludes(string);
  10841. } // Unroll Loops
  10842. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10843. 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;
  10844. function unrollLoops(string) {
  10845. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  10846. }
  10847. function deprecatedLoopReplacer(match, start, end, snippet) {
  10848. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  10849. return loopReplacer(match, start, end, snippet);
  10850. }
  10851. function loopReplacer(match, start, end, snippet) {
  10852. var string = '';
  10853. for (var i = parseInt(start); i < parseInt(end); i++) {
  10854. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  10855. }
  10856. return string;
  10857. } //
  10858. function generatePrecision(parameters) {
  10859. var precisionstring = 'precision ' + parameters.precision + ' float;\nprecision ' + parameters.precision + ' int;';
  10860. if (parameters.precision === 'highp') {
  10861. precisionstring += '\n#define HIGH_PRECISION';
  10862. } else if (parameters.precision === 'mediump') {
  10863. precisionstring += '\n#define MEDIUM_PRECISION';
  10864. } else if (parameters.precision === 'lowp') {
  10865. precisionstring += '\n#define LOW_PRECISION';
  10866. }
  10867. return precisionstring;
  10868. }
  10869. function generateShadowMapTypeDefine(parameters) {
  10870. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10871. if (parameters.shadowMapType === PCFShadowMap) {
  10872. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10873. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  10874. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10875. } else if (parameters.shadowMapType === VSMShadowMap) {
  10876. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  10877. }
  10878. return shadowMapTypeDefine;
  10879. }
  10880. function generateEnvMapTypeDefine(parameters) {
  10881. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10882. if (parameters.envMap) {
  10883. switch (parameters.envMapMode) {
  10884. case CubeReflectionMapping:
  10885. case CubeRefractionMapping:
  10886. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10887. break;
  10888. case CubeUVReflectionMapping:
  10889. case CubeUVRefractionMapping:
  10890. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10891. break;
  10892. }
  10893. }
  10894. return envMapTypeDefine;
  10895. }
  10896. function generateEnvMapModeDefine(parameters) {
  10897. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10898. if (parameters.envMap) {
  10899. switch (parameters.envMapMode) {
  10900. case CubeRefractionMapping:
  10901. case CubeUVRefractionMapping:
  10902. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10903. break;
  10904. }
  10905. }
  10906. return envMapModeDefine;
  10907. }
  10908. function generateEnvMapBlendingDefine(parameters) {
  10909. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  10910. if (parameters.envMap) {
  10911. switch (parameters.combine) {
  10912. case MultiplyOperation:
  10913. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10914. break;
  10915. case MixOperation:
  10916. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10917. break;
  10918. case AddOperation:
  10919. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10920. break;
  10921. }
  10922. }
  10923. return envMapBlendingDefine;
  10924. }
  10925. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  10926. var gl = renderer.getContext();
  10927. var defines = parameters.defines;
  10928. var vertexShader = parameters.vertexShader;
  10929. var fragmentShader = parameters.fragmentShader;
  10930. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  10931. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  10932. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  10933. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  10934. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  10935. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  10936. var customDefines = generateDefines(defines);
  10937. var program = gl.createProgram();
  10938. var prefixVertex, prefixFragment;
  10939. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
  10940. if (parameters.isRawShaderMaterial) {
  10941. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  10942. if (prefixVertex.length > 0) {
  10943. prefixVertex += '\n';
  10944. }
  10945. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  10946. if (prefixFragment.length > 0) {
  10947. prefixFragment += '\n';
  10948. }
  10949. } else {
  10950. 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');
  10951. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  10952. '#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
  10953. 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
  10954. 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');
  10955. }
  10956. vertexShader = resolveIncludes(vertexShader);
  10957. vertexShader = replaceLightNums(vertexShader, parameters);
  10958. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  10959. fragmentShader = resolveIncludes(fragmentShader);
  10960. fragmentShader = replaceLightNums(fragmentShader, parameters);
  10961. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  10962. vertexShader = unrollLoops(vertexShader);
  10963. fragmentShader = unrollLoops(fragmentShader);
  10964. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  10965. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  10966. versionString = '#version 300 es\n';
  10967. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  10968. 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;
  10969. }
  10970. var vertexGlsl = versionString + prefixVertex + vertexShader;
  10971. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  10972. // console.log( '*FRAGMENT*', fragmentGlsl );
  10973. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  10974. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  10975. gl.attachShader(program, glVertexShader);
  10976. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  10977. if (parameters.index0AttributeName !== undefined) {
  10978. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  10979. } else if (parameters.morphTargets === true) {
  10980. // programs with morphTargets displace position out of attribute 0
  10981. gl.bindAttribLocation(program, 0, 'position');
  10982. }
  10983. gl.linkProgram(program); // check for link errors
  10984. if (renderer.debug.checkShaderErrors) {
  10985. var programLog = gl.getProgramInfoLog(program).trim();
  10986. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  10987. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  10988. var runnable = true;
  10989. var haveDiagnostics = true;
  10990. if (gl.getProgramParameter(program, 35714) === false) {
  10991. runnable = false;
  10992. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  10993. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  10994. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  10995. } else if (programLog !== '') {
  10996. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  10997. } else if (vertexLog === '' || fragmentLog === '') {
  10998. haveDiagnostics = false;
  10999. }
  11000. if (haveDiagnostics) {
  11001. this.diagnostics = {
  11002. runnable: runnable,
  11003. programLog: programLog,
  11004. vertexShader: {
  11005. log: vertexLog,
  11006. prefix: prefixVertex
  11007. },
  11008. fragmentShader: {
  11009. log: fragmentLog,
  11010. prefix: prefixFragment
  11011. }
  11012. };
  11013. }
  11014. } // Clean up
  11015. // Crashes in iOS9 and iOS10. #18402
  11016. // gl.detachShader( program, glVertexShader );
  11017. // gl.detachShader( program, glFragmentShader );
  11018. gl.deleteShader(glVertexShader);
  11019. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  11020. var cachedUniforms;
  11021. this.getUniforms = function () {
  11022. if (cachedUniforms === undefined) {
  11023. cachedUniforms = new WebGLUniforms(gl, program);
  11024. }
  11025. return cachedUniforms;
  11026. }; // set up caching for attribute locations
  11027. var cachedAttributes;
  11028. this.getAttributes = function () {
  11029. if (cachedAttributes === undefined) {
  11030. cachedAttributes = fetchAttributeLocations(gl, program);
  11031. }
  11032. return cachedAttributes;
  11033. }; // free resource
  11034. this.destroy = function () {
  11035. bindingStates.releaseStatesOfProgram(this);
  11036. gl.deleteProgram(program);
  11037. this.program = undefined;
  11038. }; //
  11039. this.name = parameters.shaderName;
  11040. this.id = programIdCount++;
  11041. this.cacheKey = cacheKey;
  11042. this.usedTimes = 1;
  11043. this.program = program;
  11044. this.vertexShader = glVertexShader;
  11045. this.fragmentShader = glFragmentShader;
  11046. return this;
  11047. }
  11048. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  11049. var programs = [];
  11050. var isWebGL2 = capabilities.isWebGL2;
  11051. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11052. var floatVertexTextures = capabilities.floatVertexTextures;
  11053. var maxVertexUniforms = capabilities.maxVertexUniforms;
  11054. var vertexTextures = capabilities.vertexTextures;
  11055. var precision = capabilities.precision;
  11056. var shaderIDs = {
  11057. MeshDepthMaterial: 'depth',
  11058. MeshDistanceMaterial: 'distanceRGBA',
  11059. MeshNormalMaterial: 'normal',
  11060. MeshBasicMaterial: 'basic',
  11061. MeshLambertMaterial: 'lambert',
  11062. MeshPhongMaterial: 'phong',
  11063. MeshToonMaterial: 'toon',
  11064. MeshStandardMaterial: 'physical',
  11065. MeshPhysicalMaterial: 'physical',
  11066. MeshMatcapMaterial: 'matcap',
  11067. LineBasicMaterial: 'basic',
  11068. LineDashedMaterial: 'dashed',
  11069. PointsMaterial: 'points',
  11070. ShadowMaterial: 'shadow',
  11071. SpriteMaterial: 'sprite'
  11072. };
  11073. 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'];
  11074. function getMaxBones(object) {
  11075. var skeleton = object.skeleton;
  11076. var bones = skeleton.bones;
  11077. if (floatVertexTextures) {
  11078. return 1024;
  11079. } else {
  11080. // default for when object is not specified
  11081. // ( for example when prebuilding shader to be used with multiple objects )
  11082. //
  11083. // - leave some extra space for other uniforms
  11084. // - limit here is ANGLE's 254 max uniform vectors
  11085. // (up to 54 should be safe)
  11086. var nVertexUniforms = maxVertexUniforms;
  11087. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  11088. var maxBones = Math.min(nVertexMatrices, bones.length);
  11089. if (maxBones < bones.length) {
  11090. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  11091. return 0;
  11092. }
  11093. return maxBones;
  11094. }
  11095. }
  11096. function getTextureEncodingFromMap(map) {
  11097. var encoding;
  11098. if (map && map.isTexture) {
  11099. encoding = map.encoding;
  11100. } else if (map && map.isWebGLRenderTarget) {
  11101. console.warn('THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.');
  11102. encoding = map.texture.encoding;
  11103. } else {
  11104. encoding = LinearEncoding;
  11105. }
  11106. return encoding;
  11107. }
  11108. function getParameters(material, lights, shadows, scene, object) {
  11109. var fog = scene.fog;
  11110. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  11111. var envMap = cubemaps.get(material.envMap || environment);
  11112. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  11113. // (not to blow over maxLights budget)
  11114. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  11115. if (material.precision !== null) {
  11116. precision = capabilities.getMaxPrecision(material.precision);
  11117. if (precision !== material.precision) {
  11118. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  11119. }
  11120. }
  11121. var vertexShader, fragmentShader;
  11122. if (shaderID) {
  11123. var shader = ShaderLib[shaderID];
  11124. vertexShader = shader.vertexShader;
  11125. fragmentShader = shader.fragmentShader;
  11126. } else {
  11127. vertexShader = material.vertexShader;
  11128. fragmentShader = material.fragmentShader;
  11129. }
  11130. var currentRenderTarget = renderer.getRenderTarget();
  11131. var parameters = {
  11132. isWebGL2: isWebGL2,
  11133. shaderID: shaderID,
  11134. shaderName: material.type,
  11135. vertexShader: vertexShader,
  11136. fragmentShader: fragmentShader,
  11137. defines: material.defines,
  11138. isRawShaderMaterial: material.isRawShaderMaterial === true,
  11139. glslVersion: material.glslVersion,
  11140. precision: precision,
  11141. instancing: object.isInstancedMesh === true,
  11142. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  11143. supportsVertexTextures: vertexTextures,
  11144. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  11145. map: !!material.map,
  11146. mapEncoding: getTextureEncodingFromMap(material.map),
  11147. matcap: !!material.matcap,
  11148. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  11149. envMap: !!envMap,
  11150. envMapMode: envMap && envMap.mapping,
  11151. envMapEncoding: getTextureEncodingFromMap(envMap),
  11152. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  11153. lightMap: !!material.lightMap,
  11154. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  11155. aoMap: !!material.aoMap,
  11156. emissiveMap: !!material.emissiveMap,
  11157. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  11158. bumpMap: !!material.bumpMap,
  11159. normalMap: !!material.normalMap,
  11160. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11161. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11162. clearcoatMap: !!material.clearcoatMap,
  11163. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  11164. clearcoatNormalMap: !!material.clearcoatNormalMap,
  11165. displacementMap: !!material.displacementMap,
  11166. roughnessMap: !!material.roughnessMap,
  11167. metalnessMap: !!material.metalnessMap,
  11168. specularMap: !!material.specularMap,
  11169. alphaMap: !!material.alphaMap,
  11170. gradientMap: !!material.gradientMap,
  11171. sheen: !!material.sheen,
  11172. transmissionMap: !!material.transmissionMap,
  11173. combine: material.combine,
  11174. vertexTangents: material.normalMap && material.vertexTangents,
  11175. vertexColors: material.vertexColors,
  11176. 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,
  11177. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  11178. fog: !!fog,
  11179. useFog: material.fog,
  11180. fogExp2: fog && fog.isFogExp2,
  11181. flatShading: material.flatShading,
  11182. sizeAttenuation: material.sizeAttenuation,
  11183. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11184. skinning: material.skinning && maxBones > 0,
  11185. maxBones: maxBones,
  11186. useVertexTexture: floatVertexTextures,
  11187. morphTargets: material.morphTargets,
  11188. morphNormals: material.morphNormals,
  11189. maxMorphTargets: renderer.maxMorphTargets,
  11190. maxMorphNormals: renderer.maxMorphNormals,
  11191. numDirLights: lights.directional.length,
  11192. numPointLights: lights.point.length,
  11193. numSpotLights: lights.spot.length,
  11194. numRectAreaLights: lights.rectArea.length,
  11195. numHemiLights: lights.hemi.length,
  11196. numDirLightShadows: lights.directionalShadowMap.length,
  11197. numPointLightShadows: lights.pointShadowMap.length,
  11198. numSpotLightShadows: lights.spotShadowMap.length,
  11199. numClippingPlanes: clipping.numPlanes,
  11200. numClipIntersection: clipping.numIntersection,
  11201. dithering: material.dithering,
  11202. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11203. shadowMapType: renderer.shadowMap.type,
  11204. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11205. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11206. premultipliedAlpha: material.premultipliedAlpha,
  11207. alphaTest: material.alphaTest,
  11208. doubleSided: material.side === DoubleSide,
  11209. flipSided: material.side === BackSide,
  11210. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11211. index0AttributeName: material.index0AttributeName,
  11212. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11213. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11214. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11215. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11216. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11217. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11218. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11219. customProgramCacheKey: material.customProgramCacheKey()
  11220. };
  11221. return parameters;
  11222. }
  11223. function getProgramCacheKey(parameters) {
  11224. var array = [];
  11225. if (parameters.shaderID) {
  11226. array.push(parameters.shaderID);
  11227. } else {
  11228. array.push(parameters.fragmentShader);
  11229. array.push(parameters.vertexShader);
  11230. }
  11231. if (parameters.defines !== undefined) {
  11232. for (var name in parameters.defines) {
  11233. array.push(name);
  11234. array.push(parameters.defines[name]);
  11235. }
  11236. }
  11237. if (parameters.isRawShaderMaterial === false) {
  11238. for (var i = 0; i < parameterNames.length; i++) {
  11239. array.push(parameters[parameterNames[i]]);
  11240. }
  11241. array.push(renderer.outputEncoding);
  11242. array.push(renderer.gammaFactor);
  11243. }
  11244. array.push(parameters.customProgramCacheKey);
  11245. return array.join();
  11246. }
  11247. function getUniforms(material) {
  11248. var shaderID = shaderIDs[material.type];
  11249. var uniforms;
  11250. if (shaderID) {
  11251. var shader = ShaderLib[shaderID];
  11252. uniforms = UniformsUtils.clone(shader.uniforms);
  11253. } else {
  11254. uniforms = material.uniforms;
  11255. }
  11256. return uniforms;
  11257. }
  11258. function acquireProgram(parameters, cacheKey) {
  11259. var program; // Check if code has been already compiled
  11260. for (var p = 0, pl = programs.length; p < pl; p++) {
  11261. var preexistingProgram = programs[p];
  11262. if (preexistingProgram.cacheKey === cacheKey) {
  11263. program = preexistingProgram;
  11264. ++program.usedTimes;
  11265. break;
  11266. }
  11267. }
  11268. if (program === undefined) {
  11269. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11270. programs.push(program);
  11271. }
  11272. return program;
  11273. }
  11274. function releaseProgram(program) {
  11275. if (--program.usedTimes === 0) {
  11276. // Remove from unordered set
  11277. var i = programs.indexOf(program);
  11278. programs[i] = programs[programs.length - 1];
  11279. programs.pop(); // Free WebGL resources
  11280. program.destroy();
  11281. }
  11282. }
  11283. return {
  11284. getParameters: getParameters,
  11285. getProgramCacheKey: getProgramCacheKey,
  11286. getUniforms: getUniforms,
  11287. acquireProgram: acquireProgram,
  11288. releaseProgram: releaseProgram,
  11289. // Exposed for resource monitoring & error feedback via renderer.info:
  11290. programs: programs
  11291. };
  11292. }
  11293. function WebGLProperties() {
  11294. var properties = new WeakMap();
  11295. function get(object) {
  11296. var map = properties.get(object);
  11297. if (map === undefined) {
  11298. map = {};
  11299. properties.set(object, map);
  11300. }
  11301. return map;
  11302. }
  11303. function remove(object) {
  11304. properties.delete(object);
  11305. }
  11306. function update(object, key, value) {
  11307. properties.get(object)[key] = value;
  11308. }
  11309. function dispose() {
  11310. properties = new WeakMap();
  11311. }
  11312. return {
  11313. get: get,
  11314. remove: remove,
  11315. update: update,
  11316. dispose: dispose
  11317. };
  11318. }
  11319. function painterSortStable(a, b) {
  11320. if (a.groupOrder !== b.groupOrder) {
  11321. return a.groupOrder - b.groupOrder;
  11322. } else if (a.renderOrder !== b.renderOrder) {
  11323. return a.renderOrder - b.renderOrder;
  11324. } else if (a.program !== b.program) {
  11325. return a.program.id - b.program.id;
  11326. } else if (a.material.id !== b.material.id) {
  11327. return a.material.id - b.material.id;
  11328. } else if (a.z !== b.z) {
  11329. return a.z - b.z;
  11330. } else {
  11331. return a.id - b.id;
  11332. }
  11333. }
  11334. function reversePainterSortStable(a, b) {
  11335. if (a.groupOrder !== b.groupOrder) {
  11336. return a.groupOrder - b.groupOrder;
  11337. } else if (a.renderOrder !== b.renderOrder) {
  11338. return a.renderOrder - b.renderOrder;
  11339. } else if (a.z !== b.z) {
  11340. return b.z - a.z;
  11341. } else {
  11342. return a.id - b.id;
  11343. }
  11344. }
  11345. function WebGLRenderList(properties) {
  11346. var renderItems = [];
  11347. var renderItemsIndex = 0;
  11348. var opaque = [];
  11349. var transparent = [];
  11350. var defaultProgram = {
  11351. id: -1
  11352. };
  11353. function init() {
  11354. renderItemsIndex = 0;
  11355. opaque.length = 0;
  11356. transparent.length = 0;
  11357. }
  11358. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11359. var renderItem = renderItems[renderItemsIndex];
  11360. var materialProperties = properties.get(material);
  11361. if (renderItem === undefined) {
  11362. renderItem = {
  11363. id: object.id,
  11364. object: object,
  11365. geometry: geometry,
  11366. material: material,
  11367. program: materialProperties.program || defaultProgram,
  11368. groupOrder: groupOrder,
  11369. renderOrder: object.renderOrder,
  11370. z: z,
  11371. group: group
  11372. };
  11373. renderItems[renderItemsIndex] = renderItem;
  11374. } else {
  11375. renderItem.id = object.id;
  11376. renderItem.object = object;
  11377. renderItem.geometry = geometry;
  11378. renderItem.material = material;
  11379. renderItem.program = materialProperties.program || defaultProgram;
  11380. renderItem.groupOrder = groupOrder;
  11381. renderItem.renderOrder = object.renderOrder;
  11382. renderItem.z = z;
  11383. renderItem.group = group;
  11384. }
  11385. renderItemsIndex++;
  11386. return renderItem;
  11387. }
  11388. function push(object, geometry, material, groupOrder, z, group) {
  11389. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11390. (material.transparent === true ? transparent : opaque).push(renderItem);
  11391. }
  11392. function unshift(object, geometry, material, groupOrder, z, group) {
  11393. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11394. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11395. }
  11396. function sort(customOpaqueSort, customTransparentSort) {
  11397. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11398. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11399. }
  11400. function finish() {
  11401. // Clear references from inactive renderItems in the list
  11402. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11403. var renderItem = renderItems[i];
  11404. if (renderItem.id === null) break;
  11405. renderItem.id = null;
  11406. renderItem.object = null;
  11407. renderItem.geometry = null;
  11408. renderItem.material = null;
  11409. renderItem.program = null;
  11410. renderItem.group = null;
  11411. }
  11412. }
  11413. return {
  11414. opaque: opaque,
  11415. transparent: transparent,
  11416. init: init,
  11417. push: push,
  11418. unshift: unshift,
  11419. finish: finish,
  11420. sort: sort
  11421. };
  11422. }
  11423. function WebGLRenderLists(properties) {
  11424. var lists = new WeakMap();
  11425. function get(scene, camera) {
  11426. var cameras = lists.get(scene);
  11427. var list;
  11428. if (cameras === undefined) {
  11429. list = new WebGLRenderList(properties);
  11430. lists.set(scene, new WeakMap());
  11431. lists.get(scene).set(camera, list);
  11432. } else {
  11433. list = cameras.get(camera);
  11434. if (list === undefined) {
  11435. list = new WebGLRenderList(properties);
  11436. cameras.set(camera, list);
  11437. }
  11438. }
  11439. return list;
  11440. }
  11441. function dispose() {
  11442. lists = new WeakMap();
  11443. }
  11444. return {
  11445. get: get,
  11446. dispose: dispose
  11447. };
  11448. }
  11449. function UniformsCache() {
  11450. var lights = {};
  11451. return {
  11452. get: function get(light) {
  11453. if (lights[light.id] !== undefined) {
  11454. return lights[light.id];
  11455. }
  11456. var uniforms;
  11457. switch (light.type) {
  11458. case 'DirectionalLight':
  11459. uniforms = {
  11460. direction: new Vector3(),
  11461. color: new Color()
  11462. };
  11463. break;
  11464. case 'SpotLight':
  11465. uniforms = {
  11466. position: new Vector3(),
  11467. direction: new Vector3(),
  11468. color: new Color(),
  11469. distance: 0,
  11470. coneCos: 0,
  11471. penumbraCos: 0,
  11472. decay: 0
  11473. };
  11474. break;
  11475. case 'PointLight':
  11476. uniforms = {
  11477. position: new Vector3(),
  11478. color: new Color(),
  11479. distance: 0,
  11480. decay: 0
  11481. };
  11482. break;
  11483. case 'HemisphereLight':
  11484. uniforms = {
  11485. direction: new Vector3(),
  11486. skyColor: new Color(),
  11487. groundColor: new Color()
  11488. };
  11489. break;
  11490. case 'RectAreaLight':
  11491. uniforms = {
  11492. color: new Color(),
  11493. position: new Vector3(),
  11494. halfWidth: new Vector3(),
  11495. halfHeight: new Vector3()
  11496. };
  11497. break;
  11498. }
  11499. lights[light.id] = uniforms;
  11500. return uniforms;
  11501. }
  11502. };
  11503. }
  11504. function ShadowUniformsCache() {
  11505. var lights = {};
  11506. return {
  11507. get: function get(light) {
  11508. if (lights[light.id] !== undefined) {
  11509. return lights[light.id];
  11510. }
  11511. var uniforms;
  11512. switch (light.type) {
  11513. case 'DirectionalLight':
  11514. uniforms = {
  11515. shadowBias: 0,
  11516. shadowNormalBias: 0,
  11517. shadowRadius: 1,
  11518. shadowMapSize: new Vector2()
  11519. };
  11520. break;
  11521. case 'SpotLight':
  11522. uniforms = {
  11523. shadowBias: 0,
  11524. shadowNormalBias: 0,
  11525. shadowRadius: 1,
  11526. shadowMapSize: new Vector2()
  11527. };
  11528. break;
  11529. case 'PointLight':
  11530. uniforms = {
  11531. shadowBias: 0,
  11532. shadowNormalBias: 0,
  11533. shadowRadius: 1,
  11534. shadowMapSize: new Vector2(),
  11535. shadowCameraNear: 1,
  11536. shadowCameraFar: 1000
  11537. };
  11538. break;
  11539. // TODO (abelnation): set RectAreaLight shadow uniforms
  11540. }
  11541. lights[light.id] = uniforms;
  11542. return uniforms;
  11543. }
  11544. };
  11545. }
  11546. var nextVersion = 0;
  11547. function shadowCastingLightsFirst(lightA, lightB) {
  11548. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  11549. }
  11550. function WebGLLights(extensions, capabilities) {
  11551. var cache = new UniformsCache();
  11552. var shadowCache = ShadowUniformsCache();
  11553. var state = {
  11554. version: 0,
  11555. hash: {
  11556. directionalLength: -1,
  11557. pointLength: -1,
  11558. spotLength: -1,
  11559. rectAreaLength: -1,
  11560. hemiLength: -1,
  11561. numDirectionalShadows: -1,
  11562. numPointShadows: -1,
  11563. numSpotShadows: -1
  11564. },
  11565. ambient: [0, 0, 0],
  11566. probe: [],
  11567. directional: [],
  11568. directionalShadow: [],
  11569. directionalShadowMap: [],
  11570. directionalShadowMatrix: [],
  11571. spot: [],
  11572. spotShadow: [],
  11573. spotShadowMap: [],
  11574. spotShadowMatrix: [],
  11575. rectArea: [],
  11576. rectAreaLTC1: null,
  11577. rectAreaLTC2: null,
  11578. point: [],
  11579. pointShadow: [],
  11580. pointShadowMap: [],
  11581. pointShadowMatrix: [],
  11582. hemi: []
  11583. };
  11584. for (var i = 0; i < 9; i++) {
  11585. state.probe.push(new Vector3());
  11586. }
  11587. var vector3 = new Vector3();
  11588. var matrix4 = new Matrix4();
  11589. var matrix42 = new Matrix4();
  11590. function setup(lights) {
  11591. var r = 0,
  11592. g = 0,
  11593. b = 0;
  11594. for (var _i = 0; _i < 9; _i++) {
  11595. state.probe[_i].set(0, 0, 0);
  11596. }
  11597. var directionalLength = 0;
  11598. var pointLength = 0;
  11599. var spotLength = 0;
  11600. var rectAreaLength = 0;
  11601. var hemiLength = 0;
  11602. var numDirectionalShadows = 0;
  11603. var numPointShadows = 0;
  11604. var numSpotShadows = 0;
  11605. lights.sort(shadowCastingLightsFirst);
  11606. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  11607. var light = lights[_i2];
  11608. var color = light.color;
  11609. var intensity = light.intensity;
  11610. var distance = light.distance;
  11611. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  11612. if (light.isAmbientLight) {
  11613. r += color.r * intensity;
  11614. g += color.g * intensity;
  11615. b += color.b * intensity;
  11616. } else if (light.isLightProbe) {
  11617. for (var j = 0; j < 9; j++) {
  11618. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  11619. }
  11620. } else if (light.isDirectionalLight) {
  11621. var uniforms = cache.get(light);
  11622. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  11623. if (light.castShadow) {
  11624. var shadow = light.shadow;
  11625. var shadowUniforms = shadowCache.get(light);
  11626. shadowUniforms.shadowBias = shadow.bias;
  11627. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11628. shadowUniforms.shadowRadius = shadow.radius;
  11629. shadowUniforms.shadowMapSize = shadow.mapSize;
  11630. state.directionalShadow[directionalLength] = shadowUniforms;
  11631. state.directionalShadowMap[directionalLength] = shadowMap;
  11632. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  11633. numDirectionalShadows++;
  11634. }
  11635. state.directional[directionalLength] = uniforms;
  11636. directionalLength++;
  11637. } else if (light.isSpotLight) {
  11638. var _uniforms = cache.get(light);
  11639. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  11640. _uniforms.color.copy(color).multiplyScalar(intensity);
  11641. _uniforms.distance = distance;
  11642. _uniforms.coneCos = Math.cos(light.angle);
  11643. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  11644. _uniforms.decay = light.decay;
  11645. if (light.castShadow) {
  11646. var _shadow = light.shadow;
  11647. var _shadowUniforms = shadowCache.get(light);
  11648. _shadowUniforms.shadowBias = _shadow.bias;
  11649. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  11650. _shadowUniforms.shadowRadius = _shadow.radius;
  11651. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  11652. state.spotShadow[spotLength] = _shadowUniforms;
  11653. state.spotShadowMap[spotLength] = shadowMap;
  11654. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  11655. numSpotShadows++;
  11656. }
  11657. state.spot[spotLength] = _uniforms;
  11658. spotLength++;
  11659. } else if (light.isRectAreaLight) {
  11660. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  11661. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11662. // (b) intensity is the brightness of the light
  11663. _uniforms2.color.copy(color).multiplyScalar(intensity);
  11664. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  11665. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  11666. state.rectArea[rectAreaLength] = _uniforms2;
  11667. rectAreaLength++;
  11668. } else if (light.isPointLight) {
  11669. var _uniforms3 = cache.get(light);
  11670. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  11671. _uniforms3.distance = light.distance;
  11672. _uniforms3.decay = light.decay;
  11673. if (light.castShadow) {
  11674. var _shadow2 = light.shadow;
  11675. var _shadowUniforms2 = shadowCache.get(light);
  11676. _shadowUniforms2.shadowBias = _shadow2.bias;
  11677. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  11678. _shadowUniforms2.shadowRadius = _shadow2.radius;
  11679. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  11680. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  11681. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  11682. state.pointShadow[pointLength] = _shadowUniforms2;
  11683. state.pointShadowMap[pointLength] = shadowMap;
  11684. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  11685. numPointShadows++;
  11686. }
  11687. state.point[pointLength] = _uniforms3;
  11688. pointLength++;
  11689. } else if (light.isHemisphereLight) {
  11690. var _uniforms4 = cache.get(light);
  11691. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  11692. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  11693. state.hemi[hemiLength] = _uniforms4;
  11694. hemiLength++;
  11695. }
  11696. }
  11697. if (rectAreaLength > 0) {
  11698. if (capabilities.isWebGL2) {
  11699. // WebGL 2
  11700. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11701. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11702. } else {
  11703. // WebGL 1
  11704. if (extensions.has('OES_texture_float_linear') === true) {
  11705. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11706. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11707. } else if (extensions.has('OES_texture_half_float_linear') === true) {
  11708. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  11709. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  11710. } else {
  11711. console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
  11712. }
  11713. }
  11714. }
  11715. state.ambient[0] = r;
  11716. state.ambient[1] = g;
  11717. state.ambient[2] = b;
  11718. var hash = state.hash;
  11719. 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) {
  11720. state.directional.length = directionalLength;
  11721. state.spot.length = spotLength;
  11722. state.rectArea.length = rectAreaLength;
  11723. state.point.length = pointLength;
  11724. state.hemi.length = hemiLength;
  11725. state.directionalShadow.length = numDirectionalShadows;
  11726. state.directionalShadowMap.length = numDirectionalShadows;
  11727. state.pointShadow.length = numPointShadows;
  11728. state.pointShadowMap.length = numPointShadows;
  11729. state.spotShadow.length = numSpotShadows;
  11730. state.spotShadowMap.length = numSpotShadows;
  11731. state.directionalShadowMatrix.length = numDirectionalShadows;
  11732. state.pointShadowMatrix.length = numPointShadows;
  11733. state.spotShadowMatrix.length = numSpotShadows;
  11734. hash.directionalLength = directionalLength;
  11735. hash.pointLength = pointLength;
  11736. hash.spotLength = spotLength;
  11737. hash.rectAreaLength = rectAreaLength;
  11738. hash.hemiLength = hemiLength;
  11739. hash.numDirectionalShadows = numDirectionalShadows;
  11740. hash.numPointShadows = numPointShadows;
  11741. hash.numSpotShadows = numSpotShadows;
  11742. state.version = nextVersion++;
  11743. }
  11744. }
  11745. function setupView(lights, camera) {
  11746. var directionalLength = 0;
  11747. var pointLength = 0;
  11748. var spotLength = 0;
  11749. var rectAreaLength = 0;
  11750. var hemiLength = 0;
  11751. var viewMatrix = camera.matrixWorldInverse;
  11752. for (var _i3 = 0, l = lights.length; _i3 < l; _i3++) {
  11753. var light = lights[_i3];
  11754. if (light.isDirectionalLight) {
  11755. var uniforms = state.directional[directionalLength];
  11756. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11757. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11758. uniforms.direction.sub(vector3);
  11759. uniforms.direction.transformDirection(viewMatrix);
  11760. directionalLength++;
  11761. } else if (light.isSpotLight) {
  11762. var _uniforms5 = state.spot[spotLength];
  11763. _uniforms5.position.setFromMatrixPosition(light.matrixWorld);
  11764. _uniforms5.position.applyMatrix4(viewMatrix);
  11765. _uniforms5.direction.setFromMatrixPosition(light.matrixWorld);
  11766. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11767. _uniforms5.direction.sub(vector3);
  11768. _uniforms5.direction.transformDirection(viewMatrix);
  11769. spotLength++;
  11770. } else if (light.isRectAreaLight) {
  11771. var _uniforms6 = state.rectArea[rectAreaLength];
  11772. _uniforms6.position.setFromMatrixPosition(light.matrixWorld);
  11773. _uniforms6.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  11774. matrix42.identity();
  11775. matrix4.copy(light.matrixWorld);
  11776. matrix4.premultiply(viewMatrix);
  11777. matrix42.extractRotation(matrix4);
  11778. _uniforms6.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  11779. _uniforms6.halfHeight.set(0.0, light.height * 0.5, 0.0);
  11780. _uniforms6.halfWidth.applyMatrix4(matrix42);
  11781. _uniforms6.halfHeight.applyMatrix4(matrix42);
  11782. rectAreaLength++;
  11783. } else if (light.isPointLight) {
  11784. var _uniforms7 = state.point[pointLength];
  11785. _uniforms7.position.setFromMatrixPosition(light.matrixWorld);
  11786. _uniforms7.position.applyMatrix4(viewMatrix);
  11787. pointLength++;
  11788. } else if (light.isHemisphereLight) {
  11789. var _uniforms8 = state.hemi[hemiLength];
  11790. _uniforms8.direction.setFromMatrixPosition(light.matrixWorld);
  11791. _uniforms8.direction.transformDirection(viewMatrix);
  11792. _uniforms8.direction.normalize();
  11793. hemiLength++;
  11794. }
  11795. }
  11796. }
  11797. return {
  11798. setup: setup,
  11799. setupView: setupView,
  11800. state: state
  11801. };
  11802. }
  11803. function WebGLRenderState(extensions, capabilities) {
  11804. var lights = new WebGLLights(extensions, capabilities);
  11805. var lightsArray = [];
  11806. var shadowsArray = [];
  11807. function init() {
  11808. lightsArray.length = 0;
  11809. shadowsArray.length = 0;
  11810. }
  11811. function pushLight(light) {
  11812. lightsArray.push(light);
  11813. }
  11814. function pushShadow(shadowLight) {
  11815. shadowsArray.push(shadowLight);
  11816. }
  11817. function setupLights() {
  11818. lights.setup(lightsArray);
  11819. }
  11820. function setupLightsView(camera) {
  11821. lights.setupView(lightsArray, camera);
  11822. }
  11823. var state = {
  11824. lightsArray: lightsArray,
  11825. shadowsArray: shadowsArray,
  11826. lights: lights
  11827. };
  11828. return {
  11829. init: init,
  11830. state: state,
  11831. setupLights: setupLights,
  11832. setupLightsView: setupLightsView,
  11833. pushLight: pushLight,
  11834. pushShadow: pushShadow
  11835. };
  11836. }
  11837. function WebGLRenderStates(extensions, capabilities) {
  11838. var renderStates = new WeakMap();
  11839. function get(scene, renderCallDepth) {
  11840. if (renderCallDepth === void 0) {
  11841. renderCallDepth = 0;
  11842. }
  11843. var renderState;
  11844. if (renderStates.has(scene) === false) {
  11845. renderState = new WebGLRenderState(extensions, capabilities);
  11846. renderStates.set(scene, []);
  11847. renderStates.get(scene).push(renderState);
  11848. } else {
  11849. if (renderCallDepth >= renderStates.get(scene).length) {
  11850. renderState = new WebGLRenderState(extensions, capabilities);
  11851. renderStates.get(scene).push(renderState);
  11852. } else {
  11853. renderState = renderStates.get(scene)[renderCallDepth];
  11854. }
  11855. }
  11856. return renderState;
  11857. }
  11858. function dispose() {
  11859. renderStates = new WeakMap();
  11860. }
  11861. return {
  11862. get: get,
  11863. dispose: dispose
  11864. };
  11865. }
  11866. /**
  11867. * parameters = {
  11868. *
  11869. * opacity: <float>,
  11870. *
  11871. * map: new THREE.Texture( <Image> ),
  11872. *
  11873. * alphaMap: new THREE.Texture( <Image> ),
  11874. *
  11875. * displacementMap: new THREE.Texture( <Image> ),
  11876. * displacementScale: <float>,
  11877. * displacementBias: <float>,
  11878. *
  11879. * wireframe: <boolean>,
  11880. * wireframeLinewidth: <float>
  11881. * }
  11882. */
  11883. function MeshDepthMaterial(parameters) {
  11884. Material.call(this);
  11885. this.type = 'MeshDepthMaterial';
  11886. this.depthPacking = BasicDepthPacking;
  11887. this.skinning = false;
  11888. this.morphTargets = false;
  11889. this.map = null;
  11890. this.alphaMap = null;
  11891. this.displacementMap = null;
  11892. this.displacementScale = 1;
  11893. this.displacementBias = 0;
  11894. this.wireframe = false;
  11895. this.wireframeLinewidth = 1;
  11896. this.fog = false;
  11897. this.setValues(parameters);
  11898. }
  11899. MeshDepthMaterial.prototype = Object.create(Material.prototype);
  11900. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11901. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11902. MeshDepthMaterial.prototype.copy = function (source) {
  11903. Material.prototype.copy.call(this, source);
  11904. this.depthPacking = source.depthPacking;
  11905. this.skinning = source.skinning;
  11906. this.morphTargets = source.morphTargets;
  11907. this.map = source.map;
  11908. this.alphaMap = source.alphaMap;
  11909. this.displacementMap = source.displacementMap;
  11910. this.displacementScale = source.displacementScale;
  11911. this.displacementBias = source.displacementBias;
  11912. this.wireframe = source.wireframe;
  11913. this.wireframeLinewidth = source.wireframeLinewidth;
  11914. return this;
  11915. };
  11916. /**
  11917. * parameters = {
  11918. *
  11919. * referencePosition: <float>,
  11920. * nearDistance: <float>,
  11921. * farDistance: <float>,
  11922. *
  11923. * skinning: <bool>,
  11924. * morphTargets: <bool>,
  11925. *
  11926. * map: new THREE.Texture( <Image> ),
  11927. *
  11928. * alphaMap: new THREE.Texture( <Image> ),
  11929. *
  11930. * displacementMap: new THREE.Texture( <Image> ),
  11931. * displacementScale: <float>,
  11932. * displacementBias: <float>
  11933. *
  11934. * }
  11935. */
  11936. function MeshDistanceMaterial(parameters) {
  11937. Material.call(this);
  11938. this.type = 'MeshDistanceMaterial';
  11939. this.referencePosition = new Vector3();
  11940. this.nearDistance = 1;
  11941. this.farDistance = 1000;
  11942. this.skinning = false;
  11943. this.morphTargets = false;
  11944. this.map = null;
  11945. this.alphaMap = null;
  11946. this.displacementMap = null;
  11947. this.displacementScale = 1;
  11948. this.displacementBias = 0;
  11949. this.fog = false;
  11950. this.setValues(parameters);
  11951. }
  11952. MeshDistanceMaterial.prototype = Object.create(Material.prototype);
  11953. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11954. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11955. MeshDistanceMaterial.prototype.copy = function (source) {
  11956. Material.prototype.copy.call(this, source);
  11957. this.referencePosition.copy(source.referencePosition);
  11958. this.nearDistance = source.nearDistance;
  11959. this.farDistance = source.farDistance;
  11960. this.skinning = source.skinning;
  11961. this.morphTargets = source.morphTargets;
  11962. this.map = source.map;
  11963. this.alphaMap = source.alphaMap;
  11964. this.displacementMap = source.displacementMap;
  11965. this.displacementScale = source.displacementScale;
  11966. this.displacementBias = source.displacementBias;
  11967. return this;
  11968. };
  11969. var vsm_frag = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n\tfor ( float i = -1.0; i < 1.0 ; i += SAMPLE_RATE) {\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, i ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean * HALF_SAMPLE_RATE;\n\tsquared_mean = squared_mean * HALF_SAMPLE_RATE;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";
  11970. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  11971. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  11972. var _frustum = new Frustum();
  11973. var _shadowMapSize = new Vector2(),
  11974. _viewportSize = new Vector2(),
  11975. _viewport = new Vector4(),
  11976. _depthMaterials = [],
  11977. _distanceMaterials = [],
  11978. _materialCache = {};
  11979. var shadowSide = {
  11980. 0: BackSide,
  11981. 1: FrontSide,
  11982. 2: DoubleSide
  11983. };
  11984. var shadowMaterialVertical = new ShaderMaterial({
  11985. defines: {
  11986. SAMPLE_RATE: 2.0 / 8.0,
  11987. HALF_SAMPLE_RATE: 1.0 / 8.0
  11988. },
  11989. uniforms: {
  11990. shadow_pass: {
  11991. value: null
  11992. },
  11993. resolution: {
  11994. value: new Vector2()
  11995. },
  11996. radius: {
  11997. value: 4.0
  11998. }
  11999. },
  12000. vertexShader: vsm_vert,
  12001. fragmentShader: vsm_frag
  12002. });
  12003. var shadowMaterialHorizontal = shadowMaterialVertical.clone();
  12004. shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
  12005. var fullScreenTri = new BufferGeometry();
  12006. fullScreenTri.setAttribute('position', new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  12007. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  12008. var scope = this;
  12009. this.enabled = false;
  12010. this.autoUpdate = true;
  12011. this.needsUpdate = false;
  12012. this.type = PCFShadowMap;
  12013. this.render = function (lights, scene, camera) {
  12014. if (scope.enabled === false) return;
  12015. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  12016. if (lights.length === 0) return;
  12017. var currentRenderTarget = _renderer.getRenderTarget();
  12018. var activeCubeFace = _renderer.getActiveCubeFace();
  12019. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  12020. var _state = _renderer.state; // Set GL state for depth map.
  12021. _state.setBlending(NoBlending);
  12022. _state.buffers.color.setClear(1, 1, 1, 1);
  12023. _state.buffers.depth.setTest(true);
  12024. _state.setScissorTest(false); // render depth map
  12025. for (var i = 0, il = lights.length; i < il; i++) {
  12026. var light = lights[i];
  12027. var shadow = light.shadow;
  12028. if (shadow === undefined) {
  12029. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  12030. continue;
  12031. }
  12032. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  12033. _shadowMapSize.copy(shadow.mapSize);
  12034. var shadowFrameExtents = shadow.getFrameExtents();
  12035. _shadowMapSize.multiply(shadowFrameExtents);
  12036. _viewportSize.copy(shadow.mapSize);
  12037. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  12038. if (_shadowMapSize.x > maxTextureSize) {
  12039. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  12040. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  12041. shadow.mapSize.x = _viewportSize.x;
  12042. }
  12043. if (_shadowMapSize.y > maxTextureSize) {
  12044. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  12045. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  12046. shadow.mapSize.y = _viewportSize.y;
  12047. }
  12048. }
  12049. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12050. var pars = {
  12051. minFilter: LinearFilter,
  12052. magFilter: LinearFilter,
  12053. format: RGBAFormat
  12054. };
  12055. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12056. shadow.map.texture.name = light.name + '.shadowMap';
  12057. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12058. shadow.camera.updateProjectionMatrix();
  12059. }
  12060. if (shadow.map === null) {
  12061. var _pars = {
  12062. minFilter: NearestFilter,
  12063. magFilter: NearestFilter,
  12064. format: RGBAFormat
  12065. };
  12066. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  12067. shadow.map.texture.name = light.name + '.shadowMap';
  12068. shadow.camera.updateProjectionMatrix();
  12069. }
  12070. _renderer.setRenderTarget(shadow.map);
  12071. _renderer.clear();
  12072. var viewportCount = shadow.getViewportCount();
  12073. for (var vp = 0; vp < viewportCount; vp++) {
  12074. var viewport = shadow.getViewport(vp);
  12075. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  12076. _state.viewport(_viewport);
  12077. shadow.updateMatrices(light, vp);
  12078. _frustum = shadow.getFrustum();
  12079. renderObject(scene, camera, shadow.camera, light, this.type);
  12080. } // do blur pass for VSM
  12081. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12082. VSMPass(shadow, camera);
  12083. }
  12084. shadow.needsUpdate = false;
  12085. }
  12086. scope.needsUpdate = false;
  12087. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  12088. };
  12089. function VSMPass(shadow, camera) {
  12090. var geometry = _objects.update(fullScreenMesh); // vertical pass
  12091. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12092. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12093. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12094. _renderer.setRenderTarget(shadow.mapPass);
  12095. _renderer.clear();
  12096. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizontal pass
  12097. shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12098. shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
  12099. shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
  12100. _renderer.setRenderTarget(shadow.map);
  12101. _renderer.clear();
  12102. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null);
  12103. }
  12104. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12105. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12106. var material = _depthMaterials[index];
  12107. if (material === undefined) {
  12108. material = new MeshDepthMaterial({
  12109. depthPacking: RGBADepthPacking,
  12110. morphTargets: useMorphing,
  12111. skinning: useSkinning
  12112. });
  12113. _depthMaterials[index] = material;
  12114. }
  12115. return material;
  12116. }
  12117. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12118. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12119. var material = _distanceMaterials[index];
  12120. if (material === undefined) {
  12121. material = new MeshDistanceMaterial({
  12122. morphTargets: useMorphing,
  12123. skinning: useSkinning
  12124. });
  12125. _distanceMaterials[index] = material;
  12126. }
  12127. return material;
  12128. }
  12129. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  12130. var result = null;
  12131. var getMaterialVariant = getDepthMaterialVariant;
  12132. var customMaterial = object.customDepthMaterial;
  12133. if (light.isPointLight === true) {
  12134. getMaterialVariant = getDistanceMaterialVariant;
  12135. customMaterial = object.customDistanceMaterial;
  12136. }
  12137. if (customMaterial === undefined) {
  12138. var useMorphing = false;
  12139. if (material.morphTargets === true) {
  12140. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12141. }
  12142. var useSkinning = false;
  12143. if (object.isSkinnedMesh === true) {
  12144. if (material.skinning === true) {
  12145. useSkinning = true;
  12146. } else {
  12147. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  12148. }
  12149. }
  12150. var useInstancing = object.isInstancedMesh === true;
  12151. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  12152. } else {
  12153. result = customMaterial;
  12154. }
  12155. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  12156. // in this case we need a unique material instance reflecting the
  12157. // appropriate state
  12158. var keyA = result.uuid,
  12159. keyB = material.uuid;
  12160. var materialsForVariant = _materialCache[keyA];
  12161. if (materialsForVariant === undefined) {
  12162. materialsForVariant = {};
  12163. _materialCache[keyA] = materialsForVariant;
  12164. }
  12165. var cachedMaterial = materialsForVariant[keyB];
  12166. if (cachedMaterial === undefined) {
  12167. cachedMaterial = result.clone();
  12168. materialsForVariant[keyB] = cachedMaterial;
  12169. }
  12170. result = cachedMaterial;
  12171. }
  12172. result.visible = material.visible;
  12173. result.wireframe = material.wireframe;
  12174. if (type === VSMShadowMap) {
  12175. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  12176. } else {
  12177. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  12178. }
  12179. result.clipShadows = material.clipShadows;
  12180. result.clippingPlanes = material.clippingPlanes;
  12181. result.clipIntersection = material.clipIntersection;
  12182. result.wireframeLinewidth = material.wireframeLinewidth;
  12183. result.linewidth = material.linewidth;
  12184. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  12185. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  12186. result.nearDistance = shadowCameraNear;
  12187. result.farDistance = shadowCameraFar;
  12188. }
  12189. return result;
  12190. }
  12191. function renderObject(object, camera, shadowCamera, light, type) {
  12192. if (object.visible === false) return;
  12193. var visible = object.layers.test(camera.layers);
  12194. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  12195. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  12196. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  12197. var geometry = _objects.update(object);
  12198. var material = object.material;
  12199. if (Array.isArray(material)) {
  12200. var groups = geometry.groups;
  12201. for (var k = 0, kl = groups.length; k < kl; k++) {
  12202. var group = groups[k];
  12203. var groupMaterial = material[group.materialIndex];
  12204. if (groupMaterial && groupMaterial.visible) {
  12205. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  12206. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  12207. }
  12208. }
  12209. } else if (material.visible) {
  12210. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  12211. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  12212. }
  12213. }
  12214. }
  12215. var children = object.children;
  12216. for (var i = 0, l = children.length; i < l; i++) {
  12217. renderObject(children[i], camera, shadowCamera, light, type);
  12218. }
  12219. }
  12220. }
  12221. function WebGLState(gl, extensions, capabilities) {
  12222. var _equationToGL, _factorToGL;
  12223. var isWebGL2 = capabilities.isWebGL2;
  12224. function ColorBuffer() {
  12225. var locked = false;
  12226. var color = new Vector4();
  12227. var currentColorMask = null;
  12228. var currentColorClear = new Vector4(0, 0, 0, 0);
  12229. return {
  12230. setMask: function setMask(colorMask) {
  12231. if (currentColorMask !== colorMask && !locked) {
  12232. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12233. currentColorMask = colorMask;
  12234. }
  12235. },
  12236. setLocked: function setLocked(lock) {
  12237. locked = lock;
  12238. },
  12239. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12240. if (premultipliedAlpha === true) {
  12241. r *= a;
  12242. g *= a;
  12243. b *= a;
  12244. }
  12245. color.set(r, g, b, a);
  12246. if (currentColorClear.equals(color) === false) {
  12247. gl.clearColor(r, g, b, a);
  12248. currentColorClear.copy(color);
  12249. }
  12250. },
  12251. reset: function reset() {
  12252. locked = false;
  12253. currentColorMask = null;
  12254. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12255. }
  12256. };
  12257. }
  12258. function DepthBuffer() {
  12259. var locked = false;
  12260. var currentDepthMask = null;
  12261. var currentDepthFunc = null;
  12262. var currentDepthClear = null;
  12263. return {
  12264. setTest: function setTest(depthTest) {
  12265. if (depthTest) {
  12266. enable(2929);
  12267. } else {
  12268. disable(2929);
  12269. }
  12270. },
  12271. setMask: function setMask(depthMask) {
  12272. if (currentDepthMask !== depthMask && !locked) {
  12273. gl.depthMask(depthMask);
  12274. currentDepthMask = depthMask;
  12275. }
  12276. },
  12277. setFunc: function setFunc(depthFunc) {
  12278. if (currentDepthFunc !== depthFunc) {
  12279. if (depthFunc) {
  12280. switch (depthFunc) {
  12281. case NeverDepth:
  12282. gl.depthFunc(512);
  12283. break;
  12284. case AlwaysDepth:
  12285. gl.depthFunc(519);
  12286. break;
  12287. case LessDepth:
  12288. gl.depthFunc(513);
  12289. break;
  12290. case LessEqualDepth:
  12291. gl.depthFunc(515);
  12292. break;
  12293. case EqualDepth:
  12294. gl.depthFunc(514);
  12295. break;
  12296. case GreaterEqualDepth:
  12297. gl.depthFunc(518);
  12298. break;
  12299. case GreaterDepth:
  12300. gl.depthFunc(516);
  12301. break;
  12302. case NotEqualDepth:
  12303. gl.depthFunc(517);
  12304. break;
  12305. default:
  12306. gl.depthFunc(515);
  12307. }
  12308. } else {
  12309. gl.depthFunc(515);
  12310. }
  12311. currentDepthFunc = depthFunc;
  12312. }
  12313. },
  12314. setLocked: function setLocked(lock) {
  12315. locked = lock;
  12316. },
  12317. setClear: function setClear(depth) {
  12318. if (currentDepthClear !== depth) {
  12319. gl.clearDepth(depth);
  12320. currentDepthClear = depth;
  12321. }
  12322. },
  12323. reset: function reset() {
  12324. locked = false;
  12325. currentDepthMask = null;
  12326. currentDepthFunc = null;
  12327. currentDepthClear = null;
  12328. }
  12329. };
  12330. }
  12331. function StencilBuffer() {
  12332. var locked = false;
  12333. var currentStencilMask = null;
  12334. var currentStencilFunc = null;
  12335. var currentStencilRef = null;
  12336. var currentStencilFuncMask = null;
  12337. var currentStencilFail = null;
  12338. var currentStencilZFail = null;
  12339. var currentStencilZPass = null;
  12340. var currentStencilClear = null;
  12341. return {
  12342. setTest: function setTest(stencilTest) {
  12343. if (!locked) {
  12344. if (stencilTest) {
  12345. enable(2960);
  12346. } else {
  12347. disable(2960);
  12348. }
  12349. }
  12350. },
  12351. setMask: function setMask(stencilMask) {
  12352. if (currentStencilMask !== stencilMask && !locked) {
  12353. gl.stencilMask(stencilMask);
  12354. currentStencilMask = stencilMask;
  12355. }
  12356. },
  12357. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12358. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12359. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12360. currentStencilFunc = stencilFunc;
  12361. currentStencilRef = stencilRef;
  12362. currentStencilFuncMask = stencilMask;
  12363. }
  12364. },
  12365. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12366. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12367. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12368. currentStencilFail = stencilFail;
  12369. currentStencilZFail = stencilZFail;
  12370. currentStencilZPass = stencilZPass;
  12371. }
  12372. },
  12373. setLocked: function setLocked(lock) {
  12374. locked = lock;
  12375. },
  12376. setClear: function setClear(stencil) {
  12377. if (currentStencilClear !== stencil) {
  12378. gl.clearStencil(stencil);
  12379. currentStencilClear = stencil;
  12380. }
  12381. },
  12382. reset: function reset() {
  12383. locked = false;
  12384. currentStencilMask = null;
  12385. currentStencilFunc = null;
  12386. currentStencilRef = null;
  12387. currentStencilFuncMask = null;
  12388. currentStencilFail = null;
  12389. currentStencilZFail = null;
  12390. currentStencilZPass = null;
  12391. currentStencilClear = null;
  12392. }
  12393. };
  12394. } //
  12395. var colorBuffer = new ColorBuffer();
  12396. var depthBuffer = new DepthBuffer();
  12397. var stencilBuffer = new StencilBuffer();
  12398. var enabledCapabilities = {};
  12399. var currentProgram = null;
  12400. var currentBlendingEnabled = null;
  12401. var currentBlending = null;
  12402. var currentBlendEquation = null;
  12403. var currentBlendSrc = null;
  12404. var currentBlendDst = null;
  12405. var currentBlendEquationAlpha = null;
  12406. var currentBlendSrcAlpha = null;
  12407. var currentBlendDstAlpha = null;
  12408. var currentPremultipledAlpha = false;
  12409. var currentFlipSided = null;
  12410. var currentCullFace = null;
  12411. var currentLineWidth = null;
  12412. var currentPolygonOffsetFactor = null;
  12413. var currentPolygonOffsetUnits = null;
  12414. var maxTextures = gl.getParameter(35661);
  12415. var lineWidthAvailable = false;
  12416. var version = 0;
  12417. var glVersion = gl.getParameter(7938);
  12418. if (glVersion.indexOf('WebGL') !== -1) {
  12419. version = parseFloat(/^WebGL (\d)/.exec(glVersion)[1]);
  12420. lineWidthAvailable = version >= 1.0;
  12421. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12422. version = parseFloat(/^OpenGL ES (\d)/.exec(glVersion)[1]);
  12423. lineWidthAvailable = version >= 2.0;
  12424. }
  12425. var currentTextureSlot = null;
  12426. var currentBoundTextures = {};
  12427. var currentScissor = new Vector4();
  12428. var currentViewport = new Vector4();
  12429. function createTexture(type, target, count) {
  12430. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12431. var texture = gl.createTexture();
  12432. gl.bindTexture(type, texture);
  12433. gl.texParameteri(type, 10241, 9728);
  12434. gl.texParameteri(type, 10240, 9728);
  12435. for (var i = 0; i < count; i++) {
  12436. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12437. }
  12438. return texture;
  12439. }
  12440. var emptyTextures = {};
  12441. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12442. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12443. colorBuffer.setClear(0, 0, 0, 1);
  12444. depthBuffer.setClear(1);
  12445. stencilBuffer.setClear(0);
  12446. enable(2929);
  12447. depthBuffer.setFunc(LessEqualDepth);
  12448. setFlipSided(false);
  12449. setCullFace(CullFaceBack);
  12450. enable(2884);
  12451. setBlending(NoBlending); //
  12452. function enable(id) {
  12453. if (enabledCapabilities[id] !== true) {
  12454. gl.enable(id);
  12455. enabledCapabilities[id] = true;
  12456. }
  12457. }
  12458. function disable(id) {
  12459. if (enabledCapabilities[id] !== false) {
  12460. gl.disable(id);
  12461. enabledCapabilities[id] = false;
  12462. }
  12463. }
  12464. function useProgram(program) {
  12465. if (currentProgram !== program) {
  12466. gl.useProgram(program);
  12467. currentProgram = program;
  12468. return true;
  12469. }
  12470. return false;
  12471. }
  12472. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12473. if (isWebGL2) {
  12474. equationToGL[MinEquation] = 32775;
  12475. equationToGL[MaxEquation] = 32776;
  12476. } else {
  12477. var extension = extensions.get('EXT_blend_minmax');
  12478. if (extension !== null) {
  12479. equationToGL[MinEquation] = extension.MIN_EXT;
  12480. equationToGL[MaxEquation] = extension.MAX_EXT;
  12481. }
  12482. }
  12483. 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);
  12484. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  12485. if (blending === NoBlending) {
  12486. if (currentBlendingEnabled) {
  12487. disable(3042);
  12488. currentBlendingEnabled = false;
  12489. }
  12490. return;
  12491. }
  12492. if (!currentBlendingEnabled) {
  12493. enable(3042);
  12494. currentBlendingEnabled = true;
  12495. }
  12496. if (blending !== CustomBlending) {
  12497. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  12498. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  12499. gl.blendEquation(32774);
  12500. currentBlendEquation = AddEquation;
  12501. currentBlendEquationAlpha = AddEquation;
  12502. }
  12503. if (premultipliedAlpha) {
  12504. switch (blending) {
  12505. case NormalBlending:
  12506. gl.blendFuncSeparate(1, 771, 1, 771);
  12507. break;
  12508. case AdditiveBlending:
  12509. gl.blendFunc(1, 1);
  12510. break;
  12511. case SubtractiveBlending:
  12512. gl.blendFuncSeparate(0, 0, 769, 771);
  12513. break;
  12514. case MultiplyBlending:
  12515. gl.blendFuncSeparate(0, 768, 0, 770);
  12516. break;
  12517. default:
  12518. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12519. break;
  12520. }
  12521. } else {
  12522. switch (blending) {
  12523. case NormalBlending:
  12524. gl.blendFuncSeparate(770, 771, 1, 771);
  12525. break;
  12526. case AdditiveBlending:
  12527. gl.blendFunc(770, 1);
  12528. break;
  12529. case SubtractiveBlending:
  12530. gl.blendFunc(0, 769);
  12531. break;
  12532. case MultiplyBlending:
  12533. gl.blendFunc(0, 768);
  12534. break;
  12535. default:
  12536. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12537. break;
  12538. }
  12539. }
  12540. currentBlendSrc = null;
  12541. currentBlendDst = null;
  12542. currentBlendSrcAlpha = null;
  12543. currentBlendDstAlpha = null;
  12544. currentBlending = blending;
  12545. currentPremultipledAlpha = premultipliedAlpha;
  12546. }
  12547. return;
  12548. } // custom blending
  12549. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12550. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12551. blendDstAlpha = blendDstAlpha || blendDst;
  12552. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  12553. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  12554. currentBlendEquation = blendEquation;
  12555. currentBlendEquationAlpha = blendEquationAlpha;
  12556. }
  12557. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  12558. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  12559. currentBlendSrc = blendSrc;
  12560. currentBlendDst = blendDst;
  12561. currentBlendSrcAlpha = blendSrcAlpha;
  12562. currentBlendDstAlpha = blendDstAlpha;
  12563. }
  12564. currentBlending = blending;
  12565. currentPremultipledAlpha = null;
  12566. }
  12567. function setMaterial(material, frontFaceCW) {
  12568. material.side === DoubleSide ? disable(2884) : enable(2884);
  12569. var flipSided = material.side === BackSide;
  12570. if (frontFaceCW) flipSided = !flipSided;
  12571. setFlipSided(flipSided);
  12572. 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);
  12573. depthBuffer.setFunc(material.depthFunc);
  12574. depthBuffer.setTest(material.depthTest);
  12575. depthBuffer.setMask(material.depthWrite);
  12576. colorBuffer.setMask(material.colorWrite);
  12577. var stencilWrite = material.stencilWrite;
  12578. stencilBuffer.setTest(stencilWrite);
  12579. if (stencilWrite) {
  12580. stencilBuffer.setMask(material.stencilWriteMask);
  12581. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  12582. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  12583. }
  12584. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  12585. } //
  12586. function setFlipSided(flipSided) {
  12587. if (currentFlipSided !== flipSided) {
  12588. if (flipSided) {
  12589. gl.frontFace(2304);
  12590. } else {
  12591. gl.frontFace(2305);
  12592. }
  12593. currentFlipSided = flipSided;
  12594. }
  12595. }
  12596. function setCullFace(cullFace) {
  12597. if (cullFace !== CullFaceNone) {
  12598. enable(2884);
  12599. if (cullFace !== currentCullFace) {
  12600. if (cullFace === CullFaceBack) {
  12601. gl.cullFace(1029);
  12602. } else if (cullFace === CullFaceFront) {
  12603. gl.cullFace(1028);
  12604. } else {
  12605. gl.cullFace(1032);
  12606. }
  12607. }
  12608. } else {
  12609. disable(2884);
  12610. }
  12611. currentCullFace = cullFace;
  12612. }
  12613. function setLineWidth(width) {
  12614. if (width !== currentLineWidth) {
  12615. if (lineWidthAvailable) gl.lineWidth(width);
  12616. currentLineWidth = width;
  12617. }
  12618. }
  12619. function setPolygonOffset(polygonOffset, factor, units) {
  12620. if (polygonOffset) {
  12621. enable(32823);
  12622. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  12623. gl.polygonOffset(factor, units);
  12624. currentPolygonOffsetFactor = factor;
  12625. currentPolygonOffsetUnits = units;
  12626. }
  12627. } else {
  12628. disable(32823);
  12629. }
  12630. }
  12631. function setScissorTest(scissorTest) {
  12632. if (scissorTest) {
  12633. enable(3089);
  12634. } else {
  12635. disable(3089);
  12636. }
  12637. } // texture
  12638. function activeTexture(webglSlot) {
  12639. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  12640. if (currentTextureSlot !== webglSlot) {
  12641. gl.activeTexture(webglSlot);
  12642. currentTextureSlot = webglSlot;
  12643. }
  12644. }
  12645. function bindTexture(webglType, webglTexture) {
  12646. if (currentTextureSlot === null) {
  12647. activeTexture();
  12648. }
  12649. var boundTexture = currentBoundTextures[currentTextureSlot];
  12650. if (boundTexture === undefined) {
  12651. boundTexture = {
  12652. type: undefined,
  12653. texture: undefined
  12654. };
  12655. currentBoundTextures[currentTextureSlot] = boundTexture;
  12656. }
  12657. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  12658. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  12659. boundTexture.type = webglType;
  12660. boundTexture.texture = webglTexture;
  12661. }
  12662. }
  12663. function unbindTexture() {
  12664. var boundTexture = currentBoundTextures[currentTextureSlot];
  12665. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  12666. gl.bindTexture(boundTexture.type, null);
  12667. boundTexture.type = undefined;
  12668. boundTexture.texture = undefined;
  12669. }
  12670. }
  12671. function compressedTexImage2D() {
  12672. try {
  12673. gl.compressedTexImage2D.apply(gl, arguments);
  12674. } catch (error) {
  12675. console.error('THREE.WebGLState:', error);
  12676. }
  12677. }
  12678. function texImage2D() {
  12679. try {
  12680. gl.texImage2D.apply(gl, arguments);
  12681. } catch (error) {
  12682. console.error('THREE.WebGLState:', error);
  12683. }
  12684. }
  12685. function texImage3D() {
  12686. try {
  12687. gl.texImage3D.apply(gl, arguments);
  12688. } catch (error) {
  12689. console.error('THREE.WebGLState:', error);
  12690. }
  12691. } //
  12692. function scissor(scissor) {
  12693. if (currentScissor.equals(scissor) === false) {
  12694. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  12695. currentScissor.copy(scissor);
  12696. }
  12697. }
  12698. function viewport(viewport) {
  12699. if (currentViewport.equals(viewport) === false) {
  12700. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  12701. currentViewport.copy(viewport);
  12702. }
  12703. } //
  12704. function reset() {
  12705. enabledCapabilities = {};
  12706. currentTextureSlot = null;
  12707. currentBoundTextures = {};
  12708. currentProgram = null;
  12709. currentBlendingEnabled = null;
  12710. currentBlending = null;
  12711. currentBlendEquation = null;
  12712. currentBlendSrc = null;
  12713. currentBlendDst = null;
  12714. currentBlendEquationAlpha = null;
  12715. currentBlendSrcAlpha = null;
  12716. currentBlendDstAlpha = null;
  12717. currentPremultipledAlpha = false;
  12718. currentFlipSided = null;
  12719. currentCullFace = null;
  12720. currentLineWidth = null;
  12721. currentPolygonOffsetFactor = null;
  12722. currentPolygonOffsetUnits = null;
  12723. colorBuffer.reset();
  12724. depthBuffer.reset();
  12725. stencilBuffer.reset();
  12726. }
  12727. return {
  12728. buffers: {
  12729. color: colorBuffer,
  12730. depth: depthBuffer,
  12731. stencil: stencilBuffer
  12732. },
  12733. enable: enable,
  12734. disable: disable,
  12735. useProgram: useProgram,
  12736. setBlending: setBlending,
  12737. setMaterial: setMaterial,
  12738. setFlipSided: setFlipSided,
  12739. setCullFace: setCullFace,
  12740. setLineWidth: setLineWidth,
  12741. setPolygonOffset: setPolygonOffset,
  12742. setScissorTest: setScissorTest,
  12743. activeTexture: activeTexture,
  12744. bindTexture: bindTexture,
  12745. unbindTexture: unbindTexture,
  12746. compressedTexImage2D: compressedTexImage2D,
  12747. texImage2D: texImage2D,
  12748. texImage3D: texImage3D,
  12749. scissor: scissor,
  12750. viewport: viewport,
  12751. reset: reset
  12752. };
  12753. }
  12754. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  12755. var _wrappingToGL, _filterToGL;
  12756. var isWebGL2 = capabilities.isWebGL2;
  12757. var maxTextures = capabilities.maxTextures;
  12758. var maxCubemapSize = capabilities.maxCubemapSize;
  12759. var maxTextureSize = capabilities.maxTextureSize;
  12760. var maxSamples = capabilities.maxSamples;
  12761. var _videoTextures = new WeakMap();
  12762. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  12763. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  12764. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  12765. var useOffscreenCanvas = false;
  12766. try {
  12767. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext('2d') !== null;
  12768. } catch (err) {// Ignore any errors
  12769. }
  12770. function createCanvas(width, height) {
  12771. // Use OffscreenCanvas when available. Specially needed in web workers
  12772. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  12773. }
  12774. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  12775. var scale = 1; // handle case if texture exceeds max size
  12776. if (image.width > maxSize || image.height > maxSize) {
  12777. scale = maxSize / Math.max(image.width, image.height);
  12778. } // only perform resize if necessary
  12779. if (scale < 1 || needsPowerOfTwo === true) {
  12780. // only perform resize for certain image types
  12781. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  12782. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  12783. var width = floor(scale * image.width);
  12784. var height = floor(scale * image.height);
  12785. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  12786. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  12787. canvas.width = width;
  12788. canvas.height = height;
  12789. var context = canvas.getContext('2d');
  12790. context.drawImage(image, 0, 0, width, height);
  12791. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  12792. return canvas;
  12793. } else {
  12794. if ('data' in image) {
  12795. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  12796. }
  12797. return image;
  12798. }
  12799. }
  12800. return image;
  12801. }
  12802. function isPowerOfTwo(image) {
  12803. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  12804. }
  12805. function textureNeedsPowerOfTwo(texture) {
  12806. if (isWebGL2) return false;
  12807. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12808. }
  12809. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  12810. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12811. }
  12812. function generateMipmap(target, texture, width, height) {
  12813. _gl.generateMipmap(target);
  12814. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12815. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  12816. }
  12817. function getInternalFormat(internalFormatName, glFormat, glType) {
  12818. if (isWebGL2 === false) return glFormat;
  12819. if (internalFormatName !== null) {
  12820. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  12821. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  12822. }
  12823. var internalFormat = glFormat;
  12824. if (glFormat === 6403) {
  12825. if (glType === 5126) internalFormat = 33326;
  12826. if (glType === 5131) internalFormat = 33325;
  12827. if (glType === 5121) internalFormat = 33321;
  12828. }
  12829. if (glFormat === 6407) {
  12830. if (glType === 5126) internalFormat = 34837;
  12831. if (glType === 5131) internalFormat = 34843;
  12832. if (glType === 5121) internalFormat = 32849;
  12833. }
  12834. if (glFormat === 6408) {
  12835. if (glType === 5126) internalFormat = 34836;
  12836. if (glType === 5131) internalFormat = 34842;
  12837. if (glType === 5121) internalFormat = 32856;
  12838. }
  12839. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  12840. extensions.get('EXT_color_buffer_float');
  12841. }
  12842. return internalFormat;
  12843. } // Fallback filters for non-power-of-2 textures
  12844. function filterFallback(f) {
  12845. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  12846. return 9728;
  12847. }
  12848. return 9729;
  12849. } //
  12850. function onTextureDispose(event) {
  12851. var texture = event.target;
  12852. texture.removeEventListener('dispose', onTextureDispose);
  12853. deallocateTexture(texture);
  12854. if (texture.isVideoTexture) {
  12855. _videoTextures.delete(texture);
  12856. }
  12857. info.memory.textures--;
  12858. }
  12859. function onRenderTargetDispose(event) {
  12860. var renderTarget = event.target;
  12861. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  12862. deallocateRenderTarget(renderTarget);
  12863. info.memory.textures--;
  12864. } //
  12865. function deallocateTexture(texture) {
  12866. var textureProperties = properties.get(texture);
  12867. if (textureProperties.__webglInit === undefined) return;
  12868. _gl.deleteTexture(textureProperties.__webglTexture);
  12869. properties.remove(texture);
  12870. }
  12871. function deallocateRenderTarget(renderTarget) {
  12872. var renderTargetProperties = properties.get(renderTarget);
  12873. var textureProperties = properties.get(renderTarget.texture);
  12874. if (!renderTarget) return;
  12875. if (textureProperties.__webglTexture !== undefined) {
  12876. _gl.deleteTexture(textureProperties.__webglTexture);
  12877. }
  12878. if (renderTarget.depthTexture) {
  12879. renderTarget.depthTexture.dispose();
  12880. }
  12881. if (renderTarget.isWebGLCubeRenderTarget) {
  12882. for (var i = 0; i < 6; i++) {
  12883. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  12884. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  12885. }
  12886. } else {
  12887. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  12888. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  12889. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  12890. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  12891. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  12892. }
  12893. properties.remove(renderTarget.texture);
  12894. properties.remove(renderTarget);
  12895. } //
  12896. var textureUnits = 0;
  12897. function resetTextureUnits() {
  12898. textureUnits = 0;
  12899. }
  12900. function allocateTextureUnit() {
  12901. var textureUnit = textureUnits;
  12902. if (textureUnit >= maxTextures) {
  12903. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  12904. }
  12905. textureUnits += 1;
  12906. return textureUnit;
  12907. } //
  12908. function setTexture2D(texture, slot) {
  12909. var textureProperties = properties.get(texture);
  12910. if (texture.isVideoTexture) updateVideoTexture(texture);
  12911. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12912. var image = texture.image;
  12913. if (image === undefined) {
  12914. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  12915. } else if (image.complete === false) {
  12916. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  12917. } else {
  12918. uploadTexture(textureProperties, texture, slot);
  12919. return;
  12920. }
  12921. }
  12922. state.activeTexture(33984 + slot);
  12923. state.bindTexture(3553, textureProperties.__webglTexture);
  12924. }
  12925. function setTexture2DArray(texture, slot) {
  12926. var textureProperties = properties.get(texture);
  12927. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12928. uploadTexture(textureProperties, texture, slot);
  12929. return;
  12930. }
  12931. state.activeTexture(33984 + slot);
  12932. state.bindTexture(35866, textureProperties.__webglTexture);
  12933. }
  12934. function setTexture3D(texture, slot) {
  12935. var textureProperties = properties.get(texture);
  12936. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12937. uploadTexture(textureProperties, texture, slot);
  12938. return;
  12939. }
  12940. state.activeTexture(33984 + slot);
  12941. state.bindTexture(32879, textureProperties.__webglTexture);
  12942. }
  12943. function setTextureCube(texture, slot) {
  12944. var textureProperties = properties.get(texture);
  12945. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12946. uploadCubeTexture(textureProperties, texture, slot);
  12947. return;
  12948. }
  12949. state.activeTexture(33984 + slot);
  12950. state.bindTexture(34067, textureProperties.__webglTexture);
  12951. }
  12952. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  12953. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  12954. function setTextureParameters(textureType, texture, supportsMips) {
  12955. if (supportsMips) {
  12956. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  12957. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  12958. if (textureType === 32879 || textureType === 35866) {
  12959. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  12960. }
  12961. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  12962. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  12963. } else {
  12964. _gl.texParameteri(textureType, 10242, 33071);
  12965. _gl.texParameteri(textureType, 10243, 33071);
  12966. if (textureType === 32879 || textureType === 35866) {
  12967. _gl.texParameteri(textureType, 32882, 33071);
  12968. }
  12969. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  12970. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  12971. }
  12972. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  12973. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  12974. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  12975. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  12976. }
  12977. }
  12978. var extension = extensions.get('EXT_texture_filter_anisotropic');
  12979. if (extension) {
  12980. if (texture.type === FloatType && extensions.get('OES_texture_float_linear') === null) return;
  12981. if (texture.type === HalfFloatType && (isWebGL2 || extensions.get('OES_texture_half_float_linear')) === null) return;
  12982. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  12983. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  12984. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  12985. }
  12986. }
  12987. }
  12988. function initTexture(textureProperties, texture) {
  12989. if (textureProperties.__webglInit === undefined) {
  12990. textureProperties.__webglInit = true;
  12991. texture.addEventListener('dispose', onTextureDispose);
  12992. textureProperties.__webglTexture = _gl.createTexture();
  12993. info.memory.textures++;
  12994. }
  12995. }
  12996. function uploadTexture(textureProperties, texture, slot) {
  12997. var textureType = 3553;
  12998. if (texture.isDataTexture2DArray) textureType = 35866;
  12999. if (texture.isDataTexture3D) textureType = 32879;
  13000. initTexture(textureProperties, texture);
  13001. state.activeTexture(33984 + slot);
  13002. state.bindTexture(textureType, textureProperties.__webglTexture);
  13003. _gl.pixelStorei(37440, texture.flipY);
  13004. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13005. _gl.pixelStorei(3317, texture.unpackAlignment);
  13006. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  13007. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  13008. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  13009. glFormat = utils.convert(texture.format);
  13010. var glType = utils.convert(texture.type),
  13011. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13012. setTextureParameters(textureType, texture, supportsMips);
  13013. var mipmap;
  13014. var mipmaps = texture.mipmaps;
  13015. if (texture.isDepthTexture) {
  13016. // populate depth texture with dummy data
  13017. glInternalFormat = 6402;
  13018. if (isWebGL2) {
  13019. if (texture.type === FloatType) {
  13020. glInternalFormat = 36012;
  13021. } else if (texture.type === UnsignedIntType) {
  13022. glInternalFormat = 33190;
  13023. } else if (texture.type === UnsignedInt248Type) {
  13024. glInternalFormat = 35056;
  13025. } else {
  13026. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  13027. }
  13028. } else {
  13029. if (texture.type === FloatType) {
  13030. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  13031. }
  13032. } // validation checks for WebGL 1
  13033. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  13034. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13035. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13036. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13037. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  13038. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  13039. texture.type = UnsignedShortType;
  13040. glType = utils.convert(texture.type);
  13041. }
  13042. }
  13043. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  13044. // Depth stencil textures need the DEPTH_STENCIL internal format
  13045. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13046. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13047. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13048. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13049. if (texture.type !== UnsignedInt248Type) {
  13050. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  13051. texture.type = UnsignedInt248Type;
  13052. glType = utils.convert(texture.type);
  13053. }
  13054. } //
  13055. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  13056. } else if (texture.isDataTexture) {
  13057. // use manually created mipmaps if available
  13058. // if there are no manual mipmaps
  13059. // set 0 level mipmap and then use GL to generate other mipmap levels
  13060. if (mipmaps.length > 0 && supportsMips) {
  13061. for (var i = 0, il = mipmaps.length; i < il; i++) {
  13062. mipmap = mipmaps[i];
  13063. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13064. }
  13065. texture.generateMipmaps = false;
  13066. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13067. } else {
  13068. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  13069. textureProperties.__maxMipLevel = 0;
  13070. }
  13071. } else if (texture.isCompressedTexture) {
  13072. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  13073. mipmap = mipmaps[_i];
  13074. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13075. if (glFormat !== null) {
  13076. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13077. } else {
  13078. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  13079. }
  13080. } else {
  13081. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13082. }
  13083. }
  13084. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13085. } else if (texture.isDataTexture2DArray) {
  13086. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13087. textureProperties.__maxMipLevel = 0;
  13088. } else if (texture.isDataTexture3D) {
  13089. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13090. textureProperties.__maxMipLevel = 0;
  13091. } else {
  13092. // regular Texture (image, video, canvas)
  13093. // use manually created mipmaps if available
  13094. // if there are no manual mipmaps
  13095. // set 0 level mipmap and then use GL to generate other mipmap levels
  13096. if (mipmaps.length > 0 && supportsMips) {
  13097. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  13098. mipmap = mipmaps[_i2];
  13099. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  13100. }
  13101. texture.generateMipmaps = false;
  13102. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13103. } else {
  13104. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  13105. textureProperties.__maxMipLevel = 0;
  13106. }
  13107. }
  13108. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13109. generateMipmap(textureType, texture, image.width, image.height);
  13110. }
  13111. textureProperties.__version = texture.version;
  13112. if (texture.onUpdate) texture.onUpdate(texture);
  13113. }
  13114. function uploadCubeTexture(textureProperties, texture, slot) {
  13115. if (texture.image.length !== 6) return;
  13116. initTexture(textureProperties, texture);
  13117. state.activeTexture(33984 + slot);
  13118. state.bindTexture(34067, textureProperties.__webglTexture);
  13119. _gl.pixelStorei(37440, texture.flipY);
  13120. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  13121. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  13122. var cubeImage = [];
  13123. for (var i = 0; i < 6; i++) {
  13124. if (!isCompressed && !isDataTexture) {
  13125. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  13126. } else {
  13127. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  13128. }
  13129. }
  13130. var image = cubeImage[0],
  13131. supportsMips = isPowerOfTwo(image) || isWebGL2,
  13132. glFormat = utils.convert(texture.format),
  13133. glType = utils.convert(texture.type),
  13134. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13135. setTextureParameters(34067, texture, supportsMips);
  13136. var mipmaps;
  13137. if (isCompressed) {
  13138. for (var _i3 = 0; _i3 < 6; _i3++) {
  13139. mipmaps = cubeImage[_i3].mipmaps;
  13140. for (var j = 0; j < mipmaps.length; j++) {
  13141. var mipmap = mipmaps[j];
  13142. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13143. if (glFormat !== null) {
  13144. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13145. } else {
  13146. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  13147. }
  13148. } else {
  13149. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13150. }
  13151. }
  13152. }
  13153. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13154. } else {
  13155. mipmaps = texture.mipmaps;
  13156. for (var _i4 = 0; _i4 < 6; _i4++) {
  13157. if (isDataTexture) {
  13158. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  13159. for (var _j = 0; _j < mipmaps.length; _j++) {
  13160. var _mipmap = mipmaps[_j];
  13161. var mipmapImage = _mipmap.image[_i4].image;
  13162. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  13163. }
  13164. } else {
  13165. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  13166. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  13167. var _mipmap2 = mipmaps[_j2];
  13168. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  13169. }
  13170. }
  13171. }
  13172. textureProperties.__maxMipLevel = mipmaps.length;
  13173. }
  13174. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13175. // We assume images for cube map have the same size.
  13176. generateMipmap(34067, texture, image.width, image.height);
  13177. }
  13178. textureProperties.__version = texture.version;
  13179. if (texture.onUpdate) texture.onUpdate(texture);
  13180. } // Render targets
  13181. // Setup storage for target texture and bind it to correct framebuffer
  13182. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  13183. var glFormat = utils.convert(renderTarget.texture.format);
  13184. var glType = utils.convert(renderTarget.texture.type);
  13185. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13186. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  13187. _gl.bindFramebuffer(36160, framebuffer);
  13188. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(renderTarget.texture).__webglTexture, 0);
  13189. _gl.bindFramebuffer(36160, null);
  13190. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13191. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  13192. _gl.bindRenderbuffer(36161, renderbuffer);
  13193. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  13194. var glInternalFormat = 33189;
  13195. if (isMultisample) {
  13196. var depthTexture = renderTarget.depthTexture;
  13197. if (depthTexture && depthTexture.isDepthTexture) {
  13198. if (depthTexture.type === FloatType) {
  13199. glInternalFormat = 36012;
  13200. } else if (depthTexture.type === UnsignedIntType) {
  13201. glInternalFormat = 33190;
  13202. }
  13203. }
  13204. var samples = getRenderTargetSamples(renderTarget);
  13205. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13206. } else {
  13207. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  13208. }
  13209. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  13210. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  13211. if (isMultisample) {
  13212. var _samples = getRenderTargetSamples(renderTarget);
  13213. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  13214. } else {
  13215. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  13216. }
  13217. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  13218. } else {
  13219. var glFormat = utils.convert(renderTarget.texture.format);
  13220. var glType = utils.convert(renderTarget.texture.type);
  13221. var _glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13222. if (isMultisample) {
  13223. var _samples2 = getRenderTargetSamples(renderTarget);
  13224. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  13225. } else {
  13226. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  13227. }
  13228. }
  13229. _gl.bindRenderbuffer(36161, null);
  13230. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  13231. function setupDepthTexture(framebuffer, renderTarget) {
  13232. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  13233. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  13234. _gl.bindFramebuffer(36160, framebuffer);
  13235. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  13236. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  13237. } // upload an empty depth texture with framebuffer size
  13238. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  13239. renderTarget.depthTexture.image.width = renderTarget.width;
  13240. renderTarget.depthTexture.image.height = renderTarget.height;
  13241. renderTarget.depthTexture.needsUpdate = true;
  13242. }
  13243. setTexture2D(renderTarget.depthTexture, 0);
  13244. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13245. if (renderTarget.depthTexture.format === DepthFormat) {
  13246. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13247. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13248. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13249. } else {
  13250. throw new Error('Unknown depthTexture format');
  13251. }
  13252. } // Setup GL resources for a non-texture depth buffer
  13253. function setupDepthRenderbuffer(renderTarget) {
  13254. var renderTargetProperties = properties.get(renderTarget);
  13255. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13256. if (renderTarget.depthTexture) {
  13257. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13258. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13259. } else {
  13260. if (isCube) {
  13261. renderTargetProperties.__webglDepthbuffer = [];
  13262. for (var i = 0; i < 6; i++) {
  13263. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13264. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13265. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13266. }
  13267. } else {
  13268. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13269. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13270. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13271. }
  13272. }
  13273. _gl.bindFramebuffer(36160, null);
  13274. } // Set up GL resources for the render target
  13275. function setupRenderTarget(renderTarget) {
  13276. var renderTargetProperties = properties.get(renderTarget);
  13277. var textureProperties = properties.get(renderTarget.texture);
  13278. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13279. textureProperties.__webglTexture = _gl.createTexture();
  13280. info.memory.textures++;
  13281. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13282. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13283. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13284. if (isWebGL2 && renderTarget.texture.format === RGBFormat && (renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType)) {
  13285. renderTarget.texture.format = RGBAFormat;
  13286. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13287. } // Setup framebuffer
  13288. if (isCube) {
  13289. renderTargetProperties.__webglFramebuffer = [];
  13290. for (var i = 0; i < 6; i++) {
  13291. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13292. }
  13293. } else {
  13294. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13295. if (isMultisample) {
  13296. if (isWebGL2) {
  13297. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13298. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13299. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13300. var glFormat = utils.convert(renderTarget.texture.format);
  13301. var glType = utils.convert(renderTarget.texture.type);
  13302. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13303. var samples = getRenderTargetSamples(renderTarget);
  13304. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13305. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13306. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13307. _gl.bindRenderbuffer(36161, null);
  13308. if (renderTarget.depthBuffer) {
  13309. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13310. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13311. }
  13312. _gl.bindFramebuffer(36160, null);
  13313. } else {
  13314. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13315. }
  13316. }
  13317. } // Setup color buffer
  13318. if (isCube) {
  13319. state.bindTexture(34067, textureProperties.__webglTexture);
  13320. setTextureParameters(34067, renderTarget.texture, supportsMips);
  13321. for (var _i5 = 0; _i5 < 6; _i5++) {
  13322. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13323. }
  13324. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13325. generateMipmap(34067, renderTarget.texture, renderTarget.width, renderTarget.height);
  13326. }
  13327. state.bindTexture(34067, null);
  13328. } else {
  13329. state.bindTexture(3553, textureProperties.__webglTexture);
  13330. setTextureParameters(3553, renderTarget.texture, supportsMips);
  13331. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553);
  13332. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13333. generateMipmap(3553, renderTarget.texture, renderTarget.width, renderTarget.height);
  13334. }
  13335. state.bindTexture(3553, null);
  13336. } // Setup depth and stencil buffers
  13337. if (renderTarget.depthBuffer) {
  13338. setupDepthRenderbuffer(renderTarget);
  13339. }
  13340. }
  13341. function updateRenderTargetMipmap(renderTarget) {
  13342. var texture = renderTarget.texture;
  13343. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13344. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13345. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13346. var webglTexture = properties.get(texture).__webglTexture;
  13347. state.bindTexture(target, webglTexture);
  13348. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13349. state.bindTexture(target, null);
  13350. }
  13351. }
  13352. function updateMultisampleRenderTarget(renderTarget) {
  13353. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13354. if (isWebGL2) {
  13355. var renderTargetProperties = properties.get(renderTarget);
  13356. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13357. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13358. var width = renderTarget.width;
  13359. var height = renderTarget.height;
  13360. var mask = 16384;
  13361. if (renderTarget.depthBuffer) mask |= 256;
  13362. if (renderTarget.stencilBuffer) mask |= 1024;
  13363. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13364. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13365. } else {
  13366. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13367. }
  13368. }
  13369. }
  13370. function getRenderTargetSamples(renderTarget) {
  13371. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13372. }
  13373. function updateVideoTexture(texture) {
  13374. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13375. if (_videoTextures.get(texture) !== frame) {
  13376. _videoTextures.set(texture, frame);
  13377. texture.update();
  13378. }
  13379. } // backwards compatibility
  13380. var warnedTexture2D = false;
  13381. var warnedTextureCube = false;
  13382. function safeSetTexture2D(texture, slot) {
  13383. if (texture && texture.isWebGLRenderTarget) {
  13384. if (warnedTexture2D === false) {
  13385. console.warn('THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.');
  13386. warnedTexture2D = true;
  13387. }
  13388. texture = texture.texture;
  13389. }
  13390. setTexture2D(texture, slot);
  13391. }
  13392. function safeSetTextureCube(texture, slot) {
  13393. if (texture && texture.isWebGLCubeRenderTarget) {
  13394. if (warnedTextureCube === false) {
  13395. console.warn('THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.');
  13396. warnedTextureCube = true;
  13397. }
  13398. texture = texture.texture;
  13399. }
  13400. setTextureCube(texture, slot);
  13401. } //
  13402. this.allocateTextureUnit = allocateTextureUnit;
  13403. this.resetTextureUnits = resetTextureUnits;
  13404. this.setTexture2D = setTexture2D;
  13405. this.setTexture2DArray = setTexture2DArray;
  13406. this.setTexture3D = setTexture3D;
  13407. this.setTextureCube = setTextureCube;
  13408. this.setupRenderTarget = setupRenderTarget;
  13409. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13410. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13411. this.safeSetTexture2D = safeSetTexture2D;
  13412. this.safeSetTextureCube = safeSetTextureCube;
  13413. }
  13414. function WebGLUtils(gl, extensions, capabilities) {
  13415. var isWebGL2 = capabilities.isWebGL2;
  13416. function convert(p) {
  13417. var extension;
  13418. if (p === UnsignedByteType) return 5121;
  13419. if (p === UnsignedShort4444Type) return 32819;
  13420. if (p === UnsignedShort5551Type) return 32820;
  13421. if (p === UnsignedShort565Type) return 33635;
  13422. if (p === ByteType) return 5120;
  13423. if (p === ShortType) return 5122;
  13424. if (p === UnsignedShortType) return 5123;
  13425. if (p === IntType) return 5124;
  13426. if (p === UnsignedIntType) return 5125;
  13427. if (p === FloatType) return 5126;
  13428. if (p === HalfFloatType) {
  13429. if (isWebGL2) return 5131;
  13430. extension = extensions.get('OES_texture_half_float');
  13431. if (extension !== null) {
  13432. return extension.HALF_FLOAT_OES;
  13433. } else {
  13434. return null;
  13435. }
  13436. }
  13437. if (p === AlphaFormat) return 6406;
  13438. if (p === RGBFormat) return 6407;
  13439. if (p === RGBAFormat) return 6408;
  13440. if (p === LuminanceFormat) return 6409;
  13441. if (p === LuminanceAlphaFormat) return 6410;
  13442. if (p === DepthFormat) return 6402;
  13443. if (p === DepthStencilFormat) return 34041;
  13444. if (p === RedFormat) return 6403; // WebGL2 formats.
  13445. if (p === RedIntegerFormat) return 36244;
  13446. if (p === RGFormat) return 33319;
  13447. if (p === RGIntegerFormat) return 33320;
  13448. if (p === RGBIntegerFormat) return 36248;
  13449. if (p === RGBAIntegerFormat) return 36249;
  13450. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13451. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13452. if (extension !== null) {
  13453. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13454. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13455. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13456. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13457. } else {
  13458. return null;
  13459. }
  13460. }
  13461. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13462. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13463. if (extension !== null) {
  13464. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13465. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13466. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13467. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13468. } else {
  13469. return null;
  13470. }
  13471. }
  13472. if (p === RGB_ETC1_Format) {
  13473. extension = extensions.get('WEBGL_compressed_texture_etc1');
  13474. if (extension !== null) {
  13475. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13476. } else {
  13477. return null;
  13478. }
  13479. }
  13480. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  13481. extension = extensions.get('WEBGL_compressed_texture_etc');
  13482. if (extension !== null) {
  13483. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  13484. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13485. }
  13486. }
  13487. 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) {
  13488. extension = extensions.get('WEBGL_compressed_texture_astc');
  13489. if (extension !== null) {
  13490. // TODO Complete?
  13491. return p;
  13492. } else {
  13493. return null;
  13494. }
  13495. }
  13496. if (p === RGBA_BPTC_Format) {
  13497. extension = extensions.get('EXT_texture_compression_bptc');
  13498. if (extension !== null) {
  13499. // TODO Complete?
  13500. return p;
  13501. } else {
  13502. return null;
  13503. }
  13504. }
  13505. if (p === UnsignedInt248Type) {
  13506. if (isWebGL2) return 34042;
  13507. extension = extensions.get('WEBGL_depth_texture');
  13508. if (extension !== null) {
  13509. return extension.UNSIGNED_INT_24_8_WEBGL;
  13510. } else {
  13511. return null;
  13512. }
  13513. }
  13514. }
  13515. return {
  13516. convert: convert
  13517. };
  13518. }
  13519. function ArrayCamera(array) {
  13520. if (array === void 0) {
  13521. array = [];
  13522. }
  13523. PerspectiveCamera.call(this);
  13524. this.cameras = array;
  13525. }
  13526. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  13527. constructor: ArrayCamera,
  13528. isArrayCamera: true
  13529. });
  13530. function Group() {
  13531. Object3D.call(this);
  13532. this.type = 'Group';
  13533. }
  13534. Group.prototype = Object.assign(Object.create(Object3D.prototype), {
  13535. constructor: Group,
  13536. isGroup: true
  13537. });
  13538. function WebXRController() {
  13539. this._targetRay = null;
  13540. this._grip = null;
  13541. this._hand = null;
  13542. }
  13543. Object.assign(WebXRController.prototype, {
  13544. constructor: WebXRController,
  13545. getHandSpace: function getHandSpace() {
  13546. if (this._hand === null) {
  13547. this._hand = new Group();
  13548. this._hand.matrixAutoUpdate = false;
  13549. this._hand.visible = false;
  13550. this._hand.joints = [];
  13551. this._hand.inputState = {
  13552. pinching: false
  13553. };
  13554. if (window.XRHand) {
  13555. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13556. // The transform of this joint will be updated with the joint pose on each frame
  13557. var joint = new Group();
  13558. joint.matrixAutoUpdate = false;
  13559. joint.visible = false;
  13560. this._hand.joints.push(joint); // ??
  13561. this._hand.add(joint);
  13562. }
  13563. }
  13564. }
  13565. return this._hand;
  13566. },
  13567. getTargetRaySpace: function getTargetRaySpace() {
  13568. if (this._targetRay === null) {
  13569. this._targetRay = new Group();
  13570. this._targetRay.matrixAutoUpdate = false;
  13571. this._targetRay.visible = false;
  13572. }
  13573. return this._targetRay;
  13574. },
  13575. getGripSpace: function getGripSpace() {
  13576. if (this._grip === null) {
  13577. this._grip = new Group();
  13578. this._grip.matrixAutoUpdate = false;
  13579. this._grip.visible = false;
  13580. }
  13581. return this._grip;
  13582. },
  13583. dispatchEvent: function dispatchEvent(event) {
  13584. if (this._targetRay !== null) {
  13585. this._targetRay.dispatchEvent(event);
  13586. }
  13587. if (this._grip !== null) {
  13588. this._grip.dispatchEvent(event);
  13589. }
  13590. if (this._hand !== null) {
  13591. this._hand.dispatchEvent(event);
  13592. }
  13593. return this;
  13594. },
  13595. disconnect: function disconnect(inputSource) {
  13596. this.dispatchEvent({
  13597. type: 'disconnected',
  13598. data: inputSource
  13599. });
  13600. if (this._targetRay !== null) {
  13601. this._targetRay.visible = false;
  13602. }
  13603. if (this._grip !== null) {
  13604. this._grip.visible = false;
  13605. }
  13606. if (this._hand !== null) {
  13607. this._hand.visible = false;
  13608. }
  13609. return this;
  13610. },
  13611. update: function update(inputSource, frame, referenceSpace) {
  13612. var inputPose = null;
  13613. var gripPose = null;
  13614. var handPose = null;
  13615. var targetRay = this._targetRay;
  13616. var grip = this._grip;
  13617. var hand = this._hand;
  13618. if (inputSource && frame.session.visibilityState !== 'visible-blurred') {
  13619. if (hand && inputSource.hand) {
  13620. handPose = true;
  13621. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13622. if (inputSource.hand[i]) {
  13623. // Update the joints groups with the XRJoint poses
  13624. var jointPose = frame.getJointPose(inputSource.hand[i], referenceSpace);
  13625. var joint = hand.joints[i];
  13626. if (jointPose !== null) {
  13627. joint.matrix.fromArray(jointPose.transform.matrix);
  13628. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  13629. joint.jointRadius = jointPose.radius;
  13630. }
  13631. joint.visible = jointPose !== null; // Custom events
  13632. // Check pinch
  13633. var indexTip = hand.joints[window.XRHand.INDEX_PHALANX_TIP];
  13634. var thumbTip = hand.joints[window.XRHand.THUMB_PHALANX_TIP];
  13635. var distance = indexTip.position.distanceTo(thumbTip.position);
  13636. var distanceToPinch = 0.02;
  13637. var threshold = 0.005;
  13638. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  13639. hand.inputState.pinching = false;
  13640. this.dispatchEvent({
  13641. type: 'pinchend',
  13642. handedness: inputSource.handedness,
  13643. target: this
  13644. });
  13645. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  13646. hand.inputState.pinching = true;
  13647. this.dispatchEvent({
  13648. type: 'pinchstart',
  13649. handedness: inputSource.handedness,
  13650. target: this
  13651. });
  13652. }
  13653. }
  13654. }
  13655. } else {
  13656. if (targetRay !== null) {
  13657. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  13658. if (inputPose !== null) {
  13659. targetRay.matrix.fromArray(inputPose.transform.matrix);
  13660. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  13661. }
  13662. }
  13663. if (grip !== null && inputSource.gripSpace) {
  13664. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  13665. if (gripPose !== null) {
  13666. grip.matrix.fromArray(gripPose.transform.matrix);
  13667. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  13668. }
  13669. }
  13670. }
  13671. }
  13672. if (targetRay !== null) {
  13673. targetRay.visible = inputPose !== null;
  13674. }
  13675. if (grip !== null) {
  13676. grip.visible = gripPose !== null;
  13677. }
  13678. if (hand !== null) {
  13679. hand.visible = handPose !== null;
  13680. }
  13681. return this;
  13682. }
  13683. });
  13684. function WebXRManager(renderer, gl) {
  13685. var scope = this;
  13686. var session = null;
  13687. var framebufferScaleFactor = 1.0;
  13688. var referenceSpace = null;
  13689. var referenceSpaceType = 'local-floor';
  13690. var pose = null;
  13691. var controllers = [];
  13692. var inputSourcesMap = new Map(); //
  13693. var cameraL = new PerspectiveCamera();
  13694. cameraL.layers.enable(1);
  13695. cameraL.viewport = new Vector4();
  13696. var cameraR = new PerspectiveCamera();
  13697. cameraR.layers.enable(2);
  13698. cameraR.viewport = new Vector4();
  13699. var cameras = [cameraL, cameraR];
  13700. var cameraVR = new ArrayCamera();
  13701. cameraVR.layers.enable(1);
  13702. cameraVR.layers.enable(2);
  13703. var _currentDepthNear = null;
  13704. var _currentDepthFar = null; //
  13705. this.enabled = false;
  13706. this.isPresenting = false;
  13707. this.getController = function (index) {
  13708. var controller = controllers[index];
  13709. if (controller === undefined) {
  13710. controller = new WebXRController();
  13711. controllers[index] = controller;
  13712. }
  13713. return controller.getTargetRaySpace();
  13714. };
  13715. this.getControllerGrip = function (index) {
  13716. var controller = controllers[index];
  13717. if (controller === undefined) {
  13718. controller = new WebXRController();
  13719. controllers[index] = controller;
  13720. }
  13721. return controller.getGripSpace();
  13722. };
  13723. this.getHand = function (index) {
  13724. var controller = controllers[index];
  13725. if (controller === undefined) {
  13726. controller = new WebXRController();
  13727. controllers[index] = controller;
  13728. }
  13729. return controller.getHandSpace();
  13730. }; //
  13731. function onSessionEvent(event) {
  13732. var controller = inputSourcesMap.get(event.inputSource);
  13733. if (controller) {
  13734. controller.dispatchEvent({
  13735. type: event.type,
  13736. data: event.inputSource
  13737. });
  13738. }
  13739. }
  13740. function onSessionEnd() {
  13741. inputSourcesMap.forEach(function (controller, inputSource) {
  13742. controller.disconnect(inputSource);
  13743. });
  13744. inputSourcesMap.clear(); //
  13745. renderer.setFramebuffer(null);
  13746. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  13747. animation.stop();
  13748. scope.isPresenting = false;
  13749. scope.dispatchEvent({
  13750. type: 'sessionend'
  13751. });
  13752. }
  13753. function onRequestReferenceSpace(value) {
  13754. referenceSpace = value;
  13755. animation.setContext(session);
  13756. animation.start();
  13757. scope.isPresenting = true;
  13758. scope.dispatchEvent({
  13759. type: 'sessionstart'
  13760. });
  13761. }
  13762. this.setFramebufferScaleFactor = function (value) {
  13763. framebufferScaleFactor = value;
  13764. if (scope.isPresenting === true) {
  13765. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  13766. }
  13767. };
  13768. this.setReferenceSpaceType = function (value) {
  13769. referenceSpaceType = value;
  13770. if (scope.isPresenting === true) {
  13771. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  13772. }
  13773. };
  13774. this.getReferenceSpace = function () {
  13775. return referenceSpace;
  13776. };
  13777. this.getSession = function () {
  13778. return session;
  13779. };
  13780. this.setSession = function (value) {
  13781. session = value;
  13782. if (session !== null) {
  13783. session.addEventListener('select', onSessionEvent);
  13784. session.addEventListener('selectstart', onSessionEvent);
  13785. session.addEventListener('selectend', onSessionEvent);
  13786. session.addEventListener('squeeze', onSessionEvent);
  13787. session.addEventListener('squeezestart', onSessionEvent);
  13788. session.addEventListener('squeezeend', onSessionEvent);
  13789. session.addEventListener('end', onSessionEnd);
  13790. var attributes = gl.getContextAttributes();
  13791. if (attributes.xrCompatible !== true) {
  13792. gl.makeXRCompatible();
  13793. }
  13794. var layerInit = {
  13795. antialias: attributes.antialias,
  13796. alpha: attributes.alpha,
  13797. depth: attributes.depth,
  13798. stencil: attributes.stencil,
  13799. framebufferScaleFactor: framebufferScaleFactor
  13800. }; // eslint-disable-next-line no-undef
  13801. var baseLayer = new XRWebGLLayer(session, gl, layerInit);
  13802. session.updateRenderState({
  13803. baseLayer: baseLayer
  13804. });
  13805. session.requestReferenceSpace(referenceSpaceType).then(onRequestReferenceSpace); //
  13806. session.addEventListener('inputsourceschange', updateInputSources);
  13807. }
  13808. };
  13809. function updateInputSources(event) {
  13810. var inputSources = session.inputSources; // Assign inputSources to available controllers
  13811. for (var i = 0; i < controllers.length; i++) {
  13812. inputSourcesMap.set(inputSources[i], controllers[i]);
  13813. } // Notify disconnected
  13814. for (var _i = 0; _i < event.removed.length; _i++) {
  13815. var inputSource = event.removed[_i];
  13816. var controller = inputSourcesMap.get(inputSource);
  13817. if (controller) {
  13818. controller.dispatchEvent({
  13819. type: 'disconnected',
  13820. data: inputSource
  13821. });
  13822. inputSourcesMap.delete(inputSource);
  13823. }
  13824. } // Notify connected
  13825. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  13826. var _inputSource = event.added[_i2];
  13827. var _controller = inputSourcesMap.get(_inputSource);
  13828. if (_controller) {
  13829. _controller.dispatchEvent({
  13830. type: 'connected',
  13831. data: _inputSource
  13832. });
  13833. }
  13834. }
  13835. } //
  13836. var cameraLPos = new Vector3();
  13837. var cameraRPos = new Vector3();
  13838. /**
  13839. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13840. * the cameras' projection and world matrices have already been set.
  13841. * And that near and far planes are identical for both cameras.
  13842. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13843. */
  13844. function setProjectionFromUnion(camera, cameraL, cameraR) {
  13845. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  13846. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  13847. var ipd = cameraLPos.distanceTo(cameraRPos);
  13848. var projL = cameraL.projectionMatrix.elements;
  13849. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  13850. // most likely identical top and bottom frustum extents.
  13851. // Use the left camera for these values.
  13852. var near = projL[14] / (projL[10] - 1);
  13853. var far = projL[14] / (projL[10] + 1);
  13854. var topFov = (projL[9] + 1) / projL[5];
  13855. var bottomFov = (projL[9] - 1) / projL[5];
  13856. var leftFov = (projL[8] - 1) / projL[0];
  13857. var rightFov = (projR[8] + 1) / projR[0];
  13858. var left = near * leftFov;
  13859. var right = near * rightFov; // Calculate the new camera's position offset from the
  13860. // left camera. xOffset should be roughly half `ipd`.
  13861. var zOffset = ipd / (-leftFov + rightFov);
  13862. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  13863. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  13864. camera.translateX(xOffset);
  13865. camera.translateZ(zOffset);
  13866. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  13867. camera.matrixWorldInverse.copy(camera.matrixWorld).invert(); // Find the union of the frustum values of the cameras and scale
  13868. // the values so that the near plane's position does not change in world space,
  13869. // although must now be relative to the new union camera.
  13870. var near2 = near + zOffset;
  13871. var far2 = far + zOffset;
  13872. var left2 = left - xOffset;
  13873. var right2 = right + (ipd - xOffset);
  13874. var top2 = topFov * far / far2 * near2;
  13875. var bottom2 = bottomFov * far / far2 * near2;
  13876. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  13877. }
  13878. function updateCamera(camera, parent) {
  13879. if (parent === null) {
  13880. camera.matrixWorld.copy(camera.matrix);
  13881. } else {
  13882. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  13883. }
  13884. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  13885. }
  13886. this.getCamera = function (camera) {
  13887. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  13888. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  13889. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  13890. // Note that the new renderState won't apply until the next frame. See #18320
  13891. session.updateRenderState({
  13892. depthNear: cameraVR.near,
  13893. depthFar: cameraVR.far
  13894. });
  13895. _currentDepthNear = cameraVR.near;
  13896. _currentDepthFar = cameraVR.far;
  13897. }
  13898. var parent = camera.parent;
  13899. var cameras = cameraVR.cameras;
  13900. updateCamera(cameraVR, parent);
  13901. for (var i = 0; i < cameras.length; i++) {
  13902. updateCamera(cameras[i], parent);
  13903. } // update camera and its children
  13904. camera.matrixWorld.copy(cameraVR.matrixWorld);
  13905. var children = camera.children;
  13906. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  13907. children[_i3].updateMatrixWorld(true);
  13908. } // update projection matrix for proper view frustum culling
  13909. if (cameras.length === 2) {
  13910. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  13911. } else {
  13912. // assume single camera setup (AR)
  13913. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  13914. }
  13915. return cameraVR;
  13916. }; // Animation Loop
  13917. var onAnimationFrameCallback = null;
  13918. function onAnimationFrame(time, frame) {
  13919. pose = frame.getViewerPose(referenceSpace);
  13920. if (pose !== null) {
  13921. var views = pose.views;
  13922. var baseLayer = session.renderState.baseLayer;
  13923. renderer.setFramebuffer(baseLayer.framebuffer);
  13924. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  13925. if (views.length !== cameraVR.cameras.length) {
  13926. cameraVR.cameras.length = 0;
  13927. cameraVRNeedsUpdate = true;
  13928. }
  13929. for (var i = 0; i < views.length; i++) {
  13930. var view = views[i];
  13931. var viewport = baseLayer.getViewport(view);
  13932. var camera = cameras[i];
  13933. camera.matrix.fromArray(view.transform.matrix);
  13934. camera.projectionMatrix.fromArray(view.projectionMatrix);
  13935. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  13936. if (i === 0) {
  13937. cameraVR.matrix.copy(camera.matrix);
  13938. }
  13939. if (cameraVRNeedsUpdate === true) {
  13940. cameraVR.cameras.push(camera);
  13941. }
  13942. }
  13943. } //
  13944. var inputSources = session.inputSources;
  13945. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  13946. var controller = controllers[_i4];
  13947. var inputSource = inputSources[_i4];
  13948. controller.update(inputSource, frame, referenceSpace);
  13949. }
  13950. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  13951. }
  13952. var animation = new WebGLAnimation();
  13953. animation.setAnimationLoop(onAnimationFrame);
  13954. this.setAnimationLoop = function (callback) {
  13955. onAnimationFrameCallback = callback;
  13956. };
  13957. this.dispose = function () {};
  13958. }
  13959. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  13960. function WebGLMaterials(properties) {
  13961. function refreshFogUniforms(uniforms, fog) {
  13962. uniforms.fogColor.value.copy(fog.color);
  13963. if (fog.isFog) {
  13964. uniforms.fogNear.value = fog.near;
  13965. uniforms.fogFar.value = fog.far;
  13966. } else if (fog.isFogExp2) {
  13967. uniforms.fogDensity.value = fog.density;
  13968. }
  13969. }
  13970. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  13971. if (material.isMeshBasicMaterial) {
  13972. refreshUniformsCommon(uniforms, material);
  13973. } else if (material.isMeshLambertMaterial) {
  13974. refreshUniformsCommon(uniforms, material);
  13975. refreshUniformsLambert(uniforms, material);
  13976. } else if (material.isMeshToonMaterial) {
  13977. refreshUniformsCommon(uniforms, material);
  13978. refreshUniformsToon(uniforms, material);
  13979. } else if (material.isMeshPhongMaterial) {
  13980. refreshUniformsCommon(uniforms, material);
  13981. refreshUniformsPhong(uniforms, material);
  13982. } else if (material.isMeshStandardMaterial) {
  13983. refreshUniformsCommon(uniforms, material);
  13984. if (material.isMeshPhysicalMaterial) {
  13985. refreshUniformsPhysical(uniforms, material);
  13986. } else {
  13987. refreshUniformsStandard(uniforms, material);
  13988. }
  13989. } else if (material.isMeshMatcapMaterial) {
  13990. refreshUniformsCommon(uniforms, material);
  13991. refreshUniformsMatcap(uniforms, material);
  13992. } else if (material.isMeshDepthMaterial) {
  13993. refreshUniformsCommon(uniforms, material);
  13994. refreshUniformsDepth(uniforms, material);
  13995. } else if (material.isMeshDistanceMaterial) {
  13996. refreshUniformsCommon(uniforms, material);
  13997. refreshUniformsDistance(uniforms, material);
  13998. } else if (material.isMeshNormalMaterial) {
  13999. refreshUniformsCommon(uniforms, material);
  14000. refreshUniformsNormal(uniforms, material);
  14001. } else if (material.isLineBasicMaterial) {
  14002. refreshUniformsLine(uniforms, material);
  14003. if (material.isLineDashedMaterial) {
  14004. refreshUniformsDash(uniforms, material);
  14005. }
  14006. } else if (material.isPointsMaterial) {
  14007. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  14008. } else if (material.isSpriteMaterial) {
  14009. refreshUniformsSprites(uniforms, material);
  14010. } else if (material.isShadowMaterial) {
  14011. uniforms.color.value.copy(material.color);
  14012. uniforms.opacity.value = material.opacity;
  14013. } else if (material.isShaderMaterial) {
  14014. material.uniformsNeedUpdate = false; // #15581
  14015. }
  14016. }
  14017. function refreshUniformsCommon(uniforms, material) {
  14018. uniforms.opacity.value = material.opacity;
  14019. if (material.color) {
  14020. uniforms.diffuse.value.copy(material.color);
  14021. }
  14022. if (material.emissive) {
  14023. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  14024. }
  14025. if (material.map) {
  14026. uniforms.map.value = material.map;
  14027. }
  14028. if (material.alphaMap) {
  14029. uniforms.alphaMap.value = material.alphaMap;
  14030. }
  14031. if (material.specularMap) {
  14032. uniforms.specularMap.value = material.specularMap;
  14033. }
  14034. var envMap = properties.get(material).envMap;
  14035. if (envMap) {
  14036. uniforms.envMap.value = envMap;
  14037. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  14038. uniforms.reflectivity.value = material.reflectivity;
  14039. uniforms.refractionRatio.value = material.refractionRatio;
  14040. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  14041. if (maxMipLevel !== undefined) {
  14042. uniforms.maxMipLevel.value = maxMipLevel;
  14043. }
  14044. }
  14045. if (material.lightMap) {
  14046. uniforms.lightMap.value = material.lightMap;
  14047. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14048. }
  14049. if (material.aoMap) {
  14050. uniforms.aoMap.value = material.aoMap;
  14051. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14052. } // uv repeat and offset setting priorities
  14053. // 1. color map
  14054. // 2. specular map
  14055. // 3. displacementMap map
  14056. // 4. normal map
  14057. // 5. bump map
  14058. // 6. roughnessMap map
  14059. // 7. metalnessMap map
  14060. // 8. alphaMap map
  14061. // 9. emissiveMap map
  14062. // 10. clearcoat map
  14063. // 11. clearcoat normal map
  14064. // 12. clearcoat roughnessMap map
  14065. var uvScaleMap;
  14066. if (material.map) {
  14067. uvScaleMap = material.map;
  14068. } else if (material.specularMap) {
  14069. uvScaleMap = material.specularMap;
  14070. } else if (material.displacementMap) {
  14071. uvScaleMap = material.displacementMap;
  14072. } else if (material.normalMap) {
  14073. uvScaleMap = material.normalMap;
  14074. } else if (material.bumpMap) {
  14075. uvScaleMap = material.bumpMap;
  14076. } else if (material.roughnessMap) {
  14077. uvScaleMap = material.roughnessMap;
  14078. } else if (material.metalnessMap) {
  14079. uvScaleMap = material.metalnessMap;
  14080. } else if (material.alphaMap) {
  14081. uvScaleMap = material.alphaMap;
  14082. } else if (material.emissiveMap) {
  14083. uvScaleMap = material.emissiveMap;
  14084. } else if (material.clearcoatMap) {
  14085. uvScaleMap = material.clearcoatMap;
  14086. } else if (material.clearcoatNormalMap) {
  14087. uvScaleMap = material.clearcoatNormalMap;
  14088. } else if (material.clearcoatRoughnessMap) {
  14089. uvScaleMap = material.clearcoatRoughnessMap;
  14090. }
  14091. if (uvScaleMap !== undefined) {
  14092. // backwards compatibility
  14093. if (uvScaleMap.isWebGLRenderTarget) {
  14094. uvScaleMap = uvScaleMap.texture;
  14095. }
  14096. if (uvScaleMap.matrixAutoUpdate === true) {
  14097. uvScaleMap.updateMatrix();
  14098. }
  14099. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14100. } // uv repeat and offset setting priorities for uv2
  14101. // 1. ao map
  14102. // 2. light map
  14103. var uv2ScaleMap;
  14104. if (material.aoMap) {
  14105. uv2ScaleMap = material.aoMap;
  14106. } else if (material.lightMap) {
  14107. uv2ScaleMap = material.lightMap;
  14108. }
  14109. if (uv2ScaleMap !== undefined) {
  14110. // backwards compatibility
  14111. if (uv2ScaleMap.isWebGLRenderTarget) {
  14112. uv2ScaleMap = uv2ScaleMap.texture;
  14113. }
  14114. if (uv2ScaleMap.matrixAutoUpdate === true) {
  14115. uv2ScaleMap.updateMatrix();
  14116. }
  14117. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  14118. }
  14119. }
  14120. function refreshUniformsLine(uniforms, material) {
  14121. uniforms.diffuse.value.copy(material.color);
  14122. uniforms.opacity.value = material.opacity;
  14123. }
  14124. function refreshUniformsDash(uniforms, material) {
  14125. uniforms.dashSize.value = material.dashSize;
  14126. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14127. uniforms.scale.value = material.scale;
  14128. }
  14129. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  14130. uniforms.diffuse.value.copy(material.color);
  14131. uniforms.opacity.value = material.opacity;
  14132. uniforms.size.value = material.size * pixelRatio;
  14133. uniforms.scale.value = height * 0.5;
  14134. if (material.map) {
  14135. uniforms.map.value = material.map;
  14136. }
  14137. if (material.alphaMap) {
  14138. uniforms.alphaMap.value = material.alphaMap;
  14139. } // uv repeat and offset setting priorities
  14140. // 1. color map
  14141. // 2. alpha map
  14142. var uvScaleMap;
  14143. if (material.map) {
  14144. uvScaleMap = material.map;
  14145. } else if (material.alphaMap) {
  14146. uvScaleMap = material.alphaMap;
  14147. }
  14148. if (uvScaleMap !== undefined) {
  14149. if (uvScaleMap.matrixAutoUpdate === true) {
  14150. uvScaleMap.updateMatrix();
  14151. }
  14152. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14153. }
  14154. }
  14155. function refreshUniformsSprites(uniforms, material) {
  14156. uniforms.diffuse.value.copy(material.color);
  14157. uniforms.opacity.value = material.opacity;
  14158. uniforms.rotation.value = material.rotation;
  14159. if (material.map) {
  14160. uniforms.map.value = material.map;
  14161. }
  14162. if (material.alphaMap) {
  14163. uniforms.alphaMap.value = material.alphaMap;
  14164. } // uv repeat and offset setting priorities
  14165. // 1. color map
  14166. // 2. alpha map
  14167. var uvScaleMap;
  14168. if (material.map) {
  14169. uvScaleMap = material.map;
  14170. } else if (material.alphaMap) {
  14171. uvScaleMap = material.alphaMap;
  14172. }
  14173. if (uvScaleMap !== undefined) {
  14174. if (uvScaleMap.matrixAutoUpdate === true) {
  14175. uvScaleMap.updateMatrix();
  14176. }
  14177. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14178. }
  14179. }
  14180. function refreshUniformsLambert(uniforms, material) {
  14181. if (material.emissiveMap) {
  14182. uniforms.emissiveMap.value = material.emissiveMap;
  14183. }
  14184. }
  14185. function refreshUniformsPhong(uniforms, material) {
  14186. uniforms.specular.value.copy(material.specular);
  14187. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  14188. if (material.emissiveMap) {
  14189. uniforms.emissiveMap.value = material.emissiveMap;
  14190. }
  14191. if (material.bumpMap) {
  14192. uniforms.bumpMap.value = material.bumpMap;
  14193. uniforms.bumpScale.value = material.bumpScale;
  14194. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14195. }
  14196. if (material.normalMap) {
  14197. uniforms.normalMap.value = material.normalMap;
  14198. uniforms.normalScale.value.copy(material.normalScale);
  14199. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14200. }
  14201. if (material.displacementMap) {
  14202. uniforms.displacementMap.value = material.displacementMap;
  14203. uniforms.displacementScale.value = material.displacementScale;
  14204. uniforms.displacementBias.value = material.displacementBias;
  14205. }
  14206. }
  14207. function refreshUniformsToon(uniforms, material) {
  14208. if (material.gradientMap) {
  14209. uniforms.gradientMap.value = material.gradientMap;
  14210. }
  14211. if (material.emissiveMap) {
  14212. uniforms.emissiveMap.value = material.emissiveMap;
  14213. }
  14214. if (material.bumpMap) {
  14215. uniforms.bumpMap.value = material.bumpMap;
  14216. uniforms.bumpScale.value = material.bumpScale;
  14217. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14218. }
  14219. if (material.normalMap) {
  14220. uniforms.normalMap.value = material.normalMap;
  14221. uniforms.normalScale.value.copy(material.normalScale);
  14222. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14223. }
  14224. if (material.displacementMap) {
  14225. uniforms.displacementMap.value = material.displacementMap;
  14226. uniforms.displacementScale.value = material.displacementScale;
  14227. uniforms.displacementBias.value = material.displacementBias;
  14228. }
  14229. }
  14230. function refreshUniformsStandard(uniforms, material) {
  14231. uniforms.roughness.value = material.roughness;
  14232. uniforms.metalness.value = material.metalness;
  14233. if (material.roughnessMap) {
  14234. uniforms.roughnessMap.value = material.roughnessMap;
  14235. }
  14236. if (material.metalnessMap) {
  14237. uniforms.metalnessMap.value = material.metalnessMap;
  14238. }
  14239. if (material.emissiveMap) {
  14240. uniforms.emissiveMap.value = material.emissiveMap;
  14241. }
  14242. if (material.bumpMap) {
  14243. uniforms.bumpMap.value = material.bumpMap;
  14244. uniforms.bumpScale.value = material.bumpScale;
  14245. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14246. }
  14247. if (material.normalMap) {
  14248. uniforms.normalMap.value = material.normalMap;
  14249. uniforms.normalScale.value.copy(material.normalScale);
  14250. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14251. }
  14252. if (material.displacementMap) {
  14253. uniforms.displacementMap.value = material.displacementMap;
  14254. uniforms.displacementScale.value = material.displacementScale;
  14255. uniforms.displacementBias.value = material.displacementBias;
  14256. }
  14257. var envMap = properties.get(material).envMap;
  14258. if (envMap) {
  14259. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14260. uniforms.envMapIntensity.value = material.envMapIntensity;
  14261. }
  14262. }
  14263. function refreshUniformsPhysical(uniforms, material) {
  14264. refreshUniformsStandard(uniforms, material);
  14265. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14266. uniforms.clearcoat.value = material.clearcoat;
  14267. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14268. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14269. if (material.clearcoatMap) {
  14270. uniforms.clearcoatMap.value = material.clearcoatMap;
  14271. }
  14272. if (material.clearcoatRoughnessMap) {
  14273. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14274. }
  14275. if (material.clearcoatNormalMap) {
  14276. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14277. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14278. if (material.side === BackSide) {
  14279. uniforms.clearcoatNormalScale.value.negate();
  14280. }
  14281. }
  14282. uniforms.transmission.value = material.transmission;
  14283. if (material.transmissionMap) {
  14284. uniforms.transmissionMap.value = material.transmissionMap;
  14285. }
  14286. }
  14287. function refreshUniformsMatcap(uniforms, material) {
  14288. if (material.matcap) {
  14289. uniforms.matcap.value = material.matcap;
  14290. }
  14291. if (material.bumpMap) {
  14292. uniforms.bumpMap.value = material.bumpMap;
  14293. uniforms.bumpScale.value = material.bumpScale;
  14294. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14295. }
  14296. if (material.normalMap) {
  14297. uniforms.normalMap.value = material.normalMap;
  14298. uniforms.normalScale.value.copy(material.normalScale);
  14299. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14300. }
  14301. if (material.displacementMap) {
  14302. uniforms.displacementMap.value = material.displacementMap;
  14303. uniforms.displacementScale.value = material.displacementScale;
  14304. uniforms.displacementBias.value = material.displacementBias;
  14305. }
  14306. }
  14307. function refreshUniformsDepth(uniforms, material) {
  14308. if (material.displacementMap) {
  14309. uniforms.displacementMap.value = material.displacementMap;
  14310. uniforms.displacementScale.value = material.displacementScale;
  14311. uniforms.displacementBias.value = material.displacementBias;
  14312. }
  14313. }
  14314. function refreshUniformsDistance(uniforms, material) {
  14315. if (material.displacementMap) {
  14316. uniforms.displacementMap.value = material.displacementMap;
  14317. uniforms.displacementScale.value = material.displacementScale;
  14318. uniforms.displacementBias.value = material.displacementBias;
  14319. }
  14320. uniforms.referencePosition.value.copy(material.referencePosition);
  14321. uniforms.nearDistance.value = material.nearDistance;
  14322. uniforms.farDistance.value = material.farDistance;
  14323. }
  14324. function refreshUniformsNormal(uniforms, material) {
  14325. if (material.bumpMap) {
  14326. uniforms.bumpMap.value = material.bumpMap;
  14327. uniforms.bumpScale.value = material.bumpScale;
  14328. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14329. }
  14330. if (material.normalMap) {
  14331. uniforms.normalMap.value = material.normalMap;
  14332. uniforms.normalScale.value.copy(material.normalScale);
  14333. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14334. }
  14335. if (material.displacementMap) {
  14336. uniforms.displacementMap.value = material.displacementMap;
  14337. uniforms.displacementScale.value = material.displacementScale;
  14338. uniforms.displacementBias.value = material.displacementBias;
  14339. }
  14340. }
  14341. return {
  14342. refreshFogUniforms: refreshFogUniforms,
  14343. refreshMaterialUniforms: refreshMaterialUniforms
  14344. };
  14345. }
  14346. function createCanvasElement() {
  14347. var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  14348. canvas.style.display = 'block';
  14349. return canvas;
  14350. }
  14351. function WebGLRenderer(parameters) {
  14352. parameters = parameters || {};
  14353. var _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  14354. _context = parameters.context !== undefined ? parameters.context : null,
  14355. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14356. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14357. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14358. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14359. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14360. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14361. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14362. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14363. var currentRenderList = null;
  14364. var currentRenderState = null; // render() can be called from within a callback triggered by another render.
  14365. // We track this so that the nested render call gets its state isolated from the parent render call.
  14366. var renderStateStack = []; // public properties
  14367. this.domElement = _canvas; // Debug configuration container
  14368. this.debug = {
  14369. /**
  14370. * Enables error checking and reporting when shader programs are being compiled
  14371. * @type {boolean}
  14372. */
  14373. checkShaderErrors: true
  14374. }; // clearing
  14375. this.autoClear = true;
  14376. this.autoClearColor = true;
  14377. this.autoClearDepth = true;
  14378. this.autoClearStencil = true; // scene graph
  14379. this.sortObjects = true; // user-defined clipping
  14380. this.clippingPlanes = [];
  14381. this.localClippingEnabled = false; // physically based shading
  14382. this.gammaFactor = 2.0; // for backwards compatibility
  14383. this.outputEncoding = LinearEncoding; // physical lights
  14384. this.physicallyCorrectLights = false; // tone mapping
  14385. this.toneMapping = NoToneMapping;
  14386. this.toneMappingExposure = 1.0; // morphs
  14387. this.maxMorphTargets = 8;
  14388. this.maxMorphNormals = 4; // internal properties
  14389. var _this = this;
  14390. var _isContextLost = false; // internal state cache
  14391. var _framebuffer = null;
  14392. var _currentActiveCubeFace = 0;
  14393. var _currentActiveMipmapLevel = 0;
  14394. var _currentRenderTarget = null;
  14395. var _currentFramebuffer = null;
  14396. var _currentMaterialId = -1;
  14397. var _currentCamera = null;
  14398. var _currentViewport = new Vector4();
  14399. var _currentScissor = new Vector4();
  14400. var _currentScissorTest = null; //
  14401. var _width = _canvas.width;
  14402. var _height = _canvas.height;
  14403. var _pixelRatio = 1;
  14404. var _opaqueSort = null;
  14405. var _transparentSort = null;
  14406. var _viewport = new Vector4(0, 0, _width, _height);
  14407. var _scissor = new Vector4(0, 0, _width, _height);
  14408. var _scissorTest = false; // frustum
  14409. var _frustum = new Frustum(); // clipping
  14410. var _clippingEnabled = false;
  14411. var _localClippingEnabled = false; // camera matrices cache
  14412. var _projScreenMatrix = new Matrix4();
  14413. var _vector3 = new Vector3();
  14414. var _emptyScene = {
  14415. background: null,
  14416. fog: null,
  14417. environment: null,
  14418. overrideMaterial: null,
  14419. isScene: true
  14420. };
  14421. function getTargetPixelRatio() {
  14422. return _currentRenderTarget === null ? _pixelRatio : 1;
  14423. } // initialize
  14424. var _gl = _context;
  14425. function getContext(contextNames, contextAttributes) {
  14426. for (var i = 0; i < contextNames.length; i++) {
  14427. var contextName = contextNames[i];
  14428. var context = _canvas.getContext(contextName, contextAttributes);
  14429. if (context !== null) return context;
  14430. }
  14431. return null;
  14432. }
  14433. try {
  14434. var contextAttributes = {
  14435. alpha: _alpha,
  14436. depth: _depth,
  14437. stencil: _stencil,
  14438. antialias: _antialias,
  14439. premultipliedAlpha: _premultipliedAlpha,
  14440. preserveDrawingBuffer: _preserveDrawingBuffer,
  14441. powerPreference: _powerPreference,
  14442. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14443. }; // event listeners must be registered before WebGL context is created, see #12753
  14444. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  14445. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  14446. if (_gl === null) {
  14447. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  14448. if (_this.isWebGL1Renderer === true) {
  14449. contextNames.shift();
  14450. }
  14451. _gl = getContext(contextNames, contextAttributes);
  14452. if (_gl === null) {
  14453. if (getContext(contextNames)) {
  14454. throw new Error('Error creating WebGL context with your selected attributes.');
  14455. } else {
  14456. throw new Error('Error creating WebGL context.');
  14457. }
  14458. }
  14459. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14460. if (_gl.getShaderPrecisionFormat === undefined) {
  14461. _gl.getShaderPrecisionFormat = function () {
  14462. return {
  14463. 'rangeMin': 1,
  14464. 'rangeMax': 1,
  14465. 'precision': 1
  14466. };
  14467. };
  14468. }
  14469. } catch (error) {
  14470. console.error('THREE.WebGLRenderer: ' + error.message);
  14471. throw error;
  14472. }
  14473. var extensions, capabilities, state, info;
  14474. var properties, textures, cubemaps, attributes, geometries, objects;
  14475. var programCache, materials, renderLists, renderStates, clipping;
  14476. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14477. var utils, bindingStates;
  14478. function initGLContext() {
  14479. extensions = new WebGLExtensions(_gl);
  14480. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  14481. if (capabilities.isWebGL2 === false) {
  14482. extensions.get('WEBGL_depth_texture');
  14483. extensions.get('OES_texture_float');
  14484. extensions.get('OES_texture_half_float');
  14485. extensions.get('OES_texture_half_float_linear');
  14486. extensions.get('OES_standard_derivatives');
  14487. extensions.get('OES_element_index_uint');
  14488. extensions.get('OES_vertex_array_object');
  14489. extensions.get('ANGLE_instanced_arrays');
  14490. }
  14491. extensions.get('OES_texture_float_linear');
  14492. utils = new WebGLUtils(_gl, extensions, capabilities);
  14493. state = new WebGLState(_gl, extensions, capabilities);
  14494. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14495. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14496. info = new WebGLInfo(_gl);
  14497. properties = new WebGLProperties();
  14498. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  14499. cubemaps = new WebGLCubeMaps(_this);
  14500. attributes = new WebGLAttributes(_gl, capabilities);
  14501. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  14502. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  14503. objects = new WebGLObjects(_gl, geometries, attributes, info);
  14504. morphtargets = new WebGLMorphtargets(_gl);
  14505. clipping = new WebGLClipping(properties);
  14506. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  14507. materials = new WebGLMaterials(properties);
  14508. renderLists = new WebGLRenderLists(properties);
  14509. renderStates = new WebGLRenderStates(extensions, capabilities);
  14510. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  14511. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  14512. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  14513. info.programs = programCache.programs;
  14514. _this.capabilities = capabilities;
  14515. _this.extensions = extensions;
  14516. _this.properties = properties;
  14517. _this.renderLists = renderLists;
  14518. _this.state = state;
  14519. _this.info = info;
  14520. }
  14521. initGLContext(); // xr
  14522. var xr = new WebXRManager(_this, _gl);
  14523. this.xr = xr; // shadow map
  14524. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  14525. this.shadowMap = shadowMap; // API
  14526. this.getContext = function () {
  14527. return _gl;
  14528. };
  14529. this.getContextAttributes = function () {
  14530. return _gl.getContextAttributes();
  14531. };
  14532. this.forceContextLoss = function () {
  14533. var extension = extensions.get('WEBGL_lose_context');
  14534. if (extension) extension.loseContext();
  14535. };
  14536. this.forceContextRestore = function () {
  14537. var extension = extensions.get('WEBGL_lose_context');
  14538. if (extension) extension.restoreContext();
  14539. };
  14540. this.getPixelRatio = function () {
  14541. return _pixelRatio;
  14542. };
  14543. this.setPixelRatio = function (value) {
  14544. if (value === undefined) return;
  14545. _pixelRatio = value;
  14546. this.setSize(_width, _height, false);
  14547. };
  14548. this.getSize = function (target) {
  14549. if (target === undefined) {
  14550. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  14551. target = new Vector2();
  14552. }
  14553. return target.set(_width, _height);
  14554. };
  14555. this.setSize = function (width, height, updateStyle) {
  14556. if (xr.isPresenting) {
  14557. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  14558. return;
  14559. }
  14560. _width = width;
  14561. _height = height;
  14562. _canvas.width = Math.floor(width * _pixelRatio);
  14563. _canvas.height = Math.floor(height * _pixelRatio);
  14564. if (updateStyle !== false) {
  14565. _canvas.style.width = width + 'px';
  14566. _canvas.style.height = height + 'px';
  14567. }
  14568. this.setViewport(0, 0, width, height);
  14569. };
  14570. this.getDrawingBufferSize = function (target) {
  14571. if (target === undefined) {
  14572. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  14573. target = new Vector2();
  14574. }
  14575. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  14576. };
  14577. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  14578. _width = width;
  14579. _height = height;
  14580. _pixelRatio = pixelRatio;
  14581. _canvas.width = Math.floor(width * pixelRatio);
  14582. _canvas.height = Math.floor(height * pixelRatio);
  14583. this.setViewport(0, 0, width, height);
  14584. };
  14585. this.getCurrentViewport = function (target) {
  14586. if (target === undefined) {
  14587. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  14588. target = new Vector4();
  14589. }
  14590. return target.copy(_currentViewport);
  14591. };
  14592. this.getViewport = function (target) {
  14593. return target.copy(_viewport);
  14594. };
  14595. this.setViewport = function (x, y, width, height) {
  14596. if (x.isVector4) {
  14597. _viewport.set(x.x, x.y, x.z, x.w);
  14598. } else {
  14599. _viewport.set(x, y, width, height);
  14600. }
  14601. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14602. };
  14603. this.getScissor = function (target) {
  14604. return target.copy(_scissor);
  14605. };
  14606. this.setScissor = function (x, y, width, height) {
  14607. if (x.isVector4) {
  14608. _scissor.set(x.x, x.y, x.z, x.w);
  14609. } else {
  14610. _scissor.set(x, y, width, height);
  14611. }
  14612. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14613. };
  14614. this.getScissorTest = function () {
  14615. return _scissorTest;
  14616. };
  14617. this.setScissorTest = function (boolean) {
  14618. state.setScissorTest(_scissorTest = boolean);
  14619. };
  14620. this.setOpaqueSort = function (method) {
  14621. _opaqueSort = method;
  14622. };
  14623. this.setTransparentSort = function (method) {
  14624. _transparentSort = method;
  14625. }; // Clearing
  14626. this.getClearColor = function (target) {
  14627. if (target === undefined) {
  14628. console.warn('WebGLRenderer: .getClearColor() now requires a Color as an argument');
  14629. target = new Color();
  14630. }
  14631. return target.copy(background.getClearColor());
  14632. };
  14633. this.setClearColor = function () {
  14634. background.setClearColor.apply(background, arguments);
  14635. };
  14636. this.getClearAlpha = function () {
  14637. return background.getClearAlpha();
  14638. };
  14639. this.setClearAlpha = function () {
  14640. background.setClearAlpha.apply(background, arguments);
  14641. };
  14642. this.clear = function (color, depth, stencil) {
  14643. var bits = 0;
  14644. if (color === undefined || color) bits |= 16384;
  14645. if (depth === undefined || depth) bits |= 256;
  14646. if (stencil === undefined || stencil) bits |= 1024;
  14647. _gl.clear(bits);
  14648. };
  14649. this.clearColor = function () {
  14650. this.clear(true, false, false);
  14651. };
  14652. this.clearDepth = function () {
  14653. this.clear(false, true, false);
  14654. };
  14655. this.clearStencil = function () {
  14656. this.clear(false, false, true);
  14657. }; //
  14658. this.dispose = function () {
  14659. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  14660. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  14661. renderLists.dispose();
  14662. renderStates.dispose();
  14663. properties.dispose();
  14664. cubemaps.dispose();
  14665. objects.dispose();
  14666. bindingStates.dispose();
  14667. xr.dispose();
  14668. animation.stop();
  14669. }; // Events
  14670. function onContextLost(event) {
  14671. event.preventDefault();
  14672. console.log('THREE.WebGLRenderer: Context Lost.');
  14673. _isContextLost = true;
  14674. }
  14675. function onContextRestore()
  14676. /* event */
  14677. {
  14678. console.log('THREE.WebGLRenderer: Context Restored.');
  14679. _isContextLost = false;
  14680. initGLContext();
  14681. }
  14682. function onMaterialDispose(event) {
  14683. var material = event.target;
  14684. material.removeEventListener('dispose', onMaterialDispose);
  14685. deallocateMaterial(material);
  14686. } // Buffer deallocation
  14687. function deallocateMaterial(material) {
  14688. releaseMaterialProgramReference(material);
  14689. properties.remove(material);
  14690. }
  14691. function releaseMaterialProgramReference(material) {
  14692. var programInfo = properties.get(material).program;
  14693. if (programInfo !== undefined) {
  14694. programCache.releaseProgram(programInfo);
  14695. }
  14696. } // Buffer rendering
  14697. function renderObjectImmediate(object, program) {
  14698. object.render(function (object) {
  14699. _this.renderBufferImmediate(object, program);
  14700. });
  14701. }
  14702. this.renderBufferImmediate = function (object, program) {
  14703. bindingStates.initAttributes();
  14704. var buffers = properties.get(object);
  14705. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  14706. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  14707. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  14708. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  14709. var programAttributes = program.getAttributes();
  14710. if (object.hasPositions) {
  14711. _gl.bindBuffer(34962, buffers.position);
  14712. _gl.bufferData(34962, object.positionArray, 35048);
  14713. bindingStates.enableAttribute(programAttributes.position);
  14714. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  14715. }
  14716. if (object.hasNormals) {
  14717. _gl.bindBuffer(34962, buffers.normal);
  14718. _gl.bufferData(34962, object.normalArray, 35048);
  14719. bindingStates.enableAttribute(programAttributes.normal);
  14720. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  14721. }
  14722. if (object.hasUvs) {
  14723. _gl.bindBuffer(34962, buffers.uv);
  14724. _gl.bufferData(34962, object.uvArray, 35048);
  14725. bindingStates.enableAttribute(programAttributes.uv);
  14726. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  14727. }
  14728. if (object.hasColors) {
  14729. _gl.bindBuffer(34962, buffers.color);
  14730. _gl.bufferData(34962, object.colorArray, 35048);
  14731. bindingStates.enableAttribute(programAttributes.color);
  14732. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  14733. }
  14734. bindingStates.disableUnusedAttributes();
  14735. _gl.drawArrays(4, 0, object.count);
  14736. object.count = 0;
  14737. };
  14738. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  14739. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  14740. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  14741. var program = setProgram(camera, scene, material, object);
  14742. state.setMaterial(material, frontFaceCW); //
  14743. var index = geometry.index;
  14744. var position = geometry.attributes.position; //
  14745. if (index === null) {
  14746. if (position === undefined || position.count === 0) return;
  14747. } else if (index.count === 0) {
  14748. return;
  14749. } //
  14750. var rangeFactor = 1;
  14751. if (material.wireframe === true) {
  14752. index = geometries.getWireframeAttribute(geometry);
  14753. rangeFactor = 2;
  14754. }
  14755. if (material.morphTargets || material.morphNormals) {
  14756. morphtargets.update(object, geometry, material, program);
  14757. }
  14758. bindingStates.setup(object, material, program, geometry, index);
  14759. var attribute;
  14760. var renderer = bufferRenderer;
  14761. if (index !== null) {
  14762. attribute = attributes.get(index);
  14763. renderer = indexedBufferRenderer;
  14764. renderer.setIndex(attribute);
  14765. } //
  14766. var dataCount = index !== null ? index.count : position.count;
  14767. var rangeStart = geometry.drawRange.start * rangeFactor;
  14768. var rangeCount = geometry.drawRange.count * rangeFactor;
  14769. var groupStart = group !== null ? group.start * rangeFactor : 0;
  14770. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14771. var drawStart = Math.max(rangeStart, groupStart);
  14772. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  14773. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  14774. if (drawCount === 0) return; //
  14775. if (object.isMesh) {
  14776. if (material.wireframe === true) {
  14777. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  14778. renderer.setMode(1);
  14779. } else {
  14780. renderer.setMode(4);
  14781. }
  14782. } else if (object.isLine) {
  14783. var lineWidth = material.linewidth;
  14784. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  14785. state.setLineWidth(lineWidth * getTargetPixelRatio());
  14786. if (object.isLineSegments) {
  14787. renderer.setMode(1);
  14788. } else if (object.isLineLoop) {
  14789. renderer.setMode(2);
  14790. } else {
  14791. renderer.setMode(3);
  14792. }
  14793. } else if (object.isPoints) {
  14794. renderer.setMode(0);
  14795. } else if (object.isSprite) {
  14796. renderer.setMode(4);
  14797. }
  14798. if (object.isInstancedMesh) {
  14799. renderer.renderInstances(drawStart, drawCount, object.count);
  14800. } else if (geometry.isInstancedBufferGeometry) {
  14801. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  14802. renderer.renderInstances(drawStart, drawCount, instanceCount);
  14803. } else {
  14804. renderer.render(drawStart, drawCount);
  14805. }
  14806. }; // Compile
  14807. this.compile = function (scene, camera) {
  14808. currentRenderState = renderStates.get(scene);
  14809. currentRenderState.init();
  14810. scene.traverseVisible(function (object) {
  14811. if (object.isLight && object.layers.test(camera.layers)) {
  14812. currentRenderState.pushLight(object);
  14813. if (object.castShadow) {
  14814. currentRenderState.pushShadow(object);
  14815. }
  14816. }
  14817. });
  14818. currentRenderState.setupLights();
  14819. var compiled = new WeakMap();
  14820. scene.traverse(function (object) {
  14821. var material = object.material;
  14822. if (material) {
  14823. if (Array.isArray(material)) {
  14824. for (var i = 0; i < material.length; i++) {
  14825. var material2 = material[i];
  14826. if (compiled.has(material2) === false) {
  14827. initMaterial(material2, scene, object);
  14828. compiled.set(material2);
  14829. }
  14830. }
  14831. } else if (compiled.has(material) === false) {
  14832. initMaterial(material, scene, object);
  14833. compiled.set(material);
  14834. }
  14835. }
  14836. });
  14837. }; // Animation Loop
  14838. var onAnimationFrameCallback = null;
  14839. function onAnimationFrame(time) {
  14840. if (xr.isPresenting) return;
  14841. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  14842. }
  14843. var animation = new WebGLAnimation();
  14844. animation.setAnimationLoop(onAnimationFrame);
  14845. if (typeof window !== 'undefined') animation.setContext(window);
  14846. this.setAnimationLoop = function (callback) {
  14847. onAnimationFrameCallback = callback;
  14848. xr.setAnimationLoop(callback);
  14849. callback === null ? animation.stop() : animation.start();
  14850. }; // Rendering
  14851. this.render = function (scene, camera) {
  14852. var renderTarget, forceClear;
  14853. if (arguments[2] !== undefined) {
  14854. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  14855. renderTarget = arguments[2];
  14856. }
  14857. if (arguments[3] !== undefined) {
  14858. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  14859. forceClear = arguments[3];
  14860. }
  14861. if (camera !== undefined && camera.isCamera !== true) {
  14862. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  14863. return;
  14864. }
  14865. if (_isContextLost === true) return; // reset caching for this frame
  14866. bindingStates.resetDefaultState();
  14867. _currentMaterialId = -1;
  14868. _currentCamera = null; // update scene graph
  14869. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  14870. if (camera.parent === null) camera.updateMatrixWorld();
  14871. if (xr.enabled === true && xr.isPresenting === true) {
  14872. camera = xr.getCamera(camera);
  14873. } //
  14874. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  14875. currentRenderState = renderStates.get(scene, renderStateStack.length);
  14876. currentRenderState.init();
  14877. renderStateStack.push(currentRenderState);
  14878. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  14879. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  14880. _localClippingEnabled = this.localClippingEnabled;
  14881. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  14882. currentRenderList = renderLists.get(scene, camera);
  14883. currentRenderList.init();
  14884. projectObject(scene, camera, 0, _this.sortObjects);
  14885. currentRenderList.finish();
  14886. if (_this.sortObjects === true) {
  14887. currentRenderList.sort(_opaqueSort, _transparentSort);
  14888. } //
  14889. if (_clippingEnabled === true) clipping.beginShadows();
  14890. var shadowsArray = currentRenderState.state.shadowsArray;
  14891. shadowMap.render(shadowsArray, scene, camera);
  14892. currentRenderState.setupLights();
  14893. currentRenderState.setupLightsView(camera);
  14894. if (_clippingEnabled === true) clipping.endShadows(); //
  14895. if (this.info.autoReset === true) this.info.reset();
  14896. if (renderTarget !== undefined) {
  14897. this.setRenderTarget(renderTarget);
  14898. } //
  14899. background.render(currentRenderList, scene, camera, forceClear); // render scene
  14900. var opaqueObjects = currentRenderList.opaque;
  14901. var transparentObjects = currentRenderList.transparent;
  14902. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  14903. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  14904. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  14905. if (_currentRenderTarget !== null) {
  14906. // Generate mipmap if we're using any kind of mipmap filtering
  14907. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  14908. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  14909. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  14910. state.buffers.depth.setTest(true);
  14911. state.buffers.depth.setMask(true);
  14912. state.buffers.color.setMask(true);
  14913. state.setPolygonOffset(false); // _gl.finish();
  14914. renderStateStack.pop();
  14915. if (renderStateStack.length > 0) {
  14916. currentRenderState = renderStateStack[renderStateStack.length - 1];
  14917. } else {
  14918. currentRenderState = null;
  14919. }
  14920. currentRenderList = null;
  14921. };
  14922. function projectObject(object, camera, groupOrder, sortObjects) {
  14923. if (object.visible === false) return;
  14924. var visible = object.layers.test(camera.layers);
  14925. if (visible) {
  14926. if (object.isGroup) {
  14927. groupOrder = object.renderOrder;
  14928. } else if (object.isLOD) {
  14929. if (object.autoUpdate === true) object.update(camera);
  14930. } else if (object.isLight) {
  14931. currentRenderState.pushLight(object);
  14932. if (object.castShadow) {
  14933. currentRenderState.pushShadow(object);
  14934. }
  14935. } else if (object.isSprite) {
  14936. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  14937. if (sortObjects) {
  14938. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14939. }
  14940. var geometry = objects.update(object);
  14941. var material = object.material;
  14942. if (material.visible) {
  14943. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  14944. }
  14945. }
  14946. } else if (object.isImmediateRenderObject) {
  14947. if (sortObjects) {
  14948. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14949. }
  14950. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  14951. } else if (object.isMesh || object.isLine || object.isPoints) {
  14952. if (object.isSkinnedMesh) {
  14953. // update skeleton only once in a frame
  14954. if (object.skeleton.frame !== info.render.frame) {
  14955. object.skeleton.update();
  14956. object.skeleton.frame = info.render.frame;
  14957. }
  14958. }
  14959. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  14960. if (sortObjects) {
  14961. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14962. }
  14963. var _geometry = objects.update(object);
  14964. var _material = object.material;
  14965. if (Array.isArray(_material)) {
  14966. var groups = _geometry.groups;
  14967. for (var i = 0, l = groups.length; i < l; i++) {
  14968. var group = groups[i];
  14969. var groupMaterial = _material[group.materialIndex];
  14970. if (groupMaterial && groupMaterial.visible) {
  14971. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  14972. }
  14973. }
  14974. } else if (_material.visible) {
  14975. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  14976. }
  14977. }
  14978. }
  14979. }
  14980. var children = object.children;
  14981. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  14982. projectObject(children[_i], camera, groupOrder, sortObjects);
  14983. }
  14984. }
  14985. function renderObjects(renderList, scene, camera) {
  14986. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  14987. for (var i = 0, l = renderList.length; i < l; i++) {
  14988. var renderItem = renderList[i];
  14989. var object = renderItem.object;
  14990. var geometry = renderItem.geometry;
  14991. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  14992. var group = renderItem.group;
  14993. if (camera.isArrayCamera) {
  14994. var cameras = camera.cameras;
  14995. for (var j = 0, jl = cameras.length; j < jl; j++) {
  14996. var camera2 = cameras[j];
  14997. if (object.layers.test(camera2.layers)) {
  14998. state.viewport(_currentViewport.copy(camera2.viewport));
  14999. currentRenderState.setupLightsView(camera2);
  15000. renderObject(object, scene, camera2, geometry, material, group);
  15001. }
  15002. }
  15003. } else {
  15004. renderObject(object, scene, camera, geometry, material, group);
  15005. }
  15006. }
  15007. }
  15008. function renderObject(object, scene, camera, geometry, material, group) {
  15009. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  15010. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  15011. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  15012. if (object.isImmediateRenderObject) {
  15013. var program = setProgram(camera, scene, material, object);
  15014. state.setMaterial(material);
  15015. bindingStates.reset();
  15016. renderObjectImmediate(object, program);
  15017. } else {
  15018. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  15019. }
  15020. object.onAfterRender(_this, scene, camera, geometry, material, group);
  15021. }
  15022. function initMaterial(material, scene, object) {
  15023. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15024. var materialProperties = properties.get(material);
  15025. var lights = currentRenderState.state.lights;
  15026. var shadowsArray = currentRenderState.state.shadowsArray;
  15027. var lightsStateVersion = lights.state.version;
  15028. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  15029. var programCacheKey = programCache.getProgramCacheKey(parameters);
  15030. var program = materialProperties.program;
  15031. var programChange = true;
  15032. if (program === undefined) {
  15033. // new material
  15034. material.addEventListener('dispose', onMaterialDispose);
  15035. } else if (program.cacheKey !== programCacheKey) {
  15036. // changed glsl or parameters
  15037. releaseMaterialProgramReference(material);
  15038. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  15039. programChange = false;
  15040. } else if (parameters.shaderID !== undefined) {
  15041. // same glsl and uniform list, envMap still needs the update here to avoid a frame-late effect
  15042. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15043. materialProperties.envMap = cubemaps.get(material.envMap || environment);
  15044. return;
  15045. } else {
  15046. // only rebuild uniform list
  15047. programChange = false;
  15048. }
  15049. if (programChange) {
  15050. parameters.uniforms = programCache.getUniforms(material);
  15051. material.onBeforeCompile(parameters, _this);
  15052. program = programCache.acquireProgram(parameters, programCacheKey);
  15053. materialProperties.program = program;
  15054. materialProperties.uniforms = parameters.uniforms;
  15055. materialProperties.outputEncoding = parameters.outputEncoding;
  15056. }
  15057. var uniforms = materialProperties.uniforms;
  15058. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  15059. materialProperties.numClippingPlanes = clipping.numPlanes;
  15060. materialProperties.numIntersection = clipping.numIntersection;
  15061. uniforms.clippingPlanes = clipping.uniform;
  15062. }
  15063. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15064. materialProperties.fog = scene.fog;
  15065. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment); // store the light setup it was created for
  15066. materialProperties.needsLights = materialNeedsLights(material);
  15067. materialProperties.lightsStateVersion = lightsStateVersion;
  15068. if (materialProperties.needsLights) {
  15069. // wire up the material to this renderer's lighting state
  15070. uniforms.ambientLightColor.value = lights.state.ambient;
  15071. uniforms.lightProbe.value = lights.state.probe;
  15072. uniforms.directionalLights.value = lights.state.directional;
  15073. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15074. uniforms.spotLights.value = lights.state.spot;
  15075. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15076. uniforms.rectAreaLights.value = lights.state.rectArea;
  15077. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  15078. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  15079. uniforms.pointLights.value = lights.state.point;
  15080. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15081. uniforms.hemisphereLights.value = lights.state.hemi;
  15082. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15083. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15084. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15085. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15086. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15087. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  15088. }
  15089. var progUniforms = materialProperties.program.getUniforms();
  15090. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  15091. materialProperties.uniformsList = uniformsList;
  15092. }
  15093. function setProgram(camera, scene, material, object) {
  15094. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15095. textures.resetTextureUnits();
  15096. var fog = scene.fog;
  15097. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15098. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15099. var envMap = cubemaps.get(material.envMap || environment);
  15100. var materialProperties = properties.get(material);
  15101. var lights = currentRenderState.state.lights;
  15102. if (_clippingEnabled === true) {
  15103. if (_localClippingEnabled === true || camera !== _currentCamera) {
  15104. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  15105. // object instead of the material, once it becomes feasible
  15106. // (#8465, #8379)
  15107. clipping.setState(material, camera, useCache);
  15108. }
  15109. }
  15110. if (material.version === materialProperties.__version) {
  15111. if (material.fog && materialProperties.fog !== fog) {
  15112. initMaterial(material, scene, object);
  15113. } else if (materialProperties.environment !== environment) {
  15114. initMaterial(material, scene, object);
  15115. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  15116. initMaterial(material, scene, object);
  15117. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  15118. initMaterial(material, scene, object);
  15119. } else if (materialProperties.outputEncoding !== encoding) {
  15120. initMaterial(material, scene, object);
  15121. } else if (materialProperties.envMap !== envMap) {
  15122. initMaterial(material, scene, object);
  15123. }
  15124. } else {
  15125. initMaterial(material, scene, object);
  15126. materialProperties.__version = material.version;
  15127. }
  15128. var refreshProgram = false;
  15129. var refreshMaterial = false;
  15130. var refreshLights = false;
  15131. var program = materialProperties.program,
  15132. p_uniforms = program.getUniforms(),
  15133. m_uniforms = materialProperties.uniforms;
  15134. if (state.useProgram(program.program)) {
  15135. refreshProgram = true;
  15136. refreshMaterial = true;
  15137. refreshLights = true;
  15138. }
  15139. if (material.id !== _currentMaterialId) {
  15140. _currentMaterialId = material.id;
  15141. refreshMaterial = true;
  15142. }
  15143. if (refreshProgram || _currentCamera !== camera) {
  15144. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  15145. if (capabilities.logarithmicDepthBuffer) {
  15146. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  15147. }
  15148. if (_currentCamera !== camera) {
  15149. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  15150. // now, in case this material supports lights - or later, when
  15151. // the next material that does gets activated:
  15152. refreshMaterial = true; // set to true on material change
  15153. refreshLights = true; // remains set until update done
  15154. } // load material specific uniforms
  15155. // (shader material also gets them for the sake of genericity)
  15156. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  15157. var uCamPos = p_uniforms.map.cameraPosition;
  15158. if (uCamPos !== undefined) {
  15159. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  15160. }
  15161. }
  15162. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  15163. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  15164. }
  15165. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  15166. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  15167. }
  15168. } // skinning uniforms must be set even if material didn't change
  15169. // auto-setting of texture unit for bone texture must go before other textures
  15170. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15171. if (material.skinning) {
  15172. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  15173. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  15174. var skeleton = object.skeleton;
  15175. if (skeleton) {
  15176. var bones = skeleton.bones;
  15177. if (capabilities.floatVertexTextures) {
  15178. if (skeleton.boneTexture === null) {
  15179. // layout (1 matrix = 4 pixels)
  15180. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15181. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15182. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15183. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15184. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15185. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  15186. size = MathUtils.ceilPowerOfTwo(size);
  15187. size = Math.max(size, 4);
  15188. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  15189. boneMatrices.set(skeleton.boneMatrices); // copy current values
  15190. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  15191. skeleton.boneMatrices = boneMatrices;
  15192. skeleton.boneTexture = boneTexture;
  15193. skeleton.boneTextureSize = size;
  15194. }
  15195. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  15196. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  15197. } else {
  15198. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  15199. }
  15200. }
  15201. }
  15202. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  15203. materialProperties.receiveShadow = object.receiveShadow;
  15204. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  15205. }
  15206. if (refreshMaterial) {
  15207. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  15208. if (materialProperties.needsLights) {
  15209. // the current material requires lighting info
  15210. // note: all lighting uniforms are always set correctly
  15211. // they simply reference the renderer's state for their
  15212. // values
  15213. //
  15214. // use the current material's .needsUpdate flags to set
  15215. // the GL state when required
  15216. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  15217. } // refresh uniforms common to several materials
  15218. if (fog && material.fog) {
  15219. materials.refreshFogUniforms(m_uniforms, fog);
  15220. }
  15221. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  15222. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15223. }
  15224. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  15225. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15226. material.uniformsNeedUpdate = false;
  15227. }
  15228. if (material.isSpriteMaterial) {
  15229. p_uniforms.setValue(_gl, 'center', object.center);
  15230. } // common matrices
  15231. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  15232. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  15233. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  15234. return program;
  15235. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15236. function markUniformsLightsNeedsUpdate(uniforms, value) {
  15237. uniforms.ambientLightColor.needsUpdate = value;
  15238. uniforms.lightProbe.needsUpdate = value;
  15239. uniforms.directionalLights.needsUpdate = value;
  15240. uniforms.directionalLightShadows.needsUpdate = value;
  15241. uniforms.pointLights.needsUpdate = value;
  15242. uniforms.pointLightShadows.needsUpdate = value;
  15243. uniforms.spotLights.needsUpdate = value;
  15244. uniforms.spotLightShadows.needsUpdate = value;
  15245. uniforms.rectAreaLights.needsUpdate = value;
  15246. uniforms.hemisphereLights.needsUpdate = value;
  15247. }
  15248. function materialNeedsLights(material) {
  15249. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  15250. } //
  15251. this.setFramebuffer = function (value) {
  15252. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  15253. _framebuffer = value;
  15254. };
  15255. this.getActiveCubeFace = function () {
  15256. return _currentActiveCubeFace;
  15257. };
  15258. this.getActiveMipmapLevel = function () {
  15259. return _currentActiveMipmapLevel;
  15260. };
  15261. this.getRenderList = function () {
  15262. return currentRenderList;
  15263. };
  15264. this.setRenderList = function (renderList) {
  15265. currentRenderList = renderList;
  15266. };
  15267. this.getRenderTarget = function () {
  15268. return _currentRenderTarget;
  15269. };
  15270. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15271. if (activeCubeFace === void 0) {
  15272. activeCubeFace = 0;
  15273. }
  15274. if (activeMipmapLevel === void 0) {
  15275. activeMipmapLevel = 0;
  15276. }
  15277. _currentRenderTarget = renderTarget;
  15278. _currentActiveCubeFace = activeCubeFace;
  15279. _currentActiveMipmapLevel = activeMipmapLevel;
  15280. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15281. textures.setupRenderTarget(renderTarget);
  15282. }
  15283. var framebuffer = _framebuffer;
  15284. var isCube = false;
  15285. if (renderTarget) {
  15286. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15287. if (renderTarget.isWebGLCubeRenderTarget) {
  15288. framebuffer = __webglFramebuffer[activeCubeFace];
  15289. isCube = true;
  15290. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15291. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15292. } else {
  15293. framebuffer = __webglFramebuffer;
  15294. }
  15295. _currentViewport.copy(renderTarget.viewport);
  15296. _currentScissor.copy(renderTarget.scissor);
  15297. _currentScissorTest = renderTarget.scissorTest;
  15298. } else {
  15299. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15300. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15301. _currentScissorTest = _scissorTest;
  15302. }
  15303. if (_currentFramebuffer !== framebuffer) {
  15304. _gl.bindFramebuffer(36160, framebuffer);
  15305. _currentFramebuffer = framebuffer;
  15306. }
  15307. state.viewport(_currentViewport);
  15308. state.scissor(_currentScissor);
  15309. state.setScissorTest(_currentScissorTest);
  15310. if (isCube) {
  15311. var textureProperties = properties.get(renderTarget.texture);
  15312. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15313. }
  15314. };
  15315. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15316. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15317. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15318. return;
  15319. }
  15320. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15321. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15322. framebuffer = framebuffer[activeCubeFaceIndex];
  15323. }
  15324. if (framebuffer) {
  15325. var restore = false;
  15326. if (framebuffer !== _currentFramebuffer) {
  15327. _gl.bindFramebuffer(36160, framebuffer);
  15328. restore = true;
  15329. }
  15330. try {
  15331. var texture = renderTarget.texture;
  15332. var textureFormat = texture.format;
  15333. var textureType = texture.type;
  15334. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15335. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15336. return;
  15337. }
  15338. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15339. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.get('OES_texture_float') || extensions.get('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15340. !(textureType === HalfFloatType && (capabilities.isWebGL2 ? extensions.get('EXT_color_buffer_float') : extensions.get('EXT_color_buffer_half_float')))) {
  15341. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15342. return;
  15343. }
  15344. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15345. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15346. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15347. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15348. }
  15349. } else {
  15350. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15351. }
  15352. } finally {
  15353. if (restore) {
  15354. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15355. }
  15356. }
  15357. }
  15358. };
  15359. this.copyFramebufferToTexture = function (position, texture, level) {
  15360. if (level === void 0) {
  15361. level = 0;
  15362. }
  15363. var levelScale = Math.pow(2, -level);
  15364. var width = Math.floor(texture.image.width * levelScale);
  15365. var height = Math.floor(texture.image.height * levelScale);
  15366. var glFormat = utils.convert(texture.format);
  15367. textures.setTexture2D(texture, 0);
  15368. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15369. state.unbindTexture();
  15370. };
  15371. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15372. if (level === void 0) {
  15373. level = 0;
  15374. }
  15375. var width = srcTexture.image.width;
  15376. var height = srcTexture.image.height;
  15377. var glFormat = utils.convert(dstTexture.format);
  15378. var glType = utils.convert(dstTexture.type);
  15379. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15380. // parameters, make sure they are correct for the dstTexture
  15381. _gl.pixelStorei(37440, dstTexture.flipY);
  15382. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15383. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15384. if (srcTexture.isDataTexture) {
  15385. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15386. } else {
  15387. if (srcTexture.isCompressedTexture) {
  15388. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15389. } else {
  15390. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15391. }
  15392. } // Generate mipmaps only when copying level 0
  15393. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15394. state.unbindTexture();
  15395. };
  15396. this.initTexture = function (texture) {
  15397. textures.setTexture2D(texture, 0);
  15398. state.unbindTexture();
  15399. };
  15400. this.resetState = function () {
  15401. state.reset();
  15402. bindingStates.reset();
  15403. };
  15404. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15405. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15406. detail: this
  15407. })); // eslint-disable-line no-undef
  15408. }
  15409. }
  15410. function WebGL1Renderer(parameters) {
  15411. WebGLRenderer.call(this, parameters);
  15412. }
  15413. WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
  15414. constructor: WebGL1Renderer,
  15415. isWebGL1Renderer: true
  15416. });
  15417. var FogExp2 = /*#__PURE__*/function () {
  15418. function FogExp2(color, density) {
  15419. Object.defineProperty(this, 'isFogExp2', {
  15420. value: true
  15421. });
  15422. this.name = '';
  15423. this.color = new Color(color);
  15424. this.density = density !== undefined ? density : 0.00025;
  15425. }
  15426. var _proto = FogExp2.prototype;
  15427. _proto.clone = function clone() {
  15428. return new FogExp2(this.color, this.density);
  15429. };
  15430. _proto.toJSON = function toJSON()
  15431. /* meta */
  15432. {
  15433. return {
  15434. type: 'FogExp2',
  15435. color: this.color.getHex(),
  15436. density: this.density
  15437. };
  15438. };
  15439. return FogExp2;
  15440. }();
  15441. var Fog = /*#__PURE__*/function () {
  15442. function Fog(color, near, far) {
  15443. Object.defineProperty(this, 'isFog', {
  15444. value: true
  15445. });
  15446. this.name = '';
  15447. this.color = new Color(color);
  15448. this.near = near !== undefined ? near : 1;
  15449. this.far = far !== undefined ? far : 1000;
  15450. }
  15451. var _proto = Fog.prototype;
  15452. _proto.clone = function clone() {
  15453. return new Fog(this.color, this.near, this.far);
  15454. };
  15455. _proto.toJSON = function toJSON()
  15456. /* meta */
  15457. {
  15458. return {
  15459. type: 'Fog',
  15460. color: this.color.getHex(),
  15461. near: this.near,
  15462. far: this.far
  15463. };
  15464. };
  15465. return Fog;
  15466. }();
  15467. var Scene = /*#__PURE__*/function (_Object3D) {
  15468. _inheritsLoose(Scene, _Object3D);
  15469. function Scene() {
  15470. var _this;
  15471. _this = _Object3D.call(this) || this;
  15472. Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
  15473. value: true
  15474. });
  15475. _this.type = 'Scene';
  15476. _this.background = null;
  15477. _this.environment = null;
  15478. _this.fog = null;
  15479. _this.overrideMaterial = null;
  15480. _this.autoUpdate = true; // checked by the renderer
  15481. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15482. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15483. detail: _assertThisInitialized(_this)
  15484. })); // eslint-disable-line no-undef
  15485. }
  15486. return _this;
  15487. }
  15488. var _proto = Scene.prototype;
  15489. _proto.copy = function copy(source, recursive) {
  15490. _Object3D.prototype.copy.call(this, source, recursive);
  15491. if (source.background !== null) this.background = source.background.clone();
  15492. if (source.environment !== null) this.environment = source.environment.clone();
  15493. if (source.fog !== null) this.fog = source.fog.clone();
  15494. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  15495. this.autoUpdate = source.autoUpdate;
  15496. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15497. return this;
  15498. };
  15499. _proto.toJSON = function toJSON(meta) {
  15500. var data = _Object3D.prototype.toJSON.call(this, meta);
  15501. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  15502. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  15503. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  15504. return data;
  15505. };
  15506. return Scene;
  15507. }(Object3D);
  15508. function InterleavedBuffer(array, stride) {
  15509. this.array = array;
  15510. this.stride = stride;
  15511. this.count = array !== undefined ? array.length / stride : 0;
  15512. this.usage = StaticDrawUsage;
  15513. this.updateRange = {
  15514. offset: 0,
  15515. count: -1
  15516. };
  15517. this.version = 0;
  15518. this.uuid = MathUtils.generateUUID();
  15519. }
  15520. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  15521. set: function set(value) {
  15522. if (value === true) this.version++;
  15523. }
  15524. });
  15525. Object.assign(InterleavedBuffer.prototype, {
  15526. isInterleavedBuffer: true,
  15527. onUploadCallback: function onUploadCallback() {},
  15528. setUsage: function setUsage(value) {
  15529. this.usage = value;
  15530. return this;
  15531. },
  15532. copy: function copy(source) {
  15533. this.array = new source.array.constructor(source.array);
  15534. this.count = source.count;
  15535. this.stride = source.stride;
  15536. this.usage = source.usage;
  15537. return this;
  15538. },
  15539. copyAt: function copyAt(index1, attribute, index2) {
  15540. index1 *= this.stride;
  15541. index2 *= attribute.stride;
  15542. for (var i = 0, l = this.stride; i < l; i++) {
  15543. this.array[index1 + i] = attribute.array[index2 + i];
  15544. }
  15545. return this;
  15546. },
  15547. set: function set(value, offset) {
  15548. if (offset === void 0) {
  15549. offset = 0;
  15550. }
  15551. this.array.set(value, offset);
  15552. return this;
  15553. },
  15554. clone: function clone(data) {
  15555. if (data.arrayBuffers === undefined) {
  15556. data.arrayBuffers = {};
  15557. }
  15558. if (this.array.buffer._uuid === undefined) {
  15559. this.array.buffer._uuid = MathUtils.generateUUID();
  15560. }
  15561. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15562. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  15563. }
  15564. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  15565. var ib = new InterleavedBuffer(array, this.stride);
  15566. ib.setUsage(this.usage);
  15567. return ib;
  15568. },
  15569. onUpload: function onUpload(callback) {
  15570. this.onUploadCallback = callback;
  15571. return this;
  15572. },
  15573. toJSON: function toJSON(data) {
  15574. if (data.arrayBuffers === undefined) {
  15575. data.arrayBuffers = {};
  15576. } // generate UUID for array buffer if necessary
  15577. if (this.array.buffer._uuid === undefined) {
  15578. this.array.buffer._uuid = MathUtils.generateUUID();
  15579. }
  15580. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15581. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  15582. } //
  15583. return {
  15584. uuid: this.uuid,
  15585. buffer: this.array.buffer._uuid,
  15586. type: this.array.constructor.name,
  15587. stride: this.stride
  15588. };
  15589. }
  15590. });
  15591. var _vector$6 = new Vector3();
  15592. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  15593. this.name = '';
  15594. this.data = interleavedBuffer;
  15595. this.itemSize = itemSize;
  15596. this.offset = offset;
  15597. this.normalized = normalized === true;
  15598. }
  15599. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  15600. count: {
  15601. get: function get() {
  15602. return this.data.count;
  15603. }
  15604. },
  15605. array: {
  15606. get: function get() {
  15607. return this.data.array;
  15608. }
  15609. },
  15610. needsUpdate: {
  15611. set: function set(value) {
  15612. this.data.needsUpdate = value;
  15613. }
  15614. }
  15615. });
  15616. Object.assign(InterleavedBufferAttribute.prototype, {
  15617. isInterleavedBufferAttribute: true,
  15618. applyMatrix4: function applyMatrix4(m) {
  15619. for (var i = 0, l = this.data.count; i < l; i++) {
  15620. _vector$6.x = this.getX(i);
  15621. _vector$6.y = this.getY(i);
  15622. _vector$6.z = this.getZ(i);
  15623. _vector$6.applyMatrix4(m);
  15624. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  15625. }
  15626. return this;
  15627. },
  15628. setX: function setX(index, x) {
  15629. this.data.array[index * this.data.stride + this.offset] = x;
  15630. return this;
  15631. },
  15632. setY: function setY(index, y) {
  15633. this.data.array[index * this.data.stride + this.offset + 1] = y;
  15634. return this;
  15635. },
  15636. setZ: function setZ(index, z) {
  15637. this.data.array[index * this.data.stride + this.offset + 2] = z;
  15638. return this;
  15639. },
  15640. setW: function setW(index, w) {
  15641. this.data.array[index * this.data.stride + this.offset + 3] = w;
  15642. return this;
  15643. },
  15644. getX: function getX(index) {
  15645. return this.data.array[index * this.data.stride + this.offset];
  15646. },
  15647. getY: function getY(index) {
  15648. return this.data.array[index * this.data.stride + this.offset + 1];
  15649. },
  15650. getZ: function getZ(index) {
  15651. return this.data.array[index * this.data.stride + this.offset + 2];
  15652. },
  15653. getW: function getW(index) {
  15654. return this.data.array[index * this.data.stride + this.offset + 3];
  15655. },
  15656. setXY: function setXY(index, x, y) {
  15657. index = index * this.data.stride + this.offset;
  15658. this.data.array[index + 0] = x;
  15659. this.data.array[index + 1] = y;
  15660. return this;
  15661. },
  15662. setXYZ: function setXYZ(index, x, y, z) {
  15663. index = index * this.data.stride + this.offset;
  15664. this.data.array[index + 0] = x;
  15665. this.data.array[index + 1] = y;
  15666. this.data.array[index + 2] = z;
  15667. return this;
  15668. },
  15669. setXYZW: function setXYZW(index, x, y, z, w) {
  15670. index = index * this.data.stride + this.offset;
  15671. this.data.array[index + 0] = x;
  15672. this.data.array[index + 1] = y;
  15673. this.data.array[index + 2] = z;
  15674. this.data.array[index + 3] = w;
  15675. return this;
  15676. },
  15677. clone: function clone(data) {
  15678. if (data === undefined) {
  15679. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  15680. var array = [];
  15681. for (var i = 0; i < this.count; i++) {
  15682. var index = i * this.data.stride + this.offset;
  15683. for (var j = 0; j < this.itemSize; j++) {
  15684. array.push(this.data.array[index + j]);
  15685. }
  15686. }
  15687. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  15688. } else {
  15689. if (data.interleavedBuffers === undefined) {
  15690. data.interleavedBuffers = {};
  15691. }
  15692. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15693. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  15694. }
  15695. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  15696. }
  15697. },
  15698. toJSON: function toJSON(data) {
  15699. if (data === undefined) {
  15700. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  15701. var array = [];
  15702. for (var i = 0; i < this.count; i++) {
  15703. var index = i * this.data.stride + this.offset;
  15704. for (var j = 0; j < this.itemSize; j++) {
  15705. array.push(this.data.array[index + j]);
  15706. }
  15707. } // deinterleave data and save it as an ordinary buffer attribute for now
  15708. return {
  15709. itemSize: this.itemSize,
  15710. type: this.array.constructor.name,
  15711. array: array,
  15712. normalized: this.normalized
  15713. };
  15714. } else {
  15715. // save as true interlaved attribtue
  15716. if (data.interleavedBuffers === undefined) {
  15717. data.interleavedBuffers = {};
  15718. }
  15719. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15720. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  15721. }
  15722. return {
  15723. isInterleavedBufferAttribute: true,
  15724. itemSize: this.itemSize,
  15725. data: this.data.uuid,
  15726. offset: this.offset,
  15727. normalized: this.normalized
  15728. };
  15729. }
  15730. }
  15731. });
  15732. /**
  15733. * parameters = {
  15734. * color: <hex>,
  15735. * map: new THREE.Texture( <Image> ),
  15736. * alphaMap: new THREE.Texture( <Image> ),
  15737. * rotation: <float>,
  15738. * sizeAttenuation: <bool>
  15739. * }
  15740. */
  15741. function SpriteMaterial(parameters) {
  15742. Material.call(this);
  15743. this.type = 'SpriteMaterial';
  15744. this.color = new Color(0xffffff);
  15745. this.map = null;
  15746. this.alphaMap = null;
  15747. this.rotation = 0;
  15748. this.sizeAttenuation = true;
  15749. this.transparent = true;
  15750. this.setValues(parameters);
  15751. }
  15752. SpriteMaterial.prototype = Object.create(Material.prototype);
  15753. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15754. SpriteMaterial.prototype.isSpriteMaterial = true;
  15755. SpriteMaterial.prototype.copy = function (source) {
  15756. Material.prototype.copy.call(this, source);
  15757. this.color.copy(source.color);
  15758. this.map = source.map;
  15759. this.alphaMap = source.alphaMap;
  15760. this.rotation = source.rotation;
  15761. this.sizeAttenuation = source.sizeAttenuation;
  15762. return this;
  15763. };
  15764. var _geometry;
  15765. var _intersectPoint = new Vector3();
  15766. var _worldScale = new Vector3();
  15767. var _mvPosition = new Vector3();
  15768. var _alignedPosition = new Vector2();
  15769. var _rotatedPosition = new Vector2();
  15770. var _viewWorldMatrix = new Matrix4();
  15771. var _vA$1 = new Vector3();
  15772. var _vB$1 = new Vector3();
  15773. var _vC$1 = new Vector3();
  15774. var _uvA$1 = new Vector2();
  15775. var _uvB$1 = new Vector2();
  15776. var _uvC$1 = new Vector2();
  15777. function Sprite(material) {
  15778. Object3D.call(this);
  15779. this.type = 'Sprite';
  15780. if (_geometry === undefined) {
  15781. _geometry = new BufferGeometry();
  15782. 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]);
  15783. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  15784. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  15785. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  15786. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  15787. }
  15788. this.geometry = _geometry;
  15789. this.material = material !== undefined ? material : new SpriteMaterial();
  15790. this.center = new Vector2(0.5, 0.5);
  15791. }
  15792. Sprite.prototype = Object.assign(Object.create(Object3D.prototype), {
  15793. constructor: Sprite,
  15794. isSprite: true,
  15795. raycast: function raycast(raycaster, intersects) {
  15796. if (raycaster.camera === null) {
  15797. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  15798. }
  15799. _worldScale.setFromMatrixScale(this.matrixWorld);
  15800. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  15801. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  15802. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  15803. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  15804. _worldScale.multiplyScalar(-_mvPosition.z);
  15805. }
  15806. var rotation = this.material.rotation;
  15807. var sin, cos;
  15808. if (rotation !== 0) {
  15809. cos = Math.cos(rotation);
  15810. sin = Math.sin(rotation);
  15811. }
  15812. var center = this.center;
  15813. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15814. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15815. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15816. _uvA$1.set(0, 0);
  15817. _uvB$1.set(1, 0);
  15818. _uvC$1.set(1, 1); // check first triangle
  15819. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  15820. if (intersect === null) {
  15821. // check second triangle
  15822. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15823. _uvB$1.set(0, 1);
  15824. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  15825. if (intersect === null) {
  15826. return;
  15827. }
  15828. }
  15829. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  15830. if (distance < raycaster.near || distance > raycaster.far) return;
  15831. intersects.push({
  15832. distance: distance,
  15833. point: _intersectPoint.clone(),
  15834. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  15835. face: null,
  15836. object: this
  15837. });
  15838. },
  15839. copy: function copy(source) {
  15840. Object3D.prototype.copy.call(this, source);
  15841. if (source.center !== undefined) this.center.copy(source.center);
  15842. this.material = source.material;
  15843. return this;
  15844. }
  15845. });
  15846. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  15847. // compute position in camera space
  15848. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  15849. if (sin !== undefined) {
  15850. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  15851. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  15852. } else {
  15853. _rotatedPosition.copy(_alignedPosition);
  15854. }
  15855. vertexPosition.copy(mvPosition);
  15856. vertexPosition.x += _rotatedPosition.x;
  15857. vertexPosition.y += _rotatedPosition.y; // transform to world space
  15858. vertexPosition.applyMatrix4(_viewWorldMatrix);
  15859. }
  15860. var _v1$4 = new Vector3();
  15861. var _v2$2 = new Vector3();
  15862. function LOD() {
  15863. Object3D.call(this);
  15864. this._currentLevel = 0;
  15865. this.type = 'LOD';
  15866. Object.defineProperties(this, {
  15867. levels: {
  15868. enumerable: true,
  15869. value: []
  15870. }
  15871. });
  15872. this.autoUpdate = true;
  15873. }
  15874. LOD.prototype = Object.assign(Object.create(Object3D.prototype), {
  15875. constructor: LOD,
  15876. isLOD: true,
  15877. copy: function copy(source) {
  15878. Object3D.prototype.copy.call(this, source, false);
  15879. var levels = source.levels;
  15880. for (var i = 0, l = levels.length; i < l; i++) {
  15881. var level = levels[i];
  15882. this.addLevel(level.object.clone(), level.distance);
  15883. }
  15884. this.autoUpdate = source.autoUpdate;
  15885. return this;
  15886. },
  15887. addLevel: function addLevel(object, distance) {
  15888. if (distance === void 0) {
  15889. distance = 0;
  15890. }
  15891. distance = Math.abs(distance);
  15892. var levels = this.levels;
  15893. var l;
  15894. for (l = 0; l < levels.length; l++) {
  15895. if (distance < levels[l].distance) {
  15896. break;
  15897. }
  15898. }
  15899. levels.splice(l, 0, {
  15900. distance: distance,
  15901. object: object
  15902. });
  15903. this.add(object);
  15904. return this;
  15905. },
  15906. getCurrentLevel: function getCurrentLevel() {
  15907. return this._currentLevel;
  15908. },
  15909. getObjectForDistance: function getObjectForDistance(distance) {
  15910. var levels = this.levels;
  15911. if (levels.length > 0) {
  15912. var i, l;
  15913. for (i = 1, l = levels.length; i < l; i++) {
  15914. if (distance < levels[i].distance) {
  15915. break;
  15916. }
  15917. }
  15918. return levels[i - 1].object;
  15919. }
  15920. return null;
  15921. },
  15922. raycast: function raycast(raycaster, intersects) {
  15923. var levels = this.levels;
  15924. if (levels.length > 0) {
  15925. _v1$4.setFromMatrixPosition(this.matrixWorld);
  15926. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  15927. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  15928. }
  15929. },
  15930. update: function update(camera) {
  15931. var levels = this.levels;
  15932. if (levels.length > 1) {
  15933. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  15934. _v2$2.setFromMatrixPosition(this.matrixWorld);
  15935. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  15936. levels[0].object.visible = true;
  15937. var i, l;
  15938. for (i = 1, l = levels.length; i < l; i++) {
  15939. if (distance >= levels[i].distance) {
  15940. levels[i - 1].object.visible = false;
  15941. levels[i].object.visible = true;
  15942. } else {
  15943. break;
  15944. }
  15945. }
  15946. this._currentLevel = i - 1;
  15947. for (; i < l; i++) {
  15948. levels[i].object.visible = false;
  15949. }
  15950. }
  15951. },
  15952. toJSON: function toJSON(meta) {
  15953. var data = Object3D.prototype.toJSON.call(this, meta);
  15954. if (this.autoUpdate === false) data.object.autoUpdate = false;
  15955. data.object.levels = [];
  15956. var levels = this.levels;
  15957. for (var i = 0, l = levels.length; i < l; i++) {
  15958. var level = levels[i];
  15959. data.object.levels.push({
  15960. object: level.object.uuid,
  15961. distance: level.distance
  15962. });
  15963. }
  15964. return data;
  15965. }
  15966. });
  15967. var _basePosition = new Vector3();
  15968. var _skinIndex = new Vector4();
  15969. var _skinWeight = new Vector4();
  15970. var _vector$7 = new Vector3();
  15971. var _matrix$1 = new Matrix4();
  15972. function SkinnedMesh(geometry, material) {
  15973. if (geometry && geometry.isGeometry) {
  15974. console.error('THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  15975. }
  15976. Mesh.call(this, geometry, material);
  15977. this.type = 'SkinnedMesh';
  15978. this.bindMode = 'attached';
  15979. this.bindMatrix = new Matrix4();
  15980. this.bindMatrixInverse = new Matrix4();
  15981. }
  15982. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  15983. constructor: SkinnedMesh,
  15984. isSkinnedMesh: true,
  15985. copy: function copy(source) {
  15986. Mesh.prototype.copy.call(this, source);
  15987. this.bindMode = source.bindMode;
  15988. this.bindMatrix.copy(source.bindMatrix);
  15989. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  15990. this.skeleton = source.skeleton;
  15991. return this;
  15992. },
  15993. bind: function bind(skeleton, bindMatrix) {
  15994. this.skeleton = skeleton;
  15995. if (bindMatrix === undefined) {
  15996. this.updateMatrixWorld(true);
  15997. this.skeleton.calculateInverses();
  15998. bindMatrix = this.matrixWorld;
  15999. }
  16000. this.bindMatrix.copy(bindMatrix);
  16001. this.bindMatrixInverse.copy(bindMatrix).invert();
  16002. },
  16003. pose: function pose() {
  16004. this.skeleton.pose();
  16005. },
  16006. normalizeSkinWeights: function normalizeSkinWeights() {
  16007. var vector = new Vector4();
  16008. var skinWeight = this.geometry.attributes.skinWeight;
  16009. for (var i = 0, l = skinWeight.count; i < l; i++) {
  16010. vector.x = skinWeight.getX(i);
  16011. vector.y = skinWeight.getY(i);
  16012. vector.z = skinWeight.getZ(i);
  16013. vector.w = skinWeight.getW(i);
  16014. var scale = 1.0 / vector.manhattanLength();
  16015. if (scale !== Infinity) {
  16016. vector.multiplyScalar(scale);
  16017. } else {
  16018. vector.set(1, 0, 0, 0); // do something reasonable
  16019. }
  16020. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  16021. }
  16022. },
  16023. updateMatrixWorld: function updateMatrixWorld(force) {
  16024. Mesh.prototype.updateMatrixWorld.call(this, force);
  16025. if (this.bindMode === 'attached') {
  16026. this.bindMatrixInverse.copy(this.matrixWorld).invert();
  16027. } else if (this.bindMode === 'detached') {
  16028. this.bindMatrixInverse.copy(this.bindMatrix).invert();
  16029. } else {
  16030. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  16031. }
  16032. },
  16033. boneTransform: function boneTransform(index, target) {
  16034. var skeleton = this.skeleton;
  16035. var geometry = this.geometry;
  16036. _skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  16037. _skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  16038. _basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  16039. target.set(0, 0, 0);
  16040. for (var i = 0; i < 4; i++) {
  16041. var weight = _skinWeight.getComponent(i);
  16042. if (weight !== 0) {
  16043. var boneIndex = _skinIndex.getComponent(i);
  16044. _matrix$1.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  16045. target.addScaledVector(_vector$7.copy(_basePosition).applyMatrix4(_matrix$1), weight);
  16046. }
  16047. }
  16048. return target.applyMatrix4(this.bindMatrixInverse);
  16049. }
  16050. });
  16051. function Bone() {
  16052. Object3D.call(this);
  16053. this.type = 'Bone';
  16054. }
  16055. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  16056. constructor: Bone,
  16057. isBone: true
  16058. });
  16059. var _offsetMatrix = new Matrix4();
  16060. var _identityMatrix = new Matrix4();
  16061. function Skeleton(bones, boneInverses) {
  16062. if (bones === void 0) {
  16063. bones = [];
  16064. }
  16065. if (boneInverses === void 0) {
  16066. boneInverses = [];
  16067. }
  16068. this.uuid = MathUtils.generateUUID();
  16069. this.bones = bones.slice(0);
  16070. this.boneInverses = boneInverses;
  16071. this.boneMatrices = null;
  16072. this.boneTexture = null;
  16073. this.boneTextureSize = 0;
  16074. this.frame = -1;
  16075. this.init();
  16076. }
  16077. Object.assign(Skeleton.prototype, {
  16078. init: function init() {
  16079. var bones = this.bones;
  16080. var boneInverses = this.boneInverses;
  16081. this.boneMatrices = new Float32Array(bones.length * 16); // calculate inverse bone matrices if necessary
  16082. if (boneInverses.length === 0) {
  16083. this.calculateInverses();
  16084. } else {
  16085. // handle special case
  16086. if (bones.length !== boneInverses.length) {
  16087. console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');
  16088. this.boneInverses = [];
  16089. for (var i = 0, il = this.bones.length; i < il; i++) {
  16090. this.boneInverses.push(new Matrix4());
  16091. }
  16092. }
  16093. }
  16094. },
  16095. calculateInverses: function calculateInverses() {
  16096. this.boneInverses.length = 0;
  16097. for (var i = 0, il = this.bones.length; i < il; i++) {
  16098. var inverse = new Matrix4();
  16099. if (this.bones[i]) {
  16100. inverse.copy(this.bones[i].matrixWorld).invert();
  16101. }
  16102. this.boneInverses.push(inverse);
  16103. }
  16104. },
  16105. pose: function pose() {
  16106. // recover the bind-time world matrices
  16107. for (var i = 0, il = this.bones.length; i < il; i++) {
  16108. var bone = this.bones[i];
  16109. if (bone) {
  16110. bone.matrixWorld.copy(this.boneInverses[i]).invert();
  16111. }
  16112. } // compute the local matrices, positions, rotations and scales
  16113. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  16114. var _bone = this.bones[_i];
  16115. if (_bone) {
  16116. if (_bone.parent && _bone.parent.isBone) {
  16117. _bone.matrix.copy(_bone.parent.matrixWorld).invert();
  16118. _bone.matrix.multiply(_bone.matrixWorld);
  16119. } else {
  16120. _bone.matrix.copy(_bone.matrixWorld);
  16121. }
  16122. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  16123. }
  16124. }
  16125. },
  16126. update: function update() {
  16127. var bones = this.bones;
  16128. var boneInverses = this.boneInverses;
  16129. var boneMatrices = this.boneMatrices;
  16130. var boneTexture = this.boneTexture; // flatten bone matrices to array
  16131. for (var i = 0, il = bones.length; i < il; i++) {
  16132. // compute the offset between the current and the original transform
  16133. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  16134. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  16135. _offsetMatrix.toArray(boneMatrices, i * 16);
  16136. }
  16137. if (boneTexture !== null) {
  16138. boneTexture.needsUpdate = true;
  16139. }
  16140. },
  16141. clone: function clone() {
  16142. return new Skeleton(this.bones, this.boneInverses);
  16143. },
  16144. getBoneByName: function getBoneByName(name) {
  16145. for (var i = 0, il = this.bones.length; i < il; i++) {
  16146. var bone = this.bones[i];
  16147. if (bone.name === name) {
  16148. return bone;
  16149. }
  16150. }
  16151. return undefined;
  16152. },
  16153. dispose: function dispose() {
  16154. if (this.boneTexture !== null) {
  16155. this.boneTexture.dispose();
  16156. this.boneTexture = null;
  16157. }
  16158. },
  16159. fromJSON: function fromJSON(json, bones) {
  16160. this.uuid = json.uuid;
  16161. for (var i = 0, l = json.bones.length; i < l; i++) {
  16162. var uuid = json.bones[i];
  16163. var bone = bones[uuid];
  16164. if (bone === undefined) {
  16165. console.warn('THREE.Skeleton: No bone found with UUID:', uuid);
  16166. bone = new Bone();
  16167. }
  16168. this.bones.push(bone);
  16169. this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
  16170. }
  16171. this.init();
  16172. return this;
  16173. },
  16174. toJSON: function toJSON() {
  16175. var data = {
  16176. metadata: {
  16177. version: 4.5,
  16178. type: 'Skeleton',
  16179. generator: 'Skeleton.toJSON'
  16180. },
  16181. bones: [],
  16182. boneInverses: []
  16183. };
  16184. data.uuid = this.uuid;
  16185. var bones = this.bones;
  16186. var boneInverses = this.boneInverses;
  16187. for (var i = 0, l = bones.length; i < l; i++) {
  16188. var bone = bones[i];
  16189. data.bones.push(bone.uuid);
  16190. var boneInverse = boneInverses[i];
  16191. data.boneInverses.push(boneInverse.toArray());
  16192. }
  16193. return data;
  16194. }
  16195. });
  16196. var _instanceLocalMatrix = new Matrix4();
  16197. var _instanceWorldMatrix = new Matrix4();
  16198. var _instanceIntersects = [];
  16199. var _mesh = new Mesh();
  16200. function InstancedMesh(geometry, material, count) {
  16201. Mesh.call(this, geometry, material);
  16202. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  16203. this.instanceColor = null;
  16204. this.count = count;
  16205. this.frustumCulled = false;
  16206. }
  16207. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16208. constructor: InstancedMesh,
  16209. isInstancedMesh: true,
  16210. copy: function copy(source) {
  16211. Mesh.prototype.copy.call(this, source);
  16212. this.instanceMatrix.copy(source.instanceMatrix);
  16213. this.count = source.count;
  16214. return this;
  16215. },
  16216. getColorAt: function getColorAt(index, color) {
  16217. color.fromArray(this.instanceColor.array, index * 3);
  16218. },
  16219. getMatrixAt: function getMatrixAt(index, matrix) {
  16220. matrix.fromArray(this.instanceMatrix.array, index * 16);
  16221. },
  16222. raycast: function raycast(raycaster, intersects) {
  16223. var matrixWorld = this.matrixWorld;
  16224. var raycastTimes = this.count;
  16225. _mesh.geometry = this.geometry;
  16226. _mesh.material = this.material;
  16227. if (_mesh.material === undefined) return;
  16228. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  16229. // calculate the world matrix for each instance
  16230. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  16231. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  16232. _mesh.matrixWorld = _instanceWorldMatrix;
  16233. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  16234. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  16235. var intersect = _instanceIntersects[i];
  16236. intersect.instanceId = instanceId;
  16237. intersect.object = this;
  16238. intersects.push(intersect);
  16239. }
  16240. _instanceIntersects.length = 0;
  16241. }
  16242. },
  16243. setColorAt: function setColorAt(index, color) {
  16244. if (this.instanceColor === null) {
  16245. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  16246. }
  16247. color.toArray(this.instanceColor.array, index * 3);
  16248. },
  16249. setMatrixAt: function setMatrixAt(index, matrix) {
  16250. matrix.toArray(this.instanceMatrix.array, index * 16);
  16251. },
  16252. updateMorphTargets: function updateMorphTargets() {},
  16253. dispose: function dispose() {
  16254. this.dispatchEvent({
  16255. type: 'dispose'
  16256. });
  16257. }
  16258. });
  16259. /**
  16260. * parameters = {
  16261. * color: <hex>,
  16262. * opacity: <float>,
  16263. *
  16264. * linewidth: <float>,
  16265. * linecap: "round",
  16266. * linejoin: "round"
  16267. * }
  16268. */
  16269. function LineBasicMaterial(parameters) {
  16270. Material.call(this);
  16271. this.type = 'LineBasicMaterial';
  16272. this.color = new Color(0xffffff);
  16273. this.linewidth = 1;
  16274. this.linecap = 'round';
  16275. this.linejoin = 'round';
  16276. this.morphTargets = false;
  16277. this.setValues(parameters);
  16278. }
  16279. LineBasicMaterial.prototype = Object.create(Material.prototype);
  16280. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16281. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16282. LineBasicMaterial.prototype.copy = function (source) {
  16283. Material.prototype.copy.call(this, source);
  16284. this.color.copy(source.color);
  16285. this.linewidth = source.linewidth;
  16286. this.linecap = source.linecap;
  16287. this.linejoin = source.linejoin;
  16288. this.morphTargets = source.morphTargets;
  16289. return this;
  16290. };
  16291. var _start = new Vector3();
  16292. var _end = new Vector3();
  16293. var _inverseMatrix$1 = new Matrix4();
  16294. var _ray$1 = new Ray();
  16295. var _sphere$2 = new Sphere();
  16296. function Line(geometry, material) {
  16297. if (geometry === void 0) {
  16298. geometry = new BufferGeometry();
  16299. }
  16300. if (material === void 0) {
  16301. material = new LineBasicMaterial();
  16302. }
  16303. Object3D.call(this);
  16304. this.type = 'Line';
  16305. this.geometry = geometry;
  16306. this.material = material;
  16307. this.updateMorphTargets();
  16308. }
  16309. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  16310. constructor: Line,
  16311. isLine: true,
  16312. copy: function copy(source) {
  16313. Object3D.prototype.copy.call(this, source);
  16314. this.material = source.material;
  16315. this.geometry = source.geometry;
  16316. return this;
  16317. },
  16318. computeLineDistances: function computeLineDistances() {
  16319. var geometry = this.geometry;
  16320. if (geometry.isBufferGeometry) {
  16321. // we assume non-indexed geometry
  16322. if (geometry.index === null) {
  16323. var positionAttribute = geometry.attributes.position;
  16324. var lineDistances = [0];
  16325. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  16326. _start.fromBufferAttribute(positionAttribute, i - 1);
  16327. _end.fromBufferAttribute(positionAttribute, i);
  16328. lineDistances[i] = lineDistances[i - 1];
  16329. lineDistances[i] += _start.distanceTo(_end);
  16330. }
  16331. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16332. } else {
  16333. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16334. }
  16335. } else if (geometry.isGeometry) {
  16336. var vertices = geometry.vertices;
  16337. var _lineDistances = geometry.lineDistances;
  16338. _lineDistances[0] = 0;
  16339. for (var _i = 1, _l = vertices.length; _i < _l; _i++) {
  16340. _lineDistances[_i] = _lineDistances[_i - 1];
  16341. _lineDistances[_i] += vertices[_i - 1].distanceTo(vertices[_i]);
  16342. }
  16343. }
  16344. return this;
  16345. },
  16346. raycast: function raycast(raycaster, intersects) {
  16347. var geometry = this.geometry;
  16348. var matrixWorld = this.matrixWorld;
  16349. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  16350. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16351. _sphere$2.copy(geometry.boundingSphere);
  16352. _sphere$2.applyMatrix4(matrixWorld);
  16353. _sphere$2.radius += threshold;
  16354. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  16355. _inverseMatrix$1.copy(matrixWorld).invert();
  16356. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  16357. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16358. var localThresholdSq = localThreshold * localThreshold;
  16359. var vStart = new Vector3();
  16360. var vEnd = new Vector3();
  16361. var interSegment = new Vector3();
  16362. var interRay = new Vector3();
  16363. var step = this.isLineSegments ? 2 : 1;
  16364. if (geometry.isBufferGeometry) {
  16365. var index = geometry.index;
  16366. var attributes = geometry.attributes;
  16367. var positionAttribute = attributes.position;
  16368. if (index !== null) {
  16369. var indices = index.array;
  16370. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  16371. var a = indices[i];
  16372. var b = indices[i + 1];
  16373. vStart.fromBufferAttribute(positionAttribute, a);
  16374. vEnd.fromBufferAttribute(positionAttribute, b);
  16375. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16376. if (distSq > localThresholdSq) continue;
  16377. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16378. var distance = raycaster.ray.origin.distanceTo(interRay);
  16379. if (distance < raycaster.near || distance > raycaster.far) continue;
  16380. intersects.push({
  16381. distance: distance,
  16382. // What do we want? intersection point on the ray or on the segment??
  16383. // point: raycaster.ray.at( distance ),
  16384. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16385. index: i,
  16386. face: null,
  16387. faceIndex: null,
  16388. object: this
  16389. });
  16390. }
  16391. } else {
  16392. for (var _i2 = 0, _l2 = positionAttribute.count - 1; _i2 < _l2; _i2 += step) {
  16393. vStart.fromBufferAttribute(positionAttribute, _i2);
  16394. vEnd.fromBufferAttribute(positionAttribute, _i2 + 1);
  16395. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16396. if (_distSq > localThresholdSq) continue;
  16397. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16398. var _distance = raycaster.ray.origin.distanceTo(interRay);
  16399. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  16400. intersects.push({
  16401. distance: _distance,
  16402. // What do we want? intersection point on the ray or on the segment??
  16403. // point: raycaster.ray.at( distance ),
  16404. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16405. index: _i2,
  16406. face: null,
  16407. faceIndex: null,
  16408. object: this
  16409. });
  16410. }
  16411. }
  16412. } else if (geometry.isGeometry) {
  16413. var vertices = geometry.vertices;
  16414. var nbVertices = vertices.length;
  16415. for (var _i3 = 0; _i3 < nbVertices - 1; _i3 += step) {
  16416. var _distSq2 = _ray$1.distanceSqToSegment(vertices[_i3], vertices[_i3 + 1], interRay, interSegment);
  16417. if (_distSq2 > localThresholdSq) continue;
  16418. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16419. var _distance2 = raycaster.ray.origin.distanceTo(interRay);
  16420. if (_distance2 < raycaster.near || _distance2 > raycaster.far) continue;
  16421. intersects.push({
  16422. distance: _distance2,
  16423. // What do we want? intersection point on the ray or on the segment??
  16424. // point: raycaster.ray.at( distance ),
  16425. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16426. index: _i3,
  16427. face: null,
  16428. faceIndex: null,
  16429. object: this
  16430. });
  16431. }
  16432. }
  16433. },
  16434. updateMorphTargets: function updateMorphTargets() {
  16435. var geometry = this.geometry;
  16436. if (geometry.isBufferGeometry) {
  16437. var morphAttributes = geometry.morphAttributes;
  16438. var keys = Object.keys(morphAttributes);
  16439. if (keys.length > 0) {
  16440. var morphAttribute = morphAttributes[keys[0]];
  16441. if (morphAttribute !== undefined) {
  16442. this.morphTargetInfluences = [];
  16443. this.morphTargetDictionary = {};
  16444. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16445. var name = morphAttribute[m].name || String(m);
  16446. this.morphTargetInfluences.push(0);
  16447. this.morphTargetDictionary[name] = m;
  16448. }
  16449. }
  16450. }
  16451. } else {
  16452. var morphTargets = geometry.morphTargets;
  16453. if (morphTargets !== undefined && morphTargets.length > 0) {
  16454. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16455. }
  16456. }
  16457. }
  16458. });
  16459. var _start$1 = new Vector3();
  16460. var _end$1 = new Vector3();
  16461. function LineSegments(geometry, material) {
  16462. Line.call(this, geometry, material);
  16463. this.type = 'LineSegments';
  16464. }
  16465. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  16466. constructor: LineSegments,
  16467. isLineSegments: true,
  16468. computeLineDistances: function computeLineDistances() {
  16469. var geometry = this.geometry;
  16470. if (geometry.isBufferGeometry) {
  16471. // we assume non-indexed geometry
  16472. if (geometry.index === null) {
  16473. var positionAttribute = geometry.attributes.position;
  16474. var lineDistances = [];
  16475. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  16476. _start$1.fromBufferAttribute(positionAttribute, i);
  16477. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  16478. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  16479. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  16480. }
  16481. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16482. } else {
  16483. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16484. }
  16485. } else if (geometry.isGeometry) {
  16486. var vertices = geometry.vertices;
  16487. var _lineDistances = geometry.lineDistances;
  16488. for (var _i = 0, _l = vertices.length; _i < _l; _i += 2) {
  16489. _start$1.copy(vertices[_i]);
  16490. _end$1.copy(vertices[_i + 1]);
  16491. _lineDistances[_i] = _i === 0 ? 0 : _lineDistances[_i - 1];
  16492. _lineDistances[_i + 1] = _lineDistances[_i] + _start$1.distanceTo(_end$1);
  16493. }
  16494. }
  16495. return this;
  16496. }
  16497. });
  16498. function LineLoop(geometry, material) {
  16499. Line.call(this, geometry, material);
  16500. this.type = 'LineLoop';
  16501. }
  16502. LineLoop.prototype = Object.assign(Object.create(Line.prototype), {
  16503. constructor: LineLoop,
  16504. isLineLoop: true
  16505. });
  16506. /**
  16507. * parameters = {
  16508. * color: <hex>,
  16509. * opacity: <float>,
  16510. * map: new THREE.Texture( <Image> ),
  16511. * alphaMap: new THREE.Texture( <Image> ),
  16512. *
  16513. * size: <float>,
  16514. * sizeAttenuation: <bool>
  16515. *
  16516. * morphTargets: <bool>
  16517. * }
  16518. */
  16519. function PointsMaterial(parameters) {
  16520. Material.call(this);
  16521. this.type = 'PointsMaterial';
  16522. this.color = new Color(0xffffff);
  16523. this.map = null;
  16524. this.alphaMap = null;
  16525. this.size = 1;
  16526. this.sizeAttenuation = true;
  16527. this.morphTargets = false;
  16528. this.setValues(parameters);
  16529. }
  16530. PointsMaterial.prototype = Object.create(Material.prototype);
  16531. PointsMaterial.prototype.constructor = PointsMaterial;
  16532. PointsMaterial.prototype.isPointsMaterial = true;
  16533. PointsMaterial.prototype.copy = function (source) {
  16534. Material.prototype.copy.call(this, source);
  16535. this.color.copy(source.color);
  16536. this.map = source.map;
  16537. this.alphaMap = source.alphaMap;
  16538. this.size = source.size;
  16539. this.sizeAttenuation = source.sizeAttenuation;
  16540. this.morphTargets = source.morphTargets;
  16541. return this;
  16542. };
  16543. var _inverseMatrix$2 = new Matrix4();
  16544. var _ray$2 = new Ray();
  16545. var _sphere$3 = new Sphere();
  16546. var _position$1 = new Vector3();
  16547. function Points(geometry, material) {
  16548. if (geometry === void 0) {
  16549. geometry = new BufferGeometry();
  16550. }
  16551. if (material === void 0) {
  16552. material = new PointsMaterial();
  16553. }
  16554. Object3D.call(this);
  16555. this.type = 'Points';
  16556. this.geometry = geometry;
  16557. this.material = material;
  16558. this.updateMorphTargets();
  16559. }
  16560. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  16561. constructor: Points,
  16562. isPoints: true,
  16563. copy: function copy(source) {
  16564. Object3D.prototype.copy.call(this, source);
  16565. this.material = source.material;
  16566. this.geometry = source.geometry;
  16567. return this;
  16568. },
  16569. raycast: function raycast(raycaster, intersects) {
  16570. var geometry = this.geometry;
  16571. var matrixWorld = this.matrixWorld;
  16572. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  16573. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16574. _sphere$3.copy(geometry.boundingSphere);
  16575. _sphere$3.applyMatrix4(matrixWorld);
  16576. _sphere$3.radius += threshold;
  16577. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  16578. _inverseMatrix$2.copy(matrixWorld).invert();
  16579. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  16580. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16581. var localThresholdSq = localThreshold * localThreshold;
  16582. if (geometry.isBufferGeometry) {
  16583. var index = geometry.index;
  16584. var attributes = geometry.attributes;
  16585. var positionAttribute = attributes.position;
  16586. if (index !== null) {
  16587. var indices = index.array;
  16588. for (var i = 0, il = indices.length; i < il; i++) {
  16589. var a = indices[i];
  16590. _position$1.fromBufferAttribute(positionAttribute, a);
  16591. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16592. }
  16593. } else {
  16594. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  16595. _position$1.fromBufferAttribute(positionAttribute, _i);
  16596. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16597. }
  16598. }
  16599. } else {
  16600. var vertices = geometry.vertices;
  16601. for (var _i2 = 0, _l = vertices.length; _i2 < _l; _i2++) {
  16602. testPoint(vertices[_i2], _i2, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16603. }
  16604. }
  16605. },
  16606. updateMorphTargets: function updateMorphTargets() {
  16607. var geometry = this.geometry;
  16608. if (geometry.isBufferGeometry) {
  16609. var morphAttributes = geometry.morphAttributes;
  16610. var keys = Object.keys(morphAttributes);
  16611. if (keys.length > 0) {
  16612. var morphAttribute = morphAttributes[keys[0]];
  16613. if (morphAttribute !== undefined) {
  16614. this.morphTargetInfluences = [];
  16615. this.morphTargetDictionary = {};
  16616. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16617. var name = morphAttribute[m].name || String(m);
  16618. this.morphTargetInfluences.push(0);
  16619. this.morphTargetDictionary[name] = m;
  16620. }
  16621. }
  16622. }
  16623. } else {
  16624. var morphTargets = geometry.morphTargets;
  16625. if (morphTargets !== undefined && morphTargets.length > 0) {
  16626. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16627. }
  16628. }
  16629. }
  16630. });
  16631. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  16632. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  16633. if (rayPointDistanceSq < localThresholdSq) {
  16634. var intersectPoint = new Vector3();
  16635. _ray$2.closestPointToPoint(point, intersectPoint);
  16636. intersectPoint.applyMatrix4(matrixWorld);
  16637. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  16638. if (distance < raycaster.near || distance > raycaster.far) return;
  16639. intersects.push({
  16640. distance: distance,
  16641. distanceToRay: Math.sqrt(rayPointDistanceSq),
  16642. point: intersectPoint,
  16643. index: index,
  16644. face: null,
  16645. object: object
  16646. });
  16647. }
  16648. }
  16649. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16650. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16651. this.format = format !== undefined ? format : RGBFormat;
  16652. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16653. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16654. this.generateMipmaps = false;
  16655. var scope = this;
  16656. function updateVideo() {
  16657. scope.needsUpdate = true;
  16658. video.requestVideoFrameCallback(updateVideo);
  16659. }
  16660. if ('requestVideoFrameCallback' in video) {
  16661. video.requestVideoFrameCallback(updateVideo);
  16662. }
  16663. }
  16664. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  16665. constructor: VideoTexture,
  16666. clone: function clone() {
  16667. return new this.constructor(this.image).copy(this);
  16668. },
  16669. isVideoTexture: true,
  16670. update: function update() {
  16671. var video = this.image;
  16672. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  16673. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  16674. this.needsUpdate = true;
  16675. }
  16676. }
  16677. });
  16678. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  16679. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  16680. this.image = {
  16681. width: width,
  16682. height: height
  16683. };
  16684. this.mipmaps = mipmaps; // no flipping for cube textures
  16685. // (also flipping doesn't work for compressed textures )
  16686. this.flipY = false; // can't generate mipmaps for compressed textures
  16687. // mips must be embedded in DDS files
  16688. this.generateMipmaps = false;
  16689. }
  16690. CompressedTexture.prototype = Object.create(Texture.prototype);
  16691. CompressedTexture.prototype.constructor = CompressedTexture;
  16692. CompressedTexture.prototype.isCompressedTexture = true;
  16693. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16694. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16695. this.needsUpdate = true;
  16696. }
  16697. CanvasTexture.prototype = Object.create(Texture.prototype);
  16698. CanvasTexture.prototype.constructor = CanvasTexture;
  16699. CanvasTexture.prototype.isCanvasTexture = true;
  16700. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  16701. format = format !== undefined ? format : DepthFormat;
  16702. if (format !== DepthFormat && format !== DepthStencilFormat) {
  16703. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  16704. }
  16705. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  16706. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  16707. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16708. this.image = {
  16709. width: width,
  16710. height: height
  16711. };
  16712. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16713. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16714. this.flipY = false;
  16715. this.generateMipmaps = false;
  16716. }
  16717. DepthTexture.prototype = Object.create(Texture.prototype);
  16718. DepthTexture.prototype.constructor = DepthTexture;
  16719. DepthTexture.prototype.isDepthTexture = true;
  16720. var _geometryId = 0; // Geometry uses even numbers as Id
  16721. var _m1$3 = new Matrix4();
  16722. var _obj$1 = new Object3D();
  16723. var _offset$1 = new Vector3();
  16724. function Geometry() {
  16725. Object.defineProperty(this, 'id', {
  16726. value: _geometryId += 2
  16727. });
  16728. this.uuid = MathUtils.generateUUID();
  16729. this.name = '';
  16730. this.type = 'Geometry';
  16731. this.vertices = [];
  16732. this.colors = [];
  16733. this.faces = [];
  16734. this.faceVertexUvs = [[]];
  16735. this.morphTargets = [];
  16736. this.morphNormals = [];
  16737. this.skinWeights = [];
  16738. this.skinIndices = [];
  16739. this.lineDistances = [];
  16740. this.boundingBox = null;
  16741. this.boundingSphere = null; // update flags
  16742. this.elementsNeedUpdate = false;
  16743. this.verticesNeedUpdate = false;
  16744. this.uvsNeedUpdate = false;
  16745. this.normalsNeedUpdate = false;
  16746. this.colorsNeedUpdate = false;
  16747. this.lineDistancesNeedUpdate = false;
  16748. this.groupsNeedUpdate = false;
  16749. }
  16750. Geometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  16751. constructor: Geometry,
  16752. isGeometry: true,
  16753. applyMatrix4: function applyMatrix4(matrix) {
  16754. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  16755. for (var i = 0, il = this.vertices.length; i < il; i++) {
  16756. var vertex = this.vertices[i];
  16757. vertex.applyMatrix4(matrix);
  16758. }
  16759. for (var _i = 0, _il = this.faces.length; _i < _il; _i++) {
  16760. var face = this.faces[_i];
  16761. face.normal.applyMatrix3(normalMatrix).normalize();
  16762. for (var j = 0, jl = face.vertexNormals.length; j < jl; j++) {
  16763. face.vertexNormals[j].applyMatrix3(normalMatrix).normalize();
  16764. }
  16765. }
  16766. if (this.boundingBox !== null) {
  16767. this.computeBoundingBox();
  16768. }
  16769. if (this.boundingSphere !== null) {
  16770. this.computeBoundingSphere();
  16771. }
  16772. this.verticesNeedUpdate = true;
  16773. this.normalsNeedUpdate = true;
  16774. return this;
  16775. },
  16776. rotateX: function rotateX(angle) {
  16777. // rotate geometry around world x-axis
  16778. _m1$3.makeRotationX(angle);
  16779. this.applyMatrix4(_m1$3);
  16780. return this;
  16781. },
  16782. rotateY: function rotateY(angle) {
  16783. // rotate geometry around world y-axis
  16784. _m1$3.makeRotationY(angle);
  16785. this.applyMatrix4(_m1$3);
  16786. return this;
  16787. },
  16788. rotateZ: function rotateZ(angle) {
  16789. // rotate geometry around world z-axis
  16790. _m1$3.makeRotationZ(angle);
  16791. this.applyMatrix4(_m1$3);
  16792. return this;
  16793. },
  16794. translate: function translate(x, y, z) {
  16795. // translate geometry
  16796. _m1$3.makeTranslation(x, y, z);
  16797. this.applyMatrix4(_m1$3);
  16798. return this;
  16799. },
  16800. scale: function scale(x, y, z) {
  16801. // scale geometry
  16802. _m1$3.makeScale(x, y, z);
  16803. this.applyMatrix4(_m1$3);
  16804. return this;
  16805. },
  16806. lookAt: function lookAt(vector) {
  16807. _obj$1.lookAt(vector);
  16808. _obj$1.updateMatrix();
  16809. this.applyMatrix4(_obj$1.matrix);
  16810. return this;
  16811. },
  16812. fromBufferGeometry: function fromBufferGeometry(geometry) {
  16813. var scope = this;
  16814. var index = geometry.index !== null ? geometry.index : undefined;
  16815. var attributes = geometry.attributes;
  16816. if (attributes.position === undefined) {
  16817. console.error('THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.');
  16818. return this;
  16819. }
  16820. var position = attributes.position;
  16821. var normal = attributes.normal;
  16822. var color = attributes.color;
  16823. var uv = attributes.uv;
  16824. var uv2 = attributes.uv2;
  16825. if (uv2 !== undefined) this.faceVertexUvs[1] = [];
  16826. for (var i = 0; i < position.count; i++) {
  16827. scope.vertices.push(new Vector3().fromBufferAttribute(position, i));
  16828. if (color !== undefined) {
  16829. scope.colors.push(new Color().fromBufferAttribute(color, i));
  16830. }
  16831. }
  16832. function addFace(a, b, c, materialIndex) {
  16833. var vertexColors = color === undefined ? [] : [scope.colors[a].clone(), scope.colors[b].clone(), scope.colors[c].clone()];
  16834. var vertexNormals = normal === undefined ? [] : [new Vector3().fromBufferAttribute(normal, a), new Vector3().fromBufferAttribute(normal, b), new Vector3().fromBufferAttribute(normal, c)];
  16835. var face = new Face3(a, b, c, vertexNormals, vertexColors, materialIndex);
  16836. scope.faces.push(face);
  16837. if (uv !== undefined) {
  16838. scope.faceVertexUvs[0].push([new Vector2().fromBufferAttribute(uv, a), new Vector2().fromBufferAttribute(uv, b), new Vector2().fromBufferAttribute(uv, c)]);
  16839. }
  16840. if (uv2 !== undefined) {
  16841. scope.faceVertexUvs[1].push([new Vector2().fromBufferAttribute(uv2, a), new Vector2().fromBufferAttribute(uv2, b), new Vector2().fromBufferAttribute(uv2, c)]);
  16842. }
  16843. }
  16844. var groups = geometry.groups;
  16845. if (groups.length > 0) {
  16846. for (var _i2 = 0; _i2 < groups.length; _i2++) {
  16847. var group = groups[_i2];
  16848. var start = group.start;
  16849. var count = group.count;
  16850. for (var j = start, jl = start + count; j < jl; j += 3) {
  16851. if (index !== undefined) {
  16852. addFace(index.getX(j), index.getX(j + 1), index.getX(j + 2), group.materialIndex);
  16853. } else {
  16854. addFace(j, j + 1, j + 2, group.materialIndex);
  16855. }
  16856. }
  16857. }
  16858. } else {
  16859. if (index !== undefined) {
  16860. for (var _i3 = 0; _i3 < index.count; _i3 += 3) {
  16861. addFace(index.getX(_i3), index.getX(_i3 + 1), index.getX(_i3 + 2));
  16862. }
  16863. } else {
  16864. for (var _i4 = 0; _i4 < position.count; _i4 += 3) {
  16865. addFace(_i4, _i4 + 1, _i4 + 2);
  16866. }
  16867. }
  16868. }
  16869. this.computeFaceNormals();
  16870. if (geometry.boundingBox !== null) {
  16871. this.boundingBox = geometry.boundingBox.clone();
  16872. }
  16873. if (geometry.boundingSphere !== null) {
  16874. this.boundingSphere = geometry.boundingSphere.clone();
  16875. }
  16876. return this;
  16877. },
  16878. center: function center() {
  16879. this.computeBoundingBox();
  16880. this.boundingBox.getCenter(_offset$1).negate();
  16881. this.translate(_offset$1.x, _offset$1.y, _offset$1.z);
  16882. return this;
  16883. },
  16884. normalize: function normalize() {
  16885. this.computeBoundingSphere();
  16886. var center = this.boundingSphere.center;
  16887. var radius = this.boundingSphere.radius;
  16888. var s = radius === 0 ? 1 : 1.0 / radius;
  16889. var matrix = new Matrix4();
  16890. matrix.set(s, 0, 0, -s * center.x, 0, s, 0, -s * center.y, 0, 0, s, -s * center.z, 0, 0, 0, 1);
  16891. this.applyMatrix4(matrix);
  16892. return this;
  16893. },
  16894. computeFaceNormals: function computeFaceNormals() {
  16895. var cb = new Vector3(),
  16896. ab = new Vector3();
  16897. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16898. var face = this.faces[f];
  16899. var vA = this.vertices[face.a];
  16900. var vB = this.vertices[face.b];
  16901. var vC = this.vertices[face.c];
  16902. cb.subVectors(vC, vB);
  16903. ab.subVectors(vA, vB);
  16904. cb.cross(ab);
  16905. cb.normalize();
  16906. face.normal.copy(cb);
  16907. }
  16908. },
  16909. computeVertexNormals: function computeVertexNormals(areaWeighted) {
  16910. if (areaWeighted === void 0) {
  16911. areaWeighted = true;
  16912. }
  16913. var vertices = new Array(this.vertices.length);
  16914. for (var v = 0, vl = this.vertices.length; v < vl; v++) {
  16915. vertices[v] = new Vector3();
  16916. }
  16917. if (areaWeighted) {
  16918. // vertex normals weighted by triangle areas
  16919. // http://www.iquilezles.org/www/articles/normals/normals.htm
  16920. var cb = new Vector3(),
  16921. ab = new Vector3();
  16922. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16923. var face = this.faces[f];
  16924. var vA = this.vertices[face.a];
  16925. var vB = this.vertices[face.b];
  16926. var vC = this.vertices[face.c];
  16927. cb.subVectors(vC, vB);
  16928. ab.subVectors(vA, vB);
  16929. cb.cross(ab);
  16930. vertices[face.a].add(cb);
  16931. vertices[face.b].add(cb);
  16932. vertices[face.c].add(cb);
  16933. }
  16934. } else {
  16935. this.computeFaceNormals();
  16936. for (var _f = 0, _fl = this.faces.length; _f < _fl; _f++) {
  16937. var _face = this.faces[_f];
  16938. vertices[_face.a].add(_face.normal);
  16939. vertices[_face.b].add(_face.normal);
  16940. vertices[_face.c].add(_face.normal);
  16941. }
  16942. }
  16943. for (var _v = 0, _vl = this.vertices.length; _v < _vl; _v++) {
  16944. vertices[_v].normalize();
  16945. }
  16946. for (var _f2 = 0, _fl2 = this.faces.length; _f2 < _fl2; _f2++) {
  16947. var _face2 = this.faces[_f2];
  16948. var vertexNormals = _face2.vertexNormals;
  16949. if (vertexNormals.length === 3) {
  16950. vertexNormals[0].copy(vertices[_face2.a]);
  16951. vertexNormals[1].copy(vertices[_face2.b]);
  16952. vertexNormals[2].copy(vertices[_face2.c]);
  16953. } else {
  16954. vertexNormals[0] = vertices[_face2.a].clone();
  16955. vertexNormals[1] = vertices[_face2.b].clone();
  16956. vertexNormals[2] = vertices[_face2.c].clone();
  16957. }
  16958. }
  16959. if (this.faces.length > 0) {
  16960. this.normalsNeedUpdate = true;
  16961. }
  16962. },
  16963. computeFlatVertexNormals: function computeFlatVertexNormals() {
  16964. this.computeFaceNormals();
  16965. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16966. var face = this.faces[f];
  16967. var vertexNormals = face.vertexNormals;
  16968. if (vertexNormals.length === 3) {
  16969. vertexNormals[0].copy(face.normal);
  16970. vertexNormals[1].copy(face.normal);
  16971. vertexNormals[2].copy(face.normal);
  16972. } else {
  16973. vertexNormals[0] = face.normal.clone();
  16974. vertexNormals[1] = face.normal.clone();
  16975. vertexNormals[2] = face.normal.clone();
  16976. }
  16977. }
  16978. if (this.faces.length > 0) {
  16979. this.normalsNeedUpdate = true;
  16980. }
  16981. },
  16982. computeMorphNormals: function computeMorphNormals() {
  16983. // save original normals
  16984. // - create temp variables on first access
  16985. // otherwise just copy (for faster repeated calls)
  16986. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16987. var face = this.faces[f];
  16988. if (!face.__originalFaceNormal) {
  16989. face.__originalFaceNormal = face.normal.clone();
  16990. } else {
  16991. face.__originalFaceNormal.copy(face.normal);
  16992. }
  16993. if (!face.__originalVertexNormals) face.__originalVertexNormals = [];
  16994. for (var i = 0, il = face.vertexNormals.length; i < il; i++) {
  16995. if (!face.__originalVertexNormals[i]) {
  16996. face.__originalVertexNormals[i] = face.vertexNormals[i].clone();
  16997. } else {
  16998. face.__originalVertexNormals[i].copy(face.vertexNormals[i]);
  16999. }
  17000. }
  17001. } // use temp geometry to compute face and vertex normals for each morph
  17002. var tmpGeo = new Geometry();
  17003. tmpGeo.faces = this.faces;
  17004. for (var _i5 = 0, _il2 = this.morphTargets.length; _i5 < _il2; _i5++) {
  17005. // create on first access
  17006. if (!this.morphNormals[_i5]) {
  17007. this.morphNormals[_i5] = {};
  17008. this.morphNormals[_i5].faceNormals = [];
  17009. this.morphNormals[_i5].vertexNormals = [];
  17010. var dstNormalsFace = this.morphNormals[_i5].faceNormals;
  17011. var dstNormalsVertex = this.morphNormals[_i5].vertexNormals;
  17012. for (var _f3 = 0, _fl3 = this.faces.length; _f3 < _fl3; _f3++) {
  17013. var faceNormal = new Vector3();
  17014. var vertexNormals = {
  17015. a: new Vector3(),
  17016. b: new Vector3(),
  17017. c: new Vector3()
  17018. };
  17019. dstNormalsFace.push(faceNormal);
  17020. dstNormalsVertex.push(vertexNormals);
  17021. }
  17022. }
  17023. var morphNormals = this.morphNormals[_i5]; // set vertices to morph target
  17024. tmpGeo.vertices = this.morphTargets[_i5].vertices; // compute morph normals
  17025. tmpGeo.computeFaceNormals();
  17026. tmpGeo.computeVertexNormals(); // store morph normals
  17027. for (var _f4 = 0, _fl4 = this.faces.length; _f4 < _fl4; _f4++) {
  17028. var _face3 = this.faces[_f4];
  17029. var _faceNormal = morphNormals.faceNormals[_f4];
  17030. var _vertexNormals = morphNormals.vertexNormals[_f4];
  17031. _faceNormal.copy(_face3.normal);
  17032. _vertexNormals.a.copy(_face3.vertexNormals[0]);
  17033. _vertexNormals.b.copy(_face3.vertexNormals[1]);
  17034. _vertexNormals.c.copy(_face3.vertexNormals[2]);
  17035. }
  17036. } // restore original normals
  17037. for (var _f5 = 0, _fl5 = this.faces.length; _f5 < _fl5; _f5++) {
  17038. var _face4 = this.faces[_f5];
  17039. _face4.normal = _face4.__originalFaceNormal;
  17040. _face4.vertexNormals = _face4.__originalVertexNormals;
  17041. }
  17042. },
  17043. computeBoundingBox: function computeBoundingBox() {
  17044. if (this.boundingBox === null) {
  17045. this.boundingBox = new Box3();
  17046. }
  17047. this.boundingBox.setFromPoints(this.vertices);
  17048. },
  17049. computeBoundingSphere: function computeBoundingSphere() {
  17050. if (this.boundingSphere === null) {
  17051. this.boundingSphere = new Sphere();
  17052. }
  17053. this.boundingSphere.setFromPoints(this.vertices);
  17054. },
  17055. merge: function merge(geometry, matrix, materialIndexOffset) {
  17056. if (materialIndexOffset === void 0) {
  17057. materialIndexOffset = 0;
  17058. }
  17059. if (!(geometry && geometry.isGeometry)) {
  17060. console.error('THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry);
  17061. return;
  17062. }
  17063. var normalMatrix;
  17064. var vertexOffset = this.vertices.length,
  17065. vertices1 = this.vertices,
  17066. vertices2 = geometry.vertices,
  17067. faces1 = this.faces,
  17068. faces2 = geometry.faces,
  17069. colors1 = this.colors,
  17070. colors2 = geometry.colors;
  17071. if (matrix !== undefined) {
  17072. normalMatrix = new Matrix3().getNormalMatrix(matrix);
  17073. } // vertices
  17074. for (var i = 0, il = vertices2.length; i < il; i++) {
  17075. var vertex = vertices2[i];
  17076. var vertexCopy = vertex.clone();
  17077. if (matrix !== undefined) vertexCopy.applyMatrix4(matrix);
  17078. vertices1.push(vertexCopy);
  17079. } // colors
  17080. for (var _i6 = 0, _il3 = colors2.length; _i6 < _il3; _i6++) {
  17081. colors1.push(colors2[_i6].clone());
  17082. } // faces
  17083. for (var _i7 = 0, _il4 = faces2.length; _i7 < _il4; _i7++) {
  17084. var face = faces2[_i7];
  17085. var normal = void 0,
  17086. color = void 0;
  17087. var faceVertexNormals = face.vertexNormals,
  17088. faceVertexColors = face.vertexColors;
  17089. var faceCopy = new Face3(face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset);
  17090. faceCopy.normal.copy(face.normal);
  17091. if (normalMatrix !== undefined) {
  17092. faceCopy.normal.applyMatrix3(normalMatrix).normalize();
  17093. }
  17094. for (var j = 0, jl = faceVertexNormals.length; j < jl; j++) {
  17095. normal = faceVertexNormals[j].clone();
  17096. if (normalMatrix !== undefined) {
  17097. normal.applyMatrix3(normalMatrix).normalize();
  17098. }
  17099. faceCopy.vertexNormals.push(normal);
  17100. }
  17101. faceCopy.color.copy(face.color);
  17102. for (var _j = 0, _jl = faceVertexColors.length; _j < _jl; _j++) {
  17103. color = faceVertexColors[_j];
  17104. faceCopy.vertexColors.push(color.clone());
  17105. }
  17106. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  17107. faces1.push(faceCopy);
  17108. } // uvs
  17109. for (var _i8 = 0, _il5 = geometry.faceVertexUvs.length; _i8 < _il5; _i8++) {
  17110. var faceVertexUvs2 = geometry.faceVertexUvs[_i8];
  17111. if (this.faceVertexUvs[_i8] === undefined) this.faceVertexUvs[_i8] = [];
  17112. for (var _j2 = 0, _jl2 = faceVertexUvs2.length; _j2 < _jl2; _j2++) {
  17113. var uvs2 = faceVertexUvs2[_j2],
  17114. uvsCopy = [];
  17115. for (var k = 0, kl = uvs2.length; k < kl; k++) {
  17116. uvsCopy.push(uvs2[k].clone());
  17117. }
  17118. this.faceVertexUvs[_i8].push(uvsCopy);
  17119. }
  17120. }
  17121. },
  17122. mergeMesh: function mergeMesh(mesh) {
  17123. if (!(mesh && mesh.isMesh)) {
  17124. console.error('THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh);
  17125. return;
  17126. }
  17127. if (mesh.matrixAutoUpdate) mesh.updateMatrix();
  17128. this.merge(mesh.geometry, mesh.matrix);
  17129. },
  17130. /*
  17131. * Checks for duplicate vertices with hashmap.
  17132. * Duplicated vertices are removed
  17133. * and faces' vertices are updated.
  17134. */
  17135. mergeVertices: function mergeVertices(precisionPoints) {
  17136. if (precisionPoints === void 0) {
  17137. precisionPoints = 4;
  17138. }
  17139. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  17140. var unique = [],
  17141. changes = [];
  17142. var precision = Math.pow(10, precisionPoints);
  17143. for (var i = 0, il = this.vertices.length; i < il; i++) {
  17144. var v = this.vertices[i];
  17145. var key = Math.round(v.x * precision) + '_' + Math.round(v.y * precision) + '_' + Math.round(v.z * precision);
  17146. if (verticesMap[key] === undefined) {
  17147. verticesMap[key] = i;
  17148. unique.push(this.vertices[i]);
  17149. changes[i] = unique.length - 1;
  17150. } else {
  17151. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  17152. changes[i] = changes[verticesMap[key]];
  17153. }
  17154. } // if faces are completely degenerate after merging vertices, we
  17155. // have to remove them from the geometry.
  17156. var faceIndicesToRemove = [];
  17157. for (var _i9 = 0, _il6 = this.faces.length; _i9 < _il6; _i9++) {
  17158. var face = this.faces[_i9];
  17159. face.a = changes[face.a];
  17160. face.b = changes[face.b];
  17161. face.c = changes[face.c];
  17162. var indices = [face.a, face.b, face.c]; // if any duplicate vertices are found in a Face3
  17163. // we have to remove the face as nothing can be saved
  17164. for (var n = 0; n < 3; n++) {
  17165. if (indices[n] === indices[(n + 1) % 3]) {
  17166. faceIndicesToRemove.push(_i9);
  17167. break;
  17168. }
  17169. }
  17170. }
  17171. for (var _i10 = faceIndicesToRemove.length - 1; _i10 >= 0; _i10--) {
  17172. var idx = faceIndicesToRemove[_i10];
  17173. this.faces.splice(idx, 1);
  17174. for (var j = 0, jl = this.faceVertexUvs.length; j < jl; j++) {
  17175. this.faceVertexUvs[j].splice(idx, 1);
  17176. }
  17177. } // Use unique set of vertices
  17178. var diff = this.vertices.length - unique.length;
  17179. this.vertices = unique;
  17180. return diff;
  17181. },
  17182. setFromPoints: function setFromPoints(points) {
  17183. this.vertices = [];
  17184. for (var i = 0, l = points.length; i < l; i++) {
  17185. var point = points[i];
  17186. this.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  17187. }
  17188. return this;
  17189. },
  17190. sortFacesByMaterialIndex: function sortFacesByMaterialIndex() {
  17191. var faces = this.faces;
  17192. var length = faces.length; // tag faces
  17193. for (var i = 0; i < length; i++) {
  17194. faces[i]._id = i;
  17195. } // sort faces
  17196. function materialIndexSort(a, b) {
  17197. return a.materialIndex - b.materialIndex;
  17198. }
  17199. faces.sort(materialIndexSort); // sort uvs
  17200. var uvs1 = this.faceVertexUvs[0];
  17201. var uvs2 = this.faceVertexUvs[1];
  17202. var newUvs1, newUvs2;
  17203. if (uvs1 && uvs1.length === length) newUvs1 = [];
  17204. if (uvs2 && uvs2.length === length) newUvs2 = [];
  17205. for (var _i11 = 0; _i11 < length; _i11++) {
  17206. var id = faces[_i11]._id;
  17207. if (newUvs1) newUvs1.push(uvs1[id]);
  17208. if (newUvs2) newUvs2.push(uvs2[id]);
  17209. }
  17210. if (newUvs1) this.faceVertexUvs[0] = newUvs1;
  17211. if (newUvs2) this.faceVertexUvs[1] = newUvs2;
  17212. },
  17213. toJSON: function toJSON() {
  17214. var data = {
  17215. metadata: {
  17216. version: 4.5,
  17217. type: 'Geometry',
  17218. generator: 'Geometry.toJSON'
  17219. }
  17220. }; // standard Geometry serialization
  17221. data.uuid = this.uuid;
  17222. data.type = this.type;
  17223. if (this.name !== '') data.name = this.name;
  17224. if (this.parameters !== undefined) {
  17225. var parameters = this.parameters;
  17226. for (var key in parameters) {
  17227. if (parameters[key] !== undefined) data[key] = parameters[key];
  17228. }
  17229. return data;
  17230. }
  17231. var vertices = [];
  17232. for (var i = 0; i < this.vertices.length; i++) {
  17233. var vertex = this.vertices[i];
  17234. vertices.push(vertex.x, vertex.y, vertex.z);
  17235. }
  17236. var faces = [];
  17237. var normals = [];
  17238. var normalsHash = {};
  17239. var colors = [];
  17240. var colorsHash = {};
  17241. var uvs = [];
  17242. var uvsHash = {};
  17243. for (var _i12 = 0; _i12 < this.faces.length; _i12++) {
  17244. var face = this.faces[_i12];
  17245. var hasMaterial = true;
  17246. var hasFaceUv = false; // deprecated
  17247. var hasFaceVertexUv = this.faceVertexUvs[0][_i12] !== undefined;
  17248. var hasFaceNormal = face.normal.length() > 0;
  17249. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  17250. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  17251. var hasFaceVertexColor = face.vertexColors.length > 0;
  17252. var faceType = 0;
  17253. faceType = setBit(faceType, 0, 0); // isQuad
  17254. faceType = setBit(faceType, 1, hasMaterial);
  17255. faceType = setBit(faceType, 2, hasFaceUv);
  17256. faceType = setBit(faceType, 3, hasFaceVertexUv);
  17257. faceType = setBit(faceType, 4, hasFaceNormal);
  17258. faceType = setBit(faceType, 5, hasFaceVertexNormal);
  17259. faceType = setBit(faceType, 6, hasFaceColor);
  17260. faceType = setBit(faceType, 7, hasFaceVertexColor);
  17261. faces.push(faceType);
  17262. faces.push(face.a, face.b, face.c);
  17263. faces.push(face.materialIndex);
  17264. if (hasFaceVertexUv) {
  17265. var faceVertexUvs = this.faceVertexUvs[0][_i12];
  17266. faces.push(getUvIndex(faceVertexUvs[0]), getUvIndex(faceVertexUvs[1]), getUvIndex(faceVertexUvs[2]));
  17267. }
  17268. if (hasFaceNormal) {
  17269. faces.push(getNormalIndex(face.normal));
  17270. }
  17271. if (hasFaceVertexNormal) {
  17272. var vertexNormals = face.vertexNormals;
  17273. faces.push(getNormalIndex(vertexNormals[0]), getNormalIndex(vertexNormals[1]), getNormalIndex(vertexNormals[2]));
  17274. }
  17275. if (hasFaceColor) {
  17276. faces.push(getColorIndex(face.color));
  17277. }
  17278. if (hasFaceVertexColor) {
  17279. var vertexColors = face.vertexColors;
  17280. faces.push(getColorIndex(vertexColors[0]), getColorIndex(vertexColors[1]), getColorIndex(vertexColors[2]));
  17281. }
  17282. }
  17283. function setBit(value, position, enabled) {
  17284. return enabled ? value | 1 << position : value & ~(1 << position);
  17285. }
  17286. function getNormalIndex(normal) {
  17287. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  17288. if (normalsHash[hash] !== undefined) {
  17289. return normalsHash[hash];
  17290. }
  17291. normalsHash[hash] = normals.length / 3;
  17292. normals.push(normal.x, normal.y, normal.z);
  17293. return normalsHash[hash];
  17294. }
  17295. function getColorIndex(color) {
  17296. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  17297. if (colorsHash[hash] !== undefined) {
  17298. return colorsHash[hash];
  17299. }
  17300. colorsHash[hash] = colors.length;
  17301. colors.push(color.getHex());
  17302. return colorsHash[hash];
  17303. }
  17304. function getUvIndex(uv) {
  17305. var hash = uv.x.toString() + uv.y.toString();
  17306. if (uvsHash[hash] !== undefined) {
  17307. return uvsHash[hash];
  17308. }
  17309. uvsHash[hash] = uvs.length / 2;
  17310. uvs.push(uv.x, uv.y);
  17311. return uvsHash[hash];
  17312. }
  17313. data.data = {};
  17314. data.data.vertices = vertices;
  17315. data.data.normals = normals;
  17316. if (colors.length > 0) data.data.colors = colors;
  17317. if (uvs.length > 0) data.data.uvs = [uvs]; // temporal backward compatibility
  17318. data.data.faces = faces;
  17319. return data;
  17320. },
  17321. clone: function clone() {
  17322. /*
  17323. // Handle primitives
  17324. const parameters = this.parameters;
  17325. if ( parameters !== undefined ) {
  17326. const values = [];
  17327. for ( const key in parameters ) {
  17328. values.push( parameters[ key ] );
  17329. }
  17330. const geometry = Object.create( this.constructor.prototype );
  17331. this.constructor.apply( geometry, values );
  17332. return geometry;
  17333. }
  17334. return new this.constructor().copy( this );
  17335. */
  17336. return new Geometry().copy(this);
  17337. },
  17338. copy: function copy(source) {
  17339. // reset
  17340. this.vertices = [];
  17341. this.colors = [];
  17342. this.faces = [];
  17343. this.faceVertexUvs = [[]];
  17344. this.morphTargets = [];
  17345. this.morphNormals = [];
  17346. this.skinWeights = [];
  17347. this.skinIndices = [];
  17348. this.lineDistances = [];
  17349. this.boundingBox = null;
  17350. this.boundingSphere = null; // name
  17351. this.name = source.name; // vertices
  17352. var vertices = source.vertices;
  17353. for (var i = 0, il = vertices.length; i < il; i++) {
  17354. this.vertices.push(vertices[i].clone());
  17355. } // colors
  17356. var colors = source.colors;
  17357. for (var _i13 = 0, _il7 = colors.length; _i13 < _il7; _i13++) {
  17358. this.colors.push(colors[_i13].clone());
  17359. } // faces
  17360. var faces = source.faces;
  17361. for (var _i14 = 0, _il8 = faces.length; _i14 < _il8; _i14++) {
  17362. this.faces.push(faces[_i14].clone());
  17363. } // face vertex uvs
  17364. for (var _i15 = 0, _il9 = source.faceVertexUvs.length; _i15 < _il9; _i15++) {
  17365. var faceVertexUvs = source.faceVertexUvs[_i15];
  17366. if (this.faceVertexUvs[_i15] === undefined) {
  17367. this.faceVertexUvs[_i15] = [];
  17368. }
  17369. for (var j = 0, jl = faceVertexUvs.length; j < jl; j++) {
  17370. var uvs = faceVertexUvs[j],
  17371. uvsCopy = [];
  17372. for (var k = 0, kl = uvs.length; k < kl; k++) {
  17373. var uv = uvs[k];
  17374. uvsCopy.push(uv.clone());
  17375. }
  17376. this.faceVertexUvs[_i15].push(uvsCopy);
  17377. }
  17378. } // morph targets
  17379. var morphTargets = source.morphTargets;
  17380. for (var _i16 = 0, _il10 = morphTargets.length; _i16 < _il10; _i16++) {
  17381. var morphTarget = {};
  17382. morphTarget.name = morphTargets[_i16].name; // vertices
  17383. if (morphTargets[_i16].vertices !== undefined) {
  17384. morphTarget.vertices = [];
  17385. for (var _j3 = 0, _jl3 = morphTargets[_i16].vertices.length; _j3 < _jl3; _j3++) {
  17386. morphTarget.vertices.push(morphTargets[_i16].vertices[_j3].clone());
  17387. }
  17388. } // normals
  17389. if (morphTargets[_i16].normals !== undefined) {
  17390. morphTarget.normals = [];
  17391. for (var _j4 = 0, _jl4 = morphTargets[_i16].normals.length; _j4 < _jl4; _j4++) {
  17392. morphTarget.normals.push(morphTargets[_i16].normals[_j4].clone());
  17393. }
  17394. }
  17395. this.morphTargets.push(morphTarget);
  17396. } // morph normals
  17397. var morphNormals = source.morphNormals;
  17398. for (var _i17 = 0, _il11 = morphNormals.length; _i17 < _il11; _i17++) {
  17399. var morphNormal = {}; // vertex normals
  17400. if (morphNormals[_i17].vertexNormals !== undefined) {
  17401. morphNormal.vertexNormals = [];
  17402. for (var _j5 = 0, _jl5 = morphNormals[_i17].vertexNormals.length; _j5 < _jl5; _j5++) {
  17403. var srcVertexNormal = morphNormals[_i17].vertexNormals[_j5];
  17404. var destVertexNormal = {};
  17405. destVertexNormal.a = srcVertexNormal.a.clone();
  17406. destVertexNormal.b = srcVertexNormal.b.clone();
  17407. destVertexNormal.c = srcVertexNormal.c.clone();
  17408. morphNormal.vertexNormals.push(destVertexNormal);
  17409. }
  17410. } // face normals
  17411. if (morphNormals[_i17].faceNormals !== undefined) {
  17412. morphNormal.faceNormals = [];
  17413. for (var _j6 = 0, _jl6 = morphNormals[_i17].faceNormals.length; _j6 < _jl6; _j6++) {
  17414. morphNormal.faceNormals.push(morphNormals[_i17].faceNormals[_j6].clone());
  17415. }
  17416. }
  17417. this.morphNormals.push(morphNormal);
  17418. } // skin weights
  17419. var skinWeights = source.skinWeights;
  17420. for (var _i18 = 0, _il12 = skinWeights.length; _i18 < _il12; _i18++) {
  17421. this.skinWeights.push(skinWeights[_i18].clone());
  17422. } // skin indices
  17423. var skinIndices = source.skinIndices;
  17424. for (var _i19 = 0, _il13 = skinIndices.length; _i19 < _il13; _i19++) {
  17425. this.skinIndices.push(skinIndices[_i19].clone());
  17426. } // line distances
  17427. var lineDistances = source.lineDistances;
  17428. for (var _i20 = 0, _il14 = lineDistances.length; _i20 < _il14; _i20++) {
  17429. this.lineDistances.push(lineDistances[_i20]);
  17430. } // bounding box
  17431. var boundingBox = source.boundingBox;
  17432. if (boundingBox !== null) {
  17433. this.boundingBox = boundingBox.clone();
  17434. } // bounding sphere
  17435. var boundingSphere = source.boundingSphere;
  17436. if (boundingSphere !== null) {
  17437. this.boundingSphere = boundingSphere.clone();
  17438. } // update flags
  17439. this.elementsNeedUpdate = source.elementsNeedUpdate;
  17440. this.verticesNeedUpdate = source.verticesNeedUpdate;
  17441. this.uvsNeedUpdate = source.uvsNeedUpdate;
  17442. this.normalsNeedUpdate = source.normalsNeedUpdate;
  17443. this.colorsNeedUpdate = source.colorsNeedUpdate;
  17444. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  17445. this.groupsNeedUpdate = source.groupsNeedUpdate;
  17446. return this;
  17447. },
  17448. dispose: function dispose() {
  17449. this.dispatchEvent({
  17450. type: 'dispose'
  17451. });
  17452. }
  17453. });
  17454. var BoxGeometry = /*#__PURE__*/function (_Geometry) {
  17455. _inheritsLoose(BoxGeometry, _Geometry);
  17456. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  17457. var _this;
  17458. _this = _Geometry.call(this) || this;
  17459. _this.type = 'BoxGeometry';
  17460. _this.parameters = {
  17461. width: width,
  17462. height: height,
  17463. depth: depth,
  17464. widthSegments: widthSegments,
  17465. heightSegments: heightSegments,
  17466. depthSegments: depthSegments
  17467. };
  17468. _this.fromBufferGeometry(new BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments));
  17469. _this.mergeVertices();
  17470. return _this;
  17471. }
  17472. return BoxGeometry;
  17473. }(Geometry);
  17474. var CircleBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17475. _inheritsLoose(CircleBufferGeometry, _BufferGeometry);
  17476. function CircleBufferGeometry(radius, segments, thetaStart, thetaLength) {
  17477. var _this;
  17478. if (radius === void 0) {
  17479. radius = 1;
  17480. }
  17481. if (segments === void 0) {
  17482. segments = 8;
  17483. }
  17484. if (thetaStart === void 0) {
  17485. thetaStart = 0;
  17486. }
  17487. if (thetaLength === void 0) {
  17488. thetaLength = Math.PI * 2;
  17489. }
  17490. _this = _BufferGeometry.call(this) || this;
  17491. _this.type = 'CircleBufferGeometry';
  17492. _this.parameters = {
  17493. radius: radius,
  17494. segments: segments,
  17495. thetaStart: thetaStart,
  17496. thetaLength: thetaLength
  17497. };
  17498. segments = Math.max(3, segments); // buffers
  17499. var indices = [];
  17500. var vertices = [];
  17501. var normals = [];
  17502. var uvs = []; // helper variables
  17503. var vertex = new Vector3();
  17504. var uv = new Vector2(); // center point
  17505. vertices.push(0, 0, 0);
  17506. normals.push(0, 0, 1);
  17507. uvs.push(0.5, 0.5);
  17508. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17509. var segment = thetaStart + s / segments * thetaLength; // vertex
  17510. vertex.x = radius * Math.cos(segment);
  17511. vertex.y = radius * Math.sin(segment);
  17512. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17513. normals.push(0, 0, 1); // uvs
  17514. uv.x = (vertices[i] / radius + 1) / 2;
  17515. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17516. uvs.push(uv.x, uv.y);
  17517. } // indices
  17518. for (var _i = 1; _i <= segments; _i++) {
  17519. indices.push(_i, _i + 1, 0);
  17520. } // build geometry
  17521. _this.setIndex(indices);
  17522. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17523. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17524. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17525. return _this;
  17526. }
  17527. return CircleBufferGeometry;
  17528. }(BufferGeometry);
  17529. var CircleGeometry = /*#__PURE__*/function (_Geometry) {
  17530. _inheritsLoose(CircleGeometry, _Geometry);
  17531. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17532. var _this;
  17533. _this = _Geometry.call(this) || this;
  17534. _this.type = 'CircleGeometry';
  17535. _this.parameters = {
  17536. radius: radius,
  17537. segments: segments,
  17538. thetaStart: thetaStart,
  17539. thetaLength: thetaLength
  17540. };
  17541. _this.fromBufferGeometry(new CircleBufferGeometry(radius, segments, thetaStart, thetaLength));
  17542. _this.mergeVertices();
  17543. return _this;
  17544. }
  17545. return CircleGeometry;
  17546. }(Geometry);
  17547. var CylinderBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17548. _inheritsLoose(CylinderBufferGeometry, _BufferGeometry);
  17549. function CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17550. var _this;
  17551. if (radiusTop === void 0) {
  17552. radiusTop = 1;
  17553. }
  17554. if (radiusBottom === void 0) {
  17555. radiusBottom = 1;
  17556. }
  17557. if (height === void 0) {
  17558. height = 1;
  17559. }
  17560. if (radialSegments === void 0) {
  17561. radialSegments = 8;
  17562. }
  17563. if (heightSegments === void 0) {
  17564. heightSegments = 1;
  17565. }
  17566. if (openEnded === void 0) {
  17567. openEnded = false;
  17568. }
  17569. if (thetaStart === void 0) {
  17570. thetaStart = 0;
  17571. }
  17572. if (thetaLength === void 0) {
  17573. thetaLength = Math.PI * 2;
  17574. }
  17575. _this = _BufferGeometry.call(this) || this;
  17576. _this.type = 'CylinderBufferGeometry';
  17577. _this.parameters = {
  17578. radiusTop: radiusTop,
  17579. radiusBottom: radiusBottom,
  17580. height: height,
  17581. radialSegments: radialSegments,
  17582. heightSegments: heightSegments,
  17583. openEnded: openEnded,
  17584. thetaStart: thetaStart,
  17585. thetaLength: thetaLength
  17586. };
  17587. var scope = _assertThisInitialized(_this);
  17588. radialSegments = Math.floor(radialSegments);
  17589. heightSegments = Math.floor(heightSegments); // buffers
  17590. var indices = [];
  17591. var vertices = [];
  17592. var normals = [];
  17593. var uvs = []; // helper variables
  17594. var index = 0;
  17595. var indexArray = [];
  17596. var halfHeight = height / 2;
  17597. var groupStart = 0; // generate geometry
  17598. generateTorso();
  17599. if (openEnded === false) {
  17600. if (radiusTop > 0) generateCap(true);
  17601. if (radiusBottom > 0) generateCap(false);
  17602. } // build geometry
  17603. _this.setIndex(indices);
  17604. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17605. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17606. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17607. function generateTorso() {
  17608. var normal = new Vector3();
  17609. var vertex = new Vector3();
  17610. var groupCount = 0; // this will be used to calculate the normal
  17611. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17612. for (var y = 0; y <= heightSegments; y++) {
  17613. var indexRow = [];
  17614. var v = y / heightSegments; // calculate the radius of the current row
  17615. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17616. for (var x = 0; x <= radialSegments; x++) {
  17617. var u = x / radialSegments;
  17618. var theta = u * thetaLength + thetaStart;
  17619. var sinTheta = Math.sin(theta);
  17620. var cosTheta = Math.cos(theta); // vertex
  17621. vertex.x = radius * sinTheta;
  17622. vertex.y = -v * height + halfHeight;
  17623. vertex.z = radius * cosTheta;
  17624. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17625. normal.set(sinTheta, slope, cosTheta).normalize();
  17626. normals.push(normal.x, normal.y, normal.z); // uv
  17627. uvs.push(u, 1 - v); // save index of vertex in respective row
  17628. indexRow.push(index++);
  17629. } // now save vertices of the row in our index array
  17630. indexArray.push(indexRow);
  17631. } // generate indices
  17632. for (var _x = 0; _x < radialSegments; _x++) {
  17633. for (var _y = 0; _y < heightSegments; _y++) {
  17634. // we use the index array to access the correct indices
  17635. var a = indexArray[_y][_x];
  17636. var b = indexArray[_y + 1][_x];
  17637. var c = indexArray[_y + 1][_x + 1];
  17638. var d = indexArray[_y][_x + 1]; // faces
  17639. indices.push(a, b, d);
  17640. indices.push(b, c, d); // update group counter
  17641. groupCount += 6;
  17642. }
  17643. } // add a group to the geometry. this will ensure multi material support
  17644. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17645. groupStart += groupCount;
  17646. }
  17647. function generateCap(top) {
  17648. // save the index of the first center vertex
  17649. var centerIndexStart = index;
  17650. var uv = new Vector2();
  17651. var vertex = new Vector3();
  17652. var groupCount = 0;
  17653. var radius = top === true ? radiusTop : radiusBottom;
  17654. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17655. // because the geometry needs one set of uvs per face,
  17656. // we must generate a center vertex per face/segment
  17657. for (var x = 1; x <= radialSegments; x++) {
  17658. // vertex
  17659. vertices.push(0, halfHeight * sign, 0); // normal
  17660. normals.push(0, sign, 0); // uv
  17661. uvs.push(0.5, 0.5); // increase index
  17662. index++;
  17663. } // save the index of the last center vertex
  17664. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17665. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17666. var u = _x2 / radialSegments;
  17667. var theta = u * thetaLength + thetaStart;
  17668. var cosTheta = Math.cos(theta);
  17669. var sinTheta = Math.sin(theta); // vertex
  17670. vertex.x = radius * sinTheta;
  17671. vertex.y = halfHeight * sign;
  17672. vertex.z = radius * cosTheta;
  17673. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17674. normals.push(0, sign, 0); // uv
  17675. uv.x = cosTheta * 0.5 + 0.5;
  17676. uv.y = sinTheta * 0.5 * sign + 0.5;
  17677. uvs.push(uv.x, uv.y); // increase index
  17678. index++;
  17679. } // generate indices
  17680. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17681. var c = centerIndexStart + _x3;
  17682. var i = centerIndexEnd + _x3;
  17683. if (top === true) {
  17684. // face top
  17685. indices.push(i, i + 1, c);
  17686. } else {
  17687. // face bottom
  17688. indices.push(i + 1, i, c);
  17689. }
  17690. groupCount += 3;
  17691. } // add a group to the geometry. this will ensure multi material support
  17692. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17693. groupStart += groupCount;
  17694. }
  17695. return _this;
  17696. }
  17697. return CylinderBufferGeometry;
  17698. }(BufferGeometry);
  17699. var CylinderGeometry = /*#__PURE__*/function (_Geometry) {
  17700. _inheritsLoose(CylinderGeometry, _Geometry);
  17701. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17702. var _this;
  17703. _this = _Geometry.call(this) || this;
  17704. _this.type = 'CylinderGeometry';
  17705. _this.parameters = {
  17706. radiusTop: radiusTop,
  17707. radiusBottom: radiusBottom,
  17708. height: height,
  17709. radialSegments: radialSegments,
  17710. heightSegments: heightSegments,
  17711. openEnded: openEnded,
  17712. thetaStart: thetaStart,
  17713. thetaLength: thetaLength
  17714. };
  17715. _this.fromBufferGeometry(new CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength));
  17716. _this.mergeVertices();
  17717. return _this;
  17718. }
  17719. return CylinderGeometry;
  17720. }(Geometry);
  17721. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17722. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17723. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17724. var _this;
  17725. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17726. _this.type = 'ConeGeometry';
  17727. _this.parameters = {
  17728. radius: radius,
  17729. height: height,
  17730. radialSegments: radialSegments,
  17731. heightSegments: heightSegments,
  17732. openEnded: openEnded,
  17733. thetaStart: thetaStart,
  17734. thetaLength: thetaLength
  17735. };
  17736. return _this;
  17737. }
  17738. return ConeGeometry;
  17739. }(CylinderGeometry);
  17740. var ConeBufferGeometry = /*#__PURE__*/function (_CylinderBufferGeomet) {
  17741. _inheritsLoose(ConeBufferGeometry, _CylinderBufferGeomet);
  17742. function ConeBufferGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17743. var _this;
  17744. if (radius === void 0) {
  17745. radius = 1;
  17746. }
  17747. if (height === void 0) {
  17748. height = 1;
  17749. }
  17750. if (radialSegments === void 0) {
  17751. radialSegments = 8;
  17752. }
  17753. if (heightSegments === void 0) {
  17754. heightSegments = 1;
  17755. }
  17756. if (openEnded === void 0) {
  17757. openEnded = false;
  17758. }
  17759. if (thetaStart === void 0) {
  17760. thetaStart = 0;
  17761. }
  17762. if (thetaLength === void 0) {
  17763. thetaLength = Math.PI * 2;
  17764. }
  17765. _this = _CylinderBufferGeomet.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17766. _this.type = 'ConeBufferGeometry';
  17767. _this.parameters = {
  17768. radius: radius,
  17769. height: height,
  17770. radialSegments: radialSegments,
  17771. heightSegments: heightSegments,
  17772. openEnded: openEnded,
  17773. thetaStart: thetaStart,
  17774. thetaLength: thetaLength
  17775. };
  17776. return _this;
  17777. }
  17778. return ConeBufferGeometry;
  17779. }(CylinderBufferGeometry);
  17780. var PolyhedronBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17781. _inheritsLoose(PolyhedronBufferGeometry, _BufferGeometry);
  17782. function PolyhedronBufferGeometry(vertices, indices, radius, detail) {
  17783. var _this;
  17784. if (radius === void 0) {
  17785. radius = 1;
  17786. }
  17787. if (detail === void 0) {
  17788. detail = 0;
  17789. }
  17790. _this = _BufferGeometry.call(this) || this;
  17791. _this.type = 'PolyhedronBufferGeometry';
  17792. _this.parameters = {
  17793. vertices: vertices,
  17794. indices: indices,
  17795. radius: radius,
  17796. detail: detail
  17797. }; // default buffer data
  17798. var vertexBuffer = [];
  17799. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17800. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17801. applyRadius(radius); // finally, create the uv data
  17802. generateUVs(); // build non-indexed geometry
  17803. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17804. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17805. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17806. if (detail === 0) {
  17807. _this.computeVertexNormals(); // flat normals
  17808. } else {
  17809. _this.normalizeNormals(); // smooth normals
  17810. } // helper functions
  17811. function subdivide(detail) {
  17812. var a = new Vector3();
  17813. var b = new Vector3();
  17814. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17815. for (var i = 0; i < indices.length; i += 3) {
  17816. // get the vertices of the face
  17817. getVertexByIndex(indices[i + 0], a);
  17818. getVertexByIndex(indices[i + 1], b);
  17819. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17820. subdivideFace(a, b, c, detail);
  17821. }
  17822. }
  17823. function subdivideFace(a, b, c, detail) {
  17824. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17825. var v = []; // construct all of the vertices for this subdivision
  17826. for (var i = 0; i <= cols; i++) {
  17827. v[i] = [];
  17828. var aj = a.clone().lerp(c, i / cols);
  17829. var bj = b.clone().lerp(c, i / cols);
  17830. var rows = cols - i;
  17831. for (var j = 0; j <= rows; j++) {
  17832. if (j === 0 && i === cols) {
  17833. v[i][j] = aj;
  17834. } else {
  17835. v[i][j] = aj.clone().lerp(bj, j / rows);
  17836. }
  17837. }
  17838. } // construct all of the faces
  17839. for (var _i = 0; _i < cols; _i++) {
  17840. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17841. var k = Math.floor(_j / 2);
  17842. if (_j % 2 === 0) {
  17843. pushVertex(v[_i][k + 1]);
  17844. pushVertex(v[_i + 1][k]);
  17845. pushVertex(v[_i][k]);
  17846. } else {
  17847. pushVertex(v[_i][k + 1]);
  17848. pushVertex(v[_i + 1][k + 1]);
  17849. pushVertex(v[_i + 1][k]);
  17850. }
  17851. }
  17852. }
  17853. }
  17854. function applyRadius(radius) {
  17855. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17856. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17857. vertex.x = vertexBuffer[i + 0];
  17858. vertex.y = vertexBuffer[i + 1];
  17859. vertex.z = vertexBuffer[i + 2];
  17860. vertex.normalize().multiplyScalar(radius);
  17861. vertexBuffer[i + 0] = vertex.x;
  17862. vertexBuffer[i + 1] = vertex.y;
  17863. vertexBuffer[i + 2] = vertex.z;
  17864. }
  17865. }
  17866. function generateUVs() {
  17867. var vertex = new Vector3();
  17868. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17869. vertex.x = vertexBuffer[i + 0];
  17870. vertex.y = vertexBuffer[i + 1];
  17871. vertex.z = vertexBuffer[i + 2];
  17872. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17873. var v = inclination(vertex) / Math.PI + 0.5;
  17874. uvBuffer.push(u, 1 - v);
  17875. }
  17876. correctUVs();
  17877. correctSeam();
  17878. }
  17879. function correctSeam() {
  17880. // handle case when face straddles the seam, see #3269
  17881. for (var i = 0; i < uvBuffer.length; i += 6) {
  17882. // uv data of a single face
  17883. var x0 = uvBuffer[i + 0];
  17884. var x1 = uvBuffer[i + 2];
  17885. var x2 = uvBuffer[i + 4];
  17886. var max = Math.max(x0, x1, x2);
  17887. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17888. if (max > 0.9 && min < 0.1) {
  17889. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17890. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17891. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17892. }
  17893. }
  17894. }
  17895. function pushVertex(vertex) {
  17896. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17897. }
  17898. function getVertexByIndex(index, vertex) {
  17899. var stride = index * 3;
  17900. vertex.x = vertices[stride + 0];
  17901. vertex.y = vertices[stride + 1];
  17902. vertex.z = vertices[stride + 2];
  17903. }
  17904. function correctUVs() {
  17905. var a = new Vector3();
  17906. var b = new Vector3();
  17907. var c = new Vector3();
  17908. var centroid = new Vector3();
  17909. var uvA = new Vector2();
  17910. var uvB = new Vector2();
  17911. var uvC = new Vector2();
  17912. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17913. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17914. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17915. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17916. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17917. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17918. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17919. centroid.copy(a).add(b).add(c).divideScalar(3);
  17920. var azi = azimuth(centroid);
  17921. correctUV(uvA, j + 0, a, azi);
  17922. correctUV(uvB, j + 2, b, azi);
  17923. correctUV(uvC, j + 4, c, azi);
  17924. }
  17925. }
  17926. function correctUV(uv, stride, vector, azimuth) {
  17927. if (azimuth < 0 && uv.x === 1) {
  17928. uvBuffer[stride] = uv.x - 1;
  17929. }
  17930. if (vector.x === 0 && vector.z === 0) {
  17931. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17932. }
  17933. } // Angle around the Y axis, counter-clockwise when looking from above.
  17934. function azimuth(vector) {
  17935. return Math.atan2(vector.z, -vector.x);
  17936. } // Angle above the XZ plane.
  17937. function inclination(vector) {
  17938. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17939. }
  17940. return _this;
  17941. }
  17942. return PolyhedronBufferGeometry;
  17943. }(BufferGeometry);
  17944. var DodecahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  17945. _inheritsLoose(DodecahedronBufferGeometry, _PolyhedronBufferGeom);
  17946. function DodecahedronBufferGeometry(radius, detail) {
  17947. var _this;
  17948. if (radius === void 0) {
  17949. radius = 1;
  17950. }
  17951. if (detail === void 0) {
  17952. detail = 0;
  17953. }
  17954. var t = (1 + Math.sqrt(5)) / 2;
  17955. var r = 1 / t;
  17956. var vertices = [// (±1, ±1, ±1)
  17957. -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/φ, ±φ)
  17958. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17959. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17960. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17961. 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];
  17962. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  17963. _this.type = 'DodecahedronBufferGeometry';
  17964. _this.parameters = {
  17965. radius: radius,
  17966. detail: detail
  17967. };
  17968. return _this;
  17969. }
  17970. return DodecahedronBufferGeometry;
  17971. }(PolyhedronBufferGeometry);
  17972. var DodecahedronGeometry = /*#__PURE__*/function (_Geometry) {
  17973. _inheritsLoose(DodecahedronGeometry, _Geometry);
  17974. function DodecahedronGeometry(radius, detail) {
  17975. var _this;
  17976. _this = _Geometry.call(this) || this;
  17977. _this.type = 'DodecahedronGeometry';
  17978. _this.parameters = {
  17979. radius: radius,
  17980. detail: detail
  17981. };
  17982. _this.fromBufferGeometry(new DodecahedronBufferGeometry(radius, detail));
  17983. _this.mergeVertices();
  17984. return _this;
  17985. }
  17986. return DodecahedronGeometry;
  17987. }(Geometry);
  17988. var _v0$2 = new Vector3();
  17989. var _v1$5 = new Vector3();
  17990. var _normal$1 = new Vector3();
  17991. var _triangle = new Triangle();
  17992. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17993. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17994. function EdgesGeometry(geometry, thresholdAngle) {
  17995. var _this;
  17996. _this = _BufferGeometry.call(this) || this;
  17997. _this.type = 'EdgesGeometry';
  17998. _this.parameters = {
  17999. thresholdAngle: thresholdAngle
  18000. };
  18001. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  18002. if (geometry.isGeometry) {
  18003. geometry = new BufferGeometry().fromGeometry(geometry);
  18004. }
  18005. var precisionPoints = 4;
  18006. var precision = Math.pow(10, precisionPoints);
  18007. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  18008. var indexAttr = geometry.getIndex();
  18009. var positionAttr = geometry.getAttribute('position');
  18010. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  18011. var indexArr = [0, 0, 0];
  18012. var vertKeys = ['a', 'b', 'c'];
  18013. var hashes = new Array(3);
  18014. var edgeData = {};
  18015. var vertices = [];
  18016. for (var i = 0; i < indexCount; i += 3) {
  18017. if (indexAttr) {
  18018. indexArr[0] = indexAttr.getX(i);
  18019. indexArr[1] = indexAttr.getX(i + 1);
  18020. indexArr[2] = indexAttr.getX(i + 2);
  18021. } else {
  18022. indexArr[0] = i;
  18023. indexArr[1] = i + 1;
  18024. indexArr[2] = i + 2;
  18025. }
  18026. var a = _triangle.a,
  18027. b = _triangle.b,
  18028. c = _triangle.c;
  18029. a.fromBufferAttribute(positionAttr, indexArr[0]);
  18030. b.fromBufferAttribute(positionAttr, indexArr[1]);
  18031. c.fromBufferAttribute(positionAttr, indexArr[2]);
  18032. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  18033. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  18034. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  18035. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  18036. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  18037. continue;
  18038. } // iterate over every edge
  18039. for (var j = 0; j < 3; j++) {
  18040. // get the first and next vertex making up the edge
  18041. var jNext = (j + 1) % 3;
  18042. var vecHash0 = hashes[j];
  18043. var vecHash1 = hashes[jNext];
  18044. var v0 = _triangle[vertKeys[j]];
  18045. var v1 = _triangle[vertKeys[jNext]];
  18046. var hash = vecHash0 + "_" + vecHash1;
  18047. var reverseHash = vecHash1 + "_" + vecHash0;
  18048. if (reverseHash in edgeData && edgeData[reverseHash]) {
  18049. // if we found a sibling edge add it into the vertex array if
  18050. // it meets the angle threshold and delete the edge from the map.
  18051. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  18052. vertices.push(v0.x, v0.y, v0.z);
  18053. vertices.push(v1.x, v1.y, v1.z);
  18054. }
  18055. edgeData[reverseHash] = null;
  18056. } else if (!(hash in edgeData)) {
  18057. // if we've already got an edge here then skip adding a new one
  18058. edgeData[hash] = {
  18059. index0: indexArr[j],
  18060. index1: indexArr[jNext],
  18061. normal: _normal$1.clone()
  18062. };
  18063. }
  18064. }
  18065. } // iterate over all remaining, unmatched edges and add them to the vertex array
  18066. for (var key in edgeData) {
  18067. if (edgeData[key]) {
  18068. var _edgeData$key = edgeData[key],
  18069. index0 = _edgeData$key.index0,
  18070. index1 = _edgeData$key.index1;
  18071. _v0$2.fromBufferAttribute(positionAttr, index0);
  18072. _v1$5.fromBufferAttribute(positionAttr, index1);
  18073. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  18074. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  18075. }
  18076. }
  18077. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18078. return _this;
  18079. }
  18080. return EdgesGeometry;
  18081. }(BufferGeometry);
  18082. /**
  18083. * Port from https://github.com/mapbox/earcut (v2.2.2)
  18084. */
  18085. var Earcut = {
  18086. triangulate: function triangulate(data, holeIndices, dim) {
  18087. dim = dim || 2;
  18088. var hasHoles = holeIndices && holeIndices.length;
  18089. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  18090. var outerNode = linkedList(data, 0, outerLen, dim, true);
  18091. var triangles = [];
  18092. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  18093. var minX, minY, maxX, maxY, x, y, invSize;
  18094. 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
  18095. if (data.length > 80 * dim) {
  18096. minX = maxX = data[0];
  18097. minY = maxY = data[1];
  18098. for (var i = dim; i < outerLen; i += dim) {
  18099. x = data[i];
  18100. y = data[i + 1];
  18101. if (x < minX) minX = x;
  18102. if (y < minY) minY = y;
  18103. if (x > maxX) maxX = x;
  18104. if (y > maxY) maxY = y;
  18105. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  18106. invSize = Math.max(maxX - minX, maxY - minY);
  18107. invSize = invSize !== 0 ? 1 / invSize : 0;
  18108. }
  18109. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  18110. return triangles;
  18111. }
  18112. }; // create a circular doubly linked list from polygon points in the specified winding order
  18113. function linkedList(data, start, end, dim, clockwise) {
  18114. var i, last;
  18115. if (clockwise === signedArea(data, start, end, dim) > 0) {
  18116. for (i = start; i < end; i += dim) {
  18117. last = insertNode(i, data[i], data[i + 1], last);
  18118. }
  18119. } else {
  18120. for (i = end - dim; i >= start; i -= dim) {
  18121. last = insertNode(i, data[i], data[i + 1], last);
  18122. }
  18123. }
  18124. if (last && equals(last, last.next)) {
  18125. removeNode(last);
  18126. last = last.next;
  18127. }
  18128. return last;
  18129. } // eliminate colinear or duplicate points
  18130. function filterPoints(start, end) {
  18131. if (!start) return start;
  18132. if (!end) end = start;
  18133. var p = start,
  18134. again;
  18135. do {
  18136. again = false;
  18137. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  18138. removeNode(p);
  18139. p = end = p.prev;
  18140. if (p === p.next) break;
  18141. again = true;
  18142. } else {
  18143. p = p.next;
  18144. }
  18145. } while (again || p !== end);
  18146. return end;
  18147. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  18148. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  18149. if (!ear) return; // interlink polygon nodes in z-order
  18150. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  18151. var stop = ear,
  18152. prev,
  18153. next; // iterate through ears, slicing them one by one
  18154. while (ear.prev !== ear.next) {
  18155. prev = ear.prev;
  18156. next = ear.next;
  18157. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  18158. // cut off the triangle
  18159. triangles.push(prev.i / dim);
  18160. triangles.push(ear.i / dim);
  18161. triangles.push(next.i / dim);
  18162. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  18163. ear = next.next;
  18164. stop = next.next;
  18165. continue;
  18166. }
  18167. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  18168. if (ear === stop) {
  18169. // try filtering points and slicing again
  18170. if (!pass) {
  18171. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  18172. } else if (pass === 1) {
  18173. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  18174. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  18175. } else if (pass === 2) {
  18176. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  18177. }
  18178. break;
  18179. }
  18180. }
  18181. } // check whether a polygon node forms a valid ear with adjacent nodes
  18182. function isEar(ear) {
  18183. var a = ear.prev,
  18184. b = ear,
  18185. c = ear.next;
  18186. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  18187. // now make sure we don't have other points inside the potential ear
  18188. var p = ear.next.next;
  18189. while (p !== ear.prev) {
  18190. 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;
  18191. p = p.next;
  18192. }
  18193. return true;
  18194. }
  18195. function isEarHashed(ear, minX, minY, invSize) {
  18196. var a = ear.prev,
  18197. b = ear,
  18198. c = ear.next;
  18199. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  18200. // triangle bbox; min & max are calculated like this for speed
  18201. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  18202. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  18203. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  18204. 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;
  18205. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  18206. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  18207. var p = ear.prevZ,
  18208. n = ear.nextZ; // look for points inside the triangle in both directions
  18209. while (p && p.z >= minZ && n && n.z <= maxZ) {
  18210. if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
  18211. p = p.prevZ;
  18212. 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;
  18213. n = n.nextZ;
  18214. } // look for remaining points in decreasing z-order
  18215. while (p && p.z >= minZ) {
  18216. 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;
  18217. p = p.prevZ;
  18218. } // look for remaining points in increasing z-order
  18219. while (n && n.z <= maxZ) {
  18220. 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;
  18221. n = n.nextZ;
  18222. }
  18223. return true;
  18224. } // go through all polygon nodes and cure small local self-intersections
  18225. function cureLocalIntersections(start, triangles, dim) {
  18226. var p = start;
  18227. do {
  18228. var a = p.prev,
  18229. b = p.next.next;
  18230. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  18231. triangles.push(a.i / dim);
  18232. triangles.push(p.i / dim);
  18233. triangles.push(b.i / dim); // remove two nodes involved
  18234. removeNode(p);
  18235. removeNode(p.next);
  18236. p = start = b;
  18237. }
  18238. p = p.next;
  18239. } while (p !== start);
  18240. return filterPoints(p);
  18241. } // try splitting polygon into two and triangulate them independently
  18242. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  18243. // look for a valid diagonal that divides the polygon into two
  18244. var a = start;
  18245. do {
  18246. var b = a.next.next;
  18247. while (b !== a.prev) {
  18248. if (a.i !== b.i && isValidDiagonal(a, b)) {
  18249. // split the polygon in two by the diagonal
  18250. var c = splitPolygon(a, b); // filter colinear points around the cuts
  18251. a = filterPoints(a, a.next);
  18252. c = filterPoints(c, c.next); // run earcut on each half
  18253. earcutLinked(a, triangles, dim, minX, minY, invSize);
  18254. earcutLinked(c, triangles, dim, minX, minY, invSize);
  18255. return;
  18256. }
  18257. b = b.next;
  18258. }
  18259. a = a.next;
  18260. } while (a !== start);
  18261. } // link every hole into the outer loop, producing a single-ring polygon without holes
  18262. function eliminateHoles(data, holeIndices, outerNode, dim) {
  18263. var queue = [];
  18264. var i, len, start, end, list;
  18265. for (i = 0, len = holeIndices.length; i < len; i++) {
  18266. start = holeIndices[i] * dim;
  18267. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  18268. list = linkedList(data, start, end, dim, false);
  18269. if (list === list.next) list.steiner = true;
  18270. queue.push(getLeftmost(list));
  18271. }
  18272. queue.sort(compareX); // process holes from left to right
  18273. for (i = 0; i < queue.length; i++) {
  18274. eliminateHole(queue[i], outerNode);
  18275. outerNode = filterPoints(outerNode, outerNode.next);
  18276. }
  18277. return outerNode;
  18278. }
  18279. function compareX(a, b) {
  18280. return a.x - b.x;
  18281. } // find a bridge between vertices that connects hole with an outer ring and and link it
  18282. function eliminateHole(hole, outerNode) {
  18283. outerNode = findHoleBridge(hole, outerNode);
  18284. if (outerNode) {
  18285. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  18286. filterPoints(outerNode, outerNode.next);
  18287. filterPoints(b, b.next);
  18288. }
  18289. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  18290. function findHoleBridge(hole, outerNode) {
  18291. var p = outerNode;
  18292. var hx = hole.x;
  18293. var hy = hole.y;
  18294. var qx = -Infinity,
  18295. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  18296. // segment's endpoint with lesser x will be potential connection point
  18297. do {
  18298. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  18299. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  18300. if (x <= hx && x > qx) {
  18301. qx = x;
  18302. if (x === hx) {
  18303. if (hy === p.y) return p;
  18304. if (hy === p.next.y) return p.next;
  18305. }
  18306. m = p.x < p.next.x ? p : p.next;
  18307. }
  18308. }
  18309. p = p.next;
  18310. } while (p !== outerNode);
  18311. if (!m) return null;
  18312. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  18313. // look for points inside the triangle of hole point, segment intersection and endpoint;
  18314. // if there are no points found, we have a valid connection;
  18315. // otherwise choose the point of the minimum angle with the ray as connection point
  18316. var stop = m,
  18317. mx = m.x,
  18318. my = m.y;
  18319. var tanMin = Infinity,
  18320. tan;
  18321. p = m;
  18322. do {
  18323. 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)) {
  18324. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  18325. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  18326. m = p;
  18327. tanMin = tan;
  18328. }
  18329. }
  18330. p = p.next;
  18331. } while (p !== stop);
  18332. return m;
  18333. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  18334. function sectorContainsSector(m, p) {
  18335. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  18336. } // interlink polygon nodes in z-order
  18337. function indexCurve(start, minX, minY, invSize) {
  18338. var p = start;
  18339. do {
  18340. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  18341. p.prevZ = p.prev;
  18342. p.nextZ = p.next;
  18343. p = p.next;
  18344. } while (p !== start);
  18345. p.prevZ.nextZ = null;
  18346. p.prevZ = null;
  18347. sortLinked(p);
  18348. } // Simon Tatham's linked list merge sort algorithm
  18349. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  18350. function sortLinked(list) {
  18351. var i,
  18352. p,
  18353. q,
  18354. e,
  18355. tail,
  18356. numMerges,
  18357. pSize,
  18358. qSize,
  18359. inSize = 1;
  18360. do {
  18361. p = list;
  18362. list = null;
  18363. tail = null;
  18364. numMerges = 0;
  18365. while (p) {
  18366. numMerges++;
  18367. q = p;
  18368. pSize = 0;
  18369. for (i = 0; i < inSize; i++) {
  18370. pSize++;
  18371. q = q.nextZ;
  18372. if (!q) break;
  18373. }
  18374. qSize = inSize;
  18375. while (pSize > 0 || qSize > 0 && q) {
  18376. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  18377. e = p;
  18378. p = p.nextZ;
  18379. pSize--;
  18380. } else {
  18381. e = q;
  18382. q = q.nextZ;
  18383. qSize--;
  18384. }
  18385. if (tail) tail.nextZ = e;else list = e;
  18386. e.prevZ = tail;
  18387. tail = e;
  18388. }
  18389. p = q;
  18390. }
  18391. tail.nextZ = null;
  18392. inSize *= 2;
  18393. } while (numMerges > 1);
  18394. return list;
  18395. } // z-order of a point given coords and inverse of the longer side of data bbox
  18396. function zOrder(x, y, minX, minY, invSize) {
  18397. // coords are transformed into non-negative 15-bit integer range
  18398. x = 32767 * (x - minX) * invSize;
  18399. y = 32767 * (y - minY) * invSize;
  18400. x = (x | x << 8) & 0x00FF00FF;
  18401. x = (x | x << 4) & 0x0F0F0F0F;
  18402. x = (x | x << 2) & 0x33333333;
  18403. x = (x | x << 1) & 0x55555555;
  18404. y = (y | y << 8) & 0x00FF00FF;
  18405. y = (y | y << 4) & 0x0F0F0F0F;
  18406. y = (y | y << 2) & 0x33333333;
  18407. y = (y | y << 1) & 0x55555555;
  18408. return x | y << 1;
  18409. } // find the leftmost node of a polygon ring
  18410. function getLeftmost(start) {
  18411. var p = start,
  18412. leftmost = start;
  18413. do {
  18414. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18415. p = p.next;
  18416. } while (p !== start);
  18417. return leftmost;
  18418. } // check if a point lies within a convex triangle
  18419. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18420. 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;
  18421. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18422. function isValidDiagonal(a, b) {
  18423. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18424. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18425. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18426. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18427. } // signed area of a triangle
  18428. function area(p, q, r) {
  18429. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18430. } // check if two points are equal
  18431. function equals(p1, p2) {
  18432. return p1.x === p2.x && p1.y === p2.y;
  18433. } // check if two segments intersect
  18434. function intersects(p1, q1, p2, q2) {
  18435. var o1 = sign(area(p1, q1, p2));
  18436. var o2 = sign(area(p1, q1, q2));
  18437. var o3 = sign(area(p2, q2, p1));
  18438. var o4 = sign(area(p2, q2, q1));
  18439. if (o1 !== o2 && o3 !== o4) return true; // general case
  18440. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18441. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18442. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18443. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18444. return false;
  18445. } // for collinear points p, q, r, check if point q lies on segment pr
  18446. function onSegment(p, q, r) {
  18447. 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);
  18448. }
  18449. function sign(num) {
  18450. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18451. } // check if a polygon diagonal intersects any polygon segments
  18452. function intersectsPolygon(a, b) {
  18453. var p = a;
  18454. do {
  18455. 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;
  18456. p = p.next;
  18457. } while (p !== a);
  18458. return false;
  18459. } // check if a polygon diagonal is locally inside the polygon
  18460. function locallyInside(a, b) {
  18461. 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;
  18462. } // check if the middle point of a polygon diagonal is inside the polygon
  18463. function middleInside(a, b) {
  18464. var p = a,
  18465. inside = false;
  18466. var px = (a.x + b.x) / 2,
  18467. py = (a.y + b.y) / 2;
  18468. do {
  18469. 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;
  18470. p = p.next;
  18471. } while (p !== a);
  18472. return inside;
  18473. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18474. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18475. function splitPolygon(a, b) {
  18476. var a2 = new Node(a.i, a.x, a.y),
  18477. b2 = new Node(b.i, b.x, b.y),
  18478. an = a.next,
  18479. bp = b.prev;
  18480. a.next = b;
  18481. b.prev = a;
  18482. a2.next = an;
  18483. an.prev = a2;
  18484. b2.next = a2;
  18485. a2.prev = b2;
  18486. bp.next = b2;
  18487. b2.prev = bp;
  18488. return b2;
  18489. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18490. function insertNode(i, x, y, last) {
  18491. var p = new Node(i, x, y);
  18492. if (!last) {
  18493. p.prev = p;
  18494. p.next = p;
  18495. } else {
  18496. p.next = last.next;
  18497. p.prev = last;
  18498. last.next.prev = p;
  18499. last.next = p;
  18500. }
  18501. return p;
  18502. }
  18503. function removeNode(p) {
  18504. p.next.prev = p.prev;
  18505. p.prev.next = p.next;
  18506. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18507. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18508. }
  18509. function Node(i, x, y) {
  18510. // vertex index in coordinates array
  18511. this.i = i; // vertex coordinates
  18512. this.x = x;
  18513. this.y = y; // previous and next vertex nodes in a polygon ring
  18514. this.prev = null;
  18515. this.next = null; // z-order curve value
  18516. this.z = null; // previous and next nodes in z-order
  18517. this.prevZ = null;
  18518. this.nextZ = null; // indicates whether this is a steiner point
  18519. this.steiner = false;
  18520. }
  18521. function signedArea(data, start, end, dim) {
  18522. var sum = 0;
  18523. for (var i = start, j = end - dim; i < end; i += dim) {
  18524. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18525. j = i;
  18526. }
  18527. return sum;
  18528. }
  18529. var ShapeUtils = {
  18530. // calculate area of the contour polygon
  18531. area: function area(contour) {
  18532. var n = contour.length;
  18533. var a = 0.0;
  18534. for (var p = n - 1, q = 0; q < n; p = q++) {
  18535. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18536. }
  18537. return a * 0.5;
  18538. },
  18539. isClockWise: function isClockWise(pts) {
  18540. return ShapeUtils.area(pts) < 0;
  18541. },
  18542. triangulateShape: function triangulateShape(contour, holes) {
  18543. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18544. var holeIndices = []; // array of hole indices
  18545. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18546. removeDupEndPts(contour);
  18547. addContour(vertices, contour); //
  18548. var holeIndex = contour.length;
  18549. holes.forEach(removeDupEndPts);
  18550. for (var i = 0; i < holes.length; i++) {
  18551. holeIndices.push(holeIndex);
  18552. holeIndex += holes[i].length;
  18553. addContour(vertices, holes[i]);
  18554. } //
  18555. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18556. for (var _i = 0; _i < triangles.length; _i += 3) {
  18557. faces.push(triangles.slice(_i, _i + 3));
  18558. }
  18559. return faces;
  18560. }
  18561. };
  18562. function removeDupEndPts(points) {
  18563. var l = points.length;
  18564. if (l > 2 && points[l - 1].equals(points[0])) {
  18565. points.pop();
  18566. }
  18567. }
  18568. function addContour(vertices, contour) {
  18569. for (var i = 0; i < contour.length; i++) {
  18570. vertices.push(contour[i].x);
  18571. vertices.push(contour[i].y);
  18572. }
  18573. }
  18574. var ExtrudeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18575. _inheritsLoose(ExtrudeBufferGeometry, _BufferGeometry);
  18576. function ExtrudeBufferGeometry(shapes, options) {
  18577. var _this;
  18578. _this = _BufferGeometry.call(this) || this;
  18579. _this.type = 'ExtrudeBufferGeometry';
  18580. _this.parameters = {
  18581. shapes: shapes,
  18582. options: options
  18583. };
  18584. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18585. var scope = _assertThisInitialized(_this);
  18586. var verticesArray = [];
  18587. var uvArray = [];
  18588. for (var i = 0, l = shapes.length; i < l; i++) {
  18589. var shape = shapes[i];
  18590. addShape(shape);
  18591. } // build geometry
  18592. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18593. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18594. _this.computeVertexNormals(); // functions
  18595. function addShape(shape) {
  18596. var placeholder = []; // options
  18597. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18598. var steps = options.steps !== undefined ? options.steps : 1;
  18599. var depth = options.depth !== undefined ? options.depth : 100;
  18600. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18601. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18602. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18603. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18604. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18605. var extrudePath = options.extrudePath;
  18606. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18607. if (options.amount !== undefined) {
  18608. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18609. depth = options.amount;
  18610. } //
  18611. var extrudePts,
  18612. extrudeByPath = false;
  18613. var splineTube, binormal, normal, position2;
  18614. if (extrudePath) {
  18615. extrudePts = extrudePath.getSpacedPoints(steps);
  18616. extrudeByPath = true;
  18617. bevelEnabled = false; // bevels not supported for path extrusion
  18618. // SETUP TNB variables
  18619. // TODO1 - have a .isClosed in spline?
  18620. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18621. binormal = new Vector3();
  18622. normal = new Vector3();
  18623. position2 = new Vector3();
  18624. } // Safeguards if bevels are not enabled
  18625. if (!bevelEnabled) {
  18626. bevelSegments = 0;
  18627. bevelThickness = 0;
  18628. bevelSize = 0;
  18629. bevelOffset = 0;
  18630. } // Variables initialization
  18631. var shapePoints = shape.extractPoints(curveSegments);
  18632. var vertices = shapePoints.shape;
  18633. var holes = shapePoints.holes;
  18634. var reverse = !ShapeUtils.isClockWise(vertices);
  18635. if (reverse) {
  18636. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18637. for (var h = 0, hl = holes.length; h < hl; h++) {
  18638. var ahole = holes[h];
  18639. if (ShapeUtils.isClockWise(ahole)) {
  18640. holes[h] = ahole.reverse();
  18641. }
  18642. }
  18643. }
  18644. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18645. /* Vertices */
  18646. var contour = vertices; // vertices has all points but contour has only points of circumference
  18647. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18648. var _ahole = holes[_h];
  18649. vertices = vertices.concat(_ahole);
  18650. }
  18651. function scalePt2(pt, vec, size) {
  18652. if (!vec) console.error('THREE.ExtrudeGeometry: vec does not exist');
  18653. return vec.clone().multiplyScalar(size).add(pt);
  18654. }
  18655. var vlen = vertices.length,
  18656. flen = faces.length; // Find directions for point movement
  18657. function getBevelVec(inPt, inPrev, inNext) {
  18658. // computes for inPt the corresponding point inPt' on a new contour
  18659. // shifted by 1 unit (length of normalized vector) to the left
  18660. // if we walk along contour clockwise, this new contour is outside the old one
  18661. //
  18662. // inPt' is the intersection of the two lines parallel to the two
  18663. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18664. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18665. // good reading for geometry algorithms (here: line-line intersection)
  18666. // http://geomalgorithms.com/a05-_intersect-1.html
  18667. var v_prev_x = inPt.x - inPrev.x,
  18668. v_prev_y = inPt.y - inPrev.y;
  18669. var v_next_x = inNext.x - inPt.x,
  18670. v_next_y = inNext.y - inPt.y;
  18671. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18672. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18673. if (Math.abs(collinear0) > Number.EPSILON) {
  18674. // not collinear
  18675. // length of vectors for normalizing
  18676. var v_prev_len = Math.sqrt(v_prev_lensq);
  18677. 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
  18678. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18679. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18680. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18681. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18682. 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
  18683. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18684. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18685. // but prevent crazy spikes
  18686. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18687. if (v_trans_lensq <= 2) {
  18688. return new Vector2(v_trans_x, v_trans_y);
  18689. } else {
  18690. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18691. }
  18692. } else {
  18693. // handle special case of collinear edges
  18694. var direction_eq = false; // assumes: opposite
  18695. if (v_prev_x > Number.EPSILON) {
  18696. if (v_next_x > Number.EPSILON) {
  18697. direction_eq = true;
  18698. }
  18699. } else {
  18700. if (v_prev_x < -Number.EPSILON) {
  18701. if (v_next_x < -Number.EPSILON) {
  18702. direction_eq = true;
  18703. }
  18704. } else {
  18705. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18706. direction_eq = true;
  18707. }
  18708. }
  18709. }
  18710. if (direction_eq) {
  18711. // console.log("Warning: lines are a straight sequence");
  18712. v_trans_x = -v_prev_y;
  18713. v_trans_y = v_prev_x;
  18714. shrink_by = Math.sqrt(v_prev_lensq);
  18715. } else {
  18716. // console.log("Warning: lines are a straight spike");
  18717. v_trans_x = v_prev_x;
  18718. v_trans_y = v_prev_y;
  18719. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18720. }
  18721. }
  18722. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18723. }
  18724. var contourMovements = [];
  18725. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18726. if (j === il) j = 0;
  18727. if (k === il) k = 0; // (j)---(i)---(k)
  18728. // console.log('i,j,k', i, j , k)
  18729. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18730. }
  18731. var holesMovements = [];
  18732. var oneHoleMovements,
  18733. verticesMovements = contourMovements.concat();
  18734. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18735. var _ahole2 = holes[_h2];
  18736. oneHoleMovements = [];
  18737. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18738. if (_j === _il) _j = 0;
  18739. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18740. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18741. }
  18742. holesMovements.push(oneHoleMovements);
  18743. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18744. } // Loop bevelSegments, 1 for the front, 1 for the back
  18745. for (var b = 0; b < bevelSegments; b++) {
  18746. //for ( b = bevelSegments; b > 0; b -- ) {
  18747. var t = b / bevelSegments;
  18748. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18749. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18750. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18751. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18752. v(vert.x, vert.y, -z);
  18753. } // expand holes
  18754. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18755. var _ahole3 = holes[_h3];
  18756. oneHoleMovements = holesMovements[_h3];
  18757. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18758. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18759. v(_vert.x, _vert.y, -z);
  18760. }
  18761. }
  18762. }
  18763. var bs = bevelSize + bevelOffset; // Back facing vertices
  18764. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18765. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18766. if (!extrudeByPath) {
  18767. v(_vert2.x, _vert2.y, 0);
  18768. } else {
  18769. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18770. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18771. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18772. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18773. v(position2.x, position2.y, position2.z);
  18774. }
  18775. } // Add stepped vertices...
  18776. // Including front facing vertices
  18777. for (var s = 1; s <= steps; s++) {
  18778. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18779. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18780. if (!extrudeByPath) {
  18781. v(_vert3.x, _vert3.y, depth / steps * s);
  18782. } else {
  18783. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18784. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18785. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18786. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18787. v(position2.x, position2.y, position2.z);
  18788. }
  18789. }
  18790. } // Add bevel segments planes
  18791. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18792. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18793. var _t = _b / bevelSegments;
  18794. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18795. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18796. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18797. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18798. v(_vert4.x, _vert4.y, depth + _z);
  18799. } // expand holes
  18800. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18801. var _ahole4 = holes[_h4];
  18802. oneHoleMovements = holesMovements[_h4];
  18803. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18804. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18805. if (!extrudeByPath) {
  18806. v(_vert5.x, _vert5.y, depth + _z);
  18807. } else {
  18808. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18809. }
  18810. }
  18811. }
  18812. }
  18813. /* Faces */
  18814. // Top and bottom faces
  18815. buildLidFaces(); // Sides faces
  18816. buildSideFaces(); ///// Internal functions
  18817. function buildLidFaces() {
  18818. var start = verticesArray.length / 3;
  18819. if (bevelEnabled) {
  18820. var layer = 0; // steps + 1
  18821. var offset = vlen * layer; // Bottom faces
  18822. for (var _i9 = 0; _i9 < flen; _i9++) {
  18823. var face = faces[_i9];
  18824. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18825. }
  18826. layer = steps + bevelSegments * 2;
  18827. offset = vlen * layer; // Top faces
  18828. for (var _i10 = 0; _i10 < flen; _i10++) {
  18829. var _face = faces[_i10];
  18830. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18831. }
  18832. } else {
  18833. // Bottom faces
  18834. for (var _i11 = 0; _i11 < flen; _i11++) {
  18835. var _face2 = faces[_i11];
  18836. f3(_face2[2], _face2[1], _face2[0]);
  18837. } // Top faces
  18838. for (var _i12 = 0; _i12 < flen; _i12++) {
  18839. var _face3 = faces[_i12];
  18840. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18841. }
  18842. }
  18843. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18844. } // Create faces for the z-sides of the shape
  18845. function buildSideFaces() {
  18846. var start = verticesArray.length / 3;
  18847. var layeroffset = 0;
  18848. sidewalls(contour, layeroffset);
  18849. layeroffset += contour.length;
  18850. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18851. var _ahole5 = holes[_h5];
  18852. sidewalls(_ahole5, layeroffset); //, true
  18853. layeroffset += _ahole5.length;
  18854. }
  18855. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18856. }
  18857. function sidewalls(contour, layeroffset) {
  18858. var i = contour.length;
  18859. while (--i >= 0) {
  18860. var _j2 = i;
  18861. var _k2 = i - 1;
  18862. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18863. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18864. var slen1 = vlen * _s;
  18865. var slen2 = vlen * (_s + 1);
  18866. var a = layeroffset + _j2 + slen1,
  18867. _b2 = layeroffset + _k2 + slen1,
  18868. c = layeroffset + _k2 + slen2,
  18869. d = layeroffset + _j2 + slen2;
  18870. f4(a, _b2, c, d);
  18871. }
  18872. }
  18873. }
  18874. function v(x, y, z) {
  18875. placeholder.push(x);
  18876. placeholder.push(y);
  18877. placeholder.push(z);
  18878. }
  18879. function f3(a, b, c) {
  18880. addVertex(a);
  18881. addVertex(b);
  18882. addVertex(c);
  18883. var nextIndex = verticesArray.length / 3;
  18884. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18885. addUV(uvs[0]);
  18886. addUV(uvs[1]);
  18887. addUV(uvs[2]);
  18888. }
  18889. function f4(a, b, c, d) {
  18890. addVertex(a);
  18891. addVertex(b);
  18892. addVertex(d);
  18893. addVertex(b);
  18894. addVertex(c);
  18895. addVertex(d);
  18896. var nextIndex = verticesArray.length / 3;
  18897. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18898. addUV(uvs[0]);
  18899. addUV(uvs[1]);
  18900. addUV(uvs[3]);
  18901. addUV(uvs[1]);
  18902. addUV(uvs[2]);
  18903. addUV(uvs[3]);
  18904. }
  18905. function addVertex(index) {
  18906. verticesArray.push(placeholder[index * 3 + 0]);
  18907. verticesArray.push(placeholder[index * 3 + 1]);
  18908. verticesArray.push(placeholder[index * 3 + 2]);
  18909. }
  18910. function addUV(vector2) {
  18911. uvArray.push(vector2.x);
  18912. uvArray.push(vector2.y);
  18913. }
  18914. }
  18915. return _this;
  18916. }
  18917. var _proto = ExtrudeBufferGeometry.prototype;
  18918. _proto.toJSON = function toJSON() {
  18919. var data = BufferGeometry.prototype.toJSON.call(this);
  18920. var shapes = this.parameters.shapes;
  18921. var options = this.parameters.options;
  18922. return _toJSON(shapes, options, data);
  18923. };
  18924. return ExtrudeBufferGeometry;
  18925. }(BufferGeometry);
  18926. var WorldUVGenerator = {
  18927. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18928. var a_x = vertices[indexA * 3];
  18929. var a_y = vertices[indexA * 3 + 1];
  18930. var b_x = vertices[indexB * 3];
  18931. var b_y = vertices[indexB * 3 + 1];
  18932. var c_x = vertices[indexC * 3];
  18933. var c_y = vertices[indexC * 3 + 1];
  18934. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18935. },
  18936. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18937. var a_x = vertices[indexA * 3];
  18938. var a_y = vertices[indexA * 3 + 1];
  18939. var a_z = vertices[indexA * 3 + 2];
  18940. var b_x = vertices[indexB * 3];
  18941. var b_y = vertices[indexB * 3 + 1];
  18942. var b_z = vertices[indexB * 3 + 2];
  18943. var c_x = vertices[indexC * 3];
  18944. var c_y = vertices[indexC * 3 + 1];
  18945. var c_z = vertices[indexC * 3 + 2];
  18946. var d_x = vertices[indexD * 3];
  18947. var d_y = vertices[indexD * 3 + 1];
  18948. var d_z = vertices[indexD * 3 + 2];
  18949. if (Math.abs(a_y - b_y) < 0.01) {
  18950. 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)];
  18951. } else {
  18952. 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)];
  18953. }
  18954. }
  18955. };
  18956. function _toJSON(shapes, options, data) {
  18957. data.shapes = [];
  18958. if (Array.isArray(shapes)) {
  18959. for (var i = 0, l = shapes.length; i < l; i++) {
  18960. var shape = shapes[i];
  18961. data.shapes.push(shape.uuid);
  18962. }
  18963. } else {
  18964. data.shapes.push(shapes.uuid);
  18965. }
  18966. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18967. return data;
  18968. }
  18969. var ExtrudeGeometry = /*#__PURE__*/function (_Geometry) {
  18970. _inheritsLoose(ExtrudeGeometry, _Geometry);
  18971. function ExtrudeGeometry(shapes, options) {
  18972. var _this;
  18973. _this = _Geometry.call(this) || this;
  18974. _this.type = 'ExtrudeGeometry';
  18975. _this.parameters = {
  18976. shapes: shapes,
  18977. options: options
  18978. };
  18979. _this.fromBufferGeometry(new ExtrudeBufferGeometry(shapes, options));
  18980. _this.mergeVertices();
  18981. return _this;
  18982. }
  18983. var _proto = ExtrudeGeometry.prototype;
  18984. _proto.toJSON = function toJSON() {
  18985. var data = _Geometry.prototype.toJSON.call(this);
  18986. var shapes = this.parameters.shapes;
  18987. var options = this.parameters.options;
  18988. return _toJSON$1(shapes, options, data);
  18989. };
  18990. return ExtrudeGeometry;
  18991. }(Geometry);
  18992. function _toJSON$1(shapes, options, data) {
  18993. data.shapes = [];
  18994. if (Array.isArray(shapes)) {
  18995. for (var i = 0, l = shapes.length; i < l; i++) {
  18996. var shape = shapes[i];
  18997. data.shapes.push(shape.uuid);
  18998. }
  18999. } else {
  19000. data.shapes.push(shapes.uuid);
  19001. }
  19002. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  19003. return data;
  19004. }
  19005. var IcosahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  19006. _inheritsLoose(IcosahedronBufferGeometry, _PolyhedronBufferGeom);
  19007. function IcosahedronBufferGeometry(radius, detail) {
  19008. var _this;
  19009. if (radius === void 0) {
  19010. radius = 1;
  19011. }
  19012. if (detail === void 0) {
  19013. detail = 0;
  19014. }
  19015. var t = (1 + Math.sqrt(5)) / 2;
  19016. 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];
  19017. 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];
  19018. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  19019. _this.type = 'IcosahedronBufferGeometry';
  19020. _this.parameters = {
  19021. radius: radius,
  19022. detail: detail
  19023. };
  19024. return _this;
  19025. }
  19026. return IcosahedronBufferGeometry;
  19027. }(PolyhedronBufferGeometry);
  19028. var IcosahedronGeometry = /*#__PURE__*/function (_Geometry) {
  19029. _inheritsLoose(IcosahedronGeometry, _Geometry);
  19030. function IcosahedronGeometry(radius, detail) {
  19031. var _this;
  19032. _this = _Geometry.call(this) || this;
  19033. _this.type = 'IcosahedronGeometry';
  19034. _this.parameters = {
  19035. radius: radius,
  19036. detail: detail
  19037. };
  19038. _this.fromBufferGeometry(new IcosahedronBufferGeometry(radius, detail));
  19039. _this.mergeVertices();
  19040. return _this;
  19041. }
  19042. return IcosahedronGeometry;
  19043. }(Geometry);
  19044. var LatheBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19045. _inheritsLoose(LatheBufferGeometry, _BufferGeometry);
  19046. function LatheBufferGeometry(points, segments, phiStart, phiLength) {
  19047. var _this;
  19048. if (segments === void 0) {
  19049. segments = 12;
  19050. }
  19051. if (phiStart === void 0) {
  19052. phiStart = 0;
  19053. }
  19054. if (phiLength === void 0) {
  19055. phiLength = Math.PI * 2;
  19056. }
  19057. _this = _BufferGeometry.call(this) || this;
  19058. _this.type = 'LatheBufferGeometry';
  19059. _this.parameters = {
  19060. points: points,
  19061. segments: segments,
  19062. phiStart: phiStart,
  19063. phiLength: phiLength
  19064. };
  19065. segments = Math.floor(segments); // clamp phiLength so it's in range of [ 0, 2PI ]
  19066. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  19067. var indices = [];
  19068. var vertices = [];
  19069. var uvs = []; // helper variables
  19070. var inverseSegments = 1.0 / segments;
  19071. var vertex = new Vector3();
  19072. var uv = new Vector2(); // generate vertices and uvs
  19073. for (var i = 0; i <= segments; i++) {
  19074. var phi = phiStart + i * inverseSegments * phiLength;
  19075. var sin = Math.sin(phi);
  19076. var cos = Math.cos(phi);
  19077. for (var j = 0; j <= points.length - 1; j++) {
  19078. // vertex
  19079. vertex.x = points[j].x * sin;
  19080. vertex.y = points[j].y;
  19081. vertex.z = points[j].x * cos;
  19082. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  19083. uv.x = i / segments;
  19084. uv.y = j / (points.length - 1);
  19085. uvs.push(uv.x, uv.y);
  19086. }
  19087. } // indices
  19088. for (var _i = 0; _i < segments; _i++) {
  19089. for (var _j = 0; _j < points.length - 1; _j++) {
  19090. var base = _j + _i * points.length;
  19091. var a = base;
  19092. var b = base + points.length;
  19093. var c = base + points.length + 1;
  19094. var d = base + 1; // faces
  19095. indices.push(a, b, d);
  19096. indices.push(b, c, d);
  19097. }
  19098. } // build geometry
  19099. _this.setIndex(indices);
  19100. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19101. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  19102. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  19103. // because the corresponding vertices are identical (but still have different UVs).
  19104. if (phiLength === Math.PI * 2) {
  19105. var normals = _this.attributes.normal.array;
  19106. var n1 = new Vector3();
  19107. var n2 = new Vector3();
  19108. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  19109. var _base = segments * points.length * 3;
  19110. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  19111. // select the normal of the vertex in the first line
  19112. n1.x = normals[_j2 + 0];
  19113. n1.y = normals[_j2 + 1];
  19114. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  19115. n2.x = normals[_base + _j2 + 0];
  19116. n2.y = normals[_base + _j2 + 1];
  19117. n2.z = normals[_base + _j2 + 2]; // average normals
  19118. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  19119. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  19120. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  19121. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  19122. }
  19123. }
  19124. return _this;
  19125. }
  19126. return LatheBufferGeometry;
  19127. }(BufferGeometry);
  19128. var LatheGeometry = /*#__PURE__*/function (_Geometry) {
  19129. _inheritsLoose(LatheGeometry, _Geometry);
  19130. function LatheGeometry(points, segments, phiStart, phiLength) {
  19131. var _this;
  19132. _this = _Geometry.call(this) || this;
  19133. _this.type = 'LatheGeometry';
  19134. _this.parameters = {
  19135. points: points,
  19136. segments: segments,
  19137. phiStart: phiStart,
  19138. phiLength: phiLength
  19139. };
  19140. _this.fromBufferGeometry(new LatheBufferGeometry(points, segments, phiStart, phiLength));
  19141. _this.mergeVertices();
  19142. return _this;
  19143. }
  19144. return LatheGeometry;
  19145. }(Geometry);
  19146. var OctahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  19147. _inheritsLoose(OctahedronBufferGeometry, _PolyhedronBufferGeom);
  19148. function OctahedronBufferGeometry(radius, detail) {
  19149. var _this;
  19150. if (radius === void 0) {
  19151. radius = 1;
  19152. }
  19153. if (detail === void 0) {
  19154. detail = 0;
  19155. }
  19156. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  19157. 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];
  19158. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  19159. _this.type = 'OctahedronBufferGeometry';
  19160. _this.parameters = {
  19161. radius: radius,
  19162. detail: detail
  19163. };
  19164. return _this;
  19165. }
  19166. return OctahedronBufferGeometry;
  19167. }(PolyhedronBufferGeometry);
  19168. var OctahedronGeometry = /*#__PURE__*/function (_Geometry) {
  19169. _inheritsLoose(OctahedronGeometry, _Geometry);
  19170. function OctahedronGeometry(radius, detail) {
  19171. var _this;
  19172. _this = _Geometry.call(this) || this;
  19173. _this.type = 'OctahedronGeometry';
  19174. _this.parameters = {
  19175. radius: radius,
  19176. detail: detail
  19177. };
  19178. _this.fromBufferGeometry(new OctahedronBufferGeometry(radius, detail));
  19179. _this.mergeVertices();
  19180. return _this;
  19181. }
  19182. return OctahedronGeometry;
  19183. }(Geometry);
  19184. /**
  19185. * Parametric Surfaces Geometry
  19186. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  19187. */
  19188. function ParametricBufferGeometry(func, slices, stacks) {
  19189. BufferGeometry.call(this);
  19190. this.type = 'ParametricBufferGeometry';
  19191. this.parameters = {
  19192. func: func,
  19193. slices: slices,
  19194. stacks: stacks
  19195. }; // buffers
  19196. var indices = [];
  19197. var vertices = [];
  19198. var normals = [];
  19199. var uvs = [];
  19200. var EPS = 0.00001;
  19201. var normal = new Vector3();
  19202. var p0 = new Vector3(),
  19203. p1 = new Vector3();
  19204. var pu = new Vector3(),
  19205. pv = new Vector3();
  19206. if (func.length < 3) {
  19207. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  19208. } // generate vertices, normals and uvs
  19209. var sliceCount = slices + 1;
  19210. for (var i = 0; i <= stacks; i++) {
  19211. var v = i / stacks;
  19212. for (var j = 0; j <= slices; j++) {
  19213. var u = j / slices; // vertex
  19214. func(u, v, p0);
  19215. vertices.push(p0.x, p0.y, p0.z); // normal
  19216. // approximate tangent vectors via finite differences
  19217. if (u - EPS >= 0) {
  19218. func(u - EPS, v, p1);
  19219. pu.subVectors(p0, p1);
  19220. } else {
  19221. func(u + EPS, v, p1);
  19222. pu.subVectors(p1, p0);
  19223. }
  19224. if (v - EPS >= 0) {
  19225. func(u, v - EPS, p1);
  19226. pv.subVectors(p0, p1);
  19227. } else {
  19228. func(u, v + EPS, p1);
  19229. pv.subVectors(p1, p0);
  19230. } // cross product of tangent vectors returns surface normal
  19231. normal.crossVectors(pu, pv).normalize();
  19232. normals.push(normal.x, normal.y, normal.z); // uv
  19233. uvs.push(u, v);
  19234. }
  19235. } // generate indices
  19236. for (var _i = 0; _i < stacks; _i++) {
  19237. for (var _j = 0; _j < slices; _j++) {
  19238. var a = _i * sliceCount + _j;
  19239. var b = _i * sliceCount + _j + 1;
  19240. var c = (_i + 1) * sliceCount + _j + 1;
  19241. var d = (_i + 1) * sliceCount + _j; // faces one and two
  19242. indices.push(a, b, d);
  19243. indices.push(b, c, d);
  19244. }
  19245. } // build geometry
  19246. this.setIndex(indices);
  19247. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19248. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19249. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19250. }
  19251. ParametricBufferGeometry.prototype = Object.create(BufferGeometry.prototype);
  19252. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  19253. /**
  19254. * Parametric Surfaces Geometry
  19255. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  19256. */
  19257. function ParametricGeometry(func, slices, stacks) {
  19258. Geometry.call(this);
  19259. this.type = 'ParametricGeometry';
  19260. this.parameters = {
  19261. func: func,
  19262. slices: slices,
  19263. stacks: stacks
  19264. };
  19265. this.fromBufferGeometry(new ParametricBufferGeometry(func, slices, stacks));
  19266. this.mergeVertices();
  19267. }
  19268. ParametricGeometry.prototype = Object.create(Geometry.prototype);
  19269. ParametricGeometry.prototype.constructor = ParametricGeometry;
  19270. var PlaneGeometry = /*#__PURE__*/function (_Geometry) {
  19271. _inheritsLoose(PlaneGeometry, _Geometry);
  19272. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  19273. var _this;
  19274. _this = _Geometry.call(this) || this;
  19275. _this.type = 'PlaneGeometry';
  19276. _this.parameters = {
  19277. width: width,
  19278. height: height,
  19279. widthSegments: widthSegments,
  19280. heightSegments: heightSegments
  19281. };
  19282. _this.fromBufferGeometry(new PlaneBufferGeometry(width, height, widthSegments, heightSegments));
  19283. _this.mergeVertices();
  19284. return _this;
  19285. }
  19286. return PlaneGeometry;
  19287. }(Geometry);
  19288. var PolyhedronGeometry = /*#__PURE__*/function (_Geometry) {
  19289. _inheritsLoose(PolyhedronGeometry, _Geometry);
  19290. function PolyhedronGeometry(vertices, indices, radius, detail) {
  19291. var _this;
  19292. _this = _Geometry.call(this) || this;
  19293. _this.type = 'PolyhedronGeometry';
  19294. _this.parameters = {
  19295. vertices: vertices,
  19296. indices: indices,
  19297. radius: radius,
  19298. detail: detail
  19299. };
  19300. _this.fromBufferGeometry(new PolyhedronBufferGeometry(vertices, indices, radius, detail));
  19301. _this.mergeVertices();
  19302. return _this;
  19303. }
  19304. return PolyhedronGeometry;
  19305. }(Geometry);
  19306. var RingBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19307. _inheritsLoose(RingBufferGeometry, _BufferGeometry);
  19308. function RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  19309. var _this;
  19310. if (innerRadius === void 0) {
  19311. innerRadius = 0.5;
  19312. }
  19313. if (outerRadius === void 0) {
  19314. outerRadius = 1;
  19315. }
  19316. if (thetaSegments === void 0) {
  19317. thetaSegments = 8;
  19318. }
  19319. if (phiSegments === void 0) {
  19320. phiSegments = 1;
  19321. }
  19322. if (thetaStart === void 0) {
  19323. thetaStart = 0;
  19324. }
  19325. if (thetaLength === void 0) {
  19326. thetaLength = Math.PI * 2;
  19327. }
  19328. _this = _BufferGeometry.call(this) || this;
  19329. _this.type = 'RingBufferGeometry';
  19330. _this.parameters = {
  19331. innerRadius: innerRadius,
  19332. outerRadius: outerRadius,
  19333. thetaSegments: thetaSegments,
  19334. phiSegments: phiSegments,
  19335. thetaStart: thetaStart,
  19336. thetaLength: thetaLength
  19337. };
  19338. thetaSegments = Math.max(3, thetaSegments);
  19339. phiSegments = Math.max(1, phiSegments); // buffers
  19340. var indices = [];
  19341. var vertices = [];
  19342. var normals = [];
  19343. var uvs = []; // some helper variables
  19344. var radius = innerRadius;
  19345. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  19346. var vertex = new Vector3();
  19347. var uv = new Vector2(); // generate vertices, normals and uvs
  19348. for (var j = 0; j <= phiSegments; j++) {
  19349. for (var i = 0; i <= thetaSegments; i++) {
  19350. // values are generate from the inside of the ring to the outside
  19351. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  19352. vertex.x = radius * Math.cos(segment);
  19353. vertex.y = radius * Math.sin(segment);
  19354. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19355. normals.push(0, 0, 1); // uv
  19356. uv.x = (vertex.x / outerRadius + 1) / 2;
  19357. uv.y = (vertex.y / outerRadius + 1) / 2;
  19358. uvs.push(uv.x, uv.y);
  19359. } // increase the radius for next row of vertices
  19360. radius += radiusStep;
  19361. } // indices
  19362. for (var _j = 0; _j < phiSegments; _j++) {
  19363. var thetaSegmentLevel = _j * (thetaSegments + 1);
  19364. for (var _i = 0; _i < thetaSegments; _i++) {
  19365. var _segment = _i + thetaSegmentLevel;
  19366. var a = _segment;
  19367. var b = _segment + thetaSegments + 1;
  19368. var c = _segment + thetaSegments + 2;
  19369. var d = _segment + 1; // faces
  19370. indices.push(a, b, d);
  19371. indices.push(b, c, d);
  19372. }
  19373. } // build geometry
  19374. _this.setIndex(indices);
  19375. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19376. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19377. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19378. return _this;
  19379. }
  19380. return RingBufferGeometry;
  19381. }(BufferGeometry);
  19382. var RingGeometry = /*#__PURE__*/function (_Geometry) {
  19383. _inheritsLoose(RingGeometry, _Geometry);
  19384. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  19385. var _this;
  19386. _this = _Geometry.call(this) || this;
  19387. _this.type = 'RingGeometry';
  19388. _this.parameters = {
  19389. innerRadius: innerRadius,
  19390. outerRadius: outerRadius,
  19391. thetaSegments: thetaSegments,
  19392. phiSegments: phiSegments,
  19393. thetaStart: thetaStart,
  19394. thetaLength: thetaLength
  19395. };
  19396. _this.fromBufferGeometry(new RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength));
  19397. _this.mergeVertices();
  19398. return _this;
  19399. }
  19400. return RingGeometry;
  19401. }(Geometry);
  19402. var ShapeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19403. _inheritsLoose(ShapeBufferGeometry, _BufferGeometry);
  19404. function ShapeBufferGeometry(shapes, curveSegments) {
  19405. var _this;
  19406. if (curveSegments === void 0) {
  19407. curveSegments = 12;
  19408. }
  19409. _this = _BufferGeometry.call(this) || this;
  19410. _this.type = 'ShapeBufferGeometry';
  19411. _this.parameters = {
  19412. shapes: shapes,
  19413. curveSegments: curveSegments
  19414. }; // buffers
  19415. var indices = [];
  19416. var vertices = [];
  19417. var normals = [];
  19418. var uvs = []; // helper variables
  19419. var groupStart = 0;
  19420. var groupCount = 0; // allow single and array values for "shapes" parameter
  19421. if (Array.isArray(shapes) === false) {
  19422. addShape(shapes);
  19423. } else {
  19424. for (var i = 0; i < shapes.length; i++) {
  19425. addShape(shapes[i]);
  19426. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  19427. groupStart += groupCount;
  19428. groupCount = 0;
  19429. }
  19430. } // build geometry
  19431. _this.setIndex(indices);
  19432. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19433. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19434. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  19435. function addShape(shape) {
  19436. var indexOffset = vertices.length / 3;
  19437. var points = shape.extractPoints(curveSegments);
  19438. var shapeVertices = points.shape;
  19439. var shapeHoles = points.holes; // check direction of vertices
  19440. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  19441. shapeVertices = shapeVertices.reverse();
  19442. }
  19443. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  19444. var shapeHole = shapeHoles[_i];
  19445. if (ShapeUtils.isClockWise(shapeHole) === true) {
  19446. shapeHoles[_i] = shapeHole.reverse();
  19447. }
  19448. }
  19449. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  19450. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  19451. var _shapeHole = shapeHoles[_i2];
  19452. shapeVertices = shapeVertices.concat(_shapeHole);
  19453. } // vertices, normals, uvs
  19454. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  19455. var vertex = shapeVertices[_i3];
  19456. vertices.push(vertex.x, vertex.y, 0);
  19457. normals.push(0, 0, 1);
  19458. uvs.push(vertex.x, vertex.y); // world uvs
  19459. } // incides
  19460. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  19461. var face = faces[_i4];
  19462. var a = face[0] + indexOffset;
  19463. var b = face[1] + indexOffset;
  19464. var c = face[2] + indexOffset;
  19465. indices.push(a, b, c);
  19466. groupCount += 3;
  19467. }
  19468. }
  19469. return _this;
  19470. }
  19471. var _proto = ShapeBufferGeometry.prototype;
  19472. _proto.toJSON = function toJSON() {
  19473. var data = BufferGeometry.prototype.toJSON.call(this);
  19474. var shapes = this.parameters.shapes;
  19475. return _toJSON$2(shapes, data);
  19476. };
  19477. return ShapeBufferGeometry;
  19478. }(BufferGeometry);
  19479. function _toJSON$2(shapes, data) {
  19480. data.shapes = [];
  19481. if (Array.isArray(shapes)) {
  19482. for (var i = 0, l = shapes.length; i < l; i++) {
  19483. var shape = shapes[i];
  19484. data.shapes.push(shape.uuid);
  19485. }
  19486. } else {
  19487. data.shapes.push(shapes.uuid);
  19488. }
  19489. return data;
  19490. }
  19491. var ShapeGeometry = /*#__PURE__*/function (_Geometry) {
  19492. _inheritsLoose(ShapeGeometry, _Geometry);
  19493. function ShapeGeometry(shapes, curveSegments) {
  19494. var _this;
  19495. _this = _Geometry.call(this) || this;
  19496. _this.type = 'ShapeGeometry';
  19497. if (typeof curveSegments === 'object') {
  19498. console.warn('THREE.ShapeGeometry: Options parameter has been removed.');
  19499. curveSegments = curveSegments.curveSegments;
  19500. }
  19501. _this.parameters = {
  19502. shapes: shapes,
  19503. curveSegments: curveSegments
  19504. };
  19505. _this.fromBufferGeometry(new ShapeBufferGeometry(shapes, curveSegments));
  19506. _this.mergeVertices();
  19507. return _this;
  19508. }
  19509. var _proto = ShapeGeometry.prototype;
  19510. _proto.toJSON = function toJSON() {
  19511. var data = Geometry.prototype.toJSON.call(this);
  19512. var shapes = this.parameters.shapes;
  19513. return _toJSON$3(shapes, data);
  19514. };
  19515. return ShapeGeometry;
  19516. }(Geometry);
  19517. function _toJSON$3(shapes, data) {
  19518. data.shapes = [];
  19519. if (Array.isArray(shapes)) {
  19520. for (var i = 0, l = shapes.length; i < l; i++) {
  19521. var shape = shapes[i];
  19522. data.shapes.push(shape.uuid);
  19523. }
  19524. } else {
  19525. data.shapes.push(shapes.uuid);
  19526. }
  19527. return data;
  19528. }
  19529. var SphereBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19530. _inheritsLoose(SphereBufferGeometry, _BufferGeometry);
  19531. function SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19532. var _this;
  19533. if (radius === void 0) {
  19534. radius = 1;
  19535. }
  19536. if (widthSegments === void 0) {
  19537. widthSegments = 8;
  19538. }
  19539. if (heightSegments === void 0) {
  19540. heightSegments = 6;
  19541. }
  19542. if (phiStart === void 0) {
  19543. phiStart = 0;
  19544. }
  19545. if (phiLength === void 0) {
  19546. phiLength = Math.PI * 2;
  19547. }
  19548. if (thetaStart === void 0) {
  19549. thetaStart = 0;
  19550. }
  19551. if (thetaLength === void 0) {
  19552. thetaLength = Math.PI;
  19553. }
  19554. _this = _BufferGeometry.call(this) || this;
  19555. _this.type = 'SphereBufferGeometry';
  19556. _this.parameters = {
  19557. radius: radius,
  19558. widthSegments: widthSegments,
  19559. heightSegments: heightSegments,
  19560. phiStart: phiStart,
  19561. phiLength: phiLength,
  19562. thetaStart: thetaStart,
  19563. thetaLength: thetaLength
  19564. };
  19565. widthSegments = Math.max(3, Math.floor(widthSegments));
  19566. heightSegments = Math.max(2, Math.floor(heightSegments));
  19567. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19568. var index = 0;
  19569. var grid = [];
  19570. var vertex = new Vector3();
  19571. var normal = new Vector3(); // buffers
  19572. var indices = [];
  19573. var vertices = [];
  19574. var normals = [];
  19575. var uvs = []; // generate vertices, normals and uvs
  19576. for (var iy = 0; iy <= heightSegments; iy++) {
  19577. var verticesRow = [];
  19578. var v = iy / heightSegments; // special case for the poles
  19579. var uOffset = 0;
  19580. if (iy == 0 && thetaStart == 0) {
  19581. uOffset = 0.5 / widthSegments;
  19582. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19583. uOffset = -0.5 / widthSegments;
  19584. }
  19585. for (var ix = 0; ix <= widthSegments; ix++) {
  19586. var u = ix / widthSegments; // vertex
  19587. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19588. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19589. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19590. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19591. normal.copy(vertex).normalize();
  19592. normals.push(normal.x, normal.y, normal.z); // uv
  19593. uvs.push(u + uOffset, 1 - v);
  19594. verticesRow.push(index++);
  19595. }
  19596. grid.push(verticesRow);
  19597. } // indices
  19598. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19599. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19600. var a = grid[_iy][_ix + 1];
  19601. var b = grid[_iy][_ix];
  19602. var c = grid[_iy + 1][_ix];
  19603. var d = grid[_iy + 1][_ix + 1];
  19604. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19605. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19606. }
  19607. } // build geometry
  19608. _this.setIndex(indices);
  19609. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19610. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19611. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19612. return _this;
  19613. }
  19614. return SphereBufferGeometry;
  19615. }(BufferGeometry);
  19616. var SphereGeometry = /*#__PURE__*/function (_Geometry) {
  19617. _inheritsLoose(SphereGeometry, _Geometry);
  19618. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19619. var _this;
  19620. _this = _Geometry.call(this) || this;
  19621. _this.type = 'SphereGeometry';
  19622. _this.parameters = {
  19623. radius: radius,
  19624. widthSegments: widthSegments,
  19625. heightSegments: heightSegments,
  19626. phiStart: phiStart,
  19627. phiLength: phiLength,
  19628. thetaStart: thetaStart,
  19629. thetaLength: thetaLength
  19630. };
  19631. _this.fromBufferGeometry(new SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength));
  19632. _this.mergeVertices();
  19633. return _this;
  19634. }
  19635. return SphereGeometry;
  19636. }(Geometry);
  19637. var TetrahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  19638. _inheritsLoose(TetrahedronBufferGeometry, _PolyhedronBufferGeom);
  19639. function TetrahedronBufferGeometry(radius, detail) {
  19640. var _this;
  19641. if (radius === void 0) {
  19642. radius = 1;
  19643. }
  19644. if (detail === void 0) {
  19645. detail = 0;
  19646. }
  19647. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19648. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19649. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  19650. _this.type = 'TetrahedronBufferGeometry';
  19651. _this.parameters = {
  19652. radius: radius,
  19653. detail: detail
  19654. };
  19655. return _this;
  19656. }
  19657. return TetrahedronBufferGeometry;
  19658. }(PolyhedronBufferGeometry);
  19659. var TetrahedronGeometry = /*#__PURE__*/function (_Geometry) {
  19660. _inheritsLoose(TetrahedronGeometry, _Geometry);
  19661. function TetrahedronGeometry(radius, detail) {
  19662. var _this;
  19663. _this = _Geometry.call(this) || this;
  19664. _this.type = 'TetrahedronGeometry';
  19665. _this.parameters = {
  19666. radius: radius,
  19667. detail: detail
  19668. };
  19669. _this.fromBufferGeometry(new TetrahedronBufferGeometry(radius, detail));
  19670. _this.mergeVertices();
  19671. return _this;
  19672. }
  19673. return TetrahedronGeometry;
  19674. }(Geometry);
  19675. var TextBufferGeometry = /*#__PURE__*/function (_ExtrudeBufferGeometr) {
  19676. _inheritsLoose(TextBufferGeometry, _ExtrudeBufferGeometr);
  19677. function TextBufferGeometry(text, parameters) {
  19678. var _this;
  19679. if (parameters === void 0) {
  19680. parameters = {};
  19681. }
  19682. var font = parameters.font;
  19683. if (!(font && font.isFont)) {
  19684. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19685. return new BufferGeometry() || _assertThisInitialized(_this);
  19686. }
  19687. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19688. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19689. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19690. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19691. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19692. _this = _ExtrudeBufferGeometr.call(this, shapes, parameters) || this;
  19693. _this.type = 'TextBufferGeometry';
  19694. return _this;
  19695. }
  19696. return TextBufferGeometry;
  19697. }(ExtrudeBufferGeometry);
  19698. var TextGeometry = /*#__PURE__*/function (_Geometry) {
  19699. _inheritsLoose(TextGeometry, _Geometry);
  19700. function TextGeometry(text, parameters) {
  19701. var _this;
  19702. _this = _Geometry.call(this) || this;
  19703. _this.type = 'TextGeometry';
  19704. _this.parameters = {
  19705. text: text,
  19706. parameters: parameters
  19707. };
  19708. _this.fromBufferGeometry(new TextBufferGeometry(text, parameters));
  19709. _this.mergeVertices();
  19710. return _this;
  19711. }
  19712. return TextGeometry;
  19713. }(Geometry);
  19714. var TorusBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19715. _inheritsLoose(TorusBufferGeometry, _BufferGeometry);
  19716. function TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19717. var _this;
  19718. if (radius === void 0) {
  19719. radius = 1;
  19720. }
  19721. if (tube === void 0) {
  19722. tube = 0.4;
  19723. }
  19724. if (radialSegments === void 0) {
  19725. radialSegments = 8;
  19726. }
  19727. if (tubularSegments === void 0) {
  19728. tubularSegments = 6;
  19729. }
  19730. if (arc === void 0) {
  19731. arc = Math.PI * 2;
  19732. }
  19733. _this = _BufferGeometry.call(this) || this;
  19734. _this.type = 'TorusBufferGeometry';
  19735. _this.parameters = {
  19736. radius: radius,
  19737. tube: tube,
  19738. radialSegments: radialSegments,
  19739. tubularSegments: tubularSegments,
  19740. arc: arc
  19741. };
  19742. radialSegments = Math.floor(radialSegments);
  19743. tubularSegments = Math.floor(tubularSegments); // buffers
  19744. var indices = [];
  19745. var vertices = [];
  19746. var normals = [];
  19747. var uvs = []; // helper variables
  19748. var center = new Vector3();
  19749. var vertex = new Vector3();
  19750. var normal = new Vector3(); // generate vertices, normals and uvs
  19751. for (var j = 0; j <= radialSegments; j++) {
  19752. for (var i = 0; i <= tubularSegments; i++) {
  19753. var u = i / tubularSegments * arc;
  19754. var v = j / radialSegments * Math.PI * 2; // vertex
  19755. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19756. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19757. vertex.z = tube * Math.sin(v);
  19758. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19759. center.x = radius * Math.cos(u);
  19760. center.y = radius * Math.sin(u);
  19761. normal.subVectors(vertex, center).normalize();
  19762. normals.push(normal.x, normal.y, normal.z); // uv
  19763. uvs.push(i / tubularSegments);
  19764. uvs.push(j / radialSegments);
  19765. }
  19766. } // generate indices
  19767. for (var _j = 1; _j <= radialSegments; _j++) {
  19768. for (var _i = 1; _i <= tubularSegments; _i++) {
  19769. // indices
  19770. var a = (tubularSegments + 1) * _j + _i - 1;
  19771. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19772. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19773. var d = (tubularSegments + 1) * _j + _i; // faces
  19774. indices.push(a, b, d);
  19775. indices.push(b, c, d);
  19776. }
  19777. } // build geometry
  19778. _this.setIndex(indices);
  19779. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19780. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19781. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19782. return _this;
  19783. }
  19784. return TorusBufferGeometry;
  19785. }(BufferGeometry);
  19786. var TorusGeometry = /*#__PURE__*/function (_Geometry) {
  19787. _inheritsLoose(TorusGeometry, _Geometry);
  19788. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19789. var _this;
  19790. _this = _Geometry.call(this) || this;
  19791. _this.type = 'TorusGeometry';
  19792. _this.parameters = {
  19793. radius: radius,
  19794. tube: tube,
  19795. radialSegments: radialSegments,
  19796. tubularSegments: tubularSegments,
  19797. arc: arc
  19798. };
  19799. _this.fromBufferGeometry(new TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc));
  19800. _this.mergeVertices();
  19801. return _this;
  19802. }
  19803. return TorusGeometry;
  19804. }(Geometry);
  19805. var TorusKnotBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19806. _inheritsLoose(TorusKnotBufferGeometry, _BufferGeometry);
  19807. function TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19808. var _this;
  19809. if (radius === void 0) {
  19810. radius = 1;
  19811. }
  19812. if (tube === void 0) {
  19813. tube = 0.4;
  19814. }
  19815. if (tubularSegments === void 0) {
  19816. tubularSegments = 64;
  19817. }
  19818. if (radialSegments === void 0) {
  19819. radialSegments = 8;
  19820. }
  19821. if (p === void 0) {
  19822. p = 2;
  19823. }
  19824. if (q === void 0) {
  19825. q = 3;
  19826. }
  19827. _this = _BufferGeometry.call(this) || this;
  19828. _this.type = 'TorusKnotBufferGeometry';
  19829. _this.parameters = {
  19830. radius: radius,
  19831. tube: tube,
  19832. tubularSegments: tubularSegments,
  19833. radialSegments: radialSegments,
  19834. p: p,
  19835. q: q
  19836. };
  19837. tubularSegments = Math.floor(tubularSegments);
  19838. radialSegments = Math.floor(radialSegments); // buffers
  19839. var indices = [];
  19840. var vertices = [];
  19841. var normals = [];
  19842. var uvs = []; // helper variables
  19843. var vertex = new Vector3();
  19844. var normal = new Vector3();
  19845. var P1 = new Vector3();
  19846. var P2 = new Vector3();
  19847. var B = new Vector3();
  19848. var T = new Vector3();
  19849. var N = new Vector3(); // generate vertices, normals and uvs
  19850. for (var i = 0; i <= tubularSegments; ++i) {
  19851. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19852. 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.
  19853. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19854. calculatePositionOnCurve(u, p, q, radius, P1);
  19855. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19856. T.subVectors(P2, P1);
  19857. N.addVectors(P2, P1);
  19858. B.crossVectors(T, N);
  19859. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19860. B.normalize();
  19861. N.normalize();
  19862. for (var j = 0; j <= radialSegments; ++j) {
  19863. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19864. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19865. var v = j / radialSegments * Math.PI * 2;
  19866. var cx = -tube * Math.cos(v);
  19867. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19868. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19869. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19870. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19871. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19872. 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)
  19873. normal.subVectors(vertex, P1).normalize();
  19874. normals.push(normal.x, normal.y, normal.z); // uv
  19875. uvs.push(i / tubularSegments);
  19876. uvs.push(j / radialSegments);
  19877. }
  19878. } // generate indices
  19879. for (var _j = 1; _j <= tubularSegments; _j++) {
  19880. for (var _i = 1; _i <= radialSegments; _i++) {
  19881. // indices
  19882. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19883. var b = (radialSegments + 1) * _j + (_i - 1);
  19884. var c = (radialSegments + 1) * _j + _i;
  19885. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19886. indices.push(a, b, d);
  19887. indices.push(b, c, d);
  19888. }
  19889. } // build geometry
  19890. _this.setIndex(indices);
  19891. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19892. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19893. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19894. function calculatePositionOnCurve(u, p, q, radius, position) {
  19895. var cu = Math.cos(u);
  19896. var su = Math.sin(u);
  19897. var quOverP = q / p * u;
  19898. var cs = Math.cos(quOverP);
  19899. position.x = radius * (2 + cs) * 0.5 * cu;
  19900. position.y = radius * (2 + cs) * su * 0.5;
  19901. position.z = radius * Math.sin(quOverP) * 0.5;
  19902. }
  19903. return _this;
  19904. }
  19905. return TorusKnotBufferGeometry;
  19906. }(BufferGeometry);
  19907. var TorusKnotGeometry = /*#__PURE__*/function (_Geometry) {
  19908. _inheritsLoose(TorusKnotGeometry, _Geometry);
  19909. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q, heightScale) {
  19910. var _this;
  19911. _this = _Geometry.call(this) || this;
  19912. _this.type = 'TorusKnotGeometry';
  19913. _this.parameters = {
  19914. radius: radius,
  19915. tube: tube,
  19916. tubularSegments: tubularSegments,
  19917. radialSegments: radialSegments,
  19918. p: p,
  19919. q: q
  19920. };
  19921. if (heightScale !== undefined) console.warn('THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.');
  19922. _this.fromBufferGeometry(new TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q));
  19923. _this.mergeVertices();
  19924. return _this;
  19925. }
  19926. return TorusKnotGeometry;
  19927. }(Geometry);
  19928. var TubeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19929. _inheritsLoose(TubeBufferGeometry, _BufferGeometry);
  19930. function TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19931. var _this;
  19932. if (tubularSegments === void 0) {
  19933. tubularSegments = 64;
  19934. }
  19935. if (radius === void 0) {
  19936. radius = 1;
  19937. }
  19938. if (radialSegments === void 0) {
  19939. radialSegments = 8;
  19940. }
  19941. if (closed === void 0) {
  19942. closed = false;
  19943. }
  19944. _this = _BufferGeometry.call(this) || this;
  19945. _this.type = 'TubeBufferGeometry';
  19946. _this.parameters = {
  19947. path: path,
  19948. tubularSegments: tubularSegments,
  19949. radius: radius,
  19950. radialSegments: radialSegments,
  19951. closed: closed
  19952. };
  19953. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19954. _this.tangents = frames.tangents;
  19955. _this.normals = frames.normals;
  19956. _this.binormals = frames.binormals; // helper variables
  19957. var vertex = new Vector3();
  19958. var normal = new Vector3();
  19959. var uv = new Vector2();
  19960. var P = new Vector3(); // buffer
  19961. var vertices = [];
  19962. var normals = [];
  19963. var uvs = [];
  19964. var indices = []; // create buffer data
  19965. generateBufferData(); // build geometry
  19966. _this.setIndex(indices);
  19967. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19968. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19969. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19970. function generateBufferData() {
  19971. for (var i = 0; i < tubularSegments; i++) {
  19972. generateSegment(i);
  19973. } // if the geometry is not closed, generate the last row of vertices and normals
  19974. // at the regular position on the given path
  19975. //
  19976. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19977. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19978. // this makes it easy compute correct values for closed geometries
  19979. generateUVs(); // finally create faces
  19980. generateIndices();
  19981. }
  19982. function generateSegment(i) {
  19983. // we use getPointAt to sample evenly distributed points from the given path
  19984. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19985. var N = frames.normals[i];
  19986. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19987. for (var j = 0; j <= radialSegments; j++) {
  19988. var v = j / radialSegments * Math.PI * 2;
  19989. var sin = Math.sin(v);
  19990. var cos = -Math.cos(v); // normal
  19991. normal.x = cos * N.x + sin * B.x;
  19992. normal.y = cos * N.y + sin * B.y;
  19993. normal.z = cos * N.z + sin * B.z;
  19994. normal.normalize();
  19995. normals.push(normal.x, normal.y, normal.z); // vertex
  19996. vertex.x = P.x + radius * normal.x;
  19997. vertex.y = P.y + radius * normal.y;
  19998. vertex.z = P.z + radius * normal.z;
  19999. vertices.push(vertex.x, vertex.y, vertex.z);
  20000. }
  20001. }
  20002. function generateIndices() {
  20003. for (var j = 1; j <= tubularSegments; j++) {
  20004. for (var i = 1; i <= radialSegments; i++) {
  20005. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  20006. var b = (radialSegments + 1) * j + (i - 1);
  20007. var c = (radialSegments + 1) * j + i;
  20008. var d = (radialSegments + 1) * (j - 1) + i; // faces
  20009. indices.push(a, b, d);
  20010. indices.push(b, c, d);
  20011. }
  20012. }
  20013. }
  20014. function generateUVs() {
  20015. for (var i = 0; i <= tubularSegments; i++) {
  20016. for (var j = 0; j <= radialSegments; j++) {
  20017. uv.x = i / tubularSegments;
  20018. uv.y = j / radialSegments;
  20019. uvs.push(uv.x, uv.y);
  20020. }
  20021. }
  20022. }
  20023. return _this;
  20024. }
  20025. var _proto = TubeBufferGeometry.prototype;
  20026. _proto.toJSON = function toJSON() {
  20027. var data = BufferGeometry.prototype.toJSON.call(this);
  20028. data.path = this.parameters.path.toJSON();
  20029. return data;
  20030. };
  20031. return TubeBufferGeometry;
  20032. }(BufferGeometry);
  20033. var TubeGeometry = /*#__PURE__*/function (_Geometry) {
  20034. _inheritsLoose(TubeGeometry, _Geometry);
  20035. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed, taper) {
  20036. var _this;
  20037. _this = _Geometry.call(this) || this;
  20038. _this.type = 'TubeGeometry';
  20039. _this.parameters = {
  20040. path: path,
  20041. tubularSegments: tubularSegments,
  20042. radius: radius,
  20043. radialSegments: radialSegments,
  20044. closed: closed
  20045. };
  20046. if (taper !== undefined) console.warn('THREE.TubeGeometry: taper has been removed.');
  20047. var bufferGeometry = new TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed); // expose internals
  20048. _this.tangents = bufferGeometry.tangents;
  20049. _this.normals = bufferGeometry.normals;
  20050. _this.binormals = bufferGeometry.binormals; // create geometry
  20051. _this.fromBufferGeometry(bufferGeometry);
  20052. _this.mergeVertices();
  20053. return _this;
  20054. }
  20055. return TubeGeometry;
  20056. }(Geometry);
  20057. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  20058. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  20059. function WireframeGeometry(geometry) {
  20060. var _this;
  20061. _this = _BufferGeometry.call(this) || this;
  20062. _this.type = 'WireframeGeometry'; // buffer
  20063. var vertices = []; // helper variables
  20064. var edge = [0, 0],
  20065. edges = {};
  20066. var keys = ['a', 'b', 'c']; // different logic for Geometry and BufferGeometry
  20067. if (geometry && geometry.isGeometry) {
  20068. // create a data structure that contains all edges without duplicates
  20069. var faces = geometry.faces;
  20070. for (var i = 0, l = faces.length; i < l; i++) {
  20071. var face = faces[i];
  20072. for (var j = 0; j < 3; j++) {
  20073. var edge1 = face[keys[j]];
  20074. var edge2 = face[keys[(j + 1) % 3]];
  20075. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  20076. edge[1] = Math.max(edge1, edge2);
  20077. var key = edge[0] + ',' + edge[1];
  20078. if (edges[key] === undefined) {
  20079. edges[key] = {
  20080. index1: edge[0],
  20081. index2: edge[1]
  20082. };
  20083. }
  20084. }
  20085. } // generate vertices
  20086. for (var _key in edges) {
  20087. var e = edges[_key];
  20088. var vertex = geometry.vertices[e.index1];
  20089. vertices.push(vertex.x, vertex.y, vertex.z);
  20090. vertex = geometry.vertices[e.index2];
  20091. vertices.push(vertex.x, vertex.y, vertex.z);
  20092. }
  20093. } else if (geometry && geometry.isBufferGeometry) {
  20094. var _vertex = new Vector3();
  20095. if (geometry.index !== null) {
  20096. // indexed BufferGeometry
  20097. var position = geometry.attributes.position;
  20098. var indices = geometry.index;
  20099. var groups = geometry.groups;
  20100. if (groups.length === 0) {
  20101. groups = [{
  20102. start: 0,
  20103. count: indices.count,
  20104. materialIndex: 0
  20105. }];
  20106. } // create a data structure that contains all eges without duplicates
  20107. for (var o = 0, ol = groups.length; o < ol; ++o) {
  20108. var group = groups[o];
  20109. var start = group.start;
  20110. var count = group.count;
  20111. for (var _i = start, _l = start + count; _i < _l; _i += 3) {
  20112. for (var _j = 0; _j < 3; _j++) {
  20113. var _edge = indices.getX(_i + _j);
  20114. var _edge2 = indices.getX(_i + (_j + 1) % 3);
  20115. edge[0] = Math.min(_edge, _edge2); // sorting prevents duplicates
  20116. edge[1] = Math.max(_edge, _edge2);
  20117. var _key2 = edge[0] + ',' + edge[1];
  20118. if (edges[_key2] === undefined) {
  20119. edges[_key2] = {
  20120. index1: edge[0],
  20121. index2: edge[1]
  20122. };
  20123. }
  20124. }
  20125. }
  20126. } // generate vertices
  20127. for (var _key3 in edges) {
  20128. var _e = edges[_key3];
  20129. _vertex.fromBufferAttribute(position, _e.index1);
  20130. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  20131. _vertex.fromBufferAttribute(position, _e.index2);
  20132. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  20133. }
  20134. } else {
  20135. // non-indexed BufferGeometry
  20136. var _position = geometry.attributes.position;
  20137. for (var _i2 = 0, _l2 = _position.count / 3; _i2 < _l2; _i2++) {
  20138. for (var _j2 = 0; _j2 < 3; _j2++) {
  20139. // three edges per triangle, an edge is represented as (index1, index2)
  20140. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  20141. var index1 = 3 * _i2 + _j2;
  20142. _vertex.fromBufferAttribute(_position, index1);
  20143. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  20144. var index2 = 3 * _i2 + (_j2 + 1) % 3;
  20145. _vertex.fromBufferAttribute(_position, index2);
  20146. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  20147. }
  20148. }
  20149. }
  20150. } // build geometry
  20151. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  20152. return _this;
  20153. }
  20154. return WireframeGeometry;
  20155. }(BufferGeometry);
  20156. var Geometries = /*#__PURE__*/Object.freeze({
  20157. __proto__: null,
  20158. BoxGeometry: BoxGeometry,
  20159. BoxBufferGeometry: BoxBufferGeometry,
  20160. CircleGeometry: CircleGeometry,
  20161. CircleBufferGeometry: CircleBufferGeometry,
  20162. ConeGeometry: ConeGeometry,
  20163. ConeBufferGeometry: ConeBufferGeometry,
  20164. CylinderGeometry: CylinderGeometry,
  20165. CylinderBufferGeometry: CylinderBufferGeometry,
  20166. DodecahedronGeometry: DodecahedronGeometry,
  20167. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  20168. EdgesGeometry: EdgesGeometry,
  20169. ExtrudeGeometry: ExtrudeGeometry,
  20170. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  20171. IcosahedronGeometry: IcosahedronGeometry,
  20172. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  20173. LatheGeometry: LatheGeometry,
  20174. LatheBufferGeometry: LatheBufferGeometry,
  20175. OctahedronGeometry: OctahedronGeometry,
  20176. OctahedronBufferGeometry: OctahedronBufferGeometry,
  20177. ParametricGeometry: ParametricGeometry,
  20178. ParametricBufferGeometry: ParametricBufferGeometry,
  20179. PlaneGeometry: PlaneGeometry,
  20180. PlaneBufferGeometry: PlaneBufferGeometry,
  20181. PolyhedronGeometry: PolyhedronGeometry,
  20182. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  20183. RingGeometry: RingGeometry,
  20184. RingBufferGeometry: RingBufferGeometry,
  20185. ShapeGeometry: ShapeGeometry,
  20186. ShapeBufferGeometry: ShapeBufferGeometry,
  20187. SphereGeometry: SphereGeometry,
  20188. SphereBufferGeometry: SphereBufferGeometry,
  20189. TetrahedronGeometry: TetrahedronGeometry,
  20190. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  20191. TextGeometry: TextGeometry,
  20192. TextBufferGeometry: TextBufferGeometry,
  20193. TorusGeometry: TorusGeometry,
  20194. TorusBufferGeometry: TorusBufferGeometry,
  20195. TorusKnotGeometry: TorusKnotGeometry,
  20196. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  20197. TubeGeometry: TubeGeometry,
  20198. TubeBufferGeometry: TubeBufferGeometry,
  20199. WireframeGeometry: WireframeGeometry
  20200. });
  20201. /**
  20202. * parameters = {
  20203. * color: <THREE.Color>
  20204. * }
  20205. */
  20206. function ShadowMaterial(parameters) {
  20207. Material.call(this);
  20208. this.type = 'ShadowMaterial';
  20209. this.color = new Color(0x000000);
  20210. this.transparent = true;
  20211. this.setValues(parameters);
  20212. }
  20213. ShadowMaterial.prototype = Object.create(Material.prototype);
  20214. ShadowMaterial.prototype.constructor = ShadowMaterial;
  20215. ShadowMaterial.prototype.isShadowMaterial = true;
  20216. ShadowMaterial.prototype.copy = function (source) {
  20217. Material.prototype.copy.call(this, source);
  20218. this.color.copy(source.color);
  20219. return this;
  20220. };
  20221. function RawShaderMaterial(parameters) {
  20222. ShaderMaterial.call(this, parameters);
  20223. this.type = 'RawShaderMaterial';
  20224. }
  20225. RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
  20226. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  20227. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  20228. /**
  20229. * parameters = {
  20230. * color: <hex>,
  20231. * roughness: <float>,
  20232. * metalness: <float>,
  20233. * opacity: <float>,
  20234. *
  20235. * map: new THREE.Texture( <Image> ),
  20236. *
  20237. * lightMap: new THREE.Texture( <Image> ),
  20238. * lightMapIntensity: <float>
  20239. *
  20240. * aoMap: new THREE.Texture( <Image> ),
  20241. * aoMapIntensity: <float>
  20242. *
  20243. * emissive: <hex>,
  20244. * emissiveIntensity: <float>
  20245. * emissiveMap: new THREE.Texture( <Image> ),
  20246. *
  20247. * bumpMap: new THREE.Texture( <Image> ),
  20248. * bumpScale: <float>,
  20249. *
  20250. * normalMap: new THREE.Texture( <Image> ),
  20251. * normalMapType: THREE.TangentSpaceNormalMap,
  20252. * normalScale: <Vector2>,
  20253. *
  20254. * displacementMap: new THREE.Texture( <Image> ),
  20255. * displacementScale: <float>,
  20256. * displacementBias: <float>,
  20257. *
  20258. * roughnessMap: new THREE.Texture( <Image> ),
  20259. *
  20260. * metalnessMap: new THREE.Texture( <Image> ),
  20261. *
  20262. * alphaMap: new THREE.Texture( <Image> ),
  20263. *
  20264. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20265. * envMapIntensity: <float>
  20266. *
  20267. * refractionRatio: <float>,
  20268. *
  20269. * wireframe: <boolean>,
  20270. * wireframeLinewidth: <float>,
  20271. *
  20272. * skinning: <bool>,
  20273. * morphTargets: <bool>,
  20274. * morphNormals: <bool>
  20275. * }
  20276. */
  20277. function MeshStandardMaterial(parameters) {
  20278. Material.call(this);
  20279. this.defines = {
  20280. 'STANDARD': ''
  20281. };
  20282. this.type = 'MeshStandardMaterial';
  20283. this.color = new Color(0xffffff); // diffuse
  20284. this.roughness = 1.0;
  20285. this.metalness = 0.0;
  20286. this.map = null;
  20287. this.lightMap = null;
  20288. this.lightMapIntensity = 1.0;
  20289. this.aoMap = null;
  20290. this.aoMapIntensity = 1.0;
  20291. this.emissive = new Color(0x000000);
  20292. this.emissiveIntensity = 1.0;
  20293. this.emissiveMap = null;
  20294. this.bumpMap = null;
  20295. this.bumpScale = 1;
  20296. this.normalMap = null;
  20297. this.normalMapType = TangentSpaceNormalMap;
  20298. this.normalScale = new Vector2(1, 1);
  20299. this.displacementMap = null;
  20300. this.displacementScale = 1;
  20301. this.displacementBias = 0;
  20302. this.roughnessMap = null;
  20303. this.metalnessMap = null;
  20304. this.alphaMap = null;
  20305. this.envMap = null;
  20306. this.envMapIntensity = 1.0;
  20307. this.refractionRatio = 0.98;
  20308. this.wireframe = false;
  20309. this.wireframeLinewidth = 1;
  20310. this.wireframeLinecap = 'round';
  20311. this.wireframeLinejoin = 'round';
  20312. this.skinning = false;
  20313. this.morphTargets = false;
  20314. this.morphNormals = false;
  20315. this.vertexTangents = false;
  20316. this.setValues(parameters);
  20317. }
  20318. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  20319. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  20320. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  20321. MeshStandardMaterial.prototype.copy = function (source) {
  20322. Material.prototype.copy.call(this, source);
  20323. this.defines = {
  20324. 'STANDARD': ''
  20325. };
  20326. this.color.copy(source.color);
  20327. this.roughness = source.roughness;
  20328. this.metalness = source.metalness;
  20329. this.map = source.map;
  20330. this.lightMap = source.lightMap;
  20331. this.lightMapIntensity = source.lightMapIntensity;
  20332. this.aoMap = source.aoMap;
  20333. this.aoMapIntensity = source.aoMapIntensity;
  20334. this.emissive.copy(source.emissive);
  20335. this.emissiveMap = source.emissiveMap;
  20336. this.emissiveIntensity = source.emissiveIntensity;
  20337. this.bumpMap = source.bumpMap;
  20338. this.bumpScale = source.bumpScale;
  20339. this.normalMap = source.normalMap;
  20340. this.normalMapType = source.normalMapType;
  20341. this.normalScale.copy(source.normalScale);
  20342. this.displacementMap = source.displacementMap;
  20343. this.displacementScale = source.displacementScale;
  20344. this.displacementBias = source.displacementBias;
  20345. this.roughnessMap = source.roughnessMap;
  20346. this.metalnessMap = source.metalnessMap;
  20347. this.alphaMap = source.alphaMap;
  20348. this.envMap = source.envMap;
  20349. this.envMapIntensity = source.envMapIntensity;
  20350. this.refractionRatio = source.refractionRatio;
  20351. this.wireframe = source.wireframe;
  20352. this.wireframeLinewidth = source.wireframeLinewidth;
  20353. this.wireframeLinecap = source.wireframeLinecap;
  20354. this.wireframeLinejoin = source.wireframeLinejoin;
  20355. this.skinning = source.skinning;
  20356. this.morphTargets = source.morphTargets;
  20357. this.morphNormals = source.morphNormals;
  20358. this.vertexTangents = source.vertexTangents;
  20359. return this;
  20360. };
  20361. /**
  20362. * parameters = {
  20363. * clearcoat: <float>,
  20364. * clearcoatMap: new THREE.Texture( <Image> ),
  20365. * clearcoatRoughness: <float>,
  20366. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  20367. * clearcoatNormalScale: <Vector2>,
  20368. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  20369. *
  20370. * reflectivity: <float>,
  20371. * ior: <float>,
  20372. *
  20373. * sheen: <Color>,
  20374. *
  20375. * transmission: <float>,
  20376. * transmissionMap: new THREE.Texture( <Image> )
  20377. * }
  20378. */
  20379. function MeshPhysicalMaterial(parameters) {
  20380. MeshStandardMaterial.call(this);
  20381. this.defines = {
  20382. 'STANDARD': '',
  20383. 'PHYSICAL': ''
  20384. };
  20385. this.type = 'MeshPhysicalMaterial';
  20386. this.clearcoat = 0.0;
  20387. this.clearcoatMap = null;
  20388. this.clearcoatRoughness = 0.0;
  20389. this.clearcoatRoughnessMap = null;
  20390. this.clearcoatNormalScale = new Vector2(1, 1);
  20391. this.clearcoatNormalMap = null;
  20392. this.reflectivity = 0.5; // maps to F0 = 0.04
  20393. Object.defineProperty(this, 'ior', {
  20394. get: function get() {
  20395. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  20396. },
  20397. set: function set(ior) {
  20398. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  20399. }
  20400. });
  20401. this.sheen = null; // null will disable sheen bsdf
  20402. this.transmission = 0.0;
  20403. this.transmissionMap = null;
  20404. this.setValues(parameters);
  20405. }
  20406. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  20407. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  20408. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  20409. MeshPhysicalMaterial.prototype.copy = function (source) {
  20410. MeshStandardMaterial.prototype.copy.call(this, source);
  20411. this.defines = {
  20412. 'STANDARD': '',
  20413. 'PHYSICAL': ''
  20414. };
  20415. this.clearcoat = source.clearcoat;
  20416. this.clearcoatMap = source.clearcoatMap;
  20417. this.clearcoatRoughness = source.clearcoatRoughness;
  20418. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  20419. this.clearcoatNormalMap = source.clearcoatNormalMap;
  20420. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  20421. this.reflectivity = source.reflectivity;
  20422. if (source.sheen) {
  20423. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  20424. } else {
  20425. this.sheen = null;
  20426. }
  20427. this.transmission = source.transmission;
  20428. this.transmissionMap = source.transmissionMap;
  20429. return this;
  20430. };
  20431. /**
  20432. * parameters = {
  20433. * color: <hex>,
  20434. * specular: <hex>,
  20435. * shininess: <float>,
  20436. * opacity: <float>,
  20437. *
  20438. * map: new THREE.Texture( <Image> ),
  20439. *
  20440. * lightMap: new THREE.Texture( <Image> ),
  20441. * lightMapIntensity: <float>
  20442. *
  20443. * aoMap: new THREE.Texture( <Image> ),
  20444. * aoMapIntensity: <float>
  20445. *
  20446. * emissive: <hex>,
  20447. * emissiveIntensity: <float>
  20448. * emissiveMap: new THREE.Texture( <Image> ),
  20449. *
  20450. * bumpMap: new THREE.Texture( <Image> ),
  20451. * bumpScale: <float>,
  20452. *
  20453. * normalMap: new THREE.Texture( <Image> ),
  20454. * normalMapType: THREE.TangentSpaceNormalMap,
  20455. * normalScale: <Vector2>,
  20456. *
  20457. * displacementMap: new THREE.Texture( <Image> ),
  20458. * displacementScale: <float>,
  20459. * displacementBias: <float>,
  20460. *
  20461. * specularMap: new THREE.Texture( <Image> ),
  20462. *
  20463. * alphaMap: new THREE.Texture( <Image> ),
  20464. *
  20465. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20466. * combine: THREE.MultiplyOperation,
  20467. * reflectivity: <float>,
  20468. * refractionRatio: <float>,
  20469. *
  20470. * wireframe: <boolean>,
  20471. * wireframeLinewidth: <float>,
  20472. *
  20473. * skinning: <bool>,
  20474. * morphTargets: <bool>,
  20475. * morphNormals: <bool>
  20476. * }
  20477. */
  20478. function MeshPhongMaterial(parameters) {
  20479. Material.call(this);
  20480. this.type = 'MeshPhongMaterial';
  20481. this.color = new Color(0xffffff); // diffuse
  20482. this.specular = new Color(0x111111);
  20483. this.shininess = 30;
  20484. this.map = null;
  20485. this.lightMap = null;
  20486. this.lightMapIntensity = 1.0;
  20487. this.aoMap = null;
  20488. this.aoMapIntensity = 1.0;
  20489. this.emissive = new Color(0x000000);
  20490. this.emissiveIntensity = 1.0;
  20491. this.emissiveMap = null;
  20492. this.bumpMap = null;
  20493. this.bumpScale = 1;
  20494. this.normalMap = null;
  20495. this.normalMapType = TangentSpaceNormalMap;
  20496. this.normalScale = new Vector2(1, 1);
  20497. this.displacementMap = null;
  20498. this.displacementScale = 1;
  20499. this.displacementBias = 0;
  20500. this.specularMap = null;
  20501. this.alphaMap = null;
  20502. this.envMap = null;
  20503. this.combine = MultiplyOperation;
  20504. this.reflectivity = 1;
  20505. this.refractionRatio = 0.98;
  20506. this.wireframe = false;
  20507. this.wireframeLinewidth = 1;
  20508. this.wireframeLinecap = 'round';
  20509. this.wireframeLinejoin = 'round';
  20510. this.skinning = false;
  20511. this.morphTargets = false;
  20512. this.morphNormals = false;
  20513. this.setValues(parameters);
  20514. }
  20515. MeshPhongMaterial.prototype = Object.create(Material.prototype);
  20516. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  20517. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  20518. MeshPhongMaterial.prototype.copy = function (source) {
  20519. Material.prototype.copy.call(this, source);
  20520. this.color.copy(source.color);
  20521. this.specular.copy(source.specular);
  20522. this.shininess = source.shininess;
  20523. this.map = source.map;
  20524. this.lightMap = source.lightMap;
  20525. this.lightMapIntensity = source.lightMapIntensity;
  20526. this.aoMap = source.aoMap;
  20527. this.aoMapIntensity = source.aoMapIntensity;
  20528. this.emissive.copy(source.emissive);
  20529. this.emissiveMap = source.emissiveMap;
  20530. this.emissiveIntensity = source.emissiveIntensity;
  20531. this.bumpMap = source.bumpMap;
  20532. this.bumpScale = source.bumpScale;
  20533. this.normalMap = source.normalMap;
  20534. this.normalMapType = source.normalMapType;
  20535. this.normalScale.copy(source.normalScale);
  20536. this.displacementMap = source.displacementMap;
  20537. this.displacementScale = source.displacementScale;
  20538. this.displacementBias = source.displacementBias;
  20539. this.specularMap = source.specularMap;
  20540. this.alphaMap = source.alphaMap;
  20541. this.envMap = source.envMap;
  20542. this.combine = source.combine;
  20543. this.reflectivity = source.reflectivity;
  20544. this.refractionRatio = source.refractionRatio;
  20545. this.wireframe = source.wireframe;
  20546. this.wireframeLinewidth = source.wireframeLinewidth;
  20547. this.wireframeLinecap = source.wireframeLinecap;
  20548. this.wireframeLinejoin = source.wireframeLinejoin;
  20549. this.skinning = source.skinning;
  20550. this.morphTargets = source.morphTargets;
  20551. this.morphNormals = source.morphNormals;
  20552. return this;
  20553. };
  20554. /**
  20555. * parameters = {
  20556. * color: <hex>,
  20557. *
  20558. * map: new THREE.Texture( <Image> ),
  20559. * gradientMap: new THREE.Texture( <Image> ),
  20560. *
  20561. * lightMap: new THREE.Texture( <Image> ),
  20562. * lightMapIntensity: <float>
  20563. *
  20564. * aoMap: new THREE.Texture( <Image> ),
  20565. * aoMapIntensity: <float>
  20566. *
  20567. * emissive: <hex>,
  20568. * emissiveIntensity: <float>
  20569. * emissiveMap: new THREE.Texture( <Image> ),
  20570. *
  20571. * bumpMap: new THREE.Texture( <Image> ),
  20572. * bumpScale: <float>,
  20573. *
  20574. * normalMap: new THREE.Texture( <Image> ),
  20575. * normalMapType: THREE.TangentSpaceNormalMap,
  20576. * normalScale: <Vector2>,
  20577. *
  20578. * displacementMap: new THREE.Texture( <Image> ),
  20579. * displacementScale: <float>,
  20580. * displacementBias: <float>,
  20581. *
  20582. * alphaMap: new THREE.Texture( <Image> ),
  20583. *
  20584. * wireframe: <boolean>,
  20585. * wireframeLinewidth: <float>,
  20586. *
  20587. * skinning: <bool>,
  20588. * morphTargets: <bool>,
  20589. * morphNormals: <bool>
  20590. * }
  20591. */
  20592. function MeshToonMaterial(parameters) {
  20593. Material.call(this);
  20594. this.defines = {
  20595. 'TOON': ''
  20596. };
  20597. this.type = 'MeshToonMaterial';
  20598. this.color = new Color(0xffffff);
  20599. this.map = null;
  20600. this.gradientMap = null;
  20601. this.lightMap = null;
  20602. this.lightMapIntensity = 1.0;
  20603. this.aoMap = null;
  20604. this.aoMapIntensity = 1.0;
  20605. this.emissive = new Color(0x000000);
  20606. this.emissiveIntensity = 1.0;
  20607. this.emissiveMap = null;
  20608. this.bumpMap = null;
  20609. this.bumpScale = 1;
  20610. this.normalMap = null;
  20611. this.normalMapType = TangentSpaceNormalMap;
  20612. this.normalScale = new Vector2(1, 1);
  20613. this.displacementMap = null;
  20614. this.displacementScale = 1;
  20615. this.displacementBias = 0;
  20616. this.alphaMap = null;
  20617. this.wireframe = false;
  20618. this.wireframeLinewidth = 1;
  20619. this.wireframeLinecap = 'round';
  20620. this.wireframeLinejoin = 'round';
  20621. this.skinning = false;
  20622. this.morphTargets = false;
  20623. this.morphNormals = false;
  20624. this.setValues(parameters);
  20625. }
  20626. MeshToonMaterial.prototype = Object.create(Material.prototype);
  20627. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  20628. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20629. MeshToonMaterial.prototype.copy = function (source) {
  20630. Material.prototype.copy.call(this, source);
  20631. this.color.copy(source.color);
  20632. this.map = source.map;
  20633. this.gradientMap = source.gradientMap;
  20634. this.lightMap = source.lightMap;
  20635. this.lightMapIntensity = source.lightMapIntensity;
  20636. this.aoMap = source.aoMap;
  20637. this.aoMapIntensity = source.aoMapIntensity;
  20638. this.emissive.copy(source.emissive);
  20639. this.emissiveMap = source.emissiveMap;
  20640. this.emissiveIntensity = source.emissiveIntensity;
  20641. this.bumpMap = source.bumpMap;
  20642. this.bumpScale = source.bumpScale;
  20643. this.normalMap = source.normalMap;
  20644. this.normalMapType = source.normalMapType;
  20645. this.normalScale.copy(source.normalScale);
  20646. this.displacementMap = source.displacementMap;
  20647. this.displacementScale = source.displacementScale;
  20648. this.displacementBias = source.displacementBias;
  20649. this.alphaMap = source.alphaMap;
  20650. this.wireframe = source.wireframe;
  20651. this.wireframeLinewidth = source.wireframeLinewidth;
  20652. this.wireframeLinecap = source.wireframeLinecap;
  20653. this.wireframeLinejoin = source.wireframeLinejoin;
  20654. this.skinning = source.skinning;
  20655. this.morphTargets = source.morphTargets;
  20656. this.morphNormals = source.morphNormals;
  20657. return this;
  20658. };
  20659. /**
  20660. * parameters = {
  20661. * opacity: <float>,
  20662. *
  20663. * bumpMap: new THREE.Texture( <Image> ),
  20664. * bumpScale: <float>,
  20665. *
  20666. * normalMap: new THREE.Texture( <Image> ),
  20667. * normalMapType: THREE.TangentSpaceNormalMap,
  20668. * normalScale: <Vector2>,
  20669. *
  20670. * displacementMap: new THREE.Texture( <Image> ),
  20671. * displacementScale: <float>,
  20672. * displacementBias: <float>,
  20673. *
  20674. * wireframe: <boolean>,
  20675. * wireframeLinewidth: <float>
  20676. *
  20677. * skinning: <bool>,
  20678. * morphTargets: <bool>,
  20679. * morphNormals: <bool>
  20680. * }
  20681. */
  20682. function MeshNormalMaterial(parameters) {
  20683. Material.call(this);
  20684. this.type = 'MeshNormalMaterial';
  20685. this.bumpMap = null;
  20686. this.bumpScale = 1;
  20687. this.normalMap = null;
  20688. this.normalMapType = TangentSpaceNormalMap;
  20689. this.normalScale = new Vector2(1, 1);
  20690. this.displacementMap = null;
  20691. this.displacementScale = 1;
  20692. this.displacementBias = 0;
  20693. this.wireframe = false;
  20694. this.wireframeLinewidth = 1;
  20695. this.fog = false;
  20696. this.skinning = false;
  20697. this.morphTargets = false;
  20698. this.morphNormals = false;
  20699. this.setValues(parameters);
  20700. }
  20701. MeshNormalMaterial.prototype = Object.create(Material.prototype);
  20702. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20703. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20704. MeshNormalMaterial.prototype.copy = function (source) {
  20705. Material.prototype.copy.call(this, source);
  20706. this.bumpMap = source.bumpMap;
  20707. this.bumpScale = source.bumpScale;
  20708. this.normalMap = source.normalMap;
  20709. this.normalMapType = source.normalMapType;
  20710. this.normalScale.copy(source.normalScale);
  20711. this.displacementMap = source.displacementMap;
  20712. this.displacementScale = source.displacementScale;
  20713. this.displacementBias = source.displacementBias;
  20714. this.wireframe = source.wireframe;
  20715. this.wireframeLinewidth = source.wireframeLinewidth;
  20716. this.skinning = source.skinning;
  20717. this.morphTargets = source.morphTargets;
  20718. this.morphNormals = source.morphNormals;
  20719. return this;
  20720. };
  20721. /**
  20722. * parameters = {
  20723. * color: <hex>,
  20724. * opacity: <float>,
  20725. *
  20726. * map: new THREE.Texture( <Image> ),
  20727. *
  20728. * lightMap: new THREE.Texture( <Image> ),
  20729. * lightMapIntensity: <float>
  20730. *
  20731. * aoMap: new THREE.Texture( <Image> ),
  20732. * aoMapIntensity: <float>
  20733. *
  20734. * emissive: <hex>,
  20735. * emissiveIntensity: <float>
  20736. * emissiveMap: new THREE.Texture( <Image> ),
  20737. *
  20738. * specularMap: new THREE.Texture( <Image> ),
  20739. *
  20740. * alphaMap: new THREE.Texture( <Image> ),
  20741. *
  20742. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20743. * combine: THREE.Multiply,
  20744. * reflectivity: <float>,
  20745. * refractionRatio: <float>,
  20746. *
  20747. * wireframe: <boolean>,
  20748. * wireframeLinewidth: <float>,
  20749. *
  20750. * skinning: <bool>,
  20751. * morphTargets: <bool>,
  20752. * morphNormals: <bool>
  20753. * }
  20754. */
  20755. function MeshLambertMaterial(parameters) {
  20756. Material.call(this);
  20757. this.type = 'MeshLambertMaterial';
  20758. this.color = new Color(0xffffff); // diffuse
  20759. this.map = null;
  20760. this.lightMap = null;
  20761. this.lightMapIntensity = 1.0;
  20762. this.aoMap = null;
  20763. this.aoMapIntensity = 1.0;
  20764. this.emissive = new Color(0x000000);
  20765. this.emissiveIntensity = 1.0;
  20766. this.emissiveMap = null;
  20767. this.specularMap = null;
  20768. this.alphaMap = null;
  20769. this.envMap = null;
  20770. this.combine = MultiplyOperation;
  20771. this.reflectivity = 1;
  20772. this.refractionRatio = 0.98;
  20773. this.wireframe = false;
  20774. this.wireframeLinewidth = 1;
  20775. this.wireframeLinecap = 'round';
  20776. this.wireframeLinejoin = 'round';
  20777. this.skinning = false;
  20778. this.morphTargets = false;
  20779. this.morphNormals = false;
  20780. this.setValues(parameters);
  20781. }
  20782. MeshLambertMaterial.prototype = Object.create(Material.prototype);
  20783. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20784. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20785. MeshLambertMaterial.prototype.copy = function (source) {
  20786. Material.prototype.copy.call(this, source);
  20787. this.color.copy(source.color);
  20788. this.map = source.map;
  20789. this.lightMap = source.lightMap;
  20790. this.lightMapIntensity = source.lightMapIntensity;
  20791. this.aoMap = source.aoMap;
  20792. this.aoMapIntensity = source.aoMapIntensity;
  20793. this.emissive.copy(source.emissive);
  20794. this.emissiveMap = source.emissiveMap;
  20795. this.emissiveIntensity = source.emissiveIntensity;
  20796. this.specularMap = source.specularMap;
  20797. this.alphaMap = source.alphaMap;
  20798. this.envMap = source.envMap;
  20799. this.combine = source.combine;
  20800. this.reflectivity = source.reflectivity;
  20801. this.refractionRatio = source.refractionRatio;
  20802. this.wireframe = source.wireframe;
  20803. this.wireframeLinewidth = source.wireframeLinewidth;
  20804. this.wireframeLinecap = source.wireframeLinecap;
  20805. this.wireframeLinejoin = source.wireframeLinejoin;
  20806. this.skinning = source.skinning;
  20807. this.morphTargets = source.morphTargets;
  20808. this.morphNormals = source.morphNormals;
  20809. return this;
  20810. };
  20811. /**
  20812. * parameters = {
  20813. * color: <hex>,
  20814. * opacity: <float>,
  20815. *
  20816. * matcap: new THREE.Texture( <Image> ),
  20817. *
  20818. * map: new THREE.Texture( <Image> ),
  20819. *
  20820. * bumpMap: new THREE.Texture( <Image> ),
  20821. * bumpScale: <float>,
  20822. *
  20823. * normalMap: new THREE.Texture( <Image> ),
  20824. * normalMapType: THREE.TangentSpaceNormalMap,
  20825. * normalScale: <Vector2>,
  20826. *
  20827. * displacementMap: new THREE.Texture( <Image> ),
  20828. * displacementScale: <float>,
  20829. * displacementBias: <float>,
  20830. *
  20831. * alphaMap: new THREE.Texture( <Image> ),
  20832. *
  20833. * skinning: <bool>,
  20834. * morphTargets: <bool>,
  20835. * morphNormals: <bool>
  20836. * }
  20837. */
  20838. function MeshMatcapMaterial(parameters) {
  20839. Material.call(this);
  20840. this.defines = {
  20841. 'MATCAP': ''
  20842. };
  20843. this.type = 'MeshMatcapMaterial';
  20844. this.color = new Color(0xffffff); // diffuse
  20845. this.matcap = null;
  20846. this.map = null;
  20847. this.bumpMap = null;
  20848. this.bumpScale = 1;
  20849. this.normalMap = null;
  20850. this.normalMapType = TangentSpaceNormalMap;
  20851. this.normalScale = new Vector2(1, 1);
  20852. this.displacementMap = null;
  20853. this.displacementScale = 1;
  20854. this.displacementBias = 0;
  20855. this.alphaMap = null;
  20856. this.skinning = false;
  20857. this.morphTargets = false;
  20858. this.morphNormals = false;
  20859. this.setValues(parameters);
  20860. }
  20861. MeshMatcapMaterial.prototype = Object.create(Material.prototype);
  20862. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20863. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20864. MeshMatcapMaterial.prototype.copy = function (source) {
  20865. Material.prototype.copy.call(this, source);
  20866. this.defines = {
  20867. 'MATCAP': ''
  20868. };
  20869. this.color.copy(source.color);
  20870. this.matcap = source.matcap;
  20871. this.map = source.map;
  20872. this.bumpMap = source.bumpMap;
  20873. this.bumpScale = source.bumpScale;
  20874. this.normalMap = source.normalMap;
  20875. this.normalMapType = source.normalMapType;
  20876. this.normalScale.copy(source.normalScale);
  20877. this.displacementMap = source.displacementMap;
  20878. this.displacementScale = source.displacementScale;
  20879. this.displacementBias = source.displacementBias;
  20880. this.alphaMap = source.alphaMap;
  20881. this.skinning = source.skinning;
  20882. this.morphTargets = source.morphTargets;
  20883. this.morphNormals = source.morphNormals;
  20884. return this;
  20885. };
  20886. /**
  20887. * parameters = {
  20888. * color: <hex>,
  20889. * opacity: <float>,
  20890. *
  20891. * linewidth: <float>,
  20892. *
  20893. * scale: <float>,
  20894. * dashSize: <float>,
  20895. * gapSize: <float>
  20896. * }
  20897. */
  20898. function LineDashedMaterial(parameters) {
  20899. LineBasicMaterial.call(this);
  20900. this.type = 'LineDashedMaterial';
  20901. this.scale = 1;
  20902. this.dashSize = 3;
  20903. this.gapSize = 1;
  20904. this.setValues(parameters);
  20905. }
  20906. LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
  20907. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20908. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20909. LineDashedMaterial.prototype.copy = function (source) {
  20910. LineBasicMaterial.prototype.copy.call(this, source);
  20911. this.scale = source.scale;
  20912. this.dashSize = source.dashSize;
  20913. this.gapSize = source.gapSize;
  20914. return this;
  20915. };
  20916. var Materials = /*#__PURE__*/Object.freeze({
  20917. __proto__: null,
  20918. ShadowMaterial: ShadowMaterial,
  20919. SpriteMaterial: SpriteMaterial,
  20920. RawShaderMaterial: RawShaderMaterial,
  20921. ShaderMaterial: ShaderMaterial,
  20922. PointsMaterial: PointsMaterial,
  20923. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20924. MeshStandardMaterial: MeshStandardMaterial,
  20925. MeshPhongMaterial: MeshPhongMaterial,
  20926. MeshToonMaterial: MeshToonMaterial,
  20927. MeshNormalMaterial: MeshNormalMaterial,
  20928. MeshLambertMaterial: MeshLambertMaterial,
  20929. MeshDepthMaterial: MeshDepthMaterial,
  20930. MeshDistanceMaterial: MeshDistanceMaterial,
  20931. MeshBasicMaterial: MeshBasicMaterial,
  20932. MeshMatcapMaterial: MeshMatcapMaterial,
  20933. LineDashedMaterial: LineDashedMaterial,
  20934. LineBasicMaterial: LineBasicMaterial,
  20935. Material: Material
  20936. });
  20937. var AnimationUtils = {
  20938. // same as Array.prototype.slice, but also works on typed arrays
  20939. arraySlice: function arraySlice(array, from, to) {
  20940. if (AnimationUtils.isTypedArray(array)) {
  20941. // in ios9 array.subarray(from, undefined) will return empty array
  20942. // but array.subarray(from) or array.subarray(from, len) is correct
  20943. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20944. }
  20945. return array.slice(from, to);
  20946. },
  20947. // converts an array to a specific type
  20948. convertArray: function convertArray(array, type, forceClone) {
  20949. if (!array || // let 'undefined' and 'null' pass
  20950. !forceClone && array.constructor === type) return array;
  20951. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20952. return new type(array); // create typed array
  20953. }
  20954. return Array.prototype.slice.call(array); // create Array
  20955. },
  20956. isTypedArray: function isTypedArray(object) {
  20957. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20958. },
  20959. // returns an array by which times and values can be sorted
  20960. getKeyframeOrder: function getKeyframeOrder(times) {
  20961. function compareTime(i, j) {
  20962. return times[i] - times[j];
  20963. }
  20964. var n = times.length;
  20965. var result = new Array(n);
  20966. for (var i = 0; i !== n; ++i) {
  20967. result[i] = i;
  20968. }
  20969. result.sort(compareTime);
  20970. return result;
  20971. },
  20972. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20973. sortedArray: function sortedArray(values, stride, order) {
  20974. var nValues = values.length;
  20975. var result = new values.constructor(nValues);
  20976. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20977. var srcOffset = order[i] * stride;
  20978. for (var j = 0; j !== stride; ++j) {
  20979. result[dstOffset++] = values[srcOffset + j];
  20980. }
  20981. }
  20982. return result;
  20983. },
  20984. // function for parsing AOS keyframe formats
  20985. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20986. var i = 1,
  20987. key = jsonKeys[0];
  20988. while (key !== undefined && key[valuePropertyName] === undefined) {
  20989. key = jsonKeys[i++];
  20990. }
  20991. if (key === undefined) return; // no data
  20992. var value = key[valuePropertyName];
  20993. if (value === undefined) return; // no data
  20994. if (Array.isArray(value)) {
  20995. do {
  20996. value = key[valuePropertyName];
  20997. if (value !== undefined) {
  20998. times.push(key.time);
  20999. values.push.apply(values, value); // push all elements
  21000. }
  21001. key = jsonKeys[i++];
  21002. } while (key !== undefined);
  21003. } else if (value.toArray !== undefined) {
  21004. // ...assume THREE.Math-ish
  21005. do {
  21006. value = key[valuePropertyName];
  21007. if (value !== undefined) {
  21008. times.push(key.time);
  21009. value.toArray(values, values.length);
  21010. }
  21011. key = jsonKeys[i++];
  21012. } while (key !== undefined);
  21013. } else {
  21014. // otherwise push as-is
  21015. do {
  21016. value = key[valuePropertyName];
  21017. if (value !== undefined) {
  21018. times.push(key.time);
  21019. values.push(value);
  21020. }
  21021. key = jsonKeys[i++];
  21022. } while (key !== undefined);
  21023. }
  21024. },
  21025. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  21026. if (fps === void 0) {
  21027. fps = 30;
  21028. }
  21029. var clip = sourceClip.clone();
  21030. clip.name = name;
  21031. var tracks = [];
  21032. for (var i = 0; i < clip.tracks.length; ++i) {
  21033. var track = clip.tracks[i];
  21034. var valueSize = track.getValueSize();
  21035. var times = [];
  21036. var values = [];
  21037. for (var j = 0; j < track.times.length; ++j) {
  21038. var frame = track.times[j] * fps;
  21039. if (frame < startFrame || frame >= endFrame) continue;
  21040. times.push(track.times[j]);
  21041. for (var k = 0; k < valueSize; ++k) {
  21042. values.push(track.values[j * valueSize + k]);
  21043. }
  21044. }
  21045. if (times.length === 0) continue;
  21046. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  21047. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  21048. tracks.push(track);
  21049. }
  21050. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  21051. var minStartTime = Infinity;
  21052. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  21053. if (minStartTime > clip.tracks[_i].times[0]) {
  21054. minStartTime = clip.tracks[_i].times[0];
  21055. }
  21056. } // shift all tracks such that clip begins at t=0
  21057. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  21058. clip.tracks[_i2].shift(-1 * minStartTime);
  21059. }
  21060. clip.resetDuration();
  21061. return clip;
  21062. },
  21063. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  21064. if (referenceFrame === void 0) {
  21065. referenceFrame = 0;
  21066. }
  21067. if (referenceClip === void 0) {
  21068. referenceClip = targetClip;
  21069. }
  21070. if (fps === void 0) {
  21071. fps = 30;
  21072. }
  21073. if (fps <= 0) fps = 30;
  21074. var numTracks = referenceClip.tracks.length;
  21075. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  21076. var _loop = function _loop(i) {
  21077. var referenceTrack = referenceClip.tracks[i];
  21078. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  21079. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  21080. var targetTrack = targetClip.tracks.find(function (track) {
  21081. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  21082. });
  21083. if (targetTrack === undefined) return "continue";
  21084. var referenceOffset = 0;
  21085. var referenceValueSize = referenceTrack.getValueSize();
  21086. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  21087. referenceOffset = referenceValueSize / 3;
  21088. }
  21089. var targetOffset = 0;
  21090. var targetValueSize = targetTrack.getValueSize();
  21091. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  21092. targetOffset = targetValueSize / 3;
  21093. }
  21094. var lastIndex = referenceTrack.times.length - 1;
  21095. var referenceValue = void 0; // Find the value to subtract out of the track
  21096. if (referenceTime <= referenceTrack.times[0]) {
  21097. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  21098. var startIndex = referenceOffset;
  21099. var endIndex = referenceValueSize - referenceOffset;
  21100. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  21101. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  21102. // Reference frame is after the last keyframe, so just use the last keyframe
  21103. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  21104. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  21105. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  21106. } else {
  21107. // Interpolate to the reference value
  21108. var interpolant = referenceTrack.createInterpolant();
  21109. var _startIndex2 = referenceOffset;
  21110. var _endIndex2 = referenceValueSize - referenceOffset;
  21111. interpolant.evaluate(referenceTime);
  21112. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  21113. } // Conjugate the quaternion
  21114. if (referenceTrackType === 'quaternion') {
  21115. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  21116. referenceQuat.toArray(referenceValue);
  21117. } // Subtract the reference value from all of the track values
  21118. var numTimes = targetTrack.times.length;
  21119. for (var j = 0; j < numTimes; ++j) {
  21120. var valueStart = j * targetValueSize + targetOffset;
  21121. if (referenceTrackType === 'quaternion') {
  21122. // Multiply the conjugate for quaternion track types
  21123. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  21124. } else {
  21125. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  21126. for (var k = 0; k < valueEnd; ++k) {
  21127. targetTrack.values[valueStart + k] -= referenceValue[k];
  21128. }
  21129. }
  21130. }
  21131. };
  21132. for (var i = 0; i < numTracks; ++i) {
  21133. var _ret = _loop(i);
  21134. if (_ret === "continue") continue;
  21135. }
  21136. targetClip.blendMode = AdditiveAnimationBlendMode;
  21137. return targetClip;
  21138. }
  21139. };
  21140. /**
  21141. * Abstract base class of interpolants over parametric samples.
  21142. *
  21143. * The parameter domain is one dimensional, typically the time or a path
  21144. * along a curve defined by the data.
  21145. *
  21146. * The sample values can have any dimensionality and derived classes may
  21147. * apply special interpretations to the data.
  21148. *
  21149. * This class provides the interval seek in a Template Method, deferring
  21150. * the actual interpolation to derived classes.
  21151. *
  21152. * Time complexity is O(1) for linear access crossing at most two points
  21153. * and O(log N) for random access, where N is the number of positions.
  21154. *
  21155. * References:
  21156. *
  21157. * http://www.oodesign.com/template-method-pattern.html
  21158. *
  21159. */
  21160. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21161. this.parameterPositions = parameterPositions;
  21162. this._cachedIndex = 0;
  21163. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  21164. this.sampleValues = sampleValues;
  21165. this.valueSize = sampleSize;
  21166. }
  21167. Object.assign(Interpolant.prototype, {
  21168. evaluate: function evaluate(t) {
  21169. var pp = this.parameterPositions;
  21170. var i1 = this._cachedIndex,
  21171. t1 = pp[i1],
  21172. t0 = pp[i1 - 1];
  21173. validate_interval: {
  21174. seek: {
  21175. var right;
  21176. linear_scan: {
  21177. //- See http://jsperf.com/comparison-to-undefined/3
  21178. //- slower code:
  21179. //-
  21180. //- if ( t >= t1 || t1 === undefined ) {
  21181. forward_scan: if (!(t < t1)) {
  21182. for (var giveUpAt = i1 + 2;;) {
  21183. if (t1 === undefined) {
  21184. if (t < t0) break forward_scan; // after end
  21185. i1 = pp.length;
  21186. this._cachedIndex = i1;
  21187. return this.afterEnd_(i1 - 1, t, t0);
  21188. }
  21189. if (i1 === giveUpAt) break; // this loop
  21190. t0 = t1;
  21191. t1 = pp[++i1];
  21192. if (t < t1) {
  21193. // we have arrived at the sought interval
  21194. break seek;
  21195. }
  21196. } // prepare binary search on the right side of the index
  21197. right = pp.length;
  21198. break linear_scan;
  21199. } //- slower code:
  21200. //- if ( t < t0 || t0 === undefined ) {
  21201. if (!(t >= t0)) {
  21202. // looping?
  21203. var t1global = pp[1];
  21204. if (t < t1global) {
  21205. i1 = 2; // + 1, using the scan for the details
  21206. t0 = t1global;
  21207. } // linear reverse scan
  21208. for (var _giveUpAt = i1 - 2;;) {
  21209. if (t0 === undefined) {
  21210. // before start
  21211. this._cachedIndex = 0;
  21212. return this.beforeStart_(0, t, t1);
  21213. }
  21214. if (i1 === _giveUpAt) break; // this loop
  21215. t1 = t0;
  21216. t0 = pp[--i1 - 1];
  21217. if (t >= t0) {
  21218. // we have arrived at the sought interval
  21219. break seek;
  21220. }
  21221. } // prepare binary search on the left side of the index
  21222. right = i1;
  21223. i1 = 0;
  21224. break linear_scan;
  21225. } // the interval is valid
  21226. break validate_interval;
  21227. } // linear scan
  21228. // binary search
  21229. while (i1 < right) {
  21230. var mid = i1 + right >>> 1;
  21231. if (t < pp[mid]) {
  21232. right = mid;
  21233. } else {
  21234. i1 = mid + 1;
  21235. }
  21236. }
  21237. t1 = pp[i1];
  21238. t0 = pp[i1 - 1]; // check boundary cases, again
  21239. if (t0 === undefined) {
  21240. this._cachedIndex = 0;
  21241. return this.beforeStart_(0, t, t1);
  21242. }
  21243. if (t1 === undefined) {
  21244. i1 = pp.length;
  21245. this._cachedIndex = i1;
  21246. return this.afterEnd_(i1 - 1, t0, t);
  21247. }
  21248. } // seek
  21249. this._cachedIndex = i1;
  21250. this.intervalChanged_(i1, t0, t1);
  21251. } // validate_interval
  21252. return this.interpolate_(i1, t0, t, t1);
  21253. },
  21254. settings: null,
  21255. // optional, subclass-specific settings structure
  21256. // Note: The indirection allows central control of many interpolants.
  21257. // --- Protected interface
  21258. DefaultSettings_: {},
  21259. getSettings_: function getSettings_() {
  21260. return this.settings || this.DefaultSettings_;
  21261. },
  21262. copySampleValue_: function copySampleValue_(index) {
  21263. // copies a sample value to the result buffer
  21264. var result = this.resultBuffer,
  21265. values = this.sampleValues,
  21266. stride = this.valueSize,
  21267. offset = index * stride;
  21268. for (var i = 0; i !== stride; ++i) {
  21269. result[i] = values[offset + i];
  21270. }
  21271. return result;
  21272. },
  21273. // Template methods for derived classes:
  21274. interpolate_: function interpolate_()
  21275. /* i1, t0, t, t1 */
  21276. {
  21277. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  21278. },
  21279. intervalChanged_: function intervalChanged_()
  21280. /* i1, t0, t1 */
  21281. {// empty
  21282. }
  21283. }); // DECLARE ALIAS AFTER assign prototype
  21284. Object.assign(Interpolant.prototype, {
  21285. //( 0, t, t0 ), returns this.resultBuffer
  21286. beforeStart_: Interpolant.prototype.copySampleValue_,
  21287. //( N-1, tN-1, t ), returns this.resultBuffer
  21288. afterEnd_: Interpolant.prototype.copySampleValue_
  21289. });
  21290. /**
  21291. * Fast and simple cubic spline interpolant.
  21292. *
  21293. * It was derived from a Hermitian construction setting the first derivative
  21294. * at each sample position to the linear slope between neighboring positions
  21295. * over their parameter interval.
  21296. */
  21297. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21298. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21299. this._weightPrev = -0;
  21300. this._offsetPrev = -0;
  21301. this._weightNext = -0;
  21302. this._offsetNext = -0;
  21303. }
  21304. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21305. constructor: CubicInterpolant,
  21306. DefaultSettings_: {
  21307. endingStart: ZeroCurvatureEnding,
  21308. endingEnd: ZeroCurvatureEnding
  21309. },
  21310. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  21311. var pp = this.parameterPositions;
  21312. var iPrev = i1 - 2,
  21313. iNext = i1 + 1,
  21314. tPrev = pp[iPrev],
  21315. tNext = pp[iNext];
  21316. if (tPrev === undefined) {
  21317. switch (this.getSettings_().endingStart) {
  21318. case ZeroSlopeEnding:
  21319. // f'(t0) = 0
  21320. iPrev = i1;
  21321. tPrev = 2 * t0 - t1;
  21322. break;
  21323. case WrapAroundEnding:
  21324. // use the other end of the curve
  21325. iPrev = pp.length - 2;
  21326. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  21327. break;
  21328. default:
  21329. // ZeroCurvatureEnding
  21330. // f''(t0) = 0 a.k.a. Natural Spline
  21331. iPrev = i1;
  21332. tPrev = t1;
  21333. }
  21334. }
  21335. if (tNext === undefined) {
  21336. switch (this.getSettings_().endingEnd) {
  21337. case ZeroSlopeEnding:
  21338. // f'(tN) = 0
  21339. iNext = i1;
  21340. tNext = 2 * t1 - t0;
  21341. break;
  21342. case WrapAroundEnding:
  21343. // use the other end of the curve
  21344. iNext = 1;
  21345. tNext = t1 + pp[1] - pp[0];
  21346. break;
  21347. default:
  21348. // ZeroCurvatureEnding
  21349. // f''(tN) = 0, a.k.a. Natural Spline
  21350. iNext = i1 - 1;
  21351. tNext = t0;
  21352. }
  21353. }
  21354. var halfDt = (t1 - t0) * 0.5,
  21355. stride = this.valueSize;
  21356. this._weightPrev = halfDt / (t0 - tPrev);
  21357. this._weightNext = halfDt / (tNext - t1);
  21358. this._offsetPrev = iPrev * stride;
  21359. this._offsetNext = iNext * stride;
  21360. },
  21361. interpolate_: function interpolate_(i1, t0, t, t1) {
  21362. var result = this.resultBuffer,
  21363. values = this.sampleValues,
  21364. stride = this.valueSize,
  21365. o1 = i1 * stride,
  21366. o0 = o1 - stride,
  21367. oP = this._offsetPrev,
  21368. oN = this._offsetNext,
  21369. wP = this._weightPrev,
  21370. wN = this._weightNext,
  21371. p = (t - t0) / (t1 - t0),
  21372. pp = p * p,
  21373. ppp = pp * p; // evaluate polynomials
  21374. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  21375. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  21376. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  21377. var sN = wN * ppp - wN * pp; // combine data linearly
  21378. for (var i = 0; i !== stride; ++i) {
  21379. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  21380. }
  21381. return result;
  21382. }
  21383. });
  21384. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21385. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21386. }
  21387. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21388. constructor: LinearInterpolant,
  21389. interpolate_: function interpolate_(i1, t0, t, t1) {
  21390. var result = this.resultBuffer,
  21391. values = this.sampleValues,
  21392. stride = this.valueSize,
  21393. offset1 = i1 * stride,
  21394. offset0 = offset1 - stride,
  21395. weight1 = (t - t0) / (t1 - t0),
  21396. weight0 = 1 - weight1;
  21397. for (var i = 0; i !== stride; ++i) {
  21398. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  21399. }
  21400. return result;
  21401. }
  21402. });
  21403. /**
  21404. *
  21405. * Interpolant that evaluates to the sample value at the position preceeding
  21406. * the parameter.
  21407. */
  21408. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21409. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21410. }
  21411. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21412. constructor: DiscreteInterpolant,
  21413. interpolate_: function interpolate_(i1
  21414. /*, t0, t, t1 */
  21415. ) {
  21416. return this.copySampleValue_(i1 - 1);
  21417. }
  21418. });
  21419. function KeyframeTrack(name, times, values, interpolation) {
  21420. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  21421. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  21422. this.name = name;
  21423. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  21424. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  21425. this.setInterpolation(interpolation || this.DefaultInterpolation);
  21426. } // Static methods
  21427. Object.assign(KeyframeTrack, {
  21428. // Serialization (in static context, because of constructor invocation
  21429. // and automatic invocation of .toJSON):
  21430. toJSON: function toJSON(track) {
  21431. var trackType = track.constructor;
  21432. var json; // derived classes can define a static toJSON method
  21433. if (trackType.toJSON !== undefined) {
  21434. json = trackType.toJSON(track);
  21435. } else {
  21436. // by default, we assume the data can be serialized as-is
  21437. json = {
  21438. 'name': track.name,
  21439. 'times': AnimationUtils.convertArray(track.times, Array),
  21440. 'values': AnimationUtils.convertArray(track.values, Array)
  21441. };
  21442. var interpolation = track.getInterpolation();
  21443. if (interpolation !== track.DefaultInterpolation) {
  21444. json.interpolation = interpolation;
  21445. }
  21446. }
  21447. json.type = track.ValueTypeName; // mandatory
  21448. return json;
  21449. }
  21450. });
  21451. Object.assign(KeyframeTrack.prototype, {
  21452. constructor: KeyframeTrack,
  21453. TimeBufferType: Float32Array,
  21454. ValueBufferType: Float32Array,
  21455. DefaultInterpolation: InterpolateLinear,
  21456. InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
  21457. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  21458. },
  21459. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21460. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21461. },
  21462. InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
  21463. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  21464. },
  21465. setInterpolation: function setInterpolation(interpolation) {
  21466. var factoryMethod;
  21467. switch (interpolation) {
  21468. case InterpolateDiscrete:
  21469. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  21470. break;
  21471. case InterpolateLinear:
  21472. factoryMethod = this.InterpolantFactoryMethodLinear;
  21473. break;
  21474. case InterpolateSmooth:
  21475. factoryMethod = this.InterpolantFactoryMethodSmooth;
  21476. break;
  21477. }
  21478. if (factoryMethod === undefined) {
  21479. var message = 'unsupported interpolation for ' + this.ValueTypeName + ' keyframe track named ' + this.name;
  21480. if (this.createInterpolant === undefined) {
  21481. // fall back to default, unless the default itself is messed up
  21482. if (interpolation !== this.DefaultInterpolation) {
  21483. this.setInterpolation(this.DefaultInterpolation);
  21484. } else {
  21485. throw new Error(message); // fatal, in this case
  21486. }
  21487. }
  21488. console.warn('THREE.KeyframeTrack:', message);
  21489. return this;
  21490. }
  21491. this.createInterpolant = factoryMethod;
  21492. return this;
  21493. },
  21494. getInterpolation: function getInterpolation() {
  21495. switch (this.createInterpolant) {
  21496. case this.InterpolantFactoryMethodDiscrete:
  21497. return InterpolateDiscrete;
  21498. case this.InterpolantFactoryMethodLinear:
  21499. return InterpolateLinear;
  21500. case this.InterpolantFactoryMethodSmooth:
  21501. return InterpolateSmooth;
  21502. }
  21503. },
  21504. getValueSize: function getValueSize() {
  21505. return this.values.length / this.times.length;
  21506. },
  21507. // move all keyframes either forwards or backwards in time
  21508. shift: function shift(timeOffset) {
  21509. if (timeOffset !== 0.0) {
  21510. var times = this.times;
  21511. for (var i = 0, n = times.length; i !== n; ++i) {
  21512. times[i] += timeOffset;
  21513. }
  21514. }
  21515. return this;
  21516. },
  21517. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21518. scale: function scale(timeScale) {
  21519. if (timeScale !== 1.0) {
  21520. var times = this.times;
  21521. for (var i = 0, n = times.length; i !== n; ++i) {
  21522. times[i] *= timeScale;
  21523. }
  21524. }
  21525. return this;
  21526. },
  21527. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21528. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21529. trim: function trim(startTime, endTime) {
  21530. var times = this.times,
  21531. nKeys = times.length;
  21532. var from = 0,
  21533. to = nKeys - 1;
  21534. while (from !== nKeys && times[from] < startTime) {
  21535. ++from;
  21536. }
  21537. while (to !== -1 && times[to] > endTime) {
  21538. --to;
  21539. }
  21540. ++to; // inclusive -> exclusive bound
  21541. if (from !== 0 || to !== nKeys) {
  21542. // empty tracks are forbidden, so keep at least one keyframe
  21543. if (from >= to) {
  21544. to = Math.max(to, 1);
  21545. from = to - 1;
  21546. }
  21547. var stride = this.getValueSize();
  21548. this.times = AnimationUtils.arraySlice(times, from, to);
  21549. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  21550. }
  21551. return this;
  21552. },
  21553. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21554. validate: function validate() {
  21555. var valid = true;
  21556. var valueSize = this.getValueSize();
  21557. if (valueSize - Math.floor(valueSize) !== 0) {
  21558. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  21559. valid = false;
  21560. }
  21561. var times = this.times,
  21562. values = this.values,
  21563. nKeys = times.length;
  21564. if (nKeys === 0) {
  21565. console.error('THREE.KeyframeTrack: Track is empty.', this);
  21566. valid = false;
  21567. }
  21568. var prevTime = null;
  21569. for (var i = 0; i !== nKeys; i++) {
  21570. var currTime = times[i];
  21571. if (typeof currTime === 'number' && isNaN(currTime)) {
  21572. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  21573. valid = false;
  21574. break;
  21575. }
  21576. if (prevTime !== null && prevTime > currTime) {
  21577. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  21578. valid = false;
  21579. break;
  21580. }
  21581. prevTime = currTime;
  21582. }
  21583. if (values !== undefined) {
  21584. if (AnimationUtils.isTypedArray(values)) {
  21585. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  21586. var value = values[_i];
  21587. if (isNaN(value)) {
  21588. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  21589. valid = false;
  21590. break;
  21591. }
  21592. }
  21593. }
  21594. }
  21595. return valid;
  21596. },
  21597. // removes equivalent sequential keys as common in morph target sequences
  21598. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21599. optimize: function optimize() {
  21600. // times or values may be shared with other tracks, so overwriting is unsafe
  21601. var times = AnimationUtils.arraySlice(this.times),
  21602. values = AnimationUtils.arraySlice(this.values),
  21603. stride = this.getValueSize(),
  21604. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21605. lastIndex = times.length - 1;
  21606. var writeIndex = 1;
  21607. for (var i = 1; i < lastIndex; ++i) {
  21608. var keep = false;
  21609. var time = times[i];
  21610. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  21611. if (time !== timeNext && (i !== 1 || time !== time[0])) {
  21612. if (!smoothInterpolation) {
  21613. // remove unnecessary keyframes same as their neighbors
  21614. var offset = i * stride,
  21615. offsetP = offset - stride,
  21616. offsetN = offset + stride;
  21617. for (var j = 0; j !== stride; ++j) {
  21618. var value = values[offset + j];
  21619. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  21620. keep = true;
  21621. break;
  21622. }
  21623. }
  21624. } else {
  21625. keep = true;
  21626. }
  21627. } // in-place compaction
  21628. if (keep) {
  21629. if (i !== writeIndex) {
  21630. times[writeIndex] = times[i];
  21631. var readOffset = i * stride,
  21632. writeOffset = writeIndex * stride;
  21633. for (var _j = 0; _j !== stride; ++_j) {
  21634. values[writeOffset + _j] = values[readOffset + _j];
  21635. }
  21636. }
  21637. ++writeIndex;
  21638. }
  21639. } // flush last keyframe (compaction looks ahead)
  21640. if (lastIndex > 0) {
  21641. times[writeIndex] = times[lastIndex];
  21642. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  21643. values[_writeOffset + _j2] = values[_readOffset + _j2];
  21644. }
  21645. ++writeIndex;
  21646. }
  21647. if (writeIndex !== times.length) {
  21648. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  21649. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  21650. } else {
  21651. this.times = times;
  21652. this.values = values;
  21653. }
  21654. return this;
  21655. },
  21656. clone: function clone() {
  21657. var times = AnimationUtils.arraySlice(this.times, 0);
  21658. var values = AnimationUtils.arraySlice(this.values, 0);
  21659. var TypedKeyframeTrack = this.constructor;
  21660. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21661. track.createInterpolant = this.createInterpolant;
  21662. return track;
  21663. }
  21664. });
  21665. /**
  21666. * A Track of Boolean keyframe values.
  21667. */
  21668. function BooleanKeyframeTrack(name, times, values) {
  21669. KeyframeTrack.call(this, name, times, values);
  21670. }
  21671. BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21672. constructor: BooleanKeyframeTrack,
  21673. ValueTypeName: 'bool',
  21674. ValueBufferType: Array,
  21675. DefaultInterpolation: InterpolateDiscrete,
  21676. InterpolantFactoryMethodLinear: undefined,
  21677. InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
  21678. // representation of a single value and a custom interpolant that
  21679. // computes "firstValue ^ isOdd( index )".
  21680. });
  21681. /**
  21682. * A Track of keyframe values that represent color.
  21683. */
  21684. function ColorKeyframeTrack(name, times, values, interpolation) {
  21685. KeyframeTrack.call(this, name, times, values, interpolation);
  21686. }
  21687. ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21688. constructor: ColorKeyframeTrack,
  21689. ValueTypeName: 'color' // ValueBufferType is inherited
  21690. // DefaultInterpolation is inherited
  21691. // Note: Very basic implementation and nothing special yet.
  21692. // However, this is the place for color space parameterization.
  21693. });
  21694. /**
  21695. * A Track of numeric keyframe values.
  21696. */
  21697. function NumberKeyframeTrack(name, times, values, interpolation) {
  21698. KeyframeTrack.call(this, name, times, values, interpolation);
  21699. }
  21700. NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21701. constructor: NumberKeyframeTrack,
  21702. ValueTypeName: 'number' // ValueBufferType is inherited
  21703. // DefaultInterpolation is inherited
  21704. });
  21705. /**
  21706. * Spherical linear unit quaternion interpolant.
  21707. */
  21708. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21709. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21710. }
  21711. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21712. constructor: QuaternionLinearInterpolant,
  21713. interpolate_: function interpolate_(i1, t0, t, t1) {
  21714. var result = this.resultBuffer,
  21715. values = this.sampleValues,
  21716. stride = this.valueSize,
  21717. alpha = (t - t0) / (t1 - t0);
  21718. var offset = i1 * stride;
  21719. for (var end = offset + stride; offset !== end; offset += 4) {
  21720. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21721. }
  21722. return result;
  21723. }
  21724. });
  21725. /**
  21726. * A Track of quaternion keyframe values.
  21727. */
  21728. function QuaternionKeyframeTrack(name, times, values, interpolation) {
  21729. KeyframeTrack.call(this, name, times, values, interpolation);
  21730. }
  21731. QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21732. constructor: QuaternionKeyframeTrack,
  21733. ValueTypeName: 'quaternion',
  21734. // ValueBufferType is inherited
  21735. DefaultInterpolation: InterpolateLinear,
  21736. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21737. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21738. },
  21739. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21740. });
  21741. /**
  21742. * A Track that interpolates Strings
  21743. */
  21744. function StringKeyframeTrack(name, times, values, interpolation) {
  21745. KeyframeTrack.call(this, name, times, values, interpolation);
  21746. }
  21747. StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21748. constructor: StringKeyframeTrack,
  21749. ValueTypeName: 'string',
  21750. ValueBufferType: Array,
  21751. DefaultInterpolation: InterpolateDiscrete,
  21752. InterpolantFactoryMethodLinear: undefined,
  21753. InterpolantFactoryMethodSmooth: undefined
  21754. });
  21755. /**
  21756. * A Track of vectored keyframe values.
  21757. */
  21758. function VectorKeyframeTrack(name, times, values, interpolation) {
  21759. KeyframeTrack.call(this, name, times, values, interpolation);
  21760. }
  21761. VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21762. constructor: VectorKeyframeTrack,
  21763. ValueTypeName: 'vector' // ValueBufferType is inherited
  21764. // DefaultInterpolation is inherited
  21765. });
  21766. function AnimationClip(name, duration, tracks, blendMode) {
  21767. if (duration === void 0) {
  21768. duration = -1;
  21769. }
  21770. if (blendMode === void 0) {
  21771. blendMode = NormalAnimationBlendMode;
  21772. }
  21773. this.name = name;
  21774. this.tracks = tracks;
  21775. this.duration = duration;
  21776. this.blendMode = blendMode;
  21777. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21778. if (this.duration < 0) {
  21779. this.resetDuration();
  21780. }
  21781. }
  21782. function getTrackTypeForValueTypeName(typeName) {
  21783. switch (typeName.toLowerCase()) {
  21784. case 'scalar':
  21785. case 'double':
  21786. case 'float':
  21787. case 'number':
  21788. case 'integer':
  21789. return NumberKeyframeTrack;
  21790. case 'vector':
  21791. case 'vector2':
  21792. case 'vector3':
  21793. case 'vector4':
  21794. return VectorKeyframeTrack;
  21795. case 'color':
  21796. return ColorKeyframeTrack;
  21797. case 'quaternion':
  21798. return QuaternionKeyframeTrack;
  21799. case 'bool':
  21800. case 'boolean':
  21801. return BooleanKeyframeTrack;
  21802. case 'string':
  21803. return StringKeyframeTrack;
  21804. }
  21805. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21806. }
  21807. function parseKeyframeTrack(json) {
  21808. if (json.type === undefined) {
  21809. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21810. }
  21811. var trackType = getTrackTypeForValueTypeName(json.type);
  21812. if (json.times === undefined) {
  21813. var times = [],
  21814. values = [];
  21815. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21816. json.times = times;
  21817. json.values = values;
  21818. } // derived classes can define a static parse method
  21819. if (trackType.parse !== undefined) {
  21820. return trackType.parse(json);
  21821. } else {
  21822. // by default, we assume a constructor compatible with the base
  21823. return new trackType(json.name, json.times, json.values, json.interpolation);
  21824. }
  21825. }
  21826. Object.assign(AnimationClip, {
  21827. parse: function parse(json) {
  21828. var tracks = [],
  21829. jsonTracks = json.tracks,
  21830. frameTime = 1.0 / (json.fps || 1.0);
  21831. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21832. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21833. }
  21834. var clip = new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21835. clip.uuid = json.uuid;
  21836. return clip;
  21837. },
  21838. toJSON: function toJSON(clip) {
  21839. var tracks = [],
  21840. clipTracks = clip.tracks;
  21841. var json = {
  21842. 'name': clip.name,
  21843. 'duration': clip.duration,
  21844. 'tracks': tracks,
  21845. 'uuid': clip.uuid,
  21846. 'blendMode': clip.blendMode
  21847. };
  21848. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21849. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21850. }
  21851. return json;
  21852. },
  21853. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21854. var numMorphTargets = morphTargetSequence.length;
  21855. var tracks = [];
  21856. for (var i = 0; i < numMorphTargets; i++) {
  21857. var times = [];
  21858. var values = [];
  21859. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21860. values.push(0, 1, 0);
  21861. var order = AnimationUtils.getKeyframeOrder(times);
  21862. times = AnimationUtils.sortedArray(times, 1, order);
  21863. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21864. // last frame as well for perfect loop.
  21865. if (!noLoop && times[0] === 0) {
  21866. times.push(numMorphTargets);
  21867. values.push(values[0]);
  21868. }
  21869. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21870. }
  21871. return new AnimationClip(name, -1, tracks);
  21872. },
  21873. findByName: function findByName(objectOrClipArray, name) {
  21874. var clipArray = objectOrClipArray;
  21875. if (!Array.isArray(objectOrClipArray)) {
  21876. var o = objectOrClipArray;
  21877. clipArray = o.geometry && o.geometry.animations || o.animations;
  21878. }
  21879. for (var i = 0; i < clipArray.length; i++) {
  21880. if (clipArray[i].name === name) {
  21881. return clipArray[i];
  21882. }
  21883. }
  21884. return null;
  21885. },
  21886. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21887. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21888. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21889. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21890. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21891. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21892. var morphTarget = morphTargets[i];
  21893. var parts = morphTarget.name.match(pattern);
  21894. if (parts && parts.length > 1) {
  21895. var name = parts[1];
  21896. var animationMorphTargets = animationToMorphTargets[name];
  21897. if (!animationMorphTargets) {
  21898. animationToMorphTargets[name] = animationMorphTargets = [];
  21899. }
  21900. animationMorphTargets.push(morphTarget);
  21901. }
  21902. }
  21903. var clips = [];
  21904. for (var _name in animationToMorphTargets) {
  21905. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21906. }
  21907. return clips;
  21908. },
  21909. // parse the animation.hierarchy format
  21910. parseAnimation: function parseAnimation(animation, bones) {
  21911. if (!animation) {
  21912. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21913. return null;
  21914. }
  21915. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21916. // only return track if there are actually keys.
  21917. if (animationKeys.length !== 0) {
  21918. var times = [];
  21919. var values = [];
  21920. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21921. if (times.length !== 0) {
  21922. destTracks.push(new trackType(trackName, times, values));
  21923. }
  21924. }
  21925. };
  21926. var tracks = [];
  21927. var clipName = animation.name || 'default';
  21928. var fps = animation.fps || 30;
  21929. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21930. var duration = animation.length || -1;
  21931. var hierarchyTracks = animation.hierarchy || [];
  21932. for (var h = 0; h < hierarchyTracks.length; h++) {
  21933. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21934. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21935. if (animationKeys[0].morphTargets) {
  21936. // figure out all morph targets used in this track
  21937. var morphTargetNames = {};
  21938. var k = void 0;
  21939. for (k = 0; k < animationKeys.length; k++) {
  21940. if (animationKeys[k].morphTargets) {
  21941. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21942. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21943. }
  21944. }
  21945. } // create a track for each morph target with all zero
  21946. // morphTargetInfluences except for the keys in which
  21947. // the morphTarget is named.
  21948. for (var morphTargetName in morphTargetNames) {
  21949. var times = [];
  21950. var values = [];
  21951. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21952. var animationKey = animationKeys[k];
  21953. times.push(animationKey.time);
  21954. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21955. }
  21956. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21957. }
  21958. duration = morphTargetNames.length * (fps || 1.0);
  21959. } else {
  21960. // ...assume skeletal animation
  21961. var boneName = '.bones[' + bones[h].name + ']';
  21962. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21963. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21964. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21965. }
  21966. }
  21967. if (tracks.length === 0) {
  21968. return null;
  21969. }
  21970. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21971. return clip;
  21972. }
  21973. });
  21974. Object.assign(AnimationClip.prototype, {
  21975. resetDuration: function resetDuration() {
  21976. var tracks = this.tracks;
  21977. var duration = 0;
  21978. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21979. var track = this.tracks[i];
  21980. duration = Math.max(duration, track.times[track.times.length - 1]);
  21981. }
  21982. this.duration = duration;
  21983. return this;
  21984. },
  21985. trim: function trim() {
  21986. for (var i = 0; i < this.tracks.length; i++) {
  21987. this.tracks[i].trim(0, this.duration);
  21988. }
  21989. return this;
  21990. },
  21991. validate: function validate() {
  21992. var valid = true;
  21993. for (var i = 0; i < this.tracks.length; i++) {
  21994. valid = valid && this.tracks[i].validate();
  21995. }
  21996. return valid;
  21997. },
  21998. optimize: function optimize() {
  21999. for (var i = 0; i < this.tracks.length; i++) {
  22000. this.tracks[i].optimize();
  22001. }
  22002. return this;
  22003. },
  22004. clone: function clone() {
  22005. var tracks = [];
  22006. for (var i = 0; i < this.tracks.length; i++) {
  22007. tracks.push(this.tracks[i].clone());
  22008. }
  22009. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  22010. },
  22011. toJSON: function toJSON() {
  22012. return AnimationClip.toJSON(this);
  22013. }
  22014. });
  22015. var Cache = {
  22016. enabled: false,
  22017. files: {},
  22018. add: function add(key, file) {
  22019. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  22020. this.files[key] = file;
  22021. },
  22022. get: function get(key) {
  22023. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  22024. return this.files[key];
  22025. },
  22026. remove: function remove(key) {
  22027. delete this.files[key];
  22028. },
  22029. clear: function clear() {
  22030. this.files = {};
  22031. }
  22032. };
  22033. function LoadingManager(onLoad, onProgress, onError) {
  22034. var scope = this;
  22035. var isLoading = false;
  22036. var itemsLoaded = 0;
  22037. var itemsTotal = 0;
  22038. var urlModifier = undefined;
  22039. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  22040. // in the constructor
  22041. this.onStart = undefined;
  22042. this.onLoad = onLoad;
  22043. this.onProgress = onProgress;
  22044. this.onError = onError;
  22045. this.itemStart = function (url) {
  22046. itemsTotal++;
  22047. if (isLoading === false) {
  22048. if (scope.onStart !== undefined) {
  22049. scope.onStart(url, itemsLoaded, itemsTotal);
  22050. }
  22051. }
  22052. isLoading = true;
  22053. };
  22054. this.itemEnd = function (url) {
  22055. itemsLoaded++;
  22056. if (scope.onProgress !== undefined) {
  22057. scope.onProgress(url, itemsLoaded, itemsTotal);
  22058. }
  22059. if (itemsLoaded === itemsTotal) {
  22060. isLoading = false;
  22061. if (scope.onLoad !== undefined) {
  22062. scope.onLoad();
  22063. }
  22064. }
  22065. };
  22066. this.itemError = function (url) {
  22067. if (scope.onError !== undefined) {
  22068. scope.onError(url);
  22069. }
  22070. };
  22071. this.resolveURL = function (url) {
  22072. if (urlModifier) {
  22073. return urlModifier(url);
  22074. }
  22075. return url;
  22076. };
  22077. this.setURLModifier = function (transform) {
  22078. urlModifier = transform;
  22079. return this;
  22080. };
  22081. this.addHandler = function (regex, loader) {
  22082. handlers.push(regex, loader);
  22083. return this;
  22084. };
  22085. this.removeHandler = function (regex) {
  22086. var index = handlers.indexOf(regex);
  22087. if (index !== -1) {
  22088. handlers.splice(index, 2);
  22089. }
  22090. return this;
  22091. };
  22092. this.getHandler = function (file) {
  22093. for (var i = 0, l = handlers.length; i < l; i += 2) {
  22094. var regex = handlers[i];
  22095. var loader = handlers[i + 1];
  22096. if (regex.global) regex.lastIndex = 0; // see #17920
  22097. if (regex.test(file)) {
  22098. return loader;
  22099. }
  22100. }
  22101. return null;
  22102. };
  22103. }
  22104. var DefaultLoadingManager = new LoadingManager();
  22105. function Loader(manager) {
  22106. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  22107. this.crossOrigin = 'anonymous';
  22108. this.withCredentials = false;
  22109. this.path = '';
  22110. this.resourcePath = '';
  22111. this.requestHeader = {};
  22112. }
  22113. Object.assign(Loader.prototype, {
  22114. load: function load()
  22115. /* url, onLoad, onProgress, onError */
  22116. {},
  22117. loadAsync: function loadAsync(url, onProgress) {
  22118. var scope = this;
  22119. return new Promise(function (resolve, reject) {
  22120. scope.load(url, resolve, onProgress, reject);
  22121. });
  22122. },
  22123. parse: function parse()
  22124. /* data */
  22125. {},
  22126. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  22127. this.crossOrigin = crossOrigin;
  22128. return this;
  22129. },
  22130. setWithCredentials: function setWithCredentials(value) {
  22131. this.withCredentials = value;
  22132. return this;
  22133. },
  22134. setPath: function setPath(path) {
  22135. this.path = path;
  22136. return this;
  22137. },
  22138. setResourcePath: function setResourcePath(resourcePath) {
  22139. this.resourcePath = resourcePath;
  22140. return this;
  22141. },
  22142. setRequestHeader: function setRequestHeader(requestHeader) {
  22143. this.requestHeader = requestHeader;
  22144. return this;
  22145. }
  22146. });
  22147. var loading = {};
  22148. function FileLoader(manager) {
  22149. Loader.call(this, manager);
  22150. }
  22151. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22152. constructor: FileLoader,
  22153. load: function load(url, onLoad, onProgress, onError) {
  22154. if (url === undefined) url = '';
  22155. if (this.path !== undefined) url = this.path + url;
  22156. url = this.manager.resolveURL(url);
  22157. var scope = this;
  22158. var cached = Cache.get(url);
  22159. if (cached !== undefined) {
  22160. scope.manager.itemStart(url);
  22161. setTimeout(function () {
  22162. if (onLoad) onLoad(cached);
  22163. scope.manager.itemEnd(url);
  22164. }, 0);
  22165. return cached;
  22166. } // Check if request is duplicate
  22167. if (loading[url] !== undefined) {
  22168. loading[url].push({
  22169. onLoad: onLoad,
  22170. onProgress: onProgress,
  22171. onError: onError
  22172. });
  22173. return;
  22174. } // Check for data: URI
  22175. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  22176. var dataUriRegexResult = url.match(dataUriRegex);
  22177. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  22178. if (dataUriRegexResult) {
  22179. var mimeType = dataUriRegexResult[1];
  22180. var isBase64 = !!dataUriRegexResult[2];
  22181. var data = dataUriRegexResult[3];
  22182. data = decodeURIComponent(data);
  22183. if (isBase64) data = atob(data);
  22184. try {
  22185. var response;
  22186. var responseType = (this.responseType || '').toLowerCase();
  22187. switch (responseType) {
  22188. case 'arraybuffer':
  22189. case 'blob':
  22190. var view = new Uint8Array(data.length);
  22191. for (var i = 0; i < data.length; i++) {
  22192. view[i] = data.charCodeAt(i);
  22193. }
  22194. if (responseType === 'blob') {
  22195. response = new Blob([view.buffer], {
  22196. type: mimeType
  22197. });
  22198. } else {
  22199. response = view.buffer;
  22200. }
  22201. break;
  22202. case 'document':
  22203. var parser = new DOMParser();
  22204. response = parser.parseFromString(data, mimeType);
  22205. break;
  22206. case 'json':
  22207. response = JSON.parse(data);
  22208. break;
  22209. default:
  22210. // 'text' or other
  22211. response = data;
  22212. break;
  22213. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  22214. setTimeout(function () {
  22215. if (onLoad) onLoad(response);
  22216. scope.manager.itemEnd(url);
  22217. }, 0);
  22218. } catch (error) {
  22219. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  22220. setTimeout(function () {
  22221. if (onError) onError(error);
  22222. scope.manager.itemError(url);
  22223. scope.manager.itemEnd(url);
  22224. }, 0);
  22225. }
  22226. } else {
  22227. // Initialise array for duplicate requests
  22228. loading[url] = [];
  22229. loading[url].push({
  22230. onLoad: onLoad,
  22231. onProgress: onProgress,
  22232. onError: onError
  22233. });
  22234. request = new XMLHttpRequest();
  22235. request.open('GET', url, true);
  22236. request.addEventListener('load', function (event) {
  22237. var response = this.response;
  22238. var callbacks = loading[url];
  22239. delete loading[url];
  22240. if (this.status === 200 || this.status === 0) {
  22241. // Some browsers return HTTP Status 0 when using non-http protocol
  22242. // e.g. 'file://' or 'data://'. Handle as success.
  22243. 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
  22244. // error response bodies as proper responses to requests.
  22245. Cache.add(url, response);
  22246. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  22247. var callback = callbacks[_i];
  22248. if (callback.onLoad) callback.onLoad(response);
  22249. }
  22250. scope.manager.itemEnd(url);
  22251. } else {
  22252. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  22253. var _callback = callbacks[_i2];
  22254. if (_callback.onError) _callback.onError(event);
  22255. }
  22256. scope.manager.itemError(url);
  22257. scope.manager.itemEnd(url);
  22258. }
  22259. }, false);
  22260. request.addEventListener('progress', function (event) {
  22261. var callbacks = loading[url];
  22262. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  22263. var callback = callbacks[_i3];
  22264. if (callback.onProgress) callback.onProgress(event);
  22265. }
  22266. }, false);
  22267. request.addEventListener('error', function (event) {
  22268. var callbacks = loading[url];
  22269. delete loading[url];
  22270. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  22271. var callback = callbacks[_i4];
  22272. if (callback.onError) callback.onError(event);
  22273. }
  22274. scope.manager.itemError(url);
  22275. scope.manager.itemEnd(url);
  22276. }, false);
  22277. request.addEventListener('abort', function (event) {
  22278. var callbacks = loading[url];
  22279. delete loading[url];
  22280. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  22281. var callback = callbacks[_i5];
  22282. if (callback.onError) callback.onError(event);
  22283. }
  22284. scope.manager.itemError(url);
  22285. scope.manager.itemEnd(url);
  22286. }, false);
  22287. if (this.responseType !== undefined) request.responseType = this.responseType;
  22288. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  22289. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  22290. for (var header in this.requestHeader) {
  22291. request.setRequestHeader(header, this.requestHeader[header]);
  22292. }
  22293. request.send(null);
  22294. }
  22295. scope.manager.itemStart(url);
  22296. return request;
  22297. },
  22298. setResponseType: function setResponseType(value) {
  22299. this.responseType = value;
  22300. return this;
  22301. },
  22302. setMimeType: function setMimeType(value) {
  22303. this.mimeType = value;
  22304. return this;
  22305. }
  22306. });
  22307. function AnimationLoader(manager) {
  22308. Loader.call(this, manager);
  22309. }
  22310. AnimationLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22311. constructor: AnimationLoader,
  22312. load: function load(url, onLoad, onProgress, onError) {
  22313. var scope = this;
  22314. var loader = new FileLoader(scope.manager);
  22315. loader.setPath(scope.path);
  22316. loader.setRequestHeader(scope.requestHeader);
  22317. loader.setWithCredentials(scope.withCredentials);
  22318. loader.load(url, function (text) {
  22319. try {
  22320. onLoad(scope.parse(JSON.parse(text)));
  22321. } catch (e) {
  22322. if (onError) {
  22323. onError(e);
  22324. } else {
  22325. console.error(e);
  22326. }
  22327. scope.manager.itemError(url);
  22328. }
  22329. }, onProgress, onError);
  22330. },
  22331. parse: function parse(json) {
  22332. var animations = [];
  22333. for (var i = 0; i < json.length; i++) {
  22334. var clip = AnimationClip.parse(json[i]);
  22335. animations.push(clip);
  22336. }
  22337. return animations;
  22338. }
  22339. });
  22340. /**
  22341. * Abstract Base class to block based textures loader (dds, pvr, ...)
  22342. *
  22343. * Sub classes have to implement the parse() method which will be used in load().
  22344. */
  22345. function CompressedTextureLoader(manager) {
  22346. Loader.call(this, manager);
  22347. }
  22348. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22349. constructor: CompressedTextureLoader,
  22350. load: function load(url, onLoad, onProgress, onError) {
  22351. var scope = this;
  22352. var images = [];
  22353. var texture = new CompressedTexture();
  22354. var loader = new FileLoader(this.manager);
  22355. loader.setPath(this.path);
  22356. loader.setResponseType('arraybuffer');
  22357. loader.setRequestHeader(this.requestHeader);
  22358. loader.setWithCredentials(scope.withCredentials);
  22359. var loaded = 0;
  22360. function loadTexture(i) {
  22361. loader.load(url[i], function (buffer) {
  22362. var texDatas = scope.parse(buffer, true);
  22363. images[i] = {
  22364. width: texDatas.width,
  22365. height: texDatas.height,
  22366. format: texDatas.format,
  22367. mipmaps: texDatas.mipmaps
  22368. };
  22369. loaded += 1;
  22370. if (loaded === 6) {
  22371. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  22372. texture.image = images;
  22373. texture.format = texDatas.format;
  22374. texture.needsUpdate = true;
  22375. if (onLoad) onLoad(texture);
  22376. }
  22377. }, onProgress, onError);
  22378. }
  22379. if (Array.isArray(url)) {
  22380. for (var i = 0, il = url.length; i < il; ++i) {
  22381. loadTexture(i);
  22382. }
  22383. } else {
  22384. // compressed cubemap texture stored in a single DDS file
  22385. loader.load(url, function (buffer) {
  22386. var texDatas = scope.parse(buffer, true);
  22387. if (texDatas.isCubemap) {
  22388. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  22389. for (var f = 0; f < faces; f++) {
  22390. images[f] = {
  22391. mipmaps: []
  22392. };
  22393. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  22394. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  22395. images[f].format = texDatas.format;
  22396. images[f].width = texDatas.width;
  22397. images[f].height = texDatas.height;
  22398. }
  22399. }
  22400. texture.image = images;
  22401. } else {
  22402. texture.image.width = texDatas.width;
  22403. texture.image.height = texDatas.height;
  22404. texture.mipmaps = texDatas.mipmaps;
  22405. }
  22406. if (texDatas.mipmapCount === 1) {
  22407. texture.minFilter = LinearFilter;
  22408. }
  22409. texture.format = texDatas.format;
  22410. texture.needsUpdate = true;
  22411. if (onLoad) onLoad(texture);
  22412. }, onProgress, onError);
  22413. }
  22414. return texture;
  22415. }
  22416. });
  22417. function ImageLoader(manager) {
  22418. Loader.call(this, manager);
  22419. }
  22420. ImageLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22421. constructor: ImageLoader,
  22422. load: function load(url, onLoad, onProgress, onError) {
  22423. if (this.path !== undefined) url = this.path + url;
  22424. url = this.manager.resolveURL(url);
  22425. var scope = this;
  22426. var cached = Cache.get(url);
  22427. if (cached !== undefined) {
  22428. scope.manager.itemStart(url);
  22429. setTimeout(function () {
  22430. if (onLoad) onLoad(cached);
  22431. scope.manager.itemEnd(url);
  22432. }, 0);
  22433. return cached;
  22434. }
  22435. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  22436. function onImageLoad() {
  22437. image.removeEventListener('load', onImageLoad, false);
  22438. image.removeEventListener('error', onImageError, false);
  22439. Cache.add(url, this);
  22440. if (onLoad) onLoad(this);
  22441. scope.manager.itemEnd(url);
  22442. }
  22443. function onImageError(event) {
  22444. image.removeEventListener('load', onImageLoad, false);
  22445. image.removeEventListener('error', onImageError, false);
  22446. if (onError) onError(event);
  22447. scope.manager.itemError(url);
  22448. scope.manager.itemEnd(url);
  22449. }
  22450. image.addEventListener('load', onImageLoad, false);
  22451. image.addEventListener('error', onImageError, false);
  22452. if (url.substr(0, 5) !== 'data:') {
  22453. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  22454. }
  22455. scope.manager.itemStart(url);
  22456. image.src = url;
  22457. return image;
  22458. }
  22459. });
  22460. function CubeTextureLoader(manager) {
  22461. Loader.call(this, manager);
  22462. }
  22463. CubeTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22464. constructor: CubeTextureLoader,
  22465. load: function load(urls, onLoad, onProgress, onError) {
  22466. var texture = new CubeTexture();
  22467. var loader = new ImageLoader(this.manager);
  22468. loader.setCrossOrigin(this.crossOrigin);
  22469. loader.setPath(this.path);
  22470. var loaded = 0;
  22471. function loadTexture(i) {
  22472. loader.load(urls[i], function (image) {
  22473. texture.images[i] = image;
  22474. loaded++;
  22475. if (loaded === 6) {
  22476. texture.needsUpdate = true;
  22477. if (onLoad) onLoad(texture);
  22478. }
  22479. }, undefined, onError);
  22480. }
  22481. for (var i = 0; i < urls.length; ++i) {
  22482. loadTexture(i);
  22483. }
  22484. return texture;
  22485. }
  22486. });
  22487. /**
  22488. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  22489. *
  22490. * Sub classes have to implement the parse() method which will be used in load().
  22491. */
  22492. function DataTextureLoader(manager) {
  22493. Loader.call(this, manager);
  22494. }
  22495. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22496. constructor: DataTextureLoader,
  22497. load: function load(url, onLoad, onProgress, onError) {
  22498. var scope = this;
  22499. var texture = new DataTexture();
  22500. var loader = new FileLoader(this.manager);
  22501. loader.setResponseType('arraybuffer');
  22502. loader.setRequestHeader(this.requestHeader);
  22503. loader.setPath(this.path);
  22504. loader.setWithCredentials(scope.withCredentials);
  22505. loader.load(url, function (buffer) {
  22506. var texData = scope.parse(buffer);
  22507. if (!texData) return;
  22508. if (texData.image !== undefined) {
  22509. texture.image = texData.image;
  22510. } else if (texData.data !== undefined) {
  22511. texture.image.width = texData.width;
  22512. texture.image.height = texData.height;
  22513. texture.image.data = texData.data;
  22514. }
  22515. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  22516. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  22517. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  22518. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  22519. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  22520. if (texData.format !== undefined) {
  22521. texture.format = texData.format;
  22522. }
  22523. if (texData.type !== undefined) {
  22524. texture.type = texData.type;
  22525. }
  22526. if (texData.mipmaps !== undefined) {
  22527. texture.mipmaps = texData.mipmaps;
  22528. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  22529. }
  22530. if (texData.mipmapCount === 1) {
  22531. texture.minFilter = LinearFilter;
  22532. }
  22533. texture.needsUpdate = true;
  22534. if (onLoad) onLoad(texture, texData);
  22535. }, onProgress, onError);
  22536. return texture;
  22537. }
  22538. });
  22539. function TextureLoader(manager) {
  22540. Loader.call(this, manager);
  22541. }
  22542. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22543. constructor: TextureLoader,
  22544. load: function load(url, onLoad, onProgress, onError) {
  22545. var texture = new Texture();
  22546. var loader = new ImageLoader(this.manager);
  22547. loader.setCrossOrigin(this.crossOrigin);
  22548. loader.setPath(this.path);
  22549. loader.load(url, function (image) {
  22550. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  22551. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  22552. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  22553. texture.needsUpdate = true;
  22554. if (onLoad !== undefined) {
  22555. onLoad(texture);
  22556. }
  22557. }, onProgress, onError);
  22558. return texture;
  22559. }
  22560. });
  22561. /**
  22562. * Extensible curve object.
  22563. *
  22564. * Some common of curve methods:
  22565. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  22566. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  22567. * .getPoints(), .getSpacedPoints()
  22568. * .getLength()
  22569. * .updateArcLengths()
  22570. *
  22571. * This following curves inherit from THREE.Curve:
  22572. *
  22573. * -- 2D curves --
  22574. * THREE.ArcCurve
  22575. * THREE.CubicBezierCurve
  22576. * THREE.EllipseCurve
  22577. * THREE.LineCurve
  22578. * THREE.QuadraticBezierCurve
  22579. * THREE.SplineCurve
  22580. *
  22581. * -- 3D curves --
  22582. * THREE.CatmullRomCurve3
  22583. * THREE.CubicBezierCurve3
  22584. * THREE.LineCurve3
  22585. * THREE.QuadraticBezierCurve3
  22586. *
  22587. * A series of curves can be represented as a THREE.CurvePath.
  22588. *
  22589. **/
  22590. function Curve() {
  22591. this.type = 'Curve';
  22592. this.arcLengthDivisions = 200;
  22593. }
  22594. Object.assign(Curve.prototype, {
  22595. // Virtual base class method to overwrite and implement in subclasses
  22596. // - t [0 .. 1]
  22597. getPoint: function getPoint()
  22598. /* t, optionalTarget */
  22599. {
  22600. console.warn('THREE.Curve: .getPoint() not implemented.');
  22601. return null;
  22602. },
  22603. // Get point at relative position in curve according to arc length
  22604. // - u [0 .. 1]
  22605. getPointAt: function getPointAt(u, optionalTarget) {
  22606. var t = this.getUtoTmapping(u);
  22607. return this.getPoint(t, optionalTarget);
  22608. },
  22609. // Get sequence of points using getPoint( t )
  22610. getPoints: function getPoints(divisions) {
  22611. if (divisions === void 0) {
  22612. divisions = 5;
  22613. }
  22614. var points = [];
  22615. for (var d = 0; d <= divisions; d++) {
  22616. points.push(this.getPoint(d / divisions));
  22617. }
  22618. return points;
  22619. },
  22620. // Get sequence of points using getPointAt( u )
  22621. getSpacedPoints: function getSpacedPoints(divisions) {
  22622. if (divisions === void 0) {
  22623. divisions = 5;
  22624. }
  22625. var points = [];
  22626. for (var d = 0; d <= divisions; d++) {
  22627. points.push(this.getPointAt(d / divisions));
  22628. }
  22629. return points;
  22630. },
  22631. // Get total curve arc length
  22632. getLength: function getLength() {
  22633. var lengths = this.getLengths();
  22634. return lengths[lengths.length - 1];
  22635. },
  22636. // Get list of cumulative segment lengths
  22637. getLengths: function getLengths(divisions) {
  22638. if (divisions === undefined) divisions = this.arcLengthDivisions;
  22639. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  22640. return this.cacheArcLengths;
  22641. }
  22642. this.needsUpdate = false;
  22643. var cache = [];
  22644. var current,
  22645. last = this.getPoint(0);
  22646. var sum = 0;
  22647. cache.push(0);
  22648. for (var p = 1; p <= divisions; p++) {
  22649. current = this.getPoint(p / divisions);
  22650. sum += current.distanceTo(last);
  22651. cache.push(sum);
  22652. last = current;
  22653. }
  22654. this.cacheArcLengths = cache;
  22655. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22656. },
  22657. updateArcLengths: function updateArcLengths() {
  22658. this.needsUpdate = true;
  22659. this.getLengths();
  22660. },
  22661. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22662. getUtoTmapping: function getUtoTmapping(u, distance) {
  22663. var arcLengths = this.getLengths();
  22664. var i = 0;
  22665. var il = arcLengths.length;
  22666. var targetArcLength; // The targeted u distance value to get
  22667. if (distance) {
  22668. targetArcLength = distance;
  22669. } else {
  22670. targetArcLength = u * arcLengths[il - 1];
  22671. } // binary search for the index with largest value smaller than target u distance
  22672. var low = 0,
  22673. high = il - 1,
  22674. comparison;
  22675. while (low <= high) {
  22676. 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
  22677. comparison = arcLengths[i] - targetArcLength;
  22678. if (comparison < 0) {
  22679. low = i + 1;
  22680. } else if (comparison > 0) {
  22681. high = i - 1;
  22682. } else {
  22683. high = i;
  22684. break; // DONE
  22685. }
  22686. }
  22687. i = high;
  22688. if (arcLengths[i] === targetArcLength) {
  22689. return i / (il - 1);
  22690. } // we could get finer grain at lengths, or use simple interpolation between two points
  22691. var lengthBefore = arcLengths[i];
  22692. var lengthAfter = arcLengths[i + 1];
  22693. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  22694. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  22695. var t = (i + segmentFraction) / (il - 1);
  22696. return t;
  22697. },
  22698. // Returns a unit vector tangent at t
  22699. // In case any sub curve does not implement its tangent derivation,
  22700. // 2 points a small delta apart will be used to find its gradient
  22701. // which seems to give a reasonable approximation
  22702. getTangent: function getTangent(t, optionalTarget) {
  22703. var delta = 0.0001;
  22704. var t1 = t - delta;
  22705. var t2 = t + delta; // Capping in case of danger
  22706. if (t1 < 0) t1 = 0;
  22707. if (t2 > 1) t2 = 1;
  22708. var pt1 = this.getPoint(t1);
  22709. var pt2 = this.getPoint(t2);
  22710. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22711. tangent.copy(pt2).sub(pt1).normalize();
  22712. return tangent;
  22713. },
  22714. getTangentAt: function getTangentAt(u, optionalTarget) {
  22715. var t = this.getUtoTmapping(u);
  22716. return this.getTangent(t, optionalTarget);
  22717. },
  22718. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22719. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22720. var normal = new Vector3();
  22721. var tangents = [];
  22722. var normals = [];
  22723. var binormals = [];
  22724. var vec = new Vector3();
  22725. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22726. for (var i = 0; i <= segments; i++) {
  22727. var u = i / segments;
  22728. tangents[i] = this.getTangentAt(u, new Vector3());
  22729. tangents[i].normalize();
  22730. } // select an initial normal vector perpendicular to the first tangent vector,
  22731. // and in the direction of the minimum tangent xyz component
  22732. normals[0] = new Vector3();
  22733. binormals[0] = new Vector3();
  22734. var min = Number.MAX_VALUE;
  22735. var tx = Math.abs(tangents[0].x);
  22736. var ty = Math.abs(tangents[0].y);
  22737. var tz = Math.abs(tangents[0].z);
  22738. if (tx <= min) {
  22739. min = tx;
  22740. normal.set(1, 0, 0);
  22741. }
  22742. if (ty <= min) {
  22743. min = ty;
  22744. normal.set(0, 1, 0);
  22745. }
  22746. if (tz <= min) {
  22747. normal.set(0, 0, 1);
  22748. }
  22749. vec.crossVectors(tangents[0], normal).normalize();
  22750. normals[0].crossVectors(tangents[0], vec);
  22751. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22752. for (var _i = 1; _i <= segments; _i++) {
  22753. normals[_i] = normals[_i - 1].clone();
  22754. binormals[_i] = binormals[_i - 1].clone();
  22755. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22756. if (vec.length() > Number.EPSILON) {
  22757. vec.normalize();
  22758. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22759. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22760. }
  22761. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22762. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22763. if (closed === true) {
  22764. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22765. _theta /= segments;
  22766. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22767. _theta = -_theta;
  22768. }
  22769. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22770. // twist a little...
  22771. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22772. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22773. }
  22774. }
  22775. return {
  22776. tangents: tangents,
  22777. normals: normals,
  22778. binormals: binormals
  22779. };
  22780. },
  22781. clone: function clone() {
  22782. return new this.constructor().copy(this);
  22783. },
  22784. copy: function copy(source) {
  22785. this.arcLengthDivisions = source.arcLengthDivisions;
  22786. return this;
  22787. },
  22788. toJSON: function toJSON() {
  22789. var data = {
  22790. metadata: {
  22791. version: 4.5,
  22792. type: 'Curve',
  22793. generator: 'Curve.toJSON'
  22794. }
  22795. };
  22796. data.arcLengthDivisions = this.arcLengthDivisions;
  22797. data.type = this.type;
  22798. return data;
  22799. },
  22800. fromJSON: function fromJSON(json) {
  22801. this.arcLengthDivisions = json.arcLengthDivisions;
  22802. return this;
  22803. }
  22804. });
  22805. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22806. Curve.call(this);
  22807. this.type = 'EllipseCurve';
  22808. this.aX = aX || 0;
  22809. this.aY = aY || 0;
  22810. this.xRadius = xRadius || 1;
  22811. this.yRadius = yRadius || 1;
  22812. this.aStartAngle = aStartAngle || 0;
  22813. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22814. this.aClockwise = aClockwise || false;
  22815. this.aRotation = aRotation || 0;
  22816. }
  22817. EllipseCurve.prototype = Object.create(Curve.prototype);
  22818. EllipseCurve.prototype.constructor = EllipseCurve;
  22819. EllipseCurve.prototype.isEllipseCurve = true;
  22820. EllipseCurve.prototype.getPoint = function (t, optionalTarget) {
  22821. var point = optionalTarget || new Vector2();
  22822. var twoPi = Math.PI * 2;
  22823. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22824. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22825. while (deltaAngle < 0) {
  22826. deltaAngle += twoPi;
  22827. }
  22828. while (deltaAngle > twoPi) {
  22829. deltaAngle -= twoPi;
  22830. }
  22831. if (deltaAngle < Number.EPSILON) {
  22832. if (samePoints) {
  22833. deltaAngle = 0;
  22834. } else {
  22835. deltaAngle = twoPi;
  22836. }
  22837. }
  22838. if (this.aClockwise === true && !samePoints) {
  22839. if (deltaAngle === twoPi) {
  22840. deltaAngle = -twoPi;
  22841. } else {
  22842. deltaAngle = deltaAngle - twoPi;
  22843. }
  22844. }
  22845. var angle = this.aStartAngle + t * deltaAngle;
  22846. var x = this.aX + this.xRadius * Math.cos(angle);
  22847. var y = this.aY + this.yRadius * Math.sin(angle);
  22848. if (this.aRotation !== 0) {
  22849. var cos = Math.cos(this.aRotation);
  22850. var sin = Math.sin(this.aRotation);
  22851. var tx = x - this.aX;
  22852. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22853. x = tx * cos - ty * sin + this.aX;
  22854. y = tx * sin + ty * cos + this.aY;
  22855. }
  22856. return point.set(x, y);
  22857. };
  22858. EllipseCurve.prototype.copy = function (source) {
  22859. Curve.prototype.copy.call(this, source);
  22860. this.aX = source.aX;
  22861. this.aY = source.aY;
  22862. this.xRadius = source.xRadius;
  22863. this.yRadius = source.yRadius;
  22864. this.aStartAngle = source.aStartAngle;
  22865. this.aEndAngle = source.aEndAngle;
  22866. this.aClockwise = source.aClockwise;
  22867. this.aRotation = source.aRotation;
  22868. return this;
  22869. };
  22870. EllipseCurve.prototype.toJSON = function () {
  22871. var data = Curve.prototype.toJSON.call(this);
  22872. data.aX = this.aX;
  22873. data.aY = this.aY;
  22874. data.xRadius = this.xRadius;
  22875. data.yRadius = this.yRadius;
  22876. data.aStartAngle = this.aStartAngle;
  22877. data.aEndAngle = this.aEndAngle;
  22878. data.aClockwise = this.aClockwise;
  22879. data.aRotation = this.aRotation;
  22880. return data;
  22881. };
  22882. EllipseCurve.prototype.fromJSON = function (json) {
  22883. Curve.prototype.fromJSON.call(this, json);
  22884. this.aX = json.aX;
  22885. this.aY = json.aY;
  22886. this.xRadius = json.xRadius;
  22887. this.yRadius = json.yRadius;
  22888. this.aStartAngle = json.aStartAngle;
  22889. this.aEndAngle = json.aEndAngle;
  22890. this.aClockwise = json.aClockwise;
  22891. this.aRotation = json.aRotation;
  22892. return this;
  22893. };
  22894. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22895. EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  22896. this.type = 'ArcCurve';
  22897. }
  22898. ArcCurve.prototype = Object.create(EllipseCurve.prototype);
  22899. ArcCurve.prototype.constructor = ArcCurve;
  22900. ArcCurve.prototype.isArcCurve = true;
  22901. /**
  22902. * Centripetal CatmullRom Curve - which is useful for avoiding
  22903. * cusps and self-intersections in non-uniform catmull rom curves.
  22904. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22905. *
  22906. * curve.type accepts centripetal(default), chordal and catmullrom
  22907. * curve.tension is used for catmullrom which defaults to 0.5
  22908. */
  22909. /*
  22910. Based on an optimized c++ solution in
  22911. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22912. - http://ideone.com/NoEbVM
  22913. This CubicPoly class could be used for reusing some variables and calculations,
  22914. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22915. which can be placed in CurveUtils.
  22916. */
  22917. function CubicPoly() {
  22918. var c0 = 0,
  22919. c1 = 0,
  22920. c2 = 0,
  22921. c3 = 0;
  22922. /*
  22923. * Compute coefficients for a cubic polynomial
  22924. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22925. * such that
  22926. * p(0) = x0, p(1) = x1
  22927. * and
  22928. * p'(0) = t0, p'(1) = t1.
  22929. */
  22930. function init(x0, x1, t0, t1) {
  22931. c0 = x0;
  22932. c1 = t0;
  22933. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22934. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22935. }
  22936. return {
  22937. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22938. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22939. },
  22940. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22941. // compute tangents when parameterized in [t1,t2]
  22942. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22943. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22944. t1 *= dt1;
  22945. t2 *= dt1;
  22946. init(x1, x2, t1, t2);
  22947. },
  22948. calc: function calc(t) {
  22949. var t2 = t * t;
  22950. var t3 = t2 * t;
  22951. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22952. }
  22953. };
  22954. } //
  22955. var tmp = new Vector3();
  22956. var px = new CubicPoly(),
  22957. py = new CubicPoly(),
  22958. pz = new CubicPoly();
  22959. function CatmullRomCurve3(points, closed, curveType, tension) {
  22960. if (points === void 0) {
  22961. points = [];
  22962. }
  22963. if (closed === void 0) {
  22964. closed = false;
  22965. }
  22966. if (curveType === void 0) {
  22967. curveType = 'centripetal';
  22968. }
  22969. if (tension === void 0) {
  22970. tension = 0.5;
  22971. }
  22972. Curve.call(this);
  22973. this.type = 'CatmullRomCurve3';
  22974. this.points = points;
  22975. this.closed = closed;
  22976. this.curveType = curveType;
  22977. this.tension = tension;
  22978. }
  22979. CatmullRomCurve3.prototype = Object.create(Curve.prototype);
  22980. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22981. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22982. CatmullRomCurve3.prototype.getPoint = function (t, optionalTarget) {
  22983. if (optionalTarget === void 0) {
  22984. optionalTarget = new Vector3();
  22985. }
  22986. var point = optionalTarget;
  22987. var points = this.points;
  22988. var l = points.length;
  22989. var p = (l - (this.closed ? 0 : 1)) * t;
  22990. var intPoint = Math.floor(p);
  22991. var weight = p - intPoint;
  22992. if (this.closed) {
  22993. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22994. } else if (weight === 0 && intPoint === l - 1) {
  22995. intPoint = l - 2;
  22996. weight = 1;
  22997. }
  22998. var p0, p3; // 4 points (p1 & p2 defined below)
  22999. if (this.closed || intPoint > 0) {
  23000. p0 = points[(intPoint - 1) % l];
  23001. } else {
  23002. // extrapolate first point
  23003. tmp.subVectors(points[0], points[1]).add(points[0]);
  23004. p0 = tmp;
  23005. }
  23006. var p1 = points[intPoint % l];
  23007. var p2 = points[(intPoint + 1) % l];
  23008. if (this.closed || intPoint + 2 < l) {
  23009. p3 = points[(intPoint + 2) % l];
  23010. } else {
  23011. // extrapolate last point
  23012. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  23013. p3 = tmp;
  23014. }
  23015. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  23016. // init Centripetal / Chordal Catmull-Rom
  23017. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  23018. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  23019. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  23020. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  23021. if (dt1 < 1e-4) dt1 = 1.0;
  23022. if (dt0 < 1e-4) dt0 = dt1;
  23023. if (dt2 < 1e-4) dt2 = dt1;
  23024. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  23025. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  23026. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  23027. } else if (this.curveType === 'catmullrom') {
  23028. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  23029. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  23030. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  23031. }
  23032. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  23033. return point;
  23034. };
  23035. CatmullRomCurve3.prototype.copy = function (source) {
  23036. Curve.prototype.copy.call(this, source);
  23037. this.points = [];
  23038. for (var i = 0, l = source.points.length; i < l; i++) {
  23039. var point = source.points[i];
  23040. this.points.push(point.clone());
  23041. }
  23042. this.closed = source.closed;
  23043. this.curveType = source.curveType;
  23044. this.tension = source.tension;
  23045. return this;
  23046. };
  23047. CatmullRomCurve3.prototype.toJSON = function () {
  23048. var data = Curve.prototype.toJSON.call(this);
  23049. data.points = [];
  23050. for (var i = 0, l = this.points.length; i < l; i++) {
  23051. var point = this.points[i];
  23052. data.points.push(point.toArray());
  23053. }
  23054. data.closed = this.closed;
  23055. data.curveType = this.curveType;
  23056. data.tension = this.tension;
  23057. return data;
  23058. };
  23059. CatmullRomCurve3.prototype.fromJSON = function (json) {
  23060. Curve.prototype.fromJSON.call(this, json);
  23061. this.points = [];
  23062. for (var i = 0, l = json.points.length; i < l; i++) {
  23063. var point = json.points[i];
  23064. this.points.push(new Vector3().fromArray(point));
  23065. }
  23066. this.closed = json.closed;
  23067. this.curveType = json.curveType;
  23068. this.tension = json.tension;
  23069. return this;
  23070. };
  23071. /**
  23072. * Bezier Curves formulas obtained from
  23073. * http://en.wikipedia.org/wiki/Bézier_curve
  23074. */
  23075. function CatmullRom(t, p0, p1, p2, p3) {
  23076. var v0 = (p2 - p0) * 0.5;
  23077. var v1 = (p3 - p1) * 0.5;
  23078. var t2 = t * t;
  23079. var t3 = t * t2;
  23080. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  23081. } //
  23082. function QuadraticBezierP0(t, p) {
  23083. var k = 1 - t;
  23084. return k * k * p;
  23085. }
  23086. function QuadraticBezierP1(t, p) {
  23087. return 2 * (1 - t) * t * p;
  23088. }
  23089. function QuadraticBezierP2(t, p) {
  23090. return t * t * p;
  23091. }
  23092. function QuadraticBezier(t, p0, p1, p2) {
  23093. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  23094. } //
  23095. function CubicBezierP0(t, p) {
  23096. var k = 1 - t;
  23097. return k * k * k * p;
  23098. }
  23099. function CubicBezierP1(t, p) {
  23100. var k = 1 - t;
  23101. return 3 * k * k * t * p;
  23102. }
  23103. function CubicBezierP2(t, p) {
  23104. return 3 * (1 - t) * t * t * p;
  23105. }
  23106. function CubicBezierP3(t, p) {
  23107. return t * t * t * p;
  23108. }
  23109. function CubicBezier(t, p0, p1, p2, p3) {
  23110. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  23111. }
  23112. function CubicBezierCurve(v0, v1, v2, v3) {
  23113. if (v0 === void 0) {
  23114. v0 = new Vector2();
  23115. }
  23116. if (v1 === void 0) {
  23117. v1 = new Vector2();
  23118. }
  23119. if (v2 === void 0) {
  23120. v2 = new Vector2();
  23121. }
  23122. if (v3 === void 0) {
  23123. v3 = new Vector2();
  23124. }
  23125. Curve.call(this);
  23126. this.type = 'CubicBezierCurve';
  23127. this.v0 = v0;
  23128. this.v1 = v1;
  23129. this.v2 = v2;
  23130. this.v3 = v3;
  23131. }
  23132. CubicBezierCurve.prototype = Object.create(Curve.prototype);
  23133. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  23134. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  23135. CubicBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  23136. if (optionalTarget === void 0) {
  23137. optionalTarget = new Vector2();
  23138. }
  23139. var point = optionalTarget;
  23140. var v0 = this.v0,
  23141. v1 = this.v1,
  23142. v2 = this.v2,
  23143. v3 = this.v3;
  23144. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  23145. return point;
  23146. };
  23147. CubicBezierCurve.prototype.copy = function (source) {
  23148. Curve.prototype.copy.call(this, source);
  23149. this.v0.copy(source.v0);
  23150. this.v1.copy(source.v1);
  23151. this.v2.copy(source.v2);
  23152. this.v3.copy(source.v3);
  23153. return this;
  23154. };
  23155. CubicBezierCurve.prototype.toJSON = function () {
  23156. var data = Curve.prototype.toJSON.call(this);
  23157. data.v0 = this.v0.toArray();
  23158. data.v1 = this.v1.toArray();
  23159. data.v2 = this.v2.toArray();
  23160. data.v3 = this.v3.toArray();
  23161. return data;
  23162. };
  23163. CubicBezierCurve.prototype.fromJSON = function (json) {
  23164. Curve.prototype.fromJSON.call(this, json);
  23165. this.v0.fromArray(json.v0);
  23166. this.v1.fromArray(json.v1);
  23167. this.v2.fromArray(json.v2);
  23168. this.v3.fromArray(json.v3);
  23169. return this;
  23170. };
  23171. function CubicBezierCurve3(v0, v1, v2, v3) {
  23172. if (v0 === void 0) {
  23173. v0 = new Vector3();
  23174. }
  23175. if (v1 === void 0) {
  23176. v1 = new Vector3();
  23177. }
  23178. if (v2 === void 0) {
  23179. v2 = new Vector3();
  23180. }
  23181. if (v3 === void 0) {
  23182. v3 = new Vector3();
  23183. }
  23184. Curve.call(this);
  23185. this.type = 'CubicBezierCurve3';
  23186. this.v0 = v0;
  23187. this.v1 = v1;
  23188. this.v2 = v2;
  23189. this.v3 = v3;
  23190. }
  23191. CubicBezierCurve3.prototype = Object.create(Curve.prototype);
  23192. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  23193. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  23194. CubicBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  23195. if (optionalTarget === void 0) {
  23196. optionalTarget = new Vector3();
  23197. }
  23198. var point = optionalTarget;
  23199. var v0 = this.v0,
  23200. v1 = this.v1,
  23201. v2 = this.v2,
  23202. v3 = this.v3;
  23203. 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));
  23204. return point;
  23205. };
  23206. CubicBezierCurve3.prototype.copy = function (source) {
  23207. Curve.prototype.copy.call(this, source);
  23208. this.v0.copy(source.v0);
  23209. this.v1.copy(source.v1);
  23210. this.v2.copy(source.v2);
  23211. this.v3.copy(source.v3);
  23212. return this;
  23213. };
  23214. CubicBezierCurve3.prototype.toJSON = function () {
  23215. var data = Curve.prototype.toJSON.call(this);
  23216. data.v0 = this.v0.toArray();
  23217. data.v1 = this.v1.toArray();
  23218. data.v2 = this.v2.toArray();
  23219. data.v3 = this.v3.toArray();
  23220. return data;
  23221. };
  23222. CubicBezierCurve3.prototype.fromJSON = function (json) {
  23223. Curve.prototype.fromJSON.call(this, json);
  23224. this.v0.fromArray(json.v0);
  23225. this.v1.fromArray(json.v1);
  23226. this.v2.fromArray(json.v2);
  23227. this.v3.fromArray(json.v3);
  23228. return this;
  23229. };
  23230. function LineCurve(v1, v2) {
  23231. if (v1 === void 0) {
  23232. v1 = new Vector2();
  23233. }
  23234. if (v2 === void 0) {
  23235. v2 = new Vector2();
  23236. }
  23237. Curve.call(this);
  23238. this.type = 'LineCurve';
  23239. this.v1 = v1;
  23240. this.v2 = v2;
  23241. }
  23242. LineCurve.prototype = Object.create(Curve.prototype);
  23243. LineCurve.prototype.constructor = LineCurve;
  23244. LineCurve.prototype.isLineCurve = true;
  23245. LineCurve.prototype.getPoint = function (t, optionalTarget) {
  23246. if (optionalTarget === void 0) {
  23247. optionalTarget = new Vector2();
  23248. }
  23249. var point = optionalTarget;
  23250. if (t === 1) {
  23251. point.copy(this.v2);
  23252. } else {
  23253. point.copy(this.v2).sub(this.v1);
  23254. point.multiplyScalar(t).add(this.v1);
  23255. }
  23256. return point;
  23257. }; // Line curve is linear, so we can overwrite default getPointAt
  23258. LineCurve.prototype.getPointAt = function (u, optionalTarget) {
  23259. return this.getPoint(u, optionalTarget);
  23260. };
  23261. LineCurve.prototype.getTangent = function (t, optionalTarget) {
  23262. var tangent = optionalTarget || new Vector2();
  23263. tangent.copy(this.v2).sub(this.v1).normalize();
  23264. return tangent;
  23265. };
  23266. LineCurve.prototype.copy = function (source) {
  23267. Curve.prototype.copy.call(this, source);
  23268. this.v1.copy(source.v1);
  23269. this.v2.copy(source.v2);
  23270. return this;
  23271. };
  23272. LineCurve.prototype.toJSON = function () {
  23273. var data = Curve.prototype.toJSON.call(this);
  23274. data.v1 = this.v1.toArray();
  23275. data.v2 = this.v2.toArray();
  23276. return data;
  23277. };
  23278. LineCurve.prototype.fromJSON = function (json) {
  23279. Curve.prototype.fromJSON.call(this, json);
  23280. this.v1.fromArray(json.v1);
  23281. this.v2.fromArray(json.v2);
  23282. return this;
  23283. };
  23284. function LineCurve3(v1, v2) {
  23285. if (v1 === void 0) {
  23286. v1 = new Vector3();
  23287. }
  23288. if (v2 === void 0) {
  23289. v2 = new Vector3();
  23290. }
  23291. Curve.call(this);
  23292. this.type = 'LineCurve3';
  23293. this.v1 = v1;
  23294. this.v2 = v2;
  23295. }
  23296. LineCurve3.prototype = Object.create(Curve.prototype);
  23297. LineCurve3.prototype.constructor = LineCurve3;
  23298. LineCurve3.prototype.isLineCurve3 = true;
  23299. LineCurve3.prototype.getPoint = function (t, optionalTarget) {
  23300. if (optionalTarget === void 0) {
  23301. optionalTarget = new Vector3();
  23302. }
  23303. var point = optionalTarget;
  23304. if (t === 1) {
  23305. point.copy(this.v2);
  23306. } else {
  23307. point.copy(this.v2).sub(this.v1);
  23308. point.multiplyScalar(t).add(this.v1);
  23309. }
  23310. return point;
  23311. }; // Line curve is linear, so we can overwrite default getPointAt
  23312. LineCurve3.prototype.getPointAt = function (u, optionalTarget) {
  23313. return this.getPoint(u, optionalTarget);
  23314. };
  23315. LineCurve3.prototype.copy = function (source) {
  23316. Curve.prototype.copy.call(this, source);
  23317. this.v1.copy(source.v1);
  23318. this.v2.copy(source.v2);
  23319. return this;
  23320. };
  23321. LineCurve3.prototype.toJSON = function () {
  23322. var data = Curve.prototype.toJSON.call(this);
  23323. data.v1 = this.v1.toArray();
  23324. data.v2 = this.v2.toArray();
  23325. return data;
  23326. };
  23327. LineCurve3.prototype.fromJSON = function (json) {
  23328. Curve.prototype.fromJSON.call(this, json);
  23329. this.v1.fromArray(json.v1);
  23330. this.v2.fromArray(json.v2);
  23331. return this;
  23332. };
  23333. function QuadraticBezierCurve(v0, v1, v2) {
  23334. if (v0 === void 0) {
  23335. v0 = new Vector2();
  23336. }
  23337. if (v1 === void 0) {
  23338. v1 = new Vector2();
  23339. }
  23340. if (v2 === void 0) {
  23341. v2 = new Vector2();
  23342. }
  23343. Curve.call(this);
  23344. this.type = 'QuadraticBezierCurve';
  23345. this.v0 = v0;
  23346. this.v1 = v1;
  23347. this.v2 = v2;
  23348. }
  23349. QuadraticBezierCurve.prototype = Object.create(Curve.prototype);
  23350. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  23351. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  23352. QuadraticBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  23353. if (optionalTarget === void 0) {
  23354. optionalTarget = new Vector2();
  23355. }
  23356. var point = optionalTarget;
  23357. var v0 = this.v0,
  23358. v1 = this.v1,
  23359. v2 = this.v2;
  23360. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  23361. return point;
  23362. };
  23363. QuadraticBezierCurve.prototype.copy = function (source) {
  23364. Curve.prototype.copy.call(this, source);
  23365. this.v0.copy(source.v0);
  23366. this.v1.copy(source.v1);
  23367. this.v2.copy(source.v2);
  23368. return this;
  23369. };
  23370. QuadraticBezierCurve.prototype.toJSON = function () {
  23371. var data = Curve.prototype.toJSON.call(this);
  23372. data.v0 = this.v0.toArray();
  23373. data.v1 = this.v1.toArray();
  23374. data.v2 = this.v2.toArray();
  23375. return data;
  23376. };
  23377. QuadraticBezierCurve.prototype.fromJSON = function (json) {
  23378. Curve.prototype.fromJSON.call(this, json);
  23379. this.v0.fromArray(json.v0);
  23380. this.v1.fromArray(json.v1);
  23381. this.v2.fromArray(json.v2);
  23382. return this;
  23383. };
  23384. function QuadraticBezierCurve3(v0, v1, v2) {
  23385. if (v0 === void 0) {
  23386. v0 = new Vector3();
  23387. }
  23388. if (v1 === void 0) {
  23389. v1 = new Vector3();
  23390. }
  23391. if (v2 === void 0) {
  23392. v2 = new Vector3();
  23393. }
  23394. Curve.call(this);
  23395. this.type = 'QuadraticBezierCurve3';
  23396. this.v0 = v0;
  23397. this.v1 = v1;
  23398. this.v2 = v2;
  23399. }
  23400. QuadraticBezierCurve3.prototype = Object.create(Curve.prototype);
  23401. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  23402. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  23403. QuadraticBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  23404. if (optionalTarget === void 0) {
  23405. optionalTarget = new Vector3();
  23406. }
  23407. var point = optionalTarget;
  23408. var v0 = this.v0,
  23409. v1 = this.v1,
  23410. v2 = this.v2;
  23411. 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));
  23412. return point;
  23413. };
  23414. QuadraticBezierCurve3.prototype.copy = function (source) {
  23415. Curve.prototype.copy.call(this, source);
  23416. this.v0.copy(source.v0);
  23417. this.v1.copy(source.v1);
  23418. this.v2.copy(source.v2);
  23419. return this;
  23420. };
  23421. QuadraticBezierCurve3.prototype.toJSON = function () {
  23422. var data = Curve.prototype.toJSON.call(this);
  23423. data.v0 = this.v0.toArray();
  23424. data.v1 = this.v1.toArray();
  23425. data.v2 = this.v2.toArray();
  23426. return data;
  23427. };
  23428. QuadraticBezierCurve3.prototype.fromJSON = function (json) {
  23429. Curve.prototype.fromJSON.call(this, json);
  23430. this.v0.fromArray(json.v0);
  23431. this.v1.fromArray(json.v1);
  23432. this.v2.fromArray(json.v2);
  23433. return this;
  23434. };
  23435. function SplineCurve(points) {
  23436. if (points === void 0) {
  23437. points = [];
  23438. }
  23439. Curve.call(this);
  23440. this.type = 'SplineCurve';
  23441. this.points = points;
  23442. }
  23443. SplineCurve.prototype = Object.create(Curve.prototype);
  23444. SplineCurve.prototype.constructor = SplineCurve;
  23445. SplineCurve.prototype.isSplineCurve = true;
  23446. SplineCurve.prototype.getPoint = function (t, optionalTarget) {
  23447. if (optionalTarget === void 0) {
  23448. optionalTarget = new Vector2();
  23449. }
  23450. var point = optionalTarget;
  23451. var points = this.points;
  23452. var p = (points.length - 1) * t;
  23453. var intPoint = Math.floor(p);
  23454. var weight = p - intPoint;
  23455. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  23456. var p1 = points[intPoint];
  23457. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  23458. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  23459. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  23460. return point;
  23461. };
  23462. SplineCurve.prototype.copy = function (source) {
  23463. Curve.prototype.copy.call(this, source);
  23464. this.points = [];
  23465. for (var i = 0, l = source.points.length; i < l; i++) {
  23466. var point = source.points[i];
  23467. this.points.push(point.clone());
  23468. }
  23469. return this;
  23470. };
  23471. SplineCurve.prototype.toJSON = function () {
  23472. var data = Curve.prototype.toJSON.call(this);
  23473. data.points = [];
  23474. for (var i = 0, l = this.points.length; i < l; i++) {
  23475. var point = this.points[i];
  23476. data.points.push(point.toArray());
  23477. }
  23478. return data;
  23479. };
  23480. SplineCurve.prototype.fromJSON = function (json) {
  23481. Curve.prototype.fromJSON.call(this, json);
  23482. this.points = [];
  23483. for (var i = 0, l = json.points.length; i < l; i++) {
  23484. var point = json.points[i];
  23485. this.points.push(new Vector2().fromArray(point));
  23486. }
  23487. return this;
  23488. };
  23489. var Curves = /*#__PURE__*/Object.freeze({
  23490. __proto__: null,
  23491. ArcCurve: ArcCurve,
  23492. CatmullRomCurve3: CatmullRomCurve3,
  23493. CubicBezierCurve: CubicBezierCurve,
  23494. CubicBezierCurve3: CubicBezierCurve3,
  23495. EllipseCurve: EllipseCurve,
  23496. LineCurve: LineCurve,
  23497. LineCurve3: LineCurve3,
  23498. QuadraticBezierCurve: QuadraticBezierCurve,
  23499. QuadraticBezierCurve3: QuadraticBezierCurve3,
  23500. SplineCurve: SplineCurve
  23501. });
  23502. /**************************************************************
  23503. * Curved Path - a curve path is simply a array of connected
  23504. * curves, but retains the api of a curve
  23505. **************************************************************/
  23506. function CurvePath() {
  23507. Curve.call(this);
  23508. this.type = 'CurvePath';
  23509. this.curves = [];
  23510. this.autoClose = false; // Automatically closes the path
  23511. }
  23512. CurvePath.prototype = Object.assign(Object.create(Curve.prototype), {
  23513. constructor: CurvePath,
  23514. add: function add(curve) {
  23515. this.curves.push(curve);
  23516. },
  23517. closePath: function closePath() {
  23518. // Add a line curve if start and end of lines are not connected
  23519. var startPoint = this.curves[0].getPoint(0);
  23520. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  23521. if (!startPoint.equals(endPoint)) {
  23522. this.curves.push(new LineCurve(endPoint, startPoint));
  23523. }
  23524. },
  23525. // To get accurate point with reference to
  23526. // entire path distance at time t,
  23527. // following has to be done:
  23528. // 1. Length of each sub path have to be known
  23529. // 2. Locate and identify type of curve
  23530. // 3. Get t for the curve
  23531. // 4. Return curve.getPointAt(t')
  23532. getPoint: function getPoint(t) {
  23533. var d = t * this.getLength();
  23534. var curveLengths = this.getCurveLengths();
  23535. var i = 0; // To think about boundaries points.
  23536. while (i < curveLengths.length) {
  23537. if (curveLengths[i] >= d) {
  23538. var diff = curveLengths[i] - d;
  23539. var curve = this.curves[i];
  23540. var segmentLength = curve.getLength();
  23541. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  23542. return curve.getPointAt(u);
  23543. }
  23544. i++;
  23545. }
  23546. return null; // loop where sum != 0, sum > d , sum+1 <d
  23547. },
  23548. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  23549. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  23550. // getPoint() depends on getLength
  23551. getLength: function getLength() {
  23552. var lens = this.getCurveLengths();
  23553. return lens[lens.length - 1];
  23554. },
  23555. // cacheLengths must be recalculated.
  23556. updateArcLengths: function updateArcLengths() {
  23557. this.needsUpdate = true;
  23558. this.cacheLengths = null;
  23559. this.getCurveLengths();
  23560. },
  23561. // Compute lengths and cache them
  23562. // We cannot overwrite getLengths() because UtoT mapping uses it.
  23563. getCurveLengths: function getCurveLengths() {
  23564. // We use cache values if curves and cache array are same length
  23565. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  23566. return this.cacheLengths;
  23567. } // Get length of sub-curve
  23568. // Push sums into cached array
  23569. var lengths = [];
  23570. var sums = 0;
  23571. for (var i = 0, l = this.curves.length; i < l; i++) {
  23572. sums += this.curves[i].getLength();
  23573. lengths.push(sums);
  23574. }
  23575. this.cacheLengths = lengths;
  23576. return lengths;
  23577. },
  23578. getSpacedPoints: function getSpacedPoints(divisions) {
  23579. if (divisions === void 0) {
  23580. divisions = 40;
  23581. }
  23582. var points = [];
  23583. for (var i = 0; i <= divisions; i++) {
  23584. points.push(this.getPoint(i / divisions));
  23585. }
  23586. if (this.autoClose) {
  23587. points.push(points[0]);
  23588. }
  23589. return points;
  23590. },
  23591. getPoints: function getPoints(divisions) {
  23592. if (divisions === void 0) {
  23593. divisions = 12;
  23594. }
  23595. var points = [];
  23596. var last;
  23597. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  23598. var curve = curves[i];
  23599. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  23600. var pts = curve.getPoints(resolution);
  23601. for (var j = 0; j < pts.length; j++) {
  23602. var point = pts[j];
  23603. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  23604. points.push(point);
  23605. last = point;
  23606. }
  23607. }
  23608. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  23609. points.push(points[0]);
  23610. }
  23611. return points;
  23612. },
  23613. copy: function copy(source) {
  23614. Curve.prototype.copy.call(this, source);
  23615. this.curves = [];
  23616. for (var i = 0, l = source.curves.length; i < l; i++) {
  23617. var curve = source.curves[i];
  23618. this.curves.push(curve.clone());
  23619. }
  23620. this.autoClose = source.autoClose;
  23621. return this;
  23622. },
  23623. toJSON: function toJSON() {
  23624. var data = Curve.prototype.toJSON.call(this);
  23625. data.autoClose = this.autoClose;
  23626. data.curves = [];
  23627. for (var i = 0, l = this.curves.length; i < l; i++) {
  23628. var curve = this.curves[i];
  23629. data.curves.push(curve.toJSON());
  23630. }
  23631. return data;
  23632. },
  23633. fromJSON: function fromJSON(json) {
  23634. Curve.prototype.fromJSON.call(this, json);
  23635. this.autoClose = json.autoClose;
  23636. this.curves = [];
  23637. for (var i = 0, l = json.curves.length; i < l; i++) {
  23638. var curve = json.curves[i];
  23639. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  23640. }
  23641. return this;
  23642. }
  23643. });
  23644. function Path(points) {
  23645. CurvePath.call(this);
  23646. this.type = 'Path';
  23647. this.currentPoint = new Vector2();
  23648. if (points) {
  23649. this.setFromPoints(points);
  23650. }
  23651. }
  23652. Path.prototype = Object.assign(Object.create(CurvePath.prototype), {
  23653. constructor: Path,
  23654. setFromPoints: function setFromPoints(points) {
  23655. this.moveTo(points[0].x, points[0].y);
  23656. for (var i = 1, l = points.length; i < l; i++) {
  23657. this.lineTo(points[i].x, points[i].y);
  23658. }
  23659. return this;
  23660. },
  23661. moveTo: function moveTo(x, y) {
  23662. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  23663. return this;
  23664. },
  23665. lineTo: function lineTo(x, y) {
  23666. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  23667. this.curves.push(curve);
  23668. this.currentPoint.set(x, y);
  23669. return this;
  23670. },
  23671. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  23672. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  23673. this.curves.push(curve);
  23674. this.currentPoint.set(aX, aY);
  23675. return this;
  23676. },
  23677. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  23678. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  23679. this.curves.push(curve);
  23680. this.currentPoint.set(aX, aY);
  23681. return this;
  23682. },
  23683. splineThru: function splineThru(pts
  23684. /*Array of Vector*/
  23685. ) {
  23686. var npts = [this.currentPoint.clone()].concat(pts);
  23687. var curve = new SplineCurve(npts);
  23688. this.curves.push(curve);
  23689. this.currentPoint.copy(pts[pts.length - 1]);
  23690. return this;
  23691. },
  23692. arc: function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23693. var x0 = this.currentPoint.x;
  23694. var y0 = this.currentPoint.y;
  23695. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  23696. return this;
  23697. },
  23698. absarc: function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23699. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  23700. return this;
  23701. },
  23702. ellipse: function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23703. var x0 = this.currentPoint.x;
  23704. var y0 = this.currentPoint.y;
  23705. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23706. return this;
  23707. },
  23708. absellipse: function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23709. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23710. if (this.curves.length > 0) {
  23711. // if a previous curve is present, attempt to join
  23712. var firstPoint = curve.getPoint(0);
  23713. if (!firstPoint.equals(this.currentPoint)) {
  23714. this.lineTo(firstPoint.x, firstPoint.y);
  23715. }
  23716. }
  23717. this.curves.push(curve);
  23718. var lastPoint = curve.getPoint(1);
  23719. this.currentPoint.copy(lastPoint);
  23720. return this;
  23721. },
  23722. copy: function copy(source) {
  23723. CurvePath.prototype.copy.call(this, source);
  23724. this.currentPoint.copy(source.currentPoint);
  23725. return this;
  23726. },
  23727. toJSON: function toJSON() {
  23728. var data = CurvePath.prototype.toJSON.call(this);
  23729. data.currentPoint = this.currentPoint.toArray();
  23730. return data;
  23731. },
  23732. fromJSON: function fromJSON(json) {
  23733. CurvePath.prototype.fromJSON.call(this, json);
  23734. this.currentPoint.fromArray(json.currentPoint);
  23735. return this;
  23736. }
  23737. });
  23738. function Shape(points) {
  23739. Path.call(this, points);
  23740. this.uuid = MathUtils.generateUUID();
  23741. this.type = 'Shape';
  23742. this.holes = [];
  23743. }
  23744. Shape.prototype = Object.assign(Object.create(Path.prototype), {
  23745. constructor: Shape,
  23746. getPointsHoles: function getPointsHoles(divisions) {
  23747. var holesPts = [];
  23748. for (var i = 0, l = this.holes.length; i < l; i++) {
  23749. holesPts[i] = this.holes[i].getPoints(divisions);
  23750. }
  23751. return holesPts;
  23752. },
  23753. // get points of shape and holes (keypoints based on segments parameter)
  23754. extractPoints: function extractPoints(divisions) {
  23755. return {
  23756. shape: this.getPoints(divisions),
  23757. holes: this.getPointsHoles(divisions)
  23758. };
  23759. },
  23760. copy: function copy(source) {
  23761. Path.prototype.copy.call(this, source);
  23762. this.holes = [];
  23763. for (var i = 0, l = source.holes.length; i < l; i++) {
  23764. var hole = source.holes[i];
  23765. this.holes.push(hole.clone());
  23766. }
  23767. return this;
  23768. },
  23769. toJSON: function toJSON() {
  23770. var data = Path.prototype.toJSON.call(this);
  23771. data.uuid = this.uuid;
  23772. data.holes = [];
  23773. for (var i = 0, l = this.holes.length; i < l; i++) {
  23774. var hole = this.holes[i];
  23775. data.holes.push(hole.toJSON());
  23776. }
  23777. return data;
  23778. },
  23779. fromJSON: function fromJSON(json) {
  23780. Path.prototype.fromJSON.call(this, json);
  23781. this.uuid = json.uuid;
  23782. this.holes = [];
  23783. for (var i = 0, l = json.holes.length; i < l; i++) {
  23784. var hole = json.holes[i];
  23785. this.holes.push(new Path().fromJSON(hole));
  23786. }
  23787. return this;
  23788. }
  23789. });
  23790. function Light(color, intensity) {
  23791. if (intensity === void 0) {
  23792. intensity = 1;
  23793. }
  23794. Object3D.call(this);
  23795. this.type = 'Light';
  23796. this.color = new Color(color);
  23797. this.intensity = intensity;
  23798. }
  23799. Light.prototype = Object.assign(Object.create(Object3D.prototype), {
  23800. constructor: Light,
  23801. isLight: true,
  23802. copy: function copy(source) {
  23803. Object3D.prototype.copy.call(this, source);
  23804. this.color.copy(source.color);
  23805. this.intensity = source.intensity;
  23806. return this;
  23807. },
  23808. toJSON: function toJSON(meta) {
  23809. var data = Object3D.prototype.toJSON.call(this, meta);
  23810. data.object.color = this.color.getHex();
  23811. data.object.intensity = this.intensity;
  23812. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23813. if (this.distance !== undefined) data.object.distance = this.distance;
  23814. if (this.angle !== undefined) data.object.angle = this.angle;
  23815. if (this.decay !== undefined) data.object.decay = this.decay;
  23816. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23817. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23818. return data;
  23819. }
  23820. });
  23821. function HemisphereLight(skyColor, groundColor, intensity) {
  23822. Light.call(this, skyColor, intensity);
  23823. this.type = 'HemisphereLight';
  23824. this.position.copy(Object3D.DefaultUp);
  23825. this.updateMatrix();
  23826. this.groundColor = new Color(groundColor);
  23827. }
  23828. HemisphereLight.prototype = Object.assign(Object.create(Light.prototype), {
  23829. constructor: HemisphereLight,
  23830. isHemisphereLight: true,
  23831. copy: function copy(source) {
  23832. Light.prototype.copy.call(this, source);
  23833. this.groundColor.copy(source.groundColor);
  23834. return this;
  23835. }
  23836. });
  23837. function LightShadow(camera) {
  23838. this.camera = camera;
  23839. this.bias = 0;
  23840. this.normalBias = 0;
  23841. this.radius = 1;
  23842. this.mapSize = new Vector2(512, 512);
  23843. this.map = null;
  23844. this.mapPass = null;
  23845. this.matrix = new Matrix4();
  23846. this.autoUpdate = true;
  23847. this.needsUpdate = false;
  23848. this._frustum = new Frustum();
  23849. this._frameExtents = new Vector2(1, 1);
  23850. this._viewportCount = 1;
  23851. this._viewports = [new Vector4(0, 0, 1, 1)];
  23852. }
  23853. Object.assign(LightShadow.prototype, {
  23854. _projScreenMatrix: new Matrix4(),
  23855. _lightPositionWorld: new Vector3(),
  23856. _lookTarget: new Vector3(),
  23857. getViewportCount: function getViewportCount() {
  23858. return this._viewportCount;
  23859. },
  23860. getFrustum: function getFrustum() {
  23861. return this._frustum;
  23862. },
  23863. updateMatrices: function updateMatrices(light) {
  23864. var shadowCamera = this.camera,
  23865. shadowMatrix = this.matrix,
  23866. projScreenMatrix = this._projScreenMatrix,
  23867. lookTarget = this._lookTarget,
  23868. lightPositionWorld = this._lightPositionWorld;
  23869. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23870. shadowCamera.position.copy(lightPositionWorld);
  23871. lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23872. shadowCamera.lookAt(lookTarget);
  23873. shadowCamera.updateMatrixWorld();
  23874. projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23875. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23876. 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);
  23877. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23878. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23879. },
  23880. getViewport: function getViewport(viewportIndex) {
  23881. return this._viewports[viewportIndex];
  23882. },
  23883. getFrameExtents: function getFrameExtents() {
  23884. return this._frameExtents;
  23885. },
  23886. copy: function copy(source) {
  23887. this.camera = source.camera.clone();
  23888. this.bias = source.bias;
  23889. this.radius = source.radius;
  23890. this.mapSize.copy(source.mapSize);
  23891. return this;
  23892. },
  23893. clone: function clone() {
  23894. return new this.constructor().copy(this);
  23895. },
  23896. toJSON: function toJSON() {
  23897. var object = {};
  23898. if (this.bias !== 0) object.bias = this.bias;
  23899. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23900. if (this.radius !== 1) object.radius = this.radius;
  23901. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23902. object.camera = this.camera.toJSON(false).object;
  23903. delete object.camera.matrix;
  23904. return object;
  23905. }
  23906. });
  23907. function SpotLightShadow() {
  23908. LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500));
  23909. this.focus = 1;
  23910. }
  23911. SpotLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23912. constructor: SpotLightShadow,
  23913. isSpotLightShadow: true,
  23914. updateMatrices: function updateMatrices(light) {
  23915. var camera = this.camera;
  23916. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23917. var aspect = this.mapSize.width / this.mapSize.height;
  23918. var far = light.distance || camera.far;
  23919. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23920. camera.fov = fov;
  23921. camera.aspect = aspect;
  23922. camera.far = far;
  23923. camera.updateProjectionMatrix();
  23924. }
  23925. LightShadow.prototype.updateMatrices.call(this, light);
  23926. }
  23927. });
  23928. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23929. Light.call(this, color, intensity);
  23930. this.type = 'SpotLight';
  23931. this.position.copy(Object3D.DefaultUp);
  23932. this.updateMatrix();
  23933. this.target = new Object3D();
  23934. Object.defineProperty(this, 'power', {
  23935. get: function get() {
  23936. // intensity = power per solid angle.
  23937. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23938. return this.intensity * Math.PI;
  23939. },
  23940. set: function set(power) {
  23941. // intensity = power per solid angle.
  23942. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23943. this.intensity = power / Math.PI;
  23944. }
  23945. });
  23946. this.distance = distance !== undefined ? distance : 0;
  23947. this.angle = angle !== undefined ? angle : Math.PI / 3;
  23948. this.penumbra = penumbra !== undefined ? penumbra : 0;
  23949. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23950. this.shadow = new SpotLightShadow();
  23951. }
  23952. SpotLight.prototype = Object.assign(Object.create(Light.prototype), {
  23953. constructor: SpotLight,
  23954. isSpotLight: true,
  23955. copy: function copy(source) {
  23956. Light.prototype.copy.call(this, source);
  23957. this.distance = source.distance;
  23958. this.angle = source.angle;
  23959. this.penumbra = source.penumbra;
  23960. this.decay = source.decay;
  23961. this.target = source.target.clone();
  23962. this.shadow = source.shadow.clone();
  23963. return this;
  23964. }
  23965. });
  23966. function PointLightShadow() {
  23967. LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500));
  23968. this._frameExtents = new Vector2(4, 2);
  23969. this._viewportCount = 6;
  23970. this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23971. // following orientation:
  23972. //
  23973. // xzXZ
  23974. // y Y
  23975. //
  23976. // X - Positive x direction
  23977. // x - Negative x direction
  23978. // Y - Positive y direction
  23979. // y - Negative y direction
  23980. // Z - Positive z direction
  23981. // z - Negative z direction
  23982. // positive X
  23983. new Vector4(2, 1, 1, 1), // negative X
  23984. new Vector4(0, 1, 1, 1), // positive Z
  23985. new Vector4(3, 1, 1, 1), // negative Z
  23986. new Vector4(1, 1, 1, 1), // positive Y
  23987. new Vector4(3, 0, 1, 1), // negative Y
  23988. new Vector4(1, 0, 1, 1)];
  23989. 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)];
  23990. 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)];
  23991. }
  23992. PointLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23993. constructor: PointLightShadow,
  23994. isPointLightShadow: true,
  23995. updateMatrices: function updateMatrices(light, viewportIndex) {
  23996. if (viewportIndex === void 0) {
  23997. viewportIndex = 0;
  23998. }
  23999. var camera = this.camera,
  24000. shadowMatrix = this.matrix,
  24001. lightPositionWorld = this._lightPositionWorld,
  24002. lookTarget = this._lookTarget,
  24003. projScreenMatrix = this._projScreenMatrix;
  24004. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  24005. camera.position.copy(lightPositionWorld);
  24006. lookTarget.copy(camera.position);
  24007. lookTarget.add(this._cubeDirections[viewportIndex]);
  24008. camera.up.copy(this._cubeUps[viewportIndex]);
  24009. camera.lookAt(lookTarget);
  24010. camera.updateMatrixWorld();
  24011. shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
  24012. projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  24013. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  24014. }
  24015. });
  24016. function PointLight(color, intensity, distance, decay) {
  24017. Light.call(this, color, intensity);
  24018. this.type = 'PointLight';
  24019. Object.defineProperty(this, 'power', {
  24020. get: function get() {
  24021. // intensity = power per solid angle.
  24022. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  24023. return this.intensity * 4 * Math.PI;
  24024. },
  24025. set: function set(power) {
  24026. // intensity = power per solid angle.
  24027. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  24028. this.intensity = power / (4 * Math.PI);
  24029. }
  24030. });
  24031. this.distance = distance !== undefined ? distance : 0;
  24032. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  24033. this.shadow = new PointLightShadow();
  24034. }
  24035. PointLight.prototype = Object.assign(Object.create(Light.prototype), {
  24036. constructor: PointLight,
  24037. isPointLight: true,
  24038. copy: function copy(source) {
  24039. Light.prototype.copy.call(this, source);
  24040. this.distance = source.distance;
  24041. this.decay = source.decay;
  24042. this.shadow = source.shadow.clone();
  24043. return this;
  24044. }
  24045. });
  24046. function OrthographicCamera(left, right, top, bottom, near, far) {
  24047. if (left === void 0) {
  24048. left = -1;
  24049. }
  24050. if (right === void 0) {
  24051. right = 1;
  24052. }
  24053. if (top === void 0) {
  24054. top = 1;
  24055. }
  24056. if (bottom === void 0) {
  24057. bottom = -1;
  24058. }
  24059. if (near === void 0) {
  24060. near = 0.1;
  24061. }
  24062. if (far === void 0) {
  24063. far = 2000;
  24064. }
  24065. Camera.call(this);
  24066. this.type = 'OrthographicCamera';
  24067. this.zoom = 1;
  24068. this.view = null;
  24069. this.left = left;
  24070. this.right = right;
  24071. this.top = top;
  24072. this.bottom = bottom;
  24073. this.near = near;
  24074. this.far = far;
  24075. this.updateProjectionMatrix();
  24076. }
  24077. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  24078. constructor: OrthographicCamera,
  24079. isOrthographicCamera: true,
  24080. copy: function copy(source, recursive) {
  24081. Camera.prototype.copy.call(this, source, recursive);
  24082. this.left = source.left;
  24083. this.right = source.right;
  24084. this.top = source.top;
  24085. this.bottom = source.bottom;
  24086. this.near = source.near;
  24087. this.far = source.far;
  24088. this.zoom = source.zoom;
  24089. this.view = source.view === null ? null : Object.assign({}, source.view);
  24090. return this;
  24091. },
  24092. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  24093. if (this.view === null) {
  24094. this.view = {
  24095. enabled: true,
  24096. fullWidth: 1,
  24097. fullHeight: 1,
  24098. offsetX: 0,
  24099. offsetY: 0,
  24100. width: 1,
  24101. height: 1
  24102. };
  24103. }
  24104. this.view.enabled = true;
  24105. this.view.fullWidth = fullWidth;
  24106. this.view.fullHeight = fullHeight;
  24107. this.view.offsetX = x;
  24108. this.view.offsetY = y;
  24109. this.view.width = width;
  24110. this.view.height = height;
  24111. this.updateProjectionMatrix();
  24112. },
  24113. clearViewOffset: function clearViewOffset() {
  24114. if (this.view !== null) {
  24115. this.view.enabled = false;
  24116. }
  24117. this.updateProjectionMatrix();
  24118. },
  24119. updateProjectionMatrix: function updateProjectionMatrix() {
  24120. var dx = (this.right - this.left) / (2 * this.zoom);
  24121. var dy = (this.top - this.bottom) / (2 * this.zoom);
  24122. var cx = (this.right + this.left) / 2;
  24123. var cy = (this.top + this.bottom) / 2;
  24124. var left = cx - dx;
  24125. var right = cx + dx;
  24126. var top = cy + dy;
  24127. var bottom = cy - dy;
  24128. if (this.view !== null && this.view.enabled) {
  24129. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  24130. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  24131. left += scaleW * this.view.offsetX;
  24132. right = left + scaleW * this.view.width;
  24133. top -= scaleH * this.view.offsetY;
  24134. bottom = top - scaleH * this.view.height;
  24135. }
  24136. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  24137. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  24138. },
  24139. toJSON: function toJSON(meta) {
  24140. var data = Object3D.prototype.toJSON.call(this, meta);
  24141. data.object.zoom = this.zoom;
  24142. data.object.left = this.left;
  24143. data.object.right = this.right;
  24144. data.object.top = this.top;
  24145. data.object.bottom = this.bottom;
  24146. data.object.near = this.near;
  24147. data.object.far = this.far;
  24148. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  24149. return data;
  24150. }
  24151. });
  24152. function DirectionalLightShadow() {
  24153. LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
  24154. }
  24155. DirectionalLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  24156. constructor: DirectionalLightShadow,
  24157. isDirectionalLightShadow: true,
  24158. updateMatrices: function updateMatrices(light) {
  24159. LightShadow.prototype.updateMatrices.call(this, light);
  24160. }
  24161. });
  24162. function DirectionalLight(color, intensity) {
  24163. Light.call(this, color, intensity);
  24164. this.type = 'DirectionalLight';
  24165. this.position.copy(Object3D.DefaultUp);
  24166. this.updateMatrix();
  24167. this.target = new Object3D();
  24168. this.shadow = new DirectionalLightShadow();
  24169. }
  24170. DirectionalLight.prototype = Object.assign(Object.create(Light.prototype), {
  24171. constructor: DirectionalLight,
  24172. isDirectionalLight: true,
  24173. copy: function copy(source) {
  24174. Light.prototype.copy.call(this, source);
  24175. this.target = source.target.clone();
  24176. this.shadow = source.shadow.clone();
  24177. return this;
  24178. }
  24179. });
  24180. function AmbientLight(color, intensity) {
  24181. Light.call(this, color, intensity);
  24182. this.type = 'AmbientLight';
  24183. }
  24184. AmbientLight.prototype = Object.assign(Object.create(Light.prototype), {
  24185. constructor: AmbientLight,
  24186. isAmbientLight: true
  24187. });
  24188. function RectAreaLight(color, intensity, width, height) {
  24189. Light.call(this, color, intensity);
  24190. this.type = 'RectAreaLight';
  24191. this.width = width !== undefined ? width : 10;
  24192. this.height = height !== undefined ? height : 10;
  24193. }
  24194. RectAreaLight.prototype = Object.assign(Object.create(Light.prototype), {
  24195. constructor: RectAreaLight,
  24196. isRectAreaLight: true,
  24197. copy: function copy(source) {
  24198. Light.prototype.copy.call(this, source);
  24199. this.width = source.width;
  24200. this.height = source.height;
  24201. return this;
  24202. },
  24203. toJSON: function toJSON(meta) {
  24204. var data = Light.prototype.toJSON.call(this, meta);
  24205. data.object.width = this.width;
  24206. data.object.height = this.height;
  24207. return data;
  24208. }
  24209. });
  24210. /**
  24211. * Primary reference:
  24212. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24213. *
  24214. * Secondary reference:
  24215. * https://www.ppsloan.org/publications/StupidSH36.pdf
  24216. */
  24217. // 3-band SH defined by 9 coefficients
  24218. var SphericalHarmonics3 = /*#__PURE__*/function () {
  24219. function SphericalHarmonics3() {
  24220. Object.defineProperty(this, 'isSphericalHarmonics3', {
  24221. value: true
  24222. });
  24223. this.coefficients = [];
  24224. for (var i = 0; i < 9; i++) {
  24225. this.coefficients.push(new Vector3());
  24226. }
  24227. }
  24228. var _proto = SphericalHarmonics3.prototype;
  24229. _proto.set = function set(coefficients) {
  24230. for (var i = 0; i < 9; i++) {
  24231. this.coefficients[i].copy(coefficients[i]);
  24232. }
  24233. return this;
  24234. };
  24235. _proto.zero = function zero() {
  24236. for (var i = 0; i < 9; i++) {
  24237. this.coefficients[i].set(0, 0, 0);
  24238. }
  24239. return this;
  24240. } // get the radiance in the direction of the normal
  24241. // target is a Vector3
  24242. ;
  24243. _proto.getAt = function getAt(normal, target) {
  24244. // normal is assumed to be unit length
  24245. var x = normal.x,
  24246. y = normal.y,
  24247. z = normal.z;
  24248. var coeff = this.coefficients; // band 0
  24249. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  24250. target.addScaledVector(coeff[1], 0.488603 * y);
  24251. target.addScaledVector(coeff[2], 0.488603 * z);
  24252. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  24253. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  24254. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  24255. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  24256. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  24257. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  24258. return target;
  24259. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  24260. // target is a Vector3
  24261. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24262. ;
  24263. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  24264. // normal is assumed to be unit length
  24265. var x = normal.x,
  24266. y = normal.y,
  24267. z = normal.z;
  24268. var coeff = this.coefficients; // band 0
  24269. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  24270. // band 1
  24271. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  24272. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  24273. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  24274. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  24275. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  24276. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  24277. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  24278. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  24279. return target;
  24280. };
  24281. _proto.add = function add(sh) {
  24282. for (var i = 0; i < 9; i++) {
  24283. this.coefficients[i].add(sh.coefficients[i]);
  24284. }
  24285. return this;
  24286. };
  24287. _proto.addScaledSH = function addScaledSH(sh, s) {
  24288. for (var i = 0; i < 9; i++) {
  24289. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  24290. }
  24291. return this;
  24292. };
  24293. _proto.scale = function scale(s) {
  24294. for (var i = 0; i < 9; i++) {
  24295. this.coefficients[i].multiplyScalar(s);
  24296. }
  24297. return this;
  24298. };
  24299. _proto.lerp = function lerp(sh, alpha) {
  24300. for (var i = 0; i < 9; i++) {
  24301. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  24302. }
  24303. return this;
  24304. };
  24305. _proto.equals = function equals(sh) {
  24306. for (var i = 0; i < 9; i++) {
  24307. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  24308. return false;
  24309. }
  24310. }
  24311. return true;
  24312. };
  24313. _proto.copy = function copy(sh) {
  24314. return this.set(sh.coefficients);
  24315. };
  24316. _proto.clone = function clone() {
  24317. return new this.constructor().copy(this);
  24318. };
  24319. _proto.fromArray = function fromArray(array, offset) {
  24320. if (offset === void 0) {
  24321. offset = 0;
  24322. }
  24323. var coefficients = this.coefficients;
  24324. for (var i = 0; i < 9; i++) {
  24325. coefficients[i].fromArray(array, offset + i * 3);
  24326. }
  24327. return this;
  24328. };
  24329. _proto.toArray = function toArray(array, offset) {
  24330. if (array === void 0) {
  24331. array = [];
  24332. }
  24333. if (offset === void 0) {
  24334. offset = 0;
  24335. }
  24336. var coefficients = this.coefficients;
  24337. for (var i = 0; i < 9; i++) {
  24338. coefficients[i].toArray(array, offset + i * 3);
  24339. }
  24340. return array;
  24341. } // evaluate the basis functions
  24342. // shBasis is an Array[ 9 ]
  24343. ;
  24344. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  24345. // normal is assumed to be unit length
  24346. var x = normal.x,
  24347. y = normal.y,
  24348. z = normal.z; // band 0
  24349. shBasis[0] = 0.282095; // band 1
  24350. shBasis[1] = 0.488603 * y;
  24351. shBasis[2] = 0.488603 * z;
  24352. shBasis[3] = 0.488603 * x; // band 2
  24353. shBasis[4] = 1.092548 * x * y;
  24354. shBasis[5] = 1.092548 * y * z;
  24355. shBasis[6] = 0.315392 * (3 * z * z - 1);
  24356. shBasis[7] = 1.092548 * x * z;
  24357. shBasis[8] = 0.546274 * (x * x - y * y);
  24358. };
  24359. return SphericalHarmonics3;
  24360. }();
  24361. function LightProbe(sh, intensity) {
  24362. Light.call(this, undefined, intensity);
  24363. this.type = 'LightProbe';
  24364. this.sh = sh !== undefined ? sh : new SphericalHarmonics3();
  24365. }
  24366. LightProbe.prototype = Object.assign(Object.create(Light.prototype), {
  24367. constructor: LightProbe,
  24368. isLightProbe: true,
  24369. copy: function copy(source) {
  24370. Light.prototype.copy.call(this, source);
  24371. this.sh.copy(source.sh);
  24372. return this;
  24373. },
  24374. fromJSON: function fromJSON(json) {
  24375. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  24376. this.sh.fromArray(json.sh);
  24377. return this;
  24378. },
  24379. toJSON: function toJSON(meta) {
  24380. var data = Light.prototype.toJSON.call(this, meta);
  24381. data.object.sh = this.sh.toArray();
  24382. return data;
  24383. }
  24384. });
  24385. function MaterialLoader(manager) {
  24386. Loader.call(this, manager);
  24387. this.textures = {};
  24388. }
  24389. MaterialLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24390. constructor: MaterialLoader,
  24391. load: function load(url, onLoad, onProgress, onError) {
  24392. var scope = this;
  24393. var loader = new FileLoader(scope.manager);
  24394. loader.setPath(scope.path);
  24395. loader.setRequestHeader(scope.requestHeader);
  24396. loader.setWithCredentials(scope.withCredentials);
  24397. loader.load(url, function (text) {
  24398. try {
  24399. onLoad(scope.parse(JSON.parse(text)));
  24400. } catch (e) {
  24401. if (onError) {
  24402. onError(e);
  24403. } else {
  24404. console.error(e);
  24405. }
  24406. scope.manager.itemError(url);
  24407. }
  24408. }, onProgress, onError);
  24409. },
  24410. parse: function parse(json) {
  24411. var textures = this.textures;
  24412. function getTexture(name) {
  24413. if (textures[name] === undefined) {
  24414. console.warn('THREE.MaterialLoader: Undefined texture', name);
  24415. }
  24416. return textures[name];
  24417. }
  24418. var material = new Materials[json.type]();
  24419. if (json.uuid !== undefined) material.uuid = json.uuid;
  24420. if (json.name !== undefined) material.name = json.name;
  24421. if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
  24422. if (json.roughness !== undefined) material.roughness = json.roughness;
  24423. if (json.metalness !== undefined) material.metalness = json.metalness;
  24424. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  24425. if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
  24426. if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
  24427. if (json.shininess !== undefined) material.shininess = json.shininess;
  24428. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  24429. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  24430. if (json.fog !== undefined) material.fog = json.fog;
  24431. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  24432. if (json.blending !== undefined) material.blending = json.blending;
  24433. if (json.combine !== undefined) material.combine = json.combine;
  24434. if (json.side !== undefined) material.side = json.side;
  24435. if (json.opacity !== undefined) material.opacity = json.opacity;
  24436. if (json.transparent !== undefined) material.transparent = json.transparent;
  24437. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  24438. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  24439. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  24440. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  24441. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  24442. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  24443. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  24444. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  24445. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  24446. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  24447. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  24448. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  24449. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  24450. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  24451. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  24452. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  24453. if (json.rotation !== undefined) material.rotation = json.rotation;
  24454. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  24455. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  24456. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  24457. if (json.scale !== undefined) material.scale = json.scale;
  24458. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  24459. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  24460. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  24461. if (json.skinning !== undefined) material.skinning = json.skinning;
  24462. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  24463. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  24464. if (json.dithering !== undefined) material.dithering = json.dithering;
  24465. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  24466. if (json.visible !== undefined) material.visible = json.visible;
  24467. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  24468. if (json.userData !== undefined) material.userData = json.userData;
  24469. if (json.vertexColors !== undefined) {
  24470. if (typeof json.vertexColors === 'number') {
  24471. material.vertexColors = json.vertexColors > 0 ? true : false;
  24472. } else {
  24473. material.vertexColors = json.vertexColors;
  24474. }
  24475. } // Shader Material
  24476. if (json.uniforms !== undefined) {
  24477. for (var name in json.uniforms) {
  24478. var uniform = json.uniforms[name];
  24479. material.uniforms[name] = {};
  24480. switch (uniform.type) {
  24481. case 't':
  24482. material.uniforms[name].value = getTexture(uniform.value);
  24483. break;
  24484. case 'c':
  24485. material.uniforms[name].value = new Color().setHex(uniform.value);
  24486. break;
  24487. case 'v2':
  24488. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  24489. break;
  24490. case 'v3':
  24491. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  24492. break;
  24493. case 'v4':
  24494. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  24495. break;
  24496. case 'm3':
  24497. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  24498. break;
  24499. case 'm4':
  24500. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  24501. break;
  24502. default:
  24503. material.uniforms[name].value = uniform.value;
  24504. }
  24505. }
  24506. }
  24507. if (json.defines !== undefined) material.defines = json.defines;
  24508. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  24509. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  24510. if (json.extensions !== undefined) {
  24511. for (var key in json.extensions) {
  24512. material.extensions[key] = json.extensions[key];
  24513. }
  24514. } // Deprecated
  24515. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  24516. // for PointsMaterial
  24517. if (json.size !== undefined) material.size = json.size;
  24518. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  24519. if (json.map !== undefined) material.map = getTexture(json.map);
  24520. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  24521. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  24522. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  24523. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  24524. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  24525. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  24526. if (json.normalScale !== undefined) {
  24527. var normalScale = json.normalScale;
  24528. if (Array.isArray(normalScale) === false) {
  24529. // Blender exporter used to export a scalar. See #7459
  24530. normalScale = [normalScale, normalScale];
  24531. }
  24532. material.normalScale = new Vector2().fromArray(normalScale);
  24533. }
  24534. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  24535. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  24536. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  24537. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  24538. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  24539. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  24540. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  24541. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  24542. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  24543. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  24544. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  24545. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  24546. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  24547. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  24548. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  24549. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  24550. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  24551. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  24552. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  24553. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  24554. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  24555. if (json.transmission !== undefined) material.transmission = json.transmission;
  24556. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  24557. return material;
  24558. },
  24559. setTextures: function setTextures(value) {
  24560. this.textures = value;
  24561. return this;
  24562. }
  24563. });
  24564. var LoaderUtils = {
  24565. decodeText: function decodeText(array) {
  24566. if (typeof TextDecoder !== 'undefined') {
  24567. return new TextDecoder().decode(array);
  24568. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  24569. // throws a "maximum call stack size exceeded" error for large arrays.
  24570. var s = '';
  24571. for (var i = 0, il = array.length; i < il; i++) {
  24572. // Implicitly assumes little-endian.
  24573. s += String.fromCharCode(array[i]);
  24574. }
  24575. try {
  24576. // merges multi-byte utf-8 characters.
  24577. return decodeURIComponent(escape(s));
  24578. } catch (e) {
  24579. // see #16358
  24580. return s;
  24581. }
  24582. },
  24583. extractUrlBase: function extractUrlBase(url) {
  24584. var index = url.lastIndexOf('/');
  24585. if (index === -1) return './';
  24586. return url.substr(0, index + 1);
  24587. }
  24588. };
  24589. function InstancedBufferGeometry() {
  24590. BufferGeometry.call(this);
  24591. this.type = 'InstancedBufferGeometry';
  24592. this.instanceCount = Infinity;
  24593. }
  24594. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  24595. constructor: InstancedBufferGeometry,
  24596. isInstancedBufferGeometry: true,
  24597. copy: function copy(source) {
  24598. BufferGeometry.prototype.copy.call(this, source);
  24599. this.instanceCount = source.instanceCount;
  24600. return this;
  24601. },
  24602. clone: function clone() {
  24603. return new this.constructor().copy(this);
  24604. },
  24605. toJSON: function toJSON() {
  24606. var data = BufferGeometry.prototype.toJSON.call(this);
  24607. data.instanceCount = this.instanceCount;
  24608. data.isInstancedBufferGeometry = true;
  24609. return data;
  24610. }
  24611. });
  24612. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  24613. if (typeof normalized === 'number') {
  24614. meshPerAttribute = normalized;
  24615. normalized = false;
  24616. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  24617. }
  24618. BufferAttribute.call(this, array, itemSize, normalized);
  24619. this.meshPerAttribute = meshPerAttribute || 1;
  24620. }
  24621. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  24622. constructor: InstancedBufferAttribute,
  24623. isInstancedBufferAttribute: true,
  24624. copy: function copy(source) {
  24625. BufferAttribute.prototype.copy.call(this, source);
  24626. this.meshPerAttribute = source.meshPerAttribute;
  24627. return this;
  24628. },
  24629. toJSON: function toJSON() {
  24630. var data = BufferAttribute.prototype.toJSON.call(this);
  24631. data.meshPerAttribute = this.meshPerAttribute;
  24632. data.isInstancedBufferAttribute = true;
  24633. return data;
  24634. }
  24635. });
  24636. function BufferGeometryLoader(manager) {
  24637. Loader.call(this, manager);
  24638. }
  24639. BufferGeometryLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24640. constructor: BufferGeometryLoader,
  24641. load: function load(url, onLoad, onProgress, onError) {
  24642. var scope = this;
  24643. var loader = new FileLoader(scope.manager);
  24644. loader.setPath(scope.path);
  24645. loader.setRequestHeader(scope.requestHeader);
  24646. loader.setWithCredentials(scope.withCredentials);
  24647. loader.load(url, function (text) {
  24648. try {
  24649. onLoad(scope.parse(JSON.parse(text)));
  24650. } catch (e) {
  24651. if (onError) {
  24652. onError(e);
  24653. } else {
  24654. console.error(e);
  24655. }
  24656. scope.manager.itemError(url);
  24657. }
  24658. }, onProgress, onError);
  24659. },
  24660. parse: function parse(json) {
  24661. var interleavedBufferMap = {};
  24662. var arrayBufferMap = {};
  24663. function getInterleavedBuffer(json, uuid) {
  24664. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  24665. var interleavedBuffers = json.interleavedBuffers;
  24666. var interleavedBuffer = interleavedBuffers[uuid];
  24667. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  24668. var array = getTypedArray(interleavedBuffer.type, buffer);
  24669. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  24670. ib.uuid = interleavedBuffer.uuid;
  24671. interleavedBufferMap[uuid] = ib;
  24672. return ib;
  24673. }
  24674. function getArrayBuffer(json, uuid) {
  24675. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  24676. var arrayBuffers = json.arrayBuffers;
  24677. var arrayBuffer = arrayBuffers[uuid];
  24678. var ab = new Uint32Array(arrayBuffer).buffer;
  24679. arrayBufferMap[uuid] = ab;
  24680. return ab;
  24681. }
  24682. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24683. var index = json.data.index;
  24684. if (index !== undefined) {
  24685. var typedArray = getTypedArray(index.type, index.array);
  24686. geometry.setIndex(new BufferAttribute(typedArray, 1));
  24687. }
  24688. var attributes = json.data.attributes;
  24689. for (var key in attributes) {
  24690. var attribute = attributes[key];
  24691. var bufferAttribute = void 0;
  24692. if (attribute.isInterleavedBufferAttribute) {
  24693. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  24694. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  24695. } else {
  24696. var _typedArray = getTypedArray(attribute.type, attribute.array);
  24697. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24698. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  24699. }
  24700. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  24701. geometry.setAttribute(key, bufferAttribute);
  24702. }
  24703. var morphAttributes = json.data.morphAttributes;
  24704. if (morphAttributes) {
  24705. for (var _key in morphAttributes) {
  24706. var attributeArray = morphAttributes[_key];
  24707. var array = [];
  24708. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24709. var _attribute = attributeArray[i];
  24710. var _bufferAttribute = void 0;
  24711. if (_attribute.isInterleavedBufferAttribute) {
  24712. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24713. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24714. } else {
  24715. var _typedArray2 = getTypedArray(_attribute.type, _attribute.array);
  24716. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24717. }
  24718. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24719. array.push(_bufferAttribute);
  24720. }
  24721. geometry.morphAttributes[_key] = array;
  24722. }
  24723. }
  24724. var morphTargetsRelative = json.data.morphTargetsRelative;
  24725. if (morphTargetsRelative) {
  24726. geometry.morphTargetsRelative = true;
  24727. }
  24728. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24729. if (groups !== undefined) {
  24730. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24731. var group = groups[_i];
  24732. geometry.addGroup(group.start, group.count, group.materialIndex);
  24733. }
  24734. }
  24735. var boundingSphere = json.data.boundingSphere;
  24736. if (boundingSphere !== undefined) {
  24737. var center = new Vector3();
  24738. if (boundingSphere.center !== undefined) {
  24739. center.fromArray(boundingSphere.center);
  24740. }
  24741. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24742. }
  24743. if (json.name) geometry.name = json.name;
  24744. if (json.userData) geometry.userData = json.userData;
  24745. return geometry;
  24746. }
  24747. });
  24748. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24749. _inheritsLoose(ObjectLoader, _Loader);
  24750. function ObjectLoader(manager) {
  24751. return _Loader.call(this, manager) || this;
  24752. }
  24753. var _proto = ObjectLoader.prototype;
  24754. _proto.load = function load(url, onLoad, onProgress, onError) {
  24755. var scope = this;
  24756. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24757. this.resourcePath = this.resourcePath || path;
  24758. var loader = new FileLoader(this.manager);
  24759. loader.setPath(this.path);
  24760. loader.setRequestHeader(this.requestHeader);
  24761. loader.setWithCredentials(this.withCredentials);
  24762. loader.load(url, function (text) {
  24763. var json = null;
  24764. try {
  24765. json = JSON.parse(text);
  24766. } catch (error) {
  24767. if (onError !== undefined) onError(error);
  24768. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24769. return;
  24770. }
  24771. var metadata = json.metadata;
  24772. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24773. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24774. return;
  24775. }
  24776. scope.parse(json, onLoad);
  24777. }, onProgress, onError);
  24778. };
  24779. _proto.parse = function parse(json, onLoad) {
  24780. var animations = this.parseAnimations(json.animations);
  24781. var shapes = this.parseShapes(json.shapes);
  24782. var geometries = this.parseGeometries(json.geometries, shapes);
  24783. var images = this.parseImages(json.images, function () {
  24784. if (onLoad !== undefined) onLoad(object);
  24785. });
  24786. var textures = this.parseTextures(json.textures, images);
  24787. var materials = this.parseMaterials(json.materials, textures);
  24788. var object = this.parseObject(json.object, geometries, materials, animations);
  24789. var skeletons = this.parseSkeletons(json.skeletons, object);
  24790. this.bindSkeletons(object, skeletons); //
  24791. if (onLoad !== undefined) {
  24792. var hasImages = false;
  24793. for (var uuid in images) {
  24794. if (images[uuid] instanceof HTMLImageElement) {
  24795. hasImages = true;
  24796. break;
  24797. }
  24798. }
  24799. if (hasImages === false) onLoad(object);
  24800. }
  24801. return object;
  24802. };
  24803. _proto.parseShapes = function parseShapes(json) {
  24804. var shapes = {};
  24805. if (json !== undefined) {
  24806. for (var i = 0, l = json.length; i < l; i++) {
  24807. var shape = new Shape().fromJSON(json[i]);
  24808. shapes[shape.uuid] = shape;
  24809. }
  24810. }
  24811. return shapes;
  24812. };
  24813. _proto.parseSkeletons = function parseSkeletons(json, object) {
  24814. var skeletons = {};
  24815. var bones = {}; // generate bone lookup table
  24816. object.traverse(function (child) {
  24817. if (child.isBone) bones[child.uuid] = child;
  24818. }); // create skeletons
  24819. if (json !== undefined) {
  24820. for (var i = 0, l = json.length; i < l; i++) {
  24821. var skeleton = new Skeleton().fromJSON(json[i], bones);
  24822. skeletons[skeleton.uuid] = skeleton;
  24823. }
  24824. }
  24825. return skeletons;
  24826. };
  24827. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24828. var geometries = {};
  24829. var geometryShapes;
  24830. if (json !== undefined) {
  24831. var bufferGeometryLoader = new BufferGeometryLoader();
  24832. for (var i = 0, l = json.length; i < l; i++) {
  24833. var geometry = void 0;
  24834. var data = json[i];
  24835. switch (data.type) {
  24836. case 'PlaneGeometry':
  24837. case 'PlaneBufferGeometry':
  24838. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24839. break;
  24840. case 'BoxGeometry':
  24841. case 'BoxBufferGeometry':
  24842. case 'CubeGeometry':
  24843. // backwards compatible
  24844. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24845. break;
  24846. case 'CircleGeometry':
  24847. case 'CircleBufferGeometry':
  24848. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24849. break;
  24850. case 'CylinderGeometry':
  24851. case 'CylinderBufferGeometry':
  24852. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24853. break;
  24854. case 'ConeGeometry':
  24855. case 'ConeBufferGeometry':
  24856. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24857. break;
  24858. case 'SphereGeometry':
  24859. case 'SphereBufferGeometry':
  24860. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24861. break;
  24862. case 'DodecahedronGeometry':
  24863. case 'DodecahedronBufferGeometry':
  24864. case 'IcosahedronGeometry':
  24865. case 'IcosahedronBufferGeometry':
  24866. case 'OctahedronGeometry':
  24867. case 'OctahedronBufferGeometry':
  24868. case 'TetrahedronGeometry':
  24869. case 'TetrahedronBufferGeometry':
  24870. geometry = new Geometries[data.type](data.radius, data.detail);
  24871. break;
  24872. case 'RingGeometry':
  24873. case 'RingBufferGeometry':
  24874. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24875. break;
  24876. case 'TorusGeometry':
  24877. case 'TorusBufferGeometry':
  24878. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24879. break;
  24880. case 'TorusKnotGeometry':
  24881. case 'TorusKnotBufferGeometry':
  24882. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24883. break;
  24884. case 'TubeGeometry':
  24885. case 'TubeBufferGeometry':
  24886. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24887. // User defined curves or instances of CurvePath will not be deserialized.
  24888. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24889. break;
  24890. case 'LatheGeometry':
  24891. case 'LatheBufferGeometry':
  24892. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24893. break;
  24894. case 'PolyhedronGeometry':
  24895. case 'PolyhedronBufferGeometry':
  24896. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24897. break;
  24898. case 'ShapeGeometry':
  24899. case 'ShapeBufferGeometry':
  24900. geometryShapes = [];
  24901. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24902. var shape = shapes[data.shapes[j]];
  24903. geometryShapes.push(shape);
  24904. }
  24905. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24906. break;
  24907. case 'ExtrudeGeometry':
  24908. case 'ExtrudeBufferGeometry':
  24909. geometryShapes = [];
  24910. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24911. var _shape = shapes[data.shapes[_j]];
  24912. geometryShapes.push(_shape);
  24913. }
  24914. var extrudePath = data.options.extrudePath;
  24915. if (extrudePath !== undefined) {
  24916. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24917. }
  24918. geometry = new Geometries[data.type](geometryShapes, data.options);
  24919. break;
  24920. case 'BufferGeometry':
  24921. case 'InstancedBufferGeometry':
  24922. geometry = bufferGeometryLoader.parse(data);
  24923. break;
  24924. case 'Geometry':
  24925. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24926. break;
  24927. default:
  24928. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24929. continue;
  24930. }
  24931. geometry.uuid = data.uuid;
  24932. if (data.name !== undefined) geometry.name = data.name;
  24933. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24934. geometries[data.uuid] = geometry;
  24935. }
  24936. }
  24937. return geometries;
  24938. };
  24939. _proto.parseMaterials = function parseMaterials(json, textures) {
  24940. var cache = {}; // MultiMaterial
  24941. var materials = {};
  24942. if (json !== undefined) {
  24943. var loader = new MaterialLoader();
  24944. loader.setTextures(textures);
  24945. for (var i = 0, l = json.length; i < l; i++) {
  24946. var data = json[i];
  24947. if (data.type === 'MultiMaterial') {
  24948. // Deprecated
  24949. var array = [];
  24950. for (var j = 0; j < data.materials.length; j++) {
  24951. var material = data.materials[j];
  24952. if (cache[material.uuid] === undefined) {
  24953. cache[material.uuid] = loader.parse(material);
  24954. }
  24955. array.push(cache[material.uuid]);
  24956. }
  24957. materials[data.uuid] = array;
  24958. } else {
  24959. if (cache[data.uuid] === undefined) {
  24960. cache[data.uuid] = loader.parse(data);
  24961. }
  24962. materials[data.uuid] = cache[data.uuid];
  24963. }
  24964. }
  24965. }
  24966. return materials;
  24967. };
  24968. _proto.parseAnimations = function parseAnimations(json) {
  24969. var animations = {};
  24970. if (json !== undefined) {
  24971. for (var i = 0; i < json.length; i++) {
  24972. var data = json[i];
  24973. var clip = AnimationClip.parse(data);
  24974. animations[clip.uuid] = clip;
  24975. }
  24976. }
  24977. return animations;
  24978. };
  24979. _proto.parseImages = function parseImages(json, onLoad) {
  24980. var scope = this;
  24981. var images = {};
  24982. var loader;
  24983. function loadImage(url) {
  24984. scope.manager.itemStart(url);
  24985. return loader.load(url, function () {
  24986. scope.manager.itemEnd(url);
  24987. }, undefined, function () {
  24988. scope.manager.itemError(url);
  24989. scope.manager.itemEnd(url);
  24990. });
  24991. }
  24992. function deserializeImage(image) {
  24993. if (typeof image === 'string') {
  24994. var url = image;
  24995. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
  24996. return loadImage(path);
  24997. } else {
  24998. if (image.data) {
  24999. return {
  25000. data: getTypedArray(image.type, image.data),
  25001. width: image.width,
  25002. height: image.height
  25003. };
  25004. } else {
  25005. return null;
  25006. }
  25007. }
  25008. }
  25009. if (json !== undefined && json.length > 0) {
  25010. var manager = new LoadingManager(onLoad);
  25011. loader = new ImageLoader(manager);
  25012. loader.setCrossOrigin(this.crossOrigin);
  25013. for (var i = 0, il = json.length; i < il; i++) {
  25014. var image = json[i];
  25015. var url = image.url;
  25016. if (Array.isArray(url)) {
  25017. // load array of images e.g CubeTexture
  25018. images[image.uuid] = [];
  25019. for (var j = 0, jl = url.length; j < jl; j++) {
  25020. var currentUrl = url[j];
  25021. var deserializedImage = deserializeImage(currentUrl);
  25022. if (deserializedImage !== null) {
  25023. if (deserializedImage instanceof HTMLImageElement) {
  25024. images[image.uuid].push(deserializedImage);
  25025. } else {
  25026. // special case: handle array of data textures for cube textures
  25027. images[image.uuid].push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
  25028. }
  25029. }
  25030. }
  25031. } else {
  25032. // load single image
  25033. var _deserializedImage = deserializeImage(image.url);
  25034. if (_deserializedImage !== null) {
  25035. images[image.uuid] = _deserializedImage;
  25036. }
  25037. }
  25038. }
  25039. }
  25040. return images;
  25041. };
  25042. _proto.parseTextures = function parseTextures(json, images) {
  25043. function parseConstant(value, type) {
  25044. if (typeof value === 'number') return value;
  25045. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  25046. return type[value];
  25047. }
  25048. var textures = {};
  25049. if (json !== undefined) {
  25050. for (var i = 0, l = json.length; i < l; i++) {
  25051. var data = json[i];
  25052. if (data.image === undefined) {
  25053. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  25054. }
  25055. if (images[data.image] === undefined) {
  25056. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  25057. }
  25058. var texture = void 0;
  25059. var image = images[data.image];
  25060. if (Array.isArray(image)) {
  25061. texture = new CubeTexture(image);
  25062. if (image.length === 6) texture.needsUpdate = true;
  25063. } else {
  25064. if (image && image.data) {
  25065. texture = new DataTexture(image.data, image.width, image.height);
  25066. } else {
  25067. texture = new Texture(image);
  25068. }
  25069. if (image) texture.needsUpdate = true; // textures can have undefined image data
  25070. }
  25071. texture.uuid = data.uuid;
  25072. if (data.name !== undefined) texture.name = data.name;
  25073. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  25074. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  25075. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  25076. if (data.center !== undefined) texture.center.fromArray(data.center);
  25077. if (data.rotation !== undefined) texture.rotation = data.rotation;
  25078. if (data.wrap !== undefined) {
  25079. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  25080. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  25081. }
  25082. if (data.format !== undefined) texture.format = data.format;
  25083. if (data.type !== undefined) texture.type = data.type;
  25084. if (data.encoding !== undefined) texture.encoding = data.encoding;
  25085. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  25086. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  25087. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  25088. if (data.flipY !== undefined) texture.flipY = data.flipY;
  25089. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  25090. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  25091. textures[data.uuid] = texture;
  25092. }
  25093. }
  25094. return textures;
  25095. };
  25096. _proto.parseObject = function parseObject(data, geometries, materials, animations) {
  25097. var object;
  25098. function getGeometry(name) {
  25099. if (geometries[name] === undefined) {
  25100. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  25101. }
  25102. return geometries[name];
  25103. }
  25104. function getMaterial(name) {
  25105. if (name === undefined) return undefined;
  25106. if (Array.isArray(name)) {
  25107. var array = [];
  25108. for (var i = 0, l = name.length; i < l; i++) {
  25109. var uuid = name[i];
  25110. if (materials[uuid] === undefined) {
  25111. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  25112. }
  25113. array.push(materials[uuid]);
  25114. }
  25115. return array;
  25116. }
  25117. if (materials[name] === undefined) {
  25118. console.warn('THREE.ObjectLoader: Undefined material', name);
  25119. }
  25120. return materials[name];
  25121. }
  25122. var geometry, material;
  25123. switch (data.type) {
  25124. case 'Scene':
  25125. object = new Scene();
  25126. if (data.background !== undefined) {
  25127. if (Number.isInteger(data.background)) {
  25128. object.background = new Color(data.background);
  25129. }
  25130. }
  25131. if (data.fog !== undefined) {
  25132. if (data.fog.type === 'Fog') {
  25133. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  25134. } else if (data.fog.type === 'FogExp2') {
  25135. object.fog = new FogExp2(data.fog.color, data.fog.density);
  25136. }
  25137. }
  25138. break;
  25139. case 'PerspectiveCamera':
  25140. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  25141. if (data.focus !== undefined) object.focus = data.focus;
  25142. if (data.zoom !== undefined) object.zoom = data.zoom;
  25143. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  25144. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  25145. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  25146. break;
  25147. case 'OrthographicCamera':
  25148. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  25149. if (data.zoom !== undefined) object.zoom = data.zoom;
  25150. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  25151. break;
  25152. case 'AmbientLight':
  25153. object = new AmbientLight(data.color, data.intensity);
  25154. break;
  25155. case 'DirectionalLight':
  25156. object = new DirectionalLight(data.color, data.intensity);
  25157. break;
  25158. case 'PointLight':
  25159. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  25160. break;
  25161. case 'RectAreaLight':
  25162. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  25163. break;
  25164. case 'SpotLight':
  25165. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  25166. break;
  25167. case 'HemisphereLight':
  25168. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  25169. break;
  25170. case 'LightProbe':
  25171. object = new LightProbe().fromJSON(data);
  25172. break;
  25173. case 'SkinnedMesh':
  25174. geometry = getGeometry(data.geometry);
  25175. material = getMaterial(data.material);
  25176. object = new SkinnedMesh(geometry, material);
  25177. if (data.bindMode !== undefined) object.bindMode = data.bindMode;
  25178. if (data.bindMatrix !== undefined) object.bindMatrix.fromArray(data.bindMatrix);
  25179. if (data.skeleton !== undefined) object.skeleton = data.skeleton;
  25180. break;
  25181. case 'Mesh':
  25182. geometry = getGeometry(data.geometry);
  25183. material = getMaterial(data.material);
  25184. object = new Mesh(geometry, material);
  25185. break;
  25186. case 'InstancedMesh':
  25187. geometry = getGeometry(data.geometry);
  25188. material = getMaterial(data.material);
  25189. var count = data.count;
  25190. var instanceMatrix = data.instanceMatrix;
  25191. object = new InstancedMesh(geometry, material, count);
  25192. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  25193. break;
  25194. case 'LOD':
  25195. object = new LOD();
  25196. break;
  25197. case 'Line':
  25198. object = new Line(getGeometry(data.geometry), getMaterial(data.material));
  25199. break;
  25200. case 'LineLoop':
  25201. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  25202. break;
  25203. case 'LineSegments':
  25204. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  25205. break;
  25206. case 'PointCloud':
  25207. case 'Points':
  25208. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  25209. break;
  25210. case 'Sprite':
  25211. object = new Sprite(getMaterial(data.material));
  25212. break;
  25213. case 'Group':
  25214. object = new Group();
  25215. break;
  25216. case 'Bone':
  25217. object = new Bone();
  25218. break;
  25219. default:
  25220. object = new Object3D();
  25221. }
  25222. object.uuid = data.uuid;
  25223. if (data.name !== undefined) object.name = data.name;
  25224. if (data.matrix !== undefined) {
  25225. object.matrix.fromArray(data.matrix);
  25226. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  25227. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  25228. } else {
  25229. if (data.position !== undefined) object.position.fromArray(data.position);
  25230. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  25231. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  25232. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  25233. }
  25234. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  25235. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  25236. if (data.shadow) {
  25237. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  25238. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  25239. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  25240. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  25241. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  25242. }
  25243. if (data.visible !== undefined) object.visible = data.visible;
  25244. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  25245. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  25246. if (data.userData !== undefined) object.userData = data.userData;
  25247. if (data.layers !== undefined) object.layers.mask = data.layers;
  25248. if (data.children !== undefined) {
  25249. var children = data.children;
  25250. for (var i = 0; i < children.length; i++) {
  25251. object.add(this.parseObject(children[i], geometries, materials, animations));
  25252. }
  25253. }
  25254. if (data.animations !== undefined) {
  25255. var objectAnimations = data.animations;
  25256. for (var _i = 0; _i < objectAnimations.length; _i++) {
  25257. var uuid = objectAnimations[_i];
  25258. object.animations.push(animations[uuid]);
  25259. }
  25260. }
  25261. if (data.type === 'LOD') {
  25262. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  25263. var levels = data.levels;
  25264. for (var l = 0; l < levels.length; l++) {
  25265. var level = levels[l];
  25266. var child = object.getObjectByProperty('uuid', level.object);
  25267. if (child !== undefined) {
  25268. object.addLevel(child, level.distance);
  25269. }
  25270. }
  25271. }
  25272. return object;
  25273. };
  25274. _proto.bindSkeletons = function bindSkeletons(object, skeletons) {
  25275. if (Object.keys(skeletons).length === 0) return;
  25276. object.traverse(function (child) {
  25277. if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
  25278. var skeleton = skeletons[child.skeleton];
  25279. if (skeleton === undefined) {
  25280. console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton);
  25281. } else {
  25282. child.bind(skeleton, child.bindMatrix);
  25283. }
  25284. }
  25285. });
  25286. }
  25287. /* DEPRECATED */
  25288. ;
  25289. _proto.setTexturePath = function setTexturePath(value) {
  25290. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  25291. return this.setResourcePath(value);
  25292. };
  25293. return ObjectLoader;
  25294. }(Loader);
  25295. var TEXTURE_MAPPING = {
  25296. UVMapping: UVMapping,
  25297. CubeReflectionMapping: CubeReflectionMapping,
  25298. CubeRefractionMapping: CubeRefractionMapping,
  25299. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  25300. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  25301. CubeUVReflectionMapping: CubeUVReflectionMapping,
  25302. CubeUVRefractionMapping: CubeUVRefractionMapping
  25303. };
  25304. var TEXTURE_WRAPPING = {
  25305. RepeatWrapping: RepeatWrapping,
  25306. ClampToEdgeWrapping: ClampToEdgeWrapping,
  25307. MirroredRepeatWrapping: MirroredRepeatWrapping
  25308. };
  25309. var TEXTURE_FILTER = {
  25310. NearestFilter: NearestFilter,
  25311. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  25312. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  25313. LinearFilter: LinearFilter,
  25314. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  25315. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  25316. };
  25317. function ImageBitmapLoader(manager) {
  25318. if (typeof createImageBitmap === 'undefined') {
  25319. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  25320. }
  25321. if (typeof fetch === 'undefined') {
  25322. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  25323. }
  25324. Loader.call(this, manager);
  25325. this.options = {
  25326. premultiplyAlpha: 'none'
  25327. };
  25328. }
  25329. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25330. constructor: ImageBitmapLoader,
  25331. isImageBitmapLoader: true,
  25332. setOptions: function setOptions(options) {
  25333. this.options = options;
  25334. return this;
  25335. },
  25336. load: function load(url, onLoad, onProgress, onError) {
  25337. if (url === undefined) url = '';
  25338. if (this.path !== undefined) url = this.path + url;
  25339. url = this.manager.resolveURL(url);
  25340. var scope = this;
  25341. var cached = Cache.get(url);
  25342. if (cached !== undefined) {
  25343. scope.manager.itemStart(url);
  25344. setTimeout(function () {
  25345. if (onLoad) onLoad(cached);
  25346. scope.manager.itemEnd(url);
  25347. }, 0);
  25348. return cached;
  25349. }
  25350. var fetchOptions = {};
  25351. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  25352. fetch(url, fetchOptions).then(function (res) {
  25353. return res.blob();
  25354. }).then(function (blob) {
  25355. return createImageBitmap(blob, scope.options);
  25356. }).then(function (imageBitmap) {
  25357. Cache.add(url, imageBitmap);
  25358. if (onLoad) onLoad(imageBitmap);
  25359. scope.manager.itemEnd(url);
  25360. }).catch(function (e) {
  25361. if (onError) onError(e);
  25362. scope.manager.itemError(url);
  25363. scope.manager.itemEnd(url);
  25364. });
  25365. scope.manager.itemStart(url);
  25366. }
  25367. });
  25368. function ShapePath() {
  25369. this.type = 'ShapePath';
  25370. this.color = new Color();
  25371. this.subPaths = [];
  25372. this.currentPath = null;
  25373. }
  25374. Object.assign(ShapePath.prototype, {
  25375. moveTo: function moveTo(x, y) {
  25376. this.currentPath = new Path();
  25377. this.subPaths.push(this.currentPath);
  25378. this.currentPath.moveTo(x, y);
  25379. return this;
  25380. },
  25381. lineTo: function lineTo(x, y) {
  25382. this.currentPath.lineTo(x, y);
  25383. return this;
  25384. },
  25385. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  25386. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  25387. return this;
  25388. },
  25389. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  25390. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  25391. return this;
  25392. },
  25393. splineThru: function splineThru(pts) {
  25394. this.currentPath.splineThru(pts);
  25395. return this;
  25396. },
  25397. toShapes: function toShapes(isCCW, noHoles) {
  25398. function toShapesNoHoles(inSubpaths) {
  25399. var shapes = [];
  25400. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  25401. var _tmpPath = inSubpaths[i];
  25402. var _tmpShape = new Shape();
  25403. _tmpShape.curves = _tmpPath.curves;
  25404. shapes.push(_tmpShape);
  25405. }
  25406. return shapes;
  25407. }
  25408. function isPointInsidePolygon(inPt, inPolygon) {
  25409. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  25410. // toggling of inside/outside at every single! intersection point of an edge
  25411. // with the horizontal line through inPt, left of inPt
  25412. // not counting lowerY endpoints of edges and whole edges on that line
  25413. var inside = false;
  25414. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  25415. var edgeLowPt = inPolygon[p];
  25416. var edgeHighPt = inPolygon[q];
  25417. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  25418. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  25419. if (Math.abs(edgeDy) > Number.EPSILON) {
  25420. // not parallel
  25421. if (edgeDy < 0) {
  25422. edgeLowPt = inPolygon[q];
  25423. edgeDx = -edgeDx;
  25424. edgeHighPt = inPolygon[p];
  25425. edgeDy = -edgeDy;
  25426. }
  25427. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  25428. if (inPt.y === edgeLowPt.y) {
  25429. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  25430. // continue; // no intersection or edgeLowPt => doesn't count !!!
  25431. } else {
  25432. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  25433. if (perpEdge === 0) return true; // inPt is on contour ?
  25434. if (perpEdge < 0) continue;
  25435. inside = !inside; // true intersection left of inPt
  25436. }
  25437. } else {
  25438. // parallel or collinear
  25439. if (inPt.y !== edgeLowPt.y) continue; // parallel
  25440. // edge lies on the same horizontal line as inPt
  25441. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  25442. // continue;
  25443. }
  25444. }
  25445. return inside;
  25446. }
  25447. var isClockWise = ShapeUtils.isClockWise;
  25448. var subPaths = this.subPaths;
  25449. if (subPaths.length === 0) return [];
  25450. if (noHoles === true) return toShapesNoHoles(subPaths);
  25451. var solid, tmpPath, tmpShape;
  25452. var shapes = [];
  25453. if (subPaths.length === 1) {
  25454. tmpPath = subPaths[0];
  25455. tmpShape = new Shape();
  25456. tmpShape.curves = tmpPath.curves;
  25457. shapes.push(tmpShape);
  25458. return shapes;
  25459. }
  25460. var holesFirst = !isClockWise(subPaths[0].getPoints());
  25461. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  25462. var betterShapeHoles = [];
  25463. var newShapes = [];
  25464. var newShapeHoles = [];
  25465. var mainIdx = 0;
  25466. var tmpPoints;
  25467. newShapes[mainIdx] = undefined;
  25468. newShapeHoles[mainIdx] = [];
  25469. for (var i = 0, l = subPaths.length; i < l; i++) {
  25470. tmpPath = subPaths[i];
  25471. tmpPoints = tmpPath.getPoints();
  25472. solid = isClockWise(tmpPoints);
  25473. solid = isCCW ? !solid : solid;
  25474. if (solid) {
  25475. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  25476. newShapes[mainIdx] = {
  25477. s: new Shape(),
  25478. p: tmpPoints
  25479. };
  25480. newShapes[mainIdx].s.curves = tmpPath.curves;
  25481. if (holesFirst) mainIdx++;
  25482. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  25483. } else {
  25484. newShapeHoles[mainIdx].push({
  25485. h: tmpPath,
  25486. p: tmpPoints[0]
  25487. }); //console.log('ccw', i);
  25488. }
  25489. } // only Holes? -> probably all Shapes with wrong orientation
  25490. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  25491. if (newShapes.length > 1) {
  25492. var ambiguous = false;
  25493. var toChange = [];
  25494. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  25495. betterShapeHoles[sIdx] = [];
  25496. }
  25497. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  25498. var sho = newShapeHoles[_sIdx];
  25499. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  25500. var ho = sho[hIdx];
  25501. var hole_unassigned = true;
  25502. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  25503. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  25504. if (_sIdx !== s2Idx) toChange.push({
  25505. froms: _sIdx,
  25506. tos: s2Idx,
  25507. hole: hIdx
  25508. });
  25509. if (hole_unassigned) {
  25510. hole_unassigned = false;
  25511. betterShapeHoles[s2Idx].push(ho);
  25512. } else {
  25513. ambiguous = true;
  25514. }
  25515. }
  25516. }
  25517. if (hole_unassigned) {
  25518. betterShapeHoles[_sIdx].push(ho);
  25519. }
  25520. }
  25521. } // console.log("ambiguous: ", ambiguous);
  25522. if (toChange.length > 0) {
  25523. // console.log("to change: ", toChange);
  25524. if (!ambiguous) newShapeHoles = betterShapeHoles;
  25525. }
  25526. }
  25527. var tmpHoles;
  25528. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  25529. tmpShape = newShapes[_i].s;
  25530. shapes.push(tmpShape);
  25531. tmpHoles = newShapeHoles[_i];
  25532. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  25533. tmpShape.holes.push(tmpHoles[j].h);
  25534. }
  25535. } //console.log("shape", shapes);
  25536. return shapes;
  25537. }
  25538. });
  25539. function Font(data) {
  25540. this.type = 'Font';
  25541. this.data = data;
  25542. }
  25543. Object.assign(Font.prototype, {
  25544. isFont: true,
  25545. generateShapes: function generateShapes(text, size) {
  25546. if (size === void 0) {
  25547. size = 100;
  25548. }
  25549. var shapes = [];
  25550. var paths = createPaths(text, size, this.data);
  25551. for (var p = 0, pl = paths.length; p < pl; p++) {
  25552. Array.prototype.push.apply(shapes, paths[p].toShapes());
  25553. }
  25554. return shapes;
  25555. }
  25556. });
  25557. function createPaths(text, size, data) {
  25558. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  25559. var scale = size / data.resolution;
  25560. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  25561. var paths = [];
  25562. var offsetX = 0,
  25563. offsetY = 0;
  25564. for (var i = 0; i < chars.length; i++) {
  25565. var char = chars[i];
  25566. if (char === '\n') {
  25567. offsetX = 0;
  25568. offsetY -= line_height;
  25569. } else {
  25570. var ret = createPath(char, scale, offsetX, offsetY, data);
  25571. offsetX += ret.offsetX;
  25572. paths.push(ret.path);
  25573. }
  25574. }
  25575. return paths;
  25576. }
  25577. function createPath(char, scale, offsetX, offsetY, data) {
  25578. var glyph = data.glyphs[char] || data.glyphs['?'];
  25579. if (!glyph) {
  25580. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  25581. return;
  25582. }
  25583. var path = new ShapePath();
  25584. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  25585. if (glyph.o) {
  25586. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  25587. for (var i = 0, l = outline.length; i < l;) {
  25588. var action = outline[i++];
  25589. switch (action) {
  25590. case 'm':
  25591. // moveTo
  25592. x = outline[i++] * scale + offsetX;
  25593. y = outline[i++] * scale + offsetY;
  25594. path.moveTo(x, y);
  25595. break;
  25596. case 'l':
  25597. // lineTo
  25598. x = outline[i++] * scale + offsetX;
  25599. y = outline[i++] * scale + offsetY;
  25600. path.lineTo(x, y);
  25601. break;
  25602. case 'q':
  25603. // quadraticCurveTo
  25604. cpx = outline[i++] * scale + offsetX;
  25605. cpy = outline[i++] * scale + offsetY;
  25606. cpx1 = outline[i++] * scale + offsetX;
  25607. cpy1 = outline[i++] * scale + offsetY;
  25608. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  25609. break;
  25610. case 'b':
  25611. // bezierCurveTo
  25612. cpx = outline[i++] * scale + offsetX;
  25613. cpy = outline[i++] * scale + offsetY;
  25614. cpx1 = outline[i++] * scale + offsetX;
  25615. cpy1 = outline[i++] * scale + offsetY;
  25616. cpx2 = outline[i++] * scale + offsetX;
  25617. cpy2 = outline[i++] * scale + offsetY;
  25618. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  25619. break;
  25620. }
  25621. }
  25622. }
  25623. return {
  25624. offsetX: glyph.ha * scale,
  25625. path: path
  25626. };
  25627. }
  25628. function FontLoader(manager) {
  25629. Loader.call(this, manager);
  25630. }
  25631. FontLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25632. constructor: FontLoader,
  25633. load: function load(url, onLoad, onProgress, onError) {
  25634. var scope = this;
  25635. var loader = new FileLoader(this.manager);
  25636. loader.setPath(this.path);
  25637. loader.setRequestHeader(this.requestHeader);
  25638. loader.setWithCredentials(scope.withCredentials);
  25639. loader.load(url, function (text) {
  25640. var json;
  25641. try {
  25642. json = JSON.parse(text);
  25643. } catch (e) {
  25644. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  25645. json = JSON.parse(text.substring(65, text.length - 2));
  25646. }
  25647. var font = scope.parse(json);
  25648. if (onLoad) onLoad(font);
  25649. }, onProgress, onError);
  25650. },
  25651. parse: function parse(json) {
  25652. return new Font(json);
  25653. }
  25654. });
  25655. var _context;
  25656. var AudioContext = {
  25657. getContext: function getContext() {
  25658. if (_context === undefined) {
  25659. _context = new (window.AudioContext || window.webkitAudioContext)();
  25660. }
  25661. return _context;
  25662. },
  25663. setContext: function setContext(value) {
  25664. _context = value;
  25665. }
  25666. };
  25667. function AudioLoader(manager) {
  25668. Loader.call(this, manager);
  25669. }
  25670. AudioLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25671. constructor: AudioLoader,
  25672. load: function load(url, onLoad, onProgress, onError) {
  25673. var scope = this;
  25674. var loader = new FileLoader(scope.manager);
  25675. loader.setResponseType('arraybuffer');
  25676. loader.setPath(scope.path);
  25677. loader.setRequestHeader(scope.requestHeader);
  25678. loader.setWithCredentials(scope.withCredentials);
  25679. loader.load(url, function (buffer) {
  25680. try {
  25681. // Create a copy of the buffer. The `decodeAudioData` method
  25682. // detaches the buffer when complete, preventing reuse.
  25683. var bufferCopy = buffer.slice(0);
  25684. var context = AudioContext.getContext();
  25685. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  25686. onLoad(audioBuffer);
  25687. });
  25688. } catch (e) {
  25689. if (onError) {
  25690. onError(e);
  25691. } else {
  25692. console.error(e);
  25693. }
  25694. scope.manager.itemError(url);
  25695. }
  25696. }, onProgress, onError);
  25697. }
  25698. });
  25699. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  25700. LightProbe.call(this, undefined, intensity);
  25701. var color1 = new Color().set(skyColor);
  25702. var color2 = new Color().set(groundColor);
  25703. var sky = new Vector3(color1.r, color1.g, color1.b);
  25704. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25705. var c0 = Math.sqrt(Math.PI);
  25706. var c1 = c0 * Math.sqrt(0.75);
  25707. this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  25708. this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  25709. }
  25710. HemisphereLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25711. constructor: HemisphereLightProbe,
  25712. isHemisphereLightProbe: true,
  25713. copy: function copy(source) {
  25714. // modifying colors not currently supported
  25715. LightProbe.prototype.copy.call(this, source);
  25716. return this;
  25717. },
  25718. toJSON: function toJSON(meta) {
  25719. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25720. return data;
  25721. }
  25722. });
  25723. function AmbientLightProbe(color, intensity) {
  25724. LightProbe.call(this, undefined, intensity);
  25725. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25726. this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  25727. }
  25728. AmbientLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25729. constructor: AmbientLightProbe,
  25730. isAmbientLightProbe: true,
  25731. copy: function copy(source) {
  25732. // modifying color not currently supported
  25733. LightProbe.prototype.copy.call(this, source);
  25734. return this;
  25735. },
  25736. toJSON: function toJSON(meta) {
  25737. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25738. return data;
  25739. }
  25740. });
  25741. var _eyeRight = new Matrix4();
  25742. var _eyeLeft = new Matrix4();
  25743. function StereoCamera() {
  25744. this.type = 'StereoCamera';
  25745. this.aspect = 1;
  25746. this.eyeSep = 0.064;
  25747. this.cameraL = new PerspectiveCamera();
  25748. this.cameraL.layers.enable(1);
  25749. this.cameraL.matrixAutoUpdate = false;
  25750. this.cameraR = new PerspectiveCamera();
  25751. this.cameraR.layers.enable(2);
  25752. this.cameraR.matrixAutoUpdate = false;
  25753. this._cache = {
  25754. focus: null,
  25755. fov: null,
  25756. aspect: null,
  25757. near: null,
  25758. far: null,
  25759. zoom: null,
  25760. eyeSep: null
  25761. };
  25762. }
  25763. Object.assign(StereoCamera.prototype, {
  25764. update: function update(camera) {
  25765. var cache = this._cache;
  25766. 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;
  25767. if (needsUpdate) {
  25768. cache.focus = camera.focus;
  25769. cache.fov = camera.fov;
  25770. cache.aspect = camera.aspect * this.aspect;
  25771. cache.near = camera.near;
  25772. cache.far = camera.far;
  25773. cache.zoom = camera.zoom;
  25774. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25775. // http://paulbourke.net/stereographics/stereorender/
  25776. var projectionMatrix = camera.projectionMatrix.clone();
  25777. var eyeSepHalf = cache.eyeSep / 2;
  25778. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25779. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25780. var xmin, xmax; // translate xOffset
  25781. _eyeLeft.elements[12] = -eyeSepHalf;
  25782. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25783. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25784. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25785. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25786. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25787. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25788. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25789. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25790. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25791. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25792. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25793. }
  25794. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25795. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25796. }
  25797. });
  25798. var Clock = /*#__PURE__*/function () {
  25799. function Clock(autoStart) {
  25800. this.autoStart = autoStart !== undefined ? autoStart : true;
  25801. this.startTime = 0;
  25802. this.oldTime = 0;
  25803. this.elapsedTime = 0;
  25804. this.running = false;
  25805. }
  25806. var _proto = Clock.prototype;
  25807. _proto.start = function start() {
  25808. this.startTime = now();
  25809. this.oldTime = this.startTime;
  25810. this.elapsedTime = 0;
  25811. this.running = true;
  25812. };
  25813. _proto.stop = function stop() {
  25814. this.getElapsedTime();
  25815. this.running = false;
  25816. this.autoStart = false;
  25817. };
  25818. _proto.getElapsedTime = function getElapsedTime() {
  25819. this.getDelta();
  25820. return this.elapsedTime;
  25821. };
  25822. _proto.getDelta = function getDelta() {
  25823. var diff = 0;
  25824. if (this.autoStart && !this.running) {
  25825. this.start();
  25826. return 0;
  25827. }
  25828. if (this.running) {
  25829. var newTime = now();
  25830. diff = (newTime - this.oldTime) / 1000;
  25831. this.oldTime = newTime;
  25832. this.elapsedTime += diff;
  25833. }
  25834. return diff;
  25835. };
  25836. return Clock;
  25837. }();
  25838. function now() {
  25839. return (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25840. }
  25841. var _position$2 = /*@__PURE__*/new Vector3();
  25842. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25843. var _scale$1 = /*@__PURE__*/new Vector3();
  25844. var _orientation = /*@__PURE__*/new Vector3();
  25845. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25846. _inheritsLoose(AudioListener, _Object3D);
  25847. function AudioListener() {
  25848. var _this;
  25849. _this = _Object3D.call(this) || this;
  25850. _this.type = 'AudioListener';
  25851. _this.context = AudioContext.getContext();
  25852. _this.gain = _this.context.createGain();
  25853. _this.gain.connect(_this.context.destination);
  25854. _this.filter = null;
  25855. _this.timeDelta = 0; // private
  25856. _this._clock = new Clock();
  25857. return _this;
  25858. }
  25859. var _proto = AudioListener.prototype;
  25860. _proto.getInput = function getInput() {
  25861. return this.gain;
  25862. };
  25863. _proto.removeFilter = function removeFilter() {
  25864. if (this.filter !== null) {
  25865. this.gain.disconnect(this.filter);
  25866. this.filter.disconnect(this.context.destination);
  25867. this.gain.connect(this.context.destination);
  25868. this.filter = null;
  25869. }
  25870. return this;
  25871. };
  25872. _proto.getFilter = function getFilter() {
  25873. return this.filter;
  25874. };
  25875. _proto.setFilter = function setFilter(value) {
  25876. if (this.filter !== null) {
  25877. this.gain.disconnect(this.filter);
  25878. this.filter.disconnect(this.context.destination);
  25879. } else {
  25880. this.gain.disconnect(this.context.destination);
  25881. }
  25882. this.filter = value;
  25883. this.gain.connect(this.filter);
  25884. this.filter.connect(this.context.destination);
  25885. return this;
  25886. };
  25887. _proto.getMasterVolume = function getMasterVolume() {
  25888. return this.gain.gain.value;
  25889. };
  25890. _proto.setMasterVolume = function setMasterVolume(value) {
  25891. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25892. return this;
  25893. };
  25894. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25895. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25896. var listener = this.context.listener;
  25897. var up = this.up;
  25898. this.timeDelta = this._clock.getDelta();
  25899. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25900. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25901. if (listener.positionX) {
  25902. // code path for Chrome (see #14393)
  25903. var endTime = this.context.currentTime + this.timeDelta;
  25904. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25905. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25906. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25907. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25908. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25909. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25910. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25911. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25912. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25913. } else {
  25914. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25915. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25916. }
  25917. };
  25918. return AudioListener;
  25919. }(Object3D);
  25920. var Audio = /*#__PURE__*/function (_Object3D) {
  25921. _inheritsLoose(Audio, _Object3D);
  25922. function Audio(listener) {
  25923. var _this;
  25924. _this = _Object3D.call(this) || this;
  25925. _this.type = 'Audio';
  25926. _this.listener = listener;
  25927. _this.context = listener.context;
  25928. _this.gain = _this.context.createGain();
  25929. _this.gain.connect(listener.getInput());
  25930. _this.autoplay = false;
  25931. _this.buffer = null;
  25932. _this.detune = 0;
  25933. _this.loop = false;
  25934. _this.loopStart = 0;
  25935. _this.loopEnd = 0;
  25936. _this.offset = 0;
  25937. _this.duration = undefined;
  25938. _this.playbackRate = 1;
  25939. _this.isPlaying = false;
  25940. _this.hasPlaybackControl = true;
  25941. _this.source = null;
  25942. _this.sourceType = 'empty';
  25943. _this._startedAt = 0;
  25944. _this._progress = 0;
  25945. _this._connected = false;
  25946. _this.filters = [];
  25947. return _this;
  25948. }
  25949. var _proto = Audio.prototype;
  25950. _proto.getOutput = function getOutput() {
  25951. return this.gain;
  25952. };
  25953. _proto.setNodeSource = function setNodeSource(audioNode) {
  25954. this.hasPlaybackControl = false;
  25955. this.sourceType = 'audioNode';
  25956. this.source = audioNode;
  25957. this.connect();
  25958. return this;
  25959. };
  25960. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25961. this.hasPlaybackControl = false;
  25962. this.sourceType = 'mediaNode';
  25963. this.source = this.context.createMediaElementSource(mediaElement);
  25964. this.connect();
  25965. return this;
  25966. };
  25967. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25968. this.hasPlaybackControl = false;
  25969. this.sourceType = 'mediaStreamNode';
  25970. this.source = this.context.createMediaStreamSource(mediaStream);
  25971. this.connect();
  25972. return this;
  25973. };
  25974. _proto.setBuffer = function setBuffer(audioBuffer) {
  25975. this.buffer = audioBuffer;
  25976. this.sourceType = 'buffer';
  25977. if (this.autoplay) this.play();
  25978. return this;
  25979. };
  25980. _proto.play = function play(delay) {
  25981. if (delay === void 0) {
  25982. delay = 0;
  25983. }
  25984. if (this.isPlaying === true) {
  25985. console.warn('THREE.Audio: Audio is already playing.');
  25986. return;
  25987. }
  25988. if (this.hasPlaybackControl === false) {
  25989. console.warn('THREE.Audio: this Audio has no playback control.');
  25990. return;
  25991. }
  25992. this._startedAt = this.context.currentTime + delay;
  25993. var source = this.context.createBufferSource();
  25994. source.buffer = this.buffer;
  25995. source.loop = this.loop;
  25996. source.loopStart = this.loopStart;
  25997. source.loopEnd = this.loopEnd;
  25998. source.onended = this.onEnded.bind(this);
  25999. source.start(this._startedAt, this._progress + this.offset, this.duration);
  26000. this.isPlaying = true;
  26001. this.source = source;
  26002. this.setDetune(this.detune);
  26003. this.setPlaybackRate(this.playbackRate);
  26004. return this.connect();
  26005. };
  26006. _proto.pause = function pause() {
  26007. if (this.hasPlaybackControl === false) {
  26008. console.warn('THREE.Audio: this Audio has no playback control.');
  26009. return;
  26010. }
  26011. if (this.isPlaying === true) {
  26012. // update current progress
  26013. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  26014. if (this.loop === true) {
  26015. // ensure _progress does not exceed duration with looped audios
  26016. this._progress = this._progress % (this.duration || this.buffer.duration);
  26017. }
  26018. this.source.stop();
  26019. this.source.onended = null;
  26020. this.isPlaying = false;
  26021. }
  26022. return this;
  26023. };
  26024. _proto.stop = function stop() {
  26025. if (this.hasPlaybackControl === false) {
  26026. console.warn('THREE.Audio: this Audio has no playback control.');
  26027. return;
  26028. }
  26029. this._progress = 0;
  26030. this.source.stop();
  26031. this.source.onended = null;
  26032. this.isPlaying = false;
  26033. return this;
  26034. };
  26035. _proto.connect = function connect() {
  26036. if (this.filters.length > 0) {
  26037. this.source.connect(this.filters[0]);
  26038. for (var i = 1, l = this.filters.length; i < l; i++) {
  26039. this.filters[i - 1].connect(this.filters[i]);
  26040. }
  26041. this.filters[this.filters.length - 1].connect(this.getOutput());
  26042. } else {
  26043. this.source.connect(this.getOutput());
  26044. }
  26045. this._connected = true;
  26046. return this;
  26047. };
  26048. _proto.disconnect = function disconnect() {
  26049. if (this.filters.length > 0) {
  26050. this.source.disconnect(this.filters[0]);
  26051. for (var i = 1, l = this.filters.length; i < l; i++) {
  26052. this.filters[i - 1].disconnect(this.filters[i]);
  26053. }
  26054. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  26055. } else {
  26056. this.source.disconnect(this.getOutput());
  26057. }
  26058. this._connected = false;
  26059. return this;
  26060. };
  26061. _proto.getFilters = function getFilters() {
  26062. return this.filters;
  26063. };
  26064. _proto.setFilters = function setFilters(value) {
  26065. if (!value) value = [];
  26066. if (this._connected === true) {
  26067. this.disconnect();
  26068. this.filters = value.slice();
  26069. this.connect();
  26070. } else {
  26071. this.filters = value.slice();
  26072. }
  26073. return this;
  26074. };
  26075. _proto.setDetune = function setDetune(value) {
  26076. this.detune = value;
  26077. if (this.source.detune === undefined) return; // only set detune when available
  26078. if (this.isPlaying === true) {
  26079. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  26080. }
  26081. return this;
  26082. };
  26083. _proto.getDetune = function getDetune() {
  26084. return this.detune;
  26085. };
  26086. _proto.getFilter = function getFilter() {
  26087. return this.getFilters()[0];
  26088. };
  26089. _proto.setFilter = function setFilter(filter) {
  26090. return this.setFilters(filter ? [filter] : []);
  26091. };
  26092. _proto.setPlaybackRate = function setPlaybackRate(value) {
  26093. if (this.hasPlaybackControl === false) {
  26094. console.warn('THREE.Audio: this Audio has no playback control.');
  26095. return;
  26096. }
  26097. this.playbackRate = value;
  26098. if (this.isPlaying === true) {
  26099. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  26100. }
  26101. return this;
  26102. };
  26103. _proto.getPlaybackRate = function getPlaybackRate() {
  26104. return this.playbackRate;
  26105. };
  26106. _proto.onEnded = function onEnded() {
  26107. this.isPlaying = false;
  26108. };
  26109. _proto.getLoop = function getLoop() {
  26110. if (this.hasPlaybackControl === false) {
  26111. console.warn('THREE.Audio: this Audio has no playback control.');
  26112. return false;
  26113. }
  26114. return this.loop;
  26115. };
  26116. _proto.setLoop = function setLoop(value) {
  26117. if (this.hasPlaybackControl === false) {
  26118. console.warn('THREE.Audio: this Audio has no playback control.');
  26119. return;
  26120. }
  26121. this.loop = value;
  26122. if (this.isPlaying === true) {
  26123. this.source.loop = this.loop;
  26124. }
  26125. return this;
  26126. };
  26127. _proto.setLoopStart = function setLoopStart(value) {
  26128. this.loopStart = value;
  26129. return this;
  26130. };
  26131. _proto.setLoopEnd = function setLoopEnd(value) {
  26132. this.loopEnd = value;
  26133. return this;
  26134. };
  26135. _proto.getVolume = function getVolume() {
  26136. return this.gain.gain.value;
  26137. };
  26138. _proto.setVolume = function setVolume(value) {
  26139. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  26140. return this;
  26141. };
  26142. return Audio;
  26143. }(Object3D);
  26144. var _position$3 = /*@__PURE__*/new Vector3();
  26145. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  26146. var _scale$2 = /*@__PURE__*/new Vector3();
  26147. var _orientation$1 = /*@__PURE__*/new Vector3();
  26148. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  26149. _inheritsLoose(PositionalAudio, _Audio);
  26150. function PositionalAudio(listener) {
  26151. var _this;
  26152. _this = _Audio.call(this, listener) || this;
  26153. _this.panner = _this.context.createPanner();
  26154. _this.panner.panningModel = 'HRTF';
  26155. _this.panner.connect(_this.gain);
  26156. return _this;
  26157. }
  26158. var _proto = PositionalAudio.prototype;
  26159. _proto.getOutput = function getOutput() {
  26160. return this.panner;
  26161. };
  26162. _proto.getRefDistance = function getRefDistance() {
  26163. return this.panner.refDistance;
  26164. };
  26165. _proto.setRefDistance = function setRefDistance(value) {
  26166. this.panner.refDistance = value;
  26167. return this;
  26168. };
  26169. _proto.getRolloffFactor = function getRolloffFactor() {
  26170. return this.panner.rolloffFactor;
  26171. };
  26172. _proto.setRolloffFactor = function setRolloffFactor(value) {
  26173. this.panner.rolloffFactor = value;
  26174. return this;
  26175. };
  26176. _proto.getDistanceModel = function getDistanceModel() {
  26177. return this.panner.distanceModel;
  26178. };
  26179. _proto.setDistanceModel = function setDistanceModel(value) {
  26180. this.panner.distanceModel = value;
  26181. return this;
  26182. };
  26183. _proto.getMaxDistance = function getMaxDistance() {
  26184. return this.panner.maxDistance;
  26185. };
  26186. _proto.setMaxDistance = function setMaxDistance(value) {
  26187. this.panner.maxDistance = value;
  26188. return this;
  26189. };
  26190. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  26191. this.panner.coneInnerAngle = coneInnerAngle;
  26192. this.panner.coneOuterAngle = coneOuterAngle;
  26193. this.panner.coneOuterGain = coneOuterGain;
  26194. return this;
  26195. };
  26196. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  26197. _Audio.prototype.updateMatrixWorld.call(this, force);
  26198. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  26199. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  26200. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  26201. var panner = this.panner;
  26202. if (panner.positionX) {
  26203. // code path for Chrome and Firefox (see #14393)
  26204. var endTime = this.context.currentTime + this.listener.timeDelta;
  26205. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  26206. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  26207. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  26208. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  26209. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  26210. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  26211. } else {
  26212. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  26213. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  26214. }
  26215. };
  26216. return PositionalAudio;
  26217. }(Audio);
  26218. var AudioAnalyser = /*#__PURE__*/function () {
  26219. function AudioAnalyser(audio, fftSize) {
  26220. if (fftSize === void 0) {
  26221. fftSize = 2048;
  26222. }
  26223. this.analyser = audio.context.createAnalyser();
  26224. this.analyser.fftSize = fftSize;
  26225. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  26226. audio.getOutput().connect(this.analyser);
  26227. }
  26228. var _proto = AudioAnalyser.prototype;
  26229. _proto.getFrequencyData = function getFrequencyData() {
  26230. this.analyser.getByteFrequencyData(this.data);
  26231. return this.data;
  26232. };
  26233. _proto.getAverageFrequency = function getAverageFrequency() {
  26234. var value = 0;
  26235. var data = this.getFrequencyData();
  26236. for (var i = 0; i < data.length; i++) {
  26237. value += data[i];
  26238. }
  26239. return value / data.length;
  26240. };
  26241. return AudioAnalyser;
  26242. }();
  26243. function PropertyMixer(binding, typeName, valueSize) {
  26244. this.binding = binding;
  26245. this.valueSize = valueSize;
  26246. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  26247. //
  26248. // interpolators can use .buffer as their .result
  26249. // the data then goes to 'incoming'
  26250. //
  26251. // 'accu0' and 'accu1' are used frame-interleaved for
  26252. // the cumulative result and are compared to detect
  26253. // changes
  26254. //
  26255. // 'orig' stores the original state of the property
  26256. //
  26257. // 'add' is used for additive cumulative results
  26258. //
  26259. // 'work' is optional and is only present for quaternion types. It is used
  26260. // to store intermediate quaternion multiplication results
  26261. switch (typeName) {
  26262. case 'quaternion':
  26263. mixFunction = this._slerp;
  26264. mixFunctionAdditive = this._slerpAdditive;
  26265. setIdentity = this._setAdditiveIdentityQuaternion;
  26266. this.buffer = new Float64Array(valueSize * 6);
  26267. this._workIndex = 5;
  26268. break;
  26269. case 'string':
  26270. case 'bool':
  26271. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  26272. // additive is not relevant for non-numeric types
  26273. mixFunctionAdditive = this._select;
  26274. setIdentity = this._setAdditiveIdentityOther;
  26275. this.buffer = new Array(valueSize * 5);
  26276. break;
  26277. default:
  26278. mixFunction = this._lerp;
  26279. mixFunctionAdditive = this._lerpAdditive;
  26280. setIdentity = this._setAdditiveIdentityNumeric;
  26281. this.buffer = new Float64Array(valueSize * 5);
  26282. }
  26283. this._mixBufferRegion = mixFunction;
  26284. this._mixBufferRegionAdditive = mixFunctionAdditive;
  26285. this._setIdentity = setIdentity;
  26286. this._origIndex = 3;
  26287. this._addIndex = 4;
  26288. this.cumulativeWeight = 0;
  26289. this.cumulativeWeightAdditive = 0;
  26290. this.useCount = 0;
  26291. this.referenceCount = 0;
  26292. }
  26293. Object.assign(PropertyMixer.prototype, {
  26294. // accumulate data in the 'incoming' region into 'accu<i>'
  26295. accumulate: function accumulate(accuIndex, weight) {
  26296. // note: happily accumulating nothing when weight = 0, the caller knows
  26297. // the weight and shouldn't have made the call in the first place
  26298. var buffer = this.buffer,
  26299. stride = this.valueSize,
  26300. offset = accuIndex * stride + stride;
  26301. var currentWeight = this.cumulativeWeight;
  26302. if (currentWeight === 0) {
  26303. // accuN := incoming * weight
  26304. for (var i = 0; i !== stride; ++i) {
  26305. buffer[offset + i] = buffer[i];
  26306. }
  26307. currentWeight = weight;
  26308. } else {
  26309. // accuN := accuN + incoming * weight
  26310. currentWeight += weight;
  26311. var mix = weight / currentWeight;
  26312. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  26313. }
  26314. this.cumulativeWeight = currentWeight;
  26315. },
  26316. // accumulate data in the 'incoming' region into 'add'
  26317. accumulateAdditive: function accumulateAdditive(weight) {
  26318. var buffer = this.buffer,
  26319. stride = this.valueSize,
  26320. offset = stride * this._addIndex;
  26321. if (this.cumulativeWeightAdditive === 0) {
  26322. // add = identity
  26323. this._setIdentity();
  26324. } // add := add + incoming * weight
  26325. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  26326. this.cumulativeWeightAdditive += weight;
  26327. },
  26328. // apply the state of 'accu<i>' to the binding when accus differ
  26329. apply: function apply(accuIndex) {
  26330. var stride = this.valueSize,
  26331. buffer = this.buffer,
  26332. offset = accuIndex * stride + stride,
  26333. weight = this.cumulativeWeight,
  26334. weightAdditive = this.cumulativeWeightAdditive,
  26335. binding = this.binding;
  26336. this.cumulativeWeight = 0;
  26337. this.cumulativeWeightAdditive = 0;
  26338. if (weight < 1) {
  26339. // accuN := accuN + original * ( 1 - cumulativeWeight )
  26340. var originalValueOffset = stride * this._origIndex;
  26341. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  26342. }
  26343. if (weightAdditive > 0) {
  26344. // accuN := accuN + additive accuN
  26345. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  26346. }
  26347. for (var i = stride, e = stride + stride; i !== e; ++i) {
  26348. if (buffer[i] !== buffer[i + stride]) {
  26349. // value has changed -> update scene graph
  26350. binding.setValue(buffer, offset);
  26351. break;
  26352. }
  26353. }
  26354. },
  26355. // remember the state of the bound property and copy it to both accus
  26356. saveOriginalState: function saveOriginalState() {
  26357. var binding = this.binding;
  26358. var buffer = this.buffer,
  26359. stride = this.valueSize,
  26360. originalValueOffset = stride * this._origIndex;
  26361. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  26362. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  26363. buffer[i] = buffer[originalValueOffset + i % stride];
  26364. } // Add to identity for additive
  26365. this._setIdentity();
  26366. this.cumulativeWeight = 0;
  26367. this.cumulativeWeightAdditive = 0;
  26368. },
  26369. // apply the state previously taken via 'saveOriginalState' to the binding
  26370. restoreOriginalState: function restoreOriginalState() {
  26371. var originalValueOffset = this.valueSize * 3;
  26372. this.binding.setValue(this.buffer, originalValueOffset);
  26373. },
  26374. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  26375. var startIndex = this._addIndex * this.valueSize;
  26376. var endIndex = startIndex + this.valueSize;
  26377. for (var i = startIndex; i < endIndex; i++) {
  26378. this.buffer[i] = 0;
  26379. }
  26380. },
  26381. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  26382. this._setAdditiveIdentityNumeric();
  26383. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  26384. },
  26385. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  26386. var startIndex = this._origIndex * this.valueSize;
  26387. var targetIndex = this._addIndex * this.valueSize;
  26388. for (var i = 0; i < this.valueSize; i++) {
  26389. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  26390. }
  26391. },
  26392. // mix functions
  26393. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  26394. if (t >= 0.5) {
  26395. for (var i = 0; i !== stride; ++i) {
  26396. buffer[dstOffset + i] = buffer[srcOffset + i];
  26397. }
  26398. }
  26399. },
  26400. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  26401. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  26402. },
  26403. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  26404. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  26405. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  26406. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  26407. },
  26408. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  26409. var s = 1 - t;
  26410. for (var i = 0; i !== stride; ++i) {
  26411. var j = dstOffset + i;
  26412. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  26413. }
  26414. },
  26415. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  26416. for (var i = 0; i !== stride; ++i) {
  26417. var j = dstOffset + i;
  26418. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  26419. }
  26420. }
  26421. });
  26422. // Characters [].:/ are reserved for track binding syntax.
  26423. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  26424. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  26425. // only latin characters, and the unicode \p{L} is not yet supported. So
  26426. // instead, we exclude reserved characters and match everything else.
  26427. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  26428. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  26429. // be matched to parse the rest of the track name.
  26430. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  26431. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  26432. // characters. Accessor may contain any character except closing bracket.
  26433. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  26434. // contain any non-bracket characters.
  26435. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  26436. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  26437. var _supportedObjectNames = ['material', 'materials', 'bones'];
  26438. function Composite(targetGroup, path, optionalParsedPath) {
  26439. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  26440. this._targetGroup = targetGroup;
  26441. this._bindings = targetGroup.subscribe_(path, parsedPath);
  26442. }
  26443. Object.assign(Composite.prototype, {
  26444. getValue: function getValue(array, offset) {
  26445. this.bind(); // bind all binding
  26446. var firstValidIndex = this._targetGroup.nCachedObjects_,
  26447. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  26448. if (binding !== undefined) binding.getValue(array, offset);
  26449. },
  26450. setValue: function setValue(array, offset) {
  26451. var bindings = this._bindings;
  26452. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26453. bindings[i].setValue(array, offset);
  26454. }
  26455. },
  26456. bind: function bind() {
  26457. var bindings = this._bindings;
  26458. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26459. bindings[i].bind();
  26460. }
  26461. },
  26462. unbind: function unbind() {
  26463. var bindings = this._bindings;
  26464. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26465. bindings[i].unbind();
  26466. }
  26467. }
  26468. });
  26469. function PropertyBinding(rootNode, path, parsedPath) {
  26470. this.path = path;
  26471. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  26472. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  26473. this.rootNode = rootNode;
  26474. }
  26475. Object.assign(PropertyBinding, {
  26476. Composite: Composite,
  26477. create: function create(root, path, parsedPath) {
  26478. if (!(root && root.isAnimationObjectGroup)) {
  26479. return new PropertyBinding(root, path, parsedPath);
  26480. } else {
  26481. return new PropertyBinding.Composite(root, path, parsedPath);
  26482. }
  26483. },
  26484. /**
  26485. * Replaces spaces with underscores and removes unsupported characters from
  26486. * node names, to ensure compatibility with parseTrackName().
  26487. *
  26488. * @param {string} name Node name to be sanitized.
  26489. * @return {string}
  26490. */
  26491. sanitizeNodeName: function sanitizeNodeName(name) {
  26492. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  26493. },
  26494. parseTrackName: function parseTrackName(trackName) {
  26495. var matches = _trackRe.exec(trackName);
  26496. if (!matches) {
  26497. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  26498. }
  26499. var results = {
  26500. // directoryName: matches[ 1 ], // (tschw) currently unused
  26501. nodeName: matches[2],
  26502. objectName: matches[3],
  26503. objectIndex: matches[4],
  26504. propertyName: matches[5],
  26505. // required
  26506. propertyIndex: matches[6]
  26507. };
  26508. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  26509. if (lastDot !== undefined && lastDot !== -1) {
  26510. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  26511. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  26512. // 'bar' could be the objectName, or part of a nodeName (which can
  26513. // include '.' characters).
  26514. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  26515. results.nodeName = results.nodeName.substring(0, lastDot);
  26516. results.objectName = objectName;
  26517. }
  26518. }
  26519. if (results.propertyName === null || results.propertyName.length === 0) {
  26520. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  26521. }
  26522. return results;
  26523. },
  26524. findNode: function findNode(root, nodeName) {
  26525. if (!nodeName || nodeName === '' || nodeName === '.' || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  26526. return root;
  26527. } // search into skeleton bones.
  26528. if (root.skeleton) {
  26529. var bone = root.skeleton.getBoneByName(nodeName);
  26530. if (bone !== undefined) {
  26531. return bone;
  26532. }
  26533. } // search into node subtree.
  26534. if (root.children) {
  26535. var searchNodeSubtree = function searchNodeSubtree(children) {
  26536. for (var i = 0; i < children.length; i++) {
  26537. var childNode = children[i];
  26538. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  26539. return childNode;
  26540. }
  26541. var result = searchNodeSubtree(childNode.children);
  26542. if (result) return result;
  26543. }
  26544. return null;
  26545. };
  26546. var subTreeNode = searchNodeSubtree(root.children);
  26547. if (subTreeNode) {
  26548. return subTreeNode;
  26549. }
  26550. }
  26551. return null;
  26552. }
  26553. });
  26554. Object.assign(PropertyBinding.prototype, {
  26555. // prototype, continued
  26556. // these are used to "bind" a nonexistent property
  26557. _getValue_unavailable: function _getValue_unavailable() {},
  26558. _setValue_unavailable: function _setValue_unavailable() {},
  26559. BindingType: {
  26560. Direct: 0,
  26561. EntireArray: 1,
  26562. ArrayElement: 2,
  26563. HasFromToArray: 3
  26564. },
  26565. Versioning: {
  26566. None: 0,
  26567. NeedsUpdate: 1,
  26568. MatrixWorldNeedsUpdate: 2
  26569. },
  26570. GetterByBindingType: [function getValue_direct(buffer, offset) {
  26571. buffer[offset] = this.node[this.propertyName];
  26572. }, function getValue_array(buffer, offset) {
  26573. var source = this.resolvedProperty;
  26574. for (var i = 0, n = source.length; i !== n; ++i) {
  26575. buffer[offset++] = source[i];
  26576. }
  26577. }, function getValue_arrayElement(buffer, offset) {
  26578. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  26579. }, function getValue_toArray(buffer, offset) {
  26580. this.resolvedProperty.toArray(buffer, offset);
  26581. }],
  26582. SetterByBindingTypeAndVersioning: [[// Direct
  26583. function setValue_direct(buffer, offset) {
  26584. this.targetObject[this.propertyName] = buffer[offset];
  26585. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  26586. this.targetObject[this.propertyName] = buffer[offset];
  26587. this.targetObject.needsUpdate = true;
  26588. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  26589. this.targetObject[this.propertyName] = buffer[offset];
  26590. this.targetObject.matrixWorldNeedsUpdate = true;
  26591. }], [// EntireArray
  26592. function setValue_array(buffer, offset) {
  26593. var dest = this.resolvedProperty;
  26594. for (var i = 0, n = dest.length; i !== n; ++i) {
  26595. dest[i] = buffer[offset++];
  26596. }
  26597. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  26598. var dest = this.resolvedProperty;
  26599. for (var i = 0, n = dest.length; i !== n; ++i) {
  26600. dest[i] = buffer[offset++];
  26601. }
  26602. this.targetObject.needsUpdate = true;
  26603. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  26604. var dest = this.resolvedProperty;
  26605. for (var i = 0, n = dest.length; i !== n; ++i) {
  26606. dest[i] = buffer[offset++];
  26607. }
  26608. this.targetObject.matrixWorldNeedsUpdate = true;
  26609. }], [// ArrayElement
  26610. function setValue_arrayElement(buffer, offset) {
  26611. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26612. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  26613. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26614. this.targetObject.needsUpdate = true;
  26615. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  26616. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26617. this.targetObject.matrixWorldNeedsUpdate = true;
  26618. }], [// HasToFromArray
  26619. function setValue_fromArray(buffer, offset) {
  26620. this.resolvedProperty.fromArray(buffer, offset);
  26621. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  26622. this.resolvedProperty.fromArray(buffer, offset);
  26623. this.targetObject.needsUpdate = true;
  26624. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  26625. this.resolvedProperty.fromArray(buffer, offset);
  26626. this.targetObject.matrixWorldNeedsUpdate = true;
  26627. }]],
  26628. getValue: function getValue_unbound(targetArray, offset) {
  26629. this.bind();
  26630. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  26631. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26632. // prototype version of these methods with one that represents
  26633. // the bound state. When the property is not found, the methods
  26634. // become no-ops.
  26635. },
  26636. setValue: function getValue_unbound(sourceArray, offset) {
  26637. this.bind();
  26638. this.setValue(sourceArray, offset);
  26639. },
  26640. // create getter / setter pair for a property in the scene graph
  26641. bind: function bind() {
  26642. var targetObject = this.node;
  26643. var parsedPath = this.parsedPath;
  26644. var objectName = parsedPath.objectName;
  26645. var propertyName = parsedPath.propertyName;
  26646. var propertyIndex = parsedPath.propertyIndex;
  26647. if (!targetObject) {
  26648. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  26649. this.node = targetObject;
  26650. } // set fail state so we can just 'return' on error
  26651. this.getValue = this._getValue_unavailable;
  26652. this.setValue = this._setValue_unavailable; // ensure there is a value node
  26653. if (!targetObject) {
  26654. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  26655. return;
  26656. }
  26657. if (objectName) {
  26658. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26659. switch (objectName) {
  26660. case 'materials':
  26661. if (!targetObject.material) {
  26662. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  26663. return;
  26664. }
  26665. if (!targetObject.material.materials) {
  26666. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  26667. return;
  26668. }
  26669. targetObject = targetObject.material.materials;
  26670. break;
  26671. case 'bones':
  26672. if (!targetObject.skeleton) {
  26673. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  26674. return;
  26675. } // potential future optimization: skip this if propertyIndex is already an integer
  26676. // and convert the integer string to a true integer.
  26677. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  26678. for (var i = 0; i < targetObject.length; i++) {
  26679. if (targetObject[i].name === objectIndex) {
  26680. objectIndex = i;
  26681. break;
  26682. }
  26683. }
  26684. break;
  26685. default:
  26686. if (targetObject[objectName] === undefined) {
  26687. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  26688. return;
  26689. }
  26690. targetObject = targetObject[objectName];
  26691. }
  26692. if (objectIndex !== undefined) {
  26693. if (targetObject[objectIndex] === undefined) {
  26694. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  26695. return;
  26696. }
  26697. targetObject = targetObject[objectIndex];
  26698. }
  26699. } // resolve property
  26700. var nodeProperty = targetObject[propertyName];
  26701. if (nodeProperty === undefined) {
  26702. var nodeName = parsedPath.nodeName;
  26703. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  26704. return;
  26705. } // determine versioning scheme
  26706. var versioning = this.Versioning.None;
  26707. this.targetObject = targetObject;
  26708. if (targetObject.needsUpdate !== undefined) {
  26709. // material
  26710. versioning = this.Versioning.NeedsUpdate;
  26711. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  26712. // node transform
  26713. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26714. } // determine how the property gets bound
  26715. var bindingType = this.BindingType.Direct;
  26716. if (propertyIndex !== undefined) {
  26717. // access a sub element of the property array (only primitives are supported right now)
  26718. if (propertyName === 'morphTargetInfluences') {
  26719. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26720. // support resolving morphTarget names into indices.
  26721. if (!targetObject.geometry) {
  26722. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  26723. return;
  26724. }
  26725. if (targetObject.geometry.isBufferGeometry) {
  26726. if (!targetObject.geometry.morphAttributes) {
  26727. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  26728. return;
  26729. }
  26730. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  26731. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  26732. }
  26733. } else {
  26734. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  26735. return;
  26736. }
  26737. }
  26738. bindingType = this.BindingType.ArrayElement;
  26739. this.resolvedProperty = nodeProperty;
  26740. this.propertyIndex = propertyIndex;
  26741. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26742. // must use copy for Object3D.Euler/Quaternion
  26743. bindingType = this.BindingType.HasFromToArray;
  26744. this.resolvedProperty = nodeProperty;
  26745. } else if (Array.isArray(nodeProperty)) {
  26746. bindingType = this.BindingType.EntireArray;
  26747. this.resolvedProperty = nodeProperty;
  26748. } else {
  26749. this.propertyName = propertyName;
  26750. } // select getter / setter
  26751. this.getValue = this.GetterByBindingType[bindingType];
  26752. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26753. },
  26754. unbind: function unbind() {
  26755. this.node = null; // back to the prototype version of getValue / setValue
  26756. // note: avoiding to mutate the shape of 'this' via 'delete'
  26757. this.getValue = this._getValue_unbound;
  26758. this.setValue = this._setValue_unbound;
  26759. }
  26760. }); // DECLARE ALIAS AFTER assign prototype
  26761. Object.assign(PropertyBinding.prototype, {
  26762. // initial state of these methods that calls 'bind'
  26763. _getValue_unbound: PropertyBinding.prototype.getValue,
  26764. _setValue_unbound: PropertyBinding.prototype.setValue
  26765. });
  26766. /**
  26767. *
  26768. * A group of objects that receives a shared animation state.
  26769. *
  26770. * Usage:
  26771. *
  26772. * - Add objects you would otherwise pass as 'root' to the
  26773. * constructor or the .clipAction method of AnimationMixer.
  26774. *
  26775. * - Instead pass this object as 'root'.
  26776. *
  26777. * - You can also add and remove objects later when the mixer
  26778. * is running.
  26779. *
  26780. * Note:
  26781. *
  26782. * Objects of this class appear as one object to the mixer,
  26783. * so cache control of the individual objects must be done
  26784. * on the group.
  26785. *
  26786. * Limitation:
  26787. *
  26788. * - The animated properties must be compatible among the
  26789. * all objects in the group.
  26790. *
  26791. * - A single property can either be controlled through a
  26792. * target group or directly, but not both.
  26793. */
  26794. function AnimationObjectGroup() {
  26795. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26796. this._objects = Array.prototype.slice.call(arguments);
  26797. this.nCachedObjects_ = 0; // threshold
  26798. // note: read by PropertyBinding.Composite
  26799. var indices = {};
  26800. this._indicesByUUID = indices; // for bookkeeping
  26801. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26802. indices[arguments[i].uuid] = i;
  26803. }
  26804. this._paths = []; // inside: string
  26805. this._parsedPaths = []; // inside: { we don't care, here }
  26806. this._bindings = []; // inside: Array< PropertyBinding >
  26807. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26808. var scope = this;
  26809. this.stats = {
  26810. objects: {
  26811. get total() {
  26812. return scope._objects.length;
  26813. },
  26814. get inUse() {
  26815. return this.total - scope.nCachedObjects_;
  26816. }
  26817. },
  26818. get bindingsPerObject() {
  26819. return scope._bindings.length;
  26820. }
  26821. };
  26822. }
  26823. Object.assign(AnimationObjectGroup.prototype, {
  26824. isAnimationObjectGroup: true,
  26825. add: function add() {
  26826. var objects = this._objects,
  26827. indicesByUUID = this._indicesByUUID,
  26828. paths = this._paths,
  26829. parsedPaths = this._parsedPaths,
  26830. bindings = this._bindings,
  26831. nBindings = bindings.length;
  26832. var knownObject = undefined,
  26833. nObjects = objects.length,
  26834. nCachedObjects = this.nCachedObjects_;
  26835. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26836. var object = arguments[i],
  26837. uuid = object.uuid;
  26838. var index = indicesByUUID[uuid];
  26839. if (index === undefined) {
  26840. // unknown object -> add it to the ACTIVE region
  26841. index = nObjects++;
  26842. indicesByUUID[uuid] = index;
  26843. objects.push(object); // accounting is done, now do the same for all bindings
  26844. for (var j = 0, m = nBindings; j !== m; ++j) {
  26845. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26846. }
  26847. } else if (index < nCachedObjects) {
  26848. knownObject = objects[index]; // move existing object to the ACTIVE region
  26849. var firstActiveIndex = --nCachedObjects,
  26850. lastCachedObject = objects[firstActiveIndex];
  26851. indicesByUUID[lastCachedObject.uuid] = index;
  26852. objects[index] = lastCachedObject;
  26853. indicesByUUID[uuid] = firstActiveIndex;
  26854. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26855. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26856. var bindingsForPath = bindings[_j],
  26857. lastCached = bindingsForPath[firstActiveIndex];
  26858. var binding = bindingsForPath[index];
  26859. bindingsForPath[index] = lastCached;
  26860. if (binding === undefined) {
  26861. // since we do not bother to create new bindings
  26862. // for objects that are cached, the binding may
  26863. // or may not exist
  26864. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26865. }
  26866. bindingsForPath[firstActiveIndex] = binding;
  26867. }
  26868. } else if (objects[index] !== knownObject) {
  26869. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26870. } // else the object is already where we want it to be
  26871. } // for arguments
  26872. this.nCachedObjects_ = nCachedObjects;
  26873. },
  26874. remove: function remove() {
  26875. var objects = this._objects,
  26876. indicesByUUID = this._indicesByUUID,
  26877. bindings = this._bindings,
  26878. nBindings = bindings.length;
  26879. var nCachedObjects = this.nCachedObjects_;
  26880. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26881. var object = arguments[i],
  26882. uuid = object.uuid,
  26883. index = indicesByUUID[uuid];
  26884. if (index !== undefined && index >= nCachedObjects) {
  26885. // move existing object into the CACHED region
  26886. var lastCachedIndex = nCachedObjects++,
  26887. firstActiveObject = objects[lastCachedIndex];
  26888. indicesByUUID[firstActiveObject.uuid] = index;
  26889. objects[index] = firstActiveObject;
  26890. indicesByUUID[uuid] = lastCachedIndex;
  26891. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26892. for (var j = 0, m = nBindings; j !== m; ++j) {
  26893. var bindingsForPath = bindings[j],
  26894. firstActive = bindingsForPath[lastCachedIndex],
  26895. binding = bindingsForPath[index];
  26896. bindingsForPath[index] = firstActive;
  26897. bindingsForPath[lastCachedIndex] = binding;
  26898. }
  26899. }
  26900. } // for arguments
  26901. this.nCachedObjects_ = nCachedObjects;
  26902. },
  26903. // remove & forget
  26904. uncache: function uncache() {
  26905. var objects = this._objects,
  26906. indicesByUUID = this._indicesByUUID,
  26907. bindings = this._bindings,
  26908. nBindings = bindings.length;
  26909. var nCachedObjects = this.nCachedObjects_,
  26910. nObjects = objects.length;
  26911. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26912. var object = arguments[i],
  26913. uuid = object.uuid,
  26914. index = indicesByUUID[uuid];
  26915. if (index !== undefined) {
  26916. delete indicesByUUID[uuid];
  26917. if (index < nCachedObjects) {
  26918. // object is cached, shrink the CACHED region
  26919. var firstActiveIndex = --nCachedObjects,
  26920. lastCachedObject = objects[firstActiveIndex],
  26921. lastIndex = --nObjects,
  26922. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26923. indicesByUUID[lastCachedObject.uuid] = index;
  26924. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26925. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26926. objects[firstActiveIndex] = lastObject;
  26927. objects.pop(); // accounting is done, now do the same for all bindings
  26928. for (var j = 0, m = nBindings; j !== m; ++j) {
  26929. var bindingsForPath = bindings[j],
  26930. lastCached = bindingsForPath[firstActiveIndex],
  26931. last = bindingsForPath[lastIndex];
  26932. bindingsForPath[index] = lastCached;
  26933. bindingsForPath[firstActiveIndex] = last;
  26934. bindingsForPath.pop();
  26935. }
  26936. } else {
  26937. // object is active, just swap with the last and pop
  26938. var _lastIndex = --nObjects,
  26939. _lastObject = objects[_lastIndex];
  26940. if (_lastIndex > 0) {
  26941. indicesByUUID[_lastObject.uuid] = index;
  26942. }
  26943. objects[index] = _lastObject;
  26944. objects.pop(); // accounting is done, now do the same for all bindings
  26945. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26946. var _bindingsForPath = bindings[_j2];
  26947. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26948. _bindingsForPath.pop();
  26949. }
  26950. } // cached or active
  26951. } // if object is known
  26952. } // for arguments
  26953. this.nCachedObjects_ = nCachedObjects;
  26954. },
  26955. // Internal interface used by befriended PropertyBinding.Composite:
  26956. subscribe_: function subscribe_(path, parsedPath) {
  26957. // returns an array of bindings for the given path that is changed
  26958. // according to the contained objects in the group
  26959. var indicesByPath = this._bindingsIndicesByPath;
  26960. var index = indicesByPath[path];
  26961. var bindings = this._bindings;
  26962. if (index !== undefined) return bindings[index];
  26963. var paths = this._paths,
  26964. parsedPaths = this._parsedPaths,
  26965. objects = this._objects,
  26966. nObjects = objects.length,
  26967. nCachedObjects = this.nCachedObjects_,
  26968. bindingsForPath = new Array(nObjects);
  26969. index = bindings.length;
  26970. indicesByPath[path] = index;
  26971. paths.push(path);
  26972. parsedPaths.push(parsedPath);
  26973. bindings.push(bindingsForPath);
  26974. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26975. var object = objects[i];
  26976. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26977. }
  26978. return bindingsForPath;
  26979. },
  26980. unsubscribe_: function unsubscribe_(path) {
  26981. // tells the group to forget about a property path and no longer
  26982. // update the array previously obtained with 'subscribe_'
  26983. var indicesByPath = this._bindingsIndicesByPath,
  26984. index = indicesByPath[path];
  26985. if (index !== undefined) {
  26986. var paths = this._paths,
  26987. parsedPaths = this._parsedPaths,
  26988. bindings = this._bindings,
  26989. lastBindingsIndex = bindings.length - 1,
  26990. lastBindings = bindings[lastBindingsIndex],
  26991. lastBindingsPath = path[lastBindingsIndex];
  26992. indicesByPath[lastBindingsPath] = index;
  26993. bindings[index] = lastBindings;
  26994. bindings.pop();
  26995. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26996. parsedPaths.pop();
  26997. paths[index] = paths[lastBindingsIndex];
  26998. paths.pop();
  26999. }
  27000. }
  27001. });
  27002. var AnimationAction = /*#__PURE__*/function () {
  27003. function AnimationAction(mixer, clip, localRoot, blendMode) {
  27004. if (localRoot === void 0) {
  27005. localRoot = null;
  27006. }
  27007. if (blendMode === void 0) {
  27008. blendMode = clip.blendMode;
  27009. }
  27010. this._mixer = mixer;
  27011. this._clip = clip;
  27012. this._localRoot = localRoot;
  27013. this.blendMode = blendMode;
  27014. var tracks = clip.tracks,
  27015. nTracks = tracks.length,
  27016. interpolants = new Array(nTracks);
  27017. var interpolantSettings = {
  27018. endingStart: ZeroCurvatureEnding,
  27019. endingEnd: ZeroCurvatureEnding
  27020. };
  27021. for (var i = 0; i !== nTracks; ++i) {
  27022. var interpolant = tracks[i].createInterpolant(null);
  27023. interpolants[i] = interpolant;
  27024. interpolant.settings = interpolantSettings;
  27025. }
  27026. this._interpolantSettings = interpolantSettings;
  27027. this._interpolants = interpolants; // bound by the mixer
  27028. // inside: PropertyMixer (managed by the mixer)
  27029. this._propertyBindings = new Array(nTracks);
  27030. this._cacheIndex = null; // for the memory manager
  27031. this._byClipCacheIndex = null; // for the memory manager
  27032. this._timeScaleInterpolant = null;
  27033. this._weightInterpolant = null;
  27034. this.loop = LoopRepeat;
  27035. this._loopCount = -1; // global mixer time when the action is to be started
  27036. // it's set back to 'null' upon start of the action
  27037. this._startTime = null; // scaled local time of the action
  27038. // gets clamped or wrapped to 0..clip.duration according to loop
  27039. this.time = 0;
  27040. this.timeScale = 1;
  27041. this._effectiveTimeScale = 1;
  27042. this.weight = 1;
  27043. this._effectiveWeight = 1;
  27044. this.repetitions = Infinity; // no. of repetitions when looping
  27045. this.paused = false; // true -> zero effective time scale
  27046. this.enabled = true; // false -> zero effective weight
  27047. this.clampWhenFinished = false; // keep feeding the last frame?
  27048. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  27049. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  27050. } // State & Scheduling
  27051. var _proto = AnimationAction.prototype;
  27052. _proto.play = function play() {
  27053. this._mixer._activateAction(this);
  27054. return this;
  27055. };
  27056. _proto.stop = function stop() {
  27057. this._mixer._deactivateAction(this);
  27058. return this.reset();
  27059. };
  27060. _proto.reset = function reset() {
  27061. this.paused = false;
  27062. this.enabled = true;
  27063. this.time = 0; // restart clip
  27064. this._loopCount = -1; // forget previous loops
  27065. this._startTime = null; // forget scheduling
  27066. return this.stopFading().stopWarping();
  27067. };
  27068. _proto.isRunning = function isRunning() {
  27069. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  27070. } // return true when play has been called
  27071. ;
  27072. _proto.isScheduled = function isScheduled() {
  27073. return this._mixer._isActiveAction(this);
  27074. };
  27075. _proto.startAt = function startAt(time) {
  27076. this._startTime = time;
  27077. return this;
  27078. };
  27079. _proto.setLoop = function setLoop(mode, repetitions) {
  27080. this.loop = mode;
  27081. this.repetitions = repetitions;
  27082. return this;
  27083. } // Weight
  27084. // set the weight stopping any scheduled fading
  27085. // although .enabled = false yields an effective weight of zero, this
  27086. // method does *not* change .enabled, because it would be confusing
  27087. ;
  27088. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  27089. this.weight = weight; // note: same logic as when updated at runtime
  27090. this._effectiveWeight = this.enabled ? weight : 0;
  27091. return this.stopFading();
  27092. } // return the weight considering fading and .enabled
  27093. ;
  27094. _proto.getEffectiveWeight = function getEffectiveWeight() {
  27095. return this._effectiveWeight;
  27096. };
  27097. _proto.fadeIn = function fadeIn(duration) {
  27098. return this._scheduleFading(duration, 0, 1);
  27099. };
  27100. _proto.fadeOut = function fadeOut(duration) {
  27101. return this._scheduleFading(duration, 1, 0);
  27102. };
  27103. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  27104. fadeOutAction.fadeOut(duration);
  27105. this.fadeIn(duration);
  27106. if (warp) {
  27107. var fadeInDuration = this._clip.duration,
  27108. fadeOutDuration = fadeOutAction._clip.duration,
  27109. startEndRatio = fadeOutDuration / fadeInDuration,
  27110. endStartRatio = fadeInDuration / fadeOutDuration;
  27111. fadeOutAction.warp(1.0, startEndRatio, duration);
  27112. this.warp(endStartRatio, 1.0, duration);
  27113. }
  27114. return this;
  27115. };
  27116. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  27117. return fadeInAction.crossFadeFrom(this, duration, warp);
  27118. };
  27119. _proto.stopFading = function stopFading() {
  27120. var weightInterpolant = this._weightInterpolant;
  27121. if (weightInterpolant !== null) {
  27122. this._weightInterpolant = null;
  27123. this._mixer._takeBackControlInterpolant(weightInterpolant);
  27124. }
  27125. return this;
  27126. } // Time Scale Control
  27127. // set the time scale stopping any scheduled warping
  27128. // although .paused = true yields an effective time scale of zero, this
  27129. // method does *not* change .paused, because it would be confusing
  27130. ;
  27131. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  27132. this.timeScale = timeScale;
  27133. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  27134. return this.stopWarping();
  27135. } // return the time scale considering warping and .paused
  27136. ;
  27137. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  27138. return this._effectiveTimeScale;
  27139. };
  27140. _proto.setDuration = function setDuration(duration) {
  27141. this.timeScale = this._clip.duration / duration;
  27142. return this.stopWarping();
  27143. };
  27144. _proto.syncWith = function syncWith(action) {
  27145. this.time = action.time;
  27146. this.timeScale = action.timeScale;
  27147. return this.stopWarping();
  27148. };
  27149. _proto.halt = function halt(duration) {
  27150. return this.warp(this._effectiveTimeScale, 0, duration);
  27151. };
  27152. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  27153. var mixer = this._mixer,
  27154. now = mixer.time,
  27155. timeScale = this.timeScale;
  27156. var interpolant = this._timeScaleInterpolant;
  27157. if (interpolant === null) {
  27158. interpolant = mixer._lendControlInterpolant();
  27159. this._timeScaleInterpolant = interpolant;
  27160. }
  27161. var times = interpolant.parameterPositions,
  27162. values = interpolant.sampleValues;
  27163. times[0] = now;
  27164. times[1] = now + duration;
  27165. values[0] = startTimeScale / timeScale;
  27166. values[1] = endTimeScale / timeScale;
  27167. return this;
  27168. };
  27169. _proto.stopWarping = function stopWarping() {
  27170. var timeScaleInterpolant = this._timeScaleInterpolant;
  27171. if (timeScaleInterpolant !== null) {
  27172. this._timeScaleInterpolant = null;
  27173. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  27174. }
  27175. return this;
  27176. } // Object Accessors
  27177. ;
  27178. _proto.getMixer = function getMixer() {
  27179. return this._mixer;
  27180. };
  27181. _proto.getClip = function getClip() {
  27182. return this._clip;
  27183. };
  27184. _proto.getRoot = function getRoot() {
  27185. return this._localRoot || this._mixer._root;
  27186. } // Interna
  27187. ;
  27188. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  27189. // called by the mixer
  27190. if (!this.enabled) {
  27191. // call ._updateWeight() to update ._effectiveWeight
  27192. this._updateWeight(time);
  27193. return;
  27194. }
  27195. var startTime = this._startTime;
  27196. if (startTime !== null) {
  27197. // check for scheduled start of action
  27198. var timeRunning = (time - startTime) * timeDirection;
  27199. if (timeRunning < 0 || timeDirection === 0) {
  27200. return; // yet to come / don't decide when delta = 0
  27201. } // start
  27202. this._startTime = null; // unschedule
  27203. deltaTime = timeDirection * timeRunning;
  27204. } // apply time scale and advance time
  27205. deltaTime *= this._updateTimeScale(time);
  27206. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  27207. // an effective weight of 0
  27208. var weight = this._updateWeight(time);
  27209. if (weight > 0) {
  27210. var _interpolants = this._interpolants;
  27211. var propertyMixers = this._propertyBindings;
  27212. switch (this.blendMode) {
  27213. case AdditiveAnimationBlendMode:
  27214. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  27215. _interpolants[j].evaluate(clipTime);
  27216. propertyMixers[j].accumulateAdditive(weight);
  27217. }
  27218. break;
  27219. case NormalAnimationBlendMode:
  27220. default:
  27221. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  27222. _interpolants[_j].evaluate(clipTime);
  27223. propertyMixers[_j].accumulate(accuIndex, weight);
  27224. }
  27225. }
  27226. }
  27227. };
  27228. _proto._updateWeight = function _updateWeight(time) {
  27229. var weight = 0;
  27230. if (this.enabled) {
  27231. weight = this.weight;
  27232. var interpolant = this._weightInterpolant;
  27233. if (interpolant !== null) {
  27234. var interpolantValue = interpolant.evaluate(time)[0];
  27235. weight *= interpolantValue;
  27236. if (time > interpolant.parameterPositions[1]) {
  27237. this.stopFading();
  27238. if (interpolantValue === 0) {
  27239. // faded out, disable
  27240. this.enabled = false;
  27241. }
  27242. }
  27243. }
  27244. }
  27245. this._effectiveWeight = weight;
  27246. return weight;
  27247. };
  27248. _proto._updateTimeScale = function _updateTimeScale(time) {
  27249. var timeScale = 0;
  27250. if (!this.paused) {
  27251. timeScale = this.timeScale;
  27252. var interpolant = this._timeScaleInterpolant;
  27253. if (interpolant !== null) {
  27254. var interpolantValue = interpolant.evaluate(time)[0];
  27255. timeScale *= interpolantValue;
  27256. if (time > interpolant.parameterPositions[1]) {
  27257. this.stopWarping();
  27258. if (timeScale === 0) {
  27259. // motion has halted, pause
  27260. this.paused = true;
  27261. } else {
  27262. // warp done - apply final time scale
  27263. this.timeScale = timeScale;
  27264. }
  27265. }
  27266. }
  27267. }
  27268. this._effectiveTimeScale = timeScale;
  27269. return timeScale;
  27270. };
  27271. _proto._updateTime = function _updateTime(deltaTime) {
  27272. var duration = this._clip.duration;
  27273. var loop = this.loop;
  27274. var time = this.time + deltaTime;
  27275. var loopCount = this._loopCount;
  27276. var pingPong = loop === LoopPingPong;
  27277. if (deltaTime === 0) {
  27278. if (loopCount === -1) return time;
  27279. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  27280. }
  27281. if (loop === LoopOnce) {
  27282. if (loopCount === -1) {
  27283. // just started
  27284. this._loopCount = 0;
  27285. this._setEndings(true, true, false);
  27286. }
  27287. handle_stop: {
  27288. if (time >= duration) {
  27289. time = duration;
  27290. } else if (time < 0) {
  27291. time = 0;
  27292. } else {
  27293. this.time = time;
  27294. break handle_stop;
  27295. }
  27296. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  27297. this.time = time;
  27298. this._mixer.dispatchEvent({
  27299. type: 'finished',
  27300. action: this,
  27301. direction: deltaTime < 0 ? -1 : 1
  27302. });
  27303. }
  27304. } else {
  27305. // repetitive Repeat or PingPong
  27306. if (loopCount === -1) {
  27307. // just started
  27308. if (deltaTime >= 0) {
  27309. loopCount = 0;
  27310. this._setEndings(true, this.repetitions === 0, pingPong);
  27311. } else {
  27312. // when looping in reverse direction, the initial
  27313. // transition through zero counts as a repetition,
  27314. // so leave loopCount at -1
  27315. this._setEndings(this.repetitions === 0, true, pingPong);
  27316. }
  27317. }
  27318. if (time >= duration || time < 0) {
  27319. // wrap around
  27320. var loopDelta = Math.floor(time / duration); // signed
  27321. time -= duration * loopDelta;
  27322. loopCount += Math.abs(loopDelta);
  27323. var pending = this.repetitions - loopCount;
  27324. if (pending <= 0) {
  27325. // have to stop (switch state, clamp time, fire event)
  27326. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  27327. time = deltaTime > 0 ? duration : 0;
  27328. this.time = time;
  27329. this._mixer.dispatchEvent({
  27330. type: 'finished',
  27331. action: this,
  27332. direction: deltaTime > 0 ? 1 : -1
  27333. });
  27334. } else {
  27335. // keep running
  27336. if (pending === 1) {
  27337. // entering the last round
  27338. var atStart = deltaTime < 0;
  27339. this._setEndings(atStart, !atStart, pingPong);
  27340. } else {
  27341. this._setEndings(false, false, pingPong);
  27342. }
  27343. this._loopCount = loopCount;
  27344. this.time = time;
  27345. this._mixer.dispatchEvent({
  27346. type: 'loop',
  27347. action: this,
  27348. loopDelta: loopDelta
  27349. });
  27350. }
  27351. } else {
  27352. this.time = time;
  27353. }
  27354. if (pingPong && (loopCount & 1) === 1) {
  27355. // invert time for the "pong round"
  27356. return duration - time;
  27357. }
  27358. }
  27359. return time;
  27360. };
  27361. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  27362. var settings = this._interpolantSettings;
  27363. if (pingPong) {
  27364. settings.endingStart = ZeroSlopeEnding;
  27365. settings.endingEnd = ZeroSlopeEnding;
  27366. } else {
  27367. // assuming for LoopOnce atStart == atEnd == true
  27368. if (atStart) {
  27369. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27370. } else {
  27371. settings.endingStart = WrapAroundEnding;
  27372. }
  27373. if (atEnd) {
  27374. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27375. } else {
  27376. settings.endingEnd = WrapAroundEnding;
  27377. }
  27378. }
  27379. };
  27380. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  27381. var mixer = this._mixer,
  27382. now = mixer.time;
  27383. var interpolant = this._weightInterpolant;
  27384. if (interpolant === null) {
  27385. interpolant = mixer._lendControlInterpolant();
  27386. this._weightInterpolant = interpolant;
  27387. }
  27388. var times = interpolant.parameterPositions,
  27389. values = interpolant.sampleValues;
  27390. times[0] = now;
  27391. values[0] = weightNow;
  27392. times[1] = now + duration;
  27393. values[1] = weightThen;
  27394. return this;
  27395. };
  27396. return AnimationAction;
  27397. }();
  27398. function AnimationMixer(root) {
  27399. this._root = root;
  27400. this._initMemoryManager();
  27401. this._accuIndex = 0;
  27402. this.time = 0;
  27403. this.timeScale = 1.0;
  27404. }
  27405. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  27406. constructor: AnimationMixer,
  27407. _bindAction: function _bindAction(action, prototypeAction) {
  27408. var root = action._localRoot || this._root,
  27409. tracks = action._clip.tracks,
  27410. nTracks = tracks.length,
  27411. bindings = action._propertyBindings,
  27412. interpolants = action._interpolants,
  27413. rootUuid = root.uuid,
  27414. bindingsByRoot = this._bindingsByRootAndName;
  27415. var bindingsByName = bindingsByRoot[rootUuid];
  27416. if (bindingsByName === undefined) {
  27417. bindingsByName = {};
  27418. bindingsByRoot[rootUuid] = bindingsByName;
  27419. }
  27420. for (var i = 0; i !== nTracks; ++i) {
  27421. var track = tracks[i],
  27422. trackName = track.name;
  27423. var binding = bindingsByName[trackName];
  27424. if (binding !== undefined) {
  27425. bindings[i] = binding;
  27426. } else {
  27427. binding = bindings[i];
  27428. if (binding !== undefined) {
  27429. // existing binding, make sure the cache knows
  27430. if (binding._cacheIndex === null) {
  27431. ++binding.referenceCount;
  27432. this._addInactiveBinding(binding, rootUuid, trackName);
  27433. }
  27434. continue;
  27435. }
  27436. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  27437. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  27438. ++binding.referenceCount;
  27439. this._addInactiveBinding(binding, rootUuid, trackName);
  27440. bindings[i] = binding;
  27441. }
  27442. interpolants[i].resultBuffer = binding.buffer;
  27443. }
  27444. },
  27445. _activateAction: function _activateAction(action) {
  27446. if (!this._isActiveAction(action)) {
  27447. if (action._cacheIndex === null) {
  27448. // this action has been forgotten by the cache, but the user
  27449. // appears to be still using it -> rebind
  27450. var rootUuid = (action._localRoot || this._root).uuid,
  27451. clipUuid = action._clip.uuid,
  27452. actionsForClip = this._actionsByClip[clipUuid];
  27453. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  27454. this._addInactiveAction(action, clipUuid, rootUuid);
  27455. }
  27456. var bindings = action._propertyBindings; // increment reference counts / sort out state
  27457. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27458. var binding = bindings[i];
  27459. if (binding.useCount++ === 0) {
  27460. this._lendBinding(binding);
  27461. binding.saveOriginalState();
  27462. }
  27463. }
  27464. this._lendAction(action);
  27465. }
  27466. },
  27467. _deactivateAction: function _deactivateAction(action) {
  27468. if (this._isActiveAction(action)) {
  27469. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  27470. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27471. var binding = bindings[i];
  27472. if (--binding.useCount === 0) {
  27473. binding.restoreOriginalState();
  27474. this._takeBackBinding(binding);
  27475. }
  27476. }
  27477. this._takeBackAction(action);
  27478. }
  27479. },
  27480. // Memory manager
  27481. _initMemoryManager: function _initMemoryManager() {
  27482. this._actions = []; // 'nActiveActions' followed by inactive ones
  27483. this._nActiveActions = 0;
  27484. this._actionsByClip = {}; // inside:
  27485. // {
  27486. // knownActions: Array< AnimationAction > - used as prototypes
  27487. // actionByRoot: AnimationAction - lookup
  27488. // }
  27489. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  27490. this._nActiveBindings = 0;
  27491. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  27492. this._controlInterpolants = []; // same game as above
  27493. this._nActiveControlInterpolants = 0;
  27494. var scope = this;
  27495. this.stats = {
  27496. actions: {
  27497. get total() {
  27498. return scope._actions.length;
  27499. },
  27500. get inUse() {
  27501. return scope._nActiveActions;
  27502. }
  27503. },
  27504. bindings: {
  27505. get total() {
  27506. return scope._bindings.length;
  27507. },
  27508. get inUse() {
  27509. return scope._nActiveBindings;
  27510. }
  27511. },
  27512. controlInterpolants: {
  27513. get total() {
  27514. return scope._controlInterpolants.length;
  27515. },
  27516. get inUse() {
  27517. return scope._nActiveControlInterpolants;
  27518. }
  27519. }
  27520. };
  27521. },
  27522. // Memory management for AnimationAction objects
  27523. _isActiveAction: function _isActiveAction(action) {
  27524. var index = action._cacheIndex;
  27525. return index !== null && index < this._nActiveActions;
  27526. },
  27527. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  27528. var actions = this._actions,
  27529. actionsByClip = this._actionsByClip;
  27530. var actionsForClip = actionsByClip[clipUuid];
  27531. if (actionsForClip === undefined) {
  27532. actionsForClip = {
  27533. knownActions: [action],
  27534. actionByRoot: {}
  27535. };
  27536. action._byClipCacheIndex = 0;
  27537. actionsByClip[clipUuid] = actionsForClip;
  27538. } else {
  27539. var knownActions = actionsForClip.knownActions;
  27540. action._byClipCacheIndex = knownActions.length;
  27541. knownActions.push(action);
  27542. }
  27543. action._cacheIndex = actions.length;
  27544. actions.push(action);
  27545. actionsForClip.actionByRoot[rootUuid] = action;
  27546. },
  27547. _removeInactiveAction: function _removeInactiveAction(action) {
  27548. var actions = this._actions,
  27549. lastInactiveAction = actions[actions.length - 1],
  27550. cacheIndex = action._cacheIndex;
  27551. lastInactiveAction._cacheIndex = cacheIndex;
  27552. actions[cacheIndex] = lastInactiveAction;
  27553. actions.pop();
  27554. action._cacheIndex = null;
  27555. var clipUuid = action._clip.uuid,
  27556. actionsByClip = this._actionsByClip,
  27557. actionsForClip = actionsByClip[clipUuid],
  27558. knownActionsForClip = actionsForClip.knownActions,
  27559. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  27560. byClipCacheIndex = action._byClipCacheIndex;
  27561. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  27562. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  27563. knownActionsForClip.pop();
  27564. action._byClipCacheIndex = null;
  27565. var actionByRoot = actionsForClip.actionByRoot,
  27566. rootUuid = (action._localRoot || this._root).uuid;
  27567. delete actionByRoot[rootUuid];
  27568. if (knownActionsForClip.length === 0) {
  27569. delete actionsByClip[clipUuid];
  27570. }
  27571. this._removeInactiveBindingsForAction(action);
  27572. },
  27573. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  27574. var bindings = action._propertyBindings;
  27575. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27576. var binding = bindings[i];
  27577. if (--binding.referenceCount === 0) {
  27578. this._removeInactiveBinding(binding);
  27579. }
  27580. }
  27581. },
  27582. _lendAction: function _lendAction(action) {
  27583. // [ active actions | inactive actions ]
  27584. // [ active actions >| inactive actions ]
  27585. // s a
  27586. // <-swap->
  27587. // a s
  27588. var actions = this._actions,
  27589. prevIndex = action._cacheIndex,
  27590. lastActiveIndex = this._nActiveActions++,
  27591. firstInactiveAction = actions[lastActiveIndex];
  27592. action._cacheIndex = lastActiveIndex;
  27593. actions[lastActiveIndex] = action;
  27594. firstInactiveAction._cacheIndex = prevIndex;
  27595. actions[prevIndex] = firstInactiveAction;
  27596. },
  27597. _takeBackAction: function _takeBackAction(action) {
  27598. // [ active actions | inactive actions ]
  27599. // [ active actions |< inactive actions ]
  27600. // a s
  27601. // <-swap->
  27602. // s a
  27603. var actions = this._actions,
  27604. prevIndex = action._cacheIndex,
  27605. firstInactiveIndex = --this._nActiveActions,
  27606. lastActiveAction = actions[firstInactiveIndex];
  27607. action._cacheIndex = firstInactiveIndex;
  27608. actions[firstInactiveIndex] = action;
  27609. lastActiveAction._cacheIndex = prevIndex;
  27610. actions[prevIndex] = lastActiveAction;
  27611. },
  27612. // Memory management for PropertyMixer objects
  27613. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  27614. var bindingsByRoot = this._bindingsByRootAndName,
  27615. bindings = this._bindings;
  27616. var bindingByName = bindingsByRoot[rootUuid];
  27617. if (bindingByName === undefined) {
  27618. bindingByName = {};
  27619. bindingsByRoot[rootUuid] = bindingByName;
  27620. }
  27621. bindingByName[trackName] = binding;
  27622. binding._cacheIndex = bindings.length;
  27623. bindings.push(binding);
  27624. },
  27625. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  27626. var bindings = this._bindings,
  27627. propBinding = binding.binding,
  27628. rootUuid = propBinding.rootNode.uuid,
  27629. trackName = propBinding.path,
  27630. bindingsByRoot = this._bindingsByRootAndName,
  27631. bindingByName = bindingsByRoot[rootUuid],
  27632. lastInactiveBinding = bindings[bindings.length - 1],
  27633. cacheIndex = binding._cacheIndex;
  27634. lastInactiveBinding._cacheIndex = cacheIndex;
  27635. bindings[cacheIndex] = lastInactiveBinding;
  27636. bindings.pop();
  27637. delete bindingByName[trackName];
  27638. if (Object.keys(bindingByName).length === 0) {
  27639. delete bindingsByRoot[rootUuid];
  27640. }
  27641. },
  27642. _lendBinding: function _lendBinding(binding) {
  27643. var bindings = this._bindings,
  27644. prevIndex = binding._cacheIndex,
  27645. lastActiveIndex = this._nActiveBindings++,
  27646. firstInactiveBinding = bindings[lastActiveIndex];
  27647. binding._cacheIndex = lastActiveIndex;
  27648. bindings[lastActiveIndex] = binding;
  27649. firstInactiveBinding._cacheIndex = prevIndex;
  27650. bindings[prevIndex] = firstInactiveBinding;
  27651. },
  27652. _takeBackBinding: function _takeBackBinding(binding) {
  27653. var bindings = this._bindings,
  27654. prevIndex = binding._cacheIndex,
  27655. firstInactiveIndex = --this._nActiveBindings,
  27656. lastActiveBinding = bindings[firstInactiveIndex];
  27657. binding._cacheIndex = firstInactiveIndex;
  27658. bindings[firstInactiveIndex] = binding;
  27659. lastActiveBinding._cacheIndex = prevIndex;
  27660. bindings[prevIndex] = lastActiveBinding;
  27661. },
  27662. // Memory management of Interpolants for weight and time scale
  27663. _lendControlInterpolant: function _lendControlInterpolant() {
  27664. var interpolants = this._controlInterpolants,
  27665. lastActiveIndex = this._nActiveControlInterpolants++;
  27666. var interpolant = interpolants[lastActiveIndex];
  27667. if (interpolant === undefined) {
  27668. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  27669. interpolant.__cacheIndex = lastActiveIndex;
  27670. interpolants[lastActiveIndex] = interpolant;
  27671. }
  27672. return interpolant;
  27673. },
  27674. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  27675. var interpolants = this._controlInterpolants,
  27676. prevIndex = interpolant.__cacheIndex,
  27677. firstInactiveIndex = --this._nActiveControlInterpolants,
  27678. lastActiveInterpolant = interpolants[firstInactiveIndex];
  27679. interpolant.__cacheIndex = firstInactiveIndex;
  27680. interpolants[firstInactiveIndex] = interpolant;
  27681. lastActiveInterpolant.__cacheIndex = prevIndex;
  27682. interpolants[prevIndex] = lastActiveInterpolant;
  27683. },
  27684. _controlInterpolantsResultBuffer: new Float32Array(1),
  27685. // return an action for a clip optionally using a custom root target
  27686. // object (this method allocates a lot of dynamic memory in case a
  27687. // previously unknown clip/root combination is specified)
  27688. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  27689. var root = optionalRoot || this._root,
  27690. rootUuid = root.uuid;
  27691. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  27692. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  27693. var actionsForClip = this._actionsByClip[clipUuid];
  27694. var prototypeAction = null;
  27695. if (blendMode === undefined) {
  27696. if (clipObject !== null) {
  27697. blendMode = clipObject.blendMode;
  27698. } else {
  27699. blendMode = NormalAnimationBlendMode;
  27700. }
  27701. }
  27702. if (actionsForClip !== undefined) {
  27703. var existingAction = actionsForClip.actionByRoot[rootUuid];
  27704. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  27705. return existingAction;
  27706. } // we know the clip, so we don't have to parse all
  27707. // the bindings again but can just copy
  27708. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  27709. if (clipObject === null) clipObject = prototypeAction._clip;
  27710. } // clip must be known when specified via string
  27711. if (clipObject === null) return null; // allocate all resources required to run it
  27712. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  27713. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  27714. this._addInactiveAction(newAction, clipUuid, rootUuid);
  27715. return newAction;
  27716. },
  27717. // get an existing action
  27718. existingAction: function existingAction(clip, optionalRoot) {
  27719. var root = optionalRoot || this._root,
  27720. rootUuid = root.uuid,
  27721. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  27722. clipUuid = clipObject ? clipObject.uuid : clip,
  27723. actionsForClip = this._actionsByClip[clipUuid];
  27724. if (actionsForClip !== undefined) {
  27725. return actionsForClip.actionByRoot[rootUuid] || null;
  27726. }
  27727. return null;
  27728. },
  27729. // deactivates all previously scheduled actions
  27730. stopAllAction: function stopAllAction() {
  27731. var actions = this._actions,
  27732. nActions = this._nActiveActions;
  27733. for (var i = nActions - 1; i >= 0; --i) {
  27734. actions[i].stop();
  27735. }
  27736. return this;
  27737. },
  27738. // advance the time and update apply the animation
  27739. update: function update(deltaTime) {
  27740. deltaTime *= this.timeScale;
  27741. var actions = this._actions,
  27742. nActions = this._nActiveActions,
  27743. time = this.time += deltaTime,
  27744. timeDirection = Math.sign(deltaTime),
  27745. accuIndex = this._accuIndex ^= 1; // run active actions
  27746. for (var i = 0; i !== nActions; ++i) {
  27747. var action = actions[i];
  27748. action._update(time, deltaTime, timeDirection, accuIndex);
  27749. } // update scene graph
  27750. var bindings = this._bindings,
  27751. nBindings = this._nActiveBindings;
  27752. for (var _i = 0; _i !== nBindings; ++_i) {
  27753. bindings[_i].apply(accuIndex);
  27754. }
  27755. return this;
  27756. },
  27757. // Allows you to seek to a specific time in an animation.
  27758. setTime: function setTime(timeInSeconds) {
  27759. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27760. for (var i = 0; i < this._actions.length; i++) {
  27761. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27762. }
  27763. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27764. },
  27765. // return this mixer's root target object
  27766. getRoot: function getRoot() {
  27767. return this._root;
  27768. },
  27769. // free all resources specific to a particular clip
  27770. uncacheClip: function uncacheClip(clip) {
  27771. var actions = this._actions,
  27772. clipUuid = clip.uuid,
  27773. actionsByClip = this._actionsByClip,
  27774. actionsForClip = actionsByClip[clipUuid];
  27775. if (actionsForClip !== undefined) {
  27776. // note: just calling _removeInactiveAction would mess up the
  27777. // iteration state and also require updating the state we can
  27778. // just throw away
  27779. var actionsToRemove = actionsForClip.knownActions;
  27780. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27781. var action = actionsToRemove[i];
  27782. this._deactivateAction(action);
  27783. var cacheIndex = action._cacheIndex,
  27784. lastInactiveAction = actions[actions.length - 1];
  27785. action._cacheIndex = null;
  27786. action._byClipCacheIndex = null;
  27787. lastInactiveAction._cacheIndex = cacheIndex;
  27788. actions[cacheIndex] = lastInactiveAction;
  27789. actions.pop();
  27790. this._removeInactiveBindingsForAction(action);
  27791. }
  27792. delete actionsByClip[clipUuid];
  27793. }
  27794. },
  27795. // free all resources specific to a particular root target object
  27796. uncacheRoot: function uncacheRoot(root) {
  27797. var rootUuid = root.uuid,
  27798. actionsByClip = this._actionsByClip;
  27799. for (var clipUuid in actionsByClip) {
  27800. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27801. action = actionByRoot[rootUuid];
  27802. if (action !== undefined) {
  27803. this._deactivateAction(action);
  27804. this._removeInactiveAction(action);
  27805. }
  27806. }
  27807. var bindingsByRoot = this._bindingsByRootAndName,
  27808. bindingByName = bindingsByRoot[rootUuid];
  27809. if (bindingByName !== undefined) {
  27810. for (var trackName in bindingByName) {
  27811. var binding = bindingByName[trackName];
  27812. binding.restoreOriginalState();
  27813. this._removeInactiveBinding(binding);
  27814. }
  27815. }
  27816. },
  27817. // remove a targeted clip from the cache
  27818. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27819. var action = this.existingAction(clip, optionalRoot);
  27820. if (action !== null) {
  27821. this._deactivateAction(action);
  27822. this._removeInactiveAction(action);
  27823. }
  27824. }
  27825. });
  27826. var Uniform = /*#__PURE__*/function () {
  27827. function Uniform(value) {
  27828. if (typeof value === 'string') {
  27829. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27830. value = arguments[1];
  27831. }
  27832. this.value = value;
  27833. }
  27834. var _proto = Uniform.prototype;
  27835. _proto.clone = function clone() {
  27836. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27837. };
  27838. return Uniform;
  27839. }();
  27840. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27841. InterleavedBuffer.call(this, array, stride);
  27842. this.meshPerAttribute = meshPerAttribute || 1;
  27843. }
  27844. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27845. constructor: InstancedInterleavedBuffer,
  27846. isInstancedInterleavedBuffer: true,
  27847. copy: function copy(source) {
  27848. InterleavedBuffer.prototype.copy.call(this, source);
  27849. this.meshPerAttribute = source.meshPerAttribute;
  27850. return this;
  27851. },
  27852. clone: function clone(data) {
  27853. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27854. ib.meshPerAttribute = this.meshPerAttribute;
  27855. return ib;
  27856. },
  27857. toJSON: function toJSON(data) {
  27858. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27859. json.isInstancedInterleavedBuffer = true;
  27860. json.meshPerAttribute = this.meshPerAttribute;
  27861. return json;
  27862. }
  27863. });
  27864. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27865. this.buffer = buffer;
  27866. this.type = type;
  27867. this.itemSize = itemSize;
  27868. this.elementSize = elementSize;
  27869. this.count = count;
  27870. this.version = 0;
  27871. }
  27872. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27873. set: function set(value) {
  27874. if (value === true) this.version++;
  27875. }
  27876. });
  27877. Object.assign(GLBufferAttribute.prototype, {
  27878. isGLBufferAttribute: true,
  27879. setBuffer: function setBuffer(buffer) {
  27880. this.buffer = buffer;
  27881. return this;
  27882. },
  27883. setType: function setType(type, elementSize) {
  27884. this.type = type;
  27885. this.elementSize = elementSize;
  27886. return this;
  27887. },
  27888. setItemSize: function setItemSize(itemSize) {
  27889. this.itemSize = itemSize;
  27890. return this;
  27891. },
  27892. setCount: function setCount(count) {
  27893. this.count = count;
  27894. return this;
  27895. }
  27896. });
  27897. function Raycaster(origin, direction, near, far) {
  27898. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27899. this.near = near || 0;
  27900. this.far = far || Infinity;
  27901. this.camera = null;
  27902. this.layers = new Layers();
  27903. this.params = {
  27904. Mesh: {},
  27905. Line: {
  27906. threshold: 1
  27907. },
  27908. LOD: {},
  27909. Points: {
  27910. threshold: 1
  27911. },
  27912. Sprite: {}
  27913. };
  27914. Object.defineProperties(this.params, {
  27915. PointCloud: {
  27916. get: function get() {
  27917. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27918. return this.Points;
  27919. }
  27920. }
  27921. });
  27922. }
  27923. function ascSort(a, b) {
  27924. return a.distance - b.distance;
  27925. }
  27926. function _intersectObject(object, raycaster, intersects, recursive) {
  27927. if (object.layers.test(raycaster.layers)) {
  27928. object.raycast(raycaster, intersects);
  27929. }
  27930. if (recursive === true) {
  27931. var children = object.children;
  27932. for (var i = 0, l = children.length; i < l; i++) {
  27933. _intersectObject(children[i], raycaster, intersects, true);
  27934. }
  27935. }
  27936. }
  27937. Object.assign(Raycaster.prototype, {
  27938. set: function set(origin, direction) {
  27939. // direction is assumed to be normalized (for accurate distance calculations)
  27940. this.ray.set(origin, direction);
  27941. },
  27942. setFromCamera: function setFromCamera(coords, camera) {
  27943. if (camera && camera.isPerspectiveCamera) {
  27944. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27945. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27946. this.camera = camera;
  27947. } else if (camera && camera.isOrthographicCamera) {
  27948. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27949. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27950. this.camera = camera;
  27951. } else {
  27952. console.error('THREE.Raycaster: Unsupported camera type: ' + camera.type);
  27953. }
  27954. },
  27955. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27956. var intersects = optionalTarget || [];
  27957. _intersectObject(object, this, intersects, recursive);
  27958. intersects.sort(ascSort);
  27959. return intersects;
  27960. },
  27961. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27962. var intersects = optionalTarget || [];
  27963. if (Array.isArray(objects) === false) {
  27964. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27965. return intersects;
  27966. }
  27967. for (var i = 0, l = objects.length; i < l; i++) {
  27968. _intersectObject(objects[i], this, intersects, recursive);
  27969. }
  27970. intersects.sort(ascSort);
  27971. return intersects;
  27972. }
  27973. });
  27974. /**
  27975. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27976. *
  27977. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27978. * The azimuthal angle (theta) is measured from the positive z-axis.
  27979. */
  27980. var Spherical = /*#__PURE__*/function () {
  27981. function Spherical(radius, phi, theta) {
  27982. if (radius === void 0) {
  27983. radius = 1;
  27984. }
  27985. if (phi === void 0) {
  27986. phi = 0;
  27987. }
  27988. if (theta === void 0) {
  27989. theta = 0;
  27990. }
  27991. this.radius = radius;
  27992. this.phi = phi; // polar angle
  27993. this.theta = theta; // azimuthal angle
  27994. return this;
  27995. }
  27996. var _proto = Spherical.prototype;
  27997. _proto.set = function set(radius, phi, theta) {
  27998. this.radius = radius;
  27999. this.phi = phi;
  28000. this.theta = theta;
  28001. return this;
  28002. };
  28003. _proto.clone = function clone() {
  28004. return new this.constructor().copy(this);
  28005. };
  28006. _proto.copy = function copy(other) {
  28007. this.radius = other.radius;
  28008. this.phi = other.phi;
  28009. this.theta = other.theta;
  28010. return this;
  28011. } // restrict phi to be betwee EPS and PI-EPS
  28012. ;
  28013. _proto.makeSafe = function makeSafe() {
  28014. var EPS = 0.000001;
  28015. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  28016. return this;
  28017. };
  28018. _proto.setFromVector3 = function setFromVector3(v) {
  28019. return this.setFromCartesianCoords(v.x, v.y, v.z);
  28020. };
  28021. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  28022. this.radius = Math.sqrt(x * x + y * y + z * z);
  28023. if (this.radius === 0) {
  28024. this.theta = 0;
  28025. this.phi = 0;
  28026. } else {
  28027. this.theta = Math.atan2(x, z);
  28028. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  28029. }
  28030. return this;
  28031. };
  28032. return Spherical;
  28033. }();
  28034. /**
  28035. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  28036. */
  28037. var Cylindrical = /*#__PURE__*/function () {
  28038. function Cylindrical(radius, theta, y) {
  28039. this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
  28040. this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  28041. this.y = y !== undefined ? y : 0; // height above the x-z plane
  28042. return this;
  28043. }
  28044. var _proto = Cylindrical.prototype;
  28045. _proto.set = function set(radius, theta, y) {
  28046. this.radius = radius;
  28047. this.theta = theta;
  28048. this.y = y;
  28049. return this;
  28050. };
  28051. _proto.clone = function clone() {
  28052. return new this.constructor().copy(this);
  28053. };
  28054. _proto.copy = function copy(other) {
  28055. this.radius = other.radius;
  28056. this.theta = other.theta;
  28057. this.y = other.y;
  28058. return this;
  28059. };
  28060. _proto.setFromVector3 = function setFromVector3(v) {
  28061. return this.setFromCartesianCoords(v.x, v.y, v.z);
  28062. };
  28063. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  28064. this.radius = Math.sqrt(x * x + z * z);
  28065. this.theta = Math.atan2(x, z);
  28066. this.y = y;
  28067. return this;
  28068. };
  28069. return Cylindrical;
  28070. }();
  28071. var _vector$8 = /*@__PURE__*/new Vector2();
  28072. var Box2 = /*#__PURE__*/function () {
  28073. function Box2(min, max) {
  28074. Object.defineProperty(this, 'isBox2', {
  28075. value: true
  28076. });
  28077. this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
  28078. this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
  28079. }
  28080. var _proto = Box2.prototype;
  28081. _proto.set = function set(min, max) {
  28082. this.min.copy(min);
  28083. this.max.copy(max);
  28084. return this;
  28085. };
  28086. _proto.setFromPoints = function setFromPoints(points) {
  28087. this.makeEmpty();
  28088. for (var i = 0, il = points.length; i < il; i++) {
  28089. this.expandByPoint(points[i]);
  28090. }
  28091. return this;
  28092. };
  28093. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  28094. var halfSize = _vector$8.copy(size).multiplyScalar(0.5);
  28095. this.min.copy(center).sub(halfSize);
  28096. this.max.copy(center).add(halfSize);
  28097. return this;
  28098. };
  28099. _proto.clone = function clone() {
  28100. return new this.constructor().copy(this);
  28101. };
  28102. _proto.copy = function copy(box) {
  28103. this.min.copy(box.min);
  28104. this.max.copy(box.max);
  28105. return this;
  28106. };
  28107. _proto.makeEmpty = function makeEmpty() {
  28108. this.min.x = this.min.y = +Infinity;
  28109. this.max.x = this.max.y = -Infinity;
  28110. return this;
  28111. };
  28112. _proto.isEmpty = function isEmpty() {
  28113. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  28114. return this.max.x < this.min.x || this.max.y < this.min.y;
  28115. };
  28116. _proto.getCenter = function getCenter(target) {
  28117. if (target === undefined) {
  28118. console.warn('THREE.Box2: .getCenter() target is now required');
  28119. target = new Vector2();
  28120. }
  28121. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  28122. };
  28123. _proto.getSize = function getSize(target) {
  28124. if (target === undefined) {
  28125. console.warn('THREE.Box2: .getSize() target is now required');
  28126. target = new Vector2();
  28127. }
  28128. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  28129. };
  28130. _proto.expandByPoint = function expandByPoint(point) {
  28131. this.min.min(point);
  28132. this.max.max(point);
  28133. return this;
  28134. };
  28135. _proto.expandByVector = function expandByVector(vector) {
  28136. this.min.sub(vector);
  28137. this.max.add(vector);
  28138. return this;
  28139. };
  28140. _proto.expandByScalar = function expandByScalar(scalar) {
  28141. this.min.addScalar(-scalar);
  28142. this.max.addScalar(scalar);
  28143. return this;
  28144. };
  28145. _proto.containsPoint = function containsPoint(point) {
  28146. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  28147. };
  28148. _proto.containsBox = function containsBox(box) {
  28149. 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;
  28150. };
  28151. _proto.getParameter = function getParameter(point, target) {
  28152. // This can potentially have a divide by zero if the box
  28153. // has a size dimension of 0.
  28154. if (target === undefined) {
  28155. console.warn('THREE.Box2: .getParameter() target is now required');
  28156. target = new Vector2();
  28157. }
  28158. 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));
  28159. };
  28160. _proto.intersectsBox = function intersectsBox(box) {
  28161. // using 4 splitting planes to rule out intersections
  28162. 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;
  28163. };
  28164. _proto.clampPoint = function clampPoint(point, target) {
  28165. if (target === undefined) {
  28166. console.warn('THREE.Box2: .clampPoint() target is now required');
  28167. target = new Vector2();
  28168. }
  28169. return target.copy(point).clamp(this.min, this.max);
  28170. };
  28171. _proto.distanceToPoint = function distanceToPoint(point) {
  28172. var clampedPoint = _vector$8.copy(point).clamp(this.min, this.max);
  28173. return clampedPoint.sub(point).length();
  28174. };
  28175. _proto.intersect = function intersect(box) {
  28176. this.min.max(box.min);
  28177. this.max.min(box.max);
  28178. return this;
  28179. };
  28180. _proto.union = function union(box) {
  28181. this.min.min(box.min);
  28182. this.max.max(box.max);
  28183. return this;
  28184. };
  28185. _proto.translate = function translate(offset) {
  28186. this.min.add(offset);
  28187. this.max.add(offset);
  28188. return this;
  28189. };
  28190. _proto.equals = function equals(box) {
  28191. return box.min.equals(this.min) && box.max.equals(this.max);
  28192. };
  28193. return Box2;
  28194. }();
  28195. var _startP = /*@__PURE__*/new Vector3();
  28196. var _startEnd = /*@__PURE__*/new Vector3();
  28197. var Line3 = /*#__PURE__*/function () {
  28198. function Line3(start, end) {
  28199. this.start = start !== undefined ? start : new Vector3();
  28200. this.end = end !== undefined ? end : new Vector3();
  28201. }
  28202. var _proto = Line3.prototype;
  28203. _proto.set = function set(start, end) {
  28204. this.start.copy(start);
  28205. this.end.copy(end);
  28206. return this;
  28207. };
  28208. _proto.clone = function clone() {
  28209. return new this.constructor().copy(this);
  28210. };
  28211. _proto.copy = function copy(line) {
  28212. this.start.copy(line.start);
  28213. this.end.copy(line.end);
  28214. return this;
  28215. };
  28216. _proto.getCenter = function getCenter(target) {
  28217. if (target === undefined) {
  28218. console.warn('THREE.Line3: .getCenter() target is now required');
  28219. target = new Vector3();
  28220. }
  28221. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  28222. };
  28223. _proto.delta = function delta(target) {
  28224. if (target === undefined) {
  28225. console.warn('THREE.Line3: .delta() target is now required');
  28226. target = new Vector3();
  28227. }
  28228. return target.subVectors(this.end, this.start);
  28229. };
  28230. _proto.distanceSq = function distanceSq() {
  28231. return this.start.distanceToSquared(this.end);
  28232. };
  28233. _proto.distance = function distance() {
  28234. return this.start.distanceTo(this.end);
  28235. };
  28236. _proto.at = function at(t, target) {
  28237. if (target === undefined) {
  28238. console.warn('THREE.Line3: .at() target is now required');
  28239. target = new Vector3();
  28240. }
  28241. return this.delta(target).multiplyScalar(t).add(this.start);
  28242. };
  28243. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  28244. _startP.subVectors(point, this.start);
  28245. _startEnd.subVectors(this.end, this.start);
  28246. var startEnd2 = _startEnd.dot(_startEnd);
  28247. var startEnd_startP = _startEnd.dot(_startP);
  28248. var t = startEnd_startP / startEnd2;
  28249. if (clampToLine) {
  28250. t = MathUtils.clamp(t, 0, 1);
  28251. }
  28252. return t;
  28253. };
  28254. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  28255. var t = this.closestPointToPointParameter(point, clampToLine);
  28256. if (target === undefined) {
  28257. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  28258. target = new Vector3();
  28259. }
  28260. return this.delta(target).multiplyScalar(t).add(this.start);
  28261. };
  28262. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  28263. this.start.applyMatrix4(matrix);
  28264. this.end.applyMatrix4(matrix);
  28265. return this;
  28266. };
  28267. _proto.equals = function equals(line) {
  28268. return line.start.equals(this.start) && line.end.equals(this.end);
  28269. };
  28270. return Line3;
  28271. }();
  28272. function ImmediateRenderObject(material) {
  28273. Object3D.call(this);
  28274. this.material = material;
  28275. this.render = function ()
  28276. /* renderCallback */
  28277. {};
  28278. this.hasPositions = false;
  28279. this.hasNormals = false;
  28280. this.hasColors = false;
  28281. this.hasUvs = false;
  28282. this.positionArray = null;
  28283. this.normalArray = null;
  28284. this.colorArray = null;
  28285. this.uvArray = null;
  28286. this.count = 0;
  28287. }
  28288. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  28289. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  28290. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  28291. var _vector$9 = /*@__PURE__*/new Vector3();
  28292. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  28293. _inheritsLoose(SpotLightHelper, _Object3D);
  28294. function SpotLightHelper(light, color) {
  28295. var _this;
  28296. _this = _Object3D.call(this) || this;
  28297. _this.light = light;
  28298. _this.light.updateMatrixWorld();
  28299. _this.matrix = light.matrixWorld;
  28300. _this.matrixAutoUpdate = false;
  28301. _this.color = color;
  28302. var geometry = new BufferGeometry();
  28303. 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];
  28304. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  28305. var p1 = i / l * Math.PI * 2;
  28306. var p2 = j / l * Math.PI * 2;
  28307. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  28308. }
  28309. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28310. var material = new LineBasicMaterial({
  28311. fog: false,
  28312. toneMapped: false
  28313. });
  28314. _this.cone = new LineSegments(geometry, material);
  28315. _this.add(_this.cone);
  28316. _this.update();
  28317. return _this;
  28318. }
  28319. var _proto = SpotLightHelper.prototype;
  28320. _proto.dispose = function dispose() {
  28321. this.cone.geometry.dispose();
  28322. this.cone.material.dispose();
  28323. };
  28324. _proto.update = function update() {
  28325. this.light.updateMatrixWorld();
  28326. var coneLength = this.light.distance ? this.light.distance : 1000;
  28327. var coneWidth = coneLength * Math.tan(this.light.angle);
  28328. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  28329. _vector$9.setFromMatrixPosition(this.light.target.matrixWorld);
  28330. this.cone.lookAt(_vector$9);
  28331. if (this.color !== undefined) {
  28332. this.cone.material.color.set(this.color);
  28333. } else {
  28334. this.cone.material.color.copy(this.light.color);
  28335. }
  28336. };
  28337. return SpotLightHelper;
  28338. }(Object3D);
  28339. var _vector$a = /*@__PURE__*/new Vector3();
  28340. var _boneMatrix = /*@__PURE__*/new Matrix4();
  28341. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  28342. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  28343. _inheritsLoose(SkeletonHelper, _LineSegments);
  28344. function SkeletonHelper(object) {
  28345. var _this;
  28346. var bones = getBoneList(object);
  28347. var geometry = new BufferGeometry();
  28348. var vertices = [];
  28349. var colors = [];
  28350. var color1 = new Color(0, 0, 1);
  28351. var color2 = new Color(0, 1, 0);
  28352. for (var i = 0; i < bones.length; i++) {
  28353. var bone = bones[i];
  28354. if (bone.parent && bone.parent.isBone) {
  28355. vertices.push(0, 0, 0);
  28356. vertices.push(0, 0, 0);
  28357. colors.push(color1.r, color1.g, color1.b);
  28358. colors.push(color2.r, color2.g, color2.b);
  28359. }
  28360. }
  28361. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28362. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28363. var material = new LineBasicMaterial({
  28364. vertexColors: true,
  28365. depthTest: false,
  28366. depthWrite: false,
  28367. toneMapped: false,
  28368. transparent: true
  28369. });
  28370. _this = _LineSegments.call(this, geometry, material) || this;
  28371. _this.type = 'SkeletonHelper';
  28372. _this.isSkeletonHelper = true;
  28373. _this.root = object;
  28374. _this.bones = bones;
  28375. _this.matrix = object.matrixWorld;
  28376. _this.matrixAutoUpdate = false;
  28377. return _this;
  28378. }
  28379. var _proto = SkeletonHelper.prototype;
  28380. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28381. var bones = this.bones;
  28382. var geometry = this.geometry;
  28383. var position = geometry.getAttribute('position');
  28384. _matrixWorldInv.copy(this.root.matrixWorld).invert();
  28385. for (var i = 0, j = 0; i < bones.length; i++) {
  28386. var bone = bones[i];
  28387. if (bone.parent && bone.parent.isBone) {
  28388. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  28389. _vector$a.setFromMatrixPosition(_boneMatrix);
  28390. position.setXYZ(j, _vector$a.x, _vector$a.y, _vector$a.z);
  28391. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  28392. _vector$a.setFromMatrixPosition(_boneMatrix);
  28393. position.setXYZ(j + 1, _vector$a.x, _vector$a.y, _vector$a.z);
  28394. j += 2;
  28395. }
  28396. }
  28397. geometry.getAttribute('position').needsUpdate = true;
  28398. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28399. };
  28400. return SkeletonHelper;
  28401. }(LineSegments);
  28402. function getBoneList(object) {
  28403. var boneList = [];
  28404. if (object && object.isBone) {
  28405. boneList.push(object);
  28406. }
  28407. for (var i = 0; i < object.children.length; i++) {
  28408. boneList.push.apply(boneList, getBoneList(object.children[i]));
  28409. }
  28410. return boneList;
  28411. }
  28412. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  28413. _inheritsLoose(PointLightHelper, _Mesh);
  28414. function PointLightHelper(light, sphereSize, color) {
  28415. var _this;
  28416. var geometry = new SphereBufferGeometry(sphereSize, 4, 2);
  28417. var material = new MeshBasicMaterial({
  28418. wireframe: true,
  28419. fog: false,
  28420. toneMapped: false
  28421. });
  28422. _this = _Mesh.call(this, geometry, material) || this;
  28423. _this.light = light;
  28424. _this.light.updateMatrixWorld();
  28425. _this.color = color;
  28426. _this.type = 'PointLightHelper';
  28427. _this.matrix = _this.light.matrixWorld;
  28428. _this.matrixAutoUpdate = false;
  28429. _this.update();
  28430. /*
  28431. // TODO: delete this comment?
  28432. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  28433. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  28434. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  28435. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  28436. const d = light.distance;
  28437. if ( d === 0.0 ) {
  28438. this.lightDistance.visible = false;
  28439. } else {
  28440. this.lightDistance.scale.set( d, d, d );
  28441. }
  28442. this.add( this.lightDistance );
  28443. */
  28444. return _this;
  28445. }
  28446. var _proto = PointLightHelper.prototype;
  28447. _proto.dispose = function dispose() {
  28448. this.geometry.dispose();
  28449. this.material.dispose();
  28450. };
  28451. _proto.update = function update() {
  28452. if (this.color !== undefined) {
  28453. this.material.color.set(this.color);
  28454. } else {
  28455. this.material.color.copy(this.light.color);
  28456. }
  28457. /*
  28458. const d = this.light.distance;
  28459. if ( d === 0.0 ) {
  28460. this.lightDistance.visible = false;
  28461. } else {
  28462. this.lightDistance.visible = true;
  28463. this.lightDistance.scale.set( d, d, d );
  28464. }
  28465. */
  28466. };
  28467. return PointLightHelper;
  28468. }(Mesh);
  28469. var _vector$b = /*@__PURE__*/new Vector3();
  28470. var _color1 = /*@__PURE__*/new Color();
  28471. var _color2 = /*@__PURE__*/new Color();
  28472. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  28473. _inheritsLoose(HemisphereLightHelper, _Object3D);
  28474. function HemisphereLightHelper(light, size, color) {
  28475. var _this;
  28476. _this = _Object3D.call(this) || this;
  28477. _this.light = light;
  28478. _this.light.updateMatrixWorld();
  28479. _this.matrix = light.matrixWorld;
  28480. _this.matrixAutoUpdate = false;
  28481. _this.color = color;
  28482. var geometry = new OctahedronBufferGeometry(size);
  28483. geometry.rotateY(Math.PI * 0.5);
  28484. _this.material = new MeshBasicMaterial({
  28485. wireframe: true,
  28486. fog: false,
  28487. toneMapped: false
  28488. });
  28489. if (_this.color === undefined) _this.material.vertexColors = true;
  28490. var position = geometry.getAttribute('position');
  28491. var colors = new Float32Array(position.count * 3);
  28492. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  28493. _this.add(new Mesh(geometry, _this.material));
  28494. _this.update();
  28495. return _this;
  28496. }
  28497. var _proto = HemisphereLightHelper.prototype;
  28498. _proto.dispose = function dispose() {
  28499. this.children[0].geometry.dispose();
  28500. this.children[0].material.dispose();
  28501. };
  28502. _proto.update = function update() {
  28503. var mesh = this.children[0];
  28504. if (this.color !== undefined) {
  28505. this.material.color.set(this.color);
  28506. } else {
  28507. var colors = mesh.geometry.getAttribute('color');
  28508. _color1.copy(this.light.color);
  28509. _color2.copy(this.light.groundColor);
  28510. for (var i = 0, l = colors.count; i < l; i++) {
  28511. var color = i < l / 2 ? _color1 : _color2;
  28512. colors.setXYZ(i, color.r, color.g, color.b);
  28513. }
  28514. colors.needsUpdate = true;
  28515. }
  28516. mesh.lookAt(_vector$b.setFromMatrixPosition(this.light.matrixWorld).negate());
  28517. };
  28518. return HemisphereLightHelper;
  28519. }(Object3D);
  28520. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  28521. _inheritsLoose(GridHelper, _LineSegments);
  28522. function GridHelper(size, divisions, color1, color2) {
  28523. var _this;
  28524. if (size === void 0) {
  28525. size = 10;
  28526. }
  28527. if (divisions === void 0) {
  28528. divisions = 10;
  28529. }
  28530. if (color1 === void 0) {
  28531. color1 = 0x444444;
  28532. }
  28533. if (color2 === void 0) {
  28534. color2 = 0x888888;
  28535. }
  28536. color1 = new Color(color1);
  28537. color2 = new Color(color2);
  28538. var center = divisions / 2;
  28539. var step = size / divisions;
  28540. var halfSize = size / 2;
  28541. var vertices = [],
  28542. colors = [];
  28543. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  28544. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  28545. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  28546. var color = i === center ? color1 : color2;
  28547. color.toArray(colors, j);
  28548. j += 3;
  28549. color.toArray(colors, j);
  28550. j += 3;
  28551. color.toArray(colors, j);
  28552. j += 3;
  28553. color.toArray(colors, j);
  28554. j += 3;
  28555. }
  28556. var geometry = new BufferGeometry();
  28557. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28558. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28559. var material = new LineBasicMaterial({
  28560. vertexColors: true,
  28561. toneMapped: false
  28562. });
  28563. _this = _LineSegments.call(this, geometry, material) || this;
  28564. _this.type = 'GridHelper';
  28565. return _this;
  28566. }
  28567. return GridHelper;
  28568. }(LineSegments);
  28569. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  28570. _inheritsLoose(PolarGridHelper, _LineSegments);
  28571. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  28572. var _this;
  28573. if (radius === void 0) {
  28574. radius = 10;
  28575. }
  28576. if (radials === void 0) {
  28577. radials = 16;
  28578. }
  28579. if (circles === void 0) {
  28580. circles = 8;
  28581. }
  28582. if (divisions === void 0) {
  28583. divisions = 64;
  28584. }
  28585. if (color1 === void 0) {
  28586. color1 = 0x444444;
  28587. }
  28588. if (color2 === void 0) {
  28589. color2 = 0x888888;
  28590. }
  28591. color1 = new Color(color1);
  28592. color2 = new Color(color2);
  28593. var vertices = [];
  28594. var colors = []; // create the radials
  28595. for (var i = 0; i <= radials; i++) {
  28596. var v = i / radials * (Math.PI * 2);
  28597. var x = Math.sin(v) * radius;
  28598. var z = Math.cos(v) * radius;
  28599. vertices.push(0, 0, 0);
  28600. vertices.push(x, 0, z);
  28601. var color = i & 1 ? color1 : color2;
  28602. colors.push(color.r, color.g, color.b);
  28603. colors.push(color.r, color.g, color.b);
  28604. } // create the circles
  28605. for (var _i = 0; _i <= circles; _i++) {
  28606. var _color = _i & 1 ? color1 : color2;
  28607. var r = radius - radius / circles * _i;
  28608. for (var j = 0; j < divisions; j++) {
  28609. // first vertex
  28610. var _v = j / divisions * (Math.PI * 2);
  28611. var _x = Math.sin(_v) * r;
  28612. var _z = Math.cos(_v) * r;
  28613. vertices.push(_x, 0, _z);
  28614. colors.push(_color.r, _color.g, _color.b); // second vertex
  28615. _v = (j + 1) / divisions * (Math.PI * 2);
  28616. _x = Math.sin(_v) * r;
  28617. _z = Math.cos(_v) * r;
  28618. vertices.push(_x, 0, _z);
  28619. colors.push(_color.r, _color.g, _color.b);
  28620. }
  28621. }
  28622. var geometry = new BufferGeometry();
  28623. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28624. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28625. var material = new LineBasicMaterial({
  28626. vertexColors: true,
  28627. toneMapped: false
  28628. });
  28629. _this = _LineSegments.call(this, geometry, material) || this;
  28630. _this.type = 'PolarGridHelper';
  28631. return _this;
  28632. }
  28633. return PolarGridHelper;
  28634. }(LineSegments);
  28635. var _v1$6 = /*@__PURE__*/new Vector3();
  28636. var _v2$3 = /*@__PURE__*/new Vector3();
  28637. var _v3$1 = /*@__PURE__*/new Vector3();
  28638. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  28639. _inheritsLoose(DirectionalLightHelper, _Object3D);
  28640. function DirectionalLightHelper(light, size, color) {
  28641. var _this;
  28642. _this = _Object3D.call(this) || this;
  28643. _this.light = light;
  28644. _this.light.updateMatrixWorld();
  28645. _this.matrix = light.matrixWorld;
  28646. _this.matrixAutoUpdate = false;
  28647. _this.color = color;
  28648. if (size === undefined) size = 1;
  28649. var geometry = new BufferGeometry();
  28650. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  28651. var material = new LineBasicMaterial({
  28652. fog: false,
  28653. toneMapped: false
  28654. });
  28655. _this.lightPlane = new Line(geometry, material);
  28656. _this.add(_this.lightPlane);
  28657. geometry = new BufferGeometry();
  28658. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  28659. _this.targetLine = new Line(geometry, material);
  28660. _this.add(_this.targetLine);
  28661. _this.update();
  28662. return _this;
  28663. }
  28664. var _proto = DirectionalLightHelper.prototype;
  28665. _proto.dispose = function dispose() {
  28666. this.lightPlane.geometry.dispose();
  28667. this.lightPlane.material.dispose();
  28668. this.targetLine.geometry.dispose();
  28669. this.targetLine.material.dispose();
  28670. };
  28671. _proto.update = function update() {
  28672. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  28673. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  28674. _v3$1.subVectors(_v2$3, _v1$6);
  28675. this.lightPlane.lookAt(_v2$3);
  28676. if (this.color !== undefined) {
  28677. this.lightPlane.material.color.set(this.color);
  28678. this.targetLine.material.color.set(this.color);
  28679. } else {
  28680. this.lightPlane.material.color.copy(this.light.color);
  28681. this.targetLine.material.color.copy(this.light.color);
  28682. }
  28683. this.targetLine.lookAt(_v2$3);
  28684. this.targetLine.scale.z = _v3$1.length();
  28685. };
  28686. return DirectionalLightHelper;
  28687. }(Object3D);
  28688. var _vector$c = /*@__PURE__*/new Vector3();
  28689. var _camera = /*@__PURE__*/new Camera();
  28690. /**
  28691. * - shows frustum, line of sight and up of the camera
  28692. * - suitable for fast updates
  28693. * - based on frustum visualization in lightgl.js shadowmap example
  28694. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28695. */
  28696. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  28697. _inheritsLoose(CameraHelper, _LineSegments);
  28698. function CameraHelper(camera) {
  28699. var _this;
  28700. var geometry = new BufferGeometry();
  28701. var material = new LineBasicMaterial({
  28702. color: 0xffffff,
  28703. vertexColors: true,
  28704. toneMapped: false
  28705. });
  28706. var vertices = [];
  28707. var colors = [];
  28708. var pointMap = {}; // colors
  28709. var colorFrustum = new Color(0xffaa00);
  28710. var colorCone = new Color(0xff0000);
  28711. var colorUp = new Color(0x00aaff);
  28712. var colorTarget = new Color(0xffffff);
  28713. var colorCross = new Color(0x333333); // near
  28714. addLine('n1', 'n2', colorFrustum);
  28715. addLine('n2', 'n4', colorFrustum);
  28716. addLine('n4', 'n3', colorFrustum);
  28717. addLine('n3', 'n1', colorFrustum); // far
  28718. addLine('f1', 'f2', colorFrustum);
  28719. addLine('f2', 'f4', colorFrustum);
  28720. addLine('f4', 'f3', colorFrustum);
  28721. addLine('f3', 'f1', colorFrustum); // sides
  28722. addLine('n1', 'f1', colorFrustum);
  28723. addLine('n2', 'f2', colorFrustum);
  28724. addLine('n3', 'f3', colorFrustum);
  28725. addLine('n4', 'f4', colorFrustum); // cone
  28726. addLine('p', 'n1', colorCone);
  28727. addLine('p', 'n2', colorCone);
  28728. addLine('p', 'n3', colorCone);
  28729. addLine('p', 'n4', colorCone); // up
  28730. addLine('u1', 'u2', colorUp);
  28731. addLine('u2', 'u3', colorUp);
  28732. addLine('u3', 'u1', colorUp); // target
  28733. addLine('c', 't', colorTarget);
  28734. addLine('p', 'c', colorCross); // cross
  28735. addLine('cn1', 'cn2', colorCross);
  28736. addLine('cn3', 'cn4', colorCross);
  28737. addLine('cf1', 'cf2', colorCross);
  28738. addLine('cf3', 'cf4', colorCross);
  28739. function addLine(a, b, color) {
  28740. addPoint(a, color);
  28741. addPoint(b, color);
  28742. }
  28743. function addPoint(id, color) {
  28744. vertices.push(0, 0, 0);
  28745. colors.push(color.r, color.g, color.b);
  28746. if (pointMap[id] === undefined) {
  28747. pointMap[id] = [];
  28748. }
  28749. pointMap[id].push(vertices.length / 3 - 1);
  28750. }
  28751. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28752. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28753. _this = _LineSegments.call(this, geometry, material) || this;
  28754. _this.type = 'CameraHelper';
  28755. _this.camera = camera;
  28756. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28757. _this.matrix = camera.matrixWorld;
  28758. _this.matrixAutoUpdate = false;
  28759. _this.pointMap = pointMap;
  28760. _this.update();
  28761. return _this;
  28762. }
  28763. var _proto = CameraHelper.prototype;
  28764. _proto.update = function update() {
  28765. var geometry = this.geometry;
  28766. var pointMap = this.pointMap;
  28767. var w = 1,
  28768. h = 1; // we need just camera projection matrix inverse
  28769. // world matrix must be identity
  28770. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28771. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28772. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28773. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28774. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28775. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28776. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28777. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28778. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28779. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28780. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28781. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28782. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28783. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28784. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28785. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28786. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28787. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28788. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28789. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28790. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28791. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28792. geometry.getAttribute('position').needsUpdate = true;
  28793. };
  28794. return CameraHelper;
  28795. }(LineSegments);
  28796. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28797. _vector$c.set(x, y, z).unproject(camera);
  28798. var points = pointMap[point];
  28799. if (points !== undefined) {
  28800. var position = geometry.getAttribute('position');
  28801. for (var i = 0, l = points.length; i < l; i++) {
  28802. position.setXYZ(points[i], _vector$c.x, _vector$c.y, _vector$c.z);
  28803. }
  28804. }
  28805. }
  28806. var _box$3 = /*@__PURE__*/new Box3();
  28807. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28808. _inheritsLoose(BoxHelper, _LineSegments);
  28809. function BoxHelper(object, color) {
  28810. var _this;
  28811. if (color === void 0) {
  28812. color = 0xffff00;
  28813. }
  28814. 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]);
  28815. var positions = new Float32Array(8 * 3);
  28816. var geometry = new BufferGeometry();
  28817. geometry.setIndex(new BufferAttribute(indices, 1));
  28818. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28819. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28820. color: color,
  28821. toneMapped: false
  28822. })) || this;
  28823. _this.object = object;
  28824. _this.type = 'BoxHelper';
  28825. _this.matrixAutoUpdate = false;
  28826. _this.update();
  28827. return _this;
  28828. }
  28829. var _proto = BoxHelper.prototype;
  28830. _proto.update = function update(object) {
  28831. if (object !== undefined) {
  28832. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28833. }
  28834. if (this.object !== undefined) {
  28835. _box$3.setFromObject(this.object);
  28836. }
  28837. if (_box$3.isEmpty()) return;
  28838. var min = _box$3.min;
  28839. var max = _box$3.max;
  28840. /*
  28841. 5____4
  28842. 1/___0/|
  28843. | 6__|_7
  28844. 2/___3/
  28845. 0: max.x, max.y, max.z
  28846. 1: min.x, max.y, max.z
  28847. 2: min.x, min.y, max.z
  28848. 3: max.x, min.y, max.z
  28849. 4: max.x, max.y, min.z
  28850. 5: min.x, max.y, min.z
  28851. 6: min.x, min.y, min.z
  28852. 7: max.x, min.y, min.z
  28853. */
  28854. var position = this.geometry.attributes.position;
  28855. var array = position.array;
  28856. array[0] = max.x;
  28857. array[1] = max.y;
  28858. array[2] = max.z;
  28859. array[3] = min.x;
  28860. array[4] = max.y;
  28861. array[5] = max.z;
  28862. array[6] = min.x;
  28863. array[7] = min.y;
  28864. array[8] = max.z;
  28865. array[9] = max.x;
  28866. array[10] = min.y;
  28867. array[11] = max.z;
  28868. array[12] = max.x;
  28869. array[13] = max.y;
  28870. array[14] = min.z;
  28871. array[15] = min.x;
  28872. array[16] = max.y;
  28873. array[17] = min.z;
  28874. array[18] = min.x;
  28875. array[19] = min.y;
  28876. array[20] = min.z;
  28877. array[21] = max.x;
  28878. array[22] = min.y;
  28879. array[23] = min.z;
  28880. position.needsUpdate = true;
  28881. this.geometry.computeBoundingSphere();
  28882. };
  28883. _proto.setFromObject = function setFromObject(object) {
  28884. this.object = object;
  28885. this.update();
  28886. return this;
  28887. };
  28888. _proto.copy = function copy(source) {
  28889. LineSegments.prototype.copy.call(this, source);
  28890. this.object = source.object;
  28891. return this;
  28892. };
  28893. return BoxHelper;
  28894. }(LineSegments);
  28895. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28896. _inheritsLoose(Box3Helper, _LineSegments);
  28897. function Box3Helper(box, color) {
  28898. var _this;
  28899. if (color === void 0) {
  28900. color = 0xffff00;
  28901. }
  28902. 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]);
  28903. 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];
  28904. var geometry = new BufferGeometry();
  28905. geometry.setIndex(new BufferAttribute(indices, 1));
  28906. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28907. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28908. color: color,
  28909. toneMapped: false
  28910. })) || this;
  28911. _this.box = box;
  28912. _this.type = 'Box3Helper';
  28913. _this.geometry.computeBoundingSphere();
  28914. return _this;
  28915. }
  28916. var _proto = Box3Helper.prototype;
  28917. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28918. var box = this.box;
  28919. if (box.isEmpty()) return;
  28920. box.getCenter(this.position);
  28921. box.getSize(this.scale);
  28922. this.scale.multiplyScalar(0.5);
  28923. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28924. };
  28925. return Box3Helper;
  28926. }(LineSegments);
  28927. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28928. _inheritsLoose(PlaneHelper, _Line);
  28929. function PlaneHelper(plane, size, hex) {
  28930. var _this;
  28931. if (size === void 0) {
  28932. size = 1;
  28933. }
  28934. if (hex === void 0) {
  28935. hex = 0xffff00;
  28936. }
  28937. var color = hex;
  28938. 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];
  28939. var geometry = new BufferGeometry();
  28940. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28941. geometry.computeBoundingSphere();
  28942. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28943. color: color,
  28944. toneMapped: false
  28945. })) || this;
  28946. _this.type = 'PlaneHelper';
  28947. _this.plane = plane;
  28948. _this.size = size;
  28949. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28950. var geometry2 = new BufferGeometry();
  28951. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28952. geometry2.computeBoundingSphere();
  28953. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28954. color: color,
  28955. opacity: 0.2,
  28956. transparent: true,
  28957. depthWrite: false,
  28958. toneMapped: false
  28959. })));
  28960. return _this;
  28961. }
  28962. var _proto = PlaneHelper.prototype;
  28963. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28964. var scale = -this.plane.constant;
  28965. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28966. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28967. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28968. this.lookAt(this.plane.normal);
  28969. _Line.prototype.updateMatrixWorld.call(this, force);
  28970. };
  28971. return PlaneHelper;
  28972. }(Line);
  28973. var _axis = /*@__PURE__*/new Vector3();
  28974. var _lineGeometry, _coneGeometry;
  28975. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28976. _inheritsLoose(ArrowHelper, _Object3D);
  28977. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28978. var _this;
  28979. _this = _Object3D.call(this) || this; // dir is assumed to be normalized
  28980. _this.type = 'ArrowHelper';
  28981. if (dir === undefined) dir = new Vector3(0, 0, 1);
  28982. if (origin === undefined) origin = new Vector3(0, 0, 0);
  28983. if (length === undefined) length = 1;
  28984. if (color === undefined) color = 0xffff00;
  28985. if (headLength === undefined) headLength = 0.2 * length;
  28986. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28987. if (_lineGeometry === undefined) {
  28988. _lineGeometry = new BufferGeometry();
  28989. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28990. _coneGeometry = new CylinderBufferGeometry(0, 0.5, 1, 5, 1);
  28991. _coneGeometry.translate(0, -0.5, 0);
  28992. }
  28993. _this.position.copy(origin);
  28994. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28995. color: color,
  28996. toneMapped: false
  28997. }));
  28998. _this.line.matrixAutoUpdate = false;
  28999. _this.add(_this.line);
  29000. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  29001. color: color,
  29002. toneMapped: false
  29003. }));
  29004. _this.cone.matrixAutoUpdate = false;
  29005. _this.add(_this.cone);
  29006. _this.setDirection(dir);
  29007. _this.setLength(length, headLength, headWidth);
  29008. return _this;
  29009. }
  29010. var _proto = ArrowHelper.prototype;
  29011. _proto.setDirection = function setDirection(dir) {
  29012. // dir is assumed to be normalized
  29013. if (dir.y > 0.99999) {
  29014. this.quaternion.set(0, 0, 0, 1);
  29015. } else if (dir.y < -0.99999) {
  29016. this.quaternion.set(1, 0, 0, 0);
  29017. } else {
  29018. _axis.set(dir.z, 0, -dir.x).normalize();
  29019. var radians = Math.acos(dir.y);
  29020. this.quaternion.setFromAxisAngle(_axis, radians);
  29021. }
  29022. };
  29023. _proto.setLength = function setLength(length, headLength, headWidth) {
  29024. if (headLength === undefined) headLength = 0.2 * length;
  29025. if (headWidth === undefined) headWidth = 0.2 * headLength;
  29026. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  29027. this.line.updateMatrix();
  29028. this.cone.scale.set(headWidth, headLength, headWidth);
  29029. this.cone.position.y = length;
  29030. this.cone.updateMatrix();
  29031. };
  29032. _proto.setColor = function setColor(color) {
  29033. this.line.material.color.set(color);
  29034. this.cone.material.color.set(color);
  29035. };
  29036. _proto.copy = function copy(source) {
  29037. _Object3D.prototype.copy.call(this, source, false);
  29038. this.line.copy(source.line);
  29039. this.cone.copy(source.cone);
  29040. return this;
  29041. };
  29042. return ArrowHelper;
  29043. }(Object3D);
  29044. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  29045. _inheritsLoose(AxesHelper, _LineSegments);
  29046. function AxesHelper(size) {
  29047. var _this;
  29048. if (size === void 0) {
  29049. size = 1;
  29050. }
  29051. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  29052. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  29053. var geometry = new BufferGeometry();
  29054. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  29055. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  29056. var material = new LineBasicMaterial({
  29057. vertexColors: true,
  29058. toneMapped: false
  29059. });
  29060. _this = _LineSegments.call(this, geometry, material) || this;
  29061. _this.type = 'AxesHelper';
  29062. return _this;
  29063. }
  29064. return AxesHelper;
  29065. }(LineSegments);
  29066. var _floatView = new Float32Array(1);
  29067. var _int32View = new Int32Array(_floatView.buffer);
  29068. var DataUtils = {
  29069. // Converts float32 to float16 (stored as uint16 value).
  29070. toHalfFloat: function toHalfFloat(val) {
  29071. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  29072. /* This method is faster than the OpenEXR implementation (very often
  29073. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  29074. * by James Tursa?s half-precision code. */
  29075. _floatView[0] = val;
  29076. var x = _int32View[0];
  29077. var bits = x >> 16 & 0x8000;
  29078. /* Get the sign */
  29079. var m = x >> 12 & 0x07ff;
  29080. /* Keep one extra bit for rounding */
  29081. var e = x >> 23 & 0xff;
  29082. /* Using int is faster here */
  29083. /* If zero, or denormal, or exponent underflows too much for a denormal
  29084. * half, return signed zero. */
  29085. if (e < 103) return bits;
  29086. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  29087. if (e > 142) {
  29088. bits |= 0x7c00;
  29089. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  29090. * not Inf, so make sure we set one mantissa bit too. */
  29091. bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
  29092. return bits;
  29093. }
  29094. /* If exponent underflows but not too much, return a denormal */
  29095. if (e < 113) {
  29096. m |= 0x0800;
  29097. /* Extra rounding may overflow and set mantissa to 0 and exponent
  29098. * to 1, which is OK. */
  29099. bits |= (m >> 114 - e) + (m >> 113 - e & 1);
  29100. return bits;
  29101. }
  29102. bits |= e - 112 << 10 | m >> 1;
  29103. /* Extra rounding. An overflow will set mantissa to 0 and increment
  29104. * the exponent, which is OK. */
  29105. bits += m & 1;
  29106. return bits;
  29107. }
  29108. };
  29109. var _ENCODINGS;
  29110. var LOD_MIN = 4;
  29111. var LOD_MAX = 8;
  29112. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  29113. // chosen to approximate a Trowbridge-Reitz distribution function times the
  29114. // geometric shadowing function. These sigma values squared must match the
  29115. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  29116. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  29117. 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
  29118. // samples and exit early, but not recompile the shader.
  29119. var MAX_SAMPLES = 20;
  29120. 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);
  29121. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  29122. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  29123. _lodPlanes = _createPlanes2._lodPlanes,
  29124. _sizeLods = _createPlanes2._sizeLods,
  29125. _sigmas = _createPlanes2._sigmas;
  29126. var _clearColor = /*@__PURE__*/new Color();
  29127. var _oldTarget = null; // Golden Ratio
  29128. var PHI = (1 + Math.sqrt(5)) / 2;
  29129. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  29130. // same axis), used as axis directions evenly spread on a sphere.
  29131. 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)];
  29132. /**
  29133. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  29134. * (PMREM) from a cubeMap environment texture. This allows different levels of
  29135. * blur to be quickly accessed based on material roughness. It is packed into a
  29136. * special CubeUV format that allows us to perform custom interpolation so that
  29137. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  29138. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  29139. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  29140. * higher roughness levels. In this way we maintain resolution to smoothly
  29141. * interpolate diffuse lighting while limiting sampling computation.
  29142. */
  29143. var PMREMGenerator = /*#__PURE__*/function () {
  29144. function PMREMGenerator(renderer) {
  29145. this._renderer = renderer;
  29146. this._pingPongRenderTarget = null;
  29147. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  29148. this._equirectShader = null;
  29149. this._cubemapShader = null;
  29150. this._compileMaterial(this._blurMaterial);
  29151. }
  29152. /**
  29153. * Generates a PMREM from a supplied Scene, which can be faster than using an
  29154. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  29155. * in radians to be applied to the scene before PMREM generation. Optional near
  29156. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  29157. * is placed at the origin).
  29158. */
  29159. var _proto = PMREMGenerator.prototype;
  29160. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  29161. if (sigma === void 0) {
  29162. sigma = 0;
  29163. }
  29164. if (near === void 0) {
  29165. near = 0.1;
  29166. }
  29167. if (far === void 0) {
  29168. far = 100;
  29169. }
  29170. _oldTarget = this._renderer.getRenderTarget();
  29171. var cubeUVRenderTarget = this._allocateTargets();
  29172. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  29173. if (sigma > 0) {
  29174. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  29175. }
  29176. this._applyPMREM(cubeUVRenderTarget);
  29177. this._cleanup(cubeUVRenderTarget);
  29178. return cubeUVRenderTarget;
  29179. }
  29180. /**
  29181. * Generates a PMREM from an equirectangular texture, which can be either LDR
  29182. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  29183. * as this matches best with the 256 x 256 cubemap output.
  29184. */
  29185. ;
  29186. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  29187. return this._fromTexture(equirectangular);
  29188. }
  29189. /**
  29190. * Generates a PMREM from an cubemap texture, which can be either LDR
  29191. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  29192. * as this matches best with the 256 x 256 cubemap output.
  29193. */
  29194. ;
  29195. _proto.fromCubemap = function fromCubemap(cubemap) {
  29196. return this._fromTexture(cubemap);
  29197. }
  29198. /**
  29199. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  29200. * your texture's network fetch for increased concurrency.
  29201. */
  29202. ;
  29203. _proto.compileCubemapShader = function compileCubemapShader() {
  29204. if (this._cubemapShader === null) {
  29205. this._cubemapShader = _getCubemapShader();
  29206. this._compileMaterial(this._cubemapShader);
  29207. }
  29208. }
  29209. /**
  29210. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  29211. * your texture's network fetch for increased concurrency.
  29212. */
  29213. ;
  29214. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  29215. if (this._equirectShader === null) {
  29216. this._equirectShader = _getEquirectShader();
  29217. this._compileMaterial(this._equirectShader);
  29218. }
  29219. }
  29220. /**
  29221. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  29222. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  29223. * one of them will cause any others to also become unusable.
  29224. */
  29225. ;
  29226. _proto.dispose = function dispose() {
  29227. this._blurMaterial.dispose();
  29228. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  29229. if (this._equirectShader !== null) this._equirectShader.dispose();
  29230. for (var i = 0; i < _lodPlanes.length; i++) {
  29231. _lodPlanes[i].dispose();
  29232. }
  29233. } // private interface
  29234. ;
  29235. _proto._cleanup = function _cleanup(outputTarget) {
  29236. this._pingPongRenderTarget.dispose();
  29237. this._renderer.setRenderTarget(_oldTarget);
  29238. outputTarget.scissorTest = false;
  29239. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  29240. };
  29241. _proto._fromTexture = function _fromTexture(texture) {
  29242. _oldTarget = this._renderer.getRenderTarget();
  29243. var cubeUVRenderTarget = this._allocateTargets(texture);
  29244. this._textureToCubeUV(texture, cubeUVRenderTarget);
  29245. this._applyPMREM(cubeUVRenderTarget);
  29246. this._cleanup(cubeUVRenderTarget);
  29247. return cubeUVRenderTarget;
  29248. };
  29249. _proto._allocateTargets = function _allocateTargets(texture) {
  29250. // warning: null texture is valid
  29251. var params = {
  29252. magFilter: NearestFilter,
  29253. minFilter: NearestFilter,
  29254. generateMipmaps: false,
  29255. type: UnsignedByteType,
  29256. format: RGBEFormat,
  29257. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  29258. depthBuffer: false
  29259. };
  29260. var cubeUVRenderTarget = _createRenderTarget(params);
  29261. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  29262. this._pingPongRenderTarget = _createRenderTarget(params);
  29263. return cubeUVRenderTarget;
  29264. };
  29265. _proto._compileMaterial = function _compileMaterial(material) {
  29266. var tmpMesh = new Mesh(_lodPlanes[0], material);
  29267. this._renderer.compile(tmpMesh, _flatCamera);
  29268. };
  29269. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  29270. var fov = 90;
  29271. var aspect = 1;
  29272. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  29273. var upSign = [1, -1, 1, 1, 1, 1];
  29274. var forwardSign = [1, 1, 1, -1, -1, -1];
  29275. var renderer = this._renderer;
  29276. var outputEncoding = renderer.outputEncoding;
  29277. var toneMapping = renderer.toneMapping;
  29278. renderer.getClearColor(_clearColor);
  29279. var clearAlpha = renderer.getClearAlpha();
  29280. renderer.toneMapping = NoToneMapping;
  29281. renderer.outputEncoding = LinearEncoding;
  29282. var background = scene.background;
  29283. if (background && background.isColor) {
  29284. background.convertSRGBToLinear(); // Convert linear to RGBE
  29285. var maxComponent = Math.max(background.r, background.g, background.b);
  29286. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  29287. background = background.multiplyScalar(Math.pow(2.0, -fExp));
  29288. var alpha = (fExp + 128.0) / 255.0;
  29289. renderer.setClearColor(background, alpha);
  29290. scene.background = null;
  29291. }
  29292. for (var i = 0; i < 6; i++) {
  29293. var col = i % 3;
  29294. if (col == 0) {
  29295. cubeCamera.up.set(0, upSign[i], 0);
  29296. cubeCamera.lookAt(forwardSign[i], 0, 0);
  29297. } else if (col == 1) {
  29298. cubeCamera.up.set(0, 0, upSign[i]);
  29299. cubeCamera.lookAt(0, forwardSign[i], 0);
  29300. } else {
  29301. cubeCamera.up.set(0, upSign[i], 0);
  29302. cubeCamera.lookAt(0, 0, forwardSign[i]);
  29303. }
  29304. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  29305. renderer.setRenderTarget(cubeUVRenderTarget);
  29306. renderer.render(scene, cubeCamera);
  29307. }
  29308. renderer.toneMapping = toneMapping;
  29309. renderer.outputEncoding = outputEncoding;
  29310. renderer.setClearColor(_clearColor, clearAlpha);
  29311. };
  29312. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  29313. var renderer = this._renderer;
  29314. if (texture.isCubeTexture) {
  29315. if (this._cubemapShader == null) {
  29316. this._cubemapShader = _getCubemapShader();
  29317. }
  29318. } else {
  29319. if (this._equirectShader == null) {
  29320. this._equirectShader = _getEquirectShader();
  29321. }
  29322. }
  29323. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  29324. var mesh = new Mesh(_lodPlanes[0], material);
  29325. var uniforms = material.uniforms;
  29326. uniforms['envMap'].value = texture;
  29327. if (!texture.isCubeTexture) {
  29328. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  29329. }
  29330. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  29331. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  29332. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  29333. renderer.setRenderTarget(cubeUVRenderTarget);
  29334. renderer.render(mesh, _flatCamera);
  29335. };
  29336. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  29337. var renderer = this._renderer;
  29338. var autoClear = renderer.autoClear;
  29339. renderer.autoClear = false;
  29340. for (var i = 1; i < TOTAL_LODS; i++) {
  29341. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  29342. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  29343. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  29344. }
  29345. renderer.autoClear = autoClear;
  29346. }
  29347. /**
  29348. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  29349. * vertically and horizontally, but this breaks down on a cube. Here we apply
  29350. * the blur latitudinally (around the poles), and then longitudinally (towards
  29351. * the poles) to approximate the orthogonally-separable blur. It is least
  29352. * accurate at the poles, but still does a decent job.
  29353. */
  29354. ;
  29355. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  29356. var pingPongRenderTarget = this._pingPongRenderTarget;
  29357. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  29358. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  29359. };
  29360. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  29361. var renderer = this._renderer;
  29362. var blurMaterial = this._blurMaterial;
  29363. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  29364. console.error('blur direction must be either latitudinal or longitudinal!');
  29365. } // Number of standard deviations at which to cut off the discrete approximation.
  29366. var STANDARD_DEVIATIONS = 3;
  29367. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  29368. var blurUniforms = blurMaterial.uniforms;
  29369. var pixels = _sizeLods[lodIn] - 1;
  29370. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  29371. var sigmaPixels = sigmaRadians / radiansPerPixel;
  29372. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  29373. if (samples > MAX_SAMPLES) {
  29374. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  29375. }
  29376. var weights = [];
  29377. var sum = 0;
  29378. for (var i = 0; i < MAX_SAMPLES; ++i) {
  29379. var _x = i / sigmaPixels;
  29380. var weight = Math.exp(-_x * _x / 2);
  29381. weights.push(weight);
  29382. if (i == 0) {
  29383. sum += weight;
  29384. } else if (i < samples) {
  29385. sum += 2 * weight;
  29386. }
  29387. }
  29388. for (var _i = 0; _i < weights.length; _i++) {
  29389. weights[_i] = weights[_i] / sum;
  29390. }
  29391. blurUniforms['envMap'].value = targetIn.texture;
  29392. blurUniforms['samples'].value = samples;
  29393. blurUniforms['weights'].value = weights;
  29394. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  29395. if (poleAxis) {
  29396. blurUniforms['poleAxis'].value = poleAxis;
  29397. }
  29398. blurUniforms['dTheta'].value = radiansPerPixel;
  29399. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  29400. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  29401. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  29402. var outputSize = _sizeLods[lodOut];
  29403. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  29404. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  29405. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  29406. renderer.setRenderTarget(targetOut);
  29407. renderer.render(blurMesh, _flatCamera);
  29408. };
  29409. return PMREMGenerator;
  29410. }();
  29411. function _isLDR(texture) {
  29412. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  29413. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  29414. }
  29415. function _createPlanes() {
  29416. var _lodPlanes = [];
  29417. var _sizeLods = [];
  29418. var _sigmas = [];
  29419. var lod = LOD_MAX;
  29420. for (var i = 0; i < TOTAL_LODS; i++) {
  29421. var sizeLod = Math.pow(2, lod);
  29422. _sizeLods.push(sizeLod);
  29423. var sigma = 1.0 / sizeLod;
  29424. if (i > LOD_MAX - LOD_MIN) {
  29425. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  29426. } else if (i == 0) {
  29427. sigma = 0;
  29428. }
  29429. _sigmas.push(sigma);
  29430. var texelSize = 1.0 / (sizeLod - 1);
  29431. var min = -texelSize / 2;
  29432. var max = 1 + texelSize / 2;
  29433. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  29434. var cubeFaces = 6;
  29435. var vertices = 6;
  29436. var positionSize = 3;
  29437. var uvSize = 2;
  29438. var faceIndexSize = 1;
  29439. var position = new Float32Array(positionSize * vertices * cubeFaces);
  29440. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  29441. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  29442. for (var face = 0; face < cubeFaces; face++) {
  29443. var x = face % 3 * 2 / 3 - 1;
  29444. var y = face > 2 ? 0 : -1;
  29445. 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];
  29446. position.set(coordinates, positionSize * vertices * face);
  29447. uv.set(uv1, uvSize * vertices * face);
  29448. var fill = [face, face, face, face, face, face];
  29449. faceIndex.set(fill, faceIndexSize * vertices * face);
  29450. }
  29451. var planes = new BufferGeometry();
  29452. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  29453. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  29454. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  29455. _lodPlanes.push(planes);
  29456. if (lod > LOD_MIN) {
  29457. lod--;
  29458. }
  29459. }
  29460. return {
  29461. _lodPlanes: _lodPlanes,
  29462. _sizeLods: _sizeLods,
  29463. _sigmas: _sigmas
  29464. };
  29465. }
  29466. function _createRenderTarget(params) {
  29467. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  29468. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  29469. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  29470. cubeUVRenderTarget.scissorTest = true;
  29471. return cubeUVRenderTarget;
  29472. }
  29473. function _setViewport(target, x, y, width, height) {
  29474. target.viewport.set(x, y, width, height);
  29475. target.scissor.set(x, y, width, height);
  29476. }
  29477. function _getBlurShader(maxSamples) {
  29478. var weights = new Float32Array(maxSamples);
  29479. var poleAxis = new Vector3(0, 1, 0);
  29480. var shaderMaterial = new RawShaderMaterial({
  29481. name: 'SphericalGaussianBlur',
  29482. defines: {
  29483. 'n': maxSamples
  29484. },
  29485. uniforms: {
  29486. 'envMap': {
  29487. value: null
  29488. },
  29489. 'samples': {
  29490. value: 1
  29491. },
  29492. 'weights': {
  29493. value: weights
  29494. },
  29495. 'latitudinal': {
  29496. value: false
  29497. },
  29498. 'dTheta': {
  29499. value: 0
  29500. },
  29501. 'mipInt': {
  29502. value: 0
  29503. },
  29504. 'poleAxis': {
  29505. value: poleAxis
  29506. },
  29507. 'inputEncoding': {
  29508. value: ENCODINGS[LinearEncoding]
  29509. },
  29510. 'outputEncoding': {
  29511. value: ENCODINGS[LinearEncoding]
  29512. }
  29513. },
  29514. vertexShader: _getCommonVertexShader(),
  29515. fragmentShader:
  29516. /* glsl */
  29517. "\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",
  29518. blending: NoBlending,
  29519. depthTest: false,
  29520. depthWrite: false
  29521. });
  29522. return shaderMaterial;
  29523. }
  29524. function _getEquirectShader() {
  29525. var texelSize = new Vector2(1, 1);
  29526. var shaderMaterial = new RawShaderMaterial({
  29527. name: 'EquirectangularToCubeUV',
  29528. uniforms: {
  29529. 'envMap': {
  29530. value: null
  29531. },
  29532. 'texelSize': {
  29533. value: texelSize
  29534. },
  29535. 'inputEncoding': {
  29536. value: ENCODINGS[LinearEncoding]
  29537. },
  29538. 'outputEncoding': {
  29539. value: ENCODINGS[LinearEncoding]
  29540. }
  29541. },
  29542. vertexShader: _getCommonVertexShader(),
  29543. fragmentShader:
  29544. /* glsl */
  29545. "\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",
  29546. blending: NoBlending,
  29547. depthTest: false,
  29548. depthWrite: false
  29549. });
  29550. return shaderMaterial;
  29551. }
  29552. function _getCubemapShader() {
  29553. var shaderMaterial = new RawShaderMaterial({
  29554. name: 'CubemapToCubeUV',
  29555. uniforms: {
  29556. 'envMap': {
  29557. value: null
  29558. },
  29559. 'inputEncoding': {
  29560. value: ENCODINGS[LinearEncoding]
  29561. },
  29562. 'outputEncoding': {
  29563. value: ENCODINGS[LinearEncoding]
  29564. }
  29565. },
  29566. vertexShader: _getCommonVertexShader(),
  29567. fragmentShader:
  29568. /* glsl */
  29569. "\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",
  29570. blending: NoBlending,
  29571. depthTest: false,
  29572. depthWrite: false
  29573. });
  29574. return shaderMaterial;
  29575. }
  29576. function _getCommonVertexShader() {
  29577. return (
  29578. /* glsl */
  29579. "\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"
  29580. );
  29581. }
  29582. function _getEncodings() {
  29583. return (
  29584. /* glsl */
  29585. "\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"
  29586. );
  29587. }
  29588. function Face4(a, b, c, d, normal, color, materialIndex) {
  29589. console.warn('THREE.Face4 has been removed. A THREE.Face3 will be created instead.');
  29590. return new Face3(a, b, c, normal, color, materialIndex);
  29591. }
  29592. var LineStrip = 0;
  29593. var LinePieces = 1;
  29594. var NoColors = 0;
  29595. var FaceColors = 1;
  29596. var VertexColors = 2;
  29597. function MeshFaceMaterial(materials) {
  29598. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  29599. return materials;
  29600. }
  29601. function MultiMaterial(materials) {
  29602. if (materials === void 0) {
  29603. materials = [];
  29604. }
  29605. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  29606. materials.isMultiMaterial = true;
  29607. materials.materials = materials;
  29608. materials.clone = function () {
  29609. return materials.slice();
  29610. };
  29611. return materials;
  29612. }
  29613. function PointCloud(geometry, material) {
  29614. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  29615. return new Points(geometry, material);
  29616. }
  29617. function Particle(material) {
  29618. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  29619. return new Sprite(material);
  29620. }
  29621. function ParticleSystem(geometry, material) {
  29622. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  29623. return new Points(geometry, material);
  29624. }
  29625. function PointCloudMaterial(parameters) {
  29626. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  29627. return new PointsMaterial(parameters);
  29628. }
  29629. function ParticleBasicMaterial(parameters) {
  29630. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  29631. return new PointsMaterial(parameters);
  29632. }
  29633. function ParticleSystemMaterial(parameters) {
  29634. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  29635. return new PointsMaterial(parameters);
  29636. }
  29637. function Vertex(x, y, z) {
  29638. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  29639. return new Vector3(x, y, z);
  29640. } //
  29641. function DynamicBufferAttribute(array, itemSize) {
  29642. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  29643. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  29644. }
  29645. function Int8Attribute(array, itemSize) {
  29646. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  29647. return new Int8BufferAttribute(array, itemSize);
  29648. }
  29649. function Uint8Attribute(array, itemSize) {
  29650. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  29651. return new Uint8BufferAttribute(array, itemSize);
  29652. }
  29653. function Uint8ClampedAttribute(array, itemSize) {
  29654. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  29655. return new Uint8ClampedBufferAttribute(array, itemSize);
  29656. }
  29657. function Int16Attribute(array, itemSize) {
  29658. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  29659. return new Int16BufferAttribute(array, itemSize);
  29660. }
  29661. function Uint16Attribute(array, itemSize) {
  29662. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  29663. return new Uint16BufferAttribute(array, itemSize);
  29664. }
  29665. function Int32Attribute(array, itemSize) {
  29666. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  29667. return new Int32BufferAttribute(array, itemSize);
  29668. }
  29669. function Uint32Attribute(array, itemSize) {
  29670. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  29671. return new Uint32BufferAttribute(array, itemSize);
  29672. }
  29673. function Float32Attribute(array, itemSize) {
  29674. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  29675. return new Float32BufferAttribute(array, itemSize);
  29676. }
  29677. function Float64Attribute(array, itemSize) {
  29678. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  29679. return new Float64BufferAttribute(array, itemSize);
  29680. } //
  29681. Curve.create = function (construct, getPoint) {
  29682. console.log('THREE.Curve.create() has been deprecated');
  29683. construct.prototype = Object.create(Curve.prototype);
  29684. construct.prototype.constructor = construct;
  29685. construct.prototype.getPoint = getPoint;
  29686. return construct;
  29687. }; //
  29688. Object.assign(CurvePath.prototype, {
  29689. createPointsGeometry: function createPointsGeometry(divisions) {
  29690. 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)
  29691. var pts = this.getPoints(divisions);
  29692. return this.createGeometry(pts);
  29693. },
  29694. createSpacedPointsGeometry: function createSpacedPointsGeometry(divisions) {
  29695. console.warn('THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.'); // generate geometry from equidistant sampling along the path
  29696. var pts = this.getSpacedPoints(divisions);
  29697. return this.createGeometry(pts);
  29698. },
  29699. createGeometry: function createGeometry(points) {
  29700. console.warn('THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');
  29701. var geometry = new Geometry();
  29702. for (var i = 0, l = points.length; i < l; i++) {
  29703. var point = points[i];
  29704. geometry.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  29705. }
  29706. return geometry;
  29707. }
  29708. }); //
  29709. Object.assign(Path.prototype, {
  29710. fromPoints: function fromPoints(points) {
  29711. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  29712. return this.setFromPoints(points);
  29713. }
  29714. }); //
  29715. function ClosedSplineCurve3(points) {
  29716. console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29717. CatmullRomCurve3.call(this, points);
  29718. this.type = 'catmullrom';
  29719. this.closed = true;
  29720. }
  29721. ClosedSplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29722. function SplineCurve3(points) {
  29723. console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29724. CatmullRomCurve3.call(this, points);
  29725. this.type = 'catmullrom';
  29726. }
  29727. SplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29728. function Spline(points) {
  29729. console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');
  29730. CatmullRomCurve3.call(this, points);
  29731. this.type = 'catmullrom';
  29732. }
  29733. Spline.prototype = Object.create(CatmullRomCurve3.prototype);
  29734. Object.assign(Spline.prototype, {
  29735. initFromArray: function initFromArray()
  29736. /* a */
  29737. {
  29738. console.error('THREE.Spline: .initFromArray() has been removed.');
  29739. },
  29740. getControlPointsArray: function getControlPointsArray()
  29741. /* optionalTarget */
  29742. {
  29743. console.error('THREE.Spline: .getControlPointsArray() has been removed.');
  29744. },
  29745. reparametrizeByArcLength: function reparametrizeByArcLength()
  29746. /* samplingCoef */
  29747. {
  29748. console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');
  29749. }
  29750. }); //
  29751. function AxisHelper(size) {
  29752. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  29753. return new AxesHelper(size);
  29754. }
  29755. function BoundingBoxHelper(object, color) {
  29756. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  29757. return new BoxHelper(object, color);
  29758. }
  29759. function EdgesHelper(object, hex) {
  29760. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  29761. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  29762. color: hex !== undefined ? hex : 0xffffff
  29763. }));
  29764. }
  29765. GridHelper.prototype.setColors = function () {
  29766. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  29767. };
  29768. SkeletonHelper.prototype.update = function () {
  29769. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  29770. };
  29771. function WireframeHelper(object, hex) {
  29772. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  29773. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  29774. color: hex !== undefined ? hex : 0xffffff
  29775. }));
  29776. } //
  29777. Object.assign(Loader.prototype, {
  29778. extractUrlBase: function extractUrlBase(url) {
  29779. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  29780. return LoaderUtils.extractUrlBase(url);
  29781. }
  29782. });
  29783. Loader.Handlers = {
  29784. add: function add()
  29785. /* regex, loader */
  29786. {
  29787. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  29788. },
  29789. get: function get()
  29790. /* file */
  29791. {
  29792. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  29793. }
  29794. };
  29795. function XHRLoader(manager) {
  29796. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  29797. return new FileLoader(manager);
  29798. }
  29799. function BinaryTextureLoader(manager) {
  29800. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29801. return new DataTextureLoader(manager);
  29802. } //
  29803. Object.assign(Box2.prototype, {
  29804. center: function center(optionalTarget) {
  29805. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29806. return this.getCenter(optionalTarget);
  29807. },
  29808. empty: function empty() {
  29809. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29810. return this.isEmpty();
  29811. },
  29812. isIntersectionBox: function isIntersectionBox(box) {
  29813. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29814. return this.intersectsBox(box);
  29815. },
  29816. size: function size(optionalTarget) {
  29817. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29818. return this.getSize(optionalTarget);
  29819. }
  29820. });
  29821. Object.assign(Box3.prototype, {
  29822. center: function center(optionalTarget) {
  29823. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29824. return this.getCenter(optionalTarget);
  29825. },
  29826. empty: function empty() {
  29827. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29828. return this.isEmpty();
  29829. },
  29830. isIntersectionBox: function isIntersectionBox(box) {
  29831. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29832. return this.intersectsBox(box);
  29833. },
  29834. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29835. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29836. return this.intersectsSphere(sphere);
  29837. },
  29838. size: function size(optionalTarget) {
  29839. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29840. return this.getSize(optionalTarget);
  29841. }
  29842. });
  29843. Object.assign(Sphere.prototype, {
  29844. empty: function empty() {
  29845. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29846. return this.isEmpty();
  29847. }
  29848. });
  29849. Frustum.prototype.setFromMatrix = function (m) {
  29850. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29851. return this.setFromProjectionMatrix(m);
  29852. };
  29853. Line3.prototype.center = function (optionalTarget) {
  29854. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29855. return this.getCenter(optionalTarget);
  29856. };
  29857. Object.assign(MathUtils, {
  29858. random16: function random16() {
  29859. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29860. return Math.random();
  29861. },
  29862. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29863. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29864. return MathUtils.floorPowerOfTwo(value);
  29865. },
  29866. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29867. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29868. return MathUtils.ceilPowerOfTwo(value);
  29869. }
  29870. });
  29871. Object.assign(Matrix3.prototype, {
  29872. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29873. console.warn('THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29874. return this.toArray(array, offset);
  29875. },
  29876. multiplyVector3: function multiplyVector3(vector) {
  29877. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29878. return vector.applyMatrix3(this);
  29879. },
  29880. multiplyVector3Array: function multiplyVector3Array()
  29881. /* a */
  29882. {
  29883. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29884. },
  29885. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29886. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29887. return attribute.applyMatrix3(this);
  29888. },
  29889. applyToVector3Array: function applyToVector3Array()
  29890. /* array, offset, length */
  29891. {
  29892. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29893. },
  29894. getInverse: function getInverse(matrix) {
  29895. console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29896. return this.copy(matrix).invert();
  29897. }
  29898. });
  29899. Object.assign(Matrix4.prototype, {
  29900. extractPosition: function extractPosition(m) {
  29901. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29902. return this.copyPosition(m);
  29903. },
  29904. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29905. console.warn('THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29906. return this.toArray(array, offset);
  29907. },
  29908. getPosition: function getPosition() {
  29909. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29910. return new Vector3().setFromMatrixColumn(this, 3);
  29911. },
  29912. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29913. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29914. return this.makeRotationFromQuaternion(q);
  29915. },
  29916. multiplyToArray: function multiplyToArray() {
  29917. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29918. },
  29919. multiplyVector3: function multiplyVector3(vector) {
  29920. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29921. return vector.applyMatrix4(this);
  29922. },
  29923. multiplyVector4: function multiplyVector4(vector) {
  29924. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29925. return vector.applyMatrix4(this);
  29926. },
  29927. multiplyVector3Array: function multiplyVector3Array()
  29928. /* a */
  29929. {
  29930. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29931. },
  29932. rotateAxis: function rotateAxis(v) {
  29933. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29934. v.transformDirection(this);
  29935. },
  29936. crossVector: function crossVector(vector) {
  29937. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29938. return vector.applyMatrix4(this);
  29939. },
  29940. translate: function translate() {
  29941. console.error('THREE.Matrix4: .translate() has been removed.');
  29942. },
  29943. rotateX: function rotateX() {
  29944. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29945. },
  29946. rotateY: function rotateY() {
  29947. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29948. },
  29949. rotateZ: function rotateZ() {
  29950. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29951. },
  29952. rotateByAxis: function rotateByAxis() {
  29953. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29954. },
  29955. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29956. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29957. return attribute.applyMatrix4(this);
  29958. },
  29959. applyToVector3Array: function applyToVector3Array()
  29960. /* array, offset, length */
  29961. {
  29962. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29963. },
  29964. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29965. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29966. return this.makePerspective(left, right, top, bottom, near, far);
  29967. },
  29968. getInverse: function getInverse(matrix) {
  29969. console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29970. return this.copy(matrix).invert();
  29971. }
  29972. });
  29973. Plane.prototype.isIntersectionLine = function (line) {
  29974. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29975. return this.intersectsLine(line);
  29976. };
  29977. Object.assign(Quaternion.prototype, {
  29978. multiplyVector3: function multiplyVector3(vector) {
  29979. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29980. return vector.applyQuaternion(this);
  29981. },
  29982. inverse: function inverse() {
  29983. console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');
  29984. return this.invert();
  29985. }
  29986. });
  29987. Object.assign(Ray.prototype, {
  29988. isIntersectionBox: function isIntersectionBox(box) {
  29989. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29990. return this.intersectsBox(box);
  29991. },
  29992. isIntersectionPlane: function isIntersectionPlane(plane) {
  29993. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29994. return this.intersectsPlane(plane);
  29995. },
  29996. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29997. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29998. return this.intersectsSphere(sphere);
  29999. }
  30000. });
  30001. Object.assign(Triangle.prototype, {
  30002. area: function area() {
  30003. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  30004. return this.getArea();
  30005. },
  30006. barycoordFromPoint: function barycoordFromPoint(point, target) {
  30007. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  30008. return this.getBarycoord(point, target);
  30009. },
  30010. midpoint: function midpoint(target) {
  30011. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  30012. return this.getMidpoint(target);
  30013. },
  30014. normal: function normal(target) {
  30015. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  30016. return this.getNormal(target);
  30017. },
  30018. plane: function plane(target) {
  30019. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  30020. return this.getPlane(target);
  30021. }
  30022. });
  30023. Object.assign(Triangle, {
  30024. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  30025. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  30026. return Triangle.getBarycoord(point, a, b, c, target);
  30027. },
  30028. normal: function normal(a, b, c, target) {
  30029. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  30030. return Triangle.getNormal(a, b, c, target);
  30031. }
  30032. });
  30033. Object.assign(Shape.prototype, {
  30034. extractAllPoints: function extractAllPoints(divisions) {
  30035. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  30036. return this.extractPoints(divisions);
  30037. },
  30038. extrude: function extrude(options) {
  30039. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  30040. return new ExtrudeGeometry(this, options);
  30041. },
  30042. makeGeometry: function makeGeometry(options) {
  30043. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  30044. return new ShapeGeometry(this, options);
  30045. }
  30046. });
  30047. Object.assign(Vector2.prototype, {
  30048. fromAttribute: function fromAttribute(attribute, index, offset) {
  30049. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  30050. return this.fromBufferAttribute(attribute, index, offset);
  30051. },
  30052. distanceToManhattan: function distanceToManhattan(v) {
  30053. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  30054. return this.manhattanDistanceTo(v);
  30055. },
  30056. lengthManhattan: function lengthManhattan() {
  30057. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  30058. return this.manhattanLength();
  30059. }
  30060. });
  30061. Object.assign(Vector3.prototype, {
  30062. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  30063. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  30064. },
  30065. setEulerFromQuaternion: function setEulerFromQuaternion() {
  30066. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  30067. },
  30068. getPositionFromMatrix: function getPositionFromMatrix(m) {
  30069. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  30070. return this.setFromMatrixPosition(m);
  30071. },
  30072. getScaleFromMatrix: function getScaleFromMatrix(m) {
  30073. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  30074. return this.setFromMatrixScale(m);
  30075. },
  30076. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  30077. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  30078. return this.setFromMatrixColumn(matrix, index);
  30079. },
  30080. applyProjection: function applyProjection(m) {
  30081. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  30082. return this.applyMatrix4(m);
  30083. },
  30084. fromAttribute: function fromAttribute(attribute, index, offset) {
  30085. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  30086. return this.fromBufferAttribute(attribute, index, offset);
  30087. },
  30088. distanceToManhattan: function distanceToManhattan(v) {
  30089. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  30090. return this.manhattanDistanceTo(v);
  30091. },
  30092. lengthManhattan: function lengthManhattan() {
  30093. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  30094. return this.manhattanLength();
  30095. }
  30096. });
  30097. Object.assign(Vector4.prototype, {
  30098. fromAttribute: function fromAttribute(attribute, index, offset) {
  30099. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  30100. return this.fromBufferAttribute(attribute, index, offset);
  30101. },
  30102. lengthManhattan: function lengthManhattan() {
  30103. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  30104. return this.manhattanLength();
  30105. }
  30106. }); //
  30107. Object.assign(Geometry.prototype, {
  30108. computeTangents: function computeTangents() {
  30109. console.error('THREE.Geometry: .computeTangents() has been removed.');
  30110. },
  30111. computeLineDistances: function computeLineDistances() {
  30112. console.error('THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.');
  30113. },
  30114. applyMatrix: function applyMatrix(matrix) {
  30115. console.warn('THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().');
  30116. return this.applyMatrix4(matrix);
  30117. }
  30118. });
  30119. Object.assign(Object3D.prototype, {
  30120. getChildByName: function getChildByName(name) {
  30121. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  30122. return this.getObjectByName(name);
  30123. },
  30124. renderDepth: function renderDepth() {
  30125. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  30126. },
  30127. translate: function translate(distance, axis) {
  30128. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  30129. return this.translateOnAxis(axis, distance);
  30130. },
  30131. getWorldRotation: function getWorldRotation() {
  30132. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  30133. },
  30134. applyMatrix: function applyMatrix(matrix) {
  30135. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  30136. return this.applyMatrix4(matrix);
  30137. }
  30138. });
  30139. Object.defineProperties(Object3D.prototype, {
  30140. eulerOrder: {
  30141. get: function get() {
  30142. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  30143. return this.rotation.order;
  30144. },
  30145. set: function set(value) {
  30146. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  30147. this.rotation.order = value;
  30148. }
  30149. },
  30150. useQuaternion: {
  30151. get: function get() {
  30152. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  30153. },
  30154. set: function set() {
  30155. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  30156. }
  30157. }
  30158. });
  30159. Object.assign(Mesh.prototype, {
  30160. setDrawMode: function setDrawMode() {
  30161. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  30162. }
  30163. });
  30164. Object.defineProperties(Mesh.prototype, {
  30165. drawMode: {
  30166. get: function get() {
  30167. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  30168. return TrianglesDrawMode;
  30169. },
  30170. set: function set() {
  30171. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  30172. }
  30173. }
  30174. });
  30175. Object.defineProperties(LOD.prototype, {
  30176. objects: {
  30177. get: function get() {
  30178. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  30179. return this.levels;
  30180. }
  30181. }
  30182. });
  30183. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  30184. get: function get() {
  30185. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  30186. },
  30187. set: function set() {
  30188. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  30189. }
  30190. });
  30191. SkinnedMesh.prototype.initBones = function () {
  30192. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  30193. };
  30194. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  30195. get: function get() {
  30196. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  30197. return this.arcLengthDivisions;
  30198. },
  30199. set: function set(value) {
  30200. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  30201. this.arcLengthDivisions = value;
  30202. }
  30203. }); //
  30204. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  30205. console.warn('THREE.PerspectiveCamera.setLens is deprecated. ' + 'Use .setFocalLength and .filmGauge for a photographic setup.');
  30206. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  30207. this.setFocalLength(focalLength);
  30208. }; //
  30209. Object.defineProperties(Light.prototype, {
  30210. onlyShadow: {
  30211. set: function set() {
  30212. console.warn('THREE.Light: .onlyShadow has been removed.');
  30213. }
  30214. },
  30215. shadowCameraFov: {
  30216. set: function set(value) {
  30217. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  30218. this.shadow.camera.fov = value;
  30219. }
  30220. },
  30221. shadowCameraLeft: {
  30222. set: function set(value) {
  30223. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  30224. this.shadow.camera.left = value;
  30225. }
  30226. },
  30227. shadowCameraRight: {
  30228. set: function set(value) {
  30229. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  30230. this.shadow.camera.right = value;
  30231. }
  30232. },
  30233. shadowCameraTop: {
  30234. set: function set(value) {
  30235. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  30236. this.shadow.camera.top = value;
  30237. }
  30238. },
  30239. shadowCameraBottom: {
  30240. set: function set(value) {
  30241. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  30242. this.shadow.camera.bottom = value;
  30243. }
  30244. },
  30245. shadowCameraNear: {
  30246. set: function set(value) {
  30247. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  30248. this.shadow.camera.near = value;
  30249. }
  30250. },
  30251. shadowCameraFar: {
  30252. set: function set(value) {
  30253. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  30254. this.shadow.camera.far = value;
  30255. }
  30256. },
  30257. shadowCameraVisible: {
  30258. set: function set() {
  30259. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  30260. }
  30261. },
  30262. shadowBias: {
  30263. set: function set(value) {
  30264. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  30265. this.shadow.bias = value;
  30266. }
  30267. },
  30268. shadowDarkness: {
  30269. set: function set() {
  30270. console.warn('THREE.Light: .shadowDarkness has been removed.');
  30271. }
  30272. },
  30273. shadowMapWidth: {
  30274. set: function set(value) {
  30275. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  30276. this.shadow.mapSize.width = value;
  30277. }
  30278. },
  30279. shadowMapHeight: {
  30280. set: function set(value) {
  30281. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  30282. this.shadow.mapSize.height = value;
  30283. }
  30284. }
  30285. }); //
  30286. Object.defineProperties(BufferAttribute.prototype, {
  30287. length: {
  30288. get: function get() {
  30289. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  30290. return this.array.length;
  30291. }
  30292. },
  30293. dynamic: {
  30294. get: function get() {
  30295. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  30296. return this.usage === DynamicDrawUsage;
  30297. },
  30298. set: function set()
  30299. /* value */
  30300. {
  30301. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  30302. this.setUsage(DynamicDrawUsage);
  30303. }
  30304. }
  30305. });
  30306. Object.assign(BufferAttribute.prototype, {
  30307. setDynamic: function setDynamic(value) {
  30308. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  30309. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  30310. return this;
  30311. },
  30312. copyIndicesArray: function copyIndicesArray()
  30313. /* indices */
  30314. {
  30315. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  30316. },
  30317. setArray: function setArray()
  30318. /* array */
  30319. {
  30320. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  30321. }
  30322. });
  30323. Object.assign(BufferGeometry.prototype, {
  30324. addIndex: function addIndex(index) {
  30325. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  30326. this.setIndex(index);
  30327. },
  30328. addAttribute: function addAttribute(name, attribute) {
  30329. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  30330. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  30331. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  30332. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  30333. }
  30334. if (name === 'index') {
  30335. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  30336. this.setIndex(attribute);
  30337. return this;
  30338. }
  30339. return this.setAttribute(name, attribute);
  30340. },
  30341. addDrawCall: function addDrawCall(start, count, indexOffset) {
  30342. if (indexOffset !== undefined) {
  30343. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  30344. }
  30345. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  30346. this.addGroup(start, count);
  30347. },
  30348. clearDrawCalls: function clearDrawCalls() {
  30349. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  30350. this.clearGroups();
  30351. },
  30352. computeTangents: function computeTangents() {
  30353. console.warn('THREE.BufferGeometry: .computeTangents() has been removed.');
  30354. },
  30355. computeOffsets: function computeOffsets() {
  30356. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  30357. },
  30358. removeAttribute: function removeAttribute(name) {
  30359. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  30360. return this.deleteAttribute(name);
  30361. },
  30362. applyMatrix: function applyMatrix(matrix) {
  30363. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  30364. return this.applyMatrix4(matrix);
  30365. }
  30366. });
  30367. Object.defineProperties(BufferGeometry.prototype, {
  30368. drawcalls: {
  30369. get: function get() {
  30370. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  30371. return this.groups;
  30372. }
  30373. },
  30374. offsets: {
  30375. get: function get() {
  30376. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  30377. return this.groups;
  30378. }
  30379. }
  30380. });
  30381. Object.defineProperties(InstancedBufferGeometry.prototype, {
  30382. maxInstancedCount: {
  30383. get: function get() {
  30384. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  30385. return this.instanceCount;
  30386. },
  30387. set: function set(value) {
  30388. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  30389. this.instanceCount = value;
  30390. }
  30391. }
  30392. });
  30393. Object.defineProperties(Raycaster.prototype, {
  30394. linePrecision: {
  30395. get: function get() {
  30396. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  30397. return this.params.Line.threshold;
  30398. },
  30399. set: function set(value) {
  30400. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  30401. this.params.Line.threshold = value;
  30402. }
  30403. }
  30404. });
  30405. Object.defineProperties(InterleavedBuffer.prototype, {
  30406. dynamic: {
  30407. get: function get() {
  30408. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  30409. return this.usage === DynamicDrawUsage;
  30410. },
  30411. set: function set(value) {
  30412. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  30413. this.setUsage(value);
  30414. }
  30415. }
  30416. });
  30417. Object.assign(InterleavedBuffer.prototype, {
  30418. setDynamic: function setDynamic(value) {
  30419. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  30420. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  30421. return this;
  30422. },
  30423. setArray: function setArray()
  30424. /* array */
  30425. {
  30426. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  30427. }
  30428. }); //
  30429. Object.assign(ExtrudeBufferGeometry.prototype, {
  30430. getArrays: function getArrays() {
  30431. console.error('THREE.ExtrudeBufferGeometry: .getArrays() has been removed.');
  30432. },
  30433. addShapeList: function addShapeList() {
  30434. console.error('THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.');
  30435. },
  30436. addShape: function addShape() {
  30437. console.error('THREE.ExtrudeBufferGeometry: .addShape() has been removed.');
  30438. }
  30439. }); //
  30440. Object.assign(Scene.prototype, {
  30441. dispose: function dispose() {
  30442. console.error('THREE.Scene: .dispose() has been removed.');
  30443. }
  30444. }); //
  30445. Object.defineProperties(Uniform.prototype, {
  30446. dynamic: {
  30447. set: function set() {
  30448. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  30449. }
  30450. },
  30451. onUpdate: {
  30452. value: function value() {
  30453. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  30454. return this;
  30455. }
  30456. }
  30457. }); //
  30458. Object.defineProperties(Material.prototype, {
  30459. wrapAround: {
  30460. get: function get() {
  30461. console.warn('THREE.Material: .wrapAround has been removed.');
  30462. },
  30463. set: function set() {
  30464. console.warn('THREE.Material: .wrapAround has been removed.');
  30465. }
  30466. },
  30467. overdraw: {
  30468. get: function get() {
  30469. console.warn('THREE.Material: .overdraw has been removed.');
  30470. },
  30471. set: function set() {
  30472. console.warn('THREE.Material: .overdraw has been removed.');
  30473. }
  30474. },
  30475. wrapRGB: {
  30476. get: function get() {
  30477. console.warn('THREE.Material: .wrapRGB has been removed.');
  30478. return new Color();
  30479. }
  30480. },
  30481. shading: {
  30482. get: function get() {
  30483. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30484. },
  30485. set: function set(value) {
  30486. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30487. this.flatShading = value === FlatShading;
  30488. }
  30489. },
  30490. stencilMask: {
  30491. get: function get() {
  30492. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30493. return this.stencilFuncMask;
  30494. },
  30495. set: function set(value) {
  30496. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30497. this.stencilFuncMask = value;
  30498. }
  30499. }
  30500. });
  30501. Object.defineProperties(MeshPhongMaterial.prototype, {
  30502. metal: {
  30503. get: function get() {
  30504. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  30505. return false;
  30506. },
  30507. set: function set() {
  30508. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  30509. }
  30510. }
  30511. });
  30512. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  30513. transparency: {
  30514. get: function get() {
  30515. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30516. return this.transmission;
  30517. },
  30518. set: function set(value) {
  30519. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30520. this.transmission = value;
  30521. }
  30522. }
  30523. });
  30524. Object.defineProperties(ShaderMaterial.prototype, {
  30525. derivatives: {
  30526. get: function get() {
  30527. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30528. return this.extensions.derivatives;
  30529. },
  30530. set: function set(value) {
  30531. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30532. this.extensions.derivatives = value;
  30533. }
  30534. }
  30535. }); //
  30536. Object.assign(WebGLRenderer.prototype, {
  30537. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  30538. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  30539. this.setRenderTarget(renderTarget);
  30540. this.clear(color, depth, stencil);
  30541. },
  30542. animate: function animate(callback) {
  30543. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  30544. this.setAnimationLoop(callback);
  30545. },
  30546. getCurrentRenderTarget: function getCurrentRenderTarget() {
  30547. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  30548. return this.getRenderTarget();
  30549. },
  30550. getMaxAnisotropy: function getMaxAnisotropy() {
  30551. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  30552. return this.capabilities.getMaxAnisotropy();
  30553. },
  30554. getPrecision: function getPrecision() {
  30555. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  30556. return this.capabilities.precision;
  30557. },
  30558. resetGLState: function resetGLState() {
  30559. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  30560. return this.state.reset();
  30561. },
  30562. supportsFloatTextures: function supportsFloatTextures() {
  30563. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  30564. return this.extensions.get('OES_texture_float');
  30565. },
  30566. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  30567. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  30568. return this.extensions.get('OES_texture_half_float');
  30569. },
  30570. supportsStandardDerivatives: function supportsStandardDerivatives() {
  30571. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  30572. return this.extensions.get('OES_standard_derivatives');
  30573. },
  30574. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  30575. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  30576. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  30577. },
  30578. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  30579. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  30580. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  30581. },
  30582. supportsBlendMinMax: function supportsBlendMinMax() {
  30583. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  30584. return this.extensions.get('EXT_blend_minmax');
  30585. },
  30586. supportsVertexTextures: function supportsVertexTextures() {
  30587. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  30588. return this.capabilities.vertexTextures;
  30589. },
  30590. supportsInstancedArrays: function supportsInstancedArrays() {
  30591. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  30592. return this.extensions.get('ANGLE_instanced_arrays');
  30593. },
  30594. enableScissorTest: function enableScissorTest(boolean) {
  30595. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  30596. this.setScissorTest(boolean);
  30597. },
  30598. initMaterial: function initMaterial() {
  30599. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  30600. },
  30601. addPrePlugin: function addPrePlugin() {
  30602. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  30603. },
  30604. addPostPlugin: function addPostPlugin() {
  30605. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  30606. },
  30607. updateShadowMap: function updateShadowMap() {
  30608. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  30609. },
  30610. setFaceCulling: function setFaceCulling() {
  30611. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  30612. },
  30613. allocTextureUnit: function allocTextureUnit() {
  30614. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  30615. },
  30616. setTexture: function setTexture() {
  30617. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  30618. },
  30619. setTexture2D: function setTexture2D() {
  30620. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  30621. },
  30622. setTextureCube: function setTextureCube() {
  30623. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  30624. },
  30625. getActiveMipMapLevel: function getActiveMipMapLevel() {
  30626. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  30627. return this.getActiveMipmapLevel();
  30628. }
  30629. });
  30630. Object.defineProperties(WebGLRenderer.prototype, {
  30631. shadowMapEnabled: {
  30632. get: function get() {
  30633. return this.shadowMap.enabled;
  30634. },
  30635. set: function set(value) {
  30636. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  30637. this.shadowMap.enabled = value;
  30638. }
  30639. },
  30640. shadowMapType: {
  30641. get: function get() {
  30642. return this.shadowMap.type;
  30643. },
  30644. set: function set(value) {
  30645. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  30646. this.shadowMap.type = value;
  30647. }
  30648. },
  30649. shadowMapCullFace: {
  30650. get: function get() {
  30651. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30652. return undefined;
  30653. },
  30654. set: function set()
  30655. /* value */
  30656. {
  30657. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30658. }
  30659. },
  30660. context: {
  30661. get: function get() {
  30662. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  30663. return this.getContext();
  30664. }
  30665. },
  30666. vr: {
  30667. get: function get() {
  30668. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  30669. return this.xr;
  30670. }
  30671. },
  30672. gammaInput: {
  30673. get: function get() {
  30674. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30675. return false;
  30676. },
  30677. set: function set() {
  30678. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30679. }
  30680. },
  30681. gammaOutput: {
  30682. get: function get() {
  30683. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30684. return false;
  30685. },
  30686. set: function set(value) {
  30687. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30688. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  30689. }
  30690. },
  30691. toneMappingWhitePoint: {
  30692. get: function get() {
  30693. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30694. return 1.0;
  30695. },
  30696. set: function set() {
  30697. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30698. }
  30699. }
  30700. });
  30701. Object.defineProperties(WebGLShadowMap.prototype, {
  30702. cullFace: {
  30703. get: function get() {
  30704. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30705. return undefined;
  30706. },
  30707. set: function set()
  30708. /* cullFace */
  30709. {
  30710. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30711. }
  30712. },
  30713. renderReverseSided: {
  30714. get: function get() {
  30715. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30716. return undefined;
  30717. },
  30718. set: function set() {
  30719. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30720. }
  30721. },
  30722. renderSingleSided: {
  30723. get: function get() {
  30724. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30725. return undefined;
  30726. },
  30727. set: function set() {
  30728. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30729. }
  30730. }
  30731. });
  30732. function WebGLRenderTargetCube(width, height, options) {
  30733. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  30734. return new WebGLCubeRenderTarget(width, options);
  30735. } //
  30736. Object.defineProperties(WebGLRenderTarget.prototype, {
  30737. wrapS: {
  30738. get: function get() {
  30739. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30740. return this.texture.wrapS;
  30741. },
  30742. set: function set(value) {
  30743. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30744. this.texture.wrapS = value;
  30745. }
  30746. },
  30747. wrapT: {
  30748. get: function get() {
  30749. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30750. return this.texture.wrapT;
  30751. },
  30752. set: function set(value) {
  30753. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30754. this.texture.wrapT = value;
  30755. }
  30756. },
  30757. magFilter: {
  30758. get: function get() {
  30759. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30760. return this.texture.magFilter;
  30761. },
  30762. set: function set(value) {
  30763. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30764. this.texture.magFilter = value;
  30765. }
  30766. },
  30767. minFilter: {
  30768. get: function get() {
  30769. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30770. return this.texture.minFilter;
  30771. },
  30772. set: function set(value) {
  30773. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30774. this.texture.minFilter = value;
  30775. }
  30776. },
  30777. anisotropy: {
  30778. get: function get() {
  30779. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30780. return this.texture.anisotropy;
  30781. },
  30782. set: function set(value) {
  30783. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30784. this.texture.anisotropy = value;
  30785. }
  30786. },
  30787. offset: {
  30788. get: function get() {
  30789. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30790. return this.texture.offset;
  30791. },
  30792. set: function set(value) {
  30793. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30794. this.texture.offset = value;
  30795. }
  30796. },
  30797. repeat: {
  30798. get: function get() {
  30799. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30800. return this.texture.repeat;
  30801. },
  30802. set: function set(value) {
  30803. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30804. this.texture.repeat = value;
  30805. }
  30806. },
  30807. format: {
  30808. get: function get() {
  30809. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30810. return this.texture.format;
  30811. },
  30812. set: function set(value) {
  30813. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30814. this.texture.format = value;
  30815. }
  30816. },
  30817. type: {
  30818. get: function get() {
  30819. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30820. return this.texture.type;
  30821. },
  30822. set: function set(value) {
  30823. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30824. this.texture.type = value;
  30825. }
  30826. },
  30827. generateMipmaps: {
  30828. get: function get() {
  30829. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30830. return this.texture.generateMipmaps;
  30831. },
  30832. set: function set(value) {
  30833. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30834. this.texture.generateMipmaps = value;
  30835. }
  30836. }
  30837. }); //
  30838. Object.defineProperties(Audio.prototype, {
  30839. load: {
  30840. value: function value(file) {
  30841. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30842. var scope = this;
  30843. var audioLoader = new AudioLoader();
  30844. audioLoader.load(file, function (buffer) {
  30845. scope.setBuffer(buffer);
  30846. });
  30847. return this;
  30848. }
  30849. },
  30850. startTime: {
  30851. set: function set() {
  30852. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30853. }
  30854. }
  30855. });
  30856. AudioAnalyser.prototype.getData = function () {
  30857. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30858. return this.getFrequencyData();
  30859. }; //
  30860. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30861. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30862. return this.update(renderer, scene);
  30863. };
  30864. CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
  30865. console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
  30866. return this.renderTarget.clear(renderer, color, depth, stencil);
  30867. }; //
  30868. var GeometryUtils = {
  30869. merge: function merge(geometry1, geometry2, materialIndexOffset) {
  30870. console.warn('THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.');
  30871. var matrix;
  30872. if (geometry2.isMesh) {
  30873. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30874. matrix = geometry2.matrix;
  30875. geometry2 = geometry2.geometry;
  30876. }
  30877. geometry1.merge(geometry2, matrix, materialIndexOffset);
  30878. },
  30879. center: function center(geometry) {
  30880. console.warn('THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.');
  30881. return geometry.center();
  30882. }
  30883. };
  30884. ImageUtils.crossOrigin = undefined;
  30885. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30886. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30887. var loader = new TextureLoader();
  30888. loader.setCrossOrigin(this.crossOrigin);
  30889. var texture = loader.load(url, onLoad, undefined, onError);
  30890. if (mapping) texture.mapping = mapping;
  30891. return texture;
  30892. };
  30893. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30894. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30895. var loader = new CubeTextureLoader();
  30896. loader.setCrossOrigin(this.crossOrigin);
  30897. var texture = loader.load(urls, onLoad, undefined, onError);
  30898. if (mapping) texture.mapping = mapping;
  30899. return texture;
  30900. };
  30901. ImageUtils.loadCompressedTexture = function () {
  30902. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30903. };
  30904. ImageUtils.loadCompressedTextureCube = function () {
  30905. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30906. }; //
  30907. function CanvasRenderer() {
  30908. console.error('THREE.CanvasRenderer has been removed');
  30909. } //
  30910. function JSONLoader() {
  30911. console.error('THREE.JSONLoader has been removed.');
  30912. } //
  30913. var SceneUtils = {
  30914. createMultiMaterialObject: function createMultiMaterialObject()
  30915. /* geometry, materials */
  30916. {
  30917. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30918. },
  30919. detach: function detach()
  30920. /* child, parent, scene */
  30921. {
  30922. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30923. },
  30924. attach: function attach()
  30925. /* child, scene, parent */
  30926. {
  30927. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30928. }
  30929. }; //
  30930. function LensFlare() {
  30931. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30932. }
  30933. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30934. /* eslint-disable no-undef */
  30935. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30936. detail: {
  30937. revision: REVISION
  30938. }
  30939. }));
  30940. /* eslint-enable no-undef */
  30941. }
  30942. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30943. exports.AddEquation = AddEquation;
  30944. exports.AddOperation = AddOperation;
  30945. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30946. exports.AdditiveBlending = AdditiveBlending;
  30947. exports.AlphaFormat = AlphaFormat;
  30948. exports.AlwaysDepth = AlwaysDepth;
  30949. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30950. exports.AmbientLight = AmbientLight;
  30951. exports.AmbientLightProbe = AmbientLightProbe;
  30952. exports.AnimationClip = AnimationClip;
  30953. exports.AnimationLoader = AnimationLoader;
  30954. exports.AnimationMixer = AnimationMixer;
  30955. exports.AnimationObjectGroup = AnimationObjectGroup;
  30956. exports.AnimationUtils = AnimationUtils;
  30957. exports.ArcCurve = ArcCurve;
  30958. exports.ArrayCamera = ArrayCamera;
  30959. exports.ArrowHelper = ArrowHelper;
  30960. exports.Audio = Audio;
  30961. exports.AudioAnalyser = AudioAnalyser;
  30962. exports.AudioContext = AudioContext;
  30963. exports.AudioListener = AudioListener;
  30964. exports.AudioLoader = AudioLoader;
  30965. exports.AxesHelper = AxesHelper;
  30966. exports.AxisHelper = AxisHelper;
  30967. exports.BackSide = BackSide;
  30968. exports.BasicDepthPacking = BasicDepthPacking;
  30969. exports.BasicShadowMap = BasicShadowMap;
  30970. exports.BinaryTextureLoader = BinaryTextureLoader;
  30971. exports.Bone = Bone;
  30972. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30973. exports.BoundingBoxHelper = BoundingBoxHelper;
  30974. exports.Box2 = Box2;
  30975. exports.Box3 = Box3;
  30976. exports.Box3Helper = Box3Helper;
  30977. exports.BoxBufferGeometry = BoxBufferGeometry;
  30978. exports.BoxGeometry = BoxGeometry;
  30979. exports.BoxHelper = BoxHelper;
  30980. exports.BufferAttribute = BufferAttribute;
  30981. exports.BufferGeometry = BufferGeometry;
  30982. exports.BufferGeometryLoader = BufferGeometryLoader;
  30983. exports.ByteType = ByteType;
  30984. exports.Cache = Cache;
  30985. exports.Camera = Camera;
  30986. exports.CameraHelper = CameraHelper;
  30987. exports.CanvasRenderer = CanvasRenderer;
  30988. exports.CanvasTexture = CanvasTexture;
  30989. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30990. exports.CineonToneMapping = CineonToneMapping;
  30991. exports.CircleBufferGeometry = CircleBufferGeometry;
  30992. exports.CircleGeometry = CircleGeometry;
  30993. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30994. exports.Clock = Clock;
  30995. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  30996. exports.Color = Color;
  30997. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30998. exports.CompressedTexture = CompressedTexture;
  30999. exports.CompressedTextureLoader = CompressedTextureLoader;
  31000. exports.ConeBufferGeometry = ConeBufferGeometry;
  31001. exports.ConeGeometry = ConeGeometry;
  31002. exports.CubeCamera = CubeCamera;
  31003. exports.CubeGeometry = BoxGeometry;
  31004. exports.CubeReflectionMapping = CubeReflectionMapping;
  31005. exports.CubeRefractionMapping = CubeRefractionMapping;
  31006. exports.CubeTexture = CubeTexture;
  31007. exports.CubeTextureLoader = CubeTextureLoader;
  31008. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  31009. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  31010. exports.CubicBezierCurve = CubicBezierCurve;
  31011. exports.CubicBezierCurve3 = CubicBezierCurve3;
  31012. exports.CubicInterpolant = CubicInterpolant;
  31013. exports.CullFaceBack = CullFaceBack;
  31014. exports.CullFaceFront = CullFaceFront;
  31015. exports.CullFaceFrontBack = CullFaceFrontBack;
  31016. exports.CullFaceNone = CullFaceNone;
  31017. exports.Curve = Curve;
  31018. exports.CurvePath = CurvePath;
  31019. exports.CustomBlending = CustomBlending;
  31020. exports.CustomToneMapping = CustomToneMapping;
  31021. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  31022. exports.CylinderGeometry = CylinderGeometry;
  31023. exports.Cylindrical = Cylindrical;
  31024. exports.DataTexture = DataTexture;
  31025. exports.DataTexture2DArray = DataTexture2DArray;
  31026. exports.DataTexture3D = DataTexture3D;
  31027. exports.DataTextureLoader = DataTextureLoader;
  31028. exports.DataUtils = DataUtils;
  31029. exports.DecrementStencilOp = DecrementStencilOp;
  31030. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  31031. exports.DefaultLoadingManager = DefaultLoadingManager;
  31032. exports.DepthFormat = DepthFormat;
  31033. exports.DepthStencilFormat = DepthStencilFormat;
  31034. exports.DepthTexture = DepthTexture;
  31035. exports.DirectionalLight = DirectionalLight;
  31036. exports.DirectionalLightHelper = DirectionalLightHelper;
  31037. exports.DiscreteInterpolant = DiscreteInterpolant;
  31038. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  31039. exports.DodecahedronGeometry = DodecahedronGeometry;
  31040. exports.DoubleSide = DoubleSide;
  31041. exports.DstAlphaFactor = DstAlphaFactor;
  31042. exports.DstColorFactor = DstColorFactor;
  31043. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  31044. exports.DynamicCopyUsage = DynamicCopyUsage;
  31045. exports.DynamicDrawUsage = DynamicDrawUsage;
  31046. exports.DynamicReadUsage = DynamicReadUsage;
  31047. exports.EdgesGeometry = EdgesGeometry;
  31048. exports.EdgesHelper = EdgesHelper;
  31049. exports.EllipseCurve = EllipseCurve;
  31050. exports.EqualDepth = EqualDepth;
  31051. exports.EqualStencilFunc = EqualStencilFunc;
  31052. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  31053. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  31054. exports.Euler = Euler;
  31055. exports.EventDispatcher = EventDispatcher;
  31056. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  31057. exports.ExtrudeGeometry = ExtrudeGeometry;
  31058. exports.Face3 = Face3;
  31059. exports.Face4 = Face4;
  31060. exports.FaceColors = FaceColors;
  31061. exports.FileLoader = FileLoader;
  31062. exports.FlatShading = FlatShading;
  31063. exports.Float16BufferAttribute = Float16BufferAttribute;
  31064. exports.Float32Attribute = Float32Attribute;
  31065. exports.Float32BufferAttribute = Float32BufferAttribute;
  31066. exports.Float64Attribute = Float64Attribute;
  31067. exports.Float64BufferAttribute = Float64BufferAttribute;
  31068. exports.FloatType = FloatType;
  31069. exports.Fog = Fog;
  31070. exports.FogExp2 = FogExp2;
  31071. exports.Font = Font;
  31072. exports.FontLoader = FontLoader;
  31073. exports.FrontSide = FrontSide;
  31074. exports.Frustum = Frustum;
  31075. exports.GLBufferAttribute = GLBufferAttribute;
  31076. exports.GLSL1 = GLSL1;
  31077. exports.GLSL3 = GLSL3;
  31078. exports.GammaEncoding = GammaEncoding;
  31079. exports.Geometry = Geometry;
  31080. exports.GeometryUtils = GeometryUtils;
  31081. exports.GreaterDepth = GreaterDepth;
  31082. exports.GreaterEqualDepth = GreaterEqualDepth;
  31083. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  31084. exports.GreaterStencilFunc = GreaterStencilFunc;
  31085. exports.GridHelper = GridHelper;
  31086. exports.Group = Group;
  31087. exports.HalfFloatType = HalfFloatType;
  31088. exports.HemisphereLight = HemisphereLight;
  31089. exports.HemisphereLightHelper = HemisphereLightHelper;
  31090. exports.HemisphereLightProbe = HemisphereLightProbe;
  31091. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  31092. exports.IcosahedronGeometry = IcosahedronGeometry;
  31093. exports.ImageBitmapLoader = ImageBitmapLoader;
  31094. exports.ImageLoader = ImageLoader;
  31095. exports.ImageUtils = ImageUtils;
  31096. exports.ImmediateRenderObject = ImmediateRenderObject;
  31097. exports.IncrementStencilOp = IncrementStencilOp;
  31098. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  31099. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  31100. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  31101. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  31102. exports.InstancedMesh = InstancedMesh;
  31103. exports.Int16Attribute = Int16Attribute;
  31104. exports.Int16BufferAttribute = Int16BufferAttribute;
  31105. exports.Int32Attribute = Int32Attribute;
  31106. exports.Int32BufferAttribute = Int32BufferAttribute;
  31107. exports.Int8Attribute = Int8Attribute;
  31108. exports.Int8BufferAttribute = Int8BufferAttribute;
  31109. exports.IntType = IntType;
  31110. exports.InterleavedBuffer = InterleavedBuffer;
  31111. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  31112. exports.Interpolant = Interpolant;
  31113. exports.InterpolateDiscrete = InterpolateDiscrete;
  31114. exports.InterpolateLinear = InterpolateLinear;
  31115. exports.InterpolateSmooth = InterpolateSmooth;
  31116. exports.InvertStencilOp = InvertStencilOp;
  31117. exports.JSONLoader = JSONLoader;
  31118. exports.KeepStencilOp = KeepStencilOp;
  31119. exports.KeyframeTrack = KeyframeTrack;
  31120. exports.LOD = LOD;
  31121. exports.LatheBufferGeometry = LatheBufferGeometry;
  31122. exports.LatheGeometry = LatheGeometry;
  31123. exports.Layers = Layers;
  31124. exports.LensFlare = LensFlare;
  31125. exports.LessDepth = LessDepth;
  31126. exports.LessEqualDepth = LessEqualDepth;
  31127. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  31128. exports.LessStencilFunc = LessStencilFunc;
  31129. exports.Light = Light;
  31130. exports.LightProbe = LightProbe;
  31131. exports.Line = Line;
  31132. exports.Line3 = Line3;
  31133. exports.LineBasicMaterial = LineBasicMaterial;
  31134. exports.LineCurve = LineCurve;
  31135. exports.LineCurve3 = LineCurve3;
  31136. exports.LineDashedMaterial = LineDashedMaterial;
  31137. exports.LineLoop = LineLoop;
  31138. exports.LinePieces = LinePieces;
  31139. exports.LineSegments = LineSegments;
  31140. exports.LineStrip = LineStrip;
  31141. exports.LinearEncoding = LinearEncoding;
  31142. exports.LinearFilter = LinearFilter;
  31143. exports.LinearInterpolant = LinearInterpolant;
  31144. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  31145. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  31146. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  31147. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  31148. exports.LinearToneMapping = LinearToneMapping;
  31149. exports.Loader = Loader;
  31150. exports.LoaderUtils = LoaderUtils;
  31151. exports.LoadingManager = LoadingManager;
  31152. exports.LogLuvEncoding = LogLuvEncoding;
  31153. exports.LoopOnce = LoopOnce;
  31154. exports.LoopPingPong = LoopPingPong;
  31155. exports.LoopRepeat = LoopRepeat;
  31156. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  31157. exports.LuminanceFormat = LuminanceFormat;
  31158. exports.MOUSE = MOUSE;
  31159. exports.Material = Material;
  31160. exports.MaterialLoader = MaterialLoader;
  31161. exports.Math = MathUtils;
  31162. exports.MathUtils = MathUtils;
  31163. exports.Matrix3 = Matrix3;
  31164. exports.Matrix4 = Matrix4;
  31165. exports.MaxEquation = MaxEquation;
  31166. exports.Mesh = Mesh;
  31167. exports.MeshBasicMaterial = MeshBasicMaterial;
  31168. exports.MeshDepthMaterial = MeshDepthMaterial;
  31169. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  31170. exports.MeshFaceMaterial = MeshFaceMaterial;
  31171. exports.MeshLambertMaterial = MeshLambertMaterial;
  31172. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  31173. exports.MeshNormalMaterial = MeshNormalMaterial;
  31174. exports.MeshPhongMaterial = MeshPhongMaterial;
  31175. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  31176. exports.MeshStandardMaterial = MeshStandardMaterial;
  31177. exports.MeshToonMaterial = MeshToonMaterial;
  31178. exports.MinEquation = MinEquation;
  31179. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  31180. exports.MixOperation = MixOperation;
  31181. exports.MultiMaterial = MultiMaterial;
  31182. exports.MultiplyBlending = MultiplyBlending;
  31183. exports.MultiplyOperation = MultiplyOperation;
  31184. exports.NearestFilter = NearestFilter;
  31185. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  31186. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  31187. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  31188. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  31189. exports.NeverDepth = NeverDepth;
  31190. exports.NeverStencilFunc = NeverStencilFunc;
  31191. exports.NoBlending = NoBlending;
  31192. exports.NoColors = NoColors;
  31193. exports.NoToneMapping = NoToneMapping;
  31194. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  31195. exports.NormalBlending = NormalBlending;
  31196. exports.NotEqualDepth = NotEqualDepth;
  31197. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  31198. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  31199. exports.Object3D = Object3D;
  31200. exports.ObjectLoader = ObjectLoader;
  31201. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  31202. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  31203. exports.OctahedronGeometry = OctahedronGeometry;
  31204. exports.OneFactor = OneFactor;
  31205. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  31206. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  31207. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  31208. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  31209. exports.OrthographicCamera = OrthographicCamera;
  31210. exports.PCFShadowMap = PCFShadowMap;
  31211. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  31212. exports.PMREMGenerator = PMREMGenerator;
  31213. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  31214. exports.ParametricGeometry = ParametricGeometry;
  31215. exports.Particle = Particle;
  31216. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  31217. exports.ParticleSystem = ParticleSystem;
  31218. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  31219. exports.Path = Path;
  31220. exports.PerspectiveCamera = PerspectiveCamera;
  31221. exports.Plane = Plane;
  31222. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  31223. exports.PlaneGeometry = PlaneGeometry;
  31224. exports.PlaneHelper = PlaneHelper;
  31225. exports.PointCloud = PointCloud;
  31226. exports.PointCloudMaterial = PointCloudMaterial;
  31227. exports.PointLight = PointLight;
  31228. exports.PointLightHelper = PointLightHelper;
  31229. exports.Points = Points;
  31230. exports.PointsMaterial = PointsMaterial;
  31231. exports.PolarGridHelper = PolarGridHelper;
  31232. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  31233. exports.PolyhedronGeometry = PolyhedronGeometry;
  31234. exports.PositionalAudio = PositionalAudio;
  31235. exports.PropertyBinding = PropertyBinding;
  31236. exports.PropertyMixer = PropertyMixer;
  31237. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  31238. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  31239. exports.Quaternion = Quaternion;
  31240. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  31241. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  31242. exports.REVISION = REVISION;
  31243. exports.RGBADepthPacking = RGBADepthPacking;
  31244. exports.RGBAFormat = RGBAFormat;
  31245. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  31246. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  31247. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  31248. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  31249. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  31250. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  31251. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  31252. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  31253. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  31254. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  31255. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  31256. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  31257. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  31258. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  31259. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  31260. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  31261. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  31262. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  31263. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  31264. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  31265. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  31266. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  31267. exports.RGBDEncoding = RGBDEncoding;
  31268. exports.RGBEEncoding = RGBEEncoding;
  31269. exports.RGBEFormat = RGBEFormat;
  31270. exports.RGBFormat = RGBFormat;
  31271. exports.RGBIntegerFormat = RGBIntegerFormat;
  31272. exports.RGBM16Encoding = RGBM16Encoding;
  31273. exports.RGBM7Encoding = RGBM7Encoding;
  31274. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  31275. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  31276. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  31277. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  31278. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  31279. exports.RGFormat = RGFormat;
  31280. exports.RGIntegerFormat = RGIntegerFormat;
  31281. exports.RawShaderMaterial = RawShaderMaterial;
  31282. exports.Ray = Ray;
  31283. exports.Raycaster = Raycaster;
  31284. exports.RectAreaLight = RectAreaLight;
  31285. exports.RedFormat = RedFormat;
  31286. exports.RedIntegerFormat = RedIntegerFormat;
  31287. exports.ReinhardToneMapping = ReinhardToneMapping;
  31288. exports.RepeatWrapping = RepeatWrapping;
  31289. exports.ReplaceStencilOp = ReplaceStencilOp;
  31290. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  31291. exports.RingBufferGeometry = RingBufferGeometry;
  31292. exports.RingGeometry = RingGeometry;
  31293. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  31294. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  31295. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  31296. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  31297. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  31298. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  31299. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  31300. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  31301. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  31302. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  31303. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  31304. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  31305. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  31306. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  31307. exports.Scene = Scene;
  31308. exports.SceneUtils = SceneUtils;
  31309. exports.ShaderChunk = ShaderChunk;
  31310. exports.ShaderLib = ShaderLib;
  31311. exports.ShaderMaterial = ShaderMaterial;
  31312. exports.ShadowMaterial = ShadowMaterial;
  31313. exports.Shape = Shape;
  31314. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  31315. exports.ShapeGeometry = ShapeGeometry;
  31316. exports.ShapePath = ShapePath;
  31317. exports.ShapeUtils = ShapeUtils;
  31318. exports.ShortType = ShortType;
  31319. exports.Skeleton = Skeleton;
  31320. exports.SkeletonHelper = SkeletonHelper;
  31321. exports.SkinnedMesh = SkinnedMesh;
  31322. exports.SmoothShading = SmoothShading;
  31323. exports.Sphere = Sphere;
  31324. exports.SphereBufferGeometry = SphereBufferGeometry;
  31325. exports.SphereGeometry = SphereGeometry;
  31326. exports.Spherical = Spherical;
  31327. exports.SphericalHarmonics3 = SphericalHarmonics3;
  31328. exports.Spline = Spline;
  31329. exports.SplineCurve = SplineCurve;
  31330. exports.SplineCurve3 = SplineCurve3;
  31331. exports.SpotLight = SpotLight;
  31332. exports.SpotLightHelper = SpotLightHelper;
  31333. exports.Sprite = Sprite;
  31334. exports.SpriteMaterial = SpriteMaterial;
  31335. exports.SrcAlphaFactor = SrcAlphaFactor;
  31336. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  31337. exports.SrcColorFactor = SrcColorFactor;
  31338. exports.StaticCopyUsage = StaticCopyUsage;
  31339. exports.StaticDrawUsage = StaticDrawUsage;
  31340. exports.StaticReadUsage = StaticReadUsage;
  31341. exports.StereoCamera = StereoCamera;
  31342. exports.StreamCopyUsage = StreamCopyUsage;
  31343. exports.StreamDrawUsage = StreamDrawUsage;
  31344. exports.StreamReadUsage = StreamReadUsage;
  31345. exports.StringKeyframeTrack = StringKeyframeTrack;
  31346. exports.SubtractEquation = SubtractEquation;
  31347. exports.SubtractiveBlending = SubtractiveBlending;
  31348. exports.TOUCH = TOUCH;
  31349. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  31350. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  31351. exports.TetrahedronGeometry = TetrahedronGeometry;
  31352. exports.TextBufferGeometry = TextBufferGeometry;
  31353. exports.TextGeometry = TextGeometry;
  31354. exports.Texture = Texture;
  31355. exports.TextureLoader = TextureLoader;
  31356. exports.TorusBufferGeometry = TorusBufferGeometry;
  31357. exports.TorusGeometry = TorusGeometry;
  31358. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  31359. exports.TorusKnotGeometry = TorusKnotGeometry;
  31360. exports.Triangle = Triangle;
  31361. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  31362. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  31363. exports.TrianglesDrawMode = TrianglesDrawMode;
  31364. exports.TubeBufferGeometry = TubeBufferGeometry;
  31365. exports.TubeGeometry = TubeGeometry;
  31366. exports.UVMapping = UVMapping;
  31367. exports.Uint16Attribute = Uint16Attribute;
  31368. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  31369. exports.Uint32Attribute = Uint32Attribute;
  31370. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  31371. exports.Uint8Attribute = Uint8Attribute;
  31372. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  31373. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  31374. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  31375. exports.Uniform = Uniform;
  31376. exports.UniformsLib = UniformsLib;
  31377. exports.UniformsUtils = UniformsUtils;
  31378. exports.UnsignedByteType = UnsignedByteType;
  31379. exports.UnsignedInt248Type = UnsignedInt248Type;
  31380. exports.UnsignedIntType = UnsignedIntType;
  31381. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  31382. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  31383. exports.UnsignedShort565Type = UnsignedShort565Type;
  31384. exports.UnsignedShortType = UnsignedShortType;
  31385. exports.VSMShadowMap = VSMShadowMap;
  31386. exports.Vector2 = Vector2;
  31387. exports.Vector3 = Vector3;
  31388. exports.Vector4 = Vector4;
  31389. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  31390. exports.Vertex = Vertex;
  31391. exports.VertexColors = VertexColors;
  31392. exports.VideoTexture = VideoTexture;
  31393. exports.WebGL1Renderer = WebGL1Renderer;
  31394. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  31395. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  31396. exports.WebGLRenderTarget = WebGLRenderTarget;
  31397. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  31398. exports.WebGLRenderer = WebGLRenderer;
  31399. exports.WebGLUtils = WebGLUtils;
  31400. exports.WireframeGeometry = WireframeGeometry;
  31401. exports.WireframeHelper = WireframeHelper;
  31402. exports.WrapAroundEnding = WrapAroundEnding;
  31403. exports.XHRLoader = XHRLoader;
  31404. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  31405. exports.ZeroFactor = ZeroFactor;
  31406. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  31407. exports.ZeroStencilOp = ZeroStencilOp;
  31408. exports.sRGBEncoding = sRGBEncoding;
  31409. Object.defineProperty(exports, '__esModule', { value: true });
  31410. })));