three.js 1.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273
  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 = '124dev';
  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. Object3D.call(this);
  7140. this.type = 'Mesh';
  7141. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  7142. this.material = material !== undefined ? material : new MeshBasicMaterial();
  7143. this.updateMorphTargets();
  7144. }
  7145. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7146. constructor: Mesh,
  7147. isMesh: true,
  7148. copy: function copy(source) {
  7149. Object3D.prototype.copy.call(this, source);
  7150. if (source.morphTargetInfluences !== undefined) {
  7151. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7152. }
  7153. if (source.morphTargetDictionary !== undefined) {
  7154. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7155. }
  7156. this.material = source.material;
  7157. this.geometry = source.geometry;
  7158. return this;
  7159. },
  7160. updateMorphTargets: function updateMorphTargets() {
  7161. var geometry = this.geometry;
  7162. if (geometry.isBufferGeometry) {
  7163. var morphAttributes = geometry.morphAttributes;
  7164. var keys = Object.keys(morphAttributes);
  7165. if (keys.length > 0) {
  7166. var morphAttribute = morphAttributes[keys[0]];
  7167. if (morphAttribute !== undefined) {
  7168. this.morphTargetInfluences = [];
  7169. this.morphTargetDictionary = {};
  7170. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7171. var name = morphAttribute[m].name || String(m);
  7172. this.morphTargetInfluences.push(0);
  7173. this.morphTargetDictionary[name] = m;
  7174. }
  7175. }
  7176. }
  7177. } else {
  7178. var morphTargets = geometry.morphTargets;
  7179. if (morphTargets !== undefined && morphTargets.length > 0) {
  7180. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7181. }
  7182. }
  7183. },
  7184. raycast: function raycast(raycaster, intersects) {
  7185. var geometry = this.geometry;
  7186. var material = this.material;
  7187. var matrixWorld = this.matrixWorld;
  7188. if (material === undefined) return; // Checking boundingSphere distance to ray
  7189. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7190. _sphere.copy(geometry.boundingSphere);
  7191. _sphere.applyMatrix4(matrixWorld);
  7192. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7193. _inverseMatrix.copy(matrixWorld).invert();
  7194. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7195. if (geometry.boundingBox !== null) {
  7196. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7197. }
  7198. var intersection;
  7199. if (geometry.isBufferGeometry) {
  7200. var index = geometry.index;
  7201. var position = geometry.attributes.position;
  7202. var morphPosition = geometry.morphAttributes.position;
  7203. var morphTargetsRelative = geometry.morphTargetsRelative;
  7204. var uv = geometry.attributes.uv;
  7205. var uv2 = geometry.attributes.uv2;
  7206. var groups = geometry.groups;
  7207. var drawRange = geometry.drawRange;
  7208. if (index !== null) {
  7209. // indexed buffer geometry
  7210. if (Array.isArray(material)) {
  7211. for (var i = 0, il = groups.length; i < il; i++) {
  7212. var group = groups[i];
  7213. var groupMaterial = material[group.materialIndex];
  7214. var start = Math.max(group.start, drawRange.start);
  7215. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7216. for (var j = start, jl = end; j < jl; j += 3) {
  7217. var a = index.getX(j);
  7218. var b = index.getX(j + 1);
  7219. var c = index.getX(j + 2);
  7220. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7221. if (intersection) {
  7222. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7223. intersection.face.materialIndex = group.materialIndex;
  7224. intersects.push(intersection);
  7225. }
  7226. }
  7227. }
  7228. } else {
  7229. var _start = Math.max(0, drawRange.start);
  7230. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7231. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7232. var _a = index.getX(_i);
  7233. var _b = index.getX(_i + 1);
  7234. var _c = index.getX(_i + 2);
  7235. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7236. if (intersection) {
  7237. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7238. intersects.push(intersection);
  7239. }
  7240. }
  7241. }
  7242. } else if (position !== undefined) {
  7243. // non-indexed buffer geometry
  7244. if (Array.isArray(material)) {
  7245. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7246. var _group = groups[_i2];
  7247. var _groupMaterial = material[_group.materialIndex];
  7248. var _start2 = Math.max(_group.start, drawRange.start);
  7249. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7250. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7251. var _a2 = _j;
  7252. var _b2 = _j + 1;
  7253. var _c2 = _j + 2;
  7254. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7255. if (intersection) {
  7256. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7257. intersection.face.materialIndex = _group.materialIndex;
  7258. intersects.push(intersection);
  7259. }
  7260. }
  7261. }
  7262. } else {
  7263. var _start3 = Math.max(0, drawRange.start);
  7264. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7265. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7266. var _a3 = _i3;
  7267. var _b3 = _i3 + 1;
  7268. var _c3 = _i3 + 2;
  7269. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7270. if (intersection) {
  7271. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7272. intersects.push(intersection);
  7273. }
  7274. }
  7275. }
  7276. }
  7277. } else if (geometry.isGeometry) {
  7278. var isMultiMaterial = Array.isArray(material);
  7279. var vertices = geometry.vertices;
  7280. var faces = geometry.faces;
  7281. var uvs;
  7282. var faceVertexUvs = geometry.faceVertexUvs[0];
  7283. if (faceVertexUvs.length > 0) uvs = faceVertexUvs;
  7284. for (var f = 0, fl = faces.length; f < fl; f++) {
  7285. var face = faces[f];
  7286. var faceMaterial = isMultiMaterial ? material[face.materialIndex] : material;
  7287. if (faceMaterial === undefined) continue;
  7288. var fvA = vertices[face.a];
  7289. var fvB = vertices[face.b];
  7290. var fvC = vertices[face.c];
  7291. intersection = checkIntersection(this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint);
  7292. if (intersection) {
  7293. if (uvs && uvs[f]) {
  7294. var uvs_f = uvs[f];
  7295. _uvA.copy(uvs_f[0]);
  7296. _uvB.copy(uvs_f[1]);
  7297. _uvC.copy(uvs_f[2]);
  7298. intersection.uv = Triangle.getUV(_intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2());
  7299. }
  7300. intersection.face = face;
  7301. intersection.faceIndex = f;
  7302. intersects.push(intersection);
  7303. }
  7304. }
  7305. }
  7306. }
  7307. });
  7308. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7309. var intersect;
  7310. if (material.side === BackSide) {
  7311. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7312. } else {
  7313. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7314. }
  7315. if (intersect === null) return null;
  7316. _intersectionPointWorld.copy(point);
  7317. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7318. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7319. if (distance < raycaster.near || distance > raycaster.far) return null;
  7320. return {
  7321. distance: distance,
  7322. point: _intersectionPointWorld.clone(),
  7323. object: object
  7324. };
  7325. }
  7326. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7327. _vA.fromBufferAttribute(position, a);
  7328. _vB.fromBufferAttribute(position, b);
  7329. _vC.fromBufferAttribute(position, c);
  7330. var morphInfluences = object.morphTargetInfluences;
  7331. if (material.morphTargets && morphPosition && morphInfluences) {
  7332. _morphA.set(0, 0, 0);
  7333. _morphB.set(0, 0, 0);
  7334. _morphC.set(0, 0, 0);
  7335. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7336. var influence = morphInfluences[i];
  7337. var morphAttribute = morphPosition[i];
  7338. if (influence === 0) continue;
  7339. _tempA.fromBufferAttribute(morphAttribute, a);
  7340. _tempB.fromBufferAttribute(morphAttribute, b);
  7341. _tempC.fromBufferAttribute(morphAttribute, c);
  7342. if (morphTargetsRelative) {
  7343. _morphA.addScaledVector(_tempA, influence);
  7344. _morphB.addScaledVector(_tempB, influence);
  7345. _morphC.addScaledVector(_tempC, influence);
  7346. } else {
  7347. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7348. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7349. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7350. }
  7351. }
  7352. _vA.add(_morphA);
  7353. _vB.add(_morphB);
  7354. _vC.add(_morphC);
  7355. }
  7356. if (object.isSkinnedMesh) {
  7357. object.boneTransform(a, _vA);
  7358. object.boneTransform(b, _vB);
  7359. object.boneTransform(c, _vC);
  7360. }
  7361. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7362. if (intersection) {
  7363. if (uv) {
  7364. _uvA.fromBufferAttribute(uv, a);
  7365. _uvB.fromBufferAttribute(uv, b);
  7366. _uvC.fromBufferAttribute(uv, c);
  7367. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7368. }
  7369. if (uv2) {
  7370. _uvA.fromBufferAttribute(uv2, a);
  7371. _uvB.fromBufferAttribute(uv2, b);
  7372. _uvC.fromBufferAttribute(uv2, c);
  7373. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7374. }
  7375. var face = new Face3(a, b, c);
  7376. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7377. intersection.face = face;
  7378. }
  7379. return intersection;
  7380. }
  7381. var BoxBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7382. _inheritsLoose(BoxBufferGeometry, _BufferGeometry);
  7383. function BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7384. var _this;
  7385. if (width === void 0) {
  7386. width = 1;
  7387. }
  7388. if (height === void 0) {
  7389. height = 1;
  7390. }
  7391. if (depth === void 0) {
  7392. depth = 1;
  7393. }
  7394. if (widthSegments === void 0) {
  7395. widthSegments = 1;
  7396. }
  7397. if (heightSegments === void 0) {
  7398. heightSegments = 1;
  7399. }
  7400. if (depthSegments === void 0) {
  7401. depthSegments = 1;
  7402. }
  7403. _this = _BufferGeometry.call(this) || this;
  7404. _this.type = 'BoxBufferGeometry';
  7405. _this.parameters = {
  7406. width: width,
  7407. height: height,
  7408. depth: depth,
  7409. widthSegments: widthSegments,
  7410. heightSegments: heightSegments,
  7411. depthSegments: depthSegments
  7412. };
  7413. var scope = _assertThisInitialized(_this); // segments
  7414. widthSegments = Math.floor(widthSegments);
  7415. heightSegments = Math.floor(heightSegments);
  7416. depthSegments = Math.floor(depthSegments); // buffers
  7417. var indices = [];
  7418. var vertices = [];
  7419. var normals = [];
  7420. var uvs = []; // helper variables
  7421. var numberOfVertices = 0;
  7422. var groupStart = 0; // build each side of the box geometry
  7423. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7424. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7425. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7426. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7427. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7428. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7429. // build geometry
  7430. _this.setIndex(indices);
  7431. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7432. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7433. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7434. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7435. var segmentWidth = width / gridX;
  7436. var segmentHeight = height / gridY;
  7437. var widthHalf = width / 2;
  7438. var heightHalf = height / 2;
  7439. var depthHalf = depth / 2;
  7440. var gridX1 = gridX + 1;
  7441. var gridY1 = gridY + 1;
  7442. var vertexCounter = 0;
  7443. var groupCount = 0;
  7444. var vector = new Vector3(); // generate vertices, normals and uvs
  7445. for (var iy = 0; iy < gridY1; iy++) {
  7446. var y = iy * segmentHeight - heightHalf;
  7447. for (var ix = 0; ix < gridX1; ix++) {
  7448. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7449. vector[u] = x * udir;
  7450. vector[v] = y * vdir;
  7451. vector[w] = depthHalf; // now apply vector to vertex buffer
  7452. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7453. vector[u] = 0;
  7454. vector[v] = 0;
  7455. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7456. normals.push(vector.x, vector.y, vector.z); // uvs
  7457. uvs.push(ix / gridX);
  7458. uvs.push(1 - iy / gridY); // counters
  7459. vertexCounter += 1;
  7460. }
  7461. } // indices
  7462. // 1. you need three indices to draw a single face
  7463. // 2. a single segment consists of two faces
  7464. // 3. so we need to generate six (2*3) indices per segment
  7465. for (var _iy = 0; _iy < gridY; _iy++) {
  7466. for (var _ix = 0; _ix < gridX; _ix++) {
  7467. var a = numberOfVertices + _ix + gridX1 * _iy;
  7468. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7469. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7470. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7471. indices.push(a, b, d);
  7472. indices.push(b, c, d); // increase counter
  7473. groupCount += 6;
  7474. }
  7475. } // add a group to the geometry. this will ensure multi material support
  7476. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7477. groupStart += groupCount; // update total number of vertices
  7478. numberOfVertices += vertexCounter;
  7479. }
  7480. return _this;
  7481. }
  7482. return BoxBufferGeometry;
  7483. }(BufferGeometry);
  7484. /**
  7485. * Uniform Utilities
  7486. */
  7487. function cloneUniforms(src) {
  7488. var dst = {};
  7489. for (var u in src) {
  7490. dst[u] = {};
  7491. for (var p in src[u]) {
  7492. var property = src[u][p];
  7493. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture)) {
  7494. dst[u][p] = property.clone();
  7495. } else if (Array.isArray(property)) {
  7496. dst[u][p] = property.slice();
  7497. } else {
  7498. dst[u][p] = property;
  7499. }
  7500. }
  7501. }
  7502. return dst;
  7503. }
  7504. function mergeUniforms(uniforms) {
  7505. var merged = {};
  7506. for (var u = 0; u < uniforms.length; u++) {
  7507. var tmp = cloneUniforms(uniforms[u]);
  7508. for (var p in tmp) {
  7509. merged[p] = tmp[p];
  7510. }
  7511. }
  7512. return merged;
  7513. } // Legacy
  7514. var UniformsUtils = {
  7515. clone: cloneUniforms,
  7516. merge: mergeUniforms
  7517. };
  7518. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7519. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7520. /**
  7521. * parameters = {
  7522. * defines: { "label" : "value" },
  7523. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7524. *
  7525. * fragmentShader: <string>,
  7526. * vertexShader: <string>,
  7527. *
  7528. * wireframe: <boolean>,
  7529. * wireframeLinewidth: <float>,
  7530. *
  7531. * lights: <bool>,
  7532. *
  7533. * skinning: <bool>,
  7534. * morphTargets: <bool>,
  7535. * morphNormals: <bool>
  7536. * }
  7537. */
  7538. function ShaderMaterial(parameters) {
  7539. Material.call(this);
  7540. this.type = 'ShaderMaterial';
  7541. this.defines = {};
  7542. this.uniforms = {};
  7543. this.vertexShader = default_vertex;
  7544. this.fragmentShader = default_fragment;
  7545. this.linewidth = 1;
  7546. this.wireframe = false;
  7547. this.wireframeLinewidth = 1;
  7548. this.fog = false; // set to use scene fog
  7549. this.lights = false; // set to use scene lights
  7550. this.clipping = false; // set to use user-defined clipping planes
  7551. this.skinning = false; // set to use skinning attribute streams
  7552. this.morphTargets = false; // set to use morph targets
  7553. this.morphNormals = false; // set to use morph normals
  7554. this.extensions = {
  7555. derivatives: false,
  7556. // set to use derivatives
  7557. fragDepth: false,
  7558. // set to use fragment depth values
  7559. drawBuffers: false,
  7560. // set to use draw buffers
  7561. shaderTextureLOD: false // set to use shader texture LOD
  7562. }; // When rendered geometry doesn't include these attributes but the material does,
  7563. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7564. this.defaultAttributeValues = {
  7565. 'color': [1, 1, 1],
  7566. 'uv': [0, 0],
  7567. 'uv2': [0, 0]
  7568. };
  7569. this.index0AttributeName = undefined;
  7570. this.uniformsNeedUpdate = false;
  7571. this.glslVersion = null;
  7572. if (parameters !== undefined) {
  7573. if (parameters.attributes !== undefined) {
  7574. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  7575. }
  7576. this.setValues(parameters);
  7577. }
  7578. }
  7579. ShaderMaterial.prototype = Object.create(Material.prototype);
  7580. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7581. ShaderMaterial.prototype.isShaderMaterial = true;
  7582. ShaderMaterial.prototype.copy = function (source) {
  7583. Material.prototype.copy.call(this, source);
  7584. this.fragmentShader = source.fragmentShader;
  7585. this.vertexShader = source.vertexShader;
  7586. this.uniforms = cloneUniforms(source.uniforms);
  7587. this.defines = Object.assign({}, source.defines);
  7588. this.wireframe = source.wireframe;
  7589. this.wireframeLinewidth = source.wireframeLinewidth;
  7590. this.lights = source.lights;
  7591. this.clipping = source.clipping;
  7592. this.skinning = source.skinning;
  7593. this.morphTargets = source.morphTargets;
  7594. this.morphNormals = source.morphNormals;
  7595. this.extensions = Object.assign({}, source.extensions);
  7596. this.glslVersion = source.glslVersion;
  7597. return this;
  7598. };
  7599. ShaderMaterial.prototype.toJSON = function (meta) {
  7600. var data = Material.prototype.toJSON.call(this, meta);
  7601. data.glslVersion = this.glslVersion;
  7602. data.uniforms = {};
  7603. for (var name in this.uniforms) {
  7604. var uniform = this.uniforms[name];
  7605. var value = uniform.value;
  7606. if (value && value.isTexture) {
  7607. data.uniforms[name] = {
  7608. type: 't',
  7609. value: value.toJSON(meta).uuid
  7610. };
  7611. } else if (value && value.isColor) {
  7612. data.uniforms[name] = {
  7613. type: 'c',
  7614. value: value.getHex()
  7615. };
  7616. } else if (value && value.isVector2) {
  7617. data.uniforms[name] = {
  7618. type: 'v2',
  7619. value: value.toArray()
  7620. };
  7621. } else if (value && value.isVector3) {
  7622. data.uniforms[name] = {
  7623. type: 'v3',
  7624. value: value.toArray()
  7625. };
  7626. } else if (value && value.isVector4) {
  7627. data.uniforms[name] = {
  7628. type: 'v4',
  7629. value: value.toArray()
  7630. };
  7631. } else if (value && value.isMatrix3) {
  7632. data.uniforms[name] = {
  7633. type: 'm3',
  7634. value: value.toArray()
  7635. };
  7636. } else if (value && value.isMatrix4) {
  7637. data.uniforms[name] = {
  7638. type: 'm4',
  7639. value: value.toArray()
  7640. };
  7641. } else {
  7642. data.uniforms[name] = {
  7643. value: value
  7644. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7645. }
  7646. }
  7647. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  7648. data.vertexShader = this.vertexShader;
  7649. data.fragmentShader = this.fragmentShader;
  7650. var extensions = {};
  7651. for (var key in this.extensions) {
  7652. if (this.extensions[key] === true) extensions[key] = true;
  7653. }
  7654. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  7655. return data;
  7656. };
  7657. function Camera() {
  7658. Object3D.call(this);
  7659. this.type = 'Camera';
  7660. this.matrixWorldInverse = new Matrix4();
  7661. this.projectionMatrix = new Matrix4();
  7662. this.projectionMatrixInverse = new Matrix4();
  7663. }
  7664. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  7665. constructor: Camera,
  7666. isCamera: true,
  7667. copy: function copy(source, recursive) {
  7668. Object3D.prototype.copy.call(this, source, recursive);
  7669. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  7670. this.projectionMatrix.copy(source.projectionMatrix);
  7671. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  7672. return this;
  7673. },
  7674. getWorldDirection: function getWorldDirection(target) {
  7675. if (target === undefined) {
  7676. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  7677. target = new Vector3();
  7678. }
  7679. this.updateWorldMatrix(true, false);
  7680. var e = this.matrixWorld.elements;
  7681. return target.set(-e[8], -e[9], -e[10]).normalize();
  7682. },
  7683. updateMatrixWorld: function updateMatrixWorld(force) {
  7684. Object3D.prototype.updateMatrixWorld.call(this, force);
  7685. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  7686. },
  7687. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  7688. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  7689. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  7690. },
  7691. clone: function clone() {
  7692. return new this.constructor().copy(this);
  7693. }
  7694. });
  7695. function PerspectiveCamera(fov, aspect, near, far) {
  7696. if (fov === void 0) {
  7697. fov = 50;
  7698. }
  7699. if (aspect === void 0) {
  7700. aspect = 1;
  7701. }
  7702. if (near === void 0) {
  7703. near = 0.1;
  7704. }
  7705. if (far === void 0) {
  7706. far = 2000;
  7707. }
  7708. Camera.call(this);
  7709. this.type = 'PerspectiveCamera';
  7710. this.fov = fov;
  7711. this.zoom = 1;
  7712. this.near = near;
  7713. this.far = far;
  7714. this.focus = 10;
  7715. this.aspect = aspect;
  7716. this.view = null;
  7717. this.filmGauge = 35; // width of the film (default in millimeters)
  7718. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7719. this.updateProjectionMatrix();
  7720. }
  7721. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  7722. constructor: PerspectiveCamera,
  7723. isPerspectiveCamera: true,
  7724. copy: function copy(source, recursive) {
  7725. Camera.prototype.copy.call(this, source, recursive);
  7726. this.fov = source.fov;
  7727. this.zoom = source.zoom;
  7728. this.near = source.near;
  7729. this.far = source.far;
  7730. this.focus = source.focus;
  7731. this.aspect = source.aspect;
  7732. this.view = source.view === null ? null : Object.assign({}, source.view);
  7733. this.filmGauge = source.filmGauge;
  7734. this.filmOffset = source.filmOffset;
  7735. return this;
  7736. },
  7737. /**
  7738. * Sets the FOV by focal length in respect to the current .filmGauge.
  7739. *
  7740. * The default film gauge is 35, so that the focal length can be specified for
  7741. * a 35mm (full frame) camera.
  7742. *
  7743. * Values for focal length and film gauge must have the same unit.
  7744. */
  7745. setFocalLength: function setFocalLength(focalLength) {
  7746. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7747. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7748. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  7749. this.updateProjectionMatrix();
  7750. },
  7751. /**
  7752. * Calculates the focal length from the current .fov and .filmGauge.
  7753. */
  7754. getFocalLength: function getFocalLength() {
  7755. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  7756. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7757. },
  7758. getEffectiveFOV: function getEffectiveFOV() {
  7759. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  7760. },
  7761. getFilmWidth: function getFilmWidth() {
  7762. // film not completely covered in portrait format (aspect < 1)
  7763. return this.filmGauge * Math.min(this.aspect, 1);
  7764. },
  7765. getFilmHeight: function getFilmHeight() {
  7766. // film not completely covered in landscape format (aspect > 1)
  7767. return this.filmGauge / Math.max(this.aspect, 1);
  7768. },
  7769. /**
  7770. * Sets an offset in a larger frustum. This is useful for multi-window or
  7771. * multi-monitor/multi-machine setups.
  7772. *
  7773. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7774. * the monitors are in grid like this
  7775. *
  7776. * +---+---+---+
  7777. * | A | B | C |
  7778. * +---+---+---+
  7779. * | D | E | F |
  7780. * +---+---+---+
  7781. *
  7782. * then for each monitor you would call it like this
  7783. *
  7784. * const w = 1920;
  7785. * const h = 1080;
  7786. * const fullWidth = w * 3;
  7787. * const fullHeight = h * 2;
  7788. *
  7789. * --A--
  7790. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7791. * --B--
  7792. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7793. * --C--
  7794. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7795. * --D--
  7796. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7797. * --E--
  7798. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7799. * --F--
  7800. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7801. *
  7802. * Note there is no reason monitors have to be the same size or in a grid.
  7803. */
  7804. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  7805. this.aspect = fullWidth / fullHeight;
  7806. if (this.view === null) {
  7807. this.view = {
  7808. enabled: true,
  7809. fullWidth: 1,
  7810. fullHeight: 1,
  7811. offsetX: 0,
  7812. offsetY: 0,
  7813. width: 1,
  7814. height: 1
  7815. };
  7816. }
  7817. this.view.enabled = true;
  7818. this.view.fullWidth = fullWidth;
  7819. this.view.fullHeight = fullHeight;
  7820. this.view.offsetX = x;
  7821. this.view.offsetY = y;
  7822. this.view.width = width;
  7823. this.view.height = height;
  7824. this.updateProjectionMatrix();
  7825. },
  7826. clearViewOffset: function clearViewOffset() {
  7827. if (this.view !== null) {
  7828. this.view.enabled = false;
  7829. }
  7830. this.updateProjectionMatrix();
  7831. },
  7832. updateProjectionMatrix: function updateProjectionMatrix() {
  7833. var near = this.near;
  7834. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  7835. var height = 2 * top;
  7836. var width = this.aspect * height;
  7837. var left = -0.5 * width;
  7838. var view = this.view;
  7839. if (this.view !== null && this.view.enabled) {
  7840. var fullWidth = view.fullWidth,
  7841. fullHeight = view.fullHeight;
  7842. left += view.offsetX * width / fullWidth;
  7843. top -= view.offsetY * height / fullHeight;
  7844. width *= view.width / fullWidth;
  7845. height *= view.height / fullHeight;
  7846. }
  7847. var skew = this.filmOffset;
  7848. if (skew !== 0) left += near * skew / this.getFilmWidth();
  7849. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  7850. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  7851. },
  7852. toJSON: function toJSON(meta) {
  7853. var data = Object3D.prototype.toJSON.call(this, meta);
  7854. data.object.fov = this.fov;
  7855. data.object.zoom = this.zoom;
  7856. data.object.near = this.near;
  7857. data.object.far = this.far;
  7858. data.object.focus = this.focus;
  7859. data.object.aspect = this.aspect;
  7860. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  7861. data.object.filmGauge = this.filmGauge;
  7862. data.object.filmOffset = this.filmOffset;
  7863. return data;
  7864. }
  7865. });
  7866. var fov = 90,
  7867. aspect = 1;
  7868. function CubeCamera(near, far, renderTarget) {
  7869. Object3D.call(this);
  7870. this.type = 'CubeCamera';
  7871. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  7872. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  7873. return;
  7874. }
  7875. this.renderTarget = renderTarget;
  7876. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  7877. cameraPX.layers = this.layers;
  7878. cameraPX.up.set(0, -1, 0);
  7879. cameraPX.lookAt(new Vector3(1, 0, 0));
  7880. this.add(cameraPX);
  7881. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  7882. cameraNX.layers = this.layers;
  7883. cameraNX.up.set(0, -1, 0);
  7884. cameraNX.lookAt(new Vector3(-1, 0, 0));
  7885. this.add(cameraNX);
  7886. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  7887. cameraPY.layers = this.layers;
  7888. cameraPY.up.set(0, 0, 1);
  7889. cameraPY.lookAt(new Vector3(0, 1, 0));
  7890. this.add(cameraPY);
  7891. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  7892. cameraNY.layers = this.layers;
  7893. cameraNY.up.set(0, 0, -1);
  7894. cameraNY.lookAt(new Vector3(0, -1, 0));
  7895. this.add(cameraNY);
  7896. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  7897. cameraPZ.layers = this.layers;
  7898. cameraPZ.up.set(0, -1, 0);
  7899. cameraPZ.lookAt(new Vector3(0, 0, 1));
  7900. this.add(cameraPZ);
  7901. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  7902. cameraNZ.layers = this.layers;
  7903. cameraNZ.up.set(0, -1, 0);
  7904. cameraNZ.lookAt(new Vector3(0, 0, -1));
  7905. this.add(cameraNZ);
  7906. this.update = function (renderer, scene) {
  7907. if (this.parent === null) this.updateMatrixWorld();
  7908. var currentXrEnabled = renderer.xr.enabled;
  7909. var currentRenderTarget = renderer.getRenderTarget();
  7910. renderer.xr.enabled = false;
  7911. var generateMipmaps = renderTarget.texture.generateMipmaps;
  7912. renderTarget.texture.generateMipmaps = false;
  7913. renderer.setRenderTarget(renderTarget, 0);
  7914. renderer.render(scene, cameraPX);
  7915. renderer.setRenderTarget(renderTarget, 1);
  7916. renderer.render(scene, cameraNX);
  7917. renderer.setRenderTarget(renderTarget, 2);
  7918. renderer.render(scene, cameraPY);
  7919. renderer.setRenderTarget(renderTarget, 3);
  7920. renderer.render(scene, cameraNY);
  7921. renderer.setRenderTarget(renderTarget, 4);
  7922. renderer.render(scene, cameraPZ);
  7923. renderTarget.texture.generateMipmaps = generateMipmaps;
  7924. renderer.setRenderTarget(renderTarget, 5);
  7925. renderer.render(scene, cameraNZ);
  7926. renderer.setRenderTarget(currentRenderTarget);
  7927. renderer.xr.enabled = currentXrEnabled;
  7928. };
  7929. }
  7930. CubeCamera.prototype = Object.create(Object3D.prototype);
  7931. CubeCamera.prototype.constructor = CubeCamera;
  7932. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  7933. images = images !== undefined ? images : [];
  7934. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7935. format = format !== undefined ? format : RGBFormat;
  7936. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  7937. this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
  7938. //
  7939. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7940. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7941. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7942. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7943. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  7944. // when using WebGLCubeRenderTarget.texture as a cube texture.
  7945. this._needsFlipEnvMap = true;
  7946. }
  7947. CubeTexture.prototype = Object.create(Texture.prototype);
  7948. CubeTexture.prototype.constructor = CubeTexture;
  7949. CubeTexture.prototype.isCubeTexture = true;
  7950. Object.defineProperty(CubeTexture.prototype, 'images', {
  7951. get: function get() {
  7952. return this.image;
  7953. },
  7954. set: function set(value) {
  7955. this.image = value;
  7956. }
  7957. });
  7958. function WebGLCubeRenderTarget(size, options, dummy) {
  7959. if (Number.isInteger(options)) {
  7960. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  7961. options = dummy;
  7962. }
  7963. WebGLRenderTarget.call(this, size, size, options);
  7964. options = options || {};
  7965. this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  7966. this.texture._needsFlipEnvMap = false;
  7967. }
  7968. WebGLCubeRenderTarget.prototype = Object.create(WebGLRenderTarget.prototype);
  7969. WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
  7970. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  7971. WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function (renderer, texture) {
  7972. this.texture.type = texture.type;
  7973. this.texture.format = RGBAFormat; // see #18859
  7974. this.texture.encoding = texture.encoding;
  7975. this.texture.generateMipmaps = texture.generateMipmaps;
  7976. this.texture.minFilter = texture.minFilter;
  7977. this.texture.magFilter = texture.magFilter;
  7978. var shader = {
  7979. uniforms: {
  7980. tEquirect: {
  7981. value: null
  7982. }
  7983. },
  7984. vertexShader:
  7985. /* glsl */
  7986. "\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",
  7987. fragmentShader:
  7988. /* glsl */
  7989. "\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"
  7990. };
  7991. var geometry = new BoxBufferGeometry(5, 5, 5);
  7992. var material = new ShaderMaterial({
  7993. name: 'CubemapFromEquirect',
  7994. uniforms: cloneUniforms(shader.uniforms),
  7995. vertexShader: shader.vertexShader,
  7996. fragmentShader: shader.fragmentShader,
  7997. side: BackSide,
  7998. blending: NoBlending
  7999. });
  8000. material.uniforms.tEquirect.value = texture;
  8001. var mesh = new Mesh(geometry, material);
  8002. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  8003. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  8004. var camera = new CubeCamera(1, 10, this);
  8005. camera.update(renderer, mesh);
  8006. texture.minFilter = currentMinFilter;
  8007. mesh.geometry.dispose();
  8008. mesh.material.dispose();
  8009. return this;
  8010. };
  8011. WebGLCubeRenderTarget.prototype.clear = function (renderer, color, depth, stencil) {
  8012. var currentRenderTarget = renderer.getRenderTarget();
  8013. for (var i = 0; i < 6; i++) {
  8014. renderer.setRenderTarget(this, i);
  8015. renderer.clear(color, depth, stencil);
  8016. }
  8017. renderer.setRenderTarget(currentRenderTarget);
  8018. };
  8019. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  8020. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8021. this.image = {
  8022. data: data || null,
  8023. width: width || 1,
  8024. height: height || 1
  8025. };
  8026. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8027. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8028. this.generateMipmaps = false;
  8029. this.flipY = false;
  8030. this.unpackAlignment = 1;
  8031. this.needsUpdate = true;
  8032. }
  8033. DataTexture.prototype = Object.create(Texture.prototype);
  8034. DataTexture.prototype.constructor = DataTexture;
  8035. DataTexture.prototype.isDataTexture = true;
  8036. var _sphere$1 = /*@__PURE__*/new Sphere();
  8037. var _vector$5 = /*@__PURE__*/new Vector3();
  8038. var Frustum = /*#__PURE__*/function () {
  8039. function Frustum(p0, p1, p2, p3, p4, p5) {
  8040. 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()];
  8041. }
  8042. var _proto = Frustum.prototype;
  8043. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  8044. var planes = this.planes;
  8045. planes[0].copy(p0);
  8046. planes[1].copy(p1);
  8047. planes[2].copy(p2);
  8048. planes[3].copy(p3);
  8049. planes[4].copy(p4);
  8050. planes[5].copy(p5);
  8051. return this;
  8052. };
  8053. _proto.clone = function clone() {
  8054. return new this.constructor().copy(this);
  8055. };
  8056. _proto.copy = function copy(frustum) {
  8057. var planes = this.planes;
  8058. for (var i = 0; i < 6; i++) {
  8059. planes[i].copy(frustum.planes[i]);
  8060. }
  8061. return this;
  8062. };
  8063. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  8064. var planes = this.planes;
  8065. var me = m.elements;
  8066. var me0 = me[0],
  8067. me1 = me[1],
  8068. me2 = me[2],
  8069. me3 = me[3];
  8070. var me4 = me[4],
  8071. me5 = me[5],
  8072. me6 = me[6],
  8073. me7 = me[7];
  8074. var me8 = me[8],
  8075. me9 = me[9],
  8076. me10 = me[10],
  8077. me11 = me[11];
  8078. var me12 = me[12],
  8079. me13 = me[13],
  8080. me14 = me[14],
  8081. me15 = me[15];
  8082. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  8083. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  8084. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  8085. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  8086. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  8087. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  8088. return this;
  8089. };
  8090. _proto.intersectsObject = function intersectsObject(object) {
  8091. var geometry = object.geometry;
  8092. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  8093. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  8094. return this.intersectsSphere(_sphere$1);
  8095. };
  8096. _proto.intersectsSprite = function intersectsSprite(sprite) {
  8097. _sphere$1.center.set(0, 0, 0);
  8098. _sphere$1.radius = 0.7071067811865476;
  8099. _sphere$1.applyMatrix4(sprite.matrixWorld);
  8100. return this.intersectsSphere(_sphere$1);
  8101. };
  8102. _proto.intersectsSphere = function intersectsSphere(sphere) {
  8103. var planes = this.planes;
  8104. var center = sphere.center;
  8105. var negRadius = -sphere.radius;
  8106. for (var i = 0; i < 6; i++) {
  8107. var distance = planes[i].distanceToPoint(center);
  8108. if (distance < negRadius) {
  8109. return false;
  8110. }
  8111. }
  8112. return true;
  8113. };
  8114. _proto.intersectsBox = function intersectsBox(box) {
  8115. var planes = this.planes;
  8116. for (var i = 0; i < 6; i++) {
  8117. var plane = planes[i]; // corner at max distance
  8118. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8119. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8120. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8121. if (plane.distanceToPoint(_vector$5) < 0) {
  8122. return false;
  8123. }
  8124. }
  8125. return true;
  8126. };
  8127. _proto.containsPoint = function containsPoint(point) {
  8128. var planes = this.planes;
  8129. for (var i = 0; i < 6; i++) {
  8130. if (planes[i].distanceToPoint(point) < 0) {
  8131. return false;
  8132. }
  8133. }
  8134. return true;
  8135. };
  8136. return Frustum;
  8137. }();
  8138. function WebGLAnimation() {
  8139. var context = null;
  8140. var isAnimating = false;
  8141. var animationLoop = null;
  8142. var requestId = null;
  8143. function onAnimationFrame(time, frame) {
  8144. animationLoop(time, frame);
  8145. requestId = context.requestAnimationFrame(onAnimationFrame);
  8146. }
  8147. return {
  8148. start: function start() {
  8149. if (isAnimating === true) return;
  8150. if (animationLoop === null) return;
  8151. requestId = context.requestAnimationFrame(onAnimationFrame);
  8152. isAnimating = true;
  8153. },
  8154. stop: function stop() {
  8155. context.cancelAnimationFrame(requestId);
  8156. isAnimating = false;
  8157. },
  8158. setAnimationLoop: function setAnimationLoop(callback) {
  8159. animationLoop = callback;
  8160. },
  8161. setContext: function setContext(value) {
  8162. context = value;
  8163. }
  8164. };
  8165. }
  8166. function WebGLAttributes(gl, capabilities) {
  8167. var isWebGL2 = capabilities.isWebGL2;
  8168. var buffers = new WeakMap();
  8169. function createBuffer(attribute, bufferType) {
  8170. var array = attribute.array;
  8171. var usage = attribute.usage;
  8172. var buffer = gl.createBuffer();
  8173. gl.bindBuffer(bufferType, buffer);
  8174. gl.bufferData(bufferType, array, usage);
  8175. attribute.onUploadCallback();
  8176. var type = 5126;
  8177. if (array instanceof Float32Array) {
  8178. type = 5126;
  8179. } else if (array instanceof Float64Array) {
  8180. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8181. } else if (array instanceof Uint16Array) {
  8182. if (attribute.isFloat16BufferAttribute) {
  8183. if (isWebGL2) {
  8184. type = 5131;
  8185. } else {
  8186. console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
  8187. }
  8188. } else {
  8189. type = 5123;
  8190. }
  8191. } else if (array instanceof Int16Array) {
  8192. type = 5122;
  8193. } else if (array instanceof Uint32Array) {
  8194. type = 5125;
  8195. } else if (array instanceof Int32Array) {
  8196. type = 5124;
  8197. } else if (array instanceof Int8Array) {
  8198. type = 5120;
  8199. } else if (array instanceof Uint8Array) {
  8200. type = 5121;
  8201. }
  8202. return {
  8203. buffer: buffer,
  8204. type: type,
  8205. bytesPerElement: array.BYTES_PER_ELEMENT,
  8206. version: attribute.version
  8207. };
  8208. }
  8209. function updateBuffer(buffer, attribute, bufferType) {
  8210. var array = attribute.array;
  8211. var updateRange = attribute.updateRange;
  8212. gl.bindBuffer(bufferType, buffer);
  8213. if (updateRange.count === -1) {
  8214. // Not using update ranges
  8215. gl.bufferSubData(bufferType, 0, array);
  8216. } else {
  8217. if (isWebGL2) {
  8218. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8219. } else {
  8220. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8221. }
  8222. updateRange.count = -1; // reset range
  8223. }
  8224. } //
  8225. function get(attribute) {
  8226. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8227. return buffers.get(attribute);
  8228. }
  8229. function remove(attribute) {
  8230. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8231. var data = buffers.get(attribute);
  8232. if (data) {
  8233. gl.deleteBuffer(data.buffer);
  8234. buffers.delete(attribute);
  8235. }
  8236. }
  8237. function update(attribute, bufferType) {
  8238. if (attribute.isGLBufferAttribute) {
  8239. var cached = buffers.get(attribute);
  8240. if (!cached || cached.version < attribute.version) {
  8241. buffers.set(attribute, {
  8242. buffer: attribute.buffer,
  8243. type: attribute.type,
  8244. bytesPerElement: attribute.elementSize,
  8245. version: attribute.version
  8246. });
  8247. }
  8248. return;
  8249. }
  8250. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8251. var data = buffers.get(attribute);
  8252. if (data === undefined) {
  8253. buffers.set(attribute, createBuffer(attribute, bufferType));
  8254. } else if (data.version < attribute.version) {
  8255. updateBuffer(data.buffer, attribute, bufferType);
  8256. data.version = attribute.version;
  8257. }
  8258. }
  8259. return {
  8260. get: get,
  8261. remove: remove,
  8262. update: update
  8263. };
  8264. }
  8265. var PlaneBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8266. _inheritsLoose(PlaneBufferGeometry, _BufferGeometry);
  8267. function PlaneBufferGeometry(width, height, widthSegments, heightSegments) {
  8268. var _this;
  8269. if (width === void 0) {
  8270. width = 1;
  8271. }
  8272. if (height === void 0) {
  8273. height = 1;
  8274. }
  8275. if (widthSegments === void 0) {
  8276. widthSegments = 1;
  8277. }
  8278. if (heightSegments === void 0) {
  8279. heightSegments = 1;
  8280. }
  8281. _this = _BufferGeometry.call(this) || this;
  8282. _this.type = 'PlaneBufferGeometry';
  8283. _this.parameters = {
  8284. width: width,
  8285. height: height,
  8286. widthSegments: widthSegments,
  8287. heightSegments: heightSegments
  8288. };
  8289. var width_half = width / 2;
  8290. var height_half = height / 2;
  8291. var gridX = Math.floor(widthSegments);
  8292. var gridY = Math.floor(heightSegments);
  8293. var gridX1 = gridX + 1;
  8294. var gridY1 = gridY + 1;
  8295. var segment_width = width / gridX;
  8296. var segment_height = height / gridY; //
  8297. var indices = [];
  8298. var vertices = [];
  8299. var normals = [];
  8300. var uvs = [];
  8301. for (var iy = 0; iy < gridY1; iy++) {
  8302. var y = iy * segment_height - height_half;
  8303. for (var ix = 0; ix < gridX1; ix++) {
  8304. var x = ix * segment_width - width_half;
  8305. vertices.push(x, -y, 0);
  8306. normals.push(0, 0, 1);
  8307. uvs.push(ix / gridX);
  8308. uvs.push(1 - iy / gridY);
  8309. }
  8310. }
  8311. for (var _iy = 0; _iy < gridY; _iy++) {
  8312. for (var _ix = 0; _ix < gridX; _ix++) {
  8313. var a = _ix + gridX1 * _iy;
  8314. var b = _ix + gridX1 * (_iy + 1);
  8315. var c = _ix + 1 + gridX1 * (_iy + 1);
  8316. var d = _ix + 1 + gridX1 * _iy;
  8317. indices.push(a, b, d);
  8318. indices.push(b, c, d);
  8319. }
  8320. }
  8321. _this.setIndex(indices);
  8322. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8323. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8324. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8325. return _this;
  8326. }
  8327. return PlaneBufferGeometry;
  8328. }(BufferGeometry);
  8329. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8330. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8331. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8332. 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";
  8333. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8334. var begin_vertex = "vec3 transformed = vec3( position );";
  8335. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8336. 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";
  8337. 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";
  8338. 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";
  8339. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8340. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8341. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8342. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8343. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8344. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8345. 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";
  8346. 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}";
  8347. 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";
  8348. 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";
  8349. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8350. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8351. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8352. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8353. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8354. 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}";
  8355. 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";
  8356. 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";
  8357. 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";
  8358. 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";
  8359. 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";
  8360. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8361. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8362. 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";
  8363. 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";
  8364. 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}";
  8365. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8366. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8367. 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";
  8368. 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";
  8369. 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";
  8370. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8371. 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)";
  8372. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8373. 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)";
  8374. 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";
  8375. 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}";
  8376. 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";
  8377. 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";
  8378. 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";
  8379. 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";
  8380. 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";
  8381. 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";
  8382. 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";
  8383. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8384. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8385. 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";
  8386. 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";
  8387. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8388. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8389. 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";
  8390. 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";
  8391. 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";
  8392. 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;";
  8393. 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";
  8394. 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";
  8395. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8396. 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";
  8397. 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";
  8398. 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}";
  8399. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8400. 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;";
  8401. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8402. 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";
  8403. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8404. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8405. 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";
  8406. 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";
  8407. 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";
  8408. 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}";
  8409. 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";
  8410. 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";
  8411. 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";
  8412. 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";
  8413. 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";
  8414. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8415. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8416. 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; }";
  8417. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8418. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8419. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8420. 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";
  8421. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8422. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8423. 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";
  8424. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8425. 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";
  8426. 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}";
  8427. 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}";
  8428. 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}";
  8429. 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}";
  8430. 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}";
  8431. 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}";
  8432. 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}";
  8433. 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}";
  8434. 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}";
  8435. 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}";
  8436. 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}";
  8437. 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}";
  8438. 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}";
  8439. 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}";
  8440. 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}";
  8441. 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}";
  8442. 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}";
  8443. 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}";
  8444. 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}";
  8445. 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}";
  8446. 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}";
  8447. 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}";
  8448. 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}";
  8449. 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}";
  8450. 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}";
  8451. 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}";
  8452. 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}";
  8453. 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}";
  8454. 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}";
  8455. 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}";
  8456. 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}";
  8457. 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}";
  8458. var ShaderChunk = {
  8459. alphamap_fragment: alphamap_fragment,
  8460. alphamap_pars_fragment: alphamap_pars_fragment,
  8461. alphatest_fragment: alphatest_fragment,
  8462. aomap_fragment: aomap_fragment,
  8463. aomap_pars_fragment: aomap_pars_fragment,
  8464. begin_vertex: begin_vertex,
  8465. beginnormal_vertex: beginnormal_vertex,
  8466. bsdfs: bsdfs,
  8467. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8468. clipping_planes_fragment: clipping_planes_fragment,
  8469. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8470. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8471. clipping_planes_vertex: clipping_planes_vertex,
  8472. color_fragment: color_fragment,
  8473. color_pars_fragment: color_pars_fragment,
  8474. color_pars_vertex: color_pars_vertex,
  8475. color_vertex: color_vertex,
  8476. common: common,
  8477. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8478. defaultnormal_vertex: defaultnormal_vertex,
  8479. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8480. displacementmap_vertex: displacementmap_vertex,
  8481. emissivemap_fragment: emissivemap_fragment,
  8482. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8483. encodings_fragment: encodings_fragment,
  8484. encodings_pars_fragment: encodings_pars_fragment,
  8485. envmap_fragment: envmap_fragment,
  8486. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8487. envmap_pars_fragment: envmap_pars_fragment,
  8488. envmap_pars_vertex: envmap_pars_vertex,
  8489. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8490. envmap_vertex: envmap_vertex,
  8491. fog_vertex: fog_vertex,
  8492. fog_pars_vertex: fog_pars_vertex,
  8493. fog_fragment: fog_fragment,
  8494. fog_pars_fragment: fog_pars_fragment,
  8495. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8496. lightmap_fragment: lightmap_fragment,
  8497. lightmap_pars_fragment: lightmap_pars_fragment,
  8498. lights_lambert_vertex: lights_lambert_vertex,
  8499. lights_pars_begin: lights_pars_begin,
  8500. lights_toon_fragment: lights_toon_fragment,
  8501. lights_toon_pars_fragment: lights_toon_pars_fragment,
  8502. lights_phong_fragment: lights_phong_fragment,
  8503. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8504. lights_physical_fragment: lights_physical_fragment,
  8505. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8506. lights_fragment_begin: lights_fragment_begin,
  8507. lights_fragment_maps: lights_fragment_maps,
  8508. lights_fragment_end: lights_fragment_end,
  8509. logdepthbuf_fragment: logdepthbuf_fragment,
  8510. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8511. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8512. logdepthbuf_vertex: logdepthbuf_vertex,
  8513. map_fragment: map_fragment,
  8514. map_pars_fragment: map_pars_fragment,
  8515. map_particle_fragment: map_particle_fragment,
  8516. map_particle_pars_fragment: map_particle_pars_fragment,
  8517. metalnessmap_fragment: metalnessmap_fragment,
  8518. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  8519. morphnormal_vertex: morphnormal_vertex,
  8520. morphtarget_pars_vertex: morphtarget_pars_vertex,
  8521. morphtarget_vertex: morphtarget_vertex,
  8522. normal_fragment_begin: normal_fragment_begin,
  8523. normal_fragment_maps: normal_fragment_maps,
  8524. normalmap_pars_fragment: normalmap_pars_fragment,
  8525. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  8526. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  8527. clearcoat_pars_fragment: clearcoat_pars_fragment,
  8528. packing: packing,
  8529. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  8530. project_vertex: project_vertex,
  8531. dithering_fragment: dithering_fragment,
  8532. dithering_pars_fragment: dithering_pars_fragment,
  8533. roughnessmap_fragment: roughnessmap_fragment,
  8534. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  8535. shadowmap_pars_fragment: shadowmap_pars_fragment,
  8536. shadowmap_pars_vertex: shadowmap_pars_vertex,
  8537. shadowmap_vertex: shadowmap_vertex,
  8538. shadowmask_pars_fragment: shadowmask_pars_fragment,
  8539. skinbase_vertex: skinbase_vertex,
  8540. skinning_pars_vertex: skinning_pars_vertex,
  8541. skinning_vertex: skinning_vertex,
  8542. skinnormal_vertex: skinnormal_vertex,
  8543. specularmap_fragment: specularmap_fragment,
  8544. specularmap_pars_fragment: specularmap_pars_fragment,
  8545. tonemapping_fragment: tonemapping_fragment,
  8546. tonemapping_pars_fragment: tonemapping_pars_fragment,
  8547. transmissionmap_fragment: transmissionmap_fragment,
  8548. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  8549. uv_pars_fragment: uv_pars_fragment,
  8550. uv_pars_vertex: uv_pars_vertex,
  8551. uv_vertex: uv_vertex,
  8552. uv2_pars_fragment: uv2_pars_fragment,
  8553. uv2_pars_vertex: uv2_pars_vertex,
  8554. uv2_vertex: uv2_vertex,
  8555. worldpos_vertex: worldpos_vertex,
  8556. background_frag: background_frag,
  8557. background_vert: background_vert,
  8558. cube_frag: cube_frag,
  8559. cube_vert: cube_vert,
  8560. depth_frag: depth_frag,
  8561. depth_vert: depth_vert,
  8562. distanceRGBA_frag: distanceRGBA_frag,
  8563. distanceRGBA_vert: distanceRGBA_vert,
  8564. equirect_frag: equirect_frag,
  8565. equirect_vert: equirect_vert,
  8566. linedashed_frag: linedashed_frag,
  8567. linedashed_vert: linedashed_vert,
  8568. meshbasic_frag: meshbasic_frag,
  8569. meshbasic_vert: meshbasic_vert,
  8570. meshlambert_frag: meshlambert_frag,
  8571. meshlambert_vert: meshlambert_vert,
  8572. meshmatcap_frag: meshmatcap_frag,
  8573. meshmatcap_vert: meshmatcap_vert,
  8574. meshtoon_frag: meshtoon_frag,
  8575. meshtoon_vert: meshtoon_vert,
  8576. meshphong_frag: meshphong_frag,
  8577. meshphong_vert: meshphong_vert,
  8578. meshphysical_frag: meshphysical_frag,
  8579. meshphysical_vert: meshphysical_vert,
  8580. normal_frag: normal_frag,
  8581. normal_vert: normal_vert,
  8582. points_frag: points_frag,
  8583. points_vert: points_vert,
  8584. shadow_frag: shadow_frag,
  8585. shadow_vert: shadow_vert,
  8586. sprite_frag: sprite_frag,
  8587. sprite_vert: sprite_vert
  8588. };
  8589. /**
  8590. * Uniforms library for shared webgl shaders
  8591. */
  8592. var UniformsLib = {
  8593. common: {
  8594. diffuse: {
  8595. value: new Color(0xeeeeee)
  8596. },
  8597. opacity: {
  8598. value: 1.0
  8599. },
  8600. map: {
  8601. value: null
  8602. },
  8603. uvTransform: {
  8604. value: new Matrix3()
  8605. },
  8606. uv2Transform: {
  8607. value: new Matrix3()
  8608. },
  8609. alphaMap: {
  8610. value: null
  8611. }
  8612. },
  8613. specularmap: {
  8614. specularMap: {
  8615. value: null
  8616. }
  8617. },
  8618. envmap: {
  8619. envMap: {
  8620. value: null
  8621. },
  8622. flipEnvMap: {
  8623. value: -1
  8624. },
  8625. reflectivity: {
  8626. value: 1.0
  8627. },
  8628. refractionRatio: {
  8629. value: 0.98
  8630. },
  8631. maxMipLevel: {
  8632. value: 0
  8633. }
  8634. },
  8635. aomap: {
  8636. aoMap: {
  8637. value: null
  8638. },
  8639. aoMapIntensity: {
  8640. value: 1
  8641. }
  8642. },
  8643. lightmap: {
  8644. lightMap: {
  8645. value: null
  8646. },
  8647. lightMapIntensity: {
  8648. value: 1
  8649. }
  8650. },
  8651. emissivemap: {
  8652. emissiveMap: {
  8653. value: null
  8654. }
  8655. },
  8656. bumpmap: {
  8657. bumpMap: {
  8658. value: null
  8659. },
  8660. bumpScale: {
  8661. value: 1
  8662. }
  8663. },
  8664. normalmap: {
  8665. normalMap: {
  8666. value: null
  8667. },
  8668. normalScale: {
  8669. value: new Vector2(1, 1)
  8670. }
  8671. },
  8672. displacementmap: {
  8673. displacementMap: {
  8674. value: null
  8675. },
  8676. displacementScale: {
  8677. value: 1
  8678. },
  8679. displacementBias: {
  8680. value: 0
  8681. }
  8682. },
  8683. roughnessmap: {
  8684. roughnessMap: {
  8685. value: null
  8686. }
  8687. },
  8688. metalnessmap: {
  8689. metalnessMap: {
  8690. value: null
  8691. }
  8692. },
  8693. gradientmap: {
  8694. gradientMap: {
  8695. value: null
  8696. }
  8697. },
  8698. fog: {
  8699. fogDensity: {
  8700. value: 0.00025
  8701. },
  8702. fogNear: {
  8703. value: 1
  8704. },
  8705. fogFar: {
  8706. value: 2000
  8707. },
  8708. fogColor: {
  8709. value: new Color(0xffffff)
  8710. }
  8711. },
  8712. lights: {
  8713. ambientLightColor: {
  8714. value: []
  8715. },
  8716. lightProbe: {
  8717. value: []
  8718. },
  8719. directionalLights: {
  8720. value: [],
  8721. properties: {
  8722. direction: {},
  8723. color: {}
  8724. }
  8725. },
  8726. directionalLightShadows: {
  8727. value: [],
  8728. properties: {
  8729. shadowBias: {},
  8730. shadowNormalBias: {},
  8731. shadowRadius: {},
  8732. shadowMapSize: {}
  8733. }
  8734. },
  8735. directionalShadowMap: {
  8736. value: []
  8737. },
  8738. directionalShadowMatrix: {
  8739. value: []
  8740. },
  8741. spotLights: {
  8742. value: [],
  8743. properties: {
  8744. color: {},
  8745. position: {},
  8746. direction: {},
  8747. distance: {},
  8748. coneCos: {},
  8749. penumbraCos: {},
  8750. decay: {}
  8751. }
  8752. },
  8753. spotLightShadows: {
  8754. value: [],
  8755. properties: {
  8756. shadowBias: {},
  8757. shadowNormalBias: {},
  8758. shadowRadius: {},
  8759. shadowMapSize: {}
  8760. }
  8761. },
  8762. spotShadowMap: {
  8763. value: []
  8764. },
  8765. spotShadowMatrix: {
  8766. value: []
  8767. },
  8768. pointLights: {
  8769. value: [],
  8770. properties: {
  8771. color: {},
  8772. position: {},
  8773. decay: {},
  8774. distance: {}
  8775. }
  8776. },
  8777. pointLightShadows: {
  8778. value: [],
  8779. properties: {
  8780. shadowBias: {},
  8781. shadowNormalBias: {},
  8782. shadowRadius: {},
  8783. shadowMapSize: {},
  8784. shadowCameraNear: {},
  8785. shadowCameraFar: {}
  8786. }
  8787. },
  8788. pointShadowMap: {
  8789. value: []
  8790. },
  8791. pointShadowMatrix: {
  8792. value: []
  8793. },
  8794. hemisphereLights: {
  8795. value: [],
  8796. properties: {
  8797. direction: {},
  8798. skyColor: {},
  8799. groundColor: {}
  8800. }
  8801. },
  8802. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8803. rectAreaLights: {
  8804. value: [],
  8805. properties: {
  8806. color: {},
  8807. position: {},
  8808. width: {},
  8809. height: {}
  8810. }
  8811. },
  8812. ltc_1: {
  8813. value: null
  8814. },
  8815. ltc_2: {
  8816. value: null
  8817. }
  8818. },
  8819. points: {
  8820. diffuse: {
  8821. value: new Color(0xeeeeee)
  8822. },
  8823. opacity: {
  8824. value: 1.0
  8825. },
  8826. size: {
  8827. value: 1.0
  8828. },
  8829. scale: {
  8830. value: 1.0
  8831. },
  8832. map: {
  8833. value: null
  8834. },
  8835. alphaMap: {
  8836. value: null
  8837. },
  8838. uvTransform: {
  8839. value: new Matrix3()
  8840. }
  8841. },
  8842. sprite: {
  8843. diffuse: {
  8844. value: new Color(0xeeeeee)
  8845. },
  8846. opacity: {
  8847. value: 1.0
  8848. },
  8849. center: {
  8850. value: new Vector2(0.5, 0.5)
  8851. },
  8852. rotation: {
  8853. value: 0.0
  8854. },
  8855. map: {
  8856. value: null
  8857. },
  8858. alphaMap: {
  8859. value: null
  8860. },
  8861. uvTransform: {
  8862. value: new Matrix3()
  8863. }
  8864. }
  8865. };
  8866. var ShaderLib = {
  8867. basic: {
  8868. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  8869. vertexShader: ShaderChunk.meshbasic_vert,
  8870. fragmentShader: ShaderChunk.meshbasic_frag
  8871. },
  8872. lambert: {
  8873. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  8874. emissive: {
  8875. value: new Color(0x000000)
  8876. }
  8877. }]),
  8878. vertexShader: ShaderChunk.meshlambert_vert,
  8879. fragmentShader: ShaderChunk.meshlambert_frag
  8880. },
  8881. phong: {
  8882. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  8883. emissive: {
  8884. value: new Color(0x000000)
  8885. },
  8886. specular: {
  8887. value: new Color(0x111111)
  8888. },
  8889. shininess: {
  8890. value: 30
  8891. }
  8892. }]),
  8893. vertexShader: ShaderChunk.meshphong_vert,
  8894. fragmentShader: ShaderChunk.meshphong_frag
  8895. },
  8896. standard: {
  8897. 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, {
  8898. emissive: {
  8899. value: new Color(0x000000)
  8900. },
  8901. roughness: {
  8902. value: 1.0
  8903. },
  8904. metalness: {
  8905. value: 0.0
  8906. },
  8907. envMapIntensity: {
  8908. value: 1
  8909. } // temporary
  8910. }]),
  8911. vertexShader: ShaderChunk.meshphysical_vert,
  8912. fragmentShader: ShaderChunk.meshphysical_frag
  8913. },
  8914. toon: {
  8915. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  8916. emissive: {
  8917. value: new Color(0x000000)
  8918. }
  8919. }]),
  8920. vertexShader: ShaderChunk.meshtoon_vert,
  8921. fragmentShader: ShaderChunk.meshtoon_frag
  8922. },
  8923. matcap: {
  8924. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  8925. matcap: {
  8926. value: null
  8927. }
  8928. }]),
  8929. vertexShader: ShaderChunk.meshmatcap_vert,
  8930. fragmentShader: ShaderChunk.meshmatcap_frag
  8931. },
  8932. points: {
  8933. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  8934. vertexShader: ShaderChunk.points_vert,
  8935. fragmentShader: ShaderChunk.points_frag
  8936. },
  8937. dashed: {
  8938. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  8939. scale: {
  8940. value: 1
  8941. },
  8942. dashSize: {
  8943. value: 1
  8944. },
  8945. totalSize: {
  8946. value: 2
  8947. }
  8948. }]),
  8949. vertexShader: ShaderChunk.linedashed_vert,
  8950. fragmentShader: ShaderChunk.linedashed_frag
  8951. },
  8952. depth: {
  8953. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  8954. vertexShader: ShaderChunk.depth_vert,
  8955. fragmentShader: ShaderChunk.depth_frag
  8956. },
  8957. normal: {
  8958. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  8959. opacity: {
  8960. value: 1.0
  8961. }
  8962. }]),
  8963. vertexShader: ShaderChunk.normal_vert,
  8964. fragmentShader: ShaderChunk.normal_frag
  8965. },
  8966. sprite: {
  8967. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  8968. vertexShader: ShaderChunk.sprite_vert,
  8969. fragmentShader: ShaderChunk.sprite_frag
  8970. },
  8971. background: {
  8972. uniforms: {
  8973. uvTransform: {
  8974. value: new Matrix3()
  8975. },
  8976. t2D: {
  8977. value: null
  8978. }
  8979. },
  8980. vertexShader: ShaderChunk.background_vert,
  8981. fragmentShader: ShaderChunk.background_frag
  8982. },
  8983. /* -------------------------------------------------------------------------
  8984. // Cube map shader
  8985. ------------------------------------------------------------------------- */
  8986. cube: {
  8987. uniforms: mergeUniforms([UniformsLib.envmap, {
  8988. opacity: {
  8989. value: 1.0
  8990. }
  8991. }]),
  8992. vertexShader: ShaderChunk.cube_vert,
  8993. fragmentShader: ShaderChunk.cube_frag
  8994. },
  8995. equirect: {
  8996. uniforms: {
  8997. tEquirect: {
  8998. value: null
  8999. }
  9000. },
  9001. vertexShader: ShaderChunk.equirect_vert,
  9002. fragmentShader: ShaderChunk.equirect_frag
  9003. },
  9004. distanceRGBA: {
  9005. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  9006. referencePosition: {
  9007. value: new Vector3()
  9008. },
  9009. nearDistance: {
  9010. value: 1
  9011. },
  9012. farDistance: {
  9013. value: 1000
  9014. }
  9015. }]),
  9016. vertexShader: ShaderChunk.distanceRGBA_vert,
  9017. fragmentShader: ShaderChunk.distanceRGBA_frag
  9018. },
  9019. shadow: {
  9020. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  9021. color: {
  9022. value: new Color(0x00000)
  9023. },
  9024. opacity: {
  9025. value: 1.0
  9026. }
  9027. }]),
  9028. vertexShader: ShaderChunk.shadow_vert,
  9029. fragmentShader: ShaderChunk.shadow_frag
  9030. }
  9031. };
  9032. ShaderLib.physical = {
  9033. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  9034. clearcoat: {
  9035. value: 0
  9036. },
  9037. clearcoatMap: {
  9038. value: null
  9039. },
  9040. clearcoatRoughness: {
  9041. value: 0
  9042. },
  9043. clearcoatRoughnessMap: {
  9044. value: null
  9045. },
  9046. clearcoatNormalScale: {
  9047. value: new Vector2(1, 1)
  9048. },
  9049. clearcoatNormalMap: {
  9050. value: null
  9051. },
  9052. sheen: {
  9053. value: new Color(0x000000)
  9054. },
  9055. transmission: {
  9056. value: 0
  9057. },
  9058. transmissionMap: {
  9059. value: null
  9060. }
  9061. }]),
  9062. vertexShader: ShaderChunk.meshphysical_vert,
  9063. fragmentShader: ShaderChunk.meshphysical_frag
  9064. };
  9065. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  9066. var clearColor = new Color(0x000000);
  9067. var clearAlpha = 0;
  9068. var planeMesh;
  9069. var boxMesh;
  9070. var currentBackground = null;
  9071. var currentBackgroundVersion = 0;
  9072. var currentTonemapping = null;
  9073. function render(renderList, scene, camera, forceClear) {
  9074. var background = scene.isScene === true ? scene.background : null;
  9075. if (background && background.isTexture) {
  9076. background = cubemaps.get(background);
  9077. } // Ignore background in AR
  9078. // TODO: Reconsider this.
  9079. var xr = renderer.xr;
  9080. var session = xr.getSession && xr.getSession();
  9081. if (session && session.environmentBlendMode === 'additive') {
  9082. background = null;
  9083. }
  9084. if (background === null) {
  9085. setClear(clearColor, clearAlpha);
  9086. } else if (background && background.isColor) {
  9087. setClear(background, 1);
  9088. forceClear = true;
  9089. }
  9090. if (renderer.autoClear || forceClear) {
  9091. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  9092. }
  9093. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  9094. if (boxMesh === undefined) {
  9095. boxMesh = new Mesh(new BoxBufferGeometry(1, 1, 1), new ShaderMaterial({
  9096. name: 'BackgroundCubeMaterial',
  9097. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  9098. vertexShader: ShaderLib.cube.vertexShader,
  9099. fragmentShader: ShaderLib.cube.fragmentShader,
  9100. side: BackSide,
  9101. depthTest: false,
  9102. depthWrite: false,
  9103. fog: false
  9104. }));
  9105. boxMesh.geometry.deleteAttribute('normal');
  9106. boxMesh.geometry.deleteAttribute('uv');
  9107. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  9108. this.matrixWorld.copyPosition(camera.matrixWorld);
  9109. }; // enable code injection for non-built-in material
  9110. Object.defineProperty(boxMesh.material, 'envMap', {
  9111. get: function get() {
  9112. return this.uniforms.envMap.value;
  9113. }
  9114. });
  9115. objects.update(boxMesh);
  9116. }
  9117. if (background.isWebGLCubeRenderTarget) {
  9118. // TODO Deprecate
  9119. background = background.texture;
  9120. }
  9121. boxMesh.material.uniforms.envMap.value = background;
  9122. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  9123. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9124. boxMesh.material.needsUpdate = true;
  9125. currentBackground = background;
  9126. currentBackgroundVersion = background.version;
  9127. currentTonemapping = renderer.toneMapping;
  9128. } // push to the pre-sorted opaque render list
  9129. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  9130. } else if (background && background.isTexture) {
  9131. if (planeMesh === undefined) {
  9132. planeMesh = new Mesh(new PlaneBufferGeometry(2, 2), new ShaderMaterial({
  9133. name: 'BackgroundMaterial',
  9134. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  9135. vertexShader: ShaderLib.background.vertexShader,
  9136. fragmentShader: ShaderLib.background.fragmentShader,
  9137. side: FrontSide,
  9138. depthTest: false,
  9139. depthWrite: false,
  9140. fog: false
  9141. }));
  9142. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9143. Object.defineProperty(planeMesh.material, 'map', {
  9144. get: function get() {
  9145. return this.uniforms.t2D.value;
  9146. }
  9147. });
  9148. objects.update(planeMesh);
  9149. }
  9150. planeMesh.material.uniforms.t2D.value = background;
  9151. if (background.matrixAutoUpdate === true) {
  9152. background.updateMatrix();
  9153. }
  9154. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9155. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9156. planeMesh.material.needsUpdate = true;
  9157. currentBackground = background;
  9158. currentBackgroundVersion = background.version;
  9159. currentTonemapping = renderer.toneMapping;
  9160. } // push to the pre-sorted opaque render list
  9161. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9162. }
  9163. }
  9164. function setClear(color, alpha) {
  9165. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9166. }
  9167. return {
  9168. getClearColor: function getClearColor() {
  9169. return clearColor;
  9170. },
  9171. setClearColor: function setClearColor(color, alpha) {
  9172. if (alpha === void 0) {
  9173. alpha = 1;
  9174. }
  9175. clearColor.set(color);
  9176. clearAlpha = alpha;
  9177. setClear(clearColor, clearAlpha);
  9178. },
  9179. getClearAlpha: function getClearAlpha() {
  9180. return clearAlpha;
  9181. },
  9182. setClearAlpha: function setClearAlpha(alpha) {
  9183. clearAlpha = alpha;
  9184. setClear(clearColor, clearAlpha);
  9185. },
  9186. render: render
  9187. };
  9188. }
  9189. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9190. var maxVertexAttributes = gl.getParameter(34921);
  9191. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9192. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9193. var bindingStates = {};
  9194. var defaultState = createBindingState(null);
  9195. var currentState = defaultState;
  9196. function setup(object, material, program, geometry, index) {
  9197. var updateBuffers = false;
  9198. if (vaoAvailable) {
  9199. var state = getBindingState(geometry, program, material);
  9200. if (currentState !== state) {
  9201. currentState = state;
  9202. bindVertexArrayObject(currentState.object);
  9203. }
  9204. updateBuffers = needsUpdate(geometry, index);
  9205. if (updateBuffers) saveCache(geometry, index);
  9206. } else {
  9207. var wireframe = material.wireframe === true;
  9208. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9209. currentState.geometry = geometry.id;
  9210. currentState.program = program.id;
  9211. currentState.wireframe = wireframe;
  9212. updateBuffers = true;
  9213. }
  9214. }
  9215. if (object.isInstancedMesh === true) {
  9216. updateBuffers = true;
  9217. }
  9218. if (index !== null) {
  9219. attributes.update(index, 34963);
  9220. }
  9221. if (updateBuffers) {
  9222. setupVertexAttributes(object, material, program, geometry);
  9223. if (index !== null) {
  9224. gl.bindBuffer(34963, attributes.get(index).buffer);
  9225. }
  9226. }
  9227. }
  9228. function createVertexArrayObject() {
  9229. if (capabilities.isWebGL2) return gl.createVertexArray();
  9230. return extension.createVertexArrayOES();
  9231. }
  9232. function bindVertexArrayObject(vao) {
  9233. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9234. return extension.bindVertexArrayOES(vao);
  9235. }
  9236. function deleteVertexArrayObject(vao) {
  9237. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9238. return extension.deleteVertexArrayOES(vao);
  9239. }
  9240. function getBindingState(geometry, program, material) {
  9241. var wireframe = material.wireframe === true;
  9242. var programMap = bindingStates[geometry.id];
  9243. if (programMap === undefined) {
  9244. programMap = {};
  9245. bindingStates[geometry.id] = programMap;
  9246. }
  9247. var stateMap = programMap[program.id];
  9248. if (stateMap === undefined) {
  9249. stateMap = {};
  9250. programMap[program.id] = stateMap;
  9251. }
  9252. var state = stateMap[wireframe];
  9253. if (state === undefined) {
  9254. state = createBindingState(createVertexArrayObject());
  9255. stateMap[wireframe] = state;
  9256. }
  9257. return state;
  9258. }
  9259. function createBindingState(vao) {
  9260. var newAttributes = [];
  9261. var enabledAttributes = [];
  9262. var attributeDivisors = [];
  9263. for (var i = 0; i < maxVertexAttributes; i++) {
  9264. newAttributes[i] = 0;
  9265. enabledAttributes[i] = 0;
  9266. attributeDivisors[i] = 0;
  9267. }
  9268. return {
  9269. // for backward compatibility on non-VAO support browser
  9270. geometry: null,
  9271. program: null,
  9272. wireframe: false,
  9273. newAttributes: newAttributes,
  9274. enabledAttributes: enabledAttributes,
  9275. attributeDivisors: attributeDivisors,
  9276. object: vao,
  9277. attributes: {},
  9278. index: null
  9279. };
  9280. }
  9281. function needsUpdate(geometry, index) {
  9282. var cachedAttributes = currentState.attributes;
  9283. var geometryAttributes = geometry.attributes;
  9284. var attributesNum = 0;
  9285. for (var key in geometryAttributes) {
  9286. var cachedAttribute = cachedAttributes[key];
  9287. var geometryAttribute = geometryAttributes[key];
  9288. if (cachedAttribute === undefined) return true;
  9289. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9290. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9291. attributesNum++;
  9292. }
  9293. if (currentState.attributesNum !== attributesNum) return true;
  9294. if (currentState.index !== index) return true;
  9295. return false;
  9296. }
  9297. function saveCache(geometry, index) {
  9298. var cache = {};
  9299. var attributes = geometry.attributes;
  9300. var attributesNum = 0;
  9301. for (var key in attributes) {
  9302. var attribute = attributes[key];
  9303. var data = {};
  9304. data.attribute = attribute;
  9305. if (attribute.data) {
  9306. data.data = attribute.data;
  9307. }
  9308. cache[key] = data;
  9309. attributesNum++;
  9310. }
  9311. currentState.attributes = cache;
  9312. currentState.attributesNum = attributesNum;
  9313. currentState.index = index;
  9314. }
  9315. function initAttributes() {
  9316. var newAttributes = currentState.newAttributes;
  9317. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9318. newAttributes[i] = 0;
  9319. }
  9320. }
  9321. function enableAttribute(attribute) {
  9322. enableAttributeAndDivisor(attribute, 0);
  9323. }
  9324. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9325. var newAttributes = currentState.newAttributes;
  9326. var enabledAttributes = currentState.enabledAttributes;
  9327. var attributeDivisors = currentState.attributeDivisors;
  9328. newAttributes[attribute] = 1;
  9329. if (enabledAttributes[attribute] === 0) {
  9330. gl.enableVertexAttribArray(attribute);
  9331. enabledAttributes[attribute] = 1;
  9332. }
  9333. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9334. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9335. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9336. attributeDivisors[attribute] = meshPerAttribute;
  9337. }
  9338. }
  9339. function disableUnusedAttributes() {
  9340. var newAttributes = currentState.newAttributes;
  9341. var enabledAttributes = currentState.enabledAttributes;
  9342. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9343. if (enabledAttributes[i] !== newAttributes[i]) {
  9344. gl.disableVertexAttribArray(i);
  9345. enabledAttributes[i] = 0;
  9346. }
  9347. }
  9348. }
  9349. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9350. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9351. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9352. } else {
  9353. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9354. }
  9355. }
  9356. function setupVertexAttributes(object, material, program, geometry) {
  9357. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9358. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9359. }
  9360. initAttributes();
  9361. var geometryAttributes = geometry.attributes;
  9362. var programAttributes = program.getAttributes();
  9363. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9364. for (var name in programAttributes) {
  9365. var programAttribute = programAttributes[name];
  9366. if (programAttribute >= 0) {
  9367. var geometryAttribute = geometryAttributes[name];
  9368. if (geometryAttribute !== undefined) {
  9369. var normalized = geometryAttribute.normalized;
  9370. var size = geometryAttribute.itemSize;
  9371. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9372. if (attribute === undefined) continue;
  9373. var buffer = attribute.buffer;
  9374. var type = attribute.type;
  9375. var bytesPerElement = attribute.bytesPerElement;
  9376. if (geometryAttribute.isInterleavedBufferAttribute) {
  9377. var data = geometryAttribute.data;
  9378. var stride = data.stride;
  9379. var offset = geometryAttribute.offset;
  9380. if (data && data.isInstancedInterleavedBuffer) {
  9381. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9382. if (geometry._maxInstanceCount === undefined) {
  9383. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9384. }
  9385. } else {
  9386. enableAttribute(programAttribute);
  9387. }
  9388. gl.bindBuffer(34962, buffer);
  9389. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9390. } else {
  9391. if (geometryAttribute.isInstancedBufferAttribute) {
  9392. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9393. if (geometry._maxInstanceCount === undefined) {
  9394. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9395. }
  9396. } else {
  9397. enableAttribute(programAttribute);
  9398. }
  9399. gl.bindBuffer(34962, buffer);
  9400. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9401. }
  9402. } else if (name === 'instanceMatrix') {
  9403. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9404. if (_attribute === undefined) continue;
  9405. var _buffer = _attribute.buffer;
  9406. var _type = _attribute.type;
  9407. enableAttributeAndDivisor(programAttribute + 0, 1);
  9408. enableAttributeAndDivisor(programAttribute + 1, 1);
  9409. enableAttributeAndDivisor(programAttribute + 2, 1);
  9410. enableAttributeAndDivisor(programAttribute + 3, 1);
  9411. gl.bindBuffer(34962, _buffer);
  9412. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9413. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9414. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9415. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9416. } else if (name === 'instanceColor') {
  9417. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9418. if (_attribute2 === undefined) continue;
  9419. var _buffer2 = _attribute2.buffer;
  9420. var _type2 = _attribute2.type;
  9421. enableAttributeAndDivisor(programAttribute, 1);
  9422. gl.bindBuffer(34962, _buffer2);
  9423. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9424. } else if (materialDefaultAttributeValues !== undefined) {
  9425. var value = materialDefaultAttributeValues[name];
  9426. if (value !== undefined) {
  9427. switch (value.length) {
  9428. case 2:
  9429. gl.vertexAttrib2fv(programAttribute, value);
  9430. break;
  9431. case 3:
  9432. gl.vertexAttrib3fv(programAttribute, value);
  9433. break;
  9434. case 4:
  9435. gl.vertexAttrib4fv(programAttribute, value);
  9436. break;
  9437. default:
  9438. gl.vertexAttrib1fv(programAttribute, value);
  9439. }
  9440. }
  9441. }
  9442. }
  9443. }
  9444. disableUnusedAttributes();
  9445. }
  9446. function dispose() {
  9447. reset();
  9448. for (var geometryId in bindingStates) {
  9449. var programMap = bindingStates[geometryId];
  9450. for (var programId in programMap) {
  9451. var stateMap = programMap[programId];
  9452. for (var wireframe in stateMap) {
  9453. deleteVertexArrayObject(stateMap[wireframe].object);
  9454. delete stateMap[wireframe];
  9455. }
  9456. delete programMap[programId];
  9457. }
  9458. delete bindingStates[geometryId];
  9459. }
  9460. }
  9461. function releaseStatesOfGeometry(geometry) {
  9462. if (bindingStates[geometry.id] === undefined) return;
  9463. var programMap = bindingStates[geometry.id];
  9464. for (var programId in programMap) {
  9465. var stateMap = programMap[programId];
  9466. for (var wireframe in stateMap) {
  9467. deleteVertexArrayObject(stateMap[wireframe].object);
  9468. delete stateMap[wireframe];
  9469. }
  9470. delete programMap[programId];
  9471. }
  9472. delete bindingStates[geometry.id];
  9473. }
  9474. function releaseStatesOfProgram(program) {
  9475. for (var geometryId in bindingStates) {
  9476. var programMap = bindingStates[geometryId];
  9477. if (programMap[program.id] === undefined) continue;
  9478. var stateMap = programMap[program.id];
  9479. for (var wireframe in stateMap) {
  9480. deleteVertexArrayObject(stateMap[wireframe].object);
  9481. delete stateMap[wireframe];
  9482. }
  9483. delete programMap[program.id];
  9484. }
  9485. }
  9486. function reset() {
  9487. resetDefaultState();
  9488. if (currentState === defaultState) return;
  9489. currentState = defaultState;
  9490. bindVertexArrayObject(currentState.object);
  9491. } // for backward-compatilibity
  9492. function resetDefaultState() {
  9493. defaultState.geometry = null;
  9494. defaultState.program = null;
  9495. defaultState.wireframe = false;
  9496. }
  9497. return {
  9498. setup: setup,
  9499. reset: reset,
  9500. resetDefaultState: resetDefaultState,
  9501. dispose: dispose,
  9502. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9503. releaseStatesOfProgram: releaseStatesOfProgram,
  9504. initAttributes: initAttributes,
  9505. enableAttribute: enableAttribute,
  9506. disableUnusedAttributes: disableUnusedAttributes
  9507. };
  9508. }
  9509. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  9510. var isWebGL2 = capabilities.isWebGL2;
  9511. var mode;
  9512. function setMode(value) {
  9513. mode = value;
  9514. }
  9515. function render(start, count) {
  9516. gl.drawArrays(mode, start, count);
  9517. info.update(count, mode, 1);
  9518. }
  9519. function renderInstances(start, count, primcount) {
  9520. if (primcount === 0) return;
  9521. var extension, methodName;
  9522. if (isWebGL2) {
  9523. extension = gl;
  9524. methodName = 'drawArraysInstanced';
  9525. } else {
  9526. extension = extensions.get('ANGLE_instanced_arrays');
  9527. methodName = 'drawArraysInstancedANGLE';
  9528. if (extension === null) {
  9529. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9530. return;
  9531. }
  9532. }
  9533. extension[methodName](mode, start, count, primcount);
  9534. info.update(count, mode, primcount);
  9535. } //
  9536. this.setMode = setMode;
  9537. this.render = render;
  9538. this.renderInstances = renderInstances;
  9539. }
  9540. function WebGLCapabilities(gl, extensions, parameters) {
  9541. var maxAnisotropy;
  9542. function getMaxAnisotropy() {
  9543. if (maxAnisotropy !== undefined) return maxAnisotropy;
  9544. var extension = extensions.get('EXT_texture_filter_anisotropic');
  9545. if (extension !== null) {
  9546. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  9547. } else {
  9548. maxAnisotropy = 0;
  9549. }
  9550. return maxAnisotropy;
  9551. }
  9552. function getMaxPrecision(precision) {
  9553. if (precision === 'highp') {
  9554. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  9555. return 'highp';
  9556. }
  9557. precision = 'mediump';
  9558. }
  9559. if (precision === 'mediump') {
  9560. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  9561. return 'mediump';
  9562. }
  9563. }
  9564. return 'lowp';
  9565. }
  9566. /* eslint-disable no-undef */
  9567. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  9568. /* eslint-enable no-undef */
  9569. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9570. var maxPrecision = getMaxPrecision(precision);
  9571. if (maxPrecision !== precision) {
  9572. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  9573. precision = maxPrecision;
  9574. }
  9575. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9576. var maxTextures = gl.getParameter(34930);
  9577. var maxVertexTextures = gl.getParameter(35660);
  9578. var maxTextureSize = gl.getParameter(3379);
  9579. var maxCubemapSize = gl.getParameter(34076);
  9580. var maxAttributes = gl.getParameter(34921);
  9581. var maxVertexUniforms = gl.getParameter(36347);
  9582. var maxVaryings = gl.getParameter(36348);
  9583. var maxFragmentUniforms = gl.getParameter(36349);
  9584. var vertexTextures = maxVertexTextures > 0;
  9585. var floatFragmentTextures = isWebGL2 || !!extensions.get('OES_texture_float');
  9586. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9587. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  9588. return {
  9589. isWebGL2: isWebGL2,
  9590. getMaxAnisotropy: getMaxAnisotropy,
  9591. getMaxPrecision: getMaxPrecision,
  9592. precision: precision,
  9593. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9594. maxTextures: maxTextures,
  9595. maxVertexTextures: maxVertexTextures,
  9596. maxTextureSize: maxTextureSize,
  9597. maxCubemapSize: maxCubemapSize,
  9598. maxAttributes: maxAttributes,
  9599. maxVertexUniforms: maxVertexUniforms,
  9600. maxVaryings: maxVaryings,
  9601. maxFragmentUniforms: maxFragmentUniforms,
  9602. vertexTextures: vertexTextures,
  9603. floatFragmentTextures: floatFragmentTextures,
  9604. floatVertexTextures: floatVertexTextures,
  9605. maxSamples: maxSamples
  9606. };
  9607. }
  9608. function WebGLClipping(properties) {
  9609. var scope = this;
  9610. var globalState = null,
  9611. numGlobalPlanes = 0,
  9612. localClippingEnabled = false,
  9613. renderingShadows = false;
  9614. var plane = new Plane(),
  9615. viewNormalMatrix = new Matrix3(),
  9616. uniform = {
  9617. value: null,
  9618. needsUpdate: false
  9619. };
  9620. this.uniform = uniform;
  9621. this.numPlanes = 0;
  9622. this.numIntersection = 0;
  9623. this.init = function (planes, enableLocalClipping, camera) {
  9624. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  9625. // run another frame in order to reset the state:
  9626. numGlobalPlanes !== 0 || localClippingEnabled;
  9627. localClippingEnabled = enableLocalClipping;
  9628. globalState = projectPlanes(planes, camera, 0);
  9629. numGlobalPlanes = planes.length;
  9630. return enabled;
  9631. };
  9632. this.beginShadows = function () {
  9633. renderingShadows = true;
  9634. projectPlanes(null);
  9635. };
  9636. this.endShadows = function () {
  9637. renderingShadows = false;
  9638. resetGlobalState();
  9639. };
  9640. this.setState = function (material, camera, useCache) {
  9641. var planes = material.clippingPlanes,
  9642. clipIntersection = material.clipIntersection,
  9643. clipShadows = material.clipShadows;
  9644. var materialProperties = properties.get(material);
  9645. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  9646. // there's no local clipping
  9647. if (renderingShadows) {
  9648. // there's no global clipping
  9649. projectPlanes(null);
  9650. } else {
  9651. resetGlobalState();
  9652. }
  9653. } else {
  9654. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9655. lGlobal = nGlobal * 4;
  9656. var dstArray = materialProperties.clippingState || null;
  9657. uniform.value = dstArray; // ensure unique state
  9658. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  9659. for (var i = 0; i !== lGlobal; ++i) {
  9660. dstArray[i] = globalState[i];
  9661. }
  9662. materialProperties.clippingState = dstArray;
  9663. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9664. this.numPlanes += nGlobal;
  9665. }
  9666. };
  9667. function resetGlobalState() {
  9668. if (uniform.value !== globalState) {
  9669. uniform.value = globalState;
  9670. uniform.needsUpdate = numGlobalPlanes > 0;
  9671. }
  9672. scope.numPlanes = numGlobalPlanes;
  9673. scope.numIntersection = 0;
  9674. }
  9675. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  9676. var nPlanes = planes !== null ? planes.length : 0;
  9677. var dstArray = null;
  9678. if (nPlanes !== 0) {
  9679. dstArray = uniform.value;
  9680. if (skipTransform !== true || dstArray === null) {
  9681. var flatSize = dstOffset + nPlanes * 4,
  9682. viewMatrix = camera.matrixWorldInverse;
  9683. viewNormalMatrix.getNormalMatrix(viewMatrix);
  9684. if (dstArray === null || dstArray.length < flatSize) {
  9685. dstArray = new Float32Array(flatSize);
  9686. }
  9687. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  9688. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  9689. plane.normal.toArray(dstArray, i4);
  9690. dstArray[i4 + 3] = plane.constant;
  9691. }
  9692. }
  9693. uniform.value = dstArray;
  9694. uniform.needsUpdate = true;
  9695. }
  9696. scope.numPlanes = nPlanes;
  9697. scope.numIntersection = 0;
  9698. return dstArray;
  9699. }
  9700. }
  9701. function WebGLCubeMaps(renderer) {
  9702. var cubemaps = new WeakMap();
  9703. function mapTextureMapping(texture, mapping) {
  9704. if (mapping === EquirectangularReflectionMapping) {
  9705. texture.mapping = CubeReflectionMapping;
  9706. } else if (mapping === EquirectangularRefractionMapping) {
  9707. texture.mapping = CubeRefractionMapping;
  9708. }
  9709. return texture;
  9710. }
  9711. function get(texture) {
  9712. if (texture && texture.isTexture) {
  9713. var mapping = texture.mapping;
  9714. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  9715. if (cubemaps.has(texture)) {
  9716. var cubemap = cubemaps.get(texture).texture;
  9717. return mapTextureMapping(cubemap, texture.mapping);
  9718. } else {
  9719. var image = texture.image;
  9720. if (image && image.height > 0) {
  9721. var currentRenderList = renderer.getRenderList();
  9722. var currentRenderTarget = renderer.getRenderTarget();
  9723. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  9724. renderTarget.fromEquirectangularTexture(renderer, texture);
  9725. cubemaps.set(texture, renderTarget);
  9726. renderer.setRenderTarget(currentRenderTarget);
  9727. renderer.setRenderList(currentRenderList);
  9728. texture.addEventListener('dispose', onTextureDispose);
  9729. return mapTextureMapping(renderTarget.texture, texture.mapping);
  9730. } else {
  9731. // image not yet ready. try the conversion next frame
  9732. return null;
  9733. }
  9734. }
  9735. }
  9736. }
  9737. return texture;
  9738. }
  9739. function onTextureDispose(event) {
  9740. var texture = event.target;
  9741. texture.removeEventListener('dispose', onTextureDispose);
  9742. var cubemap = cubemaps.get(texture);
  9743. if (cubemap !== undefined) {
  9744. cubemaps.delete(texture);
  9745. cubemap.dispose();
  9746. }
  9747. }
  9748. function dispose() {
  9749. cubemaps = new WeakMap();
  9750. }
  9751. return {
  9752. get: get,
  9753. dispose: dispose
  9754. };
  9755. }
  9756. function WebGLExtensions(gl) {
  9757. var extensions = {};
  9758. return {
  9759. has: function has(name) {
  9760. if (extensions[name] !== undefined) {
  9761. return extensions[name] !== null;
  9762. }
  9763. var extension;
  9764. switch (name) {
  9765. case 'WEBGL_depth_texture':
  9766. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  9767. break;
  9768. case 'EXT_texture_filter_anisotropic':
  9769. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  9770. break;
  9771. case 'WEBGL_compressed_texture_s3tc':
  9772. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  9773. break;
  9774. case 'WEBGL_compressed_texture_pvrtc':
  9775. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  9776. break;
  9777. default:
  9778. extension = gl.getExtension(name);
  9779. }
  9780. extensions[name] = extension;
  9781. return extension !== null;
  9782. },
  9783. get: function get(name) {
  9784. if (!this.has(name)) {
  9785. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  9786. }
  9787. return extensions[name];
  9788. }
  9789. };
  9790. }
  9791. function WebGLGeometries(gl, attributes, info, bindingStates) {
  9792. var geometries = new WeakMap();
  9793. var wireframeAttributes = new WeakMap();
  9794. function onGeometryDispose(event) {
  9795. var geometry = event.target;
  9796. var buffergeometry = geometries.get(geometry);
  9797. if (buffergeometry.index !== null) {
  9798. attributes.remove(buffergeometry.index);
  9799. }
  9800. for (var name in buffergeometry.attributes) {
  9801. attributes.remove(buffergeometry.attributes[name]);
  9802. }
  9803. geometry.removeEventListener('dispose', onGeometryDispose);
  9804. geometries.delete(geometry);
  9805. var attribute = wireframeAttributes.get(buffergeometry);
  9806. if (attribute) {
  9807. attributes.remove(attribute);
  9808. wireframeAttributes.delete(buffergeometry);
  9809. }
  9810. bindingStates.releaseStatesOfGeometry(buffergeometry);
  9811. if (geometry.isInstancedBufferGeometry === true) {
  9812. delete geometry._maxInstanceCount;
  9813. } //
  9814. info.memory.geometries--;
  9815. }
  9816. function get(object, geometry) {
  9817. var buffergeometry = geometries.get(geometry);
  9818. if (buffergeometry) return buffergeometry;
  9819. geometry.addEventListener('dispose', onGeometryDispose);
  9820. if (geometry.isBufferGeometry) {
  9821. buffergeometry = geometry;
  9822. } else if (geometry.isGeometry) {
  9823. if (geometry._bufferGeometry === undefined) {
  9824. geometry._bufferGeometry = new BufferGeometry().setFromObject(object);
  9825. }
  9826. buffergeometry = geometry._bufferGeometry;
  9827. }
  9828. geometries.set(geometry, buffergeometry);
  9829. info.memory.geometries++;
  9830. return buffergeometry;
  9831. }
  9832. function update(geometry) {
  9833. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  9834. for (var name in geometryAttributes) {
  9835. attributes.update(geometryAttributes[name], 34962);
  9836. } // morph targets
  9837. var morphAttributes = geometry.morphAttributes;
  9838. for (var _name in morphAttributes) {
  9839. var array = morphAttributes[_name];
  9840. for (var i = 0, l = array.length; i < l; i++) {
  9841. attributes.update(array[i], 34962);
  9842. }
  9843. }
  9844. }
  9845. function updateWireframeAttribute(geometry) {
  9846. var indices = [];
  9847. var geometryIndex = geometry.index;
  9848. var geometryPosition = geometry.attributes.position;
  9849. var version = 0;
  9850. if (geometryIndex !== null) {
  9851. var array = geometryIndex.array;
  9852. version = geometryIndex.version;
  9853. for (var i = 0, l = array.length; i < l; i += 3) {
  9854. var a = array[i + 0];
  9855. var b = array[i + 1];
  9856. var c = array[i + 2];
  9857. indices.push(a, b, b, c, c, a);
  9858. }
  9859. } else {
  9860. var _array = geometryPosition.array;
  9861. version = geometryPosition.version;
  9862. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  9863. var _a = _i + 0;
  9864. var _b = _i + 1;
  9865. var _c = _i + 2;
  9866. indices.push(_a, _b, _b, _c, _c, _a);
  9867. }
  9868. }
  9869. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  9870. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  9871. //
  9872. var previousAttribute = wireframeAttributes.get(geometry);
  9873. if (previousAttribute) attributes.remove(previousAttribute); //
  9874. wireframeAttributes.set(geometry, attribute);
  9875. }
  9876. function getWireframeAttribute(geometry) {
  9877. var currentAttribute = wireframeAttributes.get(geometry);
  9878. if (currentAttribute) {
  9879. var geometryIndex = geometry.index;
  9880. if (geometryIndex !== null) {
  9881. // if the attribute is obsolete, create a new one
  9882. if (currentAttribute.version < geometryIndex.version) {
  9883. updateWireframeAttribute(geometry);
  9884. }
  9885. }
  9886. } else {
  9887. updateWireframeAttribute(geometry);
  9888. }
  9889. return wireframeAttributes.get(geometry);
  9890. }
  9891. return {
  9892. get: get,
  9893. update: update,
  9894. getWireframeAttribute: getWireframeAttribute
  9895. };
  9896. }
  9897. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  9898. var isWebGL2 = capabilities.isWebGL2;
  9899. var mode;
  9900. function setMode(value) {
  9901. mode = value;
  9902. }
  9903. var type, bytesPerElement;
  9904. function setIndex(value) {
  9905. type = value.type;
  9906. bytesPerElement = value.bytesPerElement;
  9907. }
  9908. function render(start, count) {
  9909. gl.drawElements(mode, count, type, start * bytesPerElement);
  9910. info.update(count, mode, 1);
  9911. }
  9912. function renderInstances(start, count, primcount) {
  9913. if (primcount === 0) return;
  9914. var extension, methodName;
  9915. if (isWebGL2) {
  9916. extension = gl;
  9917. methodName = 'drawElementsInstanced';
  9918. } else {
  9919. extension = extensions.get('ANGLE_instanced_arrays');
  9920. methodName = 'drawElementsInstancedANGLE';
  9921. if (extension === null) {
  9922. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9923. return;
  9924. }
  9925. }
  9926. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  9927. info.update(count, mode, primcount);
  9928. } //
  9929. this.setMode = setMode;
  9930. this.setIndex = setIndex;
  9931. this.render = render;
  9932. this.renderInstances = renderInstances;
  9933. }
  9934. function WebGLInfo(gl) {
  9935. var memory = {
  9936. geometries: 0,
  9937. textures: 0
  9938. };
  9939. var render = {
  9940. frame: 0,
  9941. calls: 0,
  9942. triangles: 0,
  9943. points: 0,
  9944. lines: 0
  9945. };
  9946. function update(count, mode, instanceCount) {
  9947. render.calls++;
  9948. switch (mode) {
  9949. case 4:
  9950. render.triangles += instanceCount * (count / 3);
  9951. break;
  9952. case 1:
  9953. render.lines += instanceCount * (count / 2);
  9954. break;
  9955. case 3:
  9956. render.lines += instanceCount * (count - 1);
  9957. break;
  9958. case 2:
  9959. render.lines += instanceCount * count;
  9960. break;
  9961. case 0:
  9962. render.points += instanceCount * count;
  9963. break;
  9964. default:
  9965. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  9966. break;
  9967. }
  9968. }
  9969. function reset() {
  9970. render.frame++;
  9971. render.calls = 0;
  9972. render.triangles = 0;
  9973. render.points = 0;
  9974. render.lines = 0;
  9975. }
  9976. return {
  9977. memory: memory,
  9978. render: render,
  9979. programs: null,
  9980. autoReset: true,
  9981. reset: reset,
  9982. update: update
  9983. };
  9984. }
  9985. function numericalSort(a, b) {
  9986. return a[0] - b[0];
  9987. }
  9988. function absNumericalSort(a, b) {
  9989. return Math.abs(b[1]) - Math.abs(a[1]);
  9990. }
  9991. function WebGLMorphtargets(gl) {
  9992. var influencesList = {};
  9993. var morphInfluences = new Float32Array(8);
  9994. var workInfluences = [];
  9995. for (var i = 0; i < 8; i++) {
  9996. workInfluences[i] = [i, 0];
  9997. }
  9998. function update(object, geometry, material, program) {
  9999. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  10000. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  10001. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  10002. var influences = influencesList[geometry.id];
  10003. if (influences === undefined) {
  10004. // initialise list
  10005. influences = [];
  10006. for (var _i = 0; _i < length; _i++) {
  10007. influences[_i] = [_i, 0];
  10008. }
  10009. influencesList[geometry.id] = influences;
  10010. } // Collect influences
  10011. for (var _i2 = 0; _i2 < length; _i2++) {
  10012. var influence = influences[_i2];
  10013. influence[0] = _i2;
  10014. influence[1] = objectInfluences[_i2];
  10015. }
  10016. influences.sort(absNumericalSort);
  10017. for (var _i3 = 0; _i3 < 8; _i3++) {
  10018. if (_i3 < length && influences[_i3][1]) {
  10019. workInfluences[_i3][0] = influences[_i3][0];
  10020. workInfluences[_i3][1] = influences[_i3][1];
  10021. } else {
  10022. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  10023. workInfluences[_i3][1] = 0;
  10024. }
  10025. }
  10026. workInfluences.sort(numericalSort);
  10027. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  10028. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  10029. var morphInfluencesSum = 0;
  10030. for (var _i4 = 0; _i4 < 8; _i4++) {
  10031. var _influence = workInfluences[_i4];
  10032. var index = _influence[0];
  10033. var value = _influence[1];
  10034. if (index !== Number.MAX_SAFE_INTEGER && value) {
  10035. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  10036. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  10037. }
  10038. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  10039. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  10040. }
  10041. morphInfluences[_i4] = value;
  10042. morphInfluencesSum += value;
  10043. } else {
  10044. if (morphTargets && geometry.hasAttribute('morphTarget' + _i4) === true) {
  10045. geometry.deleteAttribute('morphTarget' + _i4);
  10046. }
  10047. if (morphNormals && geometry.hasAttribute('morphNormal' + _i4) === true) {
  10048. geometry.deleteAttribute('morphNormal' + _i4);
  10049. }
  10050. morphInfluences[_i4] = 0;
  10051. }
  10052. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  10053. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  10054. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  10055. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10056. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  10057. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  10058. }
  10059. return {
  10060. update: update
  10061. };
  10062. }
  10063. function WebGLObjects(gl, geometries, attributes, info) {
  10064. var updateMap = new WeakMap();
  10065. function update(object) {
  10066. var frame = info.render.frame;
  10067. var geometry = object.geometry;
  10068. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  10069. if (updateMap.get(buffergeometry) !== frame) {
  10070. if (geometry.isGeometry) {
  10071. buffergeometry.updateFromObject(object);
  10072. }
  10073. geometries.update(buffergeometry);
  10074. updateMap.set(buffergeometry, frame);
  10075. }
  10076. if (object.isInstancedMesh) {
  10077. if (object.hasEventListener('dispose', onInstancedMeshDispose) === false) {
  10078. object.addEventListener('dispose', onInstancedMeshDispose);
  10079. }
  10080. attributes.update(object.instanceMatrix, 34962);
  10081. if (object.instanceColor !== null) {
  10082. attributes.update(object.instanceColor, 34962);
  10083. }
  10084. }
  10085. return buffergeometry;
  10086. }
  10087. function dispose() {
  10088. updateMap = new WeakMap();
  10089. }
  10090. function onInstancedMeshDispose(event) {
  10091. var instancedMesh = event.target;
  10092. instancedMesh.removeEventListener('dispose', onInstancedMeshDispose);
  10093. attributes.remove(instancedMesh.instanceMatrix);
  10094. if (instancedMesh.instanceColor !== null) attributes.remove(instancedMesh.instanceColor);
  10095. }
  10096. return {
  10097. update: update,
  10098. dispose: dispose
  10099. };
  10100. }
  10101. function DataTexture2DArray(data, width, height, depth) {
  10102. if (data === void 0) {
  10103. data = null;
  10104. }
  10105. if (width === void 0) {
  10106. width = 1;
  10107. }
  10108. if (height === void 0) {
  10109. height = 1;
  10110. }
  10111. if (depth === void 0) {
  10112. depth = 1;
  10113. }
  10114. Texture.call(this, null);
  10115. this.image = {
  10116. data: data,
  10117. width: width,
  10118. height: height,
  10119. depth: depth
  10120. };
  10121. this.magFilter = NearestFilter;
  10122. this.minFilter = NearestFilter;
  10123. this.wrapR = ClampToEdgeWrapping;
  10124. this.generateMipmaps = false;
  10125. this.flipY = false;
  10126. this.needsUpdate = true;
  10127. }
  10128. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  10129. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10130. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10131. function DataTexture3D(data, width, height, depth) {
  10132. if (data === void 0) {
  10133. data = null;
  10134. }
  10135. if (width === void 0) {
  10136. width = 1;
  10137. }
  10138. if (height === void 0) {
  10139. height = 1;
  10140. }
  10141. if (depth === void 0) {
  10142. depth = 1;
  10143. }
  10144. // We're going to add .setXXX() methods for setting properties later.
  10145. // Users can still set in DataTexture3D directly.
  10146. //
  10147. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10148. // texture.anisotropy = 16;
  10149. //
  10150. // See #14839
  10151. Texture.call(this, null);
  10152. this.image = {
  10153. data: data,
  10154. width: width,
  10155. height: height,
  10156. depth: depth
  10157. };
  10158. this.magFilter = NearestFilter;
  10159. this.minFilter = NearestFilter;
  10160. this.wrapR = ClampToEdgeWrapping;
  10161. this.generateMipmaps = false;
  10162. this.flipY = false;
  10163. this.needsUpdate = true;
  10164. }
  10165. DataTexture3D.prototype = Object.create(Texture.prototype);
  10166. DataTexture3D.prototype.constructor = DataTexture3D;
  10167. DataTexture3D.prototype.isDataTexture3D = true;
  10168. /**
  10169. * Uniforms of a program.
  10170. * Those form a tree structure with a special top-level container for the root,
  10171. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10172. *
  10173. *
  10174. * Properties of inner nodes including the top-level container:
  10175. *
  10176. * .seq - array of nested uniforms
  10177. * .map - nested uniforms by name
  10178. *
  10179. *
  10180. * Methods of all nodes except the top-level container:
  10181. *
  10182. * .setValue( gl, value, [textures] )
  10183. *
  10184. * uploads a uniform value(s)
  10185. * the 'textures' parameter is needed for sampler uniforms
  10186. *
  10187. *
  10188. * Static methods of the top-level container (textures factorizations):
  10189. *
  10190. * .upload( gl, seq, values, textures )
  10191. *
  10192. * sets uniforms in 'seq' to 'values[id].value'
  10193. *
  10194. * .seqWithValue( seq, values ) : filteredSeq
  10195. *
  10196. * filters 'seq' entries with corresponding entry in values
  10197. *
  10198. *
  10199. * Methods of the top-level container (textures factorizations):
  10200. *
  10201. * .setValue( gl, name, value, textures )
  10202. *
  10203. * sets uniform with name 'name' to 'value'
  10204. *
  10205. * .setOptional( gl, obj, prop )
  10206. *
  10207. * like .set for an optional property of the object
  10208. *
  10209. */
  10210. var emptyTexture = new Texture();
  10211. var emptyTexture2dArray = new DataTexture2DArray();
  10212. var emptyTexture3d = new DataTexture3D();
  10213. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10214. // Array Caches (provide typed arrays for temporary by size)
  10215. var arrayCacheF32 = [];
  10216. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10217. var mat4array = new Float32Array(16);
  10218. var mat3array = new Float32Array(9);
  10219. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10220. function flatten(array, nBlocks, blockSize) {
  10221. var firstElem = array[0];
  10222. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10223. // see http://jacksondunstan.com/articles/983
  10224. var n = nBlocks * blockSize;
  10225. var r = arrayCacheF32[n];
  10226. if (r === undefined) {
  10227. r = new Float32Array(n);
  10228. arrayCacheF32[n] = r;
  10229. }
  10230. if (nBlocks !== 0) {
  10231. firstElem.toArray(r, 0);
  10232. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10233. offset += blockSize;
  10234. array[i].toArray(r, offset);
  10235. }
  10236. }
  10237. return r;
  10238. }
  10239. function arraysEqual(a, b) {
  10240. if (a.length !== b.length) return false;
  10241. for (var i = 0, l = a.length; i < l; i++) {
  10242. if (a[i] !== b[i]) return false;
  10243. }
  10244. return true;
  10245. }
  10246. function copyArray(a, b) {
  10247. for (var i = 0, l = b.length; i < l; i++) {
  10248. a[i] = b[i];
  10249. }
  10250. } // Texture unit allocation
  10251. function allocTexUnits(textures, n) {
  10252. var r = arrayCacheI32[n];
  10253. if (r === undefined) {
  10254. r = new Int32Array(n);
  10255. arrayCacheI32[n] = r;
  10256. }
  10257. for (var i = 0; i !== n; ++i) {
  10258. r[i] = textures.allocateTextureUnit();
  10259. }
  10260. return r;
  10261. } // --- Setters ---
  10262. // Note: Defining these methods externally, because they come in a bunch
  10263. // and this way their names minify.
  10264. // Single scalar
  10265. function setValueV1f(gl, v) {
  10266. var cache = this.cache;
  10267. if (cache[0] === v) return;
  10268. gl.uniform1f(this.addr, v);
  10269. cache[0] = v;
  10270. } // Single float vector (from flat array or THREE.VectorN)
  10271. function setValueV2f(gl, v) {
  10272. var cache = this.cache;
  10273. if (v.x !== undefined) {
  10274. if (cache[0] !== v.x || cache[1] !== v.y) {
  10275. gl.uniform2f(this.addr, v.x, v.y);
  10276. cache[0] = v.x;
  10277. cache[1] = v.y;
  10278. }
  10279. } else {
  10280. if (arraysEqual(cache, v)) return;
  10281. gl.uniform2fv(this.addr, v);
  10282. copyArray(cache, v);
  10283. }
  10284. }
  10285. function setValueV3f(gl, v) {
  10286. var cache = this.cache;
  10287. if (v.x !== undefined) {
  10288. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10289. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10290. cache[0] = v.x;
  10291. cache[1] = v.y;
  10292. cache[2] = v.z;
  10293. }
  10294. } else if (v.r !== undefined) {
  10295. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10296. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10297. cache[0] = v.r;
  10298. cache[1] = v.g;
  10299. cache[2] = v.b;
  10300. }
  10301. } else {
  10302. if (arraysEqual(cache, v)) return;
  10303. gl.uniform3fv(this.addr, v);
  10304. copyArray(cache, v);
  10305. }
  10306. }
  10307. function setValueV4f(gl, v) {
  10308. var cache = this.cache;
  10309. if (v.x !== undefined) {
  10310. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10311. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10312. cache[0] = v.x;
  10313. cache[1] = v.y;
  10314. cache[2] = v.z;
  10315. cache[3] = v.w;
  10316. }
  10317. } else {
  10318. if (arraysEqual(cache, v)) return;
  10319. gl.uniform4fv(this.addr, v);
  10320. copyArray(cache, v);
  10321. }
  10322. } // Single matrix (from flat array or MatrixN)
  10323. function setValueM2(gl, v) {
  10324. var cache = this.cache;
  10325. var elements = v.elements;
  10326. if (elements === undefined) {
  10327. if (arraysEqual(cache, v)) return;
  10328. gl.uniformMatrix2fv(this.addr, false, v);
  10329. copyArray(cache, v);
  10330. } else {
  10331. if (arraysEqual(cache, elements)) return;
  10332. mat2array.set(elements);
  10333. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10334. copyArray(cache, elements);
  10335. }
  10336. }
  10337. function setValueM3(gl, v) {
  10338. var cache = this.cache;
  10339. var elements = v.elements;
  10340. if (elements === undefined) {
  10341. if (arraysEqual(cache, v)) return;
  10342. gl.uniformMatrix3fv(this.addr, false, v);
  10343. copyArray(cache, v);
  10344. } else {
  10345. if (arraysEqual(cache, elements)) return;
  10346. mat3array.set(elements);
  10347. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10348. copyArray(cache, elements);
  10349. }
  10350. }
  10351. function setValueM4(gl, v) {
  10352. var cache = this.cache;
  10353. var elements = v.elements;
  10354. if (elements === undefined) {
  10355. if (arraysEqual(cache, v)) return;
  10356. gl.uniformMatrix4fv(this.addr, false, v);
  10357. copyArray(cache, v);
  10358. } else {
  10359. if (arraysEqual(cache, elements)) return;
  10360. mat4array.set(elements);
  10361. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10362. copyArray(cache, elements);
  10363. }
  10364. } // Single texture (2D / Cube)
  10365. function setValueT1(gl, v, textures) {
  10366. var cache = this.cache;
  10367. var unit = textures.allocateTextureUnit();
  10368. if (cache[0] !== unit) {
  10369. gl.uniform1i(this.addr, unit);
  10370. cache[0] = unit;
  10371. }
  10372. textures.safeSetTexture2D(v || emptyTexture, unit);
  10373. }
  10374. function setValueT2DArray1(gl, v, textures) {
  10375. var cache = this.cache;
  10376. var unit = textures.allocateTextureUnit();
  10377. if (cache[0] !== unit) {
  10378. gl.uniform1i(this.addr, unit);
  10379. cache[0] = unit;
  10380. }
  10381. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10382. }
  10383. function setValueT3D1(gl, v, textures) {
  10384. var cache = this.cache;
  10385. var unit = textures.allocateTextureUnit();
  10386. if (cache[0] !== unit) {
  10387. gl.uniform1i(this.addr, unit);
  10388. cache[0] = unit;
  10389. }
  10390. textures.setTexture3D(v || emptyTexture3d, unit);
  10391. }
  10392. function setValueT6(gl, v, textures) {
  10393. var cache = this.cache;
  10394. var unit = textures.allocateTextureUnit();
  10395. if (cache[0] !== unit) {
  10396. gl.uniform1i(this.addr, unit);
  10397. cache[0] = unit;
  10398. }
  10399. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10400. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10401. function setValueV1i(gl, v) {
  10402. var cache = this.cache;
  10403. if (cache[0] === v) return;
  10404. gl.uniform1i(this.addr, v);
  10405. cache[0] = v;
  10406. }
  10407. function setValueV2i(gl, v) {
  10408. var cache = this.cache;
  10409. if (arraysEqual(cache, v)) return;
  10410. gl.uniform2iv(this.addr, v);
  10411. copyArray(cache, v);
  10412. }
  10413. function setValueV3i(gl, v) {
  10414. var cache = this.cache;
  10415. if (arraysEqual(cache, v)) return;
  10416. gl.uniform3iv(this.addr, v);
  10417. copyArray(cache, v);
  10418. }
  10419. function setValueV4i(gl, v) {
  10420. var cache = this.cache;
  10421. if (arraysEqual(cache, v)) return;
  10422. gl.uniform4iv(this.addr, v);
  10423. copyArray(cache, v);
  10424. } // uint
  10425. function setValueV1ui(gl, v) {
  10426. var cache = this.cache;
  10427. if (cache[0] === v) return;
  10428. gl.uniform1ui(this.addr, v);
  10429. cache[0] = v;
  10430. } // Helper to pick the right setter for the singular case
  10431. function getSingularSetter(type) {
  10432. switch (type) {
  10433. case 0x1406:
  10434. return setValueV1f;
  10435. // FLOAT
  10436. case 0x8b50:
  10437. return setValueV2f;
  10438. // _VEC2
  10439. case 0x8b51:
  10440. return setValueV3f;
  10441. // _VEC3
  10442. case 0x8b52:
  10443. return setValueV4f;
  10444. // _VEC4
  10445. case 0x8b5a:
  10446. return setValueM2;
  10447. // _MAT2
  10448. case 0x8b5b:
  10449. return setValueM3;
  10450. // _MAT3
  10451. case 0x8b5c:
  10452. return setValueM4;
  10453. // _MAT4
  10454. case 0x1404:
  10455. case 0x8b56:
  10456. return setValueV1i;
  10457. // INT, BOOL
  10458. case 0x8b53:
  10459. case 0x8b57:
  10460. return setValueV2i;
  10461. // _VEC2
  10462. case 0x8b54:
  10463. case 0x8b58:
  10464. return setValueV3i;
  10465. // _VEC3
  10466. case 0x8b55:
  10467. case 0x8b59:
  10468. return setValueV4i;
  10469. // _VEC4
  10470. case 0x1405:
  10471. return setValueV1ui;
  10472. // UINT
  10473. case 0x8b5e: // SAMPLER_2D
  10474. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10475. case 0x8dca: // INT_SAMPLER_2D
  10476. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10477. case 0x8b62:
  10478. // SAMPLER_2D_SHADOW
  10479. return setValueT1;
  10480. case 0x8b5f: // SAMPLER_3D
  10481. case 0x8dcb: // INT_SAMPLER_3D
  10482. case 0x8dd3:
  10483. // UNSIGNED_INT_SAMPLER_3D
  10484. return setValueT3D1;
  10485. case 0x8b60: // SAMPLER_CUBE
  10486. case 0x8dcc: // INT_SAMPLER_CUBE
  10487. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10488. case 0x8dc5:
  10489. // SAMPLER_CUBE_SHADOW
  10490. return setValueT6;
  10491. case 0x8dc1: // SAMPLER_2D_ARRAY
  10492. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10493. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10494. case 0x8dc4:
  10495. // SAMPLER_2D_ARRAY_SHADOW
  10496. return setValueT2DArray1;
  10497. }
  10498. } // Array of scalars
  10499. function setValueV1fArray(gl, v) {
  10500. gl.uniform1fv(this.addr, v);
  10501. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10502. function setValueV1iArray(gl, v) {
  10503. gl.uniform1iv(this.addr, v);
  10504. }
  10505. function setValueV2iArray(gl, v) {
  10506. gl.uniform2iv(this.addr, v);
  10507. }
  10508. function setValueV3iArray(gl, v) {
  10509. gl.uniform3iv(this.addr, v);
  10510. }
  10511. function setValueV4iArray(gl, v) {
  10512. gl.uniform4iv(this.addr, v);
  10513. } // Array of vectors (flat or from THREE classes)
  10514. function setValueV2fArray(gl, v) {
  10515. var data = flatten(v, this.size, 2);
  10516. gl.uniform2fv(this.addr, data);
  10517. }
  10518. function setValueV3fArray(gl, v) {
  10519. var data = flatten(v, this.size, 3);
  10520. gl.uniform3fv(this.addr, data);
  10521. }
  10522. function setValueV4fArray(gl, v) {
  10523. var data = flatten(v, this.size, 4);
  10524. gl.uniform4fv(this.addr, data);
  10525. } // Array of matrices (flat or from THREE clases)
  10526. function setValueM2Array(gl, v) {
  10527. var data = flatten(v, this.size, 4);
  10528. gl.uniformMatrix2fv(this.addr, false, data);
  10529. }
  10530. function setValueM3Array(gl, v) {
  10531. var data = flatten(v, this.size, 9);
  10532. gl.uniformMatrix3fv(this.addr, false, data);
  10533. }
  10534. function setValueM4Array(gl, v) {
  10535. var data = flatten(v, this.size, 16);
  10536. gl.uniformMatrix4fv(this.addr, false, data);
  10537. } // Array of textures (2D / Cube)
  10538. function setValueT1Array(gl, v, textures) {
  10539. var n = v.length;
  10540. var units = allocTexUnits(textures, n);
  10541. gl.uniform1iv(this.addr, units);
  10542. for (var i = 0; i !== n; ++i) {
  10543. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  10544. }
  10545. }
  10546. function setValueT6Array(gl, v, textures) {
  10547. var n = v.length;
  10548. var units = allocTexUnits(textures, n);
  10549. gl.uniform1iv(this.addr, units);
  10550. for (var i = 0; i !== n; ++i) {
  10551. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  10552. }
  10553. } // Helper to pick the right setter for a pure (bottom-level) array
  10554. function getPureArraySetter(type) {
  10555. switch (type) {
  10556. case 0x1406:
  10557. return setValueV1fArray;
  10558. // FLOAT
  10559. case 0x8b50:
  10560. return setValueV2fArray;
  10561. // _VEC2
  10562. case 0x8b51:
  10563. return setValueV3fArray;
  10564. // _VEC3
  10565. case 0x8b52:
  10566. return setValueV4fArray;
  10567. // _VEC4
  10568. case 0x8b5a:
  10569. return setValueM2Array;
  10570. // _MAT2
  10571. case 0x8b5b:
  10572. return setValueM3Array;
  10573. // _MAT3
  10574. case 0x8b5c:
  10575. return setValueM4Array;
  10576. // _MAT4
  10577. case 0x1404:
  10578. case 0x8b56:
  10579. return setValueV1iArray;
  10580. // INT, BOOL
  10581. case 0x8b53:
  10582. case 0x8b57:
  10583. return setValueV2iArray;
  10584. // _VEC2
  10585. case 0x8b54:
  10586. case 0x8b58:
  10587. return setValueV3iArray;
  10588. // _VEC3
  10589. case 0x8b55:
  10590. case 0x8b59:
  10591. return setValueV4iArray;
  10592. // _VEC4
  10593. case 0x8b5e: // SAMPLER_2D
  10594. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10595. case 0x8dca: // INT_SAMPLER_2D
  10596. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10597. case 0x8b62:
  10598. // SAMPLER_2D_SHADOW
  10599. return setValueT1Array;
  10600. case 0x8b60: // SAMPLER_CUBE
  10601. case 0x8dcc: // INT_SAMPLER_CUBE
  10602. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10603. case 0x8dc5:
  10604. // SAMPLER_CUBE_SHADOW
  10605. return setValueT6Array;
  10606. }
  10607. } // --- Uniform Classes ---
  10608. function SingleUniform(id, activeInfo, addr) {
  10609. this.id = id;
  10610. this.addr = addr;
  10611. this.cache = [];
  10612. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10613. }
  10614. function PureArrayUniform(id, activeInfo, addr) {
  10615. this.id = id;
  10616. this.addr = addr;
  10617. this.cache = [];
  10618. this.size = activeInfo.size;
  10619. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10620. }
  10621. PureArrayUniform.prototype.updateCache = function (data) {
  10622. var cache = this.cache;
  10623. if (data instanceof Float32Array && cache.length !== data.length) {
  10624. this.cache = new Float32Array(data.length);
  10625. }
  10626. copyArray(cache, data);
  10627. };
  10628. function StructuredUniform(id) {
  10629. this.id = id;
  10630. this.seq = [];
  10631. this.map = {};
  10632. }
  10633. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  10634. var seq = this.seq;
  10635. for (var i = 0, n = seq.length; i !== n; ++i) {
  10636. var u = seq[i];
  10637. u.setValue(gl, value[u.id], textures);
  10638. }
  10639. }; // --- Top-level ---
  10640. // Parser - builds up the property tree from the path strings
  10641. var RePathPart = /(\w+)(\])?(\[|\.)?/g; // extracts
  10642. // - the identifier (member name or array index)
  10643. // - followed by an optional right bracket (found when array index)
  10644. // - followed by an optional left bracket or dot (type of subscript)
  10645. //
  10646. // Note: These portions can be read in a non-overlapping fashion and
  10647. // allow straightforward parsing of the hierarchy that WebGL encodes
  10648. // in the uniform names.
  10649. function addUniform(container, uniformObject) {
  10650. container.seq.push(uniformObject);
  10651. container.map[uniformObject.id] = uniformObject;
  10652. }
  10653. function parseUniform(activeInfo, addr, container) {
  10654. var path = activeInfo.name,
  10655. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  10656. RePathPart.lastIndex = 0;
  10657. while (true) {
  10658. var match = RePathPart.exec(path),
  10659. matchEnd = RePathPart.lastIndex;
  10660. var id = match[1];
  10661. var idIsIndex = match[2] === ']',
  10662. subscript = match[3];
  10663. if (idIsIndex) id = id | 0; // convert to integer
  10664. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  10665. // bare name or "pure" bottom-level array "[0]" suffix
  10666. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  10667. break;
  10668. } else {
  10669. // step into inner node / create it in case it doesn't exist
  10670. var map = container.map;
  10671. var next = map[id];
  10672. if (next === undefined) {
  10673. next = new StructuredUniform(id);
  10674. addUniform(container, next);
  10675. }
  10676. container = next;
  10677. }
  10678. }
  10679. } // Root Container
  10680. function WebGLUniforms(gl, program) {
  10681. this.seq = [];
  10682. this.map = {};
  10683. var n = gl.getProgramParameter(program, 35718);
  10684. for (var i = 0; i < n; ++i) {
  10685. var info = gl.getActiveUniform(program, i),
  10686. addr = gl.getUniformLocation(program, info.name);
  10687. parseUniform(info, addr, this);
  10688. }
  10689. }
  10690. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  10691. var u = this.map[name];
  10692. if (u !== undefined) u.setValue(gl, value, textures);
  10693. };
  10694. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  10695. var v = object[name];
  10696. if (v !== undefined) this.setValue(gl, name, v);
  10697. }; // Static interface
  10698. WebGLUniforms.upload = function (gl, seq, values, textures) {
  10699. for (var i = 0, n = seq.length; i !== n; ++i) {
  10700. var u = seq[i],
  10701. v = values[u.id];
  10702. if (v.needsUpdate !== false) {
  10703. // note: always updating when .needsUpdate is undefined
  10704. u.setValue(gl, v.value, textures);
  10705. }
  10706. }
  10707. };
  10708. WebGLUniforms.seqWithValue = function (seq, values) {
  10709. var r = [];
  10710. for (var i = 0, n = seq.length; i !== n; ++i) {
  10711. var u = seq[i];
  10712. if (u.id in values) r.push(u);
  10713. }
  10714. return r;
  10715. };
  10716. function WebGLShader(gl, type, string) {
  10717. var shader = gl.createShader(type);
  10718. gl.shaderSource(shader, string);
  10719. gl.compileShader(shader);
  10720. return shader;
  10721. }
  10722. var programIdCount = 0;
  10723. function addLineNumbers(string) {
  10724. var lines = string.split('\n');
  10725. for (var i = 0; i < lines.length; i++) {
  10726. lines[i] = i + 1 + ': ' + lines[i];
  10727. }
  10728. return lines.join('\n');
  10729. }
  10730. function getEncodingComponents(encoding) {
  10731. switch (encoding) {
  10732. case LinearEncoding:
  10733. return ['Linear', '( value )'];
  10734. case sRGBEncoding:
  10735. return ['sRGB', '( value )'];
  10736. case RGBEEncoding:
  10737. return ['RGBE', '( value )'];
  10738. case RGBM7Encoding:
  10739. return ['RGBM', '( value, 7.0 )'];
  10740. case RGBM16Encoding:
  10741. return ['RGBM', '( value, 16.0 )'];
  10742. case RGBDEncoding:
  10743. return ['RGBD', '( value, 256.0 )'];
  10744. case GammaEncoding:
  10745. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  10746. case LogLuvEncoding:
  10747. return ['LogLuv', '( value )'];
  10748. default:
  10749. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  10750. return ['Linear', '( value )'];
  10751. }
  10752. }
  10753. function getShaderErrors(gl, shader, type) {
  10754. var status = gl.getShaderParameter(shader, 35713);
  10755. var log = gl.getShaderInfoLog(shader).trim();
  10756. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  10757. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10758. var source = gl.getShaderSource(shader);
  10759. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  10760. }
  10761. function getTexelDecodingFunction(functionName, encoding) {
  10762. var components = getEncodingComponents(encoding);
  10763. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  10764. }
  10765. function getTexelEncodingFunction(functionName, encoding) {
  10766. var components = getEncodingComponents(encoding);
  10767. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  10768. }
  10769. function getToneMappingFunction(functionName, toneMapping) {
  10770. var toneMappingName;
  10771. switch (toneMapping) {
  10772. case LinearToneMapping:
  10773. toneMappingName = 'Linear';
  10774. break;
  10775. case ReinhardToneMapping:
  10776. toneMappingName = 'Reinhard';
  10777. break;
  10778. case CineonToneMapping:
  10779. toneMappingName = 'OptimizedCineon';
  10780. break;
  10781. case ACESFilmicToneMapping:
  10782. toneMappingName = 'ACESFilmic';
  10783. break;
  10784. case CustomToneMapping:
  10785. toneMappingName = 'Custom';
  10786. break;
  10787. default:
  10788. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  10789. toneMappingName = 'Linear';
  10790. }
  10791. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10792. }
  10793. function generateExtensions(parameters) {
  10794. 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' : ''];
  10795. return chunks.filter(filterEmptyLine).join('\n');
  10796. }
  10797. function generateDefines(defines) {
  10798. var chunks = [];
  10799. for (var name in defines) {
  10800. var value = defines[name];
  10801. if (value === false) continue;
  10802. chunks.push('#define ' + name + ' ' + value);
  10803. }
  10804. return chunks.join('\n');
  10805. }
  10806. function fetchAttributeLocations(gl, program) {
  10807. var attributes = {};
  10808. var n = gl.getProgramParameter(program, 35721);
  10809. for (var i = 0; i < n; i++) {
  10810. var info = gl.getActiveAttrib(program, i);
  10811. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10812. attributes[name] = gl.getAttribLocation(program, name);
  10813. }
  10814. return attributes;
  10815. }
  10816. function filterEmptyLine(string) {
  10817. return string !== '';
  10818. }
  10819. function replaceLightNums(string, parameters) {
  10820. 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);
  10821. }
  10822. function replaceClippingPlaneNums(string, parameters) {
  10823. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  10824. } // Resolve Includes
  10825. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10826. function resolveIncludes(string) {
  10827. return string.replace(includePattern, includeReplacer);
  10828. }
  10829. function includeReplacer(match, include) {
  10830. var string = ShaderChunk[include];
  10831. if (string === undefined) {
  10832. throw new Error('Can not resolve #include <' + include + '>');
  10833. }
  10834. return resolveIncludes(string);
  10835. } // Unroll Loops
  10836. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10837. 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;
  10838. function unrollLoops(string) {
  10839. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  10840. }
  10841. function deprecatedLoopReplacer(match, start, end, snippet) {
  10842. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  10843. return loopReplacer(match, start, end, snippet);
  10844. }
  10845. function loopReplacer(match, start, end, snippet) {
  10846. var string = '';
  10847. for (var i = parseInt(start); i < parseInt(end); i++) {
  10848. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  10849. }
  10850. return string;
  10851. } //
  10852. function generatePrecision(parameters) {
  10853. var precisionstring = 'precision ' + parameters.precision + ' float;\nprecision ' + parameters.precision + ' int;';
  10854. if (parameters.precision === 'highp') {
  10855. precisionstring += '\n#define HIGH_PRECISION';
  10856. } else if (parameters.precision === 'mediump') {
  10857. precisionstring += '\n#define MEDIUM_PRECISION';
  10858. } else if (parameters.precision === 'lowp') {
  10859. precisionstring += '\n#define LOW_PRECISION';
  10860. }
  10861. return precisionstring;
  10862. }
  10863. function generateShadowMapTypeDefine(parameters) {
  10864. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10865. if (parameters.shadowMapType === PCFShadowMap) {
  10866. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10867. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  10868. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10869. } else if (parameters.shadowMapType === VSMShadowMap) {
  10870. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  10871. }
  10872. return shadowMapTypeDefine;
  10873. }
  10874. function generateEnvMapTypeDefine(parameters) {
  10875. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10876. if (parameters.envMap) {
  10877. switch (parameters.envMapMode) {
  10878. case CubeReflectionMapping:
  10879. case CubeRefractionMapping:
  10880. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10881. break;
  10882. case CubeUVReflectionMapping:
  10883. case CubeUVRefractionMapping:
  10884. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10885. break;
  10886. }
  10887. }
  10888. return envMapTypeDefine;
  10889. }
  10890. function generateEnvMapModeDefine(parameters) {
  10891. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10892. if (parameters.envMap) {
  10893. switch (parameters.envMapMode) {
  10894. case CubeRefractionMapping:
  10895. case CubeUVRefractionMapping:
  10896. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10897. break;
  10898. }
  10899. }
  10900. return envMapModeDefine;
  10901. }
  10902. function generateEnvMapBlendingDefine(parameters) {
  10903. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  10904. if (parameters.envMap) {
  10905. switch (parameters.combine) {
  10906. case MultiplyOperation:
  10907. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10908. break;
  10909. case MixOperation:
  10910. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10911. break;
  10912. case AddOperation:
  10913. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10914. break;
  10915. }
  10916. }
  10917. return envMapBlendingDefine;
  10918. }
  10919. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  10920. var gl = renderer.getContext();
  10921. var defines = parameters.defines;
  10922. var vertexShader = parameters.vertexShader;
  10923. var fragmentShader = parameters.fragmentShader;
  10924. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  10925. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  10926. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  10927. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  10928. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  10929. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  10930. var customDefines = generateDefines(defines);
  10931. var program = gl.createProgram();
  10932. var prefixVertex, prefixFragment;
  10933. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
  10934. if (parameters.isRawShaderMaterial) {
  10935. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  10936. if (prefixVertex.length > 0) {
  10937. prefixVertex += '\n';
  10938. }
  10939. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  10940. if (prefixFragment.length > 0) {
  10941. prefixFragment += '\n';
  10942. }
  10943. } else {
  10944. 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');
  10945. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  10946. '#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
  10947. 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
  10948. 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');
  10949. }
  10950. vertexShader = resolveIncludes(vertexShader);
  10951. vertexShader = replaceLightNums(vertexShader, parameters);
  10952. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  10953. fragmentShader = resolveIncludes(fragmentShader);
  10954. fragmentShader = replaceLightNums(fragmentShader, parameters);
  10955. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  10956. vertexShader = unrollLoops(vertexShader);
  10957. fragmentShader = unrollLoops(fragmentShader);
  10958. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  10959. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  10960. versionString = '#version 300 es\n';
  10961. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  10962. 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;
  10963. }
  10964. var vertexGlsl = versionString + prefixVertex + vertexShader;
  10965. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  10966. // console.log( '*FRAGMENT*', fragmentGlsl );
  10967. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  10968. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  10969. gl.attachShader(program, glVertexShader);
  10970. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  10971. if (parameters.index0AttributeName !== undefined) {
  10972. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  10973. } else if (parameters.morphTargets === true) {
  10974. // programs with morphTargets displace position out of attribute 0
  10975. gl.bindAttribLocation(program, 0, 'position');
  10976. }
  10977. gl.linkProgram(program); // check for link errors
  10978. if (renderer.debug.checkShaderErrors) {
  10979. var programLog = gl.getProgramInfoLog(program).trim();
  10980. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  10981. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  10982. var runnable = true;
  10983. var haveDiagnostics = true;
  10984. if (gl.getProgramParameter(program, 35714) === false) {
  10985. runnable = false;
  10986. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  10987. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  10988. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  10989. } else if (programLog !== '') {
  10990. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  10991. } else if (vertexLog === '' || fragmentLog === '') {
  10992. haveDiagnostics = false;
  10993. }
  10994. if (haveDiagnostics) {
  10995. this.diagnostics = {
  10996. runnable: runnable,
  10997. programLog: programLog,
  10998. vertexShader: {
  10999. log: vertexLog,
  11000. prefix: prefixVertex
  11001. },
  11002. fragmentShader: {
  11003. log: fragmentLog,
  11004. prefix: prefixFragment
  11005. }
  11006. };
  11007. }
  11008. } // Clean up
  11009. // Crashes in iOS9 and iOS10. #18402
  11010. // gl.detachShader( program, glVertexShader );
  11011. // gl.detachShader( program, glFragmentShader );
  11012. gl.deleteShader(glVertexShader);
  11013. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  11014. var cachedUniforms;
  11015. this.getUniforms = function () {
  11016. if (cachedUniforms === undefined) {
  11017. cachedUniforms = new WebGLUniforms(gl, program);
  11018. }
  11019. return cachedUniforms;
  11020. }; // set up caching for attribute locations
  11021. var cachedAttributes;
  11022. this.getAttributes = function () {
  11023. if (cachedAttributes === undefined) {
  11024. cachedAttributes = fetchAttributeLocations(gl, program);
  11025. }
  11026. return cachedAttributes;
  11027. }; // free resource
  11028. this.destroy = function () {
  11029. bindingStates.releaseStatesOfProgram(this);
  11030. gl.deleteProgram(program);
  11031. this.program = undefined;
  11032. }; //
  11033. this.name = parameters.shaderName;
  11034. this.id = programIdCount++;
  11035. this.cacheKey = cacheKey;
  11036. this.usedTimes = 1;
  11037. this.program = program;
  11038. this.vertexShader = glVertexShader;
  11039. this.fragmentShader = glFragmentShader;
  11040. return this;
  11041. }
  11042. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  11043. var programs = [];
  11044. var isWebGL2 = capabilities.isWebGL2;
  11045. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11046. var floatVertexTextures = capabilities.floatVertexTextures;
  11047. var maxVertexUniforms = capabilities.maxVertexUniforms;
  11048. var vertexTextures = capabilities.vertexTextures;
  11049. var precision = capabilities.precision;
  11050. var shaderIDs = {
  11051. MeshDepthMaterial: 'depth',
  11052. MeshDistanceMaterial: 'distanceRGBA',
  11053. MeshNormalMaterial: 'normal',
  11054. MeshBasicMaterial: 'basic',
  11055. MeshLambertMaterial: 'lambert',
  11056. MeshPhongMaterial: 'phong',
  11057. MeshToonMaterial: 'toon',
  11058. MeshStandardMaterial: 'physical',
  11059. MeshPhysicalMaterial: 'physical',
  11060. MeshMatcapMaterial: 'matcap',
  11061. LineBasicMaterial: 'basic',
  11062. LineDashedMaterial: 'dashed',
  11063. PointsMaterial: 'points',
  11064. ShadowMaterial: 'shadow',
  11065. SpriteMaterial: 'sprite'
  11066. };
  11067. 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'];
  11068. function getMaxBones(object) {
  11069. var skeleton = object.skeleton;
  11070. var bones = skeleton.bones;
  11071. if (floatVertexTextures) {
  11072. return 1024;
  11073. } else {
  11074. // default for when object is not specified
  11075. // ( for example when prebuilding shader to be used with multiple objects )
  11076. //
  11077. // - leave some extra space for other uniforms
  11078. // - limit here is ANGLE's 254 max uniform vectors
  11079. // (up to 54 should be safe)
  11080. var nVertexUniforms = maxVertexUniforms;
  11081. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  11082. var maxBones = Math.min(nVertexMatrices, bones.length);
  11083. if (maxBones < bones.length) {
  11084. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  11085. return 0;
  11086. }
  11087. return maxBones;
  11088. }
  11089. }
  11090. function getTextureEncodingFromMap(map) {
  11091. var encoding;
  11092. if (map && map.isTexture) {
  11093. encoding = map.encoding;
  11094. } else if (map && map.isWebGLRenderTarget) {
  11095. console.warn('THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.');
  11096. encoding = map.texture.encoding;
  11097. } else {
  11098. encoding = LinearEncoding;
  11099. }
  11100. return encoding;
  11101. }
  11102. function getParameters(material, lights, shadows, scene, object) {
  11103. var fog = scene.fog;
  11104. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  11105. var envMap = cubemaps.get(material.envMap || environment);
  11106. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  11107. // (not to blow over maxLights budget)
  11108. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  11109. if (material.precision !== null) {
  11110. precision = capabilities.getMaxPrecision(material.precision);
  11111. if (precision !== material.precision) {
  11112. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  11113. }
  11114. }
  11115. var vertexShader, fragmentShader;
  11116. if (shaderID) {
  11117. var shader = ShaderLib[shaderID];
  11118. vertexShader = shader.vertexShader;
  11119. fragmentShader = shader.fragmentShader;
  11120. } else {
  11121. vertexShader = material.vertexShader;
  11122. fragmentShader = material.fragmentShader;
  11123. }
  11124. var currentRenderTarget = renderer.getRenderTarget();
  11125. var parameters = {
  11126. isWebGL2: isWebGL2,
  11127. shaderID: shaderID,
  11128. shaderName: material.type,
  11129. vertexShader: vertexShader,
  11130. fragmentShader: fragmentShader,
  11131. defines: material.defines,
  11132. isRawShaderMaterial: material.isRawShaderMaterial === true,
  11133. glslVersion: material.glslVersion,
  11134. precision: precision,
  11135. instancing: object.isInstancedMesh === true,
  11136. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  11137. supportsVertexTextures: vertexTextures,
  11138. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  11139. map: !!material.map,
  11140. mapEncoding: getTextureEncodingFromMap(material.map),
  11141. matcap: !!material.matcap,
  11142. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  11143. envMap: !!envMap,
  11144. envMapMode: envMap && envMap.mapping,
  11145. envMapEncoding: getTextureEncodingFromMap(envMap),
  11146. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  11147. lightMap: !!material.lightMap,
  11148. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  11149. aoMap: !!material.aoMap,
  11150. emissiveMap: !!material.emissiveMap,
  11151. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  11152. bumpMap: !!material.bumpMap,
  11153. normalMap: !!material.normalMap,
  11154. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11155. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11156. clearcoatMap: !!material.clearcoatMap,
  11157. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  11158. clearcoatNormalMap: !!material.clearcoatNormalMap,
  11159. displacementMap: !!material.displacementMap,
  11160. roughnessMap: !!material.roughnessMap,
  11161. metalnessMap: !!material.metalnessMap,
  11162. specularMap: !!material.specularMap,
  11163. alphaMap: !!material.alphaMap,
  11164. gradientMap: !!material.gradientMap,
  11165. sheen: !!material.sheen,
  11166. transmissionMap: !!material.transmissionMap,
  11167. combine: material.combine,
  11168. vertexTangents: material.normalMap && material.vertexTangents,
  11169. vertexColors: material.vertexColors,
  11170. 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,
  11171. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  11172. fog: !!fog,
  11173. useFog: material.fog,
  11174. fogExp2: fog && fog.isFogExp2,
  11175. flatShading: material.flatShading,
  11176. sizeAttenuation: material.sizeAttenuation,
  11177. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11178. skinning: material.skinning && maxBones > 0,
  11179. maxBones: maxBones,
  11180. useVertexTexture: floatVertexTextures,
  11181. morphTargets: material.morphTargets,
  11182. morphNormals: material.morphNormals,
  11183. maxMorphTargets: renderer.maxMorphTargets,
  11184. maxMorphNormals: renderer.maxMorphNormals,
  11185. numDirLights: lights.directional.length,
  11186. numPointLights: lights.point.length,
  11187. numSpotLights: lights.spot.length,
  11188. numRectAreaLights: lights.rectArea.length,
  11189. numHemiLights: lights.hemi.length,
  11190. numDirLightShadows: lights.directionalShadowMap.length,
  11191. numPointLightShadows: lights.pointShadowMap.length,
  11192. numSpotLightShadows: lights.spotShadowMap.length,
  11193. numClippingPlanes: clipping.numPlanes,
  11194. numClipIntersection: clipping.numIntersection,
  11195. dithering: material.dithering,
  11196. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11197. shadowMapType: renderer.shadowMap.type,
  11198. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11199. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11200. premultipliedAlpha: material.premultipliedAlpha,
  11201. alphaTest: material.alphaTest,
  11202. doubleSided: material.side === DoubleSide,
  11203. flipSided: material.side === BackSide,
  11204. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11205. index0AttributeName: material.index0AttributeName,
  11206. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11207. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11208. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11209. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11210. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11211. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11212. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11213. customProgramCacheKey: material.customProgramCacheKey()
  11214. };
  11215. return parameters;
  11216. }
  11217. function getProgramCacheKey(parameters) {
  11218. var array = [];
  11219. if (parameters.shaderID) {
  11220. array.push(parameters.shaderID);
  11221. } else {
  11222. array.push(parameters.fragmentShader);
  11223. array.push(parameters.vertexShader);
  11224. }
  11225. if (parameters.defines !== undefined) {
  11226. for (var name in parameters.defines) {
  11227. array.push(name);
  11228. array.push(parameters.defines[name]);
  11229. }
  11230. }
  11231. if (parameters.isRawShaderMaterial === false) {
  11232. for (var i = 0; i < parameterNames.length; i++) {
  11233. array.push(parameters[parameterNames[i]]);
  11234. }
  11235. array.push(renderer.outputEncoding);
  11236. array.push(renderer.gammaFactor);
  11237. }
  11238. array.push(parameters.customProgramCacheKey);
  11239. return array.join();
  11240. }
  11241. function getUniforms(material) {
  11242. var shaderID = shaderIDs[material.type];
  11243. var uniforms;
  11244. if (shaderID) {
  11245. var shader = ShaderLib[shaderID];
  11246. uniforms = UniformsUtils.clone(shader.uniforms);
  11247. } else {
  11248. uniforms = material.uniforms;
  11249. }
  11250. return uniforms;
  11251. }
  11252. function acquireProgram(parameters, cacheKey) {
  11253. var program; // Check if code has been already compiled
  11254. for (var p = 0, pl = programs.length; p < pl; p++) {
  11255. var preexistingProgram = programs[p];
  11256. if (preexistingProgram.cacheKey === cacheKey) {
  11257. program = preexistingProgram;
  11258. ++program.usedTimes;
  11259. break;
  11260. }
  11261. }
  11262. if (program === undefined) {
  11263. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11264. programs.push(program);
  11265. }
  11266. return program;
  11267. }
  11268. function releaseProgram(program) {
  11269. if (--program.usedTimes === 0) {
  11270. // Remove from unordered set
  11271. var i = programs.indexOf(program);
  11272. programs[i] = programs[programs.length - 1];
  11273. programs.pop(); // Free WebGL resources
  11274. program.destroy();
  11275. }
  11276. }
  11277. return {
  11278. getParameters: getParameters,
  11279. getProgramCacheKey: getProgramCacheKey,
  11280. getUniforms: getUniforms,
  11281. acquireProgram: acquireProgram,
  11282. releaseProgram: releaseProgram,
  11283. // Exposed for resource monitoring & error feedback via renderer.info:
  11284. programs: programs
  11285. };
  11286. }
  11287. function WebGLProperties() {
  11288. var properties = new WeakMap();
  11289. function get(object) {
  11290. var map = properties.get(object);
  11291. if (map === undefined) {
  11292. map = {};
  11293. properties.set(object, map);
  11294. }
  11295. return map;
  11296. }
  11297. function remove(object) {
  11298. properties.delete(object);
  11299. }
  11300. function update(object, key, value) {
  11301. properties.get(object)[key] = value;
  11302. }
  11303. function dispose() {
  11304. properties = new WeakMap();
  11305. }
  11306. return {
  11307. get: get,
  11308. remove: remove,
  11309. update: update,
  11310. dispose: dispose
  11311. };
  11312. }
  11313. function painterSortStable(a, b) {
  11314. if (a.groupOrder !== b.groupOrder) {
  11315. return a.groupOrder - b.groupOrder;
  11316. } else if (a.renderOrder !== b.renderOrder) {
  11317. return a.renderOrder - b.renderOrder;
  11318. } else if (a.program !== b.program) {
  11319. return a.program.id - b.program.id;
  11320. } else if (a.material.id !== b.material.id) {
  11321. return a.material.id - b.material.id;
  11322. } else if (a.z !== b.z) {
  11323. return a.z - b.z;
  11324. } else {
  11325. return a.id - b.id;
  11326. }
  11327. }
  11328. function reversePainterSortStable(a, b) {
  11329. if (a.groupOrder !== b.groupOrder) {
  11330. return a.groupOrder - b.groupOrder;
  11331. } else if (a.renderOrder !== b.renderOrder) {
  11332. return a.renderOrder - b.renderOrder;
  11333. } else if (a.z !== b.z) {
  11334. return b.z - a.z;
  11335. } else {
  11336. return a.id - b.id;
  11337. }
  11338. }
  11339. function WebGLRenderList(properties) {
  11340. var renderItems = [];
  11341. var renderItemsIndex = 0;
  11342. var opaque = [];
  11343. var transparent = [];
  11344. var defaultProgram = {
  11345. id: -1
  11346. };
  11347. function init() {
  11348. renderItemsIndex = 0;
  11349. opaque.length = 0;
  11350. transparent.length = 0;
  11351. }
  11352. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11353. var renderItem = renderItems[renderItemsIndex];
  11354. var materialProperties = properties.get(material);
  11355. if (renderItem === undefined) {
  11356. renderItem = {
  11357. id: object.id,
  11358. object: object,
  11359. geometry: geometry,
  11360. material: material,
  11361. program: materialProperties.program || defaultProgram,
  11362. groupOrder: groupOrder,
  11363. renderOrder: object.renderOrder,
  11364. z: z,
  11365. group: group
  11366. };
  11367. renderItems[renderItemsIndex] = renderItem;
  11368. } else {
  11369. renderItem.id = object.id;
  11370. renderItem.object = object;
  11371. renderItem.geometry = geometry;
  11372. renderItem.material = material;
  11373. renderItem.program = materialProperties.program || defaultProgram;
  11374. renderItem.groupOrder = groupOrder;
  11375. renderItem.renderOrder = object.renderOrder;
  11376. renderItem.z = z;
  11377. renderItem.group = group;
  11378. }
  11379. renderItemsIndex++;
  11380. return renderItem;
  11381. }
  11382. function push(object, geometry, material, groupOrder, z, group) {
  11383. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11384. (material.transparent === true ? transparent : opaque).push(renderItem);
  11385. }
  11386. function unshift(object, geometry, material, groupOrder, z, group) {
  11387. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11388. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11389. }
  11390. function sort(customOpaqueSort, customTransparentSort) {
  11391. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11392. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11393. }
  11394. function finish() {
  11395. // Clear references from inactive renderItems in the list
  11396. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11397. var renderItem = renderItems[i];
  11398. if (renderItem.id === null) break;
  11399. renderItem.id = null;
  11400. renderItem.object = null;
  11401. renderItem.geometry = null;
  11402. renderItem.material = null;
  11403. renderItem.program = null;
  11404. renderItem.group = null;
  11405. }
  11406. }
  11407. return {
  11408. opaque: opaque,
  11409. transparent: transparent,
  11410. init: init,
  11411. push: push,
  11412. unshift: unshift,
  11413. finish: finish,
  11414. sort: sort
  11415. };
  11416. }
  11417. function WebGLRenderLists(properties) {
  11418. var lists = new WeakMap();
  11419. function get(scene, camera) {
  11420. var cameras = lists.get(scene);
  11421. var list;
  11422. if (cameras === undefined) {
  11423. list = new WebGLRenderList(properties);
  11424. lists.set(scene, new WeakMap());
  11425. lists.get(scene).set(camera, list);
  11426. } else {
  11427. list = cameras.get(camera);
  11428. if (list === undefined) {
  11429. list = new WebGLRenderList(properties);
  11430. cameras.set(camera, list);
  11431. }
  11432. }
  11433. return list;
  11434. }
  11435. function dispose() {
  11436. lists = new WeakMap();
  11437. }
  11438. return {
  11439. get: get,
  11440. dispose: dispose
  11441. };
  11442. }
  11443. function UniformsCache() {
  11444. var lights = {};
  11445. return {
  11446. get: function get(light) {
  11447. if (lights[light.id] !== undefined) {
  11448. return lights[light.id];
  11449. }
  11450. var uniforms;
  11451. switch (light.type) {
  11452. case 'DirectionalLight':
  11453. uniforms = {
  11454. direction: new Vector3(),
  11455. color: new Color()
  11456. };
  11457. break;
  11458. case 'SpotLight':
  11459. uniforms = {
  11460. position: new Vector3(),
  11461. direction: new Vector3(),
  11462. color: new Color(),
  11463. distance: 0,
  11464. coneCos: 0,
  11465. penumbraCos: 0,
  11466. decay: 0
  11467. };
  11468. break;
  11469. case 'PointLight':
  11470. uniforms = {
  11471. position: new Vector3(),
  11472. color: new Color(),
  11473. distance: 0,
  11474. decay: 0
  11475. };
  11476. break;
  11477. case 'HemisphereLight':
  11478. uniforms = {
  11479. direction: new Vector3(),
  11480. skyColor: new Color(),
  11481. groundColor: new Color()
  11482. };
  11483. break;
  11484. case 'RectAreaLight':
  11485. uniforms = {
  11486. color: new Color(),
  11487. position: new Vector3(),
  11488. halfWidth: new Vector3(),
  11489. halfHeight: new Vector3()
  11490. };
  11491. break;
  11492. }
  11493. lights[light.id] = uniforms;
  11494. return uniforms;
  11495. }
  11496. };
  11497. }
  11498. function ShadowUniformsCache() {
  11499. var lights = {};
  11500. return {
  11501. get: function get(light) {
  11502. if (lights[light.id] !== undefined) {
  11503. return lights[light.id];
  11504. }
  11505. var uniforms;
  11506. switch (light.type) {
  11507. case 'DirectionalLight':
  11508. uniforms = {
  11509. shadowBias: 0,
  11510. shadowNormalBias: 0,
  11511. shadowRadius: 1,
  11512. shadowMapSize: new Vector2()
  11513. };
  11514. break;
  11515. case 'SpotLight':
  11516. uniforms = {
  11517. shadowBias: 0,
  11518. shadowNormalBias: 0,
  11519. shadowRadius: 1,
  11520. shadowMapSize: new Vector2()
  11521. };
  11522. break;
  11523. case 'PointLight':
  11524. uniforms = {
  11525. shadowBias: 0,
  11526. shadowNormalBias: 0,
  11527. shadowRadius: 1,
  11528. shadowMapSize: new Vector2(),
  11529. shadowCameraNear: 1,
  11530. shadowCameraFar: 1000
  11531. };
  11532. break;
  11533. // TODO (abelnation): set RectAreaLight shadow uniforms
  11534. }
  11535. lights[light.id] = uniforms;
  11536. return uniforms;
  11537. }
  11538. };
  11539. }
  11540. var nextVersion = 0;
  11541. function shadowCastingLightsFirst(lightA, lightB) {
  11542. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  11543. }
  11544. function WebGLLights(extensions, capabilities) {
  11545. var cache = new UniformsCache();
  11546. var shadowCache = ShadowUniformsCache();
  11547. var state = {
  11548. version: 0,
  11549. hash: {
  11550. directionalLength: -1,
  11551. pointLength: -1,
  11552. spotLength: -1,
  11553. rectAreaLength: -1,
  11554. hemiLength: -1,
  11555. numDirectionalShadows: -1,
  11556. numPointShadows: -1,
  11557. numSpotShadows: -1
  11558. },
  11559. ambient: [0, 0, 0],
  11560. probe: [],
  11561. directional: [],
  11562. directionalShadow: [],
  11563. directionalShadowMap: [],
  11564. directionalShadowMatrix: [],
  11565. spot: [],
  11566. spotShadow: [],
  11567. spotShadowMap: [],
  11568. spotShadowMatrix: [],
  11569. rectArea: [],
  11570. rectAreaLTC1: null,
  11571. rectAreaLTC2: null,
  11572. point: [],
  11573. pointShadow: [],
  11574. pointShadowMap: [],
  11575. pointShadowMatrix: [],
  11576. hemi: []
  11577. };
  11578. for (var i = 0; i < 9; i++) {
  11579. state.probe.push(new Vector3());
  11580. }
  11581. var vector3 = new Vector3();
  11582. var matrix4 = new Matrix4();
  11583. var matrix42 = new Matrix4();
  11584. function setup(lights) {
  11585. var r = 0,
  11586. g = 0,
  11587. b = 0;
  11588. for (var _i = 0; _i < 9; _i++) {
  11589. state.probe[_i].set(0, 0, 0);
  11590. }
  11591. var directionalLength = 0;
  11592. var pointLength = 0;
  11593. var spotLength = 0;
  11594. var rectAreaLength = 0;
  11595. var hemiLength = 0;
  11596. var numDirectionalShadows = 0;
  11597. var numPointShadows = 0;
  11598. var numSpotShadows = 0;
  11599. lights.sort(shadowCastingLightsFirst);
  11600. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  11601. var light = lights[_i2];
  11602. var color = light.color;
  11603. var intensity = light.intensity;
  11604. var distance = light.distance;
  11605. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  11606. if (light.isAmbientLight) {
  11607. r += color.r * intensity;
  11608. g += color.g * intensity;
  11609. b += color.b * intensity;
  11610. } else if (light.isLightProbe) {
  11611. for (var j = 0; j < 9; j++) {
  11612. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  11613. }
  11614. } else if (light.isDirectionalLight) {
  11615. var uniforms = cache.get(light);
  11616. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  11617. if (light.castShadow) {
  11618. var shadow = light.shadow;
  11619. var shadowUniforms = shadowCache.get(light);
  11620. shadowUniforms.shadowBias = shadow.bias;
  11621. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11622. shadowUniforms.shadowRadius = shadow.radius;
  11623. shadowUniforms.shadowMapSize = shadow.mapSize;
  11624. state.directionalShadow[directionalLength] = shadowUniforms;
  11625. state.directionalShadowMap[directionalLength] = shadowMap;
  11626. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  11627. numDirectionalShadows++;
  11628. }
  11629. state.directional[directionalLength] = uniforms;
  11630. directionalLength++;
  11631. } else if (light.isSpotLight) {
  11632. var _uniforms = cache.get(light);
  11633. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  11634. _uniforms.color.copy(color).multiplyScalar(intensity);
  11635. _uniforms.distance = distance;
  11636. _uniforms.coneCos = Math.cos(light.angle);
  11637. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  11638. _uniforms.decay = light.decay;
  11639. if (light.castShadow) {
  11640. var _shadow = light.shadow;
  11641. var _shadowUniforms = shadowCache.get(light);
  11642. _shadowUniforms.shadowBias = _shadow.bias;
  11643. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  11644. _shadowUniforms.shadowRadius = _shadow.radius;
  11645. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  11646. state.spotShadow[spotLength] = _shadowUniforms;
  11647. state.spotShadowMap[spotLength] = shadowMap;
  11648. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  11649. numSpotShadows++;
  11650. }
  11651. state.spot[spotLength] = _uniforms;
  11652. spotLength++;
  11653. } else if (light.isRectAreaLight) {
  11654. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  11655. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11656. // (b) intensity is the brightness of the light
  11657. _uniforms2.color.copy(color).multiplyScalar(intensity);
  11658. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  11659. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  11660. state.rectArea[rectAreaLength] = _uniforms2;
  11661. rectAreaLength++;
  11662. } else if (light.isPointLight) {
  11663. var _uniforms3 = cache.get(light);
  11664. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  11665. _uniforms3.distance = light.distance;
  11666. _uniforms3.decay = light.decay;
  11667. if (light.castShadow) {
  11668. var _shadow2 = light.shadow;
  11669. var _shadowUniforms2 = shadowCache.get(light);
  11670. _shadowUniforms2.shadowBias = _shadow2.bias;
  11671. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  11672. _shadowUniforms2.shadowRadius = _shadow2.radius;
  11673. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  11674. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  11675. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  11676. state.pointShadow[pointLength] = _shadowUniforms2;
  11677. state.pointShadowMap[pointLength] = shadowMap;
  11678. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  11679. numPointShadows++;
  11680. }
  11681. state.point[pointLength] = _uniforms3;
  11682. pointLength++;
  11683. } else if (light.isHemisphereLight) {
  11684. var _uniforms4 = cache.get(light);
  11685. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  11686. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  11687. state.hemi[hemiLength] = _uniforms4;
  11688. hemiLength++;
  11689. }
  11690. }
  11691. if (rectAreaLength > 0) {
  11692. if (capabilities.isWebGL2) {
  11693. // WebGL 2
  11694. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11695. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11696. } else {
  11697. // WebGL 1
  11698. if (extensions.has('OES_texture_float_linear') === true) {
  11699. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11700. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11701. } else if (extensions.has('OES_texture_half_float_linear') === true) {
  11702. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  11703. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  11704. } else {
  11705. console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
  11706. }
  11707. }
  11708. }
  11709. state.ambient[0] = r;
  11710. state.ambient[1] = g;
  11711. state.ambient[2] = b;
  11712. var hash = state.hash;
  11713. 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) {
  11714. state.directional.length = directionalLength;
  11715. state.spot.length = spotLength;
  11716. state.rectArea.length = rectAreaLength;
  11717. state.point.length = pointLength;
  11718. state.hemi.length = hemiLength;
  11719. state.directionalShadow.length = numDirectionalShadows;
  11720. state.directionalShadowMap.length = numDirectionalShadows;
  11721. state.pointShadow.length = numPointShadows;
  11722. state.pointShadowMap.length = numPointShadows;
  11723. state.spotShadow.length = numSpotShadows;
  11724. state.spotShadowMap.length = numSpotShadows;
  11725. state.directionalShadowMatrix.length = numDirectionalShadows;
  11726. state.pointShadowMatrix.length = numPointShadows;
  11727. state.spotShadowMatrix.length = numSpotShadows;
  11728. hash.directionalLength = directionalLength;
  11729. hash.pointLength = pointLength;
  11730. hash.spotLength = spotLength;
  11731. hash.rectAreaLength = rectAreaLength;
  11732. hash.hemiLength = hemiLength;
  11733. hash.numDirectionalShadows = numDirectionalShadows;
  11734. hash.numPointShadows = numPointShadows;
  11735. hash.numSpotShadows = numSpotShadows;
  11736. state.version = nextVersion++;
  11737. }
  11738. }
  11739. function setupView(lights, camera) {
  11740. var directionalLength = 0;
  11741. var pointLength = 0;
  11742. var spotLength = 0;
  11743. var rectAreaLength = 0;
  11744. var hemiLength = 0;
  11745. var viewMatrix = camera.matrixWorldInverse;
  11746. for (var _i3 = 0, l = lights.length; _i3 < l; _i3++) {
  11747. var light = lights[_i3];
  11748. if (light.isDirectionalLight) {
  11749. var uniforms = state.directional[directionalLength];
  11750. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11751. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11752. uniforms.direction.sub(vector3);
  11753. uniforms.direction.transformDirection(viewMatrix);
  11754. directionalLength++;
  11755. } else if (light.isSpotLight) {
  11756. var _uniforms5 = state.spot[spotLength];
  11757. _uniforms5.position.setFromMatrixPosition(light.matrixWorld);
  11758. _uniforms5.position.applyMatrix4(viewMatrix);
  11759. _uniforms5.direction.setFromMatrixPosition(light.matrixWorld);
  11760. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11761. _uniforms5.direction.sub(vector3);
  11762. _uniforms5.direction.transformDirection(viewMatrix);
  11763. spotLength++;
  11764. } else if (light.isRectAreaLight) {
  11765. var _uniforms6 = state.rectArea[rectAreaLength];
  11766. _uniforms6.position.setFromMatrixPosition(light.matrixWorld);
  11767. _uniforms6.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  11768. matrix42.identity();
  11769. matrix4.copy(light.matrixWorld);
  11770. matrix4.premultiply(viewMatrix);
  11771. matrix42.extractRotation(matrix4);
  11772. _uniforms6.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  11773. _uniforms6.halfHeight.set(0.0, light.height * 0.5, 0.0);
  11774. _uniforms6.halfWidth.applyMatrix4(matrix42);
  11775. _uniforms6.halfHeight.applyMatrix4(matrix42);
  11776. rectAreaLength++;
  11777. } else if (light.isPointLight) {
  11778. var _uniforms7 = state.point[pointLength];
  11779. _uniforms7.position.setFromMatrixPosition(light.matrixWorld);
  11780. _uniforms7.position.applyMatrix4(viewMatrix);
  11781. pointLength++;
  11782. } else if (light.isHemisphereLight) {
  11783. var _uniforms8 = state.hemi[hemiLength];
  11784. _uniforms8.direction.setFromMatrixPosition(light.matrixWorld);
  11785. _uniforms8.direction.transformDirection(viewMatrix);
  11786. _uniforms8.direction.normalize();
  11787. hemiLength++;
  11788. }
  11789. }
  11790. }
  11791. return {
  11792. setup: setup,
  11793. setupView: setupView,
  11794. state: state
  11795. };
  11796. }
  11797. function WebGLRenderState(extensions, capabilities) {
  11798. var lights = new WebGLLights(extensions, capabilities);
  11799. var lightsArray = [];
  11800. var shadowsArray = [];
  11801. function init() {
  11802. lightsArray.length = 0;
  11803. shadowsArray.length = 0;
  11804. }
  11805. function pushLight(light) {
  11806. lightsArray.push(light);
  11807. }
  11808. function pushShadow(shadowLight) {
  11809. shadowsArray.push(shadowLight);
  11810. }
  11811. function setupLights() {
  11812. lights.setup(lightsArray);
  11813. }
  11814. function setupLightsView(camera) {
  11815. lights.setupView(lightsArray, camera);
  11816. }
  11817. var state = {
  11818. lightsArray: lightsArray,
  11819. shadowsArray: shadowsArray,
  11820. lights: lights
  11821. };
  11822. return {
  11823. init: init,
  11824. state: state,
  11825. setupLights: setupLights,
  11826. setupLightsView: setupLightsView,
  11827. pushLight: pushLight,
  11828. pushShadow: pushShadow
  11829. };
  11830. }
  11831. function WebGLRenderStates(extensions, capabilities) {
  11832. var renderStates = new WeakMap();
  11833. function get(scene, renderCallDepth) {
  11834. if (renderCallDepth === void 0) {
  11835. renderCallDepth = 0;
  11836. }
  11837. var renderState;
  11838. if (renderStates.has(scene) === false) {
  11839. renderState = new WebGLRenderState(extensions, capabilities);
  11840. renderStates.set(scene, []);
  11841. renderStates.get(scene).push(renderState);
  11842. } else {
  11843. if (renderCallDepth >= renderStates.get(scene).length) {
  11844. renderState = new WebGLRenderState(extensions, capabilities);
  11845. renderStates.get(scene).push(renderState);
  11846. } else {
  11847. renderState = renderStates.get(scene)[renderCallDepth];
  11848. }
  11849. }
  11850. return renderState;
  11851. }
  11852. function dispose() {
  11853. renderStates = new WeakMap();
  11854. }
  11855. return {
  11856. get: get,
  11857. dispose: dispose
  11858. };
  11859. }
  11860. /**
  11861. * parameters = {
  11862. *
  11863. * opacity: <float>,
  11864. *
  11865. * map: new THREE.Texture( <Image> ),
  11866. *
  11867. * alphaMap: new THREE.Texture( <Image> ),
  11868. *
  11869. * displacementMap: new THREE.Texture( <Image> ),
  11870. * displacementScale: <float>,
  11871. * displacementBias: <float>,
  11872. *
  11873. * wireframe: <boolean>,
  11874. * wireframeLinewidth: <float>
  11875. * }
  11876. */
  11877. function MeshDepthMaterial(parameters) {
  11878. Material.call(this);
  11879. this.type = 'MeshDepthMaterial';
  11880. this.depthPacking = BasicDepthPacking;
  11881. this.skinning = false;
  11882. this.morphTargets = false;
  11883. this.map = null;
  11884. this.alphaMap = null;
  11885. this.displacementMap = null;
  11886. this.displacementScale = 1;
  11887. this.displacementBias = 0;
  11888. this.wireframe = false;
  11889. this.wireframeLinewidth = 1;
  11890. this.fog = false;
  11891. this.setValues(parameters);
  11892. }
  11893. MeshDepthMaterial.prototype = Object.create(Material.prototype);
  11894. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11895. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11896. MeshDepthMaterial.prototype.copy = function (source) {
  11897. Material.prototype.copy.call(this, source);
  11898. this.depthPacking = source.depthPacking;
  11899. this.skinning = source.skinning;
  11900. this.morphTargets = source.morphTargets;
  11901. this.map = source.map;
  11902. this.alphaMap = source.alphaMap;
  11903. this.displacementMap = source.displacementMap;
  11904. this.displacementScale = source.displacementScale;
  11905. this.displacementBias = source.displacementBias;
  11906. this.wireframe = source.wireframe;
  11907. this.wireframeLinewidth = source.wireframeLinewidth;
  11908. return this;
  11909. };
  11910. /**
  11911. * parameters = {
  11912. *
  11913. * referencePosition: <float>,
  11914. * nearDistance: <float>,
  11915. * farDistance: <float>,
  11916. *
  11917. * skinning: <bool>,
  11918. * morphTargets: <bool>,
  11919. *
  11920. * map: new THREE.Texture( <Image> ),
  11921. *
  11922. * alphaMap: new THREE.Texture( <Image> ),
  11923. *
  11924. * displacementMap: new THREE.Texture( <Image> ),
  11925. * displacementScale: <float>,
  11926. * displacementBias: <float>
  11927. *
  11928. * }
  11929. */
  11930. function MeshDistanceMaterial(parameters) {
  11931. Material.call(this);
  11932. this.type = 'MeshDistanceMaterial';
  11933. this.referencePosition = new Vector3();
  11934. this.nearDistance = 1;
  11935. this.farDistance = 1000;
  11936. this.skinning = false;
  11937. this.morphTargets = false;
  11938. this.map = null;
  11939. this.alphaMap = null;
  11940. this.displacementMap = null;
  11941. this.displacementScale = 1;
  11942. this.displacementBias = 0;
  11943. this.fog = false;
  11944. this.setValues(parameters);
  11945. }
  11946. MeshDistanceMaterial.prototype = Object.create(Material.prototype);
  11947. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11948. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11949. MeshDistanceMaterial.prototype.copy = function (source) {
  11950. Material.prototype.copy.call(this, source);
  11951. this.referencePosition.copy(source.referencePosition);
  11952. this.nearDistance = source.nearDistance;
  11953. this.farDistance = source.farDistance;
  11954. this.skinning = source.skinning;
  11955. this.morphTargets = source.morphTargets;
  11956. this.map = source.map;
  11957. this.alphaMap = source.alphaMap;
  11958. this.displacementMap = source.displacementMap;
  11959. this.displacementScale = source.displacementScale;
  11960. this.displacementBias = source.displacementBias;
  11961. return this;
  11962. };
  11963. 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}";
  11964. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  11965. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  11966. var _frustum = new Frustum();
  11967. var _shadowMapSize = new Vector2(),
  11968. _viewportSize = new Vector2(),
  11969. _viewport = new Vector4(),
  11970. _depthMaterials = [],
  11971. _distanceMaterials = [],
  11972. _materialCache = {};
  11973. var shadowSide = {
  11974. 0: BackSide,
  11975. 1: FrontSide,
  11976. 2: DoubleSide
  11977. };
  11978. var shadowMaterialVertical = new ShaderMaterial({
  11979. defines: {
  11980. SAMPLE_RATE: 2.0 / 8.0,
  11981. HALF_SAMPLE_RATE: 1.0 / 8.0
  11982. },
  11983. uniforms: {
  11984. shadow_pass: {
  11985. value: null
  11986. },
  11987. resolution: {
  11988. value: new Vector2()
  11989. },
  11990. radius: {
  11991. value: 4.0
  11992. }
  11993. },
  11994. vertexShader: vsm_vert,
  11995. fragmentShader: vsm_frag
  11996. });
  11997. var shadowMaterialHorizontal = shadowMaterialVertical.clone();
  11998. shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
  11999. var fullScreenTri = new BufferGeometry();
  12000. fullScreenTri.setAttribute('position', new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  12001. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  12002. var scope = this;
  12003. this.enabled = false;
  12004. this.autoUpdate = true;
  12005. this.needsUpdate = false;
  12006. this.type = PCFShadowMap;
  12007. this.render = function (lights, scene, camera) {
  12008. if (scope.enabled === false) return;
  12009. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  12010. if (lights.length === 0) return;
  12011. var currentRenderTarget = _renderer.getRenderTarget();
  12012. var activeCubeFace = _renderer.getActiveCubeFace();
  12013. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  12014. var _state = _renderer.state; // Set GL state for depth map.
  12015. _state.setBlending(NoBlending);
  12016. _state.buffers.color.setClear(1, 1, 1, 1);
  12017. _state.buffers.depth.setTest(true);
  12018. _state.setScissorTest(false); // render depth map
  12019. for (var i = 0, il = lights.length; i < il; i++) {
  12020. var light = lights[i];
  12021. var shadow = light.shadow;
  12022. if (shadow === undefined) {
  12023. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  12024. continue;
  12025. }
  12026. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  12027. _shadowMapSize.copy(shadow.mapSize);
  12028. var shadowFrameExtents = shadow.getFrameExtents();
  12029. _shadowMapSize.multiply(shadowFrameExtents);
  12030. _viewportSize.copy(shadow.mapSize);
  12031. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  12032. if (_shadowMapSize.x > maxTextureSize) {
  12033. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  12034. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  12035. shadow.mapSize.x = _viewportSize.x;
  12036. }
  12037. if (_shadowMapSize.y > maxTextureSize) {
  12038. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  12039. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  12040. shadow.mapSize.y = _viewportSize.y;
  12041. }
  12042. }
  12043. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12044. var pars = {
  12045. minFilter: LinearFilter,
  12046. magFilter: LinearFilter,
  12047. format: RGBAFormat
  12048. };
  12049. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12050. shadow.map.texture.name = light.name + '.shadowMap';
  12051. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12052. shadow.camera.updateProjectionMatrix();
  12053. }
  12054. if (shadow.map === null) {
  12055. var _pars = {
  12056. minFilter: NearestFilter,
  12057. magFilter: NearestFilter,
  12058. format: RGBAFormat
  12059. };
  12060. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  12061. shadow.map.texture.name = light.name + '.shadowMap';
  12062. shadow.camera.updateProjectionMatrix();
  12063. }
  12064. _renderer.setRenderTarget(shadow.map);
  12065. _renderer.clear();
  12066. var viewportCount = shadow.getViewportCount();
  12067. for (var vp = 0; vp < viewportCount; vp++) {
  12068. var viewport = shadow.getViewport(vp);
  12069. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  12070. _state.viewport(_viewport);
  12071. shadow.updateMatrices(light, vp);
  12072. _frustum = shadow.getFrustum();
  12073. renderObject(scene, camera, shadow.camera, light, this.type);
  12074. } // do blur pass for VSM
  12075. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12076. VSMPass(shadow, camera);
  12077. }
  12078. shadow.needsUpdate = false;
  12079. }
  12080. scope.needsUpdate = false;
  12081. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  12082. };
  12083. function VSMPass(shadow, camera) {
  12084. var geometry = _objects.update(fullScreenMesh); // vertical pass
  12085. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12086. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12087. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12088. _renderer.setRenderTarget(shadow.mapPass);
  12089. _renderer.clear();
  12090. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizontal pass
  12091. shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12092. shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
  12093. shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
  12094. _renderer.setRenderTarget(shadow.map);
  12095. _renderer.clear();
  12096. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null);
  12097. }
  12098. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12099. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12100. var material = _depthMaterials[index];
  12101. if (material === undefined) {
  12102. material = new MeshDepthMaterial({
  12103. depthPacking: RGBADepthPacking,
  12104. morphTargets: useMorphing,
  12105. skinning: useSkinning
  12106. });
  12107. _depthMaterials[index] = material;
  12108. }
  12109. return material;
  12110. }
  12111. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12112. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12113. var material = _distanceMaterials[index];
  12114. if (material === undefined) {
  12115. material = new MeshDistanceMaterial({
  12116. morphTargets: useMorphing,
  12117. skinning: useSkinning
  12118. });
  12119. _distanceMaterials[index] = material;
  12120. }
  12121. return material;
  12122. }
  12123. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  12124. var result = null;
  12125. var getMaterialVariant = getDepthMaterialVariant;
  12126. var customMaterial = object.customDepthMaterial;
  12127. if (light.isPointLight === true) {
  12128. getMaterialVariant = getDistanceMaterialVariant;
  12129. customMaterial = object.customDistanceMaterial;
  12130. }
  12131. if (customMaterial === undefined) {
  12132. var useMorphing = false;
  12133. if (material.morphTargets === true) {
  12134. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12135. }
  12136. var useSkinning = false;
  12137. if (object.isSkinnedMesh === true) {
  12138. if (material.skinning === true) {
  12139. useSkinning = true;
  12140. } else {
  12141. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  12142. }
  12143. }
  12144. var useInstancing = object.isInstancedMesh === true;
  12145. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  12146. } else {
  12147. result = customMaterial;
  12148. }
  12149. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  12150. // in this case we need a unique material instance reflecting the
  12151. // appropriate state
  12152. var keyA = result.uuid,
  12153. keyB = material.uuid;
  12154. var materialsForVariant = _materialCache[keyA];
  12155. if (materialsForVariant === undefined) {
  12156. materialsForVariant = {};
  12157. _materialCache[keyA] = materialsForVariant;
  12158. }
  12159. var cachedMaterial = materialsForVariant[keyB];
  12160. if (cachedMaterial === undefined) {
  12161. cachedMaterial = result.clone();
  12162. materialsForVariant[keyB] = cachedMaterial;
  12163. }
  12164. result = cachedMaterial;
  12165. }
  12166. result.visible = material.visible;
  12167. result.wireframe = material.wireframe;
  12168. if (type === VSMShadowMap) {
  12169. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  12170. } else {
  12171. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  12172. }
  12173. result.clipShadows = material.clipShadows;
  12174. result.clippingPlanes = material.clippingPlanes;
  12175. result.clipIntersection = material.clipIntersection;
  12176. result.wireframeLinewidth = material.wireframeLinewidth;
  12177. result.linewidth = material.linewidth;
  12178. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  12179. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  12180. result.nearDistance = shadowCameraNear;
  12181. result.farDistance = shadowCameraFar;
  12182. }
  12183. return result;
  12184. }
  12185. function renderObject(object, camera, shadowCamera, light, type) {
  12186. if (object.visible === false) return;
  12187. var visible = object.layers.test(camera.layers);
  12188. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  12189. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  12190. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  12191. var geometry = _objects.update(object);
  12192. var material = object.material;
  12193. if (Array.isArray(material)) {
  12194. var groups = geometry.groups;
  12195. for (var k = 0, kl = groups.length; k < kl; k++) {
  12196. var group = groups[k];
  12197. var groupMaterial = material[group.materialIndex];
  12198. if (groupMaterial && groupMaterial.visible) {
  12199. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  12200. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  12201. }
  12202. }
  12203. } else if (material.visible) {
  12204. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  12205. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  12206. }
  12207. }
  12208. }
  12209. var children = object.children;
  12210. for (var i = 0, l = children.length; i < l; i++) {
  12211. renderObject(children[i], camera, shadowCamera, light, type);
  12212. }
  12213. }
  12214. }
  12215. function WebGLState(gl, extensions, capabilities) {
  12216. var _equationToGL, _factorToGL;
  12217. var isWebGL2 = capabilities.isWebGL2;
  12218. function ColorBuffer() {
  12219. var locked = false;
  12220. var color = new Vector4();
  12221. var currentColorMask = null;
  12222. var currentColorClear = new Vector4(0, 0, 0, 0);
  12223. return {
  12224. setMask: function setMask(colorMask) {
  12225. if (currentColorMask !== colorMask && !locked) {
  12226. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12227. currentColorMask = colorMask;
  12228. }
  12229. },
  12230. setLocked: function setLocked(lock) {
  12231. locked = lock;
  12232. },
  12233. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12234. if (premultipliedAlpha === true) {
  12235. r *= a;
  12236. g *= a;
  12237. b *= a;
  12238. }
  12239. color.set(r, g, b, a);
  12240. if (currentColorClear.equals(color) === false) {
  12241. gl.clearColor(r, g, b, a);
  12242. currentColorClear.copy(color);
  12243. }
  12244. },
  12245. reset: function reset() {
  12246. locked = false;
  12247. currentColorMask = null;
  12248. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12249. }
  12250. };
  12251. }
  12252. function DepthBuffer() {
  12253. var locked = false;
  12254. var currentDepthMask = null;
  12255. var currentDepthFunc = null;
  12256. var currentDepthClear = null;
  12257. return {
  12258. setTest: function setTest(depthTest) {
  12259. if (depthTest) {
  12260. enable(2929);
  12261. } else {
  12262. disable(2929);
  12263. }
  12264. },
  12265. setMask: function setMask(depthMask) {
  12266. if (currentDepthMask !== depthMask && !locked) {
  12267. gl.depthMask(depthMask);
  12268. currentDepthMask = depthMask;
  12269. }
  12270. },
  12271. setFunc: function setFunc(depthFunc) {
  12272. if (currentDepthFunc !== depthFunc) {
  12273. if (depthFunc) {
  12274. switch (depthFunc) {
  12275. case NeverDepth:
  12276. gl.depthFunc(512);
  12277. break;
  12278. case AlwaysDepth:
  12279. gl.depthFunc(519);
  12280. break;
  12281. case LessDepth:
  12282. gl.depthFunc(513);
  12283. break;
  12284. case LessEqualDepth:
  12285. gl.depthFunc(515);
  12286. break;
  12287. case EqualDepth:
  12288. gl.depthFunc(514);
  12289. break;
  12290. case GreaterEqualDepth:
  12291. gl.depthFunc(518);
  12292. break;
  12293. case GreaterDepth:
  12294. gl.depthFunc(516);
  12295. break;
  12296. case NotEqualDepth:
  12297. gl.depthFunc(517);
  12298. break;
  12299. default:
  12300. gl.depthFunc(515);
  12301. }
  12302. } else {
  12303. gl.depthFunc(515);
  12304. }
  12305. currentDepthFunc = depthFunc;
  12306. }
  12307. },
  12308. setLocked: function setLocked(lock) {
  12309. locked = lock;
  12310. },
  12311. setClear: function setClear(depth) {
  12312. if (currentDepthClear !== depth) {
  12313. gl.clearDepth(depth);
  12314. currentDepthClear = depth;
  12315. }
  12316. },
  12317. reset: function reset() {
  12318. locked = false;
  12319. currentDepthMask = null;
  12320. currentDepthFunc = null;
  12321. currentDepthClear = null;
  12322. }
  12323. };
  12324. }
  12325. function StencilBuffer() {
  12326. var locked = false;
  12327. var currentStencilMask = null;
  12328. var currentStencilFunc = null;
  12329. var currentStencilRef = null;
  12330. var currentStencilFuncMask = null;
  12331. var currentStencilFail = null;
  12332. var currentStencilZFail = null;
  12333. var currentStencilZPass = null;
  12334. var currentStencilClear = null;
  12335. return {
  12336. setTest: function setTest(stencilTest) {
  12337. if (!locked) {
  12338. if (stencilTest) {
  12339. enable(2960);
  12340. } else {
  12341. disable(2960);
  12342. }
  12343. }
  12344. },
  12345. setMask: function setMask(stencilMask) {
  12346. if (currentStencilMask !== stencilMask && !locked) {
  12347. gl.stencilMask(stencilMask);
  12348. currentStencilMask = stencilMask;
  12349. }
  12350. },
  12351. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12352. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12353. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12354. currentStencilFunc = stencilFunc;
  12355. currentStencilRef = stencilRef;
  12356. currentStencilFuncMask = stencilMask;
  12357. }
  12358. },
  12359. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12360. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12361. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12362. currentStencilFail = stencilFail;
  12363. currentStencilZFail = stencilZFail;
  12364. currentStencilZPass = stencilZPass;
  12365. }
  12366. },
  12367. setLocked: function setLocked(lock) {
  12368. locked = lock;
  12369. },
  12370. setClear: function setClear(stencil) {
  12371. if (currentStencilClear !== stencil) {
  12372. gl.clearStencil(stencil);
  12373. currentStencilClear = stencil;
  12374. }
  12375. },
  12376. reset: function reset() {
  12377. locked = false;
  12378. currentStencilMask = null;
  12379. currentStencilFunc = null;
  12380. currentStencilRef = null;
  12381. currentStencilFuncMask = null;
  12382. currentStencilFail = null;
  12383. currentStencilZFail = null;
  12384. currentStencilZPass = null;
  12385. currentStencilClear = null;
  12386. }
  12387. };
  12388. } //
  12389. var colorBuffer = new ColorBuffer();
  12390. var depthBuffer = new DepthBuffer();
  12391. var stencilBuffer = new StencilBuffer();
  12392. var enabledCapabilities = {};
  12393. var currentProgram = null;
  12394. var currentBlendingEnabled = null;
  12395. var currentBlending = null;
  12396. var currentBlendEquation = null;
  12397. var currentBlendSrc = null;
  12398. var currentBlendDst = null;
  12399. var currentBlendEquationAlpha = null;
  12400. var currentBlendSrcAlpha = null;
  12401. var currentBlendDstAlpha = null;
  12402. var currentPremultipledAlpha = false;
  12403. var currentFlipSided = null;
  12404. var currentCullFace = null;
  12405. var currentLineWidth = null;
  12406. var currentPolygonOffsetFactor = null;
  12407. var currentPolygonOffsetUnits = null;
  12408. var maxTextures = gl.getParameter(35661);
  12409. var lineWidthAvailable = false;
  12410. var version = 0;
  12411. var glVersion = gl.getParameter(7938);
  12412. if (glVersion.indexOf('WebGL') !== -1) {
  12413. version = parseFloat(/^WebGL (\d)/.exec(glVersion)[1]);
  12414. lineWidthAvailable = version >= 1.0;
  12415. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12416. version = parseFloat(/^OpenGL ES (\d)/.exec(glVersion)[1]);
  12417. lineWidthAvailable = version >= 2.0;
  12418. }
  12419. var currentTextureSlot = null;
  12420. var currentBoundTextures = {};
  12421. var currentScissor = new Vector4();
  12422. var currentViewport = new Vector4();
  12423. function createTexture(type, target, count) {
  12424. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12425. var texture = gl.createTexture();
  12426. gl.bindTexture(type, texture);
  12427. gl.texParameteri(type, 10241, 9728);
  12428. gl.texParameteri(type, 10240, 9728);
  12429. for (var i = 0; i < count; i++) {
  12430. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12431. }
  12432. return texture;
  12433. }
  12434. var emptyTextures = {};
  12435. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12436. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12437. colorBuffer.setClear(0, 0, 0, 1);
  12438. depthBuffer.setClear(1);
  12439. stencilBuffer.setClear(0);
  12440. enable(2929);
  12441. depthBuffer.setFunc(LessEqualDepth);
  12442. setFlipSided(false);
  12443. setCullFace(CullFaceBack);
  12444. enable(2884);
  12445. setBlending(NoBlending); //
  12446. function enable(id) {
  12447. if (enabledCapabilities[id] !== true) {
  12448. gl.enable(id);
  12449. enabledCapabilities[id] = true;
  12450. }
  12451. }
  12452. function disable(id) {
  12453. if (enabledCapabilities[id] !== false) {
  12454. gl.disable(id);
  12455. enabledCapabilities[id] = false;
  12456. }
  12457. }
  12458. function useProgram(program) {
  12459. if (currentProgram !== program) {
  12460. gl.useProgram(program);
  12461. currentProgram = program;
  12462. return true;
  12463. }
  12464. return false;
  12465. }
  12466. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12467. if (isWebGL2) {
  12468. equationToGL[MinEquation] = 32775;
  12469. equationToGL[MaxEquation] = 32776;
  12470. } else {
  12471. var extension = extensions.get('EXT_blend_minmax');
  12472. if (extension !== null) {
  12473. equationToGL[MinEquation] = extension.MIN_EXT;
  12474. equationToGL[MaxEquation] = extension.MAX_EXT;
  12475. }
  12476. }
  12477. 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);
  12478. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  12479. if (blending === NoBlending) {
  12480. if (currentBlendingEnabled) {
  12481. disable(3042);
  12482. currentBlendingEnabled = false;
  12483. }
  12484. return;
  12485. }
  12486. if (!currentBlendingEnabled) {
  12487. enable(3042);
  12488. currentBlendingEnabled = true;
  12489. }
  12490. if (blending !== CustomBlending) {
  12491. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  12492. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  12493. gl.blendEquation(32774);
  12494. currentBlendEquation = AddEquation;
  12495. currentBlendEquationAlpha = AddEquation;
  12496. }
  12497. if (premultipliedAlpha) {
  12498. switch (blending) {
  12499. case NormalBlending:
  12500. gl.blendFuncSeparate(1, 771, 1, 771);
  12501. break;
  12502. case AdditiveBlending:
  12503. gl.blendFunc(1, 1);
  12504. break;
  12505. case SubtractiveBlending:
  12506. gl.blendFuncSeparate(0, 0, 769, 771);
  12507. break;
  12508. case MultiplyBlending:
  12509. gl.blendFuncSeparate(0, 768, 0, 770);
  12510. break;
  12511. default:
  12512. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12513. break;
  12514. }
  12515. } else {
  12516. switch (blending) {
  12517. case NormalBlending:
  12518. gl.blendFuncSeparate(770, 771, 1, 771);
  12519. break;
  12520. case AdditiveBlending:
  12521. gl.blendFunc(770, 1);
  12522. break;
  12523. case SubtractiveBlending:
  12524. gl.blendFunc(0, 769);
  12525. break;
  12526. case MultiplyBlending:
  12527. gl.blendFunc(0, 768);
  12528. break;
  12529. default:
  12530. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12531. break;
  12532. }
  12533. }
  12534. currentBlendSrc = null;
  12535. currentBlendDst = null;
  12536. currentBlendSrcAlpha = null;
  12537. currentBlendDstAlpha = null;
  12538. currentBlending = blending;
  12539. currentPremultipledAlpha = premultipliedAlpha;
  12540. }
  12541. return;
  12542. } // custom blending
  12543. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12544. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12545. blendDstAlpha = blendDstAlpha || blendDst;
  12546. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  12547. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  12548. currentBlendEquation = blendEquation;
  12549. currentBlendEquationAlpha = blendEquationAlpha;
  12550. }
  12551. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  12552. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  12553. currentBlendSrc = blendSrc;
  12554. currentBlendDst = blendDst;
  12555. currentBlendSrcAlpha = blendSrcAlpha;
  12556. currentBlendDstAlpha = blendDstAlpha;
  12557. }
  12558. currentBlending = blending;
  12559. currentPremultipledAlpha = null;
  12560. }
  12561. function setMaterial(material, frontFaceCW) {
  12562. material.side === DoubleSide ? disable(2884) : enable(2884);
  12563. var flipSided = material.side === BackSide;
  12564. if (frontFaceCW) flipSided = !flipSided;
  12565. setFlipSided(flipSided);
  12566. 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);
  12567. depthBuffer.setFunc(material.depthFunc);
  12568. depthBuffer.setTest(material.depthTest);
  12569. depthBuffer.setMask(material.depthWrite);
  12570. colorBuffer.setMask(material.colorWrite);
  12571. var stencilWrite = material.stencilWrite;
  12572. stencilBuffer.setTest(stencilWrite);
  12573. if (stencilWrite) {
  12574. stencilBuffer.setMask(material.stencilWriteMask);
  12575. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  12576. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  12577. }
  12578. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  12579. } //
  12580. function setFlipSided(flipSided) {
  12581. if (currentFlipSided !== flipSided) {
  12582. if (flipSided) {
  12583. gl.frontFace(2304);
  12584. } else {
  12585. gl.frontFace(2305);
  12586. }
  12587. currentFlipSided = flipSided;
  12588. }
  12589. }
  12590. function setCullFace(cullFace) {
  12591. if (cullFace !== CullFaceNone) {
  12592. enable(2884);
  12593. if (cullFace !== currentCullFace) {
  12594. if (cullFace === CullFaceBack) {
  12595. gl.cullFace(1029);
  12596. } else if (cullFace === CullFaceFront) {
  12597. gl.cullFace(1028);
  12598. } else {
  12599. gl.cullFace(1032);
  12600. }
  12601. }
  12602. } else {
  12603. disable(2884);
  12604. }
  12605. currentCullFace = cullFace;
  12606. }
  12607. function setLineWidth(width) {
  12608. if (width !== currentLineWidth) {
  12609. if (lineWidthAvailable) gl.lineWidth(width);
  12610. currentLineWidth = width;
  12611. }
  12612. }
  12613. function setPolygonOffset(polygonOffset, factor, units) {
  12614. if (polygonOffset) {
  12615. enable(32823);
  12616. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  12617. gl.polygonOffset(factor, units);
  12618. currentPolygonOffsetFactor = factor;
  12619. currentPolygonOffsetUnits = units;
  12620. }
  12621. } else {
  12622. disable(32823);
  12623. }
  12624. }
  12625. function setScissorTest(scissorTest) {
  12626. if (scissorTest) {
  12627. enable(3089);
  12628. } else {
  12629. disable(3089);
  12630. }
  12631. } // texture
  12632. function activeTexture(webglSlot) {
  12633. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  12634. if (currentTextureSlot !== webglSlot) {
  12635. gl.activeTexture(webglSlot);
  12636. currentTextureSlot = webglSlot;
  12637. }
  12638. }
  12639. function bindTexture(webglType, webglTexture) {
  12640. if (currentTextureSlot === null) {
  12641. activeTexture();
  12642. }
  12643. var boundTexture = currentBoundTextures[currentTextureSlot];
  12644. if (boundTexture === undefined) {
  12645. boundTexture = {
  12646. type: undefined,
  12647. texture: undefined
  12648. };
  12649. currentBoundTextures[currentTextureSlot] = boundTexture;
  12650. }
  12651. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  12652. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  12653. boundTexture.type = webglType;
  12654. boundTexture.texture = webglTexture;
  12655. }
  12656. }
  12657. function unbindTexture() {
  12658. var boundTexture = currentBoundTextures[currentTextureSlot];
  12659. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  12660. gl.bindTexture(boundTexture.type, null);
  12661. boundTexture.type = undefined;
  12662. boundTexture.texture = undefined;
  12663. }
  12664. }
  12665. function compressedTexImage2D() {
  12666. try {
  12667. gl.compressedTexImage2D.apply(gl, arguments);
  12668. } catch (error) {
  12669. console.error('THREE.WebGLState:', error);
  12670. }
  12671. }
  12672. function texImage2D() {
  12673. try {
  12674. gl.texImage2D.apply(gl, arguments);
  12675. } catch (error) {
  12676. console.error('THREE.WebGLState:', error);
  12677. }
  12678. }
  12679. function texImage3D() {
  12680. try {
  12681. gl.texImage3D.apply(gl, arguments);
  12682. } catch (error) {
  12683. console.error('THREE.WebGLState:', error);
  12684. }
  12685. } //
  12686. function scissor(scissor) {
  12687. if (currentScissor.equals(scissor) === false) {
  12688. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  12689. currentScissor.copy(scissor);
  12690. }
  12691. }
  12692. function viewport(viewport) {
  12693. if (currentViewport.equals(viewport) === false) {
  12694. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  12695. currentViewport.copy(viewport);
  12696. }
  12697. } //
  12698. function reset() {
  12699. enabledCapabilities = {};
  12700. currentTextureSlot = null;
  12701. currentBoundTextures = {};
  12702. currentProgram = null;
  12703. currentBlendingEnabled = null;
  12704. currentBlending = null;
  12705. currentBlendEquation = null;
  12706. currentBlendSrc = null;
  12707. currentBlendDst = null;
  12708. currentBlendEquationAlpha = null;
  12709. currentBlendSrcAlpha = null;
  12710. currentBlendDstAlpha = null;
  12711. currentPremultipledAlpha = false;
  12712. currentFlipSided = null;
  12713. currentCullFace = null;
  12714. currentLineWidth = null;
  12715. currentPolygonOffsetFactor = null;
  12716. currentPolygonOffsetUnits = null;
  12717. colorBuffer.reset();
  12718. depthBuffer.reset();
  12719. stencilBuffer.reset();
  12720. }
  12721. return {
  12722. buffers: {
  12723. color: colorBuffer,
  12724. depth: depthBuffer,
  12725. stencil: stencilBuffer
  12726. },
  12727. enable: enable,
  12728. disable: disable,
  12729. useProgram: useProgram,
  12730. setBlending: setBlending,
  12731. setMaterial: setMaterial,
  12732. setFlipSided: setFlipSided,
  12733. setCullFace: setCullFace,
  12734. setLineWidth: setLineWidth,
  12735. setPolygonOffset: setPolygonOffset,
  12736. setScissorTest: setScissorTest,
  12737. activeTexture: activeTexture,
  12738. bindTexture: bindTexture,
  12739. unbindTexture: unbindTexture,
  12740. compressedTexImage2D: compressedTexImage2D,
  12741. texImage2D: texImage2D,
  12742. texImage3D: texImage3D,
  12743. scissor: scissor,
  12744. viewport: viewport,
  12745. reset: reset
  12746. };
  12747. }
  12748. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  12749. var _wrappingToGL, _filterToGL;
  12750. var isWebGL2 = capabilities.isWebGL2;
  12751. var maxTextures = capabilities.maxTextures;
  12752. var maxCubemapSize = capabilities.maxCubemapSize;
  12753. var maxTextureSize = capabilities.maxTextureSize;
  12754. var maxSamples = capabilities.maxSamples;
  12755. var _videoTextures = new WeakMap();
  12756. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  12757. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  12758. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  12759. var useOffscreenCanvas = false;
  12760. try {
  12761. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext('2d') !== null;
  12762. } catch (err) {// Ignore any errors
  12763. }
  12764. function createCanvas(width, height) {
  12765. // Use OffscreenCanvas when available. Specially needed in web workers
  12766. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  12767. }
  12768. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  12769. var scale = 1; // handle case if texture exceeds max size
  12770. if (image.width > maxSize || image.height > maxSize) {
  12771. scale = maxSize / Math.max(image.width, image.height);
  12772. } // only perform resize if necessary
  12773. if (scale < 1 || needsPowerOfTwo === true) {
  12774. // only perform resize for certain image types
  12775. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  12776. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  12777. var width = floor(scale * image.width);
  12778. var height = floor(scale * image.height);
  12779. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  12780. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  12781. canvas.width = width;
  12782. canvas.height = height;
  12783. var context = canvas.getContext('2d');
  12784. context.drawImage(image, 0, 0, width, height);
  12785. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  12786. return canvas;
  12787. } else {
  12788. if ('data' in image) {
  12789. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  12790. }
  12791. return image;
  12792. }
  12793. }
  12794. return image;
  12795. }
  12796. function isPowerOfTwo(image) {
  12797. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  12798. }
  12799. function textureNeedsPowerOfTwo(texture) {
  12800. if (isWebGL2) return false;
  12801. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12802. }
  12803. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  12804. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12805. }
  12806. function generateMipmap(target, texture, width, height) {
  12807. _gl.generateMipmap(target);
  12808. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12809. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  12810. }
  12811. function getInternalFormat(internalFormatName, glFormat, glType) {
  12812. if (isWebGL2 === false) return glFormat;
  12813. if (internalFormatName !== null) {
  12814. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  12815. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  12816. }
  12817. var internalFormat = glFormat;
  12818. if (glFormat === 6403) {
  12819. if (glType === 5126) internalFormat = 33326;
  12820. if (glType === 5131) internalFormat = 33325;
  12821. if (glType === 5121) internalFormat = 33321;
  12822. }
  12823. if (glFormat === 6407) {
  12824. if (glType === 5126) internalFormat = 34837;
  12825. if (glType === 5131) internalFormat = 34843;
  12826. if (glType === 5121) internalFormat = 32849;
  12827. }
  12828. if (glFormat === 6408) {
  12829. if (glType === 5126) internalFormat = 34836;
  12830. if (glType === 5131) internalFormat = 34842;
  12831. if (glType === 5121) internalFormat = 32856;
  12832. }
  12833. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  12834. extensions.get('EXT_color_buffer_float');
  12835. }
  12836. return internalFormat;
  12837. } // Fallback filters for non-power-of-2 textures
  12838. function filterFallback(f) {
  12839. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  12840. return 9728;
  12841. }
  12842. return 9729;
  12843. } //
  12844. function onTextureDispose(event) {
  12845. var texture = event.target;
  12846. texture.removeEventListener('dispose', onTextureDispose);
  12847. deallocateTexture(texture);
  12848. if (texture.isVideoTexture) {
  12849. _videoTextures.delete(texture);
  12850. }
  12851. info.memory.textures--;
  12852. }
  12853. function onRenderTargetDispose(event) {
  12854. var renderTarget = event.target;
  12855. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  12856. deallocateRenderTarget(renderTarget);
  12857. info.memory.textures--;
  12858. } //
  12859. function deallocateTexture(texture) {
  12860. var textureProperties = properties.get(texture);
  12861. if (textureProperties.__webglInit === undefined) return;
  12862. _gl.deleteTexture(textureProperties.__webglTexture);
  12863. properties.remove(texture);
  12864. }
  12865. function deallocateRenderTarget(renderTarget) {
  12866. var renderTargetProperties = properties.get(renderTarget);
  12867. var textureProperties = properties.get(renderTarget.texture);
  12868. if (!renderTarget) return;
  12869. if (textureProperties.__webglTexture !== undefined) {
  12870. _gl.deleteTexture(textureProperties.__webglTexture);
  12871. }
  12872. if (renderTarget.depthTexture) {
  12873. renderTarget.depthTexture.dispose();
  12874. }
  12875. if (renderTarget.isWebGLCubeRenderTarget) {
  12876. for (var i = 0; i < 6; i++) {
  12877. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  12878. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  12879. }
  12880. } else {
  12881. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  12882. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  12883. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  12884. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  12885. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  12886. }
  12887. properties.remove(renderTarget.texture);
  12888. properties.remove(renderTarget);
  12889. } //
  12890. var textureUnits = 0;
  12891. function resetTextureUnits() {
  12892. textureUnits = 0;
  12893. }
  12894. function allocateTextureUnit() {
  12895. var textureUnit = textureUnits;
  12896. if (textureUnit >= maxTextures) {
  12897. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  12898. }
  12899. textureUnits += 1;
  12900. return textureUnit;
  12901. } //
  12902. function setTexture2D(texture, slot) {
  12903. var textureProperties = properties.get(texture);
  12904. if (texture.isVideoTexture) updateVideoTexture(texture);
  12905. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12906. var image = texture.image;
  12907. if (image === undefined) {
  12908. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  12909. } else if (image.complete === false) {
  12910. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  12911. } else {
  12912. uploadTexture(textureProperties, texture, slot);
  12913. return;
  12914. }
  12915. }
  12916. state.activeTexture(33984 + slot);
  12917. state.bindTexture(3553, textureProperties.__webglTexture);
  12918. }
  12919. function setTexture2DArray(texture, slot) {
  12920. var textureProperties = properties.get(texture);
  12921. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12922. uploadTexture(textureProperties, texture, slot);
  12923. return;
  12924. }
  12925. state.activeTexture(33984 + slot);
  12926. state.bindTexture(35866, textureProperties.__webglTexture);
  12927. }
  12928. function setTexture3D(texture, slot) {
  12929. var textureProperties = properties.get(texture);
  12930. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12931. uploadTexture(textureProperties, texture, slot);
  12932. return;
  12933. }
  12934. state.activeTexture(33984 + slot);
  12935. state.bindTexture(32879, textureProperties.__webglTexture);
  12936. }
  12937. function setTextureCube(texture, slot) {
  12938. var textureProperties = properties.get(texture);
  12939. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12940. uploadCubeTexture(textureProperties, texture, slot);
  12941. return;
  12942. }
  12943. state.activeTexture(33984 + slot);
  12944. state.bindTexture(34067, textureProperties.__webglTexture);
  12945. }
  12946. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  12947. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  12948. function setTextureParameters(textureType, texture, supportsMips) {
  12949. if (supportsMips) {
  12950. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  12951. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  12952. if (textureType === 32879 || textureType === 35866) {
  12953. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  12954. }
  12955. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  12956. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  12957. } else {
  12958. _gl.texParameteri(textureType, 10242, 33071);
  12959. _gl.texParameteri(textureType, 10243, 33071);
  12960. if (textureType === 32879 || textureType === 35866) {
  12961. _gl.texParameteri(textureType, 32882, 33071);
  12962. }
  12963. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  12964. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  12965. }
  12966. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  12967. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  12968. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  12969. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  12970. }
  12971. }
  12972. var extension = extensions.get('EXT_texture_filter_anisotropic');
  12973. if (extension) {
  12974. if (texture.type === FloatType && extensions.get('OES_texture_float_linear') === null) return;
  12975. if (texture.type === HalfFloatType && (isWebGL2 || extensions.get('OES_texture_half_float_linear')) === null) return;
  12976. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  12977. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  12978. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  12979. }
  12980. }
  12981. }
  12982. function initTexture(textureProperties, texture) {
  12983. if (textureProperties.__webglInit === undefined) {
  12984. textureProperties.__webglInit = true;
  12985. texture.addEventListener('dispose', onTextureDispose);
  12986. textureProperties.__webglTexture = _gl.createTexture();
  12987. info.memory.textures++;
  12988. }
  12989. }
  12990. function uploadTexture(textureProperties, texture, slot) {
  12991. var textureType = 3553;
  12992. if (texture.isDataTexture2DArray) textureType = 35866;
  12993. if (texture.isDataTexture3D) textureType = 32879;
  12994. initTexture(textureProperties, texture);
  12995. state.activeTexture(33984 + slot);
  12996. state.bindTexture(textureType, textureProperties.__webglTexture);
  12997. _gl.pixelStorei(37440, texture.flipY);
  12998. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  12999. _gl.pixelStorei(3317, texture.unpackAlignment);
  13000. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  13001. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  13002. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  13003. glFormat = utils.convert(texture.format);
  13004. var glType = utils.convert(texture.type),
  13005. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13006. setTextureParameters(textureType, texture, supportsMips);
  13007. var mipmap;
  13008. var mipmaps = texture.mipmaps;
  13009. if (texture.isDepthTexture) {
  13010. // populate depth texture with dummy data
  13011. glInternalFormat = 6402;
  13012. if (isWebGL2) {
  13013. if (texture.type === FloatType) {
  13014. glInternalFormat = 36012;
  13015. } else if (texture.type === UnsignedIntType) {
  13016. glInternalFormat = 33190;
  13017. } else if (texture.type === UnsignedInt248Type) {
  13018. glInternalFormat = 35056;
  13019. } else {
  13020. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  13021. }
  13022. } else {
  13023. if (texture.type === FloatType) {
  13024. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  13025. }
  13026. } // validation checks for WebGL 1
  13027. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  13028. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13029. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13030. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13031. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  13032. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  13033. texture.type = UnsignedShortType;
  13034. glType = utils.convert(texture.type);
  13035. }
  13036. }
  13037. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  13038. // Depth stencil textures need the DEPTH_STENCIL internal format
  13039. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13040. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13041. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13042. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13043. if (texture.type !== UnsignedInt248Type) {
  13044. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  13045. texture.type = UnsignedInt248Type;
  13046. glType = utils.convert(texture.type);
  13047. }
  13048. } //
  13049. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  13050. } else if (texture.isDataTexture) {
  13051. // use manually created mipmaps if available
  13052. // if there are no manual mipmaps
  13053. // set 0 level mipmap and then use GL to generate other mipmap levels
  13054. if (mipmaps.length > 0 && supportsMips) {
  13055. for (var i = 0, il = mipmaps.length; i < il; i++) {
  13056. mipmap = mipmaps[i];
  13057. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13058. }
  13059. texture.generateMipmaps = false;
  13060. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13061. } else {
  13062. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  13063. textureProperties.__maxMipLevel = 0;
  13064. }
  13065. } else if (texture.isCompressedTexture) {
  13066. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  13067. mipmap = mipmaps[_i];
  13068. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13069. if (glFormat !== null) {
  13070. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13071. } else {
  13072. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  13073. }
  13074. } else {
  13075. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13076. }
  13077. }
  13078. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13079. } else if (texture.isDataTexture2DArray) {
  13080. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13081. textureProperties.__maxMipLevel = 0;
  13082. } else if (texture.isDataTexture3D) {
  13083. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13084. textureProperties.__maxMipLevel = 0;
  13085. } else {
  13086. // regular Texture (image, video, canvas)
  13087. // use manually created mipmaps if available
  13088. // if there are no manual mipmaps
  13089. // set 0 level mipmap and then use GL to generate other mipmap levels
  13090. if (mipmaps.length > 0 && supportsMips) {
  13091. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  13092. mipmap = mipmaps[_i2];
  13093. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  13094. }
  13095. texture.generateMipmaps = false;
  13096. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13097. } else {
  13098. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  13099. textureProperties.__maxMipLevel = 0;
  13100. }
  13101. }
  13102. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13103. generateMipmap(textureType, texture, image.width, image.height);
  13104. }
  13105. textureProperties.__version = texture.version;
  13106. if (texture.onUpdate) texture.onUpdate(texture);
  13107. }
  13108. function uploadCubeTexture(textureProperties, texture, slot) {
  13109. if (texture.image.length !== 6) return;
  13110. initTexture(textureProperties, texture);
  13111. state.activeTexture(33984 + slot);
  13112. state.bindTexture(34067, textureProperties.__webglTexture);
  13113. _gl.pixelStorei(37440, texture.flipY);
  13114. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  13115. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  13116. var cubeImage = [];
  13117. for (var i = 0; i < 6; i++) {
  13118. if (!isCompressed && !isDataTexture) {
  13119. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  13120. } else {
  13121. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  13122. }
  13123. }
  13124. var image = cubeImage[0],
  13125. supportsMips = isPowerOfTwo(image) || isWebGL2,
  13126. glFormat = utils.convert(texture.format),
  13127. glType = utils.convert(texture.type),
  13128. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13129. setTextureParameters(34067, texture, supportsMips);
  13130. var mipmaps;
  13131. if (isCompressed) {
  13132. for (var _i3 = 0; _i3 < 6; _i3++) {
  13133. mipmaps = cubeImage[_i3].mipmaps;
  13134. for (var j = 0; j < mipmaps.length; j++) {
  13135. var mipmap = mipmaps[j];
  13136. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13137. if (glFormat !== null) {
  13138. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13139. } else {
  13140. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  13141. }
  13142. } else {
  13143. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13144. }
  13145. }
  13146. }
  13147. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13148. } else {
  13149. mipmaps = texture.mipmaps;
  13150. for (var _i4 = 0; _i4 < 6; _i4++) {
  13151. if (isDataTexture) {
  13152. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  13153. for (var _j = 0; _j < mipmaps.length; _j++) {
  13154. var _mipmap = mipmaps[_j];
  13155. var mipmapImage = _mipmap.image[_i4].image;
  13156. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  13157. }
  13158. } else {
  13159. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  13160. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  13161. var _mipmap2 = mipmaps[_j2];
  13162. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  13163. }
  13164. }
  13165. }
  13166. textureProperties.__maxMipLevel = mipmaps.length;
  13167. }
  13168. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13169. // We assume images for cube map have the same size.
  13170. generateMipmap(34067, texture, image.width, image.height);
  13171. }
  13172. textureProperties.__version = texture.version;
  13173. if (texture.onUpdate) texture.onUpdate(texture);
  13174. } // Render targets
  13175. // Setup storage for target texture and bind it to correct framebuffer
  13176. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  13177. var glFormat = utils.convert(renderTarget.texture.format);
  13178. var glType = utils.convert(renderTarget.texture.type);
  13179. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13180. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  13181. _gl.bindFramebuffer(36160, framebuffer);
  13182. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(renderTarget.texture).__webglTexture, 0);
  13183. _gl.bindFramebuffer(36160, null);
  13184. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13185. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  13186. _gl.bindRenderbuffer(36161, renderbuffer);
  13187. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  13188. var glInternalFormat = 33189;
  13189. if (isMultisample) {
  13190. var depthTexture = renderTarget.depthTexture;
  13191. if (depthTexture && depthTexture.isDepthTexture) {
  13192. if (depthTexture.type === FloatType) {
  13193. glInternalFormat = 36012;
  13194. } else if (depthTexture.type === UnsignedIntType) {
  13195. glInternalFormat = 33190;
  13196. }
  13197. }
  13198. var samples = getRenderTargetSamples(renderTarget);
  13199. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13200. } else {
  13201. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  13202. }
  13203. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  13204. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  13205. if (isMultisample) {
  13206. var _samples = getRenderTargetSamples(renderTarget);
  13207. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  13208. } else {
  13209. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  13210. }
  13211. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  13212. } else {
  13213. var glFormat = utils.convert(renderTarget.texture.format);
  13214. var glType = utils.convert(renderTarget.texture.type);
  13215. var _glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13216. if (isMultisample) {
  13217. var _samples2 = getRenderTargetSamples(renderTarget);
  13218. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  13219. } else {
  13220. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  13221. }
  13222. }
  13223. _gl.bindRenderbuffer(36161, null);
  13224. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  13225. function setupDepthTexture(framebuffer, renderTarget) {
  13226. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  13227. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  13228. _gl.bindFramebuffer(36160, framebuffer);
  13229. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  13230. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  13231. } // upload an empty depth texture with framebuffer size
  13232. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  13233. renderTarget.depthTexture.image.width = renderTarget.width;
  13234. renderTarget.depthTexture.image.height = renderTarget.height;
  13235. renderTarget.depthTexture.needsUpdate = true;
  13236. }
  13237. setTexture2D(renderTarget.depthTexture, 0);
  13238. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13239. if (renderTarget.depthTexture.format === DepthFormat) {
  13240. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13241. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13242. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13243. } else {
  13244. throw new Error('Unknown depthTexture format');
  13245. }
  13246. } // Setup GL resources for a non-texture depth buffer
  13247. function setupDepthRenderbuffer(renderTarget) {
  13248. var renderTargetProperties = properties.get(renderTarget);
  13249. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13250. if (renderTarget.depthTexture) {
  13251. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13252. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13253. } else {
  13254. if (isCube) {
  13255. renderTargetProperties.__webglDepthbuffer = [];
  13256. for (var i = 0; i < 6; i++) {
  13257. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13258. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13259. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13260. }
  13261. } else {
  13262. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13263. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13264. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13265. }
  13266. }
  13267. _gl.bindFramebuffer(36160, null);
  13268. } // Set up GL resources for the render target
  13269. function setupRenderTarget(renderTarget) {
  13270. var renderTargetProperties = properties.get(renderTarget);
  13271. var textureProperties = properties.get(renderTarget.texture);
  13272. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13273. textureProperties.__webglTexture = _gl.createTexture();
  13274. info.memory.textures++;
  13275. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13276. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13277. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13278. if (isWebGL2 && renderTarget.texture.format === RGBFormat && (renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType)) {
  13279. renderTarget.texture.format = RGBAFormat;
  13280. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13281. } // Setup framebuffer
  13282. if (isCube) {
  13283. renderTargetProperties.__webglFramebuffer = [];
  13284. for (var i = 0; i < 6; i++) {
  13285. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13286. }
  13287. } else {
  13288. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13289. if (isMultisample) {
  13290. if (isWebGL2) {
  13291. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13292. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13293. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13294. var glFormat = utils.convert(renderTarget.texture.format);
  13295. var glType = utils.convert(renderTarget.texture.type);
  13296. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13297. var samples = getRenderTargetSamples(renderTarget);
  13298. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13299. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13300. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13301. _gl.bindRenderbuffer(36161, null);
  13302. if (renderTarget.depthBuffer) {
  13303. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13304. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13305. }
  13306. _gl.bindFramebuffer(36160, null);
  13307. } else {
  13308. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13309. }
  13310. }
  13311. } // Setup color buffer
  13312. if (isCube) {
  13313. state.bindTexture(34067, textureProperties.__webglTexture);
  13314. setTextureParameters(34067, renderTarget.texture, supportsMips);
  13315. for (var _i5 = 0; _i5 < 6; _i5++) {
  13316. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13317. }
  13318. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13319. generateMipmap(34067, renderTarget.texture, renderTarget.width, renderTarget.height);
  13320. }
  13321. state.bindTexture(34067, null);
  13322. } else {
  13323. state.bindTexture(3553, textureProperties.__webglTexture);
  13324. setTextureParameters(3553, renderTarget.texture, supportsMips);
  13325. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553);
  13326. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13327. generateMipmap(3553, renderTarget.texture, renderTarget.width, renderTarget.height);
  13328. }
  13329. state.bindTexture(3553, null);
  13330. } // Setup depth and stencil buffers
  13331. if (renderTarget.depthBuffer) {
  13332. setupDepthRenderbuffer(renderTarget);
  13333. }
  13334. }
  13335. function updateRenderTargetMipmap(renderTarget) {
  13336. var texture = renderTarget.texture;
  13337. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13338. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13339. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13340. var webglTexture = properties.get(texture).__webglTexture;
  13341. state.bindTexture(target, webglTexture);
  13342. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13343. state.bindTexture(target, null);
  13344. }
  13345. }
  13346. function updateMultisampleRenderTarget(renderTarget) {
  13347. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13348. if (isWebGL2) {
  13349. var renderTargetProperties = properties.get(renderTarget);
  13350. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13351. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13352. var width = renderTarget.width;
  13353. var height = renderTarget.height;
  13354. var mask = 16384;
  13355. if (renderTarget.depthBuffer) mask |= 256;
  13356. if (renderTarget.stencilBuffer) mask |= 1024;
  13357. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13358. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13359. } else {
  13360. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13361. }
  13362. }
  13363. }
  13364. function getRenderTargetSamples(renderTarget) {
  13365. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13366. }
  13367. function updateVideoTexture(texture) {
  13368. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13369. if (_videoTextures.get(texture) !== frame) {
  13370. _videoTextures.set(texture, frame);
  13371. texture.update();
  13372. }
  13373. } // backwards compatibility
  13374. var warnedTexture2D = false;
  13375. var warnedTextureCube = false;
  13376. function safeSetTexture2D(texture, slot) {
  13377. if (texture && texture.isWebGLRenderTarget) {
  13378. if (warnedTexture2D === false) {
  13379. console.warn('THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.');
  13380. warnedTexture2D = true;
  13381. }
  13382. texture = texture.texture;
  13383. }
  13384. setTexture2D(texture, slot);
  13385. }
  13386. function safeSetTextureCube(texture, slot) {
  13387. if (texture && texture.isWebGLCubeRenderTarget) {
  13388. if (warnedTextureCube === false) {
  13389. console.warn('THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.');
  13390. warnedTextureCube = true;
  13391. }
  13392. texture = texture.texture;
  13393. }
  13394. setTextureCube(texture, slot);
  13395. } //
  13396. this.allocateTextureUnit = allocateTextureUnit;
  13397. this.resetTextureUnits = resetTextureUnits;
  13398. this.setTexture2D = setTexture2D;
  13399. this.setTexture2DArray = setTexture2DArray;
  13400. this.setTexture3D = setTexture3D;
  13401. this.setTextureCube = setTextureCube;
  13402. this.setupRenderTarget = setupRenderTarget;
  13403. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13404. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13405. this.safeSetTexture2D = safeSetTexture2D;
  13406. this.safeSetTextureCube = safeSetTextureCube;
  13407. }
  13408. function WebGLUtils(gl, extensions, capabilities) {
  13409. var isWebGL2 = capabilities.isWebGL2;
  13410. function convert(p) {
  13411. var extension;
  13412. if (p === UnsignedByteType) return 5121;
  13413. if (p === UnsignedShort4444Type) return 32819;
  13414. if (p === UnsignedShort5551Type) return 32820;
  13415. if (p === UnsignedShort565Type) return 33635;
  13416. if (p === ByteType) return 5120;
  13417. if (p === ShortType) return 5122;
  13418. if (p === UnsignedShortType) return 5123;
  13419. if (p === IntType) return 5124;
  13420. if (p === UnsignedIntType) return 5125;
  13421. if (p === FloatType) return 5126;
  13422. if (p === HalfFloatType) {
  13423. if (isWebGL2) return 5131;
  13424. extension = extensions.get('OES_texture_half_float');
  13425. if (extension !== null) {
  13426. return extension.HALF_FLOAT_OES;
  13427. } else {
  13428. return null;
  13429. }
  13430. }
  13431. if (p === AlphaFormat) return 6406;
  13432. if (p === RGBFormat) return 6407;
  13433. if (p === RGBAFormat) return 6408;
  13434. if (p === LuminanceFormat) return 6409;
  13435. if (p === LuminanceAlphaFormat) return 6410;
  13436. if (p === DepthFormat) return 6402;
  13437. if (p === DepthStencilFormat) return 34041;
  13438. if (p === RedFormat) return 6403; // WebGL2 formats.
  13439. if (p === RedIntegerFormat) return 36244;
  13440. if (p === RGFormat) return 33319;
  13441. if (p === RGIntegerFormat) return 33320;
  13442. if (p === RGBIntegerFormat) return 36248;
  13443. if (p === RGBAIntegerFormat) return 36249;
  13444. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13445. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13446. if (extension !== null) {
  13447. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13448. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13449. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13450. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13451. } else {
  13452. return null;
  13453. }
  13454. }
  13455. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13456. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13457. if (extension !== null) {
  13458. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13459. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13460. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13461. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13462. } else {
  13463. return null;
  13464. }
  13465. }
  13466. if (p === RGB_ETC1_Format) {
  13467. extension = extensions.get('WEBGL_compressed_texture_etc1');
  13468. if (extension !== null) {
  13469. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13470. } else {
  13471. return null;
  13472. }
  13473. }
  13474. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  13475. extension = extensions.get('WEBGL_compressed_texture_etc');
  13476. if (extension !== null) {
  13477. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  13478. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13479. }
  13480. }
  13481. 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) {
  13482. extension = extensions.get('WEBGL_compressed_texture_astc');
  13483. if (extension !== null) {
  13484. // TODO Complete?
  13485. return p;
  13486. } else {
  13487. return null;
  13488. }
  13489. }
  13490. if (p === RGBA_BPTC_Format) {
  13491. extension = extensions.get('EXT_texture_compression_bptc');
  13492. if (extension !== null) {
  13493. // TODO Complete?
  13494. return p;
  13495. } else {
  13496. return null;
  13497. }
  13498. }
  13499. if (p === UnsignedInt248Type) {
  13500. if (isWebGL2) return 34042;
  13501. extension = extensions.get('WEBGL_depth_texture');
  13502. if (extension !== null) {
  13503. return extension.UNSIGNED_INT_24_8_WEBGL;
  13504. } else {
  13505. return null;
  13506. }
  13507. }
  13508. }
  13509. return {
  13510. convert: convert
  13511. };
  13512. }
  13513. function ArrayCamera(array) {
  13514. if (array === void 0) {
  13515. array = [];
  13516. }
  13517. PerspectiveCamera.call(this);
  13518. this.cameras = array;
  13519. }
  13520. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  13521. constructor: ArrayCamera,
  13522. isArrayCamera: true
  13523. });
  13524. function Group() {
  13525. Object3D.call(this);
  13526. this.type = 'Group';
  13527. }
  13528. Group.prototype = Object.assign(Object.create(Object3D.prototype), {
  13529. constructor: Group,
  13530. isGroup: true
  13531. });
  13532. function WebXRController() {
  13533. this._targetRay = null;
  13534. this._grip = null;
  13535. this._hand = null;
  13536. }
  13537. Object.assign(WebXRController.prototype, {
  13538. constructor: WebXRController,
  13539. getHandSpace: function getHandSpace() {
  13540. if (this._hand === null) {
  13541. this._hand = new Group();
  13542. this._hand.matrixAutoUpdate = false;
  13543. this._hand.visible = false;
  13544. this._hand.joints = [];
  13545. this._hand.inputState = {
  13546. pinching: false
  13547. };
  13548. if (window.XRHand) {
  13549. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13550. // The transform of this joint will be updated with the joint pose on each frame
  13551. var joint = new Group();
  13552. joint.matrixAutoUpdate = false;
  13553. joint.visible = false;
  13554. this._hand.joints.push(joint); // ??
  13555. this._hand.add(joint);
  13556. }
  13557. }
  13558. }
  13559. return this._hand;
  13560. },
  13561. getTargetRaySpace: function getTargetRaySpace() {
  13562. if (this._targetRay === null) {
  13563. this._targetRay = new Group();
  13564. this._targetRay.matrixAutoUpdate = false;
  13565. this._targetRay.visible = false;
  13566. }
  13567. return this._targetRay;
  13568. },
  13569. getGripSpace: function getGripSpace() {
  13570. if (this._grip === null) {
  13571. this._grip = new Group();
  13572. this._grip.matrixAutoUpdate = false;
  13573. this._grip.visible = false;
  13574. }
  13575. return this._grip;
  13576. },
  13577. dispatchEvent: function dispatchEvent(event) {
  13578. if (this._targetRay !== null) {
  13579. this._targetRay.dispatchEvent(event);
  13580. }
  13581. if (this._grip !== null) {
  13582. this._grip.dispatchEvent(event);
  13583. }
  13584. if (this._hand !== null) {
  13585. this._hand.dispatchEvent(event);
  13586. }
  13587. return this;
  13588. },
  13589. disconnect: function disconnect(inputSource) {
  13590. this.dispatchEvent({
  13591. type: 'disconnected',
  13592. data: inputSource
  13593. });
  13594. if (this._targetRay !== null) {
  13595. this._targetRay.visible = false;
  13596. }
  13597. if (this._grip !== null) {
  13598. this._grip.visible = false;
  13599. }
  13600. if (this._hand !== null) {
  13601. this._hand.visible = false;
  13602. }
  13603. return this;
  13604. },
  13605. update: function update(inputSource, frame, referenceSpace) {
  13606. var inputPose = null;
  13607. var gripPose = null;
  13608. var handPose = null;
  13609. var targetRay = this._targetRay;
  13610. var grip = this._grip;
  13611. var hand = this._hand;
  13612. if (inputSource && frame.session.visibilityState !== 'visible-blurred') {
  13613. if (hand && inputSource.hand) {
  13614. handPose = true;
  13615. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13616. if (inputSource.hand[i]) {
  13617. // Update the joints groups with the XRJoint poses
  13618. var jointPose = frame.getJointPose(inputSource.hand[i], referenceSpace);
  13619. var joint = hand.joints[i];
  13620. if (jointPose !== null) {
  13621. joint.matrix.fromArray(jointPose.transform.matrix);
  13622. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  13623. joint.jointRadius = jointPose.radius;
  13624. }
  13625. joint.visible = jointPose !== null; // Custom events
  13626. // Check pinch
  13627. var indexTip = hand.joints[window.XRHand.INDEX_PHALANX_TIP];
  13628. var thumbTip = hand.joints[window.XRHand.THUMB_PHALANX_TIP];
  13629. var distance = indexTip.position.distanceTo(thumbTip.position);
  13630. var distanceToPinch = 0.02;
  13631. var threshold = 0.005;
  13632. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  13633. hand.inputState.pinching = false;
  13634. this.dispatchEvent({
  13635. type: 'pinchend',
  13636. handedness: inputSource.handedness,
  13637. target: this
  13638. });
  13639. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  13640. hand.inputState.pinching = true;
  13641. this.dispatchEvent({
  13642. type: 'pinchstart',
  13643. handedness: inputSource.handedness,
  13644. target: this
  13645. });
  13646. }
  13647. }
  13648. }
  13649. } else {
  13650. if (targetRay !== null) {
  13651. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  13652. if (inputPose !== null) {
  13653. targetRay.matrix.fromArray(inputPose.transform.matrix);
  13654. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  13655. }
  13656. }
  13657. if (grip !== null && inputSource.gripSpace) {
  13658. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  13659. if (gripPose !== null) {
  13660. grip.matrix.fromArray(gripPose.transform.matrix);
  13661. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  13662. }
  13663. }
  13664. }
  13665. }
  13666. if (targetRay !== null) {
  13667. targetRay.visible = inputPose !== null;
  13668. }
  13669. if (grip !== null) {
  13670. grip.visible = gripPose !== null;
  13671. }
  13672. if (hand !== null) {
  13673. hand.visible = handPose !== null;
  13674. }
  13675. return this;
  13676. }
  13677. });
  13678. function WebXRManager(renderer, gl) {
  13679. var scope = this;
  13680. var session = null;
  13681. var framebufferScaleFactor = 1.0;
  13682. var referenceSpace = null;
  13683. var referenceSpaceType = 'local-floor';
  13684. var pose = null;
  13685. var controllers = [];
  13686. var inputSourcesMap = new Map(); //
  13687. var cameraL = new PerspectiveCamera();
  13688. cameraL.layers.enable(1);
  13689. cameraL.viewport = new Vector4();
  13690. var cameraR = new PerspectiveCamera();
  13691. cameraR.layers.enable(2);
  13692. cameraR.viewport = new Vector4();
  13693. var cameras = [cameraL, cameraR];
  13694. var cameraVR = new ArrayCamera();
  13695. cameraVR.layers.enable(1);
  13696. cameraVR.layers.enable(2);
  13697. var _currentDepthNear = null;
  13698. var _currentDepthFar = null; //
  13699. this.enabled = false;
  13700. this.isPresenting = false;
  13701. this.getController = function (index) {
  13702. var controller = controllers[index];
  13703. if (controller === undefined) {
  13704. controller = new WebXRController();
  13705. controllers[index] = controller;
  13706. }
  13707. return controller.getTargetRaySpace();
  13708. };
  13709. this.getControllerGrip = function (index) {
  13710. var controller = controllers[index];
  13711. if (controller === undefined) {
  13712. controller = new WebXRController();
  13713. controllers[index] = controller;
  13714. }
  13715. return controller.getGripSpace();
  13716. };
  13717. this.getHand = function (index) {
  13718. var controller = controllers[index];
  13719. if (controller === undefined) {
  13720. controller = new WebXRController();
  13721. controllers[index] = controller;
  13722. }
  13723. return controller.getHandSpace();
  13724. }; //
  13725. function onSessionEvent(event) {
  13726. var controller = inputSourcesMap.get(event.inputSource);
  13727. if (controller) {
  13728. controller.dispatchEvent({
  13729. type: event.type,
  13730. data: event.inputSource
  13731. });
  13732. }
  13733. }
  13734. function onSessionEnd() {
  13735. inputSourcesMap.forEach(function (controller, inputSource) {
  13736. controller.disconnect(inputSource);
  13737. });
  13738. inputSourcesMap.clear(); //
  13739. renderer.setFramebuffer(null);
  13740. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  13741. animation.stop();
  13742. scope.isPresenting = false;
  13743. scope.dispatchEvent({
  13744. type: 'sessionend'
  13745. });
  13746. }
  13747. function onRequestReferenceSpace(value) {
  13748. referenceSpace = value;
  13749. animation.setContext(session);
  13750. animation.start();
  13751. scope.isPresenting = true;
  13752. scope.dispatchEvent({
  13753. type: 'sessionstart'
  13754. });
  13755. }
  13756. this.setFramebufferScaleFactor = function (value) {
  13757. framebufferScaleFactor = value;
  13758. if (scope.isPresenting === true) {
  13759. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  13760. }
  13761. };
  13762. this.setReferenceSpaceType = function (value) {
  13763. referenceSpaceType = value;
  13764. if (scope.isPresenting === true) {
  13765. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  13766. }
  13767. };
  13768. this.getReferenceSpace = function () {
  13769. return referenceSpace;
  13770. };
  13771. this.getSession = function () {
  13772. return session;
  13773. };
  13774. this.setSession = function (value) {
  13775. session = value;
  13776. if (session !== null) {
  13777. session.addEventListener('select', onSessionEvent);
  13778. session.addEventListener('selectstart', onSessionEvent);
  13779. session.addEventListener('selectend', onSessionEvent);
  13780. session.addEventListener('squeeze', onSessionEvent);
  13781. session.addEventListener('squeezestart', onSessionEvent);
  13782. session.addEventListener('squeezeend', onSessionEvent);
  13783. session.addEventListener('end', onSessionEnd);
  13784. var attributes = gl.getContextAttributes();
  13785. if (attributes.xrCompatible !== true) {
  13786. gl.makeXRCompatible();
  13787. }
  13788. var layerInit = {
  13789. antialias: attributes.antialias,
  13790. alpha: attributes.alpha,
  13791. depth: attributes.depth,
  13792. stencil: attributes.stencil,
  13793. framebufferScaleFactor: framebufferScaleFactor
  13794. }; // eslint-disable-next-line no-undef
  13795. var baseLayer = new XRWebGLLayer(session, gl, layerInit);
  13796. session.updateRenderState({
  13797. baseLayer: baseLayer
  13798. });
  13799. session.requestReferenceSpace(referenceSpaceType).then(onRequestReferenceSpace); //
  13800. session.addEventListener('inputsourceschange', updateInputSources);
  13801. }
  13802. };
  13803. function updateInputSources(event) {
  13804. var inputSources = session.inputSources; // Assign inputSources to available controllers
  13805. for (var i = 0; i < controllers.length; i++) {
  13806. inputSourcesMap.set(inputSources[i], controllers[i]);
  13807. } // Notify disconnected
  13808. for (var _i = 0; _i < event.removed.length; _i++) {
  13809. var inputSource = event.removed[_i];
  13810. var controller = inputSourcesMap.get(inputSource);
  13811. if (controller) {
  13812. controller.dispatchEvent({
  13813. type: 'disconnected',
  13814. data: inputSource
  13815. });
  13816. inputSourcesMap.delete(inputSource);
  13817. }
  13818. } // Notify connected
  13819. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  13820. var _inputSource = event.added[_i2];
  13821. var _controller = inputSourcesMap.get(_inputSource);
  13822. if (_controller) {
  13823. _controller.dispatchEvent({
  13824. type: 'connected',
  13825. data: _inputSource
  13826. });
  13827. }
  13828. }
  13829. } //
  13830. var cameraLPos = new Vector3();
  13831. var cameraRPos = new Vector3();
  13832. /**
  13833. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13834. * the cameras' projection and world matrices have already been set.
  13835. * And that near and far planes are identical for both cameras.
  13836. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13837. */
  13838. function setProjectionFromUnion(camera, cameraL, cameraR) {
  13839. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  13840. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  13841. var ipd = cameraLPos.distanceTo(cameraRPos);
  13842. var projL = cameraL.projectionMatrix.elements;
  13843. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  13844. // most likely identical top and bottom frustum extents.
  13845. // Use the left camera for these values.
  13846. var near = projL[14] / (projL[10] - 1);
  13847. var far = projL[14] / (projL[10] + 1);
  13848. var topFov = (projL[9] + 1) / projL[5];
  13849. var bottomFov = (projL[9] - 1) / projL[5];
  13850. var leftFov = (projL[8] - 1) / projL[0];
  13851. var rightFov = (projR[8] + 1) / projR[0];
  13852. var left = near * leftFov;
  13853. var right = near * rightFov; // Calculate the new camera's position offset from the
  13854. // left camera. xOffset should be roughly half `ipd`.
  13855. var zOffset = ipd / (-leftFov + rightFov);
  13856. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  13857. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  13858. camera.translateX(xOffset);
  13859. camera.translateZ(zOffset);
  13860. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  13861. camera.matrixWorldInverse.copy(camera.matrixWorld).invert(); // Find the union of the frustum values of the cameras and scale
  13862. // the values so that the near plane's position does not change in world space,
  13863. // although must now be relative to the new union camera.
  13864. var near2 = near + zOffset;
  13865. var far2 = far + zOffset;
  13866. var left2 = left - xOffset;
  13867. var right2 = right + (ipd - xOffset);
  13868. var top2 = topFov * far / far2 * near2;
  13869. var bottom2 = bottomFov * far / far2 * near2;
  13870. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  13871. }
  13872. function updateCamera(camera, parent) {
  13873. if (parent === null) {
  13874. camera.matrixWorld.copy(camera.matrix);
  13875. } else {
  13876. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  13877. }
  13878. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  13879. }
  13880. this.getCamera = function (camera) {
  13881. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  13882. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  13883. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  13884. // Note that the new renderState won't apply until the next frame. See #18320
  13885. session.updateRenderState({
  13886. depthNear: cameraVR.near,
  13887. depthFar: cameraVR.far
  13888. });
  13889. _currentDepthNear = cameraVR.near;
  13890. _currentDepthFar = cameraVR.far;
  13891. }
  13892. var parent = camera.parent;
  13893. var cameras = cameraVR.cameras;
  13894. updateCamera(cameraVR, parent);
  13895. for (var i = 0; i < cameras.length; i++) {
  13896. updateCamera(cameras[i], parent);
  13897. } // update camera and its children
  13898. camera.matrixWorld.copy(cameraVR.matrixWorld);
  13899. var children = camera.children;
  13900. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  13901. children[_i3].updateMatrixWorld(true);
  13902. } // update projection matrix for proper view frustum culling
  13903. if (cameras.length === 2) {
  13904. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  13905. } else {
  13906. // assume single camera setup (AR)
  13907. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  13908. }
  13909. return cameraVR;
  13910. }; // Animation Loop
  13911. var onAnimationFrameCallback = null;
  13912. function onAnimationFrame(time, frame) {
  13913. pose = frame.getViewerPose(referenceSpace);
  13914. if (pose !== null) {
  13915. var views = pose.views;
  13916. var baseLayer = session.renderState.baseLayer;
  13917. renderer.setFramebuffer(baseLayer.framebuffer);
  13918. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  13919. if (views.length !== cameraVR.cameras.length) {
  13920. cameraVR.cameras.length = 0;
  13921. cameraVRNeedsUpdate = true;
  13922. }
  13923. for (var i = 0; i < views.length; i++) {
  13924. var view = views[i];
  13925. var viewport = baseLayer.getViewport(view);
  13926. var camera = cameras[i];
  13927. camera.matrix.fromArray(view.transform.matrix);
  13928. camera.projectionMatrix.fromArray(view.projectionMatrix);
  13929. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  13930. if (i === 0) {
  13931. cameraVR.matrix.copy(camera.matrix);
  13932. }
  13933. if (cameraVRNeedsUpdate === true) {
  13934. cameraVR.cameras.push(camera);
  13935. }
  13936. }
  13937. } //
  13938. var inputSources = session.inputSources;
  13939. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  13940. var controller = controllers[_i4];
  13941. var inputSource = inputSources[_i4];
  13942. controller.update(inputSource, frame, referenceSpace);
  13943. }
  13944. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  13945. }
  13946. var animation = new WebGLAnimation();
  13947. animation.setAnimationLoop(onAnimationFrame);
  13948. this.setAnimationLoop = function (callback) {
  13949. onAnimationFrameCallback = callback;
  13950. };
  13951. this.dispose = function () {};
  13952. }
  13953. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  13954. function WebGLMaterials(properties) {
  13955. function refreshFogUniforms(uniforms, fog) {
  13956. uniforms.fogColor.value.copy(fog.color);
  13957. if (fog.isFog) {
  13958. uniforms.fogNear.value = fog.near;
  13959. uniforms.fogFar.value = fog.far;
  13960. } else if (fog.isFogExp2) {
  13961. uniforms.fogDensity.value = fog.density;
  13962. }
  13963. }
  13964. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  13965. if (material.isMeshBasicMaterial) {
  13966. refreshUniformsCommon(uniforms, material);
  13967. } else if (material.isMeshLambertMaterial) {
  13968. refreshUniformsCommon(uniforms, material);
  13969. refreshUniformsLambert(uniforms, material);
  13970. } else if (material.isMeshToonMaterial) {
  13971. refreshUniformsCommon(uniforms, material);
  13972. refreshUniformsToon(uniforms, material);
  13973. } else if (material.isMeshPhongMaterial) {
  13974. refreshUniformsCommon(uniforms, material);
  13975. refreshUniformsPhong(uniforms, material);
  13976. } else if (material.isMeshStandardMaterial) {
  13977. refreshUniformsCommon(uniforms, material);
  13978. if (material.isMeshPhysicalMaterial) {
  13979. refreshUniformsPhysical(uniforms, material);
  13980. } else {
  13981. refreshUniformsStandard(uniforms, material);
  13982. }
  13983. } else if (material.isMeshMatcapMaterial) {
  13984. refreshUniformsCommon(uniforms, material);
  13985. refreshUniformsMatcap(uniforms, material);
  13986. } else if (material.isMeshDepthMaterial) {
  13987. refreshUniformsCommon(uniforms, material);
  13988. refreshUniformsDepth(uniforms, material);
  13989. } else if (material.isMeshDistanceMaterial) {
  13990. refreshUniformsCommon(uniforms, material);
  13991. refreshUniformsDistance(uniforms, material);
  13992. } else if (material.isMeshNormalMaterial) {
  13993. refreshUniformsCommon(uniforms, material);
  13994. refreshUniformsNormal(uniforms, material);
  13995. } else if (material.isLineBasicMaterial) {
  13996. refreshUniformsLine(uniforms, material);
  13997. if (material.isLineDashedMaterial) {
  13998. refreshUniformsDash(uniforms, material);
  13999. }
  14000. } else if (material.isPointsMaterial) {
  14001. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  14002. } else if (material.isSpriteMaterial) {
  14003. refreshUniformsSprites(uniforms, material);
  14004. } else if (material.isShadowMaterial) {
  14005. uniforms.color.value.copy(material.color);
  14006. uniforms.opacity.value = material.opacity;
  14007. } else if (material.isShaderMaterial) {
  14008. material.uniformsNeedUpdate = false; // #15581
  14009. }
  14010. }
  14011. function refreshUniformsCommon(uniforms, material) {
  14012. uniforms.opacity.value = material.opacity;
  14013. if (material.color) {
  14014. uniforms.diffuse.value.copy(material.color);
  14015. }
  14016. if (material.emissive) {
  14017. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  14018. }
  14019. if (material.map) {
  14020. uniforms.map.value = material.map;
  14021. }
  14022. if (material.alphaMap) {
  14023. uniforms.alphaMap.value = material.alphaMap;
  14024. }
  14025. if (material.specularMap) {
  14026. uniforms.specularMap.value = material.specularMap;
  14027. }
  14028. var envMap = properties.get(material).envMap;
  14029. if (envMap) {
  14030. uniforms.envMap.value = envMap;
  14031. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  14032. uniforms.reflectivity.value = material.reflectivity;
  14033. uniforms.refractionRatio.value = material.refractionRatio;
  14034. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  14035. if (maxMipLevel !== undefined) {
  14036. uniforms.maxMipLevel.value = maxMipLevel;
  14037. }
  14038. }
  14039. if (material.lightMap) {
  14040. uniforms.lightMap.value = material.lightMap;
  14041. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14042. }
  14043. if (material.aoMap) {
  14044. uniforms.aoMap.value = material.aoMap;
  14045. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14046. } // uv repeat and offset setting priorities
  14047. // 1. color map
  14048. // 2. specular map
  14049. // 3. displacementMap map
  14050. // 4. normal map
  14051. // 5. bump map
  14052. // 6. roughnessMap map
  14053. // 7. metalnessMap map
  14054. // 8. alphaMap map
  14055. // 9. emissiveMap map
  14056. // 10. clearcoat map
  14057. // 11. clearcoat normal map
  14058. // 12. clearcoat roughnessMap map
  14059. var uvScaleMap;
  14060. if (material.map) {
  14061. uvScaleMap = material.map;
  14062. } else if (material.specularMap) {
  14063. uvScaleMap = material.specularMap;
  14064. } else if (material.displacementMap) {
  14065. uvScaleMap = material.displacementMap;
  14066. } else if (material.normalMap) {
  14067. uvScaleMap = material.normalMap;
  14068. } else if (material.bumpMap) {
  14069. uvScaleMap = material.bumpMap;
  14070. } else if (material.roughnessMap) {
  14071. uvScaleMap = material.roughnessMap;
  14072. } else if (material.metalnessMap) {
  14073. uvScaleMap = material.metalnessMap;
  14074. } else if (material.alphaMap) {
  14075. uvScaleMap = material.alphaMap;
  14076. } else if (material.emissiveMap) {
  14077. uvScaleMap = material.emissiveMap;
  14078. } else if (material.clearcoatMap) {
  14079. uvScaleMap = material.clearcoatMap;
  14080. } else if (material.clearcoatNormalMap) {
  14081. uvScaleMap = material.clearcoatNormalMap;
  14082. } else if (material.clearcoatRoughnessMap) {
  14083. uvScaleMap = material.clearcoatRoughnessMap;
  14084. }
  14085. if (uvScaleMap !== undefined) {
  14086. // backwards compatibility
  14087. if (uvScaleMap.isWebGLRenderTarget) {
  14088. uvScaleMap = uvScaleMap.texture;
  14089. }
  14090. if (uvScaleMap.matrixAutoUpdate === true) {
  14091. uvScaleMap.updateMatrix();
  14092. }
  14093. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14094. } // uv repeat and offset setting priorities for uv2
  14095. // 1. ao map
  14096. // 2. light map
  14097. var uv2ScaleMap;
  14098. if (material.aoMap) {
  14099. uv2ScaleMap = material.aoMap;
  14100. } else if (material.lightMap) {
  14101. uv2ScaleMap = material.lightMap;
  14102. }
  14103. if (uv2ScaleMap !== undefined) {
  14104. // backwards compatibility
  14105. if (uv2ScaleMap.isWebGLRenderTarget) {
  14106. uv2ScaleMap = uv2ScaleMap.texture;
  14107. }
  14108. if (uv2ScaleMap.matrixAutoUpdate === true) {
  14109. uv2ScaleMap.updateMatrix();
  14110. }
  14111. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  14112. }
  14113. }
  14114. function refreshUniformsLine(uniforms, material) {
  14115. uniforms.diffuse.value.copy(material.color);
  14116. uniforms.opacity.value = material.opacity;
  14117. }
  14118. function refreshUniformsDash(uniforms, material) {
  14119. uniforms.dashSize.value = material.dashSize;
  14120. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14121. uniforms.scale.value = material.scale;
  14122. }
  14123. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  14124. uniforms.diffuse.value.copy(material.color);
  14125. uniforms.opacity.value = material.opacity;
  14126. uniforms.size.value = material.size * pixelRatio;
  14127. uniforms.scale.value = height * 0.5;
  14128. if (material.map) {
  14129. uniforms.map.value = material.map;
  14130. }
  14131. if (material.alphaMap) {
  14132. uniforms.alphaMap.value = material.alphaMap;
  14133. } // uv repeat and offset setting priorities
  14134. // 1. color map
  14135. // 2. alpha map
  14136. var uvScaleMap;
  14137. if (material.map) {
  14138. uvScaleMap = material.map;
  14139. } else if (material.alphaMap) {
  14140. uvScaleMap = material.alphaMap;
  14141. }
  14142. if (uvScaleMap !== undefined) {
  14143. if (uvScaleMap.matrixAutoUpdate === true) {
  14144. uvScaleMap.updateMatrix();
  14145. }
  14146. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14147. }
  14148. }
  14149. function refreshUniformsSprites(uniforms, material) {
  14150. uniforms.diffuse.value.copy(material.color);
  14151. uniforms.opacity.value = material.opacity;
  14152. uniforms.rotation.value = material.rotation;
  14153. if (material.map) {
  14154. uniforms.map.value = material.map;
  14155. }
  14156. if (material.alphaMap) {
  14157. uniforms.alphaMap.value = material.alphaMap;
  14158. } // uv repeat and offset setting priorities
  14159. // 1. color map
  14160. // 2. alpha map
  14161. var uvScaleMap;
  14162. if (material.map) {
  14163. uvScaleMap = material.map;
  14164. } else if (material.alphaMap) {
  14165. uvScaleMap = material.alphaMap;
  14166. }
  14167. if (uvScaleMap !== undefined) {
  14168. if (uvScaleMap.matrixAutoUpdate === true) {
  14169. uvScaleMap.updateMatrix();
  14170. }
  14171. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14172. }
  14173. }
  14174. function refreshUniformsLambert(uniforms, material) {
  14175. if (material.emissiveMap) {
  14176. uniforms.emissiveMap.value = material.emissiveMap;
  14177. }
  14178. }
  14179. function refreshUniformsPhong(uniforms, material) {
  14180. uniforms.specular.value.copy(material.specular);
  14181. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  14182. if (material.emissiveMap) {
  14183. uniforms.emissiveMap.value = material.emissiveMap;
  14184. }
  14185. if (material.bumpMap) {
  14186. uniforms.bumpMap.value = material.bumpMap;
  14187. uniforms.bumpScale.value = material.bumpScale;
  14188. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14189. }
  14190. if (material.normalMap) {
  14191. uniforms.normalMap.value = material.normalMap;
  14192. uniforms.normalScale.value.copy(material.normalScale);
  14193. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14194. }
  14195. if (material.displacementMap) {
  14196. uniforms.displacementMap.value = material.displacementMap;
  14197. uniforms.displacementScale.value = material.displacementScale;
  14198. uniforms.displacementBias.value = material.displacementBias;
  14199. }
  14200. }
  14201. function refreshUniformsToon(uniforms, material) {
  14202. if (material.gradientMap) {
  14203. uniforms.gradientMap.value = material.gradientMap;
  14204. }
  14205. if (material.emissiveMap) {
  14206. uniforms.emissiveMap.value = material.emissiveMap;
  14207. }
  14208. if (material.bumpMap) {
  14209. uniforms.bumpMap.value = material.bumpMap;
  14210. uniforms.bumpScale.value = material.bumpScale;
  14211. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14212. }
  14213. if (material.normalMap) {
  14214. uniforms.normalMap.value = material.normalMap;
  14215. uniforms.normalScale.value.copy(material.normalScale);
  14216. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14217. }
  14218. if (material.displacementMap) {
  14219. uniforms.displacementMap.value = material.displacementMap;
  14220. uniforms.displacementScale.value = material.displacementScale;
  14221. uniforms.displacementBias.value = material.displacementBias;
  14222. }
  14223. }
  14224. function refreshUniformsStandard(uniforms, material) {
  14225. uniforms.roughness.value = material.roughness;
  14226. uniforms.metalness.value = material.metalness;
  14227. if (material.roughnessMap) {
  14228. uniforms.roughnessMap.value = material.roughnessMap;
  14229. }
  14230. if (material.metalnessMap) {
  14231. uniforms.metalnessMap.value = material.metalnessMap;
  14232. }
  14233. if (material.emissiveMap) {
  14234. uniforms.emissiveMap.value = material.emissiveMap;
  14235. }
  14236. if (material.bumpMap) {
  14237. uniforms.bumpMap.value = material.bumpMap;
  14238. uniforms.bumpScale.value = material.bumpScale;
  14239. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14240. }
  14241. if (material.normalMap) {
  14242. uniforms.normalMap.value = material.normalMap;
  14243. uniforms.normalScale.value.copy(material.normalScale);
  14244. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14245. }
  14246. if (material.displacementMap) {
  14247. uniforms.displacementMap.value = material.displacementMap;
  14248. uniforms.displacementScale.value = material.displacementScale;
  14249. uniforms.displacementBias.value = material.displacementBias;
  14250. }
  14251. var envMap = properties.get(material).envMap;
  14252. if (envMap) {
  14253. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14254. uniforms.envMapIntensity.value = material.envMapIntensity;
  14255. }
  14256. }
  14257. function refreshUniformsPhysical(uniforms, material) {
  14258. refreshUniformsStandard(uniforms, material);
  14259. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14260. uniforms.clearcoat.value = material.clearcoat;
  14261. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14262. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14263. if (material.clearcoatMap) {
  14264. uniforms.clearcoatMap.value = material.clearcoatMap;
  14265. }
  14266. if (material.clearcoatRoughnessMap) {
  14267. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14268. }
  14269. if (material.clearcoatNormalMap) {
  14270. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14271. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14272. if (material.side === BackSide) {
  14273. uniforms.clearcoatNormalScale.value.negate();
  14274. }
  14275. }
  14276. uniforms.transmission.value = material.transmission;
  14277. if (material.transmissionMap) {
  14278. uniforms.transmissionMap.value = material.transmissionMap;
  14279. }
  14280. }
  14281. function refreshUniformsMatcap(uniforms, material) {
  14282. if (material.matcap) {
  14283. uniforms.matcap.value = material.matcap;
  14284. }
  14285. if (material.bumpMap) {
  14286. uniforms.bumpMap.value = material.bumpMap;
  14287. uniforms.bumpScale.value = material.bumpScale;
  14288. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14289. }
  14290. if (material.normalMap) {
  14291. uniforms.normalMap.value = material.normalMap;
  14292. uniforms.normalScale.value.copy(material.normalScale);
  14293. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14294. }
  14295. if (material.displacementMap) {
  14296. uniforms.displacementMap.value = material.displacementMap;
  14297. uniforms.displacementScale.value = material.displacementScale;
  14298. uniforms.displacementBias.value = material.displacementBias;
  14299. }
  14300. }
  14301. function refreshUniformsDepth(uniforms, material) {
  14302. if (material.displacementMap) {
  14303. uniforms.displacementMap.value = material.displacementMap;
  14304. uniforms.displacementScale.value = material.displacementScale;
  14305. uniforms.displacementBias.value = material.displacementBias;
  14306. }
  14307. }
  14308. function refreshUniformsDistance(uniforms, material) {
  14309. if (material.displacementMap) {
  14310. uniforms.displacementMap.value = material.displacementMap;
  14311. uniforms.displacementScale.value = material.displacementScale;
  14312. uniforms.displacementBias.value = material.displacementBias;
  14313. }
  14314. uniforms.referencePosition.value.copy(material.referencePosition);
  14315. uniforms.nearDistance.value = material.nearDistance;
  14316. uniforms.farDistance.value = material.farDistance;
  14317. }
  14318. function refreshUniformsNormal(uniforms, material) {
  14319. if (material.bumpMap) {
  14320. uniforms.bumpMap.value = material.bumpMap;
  14321. uniforms.bumpScale.value = material.bumpScale;
  14322. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14323. }
  14324. if (material.normalMap) {
  14325. uniforms.normalMap.value = material.normalMap;
  14326. uniforms.normalScale.value.copy(material.normalScale);
  14327. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14328. }
  14329. if (material.displacementMap) {
  14330. uniforms.displacementMap.value = material.displacementMap;
  14331. uniforms.displacementScale.value = material.displacementScale;
  14332. uniforms.displacementBias.value = material.displacementBias;
  14333. }
  14334. }
  14335. return {
  14336. refreshFogUniforms: refreshFogUniforms,
  14337. refreshMaterialUniforms: refreshMaterialUniforms
  14338. };
  14339. }
  14340. function createCanvasElement() {
  14341. var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  14342. canvas.style.display = 'block';
  14343. return canvas;
  14344. }
  14345. function WebGLRenderer(parameters) {
  14346. parameters = parameters || {};
  14347. var _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  14348. _context = parameters.context !== undefined ? parameters.context : null,
  14349. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14350. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14351. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14352. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14353. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14354. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14355. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14356. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14357. var currentRenderList = null;
  14358. var currentRenderState = null; // render() can be called from within a callback triggered by another render.
  14359. // We track this so that the nested render call gets its state isolated from the parent render call.
  14360. var renderStateStack = []; // public properties
  14361. this.domElement = _canvas; // Debug configuration container
  14362. this.debug = {
  14363. /**
  14364. * Enables error checking and reporting when shader programs are being compiled
  14365. * @type {boolean}
  14366. */
  14367. checkShaderErrors: true
  14368. }; // clearing
  14369. this.autoClear = true;
  14370. this.autoClearColor = true;
  14371. this.autoClearDepth = true;
  14372. this.autoClearStencil = true; // scene graph
  14373. this.sortObjects = true; // user-defined clipping
  14374. this.clippingPlanes = [];
  14375. this.localClippingEnabled = false; // physically based shading
  14376. this.gammaFactor = 2.0; // for backwards compatibility
  14377. this.outputEncoding = LinearEncoding; // physical lights
  14378. this.physicallyCorrectLights = false; // tone mapping
  14379. this.toneMapping = NoToneMapping;
  14380. this.toneMappingExposure = 1.0; // morphs
  14381. this.maxMorphTargets = 8;
  14382. this.maxMorphNormals = 4; // internal properties
  14383. var _this = this;
  14384. var _isContextLost = false; // internal state cache
  14385. var _framebuffer = null;
  14386. var _currentActiveCubeFace = 0;
  14387. var _currentActiveMipmapLevel = 0;
  14388. var _currentRenderTarget = null;
  14389. var _currentFramebuffer = null;
  14390. var _currentMaterialId = -1;
  14391. var _currentCamera = null;
  14392. var _currentViewport = new Vector4();
  14393. var _currentScissor = new Vector4();
  14394. var _currentScissorTest = null; //
  14395. var _width = _canvas.width;
  14396. var _height = _canvas.height;
  14397. var _pixelRatio = 1;
  14398. var _opaqueSort = null;
  14399. var _transparentSort = null;
  14400. var _viewport = new Vector4(0, 0, _width, _height);
  14401. var _scissor = new Vector4(0, 0, _width, _height);
  14402. var _scissorTest = false; // frustum
  14403. var _frustum = new Frustum(); // clipping
  14404. var _clippingEnabled = false;
  14405. var _localClippingEnabled = false; // camera matrices cache
  14406. var _projScreenMatrix = new Matrix4();
  14407. var _vector3 = new Vector3();
  14408. var _emptyScene = {
  14409. background: null,
  14410. fog: null,
  14411. environment: null,
  14412. overrideMaterial: null,
  14413. isScene: true
  14414. };
  14415. function getTargetPixelRatio() {
  14416. return _currentRenderTarget === null ? _pixelRatio : 1;
  14417. } // initialize
  14418. var _gl = _context;
  14419. function getContext(contextNames, contextAttributes) {
  14420. for (var i = 0; i < contextNames.length; i++) {
  14421. var contextName = contextNames[i];
  14422. var context = _canvas.getContext(contextName, contextAttributes);
  14423. if (context !== null) return context;
  14424. }
  14425. return null;
  14426. }
  14427. try {
  14428. var contextAttributes = {
  14429. alpha: _alpha,
  14430. depth: _depth,
  14431. stencil: _stencil,
  14432. antialias: _antialias,
  14433. premultipliedAlpha: _premultipliedAlpha,
  14434. preserveDrawingBuffer: _preserveDrawingBuffer,
  14435. powerPreference: _powerPreference,
  14436. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14437. }; // event listeners must be registered before WebGL context is created, see #12753
  14438. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  14439. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  14440. if (_gl === null) {
  14441. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  14442. if (_this.isWebGL1Renderer === true) {
  14443. contextNames.shift();
  14444. }
  14445. _gl = getContext(contextNames, contextAttributes);
  14446. if (_gl === null) {
  14447. if (getContext(contextNames)) {
  14448. throw new Error('Error creating WebGL context with your selected attributes.');
  14449. } else {
  14450. throw new Error('Error creating WebGL context.');
  14451. }
  14452. }
  14453. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14454. if (_gl.getShaderPrecisionFormat === undefined) {
  14455. _gl.getShaderPrecisionFormat = function () {
  14456. return {
  14457. 'rangeMin': 1,
  14458. 'rangeMax': 1,
  14459. 'precision': 1
  14460. };
  14461. };
  14462. }
  14463. } catch (error) {
  14464. console.error('THREE.WebGLRenderer: ' + error.message);
  14465. throw error;
  14466. }
  14467. var extensions, capabilities, state, info;
  14468. var properties, textures, cubemaps, attributes, geometries, objects;
  14469. var programCache, materials, renderLists, renderStates, clipping;
  14470. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14471. var utils, bindingStates;
  14472. function initGLContext() {
  14473. extensions = new WebGLExtensions(_gl);
  14474. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  14475. if (capabilities.isWebGL2 === false) {
  14476. extensions.get('WEBGL_depth_texture');
  14477. extensions.get('OES_texture_float');
  14478. extensions.get('OES_texture_half_float');
  14479. extensions.get('OES_texture_half_float_linear');
  14480. extensions.get('OES_standard_derivatives');
  14481. extensions.get('OES_element_index_uint');
  14482. extensions.get('OES_vertex_array_object');
  14483. extensions.get('ANGLE_instanced_arrays');
  14484. }
  14485. extensions.get('OES_texture_float_linear');
  14486. utils = new WebGLUtils(_gl, extensions, capabilities);
  14487. state = new WebGLState(_gl, extensions, capabilities);
  14488. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14489. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14490. info = new WebGLInfo(_gl);
  14491. properties = new WebGLProperties();
  14492. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  14493. cubemaps = new WebGLCubeMaps(_this);
  14494. attributes = new WebGLAttributes(_gl, capabilities);
  14495. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  14496. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  14497. objects = new WebGLObjects(_gl, geometries, attributes, info);
  14498. morphtargets = new WebGLMorphtargets(_gl);
  14499. clipping = new WebGLClipping(properties);
  14500. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  14501. materials = new WebGLMaterials(properties);
  14502. renderLists = new WebGLRenderLists(properties);
  14503. renderStates = new WebGLRenderStates(extensions, capabilities);
  14504. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  14505. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  14506. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  14507. info.programs = programCache.programs;
  14508. _this.capabilities = capabilities;
  14509. _this.extensions = extensions;
  14510. _this.properties = properties;
  14511. _this.renderLists = renderLists;
  14512. _this.state = state;
  14513. _this.info = info;
  14514. }
  14515. initGLContext(); // xr
  14516. var xr = new WebXRManager(_this, _gl);
  14517. this.xr = xr; // shadow map
  14518. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  14519. this.shadowMap = shadowMap; // API
  14520. this.getContext = function () {
  14521. return _gl;
  14522. };
  14523. this.getContextAttributes = function () {
  14524. return _gl.getContextAttributes();
  14525. };
  14526. this.forceContextLoss = function () {
  14527. var extension = extensions.get('WEBGL_lose_context');
  14528. if (extension) extension.loseContext();
  14529. };
  14530. this.forceContextRestore = function () {
  14531. var extension = extensions.get('WEBGL_lose_context');
  14532. if (extension) extension.restoreContext();
  14533. };
  14534. this.getPixelRatio = function () {
  14535. return _pixelRatio;
  14536. };
  14537. this.setPixelRatio = function (value) {
  14538. if (value === undefined) return;
  14539. _pixelRatio = value;
  14540. this.setSize(_width, _height, false);
  14541. };
  14542. this.getSize = function (target) {
  14543. if (target === undefined) {
  14544. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  14545. target = new Vector2();
  14546. }
  14547. return target.set(_width, _height);
  14548. };
  14549. this.setSize = function (width, height, updateStyle) {
  14550. if (xr.isPresenting) {
  14551. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  14552. return;
  14553. }
  14554. _width = width;
  14555. _height = height;
  14556. _canvas.width = Math.floor(width * _pixelRatio);
  14557. _canvas.height = Math.floor(height * _pixelRatio);
  14558. if (updateStyle !== false) {
  14559. _canvas.style.width = width + 'px';
  14560. _canvas.style.height = height + 'px';
  14561. }
  14562. this.setViewport(0, 0, width, height);
  14563. };
  14564. this.getDrawingBufferSize = function (target) {
  14565. if (target === undefined) {
  14566. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  14567. target = new Vector2();
  14568. }
  14569. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  14570. };
  14571. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  14572. _width = width;
  14573. _height = height;
  14574. _pixelRatio = pixelRatio;
  14575. _canvas.width = Math.floor(width * pixelRatio);
  14576. _canvas.height = Math.floor(height * pixelRatio);
  14577. this.setViewport(0, 0, width, height);
  14578. };
  14579. this.getCurrentViewport = function (target) {
  14580. if (target === undefined) {
  14581. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  14582. target = new Vector4();
  14583. }
  14584. return target.copy(_currentViewport);
  14585. };
  14586. this.getViewport = function (target) {
  14587. return target.copy(_viewport);
  14588. };
  14589. this.setViewport = function (x, y, width, height) {
  14590. if (x.isVector4) {
  14591. _viewport.set(x.x, x.y, x.z, x.w);
  14592. } else {
  14593. _viewport.set(x, y, width, height);
  14594. }
  14595. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14596. };
  14597. this.getScissor = function (target) {
  14598. return target.copy(_scissor);
  14599. };
  14600. this.setScissor = function (x, y, width, height) {
  14601. if (x.isVector4) {
  14602. _scissor.set(x.x, x.y, x.z, x.w);
  14603. } else {
  14604. _scissor.set(x, y, width, height);
  14605. }
  14606. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14607. };
  14608. this.getScissorTest = function () {
  14609. return _scissorTest;
  14610. };
  14611. this.setScissorTest = function (boolean) {
  14612. state.setScissorTest(_scissorTest = boolean);
  14613. };
  14614. this.setOpaqueSort = function (method) {
  14615. _opaqueSort = method;
  14616. };
  14617. this.setTransparentSort = function (method) {
  14618. _transparentSort = method;
  14619. }; // Clearing
  14620. this.getClearColor = function (target) {
  14621. if (target === undefined) {
  14622. console.warn('WebGLRenderer: .getClearColor() now requires a Color as an argument');
  14623. target = new Color();
  14624. }
  14625. return target.copy(background.getClearColor());
  14626. };
  14627. this.setClearColor = function () {
  14628. background.setClearColor.apply(background, arguments);
  14629. };
  14630. this.getClearAlpha = function () {
  14631. return background.getClearAlpha();
  14632. };
  14633. this.setClearAlpha = function () {
  14634. background.setClearAlpha.apply(background, arguments);
  14635. };
  14636. this.clear = function (color, depth, stencil) {
  14637. var bits = 0;
  14638. if (color === undefined || color) bits |= 16384;
  14639. if (depth === undefined || depth) bits |= 256;
  14640. if (stencil === undefined || stencil) bits |= 1024;
  14641. _gl.clear(bits);
  14642. };
  14643. this.clearColor = function () {
  14644. this.clear(true, false, false);
  14645. };
  14646. this.clearDepth = function () {
  14647. this.clear(false, true, false);
  14648. };
  14649. this.clearStencil = function () {
  14650. this.clear(false, false, true);
  14651. }; //
  14652. this.dispose = function () {
  14653. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  14654. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  14655. renderLists.dispose();
  14656. renderStates.dispose();
  14657. properties.dispose();
  14658. cubemaps.dispose();
  14659. objects.dispose();
  14660. bindingStates.dispose();
  14661. xr.dispose();
  14662. animation.stop();
  14663. }; // Events
  14664. function onContextLost(event) {
  14665. event.preventDefault();
  14666. console.log('THREE.WebGLRenderer: Context Lost.');
  14667. _isContextLost = true;
  14668. }
  14669. function onContextRestore()
  14670. /* event */
  14671. {
  14672. console.log('THREE.WebGLRenderer: Context Restored.');
  14673. _isContextLost = false;
  14674. initGLContext();
  14675. }
  14676. function onMaterialDispose(event) {
  14677. var material = event.target;
  14678. material.removeEventListener('dispose', onMaterialDispose);
  14679. deallocateMaterial(material);
  14680. } // Buffer deallocation
  14681. function deallocateMaterial(material) {
  14682. releaseMaterialProgramReference(material);
  14683. properties.remove(material);
  14684. }
  14685. function releaseMaterialProgramReference(material) {
  14686. var programInfo = properties.get(material).program;
  14687. if (programInfo !== undefined) {
  14688. programCache.releaseProgram(programInfo);
  14689. }
  14690. } // Buffer rendering
  14691. function renderObjectImmediate(object, program) {
  14692. object.render(function (object) {
  14693. _this.renderBufferImmediate(object, program);
  14694. });
  14695. }
  14696. this.renderBufferImmediate = function (object, program) {
  14697. bindingStates.initAttributes();
  14698. var buffers = properties.get(object);
  14699. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  14700. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  14701. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  14702. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  14703. var programAttributes = program.getAttributes();
  14704. if (object.hasPositions) {
  14705. _gl.bindBuffer(34962, buffers.position);
  14706. _gl.bufferData(34962, object.positionArray, 35048);
  14707. bindingStates.enableAttribute(programAttributes.position);
  14708. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  14709. }
  14710. if (object.hasNormals) {
  14711. _gl.bindBuffer(34962, buffers.normal);
  14712. _gl.bufferData(34962, object.normalArray, 35048);
  14713. bindingStates.enableAttribute(programAttributes.normal);
  14714. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  14715. }
  14716. if (object.hasUvs) {
  14717. _gl.bindBuffer(34962, buffers.uv);
  14718. _gl.bufferData(34962, object.uvArray, 35048);
  14719. bindingStates.enableAttribute(programAttributes.uv);
  14720. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  14721. }
  14722. if (object.hasColors) {
  14723. _gl.bindBuffer(34962, buffers.color);
  14724. _gl.bufferData(34962, object.colorArray, 35048);
  14725. bindingStates.enableAttribute(programAttributes.color);
  14726. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  14727. }
  14728. bindingStates.disableUnusedAttributes();
  14729. _gl.drawArrays(4, 0, object.count);
  14730. object.count = 0;
  14731. };
  14732. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  14733. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  14734. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  14735. var program = setProgram(camera, scene, material, object);
  14736. state.setMaterial(material, frontFaceCW); //
  14737. var index = geometry.index;
  14738. var position = geometry.attributes.position; //
  14739. if (index === null) {
  14740. if (position === undefined || position.count === 0) return;
  14741. } else if (index.count === 0) {
  14742. return;
  14743. } //
  14744. var rangeFactor = 1;
  14745. if (material.wireframe === true) {
  14746. index = geometries.getWireframeAttribute(geometry);
  14747. rangeFactor = 2;
  14748. }
  14749. if (material.morphTargets || material.morphNormals) {
  14750. morphtargets.update(object, geometry, material, program);
  14751. }
  14752. bindingStates.setup(object, material, program, geometry, index);
  14753. var attribute;
  14754. var renderer = bufferRenderer;
  14755. if (index !== null) {
  14756. attribute = attributes.get(index);
  14757. renderer = indexedBufferRenderer;
  14758. renderer.setIndex(attribute);
  14759. } //
  14760. var dataCount = index !== null ? index.count : position.count;
  14761. var rangeStart = geometry.drawRange.start * rangeFactor;
  14762. var rangeCount = geometry.drawRange.count * rangeFactor;
  14763. var groupStart = group !== null ? group.start * rangeFactor : 0;
  14764. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14765. var drawStart = Math.max(rangeStart, groupStart);
  14766. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  14767. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  14768. if (drawCount === 0) return; //
  14769. if (object.isMesh) {
  14770. if (material.wireframe === true) {
  14771. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  14772. renderer.setMode(1);
  14773. } else {
  14774. renderer.setMode(4);
  14775. }
  14776. } else if (object.isLine) {
  14777. var lineWidth = material.linewidth;
  14778. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  14779. state.setLineWidth(lineWidth * getTargetPixelRatio());
  14780. if (object.isLineSegments) {
  14781. renderer.setMode(1);
  14782. } else if (object.isLineLoop) {
  14783. renderer.setMode(2);
  14784. } else {
  14785. renderer.setMode(3);
  14786. }
  14787. } else if (object.isPoints) {
  14788. renderer.setMode(0);
  14789. } else if (object.isSprite) {
  14790. renderer.setMode(4);
  14791. }
  14792. if (object.isInstancedMesh) {
  14793. renderer.renderInstances(drawStart, drawCount, object.count);
  14794. } else if (geometry.isInstancedBufferGeometry) {
  14795. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  14796. renderer.renderInstances(drawStart, drawCount, instanceCount);
  14797. } else {
  14798. renderer.render(drawStart, drawCount);
  14799. }
  14800. }; // Compile
  14801. this.compile = function (scene, camera) {
  14802. currentRenderState = renderStates.get(scene);
  14803. currentRenderState.init();
  14804. scene.traverseVisible(function (object) {
  14805. if (object.isLight && object.layers.test(camera.layers)) {
  14806. currentRenderState.pushLight(object);
  14807. if (object.castShadow) {
  14808. currentRenderState.pushShadow(object);
  14809. }
  14810. }
  14811. });
  14812. currentRenderState.setupLights();
  14813. var compiled = new WeakMap();
  14814. scene.traverse(function (object) {
  14815. var material = object.material;
  14816. if (material) {
  14817. if (Array.isArray(material)) {
  14818. for (var i = 0; i < material.length; i++) {
  14819. var material2 = material[i];
  14820. if (compiled.has(material2) === false) {
  14821. initMaterial(material2, scene, object);
  14822. compiled.set(material2);
  14823. }
  14824. }
  14825. } else if (compiled.has(material) === false) {
  14826. initMaterial(material, scene, object);
  14827. compiled.set(material);
  14828. }
  14829. }
  14830. });
  14831. }; // Animation Loop
  14832. var onAnimationFrameCallback = null;
  14833. function onAnimationFrame(time) {
  14834. if (xr.isPresenting) return;
  14835. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  14836. }
  14837. var animation = new WebGLAnimation();
  14838. animation.setAnimationLoop(onAnimationFrame);
  14839. if (typeof window !== 'undefined') animation.setContext(window);
  14840. this.setAnimationLoop = function (callback) {
  14841. onAnimationFrameCallback = callback;
  14842. xr.setAnimationLoop(callback);
  14843. callback === null ? animation.stop() : animation.start();
  14844. }; // Rendering
  14845. this.render = function (scene, camera) {
  14846. var renderTarget, forceClear;
  14847. if (arguments[2] !== undefined) {
  14848. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  14849. renderTarget = arguments[2];
  14850. }
  14851. if (arguments[3] !== undefined) {
  14852. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  14853. forceClear = arguments[3];
  14854. }
  14855. if (camera !== undefined && camera.isCamera !== true) {
  14856. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  14857. return;
  14858. }
  14859. if (_isContextLost === true) return; // reset caching for this frame
  14860. bindingStates.resetDefaultState();
  14861. _currentMaterialId = -1;
  14862. _currentCamera = null; // update scene graph
  14863. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  14864. if (camera.parent === null) camera.updateMatrixWorld();
  14865. if (xr.enabled === true && xr.isPresenting === true) {
  14866. camera = xr.getCamera(camera);
  14867. } //
  14868. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  14869. currentRenderState = renderStates.get(scene, renderStateStack.length);
  14870. currentRenderState.init();
  14871. renderStateStack.push(currentRenderState);
  14872. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  14873. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  14874. _localClippingEnabled = this.localClippingEnabled;
  14875. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  14876. currentRenderList = renderLists.get(scene, camera);
  14877. currentRenderList.init();
  14878. projectObject(scene, camera, 0, _this.sortObjects);
  14879. currentRenderList.finish();
  14880. if (_this.sortObjects === true) {
  14881. currentRenderList.sort(_opaqueSort, _transparentSort);
  14882. } //
  14883. if (_clippingEnabled === true) clipping.beginShadows();
  14884. var shadowsArray = currentRenderState.state.shadowsArray;
  14885. shadowMap.render(shadowsArray, scene, camera);
  14886. currentRenderState.setupLights();
  14887. currentRenderState.setupLightsView(camera);
  14888. if (_clippingEnabled === true) clipping.endShadows(); //
  14889. if (this.info.autoReset === true) this.info.reset();
  14890. if (renderTarget !== undefined) {
  14891. this.setRenderTarget(renderTarget);
  14892. } //
  14893. background.render(currentRenderList, scene, camera, forceClear); // render scene
  14894. var opaqueObjects = currentRenderList.opaque;
  14895. var transparentObjects = currentRenderList.transparent;
  14896. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  14897. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  14898. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  14899. if (_currentRenderTarget !== null) {
  14900. // Generate mipmap if we're using any kind of mipmap filtering
  14901. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  14902. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  14903. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  14904. state.buffers.depth.setTest(true);
  14905. state.buffers.depth.setMask(true);
  14906. state.buffers.color.setMask(true);
  14907. state.setPolygonOffset(false); // _gl.finish();
  14908. renderStateStack.pop();
  14909. if (renderStateStack.length > 0) {
  14910. currentRenderState = renderStateStack[renderStateStack.length - 1];
  14911. } else {
  14912. currentRenderState = null;
  14913. }
  14914. currentRenderList = null;
  14915. };
  14916. function projectObject(object, camera, groupOrder, sortObjects) {
  14917. if (object.visible === false) return;
  14918. var visible = object.layers.test(camera.layers);
  14919. if (visible) {
  14920. if (object.isGroup) {
  14921. groupOrder = object.renderOrder;
  14922. } else if (object.isLOD) {
  14923. if (object.autoUpdate === true) object.update(camera);
  14924. } else if (object.isLight) {
  14925. currentRenderState.pushLight(object);
  14926. if (object.castShadow) {
  14927. currentRenderState.pushShadow(object);
  14928. }
  14929. } else if (object.isSprite) {
  14930. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  14931. if (sortObjects) {
  14932. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14933. }
  14934. var geometry = objects.update(object);
  14935. var material = object.material;
  14936. if (material.visible) {
  14937. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  14938. }
  14939. }
  14940. } else if (object.isImmediateRenderObject) {
  14941. if (sortObjects) {
  14942. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14943. }
  14944. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  14945. } else if (object.isMesh || object.isLine || object.isPoints) {
  14946. if (object.isSkinnedMesh) {
  14947. // update skeleton only once in a frame
  14948. if (object.skeleton.frame !== info.render.frame) {
  14949. object.skeleton.update();
  14950. object.skeleton.frame = info.render.frame;
  14951. }
  14952. }
  14953. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  14954. if (sortObjects) {
  14955. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14956. }
  14957. var _geometry = objects.update(object);
  14958. var _material = object.material;
  14959. if (Array.isArray(_material)) {
  14960. var groups = _geometry.groups;
  14961. for (var i = 0, l = groups.length; i < l; i++) {
  14962. var group = groups[i];
  14963. var groupMaterial = _material[group.materialIndex];
  14964. if (groupMaterial && groupMaterial.visible) {
  14965. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  14966. }
  14967. }
  14968. } else if (_material.visible) {
  14969. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  14970. }
  14971. }
  14972. }
  14973. }
  14974. var children = object.children;
  14975. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  14976. projectObject(children[_i], camera, groupOrder, sortObjects);
  14977. }
  14978. }
  14979. function renderObjects(renderList, scene, camera) {
  14980. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  14981. for (var i = 0, l = renderList.length; i < l; i++) {
  14982. var renderItem = renderList[i];
  14983. var object = renderItem.object;
  14984. var geometry = renderItem.geometry;
  14985. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  14986. var group = renderItem.group;
  14987. if (camera.isArrayCamera) {
  14988. var cameras = camera.cameras;
  14989. for (var j = 0, jl = cameras.length; j < jl; j++) {
  14990. var camera2 = cameras[j];
  14991. if (object.layers.test(camera2.layers)) {
  14992. state.viewport(_currentViewport.copy(camera2.viewport));
  14993. currentRenderState.setupLightsView(camera2);
  14994. renderObject(object, scene, camera2, geometry, material, group);
  14995. }
  14996. }
  14997. } else {
  14998. renderObject(object, scene, camera, geometry, material, group);
  14999. }
  15000. }
  15001. }
  15002. function renderObject(object, scene, camera, geometry, material, group) {
  15003. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  15004. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  15005. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  15006. if (object.isImmediateRenderObject) {
  15007. var program = setProgram(camera, scene, material, object);
  15008. state.setMaterial(material);
  15009. bindingStates.reset();
  15010. renderObjectImmediate(object, program);
  15011. } else {
  15012. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  15013. }
  15014. object.onAfterRender(_this, scene, camera, geometry, material, group);
  15015. }
  15016. function initMaterial(material, scene, object) {
  15017. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15018. var materialProperties = properties.get(material);
  15019. var lights = currentRenderState.state.lights;
  15020. var shadowsArray = currentRenderState.state.shadowsArray;
  15021. var lightsStateVersion = lights.state.version;
  15022. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  15023. var programCacheKey = programCache.getProgramCacheKey(parameters);
  15024. var program = materialProperties.program;
  15025. var programChange = true;
  15026. if (program === undefined) {
  15027. // new material
  15028. material.addEventListener('dispose', onMaterialDispose);
  15029. } else if (program.cacheKey !== programCacheKey) {
  15030. // changed glsl or parameters
  15031. releaseMaterialProgramReference(material);
  15032. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  15033. programChange = false;
  15034. } else if (parameters.shaderID !== undefined) {
  15035. // same glsl and uniform list, envMap still needs the update here to avoid a frame-late effect
  15036. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15037. materialProperties.envMap = cubemaps.get(material.envMap || environment);
  15038. return;
  15039. } else {
  15040. // only rebuild uniform list
  15041. programChange = false;
  15042. }
  15043. if (programChange) {
  15044. parameters.uniforms = programCache.getUniforms(material);
  15045. material.onBeforeCompile(parameters, _this);
  15046. program = programCache.acquireProgram(parameters, programCacheKey);
  15047. materialProperties.program = program;
  15048. materialProperties.uniforms = parameters.uniforms;
  15049. materialProperties.outputEncoding = parameters.outputEncoding;
  15050. }
  15051. var uniforms = materialProperties.uniforms;
  15052. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  15053. materialProperties.numClippingPlanes = clipping.numPlanes;
  15054. materialProperties.numIntersection = clipping.numIntersection;
  15055. uniforms.clippingPlanes = clipping.uniform;
  15056. }
  15057. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15058. materialProperties.fog = scene.fog;
  15059. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment); // store the light setup it was created for
  15060. materialProperties.needsLights = materialNeedsLights(material);
  15061. materialProperties.lightsStateVersion = lightsStateVersion;
  15062. if (materialProperties.needsLights) {
  15063. // wire up the material to this renderer's lighting state
  15064. uniforms.ambientLightColor.value = lights.state.ambient;
  15065. uniforms.lightProbe.value = lights.state.probe;
  15066. uniforms.directionalLights.value = lights.state.directional;
  15067. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15068. uniforms.spotLights.value = lights.state.spot;
  15069. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15070. uniforms.rectAreaLights.value = lights.state.rectArea;
  15071. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  15072. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  15073. uniforms.pointLights.value = lights.state.point;
  15074. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15075. uniforms.hemisphereLights.value = lights.state.hemi;
  15076. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15077. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15078. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15079. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15080. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15081. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  15082. }
  15083. var progUniforms = materialProperties.program.getUniforms();
  15084. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  15085. materialProperties.uniformsList = uniformsList;
  15086. }
  15087. function setProgram(camera, scene, material, object) {
  15088. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15089. textures.resetTextureUnits();
  15090. var fog = scene.fog;
  15091. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15092. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15093. var envMap = cubemaps.get(material.envMap || environment);
  15094. var materialProperties = properties.get(material);
  15095. var lights = currentRenderState.state.lights;
  15096. if (_clippingEnabled === true) {
  15097. if (_localClippingEnabled === true || camera !== _currentCamera) {
  15098. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  15099. // object instead of the material, once it becomes feasible
  15100. // (#8465, #8379)
  15101. clipping.setState(material, camera, useCache);
  15102. }
  15103. }
  15104. if (material.version === materialProperties.__version) {
  15105. if (material.fog && materialProperties.fog !== fog) {
  15106. initMaterial(material, scene, object);
  15107. } else if (materialProperties.environment !== environment) {
  15108. initMaterial(material, scene, object);
  15109. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  15110. initMaterial(material, scene, object);
  15111. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  15112. initMaterial(material, scene, object);
  15113. } else if (materialProperties.outputEncoding !== encoding) {
  15114. initMaterial(material, scene, object);
  15115. } else if (materialProperties.envMap !== envMap) {
  15116. initMaterial(material, scene, object);
  15117. }
  15118. } else {
  15119. initMaterial(material, scene, object);
  15120. materialProperties.__version = material.version;
  15121. }
  15122. var refreshProgram = false;
  15123. var refreshMaterial = false;
  15124. var refreshLights = false;
  15125. var program = materialProperties.program,
  15126. p_uniforms = program.getUniforms(),
  15127. m_uniforms = materialProperties.uniforms;
  15128. if (state.useProgram(program.program)) {
  15129. refreshProgram = true;
  15130. refreshMaterial = true;
  15131. refreshLights = true;
  15132. }
  15133. if (material.id !== _currentMaterialId) {
  15134. _currentMaterialId = material.id;
  15135. refreshMaterial = true;
  15136. }
  15137. if (refreshProgram || _currentCamera !== camera) {
  15138. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  15139. if (capabilities.logarithmicDepthBuffer) {
  15140. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  15141. }
  15142. if (_currentCamera !== camera) {
  15143. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  15144. // now, in case this material supports lights - or later, when
  15145. // the next material that does gets activated:
  15146. refreshMaterial = true; // set to true on material change
  15147. refreshLights = true; // remains set until update done
  15148. } // load material specific uniforms
  15149. // (shader material also gets them for the sake of genericity)
  15150. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  15151. var uCamPos = p_uniforms.map.cameraPosition;
  15152. if (uCamPos !== undefined) {
  15153. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  15154. }
  15155. }
  15156. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  15157. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  15158. }
  15159. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  15160. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  15161. }
  15162. } // skinning uniforms must be set even if material didn't change
  15163. // auto-setting of texture unit for bone texture must go before other textures
  15164. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15165. if (material.skinning) {
  15166. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  15167. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  15168. var skeleton = object.skeleton;
  15169. if (skeleton) {
  15170. var bones = skeleton.bones;
  15171. if (capabilities.floatVertexTextures) {
  15172. if (skeleton.boneTexture === null) {
  15173. // layout (1 matrix = 4 pixels)
  15174. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15175. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15176. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15177. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15178. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15179. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  15180. size = MathUtils.ceilPowerOfTwo(size);
  15181. size = Math.max(size, 4);
  15182. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  15183. boneMatrices.set(skeleton.boneMatrices); // copy current values
  15184. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  15185. skeleton.boneMatrices = boneMatrices;
  15186. skeleton.boneTexture = boneTexture;
  15187. skeleton.boneTextureSize = size;
  15188. }
  15189. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  15190. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  15191. } else {
  15192. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  15193. }
  15194. }
  15195. }
  15196. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  15197. materialProperties.receiveShadow = object.receiveShadow;
  15198. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  15199. }
  15200. if (refreshMaterial) {
  15201. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  15202. if (materialProperties.needsLights) {
  15203. // the current material requires lighting info
  15204. // note: all lighting uniforms are always set correctly
  15205. // they simply reference the renderer's state for their
  15206. // values
  15207. //
  15208. // use the current material's .needsUpdate flags to set
  15209. // the GL state when required
  15210. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  15211. } // refresh uniforms common to several materials
  15212. if (fog && material.fog) {
  15213. materials.refreshFogUniforms(m_uniforms, fog);
  15214. }
  15215. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  15216. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15217. }
  15218. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  15219. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15220. material.uniformsNeedUpdate = false;
  15221. }
  15222. if (material.isSpriteMaterial) {
  15223. p_uniforms.setValue(_gl, 'center', object.center);
  15224. } // common matrices
  15225. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  15226. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  15227. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  15228. return program;
  15229. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15230. function markUniformsLightsNeedsUpdate(uniforms, value) {
  15231. uniforms.ambientLightColor.needsUpdate = value;
  15232. uniforms.lightProbe.needsUpdate = value;
  15233. uniforms.directionalLights.needsUpdate = value;
  15234. uniforms.directionalLightShadows.needsUpdate = value;
  15235. uniforms.pointLights.needsUpdate = value;
  15236. uniforms.pointLightShadows.needsUpdate = value;
  15237. uniforms.spotLights.needsUpdate = value;
  15238. uniforms.spotLightShadows.needsUpdate = value;
  15239. uniforms.rectAreaLights.needsUpdate = value;
  15240. uniforms.hemisphereLights.needsUpdate = value;
  15241. }
  15242. function materialNeedsLights(material) {
  15243. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  15244. } //
  15245. this.setFramebuffer = function (value) {
  15246. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  15247. _framebuffer = value;
  15248. };
  15249. this.getActiveCubeFace = function () {
  15250. return _currentActiveCubeFace;
  15251. };
  15252. this.getActiveMipmapLevel = function () {
  15253. return _currentActiveMipmapLevel;
  15254. };
  15255. this.getRenderList = function () {
  15256. return currentRenderList;
  15257. };
  15258. this.setRenderList = function (renderList) {
  15259. currentRenderList = renderList;
  15260. };
  15261. this.getRenderTarget = function () {
  15262. return _currentRenderTarget;
  15263. };
  15264. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15265. if (activeCubeFace === void 0) {
  15266. activeCubeFace = 0;
  15267. }
  15268. if (activeMipmapLevel === void 0) {
  15269. activeMipmapLevel = 0;
  15270. }
  15271. _currentRenderTarget = renderTarget;
  15272. _currentActiveCubeFace = activeCubeFace;
  15273. _currentActiveMipmapLevel = activeMipmapLevel;
  15274. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15275. textures.setupRenderTarget(renderTarget);
  15276. }
  15277. var framebuffer = _framebuffer;
  15278. var isCube = false;
  15279. if (renderTarget) {
  15280. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15281. if (renderTarget.isWebGLCubeRenderTarget) {
  15282. framebuffer = __webglFramebuffer[activeCubeFace];
  15283. isCube = true;
  15284. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15285. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15286. } else {
  15287. framebuffer = __webglFramebuffer;
  15288. }
  15289. _currentViewport.copy(renderTarget.viewport);
  15290. _currentScissor.copy(renderTarget.scissor);
  15291. _currentScissorTest = renderTarget.scissorTest;
  15292. } else {
  15293. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15294. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15295. _currentScissorTest = _scissorTest;
  15296. }
  15297. if (_currentFramebuffer !== framebuffer) {
  15298. _gl.bindFramebuffer(36160, framebuffer);
  15299. _currentFramebuffer = framebuffer;
  15300. }
  15301. state.viewport(_currentViewport);
  15302. state.scissor(_currentScissor);
  15303. state.setScissorTest(_currentScissorTest);
  15304. if (isCube) {
  15305. var textureProperties = properties.get(renderTarget.texture);
  15306. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15307. }
  15308. };
  15309. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15310. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15311. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15312. return;
  15313. }
  15314. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15315. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15316. framebuffer = framebuffer[activeCubeFaceIndex];
  15317. }
  15318. if (framebuffer) {
  15319. var restore = false;
  15320. if (framebuffer !== _currentFramebuffer) {
  15321. _gl.bindFramebuffer(36160, framebuffer);
  15322. restore = true;
  15323. }
  15324. try {
  15325. var texture = renderTarget.texture;
  15326. var textureFormat = texture.format;
  15327. var textureType = texture.type;
  15328. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15329. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15330. return;
  15331. }
  15332. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15333. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.get('OES_texture_float') || extensions.get('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15334. !(textureType === HalfFloatType && (capabilities.isWebGL2 ? extensions.get('EXT_color_buffer_float') : extensions.get('EXT_color_buffer_half_float')))) {
  15335. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15336. return;
  15337. }
  15338. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15339. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15340. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15341. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15342. }
  15343. } else {
  15344. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15345. }
  15346. } finally {
  15347. if (restore) {
  15348. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15349. }
  15350. }
  15351. }
  15352. };
  15353. this.copyFramebufferToTexture = function (position, texture, level) {
  15354. if (level === void 0) {
  15355. level = 0;
  15356. }
  15357. var levelScale = Math.pow(2, -level);
  15358. var width = Math.floor(texture.image.width * levelScale);
  15359. var height = Math.floor(texture.image.height * levelScale);
  15360. var glFormat = utils.convert(texture.format);
  15361. textures.setTexture2D(texture, 0);
  15362. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15363. state.unbindTexture();
  15364. };
  15365. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15366. if (level === void 0) {
  15367. level = 0;
  15368. }
  15369. var width = srcTexture.image.width;
  15370. var height = srcTexture.image.height;
  15371. var glFormat = utils.convert(dstTexture.format);
  15372. var glType = utils.convert(dstTexture.type);
  15373. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15374. // parameters, make sure they are correct for the dstTexture
  15375. _gl.pixelStorei(37440, dstTexture.flipY);
  15376. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15377. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15378. if (srcTexture.isDataTexture) {
  15379. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15380. } else {
  15381. if (srcTexture.isCompressedTexture) {
  15382. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15383. } else {
  15384. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15385. }
  15386. } // Generate mipmaps only when copying level 0
  15387. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15388. state.unbindTexture();
  15389. };
  15390. this.initTexture = function (texture) {
  15391. textures.setTexture2D(texture, 0);
  15392. state.unbindTexture();
  15393. };
  15394. this.resetState = function () {
  15395. state.reset();
  15396. bindingStates.reset();
  15397. };
  15398. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15399. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15400. detail: this
  15401. })); // eslint-disable-line no-undef
  15402. }
  15403. }
  15404. function WebGL1Renderer(parameters) {
  15405. WebGLRenderer.call(this, parameters);
  15406. }
  15407. WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
  15408. constructor: WebGL1Renderer,
  15409. isWebGL1Renderer: true
  15410. });
  15411. var FogExp2 = /*#__PURE__*/function () {
  15412. function FogExp2(color, density) {
  15413. Object.defineProperty(this, 'isFogExp2', {
  15414. value: true
  15415. });
  15416. this.name = '';
  15417. this.color = new Color(color);
  15418. this.density = density !== undefined ? density : 0.00025;
  15419. }
  15420. var _proto = FogExp2.prototype;
  15421. _proto.clone = function clone() {
  15422. return new FogExp2(this.color, this.density);
  15423. };
  15424. _proto.toJSON = function toJSON()
  15425. /* meta */
  15426. {
  15427. return {
  15428. type: 'FogExp2',
  15429. color: this.color.getHex(),
  15430. density: this.density
  15431. };
  15432. };
  15433. return FogExp2;
  15434. }();
  15435. var Fog = /*#__PURE__*/function () {
  15436. function Fog(color, near, far) {
  15437. Object.defineProperty(this, 'isFog', {
  15438. value: true
  15439. });
  15440. this.name = '';
  15441. this.color = new Color(color);
  15442. this.near = near !== undefined ? near : 1;
  15443. this.far = far !== undefined ? far : 1000;
  15444. }
  15445. var _proto = Fog.prototype;
  15446. _proto.clone = function clone() {
  15447. return new Fog(this.color, this.near, this.far);
  15448. };
  15449. _proto.toJSON = function toJSON()
  15450. /* meta */
  15451. {
  15452. return {
  15453. type: 'Fog',
  15454. color: this.color.getHex(),
  15455. near: this.near,
  15456. far: this.far
  15457. };
  15458. };
  15459. return Fog;
  15460. }();
  15461. var Scene = /*#__PURE__*/function (_Object3D) {
  15462. _inheritsLoose(Scene, _Object3D);
  15463. function Scene() {
  15464. var _this;
  15465. _this = _Object3D.call(this) || this;
  15466. Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
  15467. value: true
  15468. });
  15469. _this.type = 'Scene';
  15470. _this.background = null;
  15471. _this.environment = null;
  15472. _this.fog = null;
  15473. _this.overrideMaterial = null;
  15474. _this.autoUpdate = true; // checked by the renderer
  15475. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15476. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15477. detail: _assertThisInitialized(_this)
  15478. })); // eslint-disable-line no-undef
  15479. }
  15480. return _this;
  15481. }
  15482. var _proto = Scene.prototype;
  15483. _proto.copy = function copy(source, recursive) {
  15484. _Object3D.prototype.copy.call(this, source, recursive);
  15485. if (source.background !== null) this.background = source.background.clone();
  15486. if (source.environment !== null) this.environment = source.environment.clone();
  15487. if (source.fog !== null) this.fog = source.fog.clone();
  15488. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  15489. this.autoUpdate = source.autoUpdate;
  15490. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15491. return this;
  15492. };
  15493. _proto.toJSON = function toJSON(meta) {
  15494. var data = _Object3D.prototype.toJSON.call(this, meta);
  15495. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  15496. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  15497. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  15498. return data;
  15499. };
  15500. return Scene;
  15501. }(Object3D);
  15502. function InterleavedBuffer(array, stride) {
  15503. this.array = array;
  15504. this.stride = stride;
  15505. this.count = array !== undefined ? array.length / stride : 0;
  15506. this.usage = StaticDrawUsage;
  15507. this.updateRange = {
  15508. offset: 0,
  15509. count: -1
  15510. };
  15511. this.version = 0;
  15512. this.uuid = MathUtils.generateUUID();
  15513. }
  15514. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  15515. set: function set(value) {
  15516. if (value === true) this.version++;
  15517. }
  15518. });
  15519. Object.assign(InterleavedBuffer.prototype, {
  15520. isInterleavedBuffer: true,
  15521. onUploadCallback: function onUploadCallback() {},
  15522. setUsage: function setUsage(value) {
  15523. this.usage = value;
  15524. return this;
  15525. },
  15526. copy: function copy(source) {
  15527. this.array = new source.array.constructor(source.array);
  15528. this.count = source.count;
  15529. this.stride = source.stride;
  15530. this.usage = source.usage;
  15531. return this;
  15532. },
  15533. copyAt: function copyAt(index1, attribute, index2) {
  15534. index1 *= this.stride;
  15535. index2 *= attribute.stride;
  15536. for (var i = 0, l = this.stride; i < l; i++) {
  15537. this.array[index1 + i] = attribute.array[index2 + i];
  15538. }
  15539. return this;
  15540. },
  15541. set: function set(value, offset) {
  15542. if (offset === void 0) {
  15543. offset = 0;
  15544. }
  15545. this.array.set(value, offset);
  15546. return this;
  15547. },
  15548. clone: function clone(data) {
  15549. if (data.arrayBuffers === undefined) {
  15550. data.arrayBuffers = {};
  15551. }
  15552. if (this.array.buffer._uuid === undefined) {
  15553. this.array.buffer._uuid = MathUtils.generateUUID();
  15554. }
  15555. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15556. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  15557. }
  15558. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  15559. var ib = new InterleavedBuffer(array, this.stride);
  15560. ib.setUsage(this.usage);
  15561. return ib;
  15562. },
  15563. onUpload: function onUpload(callback) {
  15564. this.onUploadCallback = callback;
  15565. return this;
  15566. },
  15567. toJSON: function toJSON(data) {
  15568. if (data.arrayBuffers === undefined) {
  15569. data.arrayBuffers = {};
  15570. } // generate UUID for array buffer if necessary
  15571. if (this.array.buffer._uuid === undefined) {
  15572. this.array.buffer._uuid = MathUtils.generateUUID();
  15573. }
  15574. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15575. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  15576. } //
  15577. return {
  15578. uuid: this.uuid,
  15579. buffer: this.array.buffer._uuid,
  15580. type: this.array.constructor.name,
  15581. stride: this.stride
  15582. };
  15583. }
  15584. });
  15585. var _vector$6 = new Vector3();
  15586. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  15587. this.name = '';
  15588. this.data = interleavedBuffer;
  15589. this.itemSize = itemSize;
  15590. this.offset = offset;
  15591. this.normalized = normalized === true;
  15592. }
  15593. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  15594. count: {
  15595. get: function get() {
  15596. return this.data.count;
  15597. }
  15598. },
  15599. array: {
  15600. get: function get() {
  15601. return this.data.array;
  15602. }
  15603. },
  15604. needsUpdate: {
  15605. set: function set(value) {
  15606. this.data.needsUpdate = value;
  15607. }
  15608. }
  15609. });
  15610. Object.assign(InterleavedBufferAttribute.prototype, {
  15611. isInterleavedBufferAttribute: true,
  15612. applyMatrix4: function applyMatrix4(m) {
  15613. for (var i = 0, l = this.data.count; i < l; i++) {
  15614. _vector$6.x = this.getX(i);
  15615. _vector$6.y = this.getY(i);
  15616. _vector$6.z = this.getZ(i);
  15617. _vector$6.applyMatrix4(m);
  15618. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  15619. }
  15620. return this;
  15621. },
  15622. setX: function setX(index, x) {
  15623. this.data.array[index * this.data.stride + this.offset] = x;
  15624. return this;
  15625. },
  15626. setY: function setY(index, y) {
  15627. this.data.array[index * this.data.stride + this.offset + 1] = y;
  15628. return this;
  15629. },
  15630. setZ: function setZ(index, z) {
  15631. this.data.array[index * this.data.stride + this.offset + 2] = z;
  15632. return this;
  15633. },
  15634. setW: function setW(index, w) {
  15635. this.data.array[index * this.data.stride + this.offset + 3] = w;
  15636. return this;
  15637. },
  15638. getX: function getX(index) {
  15639. return this.data.array[index * this.data.stride + this.offset];
  15640. },
  15641. getY: function getY(index) {
  15642. return this.data.array[index * this.data.stride + this.offset + 1];
  15643. },
  15644. getZ: function getZ(index) {
  15645. return this.data.array[index * this.data.stride + this.offset + 2];
  15646. },
  15647. getW: function getW(index) {
  15648. return this.data.array[index * this.data.stride + this.offset + 3];
  15649. },
  15650. setXY: function setXY(index, x, y) {
  15651. index = index * this.data.stride + this.offset;
  15652. this.data.array[index + 0] = x;
  15653. this.data.array[index + 1] = y;
  15654. return this;
  15655. },
  15656. setXYZ: function setXYZ(index, x, y, z) {
  15657. index = index * this.data.stride + this.offset;
  15658. this.data.array[index + 0] = x;
  15659. this.data.array[index + 1] = y;
  15660. this.data.array[index + 2] = z;
  15661. return this;
  15662. },
  15663. setXYZW: function setXYZW(index, x, y, z, w) {
  15664. index = index * this.data.stride + this.offset;
  15665. this.data.array[index + 0] = x;
  15666. this.data.array[index + 1] = y;
  15667. this.data.array[index + 2] = z;
  15668. this.data.array[index + 3] = w;
  15669. return this;
  15670. },
  15671. clone: function clone(data) {
  15672. if (data === undefined) {
  15673. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  15674. var array = [];
  15675. for (var i = 0; i < this.count; i++) {
  15676. var index = i * this.data.stride + this.offset;
  15677. for (var j = 0; j < this.itemSize; j++) {
  15678. array.push(this.data.array[index + j]);
  15679. }
  15680. }
  15681. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  15682. } else {
  15683. if (data.interleavedBuffers === undefined) {
  15684. data.interleavedBuffers = {};
  15685. }
  15686. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15687. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  15688. }
  15689. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  15690. }
  15691. },
  15692. toJSON: function toJSON(data) {
  15693. if (data === undefined) {
  15694. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  15695. var array = [];
  15696. for (var i = 0; i < this.count; i++) {
  15697. var index = i * this.data.stride + this.offset;
  15698. for (var j = 0; j < this.itemSize; j++) {
  15699. array.push(this.data.array[index + j]);
  15700. }
  15701. } // deinterleave data and save it as an ordinary buffer attribute for now
  15702. return {
  15703. itemSize: this.itemSize,
  15704. type: this.array.constructor.name,
  15705. array: array,
  15706. normalized: this.normalized
  15707. };
  15708. } else {
  15709. // save as true interlaved attribtue
  15710. if (data.interleavedBuffers === undefined) {
  15711. data.interleavedBuffers = {};
  15712. }
  15713. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15714. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  15715. }
  15716. return {
  15717. isInterleavedBufferAttribute: true,
  15718. itemSize: this.itemSize,
  15719. data: this.data.uuid,
  15720. offset: this.offset,
  15721. normalized: this.normalized
  15722. };
  15723. }
  15724. }
  15725. });
  15726. /**
  15727. * parameters = {
  15728. * color: <hex>,
  15729. * map: new THREE.Texture( <Image> ),
  15730. * alphaMap: new THREE.Texture( <Image> ),
  15731. * rotation: <float>,
  15732. * sizeAttenuation: <bool>
  15733. * }
  15734. */
  15735. function SpriteMaterial(parameters) {
  15736. Material.call(this);
  15737. this.type = 'SpriteMaterial';
  15738. this.color = new Color(0xffffff);
  15739. this.map = null;
  15740. this.alphaMap = null;
  15741. this.rotation = 0;
  15742. this.sizeAttenuation = true;
  15743. this.transparent = true;
  15744. this.setValues(parameters);
  15745. }
  15746. SpriteMaterial.prototype = Object.create(Material.prototype);
  15747. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15748. SpriteMaterial.prototype.isSpriteMaterial = true;
  15749. SpriteMaterial.prototype.copy = function (source) {
  15750. Material.prototype.copy.call(this, source);
  15751. this.color.copy(source.color);
  15752. this.map = source.map;
  15753. this.alphaMap = source.alphaMap;
  15754. this.rotation = source.rotation;
  15755. this.sizeAttenuation = source.sizeAttenuation;
  15756. return this;
  15757. };
  15758. var _geometry;
  15759. var _intersectPoint = new Vector3();
  15760. var _worldScale = new Vector3();
  15761. var _mvPosition = new Vector3();
  15762. var _alignedPosition = new Vector2();
  15763. var _rotatedPosition = new Vector2();
  15764. var _viewWorldMatrix = new Matrix4();
  15765. var _vA$1 = new Vector3();
  15766. var _vB$1 = new Vector3();
  15767. var _vC$1 = new Vector3();
  15768. var _uvA$1 = new Vector2();
  15769. var _uvB$1 = new Vector2();
  15770. var _uvC$1 = new Vector2();
  15771. function Sprite(material) {
  15772. Object3D.call(this);
  15773. this.type = 'Sprite';
  15774. if (_geometry === undefined) {
  15775. _geometry = new BufferGeometry();
  15776. 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]);
  15777. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  15778. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  15779. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  15780. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  15781. }
  15782. this.geometry = _geometry;
  15783. this.material = material !== undefined ? material : new SpriteMaterial();
  15784. this.center = new Vector2(0.5, 0.5);
  15785. }
  15786. Sprite.prototype = Object.assign(Object.create(Object3D.prototype), {
  15787. constructor: Sprite,
  15788. isSprite: true,
  15789. raycast: function raycast(raycaster, intersects) {
  15790. if (raycaster.camera === null) {
  15791. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  15792. }
  15793. _worldScale.setFromMatrixScale(this.matrixWorld);
  15794. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  15795. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  15796. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  15797. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  15798. _worldScale.multiplyScalar(-_mvPosition.z);
  15799. }
  15800. var rotation = this.material.rotation;
  15801. var sin, cos;
  15802. if (rotation !== 0) {
  15803. cos = Math.cos(rotation);
  15804. sin = Math.sin(rotation);
  15805. }
  15806. var center = this.center;
  15807. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15808. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15809. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15810. _uvA$1.set(0, 0);
  15811. _uvB$1.set(1, 0);
  15812. _uvC$1.set(1, 1); // check first triangle
  15813. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  15814. if (intersect === null) {
  15815. // check second triangle
  15816. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15817. _uvB$1.set(0, 1);
  15818. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  15819. if (intersect === null) {
  15820. return;
  15821. }
  15822. }
  15823. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  15824. if (distance < raycaster.near || distance > raycaster.far) return;
  15825. intersects.push({
  15826. distance: distance,
  15827. point: _intersectPoint.clone(),
  15828. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  15829. face: null,
  15830. object: this
  15831. });
  15832. },
  15833. copy: function copy(source) {
  15834. Object3D.prototype.copy.call(this, source);
  15835. if (source.center !== undefined) this.center.copy(source.center);
  15836. this.material = source.material;
  15837. return this;
  15838. }
  15839. });
  15840. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  15841. // compute position in camera space
  15842. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  15843. if (sin !== undefined) {
  15844. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  15845. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  15846. } else {
  15847. _rotatedPosition.copy(_alignedPosition);
  15848. }
  15849. vertexPosition.copy(mvPosition);
  15850. vertexPosition.x += _rotatedPosition.x;
  15851. vertexPosition.y += _rotatedPosition.y; // transform to world space
  15852. vertexPosition.applyMatrix4(_viewWorldMatrix);
  15853. }
  15854. var _v1$4 = new Vector3();
  15855. var _v2$2 = new Vector3();
  15856. function LOD() {
  15857. Object3D.call(this);
  15858. this._currentLevel = 0;
  15859. this.type = 'LOD';
  15860. Object.defineProperties(this, {
  15861. levels: {
  15862. enumerable: true,
  15863. value: []
  15864. }
  15865. });
  15866. this.autoUpdate = true;
  15867. }
  15868. LOD.prototype = Object.assign(Object.create(Object3D.prototype), {
  15869. constructor: LOD,
  15870. isLOD: true,
  15871. copy: function copy(source) {
  15872. Object3D.prototype.copy.call(this, source, false);
  15873. var levels = source.levels;
  15874. for (var i = 0, l = levels.length; i < l; i++) {
  15875. var level = levels[i];
  15876. this.addLevel(level.object.clone(), level.distance);
  15877. }
  15878. this.autoUpdate = source.autoUpdate;
  15879. return this;
  15880. },
  15881. addLevel: function addLevel(object, distance) {
  15882. if (distance === void 0) {
  15883. distance = 0;
  15884. }
  15885. distance = Math.abs(distance);
  15886. var levels = this.levels;
  15887. var l;
  15888. for (l = 0; l < levels.length; l++) {
  15889. if (distance < levels[l].distance) {
  15890. break;
  15891. }
  15892. }
  15893. levels.splice(l, 0, {
  15894. distance: distance,
  15895. object: object
  15896. });
  15897. this.add(object);
  15898. return this;
  15899. },
  15900. getCurrentLevel: function getCurrentLevel() {
  15901. return this._currentLevel;
  15902. },
  15903. getObjectForDistance: function getObjectForDistance(distance) {
  15904. var levels = this.levels;
  15905. if (levels.length > 0) {
  15906. var i, l;
  15907. for (i = 1, l = levels.length; i < l; i++) {
  15908. if (distance < levels[i].distance) {
  15909. break;
  15910. }
  15911. }
  15912. return levels[i - 1].object;
  15913. }
  15914. return null;
  15915. },
  15916. raycast: function raycast(raycaster, intersects) {
  15917. var levels = this.levels;
  15918. if (levels.length > 0) {
  15919. _v1$4.setFromMatrixPosition(this.matrixWorld);
  15920. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  15921. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  15922. }
  15923. },
  15924. update: function update(camera) {
  15925. var levels = this.levels;
  15926. if (levels.length > 1) {
  15927. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  15928. _v2$2.setFromMatrixPosition(this.matrixWorld);
  15929. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  15930. levels[0].object.visible = true;
  15931. var i, l;
  15932. for (i = 1, l = levels.length; i < l; i++) {
  15933. if (distance >= levels[i].distance) {
  15934. levels[i - 1].object.visible = false;
  15935. levels[i].object.visible = true;
  15936. } else {
  15937. break;
  15938. }
  15939. }
  15940. this._currentLevel = i - 1;
  15941. for (; i < l; i++) {
  15942. levels[i].object.visible = false;
  15943. }
  15944. }
  15945. },
  15946. toJSON: function toJSON(meta) {
  15947. var data = Object3D.prototype.toJSON.call(this, meta);
  15948. if (this.autoUpdate === false) data.object.autoUpdate = false;
  15949. data.object.levels = [];
  15950. var levels = this.levels;
  15951. for (var i = 0, l = levels.length; i < l; i++) {
  15952. var level = levels[i];
  15953. data.object.levels.push({
  15954. object: level.object.uuid,
  15955. distance: level.distance
  15956. });
  15957. }
  15958. return data;
  15959. }
  15960. });
  15961. var _basePosition = new Vector3();
  15962. var _skinIndex = new Vector4();
  15963. var _skinWeight = new Vector4();
  15964. var _vector$7 = new Vector3();
  15965. var _matrix$1 = new Matrix4();
  15966. function SkinnedMesh(geometry, material) {
  15967. if (geometry && geometry.isGeometry) {
  15968. console.error('THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  15969. }
  15970. Mesh.call(this, geometry, material);
  15971. this.type = 'SkinnedMesh';
  15972. this.bindMode = 'attached';
  15973. this.bindMatrix = new Matrix4();
  15974. this.bindMatrixInverse = new Matrix4();
  15975. }
  15976. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  15977. constructor: SkinnedMesh,
  15978. isSkinnedMesh: true,
  15979. copy: function copy(source) {
  15980. Mesh.prototype.copy.call(this, source);
  15981. this.bindMode = source.bindMode;
  15982. this.bindMatrix.copy(source.bindMatrix);
  15983. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  15984. this.skeleton = source.skeleton;
  15985. return this;
  15986. },
  15987. bind: function bind(skeleton, bindMatrix) {
  15988. this.skeleton = skeleton;
  15989. if (bindMatrix === undefined) {
  15990. this.updateMatrixWorld(true);
  15991. this.skeleton.calculateInverses();
  15992. bindMatrix = this.matrixWorld;
  15993. }
  15994. this.bindMatrix.copy(bindMatrix);
  15995. this.bindMatrixInverse.copy(bindMatrix).invert();
  15996. },
  15997. pose: function pose() {
  15998. this.skeleton.pose();
  15999. },
  16000. normalizeSkinWeights: function normalizeSkinWeights() {
  16001. var vector = new Vector4();
  16002. var skinWeight = this.geometry.attributes.skinWeight;
  16003. for (var i = 0, l = skinWeight.count; i < l; i++) {
  16004. vector.x = skinWeight.getX(i);
  16005. vector.y = skinWeight.getY(i);
  16006. vector.z = skinWeight.getZ(i);
  16007. vector.w = skinWeight.getW(i);
  16008. var scale = 1.0 / vector.manhattanLength();
  16009. if (scale !== Infinity) {
  16010. vector.multiplyScalar(scale);
  16011. } else {
  16012. vector.set(1, 0, 0, 0); // do something reasonable
  16013. }
  16014. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  16015. }
  16016. },
  16017. updateMatrixWorld: function updateMatrixWorld(force) {
  16018. Mesh.prototype.updateMatrixWorld.call(this, force);
  16019. if (this.bindMode === 'attached') {
  16020. this.bindMatrixInverse.copy(this.matrixWorld).invert();
  16021. } else if (this.bindMode === 'detached') {
  16022. this.bindMatrixInverse.copy(this.bindMatrix).invert();
  16023. } else {
  16024. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  16025. }
  16026. },
  16027. boneTransform: function boneTransform(index, target) {
  16028. var skeleton = this.skeleton;
  16029. var geometry = this.geometry;
  16030. _skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  16031. _skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  16032. _basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  16033. target.set(0, 0, 0);
  16034. for (var i = 0; i < 4; i++) {
  16035. var weight = _skinWeight.getComponent(i);
  16036. if (weight !== 0) {
  16037. var boneIndex = _skinIndex.getComponent(i);
  16038. _matrix$1.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  16039. target.addScaledVector(_vector$7.copy(_basePosition).applyMatrix4(_matrix$1), weight);
  16040. }
  16041. }
  16042. return target.applyMatrix4(this.bindMatrixInverse);
  16043. }
  16044. });
  16045. function Bone() {
  16046. Object3D.call(this);
  16047. this.type = 'Bone';
  16048. }
  16049. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  16050. constructor: Bone,
  16051. isBone: true
  16052. });
  16053. var _offsetMatrix = new Matrix4();
  16054. var _identityMatrix = new Matrix4();
  16055. function Skeleton(bones, boneInverses) {
  16056. if (bones === void 0) {
  16057. bones = [];
  16058. }
  16059. if (boneInverses === void 0) {
  16060. boneInverses = [];
  16061. }
  16062. this.uuid = MathUtils.generateUUID();
  16063. this.bones = bones.slice(0);
  16064. this.boneInverses = boneInverses;
  16065. this.boneMatrices = null;
  16066. this.boneTexture = null;
  16067. this.boneTextureSize = 0;
  16068. this.frame = -1;
  16069. this.init();
  16070. }
  16071. Object.assign(Skeleton.prototype, {
  16072. init: function init() {
  16073. var bones = this.bones;
  16074. var boneInverses = this.boneInverses;
  16075. this.boneMatrices = new Float32Array(bones.length * 16); // calculate inverse bone matrices if necessary
  16076. if (boneInverses.length === 0) {
  16077. this.calculateInverses();
  16078. } else {
  16079. // handle special case
  16080. if (bones.length !== boneInverses.length) {
  16081. console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');
  16082. this.boneInverses = [];
  16083. for (var i = 0, il = this.bones.length; i < il; i++) {
  16084. this.boneInverses.push(new Matrix4());
  16085. }
  16086. }
  16087. }
  16088. },
  16089. calculateInverses: function calculateInverses() {
  16090. this.boneInverses.length = 0;
  16091. for (var i = 0, il = this.bones.length; i < il; i++) {
  16092. var inverse = new Matrix4();
  16093. if (this.bones[i]) {
  16094. inverse.copy(this.bones[i].matrixWorld).invert();
  16095. }
  16096. this.boneInverses.push(inverse);
  16097. }
  16098. },
  16099. pose: function pose() {
  16100. // recover the bind-time world matrices
  16101. for (var i = 0, il = this.bones.length; i < il; i++) {
  16102. var bone = this.bones[i];
  16103. if (bone) {
  16104. bone.matrixWorld.copy(this.boneInverses[i]).invert();
  16105. }
  16106. } // compute the local matrices, positions, rotations and scales
  16107. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  16108. var _bone = this.bones[_i];
  16109. if (_bone) {
  16110. if (_bone.parent && _bone.parent.isBone) {
  16111. _bone.matrix.copy(_bone.parent.matrixWorld).invert();
  16112. _bone.matrix.multiply(_bone.matrixWorld);
  16113. } else {
  16114. _bone.matrix.copy(_bone.matrixWorld);
  16115. }
  16116. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  16117. }
  16118. }
  16119. },
  16120. update: function update() {
  16121. var bones = this.bones;
  16122. var boneInverses = this.boneInverses;
  16123. var boneMatrices = this.boneMatrices;
  16124. var boneTexture = this.boneTexture; // flatten bone matrices to array
  16125. for (var i = 0, il = bones.length; i < il; i++) {
  16126. // compute the offset between the current and the original transform
  16127. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  16128. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  16129. _offsetMatrix.toArray(boneMatrices, i * 16);
  16130. }
  16131. if (boneTexture !== null) {
  16132. boneTexture.needsUpdate = true;
  16133. }
  16134. },
  16135. clone: function clone() {
  16136. return new Skeleton(this.bones, this.boneInverses);
  16137. },
  16138. getBoneByName: function getBoneByName(name) {
  16139. for (var i = 0, il = this.bones.length; i < il; i++) {
  16140. var bone = this.bones[i];
  16141. if (bone.name === name) {
  16142. return bone;
  16143. }
  16144. }
  16145. return undefined;
  16146. },
  16147. dispose: function dispose() {
  16148. if (this.boneTexture !== null) {
  16149. this.boneTexture.dispose();
  16150. this.boneTexture = null;
  16151. }
  16152. },
  16153. fromJSON: function fromJSON(json, bones) {
  16154. this.uuid = json.uuid;
  16155. for (var i = 0, l = json.bones.length; i < l; i++) {
  16156. var uuid = json.bones[i];
  16157. var bone = bones[uuid];
  16158. if (bone === undefined) {
  16159. console.warn('THREE.Skeleton: No bone found with UUID:', uuid);
  16160. bone = new Bone();
  16161. }
  16162. this.bones.push(bone);
  16163. this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
  16164. }
  16165. this.init();
  16166. return this;
  16167. },
  16168. toJSON: function toJSON() {
  16169. var data = {
  16170. metadata: {
  16171. version: 4.5,
  16172. type: 'Skeleton',
  16173. generator: 'Skeleton.toJSON'
  16174. },
  16175. bones: [],
  16176. boneInverses: []
  16177. };
  16178. data.uuid = this.uuid;
  16179. var bones = this.bones;
  16180. var boneInverses = this.boneInverses;
  16181. for (var i = 0, l = bones.length; i < l; i++) {
  16182. var bone = bones[i];
  16183. data.bones.push(bone.uuid);
  16184. var boneInverse = boneInverses[i];
  16185. data.boneInverses.push(boneInverse.toArray());
  16186. }
  16187. return data;
  16188. }
  16189. });
  16190. var _instanceLocalMatrix = new Matrix4();
  16191. var _instanceWorldMatrix = new Matrix4();
  16192. var _instanceIntersects = [];
  16193. var _mesh = new Mesh();
  16194. function InstancedMesh(geometry, material, count) {
  16195. Mesh.call(this, geometry, material);
  16196. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  16197. this.instanceColor = null;
  16198. this.count = count;
  16199. this.frustumCulled = false;
  16200. }
  16201. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16202. constructor: InstancedMesh,
  16203. isInstancedMesh: true,
  16204. copy: function copy(source) {
  16205. Mesh.prototype.copy.call(this, source);
  16206. this.instanceMatrix.copy(source.instanceMatrix);
  16207. this.count = source.count;
  16208. return this;
  16209. },
  16210. getColorAt: function getColorAt(index, color) {
  16211. color.fromArray(this.instanceColor.array, index * 3);
  16212. },
  16213. getMatrixAt: function getMatrixAt(index, matrix) {
  16214. matrix.fromArray(this.instanceMatrix.array, index * 16);
  16215. },
  16216. raycast: function raycast(raycaster, intersects) {
  16217. var matrixWorld = this.matrixWorld;
  16218. var raycastTimes = this.count;
  16219. _mesh.geometry = this.geometry;
  16220. _mesh.material = this.material;
  16221. if (_mesh.material === undefined) return;
  16222. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  16223. // calculate the world matrix for each instance
  16224. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  16225. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  16226. _mesh.matrixWorld = _instanceWorldMatrix;
  16227. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  16228. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  16229. var intersect = _instanceIntersects[i];
  16230. intersect.instanceId = instanceId;
  16231. intersect.object = this;
  16232. intersects.push(intersect);
  16233. }
  16234. _instanceIntersects.length = 0;
  16235. }
  16236. },
  16237. setColorAt: function setColorAt(index, color) {
  16238. if (this.instanceColor === null) {
  16239. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  16240. }
  16241. color.toArray(this.instanceColor.array, index * 3);
  16242. },
  16243. setMatrixAt: function setMatrixAt(index, matrix) {
  16244. matrix.toArray(this.instanceMatrix.array, index * 16);
  16245. },
  16246. updateMorphTargets: function updateMorphTargets() {},
  16247. dispose: function dispose() {
  16248. this.dispatchEvent({
  16249. type: 'dispose'
  16250. });
  16251. }
  16252. });
  16253. /**
  16254. * parameters = {
  16255. * color: <hex>,
  16256. * opacity: <float>,
  16257. *
  16258. * linewidth: <float>,
  16259. * linecap: "round",
  16260. * linejoin: "round"
  16261. * }
  16262. */
  16263. function LineBasicMaterial(parameters) {
  16264. Material.call(this);
  16265. this.type = 'LineBasicMaterial';
  16266. this.color = new Color(0xffffff);
  16267. this.linewidth = 1;
  16268. this.linecap = 'round';
  16269. this.linejoin = 'round';
  16270. this.morphTargets = false;
  16271. this.setValues(parameters);
  16272. }
  16273. LineBasicMaterial.prototype = Object.create(Material.prototype);
  16274. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16275. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16276. LineBasicMaterial.prototype.copy = function (source) {
  16277. Material.prototype.copy.call(this, source);
  16278. this.color.copy(source.color);
  16279. this.linewidth = source.linewidth;
  16280. this.linecap = source.linecap;
  16281. this.linejoin = source.linejoin;
  16282. this.morphTargets = source.morphTargets;
  16283. return this;
  16284. };
  16285. var _start = new Vector3();
  16286. var _end = new Vector3();
  16287. var _inverseMatrix$1 = new Matrix4();
  16288. var _ray$1 = new Ray();
  16289. var _sphere$2 = new Sphere();
  16290. function Line(geometry, material, mode) {
  16291. if (mode === 1) {
  16292. console.error('THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.');
  16293. }
  16294. Object3D.call(this);
  16295. this.type = 'Line';
  16296. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16297. this.material = material !== undefined ? material : new LineBasicMaterial();
  16298. this.updateMorphTargets();
  16299. }
  16300. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  16301. constructor: Line,
  16302. isLine: true,
  16303. copy: function copy(source) {
  16304. Object3D.prototype.copy.call(this, source);
  16305. this.material = source.material;
  16306. this.geometry = source.geometry;
  16307. return this;
  16308. },
  16309. computeLineDistances: function computeLineDistances() {
  16310. var geometry = this.geometry;
  16311. if (geometry.isBufferGeometry) {
  16312. // we assume non-indexed geometry
  16313. if (geometry.index === null) {
  16314. var positionAttribute = geometry.attributes.position;
  16315. var lineDistances = [0];
  16316. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  16317. _start.fromBufferAttribute(positionAttribute, i - 1);
  16318. _end.fromBufferAttribute(positionAttribute, i);
  16319. lineDistances[i] = lineDistances[i - 1];
  16320. lineDistances[i] += _start.distanceTo(_end);
  16321. }
  16322. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16323. } else {
  16324. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16325. }
  16326. } else if (geometry.isGeometry) {
  16327. var vertices = geometry.vertices;
  16328. var _lineDistances = geometry.lineDistances;
  16329. _lineDistances[0] = 0;
  16330. for (var _i = 1, _l = vertices.length; _i < _l; _i++) {
  16331. _lineDistances[_i] = _lineDistances[_i - 1];
  16332. _lineDistances[_i] += vertices[_i - 1].distanceTo(vertices[_i]);
  16333. }
  16334. }
  16335. return this;
  16336. },
  16337. raycast: function raycast(raycaster, intersects) {
  16338. var geometry = this.geometry;
  16339. var matrixWorld = this.matrixWorld;
  16340. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  16341. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16342. _sphere$2.copy(geometry.boundingSphere);
  16343. _sphere$2.applyMatrix4(matrixWorld);
  16344. _sphere$2.radius += threshold;
  16345. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  16346. _inverseMatrix$1.copy(matrixWorld).invert();
  16347. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  16348. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16349. var localThresholdSq = localThreshold * localThreshold;
  16350. var vStart = new Vector3();
  16351. var vEnd = new Vector3();
  16352. var interSegment = new Vector3();
  16353. var interRay = new Vector3();
  16354. var step = this.isLineSegments ? 2 : 1;
  16355. if (geometry.isBufferGeometry) {
  16356. var index = geometry.index;
  16357. var attributes = geometry.attributes;
  16358. var positionAttribute = attributes.position;
  16359. if (index !== null) {
  16360. var indices = index.array;
  16361. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  16362. var a = indices[i];
  16363. var b = indices[i + 1];
  16364. vStart.fromBufferAttribute(positionAttribute, a);
  16365. vEnd.fromBufferAttribute(positionAttribute, b);
  16366. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16367. if (distSq > localThresholdSq) continue;
  16368. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16369. var distance = raycaster.ray.origin.distanceTo(interRay);
  16370. if (distance < raycaster.near || distance > raycaster.far) continue;
  16371. intersects.push({
  16372. distance: distance,
  16373. // What do we want? intersection point on the ray or on the segment??
  16374. // point: raycaster.ray.at( distance ),
  16375. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16376. index: i,
  16377. face: null,
  16378. faceIndex: null,
  16379. object: this
  16380. });
  16381. }
  16382. } else {
  16383. for (var _i2 = 0, _l2 = positionAttribute.count - 1; _i2 < _l2; _i2 += step) {
  16384. vStart.fromBufferAttribute(positionAttribute, _i2);
  16385. vEnd.fromBufferAttribute(positionAttribute, _i2 + 1);
  16386. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16387. if (_distSq > localThresholdSq) continue;
  16388. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16389. var _distance = raycaster.ray.origin.distanceTo(interRay);
  16390. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  16391. intersects.push({
  16392. distance: _distance,
  16393. // What do we want? intersection point on the ray or on the segment??
  16394. // point: raycaster.ray.at( distance ),
  16395. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16396. index: _i2,
  16397. face: null,
  16398. faceIndex: null,
  16399. object: this
  16400. });
  16401. }
  16402. }
  16403. } else if (geometry.isGeometry) {
  16404. var vertices = geometry.vertices;
  16405. var nbVertices = vertices.length;
  16406. for (var _i3 = 0; _i3 < nbVertices - 1; _i3 += step) {
  16407. var _distSq2 = _ray$1.distanceSqToSegment(vertices[_i3], vertices[_i3 + 1], interRay, interSegment);
  16408. if (_distSq2 > localThresholdSq) continue;
  16409. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16410. var _distance2 = raycaster.ray.origin.distanceTo(interRay);
  16411. if (_distance2 < raycaster.near || _distance2 > raycaster.far) continue;
  16412. intersects.push({
  16413. distance: _distance2,
  16414. // What do we want? intersection point on the ray or on the segment??
  16415. // point: raycaster.ray.at( distance ),
  16416. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16417. index: _i3,
  16418. face: null,
  16419. faceIndex: null,
  16420. object: this
  16421. });
  16422. }
  16423. }
  16424. },
  16425. updateMorphTargets: function updateMorphTargets() {
  16426. var geometry = this.geometry;
  16427. if (geometry.isBufferGeometry) {
  16428. var morphAttributes = geometry.morphAttributes;
  16429. var keys = Object.keys(morphAttributes);
  16430. if (keys.length > 0) {
  16431. var morphAttribute = morphAttributes[keys[0]];
  16432. if (morphAttribute !== undefined) {
  16433. this.morphTargetInfluences = [];
  16434. this.morphTargetDictionary = {};
  16435. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16436. var name = morphAttribute[m].name || String(m);
  16437. this.morphTargetInfluences.push(0);
  16438. this.morphTargetDictionary[name] = m;
  16439. }
  16440. }
  16441. }
  16442. } else {
  16443. var morphTargets = geometry.morphTargets;
  16444. if (morphTargets !== undefined && morphTargets.length > 0) {
  16445. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16446. }
  16447. }
  16448. }
  16449. });
  16450. var _start$1 = new Vector3();
  16451. var _end$1 = new Vector3();
  16452. function LineSegments(geometry, material) {
  16453. Line.call(this, geometry, material);
  16454. this.type = 'LineSegments';
  16455. }
  16456. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  16457. constructor: LineSegments,
  16458. isLineSegments: true,
  16459. computeLineDistances: function computeLineDistances() {
  16460. var geometry = this.geometry;
  16461. if (geometry.isBufferGeometry) {
  16462. // we assume non-indexed geometry
  16463. if (geometry.index === null) {
  16464. var positionAttribute = geometry.attributes.position;
  16465. var lineDistances = [];
  16466. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  16467. _start$1.fromBufferAttribute(positionAttribute, i);
  16468. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  16469. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  16470. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  16471. }
  16472. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16473. } else {
  16474. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16475. }
  16476. } else if (geometry.isGeometry) {
  16477. var vertices = geometry.vertices;
  16478. var _lineDistances = geometry.lineDistances;
  16479. for (var _i = 0, _l = vertices.length; _i < _l; _i += 2) {
  16480. _start$1.copy(vertices[_i]);
  16481. _end$1.copy(vertices[_i + 1]);
  16482. _lineDistances[_i] = _i === 0 ? 0 : _lineDistances[_i - 1];
  16483. _lineDistances[_i + 1] = _lineDistances[_i] + _start$1.distanceTo(_end$1);
  16484. }
  16485. }
  16486. return this;
  16487. }
  16488. });
  16489. function LineLoop(geometry, material) {
  16490. Line.call(this, geometry, material);
  16491. this.type = 'LineLoop';
  16492. }
  16493. LineLoop.prototype = Object.assign(Object.create(Line.prototype), {
  16494. constructor: LineLoop,
  16495. isLineLoop: true
  16496. });
  16497. /**
  16498. * parameters = {
  16499. * color: <hex>,
  16500. * opacity: <float>,
  16501. * map: new THREE.Texture( <Image> ),
  16502. * alphaMap: new THREE.Texture( <Image> ),
  16503. *
  16504. * size: <float>,
  16505. * sizeAttenuation: <bool>
  16506. *
  16507. * morphTargets: <bool>
  16508. * }
  16509. */
  16510. function PointsMaterial(parameters) {
  16511. Material.call(this);
  16512. this.type = 'PointsMaterial';
  16513. this.color = new Color(0xffffff);
  16514. this.map = null;
  16515. this.alphaMap = null;
  16516. this.size = 1;
  16517. this.sizeAttenuation = true;
  16518. this.morphTargets = false;
  16519. this.setValues(parameters);
  16520. }
  16521. PointsMaterial.prototype = Object.create(Material.prototype);
  16522. PointsMaterial.prototype.constructor = PointsMaterial;
  16523. PointsMaterial.prototype.isPointsMaterial = true;
  16524. PointsMaterial.prototype.copy = function (source) {
  16525. Material.prototype.copy.call(this, source);
  16526. this.color.copy(source.color);
  16527. this.map = source.map;
  16528. this.alphaMap = source.alphaMap;
  16529. this.size = source.size;
  16530. this.sizeAttenuation = source.sizeAttenuation;
  16531. this.morphTargets = source.morphTargets;
  16532. return this;
  16533. };
  16534. var _inverseMatrix$2 = new Matrix4();
  16535. var _ray$2 = new Ray();
  16536. var _sphere$3 = new Sphere();
  16537. var _position$1 = new Vector3();
  16538. function Points(geometry, material) {
  16539. Object3D.call(this);
  16540. this.type = 'Points';
  16541. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16542. this.material = material !== undefined ? material : new PointsMaterial();
  16543. this.updateMorphTargets();
  16544. }
  16545. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  16546. constructor: Points,
  16547. isPoints: true,
  16548. copy: function copy(source) {
  16549. Object3D.prototype.copy.call(this, source);
  16550. this.material = source.material;
  16551. this.geometry = source.geometry;
  16552. return this;
  16553. },
  16554. raycast: function raycast(raycaster, intersects) {
  16555. var geometry = this.geometry;
  16556. var matrixWorld = this.matrixWorld;
  16557. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  16558. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16559. _sphere$3.copy(geometry.boundingSphere);
  16560. _sphere$3.applyMatrix4(matrixWorld);
  16561. _sphere$3.radius += threshold;
  16562. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  16563. _inverseMatrix$2.copy(matrixWorld).invert();
  16564. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  16565. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16566. var localThresholdSq = localThreshold * localThreshold;
  16567. if (geometry.isBufferGeometry) {
  16568. var index = geometry.index;
  16569. var attributes = geometry.attributes;
  16570. var positionAttribute = attributes.position;
  16571. if (index !== null) {
  16572. var indices = index.array;
  16573. for (var i = 0, il = indices.length; i < il; i++) {
  16574. var a = indices[i];
  16575. _position$1.fromBufferAttribute(positionAttribute, a);
  16576. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16577. }
  16578. } else {
  16579. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  16580. _position$1.fromBufferAttribute(positionAttribute, _i);
  16581. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16582. }
  16583. }
  16584. } else {
  16585. var vertices = geometry.vertices;
  16586. for (var _i2 = 0, _l = vertices.length; _i2 < _l; _i2++) {
  16587. testPoint(vertices[_i2], _i2, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16588. }
  16589. }
  16590. },
  16591. updateMorphTargets: function updateMorphTargets() {
  16592. var geometry = this.geometry;
  16593. if (geometry.isBufferGeometry) {
  16594. var morphAttributes = geometry.morphAttributes;
  16595. var keys = Object.keys(morphAttributes);
  16596. if (keys.length > 0) {
  16597. var morphAttribute = morphAttributes[keys[0]];
  16598. if (morphAttribute !== undefined) {
  16599. this.morphTargetInfluences = [];
  16600. this.morphTargetDictionary = {};
  16601. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16602. var name = morphAttribute[m].name || String(m);
  16603. this.morphTargetInfluences.push(0);
  16604. this.morphTargetDictionary[name] = m;
  16605. }
  16606. }
  16607. }
  16608. } else {
  16609. var morphTargets = geometry.morphTargets;
  16610. if (morphTargets !== undefined && morphTargets.length > 0) {
  16611. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16612. }
  16613. }
  16614. }
  16615. });
  16616. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  16617. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  16618. if (rayPointDistanceSq < localThresholdSq) {
  16619. var intersectPoint = new Vector3();
  16620. _ray$2.closestPointToPoint(point, intersectPoint);
  16621. intersectPoint.applyMatrix4(matrixWorld);
  16622. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  16623. if (distance < raycaster.near || distance > raycaster.far) return;
  16624. intersects.push({
  16625. distance: distance,
  16626. distanceToRay: Math.sqrt(rayPointDistanceSq),
  16627. point: intersectPoint,
  16628. index: index,
  16629. face: null,
  16630. object: object
  16631. });
  16632. }
  16633. }
  16634. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16635. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16636. this.format = format !== undefined ? format : RGBFormat;
  16637. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16638. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16639. this.generateMipmaps = false;
  16640. var scope = this;
  16641. function updateVideo() {
  16642. scope.needsUpdate = true;
  16643. video.requestVideoFrameCallback(updateVideo);
  16644. }
  16645. if ('requestVideoFrameCallback' in video) {
  16646. video.requestVideoFrameCallback(updateVideo);
  16647. }
  16648. }
  16649. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  16650. constructor: VideoTexture,
  16651. clone: function clone() {
  16652. return new this.constructor(this.image).copy(this);
  16653. },
  16654. isVideoTexture: true,
  16655. update: function update() {
  16656. var video = this.image;
  16657. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  16658. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  16659. this.needsUpdate = true;
  16660. }
  16661. }
  16662. });
  16663. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  16664. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  16665. this.image = {
  16666. width: width,
  16667. height: height
  16668. };
  16669. this.mipmaps = mipmaps; // no flipping for cube textures
  16670. // (also flipping doesn't work for compressed textures )
  16671. this.flipY = false; // can't generate mipmaps for compressed textures
  16672. // mips must be embedded in DDS files
  16673. this.generateMipmaps = false;
  16674. }
  16675. CompressedTexture.prototype = Object.create(Texture.prototype);
  16676. CompressedTexture.prototype.constructor = CompressedTexture;
  16677. CompressedTexture.prototype.isCompressedTexture = true;
  16678. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16679. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16680. this.needsUpdate = true;
  16681. }
  16682. CanvasTexture.prototype = Object.create(Texture.prototype);
  16683. CanvasTexture.prototype.constructor = CanvasTexture;
  16684. CanvasTexture.prototype.isCanvasTexture = true;
  16685. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  16686. format = format !== undefined ? format : DepthFormat;
  16687. if (format !== DepthFormat && format !== DepthStencilFormat) {
  16688. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  16689. }
  16690. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  16691. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  16692. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16693. this.image = {
  16694. width: width,
  16695. height: height
  16696. };
  16697. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16698. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16699. this.flipY = false;
  16700. this.generateMipmaps = false;
  16701. }
  16702. DepthTexture.prototype = Object.create(Texture.prototype);
  16703. DepthTexture.prototype.constructor = DepthTexture;
  16704. DepthTexture.prototype.isDepthTexture = true;
  16705. var _geometryId = 0; // Geometry uses even numbers as Id
  16706. var _m1$3 = new Matrix4();
  16707. var _obj$1 = new Object3D();
  16708. var _offset$1 = new Vector3();
  16709. function Geometry() {
  16710. Object.defineProperty(this, 'id', {
  16711. value: _geometryId += 2
  16712. });
  16713. this.uuid = MathUtils.generateUUID();
  16714. this.name = '';
  16715. this.type = 'Geometry';
  16716. this.vertices = [];
  16717. this.colors = [];
  16718. this.faces = [];
  16719. this.faceVertexUvs = [[]];
  16720. this.morphTargets = [];
  16721. this.morphNormals = [];
  16722. this.skinWeights = [];
  16723. this.skinIndices = [];
  16724. this.lineDistances = [];
  16725. this.boundingBox = null;
  16726. this.boundingSphere = null; // update flags
  16727. this.elementsNeedUpdate = false;
  16728. this.verticesNeedUpdate = false;
  16729. this.uvsNeedUpdate = false;
  16730. this.normalsNeedUpdate = false;
  16731. this.colorsNeedUpdate = false;
  16732. this.lineDistancesNeedUpdate = false;
  16733. this.groupsNeedUpdate = false;
  16734. }
  16735. Geometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  16736. constructor: Geometry,
  16737. isGeometry: true,
  16738. applyMatrix4: function applyMatrix4(matrix) {
  16739. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  16740. for (var i = 0, il = this.vertices.length; i < il; i++) {
  16741. var vertex = this.vertices[i];
  16742. vertex.applyMatrix4(matrix);
  16743. }
  16744. for (var _i = 0, _il = this.faces.length; _i < _il; _i++) {
  16745. var face = this.faces[_i];
  16746. face.normal.applyMatrix3(normalMatrix).normalize();
  16747. for (var j = 0, jl = face.vertexNormals.length; j < jl; j++) {
  16748. face.vertexNormals[j].applyMatrix3(normalMatrix).normalize();
  16749. }
  16750. }
  16751. if (this.boundingBox !== null) {
  16752. this.computeBoundingBox();
  16753. }
  16754. if (this.boundingSphere !== null) {
  16755. this.computeBoundingSphere();
  16756. }
  16757. this.verticesNeedUpdate = true;
  16758. this.normalsNeedUpdate = true;
  16759. return this;
  16760. },
  16761. rotateX: function rotateX(angle) {
  16762. // rotate geometry around world x-axis
  16763. _m1$3.makeRotationX(angle);
  16764. this.applyMatrix4(_m1$3);
  16765. return this;
  16766. },
  16767. rotateY: function rotateY(angle) {
  16768. // rotate geometry around world y-axis
  16769. _m1$3.makeRotationY(angle);
  16770. this.applyMatrix4(_m1$3);
  16771. return this;
  16772. },
  16773. rotateZ: function rotateZ(angle) {
  16774. // rotate geometry around world z-axis
  16775. _m1$3.makeRotationZ(angle);
  16776. this.applyMatrix4(_m1$3);
  16777. return this;
  16778. },
  16779. translate: function translate(x, y, z) {
  16780. // translate geometry
  16781. _m1$3.makeTranslation(x, y, z);
  16782. this.applyMatrix4(_m1$3);
  16783. return this;
  16784. },
  16785. scale: function scale(x, y, z) {
  16786. // scale geometry
  16787. _m1$3.makeScale(x, y, z);
  16788. this.applyMatrix4(_m1$3);
  16789. return this;
  16790. },
  16791. lookAt: function lookAt(vector) {
  16792. _obj$1.lookAt(vector);
  16793. _obj$1.updateMatrix();
  16794. this.applyMatrix4(_obj$1.matrix);
  16795. return this;
  16796. },
  16797. fromBufferGeometry: function fromBufferGeometry(geometry) {
  16798. var scope = this;
  16799. var index = geometry.index !== null ? geometry.index : undefined;
  16800. var attributes = geometry.attributes;
  16801. if (attributes.position === undefined) {
  16802. console.error('THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.');
  16803. return this;
  16804. }
  16805. var position = attributes.position;
  16806. var normal = attributes.normal;
  16807. var color = attributes.color;
  16808. var uv = attributes.uv;
  16809. var uv2 = attributes.uv2;
  16810. if (uv2 !== undefined) this.faceVertexUvs[1] = [];
  16811. for (var i = 0; i < position.count; i++) {
  16812. scope.vertices.push(new Vector3().fromBufferAttribute(position, i));
  16813. if (color !== undefined) {
  16814. scope.colors.push(new Color().fromBufferAttribute(color, i));
  16815. }
  16816. }
  16817. function addFace(a, b, c, materialIndex) {
  16818. var vertexColors = color === undefined ? [] : [scope.colors[a].clone(), scope.colors[b].clone(), scope.colors[c].clone()];
  16819. var vertexNormals = normal === undefined ? [] : [new Vector3().fromBufferAttribute(normal, a), new Vector3().fromBufferAttribute(normal, b), new Vector3().fromBufferAttribute(normal, c)];
  16820. var face = new Face3(a, b, c, vertexNormals, vertexColors, materialIndex);
  16821. scope.faces.push(face);
  16822. if (uv !== undefined) {
  16823. scope.faceVertexUvs[0].push([new Vector2().fromBufferAttribute(uv, a), new Vector2().fromBufferAttribute(uv, b), new Vector2().fromBufferAttribute(uv, c)]);
  16824. }
  16825. if (uv2 !== undefined) {
  16826. scope.faceVertexUvs[1].push([new Vector2().fromBufferAttribute(uv2, a), new Vector2().fromBufferAttribute(uv2, b), new Vector2().fromBufferAttribute(uv2, c)]);
  16827. }
  16828. }
  16829. var groups = geometry.groups;
  16830. if (groups.length > 0) {
  16831. for (var _i2 = 0; _i2 < groups.length; _i2++) {
  16832. var group = groups[_i2];
  16833. var start = group.start;
  16834. var count = group.count;
  16835. for (var j = start, jl = start + count; j < jl; j += 3) {
  16836. if (index !== undefined) {
  16837. addFace(index.getX(j), index.getX(j + 1), index.getX(j + 2), group.materialIndex);
  16838. } else {
  16839. addFace(j, j + 1, j + 2, group.materialIndex);
  16840. }
  16841. }
  16842. }
  16843. } else {
  16844. if (index !== undefined) {
  16845. for (var _i3 = 0; _i3 < index.count; _i3 += 3) {
  16846. addFace(index.getX(_i3), index.getX(_i3 + 1), index.getX(_i3 + 2));
  16847. }
  16848. } else {
  16849. for (var _i4 = 0; _i4 < position.count; _i4 += 3) {
  16850. addFace(_i4, _i4 + 1, _i4 + 2);
  16851. }
  16852. }
  16853. }
  16854. this.computeFaceNormals();
  16855. if (geometry.boundingBox !== null) {
  16856. this.boundingBox = geometry.boundingBox.clone();
  16857. }
  16858. if (geometry.boundingSphere !== null) {
  16859. this.boundingSphere = geometry.boundingSphere.clone();
  16860. }
  16861. return this;
  16862. },
  16863. center: function center() {
  16864. this.computeBoundingBox();
  16865. this.boundingBox.getCenter(_offset$1).negate();
  16866. this.translate(_offset$1.x, _offset$1.y, _offset$1.z);
  16867. return this;
  16868. },
  16869. normalize: function normalize() {
  16870. this.computeBoundingSphere();
  16871. var center = this.boundingSphere.center;
  16872. var radius = this.boundingSphere.radius;
  16873. var s = radius === 0 ? 1 : 1.0 / radius;
  16874. var matrix = new Matrix4();
  16875. matrix.set(s, 0, 0, -s * center.x, 0, s, 0, -s * center.y, 0, 0, s, -s * center.z, 0, 0, 0, 1);
  16876. this.applyMatrix4(matrix);
  16877. return this;
  16878. },
  16879. computeFaceNormals: function computeFaceNormals() {
  16880. var cb = new Vector3(),
  16881. ab = new Vector3();
  16882. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16883. var face = this.faces[f];
  16884. var vA = this.vertices[face.a];
  16885. var vB = this.vertices[face.b];
  16886. var vC = this.vertices[face.c];
  16887. cb.subVectors(vC, vB);
  16888. ab.subVectors(vA, vB);
  16889. cb.cross(ab);
  16890. cb.normalize();
  16891. face.normal.copy(cb);
  16892. }
  16893. },
  16894. computeVertexNormals: function computeVertexNormals(areaWeighted) {
  16895. if (areaWeighted === void 0) {
  16896. areaWeighted = true;
  16897. }
  16898. var vertices = new Array(this.vertices.length);
  16899. for (var v = 0, vl = this.vertices.length; v < vl; v++) {
  16900. vertices[v] = new Vector3();
  16901. }
  16902. if (areaWeighted) {
  16903. // vertex normals weighted by triangle areas
  16904. // http://www.iquilezles.org/www/articles/normals/normals.htm
  16905. var cb = new Vector3(),
  16906. ab = new Vector3();
  16907. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16908. var face = this.faces[f];
  16909. var vA = this.vertices[face.a];
  16910. var vB = this.vertices[face.b];
  16911. var vC = this.vertices[face.c];
  16912. cb.subVectors(vC, vB);
  16913. ab.subVectors(vA, vB);
  16914. cb.cross(ab);
  16915. vertices[face.a].add(cb);
  16916. vertices[face.b].add(cb);
  16917. vertices[face.c].add(cb);
  16918. }
  16919. } else {
  16920. this.computeFaceNormals();
  16921. for (var _f = 0, _fl = this.faces.length; _f < _fl; _f++) {
  16922. var _face = this.faces[_f];
  16923. vertices[_face.a].add(_face.normal);
  16924. vertices[_face.b].add(_face.normal);
  16925. vertices[_face.c].add(_face.normal);
  16926. }
  16927. }
  16928. for (var _v = 0, _vl = this.vertices.length; _v < _vl; _v++) {
  16929. vertices[_v].normalize();
  16930. }
  16931. for (var _f2 = 0, _fl2 = this.faces.length; _f2 < _fl2; _f2++) {
  16932. var _face2 = this.faces[_f2];
  16933. var vertexNormals = _face2.vertexNormals;
  16934. if (vertexNormals.length === 3) {
  16935. vertexNormals[0].copy(vertices[_face2.a]);
  16936. vertexNormals[1].copy(vertices[_face2.b]);
  16937. vertexNormals[2].copy(vertices[_face2.c]);
  16938. } else {
  16939. vertexNormals[0] = vertices[_face2.a].clone();
  16940. vertexNormals[1] = vertices[_face2.b].clone();
  16941. vertexNormals[2] = vertices[_face2.c].clone();
  16942. }
  16943. }
  16944. if (this.faces.length > 0) {
  16945. this.normalsNeedUpdate = true;
  16946. }
  16947. },
  16948. computeFlatVertexNormals: function computeFlatVertexNormals() {
  16949. this.computeFaceNormals();
  16950. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16951. var face = this.faces[f];
  16952. var vertexNormals = face.vertexNormals;
  16953. if (vertexNormals.length === 3) {
  16954. vertexNormals[0].copy(face.normal);
  16955. vertexNormals[1].copy(face.normal);
  16956. vertexNormals[2].copy(face.normal);
  16957. } else {
  16958. vertexNormals[0] = face.normal.clone();
  16959. vertexNormals[1] = face.normal.clone();
  16960. vertexNormals[2] = face.normal.clone();
  16961. }
  16962. }
  16963. if (this.faces.length > 0) {
  16964. this.normalsNeedUpdate = true;
  16965. }
  16966. },
  16967. computeMorphNormals: function computeMorphNormals() {
  16968. // save original normals
  16969. // - create temp variables on first access
  16970. // otherwise just copy (for faster repeated calls)
  16971. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16972. var face = this.faces[f];
  16973. if (!face.__originalFaceNormal) {
  16974. face.__originalFaceNormal = face.normal.clone();
  16975. } else {
  16976. face.__originalFaceNormal.copy(face.normal);
  16977. }
  16978. if (!face.__originalVertexNormals) face.__originalVertexNormals = [];
  16979. for (var i = 0, il = face.vertexNormals.length; i < il; i++) {
  16980. if (!face.__originalVertexNormals[i]) {
  16981. face.__originalVertexNormals[i] = face.vertexNormals[i].clone();
  16982. } else {
  16983. face.__originalVertexNormals[i].copy(face.vertexNormals[i]);
  16984. }
  16985. }
  16986. } // use temp geometry to compute face and vertex normals for each morph
  16987. var tmpGeo = new Geometry();
  16988. tmpGeo.faces = this.faces;
  16989. for (var _i5 = 0, _il2 = this.morphTargets.length; _i5 < _il2; _i5++) {
  16990. // create on first access
  16991. if (!this.morphNormals[_i5]) {
  16992. this.morphNormals[_i5] = {};
  16993. this.morphNormals[_i5].faceNormals = [];
  16994. this.morphNormals[_i5].vertexNormals = [];
  16995. var dstNormalsFace = this.morphNormals[_i5].faceNormals;
  16996. var dstNormalsVertex = this.morphNormals[_i5].vertexNormals;
  16997. for (var _f3 = 0, _fl3 = this.faces.length; _f3 < _fl3; _f3++) {
  16998. var faceNormal = new Vector3();
  16999. var vertexNormals = {
  17000. a: new Vector3(),
  17001. b: new Vector3(),
  17002. c: new Vector3()
  17003. };
  17004. dstNormalsFace.push(faceNormal);
  17005. dstNormalsVertex.push(vertexNormals);
  17006. }
  17007. }
  17008. var morphNormals = this.morphNormals[_i5]; // set vertices to morph target
  17009. tmpGeo.vertices = this.morphTargets[_i5].vertices; // compute morph normals
  17010. tmpGeo.computeFaceNormals();
  17011. tmpGeo.computeVertexNormals(); // store morph normals
  17012. for (var _f4 = 0, _fl4 = this.faces.length; _f4 < _fl4; _f4++) {
  17013. var _face3 = this.faces[_f4];
  17014. var _faceNormal = morphNormals.faceNormals[_f4];
  17015. var _vertexNormals = morphNormals.vertexNormals[_f4];
  17016. _faceNormal.copy(_face3.normal);
  17017. _vertexNormals.a.copy(_face3.vertexNormals[0]);
  17018. _vertexNormals.b.copy(_face3.vertexNormals[1]);
  17019. _vertexNormals.c.copy(_face3.vertexNormals[2]);
  17020. }
  17021. } // restore original normals
  17022. for (var _f5 = 0, _fl5 = this.faces.length; _f5 < _fl5; _f5++) {
  17023. var _face4 = this.faces[_f5];
  17024. _face4.normal = _face4.__originalFaceNormal;
  17025. _face4.vertexNormals = _face4.__originalVertexNormals;
  17026. }
  17027. },
  17028. computeBoundingBox: function computeBoundingBox() {
  17029. if (this.boundingBox === null) {
  17030. this.boundingBox = new Box3();
  17031. }
  17032. this.boundingBox.setFromPoints(this.vertices);
  17033. },
  17034. computeBoundingSphere: function computeBoundingSphere() {
  17035. if (this.boundingSphere === null) {
  17036. this.boundingSphere = new Sphere();
  17037. }
  17038. this.boundingSphere.setFromPoints(this.vertices);
  17039. },
  17040. merge: function merge(geometry, matrix, materialIndexOffset) {
  17041. if (materialIndexOffset === void 0) {
  17042. materialIndexOffset = 0;
  17043. }
  17044. if (!(geometry && geometry.isGeometry)) {
  17045. console.error('THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry);
  17046. return;
  17047. }
  17048. var normalMatrix;
  17049. var vertexOffset = this.vertices.length,
  17050. vertices1 = this.vertices,
  17051. vertices2 = geometry.vertices,
  17052. faces1 = this.faces,
  17053. faces2 = geometry.faces,
  17054. colors1 = this.colors,
  17055. colors2 = geometry.colors;
  17056. if (matrix !== undefined) {
  17057. normalMatrix = new Matrix3().getNormalMatrix(matrix);
  17058. } // vertices
  17059. for (var i = 0, il = vertices2.length; i < il; i++) {
  17060. var vertex = vertices2[i];
  17061. var vertexCopy = vertex.clone();
  17062. if (matrix !== undefined) vertexCopy.applyMatrix4(matrix);
  17063. vertices1.push(vertexCopy);
  17064. } // colors
  17065. for (var _i6 = 0, _il3 = colors2.length; _i6 < _il3; _i6++) {
  17066. colors1.push(colors2[_i6].clone());
  17067. } // faces
  17068. for (var _i7 = 0, _il4 = faces2.length; _i7 < _il4; _i7++) {
  17069. var face = faces2[_i7];
  17070. var normal = void 0,
  17071. color = void 0;
  17072. var faceVertexNormals = face.vertexNormals,
  17073. faceVertexColors = face.vertexColors;
  17074. var faceCopy = new Face3(face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset);
  17075. faceCopy.normal.copy(face.normal);
  17076. if (normalMatrix !== undefined) {
  17077. faceCopy.normal.applyMatrix3(normalMatrix).normalize();
  17078. }
  17079. for (var j = 0, jl = faceVertexNormals.length; j < jl; j++) {
  17080. normal = faceVertexNormals[j].clone();
  17081. if (normalMatrix !== undefined) {
  17082. normal.applyMatrix3(normalMatrix).normalize();
  17083. }
  17084. faceCopy.vertexNormals.push(normal);
  17085. }
  17086. faceCopy.color.copy(face.color);
  17087. for (var _j = 0, _jl = faceVertexColors.length; _j < _jl; _j++) {
  17088. color = faceVertexColors[_j];
  17089. faceCopy.vertexColors.push(color.clone());
  17090. }
  17091. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  17092. faces1.push(faceCopy);
  17093. } // uvs
  17094. for (var _i8 = 0, _il5 = geometry.faceVertexUvs.length; _i8 < _il5; _i8++) {
  17095. var faceVertexUvs2 = geometry.faceVertexUvs[_i8];
  17096. if (this.faceVertexUvs[_i8] === undefined) this.faceVertexUvs[_i8] = [];
  17097. for (var _j2 = 0, _jl2 = faceVertexUvs2.length; _j2 < _jl2; _j2++) {
  17098. var uvs2 = faceVertexUvs2[_j2],
  17099. uvsCopy = [];
  17100. for (var k = 0, kl = uvs2.length; k < kl; k++) {
  17101. uvsCopy.push(uvs2[k].clone());
  17102. }
  17103. this.faceVertexUvs[_i8].push(uvsCopy);
  17104. }
  17105. }
  17106. },
  17107. mergeMesh: function mergeMesh(mesh) {
  17108. if (!(mesh && mesh.isMesh)) {
  17109. console.error('THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh);
  17110. return;
  17111. }
  17112. if (mesh.matrixAutoUpdate) mesh.updateMatrix();
  17113. this.merge(mesh.geometry, mesh.matrix);
  17114. },
  17115. /*
  17116. * Checks for duplicate vertices with hashmap.
  17117. * Duplicated vertices are removed
  17118. * and faces' vertices are updated.
  17119. */
  17120. mergeVertices: function mergeVertices(precisionPoints) {
  17121. if (precisionPoints === void 0) {
  17122. precisionPoints = 4;
  17123. }
  17124. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  17125. var unique = [],
  17126. changes = [];
  17127. var precision = Math.pow(10, precisionPoints);
  17128. for (var i = 0, il = this.vertices.length; i < il; i++) {
  17129. var v = this.vertices[i];
  17130. var key = Math.round(v.x * precision) + '_' + Math.round(v.y * precision) + '_' + Math.round(v.z * precision);
  17131. if (verticesMap[key] === undefined) {
  17132. verticesMap[key] = i;
  17133. unique.push(this.vertices[i]);
  17134. changes[i] = unique.length - 1;
  17135. } else {
  17136. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  17137. changes[i] = changes[verticesMap[key]];
  17138. }
  17139. } // if faces are completely degenerate after merging vertices, we
  17140. // have to remove them from the geometry.
  17141. var faceIndicesToRemove = [];
  17142. for (var _i9 = 0, _il6 = this.faces.length; _i9 < _il6; _i9++) {
  17143. var face = this.faces[_i9];
  17144. face.a = changes[face.a];
  17145. face.b = changes[face.b];
  17146. face.c = changes[face.c];
  17147. var indices = [face.a, face.b, face.c]; // if any duplicate vertices are found in a Face3
  17148. // we have to remove the face as nothing can be saved
  17149. for (var n = 0; n < 3; n++) {
  17150. if (indices[n] === indices[(n + 1) % 3]) {
  17151. faceIndicesToRemove.push(_i9);
  17152. break;
  17153. }
  17154. }
  17155. }
  17156. for (var _i10 = faceIndicesToRemove.length - 1; _i10 >= 0; _i10--) {
  17157. var idx = faceIndicesToRemove[_i10];
  17158. this.faces.splice(idx, 1);
  17159. for (var j = 0, jl = this.faceVertexUvs.length; j < jl; j++) {
  17160. this.faceVertexUvs[j].splice(idx, 1);
  17161. }
  17162. } // Use unique set of vertices
  17163. var diff = this.vertices.length - unique.length;
  17164. this.vertices = unique;
  17165. return diff;
  17166. },
  17167. setFromPoints: function setFromPoints(points) {
  17168. this.vertices = [];
  17169. for (var i = 0, l = points.length; i < l; i++) {
  17170. var point = points[i];
  17171. this.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  17172. }
  17173. return this;
  17174. },
  17175. sortFacesByMaterialIndex: function sortFacesByMaterialIndex() {
  17176. var faces = this.faces;
  17177. var length = faces.length; // tag faces
  17178. for (var i = 0; i < length; i++) {
  17179. faces[i]._id = i;
  17180. } // sort faces
  17181. function materialIndexSort(a, b) {
  17182. return a.materialIndex - b.materialIndex;
  17183. }
  17184. faces.sort(materialIndexSort); // sort uvs
  17185. var uvs1 = this.faceVertexUvs[0];
  17186. var uvs2 = this.faceVertexUvs[1];
  17187. var newUvs1, newUvs2;
  17188. if (uvs1 && uvs1.length === length) newUvs1 = [];
  17189. if (uvs2 && uvs2.length === length) newUvs2 = [];
  17190. for (var _i11 = 0; _i11 < length; _i11++) {
  17191. var id = faces[_i11]._id;
  17192. if (newUvs1) newUvs1.push(uvs1[id]);
  17193. if (newUvs2) newUvs2.push(uvs2[id]);
  17194. }
  17195. if (newUvs1) this.faceVertexUvs[0] = newUvs1;
  17196. if (newUvs2) this.faceVertexUvs[1] = newUvs2;
  17197. },
  17198. toJSON: function toJSON() {
  17199. var data = {
  17200. metadata: {
  17201. version: 4.5,
  17202. type: 'Geometry',
  17203. generator: 'Geometry.toJSON'
  17204. }
  17205. }; // standard Geometry serialization
  17206. data.uuid = this.uuid;
  17207. data.type = this.type;
  17208. if (this.name !== '') data.name = this.name;
  17209. if (this.parameters !== undefined) {
  17210. var parameters = this.parameters;
  17211. for (var key in parameters) {
  17212. if (parameters[key] !== undefined) data[key] = parameters[key];
  17213. }
  17214. return data;
  17215. }
  17216. var vertices = [];
  17217. for (var i = 0; i < this.vertices.length; i++) {
  17218. var vertex = this.vertices[i];
  17219. vertices.push(vertex.x, vertex.y, vertex.z);
  17220. }
  17221. var faces = [];
  17222. var normals = [];
  17223. var normalsHash = {};
  17224. var colors = [];
  17225. var colorsHash = {};
  17226. var uvs = [];
  17227. var uvsHash = {};
  17228. for (var _i12 = 0; _i12 < this.faces.length; _i12++) {
  17229. var face = this.faces[_i12];
  17230. var hasMaterial = true;
  17231. var hasFaceUv = false; // deprecated
  17232. var hasFaceVertexUv = this.faceVertexUvs[0][_i12] !== undefined;
  17233. var hasFaceNormal = face.normal.length() > 0;
  17234. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  17235. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  17236. var hasFaceVertexColor = face.vertexColors.length > 0;
  17237. var faceType = 0;
  17238. faceType = setBit(faceType, 0, 0); // isQuad
  17239. faceType = setBit(faceType, 1, hasMaterial);
  17240. faceType = setBit(faceType, 2, hasFaceUv);
  17241. faceType = setBit(faceType, 3, hasFaceVertexUv);
  17242. faceType = setBit(faceType, 4, hasFaceNormal);
  17243. faceType = setBit(faceType, 5, hasFaceVertexNormal);
  17244. faceType = setBit(faceType, 6, hasFaceColor);
  17245. faceType = setBit(faceType, 7, hasFaceVertexColor);
  17246. faces.push(faceType);
  17247. faces.push(face.a, face.b, face.c);
  17248. faces.push(face.materialIndex);
  17249. if (hasFaceVertexUv) {
  17250. var faceVertexUvs = this.faceVertexUvs[0][_i12];
  17251. faces.push(getUvIndex(faceVertexUvs[0]), getUvIndex(faceVertexUvs[1]), getUvIndex(faceVertexUvs[2]));
  17252. }
  17253. if (hasFaceNormal) {
  17254. faces.push(getNormalIndex(face.normal));
  17255. }
  17256. if (hasFaceVertexNormal) {
  17257. var vertexNormals = face.vertexNormals;
  17258. faces.push(getNormalIndex(vertexNormals[0]), getNormalIndex(vertexNormals[1]), getNormalIndex(vertexNormals[2]));
  17259. }
  17260. if (hasFaceColor) {
  17261. faces.push(getColorIndex(face.color));
  17262. }
  17263. if (hasFaceVertexColor) {
  17264. var vertexColors = face.vertexColors;
  17265. faces.push(getColorIndex(vertexColors[0]), getColorIndex(vertexColors[1]), getColorIndex(vertexColors[2]));
  17266. }
  17267. }
  17268. function setBit(value, position, enabled) {
  17269. return enabled ? value | 1 << position : value & ~(1 << position);
  17270. }
  17271. function getNormalIndex(normal) {
  17272. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  17273. if (normalsHash[hash] !== undefined) {
  17274. return normalsHash[hash];
  17275. }
  17276. normalsHash[hash] = normals.length / 3;
  17277. normals.push(normal.x, normal.y, normal.z);
  17278. return normalsHash[hash];
  17279. }
  17280. function getColorIndex(color) {
  17281. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  17282. if (colorsHash[hash] !== undefined) {
  17283. return colorsHash[hash];
  17284. }
  17285. colorsHash[hash] = colors.length;
  17286. colors.push(color.getHex());
  17287. return colorsHash[hash];
  17288. }
  17289. function getUvIndex(uv) {
  17290. var hash = uv.x.toString() + uv.y.toString();
  17291. if (uvsHash[hash] !== undefined) {
  17292. return uvsHash[hash];
  17293. }
  17294. uvsHash[hash] = uvs.length / 2;
  17295. uvs.push(uv.x, uv.y);
  17296. return uvsHash[hash];
  17297. }
  17298. data.data = {};
  17299. data.data.vertices = vertices;
  17300. data.data.normals = normals;
  17301. if (colors.length > 0) data.data.colors = colors;
  17302. if (uvs.length > 0) data.data.uvs = [uvs]; // temporal backward compatibility
  17303. data.data.faces = faces;
  17304. return data;
  17305. },
  17306. clone: function clone() {
  17307. /*
  17308. // Handle primitives
  17309. const parameters = this.parameters;
  17310. if ( parameters !== undefined ) {
  17311. const values = [];
  17312. for ( const key in parameters ) {
  17313. values.push( parameters[ key ] );
  17314. }
  17315. const geometry = Object.create( this.constructor.prototype );
  17316. this.constructor.apply( geometry, values );
  17317. return geometry;
  17318. }
  17319. return new this.constructor().copy( this );
  17320. */
  17321. return new Geometry().copy(this);
  17322. },
  17323. copy: function copy(source) {
  17324. // reset
  17325. this.vertices = [];
  17326. this.colors = [];
  17327. this.faces = [];
  17328. this.faceVertexUvs = [[]];
  17329. this.morphTargets = [];
  17330. this.morphNormals = [];
  17331. this.skinWeights = [];
  17332. this.skinIndices = [];
  17333. this.lineDistances = [];
  17334. this.boundingBox = null;
  17335. this.boundingSphere = null; // name
  17336. this.name = source.name; // vertices
  17337. var vertices = source.vertices;
  17338. for (var i = 0, il = vertices.length; i < il; i++) {
  17339. this.vertices.push(vertices[i].clone());
  17340. } // colors
  17341. var colors = source.colors;
  17342. for (var _i13 = 0, _il7 = colors.length; _i13 < _il7; _i13++) {
  17343. this.colors.push(colors[_i13].clone());
  17344. } // faces
  17345. var faces = source.faces;
  17346. for (var _i14 = 0, _il8 = faces.length; _i14 < _il8; _i14++) {
  17347. this.faces.push(faces[_i14].clone());
  17348. } // face vertex uvs
  17349. for (var _i15 = 0, _il9 = source.faceVertexUvs.length; _i15 < _il9; _i15++) {
  17350. var faceVertexUvs = source.faceVertexUvs[_i15];
  17351. if (this.faceVertexUvs[_i15] === undefined) {
  17352. this.faceVertexUvs[_i15] = [];
  17353. }
  17354. for (var j = 0, jl = faceVertexUvs.length; j < jl; j++) {
  17355. var uvs = faceVertexUvs[j],
  17356. uvsCopy = [];
  17357. for (var k = 0, kl = uvs.length; k < kl; k++) {
  17358. var uv = uvs[k];
  17359. uvsCopy.push(uv.clone());
  17360. }
  17361. this.faceVertexUvs[_i15].push(uvsCopy);
  17362. }
  17363. } // morph targets
  17364. var morphTargets = source.morphTargets;
  17365. for (var _i16 = 0, _il10 = morphTargets.length; _i16 < _il10; _i16++) {
  17366. var morphTarget = {};
  17367. morphTarget.name = morphTargets[_i16].name; // vertices
  17368. if (morphTargets[_i16].vertices !== undefined) {
  17369. morphTarget.vertices = [];
  17370. for (var _j3 = 0, _jl3 = morphTargets[_i16].vertices.length; _j3 < _jl3; _j3++) {
  17371. morphTarget.vertices.push(morphTargets[_i16].vertices[_j3].clone());
  17372. }
  17373. } // normals
  17374. if (morphTargets[_i16].normals !== undefined) {
  17375. morphTarget.normals = [];
  17376. for (var _j4 = 0, _jl4 = morphTargets[_i16].normals.length; _j4 < _jl4; _j4++) {
  17377. morphTarget.normals.push(morphTargets[_i16].normals[_j4].clone());
  17378. }
  17379. }
  17380. this.morphTargets.push(morphTarget);
  17381. } // morph normals
  17382. var morphNormals = source.morphNormals;
  17383. for (var _i17 = 0, _il11 = morphNormals.length; _i17 < _il11; _i17++) {
  17384. var morphNormal = {}; // vertex normals
  17385. if (morphNormals[_i17].vertexNormals !== undefined) {
  17386. morphNormal.vertexNormals = [];
  17387. for (var _j5 = 0, _jl5 = morphNormals[_i17].vertexNormals.length; _j5 < _jl5; _j5++) {
  17388. var srcVertexNormal = morphNormals[_i17].vertexNormals[_j5];
  17389. var destVertexNormal = {};
  17390. destVertexNormal.a = srcVertexNormal.a.clone();
  17391. destVertexNormal.b = srcVertexNormal.b.clone();
  17392. destVertexNormal.c = srcVertexNormal.c.clone();
  17393. morphNormal.vertexNormals.push(destVertexNormal);
  17394. }
  17395. } // face normals
  17396. if (morphNormals[_i17].faceNormals !== undefined) {
  17397. morphNormal.faceNormals = [];
  17398. for (var _j6 = 0, _jl6 = morphNormals[_i17].faceNormals.length; _j6 < _jl6; _j6++) {
  17399. morphNormal.faceNormals.push(morphNormals[_i17].faceNormals[_j6].clone());
  17400. }
  17401. }
  17402. this.morphNormals.push(morphNormal);
  17403. } // skin weights
  17404. var skinWeights = source.skinWeights;
  17405. for (var _i18 = 0, _il12 = skinWeights.length; _i18 < _il12; _i18++) {
  17406. this.skinWeights.push(skinWeights[_i18].clone());
  17407. } // skin indices
  17408. var skinIndices = source.skinIndices;
  17409. for (var _i19 = 0, _il13 = skinIndices.length; _i19 < _il13; _i19++) {
  17410. this.skinIndices.push(skinIndices[_i19].clone());
  17411. } // line distances
  17412. var lineDistances = source.lineDistances;
  17413. for (var _i20 = 0, _il14 = lineDistances.length; _i20 < _il14; _i20++) {
  17414. this.lineDistances.push(lineDistances[_i20]);
  17415. } // bounding box
  17416. var boundingBox = source.boundingBox;
  17417. if (boundingBox !== null) {
  17418. this.boundingBox = boundingBox.clone();
  17419. } // bounding sphere
  17420. var boundingSphere = source.boundingSphere;
  17421. if (boundingSphere !== null) {
  17422. this.boundingSphere = boundingSphere.clone();
  17423. } // update flags
  17424. this.elementsNeedUpdate = source.elementsNeedUpdate;
  17425. this.verticesNeedUpdate = source.verticesNeedUpdate;
  17426. this.uvsNeedUpdate = source.uvsNeedUpdate;
  17427. this.normalsNeedUpdate = source.normalsNeedUpdate;
  17428. this.colorsNeedUpdate = source.colorsNeedUpdate;
  17429. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  17430. this.groupsNeedUpdate = source.groupsNeedUpdate;
  17431. return this;
  17432. },
  17433. dispose: function dispose() {
  17434. this.dispatchEvent({
  17435. type: 'dispose'
  17436. });
  17437. }
  17438. });
  17439. var BoxGeometry = /*#__PURE__*/function (_Geometry) {
  17440. _inheritsLoose(BoxGeometry, _Geometry);
  17441. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  17442. var _this;
  17443. _this = _Geometry.call(this) || this;
  17444. _this.type = 'BoxGeometry';
  17445. _this.parameters = {
  17446. width: width,
  17447. height: height,
  17448. depth: depth,
  17449. widthSegments: widthSegments,
  17450. heightSegments: heightSegments,
  17451. depthSegments: depthSegments
  17452. };
  17453. _this.fromBufferGeometry(new BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments));
  17454. _this.mergeVertices();
  17455. return _this;
  17456. }
  17457. return BoxGeometry;
  17458. }(Geometry);
  17459. var CircleBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17460. _inheritsLoose(CircleBufferGeometry, _BufferGeometry);
  17461. function CircleBufferGeometry(radius, segments, thetaStart, thetaLength) {
  17462. var _this;
  17463. if (radius === void 0) {
  17464. radius = 1;
  17465. }
  17466. if (segments === void 0) {
  17467. segments = 8;
  17468. }
  17469. if (thetaStart === void 0) {
  17470. thetaStart = 0;
  17471. }
  17472. if (thetaLength === void 0) {
  17473. thetaLength = Math.PI * 2;
  17474. }
  17475. _this = _BufferGeometry.call(this) || this;
  17476. _this.type = 'CircleBufferGeometry';
  17477. _this.parameters = {
  17478. radius: radius,
  17479. segments: segments,
  17480. thetaStart: thetaStart,
  17481. thetaLength: thetaLength
  17482. };
  17483. segments = Math.max(3, segments); // buffers
  17484. var indices = [];
  17485. var vertices = [];
  17486. var normals = [];
  17487. var uvs = []; // helper variables
  17488. var vertex = new Vector3();
  17489. var uv = new Vector2(); // center point
  17490. vertices.push(0, 0, 0);
  17491. normals.push(0, 0, 1);
  17492. uvs.push(0.5, 0.5);
  17493. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17494. var segment = thetaStart + s / segments * thetaLength; // vertex
  17495. vertex.x = radius * Math.cos(segment);
  17496. vertex.y = radius * Math.sin(segment);
  17497. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17498. normals.push(0, 0, 1); // uvs
  17499. uv.x = (vertices[i] / radius + 1) / 2;
  17500. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17501. uvs.push(uv.x, uv.y);
  17502. } // indices
  17503. for (var _i = 1; _i <= segments; _i++) {
  17504. indices.push(_i, _i + 1, 0);
  17505. } // build geometry
  17506. _this.setIndex(indices);
  17507. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17508. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17509. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17510. return _this;
  17511. }
  17512. return CircleBufferGeometry;
  17513. }(BufferGeometry);
  17514. var CircleGeometry = /*#__PURE__*/function (_Geometry) {
  17515. _inheritsLoose(CircleGeometry, _Geometry);
  17516. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17517. var _this;
  17518. _this = _Geometry.call(this) || this;
  17519. _this.type = 'CircleGeometry';
  17520. _this.parameters = {
  17521. radius: radius,
  17522. segments: segments,
  17523. thetaStart: thetaStart,
  17524. thetaLength: thetaLength
  17525. };
  17526. _this.fromBufferGeometry(new CircleBufferGeometry(radius, segments, thetaStart, thetaLength));
  17527. _this.mergeVertices();
  17528. return _this;
  17529. }
  17530. return CircleGeometry;
  17531. }(Geometry);
  17532. var CylinderBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17533. _inheritsLoose(CylinderBufferGeometry, _BufferGeometry);
  17534. function CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17535. var _this;
  17536. if (radiusTop === void 0) {
  17537. radiusTop = 1;
  17538. }
  17539. if (radiusBottom === void 0) {
  17540. radiusBottom = 1;
  17541. }
  17542. if (height === void 0) {
  17543. height = 1;
  17544. }
  17545. if (radialSegments === void 0) {
  17546. radialSegments = 8;
  17547. }
  17548. if (heightSegments === void 0) {
  17549. heightSegments = 1;
  17550. }
  17551. if (openEnded === void 0) {
  17552. openEnded = false;
  17553. }
  17554. if (thetaStart === void 0) {
  17555. thetaStart = 0;
  17556. }
  17557. if (thetaLength === void 0) {
  17558. thetaLength = Math.PI * 2;
  17559. }
  17560. _this = _BufferGeometry.call(this) || this;
  17561. _this.type = 'CylinderBufferGeometry';
  17562. _this.parameters = {
  17563. radiusTop: radiusTop,
  17564. radiusBottom: radiusBottom,
  17565. height: height,
  17566. radialSegments: radialSegments,
  17567. heightSegments: heightSegments,
  17568. openEnded: openEnded,
  17569. thetaStart: thetaStart,
  17570. thetaLength: thetaLength
  17571. };
  17572. var scope = _assertThisInitialized(_this);
  17573. radialSegments = Math.floor(radialSegments);
  17574. heightSegments = Math.floor(heightSegments); // buffers
  17575. var indices = [];
  17576. var vertices = [];
  17577. var normals = [];
  17578. var uvs = []; // helper variables
  17579. var index = 0;
  17580. var indexArray = [];
  17581. var halfHeight = height / 2;
  17582. var groupStart = 0; // generate geometry
  17583. generateTorso();
  17584. if (openEnded === false) {
  17585. if (radiusTop > 0) generateCap(true);
  17586. if (radiusBottom > 0) generateCap(false);
  17587. } // build geometry
  17588. _this.setIndex(indices);
  17589. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17590. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17591. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17592. function generateTorso() {
  17593. var normal = new Vector3();
  17594. var vertex = new Vector3();
  17595. var groupCount = 0; // this will be used to calculate the normal
  17596. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17597. for (var y = 0; y <= heightSegments; y++) {
  17598. var indexRow = [];
  17599. var v = y / heightSegments; // calculate the radius of the current row
  17600. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17601. for (var x = 0; x <= radialSegments; x++) {
  17602. var u = x / radialSegments;
  17603. var theta = u * thetaLength + thetaStart;
  17604. var sinTheta = Math.sin(theta);
  17605. var cosTheta = Math.cos(theta); // vertex
  17606. vertex.x = radius * sinTheta;
  17607. vertex.y = -v * height + halfHeight;
  17608. vertex.z = radius * cosTheta;
  17609. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17610. normal.set(sinTheta, slope, cosTheta).normalize();
  17611. normals.push(normal.x, normal.y, normal.z); // uv
  17612. uvs.push(u, 1 - v); // save index of vertex in respective row
  17613. indexRow.push(index++);
  17614. } // now save vertices of the row in our index array
  17615. indexArray.push(indexRow);
  17616. } // generate indices
  17617. for (var _x = 0; _x < radialSegments; _x++) {
  17618. for (var _y = 0; _y < heightSegments; _y++) {
  17619. // we use the index array to access the correct indices
  17620. var a = indexArray[_y][_x];
  17621. var b = indexArray[_y + 1][_x];
  17622. var c = indexArray[_y + 1][_x + 1];
  17623. var d = indexArray[_y][_x + 1]; // faces
  17624. indices.push(a, b, d);
  17625. indices.push(b, c, d); // update group counter
  17626. groupCount += 6;
  17627. }
  17628. } // add a group to the geometry. this will ensure multi material support
  17629. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17630. groupStart += groupCount;
  17631. }
  17632. function generateCap(top) {
  17633. // save the index of the first center vertex
  17634. var centerIndexStart = index;
  17635. var uv = new Vector2();
  17636. var vertex = new Vector3();
  17637. var groupCount = 0;
  17638. var radius = top === true ? radiusTop : radiusBottom;
  17639. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17640. // because the geometry needs one set of uvs per face,
  17641. // we must generate a center vertex per face/segment
  17642. for (var x = 1; x <= radialSegments; x++) {
  17643. // vertex
  17644. vertices.push(0, halfHeight * sign, 0); // normal
  17645. normals.push(0, sign, 0); // uv
  17646. uvs.push(0.5, 0.5); // increase index
  17647. index++;
  17648. } // save the index of the last center vertex
  17649. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17650. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17651. var u = _x2 / radialSegments;
  17652. var theta = u * thetaLength + thetaStart;
  17653. var cosTheta = Math.cos(theta);
  17654. var sinTheta = Math.sin(theta); // vertex
  17655. vertex.x = radius * sinTheta;
  17656. vertex.y = halfHeight * sign;
  17657. vertex.z = radius * cosTheta;
  17658. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17659. normals.push(0, sign, 0); // uv
  17660. uv.x = cosTheta * 0.5 + 0.5;
  17661. uv.y = sinTheta * 0.5 * sign + 0.5;
  17662. uvs.push(uv.x, uv.y); // increase index
  17663. index++;
  17664. } // generate indices
  17665. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17666. var c = centerIndexStart + _x3;
  17667. var i = centerIndexEnd + _x3;
  17668. if (top === true) {
  17669. // face top
  17670. indices.push(i, i + 1, c);
  17671. } else {
  17672. // face bottom
  17673. indices.push(i + 1, i, c);
  17674. }
  17675. groupCount += 3;
  17676. } // add a group to the geometry. this will ensure multi material support
  17677. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17678. groupStart += groupCount;
  17679. }
  17680. return _this;
  17681. }
  17682. return CylinderBufferGeometry;
  17683. }(BufferGeometry);
  17684. var CylinderGeometry = /*#__PURE__*/function (_Geometry) {
  17685. _inheritsLoose(CylinderGeometry, _Geometry);
  17686. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17687. var _this;
  17688. _this = _Geometry.call(this) || this;
  17689. _this.type = 'CylinderGeometry';
  17690. _this.parameters = {
  17691. radiusTop: radiusTop,
  17692. radiusBottom: radiusBottom,
  17693. height: height,
  17694. radialSegments: radialSegments,
  17695. heightSegments: heightSegments,
  17696. openEnded: openEnded,
  17697. thetaStart: thetaStart,
  17698. thetaLength: thetaLength
  17699. };
  17700. _this.fromBufferGeometry(new CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength));
  17701. _this.mergeVertices();
  17702. return _this;
  17703. }
  17704. return CylinderGeometry;
  17705. }(Geometry);
  17706. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17707. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17708. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17709. var _this;
  17710. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17711. _this.type = 'ConeGeometry';
  17712. _this.parameters = {
  17713. radius: radius,
  17714. height: height,
  17715. radialSegments: radialSegments,
  17716. heightSegments: heightSegments,
  17717. openEnded: openEnded,
  17718. thetaStart: thetaStart,
  17719. thetaLength: thetaLength
  17720. };
  17721. return _this;
  17722. }
  17723. return ConeGeometry;
  17724. }(CylinderGeometry);
  17725. var ConeBufferGeometry = /*#__PURE__*/function (_CylinderBufferGeomet) {
  17726. _inheritsLoose(ConeBufferGeometry, _CylinderBufferGeomet);
  17727. function ConeBufferGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17728. var _this;
  17729. if (radius === void 0) {
  17730. radius = 1;
  17731. }
  17732. if (height === void 0) {
  17733. height = 1;
  17734. }
  17735. if (radialSegments === void 0) {
  17736. radialSegments = 8;
  17737. }
  17738. if (heightSegments === void 0) {
  17739. heightSegments = 1;
  17740. }
  17741. if (openEnded === void 0) {
  17742. openEnded = false;
  17743. }
  17744. if (thetaStart === void 0) {
  17745. thetaStart = 0;
  17746. }
  17747. if (thetaLength === void 0) {
  17748. thetaLength = Math.PI * 2;
  17749. }
  17750. _this = _CylinderBufferGeomet.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17751. _this.type = 'ConeBufferGeometry';
  17752. _this.parameters = {
  17753. radius: radius,
  17754. height: height,
  17755. radialSegments: radialSegments,
  17756. heightSegments: heightSegments,
  17757. openEnded: openEnded,
  17758. thetaStart: thetaStart,
  17759. thetaLength: thetaLength
  17760. };
  17761. return _this;
  17762. }
  17763. return ConeBufferGeometry;
  17764. }(CylinderBufferGeometry);
  17765. var PolyhedronBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17766. _inheritsLoose(PolyhedronBufferGeometry, _BufferGeometry);
  17767. function PolyhedronBufferGeometry(vertices, indices, radius, detail) {
  17768. var _this;
  17769. if (radius === void 0) {
  17770. radius = 1;
  17771. }
  17772. if (detail === void 0) {
  17773. detail = 0;
  17774. }
  17775. _this = _BufferGeometry.call(this) || this;
  17776. _this.type = 'PolyhedronBufferGeometry';
  17777. _this.parameters = {
  17778. vertices: vertices,
  17779. indices: indices,
  17780. radius: radius,
  17781. detail: detail
  17782. }; // default buffer data
  17783. var vertexBuffer = [];
  17784. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17785. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17786. applyRadius(radius); // finally, create the uv data
  17787. generateUVs(); // build non-indexed geometry
  17788. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17789. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17790. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17791. if (detail === 0) {
  17792. _this.computeVertexNormals(); // flat normals
  17793. } else {
  17794. _this.normalizeNormals(); // smooth normals
  17795. } // helper functions
  17796. function subdivide(detail) {
  17797. var a = new Vector3();
  17798. var b = new Vector3();
  17799. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17800. for (var i = 0; i < indices.length; i += 3) {
  17801. // get the vertices of the face
  17802. getVertexByIndex(indices[i + 0], a);
  17803. getVertexByIndex(indices[i + 1], b);
  17804. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17805. subdivideFace(a, b, c, detail);
  17806. }
  17807. }
  17808. function subdivideFace(a, b, c, detail) {
  17809. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17810. var v = []; // construct all of the vertices for this subdivision
  17811. for (var i = 0; i <= cols; i++) {
  17812. v[i] = [];
  17813. var aj = a.clone().lerp(c, i / cols);
  17814. var bj = b.clone().lerp(c, i / cols);
  17815. var rows = cols - i;
  17816. for (var j = 0; j <= rows; j++) {
  17817. if (j === 0 && i === cols) {
  17818. v[i][j] = aj;
  17819. } else {
  17820. v[i][j] = aj.clone().lerp(bj, j / rows);
  17821. }
  17822. }
  17823. } // construct all of the faces
  17824. for (var _i = 0; _i < cols; _i++) {
  17825. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17826. var k = Math.floor(_j / 2);
  17827. if (_j % 2 === 0) {
  17828. pushVertex(v[_i][k + 1]);
  17829. pushVertex(v[_i + 1][k]);
  17830. pushVertex(v[_i][k]);
  17831. } else {
  17832. pushVertex(v[_i][k + 1]);
  17833. pushVertex(v[_i + 1][k + 1]);
  17834. pushVertex(v[_i + 1][k]);
  17835. }
  17836. }
  17837. }
  17838. }
  17839. function applyRadius(radius) {
  17840. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17841. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17842. vertex.x = vertexBuffer[i + 0];
  17843. vertex.y = vertexBuffer[i + 1];
  17844. vertex.z = vertexBuffer[i + 2];
  17845. vertex.normalize().multiplyScalar(radius);
  17846. vertexBuffer[i + 0] = vertex.x;
  17847. vertexBuffer[i + 1] = vertex.y;
  17848. vertexBuffer[i + 2] = vertex.z;
  17849. }
  17850. }
  17851. function generateUVs() {
  17852. var vertex = new Vector3();
  17853. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17854. vertex.x = vertexBuffer[i + 0];
  17855. vertex.y = vertexBuffer[i + 1];
  17856. vertex.z = vertexBuffer[i + 2];
  17857. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17858. var v = inclination(vertex) / Math.PI + 0.5;
  17859. uvBuffer.push(u, 1 - v);
  17860. }
  17861. correctUVs();
  17862. correctSeam();
  17863. }
  17864. function correctSeam() {
  17865. // handle case when face straddles the seam, see #3269
  17866. for (var i = 0; i < uvBuffer.length; i += 6) {
  17867. // uv data of a single face
  17868. var x0 = uvBuffer[i + 0];
  17869. var x1 = uvBuffer[i + 2];
  17870. var x2 = uvBuffer[i + 4];
  17871. var max = Math.max(x0, x1, x2);
  17872. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17873. if (max > 0.9 && min < 0.1) {
  17874. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17875. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17876. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17877. }
  17878. }
  17879. }
  17880. function pushVertex(vertex) {
  17881. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17882. }
  17883. function getVertexByIndex(index, vertex) {
  17884. var stride = index * 3;
  17885. vertex.x = vertices[stride + 0];
  17886. vertex.y = vertices[stride + 1];
  17887. vertex.z = vertices[stride + 2];
  17888. }
  17889. function correctUVs() {
  17890. var a = new Vector3();
  17891. var b = new Vector3();
  17892. var c = new Vector3();
  17893. var centroid = new Vector3();
  17894. var uvA = new Vector2();
  17895. var uvB = new Vector2();
  17896. var uvC = new Vector2();
  17897. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17898. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17899. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17900. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17901. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17902. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17903. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17904. centroid.copy(a).add(b).add(c).divideScalar(3);
  17905. var azi = azimuth(centroid);
  17906. correctUV(uvA, j + 0, a, azi);
  17907. correctUV(uvB, j + 2, b, azi);
  17908. correctUV(uvC, j + 4, c, azi);
  17909. }
  17910. }
  17911. function correctUV(uv, stride, vector, azimuth) {
  17912. if (azimuth < 0 && uv.x === 1) {
  17913. uvBuffer[stride] = uv.x - 1;
  17914. }
  17915. if (vector.x === 0 && vector.z === 0) {
  17916. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17917. }
  17918. } // Angle around the Y axis, counter-clockwise when looking from above.
  17919. function azimuth(vector) {
  17920. return Math.atan2(vector.z, -vector.x);
  17921. } // Angle above the XZ plane.
  17922. function inclination(vector) {
  17923. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17924. }
  17925. return _this;
  17926. }
  17927. return PolyhedronBufferGeometry;
  17928. }(BufferGeometry);
  17929. var DodecahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  17930. _inheritsLoose(DodecahedronBufferGeometry, _PolyhedronBufferGeom);
  17931. function DodecahedronBufferGeometry(radius, detail) {
  17932. var _this;
  17933. if (radius === void 0) {
  17934. radius = 1;
  17935. }
  17936. if (detail === void 0) {
  17937. detail = 0;
  17938. }
  17939. var t = (1 + Math.sqrt(5)) / 2;
  17940. var r = 1 / t;
  17941. var vertices = [// (±1, ±1, ±1)
  17942. -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/φ, ±φ)
  17943. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17944. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17945. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17946. 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];
  17947. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  17948. _this.type = 'DodecahedronBufferGeometry';
  17949. _this.parameters = {
  17950. radius: radius,
  17951. detail: detail
  17952. };
  17953. return _this;
  17954. }
  17955. return DodecahedronBufferGeometry;
  17956. }(PolyhedronBufferGeometry);
  17957. var DodecahedronGeometry = /*#__PURE__*/function (_Geometry) {
  17958. _inheritsLoose(DodecahedronGeometry, _Geometry);
  17959. function DodecahedronGeometry(radius, detail) {
  17960. var _this;
  17961. _this = _Geometry.call(this) || this;
  17962. _this.type = 'DodecahedronGeometry';
  17963. _this.parameters = {
  17964. radius: radius,
  17965. detail: detail
  17966. };
  17967. _this.fromBufferGeometry(new DodecahedronBufferGeometry(radius, detail));
  17968. _this.mergeVertices();
  17969. return _this;
  17970. }
  17971. return DodecahedronGeometry;
  17972. }(Geometry);
  17973. var _v0$2 = new Vector3();
  17974. var _v1$5 = new Vector3();
  17975. var _normal$1 = new Vector3();
  17976. var _triangle = new Triangle();
  17977. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17978. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17979. function EdgesGeometry(geometry, thresholdAngle) {
  17980. var _this;
  17981. _this = _BufferGeometry.call(this) || this;
  17982. _this.type = 'EdgesGeometry';
  17983. _this.parameters = {
  17984. thresholdAngle: thresholdAngle
  17985. };
  17986. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17987. if (geometry.isGeometry) {
  17988. geometry = new BufferGeometry().fromGeometry(geometry);
  17989. }
  17990. var precisionPoints = 4;
  17991. var precision = Math.pow(10, precisionPoints);
  17992. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17993. var indexAttr = geometry.getIndex();
  17994. var positionAttr = geometry.getAttribute('position');
  17995. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17996. var indexArr = [0, 0, 0];
  17997. var vertKeys = ['a', 'b', 'c'];
  17998. var hashes = new Array(3);
  17999. var edgeData = {};
  18000. var vertices = [];
  18001. for (var i = 0; i < indexCount; i += 3) {
  18002. if (indexAttr) {
  18003. indexArr[0] = indexAttr.getX(i);
  18004. indexArr[1] = indexAttr.getX(i + 1);
  18005. indexArr[2] = indexAttr.getX(i + 2);
  18006. } else {
  18007. indexArr[0] = i;
  18008. indexArr[1] = i + 1;
  18009. indexArr[2] = i + 2;
  18010. }
  18011. var a = _triangle.a,
  18012. b = _triangle.b,
  18013. c = _triangle.c;
  18014. a.fromBufferAttribute(positionAttr, indexArr[0]);
  18015. b.fromBufferAttribute(positionAttr, indexArr[1]);
  18016. c.fromBufferAttribute(positionAttr, indexArr[2]);
  18017. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  18018. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  18019. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  18020. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  18021. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  18022. continue;
  18023. } // iterate over every edge
  18024. for (var j = 0; j < 3; j++) {
  18025. // get the first and next vertex making up the edge
  18026. var jNext = (j + 1) % 3;
  18027. var vecHash0 = hashes[j];
  18028. var vecHash1 = hashes[jNext];
  18029. var v0 = _triangle[vertKeys[j]];
  18030. var v1 = _triangle[vertKeys[jNext]];
  18031. var hash = vecHash0 + "_" + vecHash1;
  18032. var reverseHash = vecHash1 + "_" + vecHash0;
  18033. if (reverseHash in edgeData && edgeData[reverseHash]) {
  18034. // if we found a sibling edge add it into the vertex array if
  18035. // it meets the angle threshold and delete the edge from the map.
  18036. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  18037. vertices.push(v0.x, v0.y, v0.z);
  18038. vertices.push(v1.x, v1.y, v1.z);
  18039. }
  18040. edgeData[reverseHash] = null;
  18041. } else if (!(hash in edgeData)) {
  18042. // if we've already got an edge here then skip adding a new one
  18043. edgeData[hash] = {
  18044. index0: indexArr[j],
  18045. index1: indexArr[jNext],
  18046. normal: _normal$1.clone()
  18047. };
  18048. }
  18049. }
  18050. } // iterate over all remaining, unmatched edges and add them to the vertex array
  18051. for (var key in edgeData) {
  18052. if (edgeData[key]) {
  18053. var _edgeData$key = edgeData[key],
  18054. index0 = _edgeData$key.index0,
  18055. index1 = _edgeData$key.index1;
  18056. _v0$2.fromBufferAttribute(positionAttr, index0);
  18057. _v1$5.fromBufferAttribute(positionAttr, index1);
  18058. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  18059. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  18060. }
  18061. }
  18062. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18063. return _this;
  18064. }
  18065. return EdgesGeometry;
  18066. }(BufferGeometry);
  18067. /**
  18068. * Port from https://github.com/mapbox/earcut (v2.2.2)
  18069. */
  18070. var Earcut = {
  18071. triangulate: function triangulate(data, holeIndices, dim) {
  18072. dim = dim || 2;
  18073. var hasHoles = holeIndices && holeIndices.length;
  18074. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  18075. var outerNode = linkedList(data, 0, outerLen, dim, true);
  18076. var triangles = [];
  18077. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  18078. var minX, minY, maxX, maxY, x, y, invSize;
  18079. 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
  18080. if (data.length > 80 * dim) {
  18081. minX = maxX = data[0];
  18082. minY = maxY = data[1];
  18083. for (var i = dim; i < outerLen; i += dim) {
  18084. x = data[i];
  18085. y = data[i + 1];
  18086. if (x < minX) minX = x;
  18087. if (y < minY) minY = y;
  18088. if (x > maxX) maxX = x;
  18089. if (y > maxY) maxY = y;
  18090. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  18091. invSize = Math.max(maxX - minX, maxY - minY);
  18092. invSize = invSize !== 0 ? 1 / invSize : 0;
  18093. }
  18094. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  18095. return triangles;
  18096. }
  18097. }; // create a circular doubly linked list from polygon points in the specified winding order
  18098. function linkedList(data, start, end, dim, clockwise) {
  18099. var i, last;
  18100. if (clockwise === signedArea(data, start, end, dim) > 0) {
  18101. for (i = start; i < end; i += dim) {
  18102. last = insertNode(i, data[i], data[i + 1], last);
  18103. }
  18104. } else {
  18105. for (i = end - dim; i >= start; i -= dim) {
  18106. last = insertNode(i, data[i], data[i + 1], last);
  18107. }
  18108. }
  18109. if (last && equals(last, last.next)) {
  18110. removeNode(last);
  18111. last = last.next;
  18112. }
  18113. return last;
  18114. } // eliminate colinear or duplicate points
  18115. function filterPoints(start, end) {
  18116. if (!start) return start;
  18117. if (!end) end = start;
  18118. var p = start,
  18119. again;
  18120. do {
  18121. again = false;
  18122. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  18123. removeNode(p);
  18124. p = end = p.prev;
  18125. if (p === p.next) break;
  18126. again = true;
  18127. } else {
  18128. p = p.next;
  18129. }
  18130. } while (again || p !== end);
  18131. return end;
  18132. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  18133. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  18134. if (!ear) return; // interlink polygon nodes in z-order
  18135. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  18136. var stop = ear,
  18137. prev,
  18138. next; // iterate through ears, slicing them one by one
  18139. while (ear.prev !== ear.next) {
  18140. prev = ear.prev;
  18141. next = ear.next;
  18142. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  18143. // cut off the triangle
  18144. triangles.push(prev.i / dim);
  18145. triangles.push(ear.i / dim);
  18146. triangles.push(next.i / dim);
  18147. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  18148. ear = next.next;
  18149. stop = next.next;
  18150. continue;
  18151. }
  18152. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  18153. if (ear === stop) {
  18154. // try filtering points and slicing again
  18155. if (!pass) {
  18156. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  18157. } else if (pass === 1) {
  18158. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  18159. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  18160. } else if (pass === 2) {
  18161. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  18162. }
  18163. break;
  18164. }
  18165. }
  18166. } // check whether a polygon node forms a valid ear with adjacent nodes
  18167. function isEar(ear) {
  18168. var a = ear.prev,
  18169. b = ear,
  18170. c = ear.next;
  18171. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  18172. // now make sure we don't have other points inside the potential ear
  18173. var p = ear.next.next;
  18174. while (p !== ear.prev) {
  18175. 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;
  18176. p = p.next;
  18177. }
  18178. return true;
  18179. }
  18180. function isEarHashed(ear, minX, minY, invSize) {
  18181. var a = ear.prev,
  18182. b = ear,
  18183. c = ear.next;
  18184. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  18185. // triangle bbox; min & max are calculated like this for speed
  18186. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  18187. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  18188. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  18189. 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;
  18190. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  18191. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  18192. var p = ear.prevZ,
  18193. n = ear.nextZ; // look for points inside the triangle in both directions
  18194. while (p && p.z >= minZ && n && n.z <= maxZ) {
  18195. 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;
  18196. p = p.prevZ;
  18197. 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;
  18198. n = n.nextZ;
  18199. } // look for remaining points in decreasing z-order
  18200. while (p && p.z >= minZ) {
  18201. 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;
  18202. p = p.prevZ;
  18203. } // look for remaining points in increasing z-order
  18204. while (n && n.z <= maxZ) {
  18205. 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;
  18206. n = n.nextZ;
  18207. }
  18208. return true;
  18209. } // go through all polygon nodes and cure small local self-intersections
  18210. function cureLocalIntersections(start, triangles, dim) {
  18211. var p = start;
  18212. do {
  18213. var a = p.prev,
  18214. b = p.next.next;
  18215. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  18216. triangles.push(a.i / dim);
  18217. triangles.push(p.i / dim);
  18218. triangles.push(b.i / dim); // remove two nodes involved
  18219. removeNode(p);
  18220. removeNode(p.next);
  18221. p = start = b;
  18222. }
  18223. p = p.next;
  18224. } while (p !== start);
  18225. return filterPoints(p);
  18226. } // try splitting polygon into two and triangulate them independently
  18227. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  18228. // look for a valid diagonal that divides the polygon into two
  18229. var a = start;
  18230. do {
  18231. var b = a.next.next;
  18232. while (b !== a.prev) {
  18233. if (a.i !== b.i && isValidDiagonal(a, b)) {
  18234. // split the polygon in two by the diagonal
  18235. var c = splitPolygon(a, b); // filter colinear points around the cuts
  18236. a = filterPoints(a, a.next);
  18237. c = filterPoints(c, c.next); // run earcut on each half
  18238. earcutLinked(a, triangles, dim, minX, minY, invSize);
  18239. earcutLinked(c, triangles, dim, minX, minY, invSize);
  18240. return;
  18241. }
  18242. b = b.next;
  18243. }
  18244. a = a.next;
  18245. } while (a !== start);
  18246. } // link every hole into the outer loop, producing a single-ring polygon without holes
  18247. function eliminateHoles(data, holeIndices, outerNode, dim) {
  18248. var queue = [];
  18249. var i, len, start, end, list;
  18250. for (i = 0, len = holeIndices.length; i < len; i++) {
  18251. start = holeIndices[i] * dim;
  18252. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  18253. list = linkedList(data, start, end, dim, false);
  18254. if (list === list.next) list.steiner = true;
  18255. queue.push(getLeftmost(list));
  18256. }
  18257. queue.sort(compareX); // process holes from left to right
  18258. for (i = 0; i < queue.length; i++) {
  18259. eliminateHole(queue[i], outerNode);
  18260. outerNode = filterPoints(outerNode, outerNode.next);
  18261. }
  18262. return outerNode;
  18263. }
  18264. function compareX(a, b) {
  18265. return a.x - b.x;
  18266. } // find a bridge between vertices that connects hole with an outer ring and and link it
  18267. function eliminateHole(hole, outerNode) {
  18268. outerNode = findHoleBridge(hole, outerNode);
  18269. if (outerNode) {
  18270. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  18271. filterPoints(outerNode, outerNode.next);
  18272. filterPoints(b, b.next);
  18273. }
  18274. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  18275. function findHoleBridge(hole, outerNode) {
  18276. var p = outerNode;
  18277. var hx = hole.x;
  18278. var hy = hole.y;
  18279. var qx = -Infinity,
  18280. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  18281. // segment's endpoint with lesser x will be potential connection point
  18282. do {
  18283. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  18284. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  18285. if (x <= hx && x > qx) {
  18286. qx = x;
  18287. if (x === hx) {
  18288. if (hy === p.y) return p;
  18289. if (hy === p.next.y) return p.next;
  18290. }
  18291. m = p.x < p.next.x ? p : p.next;
  18292. }
  18293. }
  18294. p = p.next;
  18295. } while (p !== outerNode);
  18296. if (!m) return null;
  18297. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  18298. // look for points inside the triangle of hole point, segment intersection and endpoint;
  18299. // if there are no points found, we have a valid connection;
  18300. // otherwise choose the point of the minimum angle with the ray as connection point
  18301. var stop = m,
  18302. mx = m.x,
  18303. my = m.y;
  18304. var tanMin = Infinity,
  18305. tan;
  18306. p = m;
  18307. do {
  18308. 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)) {
  18309. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  18310. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  18311. m = p;
  18312. tanMin = tan;
  18313. }
  18314. }
  18315. p = p.next;
  18316. } while (p !== stop);
  18317. return m;
  18318. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  18319. function sectorContainsSector(m, p) {
  18320. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  18321. } // interlink polygon nodes in z-order
  18322. function indexCurve(start, minX, minY, invSize) {
  18323. var p = start;
  18324. do {
  18325. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  18326. p.prevZ = p.prev;
  18327. p.nextZ = p.next;
  18328. p = p.next;
  18329. } while (p !== start);
  18330. p.prevZ.nextZ = null;
  18331. p.prevZ = null;
  18332. sortLinked(p);
  18333. } // Simon Tatham's linked list merge sort algorithm
  18334. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  18335. function sortLinked(list) {
  18336. var i,
  18337. p,
  18338. q,
  18339. e,
  18340. tail,
  18341. numMerges,
  18342. pSize,
  18343. qSize,
  18344. inSize = 1;
  18345. do {
  18346. p = list;
  18347. list = null;
  18348. tail = null;
  18349. numMerges = 0;
  18350. while (p) {
  18351. numMerges++;
  18352. q = p;
  18353. pSize = 0;
  18354. for (i = 0; i < inSize; i++) {
  18355. pSize++;
  18356. q = q.nextZ;
  18357. if (!q) break;
  18358. }
  18359. qSize = inSize;
  18360. while (pSize > 0 || qSize > 0 && q) {
  18361. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  18362. e = p;
  18363. p = p.nextZ;
  18364. pSize--;
  18365. } else {
  18366. e = q;
  18367. q = q.nextZ;
  18368. qSize--;
  18369. }
  18370. if (tail) tail.nextZ = e;else list = e;
  18371. e.prevZ = tail;
  18372. tail = e;
  18373. }
  18374. p = q;
  18375. }
  18376. tail.nextZ = null;
  18377. inSize *= 2;
  18378. } while (numMerges > 1);
  18379. return list;
  18380. } // z-order of a point given coords and inverse of the longer side of data bbox
  18381. function zOrder(x, y, minX, minY, invSize) {
  18382. // coords are transformed into non-negative 15-bit integer range
  18383. x = 32767 * (x - minX) * invSize;
  18384. y = 32767 * (y - minY) * invSize;
  18385. x = (x | x << 8) & 0x00FF00FF;
  18386. x = (x | x << 4) & 0x0F0F0F0F;
  18387. x = (x | x << 2) & 0x33333333;
  18388. x = (x | x << 1) & 0x55555555;
  18389. y = (y | y << 8) & 0x00FF00FF;
  18390. y = (y | y << 4) & 0x0F0F0F0F;
  18391. y = (y | y << 2) & 0x33333333;
  18392. y = (y | y << 1) & 0x55555555;
  18393. return x | y << 1;
  18394. } // find the leftmost node of a polygon ring
  18395. function getLeftmost(start) {
  18396. var p = start,
  18397. leftmost = start;
  18398. do {
  18399. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18400. p = p.next;
  18401. } while (p !== start);
  18402. return leftmost;
  18403. } // check if a point lies within a convex triangle
  18404. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18405. 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;
  18406. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18407. function isValidDiagonal(a, b) {
  18408. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18409. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18410. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18411. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18412. } // signed area of a triangle
  18413. function area(p, q, r) {
  18414. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18415. } // check if two points are equal
  18416. function equals(p1, p2) {
  18417. return p1.x === p2.x && p1.y === p2.y;
  18418. } // check if two segments intersect
  18419. function intersects(p1, q1, p2, q2) {
  18420. var o1 = sign(area(p1, q1, p2));
  18421. var o2 = sign(area(p1, q1, q2));
  18422. var o3 = sign(area(p2, q2, p1));
  18423. var o4 = sign(area(p2, q2, q1));
  18424. if (o1 !== o2 && o3 !== o4) return true; // general case
  18425. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18426. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18427. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18428. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18429. return false;
  18430. } // for collinear points p, q, r, check if point q lies on segment pr
  18431. function onSegment(p, q, r) {
  18432. 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);
  18433. }
  18434. function sign(num) {
  18435. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18436. } // check if a polygon diagonal intersects any polygon segments
  18437. function intersectsPolygon(a, b) {
  18438. var p = a;
  18439. do {
  18440. 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;
  18441. p = p.next;
  18442. } while (p !== a);
  18443. return false;
  18444. } // check if a polygon diagonal is locally inside the polygon
  18445. function locallyInside(a, b) {
  18446. 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;
  18447. } // check if the middle point of a polygon diagonal is inside the polygon
  18448. function middleInside(a, b) {
  18449. var p = a,
  18450. inside = false;
  18451. var px = (a.x + b.x) / 2,
  18452. py = (a.y + b.y) / 2;
  18453. do {
  18454. 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;
  18455. p = p.next;
  18456. } while (p !== a);
  18457. return inside;
  18458. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18459. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18460. function splitPolygon(a, b) {
  18461. var a2 = new Node(a.i, a.x, a.y),
  18462. b2 = new Node(b.i, b.x, b.y),
  18463. an = a.next,
  18464. bp = b.prev;
  18465. a.next = b;
  18466. b.prev = a;
  18467. a2.next = an;
  18468. an.prev = a2;
  18469. b2.next = a2;
  18470. a2.prev = b2;
  18471. bp.next = b2;
  18472. b2.prev = bp;
  18473. return b2;
  18474. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18475. function insertNode(i, x, y, last) {
  18476. var p = new Node(i, x, y);
  18477. if (!last) {
  18478. p.prev = p;
  18479. p.next = p;
  18480. } else {
  18481. p.next = last.next;
  18482. p.prev = last;
  18483. last.next.prev = p;
  18484. last.next = p;
  18485. }
  18486. return p;
  18487. }
  18488. function removeNode(p) {
  18489. p.next.prev = p.prev;
  18490. p.prev.next = p.next;
  18491. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18492. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18493. }
  18494. function Node(i, x, y) {
  18495. // vertex index in coordinates array
  18496. this.i = i; // vertex coordinates
  18497. this.x = x;
  18498. this.y = y; // previous and next vertex nodes in a polygon ring
  18499. this.prev = null;
  18500. this.next = null; // z-order curve value
  18501. this.z = null; // previous and next nodes in z-order
  18502. this.prevZ = null;
  18503. this.nextZ = null; // indicates whether this is a steiner point
  18504. this.steiner = false;
  18505. }
  18506. function signedArea(data, start, end, dim) {
  18507. var sum = 0;
  18508. for (var i = start, j = end - dim; i < end; i += dim) {
  18509. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18510. j = i;
  18511. }
  18512. return sum;
  18513. }
  18514. var ShapeUtils = {
  18515. // calculate area of the contour polygon
  18516. area: function area(contour) {
  18517. var n = contour.length;
  18518. var a = 0.0;
  18519. for (var p = n - 1, q = 0; q < n; p = q++) {
  18520. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18521. }
  18522. return a * 0.5;
  18523. },
  18524. isClockWise: function isClockWise(pts) {
  18525. return ShapeUtils.area(pts) < 0;
  18526. },
  18527. triangulateShape: function triangulateShape(contour, holes) {
  18528. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18529. var holeIndices = []; // array of hole indices
  18530. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18531. removeDupEndPts(contour);
  18532. addContour(vertices, contour); //
  18533. var holeIndex = contour.length;
  18534. holes.forEach(removeDupEndPts);
  18535. for (var i = 0; i < holes.length; i++) {
  18536. holeIndices.push(holeIndex);
  18537. holeIndex += holes[i].length;
  18538. addContour(vertices, holes[i]);
  18539. } //
  18540. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18541. for (var _i = 0; _i < triangles.length; _i += 3) {
  18542. faces.push(triangles.slice(_i, _i + 3));
  18543. }
  18544. return faces;
  18545. }
  18546. };
  18547. function removeDupEndPts(points) {
  18548. var l = points.length;
  18549. if (l > 2 && points[l - 1].equals(points[0])) {
  18550. points.pop();
  18551. }
  18552. }
  18553. function addContour(vertices, contour) {
  18554. for (var i = 0; i < contour.length; i++) {
  18555. vertices.push(contour[i].x);
  18556. vertices.push(contour[i].y);
  18557. }
  18558. }
  18559. var ExtrudeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18560. _inheritsLoose(ExtrudeBufferGeometry, _BufferGeometry);
  18561. function ExtrudeBufferGeometry(shapes, options) {
  18562. var _this;
  18563. _this = _BufferGeometry.call(this) || this;
  18564. _this.type = 'ExtrudeBufferGeometry';
  18565. _this.parameters = {
  18566. shapes: shapes,
  18567. options: options
  18568. };
  18569. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18570. var scope = _assertThisInitialized(_this);
  18571. var verticesArray = [];
  18572. var uvArray = [];
  18573. for (var i = 0, l = shapes.length; i < l; i++) {
  18574. var shape = shapes[i];
  18575. addShape(shape);
  18576. } // build geometry
  18577. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18578. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18579. _this.computeVertexNormals(); // functions
  18580. function addShape(shape) {
  18581. var placeholder = []; // options
  18582. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18583. var steps = options.steps !== undefined ? options.steps : 1;
  18584. var depth = options.depth !== undefined ? options.depth : 100;
  18585. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18586. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18587. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18588. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18589. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18590. var extrudePath = options.extrudePath;
  18591. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18592. if (options.amount !== undefined) {
  18593. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18594. depth = options.amount;
  18595. } //
  18596. var extrudePts,
  18597. extrudeByPath = false;
  18598. var splineTube, binormal, normal, position2;
  18599. if (extrudePath) {
  18600. extrudePts = extrudePath.getSpacedPoints(steps);
  18601. extrudeByPath = true;
  18602. bevelEnabled = false; // bevels not supported for path extrusion
  18603. // SETUP TNB variables
  18604. // TODO1 - have a .isClosed in spline?
  18605. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18606. binormal = new Vector3();
  18607. normal = new Vector3();
  18608. position2 = new Vector3();
  18609. } // Safeguards if bevels are not enabled
  18610. if (!bevelEnabled) {
  18611. bevelSegments = 0;
  18612. bevelThickness = 0;
  18613. bevelSize = 0;
  18614. bevelOffset = 0;
  18615. } // Variables initialization
  18616. var shapePoints = shape.extractPoints(curveSegments);
  18617. var vertices = shapePoints.shape;
  18618. var holes = shapePoints.holes;
  18619. var reverse = !ShapeUtils.isClockWise(vertices);
  18620. if (reverse) {
  18621. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18622. for (var h = 0, hl = holes.length; h < hl; h++) {
  18623. var ahole = holes[h];
  18624. if (ShapeUtils.isClockWise(ahole)) {
  18625. holes[h] = ahole.reverse();
  18626. }
  18627. }
  18628. }
  18629. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18630. /* Vertices */
  18631. var contour = vertices; // vertices has all points but contour has only points of circumference
  18632. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18633. var _ahole = holes[_h];
  18634. vertices = vertices.concat(_ahole);
  18635. }
  18636. function scalePt2(pt, vec, size) {
  18637. if (!vec) console.error('THREE.ExtrudeGeometry: vec does not exist');
  18638. return vec.clone().multiplyScalar(size).add(pt);
  18639. }
  18640. var vlen = vertices.length,
  18641. flen = faces.length; // Find directions for point movement
  18642. function getBevelVec(inPt, inPrev, inNext) {
  18643. // computes for inPt the corresponding point inPt' on a new contour
  18644. // shifted by 1 unit (length of normalized vector) to the left
  18645. // if we walk along contour clockwise, this new contour is outside the old one
  18646. //
  18647. // inPt' is the intersection of the two lines parallel to the two
  18648. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18649. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18650. // good reading for geometry algorithms (here: line-line intersection)
  18651. // http://geomalgorithms.com/a05-_intersect-1.html
  18652. var v_prev_x = inPt.x - inPrev.x,
  18653. v_prev_y = inPt.y - inPrev.y;
  18654. var v_next_x = inNext.x - inPt.x,
  18655. v_next_y = inNext.y - inPt.y;
  18656. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18657. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18658. if (Math.abs(collinear0) > Number.EPSILON) {
  18659. // not collinear
  18660. // length of vectors for normalizing
  18661. var v_prev_len = Math.sqrt(v_prev_lensq);
  18662. 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
  18663. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18664. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18665. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18666. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18667. 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
  18668. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18669. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18670. // but prevent crazy spikes
  18671. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18672. if (v_trans_lensq <= 2) {
  18673. return new Vector2(v_trans_x, v_trans_y);
  18674. } else {
  18675. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18676. }
  18677. } else {
  18678. // handle special case of collinear edges
  18679. var direction_eq = false; // assumes: opposite
  18680. if (v_prev_x > Number.EPSILON) {
  18681. if (v_next_x > Number.EPSILON) {
  18682. direction_eq = true;
  18683. }
  18684. } else {
  18685. if (v_prev_x < -Number.EPSILON) {
  18686. if (v_next_x < -Number.EPSILON) {
  18687. direction_eq = true;
  18688. }
  18689. } else {
  18690. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18691. direction_eq = true;
  18692. }
  18693. }
  18694. }
  18695. if (direction_eq) {
  18696. // console.log("Warning: lines are a straight sequence");
  18697. v_trans_x = -v_prev_y;
  18698. v_trans_y = v_prev_x;
  18699. shrink_by = Math.sqrt(v_prev_lensq);
  18700. } else {
  18701. // console.log("Warning: lines are a straight spike");
  18702. v_trans_x = v_prev_x;
  18703. v_trans_y = v_prev_y;
  18704. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18705. }
  18706. }
  18707. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18708. }
  18709. var contourMovements = [];
  18710. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18711. if (j === il) j = 0;
  18712. if (k === il) k = 0; // (j)---(i)---(k)
  18713. // console.log('i,j,k', i, j , k)
  18714. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18715. }
  18716. var holesMovements = [];
  18717. var oneHoleMovements,
  18718. verticesMovements = contourMovements.concat();
  18719. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18720. var _ahole2 = holes[_h2];
  18721. oneHoleMovements = [];
  18722. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18723. if (_j === _il) _j = 0;
  18724. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18725. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18726. }
  18727. holesMovements.push(oneHoleMovements);
  18728. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18729. } // Loop bevelSegments, 1 for the front, 1 for the back
  18730. for (var b = 0; b < bevelSegments; b++) {
  18731. //for ( b = bevelSegments; b > 0; b -- ) {
  18732. var t = b / bevelSegments;
  18733. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18734. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18735. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18736. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18737. v(vert.x, vert.y, -z);
  18738. } // expand holes
  18739. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18740. var _ahole3 = holes[_h3];
  18741. oneHoleMovements = holesMovements[_h3];
  18742. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18743. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18744. v(_vert.x, _vert.y, -z);
  18745. }
  18746. }
  18747. }
  18748. var bs = bevelSize + bevelOffset; // Back facing vertices
  18749. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18750. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18751. if (!extrudeByPath) {
  18752. v(_vert2.x, _vert2.y, 0);
  18753. } else {
  18754. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18755. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18756. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18757. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18758. v(position2.x, position2.y, position2.z);
  18759. }
  18760. } // Add stepped vertices...
  18761. // Including front facing vertices
  18762. for (var s = 1; s <= steps; s++) {
  18763. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18764. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18765. if (!extrudeByPath) {
  18766. v(_vert3.x, _vert3.y, depth / steps * s);
  18767. } else {
  18768. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18769. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18770. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18771. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18772. v(position2.x, position2.y, position2.z);
  18773. }
  18774. }
  18775. } // Add bevel segments planes
  18776. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18777. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18778. var _t = _b / bevelSegments;
  18779. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18780. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18781. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18782. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18783. v(_vert4.x, _vert4.y, depth + _z);
  18784. } // expand holes
  18785. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18786. var _ahole4 = holes[_h4];
  18787. oneHoleMovements = holesMovements[_h4];
  18788. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18789. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18790. if (!extrudeByPath) {
  18791. v(_vert5.x, _vert5.y, depth + _z);
  18792. } else {
  18793. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18794. }
  18795. }
  18796. }
  18797. }
  18798. /* Faces */
  18799. // Top and bottom faces
  18800. buildLidFaces(); // Sides faces
  18801. buildSideFaces(); ///// Internal functions
  18802. function buildLidFaces() {
  18803. var start = verticesArray.length / 3;
  18804. if (bevelEnabled) {
  18805. var layer = 0; // steps + 1
  18806. var offset = vlen * layer; // Bottom faces
  18807. for (var _i9 = 0; _i9 < flen; _i9++) {
  18808. var face = faces[_i9];
  18809. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18810. }
  18811. layer = steps + bevelSegments * 2;
  18812. offset = vlen * layer; // Top faces
  18813. for (var _i10 = 0; _i10 < flen; _i10++) {
  18814. var _face = faces[_i10];
  18815. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18816. }
  18817. } else {
  18818. // Bottom faces
  18819. for (var _i11 = 0; _i11 < flen; _i11++) {
  18820. var _face2 = faces[_i11];
  18821. f3(_face2[2], _face2[1], _face2[0]);
  18822. } // Top faces
  18823. for (var _i12 = 0; _i12 < flen; _i12++) {
  18824. var _face3 = faces[_i12];
  18825. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18826. }
  18827. }
  18828. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18829. } // Create faces for the z-sides of the shape
  18830. function buildSideFaces() {
  18831. var start = verticesArray.length / 3;
  18832. var layeroffset = 0;
  18833. sidewalls(contour, layeroffset);
  18834. layeroffset += contour.length;
  18835. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18836. var _ahole5 = holes[_h5];
  18837. sidewalls(_ahole5, layeroffset); //, true
  18838. layeroffset += _ahole5.length;
  18839. }
  18840. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18841. }
  18842. function sidewalls(contour, layeroffset) {
  18843. var i = contour.length;
  18844. while (--i >= 0) {
  18845. var _j2 = i;
  18846. var _k2 = i - 1;
  18847. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18848. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18849. var slen1 = vlen * _s;
  18850. var slen2 = vlen * (_s + 1);
  18851. var a = layeroffset + _j2 + slen1,
  18852. _b2 = layeroffset + _k2 + slen1,
  18853. c = layeroffset + _k2 + slen2,
  18854. d = layeroffset + _j2 + slen2;
  18855. f4(a, _b2, c, d);
  18856. }
  18857. }
  18858. }
  18859. function v(x, y, z) {
  18860. placeholder.push(x);
  18861. placeholder.push(y);
  18862. placeholder.push(z);
  18863. }
  18864. function f3(a, b, c) {
  18865. addVertex(a);
  18866. addVertex(b);
  18867. addVertex(c);
  18868. var nextIndex = verticesArray.length / 3;
  18869. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18870. addUV(uvs[0]);
  18871. addUV(uvs[1]);
  18872. addUV(uvs[2]);
  18873. }
  18874. function f4(a, b, c, d) {
  18875. addVertex(a);
  18876. addVertex(b);
  18877. addVertex(d);
  18878. addVertex(b);
  18879. addVertex(c);
  18880. addVertex(d);
  18881. var nextIndex = verticesArray.length / 3;
  18882. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18883. addUV(uvs[0]);
  18884. addUV(uvs[1]);
  18885. addUV(uvs[3]);
  18886. addUV(uvs[1]);
  18887. addUV(uvs[2]);
  18888. addUV(uvs[3]);
  18889. }
  18890. function addVertex(index) {
  18891. verticesArray.push(placeholder[index * 3 + 0]);
  18892. verticesArray.push(placeholder[index * 3 + 1]);
  18893. verticesArray.push(placeholder[index * 3 + 2]);
  18894. }
  18895. function addUV(vector2) {
  18896. uvArray.push(vector2.x);
  18897. uvArray.push(vector2.y);
  18898. }
  18899. }
  18900. return _this;
  18901. }
  18902. var _proto = ExtrudeBufferGeometry.prototype;
  18903. _proto.toJSON = function toJSON() {
  18904. var data = BufferGeometry.prototype.toJSON.call(this);
  18905. var shapes = this.parameters.shapes;
  18906. var options = this.parameters.options;
  18907. return _toJSON(shapes, options, data);
  18908. };
  18909. return ExtrudeBufferGeometry;
  18910. }(BufferGeometry);
  18911. var WorldUVGenerator = {
  18912. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18913. var a_x = vertices[indexA * 3];
  18914. var a_y = vertices[indexA * 3 + 1];
  18915. var b_x = vertices[indexB * 3];
  18916. var b_y = vertices[indexB * 3 + 1];
  18917. var c_x = vertices[indexC * 3];
  18918. var c_y = vertices[indexC * 3 + 1];
  18919. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18920. },
  18921. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18922. var a_x = vertices[indexA * 3];
  18923. var a_y = vertices[indexA * 3 + 1];
  18924. var a_z = vertices[indexA * 3 + 2];
  18925. var b_x = vertices[indexB * 3];
  18926. var b_y = vertices[indexB * 3 + 1];
  18927. var b_z = vertices[indexB * 3 + 2];
  18928. var c_x = vertices[indexC * 3];
  18929. var c_y = vertices[indexC * 3 + 1];
  18930. var c_z = vertices[indexC * 3 + 2];
  18931. var d_x = vertices[indexD * 3];
  18932. var d_y = vertices[indexD * 3 + 1];
  18933. var d_z = vertices[indexD * 3 + 2];
  18934. if (Math.abs(a_y - b_y) < 0.01) {
  18935. 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)];
  18936. } else {
  18937. 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)];
  18938. }
  18939. }
  18940. };
  18941. function _toJSON(shapes, options, data) {
  18942. data.shapes = [];
  18943. if (Array.isArray(shapes)) {
  18944. for (var i = 0, l = shapes.length; i < l; i++) {
  18945. var shape = shapes[i];
  18946. data.shapes.push(shape.uuid);
  18947. }
  18948. } else {
  18949. data.shapes.push(shapes.uuid);
  18950. }
  18951. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18952. return data;
  18953. }
  18954. var ExtrudeGeometry = /*#__PURE__*/function (_Geometry) {
  18955. _inheritsLoose(ExtrudeGeometry, _Geometry);
  18956. function ExtrudeGeometry(shapes, options) {
  18957. var _this;
  18958. _this = _Geometry.call(this) || this;
  18959. _this.type = 'ExtrudeGeometry';
  18960. _this.parameters = {
  18961. shapes: shapes,
  18962. options: options
  18963. };
  18964. _this.fromBufferGeometry(new ExtrudeBufferGeometry(shapes, options));
  18965. _this.mergeVertices();
  18966. return _this;
  18967. }
  18968. var _proto = ExtrudeGeometry.prototype;
  18969. _proto.toJSON = function toJSON() {
  18970. var data = _Geometry.prototype.toJSON.call(this);
  18971. var shapes = this.parameters.shapes;
  18972. var options = this.parameters.options;
  18973. return _toJSON$1(shapes, options, data);
  18974. };
  18975. return ExtrudeGeometry;
  18976. }(Geometry);
  18977. function _toJSON$1(shapes, options, data) {
  18978. data.shapes = [];
  18979. if (Array.isArray(shapes)) {
  18980. for (var i = 0, l = shapes.length; i < l; i++) {
  18981. var shape = shapes[i];
  18982. data.shapes.push(shape.uuid);
  18983. }
  18984. } else {
  18985. data.shapes.push(shapes.uuid);
  18986. }
  18987. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18988. return data;
  18989. }
  18990. var IcosahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  18991. _inheritsLoose(IcosahedronBufferGeometry, _PolyhedronBufferGeom);
  18992. function IcosahedronBufferGeometry(radius, detail) {
  18993. var _this;
  18994. if (radius === void 0) {
  18995. radius = 1;
  18996. }
  18997. if (detail === void 0) {
  18998. detail = 0;
  18999. }
  19000. var t = (1 + Math.sqrt(5)) / 2;
  19001. 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];
  19002. 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];
  19003. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  19004. _this.type = 'IcosahedronBufferGeometry';
  19005. _this.parameters = {
  19006. radius: radius,
  19007. detail: detail
  19008. };
  19009. return _this;
  19010. }
  19011. return IcosahedronBufferGeometry;
  19012. }(PolyhedronBufferGeometry);
  19013. var IcosahedronGeometry = /*#__PURE__*/function (_Geometry) {
  19014. _inheritsLoose(IcosahedronGeometry, _Geometry);
  19015. function IcosahedronGeometry(radius, detail) {
  19016. var _this;
  19017. _this = _Geometry.call(this) || this;
  19018. _this.type = 'IcosahedronGeometry';
  19019. _this.parameters = {
  19020. radius: radius,
  19021. detail: detail
  19022. };
  19023. _this.fromBufferGeometry(new IcosahedronBufferGeometry(radius, detail));
  19024. _this.mergeVertices();
  19025. return _this;
  19026. }
  19027. return IcosahedronGeometry;
  19028. }(Geometry);
  19029. var LatheBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19030. _inheritsLoose(LatheBufferGeometry, _BufferGeometry);
  19031. function LatheBufferGeometry(points, segments, phiStart, phiLength) {
  19032. var _this;
  19033. if (segments === void 0) {
  19034. segments = 12;
  19035. }
  19036. if (phiStart === void 0) {
  19037. phiStart = 0;
  19038. }
  19039. if (phiLength === void 0) {
  19040. phiLength = Math.PI * 2;
  19041. }
  19042. _this = _BufferGeometry.call(this) || this;
  19043. _this.type = 'LatheBufferGeometry';
  19044. _this.parameters = {
  19045. points: points,
  19046. segments: segments,
  19047. phiStart: phiStart,
  19048. phiLength: phiLength
  19049. };
  19050. segments = Math.floor(segments); // clamp phiLength so it's in range of [ 0, 2PI ]
  19051. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  19052. var indices = [];
  19053. var vertices = [];
  19054. var uvs = []; // helper variables
  19055. var inverseSegments = 1.0 / segments;
  19056. var vertex = new Vector3();
  19057. var uv = new Vector2(); // generate vertices and uvs
  19058. for (var i = 0; i <= segments; i++) {
  19059. var phi = phiStart + i * inverseSegments * phiLength;
  19060. var sin = Math.sin(phi);
  19061. var cos = Math.cos(phi);
  19062. for (var j = 0; j <= points.length - 1; j++) {
  19063. // vertex
  19064. vertex.x = points[j].x * sin;
  19065. vertex.y = points[j].y;
  19066. vertex.z = points[j].x * cos;
  19067. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  19068. uv.x = i / segments;
  19069. uv.y = j / (points.length - 1);
  19070. uvs.push(uv.x, uv.y);
  19071. }
  19072. } // indices
  19073. for (var _i = 0; _i < segments; _i++) {
  19074. for (var _j = 0; _j < points.length - 1; _j++) {
  19075. var base = _j + _i * points.length;
  19076. var a = base;
  19077. var b = base + points.length;
  19078. var c = base + points.length + 1;
  19079. var d = base + 1; // faces
  19080. indices.push(a, b, d);
  19081. indices.push(b, c, d);
  19082. }
  19083. } // build geometry
  19084. _this.setIndex(indices);
  19085. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19086. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  19087. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  19088. // because the corresponding vertices are identical (but still have different UVs).
  19089. if (phiLength === Math.PI * 2) {
  19090. var normals = _this.attributes.normal.array;
  19091. var n1 = new Vector3();
  19092. var n2 = new Vector3();
  19093. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  19094. var _base = segments * points.length * 3;
  19095. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  19096. // select the normal of the vertex in the first line
  19097. n1.x = normals[_j2 + 0];
  19098. n1.y = normals[_j2 + 1];
  19099. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  19100. n2.x = normals[_base + _j2 + 0];
  19101. n2.y = normals[_base + _j2 + 1];
  19102. n2.z = normals[_base + _j2 + 2]; // average normals
  19103. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  19104. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  19105. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  19106. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  19107. }
  19108. }
  19109. return _this;
  19110. }
  19111. return LatheBufferGeometry;
  19112. }(BufferGeometry);
  19113. var LatheGeometry = /*#__PURE__*/function (_Geometry) {
  19114. _inheritsLoose(LatheGeometry, _Geometry);
  19115. function LatheGeometry(points, segments, phiStart, phiLength) {
  19116. var _this;
  19117. _this = _Geometry.call(this) || this;
  19118. _this.type = 'LatheGeometry';
  19119. _this.parameters = {
  19120. points: points,
  19121. segments: segments,
  19122. phiStart: phiStart,
  19123. phiLength: phiLength
  19124. };
  19125. _this.fromBufferGeometry(new LatheBufferGeometry(points, segments, phiStart, phiLength));
  19126. _this.mergeVertices();
  19127. return _this;
  19128. }
  19129. return LatheGeometry;
  19130. }(Geometry);
  19131. var OctahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  19132. _inheritsLoose(OctahedronBufferGeometry, _PolyhedronBufferGeom);
  19133. function OctahedronBufferGeometry(radius, detail) {
  19134. var _this;
  19135. if (radius === void 0) {
  19136. radius = 1;
  19137. }
  19138. if (detail === void 0) {
  19139. detail = 0;
  19140. }
  19141. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  19142. 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];
  19143. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  19144. _this.type = 'OctahedronBufferGeometry';
  19145. _this.parameters = {
  19146. radius: radius,
  19147. detail: detail
  19148. };
  19149. return _this;
  19150. }
  19151. return OctahedronBufferGeometry;
  19152. }(PolyhedronBufferGeometry);
  19153. var OctahedronGeometry = /*#__PURE__*/function (_Geometry) {
  19154. _inheritsLoose(OctahedronGeometry, _Geometry);
  19155. function OctahedronGeometry(radius, detail) {
  19156. var _this;
  19157. _this = _Geometry.call(this) || this;
  19158. _this.type = 'OctahedronGeometry';
  19159. _this.parameters = {
  19160. radius: radius,
  19161. detail: detail
  19162. };
  19163. _this.fromBufferGeometry(new OctahedronBufferGeometry(radius, detail));
  19164. _this.mergeVertices();
  19165. return _this;
  19166. }
  19167. return OctahedronGeometry;
  19168. }(Geometry);
  19169. /**
  19170. * Parametric Surfaces Geometry
  19171. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  19172. */
  19173. function ParametricBufferGeometry(func, slices, stacks) {
  19174. BufferGeometry.call(this);
  19175. this.type = 'ParametricBufferGeometry';
  19176. this.parameters = {
  19177. func: func,
  19178. slices: slices,
  19179. stacks: stacks
  19180. }; // buffers
  19181. var indices = [];
  19182. var vertices = [];
  19183. var normals = [];
  19184. var uvs = [];
  19185. var EPS = 0.00001;
  19186. var normal = new Vector3();
  19187. var p0 = new Vector3(),
  19188. p1 = new Vector3();
  19189. var pu = new Vector3(),
  19190. pv = new Vector3();
  19191. if (func.length < 3) {
  19192. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  19193. } // generate vertices, normals and uvs
  19194. var sliceCount = slices + 1;
  19195. for (var i = 0; i <= stacks; i++) {
  19196. var v = i / stacks;
  19197. for (var j = 0; j <= slices; j++) {
  19198. var u = j / slices; // vertex
  19199. func(u, v, p0);
  19200. vertices.push(p0.x, p0.y, p0.z); // normal
  19201. // approximate tangent vectors via finite differences
  19202. if (u - EPS >= 0) {
  19203. func(u - EPS, v, p1);
  19204. pu.subVectors(p0, p1);
  19205. } else {
  19206. func(u + EPS, v, p1);
  19207. pu.subVectors(p1, p0);
  19208. }
  19209. if (v - EPS >= 0) {
  19210. func(u, v - EPS, p1);
  19211. pv.subVectors(p0, p1);
  19212. } else {
  19213. func(u, v + EPS, p1);
  19214. pv.subVectors(p1, p0);
  19215. } // cross product of tangent vectors returns surface normal
  19216. normal.crossVectors(pu, pv).normalize();
  19217. normals.push(normal.x, normal.y, normal.z); // uv
  19218. uvs.push(u, v);
  19219. }
  19220. } // generate indices
  19221. for (var _i = 0; _i < stacks; _i++) {
  19222. for (var _j = 0; _j < slices; _j++) {
  19223. var a = _i * sliceCount + _j;
  19224. var b = _i * sliceCount + _j + 1;
  19225. var c = (_i + 1) * sliceCount + _j + 1;
  19226. var d = (_i + 1) * sliceCount + _j; // faces one and two
  19227. indices.push(a, b, d);
  19228. indices.push(b, c, d);
  19229. }
  19230. } // build geometry
  19231. this.setIndex(indices);
  19232. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19233. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19234. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19235. }
  19236. ParametricBufferGeometry.prototype = Object.create(BufferGeometry.prototype);
  19237. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  19238. /**
  19239. * Parametric Surfaces Geometry
  19240. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  19241. */
  19242. function ParametricGeometry(func, slices, stacks) {
  19243. Geometry.call(this);
  19244. this.type = 'ParametricGeometry';
  19245. this.parameters = {
  19246. func: func,
  19247. slices: slices,
  19248. stacks: stacks
  19249. };
  19250. this.fromBufferGeometry(new ParametricBufferGeometry(func, slices, stacks));
  19251. this.mergeVertices();
  19252. }
  19253. ParametricGeometry.prototype = Object.create(Geometry.prototype);
  19254. ParametricGeometry.prototype.constructor = ParametricGeometry;
  19255. var PlaneGeometry = /*#__PURE__*/function (_Geometry) {
  19256. _inheritsLoose(PlaneGeometry, _Geometry);
  19257. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  19258. var _this;
  19259. _this = _Geometry.call(this) || this;
  19260. _this.type = 'PlaneGeometry';
  19261. _this.parameters = {
  19262. width: width,
  19263. height: height,
  19264. widthSegments: widthSegments,
  19265. heightSegments: heightSegments
  19266. };
  19267. _this.fromBufferGeometry(new PlaneBufferGeometry(width, height, widthSegments, heightSegments));
  19268. _this.mergeVertices();
  19269. return _this;
  19270. }
  19271. return PlaneGeometry;
  19272. }(Geometry);
  19273. var PolyhedronGeometry = /*#__PURE__*/function (_Geometry) {
  19274. _inheritsLoose(PolyhedronGeometry, _Geometry);
  19275. function PolyhedronGeometry(vertices, indices, radius, detail) {
  19276. var _this;
  19277. _this = _Geometry.call(this) || this;
  19278. _this.type = 'PolyhedronGeometry';
  19279. _this.parameters = {
  19280. vertices: vertices,
  19281. indices: indices,
  19282. radius: radius,
  19283. detail: detail
  19284. };
  19285. _this.fromBufferGeometry(new PolyhedronBufferGeometry(vertices, indices, radius, detail));
  19286. _this.mergeVertices();
  19287. return _this;
  19288. }
  19289. return PolyhedronGeometry;
  19290. }(Geometry);
  19291. var RingBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19292. _inheritsLoose(RingBufferGeometry, _BufferGeometry);
  19293. function RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  19294. var _this;
  19295. if (innerRadius === void 0) {
  19296. innerRadius = 0.5;
  19297. }
  19298. if (outerRadius === void 0) {
  19299. outerRadius = 1;
  19300. }
  19301. if (thetaSegments === void 0) {
  19302. thetaSegments = 8;
  19303. }
  19304. if (phiSegments === void 0) {
  19305. phiSegments = 1;
  19306. }
  19307. if (thetaStart === void 0) {
  19308. thetaStart = 0;
  19309. }
  19310. if (thetaLength === void 0) {
  19311. thetaLength = Math.PI * 2;
  19312. }
  19313. _this = _BufferGeometry.call(this) || this;
  19314. _this.type = 'RingBufferGeometry';
  19315. _this.parameters = {
  19316. innerRadius: innerRadius,
  19317. outerRadius: outerRadius,
  19318. thetaSegments: thetaSegments,
  19319. phiSegments: phiSegments,
  19320. thetaStart: thetaStart,
  19321. thetaLength: thetaLength
  19322. };
  19323. thetaSegments = Math.max(3, thetaSegments);
  19324. phiSegments = Math.max(1, phiSegments); // buffers
  19325. var indices = [];
  19326. var vertices = [];
  19327. var normals = [];
  19328. var uvs = []; // some helper variables
  19329. var radius = innerRadius;
  19330. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  19331. var vertex = new Vector3();
  19332. var uv = new Vector2(); // generate vertices, normals and uvs
  19333. for (var j = 0; j <= phiSegments; j++) {
  19334. for (var i = 0; i <= thetaSegments; i++) {
  19335. // values are generate from the inside of the ring to the outside
  19336. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  19337. vertex.x = radius * Math.cos(segment);
  19338. vertex.y = radius * Math.sin(segment);
  19339. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19340. normals.push(0, 0, 1); // uv
  19341. uv.x = (vertex.x / outerRadius + 1) / 2;
  19342. uv.y = (vertex.y / outerRadius + 1) / 2;
  19343. uvs.push(uv.x, uv.y);
  19344. } // increase the radius for next row of vertices
  19345. radius += radiusStep;
  19346. } // indices
  19347. for (var _j = 0; _j < phiSegments; _j++) {
  19348. var thetaSegmentLevel = _j * (thetaSegments + 1);
  19349. for (var _i = 0; _i < thetaSegments; _i++) {
  19350. var _segment = _i + thetaSegmentLevel;
  19351. var a = _segment;
  19352. var b = _segment + thetaSegments + 1;
  19353. var c = _segment + thetaSegments + 2;
  19354. var d = _segment + 1; // faces
  19355. indices.push(a, b, d);
  19356. indices.push(b, c, d);
  19357. }
  19358. } // build geometry
  19359. _this.setIndex(indices);
  19360. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19361. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19362. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19363. return _this;
  19364. }
  19365. return RingBufferGeometry;
  19366. }(BufferGeometry);
  19367. var RingGeometry = /*#__PURE__*/function (_Geometry) {
  19368. _inheritsLoose(RingGeometry, _Geometry);
  19369. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  19370. var _this;
  19371. _this = _Geometry.call(this) || this;
  19372. _this.type = 'RingGeometry';
  19373. _this.parameters = {
  19374. innerRadius: innerRadius,
  19375. outerRadius: outerRadius,
  19376. thetaSegments: thetaSegments,
  19377. phiSegments: phiSegments,
  19378. thetaStart: thetaStart,
  19379. thetaLength: thetaLength
  19380. };
  19381. _this.fromBufferGeometry(new RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength));
  19382. _this.mergeVertices();
  19383. return _this;
  19384. }
  19385. return RingGeometry;
  19386. }(Geometry);
  19387. var ShapeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19388. _inheritsLoose(ShapeBufferGeometry, _BufferGeometry);
  19389. function ShapeBufferGeometry(shapes, curveSegments) {
  19390. var _this;
  19391. if (curveSegments === void 0) {
  19392. curveSegments = 12;
  19393. }
  19394. _this = _BufferGeometry.call(this) || this;
  19395. _this.type = 'ShapeBufferGeometry';
  19396. _this.parameters = {
  19397. shapes: shapes,
  19398. curveSegments: curveSegments
  19399. }; // buffers
  19400. var indices = [];
  19401. var vertices = [];
  19402. var normals = [];
  19403. var uvs = []; // helper variables
  19404. var groupStart = 0;
  19405. var groupCount = 0; // allow single and array values for "shapes" parameter
  19406. if (Array.isArray(shapes) === false) {
  19407. addShape(shapes);
  19408. } else {
  19409. for (var i = 0; i < shapes.length; i++) {
  19410. addShape(shapes[i]);
  19411. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  19412. groupStart += groupCount;
  19413. groupCount = 0;
  19414. }
  19415. } // build geometry
  19416. _this.setIndex(indices);
  19417. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19418. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19419. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  19420. function addShape(shape) {
  19421. var indexOffset = vertices.length / 3;
  19422. var points = shape.extractPoints(curveSegments);
  19423. var shapeVertices = points.shape;
  19424. var shapeHoles = points.holes; // check direction of vertices
  19425. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  19426. shapeVertices = shapeVertices.reverse();
  19427. }
  19428. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  19429. var shapeHole = shapeHoles[_i];
  19430. if (ShapeUtils.isClockWise(shapeHole) === true) {
  19431. shapeHoles[_i] = shapeHole.reverse();
  19432. }
  19433. }
  19434. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  19435. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  19436. var _shapeHole = shapeHoles[_i2];
  19437. shapeVertices = shapeVertices.concat(_shapeHole);
  19438. } // vertices, normals, uvs
  19439. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  19440. var vertex = shapeVertices[_i3];
  19441. vertices.push(vertex.x, vertex.y, 0);
  19442. normals.push(0, 0, 1);
  19443. uvs.push(vertex.x, vertex.y); // world uvs
  19444. } // incides
  19445. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  19446. var face = faces[_i4];
  19447. var a = face[0] + indexOffset;
  19448. var b = face[1] + indexOffset;
  19449. var c = face[2] + indexOffset;
  19450. indices.push(a, b, c);
  19451. groupCount += 3;
  19452. }
  19453. }
  19454. return _this;
  19455. }
  19456. var _proto = ShapeBufferGeometry.prototype;
  19457. _proto.toJSON = function toJSON() {
  19458. var data = BufferGeometry.prototype.toJSON.call(this);
  19459. var shapes = this.parameters.shapes;
  19460. return _toJSON$2(shapes, data);
  19461. };
  19462. return ShapeBufferGeometry;
  19463. }(BufferGeometry);
  19464. function _toJSON$2(shapes, data) {
  19465. data.shapes = [];
  19466. if (Array.isArray(shapes)) {
  19467. for (var i = 0, l = shapes.length; i < l; i++) {
  19468. var shape = shapes[i];
  19469. data.shapes.push(shape.uuid);
  19470. }
  19471. } else {
  19472. data.shapes.push(shapes.uuid);
  19473. }
  19474. return data;
  19475. }
  19476. var ShapeGeometry = /*#__PURE__*/function (_Geometry) {
  19477. _inheritsLoose(ShapeGeometry, _Geometry);
  19478. function ShapeGeometry(shapes, curveSegments) {
  19479. var _this;
  19480. _this = _Geometry.call(this) || this;
  19481. _this.type = 'ShapeGeometry';
  19482. if (typeof curveSegments === 'object') {
  19483. console.warn('THREE.ShapeGeometry: Options parameter has been removed.');
  19484. curveSegments = curveSegments.curveSegments;
  19485. }
  19486. _this.parameters = {
  19487. shapes: shapes,
  19488. curveSegments: curveSegments
  19489. };
  19490. _this.fromBufferGeometry(new ShapeBufferGeometry(shapes, curveSegments));
  19491. _this.mergeVertices();
  19492. return _this;
  19493. }
  19494. var _proto = ShapeGeometry.prototype;
  19495. _proto.toJSON = function toJSON() {
  19496. var data = Geometry.prototype.toJSON.call(this);
  19497. var shapes = this.parameters.shapes;
  19498. return _toJSON$3(shapes, data);
  19499. };
  19500. return ShapeGeometry;
  19501. }(Geometry);
  19502. function _toJSON$3(shapes, data) {
  19503. data.shapes = [];
  19504. if (Array.isArray(shapes)) {
  19505. for (var i = 0, l = shapes.length; i < l; i++) {
  19506. var shape = shapes[i];
  19507. data.shapes.push(shape.uuid);
  19508. }
  19509. } else {
  19510. data.shapes.push(shapes.uuid);
  19511. }
  19512. return data;
  19513. }
  19514. var SphereBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19515. _inheritsLoose(SphereBufferGeometry, _BufferGeometry);
  19516. function SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19517. var _this;
  19518. if (radius === void 0) {
  19519. radius = 1;
  19520. }
  19521. if (widthSegments === void 0) {
  19522. widthSegments = 8;
  19523. }
  19524. if (heightSegments === void 0) {
  19525. heightSegments = 6;
  19526. }
  19527. if (phiStart === void 0) {
  19528. phiStart = 0;
  19529. }
  19530. if (phiLength === void 0) {
  19531. phiLength = Math.PI * 2;
  19532. }
  19533. if (thetaStart === void 0) {
  19534. thetaStart = 0;
  19535. }
  19536. if (thetaLength === void 0) {
  19537. thetaLength = Math.PI;
  19538. }
  19539. _this = _BufferGeometry.call(this) || this;
  19540. _this.type = 'SphereBufferGeometry';
  19541. _this.parameters = {
  19542. radius: radius,
  19543. widthSegments: widthSegments,
  19544. heightSegments: heightSegments,
  19545. phiStart: phiStart,
  19546. phiLength: phiLength,
  19547. thetaStart: thetaStart,
  19548. thetaLength: thetaLength
  19549. };
  19550. widthSegments = Math.max(3, Math.floor(widthSegments));
  19551. heightSegments = Math.max(2, Math.floor(heightSegments));
  19552. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19553. var index = 0;
  19554. var grid = [];
  19555. var vertex = new Vector3();
  19556. var normal = new Vector3(); // buffers
  19557. var indices = [];
  19558. var vertices = [];
  19559. var normals = [];
  19560. var uvs = []; // generate vertices, normals and uvs
  19561. for (var iy = 0; iy <= heightSegments; iy++) {
  19562. var verticesRow = [];
  19563. var v = iy / heightSegments; // special case for the poles
  19564. var uOffset = 0;
  19565. if (iy == 0 && thetaStart == 0) {
  19566. uOffset = 0.5 / widthSegments;
  19567. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19568. uOffset = -0.5 / widthSegments;
  19569. }
  19570. for (var ix = 0; ix <= widthSegments; ix++) {
  19571. var u = ix / widthSegments; // vertex
  19572. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19573. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19574. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19575. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19576. normal.copy(vertex).normalize();
  19577. normals.push(normal.x, normal.y, normal.z); // uv
  19578. uvs.push(u + uOffset, 1 - v);
  19579. verticesRow.push(index++);
  19580. }
  19581. grid.push(verticesRow);
  19582. } // indices
  19583. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19584. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19585. var a = grid[_iy][_ix + 1];
  19586. var b = grid[_iy][_ix];
  19587. var c = grid[_iy + 1][_ix];
  19588. var d = grid[_iy + 1][_ix + 1];
  19589. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19590. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19591. }
  19592. } // build geometry
  19593. _this.setIndex(indices);
  19594. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19595. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19596. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19597. return _this;
  19598. }
  19599. return SphereBufferGeometry;
  19600. }(BufferGeometry);
  19601. var SphereGeometry = /*#__PURE__*/function (_Geometry) {
  19602. _inheritsLoose(SphereGeometry, _Geometry);
  19603. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19604. var _this;
  19605. _this = _Geometry.call(this) || this;
  19606. _this.type = 'SphereGeometry';
  19607. _this.parameters = {
  19608. radius: radius,
  19609. widthSegments: widthSegments,
  19610. heightSegments: heightSegments,
  19611. phiStart: phiStart,
  19612. phiLength: phiLength,
  19613. thetaStart: thetaStart,
  19614. thetaLength: thetaLength
  19615. };
  19616. _this.fromBufferGeometry(new SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength));
  19617. _this.mergeVertices();
  19618. return _this;
  19619. }
  19620. return SphereGeometry;
  19621. }(Geometry);
  19622. var TetrahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  19623. _inheritsLoose(TetrahedronBufferGeometry, _PolyhedronBufferGeom);
  19624. function TetrahedronBufferGeometry(radius, detail) {
  19625. var _this;
  19626. if (radius === void 0) {
  19627. radius = 1;
  19628. }
  19629. if (detail === void 0) {
  19630. detail = 0;
  19631. }
  19632. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19633. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19634. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  19635. _this.type = 'TetrahedronBufferGeometry';
  19636. _this.parameters = {
  19637. radius: radius,
  19638. detail: detail
  19639. };
  19640. return _this;
  19641. }
  19642. return TetrahedronBufferGeometry;
  19643. }(PolyhedronBufferGeometry);
  19644. var TetrahedronGeometry = /*#__PURE__*/function (_Geometry) {
  19645. _inheritsLoose(TetrahedronGeometry, _Geometry);
  19646. function TetrahedronGeometry(radius, detail) {
  19647. var _this;
  19648. _this = _Geometry.call(this) || this;
  19649. _this.type = 'TetrahedronGeometry';
  19650. _this.parameters = {
  19651. radius: radius,
  19652. detail: detail
  19653. };
  19654. _this.fromBufferGeometry(new TetrahedronBufferGeometry(radius, detail));
  19655. _this.mergeVertices();
  19656. return _this;
  19657. }
  19658. return TetrahedronGeometry;
  19659. }(Geometry);
  19660. var TextBufferGeometry = /*#__PURE__*/function (_ExtrudeBufferGeometr) {
  19661. _inheritsLoose(TextBufferGeometry, _ExtrudeBufferGeometr);
  19662. function TextBufferGeometry(text, parameters) {
  19663. var _this;
  19664. if (parameters === void 0) {
  19665. parameters = {};
  19666. }
  19667. var font = parameters.font;
  19668. if (!(font && font.isFont)) {
  19669. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19670. return new BufferGeometry() || _assertThisInitialized(_this);
  19671. }
  19672. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19673. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19674. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19675. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19676. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19677. _this = _ExtrudeBufferGeometr.call(this, shapes, parameters) || this;
  19678. _this.type = 'TextBufferGeometry';
  19679. return _this;
  19680. }
  19681. return TextBufferGeometry;
  19682. }(ExtrudeBufferGeometry);
  19683. var TextGeometry = /*#__PURE__*/function (_Geometry) {
  19684. _inheritsLoose(TextGeometry, _Geometry);
  19685. function TextGeometry(text, parameters) {
  19686. var _this;
  19687. _this = _Geometry.call(this) || this;
  19688. _this.type = 'TextGeometry';
  19689. _this.parameters = {
  19690. text: text,
  19691. parameters: parameters
  19692. };
  19693. _this.fromBufferGeometry(new TextBufferGeometry(text, parameters));
  19694. _this.mergeVertices();
  19695. return _this;
  19696. }
  19697. return TextGeometry;
  19698. }(Geometry);
  19699. var TorusBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19700. _inheritsLoose(TorusBufferGeometry, _BufferGeometry);
  19701. function TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19702. var _this;
  19703. if (radius === void 0) {
  19704. radius = 1;
  19705. }
  19706. if (tube === void 0) {
  19707. tube = 0.4;
  19708. }
  19709. if (radialSegments === void 0) {
  19710. radialSegments = 8;
  19711. }
  19712. if (tubularSegments === void 0) {
  19713. tubularSegments = 6;
  19714. }
  19715. if (arc === void 0) {
  19716. arc = Math.PI * 2;
  19717. }
  19718. _this = _BufferGeometry.call(this) || this;
  19719. _this.type = 'TorusBufferGeometry';
  19720. _this.parameters = {
  19721. radius: radius,
  19722. tube: tube,
  19723. radialSegments: radialSegments,
  19724. tubularSegments: tubularSegments,
  19725. arc: arc
  19726. };
  19727. radialSegments = Math.floor(radialSegments);
  19728. tubularSegments = Math.floor(tubularSegments); // buffers
  19729. var indices = [];
  19730. var vertices = [];
  19731. var normals = [];
  19732. var uvs = []; // helper variables
  19733. var center = new Vector3();
  19734. var vertex = new Vector3();
  19735. var normal = new Vector3(); // generate vertices, normals and uvs
  19736. for (var j = 0; j <= radialSegments; j++) {
  19737. for (var i = 0; i <= tubularSegments; i++) {
  19738. var u = i / tubularSegments * arc;
  19739. var v = j / radialSegments * Math.PI * 2; // vertex
  19740. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19741. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19742. vertex.z = tube * Math.sin(v);
  19743. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19744. center.x = radius * Math.cos(u);
  19745. center.y = radius * Math.sin(u);
  19746. normal.subVectors(vertex, center).normalize();
  19747. normals.push(normal.x, normal.y, normal.z); // uv
  19748. uvs.push(i / tubularSegments);
  19749. uvs.push(j / radialSegments);
  19750. }
  19751. } // generate indices
  19752. for (var _j = 1; _j <= radialSegments; _j++) {
  19753. for (var _i = 1; _i <= tubularSegments; _i++) {
  19754. // indices
  19755. var a = (tubularSegments + 1) * _j + _i - 1;
  19756. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19757. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19758. var d = (tubularSegments + 1) * _j + _i; // faces
  19759. indices.push(a, b, d);
  19760. indices.push(b, c, d);
  19761. }
  19762. } // build geometry
  19763. _this.setIndex(indices);
  19764. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19765. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19766. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19767. return _this;
  19768. }
  19769. return TorusBufferGeometry;
  19770. }(BufferGeometry);
  19771. var TorusGeometry = /*#__PURE__*/function (_Geometry) {
  19772. _inheritsLoose(TorusGeometry, _Geometry);
  19773. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19774. var _this;
  19775. _this = _Geometry.call(this) || this;
  19776. _this.type = 'TorusGeometry';
  19777. _this.parameters = {
  19778. radius: radius,
  19779. tube: tube,
  19780. radialSegments: radialSegments,
  19781. tubularSegments: tubularSegments,
  19782. arc: arc
  19783. };
  19784. _this.fromBufferGeometry(new TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc));
  19785. _this.mergeVertices();
  19786. return _this;
  19787. }
  19788. return TorusGeometry;
  19789. }(Geometry);
  19790. var TorusKnotBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19791. _inheritsLoose(TorusKnotBufferGeometry, _BufferGeometry);
  19792. function TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19793. var _this;
  19794. if (radius === void 0) {
  19795. radius = 1;
  19796. }
  19797. if (tube === void 0) {
  19798. tube = 0.4;
  19799. }
  19800. if (tubularSegments === void 0) {
  19801. tubularSegments = 64;
  19802. }
  19803. if (radialSegments === void 0) {
  19804. radialSegments = 8;
  19805. }
  19806. if (p === void 0) {
  19807. p = 2;
  19808. }
  19809. if (q === void 0) {
  19810. q = 3;
  19811. }
  19812. _this = _BufferGeometry.call(this) || this;
  19813. _this.type = 'TorusKnotBufferGeometry';
  19814. _this.parameters = {
  19815. radius: radius,
  19816. tube: tube,
  19817. tubularSegments: tubularSegments,
  19818. radialSegments: radialSegments,
  19819. p: p,
  19820. q: q
  19821. };
  19822. tubularSegments = Math.floor(tubularSegments);
  19823. radialSegments = Math.floor(radialSegments); // buffers
  19824. var indices = [];
  19825. var vertices = [];
  19826. var normals = [];
  19827. var uvs = []; // helper variables
  19828. var vertex = new Vector3();
  19829. var normal = new Vector3();
  19830. var P1 = new Vector3();
  19831. var P2 = new Vector3();
  19832. var B = new Vector3();
  19833. var T = new Vector3();
  19834. var N = new Vector3(); // generate vertices, normals and uvs
  19835. for (var i = 0; i <= tubularSegments; ++i) {
  19836. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19837. 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.
  19838. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19839. calculatePositionOnCurve(u, p, q, radius, P1);
  19840. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19841. T.subVectors(P2, P1);
  19842. N.addVectors(P2, P1);
  19843. B.crossVectors(T, N);
  19844. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19845. B.normalize();
  19846. N.normalize();
  19847. for (var j = 0; j <= radialSegments; ++j) {
  19848. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19849. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19850. var v = j / radialSegments * Math.PI * 2;
  19851. var cx = -tube * Math.cos(v);
  19852. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19853. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19854. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19855. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19856. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19857. 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)
  19858. normal.subVectors(vertex, P1).normalize();
  19859. normals.push(normal.x, normal.y, normal.z); // uv
  19860. uvs.push(i / tubularSegments);
  19861. uvs.push(j / radialSegments);
  19862. }
  19863. } // generate indices
  19864. for (var _j = 1; _j <= tubularSegments; _j++) {
  19865. for (var _i = 1; _i <= radialSegments; _i++) {
  19866. // indices
  19867. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19868. var b = (radialSegments + 1) * _j + (_i - 1);
  19869. var c = (radialSegments + 1) * _j + _i;
  19870. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19871. indices.push(a, b, d);
  19872. indices.push(b, c, d);
  19873. }
  19874. } // build geometry
  19875. _this.setIndex(indices);
  19876. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19877. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19878. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19879. function calculatePositionOnCurve(u, p, q, radius, position) {
  19880. var cu = Math.cos(u);
  19881. var su = Math.sin(u);
  19882. var quOverP = q / p * u;
  19883. var cs = Math.cos(quOverP);
  19884. position.x = radius * (2 + cs) * 0.5 * cu;
  19885. position.y = radius * (2 + cs) * su * 0.5;
  19886. position.z = radius * Math.sin(quOverP) * 0.5;
  19887. }
  19888. return _this;
  19889. }
  19890. return TorusKnotBufferGeometry;
  19891. }(BufferGeometry);
  19892. var TorusKnotGeometry = /*#__PURE__*/function (_Geometry) {
  19893. _inheritsLoose(TorusKnotGeometry, _Geometry);
  19894. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q, heightScale) {
  19895. var _this;
  19896. _this = _Geometry.call(this) || this;
  19897. _this.type = 'TorusKnotGeometry';
  19898. _this.parameters = {
  19899. radius: radius,
  19900. tube: tube,
  19901. tubularSegments: tubularSegments,
  19902. radialSegments: radialSegments,
  19903. p: p,
  19904. q: q
  19905. };
  19906. if (heightScale !== undefined) console.warn('THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.');
  19907. _this.fromBufferGeometry(new TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q));
  19908. _this.mergeVertices();
  19909. return _this;
  19910. }
  19911. return TorusKnotGeometry;
  19912. }(Geometry);
  19913. var TubeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19914. _inheritsLoose(TubeBufferGeometry, _BufferGeometry);
  19915. function TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19916. var _this;
  19917. if (tubularSegments === void 0) {
  19918. tubularSegments = 64;
  19919. }
  19920. if (radius === void 0) {
  19921. radius = 1;
  19922. }
  19923. if (radialSegments === void 0) {
  19924. radialSegments = 8;
  19925. }
  19926. if (closed === void 0) {
  19927. closed = false;
  19928. }
  19929. _this = _BufferGeometry.call(this) || this;
  19930. _this.type = 'TubeBufferGeometry';
  19931. _this.parameters = {
  19932. path: path,
  19933. tubularSegments: tubularSegments,
  19934. radius: radius,
  19935. radialSegments: radialSegments,
  19936. closed: closed
  19937. };
  19938. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19939. _this.tangents = frames.tangents;
  19940. _this.normals = frames.normals;
  19941. _this.binormals = frames.binormals; // helper variables
  19942. var vertex = new Vector3();
  19943. var normal = new Vector3();
  19944. var uv = new Vector2();
  19945. var P = new Vector3(); // buffer
  19946. var vertices = [];
  19947. var normals = [];
  19948. var uvs = [];
  19949. var indices = []; // create buffer data
  19950. generateBufferData(); // build geometry
  19951. _this.setIndex(indices);
  19952. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19953. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19954. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19955. function generateBufferData() {
  19956. for (var i = 0; i < tubularSegments; i++) {
  19957. generateSegment(i);
  19958. } // if the geometry is not closed, generate the last row of vertices and normals
  19959. // at the regular position on the given path
  19960. //
  19961. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19962. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19963. // this makes it easy compute correct values for closed geometries
  19964. generateUVs(); // finally create faces
  19965. generateIndices();
  19966. }
  19967. function generateSegment(i) {
  19968. // we use getPointAt to sample evenly distributed points from the given path
  19969. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19970. var N = frames.normals[i];
  19971. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19972. for (var j = 0; j <= radialSegments; j++) {
  19973. var v = j / radialSegments * Math.PI * 2;
  19974. var sin = Math.sin(v);
  19975. var cos = -Math.cos(v); // normal
  19976. normal.x = cos * N.x + sin * B.x;
  19977. normal.y = cos * N.y + sin * B.y;
  19978. normal.z = cos * N.z + sin * B.z;
  19979. normal.normalize();
  19980. normals.push(normal.x, normal.y, normal.z); // vertex
  19981. vertex.x = P.x + radius * normal.x;
  19982. vertex.y = P.y + radius * normal.y;
  19983. vertex.z = P.z + radius * normal.z;
  19984. vertices.push(vertex.x, vertex.y, vertex.z);
  19985. }
  19986. }
  19987. function generateIndices() {
  19988. for (var j = 1; j <= tubularSegments; j++) {
  19989. for (var i = 1; i <= radialSegments; i++) {
  19990. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  19991. var b = (radialSegments + 1) * j + (i - 1);
  19992. var c = (radialSegments + 1) * j + i;
  19993. var d = (radialSegments + 1) * (j - 1) + i; // faces
  19994. indices.push(a, b, d);
  19995. indices.push(b, c, d);
  19996. }
  19997. }
  19998. }
  19999. function generateUVs() {
  20000. for (var i = 0; i <= tubularSegments; i++) {
  20001. for (var j = 0; j <= radialSegments; j++) {
  20002. uv.x = i / tubularSegments;
  20003. uv.y = j / radialSegments;
  20004. uvs.push(uv.x, uv.y);
  20005. }
  20006. }
  20007. }
  20008. return _this;
  20009. }
  20010. var _proto = TubeBufferGeometry.prototype;
  20011. _proto.toJSON = function toJSON() {
  20012. var data = BufferGeometry.prototype.toJSON.call(this);
  20013. data.path = this.parameters.path.toJSON();
  20014. return data;
  20015. };
  20016. return TubeBufferGeometry;
  20017. }(BufferGeometry);
  20018. var TubeGeometry = /*#__PURE__*/function (_Geometry) {
  20019. _inheritsLoose(TubeGeometry, _Geometry);
  20020. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed, taper) {
  20021. var _this;
  20022. _this = _Geometry.call(this) || this;
  20023. _this.type = 'TubeGeometry';
  20024. _this.parameters = {
  20025. path: path,
  20026. tubularSegments: tubularSegments,
  20027. radius: radius,
  20028. radialSegments: radialSegments,
  20029. closed: closed
  20030. };
  20031. if (taper !== undefined) console.warn('THREE.TubeGeometry: taper has been removed.');
  20032. var bufferGeometry = new TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed); // expose internals
  20033. _this.tangents = bufferGeometry.tangents;
  20034. _this.normals = bufferGeometry.normals;
  20035. _this.binormals = bufferGeometry.binormals; // create geometry
  20036. _this.fromBufferGeometry(bufferGeometry);
  20037. _this.mergeVertices();
  20038. return _this;
  20039. }
  20040. return TubeGeometry;
  20041. }(Geometry);
  20042. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  20043. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  20044. function WireframeGeometry(geometry) {
  20045. var _this;
  20046. _this = _BufferGeometry.call(this) || this;
  20047. _this.type = 'WireframeGeometry'; // buffer
  20048. var vertices = []; // helper variables
  20049. var edge = [0, 0],
  20050. edges = {};
  20051. var keys = ['a', 'b', 'c']; // different logic for Geometry and BufferGeometry
  20052. if (geometry && geometry.isGeometry) {
  20053. // create a data structure that contains all edges without duplicates
  20054. var faces = geometry.faces;
  20055. for (var i = 0, l = faces.length; i < l; i++) {
  20056. var face = faces[i];
  20057. for (var j = 0; j < 3; j++) {
  20058. var edge1 = face[keys[j]];
  20059. var edge2 = face[keys[(j + 1) % 3]];
  20060. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  20061. edge[1] = Math.max(edge1, edge2);
  20062. var key = edge[0] + ',' + edge[1];
  20063. if (edges[key] === undefined) {
  20064. edges[key] = {
  20065. index1: edge[0],
  20066. index2: edge[1]
  20067. };
  20068. }
  20069. }
  20070. } // generate vertices
  20071. for (var _key in edges) {
  20072. var e = edges[_key];
  20073. var vertex = geometry.vertices[e.index1];
  20074. vertices.push(vertex.x, vertex.y, vertex.z);
  20075. vertex = geometry.vertices[e.index2];
  20076. vertices.push(vertex.x, vertex.y, vertex.z);
  20077. }
  20078. } else if (geometry && geometry.isBufferGeometry) {
  20079. var _vertex = new Vector3();
  20080. if (geometry.index !== null) {
  20081. // indexed BufferGeometry
  20082. var position = geometry.attributes.position;
  20083. var indices = geometry.index;
  20084. var groups = geometry.groups;
  20085. if (groups.length === 0) {
  20086. groups = [{
  20087. start: 0,
  20088. count: indices.count,
  20089. materialIndex: 0
  20090. }];
  20091. } // create a data structure that contains all eges without duplicates
  20092. for (var o = 0, ol = groups.length; o < ol; ++o) {
  20093. var group = groups[o];
  20094. var start = group.start;
  20095. var count = group.count;
  20096. for (var _i = start, _l = start + count; _i < _l; _i += 3) {
  20097. for (var _j = 0; _j < 3; _j++) {
  20098. var _edge = indices.getX(_i + _j);
  20099. var _edge2 = indices.getX(_i + (_j + 1) % 3);
  20100. edge[0] = Math.min(_edge, _edge2); // sorting prevents duplicates
  20101. edge[1] = Math.max(_edge, _edge2);
  20102. var _key2 = edge[0] + ',' + edge[1];
  20103. if (edges[_key2] === undefined) {
  20104. edges[_key2] = {
  20105. index1: edge[0],
  20106. index2: edge[1]
  20107. };
  20108. }
  20109. }
  20110. }
  20111. } // generate vertices
  20112. for (var _key3 in edges) {
  20113. var _e = edges[_key3];
  20114. _vertex.fromBufferAttribute(position, _e.index1);
  20115. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  20116. _vertex.fromBufferAttribute(position, _e.index2);
  20117. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  20118. }
  20119. } else {
  20120. // non-indexed BufferGeometry
  20121. var _position = geometry.attributes.position;
  20122. for (var _i2 = 0, _l2 = _position.count / 3; _i2 < _l2; _i2++) {
  20123. for (var _j2 = 0; _j2 < 3; _j2++) {
  20124. // three edges per triangle, an edge is represented as (index1, index2)
  20125. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  20126. var index1 = 3 * _i2 + _j2;
  20127. _vertex.fromBufferAttribute(_position, index1);
  20128. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  20129. var index2 = 3 * _i2 + (_j2 + 1) % 3;
  20130. _vertex.fromBufferAttribute(_position, index2);
  20131. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  20132. }
  20133. }
  20134. }
  20135. } // build geometry
  20136. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  20137. return _this;
  20138. }
  20139. return WireframeGeometry;
  20140. }(BufferGeometry);
  20141. var Geometries = /*#__PURE__*/Object.freeze({
  20142. __proto__: null,
  20143. BoxGeometry: BoxGeometry,
  20144. BoxBufferGeometry: BoxBufferGeometry,
  20145. CircleGeometry: CircleGeometry,
  20146. CircleBufferGeometry: CircleBufferGeometry,
  20147. ConeGeometry: ConeGeometry,
  20148. ConeBufferGeometry: ConeBufferGeometry,
  20149. CylinderGeometry: CylinderGeometry,
  20150. CylinderBufferGeometry: CylinderBufferGeometry,
  20151. DodecahedronGeometry: DodecahedronGeometry,
  20152. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  20153. EdgesGeometry: EdgesGeometry,
  20154. ExtrudeGeometry: ExtrudeGeometry,
  20155. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  20156. IcosahedronGeometry: IcosahedronGeometry,
  20157. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  20158. LatheGeometry: LatheGeometry,
  20159. LatheBufferGeometry: LatheBufferGeometry,
  20160. OctahedronGeometry: OctahedronGeometry,
  20161. OctahedronBufferGeometry: OctahedronBufferGeometry,
  20162. ParametricGeometry: ParametricGeometry,
  20163. ParametricBufferGeometry: ParametricBufferGeometry,
  20164. PlaneGeometry: PlaneGeometry,
  20165. PlaneBufferGeometry: PlaneBufferGeometry,
  20166. PolyhedronGeometry: PolyhedronGeometry,
  20167. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  20168. RingGeometry: RingGeometry,
  20169. RingBufferGeometry: RingBufferGeometry,
  20170. ShapeGeometry: ShapeGeometry,
  20171. ShapeBufferGeometry: ShapeBufferGeometry,
  20172. SphereGeometry: SphereGeometry,
  20173. SphereBufferGeometry: SphereBufferGeometry,
  20174. TetrahedronGeometry: TetrahedronGeometry,
  20175. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  20176. TextGeometry: TextGeometry,
  20177. TextBufferGeometry: TextBufferGeometry,
  20178. TorusGeometry: TorusGeometry,
  20179. TorusBufferGeometry: TorusBufferGeometry,
  20180. TorusKnotGeometry: TorusKnotGeometry,
  20181. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  20182. TubeGeometry: TubeGeometry,
  20183. TubeBufferGeometry: TubeBufferGeometry,
  20184. WireframeGeometry: WireframeGeometry
  20185. });
  20186. /**
  20187. * parameters = {
  20188. * color: <THREE.Color>
  20189. * }
  20190. */
  20191. function ShadowMaterial(parameters) {
  20192. Material.call(this);
  20193. this.type = 'ShadowMaterial';
  20194. this.color = new Color(0x000000);
  20195. this.transparent = true;
  20196. this.setValues(parameters);
  20197. }
  20198. ShadowMaterial.prototype = Object.create(Material.prototype);
  20199. ShadowMaterial.prototype.constructor = ShadowMaterial;
  20200. ShadowMaterial.prototype.isShadowMaterial = true;
  20201. ShadowMaterial.prototype.copy = function (source) {
  20202. Material.prototype.copy.call(this, source);
  20203. this.color.copy(source.color);
  20204. return this;
  20205. };
  20206. function RawShaderMaterial(parameters) {
  20207. ShaderMaterial.call(this, parameters);
  20208. this.type = 'RawShaderMaterial';
  20209. }
  20210. RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
  20211. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  20212. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  20213. /**
  20214. * parameters = {
  20215. * color: <hex>,
  20216. * roughness: <float>,
  20217. * metalness: <float>,
  20218. * opacity: <float>,
  20219. *
  20220. * map: new THREE.Texture( <Image> ),
  20221. *
  20222. * lightMap: new THREE.Texture( <Image> ),
  20223. * lightMapIntensity: <float>
  20224. *
  20225. * aoMap: new THREE.Texture( <Image> ),
  20226. * aoMapIntensity: <float>
  20227. *
  20228. * emissive: <hex>,
  20229. * emissiveIntensity: <float>
  20230. * emissiveMap: new THREE.Texture( <Image> ),
  20231. *
  20232. * bumpMap: new THREE.Texture( <Image> ),
  20233. * bumpScale: <float>,
  20234. *
  20235. * normalMap: new THREE.Texture( <Image> ),
  20236. * normalMapType: THREE.TangentSpaceNormalMap,
  20237. * normalScale: <Vector2>,
  20238. *
  20239. * displacementMap: new THREE.Texture( <Image> ),
  20240. * displacementScale: <float>,
  20241. * displacementBias: <float>,
  20242. *
  20243. * roughnessMap: new THREE.Texture( <Image> ),
  20244. *
  20245. * metalnessMap: new THREE.Texture( <Image> ),
  20246. *
  20247. * alphaMap: new THREE.Texture( <Image> ),
  20248. *
  20249. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20250. * envMapIntensity: <float>
  20251. *
  20252. * refractionRatio: <float>,
  20253. *
  20254. * wireframe: <boolean>,
  20255. * wireframeLinewidth: <float>,
  20256. *
  20257. * skinning: <bool>,
  20258. * morphTargets: <bool>,
  20259. * morphNormals: <bool>
  20260. * }
  20261. */
  20262. function MeshStandardMaterial(parameters) {
  20263. Material.call(this);
  20264. this.defines = {
  20265. 'STANDARD': ''
  20266. };
  20267. this.type = 'MeshStandardMaterial';
  20268. this.color = new Color(0xffffff); // diffuse
  20269. this.roughness = 1.0;
  20270. this.metalness = 0.0;
  20271. this.map = null;
  20272. this.lightMap = null;
  20273. this.lightMapIntensity = 1.0;
  20274. this.aoMap = null;
  20275. this.aoMapIntensity = 1.0;
  20276. this.emissive = new Color(0x000000);
  20277. this.emissiveIntensity = 1.0;
  20278. this.emissiveMap = null;
  20279. this.bumpMap = null;
  20280. this.bumpScale = 1;
  20281. this.normalMap = null;
  20282. this.normalMapType = TangentSpaceNormalMap;
  20283. this.normalScale = new Vector2(1, 1);
  20284. this.displacementMap = null;
  20285. this.displacementScale = 1;
  20286. this.displacementBias = 0;
  20287. this.roughnessMap = null;
  20288. this.metalnessMap = null;
  20289. this.alphaMap = null;
  20290. this.envMap = null;
  20291. this.envMapIntensity = 1.0;
  20292. this.refractionRatio = 0.98;
  20293. this.wireframe = false;
  20294. this.wireframeLinewidth = 1;
  20295. this.wireframeLinecap = 'round';
  20296. this.wireframeLinejoin = 'round';
  20297. this.skinning = false;
  20298. this.morphTargets = false;
  20299. this.morphNormals = false;
  20300. this.vertexTangents = false;
  20301. this.setValues(parameters);
  20302. }
  20303. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  20304. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  20305. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  20306. MeshStandardMaterial.prototype.copy = function (source) {
  20307. Material.prototype.copy.call(this, source);
  20308. this.defines = {
  20309. 'STANDARD': ''
  20310. };
  20311. this.color.copy(source.color);
  20312. this.roughness = source.roughness;
  20313. this.metalness = source.metalness;
  20314. this.map = source.map;
  20315. this.lightMap = source.lightMap;
  20316. this.lightMapIntensity = source.lightMapIntensity;
  20317. this.aoMap = source.aoMap;
  20318. this.aoMapIntensity = source.aoMapIntensity;
  20319. this.emissive.copy(source.emissive);
  20320. this.emissiveMap = source.emissiveMap;
  20321. this.emissiveIntensity = source.emissiveIntensity;
  20322. this.bumpMap = source.bumpMap;
  20323. this.bumpScale = source.bumpScale;
  20324. this.normalMap = source.normalMap;
  20325. this.normalMapType = source.normalMapType;
  20326. this.normalScale.copy(source.normalScale);
  20327. this.displacementMap = source.displacementMap;
  20328. this.displacementScale = source.displacementScale;
  20329. this.displacementBias = source.displacementBias;
  20330. this.roughnessMap = source.roughnessMap;
  20331. this.metalnessMap = source.metalnessMap;
  20332. this.alphaMap = source.alphaMap;
  20333. this.envMap = source.envMap;
  20334. this.envMapIntensity = source.envMapIntensity;
  20335. this.refractionRatio = source.refractionRatio;
  20336. this.wireframe = source.wireframe;
  20337. this.wireframeLinewidth = source.wireframeLinewidth;
  20338. this.wireframeLinecap = source.wireframeLinecap;
  20339. this.wireframeLinejoin = source.wireframeLinejoin;
  20340. this.skinning = source.skinning;
  20341. this.morphTargets = source.morphTargets;
  20342. this.morphNormals = source.morphNormals;
  20343. this.vertexTangents = source.vertexTangents;
  20344. return this;
  20345. };
  20346. /**
  20347. * parameters = {
  20348. * clearcoat: <float>,
  20349. * clearcoatMap: new THREE.Texture( <Image> ),
  20350. * clearcoatRoughness: <float>,
  20351. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  20352. * clearcoatNormalScale: <Vector2>,
  20353. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  20354. *
  20355. * reflectivity: <float>,
  20356. * ior: <float>,
  20357. *
  20358. * sheen: <Color>,
  20359. *
  20360. * transmission: <float>,
  20361. * transmissionMap: new THREE.Texture( <Image> )
  20362. * }
  20363. */
  20364. function MeshPhysicalMaterial(parameters) {
  20365. MeshStandardMaterial.call(this);
  20366. this.defines = {
  20367. 'STANDARD': '',
  20368. 'PHYSICAL': ''
  20369. };
  20370. this.type = 'MeshPhysicalMaterial';
  20371. this.clearcoat = 0.0;
  20372. this.clearcoatMap = null;
  20373. this.clearcoatRoughness = 0.0;
  20374. this.clearcoatRoughnessMap = null;
  20375. this.clearcoatNormalScale = new Vector2(1, 1);
  20376. this.clearcoatNormalMap = null;
  20377. this.reflectivity = 0.5; // maps to F0 = 0.04
  20378. Object.defineProperty(this, 'ior', {
  20379. get: function get() {
  20380. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  20381. },
  20382. set: function set(ior) {
  20383. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  20384. }
  20385. });
  20386. this.sheen = null; // null will disable sheen bsdf
  20387. this.transmission = 0.0;
  20388. this.transmissionMap = null;
  20389. this.setValues(parameters);
  20390. }
  20391. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  20392. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  20393. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  20394. MeshPhysicalMaterial.prototype.copy = function (source) {
  20395. MeshStandardMaterial.prototype.copy.call(this, source);
  20396. this.defines = {
  20397. 'STANDARD': '',
  20398. 'PHYSICAL': ''
  20399. };
  20400. this.clearcoat = source.clearcoat;
  20401. this.clearcoatMap = source.clearcoatMap;
  20402. this.clearcoatRoughness = source.clearcoatRoughness;
  20403. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  20404. this.clearcoatNormalMap = source.clearcoatNormalMap;
  20405. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  20406. this.reflectivity = source.reflectivity;
  20407. if (source.sheen) {
  20408. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  20409. } else {
  20410. this.sheen = null;
  20411. }
  20412. this.transmission = source.transmission;
  20413. this.transmissionMap = source.transmissionMap;
  20414. return this;
  20415. };
  20416. /**
  20417. * parameters = {
  20418. * color: <hex>,
  20419. * specular: <hex>,
  20420. * shininess: <float>,
  20421. * opacity: <float>,
  20422. *
  20423. * map: new THREE.Texture( <Image> ),
  20424. *
  20425. * lightMap: new THREE.Texture( <Image> ),
  20426. * lightMapIntensity: <float>
  20427. *
  20428. * aoMap: new THREE.Texture( <Image> ),
  20429. * aoMapIntensity: <float>
  20430. *
  20431. * emissive: <hex>,
  20432. * emissiveIntensity: <float>
  20433. * emissiveMap: new THREE.Texture( <Image> ),
  20434. *
  20435. * bumpMap: new THREE.Texture( <Image> ),
  20436. * bumpScale: <float>,
  20437. *
  20438. * normalMap: new THREE.Texture( <Image> ),
  20439. * normalMapType: THREE.TangentSpaceNormalMap,
  20440. * normalScale: <Vector2>,
  20441. *
  20442. * displacementMap: new THREE.Texture( <Image> ),
  20443. * displacementScale: <float>,
  20444. * displacementBias: <float>,
  20445. *
  20446. * specularMap: new THREE.Texture( <Image> ),
  20447. *
  20448. * alphaMap: new THREE.Texture( <Image> ),
  20449. *
  20450. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20451. * combine: THREE.MultiplyOperation,
  20452. * reflectivity: <float>,
  20453. * refractionRatio: <float>,
  20454. *
  20455. * wireframe: <boolean>,
  20456. * wireframeLinewidth: <float>,
  20457. *
  20458. * skinning: <bool>,
  20459. * morphTargets: <bool>,
  20460. * morphNormals: <bool>
  20461. * }
  20462. */
  20463. function MeshPhongMaterial(parameters) {
  20464. Material.call(this);
  20465. this.type = 'MeshPhongMaterial';
  20466. this.color = new Color(0xffffff); // diffuse
  20467. this.specular = new Color(0x111111);
  20468. this.shininess = 30;
  20469. this.map = null;
  20470. this.lightMap = null;
  20471. this.lightMapIntensity = 1.0;
  20472. this.aoMap = null;
  20473. this.aoMapIntensity = 1.0;
  20474. this.emissive = new Color(0x000000);
  20475. this.emissiveIntensity = 1.0;
  20476. this.emissiveMap = null;
  20477. this.bumpMap = null;
  20478. this.bumpScale = 1;
  20479. this.normalMap = null;
  20480. this.normalMapType = TangentSpaceNormalMap;
  20481. this.normalScale = new Vector2(1, 1);
  20482. this.displacementMap = null;
  20483. this.displacementScale = 1;
  20484. this.displacementBias = 0;
  20485. this.specularMap = null;
  20486. this.alphaMap = null;
  20487. this.envMap = null;
  20488. this.combine = MultiplyOperation;
  20489. this.reflectivity = 1;
  20490. this.refractionRatio = 0.98;
  20491. this.wireframe = false;
  20492. this.wireframeLinewidth = 1;
  20493. this.wireframeLinecap = 'round';
  20494. this.wireframeLinejoin = 'round';
  20495. this.skinning = false;
  20496. this.morphTargets = false;
  20497. this.morphNormals = false;
  20498. this.setValues(parameters);
  20499. }
  20500. MeshPhongMaterial.prototype = Object.create(Material.prototype);
  20501. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  20502. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  20503. MeshPhongMaterial.prototype.copy = function (source) {
  20504. Material.prototype.copy.call(this, source);
  20505. this.color.copy(source.color);
  20506. this.specular.copy(source.specular);
  20507. this.shininess = source.shininess;
  20508. this.map = source.map;
  20509. this.lightMap = source.lightMap;
  20510. this.lightMapIntensity = source.lightMapIntensity;
  20511. this.aoMap = source.aoMap;
  20512. this.aoMapIntensity = source.aoMapIntensity;
  20513. this.emissive.copy(source.emissive);
  20514. this.emissiveMap = source.emissiveMap;
  20515. this.emissiveIntensity = source.emissiveIntensity;
  20516. this.bumpMap = source.bumpMap;
  20517. this.bumpScale = source.bumpScale;
  20518. this.normalMap = source.normalMap;
  20519. this.normalMapType = source.normalMapType;
  20520. this.normalScale.copy(source.normalScale);
  20521. this.displacementMap = source.displacementMap;
  20522. this.displacementScale = source.displacementScale;
  20523. this.displacementBias = source.displacementBias;
  20524. this.specularMap = source.specularMap;
  20525. this.alphaMap = source.alphaMap;
  20526. this.envMap = source.envMap;
  20527. this.combine = source.combine;
  20528. this.reflectivity = source.reflectivity;
  20529. this.refractionRatio = source.refractionRatio;
  20530. this.wireframe = source.wireframe;
  20531. this.wireframeLinewidth = source.wireframeLinewidth;
  20532. this.wireframeLinecap = source.wireframeLinecap;
  20533. this.wireframeLinejoin = source.wireframeLinejoin;
  20534. this.skinning = source.skinning;
  20535. this.morphTargets = source.morphTargets;
  20536. this.morphNormals = source.morphNormals;
  20537. return this;
  20538. };
  20539. /**
  20540. * parameters = {
  20541. * color: <hex>,
  20542. *
  20543. * map: new THREE.Texture( <Image> ),
  20544. * gradientMap: new THREE.Texture( <Image> ),
  20545. *
  20546. * lightMap: new THREE.Texture( <Image> ),
  20547. * lightMapIntensity: <float>
  20548. *
  20549. * aoMap: new THREE.Texture( <Image> ),
  20550. * aoMapIntensity: <float>
  20551. *
  20552. * emissive: <hex>,
  20553. * emissiveIntensity: <float>
  20554. * emissiveMap: new THREE.Texture( <Image> ),
  20555. *
  20556. * bumpMap: new THREE.Texture( <Image> ),
  20557. * bumpScale: <float>,
  20558. *
  20559. * normalMap: new THREE.Texture( <Image> ),
  20560. * normalMapType: THREE.TangentSpaceNormalMap,
  20561. * normalScale: <Vector2>,
  20562. *
  20563. * displacementMap: new THREE.Texture( <Image> ),
  20564. * displacementScale: <float>,
  20565. * displacementBias: <float>,
  20566. *
  20567. * alphaMap: new THREE.Texture( <Image> ),
  20568. *
  20569. * wireframe: <boolean>,
  20570. * wireframeLinewidth: <float>,
  20571. *
  20572. * skinning: <bool>,
  20573. * morphTargets: <bool>,
  20574. * morphNormals: <bool>
  20575. * }
  20576. */
  20577. function MeshToonMaterial(parameters) {
  20578. Material.call(this);
  20579. this.defines = {
  20580. 'TOON': ''
  20581. };
  20582. this.type = 'MeshToonMaterial';
  20583. this.color = new Color(0xffffff);
  20584. this.map = null;
  20585. this.gradientMap = null;
  20586. this.lightMap = null;
  20587. this.lightMapIntensity = 1.0;
  20588. this.aoMap = null;
  20589. this.aoMapIntensity = 1.0;
  20590. this.emissive = new Color(0x000000);
  20591. this.emissiveIntensity = 1.0;
  20592. this.emissiveMap = null;
  20593. this.bumpMap = null;
  20594. this.bumpScale = 1;
  20595. this.normalMap = null;
  20596. this.normalMapType = TangentSpaceNormalMap;
  20597. this.normalScale = new Vector2(1, 1);
  20598. this.displacementMap = null;
  20599. this.displacementScale = 1;
  20600. this.displacementBias = 0;
  20601. this.alphaMap = null;
  20602. this.wireframe = false;
  20603. this.wireframeLinewidth = 1;
  20604. this.wireframeLinecap = 'round';
  20605. this.wireframeLinejoin = 'round';
  20606. this.skinning = false;
  20607. this.morphTargets = false;
  20608. this.morphNormals = false;
  20609. this.setValues(parameters);
  20610. }
  20611. MeshToonMaterial.prototype = Object.create(Material.prototype);
  20612. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  20613. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20614. MeshToonMaterial.prototype.copy = function (source) {
  20615. Material.prototype.copy.call(this, source);
  20616. this.color.copy(source.color);
  20617. this.map = source.map;
  20618. this.gradientMap = source.gradientMap;
  20619. this.lightMap = source.lightMap;
  20620. this.lightMapIntensity = source.lightMapIntensity;
  20621. this.aoMap = source.aoMap;
  20622. this.aoMapIntensity = source.aoMapIntensity;
  20623. this.emissive.copy(source.emissive);
  20624. this.emissiveMap = source.emissiveMap;
  20625. this.emissiveIntensity = source.emissiveIntensity;
  20626. this.bumpMap = source.bumpMap;
  20627. this.bumpScale = source.bumpScale;
  20628. this.normalMap = source.normalMap;
  20629. this.normalMapType = source.normalMapType;
  20630. this.normalScale.copy(source.normalScale);
  20631. this.displacementMap = source.displacementMap;
  20632. this.displacementScale = source.displacementScale;
  20633. this.displacementBias = source.displacementBias;
  20634. this.alphaMap = source.alphaMap;
  20635. this.wireframe = source.wireframe;
  20636. this.wireframeLinewidth = source.wireframeLinewidth;
  20637. this.wireframeLinecap = source.wireframeLinecap;
  20638. this.wireframeLinejoin = source.wireframeLinejoin;
  20639. this.skinning = source.skinning;
  20640. this.morphTargets = source.morphTargets;
  20641. this.morphNormals = source.morphNormals;
  20642. return this;
  20643. };
  20644. /**
  20645. * parameters = {
  20646. * opacity: <float>,
  20647. *
  20648. * bumpMap: new THREE.Texture( <Image> ),
  20649. * bumpScale: <float>,
  20650. *
  20651. * normalMap: new THREE.Texture( <Image> ),
  20652. * normalMapType: THREE.TangentSpaceNormalMap,
  20653. * normalScale: <Vector2>,
  20654. *
  20655. * displacementMap: new THREE.Texture( <Image> ),
  20656. * displacementScale: <float>,
  20657. * displacementBias: <float>,
  20658. *
  20659. * wireframe: <boolean>,
  20660. * wireframeLinewidth: <float>
  20661. *
  20662. * skinning: <bool>,
  20663. * morphTargets: <bool>,
  20664. * morphNormals: <bool>
  20665. * }
  20666. */
  20667. function MeshNormalMaterial(parameters) {
  20668. Material.call(this);
  20669. this.type = 'MeshNormalMaterial';
  20670. this.bumpMap = null;
  20671. this.bumpScale = 1;
  20672. this.normalMap = null;
  20673. this.normalMapType = TangentSpaceNormalMap;
  20674. this.normalScale = new Vector2(1, 1);
  20675. this.displacementMap = null;
  20676. this.displacementScale = 1;
  20677. this.displacementBias = 0;
  20678. this.wireframe = false;
  20679. this.wireframeLinewidth = 1;
  20680. this.fog = false;
  20681. this.skinning = false;
  20682. this.morphTargets = false;
  20683. this.morphNormals = false;
  20684. this.setValues(parameters);
  20685. }
  20686. MeshNormalMaterial.prototype = Object.create(Material.prototype);
  20687. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20688. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20689. MeshNormalMaterial.prototype.copy = function (source) {
  20690. Material.prototype.copy.call(this, source);
  20691. this.bumpMap = source.bumpMap;
  20692. this.bumpScale = source.bumpScale;
  20693. this.normalMap = source.normalMap;
  20694. this.normalMapType = source.normalMapType;
  20695. this.normalScale.copy(source.normalScale);
  20696. this.displacementMap = source.displacementMap;
  20697. this.displacementScale = source.displacementScale;
  20698. this.displacementBias = source.displacementBias;
  20699. this.wireframe = source.wireframe;
  20700. this.wireframeLinewidth = source.wireframeLinewidth;
  20701. this.skinning = source.skinning;
  20702. this.morphTargets = source.morphTargets;
  20703. this.morphNormals = source.morphNormals;
  20704. return this;
  20705. };
  20706. /**
  20707. * parameters = {
  20708. * color: <hex>,
  20709. * opacity: <float>,
  20710. *
  20711. * map: new THREE.Texture( <Image> ),
  20712. *
  20713. * lightMap: new THREE.Texture( <Image> ),
  20714. * lightMapIntensity: <float>
  20715. *
  20716. * aoMap: new THREE.Texture( <Image> ),
  20717. * aoMapIntensity: <float>
  20718. *
  20719. * emissive: <hex>,
  20720. * emissiveIntensity: <float>
  20721. * emissiveMap: new THREE.Texture( <Image> ),
  20722. *
  20723. * specularMap: new THREE.Texture( <Image> ),
  20724. *
  20725. * alphaMap: new THREE.Texture( <Image> ),
  20726. *
  20727. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20728. * combine: THREE.Multiply,
  20729. * reflectivity: <float>,
  20730. * refractionRatio: <float>,
  20731. *
  20732. * wireframe: <boolean>,
  20733. * wireframeLinewidth: <float>,
  20734. *
  20735. * skinning: <bool>,
  20736. * morphTargets: <bool>,
  20737. * morphNormals: <bool>
  20738. * }
  20739. */
  20740. function MeshLambertMaterial(parameters) {
  20741. Material.call(this);
  20742. this.type = 'MeshLambertMaterial';
  20743. this.color = new Color(0xffffff); // diffuse
  20744. this.map = null;
  20745. this.lightMap = null;
  20746. this.lightMapIntensity = 1.0;
  20747. this.aoMap = null;
  20748. this.aoMapIntensity = 1.0;
  20749. this.emissive = new Color(0x000000);
  20750. this.emissiveIntensity = 1.0;
  20751. this.emissiveMap = null;
  20752. this.specularMap = null;
  20753. this.alphaMap = null;
  20754. this.envMap = null;
  20755. this.combine = MultiplyOperation;
  20756. this.reflectivity = 1;
  20757. this.refractionRatio = 0.98;
  20758. this.wireframe = false;
  20759. this.wireframeLinewidth = 1;
  20760. this.wireframeLinecap = 'round';
  20761. this.wireframeLinejoin = 'round';
  20762. this.skinning = false;
  20763. this.morphTargets = false;
  20764. this.morphNormals = false;
  20765. this.setValues(parameters);
  20766. }
  20767. MeshLambertMaterial.prototype = Object.create(Material.prototype);
  20768. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20769. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20770. MeshLambertMaterial.prototype.copy = function (source) {
  20771. Material.prototype.copy.call(this, source);
  20772. this.color.copy(source.color);
  20773. this.map = source.map;
  20774. this.lightMap = source.lightMap;
  20775. this.lightMapIntensity = source.lightMapIntensity;
  20776. this.aoMap = source.aoMap;
  20777. this.aoMapIntensity = source.aoMapIntensity;
  20778. this.emissive.copy(source.emissive);
  20779. this.emissiveMap = source.emissiveMap;
  20780. this.emissiveIntensity = source.emissiveIntensity;
  20781. this.specularMap = source.specularMap;
  20782. this.alphaMap = source.alphaMap;
  20783. this.envMap = source.envMap;
  20784. this.combine = source.combine;
  20785. this.reflectivity = source.reflectivity;
  20786. this.refractionRatio = source.refractionRatio;
  20787. this.wireframe = source.wireframe;
  20788. this.wireframeLinewidth = source.wireframeLinewidth;
  20789. this.wireframeLinecap = source.wireframeLinecap;
  20790. this.wireframeLinejoin = source.wireframeLinejoin;
  20791. this.skinning = source.skinning;
  20792. this.morphTargets = source.morphTargets;
  20793. this.morphNormals = source.morphNormals;
  20794. return this;
  20795. };
  20796. /**
  20797. * parameters = {
  20798. * color: <hex>,
  20799. * opacity: <float>,
  20800. *
  20801. * matcap: new THREE.Texture( <Image> ),
  20802. *
  20803. * map: new THREE.Texture( <Image> ),
  20804. *
  20805. * bumpMap: new THREE.Texture( <Image> ),
  20806. * bumpScale: <float>,
  20807. *
  20808. * normalMap: new THREE.Texture( <Image> ),
  20809. * normalMapType: THREE.TangentSpaceNormalMap,
  20810. * normalScale: <Vector2>,
  20811. *
  20812. * displacementMap: new THREE.Texture( <Image> ),
  20813. * displacementScale: <float>,
  20814. * displacementBias: <float>,
  20815. *
  20816. * alphaMap: new THREE.Texture( <Image> ),
  20817. *
  20818. * skinning: <bool>,
  20819. * morphTargets: <bool>,
  20820. * morphNormals: <bool>
  20821. * }
  20822. */
  20823. function MeshMatcapMaterial(parameters) {
  20824. Material.call(this);
  20825. this.defines = {
  20826. 'MATCAP': ''
  20827. };
  20828. this.type = 'MeshMatcapMaterial';
  20829. this.color = new Color(0xffffff); // diffuse
  20830. this.matcap = null;
  20831. this.map = null;
  20832. this.bumpMap = null;
  20833. this.bumpScale = 1;
  20834. this.normalMap = null;
  20835. this.normalMapType = TangentSpaceNormalMap;
  20836. this.normalScale = new Vector2(1, 1);
  20837. this.displacementMap = null;
  20838. this.displacementScale = 1;
  20839. this.displacementBias = 0;
  20840. this.alphaMap = null;
  20841. this.skinning = false;
  20842. this.morphTargets = false;
  20843. this.morphNormals = false;
  20844. this.setValues(parameters);
  20845. }
  20846. MeshMatcapMaterial.prototype = Object.create(Material.prototype);
  20847. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20848. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20849. MeshMatcapMaterial.prototype.copy = function (source) {
  20850. Material.prototype.copy.call(this, source);
  20851. this.defines = {
  20852. 'MATCAP': ''
  20853. };
  20854. this.color.copy(source.color);
  20855. this.matcap = source.matcap;
  20856. this.map = source.map;
  20857. this.bumpMap = source.bumpMap;
  20858. this.bumpScale = source.bumpScale;
  20859. this.normalMap = source.normalMap;
  20860. this.normalMapType = source.normalMapType;
  20861. this.normalScale.copy(source.normalScale);
  20862. this.displacementMap = source.displacementMap;
  20863. this.displacementScale = source.displacementScale;
  20864. this.displacementBias = source.displacementBias;
  20865. this.alphaMap = source.alphaMap;
  20866. this.skinning = source.skinning;
  20867. this.morphTargets = source.morphTargets;
  20868. this.morphNormals = source.morphNormals;
  20869. return this;
  20870. };
  20871. /**
  20872. * parameters = {
  20873. * color: <hex>,
  20874. * opacity: <float>,
  20875. *
  20876. * linewidth: <float>,
  20877. *
  20878. * scale: <float>,
  20879. * dashSize: <float>,
  20880. * gapSize: <float>
  20881. * }
  20882. */
  20883. function LineDashedMaterial(parameters) {
  20884. LineBasicMaterial.call(this);
  20885. this.type = 'LineDashedMaterial';
  20886. this.scale = 1;
  20887. this.dashSize = 3;
  20888. this.gapSize = 1;
  20889. this.setValues(parameters);
  20890. }
  20891. LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
  20892. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20893. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20894. LineDashedMaterial.prototype.copy = function (source) {
  20895. LineBasicMaterial.prototype.copy.call(this, source);
  20896. this.scale = source.scale;
  20897. this.dashSize = source.dashSize;
  20898. this.gapSize = source.gapSize;
  20899. return this;
  20900. };
  20901. var Materials = /*#__PURE__*/Object.freeze({
  20902. __proto__: null,
  20903. ShadowMaterial: ShadowMaterial,
  20904. SpriteMaterial: SpriteMaterial,
  20905. RawShaderMaterial: RawShaderMaterial,
  20906. ShaderMaterial: ShaderMaterial,
  20907. PointsMaterial: PointsMaterial,
  20908. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20909. MeshStandardMaterial: MeshStandardMaterial,
  20910. MeshPhongMaterial: MeshPhongMaterial,
  20911. MeshToonMaterial: MeshToonMaterial,
  20912. MeshNormalMaterial: MeshNormalMaterial,
  20913. MeshLambertMaterial: MeshLambertMaterial,
  20914. MeshDepthMaterial: MeshDepthMaterial,
  20915. MeshDistanceMaterial: MeshDistanceMaterial,
  20916. MeshBasicMaterial: MeshBasicMaterial,
  20917. MeshMatcapMaterial: MeshMatcapMaterial,
  20918. LineDashedMaterial: LineDashedMaterial,
  20919. LineBasicMaterial: LineBasicMaterial,
  20920. Material: Material
  20921. });
  20922. var AnimationUtils = {
  20923. // same as Array.prototype.slice, but also works on typed arrays
  20924. arraySlice: function arraySlice(array, from, to) {
  20925. if (AnimationUtils.isTypedArray(array)) {
  20926. // in ios9 array.subarray(from, undefined) will return empty array
  20927. // but array.subarray(from) or array.subarray(from, len) is correct
  20928. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20929. }
  20930. return array.slice(from, to);
  20931. },
  20932. // converts an array to a specific type
  20933. convertArray: function convertArray(array, type, forceClone) {
  20934. if (!array || // let 'undefined' and 'null' pass
  20935. !forceClone && array.constructor === type) return array;
  20936. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20937. return new type(array); // create typed array
  20938. }
  20939. return Array.prototype.slice.call(array); // create Array
  20940. },
  20941. isTypedArray: function isTypedArray(object) {
  20942. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20943. },
  20944. // returns an array by which times and values can be sorted
  20945. getKeyframeOrder: function getKeyframeOrder(times) {
  20946. function compareTime(i, j) {
  20947. return times[i] - times[j];
  20948. }
  20949. var n = times.length;
  20950. var result = new Array(n);
  20951. for (var i = 0; i !== n; ++i) {
  20952. result[i] = i;
  20953. }
  20954. result.sort(compareTime);
  20955. return result;
  20956. },
  20957. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20958. sortedArray: function sortedArray(values, stride, order) {
  20959. var nValues = values.length;
  20960. var result = new values.constructor(nValues);
  20961. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20962. var srcOffset = order[i] * stride;
  20963. for (var j = 0; j !== stride; ++j) {
  20964. result[dstOffset++] = values[srcOffset + j];
  20965. }
  20966. }
  20967. return result;
  20968. },
  20969. // function for parsing AOS keyframe formats
  20970. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20971. var i = 1,
  20972. key = jsonKeys[0];
  20973. while (key !== undefined && key[valuePropertyName] === undefined) {
  20974. key = jsonKeys[i++];
  20975. }
  20976. if (key === undefined) return; // no data
  20977. var value = key[valuePropertyName];
  20978. if (value === undefined) return; // no data
  20979. if (Array.isArray(value)) {
  20980. do {
  20981. value = key[valuePropertyName];
  20982. if (value !== undefined) {
  20983. times.push(key.time);
  20984. values.push.apply(values, value); // push all elements
  20985. }
  20986. key = jsonKeys[i++];
  20987. } while (key !== undefined);
  20988. } else if (value.toArray !== undefined) {
  20989. // ...assume THREE.Math-ish
  20990. do {
  20991. value = key[valuePropertyName];
  20992. if (value !== undefined) {
  20993. times.push(key.time);
  20994. value.toArray(values, values.length);
  20995. }
  20996. key = jsonKeys[i++];
  20997. } while (key !== undefined);
  20998. } else {
  20999. // otherwise push as-is
  21000. do {
  21001. value = key[valuePropertyName];
  21002. if (value !== undefined) {
  21003. times.push(key.time);
  21004. values.push(value);
  21005. }
  21006. key = jsonKeys[i++];
  21007. } while (key !== undefined);
  21008. }
  21009. },
  21010. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  21011. if (fps === void 0) {
  21012. fps = 30;
  21013. }
  21014. var clip = sourceClip.clone();
  21015. clip.name = name;
  21016. var tracks = [];
  21017. for (var i = 0; i < clip.tracks.length; ++i) {
  21018. var track = clip.tracks[i];
  21019. var valueSize = track.getValueSize();
  21020. var times = [];
  21021. var values = [];
  21022. for (var j = 0; j < track.times.length; ++j) {
  21023. var frame = track.times[j] * fps;
  21024. if (frame < startFrame || frame >= endFrame) continue;
  21025. times.push(track.times[j]);
  21026. for (var k = 0; k < valueSize; ++k) {
  21027. values.push(track.values[j * valueSize + k]);
  21028. }
  21029. }
  21030. if (times.length === 0) continue;
  21031. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  21032. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  21033. tracks.push(track);
  21034. }
  21035. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  21036. var minStartTime = Infinity;
  21037. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  21038. if (minStartTime > clip.tracks[_i].times[0]) {
  21039. minStartTime = clip.tracks[_i].times[0];
  21040. }
  21041. } // shift all tracks such that clip begins at t=0
  21042. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  21043. clip.tracks[_i2].shift(-1 * minStartTime);
  21044. }
  21045. clip.resetDuration();
  21046. return clip;
  21047. },
  21048. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  21049. if (referenceFrame === void 0) {
  21050. referenceFrame = 0;
  21051. }
  21052. if (referenceClip === void 0) {
  21053. referenceClip = targetClip;
  21054. }
  21055. if (fps === void 0) {
  21056. fps = 30;
  21057. }
  21058. if (fps <= 0) fps = 30;
  21059. var numTracks = referenceClip.tracks.length;
  21060. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  21061. var _loop = function _loop(i) {
  21062. var referenceTrack = referenceClip.tracks[i];
  21063. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  21064. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  21065. var targetTrack = targetClip.tracks.find(function (track) {
  21066. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  21067. });
  21068. if (targetTrack === undefined) return "continue";
  21069. var referenceOffset = 0;
  21070. var referenceValueSize = referenceTrack.getValueSize();
  21071. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  21072. referenceOffset = referenceValueSize / 3;
  21073. }
  21074. var targetOffset = 0;
  21075. var targetValueSize = targetTrack.getValueSize();
  21076. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  21077. targetOffset = targetValueSize / 3;
  21078. }
  21079. var lastIndex = referenceTrack.times.length - 1;
  21080. var referenceValue = void 0; // Find the value to subtract out of the track
  21081. if (referenceTime <= referenceTrack.times[0]) {
  21082. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  21083. var startIndex = referenceOffset;
  21084. var endIndex = referenceValueSize - referenceOffset;
  21085. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  21086. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  21087. // Reference frame is after the last keyframe, so just use the last keyframe
  21088. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  21089. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  21090. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  21091. } else {
  21092. // Interpolate to the reference value
  21093. var interpolant = referenceTrack.createInterpolant();
  21094. var _startIndex2 = referenceOffset;
  21095. var _endIndex2 = referenceValueSize - referenceOffset;
  21096. interpolant.evaluate(referenceTime);
  21097. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  21098. } // Conjugate the quaternion
  21099. if (referenceTrackType === 'quaternion') {
  21100. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  21101. referenceQuat.toArray(referenceValue);
  21102. } // Subtract the reference value from all of the track values
  21103. var numTimes = targetTrack.times.length;
  21104. for (var j = 0; j < numTimes; ++j) {
  21105. var valueStart = j * targetValueSize + targetOffset;
  21106. if (referenceTrackType === 'quaternion') {
  21107. // Multiply the conjugate for quaternion track types
  21108. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  21109. } else {
  21110. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  21111. for (var k = 0; k < valueEnd; ++k) {
  21112. targetTrack.values[valueStart + k] -= referenceValue[k];
  21113. }
  21114. }
  21115. }
  21116. };
  21117. for (var i = 0; i < numTracks; ++i) {
  21118. var _ret = _loop(i);
  21119. if (_ret === "continue") continue;
  21120. }
  21121. targetClip.blendMode = AdditiveAnimationBlendMode;
  21122. return targetClip;
  21123. }
  21124. };
  21125. /**
  21126. * Abstract base class of interpolants over parametric samples.
  21127. *
  21128. * The parameter domain is one dimensional, typically the time or a path
  21129. * along a curve defined by the data.
  21130. *
  21131. * The sample values can have any dimensionality and derived classes may
  21132. * apply special interpretations to the data.
  21133. *
  21134. * This class provides the interval seek in a Template Method, deferring
  21135. * the actual interpolation to derived classes.
  21136. *
  21137. * Time complexity is O(1) for linear access crossing at most two points
  21138. * and O(log N) for random access, where N is the number of positions.
  21139. *
  21140. * References:
  21141. *
  21142. * http://www.oodesign.com/template-method-pattern.html
  21143. *
  21144. */
  21145. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21146. this.parameterPositions = parameterPositions;
  21147. this._cachedIndex = 0;
  21148. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  21149. this.sampleValues = sampleValues;
  21150. this.valueSize = sampleSize;
  21151. }
  21152. Object.assign(Interpolant.prototype, {
  21153. evaluate: function evaluate(t) {
  21154. var pp = this.parameterPositions;
  21155. var i1 = this._cachedIndex,
  21156. t1 = pp[i1],
  21157. t0 = pp[i1 - 1];
  21158. validate_interval: {
  21159. seek: {
  21160. var right;
  21161. linear_scan: {
  21162. //- See http://jsperf.com/comparison-to-undefined/3
  21163. //- slower code:
  21164. //-
  21165. //- if ( t >= t1 || t1 === undefined ) {
  21166. forward_scan: if (!(t < t1)) {
  21167. for (var giveUpAt = i1 + 2;;) {
  21168. if (t1 === undefined) {
  21169. if (t < t0) break forward_scan; // after end
  21170. i1 = pp.length;
  21171. this._cachedIndex = i1;
  21172. return this.afterEnd_(i1 - 1, t, t0);
  21173. }
  21174. if (i1 === giveUpAt) break; // this loop
  21175. t0 = t1;
  21176. t1 = pp[++i1];
  21177. if (t < t1) {
  21178. // we have arrived at the sought interval
  21179. break seek;
  21180. }
  21181. } // prepare binary search on the right side of the index
  21182. right = pp.length;
  21183. break linear_scan;
  21184. } //- slower code:
  21185. //- if ( t < t0 || t0 === undefined ) {
  21186. if (!(t >= t0)) {
  21187. // looping?
  21188. var t1global = pp[1];
  21189. if (t < t1global) {
  21190. i1 = 2; // + 1, using the scan for the details
  21191. t0 = t1global;
  21192. } // linear reverse scan
  21193. for (var _giveUpAt = i1 - 2;;) {
  21194. if (t0 === undefined) {
  21195. // before start
  21196. this._cachedIndex = 0;
  21197. return this.beforeStart_(0, t, t1);
  21198. }
  21199. if (i1 === _giveUpAt) break; // this loop
  21200. t1 = t0;
  21201. t0 = pp[--i1 - 1];
  21202. if (t >= t0) {
  21203. // we have arrived at the sought interval
  21204. break seek;
  21205. }
  21206. } // prepare binary search on the left side of the index
  21207. right = i1;
  21208. i1 = 0;
  21209. break linear_scan;
  21210. } // the interval is valid
  21211. break validate_interval;
  21212. } // linear scan
  21213. // binary search
  21214. while (i1 < right) {
  21215. var mid = i1 + right >>> 1;
  21216. if (t < pp[mid]) {
  21217. right = mid;
  21218. } else {
  21219. i1 = mid + 1;
  21220. }
  21221. }
  21222. t1 = pp[i1];
  21223. t0 = pp[i1 - 1]; // check boundary cases, again
  21224. if (t0 === undefined) {
  21225. this._cachedIndex = 0;
  21226. return this.beforeStart_(0, t, t1);
  21227. }
  21228. if (t1 === undefined) {
  21229. i1 = pp.length;
  21230. this._cachedIndex = i1;
  21231. return this.afterEnd_(i1 - 1, t0, t);
  21232. }
  21233. } // seek
  21234. this._cachedIndex = i1;
  21235. this.intervalChanged_(i1, t0, t1);
  21236. } // validate_interval
  21237. return this.interpolate_(i1, t0, t, t1);
  21238. },
  21239. settings: null,
  21240. // optional, subclass-specific settings structure
  21241. // Note: The indirection allows central control of many interpolants.
  21242. // --- Protected interface
  21243. DefaultSettings_: {},
  21244. getSettings_: function getSettings_() {
  21245. return this.settings || this.DefaultSettings_;
  21246. },
  21247. copySampleValue_: function copySampleValue_(index) {
  21248. // copies a sample value to the result buffer
  21249. var result = this.resultBuffer,
  21250. values = this.sampleValues,
  21251. stride = this.valueSize,
  21252. offset = index * stride;
  21253. for (var i = 0; i !== stride; ++i) {
  21254. result[i] = values[offset + i];
  21255. }
  21256. return result;
  21257. },
  21258. // Template methods for derived classes:
  21259. interpolate_: function interpolate_()
  21260. /* i1, t0, t, t1 */
  21261. {
  21262. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  21263. },
  21264. intervalChanged_: function intervalChanged_()
  21265. /* i1, t0, t1 */
  21266. {// empty
  21267. }
  21268. }); // DECLARE ALIAS AFTER assign prototype
  21269. Object.assign(Interpolant.prototype, {
  21270. //( 0, t, t0 ), returns this.resultBuffer
  21271. beforeStart_: Interpolant.prototype.copySampleValue_,
  21272. //( N-1, tN-1, t ), returns this.resultBuffer
  21273. afterEnd_: Interpolant.prototype.copySampleValue_
  21274. });
  21275. /**
  21276. * Fast and simple cubic spline interpolant.
  21277. *
  21278. * It was derived from a Hermitian construction setting the first derivative
  21279. * at each sample position to the linear slope between neighboring positions
  21280. * over their parameter interval.
  21281. */
  21282. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21283. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21284. this._weightPrev = -0;
  21285. this._offsetPrev = -0;
  21286. this._weightNext = -0;
  21287. this._offsetNext = -0;
  21288. }
  21289. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21290. constructor: CubicInterpolant,
  21291. DefaultSettings_: {
  21292. endingStart: ZeroCurvatureEnding,
  21293. endingEnd: ZeroCurvatureEnding
  21294. },
  21295. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  21296. var pp = this.parameterPositions;
  21297. var iPrev = i1 - 2,
  21298. iNext = i1 + 1,
  21299. tPrev = pp[iPrev],
  21300. tNext = pp[iNext];
  21301. if (tPrev === undefined) {
  21302. switch (this.getSettings_().endingStart) {
  21303. case ZeroSlopeEnding:
  21304. // f'(t0) = 0
  21305. iPrev = i1;
  21306. tPrev = 2 * t0 - t1;
  21307. break;
  21308. case WrapAroundEnding:
  21309. // use the other end of the curve
  21310. iPrev = pp.length - 2;
  21311. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  21312. break;
  21313. default:
  21314. // ZeroCurvatureEnding
  21315. // f''(t0) = 0 a.k.a. Natural Spline
  21316. iPrev = i1;
  21317. tPrev = t1;
  21318. }
  21319. }
  21320. if (tNext === undefined) {
  21321. switch (this.getSettings_().endingEnd) {
  21322. case ZeroSlopeEnding:
  21323. // f'(tN) = 0
  21324. iNext = i1;
  21325. tNext = 2 * t1 - t0;
  21326. break;
  21327. case WrapAroundEnding:
  21328. // use the other end of the curve
  21329. iNext = 1;
  21330. tNext = t1 + pp[1] - pp[0];
  21331. break;
  21332. default:
  21333. // ZeroCurvatureEnding
  21334. // f''(tN) = 0, a.k.a. Natural Spline
  21335. iNext = i1 - 1;
  21336. tNext = t0;
  21337. }
  21338. }
  21339. var halfDt = (t1 - t0) * 0.5,
  21340. stride = this.valueSize;
  21341. this._weightPrev = halfDt / (t0 - tPrev);
  21342. this._weightNext = halfDt / (tNext - t1);
  21343. this._offsetPrev = iPrev * stride;
  21344. this._offsetNext = iNext * stride;
  21345. },
  21346. interpolate_: function interpolate_(i1, t0, t, t1) {
  21347. var result = this.resultBuffer,
  21348. values = this.sampleValues,
  21349. stride = this.valueSize,
  21350. o1 = i1 * stride,
  21351. o0 = o1 - stride,
  21352. oP = this._offsetPrev,
  21353. oN = this._offsetNext,
  21354. wP = this._weightPrev,
  21355. wN = this._weightNext,
  21356. p = (t - t0) / (t1 - t0),
  21357. pp = p * p,
  21358. ppp = pp * p; // evaluate polynomials
  21359. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  21360. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  21361. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  21362. var sN = wN * ppp - wN * pp; // combine data linearly
  21363. for (var i = 0; i !== stride; ++i) {
  21364. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  21365. }
  21366. return result;
  21367. }
  21368. });
  21369. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21370. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21371. }
  21372. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21373. constructor: LinearInterpolant,
  21374. interpolate_: function interpolate_(i1, t0, t, t1) {
  21375. var result = this.resultBuffer,
  21376. values = this.sampleValues,
  21377. stride = this.valueSize,
  21378. offset1 = i1 * stride,
  21379. offset0 = offset1 - stride,
  21380. weight1 = (t - t0) / (t1 - t0),
  21381. weight0 = 1 - weight1;
  21382. for (var i = 0; i !== stride; ++i) {
  21383. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  21384. }
  21385. return result;
  21386. }
  21387. });
  21388. /**
  21389. *
  21390. * Interpolant that evaluates to the sample value at the position preceeding
  21391. * the parameter.
  21392. */
  21393. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21394. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21395. }
  21396. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21397. constructor: DiscreteInterpolant,
  21398. interpolate_: function interpolate_(i1
  21399. /*, t0, t, t1 */
  21400. ) {
  21401. return this.copySampleValue_(i1 - 1);
  21402. }
  21403. });
  21404. function KeyframeTrack(name, times, values, interpolation) {
  21405. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  21406. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  21407. this.name = name;
  21408. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  21409. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  21410. this.setInterpolation(interpolation || this.DefaultInterpolation);
  21411. } // Static methods
  21412. Object.assign(KeyframeTrack, {
  21413. // Serialization (in static context, because of constructor invocation
  21414. // and automatic invocation of .toJSON):
  21415. toJSON: function toJSON(track) {
  21416. var trackType = track.constructor;
  21417. var json; // derived classes can define a static toJSON method
  21418. if (trackType.toJSON !== undefined) {
  21419. json = trackType.toJSON(track);
  21420. } else {
  21421. // by default, we assume the data can be serialized as-is
  21422. json = {
  21423. 'name': track.name,
  21424. 'times': AnimationUtils.convertArray(track.times, Array),
  21425. 'values': AnimationUtils.convertArray(track.values, Array)
  21426. };
  21427. var interpolation = track.getInterpolation();
  21428. if (interpolation !== track.DefaultInterpolation) {
  21429. json.interpolation = interpolation;
  21430. }
  21431. }
  21432. json.type = track.ValueTypeName; // mandatory
  21433. return json;
  21434. }
  21435. });
  21436. Object.assign(KeyframeTrack.prototype, {
  21437. constructor: KeyframeTrack,
  21438. TimeBufferType: Float32Array,
  21439. ValueBufferType: Float32Array,
  21440. DefaultInterpolation: InterpolateLinear,
  21441. InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
  21442. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  21443. },
  21444. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21445. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21446. },
  21447. InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
  21448. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  21449. },
  21450. setInterpolation: function setInterpolation(interpolation) {
  21451. var factoryMethod;
  21452. switch (interpolation) {
  21453. case InterpolateDiscrete:
  21454. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  21455. break;
  21456. case InterpolateLinear:
  21457. factoryMethod = this.InterpolantFactoryMethodLinear;
  21458. break;
  21459. case InterpolateSmooth:
  21460. factoryMethod = this.InterpolantFactoryMethodSmooth;
  21461. break;
  21462. }
  21463. if (factoryMethod === undefined) {
  21464. var message = 'unsupported interpolation for ' + this.ValueTypeName + ' keyframe track named ' + this.name;
  21465. if (this.createInterpolant === undefined) {
  21466. // fall back to default, unless the default itself is messed up
  21467. if (interpolation !== this.DefaultInterpolation) {
  21468. this.setInterpolation(this.DefaultInterpolation);
  21469. } else {
  21470. throw new Error(message); // fatal, in this case
  21471. }
  21472. }
  21473. console.warn('THREE.KeyframeTrack:', message);
  21474. return this;
  21475. }
  21476. this.createInterpolant = factoryMethod;
  21477. return this;
  21478. },
  21479. getInterpolation: function getInterpolation() {
  21480. switch (this.createInterpolant) {
  21481. case this.InterpolantFactoryMethodDiscrete:
  21482. return InterpolateDiscrete;
  21483. case this.InterpolantFactoryMethodLinear:
  21484. return InterpolateLinear;
  21485. case this.InterpolantFactoryMethodSmooth:
  21486. return InterpolateSmooth;
  21487. }
  21488. },
  21489. getValueSize: function getValueSize() {
  21490. return this.values.length / this.times.length;
  21491. },
  21492. // move all keyframes either forwards or backwards in time
  21493. shift: function shift(timeOffset) {
  21494. if (timeOffset !== 0.0) {
  21495. var times = this.times;
  21496. for (var i = 0, n = times.length; i !== n; ++i) {
  21497. times[i] += timeOffset;
  21498. }
  21499. }
  21500. return this;
  21501. },
  21502. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21503. scale: function scale(timeScale) {
  21504. if (timeScale !== 1.0) {
  21505. var times = this.times;
  21506. for (var i = 0, n = times.length; i !== n; ++i) {
  21507. times[i] *= timeScale;
  21508. }
  21509. }
  21510. return this;
  21511. },
  21512. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21513. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21514. trim: function trim(startTime, endTime) {
  21515. var times = this.times,
  21516. nKeys = times.length;
  21517. var from = 0,
  21518. to = nKeys - 1;
  21519. while (from !== nKeys && times[from] < startTime) {
  21520. ++from;
  21521. }
  21522. while (to !== -1 && times[to] > endTime) {
  21523. --to;
  21524. }
  21525. ++to; // inclusive -> exclusive bound
  21526. if (from !== 0 || to !== nKeys) {
  21527. // empty tracks are forbidden, so keep at least one keyframe
  21528. if (from >= to) {
  21529. to = Math.max(to, 1);
  21530. from = to - 1;
  21531. }
  21532. var stride = this.getValueSize();
  21533. this.times = AnimationUtils.arraySlice(times, from, to);
  21534. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  21535. }
  21536. return this;
  21537. },
  21538. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21539. validate: function validate() {
  21540. var valid = true;
  21541. var valueSize = this.getValueSize();
  21542. if (valueSize - Math.floor(valueSize) !== 0) {
  21543. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  21544. valid = false;
  21545. }
  21546. var times = this.times,
  21547. values = this.values,
  21548. nKeys = times.length;
  21549. if (nKeys === 0) {
  21550. console.error('THREE.KeyframeTrack: Track is empty.', this);
  21551. valid = false;
  21552. }
  21553. var prevTime = null;
  21554. for (var i = 0; i !== nKeys; i++) {
  21555. var currTime = times[i];
  21556. if (typeof currTime === 'number' && isNaN(currTime)) {
  21557. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  21558. valid = false;
  21559. break;
  21560. }
  21561. if (prevTime !== null && prevTime > currTime) {
  21562. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  21563. valid = false;
  21564. break;
  21565. }
  21566. prevTime = currTime;
  21567. }
  21568. if (values !== undefined) {
  21569. if (AnimationUtils.isTypedArray(values)) {
  21570. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  21571. var value = values[_i];
  21572. if (isNaN(value)) {
  21573. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  21574. valid = false;
  21575. break;
  21576. }
  21577. }
  21578. }
  21579. }
  21580. return valid;
  21581. },
  21582. // removes equivalent sequential keys as common in morph target sequences
  21583. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21584. optimize: function optimize() {
  21585. // times or values may be shared with other tracks, so overwriting is unsafe
  21586. var times = AnimationUtils.arraySlice(this.times),
  21587. values = AnimationUtils.arraySlice(this.values),
  21588. stride = this.getValueSize(),
  21589. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21590. lastIndex = times.length - 1;
  21591. var writeIndex = 1;
  21592. for (var i = 1; i < lastIndex; ++i) {
  21593. var keep = false;
  21594. var time = times[i];
  21595. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  21596. if (time !== timeNext && (i !== 1 || time !== time[0])) {
  21597. if (!smoothInterpolation) {
  21598. // remove unnecessary keyframes same as their neighbors
  21599. var offset = i * stride,
  21600. offsetP = offset - stride,
  21601. offsetN = offset + stride;
  21602. for (var j = 0; j !== stride; ++j) {
  21603. var value = values[offset + j];
  21604. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  21605. keep = true;
  21606. break;
  21607. }
  21608. }
  21609. } else {
  21610. keep = true;
  21611. }
  21612. } // in-place compaction
  21613. if (keep) {
  21614. if (i !== writeIndex) {
  21615. times[writeIndex] = times[i];
  21616. var readOffset = i * stride,
  21617. writeOffset = writeIndex * stride;
  21618. for (var _j = 0; _j !== stride; ++_j) {
  21619. values[writeOffset + _j] = values[readOffset + _j];
  21620. }
  21621. }
  21622. ++writeIndex;
  21623. }
  21624. } // flush last keyframe (compaction looks ahead)
  21625. if (lastIndex > 0) {
  21626. times[writeIndex] = times[lastIndex];
  21627. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  21628. values[_writeOffset + _j2] = values[_readOffset + _j2];
  21629. }
  21630. ++writeIndex;
  21631. }
  21632. if (writeIndex !== times.length) {
  21633. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  21634. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  21635. } else {
  21636. this.times = times;
  21637. this.values = values;
  21638. }
  21639. return this;
  21640. },
  21641. clone: function clone() {
  21642. var times = AnimationUtils.arraySlice(this.times, 0);
  21643. var values = AnimationUtils.arraySlice(this.values, 0);
  21644. var TypedKeyframeTrack = this.constructor;
  21645. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21646. track.createInterpolant = this.createInterpolant;
  21647. return track;
  21648. }
  21649. });
  21650. /**
  21651. * A Track of Boolean keyframe values.
  21652. */
  21653. function BooleanKeyframeTrack(name, times, values) {
  21654. KeyframeTrack.call(this, name, times, values);
  21655. }
  21656. BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21657. constructor: BooleanKeyframeTrack,
  21658. ValueTypeName: 'bool',
  21659. ValueBufferType: Array,
  21660. DefaultInterpolation: InterpolateDiscrete,
  21661. InterpolantFactoryMethodLinear: undefined,
  21662. InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
  21663. // representation of a single value and a custom interpolant that
  21664. // computes "firstValue ^ isOdd( index )".
  21665. });
  21666. /**
  21667. * A Track of keyframe values that represent color.
  21668. */
  21669. function ColorKeyframeTrack(name, times, values, interpolation) {
  21670. KeyframeTrack.call(this, name, times, values, interpolation);
  21671. }
  21672. ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21673. constructor: ColorKeyframeTrack,
  21674. ValueTypeName: 'color' // ValueBufferType is inherited
  21675. // DefaultInterpolation is inherited
  21676. // Note: Very basic implementation and nothing special yet.
  21677. // However, this is the place for color space parameterization.
  21678. });
  21679. /**
  21680. * A Track of numeric keyframe values.
  21681. */
  21682. function NumberKeyframeTrack(name, times, values, interpolation) {
  21683. KeyframeTrack.call(this, name, times, values, interpolation);
  21684. }
  21685. NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21686. constructor: NumberKeyframeTrack,
  21687. ValueTypeName: 'number' // ValueBufferType is inherited
  21688. // DefaultInterpolation is inherited
  21689. });
  21690. /**
  21691. * Spherical linear unit quaternion interpolant.
  21692. */
  21693. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21694. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21695. }
  21696. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21697. constructor: QuaternionLinearInterpolant,
  21698. interpolate_: function interpolate_(i1, t0, t, t1) {
  21699. var result = this.resultBuffer,
  21700. values = this.sampleValues,
  21701. stride = this.valueSize,
  21702. alpha = (t - t0) / (t1 - t0);
  21703. var offset = i1 * stride;
  21704. for (var end = offset + stride; offset !== end; offset += 4) {
  21705. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21706. }
  21707. return result;
  21708. }
  21709. });
  21710. /**
  21711. * A Track of quaternion keyframe values.
  21712. */
  21713. function QuaternionKeyframeTrack(name, times, values, interpolation) {
  21714. KeyframeTrack.call(this, name, times, values, interpolation);
  21715. }
  21716. QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21717. constructor: QuaternionKeyframeTrack,
  21718. ValueTypeName: 'quaternion',
  21719. // ValueBufferType is inherited
  21720. DefaultInterpolation: InterpolateLinear,
  21721. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21722. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21723. },
  21724. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21725. });
  21726. /**
  21727. * A Track that interpolates Strings
  21728. */
  21729. function StringKeyframeTrack(name, times, values, interpolation) {
  21730. KeyframeTrack.call(this, name, times, values, interpolation);
  21731. }
  21732. StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21733. constructor: StringKeyframeTrack,
  21734. ValueTypeName: 'string',
  21735. ValueBufferType: Array,
  21736. DefaultInterpolation: InterpolateDiscrete,
  21737. InterpolantFactoryMethodLinear: undefined,
  21738. InterpolantFactoryMethodSmooth: undefined
  21739. });
  21740. /**
  21741. * A Track of vectored keyframe values.
  21742. */
  21743. function VectorKeyframeTrack(name, times, values, interpolation) {
  21744. KeyframeTrack.call(this, name, times, values, interpolation);
  21745. }
  21746. VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21747. constructor: VectorKeyframeTrack,
  21748. ValueTypeName: 'vector' // ValueBufferType is inherited
  21749. // DefaultInterpolation is inherited
  21750. });
  21751. function AnimationClip(name, duration, tracks, blendMode) {
  21752. this.name = name;
  21753. this.tracks = tracks;
  21754. this.duration = duration !== undefined ? duration : -1;
  21755. this.blendMode = blendMode !== undefined ? blendMode : NormalAnimationBlendMode;
  21756. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21757. if (this.duration < 0) {
  21758. this.resetDuration();
  21759. }
  21760. }
  21761. function getTrackTypeForValueTypeName(typeName) {
  21762. switch (typeName.toLowerCase()) {
  21763. case 'scalar':
  21764. case 'double':
  21765. case 'float':
  21766. case 'number':
  21767. case 'integer':
  21768. return NumberKeyframeTrack;
  21769. case 'vector':
  21770. case 'vector2':
  21771. case 'vector3':
  21772. case 'vector4':
  21773. return VectorKeyframeTrack;
  21774. case 'color':
  21775. return ColorKeyframeTrack;
  21776. case 'quaternion':
  21777. return QuaternionKeyframeTrack;
  21778. case 'bool':
  21779. case 'boolean':
  21780. return BooleanKeyframeTrack;
  21781. case 'string':
  21782. return StringKeyframeTrack;
  21783. }
  21784. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21785. }
  21786. function parseKeyframeTrack(json) {
  21787. if (json.type === undefined) {
  21788. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21789. }
  21790. var trackType = getTrackTypeForValueTypeName(json.type);
  21791. if (json.times === undefined) {
  21792. var times = [],
  21793. values = [];
  21794. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21795. json.times = times;
  21796. json.values = values;
  21797. } // derived classes can define a static parse method
  21798. if (trackType.parse !== undefined) {
  21799. return trackType.parse(json);
  21800. } else {
  21801. // by default, we assume a constructor compatible with the base
  21802. return new trackType(json.name, json.times, json.values, json.interpolation);
  21803. }
  21804. }
  21805. Object.assign(AnimationClip, {
  21806. parse: function parse(json) {
  21807. var tracks = [],
  21808. jsonTracks = json.tracks,
  21809. frameTime = 1.0 / (json.fps || 1.0);
  21810. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21811. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21812. }
  21813. var clip = new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21814. clip.uuid = json.uuid;
  21815. return clip;
  21816. },
  21817. toJSON: function toJSON(clip) {
  21818. var tracks = [],
  21819. clipTracks = clip.tracks;
  21820. var json = {
  21821. 'name': clip.name,
  21822. 'duration': clip.duration,
  21823. 'tracks': tracks,
  21824. 'uuid': clip.uuid,
  21825. 'blendMode': clip.blendMode
  21826. };
  21827. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21828. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21829. }
  21830. return json;
  21831. },
  21832. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21833. var numMorphTargets = morphTargetSequence.length;
  21834. var tracks = [];
  21835. for (var i = 0; i < numMorphTargets; i++) {
  21836. var times = [];
  21837. var values = [];
  21838. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21839. values.push(0, 1, 0);
  21840. var order = AnimationUtils.getKeyframeOrder(times);
  21841. times = AnimationUtils.sortedArray(times, 1, order);
  21842. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21843. // last frame as well for perfect loop.
  21844. if (!noLoop && times[0] === 0) {
  21845. times.push(numMorphTargets);
  21846. values.push(values[0]);
  21847. }
  21848. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21849. }
  21850. return new AnimationClip(name, -1, tracks);
  21851. },
  21852. findByName: function findByName(objectOrClipArray, name) {
  21853. var clipArray = objectOrClipArray;
  21854. if (!Array.isArray(objectOrClipArray)) {
  21855. var o = objectOrClipArray;
  21856. clipArray = o.geometry && o.geometry.animations || o.animations;
  21857. }
  21858. for (var i = 0; i < clipArray.length; i++) {
  21859. if (clipArray[i].name === name) {
  21860. return clipArray[i];
  21861. }
  21862. }
  21863. return null;
  21864. },
  21865. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21866. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21867. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21868. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21869. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21870. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21871. var morphTarget = morphTargets[i];
  21872. var parts = morphTarget.name.match(pattern);
  21873. if (parts && parts.length > 1) {
  21874. var name = parts[1];
  21875. var animationMorphTargets = animationToMorphTargets[name];
  21876. if (!animationMorphTargets) {
  21877. animationToMorphTargets[name] = animationMorphTargets = [];
  21878. }
  21879. animationMorphTargets.push(morphTarget);
  21880. }
  21881. }
  21882. var clips = [];
  21883. for (var _name in animationToMorphTargets) {
  21884. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21885. }
  21886. return clips;
  21887. },
  21888. // parse the animation.hierarchy format
  21889. parseAnimation: function parseAnimation(animation, bones) {
  21890. if (!animation) {
  21891. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21892. return null;
  21893. }
  21894. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21895. // only return track if there are actually keys.
  21896. if (animationKeys.length !== 0) {
  21897. var times = [];
  21898. var values = [];
  21899. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21900. if (times.length !== 0) {
  21901. destTracks.push(new trackType(trackName, times, values));
  21902. }
  21903. }
  21904. };
  21905. var tracks = [];
  21906. var clipName = animation.name || 'default';
  21907. var fps = animation.fps || 30;
  21908. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21909. var duration = animation.length || -1;
  21910. var hierarchyTracks = animation.hierarchy || [];
  21911. for (var h = 0; h < hierarchyTracks.length; h++) {
  21912. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21913. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21914. if (animationKeys[0].morphTargets) {
  21915. // figure out all morph targets used in this track
  21916. var morphTargetNames = {};
  21917. var k = void 0;
  21918. for (k = 0; k < animationKeys.length; k++) {
  21919. if (animationKeys[k].morphTargets) {
  21920. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21921. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21922. }
  21923. }
  21924. } // create a track for each morph target with all zero
  21925. // morphTargetInfluences except for the keys in which
  21926. // the morphTarget is named.
  21927. for (var morphTargetName in morphTargetNames) {
  21928. var times = [];
  21929. var values = [];
  21930. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21931. var animationKey = animationKeys[k];
  21932. times.push(animationKey.time);
  21933. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21934. }
  21935. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21936. }
  21937. duration = morphTargetNames.length * (fps || 1.0);
  21938. } else {
  21939. // ...assume skeletal animation
  21940. var boneName = '.bones[' + bones[h].name + ']';
  21941. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21942. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21943. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21944. }
  21945. }
  21946. if (tracks.length === 0) {
  21947. return null;
  21948. }
  21949. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21950. return clip;
  21951. }
  21952. });
  21953. Object.assign(AnimationClip.prototype, {
  21954. resetDuration: function resetDuration() {
  21955. var tracks = this.tracks;
  21956. var duration = 0;
  21957. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21958. var track = this.tracks[i];
  21959. duration = Math.max(duration, track.times[track.times.length - 1]);
  21960. }
  21961. this.duration = duration;
  21962. return this;
  21963. },
  21964. trim: function trim() {
  21965. for (var i = 0; i < this.tracks.length; i++) {
  21966. this.tracks[i].trim(0, this.duration);
  21967. }
  21968. return this;
  21969. },
  21970. validate: function validate() {
  21971. var valid = true;
  21972. for (var i = 0; i < this.tracks.length; i++) {
  21973. valid = valid && this.tracks[i].validate();
  21974. }
  21975. return valid;
  21976. },
  21977. optimize: function optimize() {
  21978. for (var i = 0; i < this.tracks.length; i++) {
  21979. this.tracks[i].optimize();
  21980. }
  21981. return this;
  21982. },
  21983. clone: function clone() {
  21984. var tracks = [];
  21985. for (var i = 0; i < this.tracks.length; i++) {
  21986. tracks.push(this.tracks[i].clone());
  21987. }
  21988. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  21989. },
  21990. toJSON: function toJSON() {
  21991. return AnimationClip.toJSON(this);
  21992. }
  21993. });
  21994. var Cache = {
  21995. enabled: false,
  21996. files: {},
  21997. add: function add(key, file) {
  21998. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  21999. this.files[key] = file;
  22000. },
  22001. get: function get(key) {
  22002. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  22003. return this.files[key];
  22004. },
  22005. remove: function remove(key) {
  22006. delete this.files[key];
  22007. },
  22008. clear: function clear() {
  22009. this.files = {};
  22010. }
  22011. };
  22012. function LoadingManager(onLoad, onProgress, onError) {
  22013. var scope = this;
  22014. var isLoading = false;
  22015. var itemsLoaded = 0;
  22016. var itemsTotal = 0;
  22017. var urlModifier = undefined;
  22018. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  22019. // in the constructor
  22020. this.onStart = undefined;
  22021. this.onLoad = onLoad;
  22022. this.onProgress = onProgress;
  22023. this.onError = onError;
  22024. this.itemStart = function (url) {
  22025. itemsTotal++;
  22026. if (isLoading === false) {
  22027. if (scope.onStart !== undefined) {
  22028. scope.onStart(url, itemsLoaded, itemsTotal);
  22029. }
  22030. }
  22031. isLoading = true;
  22032. };
  22033. this.itemEnd = function (url) {
  22034. itemsLoaded++;
  22035. if (scope.onProgress !== undefined) {
  22036. scope.onProgress(url, itemsLoaded, itemsTotal);
  22037. }
  22038. if (itemsLoaded === itemsTotal) {
  22039. isLoading = false;
  22040. if (scope.onLoad !== undefined) {
  22041. scope.onLoad();
  22042. }
  22043. }
  22044. };
  22045. this.itemError = function (url) {
  22046. if (scope.onError !== undefined) {
  22047. scope.onError(url);
  22048. }
  22049. };
  22050. this.resolveURL = function (url) {
  22051. if (urlModifier) {
  22052. return urlModifier(url);
  22053. }
  22054. return url;
  22055. };
  22056. this.setURLModifier = function (transform) {
  22057. urlModifier = transform;
  22058. return this;
  22059. };
  22060. this.addHandler = function (regex, loader) {
  22061. handlers.push(regex, loader);
  22062. return this;
  22063. };
  22064. this.removeHandler = function (regex) {
  22065. var index = handlers.indexOf(regex);
  22066. if (index !== -1) {
  22067. handlers.splice(index, 2);
  22068. }
  22069. return this;
  22070. };
  22071. this.getHandler = function (file) {
  22072. for (var i = 0, l = handlers.length; i < l; i += 2) {
  22073. var regex = handlers[i];
  22074. var loader = handlers[i + 1];
  22075. if (regex.global) regex.lastIndex = 0; // see #17920
  22076. if (regex.test(file)) {
  22077. return loader;
  22078. }
  22079. }
  22080. return null;
  22081. };
  22082. }
  22083. var DefaultLoadingManager = new LoadingManager();
  22084. function Loader(manager) {
  22085. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  22086. this.crossOrigin = 'anonymous';
  22087. this.withCredentials = false;
  22088. this.path = '';
  22089. this.resourcePath = '';
  22090. this.requestHeader = {};
  22091. }
  22092. Object.assign(Loader.prototype, {
  22093. load: function load()
  22094. /* url, onLoad, onProgress, onError */
  22095. {},
  22096. loadAsync: function loadAsync(url, onProgress) {
  22097. var scope = this;
  22098. return new Promise(function (resolve, reject) {
  22099. scope.load(url, resolve, onProgress, reject);
  22100. });
  22101. },
  22102. parse: function parse()
  22103. /* data */
  22104. {},
  22105. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  22106. this.crossOrigin = crossOrigin;
  22107. return this;
  22108. },
  22109. setWithCredentials: function setWithCredentials(value) {
  22110. this.withCredentials = value;
  22111. return this;
  22112. },
  22113. setPath: function setPath(path) {
  22114. this.path = path;
  22115. return this;
  22116. },
  22117. setResourcePath: function setResourcePath(resourcePath) {
  22118. this.resourcePath = resourcePath;
  22119. return this;
  22120. },
  22121. setRequestHeader: function setRequestHeader(requestHeader) {
  22122. this.requestHeader = requestHeader;
  22123. return this;
  22124. }
  22125. });
  22126. var loading = {};
  22127. function FileLoader(manager) {
  22128. Loader.call(this, manager);
  22129. }
  22130. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22131. constructor: FileLoader,
  22132. load: function load(url, onLoad, onProgress, onError) {
  22133. if (url === undefined) url = '';
  22134. if (this.path !== undefined) url = this.path + url;
  22135. url = this.manager.resolveURL(url);
  22136. var scope = this;
  22137. var cached = Cache.get(url);
  22138. if (cached !== undefined) {
  22139. scope.manager.itemStart(url);
  22140. setTimeout(function () {
  22141. if (onLoad) onLoad(cached);
  22142. scope.manager.itemEnd(url);
  22143. }, 0);
  22144. return cached;
  22145. } // Check if request is duplicate
  22146. if (loading[url] !== undefined) {
  22147. loading[url].push({
  22148. onLoad: onLoad,
  22149. onProgress: onProgress,
  22150. onError: onError
  22151. });
  22152. return;
  22153. } // Check for data: URI
  22154. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  22155. var dataUriRegexResult = url.match(dataUriRegex);
  22156. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  22157. if (dataUriRegexResult) {
  22158. var mimeType = dataUriRegexResult[1];
  22159. var isBase64 = !!dataUriRegexResult[2];
  22160. var data = dataUriRegexResult[3];
  22161. data = decodeURIComponent(data);
  22162. if (isBase64) data = atob(data);
  22163. try {
  22164. var response;
  22165. var responseType = (this.responseType || '').toLowerCase();
  22166. switch (responseType) {
  22167. case 'arraybuffer':
  22168. case 'blob':
  22169. var view = new Uint8Array(data.length);
  22170. for (var i = 0; i < data.length; i++) {
  22171. view[i] = data.charCodeAt(i);
  22172. }
  22173. if (responseType === 'blob') {
  22174. response = new Blob([view.buffer], {
  22175. type: mimeType
  22176. });
  22177. } else {
  22178. response = view.buffer;
  22179. }
  22180. break;
  22181. case 'document':
  22182. var parser = new DOMParser();
  22183. response = parser.parseFromString(data, mimeType);
  22184. break;
  22185. case 'json':
  22186. response = JSON.parse(data);
  22187. break;
  22188. default:
  22189. // 'text' or other
  22190. response = data;
  22191. break;
  22192. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  22193. setTimeout(function () {
  22194. if (onLoad) onLoad(response);
  22195. scope.manager.itemEnd(url);
  22196. }, 0);
  22197. } catch (error) {
  22198. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  22199. setTimeout(function () {
  22200. if (onError) onError(error);
  22201. scope.manager.itemError(url);
  22202. scope.manager.itemEnd(url);
  22203. }, 0);
  22204. }
  22205. } else {
  22206. // Initialise array for duplicate requests
  22207. loading[url] = [];
  22208. loading[url].push({
  22209. onLoad: onLoad,
  22210. onProgress: onProgress,
  22211. onError: onError
  22212. });
  22213. request = new XMLHttpRequest();
  22214. request.open('GET', url, true);
  22215. request.addEventListener('load', function (event) {
  22216. var response = this.response;
  22217. var callbacks = loading[url];
  22218. delete loading[url];
  22219. if (this.status === 200 || this.status === 0) {
  22220. // Some browsers return HTTP Status 0 when using non-http protocol
  22221. // e.g. 'file://' or 'data://'. Handle as success.
  22222. 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
  22223. // error response bodies as proper responses to requests.
  22224. Cache.add(url, response);
  22225. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  22226. var callback = callbacks[_i];
  22227. if (callback.onLoad) callback.onLoad(response);
  22228. }
  22229. scope.manager.itemEnd(url);
  22230. } else {
  22231. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  22232. var _callback = callbacks[_i2];
  22233. if (_callback.onError) _callback.onError(event);
  22234. }
  22235. scope.manager.itemError(url);
  22236. scope.manager.itemEnd(url);
  22237. }
  22238. }, false);
  22239. request.addEventListener('progress', function (event) {
  22240. var callbacks = loading[url];
  22241. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  22242. var callback = callbacks[_i3];
  22243. if (callback.onProgress) callback.onProgress(event);
  22244. }
  22245. }, false);
  22246. request.addEventListener('error', function (event) {
  22247. var callbacks = loading[url];
  22248. delete loading[url];
  22249. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  22250. var callback = callbacks[_i4];
  22251. if (callback.onError) callback.onError(event);
  22252. }
  22253. scope.manager.itemError(url);
  22254. scope.manager.itemEnd(url);
  22255. }, false);
  22256. request.addEventListener('abort', function (event) {
  22257. var callbacks = loading[url];
  22258. delete loading[url];
  22259. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  22260. var callback = callbacks[_i5];
  22261. if (callback.onError) callback.onError(event);
  22262. }
  22263. scope.manager.itemError(url);
  22264. scope.manager.itemEnd(url);
  22265. }, false);
  22266. if (this.responseType !== undefined) request.responseType = this.responseType;
  22267. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  22268. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  22269. for (var header in this.requestHeader) {
  22270. request.setRequestHeader(header, this.requestHeader[header]);
  22271. }
  22272. request.send(null);
  22273. }
  22274. scope.manager.itemStart(url);
  22275. return request;
  22276. },
  22277. setResponseType: function setResponseType(value) {
  22278. this.responseType = value;
  22279. return this;
  22280. },
  22281. setMimeType: function setMimeType(value) {
  22282. this.mimeType = value;
  22283. return this;
  22284. }
  22285. });
  22286. function AnimationLoader(manager) {
  22287. Loader.call(this, manager);
  22288. }
  22289. AnimationLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22290. constructor: AnimationLoader,
  22291. load: function load(url, onLoad, onProgress, onError) {
  22292. var scope = this;
  22293. var loader = new FileLoader(scope.manager);
  22294. loader.setPath(scope.path);
  22295. loader.setRequestHeader(scope.requestHeader);
  22296. loader.setWithCredentials(scope.withCredentials);
  22297. loader.load(url, function (text) {
  22298. try {
  22299. onLoad(scope.parse(JSON.parse(text)));
  22300. } catch (e) {
  22301. if (onError) {
  22302. onError(e);
  22303. } else {
  22304. console.error(e);
  22305. }
  22306. scope.manager.itemError(url);
  22307. }
  22308. }, onProgress, onError);
  22309. },
  22310. parse: function parse(json) {
  22311. var animations = [];
  22312. for (var i = 0; i < json.length; i++) {
  22313. var clip = AnimationClip.parse(json[i]);
  22314. animations.push(clip);
  22315. }
  22316. return animations;
  22317. }
  22318. });
  22319. /**
  22320. * Abstract Base class to block based textures loader (dds, pvr, ...)
  22321. *
  22322. * Sub classes have to implement the parse() method which will be used in load().
  22323. */
  22324. function CompressedTextureLoader(manager) {
  22325. Loader.call(this, manager);
  22326. }
  22327. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22328. constructor: CompressedTextureLoader,
  22329. load: function load(url, onLoad, onProgress, onError) {
  22330. var scope = this;
  22331. var images = [];
  22332. var texture = new CompressedTexture();
  22333. var loader = new FileLoader(this.manager);
  22334. loader.setPath(this.path);
  22335. loader.setResponseType('arraybuffer');
  22336. loader.setRequestHeader(this.requestHeader);
  22337. loader.setWithCredentials(scope.withCredentials);
  22338. var loaded = 0;
  22339. function loadTexture(i) {
  22340. loader.load(url[i], function (buffer) {
  22341. var texDatas = scope.parse(buffer, true);
  22342. images[i] = {
  22343. width: texDatas.width,
  22344. height: texDatas.height,
  22345. format: texDatas.format,
  22346. mipmaps: texDatas.mipmaps
  22347. };
  22348. loaded += 1;
  22349. if (loaded === 6) {
  22350. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  22351. texture.image = images;
  22352. texture.format = texDatas.format;
  22353. texture.needsUpdate = true;
  22354. if (onLoad) onLoad(texture);
  22355. }
  22356. }, onProgress, onError);
  22357. }
  22358. if (Array.isArray(url)) {
  22359. for (var i = 0, il = url.length; i < il; ++i) {
  22360. loadTexture(i);
  22361. }
  22362. } else {
  22363. // compressed cubemap texture stored in a single DDS file
  22364. loader.load(url, function (buffer) {
  22365. var texDatas = scope.parse(buffer, true);
  22366. if (texDatas.isCubemap) {
  22367. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  22368. for (var f = 0; f < faces; f++) {
  22369. images[f] = {
  22370. mipmaps: []
  22371. };
  22372. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  22373. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  22374. images[f].format = texDatas.format;
  22375. images[f].width = texDatas.width;
  22376. images[f].height = texDatas.height;
  22377. }
  22378. }
  22379. texture.image = images;
  22380. } else {
  22381. texture.image.width = texDatas.width;
  22382. texture.image.height = texDatas.height;
  22383. texture.mipmaps = texDatas.mipmaps;
  22384. }
  22385. if (texDatas.mipmapCount === 1) {
  22386. texture.minFilter = LinearFilter;
  22387. }
  22388. texture.format = texDatas.format;
  22389. texture.needsUpdate = true;
  22390. if (onLoad) onLoad(texture);
  22391. }, onProgress, onError);
  22392. }
  22393. return texture;
  22394. }
  22395. });
  22396. function ImageLoader(manager) {
  22397. Loader.call(this, manager);
  22398. }
  22399. ImageLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22400. constructor: ImageLoader,
  22401. load: function load(url, onLoad, onProgress, onError) {
  22402. if (this.path !== undefined) url = this.path + url;
  22403. url = this.manager.resolveURL(url);
  22404. var scope = this;
  22405. var cached = Cache.get(url);
  22406. if (cached !== undefined) {
  22407. scope.manager.itemStart(url);
  22408. setTimeout(function () {
  22409. if (onLoad) onLoad(cached);
  22410. scope.manager.itemEnd(url);
  22411. }, 0);
  22412. return cached;
  22413. }
  22414. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  22415. function onImageLoad() {
  22416. image.removeEventListener('load', onImageLoad, false);
  22417. image.removeEventListener('error', onImageError, false);
  22418. Cache.add(url, this);
  22419. if (onLoad) onLoad(this);
  22420. scope.manager.itemEnd(url);
  22421. }
  22422. function onImageError(event) {
  22423. image.removeEventListener('load', onImageLoad, false);
  22424. image.removeEventListener('error', onImageError, false);
  22425. if (onError) onError(event);
  22426. scope.manager.itemError(url);
  22427. scope.manager.itemEnd(url);
  22428. }
  22429. image.addEventListener('load', onImageLoad, false);
  22430. image.addEventListener('error', onImageError, false);
  22431. if (url.substr(0, 5) !== 'data:') {
  22432. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  22433. }
  22434. scope.manager.itemStart(url);
  22435. image.src = url;
  22436. return image;
  22437. }
  22438. });
  22439. function CubeTextureLoader(manager) {
  22440. Loader.call(this, manager);
  22441. }
  22442. CubeTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22443. constructor: CubeTextureLoader,
  22444. load: function load(urls, onLoad, onProgress, onError) {
  22445. var texture = new CubeTexture();
  22446. var loader = new ImageLoader(this.manager);
  22447. loader.setCrossOrigin(this.crossOrigin);
  22448. loader.setPath(this.path);
  22449. var loaded = 0;
  22450. function loadTexture(i) {
  22451. loader.load(urls[i], function (image) {
  22452. texture.images[i] = image;
  22453. loaded++;
  22454. if (loaded === 6) {
  22455. texture.needsUpdate = true;
  22456. if (onLoad) onLoad(texture);
  22457. }
  22458. }, undefined, onError);
  22459. }
  22460. for (var i = 0; i < urls.length; ++i) {
  22461. loadTexture(i);
  22462. }
  22463. return texture;
  22464. }
  22465. });
  22466. /**
  22467. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  22468. *
  22469. * Sub classes have to implement the parse() method which will be used in load().
  22470. */
  22471. function DataTextureLoader(manager) {
  22472. Loader.call(this, manager);
  22473. }
  22474. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22475. constructor: DataTextureLoader,
  22476. load: function load(url, onLoad, onProgress, onError) {
  22477. var scope = this;
  22478. var texture = new DataTexture();
  22479. var loader = new FileLoader(this.manager);
  22480. loader.setResponseType('arraybuffer');
  22481. loader.setRequestHeader(this.requestHeader);
  22482. loader.setPath(this.path);
  22483. loader.setWithCredentials(scope.withCredentials);
  22484. loader.load(url, function (buffer) {
  22485. var texData = scope.parse(buffer);
  22486. if (!texData) return;
  22487. if (texData.image !== undefined) {
  22488. texture.image = texData.image;
  22489. } else if (texData.data !== undefined) {
  22490. texture.image.width = texData.width;
  22491. texture.image.height = texData.height;
  22492. texture.image.data = texData.data;
  22493. }
  22494. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  22495. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  22496. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  22497. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  22498. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  22499. if (texData.format !== undefined) {
  22500. texture.format = texData.format;
  22501. }
  22502. if (texData.type !== undefined) {
  22503. texture.type = texData.type;
  22504. }
  22505. if (texData.mipmaps !== undefined) {
  22506. texture.mipmaps = texData.mipmaps;
  22507. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  22508. }
  22509. if (texData.mipmapCount === 1) {
  22510. texture.minFilter = LinearFilter;
  22511. }
  22512. texture.needsUpdate = true;
  22513. if (onLoad) onLoad(texture, texData);
  22514. }, onProgress, onError);
  22515. return texture;
  22516. }
  22517. });
  22518. function TextureLoader(manager) {
  22519. Loader.call(this, manager);
  22520. }
  22521. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22522. constructor: TextureLoader,
  22523. load: function load(url, onLoad, onProgress, onError) {
  22524. var texture = new Texture();
  22525. var loader = new ImageLoader(this.manager);
  22526. loader.setCrossOrigin(this.crossOrigin);
  22527. loader.setPath(this.path);
  22528. loader.load(url, function (image) {
  22529. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  22530. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  22531. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  22532. texture.needsUpdate = true;
  22533. if (onLoad !== undefined) {
  22534. onLoad(texture);
  22535. }
  22536. }, onProgress, onError);
  22537. return texture;
  22538. }
  22539. });
  22540. /**
  22541. * Extensible curve object.
  22542. *
  22543. * Some common of curve methods:
  22544. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  22545. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  22546. * .getPoints(), .getSpacedPoints()
  22547. * .getLength()
  22548. * .updateArcLengths()
  22549. *
  22550. * This following curves inherit from THREE.Curve:
  22551. *
  22552. * -- 2D curves --
  22553. * THREE.ArcCurve
  22554. * THREE.CubicBezierCurve
  22555. * THREE.EllipseCurve
  22556. * THREE.LineCurve
  22557. * THREE.QuadraticBezierCurve
  22558. * THREE.SplineCurve
  22559. *
  22560. * -- 3D curves --
  22561. * THREE.CatmullRomCurve3
  22562. * THREE.CubicBezierCurve3
  22563. * THREE.LineCurve3
  22564. * THREE.QuadraticBezierCurve3
  22565. *
  22566. * A series of curves can be represented as a THREE.CurvePath.
  22567. *
  22568. **/
  22569. function Curve() {
  22570. this.type = 'Curve';
  22571. this.arcLengthDivisions = 200;
  22572. }
  22573. Object.assign(Curve.prototype, {
  22574. // Virtual base class method to overwrite and implement in subclasses
  22575. // - t [0 .. 1]
  22576. getPoint: function getPoint()
  22577. /* t, optionalTarget */
  22578. {
  22579. console.warn('THREE.Curve: .getPoint() not implemented.');
  22580. return null;
  22581. },
  22582. // Get point at relative position in curve according to arc length
  22583. // - u [0 .. 1]
  22584. getPointAt: function getPointAt(u, optionalTarget) {
  22585. var t = this.getUtoTmapping(u);
  22586. return this.getPoint(t, optionalTarget);
  22587. },
  22588. // Get sequence of points using getPoint( t )
  22589. getPoints: function getPoints(divisions) {
  22590. if (divisions === void 0) {
  22591. divisions = 5;
  22592. }
  22593. var points = [];
  22594. for (var d = 0; d <= divisions; d++) {
  22595. points.push(this.getPoint(d / divisions));
  22596. }
  22597. return points;
  22598. },
  22599. // Get sequence of points using getPointAt( u )
  22600. getSpacedPoints: function getSpacedPoints(divisions) {
  22601. if (divisions === void 0) {
  22602. divisions = 5;
  22603. }
  22604. var points = [];
  22605. for (var d = 0; d <= divisions; d++) {
  22606. points.push(this.getPointAt(d / divisions));
  22607. }
  22608. return points;
  22609. },
  22610. // Get total curve arc length
  22611. getLength: function getLength() {
  22612. var lengths = this.getLengths();
  22613. return lengths[lengths.length - 1];
  22614. },
  22615. // Get list of cumulative segment lengths
  22616. getLengths: function getLengths(divisions) {
  22617. if (divisions === undefined) divisions = this.arcLengthDivisions;
  22618. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  22619. return this.cacheArcLengths;
  22620. }
  22621. this.needsUpdate = false;
  22622. var cache = [];
  22623. var current,
  22624. last = this.getPoint(0);
  22625. var sum = 0;
  22626. cache.push(0);
  22627. for (var p = 1; p <= divisions; p++) {
  22628. current = this.getPoint(p / divisions);
  22629. sum += current.distanceTo(last);
  22630. cache.push(sum);
  22631. last = current;
  22632. }
  22633. this.cacheArcLengths = cache;
  22634. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22635. },
  22636. updateArcLengths: function updateArcLengths() {
  22637. this.needsUpdate = true;
  22638. this.getLengths();
  22639. },
  22640. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22641. getUtoTmapping: function getUtoTmapping(u, distance) {
  22642. var arcLengths = this.getLengths();
  22643. var i = 0;
  22644. var il = arcLengths.length;
  22645. var targetArcLength; // The targeted u distance value to get
  22646. if (distance) {
  22647. targetArcLength = distance;
  22648. } else {
  22649. targetArcLength = u * arcLengths[il - 1];
  22650. } // binary search for the index with largest value smaller than target u distance
  22651. var low = 0,
  22652. high = il - 1,
  22653. comparison;
  22654. while (low <= high) {
  22655. 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
  22656. comparison = arcLengths[i] - targetArcLength;
  22657. if (comparison < 0) {
  22658. low = i + 1;
  22659. } else if (comparison > 0) {
  22660. high = i - 1;
  22661. } else {
  22662. high = i;
  22663. break; // DONE
  22664. }
  22665. }
  22666. i = high;
  22667. if (arcLengths[i] === targetArcLength) {
  22668. return i / (il - 1);
  22669. } // we could get finer grain at lengths, or use simple interpolation between two points
  22670. var lengthBefore = arcLengths[i];
  22671. var lengthAfter = arcLengths[i + 1];
  22672. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  22673. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  22674. var t = (i + segmentFraction) / (il - 1);
  22675. return t;
  22676. },
  22677. // Returns a unit vector tangent at t
  22678. // In case any sub curve does not implement its tangent derivation,
  22679. // 2 points a small delta apart will be used to find its gradient
  22680. // which seems to give a reasonable approximation
  22681. getTangent: function getTangent(t, optionalTarget) {
  22682. var delta = 0.0001;
  22683. var t1 = t - delta;
  22684. var t2 = t + delta; // Capping in case of danger
  22685. if (t1 < 0) t1 = 0;
  22686. if (t2 > 1) t2 = 1;
  22687. var pt1 = this.getPoint(t1);
  22688. var pt2 = this.getPoint(t2);
  22689. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22690. tangent.copy(pt2).sub(pt1).normalize();
  22691. return tangent;
  22692. },
  22693. getTangentAt: function getTangentAt(u, optionalTarget) {
  22694. var t = this.getUtoTmapping(u);
  22695. return this.getTangent(t, optionalTarget);
  22696. },
  22697. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22698. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22699. var normal = new Vector3();
  22700. var tangents = [];
  22701. var normals = [];
  22702. var binormals = [];
  22703. var vec = new Vector3();
  22704. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22705. for (var i = 0; i <= segments; i++) {
  22706. var u = i / segments;
  22707. tangents[i] = this.getTangentAt(u, new Vector3());
  22708. tangents[i].normalize();
  22709. } // select an initial normal vector perpendicular to the first tangent vector,
  22710. // and in the direction of the minimum tangent xyz component
  22711. normals[0] = new Vector3();
  22712. binormals[0] = new Vector3();
  22713. var min = Number.MAX_VALUE;
  22714. var tx = Math.abs(tangents[0].x);
  22715. var ty = Math.abs(tangents[0].y);
  22716. var tz = Math.abs(tangents[0].z);
  22717. if (tx <= min) {
  22718. min = tx;
  22719. normal.set(1, 0, 0);
  22720. }
  22721. if (ty <= min) {
  22722. min = ty;
  22723. normal.set(0, 1, 0);
  22724. }
  22725. if (tz <= min) {
  22726. normal.set(0, 0, 1);
  22727. }
  22728. vec.crossVectors(tangents[0], normal).normalize();
  22729. normals[0].crossVectors(tangents[0], vec);
  22730. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22731. for (var _i = 1; _i <= segments; _i++) {
  22732. normals[_i] = normals[_i - 1].clone();
  22733. binormals[_i] = binormals[_i - 1].clone();
  22734. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22735. if (vec.length() > Number.EPSILON) {
  22736. vec.normalize();
  22737. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22738. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22739. }
  22740. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22741. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22742. if (closed === true) {
  22743. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22744. _theta /= segments;
  22745. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22746. _theta = -_theta;
  22747. }
  22748. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22749. // twist a little...
  22750. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22751. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22752. }
  22753. }
  22754. return {
  22755. tangents: tangents,
  22756. normals: normals,
  22757. binormals: binormals
  22758. };
  22759. },
  22760. clone: function clone() {
  22761. return new this.constructor().copy(this);
  22762. },
  22763. copy: function copy(source) {
  22764. this.arcLengthDivisions = source.arcLengthDivisions;
  22765. return this;
  22766. },
  22767. toJSON: function toJSON() {
  22768. var data = {
  22769. metadata: {
  22770. version: 4.5,
  22771. type: 'Curve',
  22772. generator: 'Curve.toJSON'
  22773. }
  22774. };
  22775. data.arcLengthDivisions = this.arcLengthDivisions;
  22776. data.type = this.type;
  22777. return data;
  22778. },
  22779. fromJSON: function fromJSON(json) {
  22780. this.arcLengthDivisions = json.arcLengthDivisions;
  22781. return this;
  22782. }
  22783. });
  22784. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22785. Curve.call(this);
  22786. this.type = 'EllipseCurve';
  22787. this.aX = aX || 0;
  22788. this.aY = aY || 0;
  22789. this.xRadius = xRadius || 1;
  22790. this.yRadius = yRadius || 1;
  22791. this.aStartAngle = aStartAngle || 0;
  22792. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22793. this.aClockwise = aClockwise || false;
  22794. this.aRotation = aRotation || 0;
  22795. }
  22796. EllipseCurve.prototype = Object.create(Curve.prototype);
  22797. EllipseCurve.prototype.constructor = EllipseCurve;
  22798. EllipseCurve.prototype.isEllipseCurve = true;
  22799. EllipseCurve.prototype.getPoint = function (t, optionalTarget) {
  22800. var point = optionalTarget || new Vector2();
  22801. var twoPi = Math.PI * 2;
  22802. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22803. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22804. while (deltaAngle < 0) {
  22805. deltaAngle += twoPi;
  22806. }
  22807. while (deltaAngle > twoPi) {
  22808. deltaAngle -= twoPi;
  22809. }
  22810. if (deltaAngle < Number.EPSILON) {
  22811. if (samePoints) {
  22812. deltaAngle = 0;
  22813. } else {
  22814. deltaAngle = twoPi;
  22815. }
  22816. }
  22817. if (this.aClockwise === true && !samePoints) {
  22818. if (deltaAngle === twoPi) {
  22819. deltaAngle = -twoPi;
  22820. } else {
  22821. deltaAngle = deltaAngle - twoPi;
  22822. }
  22823. }
  22824. var angle = this.aStartAngle + t * deltaAngle;
  22825. var x = this.aX + this.xRadius * Math.cos(angle);
  22826. var y = this.aY + this.yRadius * Math.sin(angle);
  22827. if (this.aRotation !== 0) {
  22828. var cos = Math.cos(this.aRotation);
  22829. var sin = Math.sin(this.aRotation);
  22830. var tx = x - this.aX;
  22831. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22832. x = tx * cos - ty * sin + this.aX;
  22833. y = tx * sin + ty * cos + this.aY;
  22834. }
  22835. return point.set(x, y);
  22836. };
  22837. EllipseCurve.prototype.copy = function (source) {
  22838. Curve.prototype.copy.call(this, source);
  22839. this.aX = source.aX;
  22840. this.aY = source.aY;
  22841. this.xRadius = source.xRadius;
  22842. this.yRadius = source.yRadius;
  22843. this.aStartAngle = source.aStartAngle;
  22844. this.aEndAngle = source.aEndAngle;
  22845. this.aClockwise = source.aClockwise;
  22846. this.aRotation = source.aRotation;
  22847. return this;
  22848. };
  22849. EllipseCurve.prototype.toJSON = function () {
  22850. var data = Curve.prototype.toJSON.call(this);
  22851. data.aX = this.aX;
  22852. data.aY = this.aY;
  22853. data.xRadius = this.xRadius;
  22854. data.yRadius = this.yRadius;
  22855. data.aStartAngle = this.aStartAngle;
  22856. data.aEndAngle = this.aEndAngle;
  22857. data.aClockwise = this.aClockwise;
  22858. data.aRotation = this.aRotation;
  22859. return data;
  22860. };
  22861. EllipseCurve.prototype.fromJSON = function (json) {
  22862. Curve.prototype.fromJSON.call(this, json);
  22863. this.aX = json.aX;
  22864. this.aY = json.aY;
  22865. this.xRadius = json.xRadius;
  22866. this.yRadius = json.yRadius;
  22867. this.aStartAngle = json.aStartAngle;
  22868. this.aEndAngle = json.aEndAngle;
  22869. this.aClockwise = json.aClockwise;
  22870. this.aRotation = json.aRotation;
  22871. return this;
  22872. };
  22873. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22874. EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  22875. this.type = 'ArcCurve';
  22876. }
  22877. ArcCurve.prototype = Object.create(EllipseCurve.prototype);
  22878. ArcCurve.prototype.constructor = ArcCurve;
  22879. ArcCurve.prototype.isArcCurve = true;
  22880. /**
  22881. * Centripetal CatmullRom Curve - which is useful for avoiding
  22882. * cusps and self-intersections in non-uniform catmull rom curves.
  22883. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22884. *
  22885. * curve.type accepts centripetal(default), chordal and catmullrom
  22886. * curve.tension is used for catmullrom which defaults to 0.5
  22887. */
  22888. /*
  22889. Based on an optimized c++ solution in
  22890. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22891. - http://ideone.com/NoEbVM
  22892. This CubicPoly class could be used for reusing some variables and calculations,
  22893. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22894. which can be placed in CurveUtils.
  22895. */
  22896. function CubicPoly() {
  22897. var c0 = 0,
  22898. c1 = 0,
  22899. c2 = 0,
  22900. c3 = 0;
  22901. /*
  22902. * Compute coefficients for a cubic polynomial
  22903. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22904. * such that
  22905. * p(0) = x0, p(1) = x1
  22906. * and
  22907. * p'(0) = t0, p'(1) = t1.
  22908. */
  22909. function init(x0, x1, t0, t1) {
  22910. c0 = x0;
  22911. c1 = t0;
  22912. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22913. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22914. }
  22915. return {
  22916. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22917. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22918. },
  22919. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22920. // compute tangents when parameterized in [t1,t2]
  22921. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22922. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22923. t1 *= dt1;
  22924. t2 *= dt1;
  22925. init(x1, x2, t1, t2);
  22926. },
  22927. calc: function calc(t) {
  22928. var t2 = t * t;
  22929. var t3 = t2 * t;
  22930. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22931. }
  22932. };
  22933. } //
  22934. var tmp = new Vector3();
  22935. var px = new CubicPoly(),
  22936. py = new CubicPoly(),
  22937. pz = new CubicPoly();
  22938. function CatmullRomCurve3(points, closed, curveType, tension) {
  22939. if (points === void 0) {
  22940. points = [];
  22941. }
  22942. if (closed === void 0) {
  22943. closed = false;
  22944. }
  22945. if (curveType === void 0) {
  22946. curveType = 'centripetal';
  22947. }
  22948. if (tension === void 0) {
  22949. tension = 0.5;
  22950. }
  22951. Curve.call(this);
  22952. this.type = 'CatmullRomCurve3';
  22953. this.points = points;
  22954. this.closed = closed;
  22955. this.curveType = curveType;
  22956. this.tension = tension;
  22957. }
  22958. CatmullRomCurve3.prototype = Object.create(Curve.prototype);
  22959. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22960. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22961. CatmullRomCurve3.prototype.getPoint = function (t, optionalTarget) {
  22962. if (optionalTarget === void 0) {
  22963. optionalTarget = new Vector3();
  22964. }
  22965. var point = optionalTarget;
  22966. var points = this.points;
  22967. var l = points.length;
  22968. var p = (l - (this.closed ? 0 : 1)) * t;
  22969. var intPoint = Math.floor(p);
  22970. var weight = p - intPoint;
  22971. if (this.closed) {
  22972. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22973. } else if (weight === 0 && intPoint === l - 1) {
  22974. intPoint = l - 2;
  22975. weight = 1;
  22976. }
  22977. var p0, p3; // 4 points (p1 & p2 defined below)
  22978. if (this.closed || intPoint > 0) {
  22979. p0 = points[(intPoint - 1) % l];
  22980. } else {
  22981. // extrapolate first point
  22982. tmp.subVectors(points[0], points[1]).add(points[0]);
  22983. p0 = tmp;
  22984. }
  22985. var p1 = points[intPoint % l];
  22986. var p2 = points[(intPoint + 1) % l];
  22987. if (this.closed || intPoint + 2 < l) {
  22988. p3 = points[(intPoint + 2) % l];
  22989. } else {
  22990. // extrapolate last point
  22991. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  22992. p3 = tmp;
  22993. }
  22994. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  22995. // init Centripetal / Chordal Catmull-Rom
  22996. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22997. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  22998. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  22999. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  23000. if (dt1 < 1e-4) dt1 = 1.0;
  23001. if (dt0 < 1e-4) dt0 = dt1;
  23002. if (dt2 < 1e-4) dt2 = dt1;
  23003. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  23004. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  23005. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  23006. } else if (this.curveType === 'catmullrom') {
  23007. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  23008. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  23009. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  23010. }
  23011. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  23012. return point;
  23013. };
  23014. CatmullRomCurve3.prototype.copy = function (source) {
  23015. Curve.prototype.copy.call(this, source);
  23016. this.points = [];
  23017. for (var i = 0, l = source.points.length; i < l; i++) {
  23018. var point = source.points[i];
  23019. this.points.push(point.clone());
  23020. }
  23021. this.closed = source.closed;
  23022. this.curveType = source.curveType;
  23023. this.tension = source.tension;
  23024. return this;
  23025. };
  23026. CatmullRomCurve3.prototype.toJSON = function () {
  23027. var data = Curve.prototype.toJSON.call(this);
  23028. data.points = [];
  23029. for (var i = 0, l = this.points.length; i < l; i++) {
  23030. var point = this.points[i];
  23031. data.points.push(point.toArray());
  23032. }
  23033. data.closed = this.closed;
  23034. data.curveType = this.curveType;
  23035. data.tension = this.tension;
  23036. return data;
  23037. };
  23038. CatmullRomCurve3.prototype.fromJSON = function (json) {
  23039. Curve.prototype.fromJSON.call(this, json);
  23040. this.points = [];
  23041. for (var i = 0, l = json.points.length; i < l; i++) {
  23042. var point = json.points[i];
  23043. this.points.push(new Vector3().fromArray(point));
  23044. }
  23045. this.closed = json.closed;
  23046. this.curveType = json.curveType;
  23047. this.tension = json.tension;
  23048. return this;
  23049. };
  23050. /**
  23051. * Bezier Curves formulas obtained from
  23052. * http://en.wikipedia.org/wiki/Bézier_curve
  23053. */
  23054. function CatmullRom(t, p0, p1, p2, p3) {
  23055. var v0 = (p2 - p0) * 0.5;
  23056. var v1 = (p3 - p1) * 0.5;
  23057. var t2 = t * t;
  23058. var t3 = t * t2;
  23059. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  23060. } //
  23061. function QuadraticBezierP0(t, p) {
  23062. var k = 1 - t;
  23063. return k * k * p;
  23064. }
  23065. function QuadraticBezierP1(t, p) {
  23066. return 2 * (1 - t) * t * p;
  23067. }
  23068. function QuadraticBezierP2(t, p) {
  23069. return t * t * p;
  23070. }
  23071. function QuadraticBezier(t, p0, p1, p2) {
  23072. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  23073. } //
  23074. function CubicBezierP0(t, p) {
  23075. var k = 1 - t;
  23076. return k * k * k * p;
  23077. }
  23078. function CubicBezierP1(t, p) {
  23079. var k = 1 - t;
  23080. return 3 * k * k * t * p;
  23081. }
  23082. function CubicBezierP2(t, p) {
  23083. return 3 * (1 - t) * t * t * p;
  23084. }
  23085. function CubicBezierP3(t, p) {
  23086. return t * t * t * p;
  23087. }
  23088. function CubicBezier(t, p0, p1, p2, p3) {
  23089. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  23090. }
  23091. function CubicBezierCurve(v0, v1, v2, v3) {
  23092. if (v0 === void 0) {
  23093. v0 = new Vector2();
  23094. }
  23095. if (v1 === void 0) {
  23096. v1 = new Vector2();
  23097. }
  23098. if (v2 === void 0) {
  23099. v2 = new Vector2();
  23100. }
  23101. if (v3 === void 0) {
  23102. v3 = new Vector2();
  23103. }
  23104. Curve.call(this);
  23105. this.type = 'CubicBezierCurve';
  23106. this.v0 = v0;
  23107. this.v1 = v1;
  23108. this.v2 = v2;
  23109. this.v3 = v3;
  23110. }
  23111. CubicBezierCurve.prototype = Object.create(Curve.prototype);
  23112. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  23113. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  23114. CubicBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  23115. if (optionalTarget === void 0) {
  23116. optionalTarget = new Vector2();
  23117. }
  23118. var point = optionalTarget;
  23119. var v0 = this.v0,
  23120. v1 = this.v1,
  23121. v2 = this.v2,
  23122. v3 = this.v3;
  23123. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  23124. return point;
  23125. };
  23126. CubicBezierCurve.prototype.copy = function (source) {
  23127. Curve.prototype.copy.call(this, source);
  23128. this.v0.copy(source.v0);
  23129. this.v1.copy(source.v1);
  23130. this.v2.copy(source.v2);
  23131. this.v3.copy(source.v3);
  23132. return this;
  23133. };
  23134. CubicBezierCurve.prototype.toJSON = function () {
  23135. var data = Curve.prototype.toJSON.call(this);
  23136. data.v0 = this.v0.toArray();
  23137. data.v1 = this.v1.toArray();
  23138. data.v2 = this.v2.toArray();
  23139. data.v3 = this.v3.toArray();
  23140. return data;
  23141. };
  23142. CubicBezierCurve.prototype.fromJSON = function (json) {
  23143. Curve.prototype.fromJSON.call(this, json);
  23144. this.v0.fromArray(json.v0);
  23145. this.v1.fromArray(json.v1);
  23146. this.v2.fromArray(json.v2);
  23147. this.v3.fromArray(json.v3);
  23148. return this;
  23149. };
  23150. function CubicBezierCurve3(v0, v1, v2, v3) {
  23151. if (v0 === void 0) {
  23152. v0 = new Vector3();
  23153. }
  23154. if (v1 === void 0) {
  23155. v1 = new Vector3();
  23156. }
  23157. if (v2 === void 0) {
  23158. v2 = new Vector3();
  23159. }
  23160. if (v3 === void 0) {
  23161. v3 = new Vector3();
  23162. }
  23163. Curve.call(this);
  23164. this.type = 'CubicBezierCurve3';
  23165. this.v0 = v0;
  23166. this.v1 = v1;
  23167. this.v2 = v2;
  23168. this.v3 = v3;
  23169. }
  23170. CubicBezierCurve3.prototype = Object.create(Curve.prototype);
  23171. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  23172. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  23173. CubicBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  23174. if (optionalTarget === void 0) {
  23175. optionalTarget = new Vector3();
  23176. }
  23177. var point = optionalTarget;
  23178. var v0 = this.v0,
  23179. v1 = this.v1,
  23180. v2 = this.v2,
  23181. v3 = this.v3;
  23182. 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));
  23183. return point;
  23184. };
  23185. CubicBezierCurve3.prototype.copy = function (source) {
  23186. Curve.prototype.copy.call(this, source);
  23187. this.v0.copy(source.v0);
  23188. this.v1.copy(source.v1);
  23189. this.v2.copy(source.v2);
  23190. this.v3.copy(source.v3);
  23191. return this;
  23192. };
  23193. CubicBezierCurve3.prototype.toJSON = function () {
  23194. var data = Curve.prototype.toJSON.call(this);
  23195. data.v0 = this.v0.toArray();
  23196. data.v1 = this.v1.toArray();
  23197. data.v2 = this.v2.toArray();
  23198. data.v3 = this.v3.toArray();
  23199. return data;
  23200. };
  23201. CubicBezierCurve3.prototype.fromJSON = function (json) {
  23202. Curve.prototype.fromJSON.call(this, json);
  23203. this.v0.fromArray(json.v0);
  23204. this.v1.fromArray(json.v1);
  23205. this.v2.fromArray(json.v2);
  23206. this.v3.fromArray(json.v3);
  23207. return this;
  23208. };
  23209. function LineCurve(v1, v2) {
  23210. if (v1 === void 0) {
  23211. v1 = new Vector2();
  23212. }
  23213. if (v2 === void 0) {
  23214. v2 = new Vector2();
  23215. }
  23216. Curve.call(this);
  23217. this.type = 'LineCurve';
  23218. this.v1 = v1;
  23219. this.v2 = v2;
  23220. }
  23221. LineCurve.prototype = Object.create(Curve.prototype);
  23222. LineCurve.prototype.constructor = LineCurve;
  23223. LineCurve.prototype.isLineCurve = true;
  23224. LineCurve.prototype.getPoint = function (t, optionalTarget) {
  23225. if (optionalTarget === void 0) {
  23226. optionalTarget = new Vector2();
  23227. }
  23228. var point = optionalTarget;
  23229. if (t === 1) {
  23230. point.copy(this.v2);
  23231. } else {
  23232. point.copy(this.v2).sub(this.v1);
  23233. point.multiplyScalar(t).add(this.v1);
  23234. }
  23235. return point;
  23236. }; // Line curve is linear, so we can overwrite default getPointAt
  23237. LineCurve.prototype.getPointAt = function (u, optionalTarget) {
  23238. return this.getPoint(u, optionalTarget);
  23239. };
  23240. LineCurve.prototype.getTangent = function (t, optionalTarget) {
  23241. var tangent = optionalTarget || new Vector2();
  23242. tangent.copy(this.v2).sub(this.v1).normalize();
  23243. return tangent;
  23244. };
  23245. LineCurve.prototype.copy = function (source) {
  23246. Curve.prototype.copy.call(this, source);
  23247. this.v1.copy(source.v1);
  23248. this.v2.copy(source.v2);
  23249. return this;
  23250. };
  23251. LineCurve.prototype.toJSON = function () {
  23252. var data = Curve.prototype.toJSON.call(this);
  23253. data.v1 = this.v1.toArray();
  23254. data.v2 = this.v2.toArray();
  23255. return data;
  23256. };
  23257. LineCurve.prototype.fromJSON = function (json) {
  23258. Curve.prototype.fromJSON.call(this, json);
  23259. this.v1.fromArray(json.v1);
  23260. this.v2.fromArray(json.v2);
  23261. return this;
  23262. };
  23263. function LineCurve3(v1, v2) {
  23264. if (v1 === void 0) {
  23265. v1 = new Vector3();
  23266. }
  23267. if (v2 === void 0) {
  23268. v2 = new Vector3();
  23269. }
  23270. Curve.call(this);
  23271. this.type = 'LineCurve3';
  23272. this.v1 = v1;
  23273. this.v2 = v2;
  23274. }
  23275. LineCurve3.prototype = Object.create(Curve.prototype);
  23276. LineCurve3.prototype.constructor = LineCurve3;
  23277. LineCurve3.prototype.isLineCurve3 = true;
  23278. LineCurve3.prototype.getPoint = function (t, optionalTarget) {
  23279. if (optionalTarget === void 0) {
  23280. optionalTarget = new Vector3();
  23281. }
  23282. var point = optionalTarget;
  23283. if (t === 1) {
  23284. point.copy(this.v2);
  23285. } else {
  23286. point.copy(this.v2).sub(this.v1);
  23287. point.multiplyScalar(t).add(this.v1);
  23288. }
  23289. return point;
  23290. }; // Line curve is linear, so we can overwrite default getPointAt
  23291. LineCurve3.prototype.getPointAt = function (u, optionalTarget) {
  23292. return this.getPoint(u, optionalTarget);
  23293. };
  23294. LineCurve3.prototype.copy = function (source) {
  23295. Curve.prototype.copy.call(this, source);
  23296. this.v1.copy(source.v1);
  23297. this.v2.copy(source.v2);
  23298. return this;
  23299. };
  23300. LineCurve3.prototype.toJSON = function () {
  23301. var data = Curve.prototype.toJSON.call(this);
  23302. data.v1 = this.v1.toArray();
  23303. data.v2 = this.v2.toArray();
  23304. return data;
  23305. };
  23306. LineCurve3.prototype.fromJSON = function (json) {
  23307. Curve.prototype.fromJSON.call(this, json);
  23308. this.v1.fromArray(json.v1);
  23309. this.v2.fromArray(json.v2);
  23310. return this;
  23311. };
  23312. function QuadraticBezierCurve(v0, v1, v2) {
  23313. if (v0 === void 0) {
  23314. v0 = new Vector2();
  23315. }
  23316. if (v1 === void 0) {
  23317. v1 = new Vector2();
  23318. }
  23319. if (v2 === void 0) {
  23320. v2 = new Vector2();
  23321. }
  23322. Curve.call(this);
  23323. this.type = 'QuadraticBezierCurve';
  23324. this.v0 = v0;
  23325. this.v1 = v1;
  23326. this.v2 = v2;
  23327. }
  23328. QuadraticBezierCurve.prototype = Object.create(Curve.prototype);
  23329. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  23330. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  23331. QuadraticBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  23332. if (optionalTarget === void 0) {
  23333. optionalTarget = new Vector2();
  23334. }
  23335. var point = optionalTarget;
  23336. var v0 = this.v0,
  23337. v1 = this.v1,
  23338. v2 = this.v2;
  23339. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  23340. return point;
  23341. };
  23342. QuadraticBezierCurve.prototype.copy = function (source) {
  23343. Curve.prototype.copy.call(this, source);
  23344. this.v0.copy(source.v0);
  23345. this.v1.copy(source.v1);
  23346. this.v2.copy(source.v2);
  23347. return this;
  23348. };
  23349. QuadraticBezierCurve.prototype.toJSON = function () {
  23350. var data = Curve.prototype.toJSON.call(this);
  23351. data.v0 = this.v0.toArray();
  23352. data.v1 = this.v1.toArray();
  23353. data.v2 = this.v2.toArray();
  23354. return data;
  23355. };
  23356. QuadraticBezierCurve.prototype.fromJSON = function (json) {
  23357. Curve.prototype.fromJSON.call(this, json);
  23358. this.v0.fromArray(json.v0);
  23359. this.v1.fromArray(json.v1);
  23360. this.v2.fromArray(json.v2);
  23361. return this;
  23362. };
  23363. function QuadraticBezierCurve3(v0, v1, v2) {
  23364. if (v0 === void 0) {
  23365. v0 = new Vector3();
  23366. }
  23367. if (v1 === void 0) {
  23368. v1 = new Vector3();
  23369. }
  23370. if (v2 === void 0) {
  23371. v2 = new Vector3();
  23372. }
  23373. Curve.call(this);
  23374. this.type = 'QuadraticBezierCurve3';
  23375. this.v0 = v0;
  23376. this.v1 = v1;
  23377. this.v2 = v2;
  23378. }
  23379. QuadraticBezierCurve3.prototype = Object.create(Curve.prototype);
  23380. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  23381. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  23382. QuadraticBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  23383. if (optionalTarget === void 0) {
  23384. optionalTarget = new Vector3();
  23385. }
  23386. var point = optionalTarget;
  23387. var v0 = this.v0,
  23388. v1 = this.v1,
  23389. v2 = this.v2;
  23390. 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));
  23391. return point;
  23392. };
  23393. QuadraticBezierCurve3.prototype.copy = function (source) {
  23394. Curve.prototype.copy.call(this, source);
  23395. this.v0.copy(source.v0);
  23396. this.v1.copy(source.v1);
  23397. this.v2.copy(source.v2);
  23398. return this;
  23399. };
  23400. QuadraticBezierCurve3.prototype.toJSON = function () {
  23401. var data = Curve.prototype.toJSON.call(this);
  23402. data.v0 = this.v0.toArray();
  23403. data.v1 = this.v1.toArray();
  23404. data.v2 = this.v2.toArray();
  23405. return data;
  23406. };
  23407. QuadraticBezierCurve3.prototype.fromJSON = function (json) {
  23408. Curve.prototype.fromJSON.call(this, json);
  23409. this.v0.fromArray(json.v0);
  23410. this.v1.fromArray(json.v1);
  23411. this.v2.fromArray(json.v2);
  23412. return this;
  23413. };
  23414. function SplineCurve(points) {
  23415. if (points === void 0) {
  23416. points = [];
  23417. }
  23418. Curve.call(this);
  23419. this.type = 'SplineCurve';
  23420. this.points = points;
  23421. }
  23422. SplineCurve.prototype = Object.create(Curve.prototype);
  23423. SplineCurve.prototype.constructor = SplineCurve;
  23424. SplineCurve.prototype.isSplineCurve = true;
  23425. SplineCurve.prototype.getPoint = function (t, optionalTarget) {
  23426. if (optionalTarget === void 0) {
  23427. optionalTarget = new Vector2();
  23428. }
  23429. var point = optionalTarget;
  23430. var points = this.points;
  23431. var p = (points.length - 1) * t;
  23432. var intPoint = Math.floor(p);
  23433. var weight = p - intPoint;
  23434. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  23435. var p1 = points[intPoint];
  23436. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  23437. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  23438. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  23439. return point;
  23440. };
  23441. SplineCurve.prototype.copy = function (source) {
  23442. Curve.prototype.copy.call(this, source);
  23443. this.points = [];
  23444. for (var i = 0, l = source.points.length; i < l; i++) {
  23445. var point = source.points[i];
  23446. this.points.push(point.clone());
  23447. }
  23448. return this;
  23449. };
  23450. SplineCurve.prototype.toJSON = function () {
  23451. var data = Curve.prototype.toJSON.call(this);
  23452. data.points = [];
  23453. for (var i = 0, l = this.points.length; i < l; i++) {
  23454. var point = this.points[i];
  23455. data.points.push(point.toArray());
  23456. }
  23457. return data;
  23458. };
  23459. SplineCurve.prototype.fromJSON = function (json) {
  23460. Curve.prototype.fromJSON.call(this, json);
  23461. this.points = [];
  23462. for (var i = 0, l = json.points.length; i < l; i++) {
  23463. var point = json.points[i];
  23464. this.points.push(new Vector2().fromArray(point));
  23465. }
  23466. return this;
  23467. };
  23468. var Curves = /*#__PURE__*/Object.freeze({
  23469. __proto__: null,
  23470. ArcCurve: ArcCurve,
  23471. CatmullRomCurve3: CatmullRomCurve3,
  23472. CubicBezierCurve: CubicBezierCurve,
  23473. CubicBezierCurve3: CubicBezierCurve3,
  23474. EllipseCurve: EllipseCurve,
  23475. LineCurve: LineCurve,
  23476. LineCurve3: LineCurve3,
  23477. QuadraticBezierCurve: QuadraticBezierCurve,
  23478. QuadraticBezierCurve3: QuadraticBezierCurve3,
  23479. SplineCurve: SplineCurve
  23480. });
  23481. /**************************************************************
  23482. * Curved Path - a curve path is simply a array of connected
  23483. * curves, but retains the api of a curve
  23484. **************************************************************/
  23485. function CurvePath() {
  23486. Curve.call(this);
  23487. this.type = 'CurvePath';
  23488. this.curves = [];
  23489. this.autoClose = false; // Automatically closes the path
  23490. }
  23491. CurvePath.prototype = Object.assign(Object.create(Curve.prototype), {
  23492. constructor: CurvePath,
  23493. add: function add(curve) {
  23494. this.curves.push(curve);
  23495. },
  23496. closePath: function closePath() {
  23497. // Add a line curve if start and end of lines are not connected
  23498. var startPoint = this.curves[0].getPoint(0);
  23499. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  23500. if (!startPoint.equals(endPoint)) {
  23501. this.curves.push(new LineCurve(endPoint, startPoint));
  23502. }
  23503. },
  23504. // To get accurate point with reference to
  23505. // entire path distance at time t,
  23506. // following has to be done:
  23507. // 1. Length of each sub path have to be known
  23508. // 2. Locate and identify type of curve
  23509. // 3. Get t for the curve
  23510. // 4. Return curve.getPointAt(t')
  23511. getPoint: function getPoint(t) {
  23512. var d = t * this.getLength();
  23513. var curveLengths = this.getCurveLengths();
  23514. var i = 0; // To think about boundaries points.
  23515. while (i < curveLengths.length) {
  23516. if (curveLengths[i] >= d) {
  23517. var diff = curveLengths[i] - d;
  23518. var curve = this.curves[i];
  23519. var segmentLength = curve.getLength();
  23520. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  23521. return curve.getPointAt(u);
  23522. }
  23523. i++;
  23524. }
  23525. return null; // loop where sum != 0, sum > d , sum+1 <d
  23526. },
  23527. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  23528. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  23529. // getPoint() depends on getLength
  23530. getLength: function getLength() {
  23531. var lens = this.getCurveLengths();
  23532. return lens[lens.length - 1];
  23533. },
  23534. // cacheLengths must be recalculated.
  23535. updateArcLengths: function updateArcLengths() {
  23536. this.needsUpdate = true;
  23537. this.cacheLengths = null;
  23538. this.getCurveLengths();
  23539. },
  23540. // Compute lengths and cache them
  23541. // We cannot overwrite getLengths() because UtoT mapping uses it.
  23542. getCurveLengths: function getCurveLengths() {
  23543. // We use cache values if curves and cache array are same length
  23544. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  23545. return this.cacheLengths;
  23546. } // Get length of sub-curve
  23547. // Push sums into cached array
  23548. var lengths = [];
  23549. var sums = 0;
  23550. for (var i = 0, l = this.curves.length; i < l; i++) {
  23551. sums += this.curves[i].getLength();
  23552. lengths.push(sums);
  23553. }
  23554. this.cacheLengths = lengths;
  23555. return lengths;
  23556. },
  23557. getSpacedPoints: function getSpacedPoints(divisions) {
  23558. if (divisions === void 0) {
  23559. divisions = 40;
  23560. }
  23561. var points = [];
  23562. for (var i = 0; i <= divisions; i++) {
  23563. points.push(this.getPoint(i / divisions));
  23564. }
  23565. if (this.autoClose) {
  23566. points.push(points[0]);
  23567. }
  23568. return points;
  23569. },
  23570. getPoints: function getPoints(divisions) {
  23571. if (divisions === void 0) {
  23572. divisions = 12;
  23573. }
  23574. var points = [];
  23575. var last;
  23576. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  23577. var curve = curves[i];
  23578. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  23579. var pts = curve.getPoints(resolution);
  23580. for (var j = 0; j < pts.length; j++) {
  23581. var point = pts[j];
  23582. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  23583. points.push(point);
  23584. last = point;
  23585. }
  23586. }
  23587. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  23588. points.push(points[0]);
  23589. }
  23590. return points;
  23591. },
  23592. copy: function copy(source) {
  23593. Curve.prototype.copy.call(this, source);
  23594. this.curves = [];
  23595. for (var i = 0, l = source.curves.length; i < l; i++) {
  23596. var curve = source.curves[i];
  23597. this.curves.push(curve.clone());
  23598. }
  23599. this.autoClose = source.autoClose;
  23600. return this;
  23601. },
  23602. toJSON: function toJSON() {
  23603. var data = Curve.prototype.toJSON.call(this);
  23604. data.autoClose = this.autoClose;
  23605. data.curves = [];
  23606. for (var i = 0, l = this.curves.length; i < l; i++) {
  23607. var curve = this.curves[i];
  23608. data.curves.push(curve.toJSON());
  23609. }
  23610. return data;
  23611. },
  23612. fromJSON: function fromJSON(json) {
  23613. Curve.prototype.fromJSON.call(this, json);
  23614. this.autoClose = json.autoClose;
  23615. this.curves = [];
  23616. for (var i = 0, l = json.curves.length; i < l; i++) {
  23617. var curve = json.curves[i];
  23618. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  23619. }
  23620. return this;
  23621. }
  23622. });
  23623. function Path(points) {
  23624. CurvePath.call(this);
  23625. this.type = 'Path';
  23626. this.currentPoint = new Vector2();
  23627. if (points) {
  23628. this.setFromPoints(points);
  23629. }
  23630. }
  23631. Path.prototype = Object.assign(Object.create(CurvePath.prototype), {
  23632. constructor: Path,
  23633. setFromPoints: function setFromPoints(points) {
  23634. this.moveTo(points[0].x, points[0].y);
  23635. for (var i = 1, l = points.length; i < l; i++) {
  23636. this.lineTo(points[i].x, points[i].y);
  23637. }
  23638. return this;
  23639. },
  23640. moveTo: function moveTo(x, y) {
  23641. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  23642. return this;
  23643. },
  23644. lineTo: function lineTo(x, y) {
  23645. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  23646. this.curves.push(curve);
  23647. this.currentPoint.set(x, y);
  23648. return this;
  23649. },
  23650. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  23651. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  23652. this.curves.push(curve);
  23653. this.currentPoint.set(aX, aY);
  23654. return this;
  23655. },
  23656. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  23657. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  23658. this.curves.push(curve);
  23659. this.currentPoint.set(aX, aY);
  23660. return this;
  23661. },
  23662. splineThru: function splineThru(pts
  23663. /*Array of Vector*/
  23664. ) {
  23665. var npts = [this.currentPoint.clone()].concat(pts);
  23666. var curve = new SplineCurve(npts);
  23667. this.curves.push(curve);
  23668. this.currentPoint.copy(pts[pts.length - 1]);
  23669. return this;
  23670. },
  23671. arc: function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23672. var x0 = this.currentPoint.x;
  23673. var y0 = this.currentPoint.y;
  23674. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  23675. return this;
  23676. },
  23677. absarc: function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23678. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  23679. return this;
  23680. },
  23681. ellipse: function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23682. var x0 = this.currentPoint.x;
  23683. var y0 = this.currentPoint.y;
  23684. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23685. return this;
  23686. },
  23687. absellipse: function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23688. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23689. if (this.curves.length > 0) {
  23690. // if a previous curve is present, attempt to join
  23691. var firstPoint = curve.getPoint(0);
  23692. if (!firstPoint.equals(this.currentPoint)) {
  23693. this.lineTo(firstPoint.x, firstPoint.y);
  23694. }
  23695. }
  23696. this.curves.push(curve);
  23697. var lastPoint = curve.getPoint(1);
  23698. this.currentPoint.copy(lastPoint);
  23699. return this;
  23700. },
  23701. copy: function copy(source) {
  23702. CurvePath.prototype.copy.call(this, source);
  23703. this.currentPoint.copy(source.currentPoint);
  23704. return this;
  23705. },
  23706. toJSON: function toJSON() {
  23707. var data = CurvePath.prototype.toJSON.call(this);
  23708. data.currentPoint = this.currentPoint.toArray();
  23709. return data;
  23710. },
  23711. fromJSON: function fromJSON(json) {
  23712. CurvePath.prototype.fromJSON.call(this, json);
  23713. this.currentPoint.fromArray(json.currentPoint);
  23714. return this;
  23715. }
  23716. });
  23717. function Shape(points) {
  23718. Path.call(this, points);
  23719. this.uuid = MathUtils.generateUUID();
  23720. this.type = 'Shape';
  23721. this.holes = [];
  23722. }
  23723. Shape.prototype = Object.assign(Object.create(Path.prototype), {
  23724. constructor: Shape,
  23725. getPointsHoles: function getPointsHoles(divisions) {
  23726. var holesPts = [];
  23727. for (var i = 0, l = this.holes.length; i < l; i++) {
  23728. holesPts[i] = this.holes[i].getPoints(divisions);
  23729. }
  23730. return holesPts;
  23731. },
  23732. // get points of shape and holes (keypoints based on segments parameter)
  23733. extractPoints: function extractPoints(divisions) {
  23734. return {
  23735. shape: this.getPoints(divisions),
  23736. holes: this.getPointsHoles(divisions)
  23737. };
  23738. },
  23739. copy: function copy(source) {
  23740. Path.prototype.copy.call(this, source);
  23741. this.holes = [];
  23742. for (var i = 0, l = source.holes.length; i < l; i++) {
  23743. var hole = source.holes[i];
  23744. this.holes.push(hole.clone());
  23745. }
  23746. return this;
  23747. },
  23748. toJSON: function toJSON() {
  23749. var data = Path.prototype.toJSON.call(this);
  23750. data.uuid = this.uuid;
  23751. data.holes = [];
  23752. for (var i = 0, l = this.holes.length; i < l; i++) {
  23753. var hole = this.holes[i];
  23754. data.holes.push(hole.toJSON());
  23755. }
  23756. return data;
  23757. },
  23758. fromJSON: function fromJSON(json) {
  23759. Path.prototype.fromJSON.call(this, json);
  23760. this.uuid = json.uuid;
  23761. this.holes = [];
  23762. for (var i = 0, l = json.holes.length; i < l; i++) {
  23763. var hole = json.holes[i];
  23764. this.holes.push(new Path().fromJSON(hole));
  23765. }
  23766. return this;
  23767. }
  23768. });
  23769. function Light(color, intensity) {
  23770. if (intensity === void 0) {
  23771. intensity = 1;
  23772. }
  23773. Object3D.call(this);
  23774. this.type = 'Light';
  23775. this.color = new Color(color);
  23776. this.intensity = intensity;
  23777. }
  23778. Light.prototype = Object.assign(Object.create(Object3D.prototype), {
  23779. constructor: Light,
  23780. isLight: true,
  23781. copy: function copy(source) {
  23782. Object3D.prototype.copy.call(this, source);
  23783. this.color.copy(source.color);
  23784. this.intensity = source.intensity;
  23785. return this;
  23786. },
  23787. toJSON: function toJSON(meta) {
  23788. var data = Object3D.prototype.toJSON.call(this, meta);
  23789. data.object.color = this.color.getHex();
  23790. data.object.intensity = this.intensity;
  23791. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23792. if (this.distance !== undefined) data.object.distance = this.distance;
  23793. if (this.angle !== undefined) data.object.angle = this.angle;
  23794. if (this.decay !== undefined) data.object.decay = this.decay;
  23795. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23796. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23797. return data;
  23798. }
  23799. });
  23800. function HemisphereLight(skyColor, groundColor, intensity) {
  23801. Light.call(this, skyColor, intensity);
  23802. this.type = 'HemisphereLight';
  23803. this.position.copy(Object3D.DefaultUp);
  23804. this.updateMatrix();
  23805. this.groundColor = new Color(groundColor);
  23806. }
  23807. HemisphereLight.prototype = Object.assign(Object.create(Light.prototype), {
  23808. constructor: HemisphereLight,
  23809. isHemisphereLight: true,
  23810. copy: function copy(source) {
  23811. Light.prototype.copy.call(this, source);
  23812. this.groundColor.copy(source.groundColor);
  23813. return this;
  23814. }
  23815. });
  23816. function LightShadow(camera) {
  23817. this.camera = camera;
  23818. this.bias = 0;
  23819. this.normalBias = 0;
  23820. this.radius = 1;
  23821. this.mapSize = new Vector2(512, 512);
  23822. this.map = null;
  23823. this.mapPass = null;
  23824. this.matrix = new Matrix4();
  23825. this.autoUpdate = true;
  23826. this.needsUpdate = false;
  23827. this._frustum = new Frustum();
  23828. this._frameExtents = new Vector2(1, 1);
  23829. this._viewportCount = 1;
  23830. this._viewports = [new Vector4(0, 0, 1, 1)];
  23831. }
  23832. Object.assign(LightShadow.prototype, {
  23833. _projScreenMatrix: new Matrix4(),
  23834. _lightPositionWorld: new Vector3(),
  23835. _lookTarget: new Vector3(),
  23836. getViewportCount: function getViewportCount() {
  23837. return this._viewportCount;
  23838. },
  23839. getFrustum: function getFrustum() {
  23840. return this._frustum;
  23841. },
  23842. updateMatrices: function updateMatrices(light) {
  23843. var shadowCamera = this.camera,
  23844. shadowMatrix = this.matrix,
  23845. projScreenMatrix = this._projScreenMatrix,
  23846. lookTarget = this._lookTarget,
  23847. lightPositionWorld = this._lightPositionWorld;
  23848. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23849. shadowCamera.position.copy(lightPositionWorld);
  23850. lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23851. shadowCamera.lookAt(lookTarget);
  23852. shadowCamera.updateMatrixWorld();
  23853. projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23854. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23855. 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);
  23856. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23857. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23858. },
  23859. getViewport: function getViewport(viewportIndex) {
  23860. return this._viewports[viewportIndex];
  23861. },
  23862. getFrameExtents: function getFrameExtents() {
  23863. return this._frameExtents;
  23864. },
  23865. copy: function copy(source) {
  23866. this.camera = source.camera.clone();
  23867. this.bias = source.bias;
  23868. this.radius = source.radius;
  23869. this.mapSize.copy(source.mapSize);
  23870. return this;
  23871. },
  23872. clone: function clone() {
  23873. return new this.constructor().copy(this);
  23874. },
  23875. toJSON: function toJSON() {
  23876. var object = {};
  23877. if (this.bias !== 0) object.bias = this.bias;
  23878. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23879. if (this.radius !== 1) object.radius = this.radius;
  23880. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23881. object.camera = this.camera.toJSON(false).object;
  23882. delete object.camera.matrix;
  23883. return object;
  23884. }
  23885. });
  23886. function SpotLightShadow() {
  23887. LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500));
  23888. this.focus = 1;
  23889. }
  23890. SpotLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23891. constructor: SpotLightShadow,
  23892. isSpotLightShadow: true,
  23893. updateMatrices: function updateMatrices(light) {
  23894. var camera = this.camera;
  23895. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23896. var aspect = this.mapSize.width / this.mapSize.height;
  23897. var far = light.distance || camera.far;
  23898. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23899. camera.fov = fov;
  23900. camera.aspect = aspect;
  23901. camera.far = far;
  23902. camera.updateProjectionMatrix();
  23903. }
  23904. LightShadow.prototype.updateMatrices.call(this, light);
  23905. }
  23906. });
  23907. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23908. Light.call(this, color, intensity);
  23909. this.type = 'SpotLight';
  23910. this.position.copy(Object3D.DefaultUp);
  23911. this.updateMatrix();
  23912. this.target = new Object3D();
  23913. Object.defineProperty(this, 'power', {
  23914. get: function get() {
  23915. // intensity = power per solid angle.
  23916. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23917. return this.intensity * Math.PI;
  23918. },
  23919. set: function set(power) {
  23920. // intensity = power per solid angle.
  23921. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23922. this.intensity = power / Math.PI;
  23923. }
  23924. });
  23925. this.distance = distance !== undefined ? distance : 0;
  23926. this.angle = angle !== undefined ? angle : Math.PI / 3;
  23927. this.penumbra = penumbra !== undefined ? penumbra : 0;
  23928. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23929. this.shadow = new SpotLightShadow();
  23930. }
  23931. SpotLight.prototype = Object.assign(Object.create(Light.prototype), {
  23932. constructor: SpotLight,
  23933. isSpotLight: true,
  23934. copy: function copy(source) {
  23935. Light.prototype.copy.call(this, source);
  23936. this.distance = source.distance;
  23937. this.angle = source.angle;
  23938. this.penumbra = source.penumbra;
  23939. this.decay = source.decay;
  23940. this.target = source.target.clone();
  23941. this.shadow = source.shadow.clone();
  23942. return this;
  23943. }
  23944. });
  23945. function PointLightShadow() {
  23946. LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500));
  23947. this._frameExtents = new Vector2(4, 2);
  23948. this._viewportCount = 6;
  23949. this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23950. // following orientation:
  23951. //
  23952. // xzXZ
  23953. // y Y
  23954. //
  23955. // X - Positive x direction
  23956. // x - Negative x direction
  23957. // Y - Positive y direction
  23958. // y - Negative y direction
  23959. // Z - Positive z direction
  23960. // z - Negative z direction
  23961. // positive X
  23962. new Vector4(2, 1, 1, 1), // negative X
  23963. new Vector4(0, 1, 1, 1), // positive Z
  23964. new Vector4(3, 1, 1, 1), // negative Z
  23965. new Vector4(1, 1, 1, 1), // positive Y
  23966. new Vector4(3, 0, 1, 1), // negative Y
  23967. new Vector4(1, 0, 1, 1)];
  23968. 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)];
  23969. 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)];
  23970. }
  23971. PointLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23972. constructor: PointLightShadow,
  23973. isPointLightShadow: true,
  23974. updateMatrices: function updateMatrices(light, viewportIndex) {
  23975. if (viewportIndex === void 0) {
  23976. viewportIndex = 0;
  23977. }
  23978. var camera = this.camera,
  23979. shadowMatrix = this.matrix,
  23980. lightPositionWorld = this._lightPositionWorld,
  23981. lookTarget = this._lookTarget,
  23982. projScreenMatrix = this._projScreenMatrix;
  23983. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23984. camera.position.copy(lightPositionWorld);
  23985. lookTarget.copy(camera.position);
  23986. lookTarget.add(this._cubeDirections[viewportIndex]);
  23987. camera.up.copy(this._cubeUps[viewportIndex]);
  23988. camera.lookAt(lookTarget);
  23989. camera.updateMatrixWorld();
  23990. shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
  23991. projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  23992. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23993. }
  23994. });
  23995. function PointLight(color, intensity, distance, decay) {
  23996. Light.call(this, color, intensity);
  23997. this.type = 'PointLight';
  23998. Object.defineProperty(this, 'power', {
  23999. get: function get() {
  24000. // intensity = power per solid angle.
  24001. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  24002. return this.intensity * 4 * Math.PI;
  24003. },
  24004. set: function set(power) {
  24005. // intensity = power per solid angle.
  24006. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  24007. this.intensity = power / (4 * Math.PI);
  24008. }
  24009. });
  24010. this.distance = distance !== undefined ? distance : 0;
  24011. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  24012. this.shadow = new PointLightShadow();
  24013. }
  24014. PointLight.prototype = Object.assign(Object.create(Light.prototype), {
  24015. constructor: PointLight,
  24016. isPointLight: true,
  24017. copy: function copy(source) {
  24018. Light.prototype.copy.call(this, source);
  24019. this.distance = source.distance;
  24020. this.decay = source.decay;
  24021. this.shadow = source.shadow.clone();
  24022. return this;
  24023. }
  24024. });
  24025. function OrthographicCamera(left, right, top, bottom, near, far) {
  24026. Camera.call(this);
  24027. this.type = 'OrthographicCamera';
  24028. this.zoom = 1;
  24029. this.view = null;
  24030. this.left = left !== undefined ? left : -1;
  24031. this.right = right !== undefined ? right : 1;
  24032. this.top = top !== undefined ? top : 1;
  24033. this.bottom = bottom !== undefined ? bottom : -1;
  24034. this.near = near !== undefined ? near : 0.1;
  24035. this.far = far !== undefined ? far : 2000;
  24036. this.updateProjectionMatrix();
  24037. }
  24038. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  24039. constructor: OrthographicCamera,
  24040. isOrthographicCamera: true,
  24041. copy: function copy(source, recursive) {
  24042. Camera.prototype.copy.call(this, source, recursive);
  24043. this.left = source.left;
  24044. this.right = source.right;
  24045. this.top = source.top;
  24046. this.bottom = source.bottom;
  24047. this.near = source.near;
  24048. this.far = source.far;
  24049. this.zoom = source.zoom;
  24050. this.view = source.view === null ? null : Object.assign({}, source.view);
  24051. return this;
  24052. },
  24053. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  24054. if (this.view === null) {
  24055. this.view = {
  24056. enabled: true,
  24057. fullWidth: 1,
  24058. fullHeight: 1,
  24059. offsetX: 0,
  24060. offsetY: 0,
  24061. width: 1,
  24062. height: 1
  24063. };
  24064. }
  24065. this.view.enabled = true;
  24066. this.view.fullWidth = fullWidth;
  24067. this.view.fullHeight = fullHeight;
  24068. this.view.offsetX = x;
  24069. this.view.offsetY = y;
  24070. this.view.width = width;
  24071. this.view.height = height;
  24072. this.updateProjectionMatrix();
  24073. },
  24074. clearViewOffset: function clearViewOffset() {
  24075. if (this.view !== null) {
  24076. this.view.enabled = false;
  24077. }
  24078. this.updateProjectionMatrix();
  24079. },
  24080. updateProjectionMatrix: function updateProjectionMatrix() {
  24081. var dx = (this.right - this.left) / (2 * this.zoom);
  24082. var dy = (this.top - this.bottom) / (2 * this.zoom);
  24083. var cx = (this.right + this.left) / 2;
  24084. var cy = (this.top + this.bottom) / 2;
  24085. var left = cx - dx;
  24086. var right = cx + dx;
  24087. var top = cy + dy;
  24088. var bottom = cy - dy;
  24089. if (this.view !== null && this.view.enabled) {
  24090. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  24091. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  24092. left += scaleW * this.view.offsetX;
  24093. right = left + scaleW * this.view.width;
  24094. top -= scaleH * this.view.offsetY;
  24095. bottom = top - scaleH * this.view.height;
  24096. }
  24097. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  24098. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  24099. },
  24100. toJSON: function toJSON(meta) {
  24101. var data = Object3D.prototype.toJSON.call(this, meta);
  24102. data.object.zoom = this.zoom;
  24103. data.object.left = this.left;
  24104. data.object.right = this.right;
  24105. data.object.top = this.top;
  24106. data.object.bottom = this.bottom;
  24107. data.object.near = this.near;
  24108. data.object.far = this.far;
  24109. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  24110. return data;
  24111. }
  24112. });
  24113. function DirectionalLightShadow() {
  24114. LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
  24115. }
  24116. DirectionalLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  24117. constructor: DirectionalLightShadow,
  24118. isDirectionalLightShadow: true,
  24119. updateMatrices: function updateMatrices(light) {
  24120. LightShadow.prototype.updateMatrices.call(this, light);
  24121. }
  24122. });
  24123. function DirectionalLight(color, intensity) {
  24124. Light.call(this, color, intensity);
  24125. this.type = 'DirectionalLight';
  24126. this.position.copy(Object3D.DefaultUp);
  24127. this.updateMatrix();
  24128. this.target = new Object3D();
  24129. this.shadow = new DirectionalLightShadow();
  24130. }
  24131. DirectionalLight.prototype = Object.assign(Object.create(Light.prototype), {
  24132. constructor: DirectionalLight,
  24133. isDirectionalLight: true,
  24134. copy: function copy(source) {
  24135. Light.prototype.copy.call(this, source);
  24136. this.target = source.target.clone();
  24137. this.shadow = source.shadow.clone();
  24138. return this;
  24139. }
  24140. });
  24141. function AmbientLight(color, intensity) {
  24142. Light.call(this, color, intensity);
  24143. this.type = 'AmbientLight';
  24144. }
  24145. AmbientLight.prototype = Object.assign(Object.create(Light.prototype), {
  24146. constructor: AmbientLight,
  24147. isAmbientLight: true
  24148. });
  24149. function RectAreaLight(color, intensity, width, height) {
  24150. Light.call(this, color, intensity);
  24151. this.type = 'RectAreaLight';
  24152. this.width = width !== undefined ? width : 10;
  24153. this.height = height !== undefined ? height : 10;
  24154. }
  24155. RectAreaLight.prototype = Object.assign(Object.create(Light.prototype), {
  24156. constructor: RectAreaLight,
  24157. isRectAreaLight: true,
  24158. copy: function copy(source) {
  24159. Light.prototype.copy.call(this, source);
  24160. this.width = source.width;
  24161. this.height = source.height;
  24162. return this;
  24163. },
  24164. toJSON: function toJSON(meta) {
  24165. var data = Light.prototype.toJSON.call(this, meta);
  24166. data.object.width = this.width;
  24167. data.object.height = this.height;
  24168. return data;
  24169. }
  24170. });
  24171. /**
  24172. * Primary reference:
  24173. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24174. *
  24175. * Secondary reference:
  24176. * https://www.ppsloan.org/publications/StupidSH36.pdf
  24177. */
  24178. // 3-band SH defined by 9 coefficients
  24179. var SphericalHarmonics3 = /*#__PURE__*/function () {
  24180. function SphericalHarmonics3() {
  24181. Object.defineProperty(this, 'isSphericalHarmonics3', {
  24182. value: true
  24183. });
  24184. this.coefficients = [];
  24185. for (var i = 0; i < 9; i++) {
  24186. this.coefficients.push(new Vector3());
  24187. }
  24188. }
  24189. var _proto = SphericalHarmonics3.prototype;
  24190. _proto.set = function set(coefficients) {
  24191. for (var i = 0; i < 9; i++) {
  24192. this.coefficients[i].copy(coefficients[i]);
  24193. }
  24194. return this;
  24195. };
  24196. _proto.zero = function zero() {
  24197. for (var i = 0; i < 9; i++) {
  24198. this.coefficients[i].set(0, 0, 0);
  24199. }
  24200. return this;
  24201. } // get the radiance in the direction of the normal
  24202. // target is a Vector3
  24203. ;
  24204. _proto.getAt = function getAt(normal, target) {
  24205. // normal is assumed to be unit length
  24206. var x = normal.x,
  24207. y = normal.y,
  24208. z = normal.z;
  24209. var coeff = this.coefficients; // band 0
  24210. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  24211. target.addScaledVector(coeff[1], 0.488603 * y);
  24212. target.addScaledVector(coeff[2], 0.488603 * z);
  24213. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  24214. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  24215. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  24216. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  24217. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  24218. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  24219. return target;
  24220. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  24221. // target is a Vector3
  24222. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24223. ;
  24224. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  24225. // normal is assumed to be unit length
  24226. var x = normal.x,
  24227. y = normal.y,
  24228. z = normal.z;
  24229. var coeff = this.coefficients; // band 0
  24230. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  24231. // band 1
  24232. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  24233. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  24234. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  24235. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  24236. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  24237. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  24238. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  24239. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  24240. return target;
  24241. };
  24242. _proto.add = function add(sh) {
  24243. for (var i = 0; i < 9; i++) {
  24244. this.coefficients[i].add(sh.coefficients[i]);
  24245. }
  24246. return this;
  24247. };
  24248. _proto.addScaledSH = function addScaledSH(sh, s) {
  24249. for (var i = 0; i < 9; i++) {
  24250. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  24251. }
  24252. return this;
  24253. };
  24254. _proto.scale = function scale(s) {
  24255. for (var i = 0; i < 9; i++) {
  24256. this.coefficients[i].multiplyScalar(s);
  24257. }
  24258. return this;
  24259. };
  24260. _proto.lerp = function lerp(sh, alpha) {
  24261. for (var i = 0; i < 9; i++) {
  24262. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  24263. }
  24264. return this;
  24265. };
  24266. _proto.equals = function equals(sh) {
  24267. for (var i = 0; i < 9; i++) {
  24268. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  24269. return false;
  24270. }
  24271. }
  24272. return true;
  24273. };
  24274. _proto.copy = function copy(sh) {
  24275. return this.set(sh.coefficients);
  24276. };
  24277. _proto.clone = function clone() {
  24278. return new this.constructor().copy(this);
  24279. };
  24280. _proto.fromArray = function fromArray(array, offset) {
  24281. if (offset === void 0) {
  24282. offset = 0;
  24283. }
  24284. var coefficients = this.coefficients;
  24285. for (var i = 0; i < 9; i++) {
  24286. coefficients[i].fromArray(array, offset + i * 3);
  24287. }
  24288. return this;
  24289. };
  24290. _proto.toArray = function toArray(array, offset) {
  24291. if (array === void 0) {
  24292. array = [];
  24293. }
  24294. if (offset === void 0) {
  24295. offset = 0;
  24296. }
  24297. var coefficients = this.coefficients;
  24298. for (var i = 0; i < 9; i++) {
  24299. coefficients[i].toArray(array, offset + i * 3);
  24300. }
  24301. return array;
  24302. } // evaluate the basis functions
  24303. // shBasis is an Array[ 9 ]
  24304. ;
  24305. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  24306. // normal is assumed to be unit length
  24307. var x = normal.x,
  24308. y = normal.y,
  24309. z = normal.z; // band 0
  24310. shBasis[0] = 0.282095; // band 1
  24311. shBasis[1] = 0.488603 * y;
  24312. shBasis[2] = 0.488603 * z;
  24313. shBasis[3] = 0.488603 * x; // band 2
  24314. shBasis[4] = 1.092548 * x * y;
  24315. shBasis[5] = 1.092548 * y * z;
  24316. shBasis[6] = 0.315392 * (3 * z * z - 1);
  24317. shBasis[7] = 1.092548 * x * z;
  24318. shBasis[8] = 0.546274 * (x * x - y * y);
  24319. };
  24320. return SphericalHarmonics3;
  24321. }();
  24322. function LightProbe(sh, intensity) {
  24323. Light.call(this, undefined, intensity);
  24324. this.type = 'LightProbe';
  24325. this.sh = sh !== undefined ? sh : new SphericalHarmonics3();
  24326. }
  24327. LightProbe.prototype = Object.assign(Object.create(Light.prototype), {
  24328. constructor: LightProbe,
  24329. isLightProbe: true,
  24330. copy: function copy(source) {
  24331. Light.prototype.copy.call(this, source);
  24332. this.sh.copy(source.sh);
  24333. return this;
  24334. },
  24335. fromJSON: function fromJSON(json) {
  24336. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  24337. this.sh.fromArray(json.sh);
  24338. return this;
  24339. },
  24340. toJSON: function toJSON(meta) {
  24341. var data = Light.prototype.toJSON.call(this, meta);
  24342. data.object.sh = this.sh.toArray();
  24343. return data;
  24344. }
  24345. });
  24346. function MaterialLoader(manager) {
  24347. Loader.call(this, manager);
  24348. this.textures = {};
  24349. }
  24350. MaterialLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24351. constructor: MaterialLoader,
  24352. load: function load(url, onLoad, onProgress, onError) {
  24353. var scope = this;
  24354. var loader = new FileLoader(scope.manager);
  24355. loader.setPath(scope.path);
  24356. loader.setRequestHeader(scope.requestHeader);
  24357. loader.setWithCredentials(scope.withCredentials);
  24358. loader.load(url, function (text) {
  24359. try {
  24360. onLoad(scope.parse(JSON.parse(text)));
  24361. } catch (e) {
  24362. if (onError) {
  24363. onError(e);
  24364. } else {
  24365. console.error(e);
  24366. }
  24367. scope.manager.itemError(url);
  24368. }
  24369. }, onProgress, onError);
  24370. },
  24371. parse: function parse(json) {
  24372. var textures = this.textures;
  24373. function getTexture(name) {
  24374. if (textures[name] === undefined) {
  24375. console.warn('THREE.MaterialLoader: Undefined texture', name);
  24376. }
  24377. return textures[name];
  24378. }
  24379. var material = new Materials[json.type]();
  24380. if (json.uuid !== undefined) material.uuid = json.uuid;
  24381. if (json.name !== undefined) material.name = json.name;
  24382. if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
  24383. if (json.roughness !== undefined) material.roughness = json.roughness;
  24384. if (json.metalness !== undefined) material.metalness = json.metalness;
  24385. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  24386. if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
  24387. if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
  24388. if (json.shininess !== undefined) material.shininess = json.shininess;
  24389. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  24390. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  24391. if (json.fog !== undefined) material.fog = json.fog;
  24392. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  24393. if (json.blending !== undefined) material.blending = json.blending;
  24394. if (json.combine !== undefined) material.combine = json.combine;
  24395. if (json.side !== undefined) material.side = json.side;
  24396. if (json.opacity !== undefined) material.opacity = json.opacity;
  24397. if (json.transparent !== undefined) material.transparent = json.transparent;
  24398. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  24399. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  24400. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  24401. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  24402. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  24403. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  24404. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  24405. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  24406. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  24407. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  24408. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  24409. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  24410. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  24411. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  24412. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  24413. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  24414. if (json.rotation !== undefined) material.rotation = json.rotation;
  24415. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  24416. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  24417. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  24418. if (json.scale !== undefined) material.scale = json.scale;
  24419. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  24420. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  24421. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  24422. if (json.skinning !== undefined) material.skinning = json.skinning;
  24423. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  24424. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  24425. if (json.dithering !== undefined) material.dithering = json.dithering;
  24426. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  24427. if (json.visible !== undefined) material.visible = json.visible;
  24428. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  24429. if (json.userData !== undefined) material.userData = json.userData;
  24430. if (json.vertexColors !== undefined) {
  24431. if (typeof json.vertexColors === 'number') {
  24432. material.vertexColors = json.vertexColors > 0 ? true : false;
  24433. } else {
  24434. material.vertexColors = json.vertexColors;
  24435. }
  24436. } // Shader Material
  24437. if (json.uniforms !== undefined) {
  24438. for (var name in json.uniforms) {
  24439. var uniform = json.uniforms[name];
  24440. material.uniforms[name] = {};
  24441. switch (uniform.type) {
  24442. case 't':
  24443. material.uniforms[name].value = getTexture(uniform.value);
  24444. break;
  24445. case 'c':
  24446. material.uniforms[name].value = new Color().setHex(uniform.value);
  24447. break;
  24448. case 'v2':
  24449. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  24450. break;
  24451. case 'v3':
  24452. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  24453. break;
  24454. case 'v4':
  24455. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  24456. break;
  24457. case 'm3':
  24458. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  24459. break;
  24460. case 'm4':
  24461. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  24462. break;
  24463. default:
  24464. material.uniforms[name].value = uniform.value;
  24465. }
  24466. }
  24467. }
  24468. if (json.defines !== undefined) material.defines = json.defines;
  24469. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  24470. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  24471. if (json.extensions !== undefined) {
  24472. for (var key in json.extensions) {
  24473. material.extensions[key] = json.extensions[key];
  24474. }
  24475. } // Deprecated
  24476. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  24477. // for PointsMaterial
  24478. if (json.size !== undefined) material.size = json.size;
  24479. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  24480. if (json.map !== undefined) material.map = getTexture(json.map);
  24481. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  24482. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  24483. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  24484. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  24485. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  24486. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  24487. if (json.normalScale !== undefined) {
  24488. var normalScale = json.normalScale;
  24489. if (Array.isArray(normalScale) === false) {
  24490. // Blender exporter used to export a scalar. See #7459
  24491. normalScale = [normalScale, normalScale];
  24492. }
  24493. material.normalScale = new Vector2().fromArray(normalScale);
  24494. }
  24495. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  24496. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  24497. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  24498. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  24499. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  24500. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  24501. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  24502. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  24503. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  24504. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  24505. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  24506. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  24507. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  24508. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  24509. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  24510. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  24511. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  24512. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  24513. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  24514. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  24515. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  24516. if (json.transmission !== undefined) material.transmission = json.transmission;
  24517. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  24518. return material;
  24519. },
  24520. setTextures: function setTextures(value) {
  24521. this.textures = value;
  24522. return this;
  24523. }
  24524. });
  24525. var LoaderUtils = {
  24526. decodeText: function decodeText(array) {
  24527. if (typeof TextDecoder !== 'undefined') {
  24528. return new TextDecoder().decode(array);
  24529. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  24530. // throws a "maximum call stack size exceeded" error for large arrays.
  24531. var s = '';
  24532. for (var i = 0, il = array.length; i < il; i++) {
  24533. // Implicitly assumes little-endian.
  24534. s += String.fromCharCode(array[i]);
  24535. }
  24536. try {
  24537. // merges multi-byte utf-8 characters.
  24538. return decodeURIComponent(escape(s));
  24539. } catch (e) {
  24540. // see #16358
  24541. return s;
  24542. }
  24543. },
  24544. extractUrlBase: function extractUrlBase(url) {
  24545. var index = url.lastIndexOf('/');
  24546. if (index === -1) return './';
  24547. return url.substr(0, index + 1);
  24548. }
  24549. };
  24550. function InstancedBufferGeometry() {
  24551. BufferGeometry.call(this);
  24552. this.type = 'InstancedBufferGeometry';
  24553. this.instanceCount = Infinity;
  24554. }
  24555. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  24556. constructor: InstancedBufferGeometry,
  24557. isInstancedBufferGeometry: true,
  24558. copy: function copy(source) {
  24559. BufferGeometry.prototype.copy.call(this, source);
  24560. this.instanceCount = source.instanceCount;
  24561. return this;
  24562. },
  24563. clone: function clone() {
  24564. return new this.constructor().copy(this);
  24565. },
  24566. toJSON: function toJSON() {
  24567. var data = BufferGeometry.prototype.toJSON.call(this);
  24568. data.instanceCount = this.instanceCount;
  24569. data.isInstancedBufferGeometry = true;
  24570. return data;
  24571. }
  24572. });
  24573. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  24574. if (typeof normalized === 'number') {
  24575. meshPerAttribute = normalized;
  24576. normalized = false;
  24577. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  24578. }
  24579. BufferAttribute.call(this, array, itemSize, normalized);
  24580. this.meshPerAttribute = meshPerAttribute || 1;
  24581. }
  24582. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  24583. constructor: InstancedBufferAttribute,
  24584. isInstancedBufferAttribute: true,
  24585. copy: function copy(source) {
  24586. BufferAttribute.prototype.copy.call(this, source);
  24587. this.meshPerAttribute = source.meshPerAttribute;
  24588. return this;
  24589. },
  24590. toJSON: function toJSON() {
  24591. var data = BufferAttribute.prototype.toJSON.call(this);
  24592. data.meshPerAttribute = this.meshPerAttribute;
  24593. data.isInstancedBufferAttribute = true;
  24594. return data;
  24595. }
  24596. });
  24597. function BufferGeometryLoader(manager) {
  24598. Loader.call(this, manager);
  24599. }
  24600. BufferGeometryLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24601. constructor: BufferGeometryLoader,
  24602. load: function load(url, onLoad, onProgress, onError) {
  24603. var scope = this;
  24604. var loader = new FileLoader(scope.manager);
  24605. loader.setPath(scope.path);
  24606. loader.setRequestHeader(scope.requestHeader);
  24607. loader.setWithCredentials(scope.withCredentials);
  24608. loader.load(url, function (text) {
  24609. try {
  24610. onLoad(scope.parse(JSON.parse(text)));
  24611. } catch (e) {
  24612. if (onError) {
  24613. onError(e);
  24614. } else {
  24615. console.error(e);
  24616. }
  24617. scope.manager.itemError(url);
  24618. }
  24619. }, onProgress, onError);
  24620. },
  24621. parse: function parse(json) {
  24622. var interleavedBufferMap = {};
  24623. var arrayBufferMap = {};
  24624. function getInterleavedBuffer(json, uuid) {
  24625. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  24626. var interleavedBuffers = json.interleavedBuffers;
  24627. var interleavedBuffer = interleavedBuffers[uuid];
  24628. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  24629. var array = getTypedArray(interleavedBuffer.type, buffer);
  24630. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  24631. ib.uuid = interleavedBuffer.uuid;
  24632. interleavedBufferMap[uuid] = ib;
  24633. return ib;
  24634. }
  24635. function getArrayBuffer(json, uuid) {
  24636. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  24637. var arrayBuffers = json.arrayBuffers;
  24638. var arrayBuffer = arrayBuffers[uuid];
  24639. var ab = new Uint32Array(arrayBuffer).buffer;
  24640. arrayBufferMap[uuid] = ab;
  24641. return ab;
  24642. }
  24643. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24644. var index = json.data.index;
  24645. if (index !== undefined) {
  24646. var typedArray = getTypedArray(index.type, index.array);
  24647. geometry.setIndex(new BufferAttribute(typedArray, 1));
  24648. }
  24649. var attributes = json.data.attributes;
  24650. for (var key in attributes) {
  24651. var attribute = attributes[key];
  24652. var bufferAttribute = void 0;
  24653. if (attribute.isInterleavedBufferAttribute) {
  24654. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  24655. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  24656. } else {
  24657. var _typedArray = getTypedArray(attribute.type, attribute.array);
  24658. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24659. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  24660. }
  24661. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  24662. geometry.setAttribute(key, bufferAttribute);
  24663. }
  24664. var morphAttributes = json.data.morphAttributes;
  24665. if (morphAttributes) {
  24666. for (var _key in morphAttributes) {
  24667. var attributeArray = morphAttributes[_key];
  24668. var array = [];
  24669. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24670. var _attribute = attributeArray[i];
  24671. var _bufferAttribute = void 0;
  24672. if (_attribute.isInterleavedBufferAttribute) {
  24673. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24674. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24675. } else {
  24676. var _typedArray2 = getTypedArray(_attribute.type, _attribute.array);
  24677. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24678. }
  24679. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24680. array.push(_bufferAttribute);
  24681. }
  24682. geometry.morphAttributes[_key] = array;
  24683. }
  24684. }
  24685. var morphTargetsRelative = json.data.morphTargetsRelative;
  24686. if (morphTargetsRelative) {
  24687. geometry.morphTargetsRelative = true;
  24688. }
  24689. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24690. if (groups !== undefined) {
  24691. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24692. var group = groups[_i];
  24693. geometry.addGroup(group.start, group.count, group.materialIndex);
  24694. }
  24695. }
  24696. var boundingSphere = json.data.boundingSphere;
  24697. if (boundingSphere !== undefined) {
  24698. var center = new Vector3();
  24699. if (boundingSphere.center !== undefined) {
  24700. center.fromArray(boundingSphere.center);
  24701. }
  24702. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24703. }
  24704. if (json.name) geometry.name = json.name;
  24705. if (json.userData) geometry.userData = json.userData;
  24706. return geometry;
  24707. }
  24708. });
  24709. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24710. _inheritsLoose(ObjectLoader, _Loader);
  24711. function ObjectLoader(manager) {
  24712. return _Loader.call(this, manager) || this;
  24713. }
  24714. var _proto = ObjectLoader.prototype;
  24715. _proto.load = function load(url, onLoad, onProgress, onError) {
  24716. var scope = this;
  24717. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24718. this.resourcePath = this.resourcePath || path;
  24719. var loader = new FileLoader(this.manager);
  24720. loader.setPath(this.path);
  24721. loader.setRequestHeader(this.requestHeader);
  24722. loader.setWithCredentials(this.withCredentials);
  24723. loader.load(url, function (text) {
  24724. var json = null;
  24725. try {
  24726. json = JSON.parse(text);
  24727. } catch (error) {
  24728. if (onError !== undefined) onError(error);
  24729. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24730. return;
  24731. }
  24732. var metadata = json.metadata;
  24733. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24734. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24735. return;
  24736. }
  24737. scope.parse(json, onLoad);
  24738. }, onProgress, onError);
  24739. };
  24740. _proto.parse = function parse(json, onLoad) {
  24741. var animations = this.parseAnimations(json.animations);
  24742. var shapes = this.parseShapes(json.shapes);
  24743. var geometries = this.parseGeometries(json.geometries, shapes);
  24744. var images = this.parseImages(json.images, function () {
  24745. if (onLoad !== undefined) onLoad(object);
  24746. });
  24747. var textures = this.parseTextures(json.textures, images);
  24748. var materials = this.parseMaterials(json.materials, textures);
  24749. var object = this.parseObject(json.object, geometries, materials, animations);
  24750. var skeletons = this.parseSkeletons(json.skeletons, object);
  24751. this.bindSkeletons(object, skeletons); //
  24752. if (onLoad !== undefined) {
  24753. var hasImages = false;
  24754. for (var uuid in images) {
  24755. if (images[uuid] instanceof HTMLImageElement) {
  24756. hasImages = true;
  24757. break;
  24758. }
  24759. }
  24760. if (hasImages === false) onLoad(object);
  24761. }
  24762. return object;
  24763. };
  24764. _proto.parseShapes = function parseShapes(json) {
  24765. var shapes = {};
  24766. if (json !== undefined) {
  24767. for (var i = 0, l = json.length; i < l; i++) {
  24768. var shape = new Shape().fromJSON(json[i]);
  24769. shapes[shape.uuid] = shape;
  24770. }
  24771. }
  24772. return shapes;
  24773. };
  24774. _proto.parseSkeletons = function parseSkeletons(json, object) {
  24775. var skeletons = {};
  24776. var bones = {}; // generate bone lookup table
  24777. object.traverse(function (child) {
  24778. if (child.isBone) bones[child.uuid] = child;
  24779. }); // create skeletons
  24780. if (json !== undefined) {
  24781. for (var i = 0, l = json.length; i < l; i++) {
  24782. var skeleton = new Skeleton().fromJSON(json[i], bones);
  24783. skeletons[skeleton.uuid] = skeleton;
  24784. }
  24785. }
  24786. return skeletons;
  24787. };
  24788. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24789. var geometries = {};
  24790. var geometryShapes;
  24791. if (json !== undefined) {
  24792. var bufferGeometryLoader = new BufferGeometryLoader();
  24793. for (var i = 0, l = json.length; i < l; i++) {
  24794. var geometry = void 0;
  24795. var data = json[i];
  24796. switch (data.type) {
  24797. case 'PlaneGeometry':
  24798. case 'PlaneBufferGeometry':
  24799. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24800. break;
  24801. case 'BoxGeometry':
  24802. case 'BoxBufferGeometry':
  24803. case 'CubeGeometry':
  24804. // backwards compatible
  24805. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24806. break;
  24807. case 'CircleGeometry':
  24808. case 'CircleBufferGeometry':
  24809. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24810. break;
  24811. case 'CylinderGeometry':
  24812. case 'CylinderBufferGeometry':
  24813. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24814. break;
  24815. case 'ConeGeometry':
  24816. case 'ConeBufferGeometry':
  24817. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24818. break;
  24819. case 'SphereGeometry':
  24820. case 'SphereBufferGeometry':
  24821. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24822. break;
  24823. case 'DodecahedronGeometry':
  24824. case 'DodecahedronBufferGeometry':
  24825. case 'IcosahedronGeometry':
  24826. case 'IcosahedronBufferGeometry':
  24827. case 'OctahedronGeometry':
  24828. case 'OctahedronBufferGeometry':
  24829. case 'TetrahedronGeometry':
  24830. case 'TetrahedronBufferGeometry':
  24831. geometry = new Geometries[data.type](data.radius, data.detail);
  24832. break;
  24833. case 'RingGeometry':
  24834. case 'RingBufferGeometry':
  24835. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24836. break;
  24837. case 'TorusGeometry':
  24838. case 'TorusBufferGeometry':
  24839. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24840. break;
  24841. case 'TorusKnotGeometry':
  24842. case 'TorusKnotBufferGeometry':
  24843. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24844. break;
  24845. case 'TubeGeometry':
  24846. case 'TubeBufferGeometry':
  24847. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24848. // User defined curves or instances of CurvePath will not be deserialized.
  24849. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24850. break;
  24851. case 'LatheGeometry':
  24852. case 'LatheBufferGeometry':
  24853. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24854. break;
  24855. case 'PolyhedronGeometry':
  24856. case 'PolyhedronBufferGeometry':
  24857. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24858. break;
  24859. case 'ShapeGeometry':
  24860. case 'ShapeBufferGeometry':
  24861. geometryShapes = [];
  24862. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24863. var shape = shapes[data.shapes[j]];
  24864. geometryShapes.push(shape);
  24865. }
  24866. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24867. break;
  24868. case 'ExtrudeGeometry':
  24869. case 'ExtrudeBufferGeometry':
  24870. geometryShapes = [];
  24871. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24872. var _shape = shapes[data.shapes[_j]];
  24873. geometryShapes.push(_shape);
  24874. }
  24875. var extrudePath = data.options.extrudePath;
  24876. if (extrudePath !== undefined) {
  24877. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24878. }
  24879. geometry = new Geometries[data.type](geometryShapes, data.options);
  24880. break;
  24881. case 'BufferGeometry':
  24882. case 'InstancedBufferGeometry':
  24883. geometry = bufferGeometryLoader.parse(data);
  24884. break;
  24885. case 'Geometry':
  24886. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24887. break;
  24888. default:
  24889. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24890. continue;
  24891. }
  24892. geometry.uuid = data.uuid;
  24893. if (data.name !== undefined) geometry.name = data.name;
  24894. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24895. geometries[data.uuid] = geometry;
  24896. }
  24897. }
  24898. return geometries;
  24899. };
  24900. _proto.parseMaterials = function parseMaterials(json, textures) {
  24901. var cache = {}; // MultiMaterial
  24902. var materials = {};
  24903. if (json !== undefined) {
  24904. var loader = new MaterialLoader();
  24905. loader.setTextures(textures);
  24906. for (var i = 0, l = json.length; i < l; i++) {
  24907. var data = json[i];
  24908. if (data.type === 'MultiMaterial') {
  24909. // Deprecated
  24910. var array = [];
  24911. for (var j = 0; j < data.materials.length; j++) {
  24912. var material = data.materials[j];
  24913. if (cache[material.uuid] === undefined) {
  24914. cache[material.uuid] = loader.parse(material);
  24915. }
  24916. array.push(cache[material.uuid]);
  24917. }
  24918. materials[data.uuid] = array;
  24919. } else {
  24920. if (cache[data.uuid] === undefined) {
  24921. cache[data.uuid] = loader.parse(data);
  24922. }
  24923. materials[data.uuid] = cache[data.uuid];
  24924. }
  24925. }
  24926. }
  24927. return materials;
  24928. };
  24929. _proto.parseAnimations = function parseAnimations(json) {
  24930. var animations = {};
  24931. if (json !== undefined) {
  24932. for (var i = 0; i < json.length; i++) {
  24933. var data = json[i];
  24934. var clip = AnimationClip.parse(data);
  24935. animations[clip.uuid] = clip;
  24936. }
  24937. }
  24938. return animations;
  24939. };
  24940. _proto.parseImages = function parseImages(json, onLoad) {
  24941. var scope = this;
  24942. var images = {};
  24943. var loader;
  24944. function loadImage(url) {
  24945. scope.manager.itemStart(url);
  24946. return loader.load(url, function () {
  24947. scope.manager.itemEnd(url);
  24948. }, undefined, function () {
  24949. scope.manager.itemError(url);
  24950. scope.manager.itemEnd(url);
  24951. });
  24952. }
  24953. function deserializeImage(image) {
  24954. if (typeof image === 'string') {
  24955. var url = image;
  24956. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
  24957. return loadImage(path);
  24958. } else {
  24959. if (image.data) {
  24960. return {
  24961. data: getTypedArray(image.type, image.data),
  24962. width: image.width,
  24963. height: image.height
  24964. };
  24965. } else {
  24966. return null;
  24967. }
  24968. }
  24969. }
  24970. if (json !== undefined && json.length > 0) {
  24971. var manager = new LoadingManager(onLoad);
  24972. loader = new ImageLoader(manager);
  24973. loader.setCrossOrigin(this.crossOrigin);
  24974. for (var i = 0, il = json.length; i < il; i++) {
  24975. var image = json[i];
  24976. var url = image.url;
  24977. if (Array.isArray(url)) {
  24978. // load array of images e.g CubeTexture
  24979. images[image.uuid] = [];
  24980. for (var j = 0, jl = url.length; j < jl; j++) {
  24981. var currentUrl = url[j];
  24982. var deserializedImage = deserializeImage(currentUrl);
  24983. if (deserializedImage !== null) {
  24984. if (deserializedImage instanceof HTMLImageElement) {
  24985. images[image.uuid].push(deserializedImage);
  24986. } else {
  24987. // special case: handle array of data textures for cube textures
  24988. images[image.uuid].push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
  24989. }
  24990. }
  24991. }
  24992. } else {
  24993. // load single image
  24994. var _deserializedImage = deserializeImage(image.url);
  24995. if (_deserializedImage !== null) {
  24996. images[image.uuid] = _deserializedImage;
  24997. }
  24998. }
  24999. }
  25000. }
  25001. return images;
  25002. };
  25003. _proto.parseTextures = function parseTextures(json, images) {
  25004. function parseConstant(value, type) {
  25005. if (typeof value === 'number') return value;
  25006. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  25007. return type[value];
  25008. }
  25009. var textures = {};
  25010. if (json !== undefined) {
  25011. for (var i = 0, l = json.length; i < l; i++) {
  25012. var data = json[i];
  25013. if (data.image === undefined) {
  25014. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  25015. }
  25016. if (images[data.image] === undefined) {
  25017. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  25018. }
  25019. var texture = void 0;
  25020. var image = images[data.image];
  25021. if (Array.isArray(image)) {
  25022. texture = new CubeTexture(image);
  25023. if (image.length === 6) texture.needsUpdate = true;
  25024. } else {
  25025. if (image && image.data) {
  25026. texture = new DataTexture(image.data, image.width, image.height);
  25027. } else {
  25028. texture = new Texture(image);
  25029. }
  25030. if (image) texture.needsUpdate = true; // textures can have undefined image data
  25031. }
  25032. texture.uuid = data.uuid;
  25033. if (data.name !== undefined) texture.name = data.name;
  25034. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  25035. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  25036. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  25037. if (data.center !== undefined) texture.center.fromArray(data.center);
  25038. if (data.rotation !== undefined) texture.rotation = data.rotation;
  25039. if (data.wrap !== undefined) {
  25040. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  25041. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  25042. }
  25043. if (data.format !== undefined) texture.format = data.format;
  25044. if (data.type !== undefined) texture.type = data.type;
  25045. if (data.encoding !== undefined) texture.encoding = data.encoding;
  25046. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  25047. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  25048. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  25049. if (data.flipY !== undefined) texture.flipY = data.flipY;
  25050. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  25051. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  25052. textures[data.uuid] = texture;
  25053. }
  25054. }
  25055. return textures;
  25056. };
  25057. _proto.parseObject = function parseObject(data, geometries, materials, animations) {
  25058. var object;
  25059. function getGeometry(name) {
  25060. if (geometries[name] === undefined) {
  25061. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  25062. }
  25063. return geometries[name];
  25064. }
  25065. function getMaterial(name) {
  25066. if (name === undefined) return undefined;
  25067. if (Array.isArray(name)) {
  25068. var array = [];
  25069. for (var i = 0, l = name.length; i < l; i++) {
  25070. var uuid = name[i];
  25071. if (materials[uuid] === undefined) {
  25072. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  25073. }
  25074. array.push(materials[uuid]);
  25075. }
  25076. return array;
  25077. }
  25078. if (materials[name] === undefined) {
  25079. console.warn('THREE.ObjectLoader: Undefined material', name);
  25080. }
  25081. return materials[name];
  25082. }
  25083. var geometry, material;
  25084. switch (data.type) {
  25085. case 'Scene':
  25086. object = new Scene();
  25087. if (data.background !== undefined) {
  25088. if (Number.isInteger(data.background)) {
  25089. object.background = new Color(data.background);
  25090. }
  25091. }
  25092. if (data.fog !== undefined) {
  25093. if (data.fog.type === 'Fog') {
  25094. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  25095. } else if (data.fog.type === 'FogExp2') {
  25096. object.fog = new FogExp2(data.fog.color, data.fog.density);
  25097. }
  25098. }
  25099. break;
  25100. case 'PerspectiveCamera':
  25101. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  25102. if (data.focus !== undefined) object.focus = data.focus;
  25103. if (data.zoom !== undefined) object.zoom = data.zoom;
  25104. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  25105. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  25106. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  25107. break;
  25108. case 'OrthographicCamera':
  25109. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  25110. if (data.zoom !== undefined) object.zoom = data.zoom;
  25111. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  25112. break;
  25113. case 'AmbientLight':
  25114. object = new AmbientLight(data.color, data.intensity);
  25115. break;
  25116. case 'DirectionalLight':
  25117. object = new DirectionalLight(data.color, data.intensity);
  25118. break;
  25119. case 'PointLight':
  25120. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  25121. break;
  25122. case 'RectAreaLight':
  25123. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  25124. break;
  25125. case 'SpotLight':
  25126. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  25127. break;
  25128. case 'HemisphereLight':
  25129. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  25130. break;
  25131. case 'LightProbe':
  25132. object = new LightProbe().fromJSON(data);
  25133. break;
  25134. case 'SkinnedMesh':
  25135. geometry = getGeometry(data.geometry);
  25136. material = getMaterial(data.material);
  25137. object = new SkinnedMesh(geometry, material);
  25138. if (data.bindMode !== undefined) object.bindMode = data.bindMode;
  25139. if (data.bindMatrix !== undefined) object.bindMatrix.fromArray(data.bindMatrix);
  25140. if (data.skeleton !== undefined) object.skeleton = data.skeleton;
  25141. break;
  25142. case 'Mesh':
  25143. geometry = getGeometry(data.geometry);
  25144. material = getMaterial(data.material);
  25145. object = new Mesh(geometry, material);
  25146. break;
  25147. case 'InstancedMesh':
  25148. geometry = getGeometry(data.geometry);
  25149. material = getMaterial(data.material);
  25150. var count = data.count;
  25151. var instanceMatrix = data.instanceMatrix;
  25152. object = new InstancedMesh(geometry, material, count);
  25153. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  25154. break;
  25155. case 'LOD':
  25156. object = new LOD();
  25157. break;
  25158. case 'Line':
  25159. object = new Line(getGeometry(data.geometry), getMaterial(data.material), data.mode);
  25160. break;
  25161. case 'LineLoop':
  25162. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  25163. break;
  25164. case 'LineSegments':
  25165. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  25166. break;
  25167. case 'PointCloud':
  25168. case 'Points':
  25169. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  25170. break;
  25171. case 'Sprite':
  25172. object = new Sprite(getMaterial(data.material));
  25173. break;
  25174. case 'Group':
  25175. object = new Group();
  25176. break;
  25177. case 'Bone':
  25178. object = new Bone();
  25179. break;
  25180. default:
  25181. object = new Object3D();
  25182. }
  25183. object.uuid = data.uuid;
  25184. if (data.name !== undefined) object.name = data.name;
  25185. if (data.matrix !== undefined) {
  25186. object.matrix.fromArray(data.matrix);
  25187. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  25188. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  25189. } else {
  25190. if (data.position !== undefined) object.position.fromArray(data.position);
  25191. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  25192. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  25193. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  25194. }
  25195. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  25196. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  25197. if (data.shadow) {
  25198. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  25199. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  25200. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  25201. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  25202. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  25203. }
  25204. if (data.visible !== undefined) object.visible = data.visible;
  25205. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  25206. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  25207. if (data.userData !== undefined) object.userData = data.userData;
  25208. if (data.layers !== undefined) object.layers.mask = data.layers;
  25209. if (data.children !== undefined) {
  25210. var children = data.children;
  25211. for (var i = 0; i < children.length; i++) {
  25212. object.add(this.parseObject(children[i], geometries, materials, animations));
  25213. }
  25214. }
  25215. if (data.animations !== undefined) {
  25216. var objectAnimations = data.animations;
  25217. for (var _i = 0; _i < objectAnimations.length; _i++) {
  25218. var uuid = objectAnimations[_i];
  25219. object.animations.push(animations[uuid]);
  25220. }
  25221. }
  25222. if (data.type === 'LOD') {
  25223. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  25224. var levels = data.levels;
  25225. for (var l = 0; l < levels.length; l++) {
  25226. var level = levels[l];
  25227. var child = object.getObjectByProperty('uuid', level.object);
  25228. if (child !== undefined) {
  25229. object.addLevel(child, level.distance);
  25230. }
  25231. }
  25232. }
  25233. return object;
  25234. };
  25235. _proto.bindSkeletons = function bindSkeletons(object, skeletons) {
  25236. if (Object.keys(skeletons).length === 0) return;
  25237. object.traverse(function (child) {
  25238. if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
  25239. var skeleton = skeletons[child.skeleton];
  25240. if (skeleton === undefined) {
  25241. console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton);
  25242. } else {
  25243. child.bind(skeleton, child.bindMatrix);
  25244. }
  25245. }
  25246. });
  25247. }
  25248. /* DEPRECATED */
  25249. ;
  25250. _proto.setTexturePath = function setTexturePath(value) {
  25251. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  25252. return this.setResourcePath(value);
  25253. };
  25254. return ObjectLoader;
  25255. }(Loader);
  25256. var TEXTURE_MAPPING = {
  25257. UVMapping: UVMapping,
  25258. CubeReflectionMapping: CubeReflectionMapping,
  25259. CubeRefractionMapping: CubeRefractionMapping,
  25260. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  25261. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  25262. CubeUVReflectionMapping: CubeUVReflectionMapping,
  25263. CubeUVRefractionMapping: CubeUVRefractionMapping
  25264. };
  25265. var TEXTURE_WRAPPING = {
  25266. RepeatWrapping: RepeatWrapping,
  25267. ClampToEdgeWrapping: ClampToEdgeWrapping,
  25268. MirroredRepeatWrapping: MirroredRepeatWrapping
  25269. };
  25270. var TEXTURE_FILTER = {
  25271. NearestFilter: NearestFilter,
  25272. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  25273. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  25274. LinearFilter: LinearFilter,
  25275. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  25276. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  25277. };
  25278. function ImageBitmapLoader(manager) {
  25279. if (typeof createImageBitmap === 'undefined') {
  25280. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  25281. }
  25282. if (typeof fetch === 'undefined') {
  25283. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  25284. }
  25285. Loader.call(this, manager);
  25286. this.options = {
  25287. premultiplyAlpha: 'none'
  25288. };
  25289. }
  25290. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25291. constructor: ImageBitmapLoader,
  25292. isImageBitmapLoader: true,
  25293. setOptions: function setOptions(options) {
  25294. this.options = options;
  25295. return this;
  25296. },
  25297. load: function load(url, onLoad, onProgress, onError) {
  25298. if (url === undefined) url = '';
  25299. if (this.path !== undefined) url = this.path + url;
  25300. url = this.manager.resolveURL(url);
  25301. var scope = this;
  25302. var cached = Cache.get(url);
  25303. if (cached !== undefined) {
  25304. scope.manager.itemStart(url);
  25305. setTimeout(function () {
  25306. if (onLoad) onLoad(cached);
  25307. scope.manager.itemEnd(url);
  25308. }, 0);
  25309. return cached;
  25310. }
  25311. var fetchOptions = {};
  25312. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  25313. fetch(url, fetchOptions).then(function (res) {
  25314. return res.blob();
  25315. }).then(function (blob) {
  25316. return createImageBitmap(blob, scope.options);
  25317. }).then(function (imageBitmap) {
  25318. Cache.add(url, imageBitmap);
  25319. if (onLoad) onLoad(imageBitmap);
  25320. scope.manager.itemEnd(url);
  25321. }).catch(function (e) {
  25322. if (onError) onError(e);
  25323. scope.manager.itemError(url);
  25324. scope.manager.itemEnd(url);
  25325. });
  25326. scope.manager.itemStart(url);
  25327. }
  25328. });
  25329. function ShapePath() {
  25330. this.type = 'ShapePath';
  25331. this.color = new Color();
  25332. this.subPaths = [];
  25333. this.currentPath = null;
  25334. }
  25335. Object.assign(ShapePath.prototype, {
  25336. moveTo: function moveTo(x, y) {
  25337. this.currentPath = new Path();
  25338. this.subPaths.push(this.currentPath);
  25339. this.currentPath.moveTo(x, y);
  25340. return this;
  25341. },
  25342. lineTo: function lineTo(x, y) {
  25343. this.currentPath.lineTo(x, y);
  25344. return this;
  25345. },
  25346. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  25347. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  25348. return this;
  25349. },
  25350. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  25351. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  25352. return this;
  25353. },
  25354. splineThru: function splineThru(pts) {
  25355. this.currentPath.splineThru(pts);
  25356. return this;
  25357. },
  25358. toShapes: function toShapes(isCCW, noHoles) {
  25359. function toShapesNoHoles(inSubpaths) {
  25360. var shapes = [];
  25361. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  25362. var _tmpPath = inSubpaths[i];
  25363. var _tmpShape = new Shape();
  25364. _tmpShape.curves = _tmpPath.curves;
  25365. shapes.push(_tmpShape);
  25366. }
  25367. return shapes;
  25368. }
  25369. function isPointInsidePolygon(inPt, inPolygon) {
  25370. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  25371. // toggling of inside/outside at every single! intersection point of an edge
  25372. // with the horizontal line through inPt, left of inPt
  25373. // not counting lowerY endpoints of edges and whole edges on that line
  25374. var inside = false;
  25375. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  25376. var edgeLowPt = inPolygon[p];
  25377. var edgeHighPt = inPolygon[q];
  25378. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  25379. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  25380. if (Math.abs(edgeDy) > Number.EPSILON) {
  25381. // not parallel
  25382. if (edgeDy < 0) {
  25383. edgeLowPt = inPolygon[q];
  25384. edgeDx = -edgeDx;
  25385. edgeHighPt = inPolygon[p];
  25386. edgeDy = -edgeDy;
  25387. }
  25388. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  25389. if (inPt.y === edgeLowPt.y) {
  25390. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  25391. // continue; // no intersection or edgeLowPt => doesn't count !!!
  25392. } else {
  25393. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  25394. if (perpEdge === 0) return true; // inPt is on contour ?
  25395. if (perpEdge < 0) continue;
  25396. inside = !inside; // true intersection left of inPt
  25397. }
  25398. } else {
  25399. // parallel or collinear
  25400. if (inPt.y !== edgeLowPt.y) continue; // parallel
  25401. // edge lies on the same horizontal line as inPt
  25402. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  25403. // continue;
  25404. }
  25405. }
  25406. return inside;
  25407. }
  25408. var isClockWise = ShapeUtils.isClockWise;
  25409. var subPaths = this.subPaths;
  25410. if (subPaths.length === 0) return [];
  25411. if (noHoles === true) return toShapesNoHoles(subPaths);
  25412. var solid, tmpPath, tmpShape;
  25413. var shapes = [];
  25414. if (subPaths.length === 1) {
  25415. tmpPath = subPaths[0];
  25416. tmpShape = new Shape();
  25417. tmpShape.curves = tmpPath.curves;
  25418. shapes.push(tmpShape);
  25419. return shapes;
  25420. }
  25421. var holesFirst = !isClockWise(subPaths[0].getPoints());
  25422. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  25423. var betterShapeHoles = [];
  25424. var newShapes = [];
  25425. var newShapeHoles = [];
  25426. var mainIdx = 0;
  25427. var tmpPoints;
  25428. newShapes[mainIdx] = undefined;
  25429. newShapeHoles[mainIdx] = [];
  25430. for (var i = 0, l = subPaths.length; i < l; i++) {
  25431. tmpPath = subPaths[i];
  25432. tmpPoints = tmpPath.getPoints();
  25433. solid = isClockWise(tmpPoints);
  25434. solid = isCCW ? !solid : solid;
  25435. if (solid) {
  25436. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  25437. newShapes[mainIdx] = {
  25438. s: new Shape(),
  25439. p: tmpPoints
  25440. };
  25441. newShapes[mainIdx].s.curves = tmpPath.curves;
  25442. if (holesFirst) mainIdx++;
  25443. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  25444. } else {
  25445. newShapeHoles[mainIdx].push({
  25446. h: tmpPath,
  25447. p: tmpPoints[0]
  25448. }); //console.log('ccw', i);
  25449. }
  25450. } // only Holes? -> probably all Shapes with wrong orientation
  25451. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  25452. if (newShapes.length > 1) {
  25453. var ambiguous = false;
  25454. var toChange = [];
  25455. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  25456. betterShapeHoles[sIdx] = [];
  25457. }
  25458. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  25459. var sho = newShapeHoles[_sIdx];
  25460. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  25461. var ho = sho[hIdx];
  25462. var hole_unassigned = true;
  25463. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  25464. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  25465. if (_sIdx !== s2Idx) toChange.push({
  25466. froms: _sIdx,
  25467. tos: s2Idx,
  25468. hole: hIdx
  25469. });
  25470. if (hole_unassigned) {
  25471. hole_unassigned = false;
  25472. betterShapeHoles[s2Idx].push(ho);
  25473. } else {
  25474. ambiguous = true;
  25475. }
  25476. }
  25477. }
  25478. if (hole_unassigned) {
  25479. betterShapeHoles[_sIdx].push(ho);
  25480. }
  25481. }
  25482. } // console.log("ambiguous: ", ambiguous);
  25483. if (toChange.length > 0) {
  25484. // console.log("to change: ", toChange);
  25485. if (!ambiguous) newShapeHoles = betterShapeHoles;
  25486. }
  25487. }
  25488. var tmpHoles;
  25489. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  25490. tmpShape = newShapes[_i].s;
  25491. shapes.push(tmpShape);
  25492. tmpHoles = newShapeHoles[_i];
  25493. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  25494. tmpShape.holes.push(tmpHoles[j].h);
  25495. }
  25496. } //console.log("shape", shapes);
  25497. return shapes;
  25498. }
  25499. });
  25500. function Font(data) {
  25501. this.type = 'Font';
  25502. this.data = data;
  25503. }
  25504. Object.assign(Font.prototype, {
  25505. isFont: true,
  25506. generateShapes: function generateShapes(text, size) {
  25507. if (size === void 0) {
  25508. size = 100;
  25509. }
  25510. var shapes = [];
  25511. var paths = createPaths(text, size, this.data);
  25512. for (var p = 0, pl = paths.length; p < pl; p++) {
  25513. Array.prototype.push.apply(shapes, paths[p].toShapes());
  25514. }
  25515. return shapes;
  25516. }
  25517. });
  25518. function createPaths(text, size, data) {
  25519. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  25520. var scale = size / data.resolution;
  25521. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  25522. var paths = [];
  25523. var offsetX = 0,
  25524. offsetY = 0;
  25525. for (var i = 0; i < chars.length; i++) {
  25526. var char = chars[i];
  25527. if (char === '\n') {
  25528. offsetX = 0;
  25529. offsetY -= line_height;
  25530. } else {
  25531. var ret = createPath(char, scale, offsetX, offsetY, data);
  25532. offsetX += ret.offsetX;
  25533. paths.push(ret.path);
  25534. }
  25535. }
  25536. return paths;
  25537. }
  25538. function createPath(char, scale, offsetX, offsetY, data) {
  25539. var glyph = data.glyphs[char] || data.glyphs['?'];
  25540. if (!glyph) {
  25541. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  25542. return;
  25543. }
  25544. var path = new ShapePath();
  25545. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  25546. if (glyph.o) {
  25547. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  25548. for (var i = 0, l = outline.length; i < l;) {
  25549. var action = outline[i++];
  25550. switch (action) {
  25551. case 'm':
  25552. // moveTo
  25553. x = outline[i++] * scale + offsetX;
  25554. y = outline[i++] * scale + offsetY;
  25555. path.moveTo(x, y);
  25556. break;
  25557. case 'l':
  25558. // lineTo
  25559. x = outline[i++] * scale + offsetX;
  25560. y = outline[i++] * scale + offsetY;
  25561. path.lineTo(x, y);
  25562. break;
  25563. case 'q':
  25564. // quadraticCurveTo
  25565. cpx = outline[i++] * scale + offsetX;
  25566. cpy = outline[i++] * scale + offsetY;
  25567. cpx1 = outline[i++] * scale + offsetX;
  25568. cpy1 = outline[i++] * scale + offsetY;
  25569. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  25570. break;
  25571. case 'b':
  25572. // bezierCurveTo
  25573. cpx = outline[i++] * scale + offsetX;
  25574. cpy = outline[i++] * scale + offsetY;
  25575. cpx1 = outline[i++] * scale + offsetX;
  25576. cpy1 = outline[i++] * scale + offsetY;
  25577. cpx2 = outline[i++] * scale + offsetX;
  25578. cpy2 = outline[i++] * scale + offsetY;
  25579. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  25580. break;
  25581. }
  25582. }
  25583. }
  25584. return {
  25585. offsetX: glyph.ha * scale,
  25586. path: path
  25587. };
  25588. }
  25589. function FontLoader(manager) {
  25590. Loader.call(this, manager);
  25591. }
  25592. FontLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25593. constructor: FontLoader,
  25594. load: function load(url, onLoad, onProgress, onError) {
  25595. var scope = this;
  25596. var loader = new FileLoader(this.manager);
  25597. loader.setPath(this.path);
  25598. loader.setRequestHeader(this.requestHeader);
  25599. loader.setWithCredentials(scope.withCredentials);
  25600. loader.load(url, function (text) {
  25601. var json;
  25602. try {
  25603. json = JSON.parse(text);
  25604. } catch (e) {
  25605. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  25606. json = JSON.parse(text.substring(65, text.length - 2));
  25607. }
  25608. var font = scope.parse(json);
  25609. if (onLoad) onLoad(font);
  25610. }, onProgress, onError);
  25611. },
  25612. parse: function parse(json) {
  25613. return new Font(json);
  25614. }
  25615. });
  25616. var _context;
  25617. var AudioContext = {
  25618. getContext: function getContext() {
  25619. if (_context === undefined) {
  25620. _context = new (window.AudioContext || window.webkitAudioContext)();
  25621. }
  25622. return _context;
  25623. },
  25624. setContext: function setContext(value) {
  25625. _context = value;
  25626. }
  25627. };
  25628. function AudioLoader(manager) {
  25629. Loader.call(this, manager);
  25630. }
  25631. AudioLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25632. constructor: AudioLoader,
  25633. load: function load(url, onLoad, onProgress, onError) {
  25634. var scope = this;
  25635. var loader = new FileLoader(scope.manager);
  25636. loader.setResponseType('arraybuffer');
  25637. loader.setPath(scope.path);
  25638. loader.setRequestHeader(scope.requestHeader);
  25639. loader.setWithCredentials(scope.withCredentials);
  25640. loader.load(url, function (buffer) {
  25641. try {
  25642. // Create a copy of the buffer. The `decodeAudioData` method
  25643. // detaches the buffer when complete, preventing reuse.
  25644. var bufferCopy = buffer.slice(0);
  25645. var context = AudioContext.getContext();
  25646. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  25647. onLoad(audioBuffer);
  25648. });
  25649. } catch (e) {
  25650. if (onError) {
  25651. onError(e);
  25652. } else {
  25653. console.error(e);
  25654. }
  25655. scope.manager.itemError(url);
  25656. }
  25657. }, onProgress, onError);
  25658. }
  25659. });
  25660. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  25661. LightProbe.call(this, undefined, intensity);
  25662. var color1 = new Color().set(skyColor);
  25663. var color2 = new Color().set(groundColor);
  25664. var sky = new Vector3(color1.r, color1.g, color1.b);
  25665. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25666. var c0 = Math.sqrt(Math.PI);
  25667. var c1 = c0 * Math.sqrt(0.75);
  25668. this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  25669. this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  25670. }
  25671. HemisphereLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25672. constructor: HemisphereLightProbe,
  25673. isHemisphereLightProbe: true,
  25674. copy: function copy(source) {
  25675. // modifying colors not currently supported
  25676. LightProbe.prototype.copy.call(this, source);
  25677. return this;
  25678. },
  25679. toJSON: function toJSON(meta) {
  25680. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25681. return data;
  25682. }
  25683. });
  25684. function AmbientLightProbe(color, intensity) {
  25685. LightProbe.call(this, undefined, intensity);
  25686. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25687. this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  25688. }
  25689. AmbientLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25690. constructor: AmbientLightProbe,
  25691. isAmbientLightProbe: true,
  25692. copy: function copy(source) {
  25693. // modifying color not currently supported
  25694. LightProbe.prototype.copy.call(this, source);
  25695. return this;
  25696. },
  25697. toJSON: function toJSON(meta) {
  25698. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25699. return data;
  25700. }
  25701. });
  25702. var _eyeRight = new Matrix4();
  25703. var _eyeLeft = new Matrix4();
  25704. function StereoCamera() {
  25705. this.type = 'StereoCamera';
  25706. this.aspect = 1;
  25707. this.eyeSep = 0.064;
  25708. this.cameraL = new PerspectiveCamera();
  25709. this.cameraL.layers.enable(1);
  25710. this.cameraL.matrixAutoUpdate = false;
  25711. this.cameraR = new PerspectiveCamera();
  25712. this.cameraR.layers.enable(2);
  25713. this.cameraR.matrixAutoUpdate = false;
  25714. this._cache = {
  25715. focus: null,
  25716. fov: null,
  25717. aspect: null,
  25718. near: null,
  25719. far: null,
  25720. zoom: null,
  25721. eyeSep: null
  25722. };
  25723. }
  25724. Object.assign(StereoCamera.prototype, {
  25725. update: function update(camera) {
  25726. var cache = this._cache;
  25727. 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;
  25728. if (needsUpdate) {
  25729. cache.focus = camera.focus;
  25730. cache.fov = camera.fov;
  25731. cache.aspect = camera.aspect * this.aspect;
  25732. cache.near = camera.near;
  25733. cache.far = camera.far;
  25734. cache.zoom = camera.zoom;
  25735. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25736. // http://paulbourke.net/stereographics/stereorender/
  25737. var projectionMatrix = camera.projectionMatrix.clone();
  25738. var eyeSepHalf = cache.eyeSep / 2;
  25739. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25740. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25741. var xmin, xmax; // translate xOffset
  25742. _eyeLeft.elements[12] = -eyeSepHalf;
  25743. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25744. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25745. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25746. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25747. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25748. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25749. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25750. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25751. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25752. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25753. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25754. }
  25755. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25756. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25757. }
  25758. });
  25759. var Clock = /*#__PURE__*/function () {
  25760. function Clock(autoStart) {
  25761. this.autoStart = autoStart !== undefined ? autoStart : true;
  25762. this.startTime = 0;
  25763. this.oldTime = 0;
  25764. this.elapsedTime = 0;
  25765. this.running = false;
  25766. }
  25767. var _proto = Clock.prototype;
  25768. _proto.start = function start() {
  25769. this.startTime = now();
  25770. this.oldTime = this.startTime;
  25771. this.elapsedTime = 0;
  25772. this.running = true;
  25773. };
  25774. _proto.stop = function stop() {
  25775. this.getElapsedTime();
  25776. this.running = false;
  25777. this.autoStart = false;
  25778. };
  25779. _proto.getElapsedTime = function getElapsedTime() {
  25780. this.getDelta();
  25781. return this.elapsedTime;
  25782. };
  25783. _proto.getDelta = function getDelta() {
  25784. var diff = 0;
  25785. if (this.autoStart && !this.running) {
  25786. this.start();
  25787. return 0;
  25788. }
  25789. if (this.running) {
  25790. var newTime = now();
  25791. diff = (newTime - this.oldTime) / 1000;
  25792. this.oldTime = newTime;
  25793. this.elapsedTime += diff;
  25794. }
  25795. return diff;
  25796. };
  25797. return Clock;
  25798. }();
  25799. function now() {
  25800. return (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25801. }
  25802. var _position$2 = /*@__PURE__*/new Vector3();
  25803. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25804. var _scale$1 = /*@__PURE__*/new Vector3();
  25805. var _orientation = /*@__PURE__*/new Vector3();
  25806. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25807. _inheritsLoose(AudioListener, _Object3D);
  25808. function AudioListener() {
  25809. var _this;
  25810. _this = _Object3D.call(this) || this;
  25811. _this.type = 'AudioListener';
  25812. _this.context = AudioContext.getContext();
  25813. _this.gain = _this.context.createGain();
  25814. _this.gain.connect(_this.context.destination);
  25815. _this.filter = null;
  25816. _this.timeDelta = 0; // private
  25817. _this._clock = new Clock();
  25818. return _this;
  25819. }
  25820. var _proto = AudioListener.prototype;
  25821. _proto.getInput = function getInput() {
  25822. return this.gain;
  25823. };
  25824. _proto.removeFilter = function removeFilter() {
  25825. if (this.filter !== null) {
  25826. this.gain.disconnect(this.filter);
  25827. this.filter.disconnect(this.context.destination);
  25828. this.gain.connect(this.context.destination);
  25829. this.filter = null;
  25830. }
  25831. return this;
  25832. };
  25833. _proto.getFilter = function getFilter() {
  25834. return this.filter;
  25835. };
  25836. _proto.setFilter = function setFilter(value) {
  25837. if (this.filter !== null) {
  25838. this.gain.disconnect(this.filter);
  25839. this.filter.disconnect(this.context.destination);
  25840. } else {
  25841. this.gain.disconnect(this.context.destination);
  25842. }
  25843. this.filter = value;
  25844. this.gain.connect(this.filter);
  25845. this.filter.connect(this.context.destination);
  25846. return this;
  25847. };
  25848. _proto.getMasterVolume = function getMasterVolume() {
  25849. return this.gain.gain.value;
  25850. };
  25851. _proto.setMasterVolume = function setMasterVolume(value) {
  25852. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25853. return this;
  25854. };
  25855. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25856. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25857. var listener = this.context.listener;
  25858. var up = this.up;
  25859. this.timeDelta = this._clock.getDelta();
  25860. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25861. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25862. if (listener.positionX) {
  25863. // code path for Chrome (see #14393)
  25864. var endTime = this.context.currentTime + this.timeDelta;
  25865. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25866. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25867. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25868. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25869. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25870. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25871. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25872. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25873. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25874. } else {
  25875. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25876. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25877. }
  25878. };
  25879. return AudioListener;
  25880. }(Object3D);
  25881. var Audio = /*#__PURE__*/function (_Object3D) {
  25882. _inheritsLoose(Audio, _Object3D);
  25883. function Audio(listener) {
  25884. var _this;
  25885. _this = _Object3D.call(this) || this;
  25886. _this.type = 'Audio';
  25887. _this.listener = listener;
  25888. _this.context = listener.context;
  25889. _this.gain = _this.context.createGain();
  25890. _this.gain.connect(listener.getInput());
  25891. _this.autoplay = false;
  25892. _this.buffer = null;
  25893. _this.detune = 0;
  25894. _this.loop = false;
  25895. _this.loopStart = 0;
  25896. _this.loopEnd = 0;
  25897. _this.offset = 0;
  25898. _this.duration = undefined;
  25899. _this.playbackRate = 1;
  25900. _this.isPlaying = false;
  25901. _this.hasPlaybackControl = true;
  25902. _this.source = null;
  25903. _this.sourceType = 'empty';
  25904. _this._startedAt = 0;
  25905. _this._progress = 0;
  25906. _this._connected = false;
  25907. _this.filters = [];
  25908. return _this;
  25909. }
  25910. var _proto = Audio.prototype;
  25911. _proto.getOutput = function getOutput() {
  25912. return this.gain;
  25913. };
  25914. _proto.setNodeSource = function setNodeSource(audioNode) {
  25915. this.hasPlaybackControl = false;
  25916. this.sourceType = 'audioNode';
  25917. this.source = audioNode;
  25918. this.connect();
  25919. return this;
  25920. };
  25921. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25922. this.hasPlaybackControl = false;
  25923. this.sourceType = 'mediaNode';
  25924. this.source = this.context.createMediaElementSource(mediaElement);
  25925. this.connect();
  25926. return this;
  25927. };
  25928. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25929. this.hasPlaybackControl = false;
  25930. this.sourceType = 'mediaStreamNode';
  25931. this.source = this.context.createMediaStreamSource(mediaStream);
  25932. this.connect();
  25933. return this;
  25934. };
  25935. _proto.setBuffer = function setBuffer(audioBuffer) {
  25936. this.buffer = audioBuffer;
  25937. this.sourceType = 'buffer';
  25938. if (this.autoplay) this.play();
  25939. return this;
  25940. };
  25941. _proto.play = function play(delay) {
  25942. if (delay === void 0) {
  25943. delay = 0;
  25944. }
  25945. if (this.isPlaying === true) {
  25946. console.warn('THREE.Audio: Audio is already playing.');
  25947. return;
  25948. }
  25949. if (this.hasPlaybackControl === false) {
  25950. console.warn('THREE.Audio: this Audio has no playback control.');
  25951. return;
  25952. }
  25953. this._startedAt = this.context.currentTime + delay;
  25954. var source = this.context.createBufferSource();
  25955. source.buffer = this.buffer;
  25956. source.loop = this.loop;
  25957. source.loopStart = this.loopStart;
  25958. source.loopEnd = this.loopEnd;
  25959. source.onended = this.onEnded.bind(this);
  25960. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25961. this.isPlaying = true;
  25962. this.source = source;
  25963. this.setDetune(this.detune);
  25964. this.setPlaybackRate(this.playbackRate);
  25965. return this.connect();
  25966. };
  25967. _proto.pause = function pause() {
  25968. if (this.hasPlaybackControl === false) {
  25969. console.warn('THREE.Audio: this Audio has no playback control.');
  25970. return;
  25971. }
  25972. if (this.isPlaying === true) {
  25973. // update current progress
  25974. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  25975. if (this.loop === true) {
  25976. // ensure _progress does not exceed duration with looped audios
  25977. this._progress = this._progress % (this.duration || this.buffer.duration);
  25978. }
  25979. this.source.stop();
  25980. this.source.onended = null;
  25981. this.isPlaying = false;
  25982. }
  25983. return this;
  25984. };
  25985. _proto.stop = function stop() {
  25986. if (this.hasPlaybackControl === false) {
  25987. console.warn('THREE.Audio: this Audio has no playback control.');
  25988. return;
  25989. }
  25990. this._progress = 0;
  25991. this.source.stop();
  25992. this.source.onended = null;
  25993. this.isPlaying = false;
  25994. return this;
  25995. };
  25996. _proto.connect = function connect() {
  25997. if (this.filters.length > 0) {
  25998. this.source.connect(this.filters[0]);
  25999. for (var i = 1, l = this.filters.length; i < l; i++) {
  26000. this.filters[i - 1].connect(this.filters[i]);
  26001. }
  26002. this.filters[this.filters.length - 1].connect(this.getOutput());
  26003. } else {
  26004. this.source.connect(this.getOutput());
  26005. }
  26006. this._connected = true;
  26007. return this;
  26008. };
  26009. _proto.disconnect = function disconnect() {
  26010. if (this.filters.length > 0) {
  26011. this.source.disconnect(this.filters[0]);
  26012. for (var i = 1, l = this.filters.length; i < l; i++) {
  26013. this.filters[i - 1].disconnect(this.filters[i]);
  26014. }
  26015. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  26016. } else {
  26017. this.source.disconnect(this.getOutput());
  26018. }
  26019. this._connected = false;
  26020. return this;
  26021. };
  26022. _proto.getFilters = function getFilters() {
  26023. return this.filters;
  26024. };
  26025. _proto.setFilters = function setFilters(value) {
  26026. if (!value) value = [];
  26027. if (this._connected === true) {
  26028. this.disconnect();
  26029. this.filters = value.slice();
  26030. this.connect();
  26031. } else {
  26032. this.filters = value.slice();
  26033. }
  26034. return this;
  26035. };
  26036. _proto.setDetune = function setDetune(value) {
  26037. this.detune = value;
  26038. if (this.source.detune === undefined) return; // only set detune when available
  26039. if (this.isPlaying === true) {
  26040. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  26041. }
  26042. return this;
  26043. };
  26044. _proto.getDetune = function getDetune() {
  26045. return this.detune;
  26046. };
  26047. _proto.getFilter = function getFilter() {
  26048. return this.getFilters()[0];
  26049. };
  26050. _proto.setFilter = function setFilter(filter) {
  26051. return this.setFilters(filter ? [filter] : []);
  26052. };
  26053. _proto.setPlaybackRate = function setPlaybackRate(value) {
  26054. if (this.hasPlaybackControl === false) {
  26055. console.warn('THREE.Audio: this Audio has no playback control.');
  26056. return;
  26057. }
  26058. this.playbackRate = value;
  26059. if (this.isPlaying === true) {
  26060. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  26061. }
  26062. return this;
  26063. };
  26064. _proto.getPlaybackRate = function getPlaybackRate() {
  26065. return this.playbackRate;
  26066. };
  26067. _proto.onEnded = function onEnded() {
  26068. this.isPlaying = false;
  26069. };
  26070. _proto.getLoop = function getLoop() {
  26071. if (this.hasPlaybackControl === false) {
  26072. console.warn('THREE.Audio: this Audio has no playback control.');
  26073. return false;
  26074. }
  26075. return this.loop;
  26076. };
  26077. _proto.setLoop = function setLoop(value) {
  26078. if (this.hasPlaybackControl === false) {
  26079. console.warn('THREE.Audio: this Audio has no playback control.');
  26080. return;
  26081. }
  26082. this.loop = value;
  26083. if (this.isPlaying === true) {
  26084. this.source.loop = this.loop;
  26085. }
  26086. return this;
  26087. };
  26088. _proto.setLoopStart = function setLoopStart(value) {
  26089. this.loopStart = value;
  26090. return this;
  26091. };
  26092. _proto.setLoopEnd = function setLoopEnd(value) {
  26093. this.loopEnd = value;
  26094. return this;
  26095. };
  26096. _proto.getVolume = function getVolume() {
  26097. return this.gain.gain.value;
  26098. };
  26099. _proto.setVolume = function setVolume(value) {
  26100. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  26101. return this;
  26102. };
  26103. return Audio;
  26104. }(Object3D);
  26105. var _position$3 = /*@__PURE__*/new Vector3();
  26106. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  26107. var _scale$2 = /*@__PURE__*/new Vector3();
  26108. var _orientation$1 = /*@__PURE__*/new Vector3();
  26109. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  26110. _inheritsLoose(PositionalAudio, _Audio);
  26111. function PositionalAudio(listener) {
  26112. var _this;
  26113. _this = _Audio.call(this, listener) || this;
  26114. _this.panner = _this.context.createPanner();
  26115. _this.panner.panningModel = 'HRTF';
  26116. _this.panner.connect(_this.gain);
  26117. return _this;
  26118. }
  26119. var _proto = PositionalAudio.prototype;
  26120. _proto.getOutput = function getOutput() {
  26121. return this.panner;
  26122. };
  26123. _proto.getRefDistance = function getRefDistance() {
  26124. return this.panner.refDistance;
  26125. };
  26126. _proto.setRefDistance = function setRefDistance(value) {
  26127. this.panner.refDistance = value;
  26128. return this;
  26129. };
  26130. _proto.getRolloffFactor = function getRolloffFactor() {
  26131. return this.panner.rolloffFactor;
  26132. };
  26133. _proto.setRolloffFactor = function setRolloffFactor(value) {
  26134. this.panner.rolloffFactor = value;
  26135. return this;
  26136. };
  26137. _proto.getDistanceModel = function getDistanceModel() {
  26138. return this.panner.distanceModel;
  26139. };
  26140. _proto.setDistanceModel = function setDistanceModel(value) {
  26141. this.panner.distanceModel = value;
  26142. return this;
  26143. };
  26144. _proto.getMaxDistance = function getMaxDistance() {
  26145. return this.panner.maxDistance;
  26146. };
  26147. _proto.setMaxDistance = function setMaxDistance(value) {
  26148. this.panner.maxDistance = value;
  26149. return this;
  26150. };
  26151. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  26152. this.panner.coneInnerAngle = coneInnerAngle;
  26153. this.panner.coneOuterAngle = coneOuterAngle;
  26154. this.panner.coneOuterGain = coneOuterGain;
  26155. return this;
  26156. };
  26157. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  26158. _Audio.prototype.updateMatrixWorld.call(this, force);
  26159. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  26160. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  26161. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  26162. var panner = this.panner;
  26163. if (panner.positionX) {
  26164. // code path for Chrome and Firefox (see #14393)
  26165. var endTime = this.context.currentTime + this.listener.timeDelta;
  26166. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  26167. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  26168. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  26169. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  26170. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  26171. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  26172. } else {
  26173. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  26174. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  26175. }
  26176. };
  26177. return PositionalAudio;
  26178. }(Audio);
  26179. var AudioAnalyser = /*#__PURE__*/function () {
  26180. function AudioAnalyser(audio, fftSize) {
  26181. if (fftSize === void 0) {
  26182. fftSize = 2048;
  26183. }
  26184. this.analyser = audio.context.createAnalyser();
  26185. this.analyser.fftSize = fftSize;
  26186. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  26187. audio.getOutput().connect(this.analyser);
  26188. }
  26189. var _proto = AudioAnalyser.prototype;
  26190. _proto.getFrequencyData = function getFrequencyData() {
  26191. this.analyser.getByteFrequencyData(this.data);
  26192. return this.data;
  26193. };
  26194. _proto.getAverageFrequency = function getAverageFrequency() {
  26195. var value = 0;
  26196. var data = this.getFrequencyData();
  26197. for (var i = 0; i < data.length; i++) {
  26198. value += data[i];
  26199. }
  26200. return value / data.length;
  26201. };
  26202. return AudioAnalyser;
  26203. }();
  26204. function PropertyMixer(binding, typeName, valueSize) {
  26205. this.binding = binding;
  26206. this.valueSize = valueSize;
  26207. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  26208. //
  26209. // interpolators can use .buffer as their .result
  26210. // the data then goes to 'incoming'
  26211. //
  26212. // 'accu0' and 'accu1' are used frame-interleaved for
  26213. // the cumulative result and are compared to detect
  26214. // changes
  26215. //
  26216. // 'orig' stores the original state of the property
  26217. //
  26218. // 'add' is used for additive cumulative results
  26219. //
  26220. // 'work' is optional and is only present for quaternion types. It is used
  26221. // to store intermediate quaternion multiplication results
  26222. switch (typeName) {
  26223. case 'quaternion':
  26224. mixFunction = this._slerp;
  26225. mixFunctionAdditive = this._slerpAdditive;
  26226. setIdentity = this._setAdditiveIdentityQuaternion;
  26227. this.buffer = new Float64Array(valueSize * 6);
  26228. this._workIndex = 5;
  26229. break;
  26230. case 'string':
  26231. case 'bool':
  26232. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  26233. // additive is not relevant for non-numeric types
  26234. mixFunctionAdditive = this._select;
  26235. setIdentity = this._setAdditiveIdentityOther;
  26236. this.buffer = new Array(valueSize * 5);
  26237. break;
  26238. default:
  26239. mixFunction = this._lerp;
  26240. mixFunctionAdditive = this._lerpAdditive;
  26241. setIdentity = this._setAdditiveIdentityNumeric;
  26242. this.buffer = new Float64Array(valueSize * 5);
  26243. }
  26244. this._mixBufferRegion = mixFunction;
  26245. this._mixBufferRegionAdditive = mixFunctionAdditive;
  26246. this._setIdentity = setIdentity;
  26247. this._origIndex = 3;
  26248. this._addIndex = 4;
  26249. this.cumulativeWeight = 0;
  26250. this.cumulativeWeightAdditive = 0;
  26251. this.useCount = 0;
  26252. this.referenceCount = 0;
  26253. }
  26254. Object.assign(PropertyMixer.prototype, {
  26255. // accumulate data in the 'incoming' region into 'accu<i>'
  26256. accumulate: function accumulate(accuIndex, weight) {
  26257. // note: happily accumulating nothing when weight = 0, the caller knows
  26258. // the weight and shouldn't have made the call in the first place
  26259. var buffer = this.buffer,
  26260. stride = this.valueSize,
  26261. offset = accuIndex * stride + stride;
  26262. var currentWeight = this.cumulativeWeight;
  26263. if (currentWeight === 0) {
  26264. // accuN := incoming * weight
  26265. for (var i = 0; i !== stride; ++i) {
  26266. buffer[offset + i] = buffer[i];
  26267. }
  26268. currentWeight = weight;
  26269. } else {
  26270. // accuN := accuN + incoming * weight
  26271. currentWeight += weight;
  26272. var mix = weight / currentWeight;
  26273. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  26274. }
  26275. this.cumulativeWeight = currentWeight;
  26276. },
  26277. // accumulate data in the 'incoming' region into 'add'
  26278. accumulateAdditive: function accumulateAdditive(weight) {
  26279. var buffer = this.buffer,
  26280. stride = this.valueSize,
  26281. offset = stride * this._addIndex;
  26282. if (this.cumulativeWeightAdditive === 0) {
  26283. // add = identity
  26284. this._setIdentity();
  26285. } // add := add + incoming * weight
  26286. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  26287. this.cumulativeWeightAdditive += weight;
  26288. },
  26289. // apply the state of 'accu<i>' to the binding when accus differ
  26290. apply: function apply(accuIndex) {
  26291. var stride = this.valueSize,
  26292. buffer = this.buffer,
  26293. offset = accuIndex * stride + stride,
  26294. weight = this.cumulativeWeight,
  26295. weightAdditive = this.cumulativeWeightAdditive,
  26296. binding = this.binding;
  26297. this.cumulativeWeight = 0;
  26298. this.cumulativeWeightAdditive = 0;
  26299. if (weight < 1) {
  26300. // accuN := accuN + original * ( 1 - cumulativeWeight )
  26301. var originalValueOffset = stride * this._origIndex;
  26302. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  26303. }
  26304. if (weightAdditive > 0) {
  26305. // accuN := accuN + additive accuN
  26306. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  26307. }
  26308. for (var i = stride, e = stride + stride; i !== e; ++i) {
  26309. if (buffer[i] !== buffer[i + stride]) {
  26310. // value has changed -> update scene graph
  26311. binding.setValue(buffer, offset);
  26312. break;
  26313. }
  26314. }
  26315. },
  26316. // remember the state of the bound property and copy it to both accus
  26317. saveOriginalState: function saveOriginalState() {
  26318. var binding = this.binding;
  26319. var buffer = this.buffer,
  26320. stride = this.valueSize,
  26321. originalValueOffset = stride * this._origIndex;
  26322. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  26323. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  26324. buffer[i] = buffer[originalValueOffset + i % stride];
  26325. } // Add to identity for additive
  26326. this._setIdentity();
  26327. this.cumulativeWeight = 0;
  26328. this.cumulativeWeightAdditive = 0;
  26329. },
  26330. // apply the state previously taken via 'saveOriginalState' to the binding
  26331. restoreOriginalState: function restoreOriginalState() {
  26332. var originalValueOffset = this.valueSize * 3;
  26333. this.binding.setValue(this.buffer, originalValueOffset);
  26334. },
  26335. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  26336. var startIndex = this._addIndex * this.valueSize;
  26337. var endIndex = startIndex + this.valueSize;
  26338. for (var i = startIndex; i < endIndex; i++) {
  26339. this.buffer[i] = 0;
  26340. }
  26341. },
  26342. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  26343. this._setAdditiveIdentityNumeric();
  26344. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  26345. },
  26346. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  26347. var startIndex = this._origIndex * this.valueSize;
  26348. var targetIndex = this._addIndex * this.valueSize;
  26349. for (var i = 0; i < this.valueSize; i++) {
  26350. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  26351. }
  26352. },
  26353. // mix functions
  26354. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  26355. if (t >= 0.5) {
  26356. for (var i = 0; i !== stride; ++i) {
  26357. buffer[dstOffset + i] = buffer[srcOffset + i];
  26358. }
  26359. }
  26360. },
  26361. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  26362. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  26363. },
  26364. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  26365. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  26366. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  26367. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  26368. },
  26369. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  26370. var s = 1 - t;
  26371. for (var i = 0; i !== stride; ++i) {
  26372. var j = dstOffset + i;
  26373. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  26374. }
  26375. },
  26376. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  26377. for (var i = 0; i !== stride; ++i) {
  26378. var j = dstOffset + i;
  26379. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  26380. }
  26381. }
  26382. });
  26383. // Characters [].:/ are reserved for track binding syntax.
  26384. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  26385. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  26386. // only latin characters, and the unicode \p{L} is not yet supported. So
  26387. // instead, we exclude reserved characters and match everything else.
  26388. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  26389. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  26390. // be matched to parse the rest of the track name.
  26391. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  26392. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  26393. // characters. Accessor may contain any character except closing bracket.
  26394. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  26395. // contain any non-bracket characters.
  26396. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  26397. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  26398. var _supportedObjectNames = ['material', 'materials', 'bones'];
  26399. function Composite(targetGroup, path, optionalParsedPath) {
  26400. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  26401. this._targetGroup = targetGroup;
  26402. this._bindings = targetGroup.subscribe_(path, parsedPath);
  26403. }
  26404. Object.assign(Composite.prototype, {
  26405. getValue: function getValue(array, offset) {
  26406. this.bind(); // bind all binding
  26407. var firstValidIndex = this._targetGroup.nCachedObjects_,
  26408. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  26409. if (binding !== undefined) binding.getValue(array, offset);
  26410. },
  26411. setValue: function setValue(array, offset) {
  26412. var bindings = this._bindings;
  26413. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26414. bindings[i].setValue(array, offset);
  26415. }
  26416. },
  26417. bind: function bind() {
  26418. var bindings = this._bindings;
  26419. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26420. bindings[i].bind();
  26421. }
  26422. },
  26423. unbind: function unbind() {
  26424. var bindings = this._bindings;
  26425. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26426. bindings[i].unbind();
  26427. }
  26428. }
  26429. });
  26430. function PropertyBinding(rootNode, path, parsedPath) {
  26431. this.path = path;
  26432. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  26433. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  26434. this.rootNode = rootNode;
  26435. }
  26436. Object.assign(PropertyBinding, {
  26437. Composite: Composite,
  26438. create: function create(root, path, parsedPath) {
  26439. if (!(root && root.isAnimationObjectGroup)) {
  26440. return new PropertyBinding(root, path, parsedPath);
  26441. } else {
  26442. return new PropertyBinding.Composite(root, path, parsedPath);
  26443. }
  26444. },
  26445. /**
  26446. * Replaces spaces with underscores and removes unsupported characters from
  26447. * node names, to ensure compatibility with parseTrackName().
  26448. *
  26449. * @param {string} name Node name to be sanitized.
  26450. * @return {string}
  26451. */
  26452. sanitizeNodeName: function sanitizeNodeName(name) {
  26453. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  26454. },
  26455. parseTrackName: function parseTrackName(trackName) {
  26456. var matches = _trackRe.exec(trackName);
  26457. if (!matches) {
  26458. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  26459. }
  26460. var results = {
  26461. // directoryName: matches[ 1 ], // (tschw) currently unused
  26462. nodeName: matches[2],
  26463. objectName: matches[3],
  26464. objectIndex: matches[4],
  26465. propertyName: matches[5],
  26466. // required
  26467. propertyIndex: matches[6]
  26468. };
  26469. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  26470. if (lastDot !== undefined && lastDot !== -1) {
  26471. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  26472. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  26473. // 'bar' could be the objectName, or part of a nodeName (which can
  26474. // include '.' characters).
  26475. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  26476. results.nodeName = results.nodeName.substring(0, lastDot);
  26477. results.objectName = objectName;
  26478. }
  26479. }
  26480. if (results.propertyName === null || results.propertyName.length === 0) {
  26481. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  26482. }
  26483. return results;
  26484. },
  26485. findNode: function findNode(root, nodeName) {
  26486. if (!nodeName || nodeName === '' || nodeName === '.' || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  26487. return root;
  26488. } // search into skeleton bones.
  26489. if (root.skeleton) {
  26490. var bone = root.skeleton.getBoneByName(nodeName);
  26491. if (bone !== undefined) {
  26492. return bone;
  26493. }
  26494. } // search into node subtree.
  26495. if (root.children) {
  26496. var searchNodeSubtree = function searchNodeSubtree(children) {
  26497. for (var i = 0; i < children.length; i++) {
  26498. var childNode = children[i];
  26499. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  26500. return childNode;
  26501. }
  26502. var result = searchNodeSubtree(childNode.children);
  26503. if (result) return result;
  26504. }
  26505. return null;
  26506. };
  26507. var subTreeNode = searchNodeSubtree(root.children);
  26508. if (subTreeNode) {
  26509. return subTreeNode;
  26510. }
  26511. }
  26512. return null;
  26513. }
  26514. });
  26515. Object.assign(PropertyBinding.prototype, {
  26516. // prototype, continued
  26517. // these are used to "bind" a nonexistent property
  26518. _getValue_unavailable: function _getValue_unavailable() {},
  26519. _setValue_unavailable: function _setValue_unavailable() {},
  26520. BindingType: {
  26521. Direct: 0,
  26522. EntireArray: 1,
  26523. ArrayElement: 2,
  26524. HasFromToArray: 3
  26525. },
  26526. Versioning: {
  26527. None: 0,
  26528. NeedsUpdate: 1,
  26529. MatrixWorldNeedsUpdate: 2
  26530. },
  26531. GetterByBindingType: [function getValue_direct(buffer, offset) {
  26532. buffer[offset] = this.node[this.propertyName];
  26533. }, function getValue_array(buffer, offset) {
  26534. var source = this.resolvedProperty;
  26535. for (var i = 0, n = source.length; i !== n; ++i) {
  26536. buffer[offset++] = source[i];
  26537. }
  26538. }, function getValue_arrayElement(buffer, offset) {
  26539. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  26540. }, function getValue_toArray(buffer, offset) {
  26541. this.resolvedProperty.toArray(buffer, offset);
  26542. }],
  26543. SetterByBindingTypeAndVersioning: [[// Direct
  26544. function setValue_direct(buffer, offset) {
  26545. this.targetObject[this.propertyName] = buffer[offset];
  26546. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  26547. this.targetObject[this.propertyName] = buffer[offset];
  26548. this.targetObject.needsUpdate = true;
  26549. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  26550. this.targetObject[this.propertyName] = buffer[offset];
  26551. this.targetObject.matrixWorldNeedsUpdate = true;
  26552. }], [// EntireArray
  26553. function setValue_array(buffer, offset) {
  26554. var dest = this.resolvedProperty;
  26555. for (var i = 0, n = dest.length; i !== n; ++i) {
  26556. dest[i] = buffer[offset++];
  26557. }
  26558. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  26559. var dest = this.resolvedProperty;
  26560. for (var i = 0, n = dest.length; i !== n; ++i) {
  26561. dest[i] = buffer[offset++];
  26562. }
  26563. this.targetObject.needsUpdate = true;
  26564. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  26565. var dest = this.resolvedProperty;
  26566. for (var i = 0, n = dest.length; i !== n; ++i) {
  26567. dest[i] = buffer[offset++];
  26568. }
  26569. this.targetObject.matrixWorldNeedsUpdate = true;
  26570. }], [// ArrayElement
  26571. function setValue_arrayElement(buffer, offset) {
  26572. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26573. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  26574. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26575. this.targetObject.needsUpdate = true;
  26576. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  26577. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26578. this.targetObject.matrixWorldNeedsUpdate = true;
  26579. }], [// HasToFromArray
  26580. function setValue_fromArray(buffer, offset) {
  26581. this.resolvedProperty.fromArray(buffer, offset);
  26582. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  26583. this.resolvedProperty.fromArray(buffer, offset);
  26584. this.targetObject.needsUpdate = true;
  26585. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  26586. this.resolvedProperty.fromArray(buffer, offset);
  26587. this.targetObject.matrixWorldNeedsUpdate = true;
  26588. }]],
  26589. getValue: function getValue_unbound(targetArray, offset) {
  26590. this.bind();
  26591. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  26592. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26593. // prototype version of these methods with one that represents
  26594. // the bound state. When the property is not found, the methods
  26595. // become no-ops.
  26596. },
  26597. setValue: function getValue_unbound(sourceArray, offset) {
  26598. this.bind();
  26599. this.setValue(sourceArray, offset);
  26600. },
  26601. // create getter / setter pair for a property in the scene graph
  26602. bind: function bind() {
  26603. var targetObject = this.node;
  26604. var parsedPath = this.parsedPath;
  26605. var objectName = parsedPath.objectName;
  26606. var propertyName = parsedPath.propertyName;
  26607. var propertyIndex = parsedPath.propertyIndex;
  26608. if (!targetObject) {
  26609. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  26610. this.node = targetObject;
  26611. } // set fail state so we can just 'return' on error
  26612. this.getValue = this._getValue_unavailable;
  26613. this.setValue = this._setValue_unavailable; // ensure there is a value node
  26614. if (!targetObject) {
  26615. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  26616. return;
  26617. }
  26618. if (objectName) {
  26619. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26620. switch (objectName) {
  26621. case 'materials':
  26622. if (!targetObject.material) {
  26623. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  26624. return;
  26625. }
  26626. if (!targetObject.material.materials) {
  26627. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  26628. return;
  26629. }
  26630. targetObject = targetObject.material.materials;
  26631. break;
  26632. case 'bones':
  26633. if (!targetObject.skeleton) {
  26634. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  26635. return;
  26636. } // potential future optimization: skip this if propertyIndex is already an integer
  26637. // and convert the integer string to a true integer.
  26638. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  26639. for (var i = 0; i < targetObject.length; i++) {
  26640. if (targetObject[i].name === objectIndex) {
  26641. objectIndex = i;
  26642. break;
  26643. }
  26644. }
  26645. break;
  26646. default:
  26647. if (targetObject[objectName] === undefined) {
  26648. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  26649. return;
  26650. }
  26651. targetObject = targetObject[objectName];
  26652. }
  26653. if (objectIndex !== undefined) {
  26654. if (targetObject[objectIndex] === undefined) {
  26655. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  26656. return;
  26657. }
  26658. targetObject = targetObject[objectIndex];
  26659. }
  26660. } // resolve property
  26661. var nodeProperty = targetObject[propertyName];
  26662. if (nodeProperty === undefined) {
  26663. var nodeName = parsedPath.nodeName;
  26664. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  26665. return;
  26666. } // determine versioning scheme
  26667. var versioning = this.Versioning.None;
  26668. this.targetObject = targetObject;
  26669. if (targetObject.needsUpdate !== undefined) {
  26670. // material
  26671. versioning = this.Versioning.NeedsUpdate;
  26672. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  26673. // node transform
  26674. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26675. } // determine how the property gets bound
  26676. var bindingType = this.BindingType.Direct;
  26677. if (propertyIndex !== undefined) {
  26678. // access a sub element of the property array (only primitives are supported right now)
  26679. if (propertyName === 'morphTargetInfluences') {
  26680. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26681. // support resolving morphTarget names into indices.
  26682. if (!targetObject.geometry) {
  26683. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  26684. return;
  26685. }
  26686. if (targetObject.geometry.isBufferGeometry) {
  26687. if (!targetObject.geometry.morphAttributes) {
  26688. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  26689. return;
  26690. }
  26691. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  26692. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  26693. }
  26694. } else {
  26695. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  26696. return;
  26697. }
  26698. }
  26699. bindingType = this.BindingType.ArrayElement;
  26700. this.resolvedProperty = nodeProperty;
  26701. this.propertyIndex = propertyIndex;
  26702. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26703. // must use copy for Object3D.Euler/Quaternion
  26704. bindingType = this.BindingType.HasFromToArray;
  26705. this.resolvedProperty = nodeProperty;
  26706. } else if (Array.isArray(nodeProperty)) {
  26707. bindingType = this.BindingType.EntireArray;
  26708. this.resolvedProperty = nodeProperty;
  26709. } else {
  26710. this.propertyName = propertyName;
  26711. } // select getter / setter
  26712. this.getValue = this.GetterByBindingType[bindingType];
  26713. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26714. },
  26715. unbind: function unbind() {
  26716. this.node = null; // back to the prototype version of getValue / setValue
  26717. // note: avoiding to mutate the shape of 'this' via 'delete'
  26718. this.getValue = this._getValue_unbound;
  26719. this.setValue = this._setValue_unbound;
  26720. }
  26721. }); // DECLARE ALIAS AFTER assign prototype
  26722. Object.assign(PropertyBinding.prototype, {
  26723. // initial state of these methods that calls 'bind'
  26724. _getValue_unbound: PropertyBinding.prototype.getValue,
  26725. _setValue_unbound: PropertyBinding.prototype.setValue
  26726. });
  26727. /**
  26728. *
  26729. * A group of objects that receives a shared animation state.
  26730. *
  26731. * Usage:
  26732. *
  26733. * - Add objects you would otherwise pass as 'root' to the
  26734. * constructor or the .clipAction method of AnimationMixer.
  26735. *
  26736. * - Instead pass this object as 'root'.
  26737. *
  26738. * - You can also add and remove objects later when the mixer
  26739. * is running.
  26740. *
  26741. * Note:
  26742. *
  26743. * Objects of this class appear as one object to the mixer,
  26744. * so cache control of the individual objects must be done
  26745. * on the group.
  26746. *
  26747. * Limitation:
  26748. *
  26749. * - The animated properties must be compatible among the
  26750. * all objects in the group.
  26751. *
  26752. * - A single property can either be controlled through a
  26753. * target group or directly, but not both.
  26754. */
  26755. function AnimationObjectGroup() {
  26756. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26757. this._objects = Array.prototype.slice.call(arguments);
  26758. this.nCachedObjects_ = 0; // threshold
  26759. // note: read by PropertyBinding.Composite
  26760. var indices = {};
  26761. this._indicesByUUID = indices; // for bookkeeping
  26762. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26763. indices[arguments[i].uuid] = i;
  26764. }
  26765. this._paths = []; // inside: string
  26766. this._parsedPaths = []; // inside: { we don't care, here }
  26767. this._bindings = []; // inside: Array< PropertyBinding >
  26768. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26769. var scope = this;
  26770. this.stats = {
  26771. objects: {
  26772. get total() {
  26773. return scope._objects.length;
  26774. },
  26775. get inUse() {
  26776. return this.total - scope.nCachedObjects_;
  26777. }
  26778. },
  26779. get bindingsPerObject() {
  26780. return scope._bindings.length;
  26781. }
  26782. };
  26783. }
  26784. Object.assign(AnimationObjectGroup.prototype, {
  26785. isAnimationObjectGroup: true,
  26786. add: function add() {
  26787. var objects = this._objects,
  26788. indicesByUUID = this._indicesByUUID,
  26789. paths = this._paths,
  26790. parsedPaths = this._parsedPaths,
  26791. bindings = this._bindings,
  26792. nBindings = bindings.length;
  26793. var knownObject = undefined,
  26794. nObjects = objects.length,
  26795. nCachedObjects = this.nCachedObjects_;
  26796. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26797. var object = arguments[i],
  26798. uuid = object.uuid;
  26799. var index = indicesByUUID[uuid];
  26800. if (index === undefined) {
  26801. // unknown object -> add it to the ACTIVE region
  26802. index = nObjects++;
  26803. indicesByUUID[uuid] = index;
  26804. objects.push(object); // accounting is done, now do the same for all bindings
  26805. for (var j = 0, m = nBindings; j !== m; ++j) {
  26806. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26807. }
  26808. } else if (index < nCachedObjects) {
  26809. knownObject = objects[index]; // move existing object to the ACTIVE region
  26810. var firstActiveIndex = --nCachedObjects,
  26811. lastCachedObject = objects[firstActiveIndex];
  26812. indicesByUUID[lastCachedObject.uuid] = index;
  26813. objects[index] = lastCachedObject;
  26814. indicesByUUID[uuid] = firstActiveIndex;
  26815. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26816. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26817. var bindingsForPath = bindings[_j],
  26818. lastCached = bindingsForPath[firstActiveIndex];
  26819. var binding = bindingsForPath[index];
  26820. bindingsForPath[index] = lastCached;
  26821. if (binding === undefined) {
  26822. // since we do not bother to create new bindings
  26823. // for objects that are cached, the binding may
  26824. // or may not exist
  26825. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26826. }
  26827. bindingsForPath[firstActiveIndex] = binding;
  26828. }
  26829. } else if (objects[index] !== knownObject) {
  26830. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26831. } // else the object is already where we want it to be
  26832. } // for arguments
  26833. this.nCachedObjects_ = nCachedObjects;
  26834. },
  26835. remove: function remove() {
  26836. var objects = this._objects,
  26837. indicesByUUID = this._indicesByUUID,
  26838. bindings = this._bindings,
  26839. nBindings = bindings.length;
  26840. var nCachedObjects = this.nCachedObjects_;
  26841. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26842. var object = arguments[i],
  26843. uuid = object.uuid,
  26844. index = indicesByUUID[uuid];
  26845. if (index !== undefined && index >= nCachedObjects) {
  26846. // move existing object into the CACHED region
  26847. var lastCachedIndex = nCachedObjects++,
  26848. firstActiveObject = objects[lastCachedIndex];
  26849. indicesByUUID[firstActiveObject.uuid] = index;
  26850. objects[index] = firstActiveObject;
  26851. indicesByUUID[uuid] = lastCachedIndex;
  26852. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26853. for (var j = 0, m = nBindings; j !== m; ++j) {
  26854. var bindingsForPath = bindings[j],
  26855. firstActive = bindingsForPath[lastCachedIndex],
  26856. binding = bindingsForPath[index];
  26857. bindingsForPath[index] = firstActive;
  26858. bindingsForPath[lastCachedIndex] = binding;
  26859. }
  26860. }
  26861. } // for arguments
  26862. this.nCachedObjects_ = nCachedObjects;
  26863. },
  26864. // remove & forget
  26865. uncache: function uncache() {
  26866. var objects = this._objects,
  26867. indicesByUUID = this._indicesByUUID,
  26868. bindings = this._bindings,
  26869. nBindings = bindings.length;
  26870. var nCachedObjects = this.nCachedObjects_,
  26871. nObjects = objects.length;
  26872. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26873. var object = arguments[i],
  26874. uuid = object.uuid,
  26875. index = indicesByUUID[uuid];
  26876. if (index !== undefined) {
  26877. delete indicesByUUID[uuid];
  26878. if (index < nCachedObjects) {
  26879. // object is cached, shrink the CACHED region
  26880. var firstActiveIndex = --nCachedObjects,
  26881. lastCachedObject = objects[firstActiveIndex],
  26882. lastIndex = --nObjects,
  26883. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26884. indicesByUUID[lastCachedObject.uuid] = index;
  26885. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26886. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26887. objects[firstActiveIndex] = lastObject;
  26888. objects.pop(); // accounting is done, now do the same for all bindings
  26889. for (var j = 0, m = nBindings; j !== m; ++j) {
  26890. var bindingsForPath = bindings[j],
  26891. lastCached = bindingsForPath[firstActiveIndex],
  26892. last = bindingsForPath[lastIndex];
  26893. bindingsForPath[index] = lastCached;
  26894. bindingsForPath[firstActiveIndex] = last;
  26895. bindingsForPath.pop();
  26896. }
  26897. } else {
  26898. // object is active, just swap with the last and pop
  26899. var _lastIndex = --nObjects,
  26900. _lastObject = objects[_lastIndex];
  26901. if (_lastIndex > 0) {
  26902. indicesByUUID[_lastObject.uuid] = index;
  26903. }
  26904. objects[index] = _lastObject;
  26905. objects.pop(); // accounting is done, now do the same for all bindings
  26906. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26907. var _bindingsForPath = bindings[_j2];
  26908. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26909. _bindingsForPath.pop();
  26910. }
  26911. } // cached or active
  26912. } // if object is known
  26913. } // for arguments
  26914. this.nCachedObjects_ = nCachedObjects;
  26915. },
  26916. // Internal interface used by befriended PropertyBinding.Composite:
  26917. subscribe_: function subscribe_(path, parsedPath) {
  26918. // returns an array of bindings for the given path that is changed
  26919. // according to the contained objects in the group
  26920. var indicesByPath = this._bindingsIndicesByPath;
  26921. var index = indicesByPath[path];
  26922. var bindings = this._bindings;
  26923. if (index !== undefined) return bindings[index];
  26924. var paths = this._paths,
  26925. parsedPaths = this._parsedPaths,
  26926. objects = this._objects,
  26927. nObjects = objects.length,
  26928. nCachedObjects = this.nCachedObjects_,
  26929. bindingsForPath = new Array(nObjects);
  26930. index = bindings.length;
  26931. indicesByPath[path] = index;
  26932. paths.push(path);
  26933. parsedPaths.push(parsedPath);
  26934. bindings.push(bindingsForPath);
  26935. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26936. var object = objects[i];
  26937. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26938. }
  26939. return bindingsForPath;
  26940. },
  26941. unsubscribe_: function unsubscribe_(path) {
  26942. // tells the group to forget about a property path and no longer
  26943. // update the array previously obtained with 'subscribe_'
  26944. var indicesByPath = this._bindingsIndicesByPath,
  26945. index = indicesByPath[path];
  26946. if (index !== undefined) {
  26947. var paths = this._paths,
  26948. parsedPaths = this._parsedPaths,
  26949. bindings = this._bindings,
  26950. lastBindingsIndex = bindings.length - 1,
  26951. lastBindings = bindings[lastBindingsIndex],
  26952. lastBindingsPath = path[lastBindingsIndex];
  26953. indicesByPath[lastBindingsPath] = index;
  26954. bindings[index] = lastBindings;
  26955. bindings.pop();
  26956. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26957. parsedPaths.pop();
  26958. paths[index] = paths[lastBindingsIndex];
  26959. paths.pop();
  26960. }
  26961. }
  26962. });
  26963. var AnimationAction = /*#__PURE__*/function () {
  26964. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26965. if (localRoot === void 0) {
  26966. localRoot = null;
  26967. }
  26968. if (blendMode === void 0) {
  26969. blendMode = clip.blendMode;
  26970. }
  26971. this._mixer = mixer;
  26972. this._clip = clip;
  26973. this._localRoot = localRoot;
  26974. this.blendMode = blendMode;
  26975. var tracks = clip.tracks,
  26976. nTracks = tracks.length,
  26977. interpolants = new Array(nTracks);
  26978. var interpolantSettings = {
  26979. endingStart: ZeroCurvatureEnding,
  26980. endingEnd: ZeroCurvatureEnding
  26981. };
  26982. for (var i = 0; i !== nTracks; ++i) {
  26983. var interpolant = tracks[i].createInterpolant(null);
  26984. interpolants[i] = interpolant;
  26985. interpolant.settings = interpolantSettings;
  26986. }
  26987. this._interpolantSettings = interpolantSettings;
  26988. this._interpolants = interpolants; // bound by the mixer
  26989. // inside: PropertyMixer (managed by the mixer)
  26990. this._propertyBindings = new Array(nTracks);
  26991. this._cacheIndex = null; // for the memory manager
  26992. this._byClipCacheIndex = null; // for the memory manager
  26993. this._timeScaleInterpolant = null;
  26994. this._weightInterpolant = null;
  26995. this.loop = LoopRepeat;
  26996. this._loopCount = -1; // global mixer time when the action is to be started
  26997. // it's set back to 'null' upon start of the action
  26998. this._startTime = null; // scaled local time of the action
  26999. // gets clamped or wrapped to 0..clip.duration according to loop
  27000. this.time = 0;
  27001. this.timeScale = 1;
  27002. this._effectiveTimeScale = 1;
  27003. this.weight = 1;
  27004. this._effectiveWeight = 1;
  27005. this.repetitions = Infinity; // no. of repetitions when looping
  27006. this.paused = false; // true -> zero effective time scale
  27007. this.enabled = true; // false -> zero effective weight
  27008. this.clampWhenFinished = false; // keep feeding the last frame?
  27009. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  27010. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  27011. } // State & Scheduling
  27012. var _proto = AnimationAction.prototype;
  27013. _proto.play = function play() {
  27014. this._mixer._activateAction(this);
  27015. return this;
  27016. };
  27017. _proto.stop = function stop() {
  27018. this._mixer._deactivateAction(this);
  27019. return this.reset();
  27020. };
  27021. _proto.reset = function reset() {
  27022. this.paused = false;
  27023. this.enabled = true;
  27024. this.time = 0; // restart clip
  27025. this._loopCount = -1; // forget previous loops
  27026. this._startTime = null; // forget scheduling
  27027. return this.stopFading().stopWarping();
  27028. };
  27029. _proto.isRunning = function isRunning() {
  27030. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  27031. } // return true when play has been called
  27032. ;
  27033. _proto.isScheduled = function isScheduled() {
  27034. return this._mixer._isActiveAction(this);
  27035. };
  27036. _proto.startAt = function startAt(time) {
  27037. this._startTime = time;
  27038. return this;
  27039. };
  27040. _proto.setLoop = function setLoop(mode, repetitions) {
  27041. this.loop = mode;
  27042. this.repetitions = repetitions;
  27043. return this;
  27044. } // Weight
  27045. // set the weight stopping any scheduled fading
  27046. // although .enabled = false yields an effective weight of zero, this
  27047. // method does *not* change .enabled, because it would be confusing
  27048. ;
  27049. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  27050. this.weight = weight; // note: same logic as when updated at runtime
  27051. this._effectiveWeight = this.enabled ? weight : 0;
  27052. return this.stopFading();
  27053. } // return the weight considering fading and .enabled
  27054. ;
  27055. _proto.getEffectiveWeight = function getEffectiveWeight() {
  27056. return this._effectiveWeight;
  27057. };
  27058. _proto.fadeIn = function fadeIn(duration) {
  27059. return this._scheduleFading(duration, 0, 1);
  27060. };
  27061. _proto.fadeOut = function fadeOut(duration) {
  27062. return this._scheduleFading(duration, 1, 0);
  27063. };
  27064. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  27065. fadeOutAction.fadeOut(duration);
  27066. this.fadeIn(duration);
  27067. if (warp) {
  27068. var fadeInDuration = this._clip.duration,
  27069. fadeOutDuration = fadeOutAction._clip.duration,
  27070. startEndRatio = fadeOutDuration / fadeInDuration,
  27071. endStartRatio = fadeInDuration / fadeOutDuration;
  27072. fadeOutAction.warp(1.0, startEndRatio, duration);
  27073. this.warp(endStartRatio, 1.0, duration);
  27074. }
  27075. return this;
  27076. };
  27077. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  27078. return fadeInAction.crossFadeFrom(this, duration, warp);
  27079. };
  27080. _proto.stopFading = function stopFading() {
  27081. var weightInterpolant = this._weightInterpolant;
  27082. if (weightInterpolant !== null) {
  27083. this._weightInterpolant = null;
  27084. this._mixer._takeBackControlInterpolant(weightInterpolant);
  27085. }
  27086. return this;
  27087. } // Time Scale Control
  27088. // set the time scale stopping any scheduled warping
  27089. // although .paused = true yields an effective time scale of zero, this
  27090. // method does *not* change .paused, because it would be confusing
  27091. ;
  27092. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  27093. this.timeScale = timeScale;
  27094. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  27095. return this.stopWarping();
  27096. } // return the time scale considering warping and .paused
  27097. ;
  27098. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  27099. return this._effectiveTimeScale;
  27100. };
  27101. _proto.setDuration = function setDuration(duration) {
  27102. this.timeScale = this._clip.duration / duration;
  27103. return this.stopWarping();
  27104. };
  27105. _proto.syncWith = function syncWith(action) {
  27106. this.time = action.time;
  27107. this.timeScale = action.timeScale;
  27108. return this.stopWarping();
  27109. };
  27110. _proto.halt = function halt(duration) {
  27111. return this.warp(this._effectiveTimeScale, 0, duration);
  27112. };
  27113. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  27114. var mixer = this._mixer,
  27115. now = mixer.time,
  27116. timeScale = this.timeScale;
  27117. var interpolant = this._timeScaleInterpolant;
  27118. if (interpolant === null) {
  27119. interpolant = mixer._lendControlInterpolant();
  27120. this._timeScaleInterpolant = interpolant;
  27121. }
  27122. var times = interpolant.parameterPositions,
  27123. values = interpolant.sampleValues;
  27124. times[0] = now;
  27125. times[1] = now + duration;
  27126. values[0] = startTimeScale / timeScale;
  27127. values[1] = endTimeScale / timeScale;
  27128. return this;
  27129. };
  27130. _proto.stopWarping = function stopWarping() {
  27131. var timeScaleInterpolant = this._timeScaleInterpolant;
  27132. if (timeScaleInterpolant !== null) {
  27133. this._timeScaleInterpolant = null;
  27134. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  27135. }
  27136. return this;
  27137. } // Object Accessors
  27138. ;
  27139. _proto.getMixer = function getMixer() {
  27140. return this._mixer;
  27141. };
  27142. _proto.getClip = function getClip() {
  27143. return this._clip;
  27144. };
  27145. _proto.getRoot = function getRoot() {
  27146. return this._localRoot || this._mixer._root;
  27147. } // Interna
  27148. ;
  27149. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  27150. // called by the mixer
  27151. if (!this.enabled) {
  27152. // call ._updateWeight() to update ._effectiveWeight
  27153. this._updateWeight(time);
  27154. return;
  27155. }
  27156. var startTime = this._startTime;
  27157. if (startTime !== null) {
  27158. // check for scheduled start of action
  27159. var timeRunning = (time - startTime) * timeDirection;
  27160. if (timeRunning < 0 || timeDirection === 0) {
  27161. return; // yet to come / don't decide when delta = 0
  27162. } // start
  27163. this._startTime = null; // unschedule
  27164. deltaTime = timeDirection * timeRunning;
  27165. } // apply time scale and advance time
  27166. deltaTime *= this._updateTimeScale(time);
  27167. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  27168. // an effective weight of 0
  27169. var weight = this._updateWeight(time);
  27170. if (weight > 0) {
  27171. var _interpolants = this._interpolants;
  27172. var propertyMixers = this._propertyBindings;
  27173. switch (this.blendMode) {
  27174. case AdditiveAnimationBlendMode:
  27175. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  27176. _interpolants[j].evaluate(clipTime);
  27177. propertyMixers[j].accumulateAdditive(weight);
  27178. }
  27179. break;
  27180. case NormalAnimationBlendMode:
  27181. default:
  27182. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  27183. _interpolants[_j].evaluate(clipTime);
  27184. propertyMixers[_j].accumulate(accuIndex, weight);
  27185. }
  27186. }
  27187. }
  27188. };
  27189. _proto._updateWeight = function _updateWeight(time) {
  27190. var weight = 0;
  27191. if (this.enabled) {
  27192. weight = this.weight;
  27193. var interpolant = this._weightInterpolant;
  27194. if (interpolant !== null) {
  27195. var interpolantValue = interpolant.evaluate(time)[0];
  27196. weight *= interpolantValue;
  27197. if (time > interpolant.parameterPositions[1]) {
  27198. this.stopFading();
  27199. if (interpolantValue === 0) {
  27200. // faded out, disable
  27201. this.enabled = false;
  27202. }
  27203. }
  27204. }
  27205. }
  27206. this._effectiveWeight = weight;
  27207. return weight;
  27208. };
  27209. _proto._updateTimeScale = function _updateTimeScale(time) {
  27210. var timeScale = 0;
  27211. if (!this.paused) {
  27212. timeScale = this.timeScale;
  27213. var interpolant = this._timeScaleInterpolant;
  27214. if (interpolant !== null) {
  27215. var interpolantValue = interpolant.evaluate(time)[0];
  27216. timeScale *= interpolantValue;
  27217. if (time > interpolant.parameterPositions[1]) {
  27218. this.stopWarping();
  27219. if (timeScale === 0) {
  27220. // motion has halted, pause
  27221. this.paused = true;
  27222. } else {
  27223. // warp done - apply final time scale
  27224. this.timeScale = timeScale;
  27225. }
  27226. }
  27227. }
  27228. }
  27229. this._effectiveTimeScale = timeScale;
  27230. return timeScale;
  27231. };
  27232. _proto._updateTime = function _updateTime(deltaTime) {
  27233. var duration = this._clip.duration;
  27234. var loop = this.loop;
  27235. var time = this.time + deltaTime;
  27236. var loopCount = this._loopCount;
  27237. var pingPong = loop === LoopPingPong;
  27238. if (deltaTime === 0) {
  27239. if (loopCount === -1) return time;
  27240. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  27241. }
  27242. if (loop === LoopOnce) {
  27243. if (loopCount === -1) {
  27244. // just started
  27245. this._loopCount = 0;
  27246. this._setEndings(true, true, false);
  27247. }
  27248. handle_stop: {
  27249. if (time >= duration) {
  27250. time = duration;
  27251. } else if (time < 0) {
  27252. time = 0;
  27253. } else {
  27254. this.time = time;
  27255. break handle_stop;
  27256. }
  27257. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  27258. this.time = time;
  27259. this._mixer.dispatchEvent({
  27260. type: 'finished',
  27261. action: this,
  27262. direction: deltaTime < 0 ? -1 : 1
  27263. });
  27264. }
  27265. } else {
  27266. // repetitive Repeat or PingPong
  27267. if (loopCount === -1) {
  27268. // just started
  27269. if (deltaTime >= 0) {
  27270. loopCount = 0;
  27271. this._setEndings(true, this.repetitions === 0, pingPong);
  27272. } else {
  27273. // when looping in reverse direction, the initial
  27274. // transition through zero counts as a repetition,
  27275. // so leave loopCount at -1
  27276. this._setEndings(this.repetitions === 0, true, pingPong);
  27277. }
  27278. }
  27279. if (time >= duration || time < 0) {
  27280. // wrap around
  27281. var loopDelta = Math.floor(time / duration); // signed
  27282. time -= duration * loopDelta;
  27283. loopCount += Math.abs(loopDelta);
  27284. var pending = this.repetitions - loopCount;
  27285. if (pending <= 0) {
  27286. // have to stop (switch state, clamp time, fire event)
  27287. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  27288. time = deltaTime > 0 ? duration : 0;
  27289. this.time = time;
  27290. this._mixer.dispatchEvent({
  27291. type: 'finished',
  27292. action: this,
  27293. direction: deltaTime > 0 ? 1 : -1
  27294. });
  27295. } else {
  27296. // keep running
  27297. if (pending === 1) {
  27298. // entering the last round
  27299. var atStart = deltaTime < 0;
  27300. this._setEndings(atStart, !atStart, pingPong);
  27301. } else {
  27302. this._setEndings(false, false, pingPong);
  27303. }
  27304. this._loopCount = loopCount;
  27305. this.time = time;
  27306. this._mixer.dispatchEvent({
  27307. type: 'loop',
  27308. action: this,
  27309. loopDelta: loopDelta
  27310. });
  27311. }
  27312. } else {
  27313. this.time = time;
  27314. }
  27315. if (pingPong && (loopCount & 1) === 1) {
  27316. // invert time for the "pong round"
  27317. return duration - time;
  27318. }
  27319. }
  27320. return time;
  27321. };
  27322. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  27323. var settings = this._interpolantSettings;
  27324. if (pingPong) {
  27325. settings.endingStart = ZeroSlopeEnding;
  27326. settings.endingEnd = ZeroSlopeEnding;
  27327. } else {
  27328. // assuming for LoopOnce atStart == atEnd == true
  27329. if (atStart) {
  27330. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27331. } else {
  27332. settings.endingStart = WrapAroundEnding;
  27333. }
  27334. if (atEnd) {
  27335. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27336. } else {
  27337. settings.endingEnd = WrapAroundEnding;
  27338. }
  27339. }
  27340. };
  27341. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  27342. var mixer = this._mixer,
  27343. now = mixer.time;
  27344. var interpolant = this._weightInterpolant;
  27345. if (interpolant === null) {
  27346. interpolant = mixer._lendControlInterpolant();
  27347. this._weightInterpolant = interpolant;
  27348. }
  27349. var times = interpolant.parameterPositions,
  27350. values = interpolant.sampleValues;
  27351. times[0] = now;
  27352. values[0] = weightNow;
  27353. times[1] = now + duration;
  27354. values[1] = weightThen;
  27355. return this;
  27356. };
  27357. return AnimationAction;
  27358. }();
  27359. function AnimationMixer(root) {
  27360. this._root = root;
  27361. this._initMemoryManager();
  27362. this._accuIndex = 0;
  27363. this.time = 0;
  27364. this.timeScale = 1.0;
  27365. }
  27366. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  27367. constructor: AnimationMixer,
  27368. _bindAction: function _bindAction(action, prototypeAction) {
  27369. var root = action._localRoot || this._root,
  27370. tracks = action._clip.tracks,
  27371. nTracks = tracks.length,
  27372. bindings = action._propertyBindings,
  27373. interpolants = action._interpolants,
  27374. rootUuid = root.uuid,
  27375. bindingsByRoot = this._bindingsByRootAndName;
  27376. var bindingsByName = bindingsByRoot[rootUuid];
  27377. if (bindingsByName === undefined) {
  27378. bindingsByName = {};
  27379. bindingsByRoot[rootUuid] = bindingsByName;
  27380. }
  27381. for (var i = 0; i !== nTracks; ++i) {
  27382. var track = tracks[i],
  27383. trackName = track.name;
  27384. var binding = bindingsByName[trackName];
  27385. if (binding !== undefined) {
  27386. bindings[i] = binding;
  27387. } else {
  27388. binding = bindings[i];
  27389. if (binding !== undefined) {
  27390. // existing binding, make sure the cache knows
  27391. if (binding._cacheIndex === null) {
  27392. ++binding.referenceCount;
  27393. this._addInactiveBinding(binding, rootUuid, trackName);
  27394. }
  27395. continue;
  27396. }
  27397. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  27398. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  27399. ++binding.referenceCount;
  27400. this._addInactiveBinding(binding, rootUuid, trackName);
  27401. bindings[i] = binding;
  27402. }
  27403. interpolants[i].resultBuffer = binding.buffer;
  27404. }
  27405. },
  27406. _activateAction: function _activateAction(action) {
  27407. if (!this._isActiveAction(action)) {
  27408. if (action._cacheIndex === null) {
  27409. // this action has been forgotten by the cache, but the user
  27410. // appears to be still using it -> rebind
  27411. var rootUuid = (action._localRoot || this._root).uuid,
  27412. clipUuid = action._clip.uuid,
  27413. actionsForClip = this._actionsByClip[clipUuid];
  27414. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  27415. this._addInactiveAction(action, clipUuid, rootUuid);
  27416. }
  27417. var bindings = action._propertyBindings; // increment reference counts / sort out state
  27418. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27419. var binding = bindings[i];
  27420. if (binding.useCount++ === 0) {
  27421. this._lendBinding(binding);
  27422. binding.saveOriginalState();
  27423. }
  27424. }
  27425. this._lendAction(action);
  27426. }
  27427. },
  27428. _deactivateAction: function _deactivateAction(action) {
  27429. if (this._isActiveAction(action)) {
  27430. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  27431. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27432. var binding = bindings[i];
  27433. if (--binding.useCount === 0) {
  27434. binding.restoreOriginalState();
  27435. this._takeBackBinding(binding);
  27436. }
  27437. }
  27438. this._takeBackAction(action);
  27439. }
  27440. },
  27441. // Memory manager
  27442. _initMemoryManager: function _initMemoryManager() {
  27443. this._actions = []; // 'nActiveActions' followed by inactive ones
  27444. this._nActiveActions = 0;
  27445. this._actionsByClip = {}; // inside:
  27446. // {
  27447. // knownActions: Array< AnimationAction > - used as prototypes
  27448. // actionByRoot: AnimationAction - lookup
  27449. // }
  27450. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  27451. this._nActiveBindings = 0;
  27452. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  27453. this._controlInterpolants = []; // same game as above
  27454. this._nActiveControlInterpolants = 0;
  27455. var scope = this;
  27456. this.stats = {
  27457. actions: {
  27458. get total() {
  27459. return scope._actions.length;
  27460. },
  27461. get inUse() {
  27462. return scope._nActiveActions;
  27463. }
  27464. },
  27465. bindings: {
  27466. get total() {
  27467. return scope._bindings.length;
  27468. },
  27469. get inUse() {
  27470. return scope._nActiveBindings;
  27471. }
  27472. },
  27473. controlInterpolants: {
  27474. get total() {
  27475. return scope._controlInterpolants.length;
  27476. },
  27477. get inUse() {
  27478. return scope._nActiveControlInterpolants;
  27479. }
  27480. }
  27481. };
  27482. },
  27483. // Memory management for AnimationAction objects
  27484. _isActiveAction: function _isActiveAction(action) {
  27485. var index = action._cacheIndex;
  27486. return index !== null && index < this._nActiveActions;
  27487. },
  27488. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  27489. var actions = this._actions,
  27490. actionsByClip = this._actionsByClip;
  27491. var actionsForClip = actionsByClip[clipUuid];
  27492. if (actionsForClip === undefined) {
  27493. actionsForClip = {
  27494. knownActions: [action],
  27495. actionByRoot: {}
  27496. };
  27497. action._byClipCacheIndex = 0;
  27498. actionsByClip[clipUuid] = actionsForClip;
  27499. } else {
  27500. var knownActions = actionsForClip.knownActions;
  27501. action._byClipCacheIndex = knownActions.length;
  27502. knownActions.push(action);
  27503. }
  27504. action._cacheIndex = actions.length;
  27505. actions.push(action);
  27506. actionsForClip.actionByRoot[rootUuid] = action;
  27507. },
  27508. _removeInactiveAction: function _removeInactiveAction(action) {
  27509. var actions = this._actions,
  27510. lastInactiveAction = actions[actions.length - 1],
  27511. cacheIndex = action._cacheIndex;
  27512. lastInactiveAction._cacheIndex = cacheIndex;
  27513. actions[cacheIndex] = lastInactiveAction;
  27514. actions.pop();
  27515. action._cacheIndex = null;
  27516. var clipUuid = action._clip.uuid,
  27517. actionsByClip = this._actionsByClip,
  27518. actionsForClip = actionsByClip[clipUuid],
  27519. knownActionsForClip = actionsForClip.knownActions,
  27520. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  27521. byClipCacheIndex = action._byClipCacheIndex;
  27522. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  27523. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  27524. knownActionsForClip.pop();
  27525. action._byClipCacheIndex = null;
  27526. var actionByRoot = actionsForClip.actionByRoot,
  27527. rootUuid = (action._localRoot || this._root).uuid;
  27528. delete actionByRoot[rootUuid];
  27529. if (knownActionsForClip.length === 0) {
  27530. delete actionsByClip[clipUuid];
  27531. }
  27532. this._removeInactiveBindingsForAction(action);
  27533. },
  27534. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  27535. var bindings = action._propertyBindings;
  27536. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27537. var binding = bindings[i];
  27538. if (--binding.referenceCount === 0) {
  27539. this._removeInactiveBinding(binding);
  27540. }
  27541. }
  27542. },
  27543. _lendAction: function _lendAction(action) {
  27544. // [ active actions | inactive actions ]
  27545. // [ active actions >| inactive actions ]
  27546. // s a
  27547. // <-swap->
  27548. // a s
  27549. var actions = this._actions,
  27550. prevIndex = action._cacheIndex,
  27551. lastActiveIndex = this._nActiveActions++,
  27552. firstInactiveAction = actions[lastActiveIndex];
  27553. action._cacheIndex = lastActiveIndex;
  27554. actions[lastActiveIndex] = action;
  27555. firstInactiveAction._cacheIndex = prevIndex;
  27556. actions[prevIndex] = firstInactiveAction;
  27557. },
  27558. _takeBackAction: function _takeBackAction(action) {
  27559. // [ active actions | inactive actions ]
  27560. // [ active actions |< inactive actions ]
  27561. // a s
  27562. // <-swap->
  27563. // s a
  27564. var actions = this._actions,
  27565. prevIndex = action._cacheIndex,
  27566. firstInactiveIndex = --this._nActiveActions,
  27567. lastActiveAction = actions[firstInactiveIndex];
  27568. action._cacheIndex = firstInactiveIndex;
  27569. actions[firstInactiveIndex] = action;
  27570. lastActiveAction._cacheIndex = prevIndex;
  27571. actions[prevIndex] = lastActiveAction;
  27572. },
  27573. // Memory management for PropertyMixer objects
  27574. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  27575. var bindingsByRoot = this._bindingsByRootAndName,
  27576. bindings = this._bindings;
  27577. var bindingByName = bindingsByRoot[rootUuid];
  27578. if (bindingByName === undefined) {
  27579. bindingByName = {};
  27580. bindingsByRoot[rootUuid] = bindingByName;
  27581. }
  27582. bindingByName[trackName] = binding;
  27583. binding._cacheIndex = bindings.length;
  27584. bindings.push(binding);
  27585. },
  27586. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  27587. var bindings = this._bindings,
  27588. propBinding = binding.binding,
  27589. rootUuid = propBinding.rootNode.uuid,
  27590. trackName = propBinding.path,
  27591. bindingsByRoot = this._bindingsByRootAndName,
  27592. bindingByName = bindingsByRoot[rootUuid],
  27593. lastInactiveBinding = bindings[bindings.length - 1],
  27594. cacheIndex = binding._cacheIndex;
  27595. lastInactiveBinding._cacheIndex = cacheIndex;
  27596. bindings[cacheIndex] = lastInactiveBinding;
  27597. bindings.pop();
  27598. delete bindingByName[trackName];
  27599. if (Object.keys(bindingByName).length === 0) {
  27600. delete bindingsByRoot[rootUuid];
  27601. }
  27602. },
  27603. _lendBinding: function _lendBinding(binding) {
  27604. var bindings = this._bindings,
  27605. prevIndex = binding._cacheIndex,
  27606. lastActiveIndex = this._nActiveBindings++,
  27607. firstInactiveBinding = bindings[lastActiveIndex];
  27608. binding._cacheIndex = lastActiveIndex;
  27609. bindings[lastActiveIndex] = binding;
  27610. firstInactiveBinding._cacheIndex = prevIndex;
  27611. bindings[prevIndex] = firstInactiveBinding;
  27612. },
  27613. _takeBackBinding: function _takeBackBinding(binding) {
  27614. var bindings = this._bindings,
  27615. prevIndex = binding._cacheIndex,
  27616. firstInactiveIndex = --this._nActiveBindings,
  27617. lastActiveBinding = bindings[firstInactiveIndex];
  27618. binding._cacheIndex = firstInactiveIndex;
  27619. bindings[firstInactiveIndex] = binding;
  27620. lastActiveBinding._cacheIndex = prevIndex;
  27621. bindings[prevIndex] = lastActiveBinding;
  27622. },
  27623. // Memory management of Interpolants for weight and time scale
  27624. _lendControlInterpolant: function _lendControlInterpolant() {
  27625. var interpolants = this._controlInterpolants,
  27626. lastActiveIndex = this._nActiveControlInterpolants++;
  27627. var interpolant = interpolants[lastActiveIndex];
  27628. if (interpolant === undefined) {
  27629. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  27630. interpolant.__cacheIndex = lastActiveIndex;
  27631. interpolants[lastActiveIndex] = interpolant;
  27632. }
  27633. return interpolant;
  27634. },
  27635. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  27636. var interpolants = this._controlInterpolants,
  27637. prevIndex = interpolant.__cacheIndex,
  27638. firstInactiveIndex = --this._nActiveControlInterpolants,
  27639. lastActiveInterpolant = interpolants[firstInactiveIndex];
  27640. interpolant.__cacheIndex = firstInactiveIndex;
  27641. interpolants[firstInactiveIndex] = interpolant;
  27642. lastActiveInterpolant.__cacheIndex = prevIndex;
  27643. interpolants[prevIndex] = lastActiveInterpolant;
  27644. },
  27645. _controlInterpolantsResultBuffer: new Float32Array(1),
  27646. // return an action for a clip optionally using a custom root target
  27647. // object (this method allocates a lot of dynamic memory in case a
  27648. // previously unknown clip/root combination is specified)
  27649. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  27650. var root = optionalRoot || this._root,
  27651. rootUuid = root.uuid;
  27652. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  27653. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  27654. var actionsForClip = this._actionsByClip[clipUuid];
  27655. var prototypeAction = null;
  27656. if (blendMode === undefined) {
  27657. if (clipObject !== null) {
  27658. blendMode = clipObject.blendMode;
  27659. } else {
  27660. blendMode = NormalAnimationBlendMode;
  27661. }
  27662. }
  27663. if (actionsForClip !== undefined) {
  27664. var existingAction = actionsForClip.actionByRoot[rootUuid];
  27665. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  27666. return existingAction;
  27667. } // we know the clip, so we don't have to parse all
  27668. // the bindings again but can just copy
  27669. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  27670. if (clipObject === null) clipObject = prototypeAction._clip;
  27671. } // clip must be known when specified via string
  27672. if (clipObject === null) return null; // allocate all resources required to run it
  27673. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  27674. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  27675. this._addInactiveAction(newAction, clipUuid, rootUuid);
  27676. return newAction;
  27677. },
  27678. // get an existing action
  27679. existingAction: function existingAction(clip, optionalRoot) {
  27680. var root = optionalRoot || this._root,
  27681. rootUuid = root.uuid,
  27682. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  27683. clipUuid = clipObject ? clipObject.uuid : clip,
  27684. actionsForClip = this._actionsByClip[clipUuid];
  27685. if (actionsForClip !== undefined) {
  27686. return actionsForClip.actionByRoot[rootUuid] || null;
  27687. }
  27688. return null;
  27689. },
  27690. // deactivates all previously scheduled actions
  27691. stopAllAction: function stopAllAction() {
  27692. var actions = this._actions,
  27693. nActions = this._nActiveActions;
  27694. for (var i = nActions - 1; i >= 0; --i) {
  27695. actions[i].stop();
  27696. }
  27697. return this;
  27698. },
  27699. // advance the time and update apply the animation
  27700. update: function update(deltaTime) {
  27701. deltaTime *= this.timeScale;
  27702. var actions = this._actions,
  27703. nActions = this._nActiveActions,
  27704. time = this.time += deltaTime,
  27705. timeDirection = Math.sign(deltaTime),
  27706. accuIndex = this._accuIndex ^= 1; // run active actions
  27707. for (var i = 0; i !== nActions; ++i) {
  27708. var action = actions[i];
  27709. action._update(time, deltaTime, timeDirection, accuIndex);
  27710. } // update scene graph
  27711. var bindings = this._bindings,
  27712. nBindings = this._nActiveBindings;
  27713. for (var _i = 0; _i !== nBindings; ++_i) {
  27714. bindings[_i].apply(accuIndex);
  27715. }
  27716. return this;
  27717. },
  27718. // Allows you to seek to a specific time in an animation.
  27719. setTime: function setTime(timeInSeconds) {
  27720. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27721. for (var i = 0; i < this._actions.length; i++) {
  27722. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27723. }
  27724. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27725. },
  27726. // return this mixer's root target object
  27727. getRoot: function getRoot() {
  27728. return this._root;
  27729. },
  27730. // free all resources specific to a particular clip
  27731. uncacheClip: function uncacheClip(clip) {
  27732. var actions = this._actions,
  27733. clipUuid = clip.uuid,
  27734. actionsByClip = this._actionsByClip,
  27735. actionsForClip = actionsByClip[clipUuid];
  27736. if (actionsForClip !== undefined) {
  27737. // note: just calling _removeInactiveAction would mess up the
  27738. // iteration state and also require updating the state we can
  27739. // just throw away
  27740. var actionsToRemove = actionsForClip.knownActions;
  27741. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27742. var action = actionsToRemove[i];
  27743. this._deactivateAction(action);
  27744. var cacheIndex = action._cacheIndex,
  27745. lastInactiveAction = actions[actions.length - 1];
  27746. action._cacheIndex = null;
  27747. action._byClipCacheIndex = null;
  27748. lastInactiveAction._cacheIndex = cacheIndex;
  27749. actions[cacheIndex] = lastInactiveAction;
  27750. actions.pop();
  27751. this._removeInactiveBindingsForAction(action);
  27752. }
  27753. delete actionsByClip[clipUuid];
  27754. }
  27755. },
  27756. // free all resources specific to a particular root target object
  27757. uncacheRoot: function uncacheRoot(root) {
  27758. var rootUuid = root.uuid,
  27759. actionsByClip = this._actionsByClip;
  27760. for (var clipUuid in actionsByClip) {
  27761. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27762. action = actionByRoot[rootUuid];
  27763. if (action !== undefined) {
  27764. this._deactivateAction(action);
  27765. this._removeInactiveAction(action);
  27766. }
  27767. }
  27768. var bindingsByRoot = this._bindingsByRootAndName,
  27769. bindingByName = bindingsByRoot[rootUuid];
  27770. if (bindingByName !== undefined) {
  27771. for (var trackName in bindingByName) {
  27772. var binding = bindingByName[trackName];
  27773. binding.restoreOriginalState();
  27774. this._removeInactiveBinding(binding);
  27775. }
  27776. }
  27777. },
  27778. // remove a targeted clip from the cache
  27779. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27780. var action = this.existingAction(clip, optionalRoot);
  27781. if (action !== null) {
  27782. this._deactivateAction(action);
  27783. this._removeInactiveAction(action);
  27784. }
  27785. }
  27786. });
  27787. var Uniform = /*#__PURE__*/function () {
  27788. function Uniform(value) {
  27789. if (typeof value === 'string') {
  27790. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27791. value = arguments[1];
  27792. }
  27793. this.value = value;
  27794. }
  27795. var _proto = Uniform.prototype;
  27796. _proto.clone = function clone() {
  27797. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27798. };
  27799. return Uniform;
  27800. }();
  27801. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27802. InterleavedBuffer.call(this, array, stride);
  27803. this.meshPerAttribute = meshPerAttribute || 1;
  27804. }
  27805. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27806. constructor: InstancedInterleavedBuffer,
  27807. isInstancedInterleavedBuffer: true,
  27808. copy: function copy(source) {
  27809. InterleavedBuffer.prototype.copy.call(this, source);
  27810. this.meshPerAttribute = source.meshPerAttribute;
  27811. return this;
  27812. },
  27813. clone: function clone(data) {
  27814. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27815. ib.meshPerAttribute = this.meshPerAttribute;
  27816. return ib;
  27817. },
  27818. toJSON: function toJSON(data) {
  27819. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27820. json.isInstancedInterleavedBuffer = true;
  27821. json.meshPerAttribute = this.meshPerAttribute;
  27822. return json;
  27823. }
  27824. });
  27825. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27826. this.buffer = buffer;
  27827. this.type = type;
  27828. this.itemSize = itemSize;
  27829. this.elementSize = elementSize;
  27830. this.count = count;
  27831. this.version = 0;
  27832. }
  27833. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27834. set: function set(value) {
  27835. if (value === true) this.version++;
  27836. }
  27837. });
  27838. Object.assign(GLBufferAttribute.prototype, {
  27839. isGLBufferAttribute: true,
  27840. setBuffer: function setBuffer(buffer) {
  27841. this.buffer = buffer;
  27842. return this;
  27843. },
  27844. setType: function setType(type, elementSize) {
  27845. this.type = type;
  27846. this.elementSize = elementSize;
  27847. return this;
  27848. },
  27849. setItemSize: function setItemSize(itemSize) {
  27850. this.itemSize = itemSize;
  27851. return this;
  27852. },
  27853. setCount: function setCount(count) {
  27854. this.count = count;
  27855. return this;
  27856. }
  27857. });
  27858. function Raycaster(origin, direction, near, far) {
  27859. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27860. this.near = near || 0;
  27861. this.far = far || Infinity;
  27862. this.camera = null;
  27863. this.layers = new Layers();
  27864. this.params = {
  27865. Mesh: {},
  27866. Line: {
  27867. threshold: 1
  27868. },
  27869. LOD: {},
  27870. Points: {
  27871. threshold: 1
  27872. },
  27873. Sprite: {}
  27874. };
  27875. Object.defineProperties(this.params, {
  27876. PointCloud: {
  27877. get: function get() {
  27878. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27879. return this.Points;
  27880. }
  27881. }
  27882. });
  27883. }
  27884. function ascSort(a, b) {
  27885. return a.distance - b.distance;
  27886. }
  27887. function _intersectObject(object, raycaster, intersects, recursive) {
  27888. if (object.layers.test(raycaster.layers)) {
  27889. object.raycast(raycaster, intersects);
  27890. }
  27891. if (recursive === true) {
  27892. var children = object.children;
  27893. for (var i = 0, l = children.length; i < l; i++) {
  27894. _intersectObject(children[i], raycaster, intersects, true);
  27895. }
  27896. }
  27897. }
  27898. Object.assign(Raycaster.prototype, {
  27899. set: function set(origin, direction) {
  27900. // direction is assumed to be normalized (for accurate distance calculations)
  27901. this.ray.set(origin, direction);
  27902. },
  27903. setFromCamera: function setFromCamera(coords, camera) {
  27904. if (camera && camera.isPerspectiveCamera) {
  27905. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27906. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27907. this.camera = camera;
  27908. } else if (camera && camera.isOrthographicCamera) {
  27909. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27910. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27911. this.camera = camera;
  27912. } else {
  27913. console.error('THREE.Raycaster: Unsupported camera type.');
  27914. }
  27915. },
  27916. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27917. var intersects = optionalTarget || [];
  27918. _intersectObject(object, this, intersects, recursive);
  27919. intersects.sort(ascSort);
  27920. return intersects;
  27921. },
  27922. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27923. var intersects = optionalTarget || [];
  27924. if (Array.isArray(objects) === false) {
  27925. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27926. return intersects;
  27927. }
  27928. for (var i = 0, l = objects.length; i < l; i++) {
  27929. _intersectObject(objects[i], this, intersects, recursive);
  27930. }
  27931. intersects.sort(ascSort);
  27932. return intersects;
  27933. }
  27934. });
  27935. /**
  27936. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27937. *
  27938. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27939. * The azimuthal angle (theta) is measured from the positive z-axis.
  27940. */
  27941. var Spherical = /*#__PURE__*/function () {
  27942. function Spherical(radius, phi, theta) {
  27943. if (radius === void 0) {
  27944. radius = 1;
  27945. }
  27946. if (phi === void 0) {
  27947. phi = 0;
  27948. }
  27949. if (theta === void 0) {
  27950. theta = 0;
  27951. }
  27952. this.radius = radius;
  27953. this.phi = phi; // polar angle
  27954. this.theta = theta; // azimuthal angle
  27955. return this;
  27956. }
  27957. var _proto = Spherical.prototype;
  27958. _proto.set = function set(radius, phi, theta) {
  27959. this.radius = radius;
  27960. this.phi = phi;
  27961. this.theta = theta;
  27962. return this;
  27963. };
  27964. _proto.clone = function clone() {
  27965. return new this.constructor().copy(this);
  27966. };
  27967. _proto.copy = function copy(other) {
  27968. this.radius = other.radius;
  27969. this.phi = other.phi;
  27970. this.theta = other.theta;
  27971. return this;
  27972. } // restrict phi to be betwee EPS and PI-EPS
  27973. ;
  27974. _proto.makeSafe = function makeSafe() {
  27975. var EPS = 0.000001;
  27976. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27977. return this;
  27978. };
  27979. _proto.setFromVector3 = function setFromVector3(v) {
  27980. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27981. };
  27982. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27983. this.radius = Math.sqrt(x * x + y * y + z * z);
  27984. if (this.radius === 0) {
  27985. this.theta = 0;
  27986. this.phi = 0;
  27987. } else {
  27988. this.theta = Math.atan2(x, z);
  27989. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27990. }
  27991. return this;
  27992. };
  27993. return Spherical;
  27994. }();
  27995. /**
  27996. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27997. */
  27998. var Cylindrical = /*#__PURE__*/function () {
  27999. function Cylindrical(radius, theta, y) {
  28000. this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
  28001. this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  28002. this.y = y !== undefined ? y : 0; // height above the x-z plane
  28003. return this;
  28004. }
  28005. var _proto = Cylindrical.prototype;
  28006. _proto.set = function set(radius, theta, y) {
  28007. this.radius = radius;
  28008. this.theta = theta;
  28009. this.y = y;
  28010. return this;
  28011. };
  28012. _proto.clone = function clone() {
  28013. return new this.constructor().copy(this);
  28014. };
  28015. _proto.copy = function copy(other) {
  28016. this.radius = other.radius;
  28017. this.theta = other.theta;
  28018. this.y = other.y;
  28019. return this;
  28020. };
  28021. _proto.setFromVector3 = function setFromVector3(v) {
  28022. return this.setFromCartesianCoords(v.x, v.y, v.z);
  28023. };
  28024. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  28025. this.radius = Math.sqrt(x * x + z * z);
  28026. this.theta = Math.atan2(x, z);
  28027. this.y = y;
  28028. return this;
  28029. };
  28030. return Cylindrical;
  28031. }();
  28032. var _vector$8 = /*@__PURE__*/new Vector2();
  28033. var Box2 = /*#__PURE__*/function () {
  28034. function Box2(min, max) {
  28035. Object.defineProperty(this, 'isBox2', {
  28036. value: true
  28037. });
  28038. this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
  28039. this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
  28040. }
  28041. var _proto = Box2.prototype;
  28042. _proto.set = function set(min, max) {
  28043. this.min.copy(min);
  28044. this.max.copy(max);
  28045. return this;
  28046. };
  28047. _proto.setFromPoints = function setFromPoints(points) {
  28048. this.makeEmpty();
  28049. for (var i = 0, il = points.length; i < il; i++) {
  28050. this.expandByPoint(points[i]);
  28051. }
  28052. return this;
  28053. };
  28054. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  28055. var halfSize = _vector$8.copy(size).multiplyScalar(0.5);
  28056. this.min.copy(center).sub(halfSize);
  28057. this.max.copy(center).add(halfSize);
  28058. return this;
  28059. };
  28060. _proto.clone = function clone() {
  28061. return new this.constructor().copy(this);
  28062. };
  28063. _proto.copy = function copy(box) {
  28064. this.min.copy(box.min);
  28065. this.max.copy(box.max);
  28066. return this;
  28067. };
  28068. _proto.makeEmpty = function makeEmpty() {
  28069. this.min.x = this.min.y = +Infinity;
  28070. this.max.x = this.max.y = -Infinity;
  28071. return this;
  28072. };
  28073. _proto.isEmpty = function isEmpty() {
  28074. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  28075. return this.max.x < this.min.x || this.max.y < this.min.y;
  28076. };
  28077. _proto.getCenter = function getCenter(target) {
  28078. if (target === undefined) {
  28079. console.warn('THREE.Box2: .getCenter() target is now required');
  28080. target = new Vector2();
  28081. }
  28082. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  28083. };
  28084. _proto.getSize = function getSize(target) {
  28085. if (target === undefined) {
  28086. console.warn('THREE.Box2: .getSize() target is now required');
  28087. target = new Vector2();
  28088. }
  28089. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  28090. };
  28091. _proto.expandByPoint = function expandByPoint(point) {
  28092. this.min.min(point);
  28093. this.max.max(point);
  28094. return this;
  28095. };
  28096. _proto.expandByVector = function expandByVector(vector) {
  28097. this.min.sub(vector);
  28098. this.max.add(vector);
  28099. return this;
  28100. };
  28101. _proto.expandByScalar = function expandByScalar(scalar) {
  28102. this.min.addScalar(-scalar);
  28103. this.max.addScalar(scalar);
  28104. return this;
  28105. };
  28106. _proto.containsPoint = function containsPoint(point) {
  28107. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  28108. };
  28109. _proto.containsBox = function containsBox(box) {
  28110. 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;
  28111. };
  28112. _proto.getParameter = function getParameter(point, target) {
  28113. // This can potentially have a divide by zero if the box
  28114. // has a size dimension of 0.
  28115. if (target === undefined) {
  28116. console.warn('THREE.Box2: .getParameter() target is now required');
  28117. target = new Vector2();
  28118. }
  28119. 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));
  28120. };
  28121. _proto.intersectsBox = function intersectsBox(box) {
  28122. // using 4 splitting planes to rule out intersections
  28123. 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;
  28124. };
  28125. _proto.clampPoint = function clampPoint(point, target) {
  28126. if (target === undefined) {
  28127. console.warn('THREE.Box2: .clampPoint() target is now required');
  28128. target = new Vector2();
  28129. }
  28130. return target.copy(point).clamp(this.min, this.max);
  28131. };
  28132. _proto.distanceToPoint = function distanceToPoint(point) {
  28133. var clampedPoint = _vector$8.copy(point).clamp(this.min, this.max);
  28134. return clampedPoint.sub(point).length();
  28135. };
  28136. _proto.intersect = function intersect(box) {
  28137. this.min.max(box.min);
  28138. this.max.min(box.max);
  28139. return this;
  28140. };
  28141. _proto.union = function union(box) {
  28142. this.min.min(box.min);
  28143. this.max.max(box.max);
  28144. return this;
  28145. };
  28146. _proto.translate = function translate(offset) {
  28147. this.min.add(offset);
  28148. this.max.add(offset);
  28149. return this;
  28150. };
  28151. _proto.equals = function equals(box) {
  28152. return box.min.equals(this.min) && box.max.equals(this.max);
  28153. };
  28154. return Box2;
  28155. }();
  28156. var _startP = /*@__PURE__*/new Vector3();
  28157. var _startEnd = /*@__PURE__*/new Vector3();
  28158. var Line3 = /*#__PURE__*/function () {
  28159. function Line3(start, end) {
  28160. this.start = start !== undefined ? start : new Vector3();
  28161. this.end = end !== undefined ? end : new Vector3();
  28162. }
  28163. var _proto = Line3.prototype;
  28164. _proto.set = function set(start, end) {
  28165. this.start.copy(start);
  28166. this.end.copy(end);
  28167. return this;
  28168. };
  28169. _proto.clone = function clone() {
  28170. return new this.constructor().copy(this);
  28171. };
  28172. _proto.copy = function copy(line) {
  28173. this.start.copy(line.start);
  28174. this.end.copy(line.end);
  28175. return this;
  28176. };
  28177. _proto.getCenter = function getCenter(target) {
  28178. if (target === undefined) {
  28179. console.warn('THREE.Line3: .getCenter() target is now required');
  28180. target = new Vector3();
  28181. }
  28182. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  28183. };
  28184. _proto.delta = function delta(target) {
  28185. if (target === undefined) {
  28186. console.warn('THREE.Line3: .delta() target is now required');
  28187. target = new Vector3();
  28188. }
  28189. return target.subVectors(this.end, this.start);
  28190. };
  28191. _proto.distanceSq = function distanceSq() {
  28192. return this.start.distanceToSquared(this.end);
  28193. };
  28194. _proto.distance = function distance() {
  28195. return this.start.distanceTo(this.end);
  28196. };
  28197. _proto.at = function at(t, target) {
  28198. if (target === undefined) {
  28199. console.warn('THREE.Line3: .at() target is now required');
  28200. target = new Vector3();
  28201. }
  28202. return this.delta(target).multiplyScalar(t).add(this.start);
  28203. };
  28204. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  28205. _startP.subVectors(point, this.start);
  28206. _startEnd.subVectors(this.end, this.start);
  28207. var startEnd2 = _startEnd.dot(_startEnd);
  28208. var startEnd_startP = _startEnd.dot(_startP);
  28209. var t = startEnd_startP / startEnd2;
  28210. if (clampToLine) {
  28211. t = MathUtils.clamp(t, 0, 1);
  28212. }
  28213. return t;
  28214. };
  28215. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  28216. var t = this.closestPointToPointParameter(point, clampToLine);
  28217. if (target === undefined) {
  28218. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  28219. target = new Vector3();
  28220. }
  28221. return this.delta(target).multiplyScalar(t).add(this.start);
  28222. };
  28223. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  28224. this.start.applyMatrix4(matrix);
  28225. this.end.applyMatrix4(matrix);
  28226. return this;
  28227. };
  28228. _proto.equals = function equals(line) {
  28229. return line.start.equals(this.start) && line.end.equals(this.end);
  28230. };
  28231. return Line3;
  28232. }();
  28233. function ImmediateRenderObject(material) {
  28234. Object3D.call(this);
  28235. this.material = material;
  28236. this.render = function ()
  28237. /* renderCallback */
  28238. {};
  28239. this.hasPositions = false;
  28240. this.hasNormals = false;
  28241. this.hasColors = false;
  28242. this.hasUvs = false;
  28243. this.positionArray = null;
  28244. this.normalArray = null;
  28245. this.colorArray = null;
  28246. this.uvArray = null;
  28247. this.count = 0;
  28248. }
  28249. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  28250. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  28251. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  28252. var _vector$9 = /*@__PURE__*/new Vector3();
  28253. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  28254. _inheritsLoose(SpotLightHelper, _Object3D);
  28255. function SpotLightHelper(light, color) {
  28256. var _this;
  28257. _this = _Object3D.call(this) || this;
  28258. _this.light = light;
  28259. _this.light.updateMatrixWorld();
  28260. _this.matrix = light.matrixWorld;
  28261. _this.matrixAutoUpdate = false;
  28262. _this.color = color;
  28263. var geometry = new BufferGeometry();
  28264. 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];
  28265. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  28266. var p1 = i / l * Math.PI * 2;
  28267. var p2 = j / l * Math.PI * 2;
  28268. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  28269. }
  28270. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28271. var material = new LineBasicMaterial({
  28272. fog: false,
  28273. toneMapped: false
  28274. });
  28275. _this.cone = new LineSegments(geometry, material);
  28276. _this.add(_this.cone);
  28277. _this.update();
  28278. return _this;
  28279. }
  28280. var _proto = SpotLightHelper.prototype;
  28281. _proto.dispose = function dispose() {
  28282. this.cone.geometry.dispose();
  28283. this.cone.material.dispose();
  28284. };
  28285. _proto.update = function update() {
  28286. this.light.updateMatrixWorld();
  28287. var coneLength = this.light.distance ? this.light.distance : 1000;
  28288. var coneWidth = coneLength * Math.tan(this.light.angle);
  28289. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  28290. _vector$9.setFromMatrixPosition(this.light.target.matrixWorld);
  28291. this.cone.lookAt(_vector$9);
  28292. if (this.color !== undefined) {
  28293. this.cone.material.color.set(this.color);
  28294. } else {
  28295. this.cone.material.color.copy(this.light.color);
  28296. }
  28297. };
  28298. return SpotLightHelper;
  28299. }(Object3D);
  28300. var _vector$a = /*@__PURE__*/new Vector3();
  28301. var _boneMatrix = /*@__PURE__*/new Matrix4();
  28302. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  28303. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  28304. _inheritsLoose(SkeletonHelper, _LineSegments);
  28305. function SkeletonHelper(object) {
  28306. var _this;
  28307. var bones = getBoneList(object);
  28308. var geometry = new BufferGeometry();
  28309. var vertices = [];
  28310. var colors = [];
  28311. var color1 = new Color(0, 0, 1);
  28312. var color2 = new Color(0, 1, 0);
  28313. for (var i = 0; i < bones.length; i++) {
  28314. var bone = bones[i];
  28315. if (bone.parent && bone.parent.isBone) {
  28316. vertices.push(0, 0, 0);
  28317. vertices.push(0, 0, 0);
  28318. colors.push(color1.r, color1.g, color1.b);
  28319. colors.push(color2.r, color2.g, color2.b);
  28320. }
  28321. }
  28322. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28323. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28324. var material = new LineBasicMaterial({
  28325. vertexColors: true,
  28326. depthTest: false,
  28327. depthWrite: false,
  28328. toneMapped: false,
  28329. transparent: true
  28330. });
  28331. _this = _LineSegments.call(this, geometry, material) || this;
  28332. _this.type = 'SkeletonHelper';
  28333. _this.isSkeletonHelper = true;
  28334. _this.root = object;
  28335. _this.bones = bones;
  28336. _this.matrix = object.matrixWorld;
  28337. _this.matrixAutoUpdate = false;
  28338. return _this;
  28339. }
  28340. var _proto = SkeletonHelper.prototype;
  28341. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28342. var bones = this.bones;
  28343. var geometry = this.geometry;
  28344. var position = geometry.getAttribute('position');
  28345. _matrixWorldInv.copy(this.root.matrixWorld).invert();
  28346. for (var i = 0, j = 0; i < bones.length; i++) {
  28347. var bone = bones[i];
  28348. if (bone.parent && bone.parent.isBone) {
  28349. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  28350. _vector$a.setFromMatrixPosition(_boneMatrix);
  28351. position.setXYZ(j, _vector$a.x, _vector$a.y, _vector$a.z);
  28352. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  28353. _vector$a.setFromMatrixPosition(_boneMatrix);
  28354. position.setXYZ(j + 1, _vector$a.x, _vector$a.y, _vector$a.z);
  28355. j += 2;
  28356. }
  28357. }
  28358. geometry.getAttribute('position').needsUpdate = true;
  28359. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28360. };
  28361. return SkeletonHelper;
  28362. }(LineSegments);
  28363. function getBoneList(object) {
  28364. var boneList = [];
  28365. if (object && object.isBone) {
  28366. boneList.push(object);
  28367. }
  28368. for (var i = 0; i < object.children.length; i++) {
  28369. boneList.push.apply(boneList, getBoneList(object.children[i]));
  28370. }
  28371. return boneList;
  28372. }
  28373. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  28374. _inheritsLoose(PointLightHelper, _Mesh);
  28375. function PointLightHelper(light, sphereSize, color) {
  28376. var _this;
  28377. var geometry = new SphereBufferGeometry(sphereSize, 4, 2);
  28378. var material = new MeshBasicMaterial({
  28379. wireframe: true,
  28380. fog: false,
  28381. toneMapped: false
  28382. });
  28383. _this = _Mesh.call(this, geometry, material) || this;
  28384. _this.light = light;
  28385. _this.light.updateMatrixWorld();
  28386. _this.color = color;
  28387. _this.type = 'PointLightHelper';
  28388. _this.matrix = _this.light.matrixWorld;
  28389. _this.matrixAutoUpdate = false;
  28390. _this.update();
  28391. /*
  28392. // TODO: delete this comment?
  28393. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  28394. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  28395. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  28396. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  28397. const d = light.distance;
  28398. if ( d === 0.0 ) {
  28399. this.lightDistance.visible = false;
  28400. } else {
  28401. this.lightDistance.scale.set( d, d, d );
  28402. }
  28403. this.add( this.lightDistance );
  28404. */
  28405. return _this;
  28406. }
  28407. var _proto = PointLightHelper.prototype;
  28408. _proto.dispose = function dispose() {
  28409. this.geometry.dispose();
  28410. this.material.dispose();
  28411. };
  28412. _proto.update = function update() {
  28413. if (this.color !== undefined) {
  28414. this.material.color.set(this.color);
  28415. } else {
  28416. this.material.color.copy(this.light.color);
  28417. }
  28418. /*
  28419. const d = this.light.distance;
  28420. if ( d === 0.0 ) {
  28421. this.lightDistance.visible = false;
  28422. } else {
  28423. this.lightDistance.visible = true;
  28424. this.lightDistance.scale.set( d, d, d );
  28425. }
  28426. */
  28427. };
  28428. return PointLightHelper;
  28429. }(Mesh);
  28430. var _vector$b = /*@__PURE__*/new Vector3();
  28431. var _color1 = /*@__PURE__*/new Color();
  28432. var _color2 = /*@__PURE__*/new Color();
  28433. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  28434. _inheritsLoose(HemisphereLightHelper, _Object3D);
  28435. function HemisphereLightHelper(light, size, color) {
  28436. var _this;
  28437. _this = _Object3D.call(this) || this;
  28438. _this.light = light;
  28439. _this.light.updateMatrixWorld();
  28440. _this.matrix = light.matrixWorld;
  28441. _this.matrixAutoUpdate = false;
  28442. _this.color = color;
  28443. var geometry = new OctahedronBufferGeometry(size);
  28444. geometry.rotateY(Math.PI * 0.5);
  28445. _this.material = new MeshBasicMaterial({
  28446. wireframe: true,
  28447. fog: false,
  28448. toneMapped: false
  28449. });
  28450. if (_this.color === undefined) _this.material.vertexColors = true;
  28451. var position = geometry.getAttribute('position');
  28452. var colors = new Float32Array(position.count * 3);
  28453. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  28454. _this.add(new Mesh(geometry, _this.material));
  28455. _this.update();
  28456. return _this;
  28457. }
  28458. var _proto = HemisphereLightHelper.prototype;
  28459. _proto.dispose = function dispose() {
  28460. this.children[0].geometry.dispose();
  28461. this.children[0].material.dispose();
  28462. };
  28463. _proto.update = function update() {
  28464. var mesh = this.children[0];
  28465. if (this.color !== undefined) {
  28466. this.material.color.set(this.color);
  28467. } else {
  28468. var colors = mesh.geometry.getAttribute('color');
  28469. _color1.copy(this.light.color);
  28470. _color2.copy(this.light.groundColor);
  28471. for (var i = 0, l = colors.count; i < l; i++) {
  28472. var color = i < l / 2 ? _color1 : _color2;
  28473. colors.setXYZ(i, color.r, color.g, color.b);
  28474. }
  28475. colors.needsUpdate = true;
  28476. }
  28477. mesh.lookAt(_vector$b.setFromMatrixPosition(this.light.matrixWorld).negate());
  28478. };
  28479. return HemisphereLightHelper;
  28480. }(Object3D);
  28481. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  28482. _inheritsLoose(GridHelper, _LineSegments);
  28483. function GridHelper(size, divisions, color1, color2) {
  28484. var _this;
  28485. if (size === void 0) {
  28486. size = 10;
  28487. }
  28488. if (divisions === void 0) {
  28489. divisions = 10;
  28490. }
  28491. if (color1 === void 0) {
  28492. color1 = 0x444444;
  28493. }
  28494. if (color2 === void 0) {
  28495. color2 = 0x888888;
  28496. }
  28497. color1 = new Color(color1);
  28498. color2 = new Color(color2);
  28499. var center = divisions / 2;
  28500. var step = size / divisions;
  28501. var halfSize = size / 2;
  28502. var vertices = [],
  28503. colors = [];
  28504. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  28505. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  28506. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  28507. var color = i === center ? color1 : color2;
  28508. color.toArray(colors, j);
  28509. j += 3;
  28510. color.toArray(colors, j);
  28511. j += 3;
  28512. color.toArray(colors, j);
  28513. j += 3;
  28514. color.toArray(colors, j);
  28515. j += 3;
  28516. }
  28517. var geometry = new BufferGeometry();
  28518. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28519. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28520. var material = new LineBasicMaterial({
  28521. vertexColors: true,
  28522. toneMapped: false
  28523. });
  28524. _this = _LineSegments.call(this, geometry, material) || this;
  28525. _this.type = 'GridHelper';
  28526. return _this;
  28527. }
  28528. return GridHelper;
  28529. }(LineSegments);
  28530. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  28531. _inheritsLoose(PolarGridHelper, _LineSegments);
  28532. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  28533. var _this;
  28534. if (radius === void 0) {
  28535. radius = 10;
  28536. }
  28537. if (radials === void 0) {
  28538. radials = 16;
  28539. }
  28540. if (circles === void 0) {
  28541. circles = 8;
  28542. }
  28543. if (divisions === void 0) {
  28544. divisions = 64;
  28545. }
  28546. if (color1 === void 0) {
  28547. color1 = 0x444444;
  28548. }
  28549. if (color2 === void 0) {
  28550. color2 = 0x888888;
  28551. }
  28552. color1 = new Color(color1);
  28553. color2 = new Color(color2);
  28554. var vertices = [];
  28555. var colors = []; // create the radials
  28556. for (var i = 0; i <= radials; i++) {
  28557. var v = i / radials * (Math.PI * 2);
  28558. var x = Math.sin(v) * radius;
  28559. var z = Math.cos(v) * radius;
  28560. vertices.push(0, 0, 0);
  28561. vertices.push(x, 0, z);
  28562. var color = i & 1 ? color1 : color2;
  28563. colors.push(color.r, color.g, color.b);
  28564. colors.push(color.r, color.g, color.b);
  28565. } // create the circles
  28566. for (var _i = 0; _i <= circles; _i++) {
  28567. var _color = _i & 1 ? color1 : color2;
  28568. var r = radius - radius / circles * _i;
  28569. for (var j = 0; j < divisions; j++) {
  28570. // first vertex
  28571. var _v = j / divisions * (Math.PI * 2);
  28572. var _x = Math.sin(_v) * r;
  28573. var _z = Math.cos(_v) * r;
  28574. vertices.push(_x, 0, _z);
  28575. colors.push(_color.r, _color.g, _color.b); // second vertex
  28576. _v = (j + 1) / divisions * (Math.PI * 2);
  28577. _x = Math.sin(_v) * r;
  28578. _z = Math.cos(_v) * r;
  28579. vertices.push(_x, 0, _z);
  28580. colors.push(_color.r, _color.g, _color.b);
  28581. }
  28582. }
  28583. var geometry = new BufferGeometry();
  28584. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28585. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28586. var material = new LineBasicMaterial({
  28587. vertexColors: true,
  28588. toneMapped: false
  28589. });
  28590. _this = _LineSegments.call(this, geometry, material) || this;
  28591. _this.type = 'PolarGridHelper';
  28592. return _this;
  28593. }
  28594. return PolarGridHelper;
  28595. }(LineSegments);
  28596. var _v1$6 = /*@__PURE__*/new Vector3();
  28597. var _v2$3 = /*@__PURE__*/new Vector3();
  28598. var _v3$1 = /*@__PURE__*/new Vector3();
  28599. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  28600. _inheritsLoose(DirectionalLightHelper, _Object3D);
  28601. function DirectionalLightHelper(light, size, color) {
  28602. var _this;
  28603. _this = _Object3D.call(this) || this;
  28604. _this.light = light;
  28605. _this.light.updateMatrixWorld();
  28606. _this.matrix = light.matrixWorld;
  28607. _this.matrixAutoUpdate = false;
  28608. _this.color = color;
  28609. if (size === undefined) size = 1;
  28610. var geometry = new BufferGeometry();
  28611. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  28612. var material = new LineBasicMaterial({
  28613. fog: false,
  28614. toneMapped: false
  28615. });
  28616. _this.lightPlane = new Line(geometry, material);
  28617. _this.add(_this.lightPlane);
  28618. geometry = new BufferGeometry();
  28619. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  28620. _this.targetLine = new Line(geometry, material);
  28621. _this.add(_this.targetLine);
  28622. _this.update();
  28623. return _this;
  28624. }
  28625. var _proto = DirectionalLightHelper.prototype;
  28626. _proto.dispose = function dispose() {
  28627. this.lightPlane.geometry.dispose();
  28628. this.lightPlane.material.dispose();
  28629. this.targetLine.geometry.dispose();
  28630. this.targetLine.material.dispose();
  28631. };
  28632. _proto.update = function update() {
  28633. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  28634. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  28635. _v3$1.subVectors(_v2$3, _v1$6);
  28636. this.lightPlane.lookAt(_v2$3);
  28637. if (this.color !== undefined) {
  28638. this.lightPlane.material.color.set(this.color);
  28639. this.targetLine.material.color.set(this.color);
  28640. } else {
  28641. this.lightPlane.material.color.copy(this.light.color);
  28642. this.targetLine.material.color.copy(this.light.color);
  28643. }
  28644. this.targetLine.lookAt(_v2$3);
  28645. this.targetLine.scale.z = _v3$1.length();
  28646. };
  28647. return DirectionalLightHelper;
  28648. }(Object3D);
  28649. var _vector$c = /*@__PURE__*/new Vector3();
  28650. var _camera = /*@__PURE__*/new Camera();
  28651. /**
  28652. * - shows frustum, line of sight and up of the camera
  28653. * - suitable for fast updates
  28654. * - based on frustum visualization in lightgl.js shadowmap example
  28655. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28656. */
  28657. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  28658. _inheritsLoose(CameraHelper, _LineSegments);
  28659. function CameraHelper(camera) {
  28660. var _this;
  28661. var geometry = new BufferGeometry();
  28662. var material = new LineBasicMaterial({
  28663. color: 0xffffff,
  28664. vertexColors: true,
  28665. toneMapped: false
  28666. });
  28667. var vertices = [];
  28668. var colors = [];
  28669. var pointMap = {}; // colors
  28670. var colorFrustum = new Color(0xffaa00);
  28671. var colorCone = new Color(0xff0000);
  28672. var colorUp = new Color(0x00aaff);
  28673. var colorTarget = new Color(0xffffff);
  28674. var colorCross = new Color(0x333333); // near
  28675. addLine('n1', 'n2', colorFrustum);
  28676. addLine('n2', 'n4', colorFrustum);
  28677. addLine('n4', 'n3', colorFrustum);
  28678. addLine('n3', 'n1', colorFrustum); // far
  28679. addLine('f1', 'f2', colorFrustum);
  28680. addLine('f2', 'f4', colorFrustum);
  28681. addLine('f4', 'f3', colorFrustum);
  28682. addLine('f3', 'f1', colorFrustum); // sides
  28683. addLine('n1', 'f1', colorFrustum);
  28684. addLine('n2', 'f2', colorFrustum);
  28685. addLine('n3', 'f3', colorFrustum);
  28686. addLine('n4', 'f4', colorFrustum); // cone
  28687. addLine('p', 'n1', colorCone);
  28688. addLine('p', 'n2', colorCone);
  28689. addLine('p', 'n3', colorCone);
  28690. addLine('p', 'n4', colorCone); // up
  28691. addLine('u1', 'u2', colorUp);
  28692. addLine('u2', 'u3', colorUp);
  28693. addLine('u3', 'u1', colorUp); // target
  28694. addLine('c', 't', colorTarget);
  28695. addLine('p', 'c', colorCross); // cross
  28696. addLine('cn1', 'cn2', colorCross);
  28697. addLine('cn3', 'cn4', colorCross);
  28698. addLine('cf1', 'cf2', colorCross);
  28699. addLine('cf3', 'cf4', colorCross);
  28700. function addLine(a, b, color) {
  28701. addPoint(a, color);
  28702. addPoint(b, color);
  28703. }
  28704. function addPoint(id, color) {
  28705. vertices.push(0, 0, 0);
  28706. colors.push(color.r, color.g, color.b);
  28707. if (pointMap[id] === undefined) {
  28708. pointMap[id] = [];
  28709. }
  28710. pointMap[id].push(vertices.length / 3 - 1);
  28711. }
  28712. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28713. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28714. _this = _LineSegments.call(this, geometry, material) || this;
  28715. _this.type = 'CameraHelper';
  28716. _this.camera = camera;
  28717. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28718. _this.matrix = camera.matrixWorld;
  28719. _this.matrixAutoUpdate = false;
  28720. _this.pointMap = pointMap;
  28721. _this.update();
  28722. return _this;
  28723. }
  28724. var _proto = CameraHelper.prototype;
  28725. _proto.update = function update() {
  28726. var geometry = this.geometry;
  28727. var pointMap = this.pointMap;
  28728. var w = 1,
  28729. h = 1; // we need just camera projection matrix inverse
  28730. // world matrix must be identity
  28731. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28732. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28733. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28734. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28735. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28736. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28737. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28738. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28739. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28740. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28741. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28742. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28743. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28744. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28745. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28746. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28747. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28748. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28749. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28750. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28751. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28752. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28753. geometry.getAttribute('position').needsUpdate = true;
  28754. };
  28755. return CameraHelper;
  28756. }(LineSegments);
  28757. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28758. _vector$c.set(x, y, z).unproject(camera);
  28759. var points = pointMap[point];
  28760. if (points !== undefined) {
  28761. var position = geometry.getAttribute('position');
  28762. for (var i = 0, l = points.length; i < l; i++) {
  28763. position.setXYZ(points[i], _vector$c.x, _vector$c.y, _vector$c.z);
  28764. }
  28765. }
  28766. }
  28767. var _box$3 = /*@__PURE__*/new Box3();
  28768. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28769. _inheritsLoose(BoxHelper, _LineSegments);
  28770. function BoxHelper(object, color) {
  28771. var _this;
  28772. if (color === void 0) {
  28773. color = 0xffff00;
  28774. }
  28775. 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]);
  28776. var positions = new Float32Array(8 * 3);
  28777. var geometry = new BufferGeometry();
  28778. geometry.setIndex(new BufferAttribute(indices, 1));
  28779. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28780. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28781. color: color,
  28782. toneMapped: false
  28783. })) || this;
  28784. _this.object = object;
  28785. _this.type = 'BoxHelper';
  28786. _this.matrixAutoUpdate = false;
  28787. _this.update();
  28788. return _this;
  28789. }
  28790. var _proto = BoxHelper.prototype;
  28791. _proto.update = function update(object) {
  28792. if (object !== undefined) {
  28793. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28794. }
  28795. if (this.object !== undefined) {
  28796. _box$3.setFromObject(this.object);
  28797. }
  28798. if (_box$3.isEmpty()) return;
  28799. var min = _box$3.min;
  28800. var max = _box$3.max;
  28801. /*
  28802. 5____4
  28803. 1/___0/|
  28804. | 6__|_7
  28805. 2/___3/
  28806. 0: max.x, max.y, max.z
  28807. 1: min.x, max.y, max.z
  28808. 2: min.x, min.y, max.z
  28809. 3: max.x, min.y, max.z
  28810. 4: max.x, max.y, min.z
  28811. 5: min.x, max.y, min.z
  28812. 6: min.x, min.y, min.z
  28813. 7: max.x, min.y, min.z
  28814. */
  28815. var position = this.geometry.attributes.position;
  28816. var array = position.array;
  28817. array[0] = max.x;
  28818. array[1] = max.y;
  28819. array[2] = max.z;
  28820. array[3] = min.x;
  28821. array[4] = max.y;
  28822. array[5] = max.z;
  28823. array[6] = min.x;
  28824. array[7] = min.y;
  28825. array[8] = max.z;
  28826. array[9] = max.x;
  28827. array[10] = min.y;
  28828. array[11] = max.z;
  28829. array[12] = max.x;
  28830. array[13] = max.y;
  28831. array[14] = min.z;
  28832. array[15] = min.x;
  28833. array[16] = max.y;
  28834. array[17] = min.z;
  28835. array[18] = min.x;
  28836. array[19] = min.y;
  28837. array[20] = min.z;
  28838. array[21] = max.x;
  28839. array[22] = min.y;
  28840. array[23] = min.z;
  28841. position.needsUpdate = true;
  28842. this.geometry.computeBoundingSphere();
  28843. };
  28844. _proto.setFromObject = function setFromObject(object) {
  28845. this.object = object;
  28846. this.update();
  28847. return this;
  28848. };
  28849. _proto.copy = function copy(source) {
  28850. LineSegments.prototype.copy.call(this, source);
  28851. this.object = source.object;
  28852. return this;
  28853. };
  28854. return BoxHelper;
  28855. }(LineSegments);
  28856. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28857. _inheritsLoose(Box3Helper, _LineSegments);
  28858. function Box3Helper(box, color) {
  28859. var _this;
  28860. if (color === void 0) {
  28861. color = 0xffff00;
  28862. }
  28863. 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]);
  28864. 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];
  28865. var geometry = new BufferGeometry();
  28866. geometry.setIndex(new BufferAttribute(indices, 1));
  28867. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28868. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28869. color: color,
  28870. toneMapped: false
  28871. })) || this;
  28872. _this.box = box;
  28873. _this.type = 'Box3Helper';
  28874. _this.geometry.computeBoundingSphere();
  28875. return _this;
  28876. }
  28877. var _proto = Box3Helper.prototype;
  28878. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28879. var box = this.box;
  28880. if (box.isEmpty()) return;
  28881. box.getCenter(this.position);
  28882. box.getSize(this.scale);
  28883. this.scale.multiplyScalar(0.5);
  28884. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28885. };
  28886. return Box3Helper;
  28887. }(LineSegments);
  28888. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28889. _inheritsLoose(PlaneHelper, _Line);
  28890. function PlaneHelper(plane, size, hex) {
  28891. var _this;
  28892. if (size === void 0) {
  28893. size = 1;
  28894. }
  28895. if (hex === void 0) {
  28896. hex = 0xffff00;
  28897. }
  28898. var color = hex;
  28899. 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];
  28900. var geometry = new BufferGeometry();
  28901. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28902. geometry.computeBoundingSphere();
  28903. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28904. color: color,
  28905. toneMapped: false
  28906. })) || this;
  28907. _this.type = 'PlaneHelper';
  28908. _this.plane = plane;
  28909. _this.size = size;
  28910. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28911. var geometry2 = new BufferGeometry();
  28912. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28913. geometry2.computeBoundingSphere();
  28914. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28915. color: color,
  28916. opacity: 0.2,
  28917. transparent: true,
  28918. depthWrite: false,
  28919. toneMapped: false
  28920. })));
  28921. return _this;
  28922. }
  28923. var _proto = PlaneHelper.prototype;
  28924. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28925. var scale = -this.plane.constant;
  28926. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28927. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28928. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28929. this.lookAt(this.plane.normal);
  28930. _Line.prototype.updateMatrixWorld.call(this, force);
  28931. };
  28932. return PlaneHelper;
  28933. }(Line);
  28934. var _axis = /*@__PURE__*/new Vector3();
  28935. var _lineGeometry, _coneGeometry;
  28936. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28937. _inheritsLoose(ArrowHelper, _Object3D);
  28938. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28939. var _this;
  28940. _this = _Object3D.call(this) || this; // dir is assumed to be normalized
  28941. _this.type = 'ArrowHelper';
  28942. if (dir === undefined) dir = new Vector3(0, 0, 1);
  28943. if (origin === undefined) origin = new Vector3(0, 0, 0);
  28944. if (length === undefined) length = 1;
  28945. if (color === undefined) color = 0xffff00;
  28946. if (headLength === undefined) headLength = 0.2 * length;
  28947. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28948. if (_lineGeometry === undefined) {
  28949. _lineGeometry = new BufferGeometry();
  28950. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28951. _coneGeometry = new CylinderBufferGeometry(0, 0.5, 1, 5, 1);
  28952. _coneGeometry.translate(0, -0.5, 0);
  28953. }
  28954. _this.position.copy(origin);
  28955. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28956. color: color,
  28957. toneMapped: false
  28958. }));
  28959. _this.line.matrixAutoUpdate = false;
  28960. _this.add(_this.line);
  28961. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28962. color: color,
  28963. toneMapped: false
  28964. }));
  28965. _this.cone.matrixAutoUpdate = false;
  28966. _this.add(_this.cone);
  28967. _this.setDirection(dir);
  28968. _this.setLength(length, headLength, headWidth);
  28969. return _this;
  28970. }
  28971. var _proto = ArrowHelper.prototype;
  28972. _proto.setDirection = function setDirection(dir) {
  28973. // dir is assumed to be normalized
  28974. if (dir.y > 0.99999) {
  28975. this.quaternion.set(0, 0, 0, 1);
  28976. } else if (dir.y < -0.99999) {
  28977. this.quaternion.set(1, 0, 0, 0);
  28978. } else {
  28979. _axis.set(dir.z, 0, -dir.x).normalize();
  28980. var radians = Math.acos(dir.y);
  28981. this.quaternion.setFromAxisAngle(_axis, radians);
  28982. }
  28983. };
  28984. _proto.setLength = function setLength(length, headLength, headWidth) {
  28985. if (headLength === undefined) headLength = 0.2 * length;
  28986. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28987. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28988. this.line.updateMatrix();
  28989. this.cone.scale.set(headWidth, headLength, headWidth);
  28990. this.cone.position.y = length;
  28991. this.cone.updateMatrix();
  28992. };
  28993. _proto.setColor = function setColor(color) {
  28994. this.line.material.color.set(color);
  28995. this.cone.material.color.set(color);
  28996. };
  28997. _proto.copy = function copy(source) {
  28998. _Object3D.prototype.copy.call(this, source, false);
  28999. this.line.copy(source.line);
  29000. this.cone.copy(source.cone);
  29001. return this;
  29002. };
  29003. return ArrowHelper;
  29004. }(Object3D);
  29005. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  29006. _inheritsLoose(AxesHelper, _LineSegments);
  29007. function AxesHelper(size) {
  29008. var _this;
  29009. if (size === void 0) {
  29010. size = 1;
  29011. }
  29012. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  29013. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  29014. var geometry = new BufferGeometry();
  29015. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  29016. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  29017. var material = new LineBasicMaterial({
  29018. vertexColors: true,
  29019. toneMapped: false
  29020. });
  29021. _this = _LineSegments.call(this, geometry, material) || this;
  29022. _this.type = 'AxesHelper';
  29023. return _this;
  29024. }
  29025. return AxesHelper;
  29026. }(LineSegments);
  29027. var _floatView = new Float32Array(1);
  29028. var _int32View = new Int32Array(_floatView.buffer);
  29029. var DataUtils = {
  29030. // Converts float32 to float16 (stored as uint16 value).
  29031. toHalfFloat: function toHalfFloat(val) {
  29032. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  29033. /* This method is faster than the OpenEXR implementation (very often
  29034. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  29035. * by James Tursa?s half-precision code. */
  29036. _floatView[0] = val;
  29037. var x = _int32View[0];
  29038. var bits = x >> 16 & 0x8000;
  29039. /* Get the sign */
  29040. var m = x >> 12 & 0x07ff;
  29041. /* Keep one extra bit for rounding */
  29042. var e = x >> 23 & 0xff;
  29043. /* Using int is faster here */
  29044. /* If zero, or denormal, or exponent underflows too much for a denormal
  29045. * half, return signed zero. */
  29046. if (e < 103) return bits;
  29047. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  29048. if (e > 142) {
  29049. bits |= 0x7c00;
  29050. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  29051. * not Inf, so make sure we set one mantissa bit too. */
  29052. bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
  29053. return bits;
  29054. }
  29055. /* If exponent underflows but not too much, return a denormal */
  29056. if (e < 113) {
  29057. m |= 0x0800;
  29058. /* Extra rounding may overflow and set mantissa to 0 and exponent
  29059. * to 1, which is OK. */
  29060. bits |= (m >> 114 - e) + (m >> 113 - e & 1);
  29061. return bits;
  29062. }
  29063. bits |= e - 112 << 10 | m >> 1;
  29064. /* Extra rounding. An overflow will set mantissa to 0 and increment
  29065. * the exponent, which is OK. */
  29066. bits += m & 1;
  29067. return bits;
  29068. }
  29069. };
  29070. var _ENCODINGS;
  29071. var LOD_MIN = 4;
  29072. var LOD_MAX = 8;
  29073. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  29074. // chosen to approximate a Trowbridge-Reitz distribution function times the
  29075. // geometric shadowing function. These sigma values squared must match the
  29076. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  29077. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  29078. 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
  29079. // samples and exit early, but not recompile the shader.
  29080. var MAX_SAMPLES = 20;
  29081. 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);
  29082. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  29083. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  29084. _lodPlanes = _createPlanes2._lodPlanes,
  29085. _sizeLods = _createPlanes2._sizeLods,
  29086. _sigmas = _createPlanes2._sigmas;
  29087. var _clearColor = /*@__PURE__*/new Color();
  29088. var _oldTarget = null; // Golden Ratio
  29089. var PHI = (1 + Math.sqrt(5)) / 2;
  29090. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  29091. // same axis), used as axis directions evenly spread on a sphere.
  29092. 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)];
  29093. /**
  29094. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  29095. * (PMREM) from a cubeMap environment texture. This allows different levels of
  29096. * blur to be quickly accessed based on material roughness. It is packed into a
  29097. * special CubeUV format that allows us to perform custom interpolation so that
  29098. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  29099. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  29100. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  29101. * higher roughness levels. In this way we maintain resolution to smoothly
  29102. * interpolate diffuse lighting while limiting sampling computation.
  29103. */
  29104. var PMREMGenerator = /*#__PURE__*/function () {
  29105. function PMREMGenerator(renderer) {
  29106. this._renderer = renderer;
  29107. this._pingPongRenderTarget = null;
  29108. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  29109. this._equirectShader = null;
  29110. this._cubemapShader = null;
  29111. this._compileMaterial(this._blurMaterial);
  29112. }
  29113. /**
  29114. * Generates a PMREM from a supplied Scene, which can be faster than using an
  29115. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  29116. * in radians to be applied to the scene before PMREM generation. Optional near
  29117. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  29118. * is placed at the origin).
  29119. */
  29120. var _proto = PMREMGenerator.prototype;
  29121. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  29122. if (sigma === void 0) {
  29123. sigma = 0;
  29124. }
  29125. if (near === void 0) {
  29126. near = 0.1;
  29127. }
  29128. if (far === void 0) {
  29129. far = 100;
  29130. }
  29131. _oldTarget = this._renderer.getRenderTarget();
  29132. var cubeUVRenderTarget = this._allocateTargets();
  29133. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  29134. if (sigma > 0) {
  29135. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  29136. }
  29137. this._applyPMREM(cubeUVRenderTarget);
  29138. this._cleanup(cubeUVRenderTarget);
  29139. return cubeUVRenderTarget;
  29140. }
  29141. /**
  29142. * Generates a PMREM from an equirectangular texture, which can be either LDR
  29143. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  29144. * as this matches best with the 256 x 256 cubemap output.
  29145. */
  29146. ;
  29147. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  29148. return this._fromTexture(equirectangular);
  29149. }
  29150. /**
  29151. * Generates a PMREM from an cubemap texture, which can be either LDR
  29152. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  29153. * as this matches best with the 256 x 256 cubemap output.
  29154. */
  29155. ;
  29156. _proto.fromCubemap = function fromCubemap(cubemap) {
  29157. return this._fromTexture(cubemap);
  29158. }
  29159. /**
  29160. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  29161. * your texture's network fetch for increased concurrency.
  29162. */
  29163. ;
  29164. _proto.compileCubemapShader = function compileCubemapShader() {
  29165. if (this._cubemapShader === null) {
  29166. this._cubemapShader = _getCubemapShader();
  29167. this._compileMaterial(this._cubemapShader);
  29168. }
  29169. }
  29170. /**
  29171. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  29172. * your texture's network fetch for increased concurrency.
  29173. */
  29174. ;
  29175. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  29176. if (this._equirectShader === null) {
  29177. this._equirectShader = _getEquirectShader();
  29178. this._compileMaterial(this._equirectShader);
  29179. }
  29180. }
  29181. /**
  29182. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  29183. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  29184. * one of them will cause any others to also become unusable.
  29185. */
  29186. ;
  29187. _proto.dispose = function dispose() {
  29188. this._blurMaterial.dispose();
  29189. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  29190. if (this._equirectShader !== null) this._equirectShader.dispose();
  29191. for (var i = 0; i < _lodPlanes.length; i++) {
  29192. _lodPlanes[i].dispose();
  29193. }
  29194. } // private interface
  29195. ;
  29196. _proto._cleanup = function _cleanup(outputTarget) {
  29197. this._pingPongRenderTarget.dispose();
  29198. this._renderer.setRenderTarget(_oldTarget);
  29199. outputTarget.scissorTest = false;
  29200. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  29201. };
  29202. _proto._fromTexture = function _fromTexture(texture) {
  29203. _oldTarget = this._renderer.getRenderTarget();
  29204. var cubeUVRenderTarget = this._allocateTargets(texture);
  29205. this._textureToCubeUV(texture, cubeUVRenderTarget);
  29206. this._applyPMREM(cubeUVRenderTarget);
  29207. this._cleanup(cubeUVRenderTarget);
  29208. return cubeUVRenderTarget;
  29209. };
  29210. _proto._allocateTargets = function _allocateTargets(texture) {
  29211. // warning: null texture is valid
  29212. var params = {
  29213. magFilter: NearestFilter,
  29214. minFilter: NearestFilter,
  29215. generateMipmaps: false,
  29216. type: UnsignedByteType,
  29217. format: RGBEFormat,
  29218. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  29219. depthBuffer: false
  29220. };
  29221. var cubeUVRenderTarget = _createRenderTarget(params);
  29222. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  29223. this._pingPongRenderTarget = _createRenderTarget(params);
  29224. return cubeUVRenderTarget;
  29225. };
  29226. _proto._compileMaterial = function _compileMaterial(material) {
  29227. var tmpMesh = new Mesh(_lodPlanes[0], material);
  29228. this._renderer.compile(tmpMesh, _flatCamera);
  29229. };
  29230. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  29231. var fov = 90;
  29232. var aspect = 1;
  29233. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  29234. var upSign = [1, -1, 1, 1, 1, 1];
  29235. var forwardSign = [1, 1, 1, -1, -1, -1];
  29236. var renderer = this._renderer;
  29237. var outputEncoding = renderer.outputEncoding;
  29238. var toneMapping = renderer.toneMapping;
  29239. renderer.getClearColor(_clearColor);
  29240. var clearAlpha = renderer.getClearAlpha();
  29241. renderer.toneMapping = NoToneMapping;
  29242. renderer.outputEncoding = LinearEncoding;
  29243. var background = scene.background;
  29244. if (background && background.isColor) {
  29245. background.convertSRGBToLinear(); // Convert linear to RGBE
  29246. var maxComponent = Math.max(background.r, background.g, background.b);
  29247. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  29248. background = background.multiplyScalar(Math.pow(2.0, -fExp));
  29249. var alpha = (fExp + 128.0) / 255.0;
  29250. renderer.setClearColor(background, alpha);
  29251. scene.background = null;
  29252. }
  29253. for (var i = 0; i < 6; i++) {
  29254. var col = i % 3;
  29255. if (col == 0) {
  29256. cubeCamera.up.set(0, upSign[i], 0);
  29257. cubeCamera.lookAt(forwardSign[i], 0, 0);
  29258. } else if (col == 1) {
  29259. cubeCamera.up.set(0, 0, upSign[i]);
  29260. cubeCamera.lookAt(0, forwardSign[i], 0);
  29261. } else {
  29262. cubeCamera.up.set(0, upSign[i], 0);
  29263. cubeCamera.lookAt(0, 0, forwardSign[i]);
  29264. }
  29265. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  29266. renderer.setRenderTarget(cubeUVRenderTarget);
  29267. renderer.render(scene, cubeCamera);
  29268. }
  29269. renderer.toneMapping = toneMapping;
  29270. renderer.outputEncoding = outputEncoding;
  29271. renderer.setClearColor(_clearColor, clearAlpha);
  29272. };
  29273. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  29274. var renderer = this._renderer;
  29275. if (texture.isCubeTexture) {
  29276. if (this._cubemapShader == null) {
  29277. this._cubemapShader = _getCubemapShader();
  29278. }
  29279. } else {
  29280. if (this._equirectShader == null) {
  29281. this._equirectShader = _getEquirectShader();
  29282. }
  29283. }
  29284. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  29285. var mesh = new Mesh(_lodPlanes[0], material);
  29286. var uniforms = material.uniforms;
  29287. uniforms['envMap'].value = texture;
  29288. if (!texture.isCubeTexture) {
  29289. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  29290. }
  29291. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  29292. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  29293. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  29294. renderer.setRenderTarget(cubeUVRenderTarget);
  29295. renderer.render(mesh, _flatCamera);
  29296. };
  29297. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  29298. var renderer = this._renderer;
  29299. var autoClear = renderer.autoClear;
  29300. renderer.autoClear = false;
  29301. for (var i = 1; i < TOTAL_LODS; i++) {
  29302. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  29303. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  29304. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  29305. }
  29306. renderer.autoClear = autoClear;
  29307. }
  29308. /**
  29309. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  29310. * vertically and horizontally, but this breaks down on a cube. Here we apply
  29311. * the blur latitudinally (around the poles), and then longitudinally (towards
  29312. * the poles) to approximate the orthogonally-separable blur. It is least
  29313. * accurate at the poles, but still does a decent job.
  29314. */
  29315. ;
  29316. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  29317. var pingPongRenderTarget = this._pingPongRenderTarget;
  29318. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  29319. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  29320. };
  29321. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  29322. var renderer = this._renderer;
  29323. var blurMaterial = this._blurMaterial;
  29324. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  29325. console.error('blur direction must be either latitudinal or longitudinal!');
  29326. } // Number of standard deviations at which to cut off the discrete approximation.
  29327. var STANDARD_DEVIATIONS = 3;
  29328. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  29329. var blurUniforms = blurMaterial.uniforms;
  29330. var pixels = _sizeLods[lodIn] - 1;
  29331. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  29332. var sigmaPixels = sigmaRadians / radiansPerPixel;
  29333. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  29334. if (samples > MAX_SAMPLES) {
  29335. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  29336. }
  29337. var weights = [];
  29338. var sum = 0;
  29339. for (var i = 0; i < MAX_SAMPLES; ++i) {
  29340. var _x = i / sigmaPixels;
  29341. var weight = Math.exp(-_x * _x / 2);
  29342. weights.push(weight);
  29343. if (i == 0) {
  29344. sum += weight;
  29345. } else if (i < samples) {
  29346. sum += 2 * weight;
  29347. }
  29348. }
  29349. for (var _i = 0; _i < weights.length; _i++) {
  29350. weights[_i] = weights[_i] / sum;
  29351. }
  29352. blurUniforms['envMap'].value = targetIn.texture;
  29353. blurUniforms['samples'].value = samples;
  29354. blurUniforms['weights'].value = weights;
  29355. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  29356. if (poleAxis) {
  29357. blurUniforms['poleAxis'].value = poleAxis;
  29358. }
  29359. blurUniforms['dTheta'].value = radiansPerPixel;
  29360. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  29361. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  29362. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  29363. var outputSize = _sizeLods[lodOut];
  29364. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  29365. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  29366. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  29367. renderer.setRenderTarget(targetOut);
  29368. renderer.render(blurMesh, _flatCamera);
  29369. };
  29370. return PMREMGenerator;
  29371. }();
  29372. function _isLDR(texture) {
  29373. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  29374. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  29375. }
  29376. function _createPlanes() {
  29377. var _lodPlanes = [];
  29378. var _sizeLods = [];
  29379. var _sigmas = [];
  29380. var lod = LOD_MAX;
  29381. for (var i = 0; i < TOTAL_LODS; i++) {
  29382. var sizeLod = Math.pow(2, lod);
  29383. _sizeLods.push(sizeLod);
  29384. var sigma = 1.0 / sizeLod;
  29385. if (i > LOD_MAX - LOD_MIN) {
  29386. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  29387. } else if (i == 0) {
  29388. sigma = 0;
  29389. }
  29390. _sigmas.push(sigma);
  29391. var texelSize = 1.0 / (sizeLod - 1);
  29392. var min = -texelSize / 2;
  29393. var max = 1 + texelSize / 2;
  29394. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  29395. var cubeFaces = 6;
  29396. var vertices = 6;
  29397. var positionSize = 3;
  29398. var uvSize = 2;
  29399. var faceIndexSize = 1;
  29400. var position = new Float32Array(positionSize * vertices * cubeFaces);
  29401. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  29402. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  29403. for (var face = 0; face < cubeFaces; face++) {
  29404. var x = face % 3 * 2 / 3 - 1;
  29405. var y = face > 2 ? 0 : -1;
  29406. 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];
  29407. position.set(coordinates, positionSize * vertices * face);
  29408. uv.set(uv1, uvSize * vertices * face);
  29409. var fill = [face, face, face, face, face, face];
  29410. faceIndex.set(fill, faceIndexSize * vertices * face);
  29411. }
  29412. var planes = new BufferGeometry();
  29413. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  29414. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  29415. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  29416. _lodPlanes.push(planes);
  29417. if (lod > LOD_MIN) {
  29418. lod--;
  29419. }
  29420. }
  29421. return {
  29422. _lodPlanes: _lodPlanes,
  29423. _sizeLods: _sizeLods,
  29424. _sigmas: _sigmas
  29425. };
  29426. }
  29427. function _createRenderTarget(params) {
  29428. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  29429. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  29430. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  29431. cubeUVRenderTarget.scissorTest = true;
  29432. return cubeUVRenderTarget;
  29433. }
  29434. function _setViewport(target, x, y, width, height) {
  29435. target.viewport.set(x, y, width, height);
  29436. target.scissor.set(x, y, width, height);
  29437. }
  29438. function _getBlurShader(maxSamples) {
  29439. var weights = new Float32Array(maxSamples);
  29440. var poleAxis = new Vector3(0, 1, 0);
  29441. var shaderMaterial = new RawShaderMaterial({
  29442. name: 'SphericalGaussianBlur',
  29443. defines: {
  29444. 'n': maxSamples
  29445. },
  29446. uniforms: {
  29447. 'envMap': {
  29448. value: null
  29449. },
  29450. 'samples': {
  29451. value: 1
  29452. },
  29453. 'weights': {
  29454. value: weights
  29455. },
  29456. 'latitudinal': {
  29457. value: false
  29458. },
  29459. 'dTheta': {
  29460. value: 0
  29461. },
  29462. 'mipInt': {
  29463. value: 0
  29464. },
  29465. 'poleAxis': {
  29466. value: poleAxis
  29467. },
  29468. 'inputEncoding': {
  29469. value: ENCODINGS[LinearEncoding]
  29470. },
  29471. 'outputEncoding': {
  29472. value: ENCODINGS[LinearEncoding]
  29473. }
  29474. },
  29475. vertexShader: _getCommonVertexShader(),
  29476. fragmentShader:
  29477. /* glsl */
  29478. "\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",
  29479. blending: NoBlending,
  29480. depthTest: false,
  29481. depthWrite: false
  29482. });
  29483. return shaderMaterial;
  29484. }
  29485. function _getEquirectShader() {
  29486. var texelSize = new Vector2(1, 1);
  29487. var shaderMaterial = new RawShaderMaterial({
  29488. name: 'EquirectangularToCubeUV',
  29489. uniforms: {
  29490. 'envMap': {
  29491. value: null
  29492. },
  29493. 'texelSize': {
  29494. value: texelSize
  29495. },
  29496. 'inputEncoding': {
  29497. value: ENCODINGS[LinearEncoding]
  29498. },
  29499. 'outputEncoding': {
  29500. value: ENCODINGS[LinearEncoding]
  29501. }
  29502. },
  29503. vertexShader: _getCommonVertexShader(),
  29504. fragmentShader:
  29505. /* glsl */
  29506. "\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",
  29507. blending: NoBlending,
  29508. depthTest: false,
  29509. depthWrite: false
  29510. });
  29511. return shaderMaterial;
  29512. }
  29513. function _getCubemapShader() {
  29514. var shaderMaterial = new RawShaderMaterial({
  29515. name: 'CubemapToCubeUV',
  29516. uniforms: {
  29517. 'envMap': {
  29518. value: null
  29519. },
  29520. 'inputEncoding': {
  29521. value: ENCODINGS[LinearEncoding]
  29522. },
  29523. 'outputEncoding': {
  29524. value: ENCODINGS[LinearEncoding]
  29525. }
  29526. },
  29527. vertexShader: _getCommonVertexShader(),
  29528. fragmentShader:
  29529. /* glsl */
  29530. "\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",
  29531. blending: NoBlending,
  29532. depthTest: false,
  29533. depthWrite: false
  29534. });
  29535. return shaderMaterial;
  29536. }
  29537. function _getCommonVertexShader() {
  29538. return (
  29539. /* glsl */
  29540. "\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"
  29541. );
  29542. }
  29543. function _getEncodings() {
  29544. return (
  29545. /* glsl */
  29546. "\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"
  29547. );
  29548. }
  29549. function Face4(a, b, c, d, normal, color, materialIndex) {
  29550. console.warn('THREE.Face4 has been removed. A THREE.Face3 will be created instead.');
  29551. return new Face3(a, b, c, normal, color, materialIndex);
  29552. }
  29553. var LineStrip = 0;
  29554. var LinePieces = 1;
  29555. var NoColors = 0;
  29556. var FaceColors = 1;
  29557. var VertexColors = 2;
  29558. function MeshFaceMaterial(materials) {
  29559. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  29560. return materials;
  29561. }
  29562. function MultiMaterial(materials) {
  29563. if (materials === void 0) {
  29564. materials = [];
  29565. }
  29566. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  29567. materials.isMultiMaterial = true;
  29568. materials.materials = materials;
  29569. materials.clone = function () {
  29570. return materials.slice();
  29571. };
  29572. return materials;
  29573. }
  29574. function PointCloud(geometry, material) {
  29575. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  29576. return new Points(geometry, material);
  29577. }
  29578. function Particle(material) {
  29579. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  29580. return new Sprite(material);
  29581. }
  29582. function ParticleSystem(geometry, material) {
  29583. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  29584. return new Points(geometry, material);
  29585. }
  29586. function PointCloudMaterial(parameters) {
  29587. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  29588. return new PointsMaterial(parameters);
  29589. }
  29590. function ParticleBasicMaterial(parameters) {
  29591. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  29592. return new PointsMaterial(parameters);
  29593. }
  29594. function ParticleSystemMaterial(parameters) {
  29595. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  29596. return new PointsMaterial(parameters);
  29597. }
  29598. function Vertex(x, y, z) {
  29599. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  29600. return new Vector3(x, y, z);
  29601. } //
  29602. function DynamicBufferAttribute(array, itemSize) {
  29603. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  29604. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  29605. }
  29606. function Int8Attribute(array, itemSize) {
  29607. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  29608. return new Int8BufferAttribute(array, itemSize);
  29609. }
  29610. function Uint8Attribute(array, itemSize) {
  29611. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  29612. return new Uint8BufferAttribute(array, itemSize);
  29613. }
  29614. function Uint8ClampedAttribute(array, itemSize) {
  29615. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  29616. return new Uint8ClampedBufferAttribute(array, itemSize);
  29617. }
  29618. function Int16Attribute(array, itemSize) {
  29619. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  29620. return new Int16BufferAttribute(array, itemSize);
  29621. }
  29622. function Uint16Attribute(array, itemSize) {
  29623. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  29624. return new Uint16BufferAttribute(array, itemSize);
  29625. }
  29626. function Int32Attribute(array, itemSize) {
  29627. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  29628. return new Int32BufferAttribute(array, itemSize);
  29629. }
  29630. function Uint32Attribute(array, itemSize) {
  29631. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  29632. return new Uint32BufferAttribute(array, itemSize);
  29633. }
  29634. function Float32Attribute(array, itemSize) {
  29635. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  29636. return new Float32BufferAttribute(array, itemSize);
  29637. }
  29638. function Float64Attribute(array, itemSize) {
  29639. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  29640. return new Float64BufferAttribute(array, itemSize);
  29641. } //
  29642. Curve.create = function (construct, getPoint) {
  29643. console.log('THREE.Curve.create() has been deprecated');
  29644. construct.prototype = Object.create(Curve.prototype);
  29645. construct.prototype.constructor = construct;
  29646. construct.prototype.getPoint = getPoint;
  29647. return construct;
  29648. }; //
  29649. Object.assign(CurvePath.prototype, {
  29650. createPointsGeometry: function createPointsGeometry(divisions) {
  29651. 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)
  29652. var pts = this.getPoints(divisions);
  29653. return this.createGeometry(pts);
  29654. },
  29655. createSpacedPointsGeometry: function createSpacedPointsGeometry(divisions) {
  29656. console.warn('THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.'); // generate geometry from equidistant sampling along the path
  29657. var pts = this.getSpacedPoints(divisions);
  29658. return this.createGeometry(pts);
  29659. },
  29660. createGeometry: function createGeometry(points) {
  29661. console.warn('THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');
  29662. var geometry = new Geometry();
  29663. for (var i = 0, l = points.length; i < l; i++) {
  29664. var point = points[i];
  29665. geometry.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  29666. }
  29667. return geometry;
  29668. }
  29669. }); //
  29670. Object.assign(Path.prototype, {
  29671. fromPoints: function fromPoints(points) {
  29672. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  29673. return this.setFromPoints(points);
  29674. }
  29675. }); //
  29676. function ClosedSplineCurve3(points) {
  29677. console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29678. CatmullRomCurve3.call(this, points);
  29679. this.type = 'catmullrom';
  29680. this.closed = true;
  29681. }
  29682. ClosedSplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29683. function SplineCurve3(points) {
  29684. console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29685. CatmullRomCurve3.call(this, points);
  29686. this.type = 'catmullrom';
  29687. }
  29688. SplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29689. function Spline(points) {
  29690. console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');
  29691. CatmullRomCurve3.call(this, points);
  29692. this.type = 'catmullrom';
  29693. }
  29694. Spline.prototype = Object.create(CatmullRomCurve3.prototype);
  29695. Object.assign(Spline.prototype, {
  29696. initFromArray: function initFromArray()
  29697. /* a */
  29698. {
  29699. console.error('THREE.Spline: .initFromArray() has been removed.');
  29700. },
  29701. getControlPointsArray: function getControlPointsArray()
  29702. /* optionalTarget */
  29703. {
  29704. console.error('THREE.Spline: .getControlPointsArray() has been removed.');
  29705. },
  29706. reparametrizeByArcLength: function reparametrizeByArcLength()
  29707. /* samplingCoef */
  29708. {
  29709. console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');
  29710. }
  29711. }); //
  29712. function AxisHelper(size) {
  29713. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  29714. return new AxesHelper(size);
  29715. }
  29716. function BoundingBoxHelper(object, color) {
  29717. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  29718. return new BoxHelper(object, color);
  29719. }
  29720. function EdgesHelper(object, hex) {
  29721. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  29722. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  29723. color: hex !== undefined ? hex : 0xffffff
  29724. }));
  29725. }
  29726. GridHelper.prototype.setColors = function () {
  29727. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  29728. };
  29729. SkeletonHelper.prototype.update = function () {
  29730. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  29731. };
  29732. function WireframeHelper(object, hex) {
  29733. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  29734. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  29735. color: hex !== undefined ? hex : 0xffffff
  29736. }));
  29737. } //
  29738. Object.assign(Loader.prototype, {
  29739. extractUrlBase: function extractUrlBase(url) {
  29740. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  29741. return LoaderUtils.extractUrlBase(url);
  29742. }
  29743. });
  29744. Loader.Handlers = {
  29745. add: function add()
  29746. /* regex, loader */
  29747. {
  29748. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  29749. },
  29750. get: function get()
  29751. /* file */
  29752. {
  29753. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  29754. }
  29755. };
  29756. function XHRLoader(manager) {
  29757. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  29758. return new FileLoader(manager);
  29759. }
  29760. function BinaryTextureLoader(manager) {
  29761. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29762. return new DataTextureLoader(manager);
  29763. } //
  29764. Object.assign(Box2.prototype, {
  29765. center: function center(optionalTarget) {
  29766. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29767. return this.getCenter(optionalTarget);
  29768. },
  29769. empty: function empty() {
  29770. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29771. return this.isEmpty();
  29772. },
  29773. isIntersectionBox: function isIntersectionBox(box) {
  29774. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29775. return this.intersectsBox(box);
  29776. },
  29777. size: function size(optionalTarget) {
  29778. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29779. return this.getSize(optionalTarget);
  29780. }
  29781. });
  29782. Object.assign(Box3.prototype, {
  29783. center: function center(optionalTarget) {
  29784. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29785. return this.getCenter(optionalTarget);
  29786. },
  29787. empty: function empty() {
  29788. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29789. return this.isEmpty();
  29790. },
  29791. isIntersectionBox: function isIntersectionBox(box) {
  29792. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29793. return this.intersectsBox(box);
  29794. },
  29795. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29796. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29797. return this.intersectsSphere(sphere);
  29798. },
  29799. size: function size(optionalTarget) {
  29800. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29801. return this.getSize(optionalTarget);
  29802. }
  29803. });
  29804. Object.assign(Sphere.prototype, {
  29805. empty: function empty() {
  29806. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29807. return this.isEmpty();
  29808. }
  29809. });
  29810. Frustum.prototype.setFromMatrix = function (m) {
  29811. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29812. return this.setFromProjectionMatrix(m);
  29813. };
  29814. Line3.prototype.center = function (optionalTarget) {
  29815. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29816. return this.getCenter(optionalTarget);
  29817. };
  29818. Object.assign(MathUtils, {
  29819. random16: function random16() {
  29820. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29821. return Math.random();
  29822. },
  29823. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29824. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29825. return MathUtils.floorPowerOfTwo(value);
  29826. },
  29827. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29828. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29829. return MathUtils.ceilPowerOfTwo(value);
  29830. }
  29831. });
  29832. Object.assign(Matrix3.prototype, {
  29833. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29834. console.warn('THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29835. return this.toArray(array, offset);
  29836. },
  29837. multiplyVector3: function multiplyVector3(vector) {
  29838. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29839. return vector.applyMatrix3(this);
  29840. },
  29841. multiplyVector3Array: function multiplyVector3Array()
  29842. /* a */
  29843. {
  29844. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29845. },
  29846. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29847. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29848. return attribute.applyMatrix3(this);
  29849. },
  29850. applyToVector3Array: function applyToVector3Array()
  29851. /* array, offset, length */
  29852. {
  29853. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29854. },
  29855. getInverse: function getInverse(matrix) {
  29856. console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29857. return this.copy(matrix).invert();
  29858. }
  29859. });
  29860. Object.assign(Matrix4.prototype, {
  29861. extractPosition: function extractPosition(m) {
  29862. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29863. return this.copyPosition(m);
  29864. },
  29865. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29866. console.warn('THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29867. return this.toArray(array, offset);
  29868. },
  29869. getPosition: function getPosition() {
  29870. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29871. return new Vector3().setFromMatrixColumn(this, 3);
  29872. },
  29873. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29874. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29875. return this.makeRotationFromQuaternion(q);
  29876. },
  29877. multiplyToArray: function multiplyToArray() {
  29878. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29879. },
  29880. multiplyVector3: function multiplyVector3(vector) {
  29881. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29882. return vector.applyMatrix4(this);
  29883. },
  29884. multiplyVector4: function multiplyVector4(vector) {
  29885. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29886. return vector.applyMatrix4(this);
  29887. },
  29888. multiplyVector3Array: function multiplyVector3Array()
  29889. /* a */
  29890. {
  29891. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29892. },
  29893. rotateAxis: function rotateAxis(v) {
  29894. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29895. v.transformDirection(this);
  29896. },
  29897. crossVector: function crossVector(vector) {
  29898. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29899. return vector.applyMatrix4(this);
  29900. },
  29901. translate: function translate() {
  29902. console.error('THREE.Matrix4: .translate() has been removed.');
  29903. },
  29904. rotateX: function rotateX() {
  29905. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29906. },
  29907. rotateY: function rotateY() {
  29908. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29909. },
  29910. rotateZ: function rotateZ() {
  29911. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29912. },
  29913. rotateByAxis: function rotateByAxis() {
  29914. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29915. },
  29916. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29917. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29918. return attribute.applyMatrix4(this);
  29919. },
  29920. applyToVector3Array: function applyToVector3Array()
  29921. /* array, offset, length */
  29922. {
  29923. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29924. },
  29925. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29926. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29927. return this.makePerspective(left, right, top, bottom, near, far);
  29928. },
  29929. getInverse: function getInverse(matrix) {
  29930. console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29931. return this.copy(matrix).invert();
  29932. }
  29933. });
  29934. Plane.prototype.isIntersectionLine = function (line) {
  29935. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29936. return this.intersectsLine(line);
  29937. };
  29938. Object.assign(Quaternion.prototype, {
  29939. multiplyVector3: function multiplyVector3(vector) {
  29940. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29941. return vector.applyQuaternion(this);
  29942. },
  29943. inverse: function inverse() {
  29944. console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');
  29945. return this.invert();
  29946. }
  29947. });
  29948. Object.assign(Ray.prototype, {
  29949. isIntersectionBox: function isIntersectionBox(box) {
  29950. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29951. return this.intersectsBox(box);
  29952. },
  29953. isIntersectionPlane: function isIntersectionPlane(plane) {
  29954. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29955. return this.intersectsPlane(plane);
  29956. },
  29957. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29958. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29959. return this.intersectsSphere(sphere);
  29960. }
  29961. });
  29962. Object.assign(Triangle.prototype, {
  29963. area: function area() {
  29964. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29965. return this.getArea();
  29966. },
  29967. barycoordFromPoint: function barycoordFromPoint(point, target) {
  29968. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29969. return this.getBarycoord(point, target);
  29970. },
  29971. midpoint: function midpoint(target) {
  29972. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29973. return this.getMidpoint(target);
  29974. },
  29975. normal: function normal(target) {
  29976. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29977. return this.getNormal(target);
  29978. },
  29979. plane: function plane(target) {
  29980. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29981. return this.getPlane(target);
  29982. }
  29983. });
  29984. Object.assign(Triangle, {
  29985. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  29986. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29987. return Triangle.getBarycoord(point, a, b, c, target);
  29988. },
  29989. normal: function normal(a, b, c, target) {
  29990. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29991. return Triangle.getNormal(a, b, c, target);
  29992. }
  29993. });
  29994. Object.assign(Shape.prototype, {
  29995. extractAllPoints: function extractAllPoints(divisions) {
  29996. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29997. return this.extractPoints(divisions);
  29998. },
  29999. extrude: function extrude(options) {
  30000. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  30001. return new ExtrudeGeometry(this, options);
  30002. },
  30003. makeGeometry: function makeGeometry(options) {
  30004. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  30005. return new ShapeGeometry(this, options);
  30006. }
  30007. });
  30008. Object.assign(Vector2.prototype, {
  30009. fromAttribute: function fromAttribute(attribute, index, offset) {
  30010. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  30011. return this.fromBufferAttribute(attribute, index, offset);
  30012. },
  30013. distanceToManhattan: function distanceToManhattan(v) {
  30014. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  30015. return this.manhattanDistanceTo(v);
  30016. },
  30017. lengthManhattan: function lengthManhattan() {
  30018. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  30019. return this.manhattanLength();
  30020. }
  30021. });
  30022. Object.assign(Vector3.prototype, {
  30023. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  30024. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  30025. },
  30026. setEulerFromQuaternion: function setEulerFromQuaternion() {
  30027. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  30028. },
  30029. getPositionFromMatrix: function getPositionFromMatrix(m) {
  30030. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  30031. return this.setFromMatrixPosition(m);
  30032. },
  30033. getScaleFromMatrix: function getScaleFromMatrix(m) {
  30034. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  30035. return this.setFromMatrixScale(m);
  30036. },
  30037. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  30038. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  30039. return this.setFromMatrixColumn(matrix, index);
  30040. },
  30041. applyProjection: function applyProjection(m) {
  30042. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  30043. return this.applyMatrix4(m);
  30044. },
  30045. fromAttribute: function fromAttribute(attribute, index, offset) {
  30046. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  30047. return this.fromBufferAttribute(attribute, index, offset);
  30048. },
  30049. distanceToManhattan: function distanceToManhattan(v) {
  30050. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  30051. return this.manhattanDistanceTo(v);
  30052. },
  30053. lengthManhattan: function lengthManhattan() {
  30054. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  30055. return this.manhattanLength();
  30056. }
  30057. });
  30058. Object.assign(Vector4.prototype, {
  30059. fromAttribute: function fromAttribute(attribute, index, offset) {
  30060. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  30061. return this.fromBufferAttribute(attribute, index, offset);
  30062. },
  30063. lengthManhattan: function lengthManhattan() {
  30064. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  30065. return this.manhattanLength();
  30066. }
  30067. }); //
  30068. Object.assign(Geometry.prototype, {
  30069. computeTangents: function computeTangents() {
  30070. console.error('THREE.Geometry: .computeTangents() has been removed.');
  30071. },
  30072. computeLineDistances: function computeLineDistances() {
  30073. console.error('THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.');
  30074. },
  30075. applyMatrix: function applyMatrix(matrix) {
  30076. console.warn('THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().');
  30077. return this.applyMatrix4(matrix);
  30078. }
  30079. });
  30080. Object.assign(Object3D.prototype, {
  30081. getChildByName: function getChildByName(name) {
  30082. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  30083. return this.getObjectByName(name);
  30084. },
  30085. renderDepth: function renderDepth() {
  30086. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  30087. },
  30088. translate: function translate(distance, axis) {
  30089. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  30090. return this.translateOnAxis(axis, distance);
  30091. },
  30092. getWorldRotation: function getWorldRotation() {
  30093. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  30094. },
  30095. applyMatrix: function applyMatrix(matrix) {
  30096. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  30097. return this.applyMatrix4(matrix);
  30098. }
  30099. });
  30100. Object.defineProperties(Object3D.prototype, {
  30101. eulerOrder: {
  30102. get: function get() {
  30103. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  30104. return this.rotation.order;
  30105. },
  30106. set: function set(value) {
  30107. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  30108. this.rotation.order = value;
  30109. }
  30110. },
  30111. useQuaternion: {
  30112. get: function get() {
  30113. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  30114. },
  30115. set: function set() {
  30116. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  30117. }
  30118. }
  30119. });
  30120. Object.assign(Mesh.prototype, {
  30121. setDrawMode: function setDrawMode() {
  30122. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  30123. }
  30124. });
  30125. Object.defineProperties(Mesh.prototype, {
  30126. drawMode: {
  30127. get: function get() {
  30128. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  30129. return TrianglesDrawMode;
  30130. },
  30131. set: function set() {
  30132. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  30133. }
  30134. }
  30135. });
  30136. Object.defineProperties(LOD.prototype, {
  30137. objects: {
  30138. get: function get() {
  30139. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  30140. return this.levels;
  30141. }
  30142. }
  30143. });
  30144. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  30145. get: function get() {
  30146. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  30147. },
  30148. set: function set() {
  30149. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  30150. }
  30151. });
  30152. SkinnedMesh.prototype.initBones = function () {
  30153. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  30154. };
  30155. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  30156. get: function get() {
  30157. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  30158. return this.arcLengthDivisions;
  30159. },
  30160. set: function set(value) {
  30161. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  30162. this.arcLengthDivisions = value;
  30163. }
  30164. }); //
  30165. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  30166. console.warn('THREE.PerspectiveCamera.setLens is deprecated. ' + 'Use .setFocalLength and .filmGauge for a photographic setup.');
  30167. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  30168. this.setFocalLength(focalLength);
  30169. }; //
  30170. Object.defineProperties(Light.prototype, {
  30171. onlyShadow: {
  30172. set: function set() {
  30173. console.warn('THREE.Light: .onlyShadow has been removed.');
  30174. }
  30175. },
  30176. shadowCameraFov: {
  30177. set: function set(value) {
  30178. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  30179. this.shadow.camera.fov = value;
  30180. }
  30181. },
  30182. shadowCameraLeft: {
  30183. set: function set(value) {
  30184. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  30185. this.shadow.camera.left = value;
  30186. }
  30187. },
  30188. shadowCameraRight: {
  30189. set: function set(value) {
  30190. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  30191. this.shadow.camera.right = value;
  30192. }
  30193. },
  30194. shadowCameraTop: {
  30195. set: function set(value) {
  30196. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  30197. this.shadow.camera.top = value;
  30198. }
  30199. },
  30200. shadowCameraBottom: {
  30201. set: function set(value) {
  30202. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  30203. this.shadow.camera.bottom = value;
  30204. }
  30205. },
  30206. shadowCameraNear: {
  30207. set: function set(value) {
  30208. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  30209. this.shadow.camera.near = value;
  30210. }
  30211. },
  30212. shadowCameraFar: {
  30213. set: function set(value) {
  30214. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  30215. this.shadow.camera.far = value;
  30216. }
  30217. },
  30218. shadowCameraVisible: {
  30219. set: function set() {
  30220. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  30221. }
  30222. },
  30223. shadowBias: {
  30224. set: function set(value) {
  30225. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  30226. this.shadow.bias = value;
  30227. }
  30228. },
  30229. shadowDarkness: {
  30230. set: function set() {
  30231. console.warn('THREE.Light: .shadowDarkness has been removed.');
  30232. }
  30233. },
  30234. shadowMapWidth: {
  30235. set: function set(value) {
  30236. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  30237. this.shadow.mapSize.width = value;
  30238. }
  30239. },
  30240. shadowMapHeight: {
  30241. set: function set(value) {
  30242. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  30243. this.shadow.mapSize.height = value;
  30244. }
  30245. }
  30246. }); //
  30247. Object.defineProperties(BufferAttribute.prototype, {
  30248. length: {
  30249. get: function get() {
  30250. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  30251. return this.array.length;
  30252. }
  30253. },
  30254. dynamic: {
  30255. get: function get() {
  30256. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  30257. return this.usage === DynamicDrawUsage;
  30258. },
  30259. set: function set()
  30260. /* value */
  30261. {
  30262. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  30263. this.setUsage(DynamicDrawUsage);
  30264. }
  30265. }
  30266. });
  30267. Object.assign(BufferAttribute.prototype, {
  30268. setDynamic: function setDynamic(value) {
  30269. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  30270. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  30271. return this;
  30272. },
  30273. copyIndicesArray: function copyIndicesArray()
  30274. /* indices */
  30275. {
  30276. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  30277. },
  30278. setArray: function setArray()
  30279. /* array */
  30280. {
  30281. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  30282. }
  30283. });
  30284. Object.assign(BufferGeometry.prototype, {
  30285. addIndex: function addIndex(index) {
  30286. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  30287. this.setIndex(index);
  30288. },
  30289. addAttribute: function addAttribute(name, attribute) {
  30290. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  30291. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  30292. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  30293. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  30294. }
  30295. if (name === 'index') {
  30296. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  30297. this.setIndex(attribute);
  30298. return this;
  30299. }
  30300. return this.setAttribute(name, attribute);
  30301. },
  30302. addDrawCall: function addDrawCall(start, count, indexOffset) {
  30303. if (indexOffset !== undefined) {
  30304. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  30305. }
  30306. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  30307. this.addGroup(start, count);
  30308. },
  30309. clearDrawCalls: function clearDrawCalls() {
  30310. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  30311. this.clearGroups();
  30312. },
  30313. computeTangents: function computeTangents() {
  30314. console.warn('THREE.BufferGeometry: .computeTangents() has been removed.');
  30315. },
  30316. computeOffsets: function computeOffsets() {
  30317. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  30318. },
  30319. removeAttribute: function removeAttribute(name) {
  30320. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  30321. return this.deleteAttribute(name);
  30322. },
  30323. applyMatrix: function applyMatrix(matrix) {
  30324. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  30325. return this.applyMatrix4(matrix);
  30326. }
  30327. });
  30328. Object.defineProperties(BufferGeometry.prototype, {
  30329. drawcalls: {
  30330. get: function get() {
  30331. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  30332. return this.groups;
  30333. }
  30334. },
  30335. offsets: {
  30336. get: function get() {
  30337. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  30338. return this.groups;
  30339. }
  30340. }
  30341. });
  30342. Object.defineProperties(InstancedBufferGeometry.prototype, {
  30343. maxInstancedCount: {
  30344. get: function get() {
  30345. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  30346. return this.instanceCount;
  30347. },
  30348. set: function set(value) {
  30349. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  30350. this.instanceCount = value;
  30351. }
  30352. }
  30353. });
  30354. Object.defineProperties(Raycaster.prototype, {
  30355. linePrecision: {
  30356. get: function get() {
  30357. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  30358. return this.params.Line.threshold;
  30359. },
  30360. set: function set(value) {
  30361. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  30362. this.params.Line.threshold = value;
  30363. }
  30364. }
  30365. });
  30366. Object.defineProperties(InterleavedBuffer.prototype, {
  30367. dynamic: {
  30368. get: function get() {
  30369. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  30370. return this.usage === DynamicDrawUsage;
  30371. },
  30372. set: function set(value) {
  30373. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  30374. this.setUsage(value);
  30375. }
  30376. }
  30377. });
  30378. Object.assign(InterleavedBuffer.prototype, {
  30379. setDynamic: function setDynamic(value) {
  30380. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  30381. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  30382. return this;
  30383. },
  30384. setArray: function setArray()
  30385. /* array */
  30386. {
  30387. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  30388. }
  30389. }); //
  30390. Object.assign(ExtrudeBufferGeometry.prototype, {
  30391. getArrays: function getArrays() {
  30392. console.error('THREE.ExtrudeBufferGeometry: .getArrays() has been removed.');
  30393. },
  30394. addShapeList: function addShapeList() {
  30395. console.error('THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.');
  30396. },
  30397. addShape: function addShape() {
  30398. console.error('THREE.ExtrudeBufferGeometry: .addShape() has been removed.');
  30399. }
  30400. }); //
  30401. Object.assign(Scene.prototype, {
  30402. dispose: function dispose() {
  30403. console.error('THREE.Scene: .dispose() has been removed.');
  30404. }
  30405. }); //
  30406. Object.defineProperties(Uniform.prototype, {
  30407. dynamic: {
  30408. set: function set() {
  30409. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  30410. }
  30411. },
  30412. onUpdate: {
  30413. value: function value() {
  30414. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  30415. return this;
  30416. }
  30417. }
  30418. }); //
  30419. Object.defineProperties(Material.prototype, {
  30420. wrapAround: {
  30421. get: function get() {
  30422. console.warn('THREE.Material: .wrapAround has been removed.');
  30423. },
  30424. set: function set() {
  30425. console.warn('THREE.Material: .wrapAround has been removed.');
  30426. }
  30427. },
  30428. overdraw: {
  30429. get: function get() {
  30430. console.warn('THREE.Material: .overdraw has been removed.');
  30431. },
  30432. set: function set() {
  30433. console.warn('THREE.Material: .overdraw has been removed.');
  30434. }
  30435. },
  30436. wrapRGB: {
  30437. get: function get() {
  30438. console.warn('THREE.Material: .wrapRGB has been removed.');
  30439. return new Color();
  30440. }
  30441. },
  30442. shading: {
  30443. get: function get() {
  30444. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30445. },
  30446. set: function set(value) {
  30447. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30448. this.flatShading = value === FlatShading;
  30449. }
  30450. },
  30451. stencilMask: {
  30452. get: function get() {
  30453. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30454. return this.stencilFuncMask;
  30455. },
  30456. set: function set(value) {
  30457. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30458. this.stencilFuncMask = value;
  30459. }
  30460. }
  30461. });
  30462. Object.defineProperties(MeshPhongMaterial.prototype, {
  30463. metal: {
  30464. get: function get() {
  30465. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  30466. return false;
  30467. },
  30468. set: function set() {
  30469. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  30470. }
  30471. }
  30472. });
  30473. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  30474. transparency: {
  30475. get: function get() {
  30476. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30477. return this.transmission;
  30478. },
  30479. set: function set(value) {
  30480. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30481. this.transmission = value;
  30482. }
  30483. }
  30484. });
  30485. Object.defineProperties(ShaderMaterial.prototype, {
  30486. derivatives: {
  30487. get: function get() {
  30488. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30489. return this.extensions.derivatives;
  30490. },
  30491. set: function set(value) {
  30492. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30493. this.extensions.derivatives = value;
  30494. }
  30495. }
  30496. }); //
  30497. Object.assign(WebGLRenderer.prototype, {
  30498. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  30499. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  30500. this.setRenderTarget(renderTarget);
  30501. this.clear(color, depth, stencil);
  30502. },
  30503. animate: function animate(callback) {
  30504. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  30505. this.setAnimationLoop(callback);
  30506. },
  30507. getCurrentRenderTarget: function getCurrentRenderTarget() {
  30508. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  30509. return this.getRenderTarget();
  30510. },
  30511. getMaxAnisotropy: function getMaxAnisotropy() {
  30512. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  30513. return this.capabilities.getMaxAnisotropy();
  30514. },
  30515. getPrecision: function getPrecision() {
  30516. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  30517. return this.capabilities.precision;
  30518. },
  30519. resetGLState: function resetGLState() {
  30520. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  30521. return this.state.reset();
  30522. },
  30523. supportsFloatTextures: function supportsFloatTextures() {
  30524. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  30525. return this.extensions.get('OES_texture_float');
  30526. },
  30527. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  30528. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  30529. return this.extensions.get('OES_texture_half_float');
  30530. },
  30531. supportsStandardDerivatives: function supportsStandardDerivatives() {
  30532. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  30533. return this.extensions.get('OES_standard_derivatives');
  30534. },
  30535. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  30536. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  30537. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  30538. },
  30539. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  30540. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  30541. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  30542. },
  30543. supportsBlendMinMax: function supportsBlendMinMax() {
  30544. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  30545. return this.extensions.get('EXT_blend_minmax');
  30546. },
  30547. supportsVertexTextures: function supportsVertexTextures() {
  30548. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  30549. return this.capabilities.vertexTextures;
  30550. },
  30551. supportsInstancedArrays: function supportsInstancedArrays() {
  30552. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  30553. return this.extensions.get('ANGLE_instanced_arrays');
  30554. },
  30555. enableScissorTest: function enableScissorTest(boolean) {
  30556. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  30557. this.setScissorTest(boolean);
  30558. },
  30559. initMaterial: function initMaterial() {
  30560. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  30561. },
  30562. addPrePlugin: function addPrePlugin() {
  30563. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  30564. },
  30565. addPostPlugin: function addPostPlugin() {
  30566. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  30567. },
  30568. updateShadowMap: function updateShadowMap() {
  30569. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  30570. },
  30571. setFaceCulling: function setFaceCulling() {
  30572. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  30573. },
  30574. allocTextureUnit: function allocTextureUnit() {
  30575. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  30576. },
  30577. setTexture: function setTexture() {
  30578. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  30579. },
  30580. setTexture2D: function setTexture2D() {
  30581. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  30582. },
  30583. setTextureCube: function setTextureCube() {
  30584. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  30585. },
  30586. getActiveMipMapLevel: function getActiveMipMapLevel() {
  30587. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  30588. return this.getActiveMipmapLevel();
  30589. }
  30590. });
  30591. Object.defineProperties(WebGLRenderer.prototype, {
  30592. shadowMapEnabled: {
  30593. get: function get() {
  30594. return this.shadowMap.enabled;
  30595. },
  30596. set: function set(value) {
  30597. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  30598. this.shadowMap.enabled = value;
  30599. }
  30600. },
  30601. shadowMapType: {
  30602. get: function get() {
  30603. return this.shadowMap.type;
  30604. },
  30605. set: function set(value) {
  30606. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  30607. this.shadowMap.type = value;
  30608. }
  30609. },
  30610. shadowMapCullFace: {
  30611. get: function get() {
  30612. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30613. return undefined;
  30614. },
  30615. set: function set()
  30616. /* value */
  30617. {
  30618. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30619. }
  30620. },
  30621. context: {
  30622. get: function get() {
  30623. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  30624. return this.getContext();
  30625. }
  30626. },
  30627. vr: {
  30628. get: function get() {
  30629. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  30630. return this.xr;
  30631. }
  30632. },
  30633. gammaInput: {
  30634. get: function get() {
  30635. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30636. return false;
  30637. },
  30638. set: function set() {
  30639. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30640. }
  30641. },
  30642. gammaOutput: {
  30643. get: function get() {
  30644. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30645. return false;
  30646. },
  30647. set: function set(value) {
  30648. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30649. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  30650. }
  30651. },
  30652. toneMappingWhitePoint: {
  30653. get: function get() {
  30654. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30655. return 1.0;
  30656. },
  30657. set: function set() {
  30658. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30659. }
  30660. }
  30661. });
  30662. Object.defineProperties(WebGLShadowMap.prototype, {
  30663. cullFace: {
  30664. get: function get() {
  30665. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30666. return undefined;
  30667. },
  30668. set: function set()
  30669. /* cullFace */
  30670. {
  30671. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30672. }
  30673. },
  30674. renderReverseSided: {
  30675. get: function get() {
  30676. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30677. return undefined;
  30678. },
  30679. set: function set() {
  30680. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30681. }
  30682. },
  30683. renderSingleSided: {
  30684. get: function get() {
  30685. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30686. return undefined;
  30687. },
  30688. set: function set() {
  30689. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30690. }
  30691. }
  30692. });
  30693. function WebGLRenderTargetCube(width, height, options) {
  30694. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  30695. return new WebGLCubeRenderTarget(width, options);
  30696. } //
  30697. Object.defineProperties(WebGLRenderTarget.prototype, {
  30698. wrapS: {
  30699. get: function get() {
  30700. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30701. return this.texture.wrapS;
  30702. },
  30703. set: function set(value) {
  30704. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30705. this.texture.wrapS = value;
  30706. }
  30707. },
  30708. wrapT: {
  30709. get: function get() {
  30710. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30711. return this.texture.wrapT;
  30712. },
  30713. set: function set(value) {
  30714. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30715. this.texture.wrapT = value;
  30716. }
  30717. },
  30718. magFilter: {
  30719. get: function get() {
  30720. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30721. return this.texture.magFilter;
  30722. },
  30723. set: function set(value) {
  30724. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30725. this.texture.magFilter = value;
  30726. }
  30727. },
  30728. minFilter: {
  30729. get: function get() {
  30730. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30731. return this.texture.minFilter;
  30732. },
  30733. set: function set(value) {
  30734. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30735. this.texture.minFilter = value;
  30736. }
  30737. },
  30738. anisotropy: {
  30739. get: function get() {
  30740. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30741. return this.texture.anisotropy;
  30742. },
  30743. set: function set(value) {
  30744. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30745. this.texture.anisotropy = value;
  30746. }
  30747. },
  30748. offset: {
  30749. get: function get() {
  30750. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30751. return this.texture.offset;
  30752. },
  30753. set: function set(value) {
  30754. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30755. this.texture.offset = value;
  30756. }
  30757. },
  30758. repeat: {
  30759. get: function get() {
  30760. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30761. return this.texture.repeat;
  30762. },
  30763. set: function set(value) {
  30764. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30765. this.texture.repeat = value;
  30766. }
  30767. },
  30768. format: {
  30769. get: function get() {
  30770. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30771. return this.texture.format;
  30772. },
  30773. set: function set(value) {
  30774. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30775. this.texture.format = value;
  30776. }
  30777. },
  30778. type: {
  30779. get: function get() {
  30780. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30781. return this.texture.type;
  30782. },
  30783. set: function set(value) {
  30784. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30785. this.texture.type = value;
  30786. }
  30787. },
  30788. generateMipmaps: {
  30789. get: function get() {
  30790. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30791. return this.texture.generateMipmaps;
  30792. },
  30793. set: function set(value) {
  30794. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30795. this.texture.generateMipmaps = value;
  30796. }
  30797. }
  30798. }); //
  30799. Object.defineProperties(Audio.prototype, {
  30800. load: {
  30801. value: function value(file) {
  30802. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30803. var scope = this;
  30804. var audioLoader = new AudioLoader();
  30805. audioLoader.load(file, function (buffer) {
  30806. scope.setBuffer(buffer);
  30807. });
  30808. return this;
  30809. }
  30810. },
  30811. startTime: {
  30812. set: function set() {
  30813. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30814. }
  30815. }
  30816. });
  30817. AudioAnalyser.prototype.getData = function () {
  30818. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30819. return this.getFrequencyData();
  30820. }; //
  30821. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30822. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30823. return this.update(renderer, scene);
  30824. };
  30825. CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
  30826. console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
  30827. return this.renderTarget.clear(renderer, color, depth, stencil);
  30828. }; //
  30829. var GeometryUtils = {
  30830. merge: function merge(geometry1, geometry2, materialIndexOffset) {
  30831. console.warn('THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.');
  30832. var matrix;
  30833. if (geometry2.isMesh) {
  30834. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30835. matrix = geometry2.matrix;
  30836. geometry2 = geometry2.geometry;
  30837. }
  30838. geometry1.merge(geometry2, matrix, materialIndexOffset);
  30839. },
  30840. center: function center(geometry) {
  30841. console.warn('THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.');
  30842. return geometry.center();
  30843. }
  30844. };
  30845. ImageUtils.crossOrigin = undefined;
  30846. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30847. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30848. var loader = new TextureLoader();
  30849. loader.setCrossOrigin(this.crossOrigin);
  30850. var texture = loader.load(url, onLoad, undefined, onError);
  30851. if (mapping) texture.mapping = mapping;
  30852. return texture;
  30853. };
  30854. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30855. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30856. var loader = new CubeTextureLoader();
  30857. loader.setCrossOrigin(this.crossOrigin);
  30858. var texture = loader.load(urls, onLoad, undefined, onError);
  30859. if (mapping) texture.mapping = mapping;
  30860. return texture;
  30861. };
  30862. ImageUtils.loadCompressedTexture = function () {
  30863. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30864. };
  30865. ImageUtils.loadCompressedTextureCube = function () {
  30866. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30867. }; //
  30868. function CanvasRenderer() {
  30869. console.error('THREE.CanvasRenderer has been removed');
  30870. } //
  30871. function JSONLoader() {
  30872. console.error('THREE.JSONLoader has been removed.');
  30873. } //
  30874. var SceneUtils = {
  30875. createMultiMaterialObject: function createMultiMaterialObject()
  30876. /* geometry, materials */
  30877. {
  30878. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30879. },
  30880. detach: function detach()
  30881. /* child, parent, scene */
  30882. {
  30883. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30884. },
  30885. attach: function attach()
  30886. /* child, scene, parent */
  30887. {
  30888. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30889. }
  30890. }; //
  30891. function LensFlare() {
  30892. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30893. }
  30894. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30895. /* eslint-disable no-undef */
  30896. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30897. detail: {
  30898. revision: REVISION
  30899. }
  30900. }));
  30901. /* eslint-enable no-undef */
  30902. }
  30903. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30904. exports.AddEquation = AddEquation;
  30905. exports.AddOperation = AddOperation;
  30906. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30907. exports.AdditiveBlending = AdditiveBlending;
  30908. exports.AlphaFormat = AlphaFormat;
  30909. exports.AlwaysDepth = AlwaysDepth;
  30910. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30911. exports.AmbientLight = AmbientLight;
  30912. exports.AmbientLightProbe = AmbientLightProbe;
  30913. exports.AnimationClip = AnimationClip;
  30914. exports.AnimationLoader = AnimationLoader;
  30915. exports.AnimationMixer = AnimationMixer;
  30916. exports.AnimationObjectGroup = AnimationObjectGroup;
  30917. exports.AnimationUtils = AnimationUtils;
  30918. exports.ArcCurve = ArcCurve;
  30919. exports.ArrayCamera = ArrayCamera;
  30920. exports.ArrowHelper = ArrowHelper;
  30921. exports.Audio = Audio;
  30922. exports.AudioAnalyser = AudioAnalyser;
  30923. exports.AudioContext = AudioContext;
  30924. exports.AudioListener = AudioListener;
  30925. exports.AudioLoader = AudioLoader;
  30926. exports.AxesHelper = AxesHelper;
  30927. exports.AxisHelper = AxisHelper;
  30928. exports.BackSide = BackSide;
  30929. exports.BasicDepthPacking = BasicDepthPacking;
  30930. exports.BasicShadowMap = BasicShadowMap;
  30931. exports.BinaryTextureLoader = BinaryTextureLoader;
  30932. exports.Bone = Bone;
  30933. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30934. exports.BoundingBoxHelper = BoundingBoxHelper;
  30935. exports.Box2 = Box2;
  30936. exports.Box3 = Box3;
  30937. exports.Box3Helper = Box3Helper;
  30938. exports.BoxBufferGeometry = BoxBufferGeometry;
  30939. exports.BoxGeometry = BoxGeometry;
  30940. exports.BoxHelper = BoxHelper;
  30941. exports.BufferAttribute = BufferAttribute;
  30942. exports.BufferGeometry = BufferGeometry;
  30943. exports.BufferGeometryLoader = BufferGeometryLoader;
  30944. exports.ByteType = ByteType;
  30945. exports.Cache = Cache;
  30946. exports.Camera = Camera;
  30947. exports.CameraHelper = CameraHelper;
  30948. exports.CanvasRenderer = CanvasRenderer;
  30949. exports.CanvasTexture = CanvasTexture;
  30950. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30951. exports.CineonToneMapping = CineonToneMapping;
  30952. exports.CircleBufferGeometry = CircleBufferGeometry;
  30953. exports.CircleGeometry = CircleGeometry;
  30954. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30955. exports.Clock = Clock;
  30956. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  30957. exports.Color = Color;
  30958. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30959. exports.CompressedTexture = CompressedTexture;
  30960. exports.CompressedTextureLoader = CompressedTextureLoader;
  30961. exports.ConeBufferGeometry = ConeBufferGeometry;
  30962. exports.ConeGeometry = ConeGeometry;
  30963. exports.CubeCamera = CubeCamera;
  30964. exports.CubeGeometry = BoxGeometry;
  30965. exports.CubeReflectionMapping = CubeReflectionMapping;
  30966. exports.CubeRefractionMapping = CubeRefractionMapping;
  30967. exports.CubeTexture = CubeTexture;
  30968. exports.CubeTextureLoader = CubeTextureLoader;
  30969. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30970. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30971. exports.CubicBezierCurve = CubicBezierCurve;
  30972. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30973. exports.CubicInterpolant = CubicInterpolant;
  30974. exports.CullFaceBack = CullFaceBack;
  30975. exports.CullFaceFront = CullFaceFront;
  30976. exports.CullFaceFrontBack = CullFaceFrontBack;
  30977. exports.CullFaceNone = CullFaceNone;
  30978. exports.Curve = Curve;
  30979. exports.CurvePath = CurvePath;
  30980. exports.CustomBlending = CustomBlending;
  30981. exports.CustomToneMapping = CustomToneMapping;
  30982. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  30983. exports.CylinderGeometry = CylinderGeometry;
  30984. exports.Cylindrical = Cylindrical;
  30985. exports.DataTexture = DataTexture;
  30986. exports.DataTexture2DArray = DataTexture2DArray;
  30987. exports.DataTexture3D = DataTexture3D;
  30988. exports.DataTextureLoader = DataTextureLoader;
  30989. exports.DataUtils = DataUtils;
  30990. exports.DecrementStencilOp = DecrementStencilOp;
  30991. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30992. exports.DefaultLoadingManager = DefaultLoadingManager;
  30993. exports.DepthFormat = DepthFormat;
  30994. exports.DepthStencilFormat = DepthStencilFormat;
  30995. exports.DepthTexture = DepthTexture;
  30996. exports.DirectionalLight = DirectionalLight;
  30997. exports.DirectionalLightHelper = DirectionalLightHelper;
  30998. exports.DiscreteInterpolant = DiscreteInterpolant;
  30999. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  31000. exports.DodecahedronGeometry = DodecahedronGeometry;
  31001. exports.DoubleSide = DoubleSide;
  31002. exports.DstAlphaFactor = DstAlphaFactor;
  31003. exports.DstColorFactor = DstColorFactor;
  31004. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  31005. exports.DynamicCopyUsage = DynamicCopyUsage;
  31006. exports.DynamicDrawUsage = DynamicDrawUsage;
  31007. exports.DynamicReadUsage = DynamicReadUsage;
  31008. exports.EdgesGeometry = EdgesGeometry;
  31009. exports.EdgesHelper = EdgesHelper;
  31010. exports.EllipseCurve = EllipseCurve;
  31011. exports.EqualDepth = EqualDepth;
  31012. exports.EqualStencilFunc = EqualStencilFunc;
  31013. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  31014. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  31015. exports.Euler = Euler;
  31016. exports.EventDispatcher = EventDispatcher;
  31017. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  31018. exports.ExtrudeGeometry = ExtrudeGeometry;
  31019. exports.Face3 = Face3;
  31020. exports.Face4 = Face4;
  31021. exports.FaceColors = FaceColors;
  31022. exports.FileLoader = FileLoader;
  31023. exports.FlatShading = FlatShading;
  31024. exports.Float16BufferAttribute = Float16BufferAttribute;
  31025. exports.Float32Attribute = Float32Attribute;
  31026. exports.Float32BufferAttribute = Float32BufferAttribute;
  31027. exports.Float64Attribute = Float64Attribute;
  31028. exports.Float64BufferAttribute = Float64BufferAttribute;
  31029. exports.FloatType = FloatType;
  31030. exports.Fog = Fog;
  31031. exports.FogExp2 = FogExp2;
  31032. exports.Font = Font;
  31033. exports.FontLoader = FontLoader;
  31034. exports.FrontSide = FrontSide;
  31035. exports.Frustum = Frustum;
  31036. exports.GLBufferAttribute = GLBufferAttribute;
  31037. exports.GLSL1 = GLSL1;
  31038. exports.GLSL3 = GLSL3;
  31039. exports.GammaEncoding = GammaEncoding;
  31040. exports.Geometry = Geometry;
  31041. exports.GeometryUtils = GeometryUtils;
  31042. exports.GreaterDepth = GreaterDepth;
  31043. exports.GreaterEqualDepth = GreaterEqualDepth;
  31044. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  31045. exports.GreaterStencilFunc = GreaterStencilFunc;
  31046. exports.GridHelper = GridHelper;
  31047. exports.Group = Group;
  31048. exports.HalfFloatType = HalfFloatType;
  31049. exports.HemisphereLight = HemisphereLight;
  31050. exports.HemisphereLightHelper = HemisphereLightHelper;
  31051. exports.HemisphereLightProbe = HemisphereLightProbe;
  31052. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  31053. exports.IcosahedronGeometry = IcosahedronGeometry;
  31054. exports.ImageBitmapLoader = ImageBitmapLoader;
  31055. exports.ImageLoader = ImageLoader;
  31056. exports.ImageUtils = ImageUtils;
  31057. exports.ImmediateRenderObject = ImmediateRenderObject;
  31058. exports.IncrementStencilOp = IncrementStencilOp;
  31059. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  31060. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  31061. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  31062. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  31063. exports.InstancedMesh = InstancedMesh;
  31064. exports.Int16Attribute = Int16Attribute;
  31065. exports.Int16BufferAttribute = Int16BufferAttribute;
  31066. exports.Int32Attribute = Int32Attribute;
  31067. exports.Int32BufferAttribute = Int32BufferAttribute;
  31068. exports.Int8Attribute = Int8Attribute;
  31069. exports.Int8BufferAttribute = Int8BufferAttribute;
  31070. exports.IntType = IntType;
  31071. exports.InterleavedBuffer = InterleavedBuffer;
  31072. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  31073. exports.Interpolant = Interpolant;
  31074. exports.InterpolateDiscrete = InterpolateDiscrete;
  31075. exports.InterpolateLinear = InterpolateLinear;
  31076. exports.InterpolateSmooth = InterpolateSmooth;
  31077. exports.InvertStencilOp = InvertStencilOp;
  31078. exports.JSONLoader = JSONLoader;
  31079. exports.KeepStencilOp = KeepStencilOp;
  31080. exports.KeyframeTrack = KeyframeTrack;
  31081. exports.LOD = LOD;
  31082. exports.LatheBufferGeometry = LatheBufferGeometry;
  31083. exports.LatheGeometry = LatheGeometry;
  31084. exports.Layers = Layers;
  31085. exports.LensFlare = LensFlare;
  31086. exports.LessDepth = LessDepth;
  31087. exports.LessEqualDepth = LessEqualDepth;
  31088. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  31089. exports.LessStencilFunc = LessStencilFunc;
  31090. exports.Light = Light;
  31091. exports.LightProbe = LightProbe;
  31092. exports.Line = Line;
  31093. exports.Line3 = Line3;
  31094. exports.LineBasicMaterial = LineBasicMaterial;
  31095. exports.LineCurve = LineCurve;
  31096. exports.LineCurve3 = LineCurve3;
  31097. exports.LineDashedMaterial = LineDashedMaterial;
  31098. exports.LineLoop = LineLoop;
  31099. exports.LinePieces = LinePieces;
  31100. exports.LineSegments = LineSegments;
  31101. exports.LineStrip = LineStrip;
  31102. exports.LinearEncoding = LinearEncoding;
  31103. exports.LinearFilter = LinearFilter;
  31104. exports.LinearInterpolant = LinearInterpolant;
  31105. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  31106. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  31107. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  31108. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  31109. exports.LinearToneMapping = LinearToneMapping;
  31110. exports.Loader = Loader;
  31111. exports.LoaderUtils = LoaderUtils;
  31112. exports.LoadingManager = LoadingManager;
  31113. exports.LogLuvEncoding = LogLuvEncoding;
  31114. exports.LoopOnce = LoopOnce;
  31115. exports.LoopPingPong = LoopPingPong;
  31116. exports.LoopRepeat = LoopRepeat;
  31117. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  31118. exports.LuminanceFormat = LuminanceFormat;
  31119. exports.MOUSE = MOUSE;
  31120. exports.Material = Material;
  31121. exports.MaterialLoader = MaterialLoader;
  31122. exports.Math = MathUtils;
  31123. exports.MathUtils = MathUtils;
  31124. exports.Matrix3 = Matrix3;
  31125. exports.Matrix4 = Matrix4;
  31126. exports.MaxEquation = MaxEquation;
  31127. exports.Mesh = Mesh;
  31128. exports.MeshBasicMaterial = MeshBasicMaterial;
  31129. exports.MeshDepthMaterial = MeshDepthMaterial;
  31130. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  31131. exports.MeshFaceMaterial = MeshFaceMaterial;
  31132. exports.MeshLambertMaterial = MeshLambertMaterial;
  31133. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  31134. exports.MeshNormalMaterial = MeshNormalMaterial;
  31135. exports.MeshPhongMaterial = MeshPhongMaterial;
  31136. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  31137. exports.MeshStandardMaterial = MeshStandardMaterial;
  31138. exports.MeshToonMaterial = MeshToonMaterial;
  31139. exports.MinEquation = MinEquation;
  31140. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  31141. exports.MixOperation = MixOperation;
  31142. exports.MultiMaterial = MultiMaterial;
  31143. exports.MultiplyBlending = MultiplyBlending;
  31144. exports.MultiplyOperation = MultiplyOperation;
  31145. exports.NearestFilter = NearestFilter;
  31146. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  31147. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  31148. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  31149. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  31150. exports.NeverDepth = NeverDepth;
  31151. exports.NeverStencilFunc = NeverStencilFunc;
  31152. exports.NoBlending = NoBlending;
  31153. exports.NoColors = NoColors;
  31154. exports.NoToneMapping = NoToneMapping;
  31155. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  31156. exports.NormalBlending = NormalBlending;
  31157. exports.NotEqualDepth = NotEqualDepth;
  31158. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  31159. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  31160. exports.Object3D = Object3D;
  31161. exports.ObjectLoader = ObjectLoader;
  31162. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  31163. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  31164. exports.OctahedronGeometry = OctahedronGeometry;
  31165. exports.OneFactor = OneFactor;
  31166. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  31167. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  31168. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  31169. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  31170. exports.OrthographicCamera = OrthographicCamera;
  31171. exports.PCFShadowMap = PCFShadowMap;
  31172. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  31173. exports.PMREMGenerator = PMREMGenerator;
  31174. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  31175. exports.ParametricGeometry = ParametricGeometry;
  31176. exports.Particle = Particle;
  31177. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  31178. exports.ParticleSystem = ParticleSystem;
  31179. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  31180. exports.Path = Path;
  31181. exports.PerspectiveCamera = PerspectiveCamera;
  31182. exports.Plane = Plane;
  31183. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  31184. exports.PlaneGeometry = PlaneGeometry;
  31185. exports.PlaneHelper = PlaneHelper;
  31186. exports.PointCloud = PointCloud;
  31187. exports.PointCloudMaterial = PointCloudMaterial;
  31188. exports.PointLight = PointLight;
  31189. exports.PointLightHelper = PointLightHelper;
  31190. exports.Points = Points;
  31191. exports.PointsMaterial = PointsMaterial;
  31192. exports.PolarGridHelper = PolarGridHelper;
  31193. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  31194. exports.PolyhedronGeometry = PolyhedronGeometry;
  31195. exports.PositionalAudio = PositionalAudio;
  31196. exports.PropertyBinding = PropertyBinding;
  31197. exports.PropertyMixer = PropertyMixer;
  31198. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  31199. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  31200. exports.Quaternion = Quaternion;
  31201. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  31202. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  31203. exports.REVISION = REVISION;
  31204. exports.RGBADepthPacking = RGBADepthPacking;
  31205. exports.RGBAFormat = RGBAFormat;
  31206. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  31207. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  31208. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  31209. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  31210. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  31211. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  31212. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  31213. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  31214. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  31215. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  31216. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  31217. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  31218. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  31219. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  31220. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  31221. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  31222. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  31223. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  31224. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  31225. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  31226. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  31227. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  31228. exports.RGBDEncoding = RGBDEncoding;
  31229. exports.RGBEEncoding = RGBEEncoding;
  31230. exports.RGBEFormat = RGBEFormat;
  31231. exports.RGBFormat = RGBFormat;
  31232. exports.RGBIntegerFormat = RGBIntegerFormat;
  31233. exports.RGBM16Encoding = RGBM16Encoding;
  31234. exports.RGBM7Encoding = RGBM7Encoding;
  31235. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  31236. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  31237. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  31238. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  31239. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  31240. exports.RGFormat = RGFormat;
  31241. exports.RGIntegerFormat = RGIntegerFormat;
  31242. exports.RawShaderMaterial = RawShaderMaterial;
  31243. exports.Ray = Ray;
  31244. exports.Raycaster = Raycaster;
  31245. exports.RectAreaLight = RectAreaLight;
  31246. exports.RedFormat = RedFormat;
  31247. exports.RedIntegerFormat = RedIntegerFormat;
  31248. exports.ReinhardToneMapping = ReinhardToneMapping;
  31249. exports.RepeatWrapping = RepeatWrapping;
  31250. exports.ReplaceStencilOp = ReplaceStencilOp;
  31251. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  31252. exports.RingBufferGeometry = RingBufferGeometry;
  31253. exports.RingGeometry = RingGeometry;
  31254. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  31255. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  31256. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  31257. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  31258. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  31259. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  31260. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  31261. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  31262. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  31263. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  31264. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  31265. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  31266. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  31267. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  31268. exports.Scene = Scene;
  31269. exports.SceneUtils = SceneUtils;
  31270. exports.ShaderChunk = ShaderChunk;
  31271. exports.ShaderLib = ShaderLib;
  31272. exports.ShaderMaterial = ShaderMaterial;
  31273. exports.ShadowMaterial = ShadowMaterial;
  31274. exports.Shape = Shape;
  31275. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  31276. exports.ShapeGeometry = ShapeGeometry;
  31277. exports.ShapePath = ShapePath;
  31278. exports.ShapeUtils = ShapeUtils;
  31279. exports.ShortType = ShortType;
  31280. exports.Skeleton = Skeleton;
  31281. exports.SkeletonHelper = SkeletonHelper;
  31282. exports.SkinnedMesh = SkinnedMesh;
  31283. exports.SmoothShading = SmoothShading;
  31284. exports.Sphere = Sphere;
  31285. exports.SphereBufferGeometry = SphereBufferGeometry;
  31286. exports.SphereGeometry = SphereGeometry;
  31287. exports.Spherical = Spherical;
  31288. exports.SphericalHarmonics3 = SphericalHarmonics3;
  31289. exports.Spline = Spline;
  31290. exports.SplineCurve = SplineCurve;
  31291. exports.SplineCurve3 = SplineCurve3;
  31292. exports.SpotLight = SpotLight;
  31293. exports.SpotLightHelper = SpotLightHelper;
  31294. exports.Sprite = Sprite;
  31295. exports.SpriteMaterial = SpriteMaterial;
  31296. exports.SrcAlphaFactor = SrcAlphaFactor;
  31297. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  31298. exports.SrcColorFactor = SrcColorFactor;
  31299. exports.StaticCopyUsage = StaticCopyUsage;
  31300. exports.StaticDrawUsage = StaticDrawUsage;
  31301. exports.StaticReadUsage = StaticReadUsage;
  31302. exports.StereoCamera = StereoCamera;
  31303. exports.StreamCopyUsage = StreamCopyUsage;
  31304. exports.StreamDrawUsage = StreamDrawUsage;
  31305. exports.StreamReadUsage = StreamReadUsage;
  31306. exports.StringKeyframeTrack = StringKeyframeTrack;
  31307. exports.SubtractEquation = SubtractEquation;
  31308. exports.SubtractiveBlending = SubtractiveBlending;
  31309. exports.TOUCH = TOUCH;
  31310. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  31311. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  31312. exports.TetrahedronGeometry = TetrahedronGeometry;
  31313. exports.TextBufferGeometry = TextBufferGeometry;
  31314. exports.TextGeometry = TextGeometry;
  31315. exports.Texture = Texture;
  31316. exports.TextureLoader = TextureLoader;
  31317. exports.TorusBufferGeometry = TorusBufferGeometry;
  31318. exports.TorusGeometry = TorusGeometry;
  31319. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  31320. exports.TorusKnotGeometry = TorusKnotGeometry;
  31321. exports.Triangle = Triangle;
  31322. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  31323. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  31324. exports.TrianglesDrawMode = TrianglesDrawMode;
  31325. exports.TubeBufferGeometry = TubeBufferGeometry;
  31326. exports.TubeGeometry = TubeGeometry;
  31327. exports.UVMapping = UVMapping;
  31328. exports.Uint16Attribute = Uint16Attribute;
  31329. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  31330. exports.Uint32Attribute = Uint32Attribute;
  31331. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  31332. exports.Uint8Attribute = Uint8Attribute;
  31333. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  31334. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  31335. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  31336. exports.Uniform = Uniform;
  31337. exports.UniformsLib = UniformsLib;
  31338. exports.UniformsUtils = UniformsUtils;
  31339. exports.UnsignedByteType = UnsignedByteType;
  31340. exports.UnsignedInt248Type = UnsignedInt248Type;
  31341. exports.UnsignedIntType = UnsignedIntType;
  31342. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  31343. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  31344. exports.UnsignedShort565Type = UnsignedShort565Type;
  31345. exports.UnsignedShortType = UnsignedShortType;
  31346. exports.VSMShadowMap = VSMShadowMap;
  31347. exports.Vector2 = Vector2;
  31348. exports.Vector3 = Vector3;
  31349. exports.Vector4 = Vector4;
  31350. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  31351. exports.Vertex = Vertex;
  31352. exports.VertexColors = VertexColors;
  31353. exports.VideoTexture = VideoTexture;
  31354. exports.WebGL1Renderer = WebGL1Renderer;
  31355. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  31356. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  31357. exports.WebGLRenderTarget = WebGLRenderTarget;
  31358. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  31359. exports.WebGLRenderer = WebGLRenderer;
  31360. exports.WebGLUtils = WebGLUtils;
  31361. exports.WireframeGeometry = WireframeGeometry;
  31362. exports.WireframeHelper = WireframeHelper;
  31363. exports.WrapAroundEnding = WrapAroundEnding;
  31364. exports.XHRLoader = XHRLoader;
  31365. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  31366. exports.ZeroFactor = ZeroFactor;
  31367. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  31368. exports.ZeroStencilOp = ZeroStencilOp;
  31369. exports.sRGBEncoding = sRGBEncoding;
  31370. Object.defineProperty(exports, '__esModule', { value: true });
  31371. })));
粤ICP备19079148号