three.js 1.2 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654
  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 = '123dev';
  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. };
  924. _proto.scale = function scale(sx, sy) {
  925. var te = this.elements;
  926. te[0] *= sx;
  927. te[3] *= sx;
  928. te[6] *= sx;
  929. te[1] *= sy;
  930. te[4] *= sy;
  931. te[7] *= sy;
  932. return this;
  933. };
  934. _proto.rotate = function rotate(theta) {
  935. var c = Math.cos(theta);
  936. var s = Math.sin(theta);
  937. var te = this.elements;
  938. var a11 = te[0],
  939. a12 = te[3],
  940. a13 = te[6];
  941. var a21 = te[1],
  942. a22 = te[4],
  943. a23 = te[7];
  944. te[0] = c * a11 + s * a21;
  945. te[3] = c * a12 + s * a22;
  946. te[6] = c * a13 + s * a23;
  947. te[1] = -s * a11 + c * a21;
  948. te[4] = -s * a12 + c * a22;
  949. te[7] = -s * a13 + c * a23;
  950. return this;
  951. };
  952. _proto.translate = function translate(tx, ty) {
  953. var te = this.elements;
  954. te[0] += tx * te[2];
  955. te[3] += tx * te[5];
  956. te[6] += tx * te[8];
  957. te[1] += ty * te[2];
  958. te[4] += ty * te[5];
  959. te[7] += ty * te[8];
  960. return this;
  961. };
  962. _proto.equals = function equals(matrix) {
  963. var te = this.elements;
  964. var me = matrix.elements;
  965. for (var i = 0; i < 9; i++) {
  966. if (te[i] !== me[i]) return false;
  967. }
  968. return true;
  969. };
  970. _proto.fromArray = function fromArray(array, offset) {
  971. if (offset === void 0) {
  972. offset = 0;
  973. }
  974. for (var i = 0; i < 9; i++) {
  975. this.elements[i] = array[i + offset];
  976. }
  977. return this;
  978. };
  979. _proto.toArray = function toArray(array, offset) {
  980. if (array === void 0) {
  981. array = [];
  982. }
  983. if (offset === void 0) {
  984. offset = 0;
  985. }
  986. var te = this.elements;
  987. array[offset] = te[0];
  988. array[offset + 1] = te[1];
  989. array[offset + 2] = te[2];
  990. array[offset + 3] = te[3];
  991. array[offset + 4] = te[4];
  992. array[offset + 5] = te[5];
  993. array[offset + 6] = te[6];
  994. array[offset + 7] = te[7];
  995. array[offset + 8] = te[8];
  996. return array;
  997. };
  998. return Matrix3;
  999. }();
  1000. var _canvas;
  1001. var ImageUtils = {
  1002. getDataURL: function getDataURL(image) {
  1003. if (/^data:/i.test(image.src)) {
  1004. return image.src;
  1005. }
  1006. if (typeof HTMLCanvasElement == 'undefined') {
  1007. return image.src;
  1008. }
  1009. var canvas;
  1010. if (image instanceof HTMLCanvasElement) {
  1011. canvas = image;
  1012. } else {
  1013. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1014. _canvas.width = image.width;
  1015. _canvas.height = image.height;
  1016. var context = _canvas.getContext('2d');
  1017. if (image instanceof ImageData) {
  1018. context.putImageData(image, 0, 0);
  1019. } else {
  1020. context.drawImage(image, 0, 0, image.width, image.height);
  1021. }
  1022. canvas = _canvas;
  1023. }
  1024. if (canvas.width > 2048 || canvas.height > 2048) {
  1025. return canvas.toDataURL('image/jpeg', 0.6);
  1026. } else {
  1027. return canvas.toDataURL('image/png');
  1028. }
  1029. }
  1030. };
  1031. var textureId = 0;
  1032. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1033. Object.defineProperty(this, 'id', {
  1034. value: textureId++
  1035. });
  1036. this.uuid = MathUtils.generateUUID();
  1037. this.name = '';
  1038. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  1039. this.mipmaps = [];
  1040. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  1041. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  1042. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  1043. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  1044. this.minFilter = minFilter !== undefined ? minFilter : LinearMipmapLinearFilter;
  1045. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  1046. this.format = format !== undefined ? format : RGBAFormat;
  1047. this.internalFormat = null;
  1048. this.type = type !== undefined ? type : UnsignedByteType;
  1049. this.offset = new Vector2(0, 0);
  1050. this.repeat = new Vector2(1, 1);
  1051. this.center = new Vector2(0, 0);
  1052. this.rotation = 0;
  1053. this.matrixAutoUpdate = true;
  1054. this.matrix = new Matrix3();
  1055. this.generateMipmaps = true;
  1056. this.premultiplyAlpha = false;
  1057. this.flipY = true;
  1058. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1059. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1060. //
  1061. // Also changing the encoding after already used by a Material will not automatically make the Material
  1062. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1063. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  1064. this.version = 0;
  1065. this.onUpdate = null;
  1066. }
  1067. Texture.DEFAULT_IMAGE = undefined;
  1068. Texture.DEFAULT_MAPPING = UVMapping;
  1069. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1070. constructor: Texture,
  1071. isTexture: true,
  1072. updateMatrix: function updateMatrix() {
  1073. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1074. },
  1075. clone: function clone() {
  1076. return new this.constructor().copy(this);
  1077. },
  1078. copy: function copy(source) {
  1079. this.name = source.name;
  1080. this.image = source.image;
  1081. this.mipmaps = source.mipmaps.slice(0);
  1082. this.mapping = source.mapping;
  1083. this.wrapS = source.wrapS;
  1084. this.wrapT = source.wrapT;
  1085. this.magFilter = source.magFilter;
  1086. this.minFilter = source.minFilter;
  1087. this.anisotropy = source.anisotropy;
  1088. this.format = source.format;
  1089. this.internalFormat = source.internalFormat;
  1090. this.type = source.type;
  1091. this.offset.copy(source.offset);
  1092. this.repeat.copy(source.repeat);
  1093. this.center.copy(source.center);
  1094. this.rotation = source.rotation;
  1095. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1096. this.matrix.copy(source.matrix);
  1097. this.generateMipmaps = source.generateMipmaps;
  1098. this.premultiplyAlpha = source.premultiplyAlpha;
  1099. this.flipY = source.flipY;
  1100. this.unpackAlignment = source.unpackAlignment;
  1101. this.encoding = source.encoding;
  1102. return this;
  1103. },
  1104. toJSON: function toJSON(meta) {
  1105. var isRootObject = meta === undefined || typeof meta === 'string';
  1106. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1107. return meta.textures[this.uuid];
  1108. }
  1109. var output = {
  1110. metadata: {
  1111. version: 4.5,
  1112. type: 'Texture',
  1113. generator: 'Texture.toJSON'
  1114. },
  1115. uuid: this.uuid,
  1116. name: this.name,
  1117. mapping: this.mapping,
  1118. repeat: [this.repeat.x, this.repeat.y],
  1119. offset: [this.offset.x, this.offset.y],
  1120. center: [this.center.x, this.center.y],
  1121. rotation: this.rotation,
  1122. wrap: [this.wrapS, this.wrapT],
  1123. format: this.format,
  1124. type: this.type,
  1125. encoding: this.encoding,
  1126. minFilter: this.minFilter,
  1127. magFilter: this.magFilter,
  1128. anisotropy: this.anisotropy,
  1129. flipY: this.flipY,
  1130. premultiplyAlpha: this.premultiplyAlpha,
  1131. unpackAlignment: this.unpackAlignment
  1132. };
  1133. if (this.image !== undefined) {
  1134. // TODO: Move to THREE.Image
  1135. var image = this.image;
  1136. if (image.uuid === undefined) {
  1137. image.uuid = MathUtils.generateUUID(); // UGH
  1138. }
  1139. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1140. var url;
  1141. if (Array.isArray(image)) {
  1142. // process array of images e.g. CubeTexture
  1143. url = [];
  1144. for (var i = 0, l = image.length; i < l; i++) {
  1145. // check cube texture with data textures
  1146. if (image[i].isDataTexture) {
  1147. url.push(serializeImage(image[i].image));
  1148. } else {
  1149. url.push(serializeImage(image[i]));
  1150. }
  1151. }
  1152. } else {
  1153. // process single image
  1154. url = serializeImage(image);
  1155. }
  1156. meta.images[image.uuid] = {
  1157. uuid: image.uuid,
  1158. url: url
  1159. };
  1160. }
  1161. output.image = image.uuid;
  1162. }
  1163. if (!isRootObject) {
  1164. meta.textures[this.uuid] = output;
  1165. }
  1166. return output;
  1167. },
  1168. dispose: function dispose() {
  1169. this.dispatchEvent({
  1170. type: 'dispose'
  1171. });
  1172. },
  1173. transformUv: function transformUv(uv) {
  1174. if (this.mapping !== UVMapping) return uv;
  1175. uv.applyMatrix3(this.matrix);
  1176. if (uv.x < 0 || uv.x > 1) {
  1177. switch (this.wrapS) {
  1178. case RepeatWrapping:
  1179. uv.x = uv.x - Math.floor(uv.x);
  1180. break;
  1181. case ClampToEdgeWrapping:
  1182. uv.x = uv.x < 0 ? 0 : 1;
  1183. break;
  1184. case MirroredRepeatWrapping:
  1185. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1186. uv.x = Math.ceil(uv.x) - uv.x;
  1187. } else {
  1188. uv.x = uv.x - Math.floor(uv.x);
  1189. }
  1190. break;
  1191. }
  1192. }
  1193. if (uv.y < 0 || uv.y > 1) {
  1194. switch (this.wrapT) {
  1195. case RepeatWrapping:
  1196. uv.y = uv.y - Math.floor(uv.y);
  1197. break;
  1198. case ClampToEdgeWrapping:
  1199. uv.y = uv.y < 0 ? 0 : 1;
  1200. break;
  1201. case MirroredRepeatWrapping:
  1202. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1203. uv.y = Math.ceil(uv.y) - uv.y;
  1204. } else {
  1205. uv.y = uv.y - Math.floor(uv.y);
  1206. }
  1207. break;
  1208. }
  1209. }
  1210. if (this.flipY) {
  1211. uv.y = 1 - uv.y;
  1212. }
  1213. return uv;
  1214. }
  1215. });
  1216. Object.defineProperty(Texture.prototype, "needsUpdate", {
  1217. set: function set(value) {
  1218. if (value === true) this.version++;
  1219. }
  1220. });
  1221. function serializeImage(image) {
  1222. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  1223. // default images
  1224. return ImageUtils.getDataURL(image);
  1225. } else {
  1226. if (image.data) {
  1227. // images of DataTexture
  1228. return {
  1229. data: Array.prototype.slice.call(image.data),
  1230. width: image.width,
  1231. height: image.height,
  1232. type: image.data.constructor.name
  1233. };
  1234. } else {
  1235. console.warn('THREE.Texture: Unable to serialize Texture.');
  1236. return {};
  1237. }
  1238. }
  1239. }
  1240. var Vector4 = /*#__PURE__*/function () {
  1241. function Vector4(x, y, z, w) {
  1242. if (x === void 0) {
  1243. x = 0;
  1244. }
  1245. if (y === void 0) {
  1246. y = 0;
  1247. }
  1248. if (z === void 0) {
  1249. z = 0;
  1250. }
  1251. if (w === void 0) {
  1252. w = 1;
  1253. }
  1254. Object.defineProperty(this, 'isVector4', {
  1255. value: true
  1256. });
  1257. this.x = x;
  1258. this.y = y;
  1259. this.z = z;
  1260. this.w = w;
  1261. }
  1262. var _proto = Vector4.prototype;
  1263. _proto.set = function set(x, y, z, w) {
  1264. this.x = x;
  1265. this.y = y;
  1266. this.z = z;
  1267. this.w = w;
  1268. return this;
  1269. };
  1270. _proto.setScalar = function setScalar(scalar) {
  1271. this.x = scalar;
  1272. this.y = scalar;
  1273. this.z = scalar;
  1274. this.w = scalar;
  1275. return this;
  1276. };
  1277. _proto.setX = function setX(x) {
  1278. this.x = x;
  1279. return this;
  1280. };
  1281. _proto.setY = function setY(y) {
  1282. this.y = y;
  1283. return this;
  1284. };
  1285. _proto.setZ = function setZ(z) {
  1286. this.z = z;
  1287. return this;
  1288. };
  1289. _proto.setW = function setW(w) {
  1290. this.w = w;
  1291. return this;
  1292. };
  1293. _proto.setComponent = function setComponent(index, value) {
  1294. switch (index) {
  1295. case 0:
  1296. this.x = value;
  1297. break;
  1298. case 1:
  1299. this.y = value;
  1300. break;
  1301. case 2:
  1302. this.z = value;
  1303. break;
  1304. case 3:
  1305. this.w = value;
  1306. break;
  1307. default:
  1308. throw new Error('index is out of range: ' + index);
  1309. }
  1310. return this;
  1311. };
  1312. _proto.getComponent = function getComponent(index) {
  1313. switch (index) {
  1314. case 0:
  1315. return this.x;
  1316. case 1:
  1317. return this.y;
  1318. case 2:
  1319. return this.z;
  1320. case 3:
  1321. return this.w;
  1322. default:
  1323. throw new Error('index is out of range: ' + index);
  1324. }
  1325. };
  1326. _proto.clone = function clone() {
  1327. return new this.constructor(this.x, this.y, this.z, this.w);
  1328. };
  1329. _proto.copy = function copy(v) {
  1330. this.x = v.x;
  1331. this.y = v.y;
  1332. this.z = v.z;
  1333. this.w = v.w !== undefined ? v.w : 1;
  1334. return this;
  1335. };
  1336. _proto.add = function add(v, w) {
  1337. if (w !== undefined) {
  1338. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1339. return this.addVectors(v, w);
  1340. }
  1341. this.x += v.x;
  1342. this.y += v.y;
  1343. this.z += v.z;
  1344. this.w += v.w;
  1345. return this;
  1346. };
  1347. _proto.addScalar = function addScalar(s) {
  1348. this.x += s;
  1349. this.y += s;
  1350. this.z += s;
  1351. this.w += s;
  1352. return this;
  1353. };
  1354. _proto.addVectors = function addVectors(a, b) {
  1355. this.x = a.x + b.x;
  1356. this.y = a.y + b.y;
  1357. this.z = a.z + b.z;
  1358. this.w = a.w + b.w;
  1359. return this;
  1360. };
  1361. _proto.addScaledVector = function addScaledVector(v, s) {
  1362. this.x += v.x * s;
  1363. this.y += v.y * s;
  1364. this.z += v.z * s;
  1365. this.w += v.w * s;
  1366. return this;
  1367. };
  1368. _proto.sub = function sub(v, w) {
  1369. if (w !== undefined) {
  1370. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1371. return this.subVectors(v, w);
  1372. }
  1373. this.x -= v.x;
  1374. this.y -= v.y;
  1375. this.z -= v.z;
  1376. this.w -= v.w;
  1377. return this;
  1378. };
  1379. _proto.subScalar = function subScalar(s) {
  1380. this.x -= s;
  1381. this.y -= s;
  1382. this.z -= s;
  1383. this.w -= s;
  1384. return this;
  1385. };
  1386. _proto.subVectors = function subVectors(a, b) {
  1387. this.x = a.x - b.x;
  1388. this.y = a.y - b.y;
  1389. this.z = a.z - b.z;
  1390. this.w = a.w - b.w;
  1391. return this;
  1392. };
  1393. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1394. this.x *= scalar;
  1395. this.y *= scalar;
  1396. this.z *= scalar;
  1397. this.w *= scalar;
  1398. return this;
  1399. };
  1400. _proto.applyMatrix4 = function applyMatrix4(m) {
  1401. var x = this.x,
  1402. y = this.y,
  1403. z = this.z,
  1404. w = this.w;
  1405. var e = m.elements;
  1406. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  1407. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  1408. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  1409. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  1410. return this;
  1411. };
  1412. _proto.divideScalar = function divideScalar(scalar) {
  1413. return this.multiplyScalar(1 / scalar);
  1414. };
  1415. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  1416. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1417. // q is assumed to be normalized
  1418. this.w = 2 * Math.acos(q.w);
  1419. var s = Math.sqrt(1 - q.w * q.w);
  1420. if (s < 0.0001) {
  1421. this.x = 1;
  1422. this.y = 0;
  1423. this.z = 0;
  1424. } else {
  1425. this.x = q.x / s;
  1426. this.y = q.y / s;
  1427. this.z = q.z / s;
  1428. }
  1429. return this;
  1430. };
  1431. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  1432. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1433. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1434. var angle, x, y, z; // variables for result
  1435. var epsilon = 0.01,
  1436. // margin to allow for rounding errors
  1437. epsilon2 = 0.1,
  1438. // margin to distinguish between 0 and 180 degrees
  1439. te = m.elements,
  1440. m11 = te[0],
  1441. m12 = te[4],
  1442. m13 = te[8],
  1443. m21 = te[1],
  1444. m22 = te[5],
  1445. m23 = te[9],
  1446. m31 = te[2],
  1447. m32 = te[6],
  1448. m33 = te[10];
  1449. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  1450. // singularity found
  1451. // first check for identity matrix which must have +1 for all terms
  1452. // in leading diagonal and zero in other terms
  1453. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  1454. // this singularity is identity matrix so angle = 0
  1455. this.set(1, 0, 0, 0);
  1456. return this; // zero angle, arbitrary axis
  1457. } // otherwise this singularity is angle = 180
  1458. angle = Math.PI;
  1459. var xx = (m11 + 1) / 2;
  1460. var yy = (m22 + 1) / 2;
  1461. var zz = (m33 + 1) / 2;
  1462. var xy = (m12 + m21) / 4;
  1463. var xz = (m13 + m31) / 4;
  1464. var yz = (m23 + m32) / 4;
  1465. if (xx > yy && xx > zz) {
  1466. // m11 is the largest diagonal term
  1467. if (xx < epsilon) {
  1468. x = 0;
  1469. y = 0.707106781;
  1470. z = 0.707106781;
  1471. } else {
  1472. x = Math.sqrt(xx);
  1473. y = xy / x;
  1474. z = xz / x;
  1475. }
  1476. } else if (yy > zz) {
  1477. // m22 is the largest diagonal term
  1478. if (yy < epsilon) {
  1479. x = 0.707106781;
  1480. y = 0;
  1481. z = 0.707106781;
  1482. } else {
  1483. y = Math.sqrt(yy);
  1484. x = xy / y;
  1485. z = yz / y;
  1486. }
  1487. } else {
  1488. // m33 is the largest diagonal term so base result on this
  1489. if (zz < epsilon) {
  1490. x = 0.707106781;
  1491. y = 0.707106781;
  1492. z = 0;
  1493. } else {
  1494. z = Math.sqrt(zz);
  1495. x = xz / z;
  1496. y = yz / z;
  1497. }
  1498. }
  1499. this.set(x, y, z, angle);
  1500. return this; // return 180 deg rotation
  1501. } // as we have reached here there are no singularities so we can handle normally
  1502. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  1503. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1504. // caught by singularity test above, but I've left it in just in case
  1505. this.x = (m32 - m23) / s;
  1506. this.y = (m13 - m31) / s;
  1507. this.z = (m21 - m12) / s;
  1508. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  1509. return this;
  1510. };
  1511. _proto.min = function min(v) {
  1512. this.x = Math.min(this.x, v.x);
  1513. this.y = Math.min(this.y, v.y);
  1514. this.z = Math.min(this.z, v.z);
  1515. this.w = Math.min(this.w, v.w);
  1516. return this;
  1517. };
  1518. _proto.max = function max(v) {
  1519. this.x = Math.max(this.x, v.x);
  1520. this.y = Math.max(this.y, v.y);
  1521. this.z = Math.max(this.z, v.z);
  1522. this.w = Math.max(this.w, v.w);
  1523. return this;
  1524. };
  1525. _proto.clamp = function clamp(min, max) {
  1526. // assumes min < max, componentwise
  1527. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1528. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1529. this.z = Math.max(min.z, Math.min(max.z, this.z));
  1530. this.w = Math.max(min.w, Math.min(max.w, this.w));
  1531. return this;
  1532. };
  1533. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1534. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1535. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1536. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  1537. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  1538. return this;
  1539. };
  1540. _proto.clampLength = function clampLength(min, max) {
  1541. var length = this.length();
  1542. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1543. };
  1544. _proto.floor = function floor() {
  1545. this.x = Math.floor(this.x);
  1546. this.y = Math.floor(this.y);
  1547. this.z = Math.floor(this.z);
  1548. this.w = Math.floor(this.w);
  1549. return this;
  1550. };
  1551. _proto.ceil = function ceil() {
  1552. this.x = Math.ceil(this.x);
  1553. this.y = Math.ceil(this.y);
  1554. this.z = Math.ceil(this.z);
  1555. this.w = Math.ceil(this.w);
  1556. return this;
  1557. };
  1558. _proto.round = function round() {
  1559. this.x = Math.round(this.x);
  1560. this.y = Math.round(this.y);
  1561. this.z = Math.round(this.z);
  1562. this.w = Math.round(this.w);
  1563. return this;
  1564. };
  1565. _proto.roundToZero = function roundToZero() {
  1566. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1567. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1568. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  1569. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  1570. return this;
  1571. };
  1572. _proto.negate = function negate() {
  1573. this.x = -this.x;
  1574. this.y = -this.y;
  1575. this.z = -this.z;
  1576. this.w = -this.w;
  1577. return this;
  1578. };
  1579. _proto.dot = function dot(v) {
  1580. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1581. };
  1582. _proto.lengthSq = function lengthSq() {
  1583. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1584. };
  1585. _proto.length = function length() {
  1586. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  1587. };
  1588. _proto.manhattanLength = function manhattanLength() {
  1589. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  1590. };
  1591. _proto.normalize = function normalize() {
  1592. return this.divideScalar(this.length() || 1);
  1593. };
  1594. _proto.setLength = function setLength(length) {
  1595. return this.normalize().multiplyScalar(length);
  1596. };
  1597. _proto.lerp = function lerp(v, alpha) {
  1598. this.x += (v.x - this.x) * alpha;
  1599. this.y += (v.y - this.y) * alpha;
  1600. this.z += (v.z - this.z) * alpha;
  1601. this.w += (v.w - this.w) * alpha;
  1602. return this;
  1603. };
  1604. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1605. this.x = v1.x + (v2.x - v1.x) * alpha;
  1606. this.y = v1.y + (v2.y - v1.y) * alpha;
  1607. this.z = v1.z + (v2.z - v1.z) * alpha;
  1608. this.w = v1.w + (v2.w - v1.w) * alpha;
  1609. return this;
  1610. };
  1611. _proto.equals = function equals(v) {
  1612. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  1613. };
  1614. _proto.fromArray = function fromArray(array, offset) {
  1615. if (offset === void 0) {
  1616. offset = 0;
  1617. }
  1618. this.x = array[offset];
  1619. this.y = array[offset + 1];
  1620. this.z = array[offset + 2];
  1621. this.w = array[offset + 3];
  1622. return this;
  1623. };
  1624. _proto.toArray = function toArray(array, offset) {
  1625. if (array === void 0) {
  1626. array = [];
  1627. }
  1628. if (offset === void 0) {
  1629. offset = 0;
  1630. }
  1631. array[offset] = this.x;
  1632. array[offset + 1] = this.y;
  1633. array[offset + 2] = this.z;
  1634. array[offset + 3] = this.w;
  1635. return array;
  1636. };
  1637. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1638. if (offset !== undefined) {
  1639. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  1640. }
  1641. this.x = attribute.getX(index);
  1642. this.y = attribute.getY(index);
  1643. this.z = attribute.getZ(index);
  1644. this.w = attribute.getW(index);
  1645. return this;
  1646. };
  1647. _proto.random = function random() {
  1648. this.x = Math.random();
  1649. this.y = Math.random();
  1650. this.z = Math.random();
  1651. this.w = Math.random();
  1652. return this;
  1653. };
  1654. _createClass(Vector4, [{
  1655. key: "width",
  1656. get: function get() {
  1657. return this.z;
  1658. },
  1659. set: function set(value) {
  1660. this.z = value;
  1661. }
  1662. }, {
  1663. key: "height",
  1664. get: function get() {
  1665. return this.w;
  1666. },
  1667. set: function set(value) {
  1668. this.w = value;
  1669. }
  1670. }]);
  1671. return Vector4;
  1672. }();
  1673. /*
  1674. In options, we can specify:
  1675. * Texture parameters for an auto-generated target texture
  1676. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1677. */
  1678. function WebGLRenderTarget(width, height, options) {
  1679. this.width = width;
  1680. this.height = height;
  1681. this.scissor = new Vector4(0, 0, width, height);
  1682. this.scissorTest = false;
  1683. this.viewport = new Vector4(0, 0, width, height);
  1684. options = options || {};
  1685. this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  1686. this.texture.image = {};
  1687. this.texture.image.width = width;
  1688. this.texture.image.height = height;
  1689. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  1690. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  1691. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1692. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  1693. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1694. }
  1695. WebGLRenderTarget.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1696. constructor: WebGLRenderTarget,
  1697. isWebGLRenderTarget: true,
  1698. setSize: function setSize(width, height) {
  1699. if (this.width !== width || this.height !== height) {
  1700. this.width = width;
  1701. this.height = height;
  1702. this.texture.image.width = width;
  1703. this.texture.image.height = height;
  1704. this.dispose();
  1705. }
  1706. this.viewport.set(0, 0, width, height);
  1707. this.scissor.set(0, 0, width, height);
  1708. },
  1709. clone: function clone() {
  1710. return new this.constructor().copy(this);
  1711. },
  1712. copy: function copy(source) {
  1713. this.width = source.width;
  1714. this.height = source.height;
  1715. this.viewport.copy(source.viewport);
  1716. this.texture = source.texture.clone();
  1717. this.depthBuffer = source.depthBuffer;
  1718. this.stencilBuffer = source.stencilBuffer;
  1719. this.depthTexture = source.depthTexture;
  1720. return this;
  1721. },
  1722. dispose: function dispose() {
  1723. this.dispatchEvent({
  1724. type: 'dispose'
  1725. });
  1726. }
  1727. });
  1728. function WebGLMultisampleRenderTarget(width, height, options) {
  1729. WebGLRenderTarget.call(this, width, height, options);
  1730. this.samples = 4;
  1731. }
  1732. WebGLMultisampleRenderTarget.prototype = Object.assign(Object.create(WebGLRenderTarget.prototype), {
  1733. constructor: WebGLMultisampleRenderTarget,
  1734. isWebGLMultisampleRenderTarget: true,
  1735. copy: function copy(source) {
  1736. WebGLRenderTarget.prototype.copy.call(this, source);
  1737. this.samples = source.samples;
  1738. return this;
  1739. }
  1740. });
  1741. var Quaternion = /*#__PURE__*/function () {
  1742. function Quaternion(x, y, z, w) {
  1743. if (x === void 0) {
  1744. x = 0;
  1745. }
  1746. if (y === void 0) {
  1747. y = 0;
  1748. }
  1749. if (z === void 0) {
  1750. z = 0;
  1751. }
  1752. if (w === void 0) {
  1753. w = 1;
  1754. }
  1755. Object.defineProperty(this, 'isQuaternion', {
  1756. value: true
  1757. });
  1758. this._x = x;
  1759. this._y = y;
  1760. this._z = z;
  1761. this._w = w;
  1762. }
  1763. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  1764. return qm.copy(qa).slerp(qb, t);
  1765. };
  1766. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  1767. // fuzz-free, array-based Quaternion SLERP operation
  1768. var x0 = src0[srcOffset0 + 0],
  1769. y0 = src0[srcOffset0 + 1],
  1770. z0 = src0[srcOffset0 + 2],
  1771. w0 = src0[srcOffset0 + 3];
  1772. var x1 = src1[srcOffset1 + 0],
  1773. y1 = src1[srcOffset1 + 1],
  1774. z1 = src1[srcOffset1 + 2],
  1775. w1 = src1[srcOffset1 + 3];
  1776. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  1777. var s = 1 - t;
  1778. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1779. dir = cos >= 0 ? 1 : -1,
  1780. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  1781. if (sqrSin > Number.EPSILON) {
  1782. var sin = Math.sqrt(sqrSin),
  1783. len = Math.atan2(sin, cos * dir);
  1784. s = Math.sin(s * len) / sin;
  1785. t = Math.sin(t * len) / sin;
  1786. }
  1787. var tDir = t * dir;
  1788. x0 = x0 * s + x1 * tDir;
  1789. y0 = y0 * s + y1 * tDir;
  1790. z0 = z0 * s + z1 * tDir;
  1791. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  1792. if (s === 1 - t) {
  1793. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  1794. x0 *= f;
  1795. y0 *= f;
  1796. z0 *= f;
  1797. w0 *= f;
  1798. }
  1799. }
  1800. dst[dstOffset] = x0;
  1801. dst[dstOffset + 1] = y0;
  1802. dst[dstOffset + 2] = z0;
  1803. dst[dstOffset + 3] = w0;
  1804. };
  1805. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  1806. var x0 = src0[srcOffset0];
  1807. var y0 = src0[srcOffset0 + 1];
  1808. var z0 = src0[srcOffset0 + 2];
  1809. var w0 = src0[srcOffset0 + 3];
  1810. var x1 = src1[srcOffset1];
  1811. var y1 = src1[srcOffset1 + 1];
  1812. var z1 = src1[srcOffset1 + 2];
  1813. var w1 = src1[srcOffset1 + 3];
  1814. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  1815. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  1816. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  1817. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  1818. return dst;
  1819. };
  1820. var _proto = Quaternion.prototype;
  1821. _proto.set = function set(x, y, z, w) {
  1822. this._x = x;
  1823. this._y = y;
  1824. this._z = z;
  1825. this._w = w;
  1826. this._onChangeCallback();
  1827. return this;
  1828. };
  1829. _proto.clone = function clone() {
  1830. return new this.constructor(this._x, this._y, this._z, this._w);
  1831. };
  1832. _proto.copy = function copy(quaternion) {
  1833. this._x = quaternion.x;
  1834. this._y = quaternion.y;
  1835. this._z = quaternion.z;
  1836. this._w = quaternion.w;
  1837. this._onChangeCallback();
  1838. return this;
  1839. };
  1840. _proto.setFromEuler = function setFromEuler(euler, update) {
  1841. if (!(euler && euler.isEuler)) {
  1842. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  1843. }
  1844. var x = euler._x,
  1845. y = euler._y,
  1846. z = euler._z,
  1847. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  1848. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1849. // content/SpinCalc.m
  1850. var cos = Math.cos;
  1851. var sin = Math.sin;
  1852. var c1 = cos(x / 2);
  1853. var c2 = cos(y / 2);
  1854. var c3 = cos(z / 2);
  1855. var s1 = sin(x / 2);
  1856. var s2 = sin(y / 2);
  1857. var s3 = sin(z / 2);
  1858. switch (order) {
  1859. case 'XYZ':
  1860. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1861. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1862. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1863. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1864. break;
  1865. case 'YXZ':
  1866. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1867. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1868. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1869. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1870. break;
  1871. case 'ZXY':
  1872. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1873. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1874. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1875. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1876. break;
  1877. case 'ZYX':
  1878. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1879. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1880. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1881. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1882. break;
  1883. case 'YZX':
  1884. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1885. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1886. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1887. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1888. break;
  1889. case 'XZY':
  1890. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1891. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1892. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1893. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1894. break;
  1895. default:
  1896. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  1897. }
  1898. if (update !== false) this._onChangeCallback();
  1899. return this;
  1900. };
  1901. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  1902. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1903. // assumes axis is normalized
  1904. var halfAngle = angle / 2,
  1905. s = Math.sin(halfAngle);
  1906. this._x = axis.x * s;
  1907. this._y = axis.y * s;
  1908. this._z = axis.z * s;
  1909. this._w = Math.cos(halfAngle);
  1910. this._onChangeCallback();
  1911. return this;
  1912. };
  1913. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  1914. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1915. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1916. var te = m.elements,
  1917. m11 = te[0],
  1918. m12 = te[4],
  1919. m13 = te[8],
  1920. m21 = te[1],
  1921. m22 = te[5],
  1922. m23 = te[9],
  1923. m31 = te[2],
  1924. m32 = te[6],
  1925. m33 = te[10],
  1926. trace = m11 + m22 + m33;
  1927. if (trace > 0) {
  1928. var s = 0.5 / Math.sqrt(trace + 1.0);
  1929. this._w = 0.25 / s;
  1930. this._x = (m32 - m23) * s;
  1931. this._y = (m13 - m31) * s;
  1932. this._z = (m21 - m12) * s;
  1933. } else if (m11 > m22 && m11 > m33) {
  1934. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  1935. this._w = (m32 - m23) / _s;
  1936. this._x = 0.25 * _s;
  1937. this._y = (m12 + m21) / _s;
  1938. this._z = (m13 + m31) / _s;
  1939. } else if (m22 > m33) {
  1940. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  1941. this._w = (m13 - m31) / _s2;
  1942. this._x = (m12 + m21) / _s2;
  1943. this._y = 0.25 * _s2;
  1944. this._z = (m23 + m32) / _s2;
  1945. } else {
  1946. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  1947. this._w = (m21 - m12) / _s3;
  1948. this._x = (m13 + m31) / _s3;
  1949. this._y = (m23 + m32) / _s3;
  1950. this._z = 0.25 * _s3;
  1951. }
  1952. this._onChangeCallback();
  1953. return this;
  1954. };
  1955. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  1956. // assumes direction vectors vFrom and vTo are normalized
  1957. var EPS = 0.000001;
  1958. var r = vFrom.dot(vTo) + 1;
  1959. if (r < EPS) {
  1960. r = 0;
  1961. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  1962. this._x = -vFrom.y;
  1963. this._y = vFrom.x;
  1964. this._z = 0;
  1965. this._w = r;
  1966. } else {
  1967. this._x = 0;
  1968. this._y = -vFrom.z;
  1969. this._z = vFrom.y;
  1970. this._w = r;
  1971. }
  1972. } else {
  1973. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  1974. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  1975. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  1976. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  1977. this._w = r;
  1978. }
  1979. return this.normalize();
  1980. };
  1981. _proto.angleTo = function angleTo(q) {
  1982. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  1983. };
  1984. _proto.rotateTowards = function rotateTowards(q, step) {
  1985. var angle = this.angleTo(q);
  1986. if (angle === 0) return this;
  1987. var t = Math.min(1, step / angle);
  1988. this.slerp(q, t);
  1989. return this;
  1990. };
  1991. _proto.identity = function identity() {
  1992. return this.set(0, 0, 0, 1);
  1993. };
  1994. _proto.invert = function invert() {
  1995. // quaternion is assumed to have unit length
  1996. return this.conjugate();
  1997. };
  1998. _proto.conjugate = function conjugate() {
  1999. this._x *= -1;
  2000. this._y *= -1;
  2001. this._z *= -1;
  2002. this._onChangeCallback();
  2003. return this;
  2004. };
  2005. _proto.dot = function dot(v) {
  2006. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2007. };
  2008. _proto.lengthSq = function lengthSq() {
  2009. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2010. };
  2011. _proto.length = function length() {
  2012. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  2013. };
  2014. _proto.normalize = function normalize() {
  2015. var l = this.length();
  2016. if (l === 0) {
  2017. this._x = 0;
  2018. this._y = 0;
  2019. this._z = 0;
  2020. this._w = 1;
  2021. } else {
  2022. l = 1 / l;
  2023. this._x = this._x * l;
  2024. this._y = this._y * l;
  2025. this._z = this._z * l;
  2026. this._w = this._w * l;
  2027. }
  2028. this._onChangeCallback();
  2029. return this;
  2030. };
  2031. _proto.multiply = function multiply(q, p) {
  2032. if (p !== undefined) {
  2033. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2034. return this.multiplyQuaternions(q, p);
  2035. }
  2036. return this.multiplyQuaternions(this, q);
  2037. };
  2038. _proto.premultiply = function premultiply(q) {
  2039. return this.multiplyQuaternions(q, this);
  2040. };
  2041. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2042. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2043. var qax = a._x,
  2044. qay = a._y,
  2045. qaz = a._z,
  2046. qaw = a._w;
  2047. var qbx = b._x,
  2048. qby = b._y,
  2049. qbz = b._z,
  2050. qbw = b._w;
  2051. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2052. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2053. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2054. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2055. this._onChangeCallback();
  2056. return this;
  2057. };
  2058. _proto.slerp = function slerp(qb, t) {
  2059. if (t === 0) return this;
  2060. if (t === 1) return this.copy(qb);
  2061. var x = this._x,
  2062. y = this._y,
  2063. z = this._z,
  2064. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2065. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2066. if (cosHalfTheta < 0) {
  2067. this._w = -qb._w;
  2068. this._x = -qb._x;
  2069. this._y = -qb._y;
  2070. this._z = -qb._z;
  2071. cosHalfTheta = -cosHalfTheta;
  2072. } else {
  2073. this.copy(qb);
  2074. }
  2075. if (cosHalfTheta >= 1.0) {
  2076. this._w = w;
  2077. this._x = x;
  2078. this._y = y;
  2079. this._z = z;
  2080. return this;
  2081. }
  2082. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2083. if (sqrSinHalfTheta <= Number.EPSILON) {
  2084. var s = 1 - t;
  2085. this._w = s * w + t * this._w;
  2086. this._x = s * x + t * this._x;
  2087. this._y = s * y + t * this._y;
  2088. this._z = s * z + t * this._z;
  2089. this.normalize();
  2090. this._onChangeCallback();
  2091. return this;
  2092. }
  2093. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2094. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2095. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2096. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2097. this._w = w * ratioA + this._w * ratioB;
  2098. this._x = x * ratioA + this._x * ratioB;
  2099. this._y = y * ratioA + this._y * ratioB;
  2100. this._z = z * ratioA + this._z * ratioB;
  2101. this._onChangeCallback();
  2102. return this;
  2103. };
  2104. _proto.equals = function equals(quaternion) {
  2105. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2106. };
  2107. _proto.fromArray = function fromArray(array, offset) {
  2108. if (offset === void 0) {
  2109. offset = 0;
  2110. }
  2111. this._x = array[offset];
  2112. this._y = array[offset + 1];
  2113. this._z = array[offset + 2];
  2114. this._w = array[offset + 3];
  2115. this._onChangeCallback();
  2116. return this;
  2117. };
  2118. _proto.toArray = function toArray(array, offset) {
  2119. if (array === void 0) {
  2120. array = [];
  2121. }
  2122. if (offset === void 0) {
  2123. offset = 0;
  2124. }
  2125. array[offset] = this._x;
  2126. array[offset + 1] = this._y;
  2127. array[offset + 2] = this._z;
  2128. array[offset + 3] = this._w;
  2129. return array;
  2130. };
  2131. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2132. this._x = attribute.getX(index);
  2133. this._y = attribute.getY(index);
  2134. this._z = attribute.getZ(index);
  2135. this._w = attribute.getW(index);
  2136. return this;
  2137. };
  2138. _proto._onChange = function _onChange(callback) {
  2139. this._onChangeCallback = callback;
  2140. return this;
  2141. };
  2142. _proto._onChangeCallback = function _onChangeCallback() {};
  2143. _createClass(Quaternion, [{
  2144. key: "x",
  2145. get: function get() {
  2146. return this._x;
  2147. },
  2148. set: function set(value) {
  2149. this._x = value;
  2150. this._onChangeCallback();
  2151. }
  2152. }, {
  2153. key: "y",
  2154. get: function get() {
  2155. return this._y;
  2156. },
  2157. set: function set(value) {
  2158. this._y = value;
  2159. this._onChangeCallback();
  2160. }
  2161. }, {
  2162. key: "z",
  2163. get: function get() {
  2164. return this._z;
  2165. },
  2166. set: function set(value) {
  2167. this._z = value;
  2168. this._onChangeCallback();
  2169. }
  2170. }, {
  2171. key: "w",
  2172. get: function get() {
  2173. return this._w;
  2174. },
  2175. set: function set(value) {
  2176. this._w = value;
  2177. this._onChangeCallback();
  2178. }
  2179. }]);
  2180. return Quaternion;
  2181. }();
  2182. var Vector3 = /*#__PURE__*/function () {
  2183. function Vector3(x, y, z) {
  2184. if (x === void 0) {
  2185. x = 0;
  2186. }
  2187. if (y === void 0) {
  2188. y = 0;
  2189. }
  2190. if (z === void 0) {
  2191. z = 0;
  2192. }
  2193. Object.defineProperty(this, 'isVector3', {
  2194. value: true
  2195. });
  2196. this.x = x;
  2197. this.y = y;
  2198. this.z = z;
  2199. }
  2200. var _proto = Vector3.prototype;
  2201. _proto.set = function set(x, y, z) {
  2202. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2203. this.x = x;
  2204. this.y = y;
  2205. this.z = z;
  2206. return this;
  2207. };
  2208. _proto.setScalar = function setScalar(scalar) {
  2209. this.x = scalar;
  2210. this.y = scalar;
  2211. this.z = scalar;
  2212. return this;
  2213. };
  2214. _proto.setX = function setX(x) {
  2215. this.x = x;
  2216. return this;
  2217. };
  2218. _proto.setY = function setY(y) {
  2219. this.y = y;
  2220. return this;
  2221. };
  2222. _proto.setZ = function setZ(z) {
  2223. this.z = z;
  2224. return this;
  2225. };
  2226. _proto.setComponent = function setComponent(index, value) {
  2227. switch (index) {
  2228. case 0:
  2229. this.x = value;
  2230. break;
  2231. case 1:
  2232. this.y = value;
  2233. break;
  2234. case 2:
  2235. this.z = value;
  2236. break;
  2237. default:
  2238. throw new Error('index is out of range: ' + index);
  2239. }
  2240. return this;
  2241. };
  2242. _proto.getComponent = function getComponent(index) {
  2243. switch (index) {
  2244. case 0:
  2245. return this.x;
  2246. case 1:
  2247. return this.y;
  2248. case 2:
  2249. return this.z;
  2250. default:
  2251. throw new Error('index is out of range: ' + index);
  2252. }
  2253. };
  2254. _proto.clone = function clone() {
  2255. return new this.constructor(this.x, this.y, this.z);
  2256. };
  2257. _proto.copy = function copy(v) {
  2258. this.x = v.x;
  2259. this.y = v.y;
  2260. this.z = v.z;
  2261. return this;
  2262. };
  2263. _proto.add = function add(v, w) {
  2264. if (w !== undefined) {
  2265. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2266. return this.addVectors(v, w);
  2267. }
  2268. this.x += v.x;
  2269. this.y += v.y;
  2270. this.z += v.z;
  2271. return this;
  2272. };
  2273. _proto.addScalar = function addScalar(s) {
  2274. this.x += s;
  2275. this.y += s;
  2276. this.z += s;
  2277. return this;
  2278. };
  2279. _proto.addVectors = function addVectors(a, b) {
  2280. this.x = a.x + b.x;
  2281. this.y = a.y + b.y;
  2282. this.z = a.z + b.z;
  2283. return this;
  2284. };
  2285. _proto.addScaledVector = function addScaledVector(v, s) {
  2286. this.x += v.x * s;
  2287. this.y += v.y * s;
  2288. this.z += v.z * s;
  2289. return this;
  2290. };
  2291. _proto.sub = function sub(v, w) {
  2292. if (w !== undefined) {
  2293. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2294. return this.subVectors(v, w);
  2295. }
  2296. this.x -= v.x;
  2297. this.y -= v.y;
  2298. this.z -= v.z;
  2299. return this;
  2300. };
  2301. _proto.subScalar = function subScalar(s) {
  2302. this.x -= s;
  2303. this.y -= s;
  2304. this.z -= s;
  2305. return this;
  2306. };
  2307. _proto.subVectors = function subVectors(a, b) {
  2308. this.x = a.x - b.x;
  2309. this.y = a.y - b.y;
  2310. this.z = a.z - b.z;
  2311. return this;
  2312. };
  2313. _proto.multiply = function multiply(v, w) {
  2314. if (w !== undefined) {
  2315. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  2316. return this.multiplyVectors(v, w);
  2317. }
  2318. this.x *= v.x;
  2319. this.y *= v.y;
  2320. this.z *= v.z;
  2321. return this;
  2322. };
  2323. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2324. this.x *= scalar;
  2325. this.y *= scalar;
  2326. this.z *= scalar;
  2327. return this;
  2328. };
  2329. _proto.multiplyVectors = function multiplyVectors(a, b) {
  2330. this.x = a.x * b.x;
  2331. this.y = a.y * b.y;
  2332. this.z = a.z * b.z;
  2333. return this;
  2334. };
  2335. _proto.applyEuler = function applyEuler(euler) {
  2336. if (!(euler && euler.isEuler)) {
  2337. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2338. }
  2339. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  2340. };
  2341. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  2342. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  2343. };
  2344. _proto.applyMatrix3 = function applyMatrix3(m) {
  2345. var x = this.x,
  2346. y = this.y,
  2347. z = this.z;
  2348. var e = m.elements;
  2349. this.x = e[0] * x + e[3] * y + e[6] * z;
  2350. this.y = e[1] * x + e[4] * y + e[7] * z;
  2351. this.z = e[2] * x + e[5] * y + e[8] * z;
  2352. return this;
  2353. };
  2354. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  2355. return this.applyMatrix3(m).normalize();
  2356. };
  2357. _proto.applyMatrix4 = function applyMatrix4(m) {
  2358. var x = this.x,
  2359. y = this.y,
  2360. z = this.z;
  2361. var e = m.elements;
  2362. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  2363. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  2364. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  2365. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  2366. return this;
  2367. };
  2368. _proto.applyQuaternion = function applyQuaternion(q) {
  2369. var x = this.x,
  2370. y = this.y,
  2371. z = this.z;
  2372. var qx = q.x,
  2373. qy = q.y,
  2374. qz = q.z,
  2375. qw = q.w; // calculate quat * vector
  2376. var ix = qw * x + qy * z - qz * y;
  2377. var iy = qw * y + qz * x - qx * z;
  2378. var iz = qw * z + qx * y - qy * x;
  2379. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  2380. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  2381. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  2382. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  2383. return this;
  2384. };
  2385. _proto.project = function project(camera) {
  2386. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  2387. };
  2388. _proto.unproject = function unproject(camera) {
  2389. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  2390. };
  2391. _proto.transformDirection = function transformDirection(m) {
  2392. // input: THREE.Matrix4 affine matrix
  2393. // vector interpreted as a direction
  2394. var x = this.x,
  2395. y = this.y,
  2396. z = this.z;
  2397. var e = m.elements;
  2398. this.x = e[0] * x + e[4] * y + e[8] * z;
  2399. this.y = e[1] * x + e[5] * y + e[9] * z;
  2400. this.z = e[2] * x + e[6] * y + e[10] * z;
  2401. return this.normalize();
  2402. };
  2403. _proto.divide = function divide(v) {
  2404. this.x /= v.x;
  2405. this.y /= v.y;
  2406. this.z /= v.z;
  2407. return this;
  2408. };
  2409. _proto.divideScalar = function divideScalar(scalar) {
  2410. return this.multiplyScalar(1 / scalar);
  2411. };
  2412. _proto.min = function min(v) {
  2413. this.x = Math.min(this.x, v.x);
  2414. this.y = Math.min(this.y, v.y);
  2415. this.z = Math.min(this.z, v.z);
  2416. return this;
  2417. };
  2418. _proto.max = function max(v) {
  2419. this.x = Math.max(this.x, v.x);
  2420. this.y = Math.max(this.y, v.y);
  2421. this.z = Math.max(this.z, v.z);
  2422. return this;
  2423. };
  2424. _proto.clamp = function clamp(min, max) {
  2425. // assumes min < max, componentwise
  2426. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2427. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2428. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2429. return this;
  2430. };
  2431. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2432. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2433. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2434. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2435. return this;
  2436. };
  2437. _proto.clampLength = function clampLength(min, max) {
  2438. var length = this.length();
  2439. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2440. };
  2441. _proto.floor = function floor() {
  2442. this.x = Math.floor(this.x);
  2443. this.y = Math.floor(this.y);
  2444. this.z = Math.floor(this.z);
  2445. return this;
  2446. };
  2447. _proto.ceil = function ceil() {
  2448. this.x = Math.ceil(this.x);
  2449. this.y = Math.ceil(this.y);
  2450. this.z = Math.ceil(this.z);
  2451. return this;
  2452. };
  2453. _proto.round = function round() {
  2454. this.x = Math.round(this.x);
  2455. this.y = Math.round(this.y);
  2456. this.z = Math.round(this.z);
  2457. return this;
  2458. };
  2459. _proto.roundToZero = function roundToZero() {
  2460. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2461. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2462. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2463. return this;
  2464. };
  2465. _proto.negate = function negate() {
  2466. this.x = -this.x;
  2467. this.y = -this.y;
  2468. this.z = -this.z;
  2469. return this;
  2470. };
  2471. _proto.dot = function dot(v) {
  2472. return this.x * v.x + this.y * v.y + this.z * v.z;
  2473. } // TODO lengthSquared?
  2474. ;
  2475. _proto.lengthSq = function lengthSq() {
  2476. return this.x * this.x + this.y * this.y + this.z * this.z;
  2477. };
  2478. _proto.length = function length() {
  2479. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  2480. };
  2481. _proto.manhattanLength = function manhattanLength() {
  2482. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  2483. };
  2484. _proto.normalize = function normalize() {
  2485. return this.divideScalar(this.length() || 1);
  2486. };
  2487. _proto.setLength = function setLength(length) {
  2488. return this.normalize().multiplyScalar(length);
  2489. };
  2490. _proto.lerp = function lerp(v, alpha) {
  2491. this.x += (v.x - this.x) * alpha;
  2492. this.y += (v.y - this.y) * alpha;
  2493. this.z += (v.z - this.z) * alpha;
  2494. return this;
  2495. };
  2496. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2497. this.x = v1.x + (v2.x - v1.x) * alpha;
  2498. this.y = v1.y + (v2.y - v1.y) * alpha;
  2499. this.z = v1.z + (v2.z - v1.z) * alpha;
  2500. return this;
  2501. };
  2502. _proto.cross = function cross(v, w) {
  2503. if (w !== undefined) {
  2504. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  2505. return this.crossVectors(v, w);
  2506. }
  2507. return this.crossVectors(this, v);
  2508. };
  2509. _proto.crossVectors = function crossVectors(a, b) {
  2510. var ax = a.x,
  2511. ay = a.y,
  2512. az = a.z;
  2513. var bx = b.x,
  2514. by = b.y,
  2515. bz = b.z;
  2516. this.x = ay * bz - az * by;
  2517. this.y = az * bx - ax * bz;
  2518. this.z = ax * by - ay * bx;
  2519. return this;
  2520. };
  2521. _proto.projectOnVector = function projectOnVector(v) {
  2522. var denominator = v.lengthSq();
  2523. if (denominator === 0) return this.set(0, 0, 0);
  2524. var scalar = v.dot(this) / denominator;
  2525. return this.copy(v).multiplyScalar(scalar);
  2526. };
  2527. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  2528. _vector.copy(this).projectOnVector(planeNormal);
  2529. return this.sub(_vector);
  2530. };
  2531. _proto.reflect = function reflect(normal) {
  2532. // reflect incident vector off plane orthogonal to normal
  2533. // normal is assumed to have unit length
  2534. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  2535. };
  2536. _proto.angleTo = function angleTo(v) {
  2537. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  2538. if (denominator === 0) return Math.PI / 2;
  2539. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  2540. return Math.acos(MathUtils.clamp(theta, -1, 1));
  2541. };
  2542. _proto.distanceTo = function distanceTo(v) {
  2543. return Math.sqrt(this.distanceToSquared(v));
  2544. };
  2545. _proto.distanceToSquared = function distanceToSquared(v) {
  2546. var dx = this.x - v.x,
  2547. dy = this.y - v.y,
  2548. dz = this.z - v.z;
  2549. return dx * dx + dy * dy + dz * dz;
  2550. };
  2551. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  2552. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  2553. };
  2554. _proto.setFromSpherical = function setFromSpherical(s) {
  2555. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  2556. };
  2557. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  2558. var sinPhiRadius = Math.sin(phi) * radius;
  2559. this.x = sinPhiRadius * Math.sin(theta);
  2560. this.y = Math.cos(phi) * radius;
  2561. this.z = sinPhiRadius * Math.cos(theta);
  2562. return this;
  2563. };
  2564. _proto.setFromCylindrical = function setFromCylindrical(c) {
  2565. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  2566. };
  2567. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  2568. this.x = radius * Math.sin(theta);
  2569. this.y = y;
  2570. this.z = radius * Math.cos(theta);
  2571. return this;
  2572. };
  2573. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  2574. var e = m.elements;
  2575. this.x = e[12];
  2576. this.y = e[13];
  2577. this.z = e[14];
  2578. return this;
  2579. };
  2580. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  2581. var sx = this.setFromMatrixColumn(m, 0).length();
  2582. var sy = this.setFromMatrixColumn(m, 1).length();
  2583. var sz = this.setFromMatrixColumn(m, 2).length();
  2584. this.x = sx;
  2585. this.y = sy;
  2586. this.z = sz;
  2587. return this;
  2588. };
  2589. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  2590. return this.fromArray(m.elements, index * 4);
  2591. };
  2592. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  2593. return this.fromArray(m.elements, index * 3);
  2594. };
  2595. _proto.equals = function equals(v) {
  2596. return v.x === this.x && v.y === this.y && v.z === this.z;
  2597. };
  2598. _proto.fromArray = function fromArray(array, offset) {
  2599. if (offset === void 0) {
  2600. offset = 0;
  2601. }
  2602. this.x = array[offset];
  2603. this.y = array[offset + 1];
  2604. this.z = array[offset + 2];
  2605. return this;
  2606. };
  2607. _proto.toArray = function toArray(array, offset) {
  2608. if (array === void 0) {
  2609. array = [];
  2610. }
  2611. if (offset === void 0) {
  2612. offset = 0;
  2613. }
  2614. array[offset] = this.x;
  2615. array[offset + 1] = this.y;
  2616. array[offset + 2] = this.z;
  2617. return array;
  2618. };
  2619. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2620. if (offset !== undefined) {
  2621. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  2622. }
  2623. this.x = attribute.getX(index);
  2624. this.y = attribute.getY(index);
  2625. this.z = attribute.getZ(index);
  2626. return this;
  2627. };
  2628. _proto.random = function random() {
  2629. this.x = Math.random();
  2630. this.y = Math.random();
  2631. this.z = Math.random();
  2632. return this;
  2633. };
  2634. return Vector3;
  2635. }();
  2636. var _vector = /*@__PURE__*/new Vector3();
  2637. var _quaternion = /*@__PURE__*/new Quaternion();
  2638. var Box3 = /*#__PURE__*/function () {
  2639. function Box3(min, max) {
  2640. Object.defineProperty(this, 'isBox3', {
  2641. value: true
  2642. });
  2643. this.min = min !== undefined ? min : new Vector3(+Infinity, +Infinity, +Infinity);
  2644. this.max = max !== undefined ? max : new Vector3(-Infinity, -Infinity, -Infinity);
  2645. }
  2646. var _proto = Box3.prototype;
  2647. _proto.set = function set(min, max) {
  2648. this.min.copy(min);
  2649. this.max.copy(max);
  2650. return this;
  2651. };
  2652. _proto.setFromArray = function setFromArray(array) {
  2653. var minX = +Infinity;
  2654. var minY = +Infinity;
  2655. var minZ = +Infinity;
  2656. var maxX = -Infinity;
  2657. var maxY = -Infinity;
  2658. var maxZ = -Infinity;
  2659. for (var i = 0, l = array.length; i < l; i += 3) {
  2660. var x = array[i];
  2661. var y = array[i + 1];
  2662. var z = array[i + 2];
  2663. if (x < minX) minX = x;
  2664. if (y < minY) minY = y;
  2665. if (z < minZ) minZ = z;
  2666. if (x > maxX) maxX = x;
  2667. if (y > maxY) maxY = y;
  2668. if (z > maxZ) maxZ = z;
  2669. }
  2670. this.min.set(minX, minY, minZ);
  2671. this.max.set(maxX, maxY, maxZ);
  2672. return this;
  2673. };
  2674. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  2675. var minX = +Infinity;
  2676. var minY = +Infinity;
  2677. var minZ = +Infinity;
  2678. var maxX = -Infinity;
  2679. var maxY = -Infinity;
  2680. var maxZ = -Infinity;
  2681. for (var i = 0, l = attribute.count; i < l; i++) {
  2682. var x = attribute.getX(i);
  2683. var y = attribute.getY(i);
  2684. var z = attribute.getZ(i);
  2685. if (x < minX) minX = x;
  2686. if (y < minY) minY = y;
  2687. if (z < minZ) minZ = z;
  2688. if (x > maxX) maxX = x;
  2689. if (y > maxY) maxY = y;
  2690. if (z > maxZ) maxZ = z;
  2691. }
  2692. this.min.set(minX, minY, minZ);
  2693. this.max.set(maxX, maxY, maxZ);
  2694. return this;
  2695. };
  2696. _proto.setFromPoints = function setFromPoints(points) {
  2697. this.makeEmpty();
  2698. for (var i = 0, il = points.length; i < il; i++) {
  2699. this.expandByPoint(points[i]);
  2700. }
  2701. return this;
  2702. };
  2703. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  2704. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  2705. this.min.copy(center).sub(halfSize);
  2706. this.max.copy(center).add(halfSize);
  2707. return this;
  2708. };
  2709. _proto.setFromObject = function setFromObject(object) {
  2710. this.makeEmpty();
  2711. return this.expandByObject(object);
  2712. };
  2713. _proto.clone = function clone() {
  2714. return new this.constructor().copy(this);
  2715. };
  2716. _proto.copy = function copy(box) {
  2717. this.min.copy(box.min);
  2718. this.max.copy(box.max);
  2719. return this;
  2720. };
  2721. _proto.makeEmpty = function makeEmpty() {
  2722. this.min.x = this.min.y = this.min.z = +Infinity;
  2723. this.max.x = this.max.y = this.max.z = -Infinity;
  2724. return this;
  2725. };
  2726. _proto.isEmpty = function isEmpty() {
  2727. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2728. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  2729. };
  2730. _proto.getCenter = function getCenter(target) {
  2731. if (target === undefined) {
  2732. console.warn('THREE.Box3: .getCenter() target is now required');
  2733. target = new Vector3();
  2734. }
  2735. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  2736. };
  2737. _proto.getSize = function getSize(target) {
  2738. if (target === undefined) {
  2739. console.warn('THREE.Box3: .getSize() target is now required');
  2740. target = new Vector3();
  2741. }
  2742. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  2743. };
  2744. _proto.expandByPoint = function expandByPoint(point) {
  2745. this.min.min(point);
  2746. this.max.max(point);
  2747. return this;
  2748. };
  2749. _proto.expandByVector = function expandByVector(vector) {
  2750. this.min.sub(vector);
  2751. this.max.add(vector);
  2752. return this;
  2753. };
  2754. _proto.expandByScalar = function expandByScalar(scalar) {
  2755. this.min.addScalar(-scalar);
  2756. this.max.addScalar(scalar);
  2757. return this;
  2758. };
  2759. _proto.expandByObject = function expandByObject(object) {
  2760. // Computes the world-axis-aligned bounding box of an object (including its children),
  2761. // accounting for both the object's, and children's, world transforms
  2762. object.updateWorldMatrix(false, false);
  2763. var geometry = object.geometry;
  2764. if (geometry !== undefined) {
  2765. if (geometry.boundingBox === null) {
  2766. geometry.computeBoundingBox();
  2767. }
  2768. _box.copy(geometry.boundingBox);
  2769. _box.applyMatrix4(object.matrixWorld);
  2770. this.union(_box);
  2771. }
  2772. var children = object.children;
  2773. for (var i = 0, l = children.length; i < l; i++) {
  2774. this.expandByObject(children[i]);
  2775. }
  2776. return this;
  2777. };
  2778. _proto.containsPoint = function containsPoint(point) {
  2779. 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;
  2780. };
  2781. _proto.containsBox = function containsBox(box) {
  2782. 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;
  2783. };
  2784. _proto.getParameter = function getParameter(point, target) {
  2785. // This can potentially have a divide by zero if the box
  2786. // has a size dimension of 0.
  2787. if (target === undefined) {
  2788. console.warn('THREE.Box3: .getParameter() target is now required');
  2789. target = new Vector3();
  2790. }
  2791. 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));
  2792. };
  2793. _proto.intersectsBox = function intersectsBox(box) {
  2794. // using 6 splitting planes to rule out intersections.
  2795. 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;
  2796. };
  2797. _proto.intersectsSphere = function intersectsSphere(sphere) {
  2798. // Find the point on the AABB closest to the sphere center.
  2799. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  2800. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  2801. };
  2802. _proto.intersectsPlane = function intersectsPlane(plane) {
  2803. // We compute the minimum and maximum dot product values. If those values
  2804. // are on the same side (back or front) of the plane, then there is no intersection.
  2805. var min, max;
  2806. if (plane.normal.x > 0) {
  2807. min = plane.normal.x * this.min.x;
  2808. max = plane.normal.x * this.max.x;
  2809. } else {
  2810. min = plane.normal.x * this.max.x;
  2811. max = plane.normal.x * this.min.x;
  2812. }
  2813. if (plane.normal.y > 0) {
  2814. min += plane.normal.y * this.min.y;
  2815. max += plane.normal.y * this.max.y;
  2816. } else {
  2817. min += plane.normal.y * this.max.y;
  2818. max += plane.normal.y * this.min.y;
  2819. }
  2820. if (plane.normal.z > 0) {
  2821. min += plane.normal.z * this.min.z;
  2822. max += plane.normal.z * this.max.z;
  2823. } else {
  2824. min += plane.normal.z * this.max.z;
  2825. max += plane.normal.z * this.min.z;
  2826. }
  2827. return min <= -plane.constant && max >= -plane.constant;
  2828. };
  2829. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  2830. if (this.isEmpty()) {
  2831. return false;
  2832. } // compute box center and extents
  2833. this.getCenter(_center);
  2834. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  2835. _v0.subVectors(triangle.a, _center);
  2836. _v1.subVectors(triangle.b, _center);
  2837. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  2838. _f0.subVectors(_v1, _v0);
  2839. _f1.subVectors(_v2, _v1);
  2840. _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
  2841. // 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
  2842. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  2843. 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];
  2844. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2845. return false;
  2846. } // test 3 face normals from the aabb
  2847. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  2848. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2849. return false;
  2850. } // finally testing the face normal of the triangle
  2851. // use already existing triangle edge vectors here
  2852. _triangleNormal.crossVectors(_f0, _f1);
  2853. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  2854. return satForAxes(axes, _v0, _v1, _v2, _extents);
  2855. };
  2856. _proto.clampPoint = function clampPoint(point, target) {
  2857. if (target === undefined) {
  2858. console.warn('THREE.Box3: .clampPoint() target is now required');
  2859. target = new Vector3();
  2860. }
  2861. return target.copy(point).clamp(this.min, this.max);
  2862. };
  2863. _proto.distanceToPoint = function distanceToPoint(point) {
  2864. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  2865. return clampedPoint.sub(point).length();
  2866. };
  2867. _proto.getBoundingSphere = function getBoundingSphere(target) {
  2868. if (target === undefined) {
  2869. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  2870. }
  2871. this.getCenter(target.center);
  2872. target.radius = this.getSize(_vector$1).length() * 0.5;
  2873. return target;
  2874. };
  2875. _proto.intersect = function intersect(box) {
  2876. this.min.max(box.min);
  2877. 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.
  2878. if (this.isEmpty()) this.makeEmpty();
  2879. return this;
  2880. };
  2881. _proto.union = function union(box) {
  2882. this.min.min(box.min);
  2883. this.max.max(box.max);
  2884. return this;
  2885. };
  2886. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  2887. // transform of empty box is an empty box.
  2888. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2889. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  2890. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  2891. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  2892. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  2893. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  2894. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  2895. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  2896. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  2897. this.setFromPoints(_points);
  2898. return this;
  2899. };
  2900. _proto.translate = function translate(offset) {
  2901. this.min.add(offset);
  2902. this.max.add(offset);
  2903. return this;
  2904. };
  2905. _proto.equals = function equals(box) {
  2906. return box.min.equals(this.min) && box.max.equals(this.max);
  2907. };
  2908. return Box3;
  2909. }();
  2910. function satForAxes(axes, v0, v1, v2, extents) {
  2911. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  2912. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  2913. 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
  2914. var p0 = v0.dot(_testAxis);
  2915. var p1 = v1.dot(_testAxis);
  2916. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  2917. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  2918. // points of the projected triangle are outside the projected half-length of the aabb
  2919. // the axis is seperating and we can exit
  2920. return false;
  2921. }
  2922. }
  2923. return true;
  2924. }
  2925. 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()];
  2926. var _vector$1 = /*@__PURE__*/new Vector3();
  2927. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  2928. var _v0 = /*@__PURE__*/new Vector3();
  2929. var _v1 = /*@__PURE__*/new Vector3();
  2930. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  2931. var _f0 = /*@__PURE__*/new Vector3();
  2932. var _f1 = /*@__PURE__*/new Vector3();
  2933. var _f2 = /*@__PURE__*/new Vector3();
  2934. var _center = /*@__PURE__*/new Vector3();
  2935. var _extents = /*@__PURE__*/new Vector3();
  2936. var _triangleNormal = /*@__PURE__*/new Vector3();
  2937. var _testAxis = /*@__PURE__*/new Vector3();
  2938. var _box$1 = /*@__PURE__*/new Box3();
  2939. var Sphere = /*#__PURE__*/function () {
  2940. function Sphere(center, radius) {
  2941. this.center = center !== undefined ? center : new Vector3();
  2942. this.radius = radius !== undefined ? radius : -1;
  2943. }
  2944. var _proto = Sphere.prototype;
  2945. _proto.set = function set(center, radius) {
  2946. this.center.copy(center);
  2947. this.radius = radius;
  2948. return this;
  2949. };
  2950. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  2951. var center = this.center;
  2952. if (optionalCenter !== undefined) {
  2953. center.copy(optionalCenter);
  2954. } else {
  2955. _box$1.setFromPoints(points).getCenter(center);
  2956. }
  2957. var maxRadiusSq = 0;
  2958. for (var i = 0, il = points.length; i < il; i++) {
  2959. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  2960. }
  2961. this.radius = Math.sqrt(maxRadiusSq);
  2962. return this;
  2963. };
  2964. _proto.clone = function clone() {
  2965. return new this.constructor().copy(this);
  2966. };
  2967. _proto.copy = function copy(sphere) {
  2968. this.center.copy(sphere.center);
  2969. this.radius = sphere.radius;
  2970. return this;
  2971. };
  2972. _proto.isEmpty = function isEmpty() {
  2973. return this.radius < 0;
  2974. };
  2975. _proto.makeEmpty = function makeEmpty() {
  2976. this.center.set(0, 0, 0);
  2977. this.radius = -1;
  2978. return this;
  2979. };
  2980. _proto.containsPoint = function containsPoint(point) {
  2981. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  2982. };
  2983. _proto.distanceToPoint = function distanceToPoint(point) {
  2984. return point.distanceTo(this.center) - this.radius;
  2985. };
  2986. _proto.intersectsSphere = function intersectsSphere(sphere) {
  2987. var radiusSum = this.radius + sphere.radius;
  2988. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  2989. };
  2990. _proto.intersectsBox = function intersectsBox(box) {
  2991. return box.intersectsSphere(this);
  2992. };
  2993. _proto.intersectsPlane = function intersectsPlane(plane) {
  2994. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  2995. };
  2996. _proto.clampPoint = function clampPoint(point, target) {
  2997. var deltaLengthSq = this.center.distanceToSquared(point);
  2998. if (target === undefined) {
  2999. console.warn('THREE.Sphere: .clampPoint() target is now required');
  3000. target = new Vector3();
  3001. }
  3002. target.copy(point);
  3003. if (deltaLengthSq > this.radius * this.radius) {
  3004. target.sub(this.center).normalize();
  3005. target.multiplyScalar(this.radius).add(this.center);
  3006. }
  3007. return target;
  3008. };
  3009. _proto.getBoundingBox = function getBoundingBox(target) {
  3010. if (target === undefined) {
  3011. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  3012. target = new Box3();
  3013. }
  3014. if (this.isEmpty()) {
  3015. // Empty sphere produces empty bounding box
  3016. target.makeEmpty();
  3017. return target;
  3018. }
  3019. target.set(this.center, this.center);
  3020. target.expandByScalar(this.radius);
  3021. return target;
  3022. };
  3023. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3024. this.center.applyMatrix4(matrix);
  3025. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3026. return this;
  3027. };
  3028. _proto.translate = function translate(offset) {
  3029. this.center.add(offset);
  3030. return this;
  3031. };
  3032. _proto.equals = function equals(sphere) {
  3033. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3034. };
  3035. return Sphere;
  3036. }();
  3037. var _vector$2 = /*@__PURE__*/new Vector3();
  3038. var _segCenter = /*@__PURE__*/new Vector3();
  3039. var _segDir = /*@__PURE__*/new Vector3();
  3040. var _diff = /*@__PURE__*/new Vector3();
  3041. var _edge1 = /*@__PURE__*/new Vector3();
  3042. var _edge2 = /*@__PURE__*/new Vector3();
  3043. var _normal = /*@__PURE__*/new Vector3();
  3044. var Ray = /*#__PURE__*/function () {
  3045. function Ray(origin, direction) {
  3046. this.origin = origin !== undefined ? origin : new Vector3();
  3047. this.direction = direction !== undefined ? direction : new Vector3(0, 0, -1);
  3048. }
  3049. var _proto = Ray.prototype;
  3050. _proto.set = function set(origin, direction) {
  3051. this.origin.copy(origin);
  3052. this.direction.copy(direction);
  3053. return this;
  3054. };
  3055. _proto.clone = function clone() {
  3056. return new this.constructor().copy(this);
  3057. };
  3058. _proto.copy = function copy(ray) {
  3059. this.origin.copy(ray.origin);
  3060. this.direction.copy(ray.direction);
  3061. return this;
  3062. };
  3063. _proto.at = function at(t, target) {
  3064. if (target === undefined) {
  3065. console.warn('THREE.Ray: .at() target is now required');
  3066. target = new Vector3();
  3067. }
  3068. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3069. };
  3070. _proto.lookAt = function lookAt(v) {
  3071. this.direction.copy(v).sub(this.origin).normalize();
  3072. return this;
  3073. };
  3074. _proto.recast = function recast(t) {
  3075. this.origin.copy(this.at(t, _vector$2));
  3076. return this;
  3077. };
  3078. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3079. if (target === undefined) {
  3080. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3081. target = new Vector3();
  3082. }
  3083. target.subVectors(point, this.origin);
  3084. var directionDistance = target.dot(this.direction);
  3085. if (directionDistance < 0) {
  3086. return target.copy(this.origin);
  3087. }
  3088. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3089. };
  3090. _proto.distanceToPoint = function distanceToPoint(point) {
  3091. return Math.sqrt(this.distanceSqToPoint(point));
  3092. };
  3093. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3094. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3095. if (directionDistance < 0) {
  3096. return this.origin.distanceToSquared(point);
  3097. }
  3098. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3099. return _vector$2.distanceToSquared(point);
  3100. };
  3101. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3102. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3103. // It returns the min distance between the ray and the segment
  3104. // defined by v0 and v1
  3105. // It can also set two optional targets :
  3106. // - The closest point on the ray
  3107. // - The closest point on the segment
  3108. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3109. _segDir.copy(v1).sub(v0).normalize();
  3110. _diff.copy(this.origin).sub(_segCenter);
  3111. var segExtent = v0.distanceTo(v1) * 0.5;
  3112. var a01 = -this.direction.dot(_segDir);
  3113. var b0 = _diff.dot(this.direction);
  3114. var b1 = -_diff.dot(_segDir);
  3115. var c = _diff.lengthSq();
  3116. var det = Math.abs(1 - a01 * a01);
  3117. var s0, s1, sqrDist, extDet;
  3118. if (det > 0) {
  3119. // The ray and segment are not parallel.
  3120. s0 = a01 * b1 - b0;
  3121. s1 = a01 * b0 - b1;
  3122. extDet = segExtent * det;
  3123. if (s0 >= 0) {
  3124. if (s1 >= -extDet) {
  3125. if (s1 <= extDet) {
  3126. // region 0
  3127. // Minimum at interior points of ray and segment.
  3128. var invDet = 1 / det;
  3129. s0 *= invDet;
  3130. s1 *= invDet;
  3131. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3132. } else {
  3133. // region 1
  3134. s1 = segExtent;
  3135. s0 = Math.max(0, -(a01 * s1 + b0));
  3136. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3137. }
  3138. } else {
  3139. // region 5
  3140. s1 = -segExtent;
  3141. s0 = Math.max(0, -(a01 * s1 + b0));
  3142. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3143. }
  3144. } else {
  3145. if (s1 <= -extDet) {
  3146. // region 4
  3147. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3148. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3149. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3150. } else if (s1 <= extDet) {
  3151. // region 3
  3152. s0 = 0;
  3153. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3154. sqrDist = s1 * (s1 + 2 * b1) + c;
  3155. } else {
  3156. // region 2
  3157. s0 = Math.max(0, -(a01 * segExtent + b0));
  3158. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3159. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3160. }
  3161. }
  3162. } else {
  3163. // Ray and segment are parallel.
  3164. s1 = a01 > 0 ? -segExtent : segExtent;
  3165. s0 = Math.max(0, -(a01 * s1 + b0));
  3166. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3167. }
  3168. if (optionalPointOnRay) {
  3169. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3170. }
  3171. if (optionalPointOnSegment) {
  3172. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3173. }
  3174. return sqrDist;
  3175. };
  3176. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3177. _vector$2.subVectors(sphere.center, this.origin);
  3178. var tca = _vector$2.dot(this.direction);
  3179. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3180. var radius2 = sphere.radius * sphere.radius;
  3181. if (d2 > radius2) return null;
  3182. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3183. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3184. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3185. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3186. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3187. // in order to always return an intersect point that is in front of the ray.
  3188. 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
  3189. return this.at(t0, target);
  3190. };
  3191. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3192. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3193. };
  3194. _proto.distanceToPlane = function distanceToPlane(plane) {
  3195. var denominator = plane.normal.dot(this.direction);
  3196. if (denominator === 0) {
  3197. // line is coplanar, return origin
  3198. if (plane.distanceToPoint(this.origin) === 0) {
  3199. return 0;
  3200. } // Null is preferable to undefined since undefined means.... it is undefined
  3201. return null;
  3202. }
  3203. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3204. return t >= 0 ? t : null;
  3205. };
  3206. _proto.intersectPlane = function intersectPlane(plane, target) {
  3207. var t = this.distanceToPlane(plane);
  3208. if (t === null) {
  3209. return null;
  3210. }
  3211. return this.at(t, target);
  3212. };
  3213. _proto.intersectsPlane = function intersectsPlane(plane) {
  3214. // check if the ray lies on the plane first
  3215. var distToPoint = plane.distanceToPoint(this.origin);
  3216. if (distToPoint === 0) {
  3217. return true;
  3218. }
  3219. var denominator = plane.normal.dot(this.direction);
  3220. if (denominator * distToPoint < 0) {
  3221. return true;
  3222. } // ray origin is behind the plane (and is pointing behind it)
  3223. return false;
  3224. };
  3225. _proto.intersectBox = function intersectBox(box, target) {
  3226. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3227. var invdirx = 1 / this.direction.x,
  3228. invdiry = 1 / this.direction.y,
  3229. invdirz = 1 / this.direction.z;
  3230. var origin = this.origin;
  3231. if (invdirx >= 0) {
  3232. tmin = (box.min.x - origin.x) * invdirx;
  3233. tmax = (box.max.x - origin.x) * invdirx;
  3234. } else {
  3235. tmin = (box.max.x - origin.x) * invdirx;
  3236. tmax = (box.min.x - origin.x) * invdirx;
  3237. }
  3238. if (invdiry >= 0) {
  3239. tymin = (box.min.y - origin.y) * invdiry;
  3240. tymax = (box.max.y - origin.y) * invdiry;
  3241. } else {
  3242. tymin = (box.max.y - origin.y) * invdiry;
  3243. tymax = (box.min.y - origin.y) * invdiry;
  3244. }
  3245. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  3246. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3247. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  3248. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  3249. if (invdirz >= 0) {
  3250. tzmin = (box.min.z - origin.z) * invdirz;
  3251. tzmax = (box.max.z - origin.z) * invdirz;
  3252. } else {
  3253. tzmin = (box.max.z - origin.z) * invdirz;
  3254. tzmax = (box.min.z - origin.z) * invdirz;
  3255. }
  3256. if (tmin > tzmax || tzmin > tmax) return null;
  3257. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  3258. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  3259. if (tmax < 0) return null;
  3260. return this.at(tmin >= 0 ? tmin : tmax, target);
  3261. };
  3262. _proto.intersectsBox = function intersectsBox(box) {
  3263. return this.intersectBox(box, _vector$2) !== null;
  3264. };
  3265. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  3266. // Compute the offset origin, edges, and normal.
  3267. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3268. _edge1.subVectors(b, a);
  3269. _edge2.subVectors(c, a);
  3270. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3271. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3272. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3273. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3274. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3275. var DdN = this.direction.dot(_normal);
  3276. var sign;
  3277. if (DdN > 0) {
  3278. if (backfaceCulling) return null;
  3279. sign = 1;
  3280. } else if (DdN < 0) {
  3281. sign = -1;
  3282. DdN = -DdN;
  3283. } else {
  3284. return null;
  3285. }
  3286. _diff.subVectors(this.origin, a);
  3287. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  3288. if (DdQxE2 < 0) {
  3289. return null;
  3290. }
  3291. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  3292. if (DdE1xQ < 0) {
  3293. return null;
  3294. } // b1+b2 > 1, no intersection
  3295. if (DdQxE2 + DdE1xQ > DdN) {
  3296. return null;
  3297. } // Line intersects triangle, check if ray does.
  3298. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  3299. if (QdN < 0) {
  3300. return null;
  3301. } // Ray intersects triangle.
  3302. return this.at(QdN / DdN, target);
  3303. };
  3304. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  3305. this.origin.applyMatrix4(matrix4);
  3306. this.direction.transformDirection(matrix4);
  3307. return this;
  3308. };
  3309. _proto.equals = function equals(ray) {
  3310. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  3311. };
  3312. return Ray;
  3313. }();
  3314. var Matrix4 = /*#__PURE__*/function () {
  3315. function Matrix4() {
  3316. Object.defineProperty(this, 'isMatrix4', {
  3317. value: true
  3318. });
  3319. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  3320. if (arguments.length > 0) {
  3321. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  3322. }
  3323. }
  3324. var _proto = Matrix4.prototype;
  3325. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  3326. var te = this.elements;
  3327. te[0] = n11;
  3328. te[4] = n12;
  3329. te[8] = n13;
  3330. te[12] = n14;
  3331. te[1] = n21;
  3332. te[5] = n22;
  3333. te[9] = n23;
  3334. te[13] = n24;
  3335. te[2] = n31;
  3336. te[6] = n32;
  3337. te[10] = n33;
  3338. te[14] = n34;
  3339. te[3] = n41;
  3340. te[7] = n42;
  3341. te[11] = n43;
  3342. te[15] = n44;
  3343. return this;
  3344. };
  3345. _proto.identity = function identity() {
  3346. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3347. return this;
  3348. };
  3349. _proto.clone = function clone() {
  3350. return new Matrix4().fromArray(this.elements);
  3351. };
  3352. _proto.copy = function copy(m) {
  3353. var te = this.elements;
  3354. var me = m.elements;
  3355. te[0] = me[0];
  3356. te[1] = me[1];
  3357. te[2] = me[2];
  3358. te[3] = me[3];
  3359. te[4] = me[4];
  3360. te[5] = me[5];
  3361. te[6] = me[6];
  3362. te[7] = me[7];
  3363. te[8] = me[8];
  3364. te[9] = me[9];
  3365. te[10] = me[10];
  3366. te[11] = me[11];
  3367. te[12] = me[12];
  3368. te[13] = me[13];
  3369. te[14] = me[14];
  3370. te[15] = me[15];
  3371. return this;
  3372. };
  3373. _proto.copyPosition = function copyPosition(m) {
  3374. var te = this.elements,
  3375. me = m.elements;
  3376. te[12] = me[12];
  3377. te[13] = me[13];
  3378. te[14] = me[14];
  3379. return this;
  3380. };
  3381. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  3382. xAxis.setFromMatrixColumn(this, 0);
  3383. yAxis.setFromMatrixColumn(this, 1);
  3384. zAxis.setFromMatrixColumn(this, 2);
  3385. return this;
  3386. };
  3387. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  3388. 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);
  3389. return this;
  3390. };
  3391. _proto.extractRotation = function extractRotation(m) {
  3392. // this method does not support reflection matrices
  3393. var te = this.elements;
  3394. var me = m.elements;
  3395. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  3396. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  3397. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  3398. te[0] = me[0] * scaleX;
  3399. te[1] = me[1] * scaleX;
  3400. te[2] = me[2] * scaleX;
  3401. te[3] = 0;
  3402. te[4] = me[4] * scaleY;
  3403. te[5] = me[5] * scaleY;
  3404. te[6] = me[6] * scaleY;
  3405. te[7] = 0;
  3406. te[8] = me[8] * scaleZ;
  3407. te[9] = me[9] * scaleZ;
  3408. te[10] = me[10] * scaleZ;
  3409. te[11] = 0;
  3410. te[12] = 0;
  3411. te[13] = 0;
  3412. te[14] = 0;
  3413. te[15] = 1;
  3414. return this;
  3415. };
  3416. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  3417. if (!(euler && euler.isEuler)) {
  3418. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  3419. }
  3420. var te = this.elements;
  3421. var x = euler.x,
  3422. y = euler.y,
  3423. z = euler.z;
  3424. var a = Math.cos(x),
  3425. b = Math.sin(x);
  3426. var c = Math.cos(y),
  3427. d = Math.sin(y);
  3428. var e = Math.cos(z),
  3429. f = Math.sin(z);
  3430. if (euler.order === 'XYZ') {
  3431. var ae = a * e,
  3432. af = a * f,
  3433. be = b * e,
  3434. bf = b * f;
  3435. te[0] = c * e;
  3436. te[4] = -c * f;
  3437. te[8] = d;
  3438. te[1] = af + be * d;
  3439. te[5] = ae - bf * d;
  3440. te[9] = -b * c;
  3441. te[2] = bf - ae * d;
  3442. te[6] = be + af * d;
  3443. te[10] = a * c;
  3444. } else if (euler.order === 'YXZ') {
  3445. var ce = c * e,
  3446. cf = c * f,
  3447. de = d * e,
  3448. df = d * f;
  3449. te[0] = ce + df * b;
  3450. te[4] = de * b - cf;
  3451. te[8] = a * d;
  3452. te[1] = a * f;
  3453. te[5] = a * e;
  3454. te[9] = -b;
  3455. te[2] = cf * b - de;
  3456. te[6] = df + ce * b;
  3457. te[10] = a * c;
  3458. } else if (euler.order === 'ZXY') {
  3459. var _ce = c * e,
  3460. _cf = c * f,
  3461. _de = d * e,
  3462. _df = d * f;
  3463. te[0] = _ce - _df * b;
  3464. te[4] = -a * f;
  3465. te[8] = _de + _cf * b;
  3466. te[1] = _cf + _de * b;
  3467. te[5] = a * e;
  3468. te[9] = _df - _ce * b;
  3469. te[2] = -a * d;
  3470. te[6] = b;
  3471. te[10] = a * c;
  3472. } else if (euler.order === 'ZYX') {
  3473. var _ae = a * e,
  3474. _af = a * f,
  3475. _be = b * e,
  3476. _bf = b * f;
  3477. te[0] = c * e;
  3478. te[4] = _be * d - _af;
  3479. te[8] = _ae * d + _bf;
  3480. te[1] = c * f;
  3481. te[5] = _bf * d + _ae;
  3482. te[9] = _af * d - _be;
  3483. te[2] = -d;
  3484. te[6] = b * c;
  3485. te[10] = a * c;
  3486. } else if (euler.order === 'YZX') {
  3487. var ac = a * c,
  3488. ad = a * d,
  3489. bc = b * c,
  3490. bd = b * d;
  3491. te[0] = c * e;
  3492. te[4] = bd - ac * f;
  3493. te[8] = bc * f + ad;
  3494. te[1] = f;
  3495. te[5] = a * e;
  3496. te[9] = -b * e;
  3497. te[2] = -d * e;
  3498. te[6] = ad * f + bc;
  3499. te[10] = ac - bd * f;
  3500. } else if (euler.order === 'XZY') {
  3501. var _ac = a * c,
  3502. _ad = a * d,
  3503. _bc = b * c,
  3504. _bd = b * d;
  3505. te[0] = c * e;
  3506. te[4] = -f;
  3507. te[8] = d * e;
  3508. te[1] = _ac * f + _bd;
  3509. te[5] = a * e;
  3510. te[9] = _ad * f - _bc;
  3511. te[2] = _bc * f - _ad;
  3512. te[6] = b * e;
  3513. te[10] = _bd * f + _ac;
  3514. } // bottom row
  3515. te[3] = 0;
  3516. te[7] = 0;
  3517. te[11] = 0; // last column
  3518. te[12] = 0;
  3519. te[13] = 0;
  3520. te[14] = 0;
  3521. te[15] = 1;
  3522. return this;
  3523. };
  3524. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  3525. return this.compose(_zero, q, _one);
  3526. };
  3527. _proto.lookAt = function lookAt(eye, target, up) {
  3528. var te = this.elements;
  3529. _z.subVectors(eye, target);
  3530. if (_z.lengthSq() === 0) {
  3531. // eye and target are in the same position
  3532. _z.z = 1;
  3533. }
  3534. _z.normalize();
  3535. _x.crossVectors(up, _z);
  3536. if (_x.lengthSq() === 0) {
  3537. // up and z are parallel
  3538. if (Math.abs(up.z) === 1) {
  3539. _z.x += 0.0001;
  3540. } else {
  3541. _z.z += 0.0001;
  3542. }
  3543. _z.normalize();
  3544. _x.crossVectors(up, _z);
  3545. }
  3546. _x.normalize();
  3547. _y.crossVectors(_z, _x);
  3548. te[0] = _x.x;
  3549. te[4] = _y.x;
  3550. te[8] = _z.x;
  3551. te[1] = _x.y;
  3552. te[5] = _y.y;
  3553. te[9] = _z.y;
  3554. te[2] = _x.z;
  3555. te[6] = _y.z;
  3556. te[10] = _z.z;
  3557. return this;
  3558. };
  3559. _proto.multiply = function multiply(m, n) {
  3560. if (n !== undefined) {
  3561. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  3562. return this.multiplyMatrices(m, n);
  3563. }
  3564. return this.multiplyMatrices(this, m);
  3565. };
  3566. _proto.premultiply = function premultiply(m) {
  3567. return this.multiplyMatrices(m, this);
  3568. };
  3569. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  3570. var ae = a.elements;
  3571. var be = b.elements;
  3572. var te = this.elements;
  3573. var a11 = ae[0],
  3574. a12 = ae[4],
  3575. a13 = ae[8],
  3576. a14 = ae[12];
  3577. var a21 = ae[1],
  3578. a22 = ae[5],
  3579. a23 = ae[9],
  3580. a24 = ae[13];
  3581. var a31 = ae[2],
  3582. a32 = ae[6],
  3583. a33 = ae[10],
  3584. a34 = ae[14];
  3585. var a41 = ae[3],
  3586. a42 = ae[7],
  3587. a43 = ae[11],
  3588. a44 = ae[15];
  3589. var b11 = be[0],
  3590. b12 = be[4],
  3591. b13 = be[8],
  3592. b14 = be[12];
  3593. var b21 = be[1],
  3594. b22 = be[5],
  3595. b23 = be[9],
  3596. b24 = be[13];
  3597. var b31 = be[2],
  3598. b32 = be[6],
  3599. b33 = be[10],
  3600. b34 = be[14];
  3601. var b41 = be[3],
  3602. b42 = be[7],
  3603. b43 = be[11],
  3604. b44 = be[15];
  3605. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3606. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3607. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3608. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3609. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3610. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3611. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3612. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3613. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3614. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3615. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3616. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3617. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3618. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3619. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3620. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3621. return this;
  3622. };
  3623. _proto.multiplyScalar = function multiplyScalar(s) {
  3624. var te = this.elements;
  3625. te[0] *= s;
  3626. te[4] *= s;
  3627. te[8] *= s;
  3628. te[12] *= s;
  3629. te[1] *= s;
  3630. te[5] *= s;
  3631. te[9] *= s;
  3632. te[13] *= s;
  3633. te[2] *= s;
  3634. te[6] *= s;
  3635. te[10] *= s;
  3636. te[14] *= s;
  3637. te[3] *= s;
  3638. te[7] *= s;
  3639. te[11] *= s;
  3640. te[15] *= s;
  3641. return this;
  3642. };
  3643. _proto.determinant = function determinant() {
  3644. var te = this.elements;
  3645. var n11 = te[0],
  3646. n12 = te[4],
  3647. n13 = te[8],
  3648. n14 = te[12];
  3649. var n21 = te[1],
  3650. n22 = te[5],
  3651. n23 = te[9],
  3652. n24 = te[13];
  3653. var n31 = te[2],
  3654. n32 = te[6],
  3655. n33 = te[10],
  3656. n34 = te[14];
  3657. var n41 = te[3],
  3658. n42 = te[7],
  3659. n43 = te[11],
  3660. n44 = te[15]; //TODO: make this more efficient
  3661. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3662. 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);
  3663. };
  3664. _proto.transpose = function transpose() {
  3665. var te = this.elements;
  3666. var tmp;
  3667. tmp = te[1];
  3668. te[1] = te[4];
  3669. te[4] = tmp;
  3670. tmp = te[2];
  3671. te[2] = te[8];
  3672. te[8] = tmp;
  3673. tmp = te[6];
  3674. te[6] = te[9];
  3675. te[9] = tmp;
  3676. tmp = te[3];
  3677. te[3] = te[12];
  3678. te[12] = tmp;
  3679. tmp = te[7];
  3680. te[7] = te[13];
  3681. te[13] = tmp;
  3682. tmp = te[11];
  3683. te[11] = te[14];
  3684. te[14] = tmp;
  3685. return this;
  3686. };
  3687. _proto.setPosition = function setPosition(x, y, z) {
  3688. var te = this.elements;
  3689. if (x.isVector3) {
  3690. te[12] = x.x;
  3691. te[13] = x.y;
  3692. te[14] = x.z;
  3693. } else {
  3694. te[12] = x;
  3695. te[13] = y;
  3696. te[14] = z;
  3697. }
  3698. return this;
  3699. };
  3700. _proto.invert = function invert() {
  3701. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3702. var te = this.elements,
  3703. n11 = te[0],
  3704. n21 = te[1],
  3705. n31 = te[2],
  3706. n41 = te[3],
  3707. n12 = te[4],
  3708. n22 = te[5],
  3709. n32 = te[6],
  3710. n42 = te[7],
  3711. n13 = te[8],
  3712. n23 = te[9],
  3713. n33 = te[10],
  3714. n43 = te[11],
  3715. n14 = te[12],
  3716. n24 = te[13],
  3717. n34 = te[14],
  3718. n44 = te[15],
  3719. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3720. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3721. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3722. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3723. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3724. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  3725. var detInv = 1 / det;
  3726. te[0] = t11 * detInv;
  3727. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  3728. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  3729. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  3730. te[4] = t12 * detInv;
  3731. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  3732. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  3733. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  3734. te[8] = t13 * detInv;
  3735. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  3736. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  3737. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  3738. te[12] = t14 * detInv;
  3739. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  3740. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  3741. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  3742. return this;
  3743. };
  3744. _proto.scale = function scale(v) {
  3745. var te = this.elements;
  3746. var x = v.x,
  3747. y = v.y,
  3748. z = v.z;
  3749. te[0] *= x;
  3750. te[4] *= y;
  3751. te[8] *= z;
  3752. te[1] *= x;
  3753. te[5] *= y;
  3754. te[9] *= z;
  3755. te[2] *= x;
  3756. te[6] *= y;
  3757. te[10] *= z;
  3758. te[3] *= x;
  3759. te[7] *= y;
  3760. te[11] *= z;
  3761. return this;
  3762. };
  3763. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  3764. var te = this.elements;
  3765. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  3766. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  3767. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  3768. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  3769. };
  3770. _proto.makeTranslation = function makeTranslation(x, y, z) {
  3771. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  3772. return this;
  3773. };
  3774. _proto.makeRotationX = function makeRotationX(theta) {
  3775. var c = Math.cos(theta),
  3776. s = Math.sin(theta);
  3777. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  3778. return this;
  3779. };
  3780. _proto.makeRotationY = function makeRotationY(theta) {
  3781. var c = Math.cos(theta),
  3782. s = Math.sin(theta);
  3783. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  3784. return this;
  3785. };
  3786. _proto.makeRotationZ = function makeRotationZ(theta) {
  3787. var c = Math.cos(theta),
  3788. s = Math.sin(theta);
  3789. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3790. return this;
  3791. };
  3792. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  3793. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3794. var c = Math.cos(angle);
  3795. var s = Math.sin(angle);
  3796. var t = 1 - c;
  3797. var x = axis.x,
  3798. y = axis.y,
  3799. z = axis.z;
  3800. var tx = t * x,
  3801. ty = t * y;
  3802. 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);
  3803. return this;
  3804. };
  3805. _proto.makeScale = function makeScale(x, y, z) {
  3806. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  3807. return this;
  3808. };
  3809. _proto.makeShear = function makeShear(x, y, z) {
  3810. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  3811. return this;
  3812. };
  3813. _proto.compose = function compose(position, quaternion, scale) {
  3814. var te = this.elements;
  3815. var x = quaternion._x,
  3816. y = quaternion._y,
  3817. z = quaternion._z,
  3818. w = quaternion._w;
  3819. var x2 = x + x,
  3820. y2 = y + y,
  3821. z2 = z + z;
  3822. var xx = x * x2,
  3823. xy = x * y2,
  3824. xz = x * z2;
  3825. var yy = y * y2,
  3826. yz = y * z2,
  3827. zz = z * z2;
  3828. var wx = w * x2,
  3829. wy = w * y2,
  3830. wz = w * z2;
  3831. var sx = scale.x,
  3832. sy = scale.y,
  3833. sz = scale.z;
  3834. te[0] = (1 - (yy + zz)) * sx;
  3835. te[1] = (xy + wz) * sx;
  3836. te[2] = (xz - wy) * sx;
  3837. te[3] = 0;
  3838. te[4] = (xy - wz) * sy;
  3839. te[5] = (1 - (xx + zz)) * sy;
  3840. te[6] = (yz + wx) * sy;
  3841. te[7] = 0;
  3842. te[8] = (xz + wy) * sz;
  3843. te[9] = (yz - wx) * sz;
  3844. te[10] = (1 - (xx + yy)) * sz;
  3845. te[11] = 0;
  3846. te[12] = position.x;
  3847. te[13] = position.y;
  3848. te[14] = position.z;
  3849. te[15] = 1;
  3850. return this;
  3851. };
  3852. _proto.decompose = function decompose(position, quaternion, scale) {
  3853. var te = this.elements;
  3854. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  3855. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  3856. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  3857. var det = this.determinant();
  3858. if (det < 0) sx = -sx;
  3859. position.x = te[12];
  3860. position.y = te[13];
  3861. position.z = te[14]; // scale the rotation part
  3862. _m1.copy(this);
  3863. var invSX = 1 / sx;
  3864. var invSY = 1 / sy;
  3865. var invSZ = 1 / sz;
  3866. _m1.elements[0] *= invSX;
  3867. _m1.elements[1] *= invSX;
  3868. _m1.elements[2] *= invSX;
  3869. _m1.elements[4] *= invSY;
  3870. _m1.elements[5] *= invSY;
  3871. _m1.elements[6] *= invSY;
  3872. _m1.elements[8] *= invSZ;
  3873. _m1.elements[9] *= invSZ;
  3874. _m1.elements[10] *= invSZ;
  3875. quaternion.setFromRotationMatrix(_m1);
  3876. scale.x = sx;
  3877. scale.y = sy;
  3878. scale.z = sz;
  3879. return this;
  3880. };
  3881. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  3882. if (far === undefined) {
  3883. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  3884. }
  3885. var te = this.elements;
  3886. var x = 2 * near / (right - left);
  3887. var y = 2 * near / (top - bottom);
  3888. var a = (right + left) / (right - left);
  3889. var b = (top + bottom) / (top - bottom);
  3890. var c = -(far + near) / (far - near);
  3891. var d = -2 * far * near / (far - near);
  3892. te[0] = x;
  3893. te[4] = 0;
  3894. te[8] = a;
  3895. te[12] = 0;
  3896. te[1] = 0;
  3897. te[5] = y;
  3898. te[9] = b;
  3899. te[13] = 0;
  3900. te[2] = 0;
  3901. te[6] = 0;
  3902. te[10] = c;
  3903. te[14] = d;
  3904. te[3] = 0;
  3905. te[7] = 0;
  3906. te[11] = -1;
  3907. te[15] = 0;
  3908. return this;
  3909. };
  3910. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  3911. var te = this.elements;
  3912. var w = 1.0 / (right - left);
  3913. var h = 1.0 / (top - bottom);
  3914. var p = 1.0 / (far - near);
  3915. var x = (right + left) * w;
  3916. var y = (top + bottom) * h;
  3917. var z = (far + near) * p;
  3918. te[0] = 2 * w;
  3919. te[4] = 0;
  3920. te[8] = 0;
  3921. te[12] = -x;
  3922. te[1] = 0;
  3923. te[5] = 2 * h;
  3924. te[9] = 0;
  3925. te[13] = -y;
  3926. te[2] = 0;
  3927. te[6] = 0;
  3928. te[10] = -2 * p;
  3929. te[14] = -z;
  3930. te[3] = 0;
  3931. te[7] = 0;
  3932. te[11] = 0;
  3933. te[15] = 1;
  3934. return this;
  3935. };
  3936. _proto.equals = function equals(matrix) {
  3937. var te = this.elements;
  3938. var me = matrix.elements;
  3939. for (var i = 0; i < 16; i++) {
  3940. if (te[i] !== me[i]) return false;
  3941. }
  3942. return true;
  3943. };
  3944. _proto.fromArray = function fromArray(array, offset) {
  3945. if (offset === void 0) {
  3946. offset = 0;
  3947. }
  3948. for (var i = 0; i < 16; i++) {
  3949. this.elements[i] = array[i + offset];
  3950. }
  3951. return this;
  3952. };
  3953. _proto.toArray = function toArray(array, offset) {
  3954. if (array === void 0) {
  3955. array = [];
  3956. }
  3957. if (offset === void 0) {
  3958. offset = 0;
  3959. }
  3960. var te = this.elements;
  3961. array[offset] = te[0];
  3962. array[offset + 1] = te[1];
  3963. array[offset + 2] = te[2];
  3964. array[offset + 3] = te[3];
  3965. array[offset + 4] = te[4];
  3966. array[offset + 5] = te[5];
  3967. array[offset + 6] = te[6];
  3968. array[offset + 7] = te[7];
  3969. array[offset + 8] = te[8];
  3970. array[offset + 9] = te[9];
  3971. array[offset + 10] = te[10];
  3972. array[offset + 11] = te[11];
  3973. array[offset + 12] = te[12];
  3974. array[offset + 13] = te[13];
  3975. array[offset + 14] = te[14];
  3976. array[offset + 15] = te[15];
  3977. return array;
  3978. };
  3979. return Matrix4;
  3980. }();
  3981. var _v1$1 = /*@__PURE__*/new Vector3();
  3982. var _m1 = /*@__PURE__*/new Matrix4();
  3983. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  3984. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  3985. var _x = /*@__PURE__*/new Vector3();
  3986. var _y = /*@__PURE__*/new Vector3();
  3987. var _z = /*@__PURE__*/new Vector3();
  3988. var Euler = /*#__PURE__*/function () {
  3989. function Euler(x, y, z, order) {
  3990. if (x === void 0) {
  3991. x = 0;
  3992. }
  3993. if (y === void 0) {
  3994. y = 0;
  3995. }
  3996. if (z === void 0) {
  3997. z = 0;
  3998. }
  3999. if (order === void 0) {
  4000. order = Euler.DefaultOrder;
  4001. }
  4002. Object.defineProperty(this, 'isEuler', {
  4003. value: true
  4004. });
  4005. this._x = x;
  4006. this._y = y;
  4007. this._z = z;
  4008. this._order = order;
  4009. }
  4010. var _proto = Euler.prototype;
  4011. _proto.set = function set(x, y, z, order) {
  4012. this._x = x;
  4013. this._y = y;
  4014. this._z = z;
  4015. this._order = order || this._order;
  4016. this._onChangeCallback();
  4017. return this;
  4018. };
  4019. _proto.clone = function clone() {
  4020. return new this.constructor(this._x, this._y, this._z, this._order);
  4021. };
  4022. _proto.copy = function copy(euler) {
  4023. this._x = euler._x;
  4024. this._y = euler._y;
  4025. this._z = euler._z;
  4026. this._order = euler._order;
  4027. this._onChangeCallback();
  4028. return this;
  4029. };
  4030. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4031. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4032. var te = m.elements;
  4033. var m11 = te[0],
  4034. m12 = te[4],
  4035. m13 = te[8];
  4036. var m21 = te[1],
  4037. m22 = te[5],
  4038. m23 = te[9];
  4039. var m31 = te[2],
  4040. m32 = te[6],
  4041. m33 = te[10];
  4042. order = order || this._order;
  4043. switch (order) {
  4044. case 'XYZ':
  4045. this._y = Math.asin(clamp(m13, -1, 1));
  4046. if (Math.abs(m13) < 0.9999999) {
  4047. this._x = Math.atan2(-m23, m33);
  4048. this._z = Math.atan2(-m12, m11);
  4049. } else {
  4050. this._x = Math.atan2(m32, m22);
  4051. this._z = 0;
  4052. }
  4053. break;
  4054. case 'YXZ':
  4055. this._x = Math.asin(-clamp(m23, -1, 1));
  4056. if (Math.abs(m23) < 0.9999999) {
  4057. this._y = Math.atan2(m13, m33);
  4058. this._z = Math.atan2(m21, m22);
  4059. } else {
  4060. this._y = Math.atan2(-m31, m11);
  4061. this._z = 0;
  4062. }
  4063. break;
  4064. case 'ZXY':
  4065. this._x = Math.asin(clamp(m32, -1, 1));
  4066. if (Math.abs(m32) < 0.9999999) {
  4067. this._y = Math.atan2(-m31, m33);
  4068. this._z = Math.atan2(-m12, m22);
  4069. } else {
  4070. this._y = 0;
  4071. this._z = Math.atan2(m21, m11);
  4072. }
  4073. break;
  4074. case 'ZYX':
  4075. this._y = Math.asin(-clamp(m31, -1, 1));
  4076. if (Math.abs(m31) < 0.9999999) {
  4077. this._x = Math.atan2(m32, m33);
  4078. this._z = Math.atan2(m21, m11);
  4079. } else {
  4080. this._x = 0;
  4081. this._z = Math.atan2(-m12, m22);
  4082. }
  4083. break;
  4084. case 'YZX':
  4085. this._z = Math.asin(clamp(m21, -1, 1));
  4086. if (Math.abs(m21) < 0.9999999) {
  4087. this._x = Math.atan2(-m23, m22);
  4088. this._y = Math.atan2(-m31, m11);
  4089. } else {
  4090. this._x = 0;
  4091. this._y = Math.atan2(m13, m33);
  4092. }
  4093. break;
  4094. case 'XZY':
  4095. this._z = Math.asin(-clamp(m12, -1, 1));
  4096. if (Math.abs(m12) < 0.9999999) {
  4097. this._x = Math.atan2(m32, m22);
  4098. this._y = Math.atan2(m13, m11);
  4099. } else {
  4100. this._x = Math.atan2(-m23, m33);
  4101. this._y = 0;
  4102. }
  4103. break;
  4104. default:
  4105. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4106. }
  4107. this._order = order;
  4108. if (update !== false) this._onChangeCallback();
  4109. return this;
  4110. };
  4111. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4112. _matrix.makeRotationFromQuaternion(q);
  4113. return this.setFromRotationMatrix(_matrix, order, update);
  4114. };
  4115. _proto.setFromVector3 = function setFromVector3(v, order) {
  4116. return this.set(v.x, v.y, v.z, order || this._order);
  4117. };
  4118. _proto.reorder = function reorder(newOrder) {
  4119. // WARNING: this discards revolution information -bhouston
  4120. _quaternion$1.setFromEuler(this);
  4121. return this.setFromQuaternion(_quaternion$1, newOrder);
  4122. };
  4123. _proto.equals = function equals(euler) {
  4124. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4125. };
  4126. _proto.fromArray = function fromArray(array) {
  4127. this._x = array[0];
  4128. this._y = array[1];
  4129. this._z = array[2];
  4130. if (array[3] !== undefined) this._order = array[3];
  4131. this._onChangeCallback();
  4132. return this;
  4133. };
  4134. _proto.toArray = function toArray(array, offset) {
  4135. if (array === void 0) {
  4136. array = [];
  4137. }
  4138. if (offset === void 0) {
  4139. offset = 0;
  4140. }
  4141. array[offset] = this._x;
  4142. array[offset + 1] = this._y;
  4143. array[offset + 2] = this._z;
  4144. array[offset + 3] = this._order;
  4145. return array;
  4146. };
  4147. _proto.toVector3 = function toVector3(optionalResult) {
  4148. if (optionalResult) {
  4149. return optionalResult.set(this._x, this._y, this._z);
  4150. } else {
  4151. return new Vector3(this._x, this._y, this._z);
  4152. }
  4153. };
  4154. _proto._onChange = function _onChange(callback) {
  4155. this._onChangeCallback = callback;
  4156. return this;
  4157. };
  4158. _proto._onChangeCallback = function _onChangeCallback() {};
  4159. _createClass(Euler, [{
  4160. key: "x",
  4161. get: function get() {
  4162. return this._x;
  4163. },
  4164. set: function set(value) {
  4165. this._x = value;
  4166. this._onChangeCallback();
  4167. }
  4168. }, {
  4169. key: "y",
  4170. get: function get() {
  4171. return this._y;
  4172. },
  4173. set: function set(value) {
  4174. this._y = value;
  4175. this._onChangeCallback();
  4176. }
  4177. }, {
  4178. key: "z",
  4179. get: function get() {
  4180. return this._z;
  4181. },
  4182. set: function set(value) {
  4183. this._z = value;
  4184. this._onChangeCallback();
  4185. }
  4186. }, {
  4187. key: "order",
  4188. get: function get() {
  4189. return this._order;
  4190. },
  4191. set: function set(value) {
  4192. this._order = value;
  4193. this._onChangeCallback();
  4194. }
  4195. }]);
  4196. return Euler;
  4197. }();
  4198. Euler.DefaultOrder = 'XYZ';
  4199. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4200. var _matrix = /*@__PURE__*/new Matrix4();
  4201. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4202. var Layers = /*#__PURE__*/function () {
  4203. function Layers() {
  4204. this.mask = 1 | 0;
  4205. }
  4206. var _proto = Layers.prototype;
  4207. _proto.set = function set(channel) {
  4208. this.mask = 1 << channel | 0;
  4209. };
  4210. _proto.enable = function enable(channel) {
  4211. this.mask |= 1 << channel | 0;
  4212. };
  4213. _proto.enableAll = function enableAll() {
  4214. this.mask = 0xffffffff | 0;
  4215. };
  4216. _proto.toggle = function toggle(channel) {
  4217. this.mask ^= 1 << channel | 0;
  4218. };
  4219. _proto.disable = function disable(channel) {
  4220. this.mask &= ~(1 << channel | 0);
  4221. };
  4222. _proto.disableAll = function disableAll() {
  4223. this.mask = 0;
  4224. };
  4225. _proto.test = function test(layers) {
  4226. return (this.mask & layers.mask) !== 0;
  4227. };
  4228. return Layers;
  4229. }();
  4230. var _object3DId = 0;
  4231. var _v1$2 = new Vector3();
  4232. var _q1 = new Quaternion();
  4233. var _m1$1 = new Matrix4();
  4234. var _target = new Vector3();
  4235. var _position = new Vector3();
  4236. var _scale = new Vector3();
  4237. var _quaternion$2 = new Quaternion();
  4238. var _xAxis = new Vector3(1, 0, 0);
  4239. var _yAxis = new Vector3(0, 1, 0);
  4240. var _zAxis = new Vector3(0, 0, 1);
  4241. var _addedEvent = {
  4242. type: 'added'
  4243. };
  4244. var _removedEvent = {
  4245. type: 'removed'
  4246. };
  4247. function Object3D() {
  4248. Object.defineProperty(this, 'id', {
  4249. value: _object3DId++
  4250. });
  4251. this.uuid = MathUtils.generateUUID();
  4252. this.name = '';
  4253. this.type = 'Object3D';
  4254. this.parent = null;
  4255. this.children = [];
  4256. this.up = Object3D.DefaultUp.clone();
  4257. var position = new Vector3();
  4258. var rotation = new Euler();
  4259. var quaternion = new Quaternion();
  4260. var scale = new Vector3(1, 1, 1);
  4261. function onRotationChange() {
  4262. quaternion.setFromEuler(rotation, false);
  4263. }
  4264. function onQuaternionChange() {
  4265. rotation.setFromQuaternion(quaternion, undefined, false);
  4266. }
  4267. rotation._onChange(onRotationChange);
  4268. quaternion._onChange(onQuaternionChange);
  4269. Object.defineProperties(this, {
  4270. position: {
  4271. configurable: true,
  4272. enumerable: true,
  4273. value: position
  4274. },
  4275. rotation: {
  4276. configurable: true,
  4277. enumerable: true,
  4278. value: rotation
  4279. },
  4280. quaternion: {
  4281. configurable: true,
  4282. enumerable: true,
  4283. value: quaternion
  4284. },
  4285. scale: {
  4286. configurable: true,
  4287. enumerable: true,
  4288. value: scale
  4289. },
  4290. modelViewMatrix: {
  4291. value: new Matrix4()
  4292. },
  4293. normalMatrix: {
  4294. value: new Matrix3()
  4295. }
  4296. });
  4297. this.matrix = new Matrix4();
  4298. this.matrixWorld = new Matrix4();
  4299. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  4300. this.matrixWorldNeedsUpdate = false;
  4301. this.layers = new Layers();
  4302. this.visible = true;
  4303. this.castShadow = false;
  4304. this.receiveShadow = false;
  4305. this.frustumCulled = true;
  4306. this.renderOrder = 0;
  4307. this.userData = {};
  4308. }
  4309. Object3D.DefaultUp = new Vector3(0, 1, 0);
  4310. Object3D.DefaultMatrixAutoUpdate = true;
  4311. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  4312. constructor: Object3D,
  4313. isObject3D: true,
  4314. onBeforeRender: function onBeforeRender() {},
  4315. onAfterRender: function onAfterRender() {},
  4316. applyMatrix4: function applyMatrix4(matrix) {
  4317. if (this.matrixAutoUpdate) this.updateMatrix();
  4318. this.matrix.premultiply(matrix);
  4319. this.matrix.decompose(this.position, this.quaternion, this.scale);
  4320. },
  4321. applyQuaternion: function applyQuaternion(q) {
  4322. this.quaternion.premultiply(q);
  4323. return this;
  4324. },
  4325. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  4326. // assumes axis is normalized
  4327. this.quaternion.setFromAxisAngle(axis, angle);
  4328. },
  4329. setRotationFromEuler: function setRotationFromEuler(euler) {
  4330. this.quaternion.setFromEuler(euler, true);
  4331. },
  4332. setRotationFromMatrix: function setRotationFromMatrix(m) {
  4333. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4334. this.quaternion.setFromRotationMatrix(m);
  4335. },
  4336. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  4337. // assumes q is normalized
  4338. this.quaternion.copy(q);
  4339. },
  4340. rotateOnAxis: function rotateOnAxis(axis, angle) {
  4341. // rotate object on axis in object space
  4342. // axis is assumed to be normalized
  4343. _q1.setFromAxisAngle(axis, angle);
  4344. this.quaternion.multiply(_q1);
  4345. return this;
  4346. },
  4347. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  4348. // rotate object on axis in world space
  4349. // axis is assumed to be normalized
  4350. // method assumes no rotated parent
  4351. _q1.setFromAxisAngle(axis, angle);
  4352. this.quaternion.premultiply(_q1);
  4353. return this;
  4354. },
  4355. rotateX: function rotateX(angle) {
  4356. return this.rotateOnAxis(_xAxis, angle);
  4357. },
  4358. rotateY: function rotateY(angle) {
  4359. return this.rotateOnAxis(_yAxis, angle);
  4360. },
  4361. rotateZ: function rotateZ(angle) {
  4362. return this.rotateOnAxis(_zAxis, angle);
  4363. },
  4364. translateOnAxis: function translateOnAxis(axis, distance) {
  4365. // translate object by distance along axis in object space
  4366. // axis is assumed to be normalized
  4367. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  4368. this.position.add(_v1$2.multiplyScalar(distance));
  4369. return this;
  4370. },
  4371. translateX: function translateX(distance) {
  4372. return this.translateOnAxis(_xAxis, distance);
  4373. },
  4374. translateY: function translateY(distance) {
  4375. return this.translateOnAxis(_yAxis, distance);
  4376. },
  4377. translateZ: function translateZ(distance) {
  4378. return this.translateOnAxis(_zAxis, distance);
  4379. },
  4380. localToWorld: function localToWorld(vector) {
  4381. return vector.applyMatrix4(this.matrixWorld);
  4382. },
  4383. worldToLocal: function worldToLocal(vector) {
  4384. return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());
  4385. },
  4386. lookAt: function lookAt(x, y, z) {
  4387. // This method does not support objects having non-uniformly-scaled parent(s)
  4388. if (x.isVector3) {
  4389. _target.copy(x);
  4390. } else {
  4391. _target.set(x, y, z);
  4392. }
  4393. var parent = this.parent;
  4394. this.updateWorldMatrix(true, false);
  4395. _position.setFromMatrixPosition(this.matrixWorld);
  4396. if (this.isCamera || this.isLight) {
  4397. _m1$1.lookAt(_position, _target, this.up);
  4398. } else {
  4399. _m1$1.lookAt(_target, _position, this.up);
  4400. }
  4401. this.quaternion.setFromRotationMatrix(_m1$1);
  4402. if (parent) {
  4403. _m1$1.extractRotation(parent.matrixWorld);
  4404. _q1.setFromRotationMatrix(_m1$1);
  4405. this.quaternion.premultiply(_q1.invert());
  4406. }
  4407. },
  4408. add: function add(object) {
  4409. if (arguments.length > 1) {
  4410. for (var i = 0; i < arguments.length; i++) {
  4411. this.add(arguments[i]);
  4412. }
  4413. return this;
  4414. }
  4415. if (object === this) {
  4416. console.error("THREE.Object3D.add: object can't be added as a child of itself.", object);
  4417. return this;
  4418. }
  4419. if (object && object.isObject3D) {
  4420. if (object.parent !== null) {
  4421. object.parent.remove(object);
  4422. }
  4423. object.parent = this;
  4424. this.children.push(object);
  4425. object.dispatchEvent(_addedEvent);
  4426. } else {
  4427. console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.", object);
  4428. }
  4429. return this;
  4430. },
  4431. remove: function remove(object) {
  4432. if (arguments.length > 1) {
  4433. for (var i = 0; i < arguments.length; i++) {
  4434. this.remove(arguments[i]);
  4435. }
  4436. return this;
  4437. }
  4438. var index = this.children.indexOf(object);
  4439. if (index !== -1) {
  4440. object.parent = null;
  4441. this.children.splice(index, 1);
  4442. object.dispatchEvent(_removedEvent);
  4443. }
  4444. return this;
  4445. },
  4446. clear: function clear() {
  4447. for (var i = 0; i < this.children.length; i++) {
  4448. var object = this.children[i];
  4449. object.parent = null;
  4450. object.dispatchEvent(_removedEvent);
  4451. }
  4452. this.children.length = 0;
  4453. return this;
  4454. },
  4455. attach: function attach(object) {
  4456. // adds object as a child of this, while maintaining the object's world transform
  4457. this.updateWorldMatrix(true, false);
  4458. _m1$1.copy(this.matrixWorld).invert();
  4459. if (object.parent !== null) {
  4460. object.parent.updateWorldMatrix(true, false);
  4461. _m1$1.multiply(object.parent.matrixWorld);
  4462. }
  4463. object.applyMatrix4(_m1$1);
  4464. object.updateWorldMatrix(false, false);
  4465. this.add(object);
  4466. return this;
  4467. },
  4468. getObjectById: function getObjectById(id) {
  4469. return this.getObjectByProperty('id', id);
  4470. },
  4471. getObjectByName: function getObjectByName(name) {
  4472. return this.getObjectByProperty('name', name);
  4473. },
  4474. getObjectByProperty: function getObjectByProperty(name, value) {
  4475. if (this[name] === value) return this;
  4476. for (var i = 0, l = this.children.length; i < l; i++) {
  4477. var child = this.children[i];
  4478. var object = child.getObjectByProperty(name, value);
  4479. if (object !== undefined) {
  4480. return object;
  4481. }
  4482. }
  4483. return undefined;
  4484. },
  4485. getWorldPosition: function getWorldPosition(target) {
  4486. if (target === undefined) {
  4487. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  4488. target = new Vector3();
  4489. }
  4490. this.updateWorldMatrix(true, false);
  4491. return target.setFromMatrixPosition(this.matrixWorld);
  4492. },
  4493. getWorldQuaternion: function getWorldQuaternion(target) {
  4494. if (target === undefined) {
  4495. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  4496. target = new Quaternion();
  4497. }
  4498. this.updateWorldMatrix(true, false);
  4499. this.matrixWorld.decompose(_position, target, _scale);
  4500. return target;
  4501. },
  4502. getWorldScale: function getWorldScale(target) {
  4503. if (target === undefined) {
  4504. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  4505. target = new Vector3();
  4506. }
  4507. this.updateWorldMatrix(true, false);
  4508. this.matrixWorld.decompose(_position, _quaternion$2, target);
  4509. return target;
  4510. },
  4511. getWorldDirection: function getWorldDirection(target) {
  4512. if (target === undefined) {
  4513. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  4514. target = new Vector3();
  4515. }
  4516. this.updateWorldMatrix(true, false);
  4517. var e = this.matrixWorld.elements;
  4518. return target.set(e[8], e[9], e[10]).normalize();
  4519. },
  4520. raycast: function raycast() {},
  4521. traverse: function traverse(callback) {
  4522. callback(this);
  4523. var children = this.children;
  4524. for (var i = 0, l = children.length; i < l; i++) {
  4525. children[i].traverse(callback);
  4526. }
  4527. },
  4528. traverseVisible: function traverseVisible(callback) {
  4529. if (this.visible === false) return;
  4530. callback(this);
  4531. var children = this.children;
  4532. for (var i = 0, l = children.length; i < l; i++) {
  4533. children[i].traverseVisible(callback);
  4534. }
  4535. },
  4536. traverseAncestors: function traverseAncestors(callback) {
  4537. var parent = this.parent;
  4538. if (parent !== null) {
  4539. callback(parent);
  4540. parent.traverseAncestors(callback);
  4541. }
  4542. },
  4543. updateMatrix: function updateMatrix() {
  4544. this.matrix.compose(this.position, this.quaternion, this.scale);
  4545. this.matrixWorldNeedsUpdate = true;
  4546. },
  4547. updateMatrixWorld: function updateMatrixWorld(force) {
  4548. if (this.matrixAutoUpdate) this.updateMatrix();
  4549. if (this.matrixWorldNeedsUpdate || force) {
  4550. if (this.parent === null) {
  4551. this.matrixWorld.copy(this.matrix);
  4552. } else {
  4553. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4554. }
  4555. this.matrixWorldNeedsUpdate = false;
  4556. force = true;
  4557. } // update children
  4558. var children = this.children;
  4559. for (var i = 0, l = children.length; i < l; i++) {
  4560. children[i].updateMatrixWorld(force);
  4561. }
  4562. },
  4563. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  4564. var parent = this.parent;
  4565. if (updateParents === true && parent !== null) {
  4566. parent.updateWorldMatrix(true, false);
  4567. }
  4568. if (this.matrixAutoUpdate) this.updateMatrix();
  4569. if (this.parent === null) {
  4570. this.matrixWorld.copy(this.matrix);
  4571. } else {
  4572. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4573. } // update children
  4574. if (updateChildren === true) {
  4575. var children = this.children;
  4576. for (var i = 0, l = children.length; i < l; i++) {
  4577. children[i].updateWorldMatrix(false, true);
  4578. }
  4579. }
  4580. },
  4581. toJSON: function toJSON(meta) {
  4582. // meta is a string when called from JSON.stringify
  4583. var isRootObject = meta === undefined || typeof meta === 'string';
  4584. var output = {}; // meta is a hash used to collect geometries, materials.
  4585. // not providing it implies that this is the root object
  4586. // being serialized.
  4587. if (isRootObject) {
  4588. // initialize meta obj
  4589. meta = {
  4590. geometries: {},
  4591. materials: {},
  4592. textures: {},
  4593. images: {},
  4594. shapes: {},
  4595. skeletons: {}
  4596. };
  4597. output.metadata = {
  4598. version: 4.5,
  4599. type: 'Object',
  4600. generator: 'Object3D.toJSON'
  4601. };
  4602. } // standard Object3D serialization
  4603. var object = {};
  4604. object.uuid = this.uuid;
  4605. object.type = this.type;
  4606. if (this.name !== '') object.name = this.name;
  4607. if (this.castShadow === true) object.castShadow = true;
  4608. if (this.receiveShadow === true) object.receiveShadow = true;
  4609. if (this.visible === false) object.visible = false;
  4610. if (this.frustumCulled === false) object.frustumCulled = false;
  4611. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  4612. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  4613. object.layers = this.layers.mask;
  4614. object.matrix = this.matrix.toArray();
  4615. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  4616. if (this.isInstancedMesh) {
  4617. object.type = 'InstancedMesh';
  4618. object.count = this.count;
  4619. object.instanceMatrix = this.instanceMatrix.toJSON();
  4620. } //
  4621. function serialize(library, element) {
  4622. if (library[element.uuid] === undefined) {
  4623. library[element.uuid] = element.toJSON(meta);
  4624. }
  4625. return element.uuid;
  4626. }
  4627. if (this.isMesh || this.isLine || this.isPoints) {
  4628. object.geometry = serialize(meta.geometries, this.geometry);
  4629. var parameters = this.geometry.parameters;
  4630. if (parameters !== undefined && parameters.shapes !== undefined) {
  4631. var shapes = parameters.shapes;
  4632. if (Array.isArray(shapes)) {
  4633. for (var i = 0, l = shapes.length; i < l; i++) {
  4634. var shape = shapes[i];
  4635. serialize(meta.shapes, shape);
  4636. }
  4637. } else {
  4638. serialize(meta.shapes, shapes);
  4639. }
  4640. }
  4641. }
  4642. if (this.isSkinnedMesh) {
  4643. object.bindMode = this.bindMode;
  4644. object.bindMatrix = this.bindMatrix.toArray();
  4645. if (this.skeleton !== undefined) {
  4646. serialize(meta.skeletons, this.skeleton);
  4647. object.skeleton = this.skeleton.uuid;
  4648. }
  4649. }
  4650. if (this.material !== undefined) {
  4651. if (Array.isArray(this.material)) {
  4652. var uuids = [];
  4653. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  4654. uuids.push(serialize(meta.materials, this.material[_i]));
  4655. }
  4656. object.material = uuids;
  4657. } else {
  4658. object.material = serialize(meta.materials, this.material);
  4659. }
  4660. } //
  4661. if (this.children.length > 0) {
  4662. object.children = [];
  4663. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  4664. object.children.push(this.children[_i2].toJSON(meta).object);
  4665. }
  4666. }
  4667. if (isRootObject) {
  4668. var geometries = extractFromCache(meta.geometries);
  4669. var materials = extractFromCache(meta.materials);
  4670. var textures = extractFromCache(meta.textures);
  4671. var images = extractFromCache(meta.images);
  4672. var _shapes = extractFromCache(meta.shapes);
  4673. var skeletons = extractFromCache(meta.skeletons);
  4674. if (geometries.length > 0) output.geometries = geometries;
  4675. if (materials.length > 0) output.materials = materials;
  4676. if (textures.length > 0) output.textures = textures;
  4677. if (images.length > 0) output.images = images;
  4678. if (_shapes.length > 0) output.shapes = _shapes;
  4679. if (skeletons.length > 0) output.skeletons = skeletons;
  4680. }
  4681. output.object = object;
  4682. return output; // extract data from the cache hash
  4683. // remove metadata on each item
  4684. // and return as array
  4685. function extractFromCache(cache) {
  4686. var values = [];
  4687. for (var key in cache) {
  4688. var data = cache[key];
  4689. delete data.metadata;
  4690. values.push(data);
  4691. }
  4692. return values;
  4693. }
  4694. },
  4695. clone: function clone(recursive) {
  4696. return new this.constructor().copy(this, recursive);
  4697. },
  4698. copy: function copy(source, recursive) {
  4699. if (recursive === void 0) {
  4700. recursive = true;
  4701. }
  4702. this.name = source.name;
  4703. this.up.copy(source.up);
  4704. this.position.copy(source.position);
  4705. this.rotation.order = source.rotation.order;
  4706. this.quaternion.copy(source.quaternion);
  4707. this.scale.copy(source.scale);
  4708. this.matrix.copy(source.matrix);
  4709. this.matrixWorld.copy(source.matrixWorld);
  4710. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4711. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4712. this.layers.mask = source.layers.mask;
  4713. this.visible = source.visible;
  4714. this.castShadow = source.castShadow;
  4715. this.receiveShadow = source.receiveShadow;
  4716. this.frustumCulled = source.frustumCulled;
  4717. this.renderOrder = source.renderOrder;
  4718. this.userData = JSON.parse(JSON.stringify(source.userData));
  4719. if (recursive === true) {
  4720. for (var i = 0; i < source.children.length; i++) {
  4721. var child = source.children[i];
  4722. this.add(child.clone());
  4723. }
  4724. }
  4725. return this;
  4726. }
  4727. });
  4728. var _vector1 = /*@__PURE__*/new Vector3();
  4729. var _vector2 = /*@__PURE__*/new Vector3();
  4730. var _normalMatrix = /*@__PURE__*/new Matrix3();
  4731. var Plane = /*#__PURE__*/function () {
  4732. function Plane(normal, constant) {
  4733. Object.defineProperty(this, 'isPlane', {
  4734. value: true
  4735. }); // normal is assumed to be normalized
  4736. this.normal = normal !== undefined ? normal : new Vector3(1, 0, 0);
  4737. this.constant = constant !== undefined ? constant : 0;
  4738. }
  4739. var _proto = Plane.prototype;
  4740. _proto.set = function set(normal, constant) {
  4741. this.normal.copy(normal);
  4742. this.constant = constant;
  4743. return this;
  4744. };
  4745. _proto.setComponents = function setComponents(x, y, z, w) {
  4746. this.normal.set(x, y, z);
  4747. this.constant = w;
  4748. return this;
  4749. };
  4750. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  4751. this.normal.copy(normal);
  4752. this.constant = -point.dot(this.normal);
  4753. return this;
  4754. };
  4755. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  4756. 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)?
  4757. this.setFromNormalAndCoplanarPoint(normal, a);
  4758. return this;
  4759. };
  4760. _proto.clone = function clone() {
  4761. return new this.constructor().copy(this);
  4762. };
  4763. _proto.copy = function copy(plane) {
  4764. this.normal.copy(plane.normal);
  4765. this.constant = plane.constant;
  4766. return this;
  4767. };
  4768. _proto.normalize = function normalize() {
  4769. // Note: will lead to a divide by zero if the plane is invalid.
  4770. var inverseNormalLength = 1.0 / this.normal.length();
  4771. this.normal.multiplyScalar(inverseNormalLength);
  4772. this.constant *= inverseNormalLength;
  4773. return this;
  4774. };
  4775. _proto.negate = function negate() {
  4776. this.constant *= -1;
  4777. this.normal.negate();
  4778. return this;
  4779. };
  4780. _proto.distanceToPoint = function distanceToPoint(point) {
  4781. return this.normal.dot(point) + this.constant;
  4782. };
  4783. _proto.distanceToSphere = function distanceToSphere(sphere) {
  4784. return this.distanceToPoint(sphere.center) - sphere.radius;
  4785. };
  4786. _proto.projectPoint = function projectPoint(point, target) {
  4787. if (target === undefined) {
  4788. console.warn('THREE.Plane: .projectPoint() target is now required');
  4789. target = new Vector3();
  4790. }
  4791. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  4792. };
  4793. _proto.intersectLine = function intersectLine(line, target) {
  4794. if (target === undefined) {
  4795. console.warn('THREE.Plane: .intersectLine() target is now required');
  4796. target = new Vector3();
  4797. }
  4798. var direction = line.delta(_vector1);
  4799. var denominator = this.normal.dot(direction);
  4800. if (denominator === 0) {
  4801. // line is coplanar, return origin
  4802. if (this.distanceToPoint(line.start) === 0) {
  4803. return target.copy(line.start);
  4804. } // Unsure if this is the correct method to handle this case.
  4805. return undefined;
  4806. }
  4807. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  4808. if (t < 0 || t > 1) {
  4809. return undefined;
  4810. }
  4811. return target.copy(direction).multiplyScalar(t).add(line.start);
  4812. };
  4813. _proto.intersectsLine = function intersectsLine(line) {
  4814. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4815. var startSign = this.distanceToPoint(line.start);
  4816. var endSign = this.distanceToPoint(line.end);
  4817. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  4818. };
  4819. _proto.intersectsBox = function intersectsBox(box) {
  4820. return box.intersectsPlane(this);
  4821. };
  4822. _proto.intersectsSphere = function intersectsSphere(sphere) {
  4823. return sphere.intersectsPlane(this);
  4824. };
  4825. _proto.coplanarPoint = function coplanarPoint(target) {
  4826. if (target === undefined) {
  4827. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  4828. target = new Vector3();
  4829. }
  4830. return target.copy(this.normal).multiplyScalar(-this.constant);
  4831. };
  4832. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  4833. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  4834. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  4835. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  4836. this.constant = -referencePoint.dot(normal);
  4837. return this;
  4838. };
  4839. _proto.translate = function translate(offset) {
  4840. this.constant -= offset.dot(this.normal);
  4841. return this;
  4842. };
  4843. _proto.equals = function equals(plane) {
  4844. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  4845. };
  4846. return Plane;
  4847. }();
  4848. var _v0$1 = /*@__PURE__*/new Vector3();
  4849. var _v1$3 = /*@__PURE__*/new Vector3();
  4850. var _v2$1 = /*@__PURE__*/new Vector3();
  4851. var _v3 = /*@__PURE__*/new Vector3();
  4852. var _vab = /*@__PURE__*/new Vector3();
  4853. var _vac = /*@__PURE__*/new Vector3();
  4854. var _vbc = /*@__PURE__*/new Vector3();
  4855. var _vap = /*@__PURE__*/new Vector3();
  4856. var _vbp = /*@__PURE__*/new Vector3();
  4857. var _vcp = /*@__PURE__*/new Vector3();
  4858. var Triangle = /*#__PURE__*/function () {
  4859. function Triangle(a, b, c) {
  4860. this.a = a !== undefined ? a : new Vector3();
  4861. this.b = b !== undefined ? b : new Vector3();
  4862. this.c = c !== undefined ? c : new Vector3();
  4863. }
  4864. Triangle.getNormal = function getNormal(a, b, c, target) {
  4865. if (target === undefined) {
  4866. console.warn('THREE.Triangle: .getNormal() target is now required');
  4867. target = new Vector3();
  4868. }
  4869. target.subVectors(c, b);
  4870. _v0$1.subVectors(a, b);
  4871. target.cross(_v0$1);
  4872. var targetLengthSq = target.lengthSq();
  4873. if (targetLengthSq > 0) {
  4874. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  4875. }
  4876. return target.set(0, 0, 0);
  4877. } // static/instance method to calculate barycentric coordinates
  4878. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4879. ;
  4880. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  4881. _v0$1.subVectors(c, a);
  4882. _v1$3.subVectors(b, a);
  4883. _v2$1.subVectors(point, a);
  4884. var dot00 = _v0$1.dot(_v0$1);
  4885. var dot01 = _v0$1.dot(_v1$3);
  4886. var dot02 = _v0$1.dot(_v2$1);
  4887. var dot11 = _v1$3.dot(_v1$3);
  4888. var dot12 = _v1$3.dot(_v2$1);
  4889. var denom = dot00 * dot11 - dot01 * dot01;
  4890. if (target === undefined) {
  4891. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  4892. target = new Vector3();
  4893. } // collinear or singular triangle
  4894. if (denom === 0) {
  4895. // arbitrary location outside of triangle?
  4896. // not sure if this is the best idea, maybe should be returning undefined
  4897. return target.set(-2, -1, -1);
  4898. }
  4899. var invDenom = 1 / denom;
  4900. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  4901. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  4902. return target.set(1 - u - v, v, u);
  4903. };
  4904. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  4905. this.getBarycoord(point, a, b, c, _v3);
  4906. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  4907. };
  4908. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  4909. this.getBarycoord(point, p1, p2, p3, _v3);
  4910. target.set(0, 0);
  4911. target.addScaledVector(uv1, _v3.x);
  4912. target.addScaledVector(uv2, _v3.y);
  4913. target.addScaledVector(uv3, _v3.z);
  4914. return target;
  4915. };
  4916. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  4917. _v0$1.subVectors(c, b);
  4918. _v1$3.subVectors(a, b); // strictly front facing
  4919. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  4920. };
  4921. var _proto = Triangle.prototype;
  4922. _proto.set = function set(a, b, c) {
  4923. this.a.copy(a);
  4924. this.b.copy(b);
  4925. this.c.copy(c);
  4926. return this;
  4927. };
  4928. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  4929. this.a.copy(points[i0]);
  4930. this.b.copy(points[i1]);
  4931. this.c.copy(points[i2]);
  4932. return this;
  4933. };
  4934. _proto.clone = function clone() {
  4935. return new this.constructor().copy(this);
  4936. };
  4937. _proto.copy = function copy(triangle) {
  4938. this.a.copy(triangle.a);
  4939. this.b.copy(triangle.b);
  4940. this.c.copy(triangle.c);
  4941. return this;
  4942. };
  4943. _proto.getArea = function getArea() {
  4944. _v0$1.subVectors(this.c, this.b);
  4945. _v1$3.subVectors(this.a, this.b);
  4946. return _v0$1.cross(_v1$3).length() * 0.5;
  4947. };
  4948. _proto.getMidpoint = function getMidpoint(target) {
  4949. if (target === undefined) {
  4950. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  4951. target = new Vector3();
  4952. }
  4953. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  4954. };
  4955. _proto.getNormal = function getNormal(target) {
  4956. return Triangle.getNormal(this.a, this.b, this.c, target);
  4957. };
  4958. _proto.getPlane = function getPlane(target) {
  4959. if (target === undefined) {
  4960. console.warn('THREE.Triangle: .getPlane() target is now required');
  4961. target = new Plane();
  4962. }
  4963. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  4964. };
  4965. _proto.getBarycoord = function getBarycoord(point, target) {
  4966. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  4967. };
  4968. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  4969. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  4970. };
  4971. _proto.containsPoint = function containsPoint(point) {
  4972. return Triangle.containsPoint(point, this.a, this.b, this.c);
  4973. };
  4974. _proto.isFrontFacing = function isFrontFacing(direction) {
  4975. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  4976. };
  4977. _proto.intersectsBox = function intersectsBox(box) {
  4978. return box.intersectsTriangle(this);
  4979. };
  4980. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  4981. if (target === undefined) {
  4982. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  4983. target = new Vector3();
  4984. }
  4985. var a = this.a,
  4986. b = this.b,
  4987. c = this.c;
  4988. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4989. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4990. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4991. // basically, we're distinguishing which of the voronoi regions of the triangle
  4992. // the point lies in with the minimum amount of redundant computation.
  4993. _vab.subVectors(b, a);
  4994. _vac.subVectors(c, a);
  4995. _vap.subVectors(p, a);
  4996. var d1 = _vab.dot(_vap);
  4997. var d2 = _vac.dot(_vap);
  4998. if (d1 <= 0 && d2 <= 0) {
  4999. // vertex region of A; barycentric coords (1, 0, 0)
  5000. return target.copy(a);
  5001. }
  5002. _vbp.subVectors(p, b);
  5003. var d3 = _vab.dot(_vbp);
  5004. var d4 = _vac.dot(_vbp);
  5005. if (d3 >= 0 && d4 <= d3) {
  5006. // vertex region of B; barycentric coords (0, 1, 0)
  5007. return target.copy(b);
  5008. }
  5009. var vc = d1 * d4 - d3 * d2;
  5010. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  5011. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  5012. return target.copy(a).addScaledVector(_vab, v);
  5013. }
  5014. _vcp.subVectors(p, c);
  5015. var d5 = _vab.dot(_vcp);
  5016. var d6 = _vac.dot(_vcp);
  5017. if (d6 >= 0 && d5 <= d6) {
  5018. // vertex region of C; barycentric coords (0, 0, 1)
  5019. return target.copy(c);
  5020. }
  5021. var vb = d5 * d2 - d1 * d6;
  5022. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  5023. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  5024. return target.copy(a).addScaledVector(_vac, w);
  5025. }
  5026. var va = d3 * d6 - d5 * d4;
  5027. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  5028. _vbc.subVectors(c, b);
  5029. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5030. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5031. } // face region
  5032. var denom = 1 / (va + vb + vc); // u = va * denom
  5033. v = vb * denom;
  5034. w = vc * denom;
  5035. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5036. };
  5037. _proto.equals = function equals(triangle) {
  5038. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5039. };
  5040. return Triangle;
  5041. }();
  5042. var _colorKeywords = {
  5043. 'aliceblue': 0xF0F8FF,
  5044. 'antiquewhite': 0xFAEBD7,
  5045. 'aqua': 0x00FFFF,
  5046. 'aquamarine': 0x7FFFD4,
  5047. 'azure': 0xF0FFFF,
  5048. 'beige': 0xF5F5DC,
  5049. 'bisque': 0xFFE4C4,
  5050. 'black': 0x000000,
  5051. 'blanchedalmond': 0xFFEBCD,
  5052. 'blue': 0x0000FF,
  5053. 'blueviolet': 0x8A2BE2,
  5054. 'brown': 0xA52A2A,
  5055. 'burlywood': 0xDEB887,
  5056. 'cadetblue': 0x5F9EA0,
  5057. 'chartreuse': 0x7FFF00,
  5058. 'chocolate': 0xD2691E,
  5059. 'coral': 0xFF7F50,
  5060. 'cornflowerblue': 0x6495ED,
  5061. 'cornsilk': 0xFFF8DC,
  5062. 'crimson': 0xDC143C,
  5063. 'cyan': 0x00FFFF,
  5064. 'darkblue': 0x00008B,
  5065. 'darkcyan': 0x008B8B,
  5066. 'darkgoldenrod': 0xB8860B,
  5067. 'darkgray': 0xA9A9A9,
  5068. 'darkgreen': 0x006400,
  5069. 'darkgrey': 0xA9A9A9,
  5070. 'darkkhaki': 0xBDB76B,
  5071. 'darkmagenta': 0x8B008B,
  5072. 'darkolivegreen': 0x556B2F,
  5073. 'darkorange': 0xFF8C00,
  5074. 'darkorchid': 0x9932CC,
  5075. 'darkred': 0x8B0000,
  5076. 'darksalmon': 0xE9967A,
  5077. 'darkseagreen': 0x8FBC8F,
  5078. 'darkslateblue': 0x483D8B,
  5079. 'darkslategray': 0x2F4F4F,
  5080. 'darkslategrey': 0x2F4F4F,
  5081. 'darkturquoise': 0x00CED1,
  5082. 'darkviolet': 0x9400D3,
  5083. 'deeppink': 0xFF1493,
  5084. 'deepskyblue': 0x00BFFF,
  5085. 'dimgray': 0x696969,
  5086. 'dimgrey': 0x696969,
  5087. 'dodgerblue': 0x1E90FF,
  5088. 'firebrick': 0xB22222,
  5089. 'floralwhite': 0xFFFAF0,
  5090. 'forestgreen': 0x228B22,
  5091. 'fuchsia': 0xFF00FF,
  5092. 'gainsboro': 0xDCDCDC,
  5093. 'ghostwhite': 0xF8F8FF,
  5094. 'gold': 0xFFD700,
  5095. 'goldenrod': 0xDAA520,
  5096. 'gray': 0x808080,
  5097. 'green': 0x008000,
  5098. 'greenyellow': 0xADFF2F,
  5099. 'grey': 0x808080,
  5100. 'honeydew': 0xF0FFF0,
  5101. 'hotpink': 0xFF69B4,
  5102. 'indianred': 0xCD5C5C,
  5103. 'indigo': 0x4B0082,
  5104. 'ivory': 0xFFFFF0,
  5105. 'khaki': 0xF0E68C,
  5106. 'lavender': 0xE6E6FA,
  5107. 'lavenderblush': 0xFFF0F5,
  5108. 'lawngreen': 0x7CFC00,
  5109. 'lemonchiffon': 0xFFFACD,
  5110. 'lightblue': 0xADD8E6,
  5111. 'lightcoral': 0xF08080,
  5112. 'lightcyan': 0xE0FFFF,
  5113. 'lightgoldenrodyellow': 0xFAFAD2,
  5114. 'lightgray': 0xD3D3D3,
  5115. 'lightgreen': 0x90EE90,
  5116. 'lightgrey': 0xD3D3D3,
  5117. 'lightpink': 0xFFB6C1,
  5118. 'lightsalmon': 0xFFA07A,
  5119. 'lightseagreen': 0x20B2AA,
  5120. 'lightskyblue': 0x87CEFA,
  5121. 'lightslategray': 0x778899,
  5122. 'lightslategrey': 0x778899,
  5123. 'lightsteelblue': 0xB0C4DE,
  5124. 'lightyellow': 0xFFFFE0,
  5125. 'lime': 0x00FF00,
  5126. 'limegreen': 0x32CD32,
  5127. 'linen': 0xFAF0E6,
  5128. 'magenta': 0xFF00FF,
  5129. 'maroon': 0x800000,
  5130. 'mediumaquamarine': 0x66CDAA,
  5131. 'mediumblue': 0x0000CD,
  5132. 'mediumorchid': 0xBA55D3,
  5133. 'mediumpurple': 0x9370DB,
  5134. 'mediumseagreen': 0x3CB371,
  5135. 'mediumslateblue': 0x7B68EE,
  5136. 'mediumspringgreen': 0x00FA9A,
  5137. 'mediumturquoise': 0x48D1CC,
  5138. 'mediumvioletred': 0xC71585,
  5139. 'midnightblue': 0x191970,
  5140. 'mintcream': 0xF5FFFA,
  5141. 'mistyrose': 0xFFE4E1,
  5142. 'moccasin': 0xFFE4B5,
  5143. 'navajowhite': 0xFFDEAD,
  5144. 'navy': 0x000080,
  5145. 'oldlace': 0xFDF5E6,
  5146. 'olive': 0x808000,
  5147. 'olivedrab': 0x6B8E23,
  5148. 'orange': 0xFFA500,
  5149. 'orangered': 0xFF4500,
  5150. 'orchid': 0xDA70D6,
  5151. 'palegoldenrod': 0xEEE8AA,
  5152. 'palegreen': 0x98FB98,
  5153. 'paleturquoise': 0xAFEEEE,
  5154. 'palevioletred': 0xDB7093,
  5155. 'papayawhip': 0xFFEFD5,
  5156. 'peachpuff': 0xFFDAB9,
  5157. 'peru': 0xCD853F,
  5158. 'pink': 0xFFC0CB,
  5159. 'plum': 0xDDA0DD,
  5160. 'powderblue': 0xB0E0E6,
  5161. 'purple': 0x800080,
  5162. 'rebeccapurple': 0x663399,
  5163. 'red': 0xFF0000,
  5164. 'rosybrown': 0xBC8F8F,
  5165. 'royalblue': 0x4169E1,
  5166. 'saddlebrown': 0x8B4513,
  5167. 'salmon': 0xFA8072,
  5168. 'sandybrown': 0xF4A460,
  5169. 'seagreen': 0x2E8B57,
  5170. 'seashell': 0xFFF5EE,
  5171. 'sienna': 0xA0522D,
  5172. 'silver': 0xC0C0C0,
  5173. 'skyblue': 0x87CEEB,
  5174. 'slateblue': 0x6A5ACD,
  5175. 'slategray': 0x708090,
  5176. 'slategrey': 0x708090,
  5177. 'snow': 0xFFFAFA,
  5178. 'springgreen': 0x00FF7F,
  5179. 'steelblue': 0x4682B4,
  5180. 'tan': 0xD2B48C,
  5181. 'teal': 0x008080,
  5182. 'thistle': 0xD8BFD8,
  5183. 'tomato': 0xFF6347,
  5184. 'turquoise': 0x40E0D0,
  5185. 'violet': 0xEE82EE,
  5186. 'wheat': 0xF5DEB3,
  5187. 'white': 0xFFFFFF,
  5188. 'whitesmoke': 0xF5F5F5,
  5189. 'yellow': 0xFFFF00,
  5190. 'yellowgreen': 0x9ACD32
  5191. };
  5192. var _hslA = {
  5193. h: 0,
  5194. s: 0,
  5195. l: 0
  5196. };
  5197. var _hslB = {
  5198. h: 0,
  5199. s: 0,
  5200. l: 0
  5201. };
  5202. function hue2rgb(p, q, t) {
  5203. if (t < 0) t += 1;
  5204. if (t > 1) t -= 1;
  5205. if (t < 1 / 6) return p + (q - p) * 6 * t;
  5206. if (t < 1 / 2) return q;
  5207. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  5208. return p;
  5209. }
  5210. function SRGBToLinear(c) {
  5211. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  5212. }
  5213. function LinearToSRGB(c) {
  5214. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  5215. }
  5216. var Color = /*#__PURE__*/function () {
  5217. function Color(r, g, b) {
  5218. Object.defineProperty(this, 'isColor', {
  5219. value: true
  5220. });
  5221. if (g === undefined && b === undefined) {
  5222. // r is THREE.Color, hex or string
  5223. return this.set(r);
  5224. }
  5225. return this.setRGB(r, g, b);
  5226. }
  5227. var _proto = Color.prototype;
  5228. _proto.set = function set(value) {
  5229. if (value && value.isColor) {
  5230. this.copy(value);
  5231. } else if (typeof value === 'number') {
  5232. this.setHex(value);
  5233. } else if (typeof value === 'string') {
  5234. this.setStyle(value);
  5235. }
  5236. return this;
  5237. };
  5238. _proto.setScalar = function setScalar(scalar) {
  5239. this.r = scalar;
  5240. this.g = scalar;
  5241. this.b = scalar;
  5242. return this;
  5243. };
  5244. _proto.setHex = function setHex(hex) {
  5245. hex = Math.floor(hex);
  5246. this.r = (hex >> 16 & 255) / 255;
  5247. this.g = (hex >> 8 & 255) / 255;
  5248. this.b = (hex & 255) / 255;
  5249. return this;
  5250. };
  5251. _proto.setRGB = function setRGB(r, g, b) {
  5252. this.r = r;
  5253. this.g = g;
  5254. this.b = b;
  5255. return this;
  5256. };
  5257. _proto.setHSL = function setHSL(h, s, l) {
  5258. // h,s,l ranges are in 0.0 - 1.0
  5259. h = MathUtils.euclideanModulo(h, 1);
  5260. s = MathUtils.clamp(s, 0, 1);
  5261. l = MathUtils.clamp(l, 0, 1);
  5262. if (s === 0) {
  5263. this.r = this.g = this.b = l;
  5264. } else {
  5265. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  5266. var q = 2 * l - p;
  5267. this.r = hue2rgb(q, p, h + 1 / 3);
  5268. this.g = hue2rgb(q, p, h);
  5269. this.b = hue2rgb(q, p, h - 1 / 3);
  5270. }
  5271. return this;
  5272. };
  5273. _proto.setStyle = function setStyle(style) {
  5274. function handleAlpha(string) {
  5275. if (string === undefined) return;
  5276. if (parseFloat(string) < 1) {
  5277. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  5278. }
  5279. }
  5280. var m;
  5281. if (m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(style)) {
  5282. // rgb / hsl
  5283. var color;
  5284. var name = m[1];
  5285. var components = m[2];
  5286. switch (name) {
  5287. case 'rgb':
  5288. case 'rgba':
  5289. if (color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5290. // rgb(255,0,0) rgba(255,0,0,0.5)
  5291. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  5292. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  5293. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  5294. handleAlpha(color[5]);
  5295. return this;
  5296. }
  5297. if (color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5298. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5299. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  5300. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  5301. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  5302. handleAlpha(color[5]);
  5303. return this;
  5304. }
  5305. break;
  5306. case 'hsl':
  5307. case 'hsla':
  5308. if (color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5309. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  5310. var h = parseFloat(color[1]) / 360;
  5311. var s = parseInt(color[2], 10) / 100;
  5312. var l = parseInt(color[3], 10) / 100;
  5313. handleAlpha(color[5]);
  5314. return this.setHSL(h, s, l);
  5315. }
  5316. break;
  5317. }
  5318. } else if (m = /^\#([A-Fa-f0-9]+)$/.exec(style)) {
  5319. // hex color
  5320. var hex = m[1];
  5321. var size = hex.length;
  5322. if (size === 3) {
  5323. // #ff0
  5324. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  5325. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  5326. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  5327. return this;
  5328. } else if (size === 6) {
  5329. // #ff0000
  5330. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  5331. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  5332. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  5333. return this;
  5334. }
  5335. }
  5336. if (style && style.length > 0) {
  5337. return this.setColorName(style);
  5338. }
  5339. return this;
  5340. };
  5341. _proto.setColorName = function setColorName(style) {
  5342. // color keywords
  5343. var hex = _colorKeywords[style];
  5344. if (hex !== undefined) {
  5345. // red
  5346. this.setHex(hex);
  5347. } else {
  5348. // unknown color
  5349. console.warn('THREE.Color: Unknown color ' + style);
  5350. }
  5351. return this;
  5352. };
  5353. _proto.clone = function clone() {
  5354. return new this.constructor(this.r, this.g, this.b);
  5355. };
  5356. _proto.copy = function copy(color) {
  5357. this.r = color.r;
  5358. this.g = color.g;
  5359. this.b = color.b;
  5360. return this;
  5361. };
  5362. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  5363. if (gammaFactor === void 0) {
  5364. gammaFactor = 2.0;
  5365. }
  5366. this.r = Math.pow(color.r, gammaFactor);
  5367. this.g = Math.pow(color.g, gammaFactor);
  5368. this.b = Math.pow(color.b, gammaFactor);
  5369. return this;
  5370. };
  5371. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  5372. if (gammaFactor === void 0) {
  5373. gammaFactor = 2.0;
  5374. }
  5375. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  5376. this.r = Math.pow(color.r, safeInverse);
  5377. this.g = Math.pow(color.g, safeInverse);
  5378. this.b = Math.pow(color.b, safeInverse);
  5379. return this;
  5380. };
  5381. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  5382. this.copyGammaToLinear(this, gammaFactor);
  5383. return this;
  5384. };
  5385. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  5386. this.copyLinearToGamma(this, gammaFactor);
  5387. return this;
  5388. };
  5389. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  5390. this.r = SRGBToLinear(color.r);
  5391. this.g = SRGBToLinear(color.g);
  5392. this.b = SRGBToLinear(color.b);
  5393. return this;
  5394. };
  5395. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  5396. this.r = LinearToSRGB(color.r);
  5397. this.g = LinearToSRGB(color.g);
  5398. this.b = LinearToSRGB(color.b);
  5399. return this;
  5400. };
  5401. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  5402. this.copySRGBToLinear(this);
  5403. return this;
  5404. };
  5405. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  5406. this.copyLinearToSRGB(this);
  5407. return this;
  5408. };
  5409. _proto.getHex = function getHex() {
  5410. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  5411. };
  5412. _proto.getHexString = function getHexString() {
  5413. return ('000000' + this.getHex().toString(16)).slice(-6);
  5414. };
  5415. _proto.getHSL = function getHSL(target) {
  5416. // h,s,l ranges are in 0.0 - 1.0
  5417. if (target === undefined) {
  5418. console.warn('THREE.Color: .getHSL() target is now required');
  5419. target = {
  5420. h: 0,
  5421. s: 0,
  5422. l: 0
  5423. };
  5424. }
  5425. var r = this.r,
  5426. g = this.g,
  5427. b = this.b;
  5428. var max = Math.max(r, g, b);
  5429. var min = Math.min(r, g, b);
  5430. var hue, saturation;
  5431. var lightness = (min + max) / 2.0;
  5432. if (min === max) {
  5433. hue = 0;
  5434. saturation = 0;
  5435. } else {
  5436. var delta = max - min;
  5437. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  5438. switch (max) {
  5439. case r:
  5440. hue = (g - b) / delta + (g < b ? 6 : 0);
  5441. break;
  5442. case g:
  5443. hue = (b - r) / delta + 2;
  5444. break;
  5445. case b:
  5446. hue = (r - g) / delta + 4;
  5447. break;
  5448. }
  5449. hue /= 6;
  5450. }
  5451. target.h = hue;
  5452. target.s = saturation;
  5453. target.l = lightness;
  5454. return target;
  5455. };
  5456. _proto.getStyle = function getStyle() {
  5457. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  5458. };
  5459. _proto.offsetHSL = function offsetHSL(h, s, l) {
  5460. this.getHSL(_hslA);
  5461. _hslA.h += h;
  5462. _hslA.s += s;
  5463. _hslA.l += l;
  5464. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  5465. return this;
  5466. };
  5467. _proto.add = function add(color) {
  5468. this.r += color.r;
  5469. this.g += color.g;
  5470. this.b += color.b;
  5471. return this;
  5472. };
  5473. _proto.addColors = function addColors(color1, color2) {
  5474. this.r = color1.r + color2.r;
  5475. this.g = color1.g + color2.g;
  5476. this.b = color1.b + color2.b;
  5477. return this;
  5478. };
  5479. _proto.addScalar = function addScalar(s) {
  5480. this.r += s;
  5481. this.g += s;
  5482. this.b += s;
  5483. return this;
  5484. };
  5485. _proto.sub = function sub(color) {
  5486. this.r = Math.max(0, this.r - color.r);
  5487. this.g = Math.max(0, this.g - color.g);
  5488. this.b = Math.max(0, this.b - color.b);
  5489. return this;
  5490. };
  5491. _proto.multiply = function multiply(color) {
  5492. this.r *= color.r;
  5493. this.g *= color.g;
  5494. this.b *= color.b;
  5495. return this;
  5496. };
  5497. _proto.multiplyScalar = function multiplyScalar(s) {
  5498. this.r *= s;
  5499. this.g *= s;
  5500. this.b *= s;
  5501. return this;
  5502. };
  5503. _proto.lerp = function lerp(color, alpha) {
  5504. this.r += (color.r - this.r) * alpha;
  5505. this.g += (color.g - this.g) * alpha;
  5506. this.b += (color.b - this.b) * alpha;
  5507. return this;
  5508. };
  5509. _proto.lerpHSL = function lerpHSL(color, alpha) {
  5510. this.getHSL(_hslA);
  5511. color.getHSL(_hslB);
  5512. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  5513. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  5514. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  5515. this.setHSL(h, s, l);
  5516. return this;
  5517. };
  5518. _proto.equals = function equals(c) {
  5519. return c.r === this.r && c.g === this.g && c.b === this.b;
  5520. };
  5521. _proto.fromArray = function fromArray(array, offset) {
  5522. if (offset === void 0) {
  5523. offset = 0;
  5524. }
  5525. this.r = array[offset];
  5526. this.g = array[offset + 1];
  5527. this.b = array[offset + 2];
  5528. return this;
  5529. };
  5530. _proto.toArray = function toArray(array, offset) {
  5531. if (array === void 0) {
  5532. array = [];
  5533. }
  5534. if (offset === void 0) {
  5535. offset = 0;
  5536. }
  5537. array[offset] = this.r;
  5538. array[offset + 1] = this.g;
  5539. array[offset + 2] = this.b;
  5540. return array;
  5541. };
  5542. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  5543. this.r = attribute.getX(index);
  5544. this.g = attribute.getY(index);
  5545. this.b = attribute.getZ(index);
  5546. if (attribute.normalized === true) {
  5547. // assuming Uint8Array
  5548. this.r /= 255;
  5549. this.g /= 255;
  5550. this.b /= 255;
  5551. }
  5552. return this;
  5553. };
  5554. _proto.toJSON = function toJSON() {
  5555. return this.getHex();
  5556. };
  5557. return Color;
  5558. }();
  5559. Color.NAMES = _colorKeywords;
  5560. Color.prototype.r = 1;
  5561. Color.prototype.g = 1;
  5562. Color.prototype.b = 1;
  5563. var Face3 = /*#__PURE__*/function () {
  5564. function Face3(a, b, c, normal, color, materialIndex) {
  5565. this.a = a;
  5566. this.b = b;
  5567. this.c = c;
  5568. this.normal = normal && normal.isVector3 ? normal : new Vector3();
  5569. this.vertexNormals = Array.isArray(normal) ? normal : [];
  5570. this.color = color && color.isColor ? color : new Color();
  5571. this.vertexColors = Array.isArray(color) ? color : [];
  5572. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5573. }
  5574. var _proto = Face3.prototype;
  5575. _proto.clone = function clone() {
  5576. return new this.constructor().copy(this);
  5577. };
  5578. _proto.copy = function copy(source) {
  5579. this.a = source.a;
  5580. this.b = source.b;
  5581. this.c = source.c;
  5582. this.normal.copy(source.normal);
  5583. this.color.copy(source.color);
  5584. this.materialIndex = source.materialIndex;
  5585. for (var i = 0, il = source.vertexNormals.length; i < il; i++) {
  5586. this.vertexNormals[i] = source.vertexNormals[i].clone();
  5587. }
  5588. for (var _i = 0, _il = source.vertexColors.length; _i < _il; _i++) {
  5589. this.vertexColors[_i] = source.vertexColors[_i].clone();
  5590. }
  5591. return this;
  5592. };
  5593. return Face3;
  5594. }();
  5595. var materialId = 0;
  5596. function Material() {
  5597. Object.defineProperty(this, 'id', {
  5598. value: materialId++
  5599. });
  5600. this.uuid = MathUtils.generateUUID();
  5601. this.name = '';
  5602. this.type = 'Material';
  5603. this.fog = true;
  5604. this.blending = NormalBlending;
  5605. this.side = FrontSide;
  5606. this.flatShading = false;
  5607. this.vertexColors = false;
  5608. this.opacity = 1;
  5609. this.transparent = false;
  5610. this.blendSrc = SrcAlphaFactor;
  5611. this.blendDst = OneMinusSrcAlphaFactor;
  5612. this.blendEquation = AddEquation;
  5613. this.blendSrcAlpha = null;
  5614. this.blendDstAlpha = null;
  5615. this.blendEquationAlpha = null;
  5616. this.depthFunc = LessEqualDepth;
  5617. this.depthTest = true;
  5618. this.depthWrite = true;
  5619. this.stencilWriteMask = 0xff;
  5620. this.stencilFunc = AlwaysStencilFunc;
  5621. this.stencilRef = 0;
  5622. this.stencilFuncMask = 0xff;
  5623. this.stencilFail = KeepStencilOp;
  5624. this.stencilZFail = KeepStencilOp;
  5625. this.stencilZPass = KeepStencilOp;
  5626. this.stencilWrite = false;
  5627. this.clippingPlanes = null;
  5628. this.clipIntersection = false;
  5629. this.clipShadows = false;
  5630. this.shadowSide = null;
  5631. this.colorWrite = true;
  5632. this.precision = null; // override the renderer's default precision for this material
  5633. this.polygonOffset = false;
  5634. this.polygonOffsetFactor = 0;
  5635. this.polygonOffsetUnits = 0;
  5636. this.dithering = false;
  5637. this.alphaTest = 0;
  5638. this.premultipliedAlpha = false;
  5639. this.visible = true;
  5640. this.toneMapped = true;
  5641. this.userData = {};
  5642. this.version = 0;
  5643. }
  5644. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5645. constructor: Material,
  5646. isMaterial: true,
  5647. onBeforeCompile: function onBeforeCompile()
  5648. /* shaderobject, renderer */
  5649. {},
  5650. customProgramCacheKey: function customProgramCacheKey() {
  5651. return this.onBeforeCompile.toString();
  5652. },
  5653. setValues: function setValues(values) {
  5654. if (values === undefined) return;
  5655. for (var key in values) {
  5656. var newValue = values[key];
  5657. if (newValue === undefined) {
  5658. console.warn("THREE.Material: '" + key + "' parameter is undefined.");
  5659. continue;
  5660. } // for backward compatability if shading is set in the constructor
  5661. if (key === 'shading') {
  5662. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  5663. this.flatShading = newValue === FlatShading ? true : false;
  5664. continue;
  5665. }
  5666. var currentValue = this[key];
  5667. if (currentValue === undefined) {
  5668. console.warn("THREE." + this.type + ": '" + key + "' is not a property of this material.");
  5669. continue;
  5670. }
  5671. if (currentValue && currentValue.isColor) {
  5672. currentValue.set(newValue);
  5673. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  5674. currentValue.copy(newValue);
  5675. } else {
  5676. this[key] = newValue;
  5677. }
  5678. }
  5679. },
  5680. toJSON: function toJSON(meta) {
  5681. var isRoot = meta === undefined || typeof meta === 'string';
  5682. if (isRoot) {
  5683. meta = {
  5684. textures: {},
  5685. images: {}
  5686. };
  5687. }
  5688. var data = {
  5689. metadata: {
  5690. version: 4.5,
  5691. type: 'Material',
  5692. generator: 'Material.toJSON'
  5693. }
  5694. }; // standard Material serialization
  5695. data.uuid = this.uuid;
  5696. data.type = this.type;
  5697. if (this.name !== '') data.name = this.name;
  5698. if (this.color && this.color.isColor) data.color = this.color.getHex();
  5699. if (this.roughness !== undefined) data.roughness = this.roughness;
  5700. if (this.metalness !== undefined) data.metalness = this.metalness;
  5701. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  5702. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  5703. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  5704. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  5705. if (this.shininess !== undefined) data.shininess = this.shininess;
  5706. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  5707. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  5708. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  5709. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  5710. }
  5711. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  5712. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  5713. }
  5714. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  5715. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  5716. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5717. }
  5718. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  5719. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  5720. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  5721. if (this.lightMap && this.lightMap.isTexture) data.lightMap = this.lightMap.toJSON(meta).uuid;
  5722. if (this.aoMap && this.aoMap.isTexture) {
  5723. data.aoMap = this.aoMap.toJSON(meta).uuid;
  5724. data.aoMapIntensity = this.aoMapIntensity;
  5725. }
  5726. if (this.bumpMap && this.bumpMap.isTexture) {
  5727. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  5728. data.bumpScale = this.bumpScale;
  5729. }
  5730. if (this.normalMap && this.normalMap.isTexture) {
  5731. data.normalMap = this.normalMap.toJSON(meta).uuid;
  5732. data.normalMapType = this.normalMapType;
  5733. data.normalScale = this.normalScale.toArray();
  5734. }
  5735. if (this.displacementMap && this.displacementMap.isTexture) {
  5736. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  5737. data.displacementScale = this.displacementScale;
  5738. data.displacementBias = this.displacementBias;
  5739. }
  5740. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  5741. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  5742. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  5743. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  5744. if (this.envMap && this.envMap.isTexture) {
  5745. data.envMap = this.envMap.toJSON(meta).uuid;
  5746. data.reflectivity = this.reflectivity; // Scale behind envMap
  5747. data.refractionRatio = this.refractionRatio;
  5748. if (this.combine !== undefined) data.combine = this.combine;
  5749. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  5750. }
  5751. if (this.gradientMap && this.gradientMap.isTexture) {
  5752. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  5753. }
  5754. if (this.size !== undefined) data.size = this.size;
  5755. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  5756. if (this.blending !== NormalBlending) data.blending = this.blending;
  5757. if (this.flatShading === true) data.flatShading = this.flatShading;
  5758. if (this.side !== FrontSide) data.side = this.side;
  5759. if (this.vertexColors) data.vertexColors = true;
  5760. if (this.opacity < 1) data.opacity = this.opacity;
  5761. if (this.transparent === true) data.transparent = this.transparent;
  5762. data.depthFunc = this.depthFunc;
  5763. data.depthTest = this.depthTest;
  5764. data.depthWrite = this.depthWrite;
  5765. data.stencilWrite = this.stencilWrite;
  5766. data.stencilWriteMask = this.stencilWriteMask;
  5767. data.stencilFunc = this.stencilFunc;
  5768. data.stencilRef = this.stencilRef;
  5769. data.stencilFuncMask = this.stencilFuncMask;
  5770. data.stencilFail = this.stencilFail;
  5771. data.stencilZFail = this.stencilZFail;
  5772. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  5773. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  5774. if (this.polygonOffset === true) data.polygonOffset = true;
  5775. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5776. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5777. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  5778. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  5779. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  5780. if (this.scale !== undefined) data.scale = this.scale;
  5781. if (this.dithering === true) data.dithering = true;
  5782. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  5783. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  5784. if (this.wireframe === true) data.wireframe = this.wireframe;
  5785. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  5786. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  5787. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  5788. if (this.morphTargets === true) data.morphTargets = true;
  5789. if (this.morphNormals === true) data.morphNormals = true;
  5790. if (this.skinning === true) data.skinning = true;
  5791. if (this.visible === false) data.visible = false;
  5792. if (this.toneMapped === false) data.toneMapped = false;
  5793. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  5794. function extractFromCache(cache) {
  5795. var values = [];
  5796. for (var key in cache) {
  5797. var _data = cache[key];
  5798. delete _data.metadata;
  5799. values.push(_data);
  5800. }
  5801. return values;
  5802. }
  5803. if (isRoot) {
  5804. var textures = extractFromCache(meta.textures);
  5805. var images = extractFromCache(meta.images);
  5806. if (textures.length > 0) data.textures = textures;
  5807. if (images.length > 0) data.images = images;
  5808. }
  5809. return data;
  5810. },
  5811. clone: function clone() {
  5812. return new this.constructor().copy(this);
  5813. },
  5814. copy: function copy(source) {
  5815. this.name = source.name;
  5816. this.fog = source.fog;
  5817. this.blending = source.blending;
  5818. this.side = source.side;
  5819. this.flatShading = source.flatShading;
  5820. this.vertexColors = source.vertexColors;
  5821. this.opacity = source.opacity;
  5822. this.transparent = source.transparent;
  5823. this.blendSrc = source.blendSrc;
  5824. this.blendDst = source.blendDst;
  5825. this.blendEquation = source.blendEquation;
  5826. this.blendSrcAlpha = source.blendSrcAlpha;
  5827. this.blendDstAlpha = source.blendDstAlpha;
  5828. this.blendEquationAlpha = source.blendEquationAlpha;
  5829. this.depthFunc = source.depthFunc;
  5830. this.depthTest = source.depthTest;
  5831. this.depthWrite = source.depthWrite;
  5832. this.stencilWriteMask = source.stencilWriteMask;
  5833. this.stencilFunc = source.stencilFunc;
  5834. this.stencilRef = source.stencilRef;
  5835. this.stencilFuncMask = source.stencilFuncMask;
  5836. this.stencilFail = source.stencilFail;
  5837. this.stencilZFail = source.stencilZFail;
  5838. this.stencilZPass = source.stencilZPass;
  5839. this.stencilWrite = source.stencilWrite;
  5840. var srcPlanes = source.clippingPlanes;
  5841. var dstPlanes = null;
  5842. if (srcPlanes !== null) {
  5843. var n = srcPlanes.length;
  5844. dstPlanes = new Array(n);
  5845. for (var i = 0; i !== n; ++i) {
  5846. dstPlanes[i] = srcPlanes[i].clone();
  5847. }
  5848. }
  5849. this.clippingPlanes = dstPlanes;
  5850. this.clipIntersection = source.clipIntersection;
  5851. this.clipShadows = source.clipShadows;
  5852. this.shadowSide = source.shadowSide;
  5853. this.colorWrite = source.colorWrite;
  5854. this.precision = source.precision;
  5855. this.polygonOffset = source.polygonOffset;
  5856. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5857. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5858. this.dithering = source.dithering;
  5859. this.alphaTest = source.alphaTest;
  5860. this.premultipliedAlpha = source.premultipliedAlpha;
  5861. this.visible = source.visible;
  5862. this.toneMapped = source.toneMapped;
  5863. this.userData = JSON.parse(JSON.stringify(source.userData));
  5864. return this;
  5865. },
  5866. dispose: function dispose() {
  5867. this.dispatchEvent({
  5868. type: 'dispose'
  5869. });
  5870. }
  5871. });
  5872. Object.defineProperty(Material.prototype, 'needsUpdate', {
  5873. set: function set(value) {
  5874. if (value === true) this.version++;
  5875. }
  5876. });
  5877. /**
  5878. * parameters = {
  5879. * color: <hex>,
  5880. * opacity: <float>,
  5881. * map: new THREE.Texture( <Image> ),
  5882. *
  5883. * lightMap: new THREE.Texture( <Image> ),
  5884. * lightMapIntensity: <float>
  5885. *
  5886. * aoMap: new THREE.Texture( <Image> ),
  5887. * aoMapIntensity: <float>
  5888. *
  5889. * specularMap: new THREE.Texture( <Image> ),
  5890. *
  5891. * alphaMap: new THREE.Texture( <Image> ),
  5892. *
  5893. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5894. * combine: THREE.Multiply,
  5895. * reflectivity: <float>,
  5896. * refractionRatio: <float>,
  5897. *
  5898. * depthTest: <bool>,
  5899. * depthWrite: <bool>,
  5900. *
  5901. * wireframe: <boolean>,
  5902. * wireframeLinewidth: <float>,
  5903. *
  5904. * skinning: <bool>,
  5905. * morphTargets: <bool>
  5906. * }
  5907. */
  5908. function MeshBasicMaterial(parameters) {
  5909. Material.call(this);
  5910. this.type = 'MeshBasicMaterial';
  5911. this.color = new Color(0xffffff); // emissive
  5912. this.map = null;
  5913. this.lightMap = null;
  5914. this.lightMapIntensity = 1.0;
  5915. this.aoMap = null;
  5916. this.aoMapIntensity = 1.0;
  5917. this.specularMap = null;
  5918. this.alphaMap = null;
  5919. this.envMap = null;
  5920. this.combine = MultiplyOperation;
  5921. this.reflectivity = 1;
  5922. this.refractionRatio = 0.98;
  5923. this.wireframe = false;
  5924. this.wireframeLinewidth = 1;
  5925. this.wireframeLinecap = 'round';
  5926. this.wireframeLinejoin = 'round';
  5927. this.skinning = false;
  5928. this.morphTargets = false;
  5929. this.setValues(parameters);
  5930. }
  5931. MeshBasicMaterial.prototype = Object.create(Material.prototype);
  5932. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5933. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5934. MeshBasicMaterial.prototype.copy = function (source) {
  5935. Material.prototype.copy.call(this, source);
  5936. this.color.copy(source.color);
  5937. this.map = source.map;
  5938. this.lightMap = source.lightMap;
  5939. this.lightMapIntensity = source.lightMapIntensity;
  5940. this.aoMap = source.aoMap;
  5941. this.aoMapIntensity = source.aoMapIntensity;
  5942. this.specularMap = source.specularMap;
  5943. this.alphaMap = source.alphaMap;
  5944. this.envMap = source.envMap;
  5945. this.combine = source.combine;
  5946. this.reflectivity = source.reflectivity;
  5947. this.refractionRatio = source.refractionRatio;
  5948. this.wireframe = source.wireframe;
  5949. this.wireframeLinewidth = source.wireframeLinewidth;
  5950. this.wireframeLinecap = source.wireframeLinecap;
  5951. this.wireframeLinejoin = source.wireframeLinejoin;
  5952. this.skinning = source.skinning;
  5953. this.morphTargets = source.morphTargets;
  5954. return this;
  5955. };
  5956. var _vector$3 = new Vector3();
  5957. var _vector2$1 = new Vector2();
  5958. function BufferAttribute(array, itemSize, normalized) {
  5959. if (Array.isArray(array)) {
  5960. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  5961. }
  5962. this.name = '';
  5963. this.array = array;
  5964. this.itemSize = itemSize;
  5965. this.count = array !== undefined ? array.length / itemSize : 0;
  5966. this.normalized = normalized === true;
  5967. this.usage = StaticDrawUsage;
  5968. this.updateRange = {
  5969. offset: 0,
  5970. count: -1
  5971. };
  5972. this.version = 0;
  5973. }
  5974. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  5975. set: function set(value) {
  5976. if (value === true) this.version++;
  5977. }
  5978. });
  5979. Object.assign(BufferAttribute.prototype, {
  5980. isBufferAttribute: true,
  5981. onUploadCallback: function onUploadCallback() {},
  5982. setUsage: function setUsage(value) {
  5983. this.usage = value;
  5984. return this;
  5985. },
  5986. copy: function copy(source) {
  5987. this.name = source.name;
  5988. this.array = new source.array.constructor(source.array);
  5989. this.itemSize = source.itemSize;
  5990. this.count = source.count;
  5991. this.normalized = source.normalized;
  5992. this.usage = source.usage;
  5993. return this;
  5994. },
  5995. copyAt: function copyAt(index1, attribute, index2) {
  5996. index1 *= this.itemSize;
  5997. index2 *= attribute.itemSize;
  5998. for (var i = 0, l = this.itemSize; i < l; i++) {
  5999. this.array[index1 + i] = attribute.array[index2 + i];
  6000. }
  6001. return this;
  6002. },
  6003. copyArray: function copyArray(array) {
  6004. this.array.set(array);
  6005. return this;
  6006. },
  6007. copyColorsArray: function copyColorsArray(colors) {
  6008. var array = this.array;
  6009. var offset = 0;
  6010. for (var i = 0, l = colors.length; i < l; i++) {
  6011. var color = colors[i];
  6012. if (color === undefined) {
  6013. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  6014. color = new Color();
  6015. }
  6016. array[offset++] = color.r;
  6017. array[offset++] = color.g;
  6018. array[offset++] = color.b;
  6019. }
  6020. return this;
  6021. },
  6022. copyVector2sArray: function copyVector2sArray(vectors) {
  6023. var array = this.array;
  6024. var offset = 0;
  6025. for (var i = 0, l = vectors.length; i < l; i++) {
  6026. var vector = vectors[i];
  6027. if (vector === undefined) {
  6028. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  6029. vector = new Vector2();
  6030. }
  6031. array[offset++] = vector.x;
  6032. array[offset++] = vector.y;
  6033. }
  6034. return this;
  6035. },
  6036. copyVector3sArray: function copyVector3sArray(vectors) {
  6037. var array = this.array;
  6038. var offset = 0;
  6039. for (var i = 0, l = vectors.length; i < l; i++) {
  6040. var vector = vectors[i];
  6041. if (vector === undefined) {
  6042. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  6043. vector = new Vector3();
  6044. }
  6045. array[offset++] = vector.x;
  6046. array[offset++] = vector.y;
  6047. array[offset++] = vector.z;
  6048. }
  6049. return this;
  6050. },
  6051. copyVector4sArray: function copyVector4sArray(vectors) {
  6052. var array = this.array;
  6053. var offset = 0;
  6054. for (var i = 0, l = vectors.length; i < l; i++) {
  6055. var vector = vectors[i];
  6056. if (vector === undefined) {
  6057. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  6058. vector = new Vector4();
  6059. }
  6060. array[offset++] = vector.x;
  6061. array[offset++] = vector.y;
  6062. array[offset++] = vector.z;
  6063. array[offset++] = vector.w;
  6064. }
  6065. return this;
  6066. },
  6067. applyMatrix3: function applyMatrix3(m) {
  6068. if (this.itemSize === 2) {
  6069. for (var i = 0, l = this.count; i < l; i++) {
  6070. _vector2$1.fromBufferAttribute(this, i);
  6071. _vector2$1.applyMatrix3(m);
  6072. this.setXY(i, _vector2$1.x, _vector2$1.y);
  6073. }
  6074. } else if (this.itemSize === 3) {
  6075. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  6076. _vector$3.fromBufferAttribute(this, _i);
  6077. _vector$3.applyMatrix3(m);
  6078. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  6079. }
  6080. }
  6081. return this;
  6082. },
  6083. applyMatrix4: function applyMatrix4(m) {
  6084. for (var i = 0, l = this.count; i < l; i++) {
  6085. _vector$3.x = this.getX(i);
  6086. _vector$3.y = this.getY(i);
  6087. _vector$3.z = this.getZ(i);
  6088. _vector$3.applyMatrix4(m);
  6089. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6090. }
  6091. return this;
  6092. },
  6093. applyNormalMatrix: function applyNormalMatrix(m) {
  6094. for (var i = 0, l = this.count; i < l; i++) {
  6095. _vector$3.x = this.getX(i);
  6096. _vector$3.y = this.getY(i);
  6097. _vector$3.z = this.getZ(i);
  6098. _vector$3.applyNormalMatrix(m);
  6099. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6100. }
  6101. return this;
  6102. },
  6103. transformDirection: function transformDirection(m) {
  6104. for (var i = 0, l = this.count; i < l; i++) {
  6105. _vector$3.x = this.getX(i);
  6106. _vector$3.y = this.getY(i);
  6107. _vector$3.z = this.getZ(i);
  6108. _vector$3.transformDirection(m);
  6109. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6110. }
  6111. return this;
  6112. },
  6113. set: function set(value, offset) {
  6114. if (offset === void 0) {
  6115. offset = 0;
  6116. }
  6117. this.array.set(value, offset);
  6118. return this;
  6119. },
  6120. getX: function getX(index) {
  6121. return this.array[index * this.itemSize];
  6122. },
  6123. setX: function setX(index, x) {
  6124. this.array[index * this.itemSize] = x;
  6125. return this;
  6126. },
  6127. getY: function getY(index) {
  6128. return this.array[index * this.itemSize + 1];
  6129. },
  6130. setY: function setY(index, y) {
  6131. this.array[index * this.itemSize + 1] = y;
  6132. return this;
  6133. },
  6134. getZ: function getZ(index) {
  6135. return this.array[index * this.itemSize + 2];
  6136. },
  6137. setZ: function setZ(index, z) {
  6138. this.array[index * this.itemSize + 2] = z;
  6139. return this;
  6140. },
  6141. getW: function getW(index) {
  6142. return this.array[index * this.itemSize + 3];
  6143. },
  6144. setW: function setW(index, w) {
  6145. this.array[index * this.itemSize + 3] = w;
  6146. return this;
  6147. },
  6148. setXY: function setXY(index, x, y) {
  6149. index *= this.itemSize;
  6150. this.array[index + 0] = x;
  6151. this.array[index + 1] = y;
  6152. return this;
  6153. },
  6154. setXYZ: function setXYZ(index, x, y, z) {
  6155. index *= this.itemSize;
  6156. this.array[index + 0] = x;
  6157. this.array[index + 1] = y;
  6158. this.array[index + 2] = z;
  6159. return this;
  6160. },
  6161. setXYZW: function setXYZW(index, x, y, z, w) {
  6162. index *= this.itemSize;
  6163. this.array[index + 0] = x;
  6164. this.array[index + 1] = y;
  6165. this.array[index + 2] = z;
  6166. this.array[index + 3] = w;
  6167. return this;
  6168. },
  6169. onUpload: function onUpload(callback) {
  6170. this.onUploadCallback = callback;
  6171. return this;
  6172. },
  6173. clone: function clone() {
  6174. return new this.constructor(this.array, this.itemSize).copy(this);
  6175. },
  6176. toJSON: function toJSON() {
  6177. return {
  6178. itemSize: this.itemSize,
  6179. type: this.array.constructor.name,
  6180. array: Array.prototype.slice.call(this.array),
  6181. normalized: this.normalized
  6182. };
  6183. }
  6184. }); //
  6185. function Int8BufferAttribute(array, itemSize, normalized) {
  6186. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6187. }
  6188. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6189. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6190. function Uint8BufferAttribute(array, itemSize, normalized) {
  6191. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6192. }
  6193. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6194. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6195. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6196. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6197. }
  6198. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6199. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6200. function Int16BufferAttribute(array, itemSize, normalized) {
  6201. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6202. }
  6203. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6204. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6205. function Uint16BufferAttribute(array, itemSize, normalized) {
  6206. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6207. }
  6208. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6209. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6210. function Int32BufferAttribute(array, itemSize, normalized) {
  6211. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6212. }
  6213. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6214. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6215. function Uint32BufferAttribute(array, itemSize, normalized) {
  6216. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6217. }
  6218. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6219. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6220. function Float16BufferAttribute(array, itemSize, normalized) {
  6221. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6222. }
  6223. Float16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6224. Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
  6225. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  6226. function Float32BufferAttribute(array, itemSize, normalized) {
  6227. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6228. }
  6229. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6230. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6231. function Float64BufferAttribute(array, itemSize, normalized) {
  6232. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6233. }
  6234. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6235. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  6236. var DirectGeometry = /*#__PURE__*/function () {
  6237. function DirectGeometry() {
  6238. this.vertices = [];
  6239. this.normals = [];
  6240. this.colors = [];
  6241. this.uvs = [];
  6242. this.uvs2 = [];
  6243. this.groups = [];
  6244. this.morphTargets = {};
  6245. this.skinWeights = [];
  6246. this.skinIndices = []; // this.lineDistances = [];
  6247. this.boundingBox = null;
  6248. this.boundingSphere = null; // update flags
  6249. this.verticesNeedUpdate = false;
  6250. this.normalsNeedUpdate = false;
  6251. this.colorsNeedUpdate = false;
  6252. this.uvsNeedUpdate = false;
  6253. this.groupsNeedUpdate = false;
  6254. }
  6255. var _proto = DirectGeometry.prototype;
  6256. _proto.computeGroups = function computeGroups(geometry) {
  6257. var groups = [];
  6258. var group, i;
  6259. var materialIndex = undefined;
  6260. var faces = geometry.faces;
  6261. for (i = 0; i < faces.length; i++) {
  6262. var face = faces[i]; // materials
  6263. if (face.materialIndex !== materialIndex) {
  6264. materialIndex = face.materialIndex;
  6265. if (group !== undefined) {
  6266. group.count = i * 3 - group.start;
  6267. groups.push(group);
  6268. }
  6269. group = {
  6270. start: i * 3,
  6271. materialIndex: materialIndex
  6272. };
  6273. }
  6274. }
  6275. if (group !== undefined) {
  6276. group.count = i * 3 - group.start;
  6277. groups.push(group);
  6278. }
  6279. this.groups = groups;
  6280. };
  6281. _proto.fromGeometry = function fromGeometry(geometry) {
  6282. var faces = geometry.faces;
  6283. var vertices = geometry.vertices;
  6284. var faceVertexUvs = geometry.faceVertexUvs;
  6285. var hasFaceVertexUv = faceVertexUvs[0] && faceVertexUvs[0].length > 0;
  6286. var hasFaceVertexUv2 = faceVertexUvs[1] && faceVertexUvs[1].length > 0; // morphs
  6287. var morphTargets = geometry.morphTargets;
  6288. var morphTargetsLength = morphTargets.length;
  6289. var morphTargetsPosition;
  6290. if (morphTargetsLength > 0) {
  6291. morphTargetsPosition = [];
  6292. for (var i = 0; i < morphTargetsLength; i++) {
  6293. morphTargetsPosition[i] = {
  6294. name: morphTargets[i].name,
  6295. data: []
  6296. };
  6297. }
  6298. this.morphTargets.position = morphTargetsPosition;
  6299. }
  6300. var morphNormals = geometry.morphNormals;
  6301. var morphNormalsLength = morphNormals.length;
  6302. var morphTargetsNormal;
  6303. if (morphNormalsLength > 0) {
  6304. morphTargetsNormal = [];
  6305. for (var _i = 0; _i < morphNormalsLength; _i++) {
  6306. morphTargetsNormal[_i] = {
  6307. name: morphNormals[_i].name,
  6308. data: []
  6309. };
  6310. }
  6311. this.morphTargets.normal = morphTargetsNormal;
  6312. } // skins
  6313. var skinIndices = geometry.skinIndices;
  6314. var skinWeights = geometry.skinWeights;
  6315. var hasSkinIndices = skinIndices.length === vertices.length;
  6316. var hasSkinWeights = skinWeights.length === vertices.length; //
  6317. if (vertices.length > 0 && faces.length === 0) {
  6318. console.error('THREE.DirectGeometry: Faceless geometries are not supported.');
  6319. }
  6320. for (var _i2 = 0; _i2 < faces.length; _i2++) {
  6321. var face = faces[_i2];
  6322. this.vertices.push(vertices[face.a], vertices[face.b], vertices[face.c]);
  6323. var vertexNormals = face.vertexNormals;
  6324. if (vertexNormals.length === 3) {
  6325. this.normals.push(vertexNormals[0], vertexNormals[1], vertexNormals[2]);
  6326. } else {
  6327. var normal = face.normal;
  6328. this.normals.push(normal, normal, normal);
  6329. }
  6330. var vertexColors = face.vertexColors;
  6331. if (vertexColors.length === 3) {
  6332. this.colors.push(vertexColors[0], vertexColors[1], vertexColors[2]);
  6333. } else {
  6334. var color = face.color;
  6335. this.colors.push(color, color, color);
  6336. }
  6337. if (hasFaceVertexUv === true) {
  6338. var vertexUvs = faceVertexUvs[0][_i2];
  6339. if (vertexUvs !== undefined) {
  6340. this.uvs.push(vertexUvs[0], vertexUvs[1], vertexUvs[2]);
  6341. } else {
  6342. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', _i2);
  6343. this.uvs.push(new Vector2(), new Vector2(), new Vector2());
  6344. }
  6345. }
  6346. if (hasFaceVertexUv2 === true) {
  6347. var _vertexUvs = faceVertexUvs[1][_i2];
  6348. if (_vertexUvs !== undefined) {
  6349. this.uvs2.push(_vertexUvs[0], _vertexUvs[1], _vertexUvs[2]);
  6350. } else {
  6351. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', _i2);
  6352. this.uvs2.push(new Vector2(), new Vector2(), new Vector2());
  6353. }
  6354. } // morphs
  6355. for (var j = 0; j < morphTargetsLength; j++) {
  6356. var morphTarget = morphTargets[j].vertices;
  6357. morphTargetsPosition[j].data.push(morphTarget[face.a], morphTarget[face.b], morphTarget[face.c]);
  6358. }
  6359. for (var _j = 0; _j < morphNormalsLength; _j++) {
  6360. var morphNormal = morphNormals[_j].vertexNormals[_i2];
  6361. morphTargetsNormal[_j].data.push(morphNormal.a, morphNormal.b, morphNormal.c);
  6362. } // skins
  6363. if (hasSkinIndices) {
  6364. this.skinIndices.push(skinIndices[face.a], skinIndices[face.b], skinIndices[face.c]);
  6365. }
  6366. if (hasSkinWeights) {
  6367. this.skinWeights.push(skinWeights[face.a], skinWeights[face.b], skinWeights[face.c]);
  6368. }
  6369. }
  6370. this.computeGroups(geometry);
  6371. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6372. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6373. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6374. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6375. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6376. if (geometry.boundingSphere !== null) {
  6377. this.boundingSphere = geometry.boundingSphere.clone();
  6378. }
  6379. if (geometry.boundingBox !== null) {
  6380. this.boundingBox = geometry.boundingBox.clone();
  6381. }
  6382. return this;
  6383. };
  6384. return DirectGeometry;
  6385. }();
  6386. function arrayMax(array) {
  6387. if (array.length === 0) return -Infinity;
  6388. var max = array[0];
  6389. for (var i = 1, l = array.length; i < l; ++i) {
  6390. if (array[i] > max) max = array[i];
  6391. }
  6392. return max;
  6393. }
  6394. var TYPED_ARRAYS = {
  6395. Int8Array: Int8Array,
  6396. Uint8Array: Uint8Array,
  6397. // Workaround for IE11 pre KB2929437. See #11440
  6398. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  6399. Int16Array: Int16Array,
  6400. Uint16Array: Uint16Array,
  6401. Int32Array: Int32Array,
  6402. Uint32Array: Uint32Array,
  6403. Float32Array: Float32Array,
  6404. Float64Array: Float64Array
  6405. };
  6406. function getTypedArray(type, buffer) {
  6407. return new TYPED_ARRAYS[type](buffer);
  6408. }
  6409. var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6410. var _m1$2 = new Matrix4();
  6411. var _obj = new Object3D();
  6412. var _offset = new Vector3();
  6413. var _box$2 = new Box3();
  6414. var _boxMorphTargets = new Box3();
  6415. var _vector$4 = new Vector3();
  6416. function BufferGeometry() {
  6417. Object.defineProperty(this, 'id', {
  6418. value: _bufferGeometryId += 2
  6419. });
  6420. this.uuid = MathUtils.generateUUID();
  6421. this.name = '';
  6422. this.type = 'BufferGeometry';
  6423. this.index = null;
  6424. this.attributes = {};
  6425. this.morphAttributes = {};
  6426. this.morphTargetsRelative = false;
  6427. this.groups = [];
  6428. this.boundingBox = null;
  6429. this.boundingSphere = null;
  6430. this.drawRange = {
  6431. start: 0,
  6432. count: Infinity
  6433. };
  6434. this.userData = {};
  6435. }
  6436. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  6437. constructor: BufferGeometry,
  6438. isBufferGeometry: true,
  6439. getIndex: function getIndex() {
  6440. return this.index;
  6441. },
  6442. setIndex: function setIndex(index) {
  6443. if (Array.isArray(index)) {
  6444. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  6445. } else {
  6446. this.index = index;
  6447. }
  6448. return this;
  6449. },
  6450. getAttribute: function getAttribute(name) {
  6451. return this.attributes[name];
  6452. },
  6453. setAttribute: function setAttribute(name, attribute) {
  6454. this.attributes[name] = attribute;
  6455. return this;
  6456. },
  6457. deleteAttribute: function deleteAttribute(name) {
  6458. delete this.attributes[name];
  6459. return this;
  6460. },
  6461. hasAttribute: function hasAttribute(name) {
  6462. return this.attributes[name] !== undefined;
  6463. },
  6464. addGroup: function addGroup(start, count, materialIndex) {
  6465. this.groups.push({
  6466. start: start,
  6467. count: count,
  6468. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6469. });
  6470. },
  6471. clearGroups: function clearGroups() {
  6472. this.groups = [];
  6473. },
  6474. setDrawRange: function setDrawRange(start, count) {
  6475. this.drawRange.start = start;
  6476. this.drawRange.count = count;
  6477. },
  6478. applyMatrix4: function applyMatrix4(matrix) {
  6479. var position = this.attributes.position;
  6480. if (position !== undefined) {
  6481. position.applyMatrix4(matrix);
  6482. position.needsUpdate = true;
  6483. }
  6484. var normal = this.attributes.normal;
  6485. if (normal !== undefined) {
  6486. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  6487. normal.applyNormalMatrix(normalMatrix);
  6488. normal.needsUpdate = true;
  6489. }
  6490. var tangent = this.attributes.tangent;
  6491. if (tangent !== undefined) {
  6492. tangent.transformDirection(matrix);
  6493. tangent.needsUpdate = true;
  6494. }
  6495. if (this.boundingBox !== null) {
  6496. this.computeBoundingBox();
  6497. }
  6498. if (this.boundingSphere !== null) {
  6499. this.computeBoundingSphere();
  6500. }
  6501. return this;
  6502. },
  6503. rotateX: function rotateX(angle) {
  6504. // rotate geometry around world x-axis
  6505. _m1$2.makeRotationX(angle);
  6506. this.applyMatrix4(_m1$2);
  6507. return this;
  6508. },
  6509. rotateY: function rotateY(angle) {
  6510. // rotate geometry around world y-axis
  6511. _m1$2.makeRotationY(angle);
  6512. this.applyMatrix4(_m1$2);
  6513. return this;
  6514. },
  6515. rotateZ: function rotateZ(angle) {
  6516. // rotate geometry around world z-axis
  6517. _m1$2.makeRotationZ(angle);
  6518. this.applyMatrix4(_m1$2);
  6519. return this;
  6520. },
  6521. translate: function translate(x, y, z) {
  6522. // translate geometry
  6523. _m1$2.makeTranslation(x, y, z);
  6524. this.applyMatrix4(_m1$2);
  6525. return this;
  6526. },
  6527. scale: function scale(x, y, z) {
  6528. // scale geometry
  6529. _m1$2.makeScale(x, y, z);
  6530. this.applyMatrix4(_m1$2);
  6531. return this;
  6532. },
  6533. lookAt: function lookAt(vector) {
  6534. _obj.lookAt(vector);
  6535. _obj.updateMatrix();
  6536. this.applyMatrix4(_obj.matrix);
  6537. return this;
  6538. },
  6539. center: function center() {
  6540. this.computeBoundingBox();
  6541. this.boundingBox.getCenter(_offset).negate();
  6542. this.translate(_offset.x, _offset.y, _offset.z);
  6543. return this;
  6544. },
  6545. setFromObject: function setFromObject(object) {
  6546. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6547. var geometry = object.geometry;
  6548. if (object.isPoints || object.isLine) {
  6549. var positions = new Float32BufferAttribute(geometry.vertices.length * 3, 3);
  6550. var colors = new Float32BufferAttribute(geometry.colors.length * 3, 3);
  6551. this.setAttribute('position', positions.copyVector3sArray(geometry.vertices));
  6552. this.setAttribute('color', colors.copyColorsArray(geometry.colors));
  6553. if (geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length) {
  6554. var lineDistances = new Float32BufferAttribute(geometry.lineDistances.length, 1);
  6555. this.setAttribute('lineDistance', lineDistances.copyArray(geometry.lineDistances));
  6556. }
  6557. if (geometry.boundingSphere !== null) {
  6558. this.boundingSphere = geometry.boundingSphere.clone();
  6559. }
  6560. if (geometry.boundingBox !== null) {
  6561. this.boundingBox = geometry.boundingBox.clone();
  6562. }
  6563. } else if (object.isMesh) {
  6564. if (geometry && geometry.isGeometry) {
  6565. this.fromGeometry(geometry);
  6566. }
  6567. }
  6568. return this;
  6569. },
  6570. setFromPoints: function setFromPoints(points) {
  6571. var position = [];
  6572. for (var i = 0, l = points.length; i < l; i++) {
  6573. var point = points[i];
  6574. position.push(point.x, point.y, point.z || 0);
  6575. }
  6576. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  6577. return this;
  6578. },
  6579. updateFromObject: function updateFromObject(object) {
  6580. var geometry = object.geometry;
  6581. if (object.isMesh) {
  6582. var direct = geometry.__directGeometry;
  6583. if (geometry.elementsNeedUpdate === true) {
  6584. direct = undefined;
  6585. geometry.elementsNeedUpdate = false;
  6586. }
  6587. if (direct === undefined) {
  6588. return this.fromGeometry(geometry);
  6589. }
  6590. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6591. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6592. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6593. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6594. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6595. geometry.verticesNeedUpdate = false;
  6596. geometry.normalsNeedUpdate = false;
  6597. geometry.colorsNeedUpdate = false;
  6598. geometry.uvsNeedUpdate = false;
  6599. geometry.groupsNeedUpdate = false;
  6600. geometry = direct;
  6601. }
  6602. if (geometry.verticesNeedUpdate === true) {
  6603. var attribute = this.attributes.position;
  6604. if (attribute !== undefined) {
  6605. attribute.copyVector3sArray(geometry.vertices);
  6606. attribute.needsUpdate = true;
  6607. }
  6608. geometry.verticesNeedUpdate = false;
  6609. }
  6610. if (geometry.normalsNeedUpdate === true) {
  6611. var _attribute = this.attributes.normal;
  6612. if (_attribute !== undefined) {
  6613. _attribute.copyVector3sArray(geometry.normals);
  6614. _attribute.needsUpdate = true;
  6615. }
  6616. geometry.normalsNeedUpdate = false;
  6617. }
  6618. if (geometry.colorsNeedUpdate === true) {
  6619. var _attribute2 = this.attributes.color;
  6620. if (_attribute2 !== undefined) {
  6621. _attribute2.copyColorsArray(geometry.colors);
  6622. _attribute2.needsUpdate = true;
  6623. }
  6624. geometry.colorsNeedUpdate = false;
  6625. }
  6626. if (geometry.uvsNeedUpdate) {
  6627. var _attribute3 = this.attributes.uv;
  6628. if (_attribute3 !== undefined) {
  6629. _attribute3.copyVector2sArray(geometry.uvs);
  6630. _attribute3.needsUpdate = true;
  6631. }
  6632. geometry.uvsNeedUpdate = false;
  6633. }
  6634. if (geometry.lineDistancesNeedUpdate) {
  6635. var _attribute4 = this.attributes.lineDistance;
  6636. if (_attribute4 !== undefined) {
  6637. _attribute4.copyArray(geometry.lineDistances);
  6638. _attribute4.needsUpdate = true;
  6639. }
  6640. geometry.lineDistancesNeedUpdate = false;
  6641. }
  6642. if (geometry.groupsNeedUpdate) {
  6643. geometry.computeGroups(object.geometry);
  6644. this.groups = geometry.groups;
  6645. geometry.groupsNeedUpdate = false;
  6646. }
  6647. return this;
  6648. },
  6649. fromGeometry: function fromGeometry(geometry) {
  6650. geometry.__directGeometry = new DirectGeometry().fromGeometry(geometry);
  6651. return this.fromDirectGeometry(geometry.__directGeometry);
  6652. },
  6653. fromDirectGeometry: function fromDirectGeometry(geometry) {
  6654. var positions = new Float32Array(geometry.vertices.length * 3);
  6655. this.setAttribute('position', new BufferAttribute(positions, 3).copyVector3sArray(geometry.vertices));
  6656. if (geometry.normals.length > 0) {
  6657. var normals = new Float32Array(geometry.normals.length * 3);
  6658. this.setAttribute('normal', new BufferAttribute(normals, 3).copyVector3sArray(geometry.normals));
  6659. }
  6660. if (geometry.colors.length > 0) {
  6661. var colors = new Float32Array(geometry.colors.length * 3);
  6662. this.setAttribute('color', new BufferAttribute(colors, 3).copyColorsArray(geometry.colors));
  6663. }
  6664. if (geometry.uvs.length > 0) {
  6665. var uvs = new Float32Array(geometry.uvs.length * 2);
  6666. this.setAttribute('uv', new BufferAttribute(uvs, 2).copyVector2sArray(geometry.uvs));
  6667. }
  6668. if (geometry.uvs2.length > 0) {
  6669. var uvs2 = new Float32Array(geometry.uvs2.length * 2);
  6670. this.setAttribute('uv2', new BufferAttribute(uvs2, 2).copyVector2sArray(geometry.uvs2));
  6671. } // groups
  6672. this.groups = geometry.groups; // morphs
  6673. for (var name in geometry.morphTargets) {
  6674. var array = [];
  6675. var morphTargets = geometry.morphTargets[name];
  6676. for (var i = 0, l = morphTargets.length; i < l; i++) {
  6677. var morphTarget = morphTargets[i];
  6678. var attribute = new Float32BufferAttribute(morphTarget.data.length * 3, 3);
  6679. attribute.name = morphTarget.name;
  6680. array.push(attribute.copyVector3sArray(morphTarget.data));
  6681. }
  6682. this.morphAttributes[name] = array;
  6683. } // skinning
  6684. if (geometry.skinIndices.length > 0) {
  6685. var skinIndices = new Float32BufferAttribute(geometry.skinIndices.length * 4, 4);
  6686. this.setAttribute('skinIndex', skinIndices.copyVector4sArray(geometry.skinIndices));
  6687. }
  6688. if (geometry.skinWeights.length > 0) {
  6689. var skinWeights = new Float32BufferAttribute(geometry.skinWeights.length * 4, 4);
  6690. this.setAttribute('skinWeight', skinWeights.copyVector4sArray(geometry.skinWeights));
  6691. } //
  6692. if (geometry.boundingSphere !== null) {
  6693. this.boundingSphere = geometry.boundingSphere.clone();
  6694. }
  6695. if (geometry.boundingBox !== null) {
  6696. this.boundingBox = geometry.boundingBox.clone();
  6697. }
  6698. return this;
  6699. },
  6700. computeBoundingBox: function computeBoundingBox() {
  6701. if (this.boundingBox === null) {
  6702. this.boundingBox = new Box3();
  6703. }
  6704. var position = this.attributes.position;
  6705. var morphAttributesPosition = this.morphAttributes.position;
  6706. if (position && position.isGLBufferAttribute) {
  6707. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  6708. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  6709. return;
  6710. }
  6711. if (position !== undefined) {
  6712. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  6713. if (morphAttributesPosition) {
  6714. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6715. var morphAttribute = morphAttributesPosition[i];
  6716. _box$2.setFromBufferAttribute(morphAttribute);
  6717. if (this.morphTargetsRelative) {
  6718. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  6719. this.boundingBox.expandByPoint(_vector$4);
  6720. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  6721. this.boundingBox.expandByPoint(_vector$4);
  6722. } else {
  6723. this.boundingBox.expandByPoint(_box$2.min);
  6724. this.boundingBox.expandByPoint(_box$2.max);
  6725. }
  6726. }
  6727. }
  6728. } else {
  6729. this.boundingBox.makeEmpty();
  6730. }
  6731. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  6732. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  6733. }
  6734. },
  6735. computeBoundingSphere: function computeBoundingSphere() {
  6736. if (this.boundingSphere === null) {
  6737. this.boundingSphere = new Sphere();
  6738. }
  6739. var position = this.attributes.position;
  6740. var morphAttributesPosition = this.morphAttributes.position;
  6741. if (position && position.isGLBufferAttribute) {
  6742. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  6743. this.boundingSphere.set(new Vector3(), Infinity);
  6744. return;
  6745. }
  6746. if (position) {
  6747. // first, find the center of the bounding sphere
  6748. var center = this.boundingSphere.center;
  6749. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  6750. if (morphAttributesPosition) {
  6751. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6752. var morphAttribute = morphAttributesPosition[i];
  6753. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  6754. if (this.morphTargetsRelative) {
  6755. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  6756. _box$2.expandByPoint(_vector$4);
  6757. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  6758. _box$2.expandByPoint(_vector$4);
  6759. } else {
  6760. _box$2.expandByPoint(_boxMorphTargets.min);
  6761. _box$2.expandByPoint(_boxMorphTargets.max);
  6762. }
  6763. }
  6764. }
  6765. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  6766. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6767. var maxRadiusSq = 0;
  6768. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  6769. _vector$4.fromBufferAttribute(position, _i);
  6770. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6771. } // process morph attributes if present
  6772. if (morphAttributesPosition) {
  6773. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  6774. var _morphAttribute = morphAttributesPosition[_i2];
  6775. var morphTargetsRelative = this.morphTargetsRelative;
  6776. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  6777. _vector$4.fromBufferAttribute(_morphAttribute, j);
  6778. if (morphTargetsRelative) {
  6779. _offset.fromBufferAttribute(position, j);
  6780. _vector$4.add(_offset);
  6781. }
  6782. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6783. }
  6784. }
  6785. }
  6786. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  6787. if (isNaN(this.boundingSphere.radius)) {
  6788. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  6789. }
  6790. }
  6791. },
  6792. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  6793. },
  6794. computeVertexNormals: function computeVertexNormals() {
  6795. var index = this.index;
  6796. var positionAttribute = this.getAttribute('position');
  6797. if (positionAttribute !== undefined) {
  6798. var normalAttribute = this.getAttribute('normal');
  6799. if (normalAttribute === undefined) {
  6800. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  6801. this.setAttribute('normal', normalAttribute);
  6802. } else {
  6803. // reset existing normals to zero
  6804. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  6805. normalAttribute.setXYZ(i, 0, 0, 0);
  6806. }
  6807. }
  6808. var pA = new Vector3(),
  6809. pB = new Vector3(),
  6810. pC = new Vector3();
  6811. var nA = new Vector3(),
  6812. nB = new Vector3(),
  6813. nC = new Vector3();
  6814. var cb = new Vector3(),
  6815. ab = new Vector3(); // indexed elements
  6816. if (index) {
  6817. for (var _i3 = 0, _il3 = index.count; _i3 < _il3; _i3 += 3) {
  6818. var vA = index.getX(_i3 + 0);
  6819. var vB = index.getX(_i3 + 1);
  6820. var vC = index.getX(_i3 + 2);
  6821. pA.fromBufferAttribute(positionAttribute, vA);
  6822. pB.fromBufferAttribute(positionAttribute, vB);
  6823. pC.fromBufferAttribute(positionAttribute, vC);
  6824. cb.subVectors(pC, pB);
  6825. ab.subVectors(pA, pB);
  6826. cb.cross(ab);
  6827. nA.fromBufferAttribute(normalAttribute, vA);
  6828. nB.fromBufferAttribute(normalAttribute, vB);
  6829. nC.fromBufferAttribute(normalAttribute, vC);
  6830. nA.add(cb);
  6831. nB.add(cb);
  6832. nC.add(cb);
  6833. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  6834. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  6835. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  6836. }
  6837. } else {
  6838. // non-indexed elements (unconnected triangle soup)
  6839. for (var _i4 = 0, _il4 = positionAttribute.count; _i4 < _il4; _i4 += 3) {
  6840. pA.fromBufferAttribute(positionAttribute, _i4 + 0);
  6841. pB.fromBufferAttribute(positionAttribute, _i4 + 1);
  6842. pC.fromBufferAttribute(positionAttribute, _i4 + 2);
  6843. cb.subVectors(pC, pB);
  6844. ab.subVectors(pA, pB);
  6845. cb.cross(ab);
  6846. normalAttribute.setXYZ(_i4 + 0, cb.x, cb.y, cb.z);
  6847. normalAttribute.setXYZ(_i4 + 1, cb.x, cb.y, cb.z);
  6848. normalAttribute.setXYZ(_i4 + 2, cb.x, cb.y, cb.z);
  6849. }
  6850. }
  6851. this.normalizeNormals();
  6852. normalAttribute.needsUpdate = true;
  6853. }
  6854. },
  6855. merge: function merge(geometry, offset) {
  6856. if (!(geometry && geometry.isBufferGeometry)) {
  6857. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  6858. return;
  6859. }
  6860. if (offset === undefined) {
  6861. offset = 0;
  6862. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  6863. }
  6864. var attributes = this.attributes;
  6865. for (var key in attributes) {
  6866. if (geometry.attributes[key] === undefined) continue;
  6867. var attribute1 = attributes[key];
  6868. var attributeArray1 = attribute1.array;
  6869. var attribute2 = geometry.attributes[key];
  6870. var attributeArray2 = attribute2.array;
  6871. var attributeOffset = attribute2.itemSize * offset;
  6872. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  6873. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  6874. attributeArray1[j] = attributeArray2[i];
  6875. }
  6876. }
  6877. return this;
  6878. },
  6879. normalizeNormals: function normalizeNormals() {
  6880. var normals = this.attributes.normal;
  6881. for (var i = 0, il = normals.count; i < il; i++) {
  6882. _vector$4.fromBufferAttribute(normals, i);
  6883. _vector$4.normalize();
  6884. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  6885. }
  6886. },
  6887. toNonIndexed: function toNonIndexed() {
  6888. function convertBufferAttribute(attribute, indices) {
  6889. var array = attribute.array;
  6890. var itemSize = attribute.itemSize;
  6891. var normalized = attribute.normalized;
  6892. var array2 = new array.constructor(indices.length * itemSize);
  6893. var index = 0,
  6894. index2 = 0;
  6895. for (var i = 0, l = indices.length; i < l; i++) {
  6896. index = indices[i] * itemSize;
  6897. for (var j = 0; j < itemSize; j++) {
  6898. array2[index2++] = array[index++];
  6899. }
  6900. }
  6901. return new BufferAttribute(array2, itemSize, normalized);
  6902. } //
  6903. if (this.index === null) {
  6904. console.warn('THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.');
  6905. return this;
  6906. }
  6907. var geometry2 = new BufferGeometry();
  6908. var indices = this.index.array;
  6909. var attributes = this.attributes; // attributes
  6910. for (var name in attributes) {
  6911. var attribute = attributes[name];
  6912. var newAttribute = convertBufferAttribute(attribute, indices);
  6913. geometry2.setAttribute(name, newAttribute);
  6914. } // morph attributes
  6915. var morphAttributes = this.morphAttributes;
  6916. for (var _name in morphAttributes) {
  6917. var morphArray = [];
  6918. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  6919. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  6920. var _attribute5 = morphAttribute[i];
  6921. var _newAttribute = convertBufferAttribute(_attribute5, indices);
  6922. morphArray.push(_newAttribute);
  6923. }
  6924. geometry2.morphAttributes[_name] = morphArray;
  6925. }
  6926. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  6927. var groups = this.groups;
  6928. for (var _i5 = 0, l = groups.length; _i5 < l; _i5++) {
  6929. var group = groups[_i5];
  6930. geometry2.addGroup(group.start, group.count, group.materialIndex);
  6931. }
  6932. return geometry2;
  6933. },
  6934. toJSON: function toJSON() {
  6935. var data = {
  6936. metadata: {
  6937. version: 4.5,
  6938. type: 'BufferGeometry',
  6939. generator: 'BufferGeometry.toJSON'
  6940. }
  6941. }; // standard BufferGeometry serialization
  6942. data.uuid = this.uuid;
  6943. data.type = this.type;
  6944. if (this.name !== '') data.name = this.name;
  6945. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  6946. if (this.parameters !== undefined) {
  6947. var parameters = this.parameters;
  6948. for (var key in parameters) {
  6949. if (parameters[key] !== undefined) data[key] = parameters[key];
  6950. }
  6951. return data;
  6952. }
  6953. data.data = {
  6954. attributes: {}
  6955. };
  6956. var index = this.index;
  6957. if (index !== null) {
  6958. data.data.index = {
  6959. type: index.array.constructor.name,
  6960. array: Array.prototype.slice.call(index.array)
  6961. };
  6962. }
  6963. var attributes = this.attributes;
  6964. for (var _key in attributes) {
  6965. var attribute = attributes[_key];
  6966. var attributeData = attribute.toJSON(data.data);
  6967. if (attribute.name !== '') attributeData.name = attribute.name;
  6968. data.data.attributes[_key] = attributeData;
  6969. }
  6970. var morphAttributes = {};
  6971. var hasMorphAttributes = false;
  6972. for (var _key2 in this.morphAttributes) {
  6973. var attributeArray = this.morphAttributes[_key2];
  6974. var array = [];
  6975. for (var i = 0, il = attributeArray.length; i < il; i++) {
  6976. var _attribute6 = attributeArray[i];
  6977. var _attributeData = _attribute6.toJSON(data.data);
  6978. if (_attribute6.name !== '') _attributeData.name = _attribute6.name;
  6979. array.push(_attributeData);
  6980. }
  6981. if (array.length > 0) {
  6982. morphAttributes[_key2] = array;
  6983. hasMorphAttributes = true;
  6984. }
  6985. }
  6986. if (hasMorphAttributes) {
  6987. data.data.morphAttributes = morphAttributes;
  6988. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6989. }
  6990. var groups = this.groups;
  6991. if (groups.length > 0) {
  6992. data.data.groups = JSON.parse(JSON.stringify(groups));
  6993. }
  6994. var boundingSphere = this.boundingSphere;
  6995. if (boundingSphere !== null) {
  6996. data.data.boundingSphere = {
  6997. center: boundingSphere.center.toArray(),
  6998. radius: boundingSphere.radius
  6999. };
  7000. }
  7001. return data;
  7002. },
  7003. clone: function clone() {
  7004. /*
  7005. // Handle primitives
  7006. const parameters = this.parameters;
  7007. if ( parameters !== undefined ) {
  7008. const values = [];
  7009. for ( const key in parameters ) {
  7010. values.push( parameters[ key ] );
  7011. }
  7012. const geometry = Object.create( this.constructor.prototype );
  7013. this.constructor.apply( geometry, values );
  7014. return geometry;
  7015. }
  7016. return new this.constructor().copy( this );
  7017. */
  7018. return new BufferGeometry().copy(this);
  7019. },
  7020. copy: function copy(source) {
  7021. // reset
  7022. this.index = null;
  7023. this.attributes = {};
  7024. this.morphAttributes = {};
  7025. this.groups = [];
  7026. this.boundingBox = null;
  7027. this.boundingSphere = null; // used for storing cloned, shared data
  7028. var data = {}; // name
  7029. this.name = source.name; // index
  7030. var index = source.index;
  7031. if (index !== null) {
  7032. this.setIndex(index.clone(data));
  7033. } // attributes
  7034. var attributes = source.attributes;
  7035. for (var name in attributes) {
  7036. var attribute = attributes[name];
  7037. this.setAttribute(name, attribute.clone(data));
  7038. } // morph attributes
  7039. var morphAttributes = source.morphAttributes;
  7040. for (var _name2 in morphAttributes) {
  7041. var array = [];
  7042. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  7043. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  7044. array.push(morphAttribute[i].clone(data));
  7045. }
  7046. this.morphAttributes[_name2] = array;
  7047. }
  7048. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  7049. var groups = source.groups;
  7050. for (var _i6 = 0, _l = groups.length; _i6 < _l; _i6++) {
  7051. var group = groups[_i6];
  7052. this.addGroup(group.start, group.count, group.materialIndex);
  7053. } // bounding box
  7054. var boundingBox = source.boundingBox;
  7055. if (boundingBox !== null) {
  7056. this.boundingBox = boundingBox.clone();
  7057. } // bounding sphere
  7058. var boundingSphere = source.boundingSphere;
  7059. if (boundingSphere !== null) {
  7060. this.boundingSphere = boundingSphere.clone();
  7061. } // draw range
  7062. this.drawRange.start = source.drawRange.start;
  7063. this.drawRange.count = source.drawRange.count; // user data
  7064. this.userData = source.userData;
  7065. return this;
  7066. },
  7067. dispose: function dispose() {
  7068. this.dispatchEvent({
  7069. type: 'dispose'
  7070. });
  7071. }
  7072. });
  7073. var _inverseMatrix = new Matrix4();
  7074. var _ray = new Ray();
  7075. var _sphere = new Sphere();
  7076. var _vA = new Vector3();
  7077. var _vB = new Vector3();
  7078. var _vC = new Vector3();
  7079. var _tempA = new Vector3();
  7080. var _tempB = new Vector3();
  7081. var _tempC = new Vector3();
  7082. var _morphA = new Vector3();
  7083. var _morphB = new Vector3();
  7084. var _morphC = new Vector3();
  7085. var _uvA = new Vector2();
  7086. var _uvB = new Vector2();
  7087. var _uvC = new Vector2();
  7088. var _intersectionPoint = new Vector3();
  7089. var _intersectionPointWorld = new Vector3();
  7090. function Mesh(geometry, material) {
  7091. Object3D.call(this);
  7092. this.type = 'Mesh';
  7093. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  7094. this.material = material !== undefined ? material : new MeshBasicMaterial();
  7095. this.updateMorphTargets();
  7096. }
  7097. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7098. constructor: Mesh,
  7099. isMesh: true,
  7100. copy: function copy(source) {
  7101. Object3D.prototype.copy.call(this, source);
  7102. if (source.morphTargetInfluences !== undefined) {
  7103. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7104. }
  7105. if (source.morphTargetDictionary !== undefined) {
  7106. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7107. }
  7108. this.material = source.material;
  7109. this.geometry = source.geometry;
  7110. return this;
  7111. },
  7112. updateMorphTargets: function updateMorphTargets() {
  7113. var geometry = this.geometry;
  7114. if (geometry.isBufferGeometry) {
  7115. var morphAttributes = geometry.morphAttributes;
  7116. var keys = Object.keys(morphAttributes);
  7117. if (keys.length > 0) {
  7118. var morphAttribute = morphAttributes[keys[0]];
  7119. if (morphAttribute !== undefined) {
  7120. this.morphTargetInfluences = [];
  7121. this.morphTargetDictionary = {};
  7122. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7123. var name = morphAttribute[m].name || String(m);
  7124. this.morphTargetInfluences.push(0);
  7125. this.morphTargetDictionary[name] = m;
  7126. }
  7127. }
  7128. }
  7129. } else {
  7130. var morphTargets = geometry.morphTargets;
  7131. if (morphTargets !== undefined && morphTargets.length > 0) {
  7132. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7133. }
  7134. }
  7135. },
  7136. raycast: function raycast(raycaster, intersects) {
  7137. var geometry = this.geometry;
  7138. var material = this.material;
  7139. var matrixWorld = this.matrixWorld;
  7140. if (material === undefined) return; // Checking boundingSphere distance to ray
  7141. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7142. _sphere.copy(geometry.boundingSphere);
  7143. _sphere.applyMatrix4(matrixWorld);
  7144. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7145. _inverseMatrix.copy(matrixWorld).invert();
  7146. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7147. if (geometry.boundingBox !== null) {
  7148. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7149. }
  7150. var intersection;
  7151. if (geometry.isBufferGeometry) {
  7152. var index = geometry.index;
  7153. var position = geometry.attributes.position;
  7154. var morphPosition = geometry.morphAttributes.position;
  7155. var morphTargetsRelative = geometry.morphTargetsRelative;
  7156. var uv = geometry.attributes.uv;
  7157. var uv2 = geometry.attributes.uv2;
  7158. var groups = geometry.groups;
  7159. var drawRange = geometry.drawRange;
  7160. if (index !== null) {
  7161. // indexed buffer geometry
  7162. if (Array.isArray(material)) {
  7163. for (var i = 0, il = groups.length; i < il; i++) {
  7164. var group = groups[i];
  7165. var groupMaterial = material[group.materialIndex];
  7166. var start = Math.max(group.start, drawRange.start);
  7167. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7168. for (var j = start, jl = end; j < jl; j += 3) {
  7169. var a = index.getX(j);
  7170. var b = index.getX(j + 1);
  7171. var c = index.getX(j + 2);
  7172. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7173. if (intersection) {
  7174. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7175. intersection.face.materialIndex = group.materialIndex;
  7176. intersects.push(intersection);
  7177. }
  7178. }
  7179. }
  7180. } else {
  7181. var _start = Math.max(0, drawRange.start);
  7182. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7183. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7184. var _a = index.getX(_i);
  7185. var _b = index.getX(_i + 1);
  7186. var _c = index.getX(_i + 2);
  7187. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7188. if (intersection) {
  7189. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7190. intersects.push(intersection);
  7191. }
  7192. }
  7193. }
  7194. } else if (position !== undefined) {
  7195. // non-indexed buffer geometry
  7196. if (Array.isArray(material)) {
  7197. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7198. var _group = groups[_i2];
  7199. var _groupMaterial = material[_group.materialIndex];
  7200. var _start2 = Math.max(_group.start, drawRange.start);
  7201. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7202. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7203. var _a2 = _j;
  7204. var _b2 = _j + 1;
  7205. var _c2 = _j + 2;
  7206. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7207. if (intersection) {
  7208. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7209. intersection.face.materialIndex = _group.materialIndex;
  7210. intersects.push(intersection);
  7211. }
  7212. }
  7213. }
  7214. } else {
  7215. var _start3 = Math.max(0, drawRange.start);
  7216. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7217. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7218. var _a3 = _i3;
  7219. var _b3 = _i3 + 1;
  7220. var _c3 = _i3 + 2;
  7221. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7222. if (intersection) {
  7223. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7224. intersects.push(intersection);
  7225. }
  7226. }
  7227. }
  7228. }
  7229. } else if (geometry.isGeometry) {
  7230. var isMultiMaterial = Array.isArray(material);
  7231. var vertices = geometry.vertices;
  7232. var faces = geometry.faces;
  7233. var uvs;
  7234. var faceVertexUvs = geometry.faceVertexUvs[0];
  7235. if (faceVertexUvs.length > 0) uvs = faceVertexUvs;
  7236. for (var f = 0, fl = faces.length; f < fl; f++) {
  7237. var face = faces[f];
  7238. var faceMaterial = isMultiMaterial ? material[face.materialIndex] : material;
  7239. if (faceMaterial === undefined) continue;
  7240. var fvA = vertices[face.a];
  7241. var fvB = vertices[face.b];
  7242. var fvC = vertices[face.c];
  7243. intersection = checkIntersection(this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint);
  7244. if (intersection) {
  7245. if (uvs && uvs[f]) {
  7246. var uvs_f = uvs[f];
  7247. _uvA.copy(uvs_f[0]);
  7248. _uvB.copy(uvs_f[1]);
  7249. _uvC.copy(uvs_f[2]);
  7250. intersection.uv = Triangle.getUV(_intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2());
  7251. }
  7252. intersection.face = face;
  7253. intersection.faceIndex = f;
  7254. intersects.push(intersection);
  7255. }
  7256. }
  7257. }
  7258. }
  7259. });
  7260. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7261. var intersect;
  7262. if (material.side === BackSide) {
  7263. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7264. } else {
  7265. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7266. }
  7267. if (intersect === null) return null;
  7268. _intersectionPointWorld.copy(point);
  7269. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7270. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7271. if (distance < raycaster.near || distance > raycaster.far) return null;
  7272. return {
  7273. distance: distance,
  7274. point: _intersectionPointWorld.clone(),
  7275. object: object
  7276. };
  7277. }
  7278. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7279. _vA.fromBufferAttribute(position, a);
  7280. _vB.fromBufferAttribute(position, b);
  7281. _vC.fromBufferAttribute(position, c);
  7282. var morphInfluences = object.morphTargetInfluences;
  7283. if (material.morphTargets && morphPosition && morphInfluences) {
  7284. _morphA.set(0, 0, 0);
  7285. _morphB.set(0, 0, 0);
  7286. _morphC.set(0, 0, 0);
  7287. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7288. var influence = morphInfluences[i];
  7289. var morphAttribute = morphPosition[i];
  7290. if (influence === 0) continue;
  7291. _tempA.fromBufferAttribute(morphAttribute, a);
  7292. _tempB.fromBufferAttribute(morphAttribute, b);
  7293. _tempC.fromBufferAttribute(morphAttribute, c);
  7294. if (morphTargetsRelative) {
  7295. _morphA.addScaledVector(_tempA, influence);
  7296. _morphB.addScaledVector(_tempB, influence);
  7297. _morphC.addScaledVector(_tempC, influence);
  7298. } else {
  7299. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7300. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7301. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7302. }
  7303. }
  7304. _vA.add(_morphA);
  7305. _vB.add(_morphB);
  7306. _vC.add(_morphC);
  7307. }
  7308. if (object.isSkinnedMesh) {
  7309. object.boneTransform(a, _vA);
  7310. object.boneTransform(b, _vB);
  7311. object.boneTransform(c, _vC);
  7312. }
  7313. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7314. if (intersection) {
  7315. if (uv) {
  7316. _uvA.fromBufferAttribute(uv, a);
  7317. _uvB.fromBufferAttribute(uv, b);
  7318. _uvC.fromBufferAttribute(uv, c);
  7319. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7320. }
  7321. if (uv2) {
  7322. _uvA.fromBufferAttribute(uv2, a);
  7323. _uvB.fromBufferAttribute(uv2, b);
  7324. _uvC.fromBufferAttribute(uv2, c);
  7325. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7326. }
  7327. var face = new Face3(a, b, c);
  7328. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7329. intersection.face = face;
  7330. }
  7331. return intersection;
  7332. }
  7333. var BoxBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7334. _inheritsLoose(BoxBufferGeometry, _BufferGeometry);
  7335. function BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7336. var _this;
  7337. if (width === void 0) {
  7338. width = 1;
  7339. }
  7340. if (height === void 0) {
  7341. height = 1;
  7342. }
  7343. if (depth === void 0) {
  7344. depth = 1;
  7345. }
  7346. if (widthSegments === void 0) {
  7347. widthSegments = 1;
  7348. }
  7349. if (heightSegments === void 0) {
  7350. heightSegments = 1;
  7351. }
  7352. if (depthSegments === void 0) {
  7353. depthSegments = 1;
  7354. }
  7355. _this = _BufferGeometry.call(this) || this;
  7356. _this.type = 'BoxBufferGeometry';
  7357. _this.parameters = {
  7358. width: width,
  7359. height: height,
  7360. depth: depth,
  7361. widthSegments: widthSegments,
  7362. heightSegments: heightSegments,
  7363. depthSegments: depthSegments
  7364. };
  7365. var scope = _assertThisInitialized(_this); // segments
  7366. widthSegments = Math.floor(widthSegments);
  7367. heightSegments = Math.floor(heightSegments);
  7368. depthSegments = Math.floor(depthSegments); // buffers
  7369. var indices = [];
  7370. var vertices = [];
  7371. var normals = [];
  7372. var uvs = []; // helper variables
  7373. var numberOfVertices = 0;
  7374. var groupStart = 0; // build each side of the box geometry
  7375. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7376. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7377. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7378. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7379. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7380. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7381. // build geometry
  7382. _this.setIndex(indices);
  7383. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7384. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7385. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7386. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7387. var segmentWidth = width / gridX;
  7388. var segmentHeight = height / gridY;
  7389. var widthHalf = width / 2;
  7390. var heightHalf = height / 2;
  7391. var depthHalf = depth / 2;
  7392. var gridX1 = gridX + 1;
  7393. var gridY1 = gridY + 1;
  7394. var vertexCounter = 0;
  7395. var groupCount = 0;
  7396. var vector = new Vector3(); // generate vertices, normals and uvs
  7397. for (var iy = 0; iy < gridY1; iy++) {
  7398. var y = iy * segmentHeight - heightHalf;
  7399. for (var ix = 0; ix < gridX1; ix++) {
  7400. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7401. vector[u] = x * udir;
  7402. vector[v] = y * vdir;
  7403. vector[w] = depthHalf; // now apply vector to vertex buffer
  7404. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7405. vector[u] = 0;
  7406. vector[v] = 0;
  7407. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7408. normals.push(vector.x, vector.y, vector.z); // uvs
  7409. uvs.push(ix / gridX);
  7410. uvs.push(1 - iy / gridY); // counters
  7411. vertexCounter += 1;
  7412. }
  7413. } // indices
  7414. // 1. you need three indices to draw a single face
  7415. // 2. a single segment consists of two faces
  7416. // 3. so we need to generate six (2*3) indices per segment
  7417. for (var _iy = 0; _iy < gridY; _iy++) {
  7418. for (var _ix = 0; _ix < gridX; _ix++) {
  7419. var a = numberOfVertices + _ix + gridX1 * _iy;
  7420. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7421. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7422. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7423. indices.push(a, b, d);
  7424. indices.push(b, c, d); // increase counter
  7425. groupCount += 6;
  7426. }
  7427. } // add a group to the geometry. this will ensure multi material support
  7428. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7429. groupStart += groupCount; // update total number of vertices
  7430. numberOfVertices += vertexCounter;
  7431. }
  7432. return _this;
  7433. }
  7434. return BoxBufferGeometry;
  7435. }(BufferGeometry);
  7436. /**
  7437. * Uniform Utilities
  7438. */
  7439. function cloneUniforms(src) {
  7440. var dst = {};
  7441. for (var u in src) {
  7442. dst[u] = {};
  7443. for (var p in src[u]) {
  7444. var property = src[u][p];
  7445. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture)) {
  7446. dst[u][p] = property.clone();
  7447. } else if (Array.isArray(property)) {
  7448. dst[u][p] = property.slice();
  7449. } else {
  7450. dst[u][p] = property;
  7451. }
  7452. }
  7453. }
  7454. return dst;
  7455. }
  7456. function mergeUniforms(uniforms) {
  7457. var merged = {};
  7458. for (var u = 0; u < uniforms.length; u++) {
  7459. var tmp = cloneUniforms(uniforms[u]);
  7460. for (var p in tmp) {
  7461. merged[p] = tmp[p];
  7462. }
  7463. }
  7464. return merged;
  7465. } // Legacy
  7466. var UniformsUtils = {
  7467. clone: cloneUniforms,
  7468. merge: mergeUniforms
  7469. };
  7470. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7471. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7472. /**
  7473. * parameters = {
  7474. * defines: { "label" : "value" },
  7475. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7476. *
  7477. * fragmentShader: <string>,
  7478. * vertexShader: <string>,
  7479. *
  7480. * wireframe: <boolean>,
  7481. * wireframeLinewidth: <float>,
  7482. *
  7483. * lights: <bool>,
  7484. *
  7485. * skinning: <bool>,
  7486. * morphTargets: <bool>,
  7487. * morphNormals: <bool>
  7488. * }
  7489. */
  7490. function ShaderMaterial(parameters) {
  7491. Material.call(this);
  7492. this.type = 'ShaderMaterial';
  7493. this.defines = {};
  7494. this.uniforms = {};
  7495. this.vertexShader = default_vertex;
  7496. this.fragmentShader = default_fragment;
  7497. this.linewidth = 1;
  7498. this.wireframe = false;
  7499. this.wireframeLinewidth = 1;
  7500. this.fog = false; // set to use scene fog
  7501. this.lights = false; // set to use scene lights
  7502. this.clipping = false; // set to use user-defined clipping planes
  7503. this.skinning = false; // set to use skinning attribute streams
  7504. this.morphTargets = false; // set to use morph targets
  7505. this.morphNormals = false; // set to use morph normals
  7506. this.extensions = {
  7507. derivatives: false,
  7508. // set to use derivatives
  7509. fragDepth: false,
  7510. // set to use fragment depth values
  7511. drawBuffers: false,
  7512. // set to use draw buffers
  7513. shaderTextureLOD: false // set to use shader texture LOD
  7514. }; // When rendered geometry doesn't include these attributes but the material does,
  7515. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7516. this.defaultAttributeValues = {
  7517. 'color': [1, 1, 1],
  7518. 'uv': [0, 0],
  7519. 'uv2': [0, 0]
  7520. };
  7521. this.index0AttributeName = undefined;
  7522. this.uniformsNeedUpdate = false;
  7523. this.glslVersion = null;
  7524. if (parameters !== undefined) {
  7525. if (parameters.attributes !== undefined) {
  7526. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  7527. }
  7528. this.setValues(parameters);
  7529. }
  7530. }
  7531. ShaderMaterial.prototype = Object.create(Material.prototype);
  7532. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7533. ShaderMaterial.prototype.isShaderMaterial = true;
  7534. ShaderMaterial.prototype.copy = function (source) {
  7535. Material.prototype.copy.call(this, source);
  7536. this.fragmentShader = source.fragmentShader;
  7537. this.vertexShader = source.vertexShader;
  7538. this.uniforms = cloneUniforms(source.uniforms);
  7539. this.defines = Object.assign({}, source.defines);
  7540. this.wireframe = source.wireframe;
  7541. this.wireframeLinewidth = source.wireframeLinewidth;
  7542. this.lights = source.lights;
  7543. this.clipping = source.clipping;
  7544. this.skinning = source.skinning;
  7545. this.morphTargets = source.morphTargets;
  7546. this.morphNormals = source.morphNormals;
  7547. this.extensions = Object.assign({}, source.extensions);
  7548. this.glslVersion = source.glslVersion;
  7549. return this;
  7550. };
  7551. ShaderMaterial.prototype.toJSON = function (meta) {
  7552. var data = Material.prototype.toJSON.call(this, meta);
  7553. data.glslVersion = this.glslVersion;
  7554. data.uniforms = {};
  7555. for (var name in this.uniforms) {
  7556. var uniform = this.uniforms[name];
  7557. var value = uniform.value;
  7558. if (value && value.isTexture) {
  7559. data.uniforms[name] = {
  7560. type: 't',
  7561. value: value.toJSON(meta).uuid
  7562. };
  7563. } else if (value && value.isColor) {
  7564. data.uniforms[name] = {
  7565. type: 'c',
  7566. value: value.getHex()
  7567. };
  7568. } else if (value && value.isVector2) {
  7569. data.uniforms[name] = {
  7570. type: 'v2',
  7571. value: value.toArray()
  7572. };
  7573. } else if (value && value.isVector3) {
  7574. data.uniforms[name] = {
  7575. type: 'v3',
  7576. value: value.toArray()
  7577. };
  7578. } else if (value && value.isVector4) {
  7579. data.uniforms[name] = {
  7580. type: 'v4',
  7581. value: value.toArray()
  7582. };
  7583. } else if (value && value.isMatrix3) {
  7584. data.uniforms[name] = {
  7585. type: 'm3',
  7586. value: value.toArray()
  7587. };
  7588. } else if (value && value.isMatrix4) {
  7589. data.uniforms[name] = {
  7590. type: 'm4',
  7591. value: value.toArray()
  7592. };
  7593. } else {
  7594. data.uniforms[name] = {
  7595. value: value
  7596. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7597. }
  7598. }
  7599. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  7600. data.vertexShader = this.vertexShader;
  7601. data.fragmentShader = this.fragmentShader;
  7602. var extensions = {};
  7603. for (var key in this.extensions) {
  7604. if (this.extensions[key] === true) extensions[key] = true;
  7605. }
  7606. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  7607. return data;
  7608. };
  7609. function Camera() {
  7610. Object3D.call(this);
  7611. this.type = 'Camera';
  7612. this.matrixWorldInverse = new Matrix4();
  7613. this.projectionMatrix = new Matrix4();
  7614. this.projectionMatrixInverse = new Matrix4();
  7615. }
  7616. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  7617. constructor: Camera,
  7618. isCamera: true,
  7619. copy: function copy(source, recursive) {
  7620. Object3D.prototype.copy.call(this, source, recursive);
  7621. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  7622. this.projectionMatrix.copy(source.projectionMatrix);
  7623. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  7624. return this;
  7625. },
  7626. getWorldDirection: function getWorldDirection(target) {
  7627. if (target === undefined) {
  7628. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  7629. target = new Vector3();
  7630. }
  7631. this.updateWorldMatrix(true, false);
  7632. var e = this.matrixWorld.elements;
  7633. return target.set(-e[8], -e[9], -e[10]).normalize();
  7634. },
  7635. updateMatrixWorld: function updateMatrixWorld(force) {
  7636. Object3D.prototype.updateMatrixWorld.call(this, force);
  7637. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  7638. },
  7639. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  7640. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  7641. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  7642. },
  7643. clone: function clone() {
  7644. return new this.constructor().copy(this);
  7645. }
  7646. });
  7647. function PerspectiveCamera(fov, aspect, near, far) {
  7648. Camera.call(this);
  7649. this.type = 'PerspectiveCamera';
  7650. this.fov = fov !== undefined ? fov : 50;
  7651. this.zoom = 1;
  7652. this.near = near !== undefined ? near : 0.1;
  7653. this.far = far !== undefined ? far : 2000;
  7654. this.focus = 10;
  7655. this.aspect = aspect !== undefined ? aspect : 1;
  7656. this.view = null;
  7657. this.filmGauge = 35; // width of the film (default in millimeters)
  7658. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7659. this.updateProjectionMatrix();
  7660. }
  7661. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  7662. constructor: PerspectiveCamera,
  7663. isPerspectiveCamera: true,
  7664. copy: function copy(source, recursive) {
  7665. Camera.prototype.copy.call(this, source, recursive);
  7666. this.fov = source.fov;
  7667. this.zoom = source.zoom;
  7668. this.near = source.near;
  7669. this.far = source.far;
  7670. this.focus = source.focus;
  7671. this.aspect = source.aspect;
  7672. this.view = source.view === null ? null : Object.assign({}, source.view);
  7673. this.filmGauge = source.filmGauge;
  7674. this.filmOffset = source.filmOffset;
  7675. return this;
  7676. },
  7677. /**
  7678. * Sets the FOV by focal length in respect to the current .filmGauge.
  7679. *
  7680. * The default film gauge is 35, so that the focal length can be specified for
  7681. * a 35mm (full frame) camera.
  7682. *
  7683. * Values for focal length and film gauge must have the same unit.
  7684. */
  7685. setFocalLength: function setFocalLength(focalLength) {
  7686. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7687. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7688. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  7689. this.updateProjectionMatrix();
  7690. },
  7691. /**
  7692. * Calculates the focal length from the current .fov and .filmGauge.
  7693. */
  7694. getFocalLength: function getFocalLength() {
  7695. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  7696. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7697. },
  7698. getEffectiveFOV: function getEffectiveFOV() {
  7699. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  7700. },
  7701. getFilmWidth: function getFilmWidth() {
  7702. // film not completely covered in portrait format (aspect < 1)
  7703. return this.filmGauge * Math.min(this.aspect, 1);
  7704. },
  7705. getFilmHeight: function getFilmHeight() {
  7706. // film not completely covered in landscape format (aspect > 1)
  7707. return this.filmGauge / Math.max(this.aspect, 1);
  7708. },
  7709. /**
  7710. * Sets an offset in a larger frustum. This is useful for multi-window or
  7711. * multi-monitor/multi-machine setups.
  7712. *
  7713. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7714. * the monitors are in grid like this
  7715. *
  7716. * +---+---+---+
  7717. * | A | B | C |
  7718. * +---+---+---+
  7719. * | D | E | F |
  7720. * +---+---+---+
  7721. *
  7722. * then for each monitor you would call it like this
  7723. *
  7724. * const w = 1920;
  7725. * const h = 1080;
  7726. * const fullWidth = w * 3;
  7727. * const fullHeight = h * 2;
  7728. *
  7729. * --A--
  7730. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7731. * --B--
  7732. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7733. * --C--
  7734. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7735. * --D--
  7736. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7737. * --E--
  7738. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7739. * --F--
  7740. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7741. *
  7742. * Note there is no reason monitors have to be the same size or in a grid.
  7743. */
  7744. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  7745. this.aspect = fullWidth / fullHeight;
  7746. if (this.view === null) {
  7747. this.view = {
  7748. enabled: true,
  7749. fullWidth: 1,
  7750. fullHeight: 1,
  7751. offsetX: 0,
  7752. offsetY: 0,
  7753. width: 1,
  7754. height: 1
  7755. };
  7756. }
  7757. this.view.enabled = true;
  7758. this.view.fullWidth = fullWidth;
  7759. this.view.fullHeight = fullHeight;
  7760. this.view.offsetX = x;
  7761. this.view.offsetY = y;
  7762. this.view.width = width;
  7763. this.view.height = height;
  7764. this.updateProjectionMatrix();
  7765. },
  7766. clearViewOffset: function clearViewOffset() {
  7767. if (this.view !== null) {
  7768. this.view.enabled = false;
  7769. }
  7770. this.updateProjectionMatrix();
  7771. },
  7772. updateProjectionMatrix: function updateProjectionMatrix() {
  7773. var near = this.near;
  7774. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  7775. var height = 2 * top;
  7776. var width = this.aspect * height;
  7777. var left = -0.5 * width;
  7778. var view = this.view;
  7779. if (this.view !== null && this.view.enabled) {
  7780. var fullWidth = view.fullWidth,
  7781. fullHeight = view.fullHeight;
  7782. left += view.offsetX * width / fullWidth;
  7783. top -= view.offsetY * height / fullHeight;
  7784. width *= view.width / fullWidth;
  7785. height *= view.height / fullHeight;
  7786. }
  7787. var skew = this.filmOffset;
  7788. if (skew !== 0) left += near * skew / this.getFilmWidth();
  7789. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  7790. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  7791. },
  7792. toJSON: function toJSON(meta) {
  7793. var data = Object3D.prototype.toJSON.call(this, meta);
  7794. data.object.fov = this.fov;
  7795. data.object.zoom = this.zoom;
  7796. data.object.near = this.near;
  7797. data.object.far = this.far;
  7798. data.object.focus = this.focus;
  7799. data.object.aspect = this.aspect;
  7800. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  7801. data.object.filmGauge = this.filmGauge;
  7802. data.object.filmOffset = this.filmOffset;
  7803. return data;
  7804. }
  7805. });
  7806. var fov = 90,
  7807. aspect = 1;
  7808. function CubeCamera(near, far, renderTarget) {
  7809. Object3D.call(this);
  7810. this.type = 'CubeCamera';
  7811. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  7812. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  7813. return;
  7814. }
  7815. this.renderTarget = renderTarget;
  7816. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  7817. cameraPX.layers = this.layers;
  7818. cameraPX.up.set(0, -1, 0);
  7819. cameraPX.lookAt(new Vector3(1, 0, 0));
  7820. this.add(cameraPX);
  7821. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  7822. cameraNX.layers = this.layers;
  7823. cameraNX.up.set(0, -1, 0);
  7824. cameraNX.lookAt(new Vector3(-1, 0, 0));
  7825. this.add(cameraNX);
  7826. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  7827. cameraPY.layers = this.layers;
  7828. cameraPY.up.set(0, 0, 1);
  7829. cameraPY.lookAt(new Vector3(0, 1, 0));
  7830. this.add(cameraPY);
  7831. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  7832. cameraNY.layers = this.layers;
  7833. cameraNY.up.set(0, 0, -1);
  7834. cameraNY.lookAt(new Vector3(0, -1, 0));
  7835. this.add(cameraNY);
  7836. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  7837. cameraPZ.layers = this.layers;
  7838. cameraPZ.up.set(0, -1, 0);
  7839. cameraPZ.lookAt(new Vector3(0, 0, 1));
  7840. this.add(cameraPZ);
  7841. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  7842. cameraNZ.layers = this.layers;
  7843. cameraNZ.up.set(0, -1, 0);
  7844. cameraNZ.lookAt(new Vector3(0, 0, -1));
  7845. this.add(cameraNZ);
  7846. this.update = function (renderer, scene) {
  7847. if (this.parent === null) this.updateMatrixWorld();
  7848. var currentXrEnabled = renderer.xr.enabled;
  7849. var currentRenderTarget = renderer.getRenderTarget();
  7850. renderer.xr.enabled = false;
  7851. var generateMipmaps = renderTarget.texture.generateMipmaps;
  7852. renderTarget.texture.generateMipmaps = false;
  7853. renderer.setRenderTarget(renderTarget, 0);
  7854. renderer.render(scene, cameraPX);
  7855. renderer.setRenderTarget(renderTarget, 1);
  7856. renderer.render(scene, cameraNX);
  7857. renderer.setRenderTarget(renderTarget, 2);
  7858. renderer.render(scene, cameraPY);
  7859. renderer.setRenderTarget(renderTarget, 3);
  7860. renderer.render(scene, cameraNY);
  7861. renderer.setRenderTarget(renderTarget, 4);
  7862. renderer.render(scene, cameraPZ);
  7863. renderTarget.texture.generateMipmaps = generateMipmaps;
  7864. renderer.setRenderTarget(renderTarget, 5);
  7865. renderer.render(scene, cameraNZ);
  7866. renderer.setRenderTarget(currentRenderTarget);
  7867. renderer.xr.enabled = currentXrEnabled;
  7868. };
  7869. }
  7870. CubeCamera.prototype = Object.create(Object3D.prototype);
  7871. CubeCamera.prototype.constructor = CubeCamera;
  7872. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  7873. images = images !== undefined ? images : [];
  7874. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7875. format = format !== undefined ? format : RGBFormat;
  7876. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  7877. this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
  7878. //
  7879. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7880. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7881. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7882. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7883. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  7884. // when using WebGLCubeRenderTarget.texture as a cube texture.
  7885. this._needsFlipEnvMap = true;
  7886. }
  7887. CubeTexture.prototype = Object.create(Texture.prototype);
  7888. CubeTexture.prototype.constructor = CubeTexture;
  7889. CubeTexture.prototype.isCubeTexture = true;
  7890. Object.defineProperty(CubeTexture.prototype, 'images', {
  7891. get: function get() {
  7892. return this.image;
  7893. },
  7894. set: function set(value) {
  7895. this.image = value;
  7896. }
  7897. });
  7898. function WebGLCubeRenderTarget(size, options, dummy) {
  7899. if (Number.isInteger(options)) {
  7900. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  7901. options = dummy;
  7902. }
  7903. WebGLRenderTarget.call(this, size, size, options);
  7904. options = options || {};
  7905. this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  7906. this.texture._needsFlipEnvMap = false;
  7907. }
  7908. WebGLCubeRenderTarget.prototype = Object.create(WebGLRenderTarget.prototype);
  7909. WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
  7910. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  7911. WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function (renderer, texture) {
  7912. this.texture.type = texture.type;
  7913. this.texture.format = RGBAFormat; // see #18859
  7914. this.texture.encoding = texture.encoding;
  7915. this.texture.generateMipmaps = texture.generateMipmaps;
  7916. this.texture.minFilter = texture.minFilter;
  7917. this.texture.magFilter = texture.magFilter;
  7918. var shader = {
  7919. uniforms: {
  7920. tEquirect: {
  7921. value: null
  7922. }
  7923. },
  7924. vertexShader:
  7925. /* glsl */
  7926. "\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",
  7927. fragmentShader:
  7928. /* glsl */
  7929. "\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"
  7930. };
  7931. var geometry = new BoxBufferGeometry(5, 5, 5);
  7932. var material = new ShaderMaterial({
  7933. name: 'CubemapFromEquirect',
  7934. uniforms: cloneUniforms(shader.uniforms),
  7935. vertexShader: shader.vertexShader,
  7936. fragmentShader: shader.fragmentShader,
  7937. side: BackSide,
  7938. blending: NoBlending
  7939. });
  7940. material.uniforms.tEquirect.value = texture;
  7941. var mesh = new Mesh(geometry, material);
  7942. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  7943. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  7944. var camera = new CubeCamera(1, 10, this);
  7945. camera.update(renderer, mesh);
  7946. texture.minFilter = currentMinFilter;
  7947. mesh.geometry.dispose();
  7948. mesh.material.dispose();
  7949. return this;
  7950. };
  7951. WebGLCubeRenderTarget.prototype.clear = function (renderer, color, depth, stencil) {
  7952. var currentRenderTarget = renderer.getRenderTarget();
  7953. for (var i = 0; i < 6; i++) {
  7954. renderer.setRenderTarget(this, i);
  7955. renderer.clear(color, depth, stencil);
  7956. }
  7957. renderer.setRenderTarget(currentRenderTarget);
  7958. };
  7959. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  7960. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  7961. this.image = {
  7962. data: data || null,
  7963. width: width || 1,
  7964. height: height || 1
  7965. };
  7966. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  7967. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  7968. this.generateMipmaps = false;
  7969. this.flipY = false;
  7970. this.unpackAlignment = 1;
  7971. this.needsUpdate = true;
  7972. }
  7973. DataTexture.prototype = Object.create(Texture.prototype);
  7974. DataTexture.prototype.constructor = DataTexture;
  7975. DataTexture.prototype.isDataTexture = true;
  7976. var _sphere$1 = /*@__PURE__*/new Sphere();
  7977. var _vector$5 = /*@__PURE__*/new Vector3();
  7978. var Frustum = /*#__PURE__*/function () {
  7979. function Frustum(p0, p1, p2, p3, p4, p5) {
  7980. 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()];
  7981. }
  7982. var _proto = Frustum.prototype;
  7983. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  7984. var planes = this.planes;
  7985. planes[0].copy(p0);
  7986. planes[1].copy(p1);
  7987. planes[2].copy(p2);
  7988. planes[3].copy(p3);
  7989. planes[4].copy(p4);
  7990. planes[5].copy(p5);
  7991. return this;
  7992. };
  7993. _proto.clone = function clone() {
  7994. return new this.constructor().copy(this);
  7995. };
  7996. _proto.copy = function copy(frustum) {
  7997. var planes = this.planes;
  7998. for (var i = 0; i < 6; i++) {
  7999. planes[i].copy(frustum.planes[i]);
  8000. }
  8001. return this;
  8002. };
  8003. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  8004. var planes = this.planes;
  8005. var me = m.elements;
  8006. var me0 = me[0],
  8007. me1 = me[1],
  8008. me2 = me[2],
  8009. me3 = me[3];
  8010. var me4 = me[4],
  8011. me5 = me[5],
  8012. me6 = me[6],
  8013. me7 = me[7];
  8014. var me8 = me[8],
  8015. me9 = me[9],
  8016. me10 = me[10],
  8017. me11 = me[11];
  8018. var me12 = me[12],
  8019. me13 = me[13],
  8020. me14 = me[14],
  8021. me15 = me[15];
  8022. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  8023. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  8024. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  8025. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  8026. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  8027. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  8028. return this;
  8029. };
  8030. _proto.intersectsObject = function intersectsObject(object) {
  8031. var geometry = object.geometry;
  8032. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  8033. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  8034. return this.intersectsSphere(_sphere$1);
  8035. };
  8036. _proto.intersectsSprite = function intersectsSprite(sprite) {
  8037. _sphere$1.center.set(0, 0, 0);
  8038. _sphere$1.radius = 0.7071067811865476;
  8039. _sphere$1.applyMatrix4(sprite.matrixWorld);
  8040. return this.intersectsSphere(_sphere$1);
  8041. };
  8042. _proto.intersectsSphere = function intersectsSphere(sphere) {
  8043. var planes = this.planes;
  8044. var center = sphere.center;
  8045. var negRadius = -sphere.radius;
  8046. for (var i = 0; i < 6; i++) {
  8047. var distance = planes[i].distanceToPoint(center);
  8048. if (distance < negRadius) {
  8049. return false;
  8050. }
  8051. }
  8052. return true;
  8053. };
  8054. _proto.intersectsBox = function intersectsBox(box) {
  8055. var planes = this.planes;
  8056. for (var i = 0; i < 6; i++) {
  8057. var plane = planes[i]; // corner at max distance
  8058. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8059. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8060. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8061. if (plane.distanceToPoint(_vector$5) < 0) {
  8062. return false;
  8063. }
  8064. }
  8065. return true;
  8066. };
  8067. _proto.containsPoint = function containsPoint(point) {
  8068. var planes = this.planes;
  8069. for (var i = 0; i < 6; i++) {
  8070. if (planes[i].distanceToPoint(point) < 0) {
  8071. return false;
  8072. }
  8073. }
  8074. return true;
  8075. };
  8076. return Frustum;
  8077. }();
  8078. function WebGLAnimation() {
  8079. var context = null;
  8080. var isAnimating = false;
  8081. var animationLoop = null;
  8082. var requestId = null;
  8083. function onAnimationFrame(time, frame) {
  8084. animationLoop(time, frame);
  8085. requestId = context.requestAnimationFrame(onAnimationFrame);
  8086. }
  8087. return {
  8088. start: function start() {
  8089. if (isAnimating === true) return;
  8090. if (animationLoop === null) return;
  8091. requestId = context.requestAnimationFrame(onAnimationFrame);
  8092. isAnimating = true;
  8093. },
  8094. stop: function stop() {
  8095. context.cancelAnimationFrame(requestId);
  8096. isAnimating = false;
  8097. },
  8098. setAnimationLoop: function setAnimationLoop(callback) {
  8099. animationLoop = callback;
  8100. },
  8101. setContext: function setContext(value) {
  8102. context = value;
  8103. }
  8104. };
  8105. }
  8106. function WebGLAttributes(gl, capabilities) {
  8107. var isWebGL2 = capabilities.isWebGL2;
  8108. var buffers = new WeakMap();
  8109. function createBuffer(attribute, bufferType) {
  8110. var array = attribute.array;
  8111. var usage = attribute.usage;
  8112. var buffer = gl.createBuffer();
  8113. gl.bindBuffer(bufferType, buffer);
  8114. gl.bufferData(bufferType, array, usage);
  8115. attribute.onUploadCallback();
  8116. var type = 5126;
  8117. if (array instanceof Float32Array) {
  8118. type = 5126;
  8119. } else if (array instanceof Float64Array) {
  8120. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8121. } else if (array instanceof Uint16Array) {
  8122. if (attribute.isFloat16BufferAttribute) {
  8123. if (isWebGL2) {
  8124. type = 5131;
  8125. } else {
  8126. console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
  8127. }
  8128. } else {
  8129. type = 5123;
  8130. }
  8131. } else if (array instanceof Int16Array) {
  8132. type = 5122;
  8133. } else if (array instanceof Uint32Array) {
  8134. type = 5125;
  8135. } else if (array instanceof Int32Array) {
  8136. type = 5124;
  8137. } else if (array instanceof Int8Array) {
  8138. type = 5120;
  8139. } else if (array instanceof Uint8Array) {
  8140. type = 5121;
  8141. }
  8142. return {
  8143. buffer: buffer,
  8144. type: type,
  8145. bytesPerElement: array.BYTES_PER_ELEMENT,
  8146. version: attribute.version
  8147. };
  8148. }
  8149. function updateBuffer(buffer, attribute, bufferType) {
  8150. var array = attribute.array;
  8151. var updateRange = attribute.updateRange;
  8152. gl.bindBuffer(bufferType, buffer);
  8153. if (updateRange.count === -1) {
  8154. // Not using update ranges
  8155. gl.bufferSubData(bufferType, 0, array);
  8156. } else {
  8157. if (isWebGL2) {
  8158. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8159. } else {
  8160. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8161. }
  8162. updateRange.count = -1; // reset range
  8163. }
  8164. } //
  8165. function get(attribute) {
  8166. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8167. return buffers.get(attribute);
  8168. }
  8169. function remove(attribute) {
  8170. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8171. var data = buffers.get(attribute);
  8172. if (data) {
  8173. gl.deleteBuffer(data.buffer);
  8174. buffers.delete(attribute);
  8175. }
  8176. }
  8177. function update(attribute, bufferType) {
  8178. if (attribute.isGLBufferAttribute) {
  8179. var cached = buffers.get(attribute);
  8180. if (!cached || cached.version < attribute.version) {
  8181. buffers.set(attribute, {
  8182. buffer: attribute.buffer,
  8183. type: attribute.type,
  8184. bytesPerElement: attribute.elementSize,
  8185. version: attribute.version
  8186. });
  8187. }
  8188. return;
  8189. }
  8190. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8191. var data = buffers.get(attribute);
  8192. if (data === undefined) {
  8193. buffers.set(attribute, createBuffer(attribute, bufferType));
  8194. } else if (data.version < attribute.version) {
  8195. updateBuffer(data.buffer, attribute, bufferType);
  8196. data.version = attribute.version;
  8197. }
  8198. }
  8199. return {
  8200. get: get,
  8201. remove: remove,
  8202. update: update
  8203. };
  8204. }
  8205. var PlaneBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8206. _inheritsLoose(PlaneBufferGeometry, _BufferGeometry);
  8207. function PlaneBufferGeometry(width, height, widthSegments, heightSegments) {
  8208. var _this;
  8209. _this = _BufferGeometry.call(this) || this;
  8210. _this.type = 'PlaneBufferGeometry';
  8211. _this.parameters = {
  8212. width: width,
  8213. height: height,
  8214. widthSegments: widthSegments,
  8215. heightSegments: heightSegments
  8216. };
  8217. width = width || 1;
  8218. height = height || 1;
  8219. var width_half = width / 2;
  8220. var height_half = height / 2;
  8221. var gridX = Math.floor(widthSegments) || 1;
  8222. var gridY = Math.floor(heightSegments) || 1;
  8223. var gridX1 = gridX + 1;
  8224. var gridY1 = gridY + 1;
  8225. var segment_width = width / gridX;
  8226. var segment_height = height / gridY; // buffers
  8227. var indices = [];
  8228. var vertices = [];
  8229. var normals = [];
  8230. var uvs = []; // generate vertices, normals and uvs
  8231. for (var iy = 0; iy < gridY1; iy++) {
  8232. var y = iy * segment_height - height_half;
  8233. for (var ix = 0; ix < gridX1; ix++) {
  8234. var x = ix * segment_width - width_half;
  8235. vertices.push(x, -y, 0);
  8236. normals.push(0, 0, 1);
  8237. uvs.push(ix / gridX);
  8238. uvs.push(1 - iy / gridY);
  8239. }
  8240. } // indices
  8241. for (var _iy = 0; _iy < gridY; _iy++) {
  8242. for (var _ix = 0; _ix < gridX; _ix++) {
  8243. var a = _ix + gridX1 * _iy;
  8244. var b = _ix + gridX1 * (_iy + 1);
  8245. var c = _ix + 1 + gridX1 * (_iy + 1);
  8246. var d = _ix + 1 + gridX1 * _iy; // faces
  8247. indices.push(a, b, d);
  8248. indices.push(b, c, d);
  8249. }
  8250. } // build geometry
  8251. _this.setIndex(indices);
  8252. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8253. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8254. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8255. return _this;
  8256. }
  8257. return PlaneBufferGeometry;
  8258. }(BufferGeometry);
  8259. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8260. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8261. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8262. 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";
  8263. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8264. var begin_vertex = "vec3 transformed = vec3( position );";
  8265. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8266. 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";
  8267. 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";
  8268. 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";
  8269. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8270. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8271. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8272. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8273. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8274. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8275. 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";
  8276. 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}";
  8277. 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";
  8278. 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";
  8279. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8280. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8281. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8282. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8283. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8284. 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}";
  8285. 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";
  8286. 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";
  8287. 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";
  8288. 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";
  8289. 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";
  8290. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8291. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8292. 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";
  8293. 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";
  8294. 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}";
  8295. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8296. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8297. 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";
  8298. 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";
  8299. 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";
  8300. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8301. 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)";
  8302. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8303. 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)";
  8304. 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";
  8305. 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}";
  8306. 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";
  8307. 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";
  8308. 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";
  8309. 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";
  8310. 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";
  8311. 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";
  8312. 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";
  8313. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8314. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8315. 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";
  8316. 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";
  8317. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8318. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8319. 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";
  8320. 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";
  8321. 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";
  8322. 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;";
  8323. 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";
  8324. 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";
  8325. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8326. 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";
  8327. 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";
  8328. 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}";
  8329. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8330. 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;";
  8331. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8332. 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";
  8333. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8334. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8335. 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";
  8336. 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";
  8337. 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";
  8338. 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}";
  8339. 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";
  8340. 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";
  8341. 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";
  8342. 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";
  8343. 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";
  8344. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8345. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8346. 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; }";
  8347. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8348. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8349. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8350. 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";
  8351. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8352. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8353. 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";
  8354. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8355. 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";
  8356. 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}";
  8357. 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}";
  8358. 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}";
  8359. 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}";
  8360. 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}";
  8361. 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}";
  8362. 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}";
  8363. 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}";
  8364. 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}";
  8365. 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}";
  8366. 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}";
  8367. 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}";
  8368. 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}";
  8369. 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}";
  8370. 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}";
  8371. 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}";
  8372. 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}";
  8373. 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}";
  8374. 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}";
  8375. 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}";
  8376. 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}";
  8377. 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}";
  8378. 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}";
  8379. 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}";
  8380. 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}";
  8381. 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}";
  8382. 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}";
  8383. 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}";
  8384. 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}";
  8385. 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}";
  8386. 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}";
  8387. 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}";
  8388. var ShaderChunk = {
  8389. alphamap_fragment: alphamap_fragment,
  8390. alphamap_pars_fragment: alphamap_pars_fragment,
  8391. alphatest_fragment: alphatest_fragment,
  8392. aomap_fragment: aomap_fragment,
  8393. aomap_pars_fragment: aomap_pars_fragment,
  8394. begin_vertex: begin_vertex,
  8395. beginnormal_vertex: beginnormal_vertex,
  8396. bsdfs: bsdfs,
  8397. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8398. clipping_planes_fragment: clipping_planes_fragment,
  8399. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8400. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8401. clipping_planes_vertex: clipping_planes_vertex,
  8402. color_fragment: color_fragment,
  8403. color_pars_fragment: color_pars_fragment,
  8404. color_pars_vertex: color_pars_vertex,
  8405. color_vertex: color_vertex,
  8406. common: common,
  8407. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8408. defaultnormal_vertex: defaultnormal_vertex,
  8409. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8410. displacementmap_vertex: displacementmap_vertex,
  8411. emissivemap_fragment: emissivemap_fragment,
  8412. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8413. encodings_fragment: encodings_fragment,
  8414. encodings_pars_fragment: encodings_pars_fragment,
  8415. envmap_fragment: envmap_fragment,
  8416. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8417. envmap_pars_fragment: envmap_pars_fragment,
  8418. envmap_pars_vertex: envmap_pars_vertex,
  8419. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8420. envmap_vertex: envmap_vertex,
  8421. fog_vertex: fog_vertex,
  8422. fog_pars_vertex: fog_pars_vertex,
  8423. fog_fragment: fog_fragment,
  8424. fog_pars_fragment: fog_pars_fragment,
  8425. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8426. lightmap_fragment: lightmap_fragment,
  8427. lightmap_pars_fragment: lightmap_pars_fragment,
  8428. lights_lambert_vertex: lights_lambert_vertex,
  8429. lights_pars_begin: lights_pars_begin,
  8430. lights_toon_fragment: lights_toon_fragment,
  8431. lights_toon_pars_fragment: lights_toon_pars_fragment,
  8432. lights_phong_fragment: lights_phong_fragment,
  8433. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8434. lights_physical_fragment: lights_physical_fragment,
  8435. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8436. lights_fragment_begin: lights_fragment_begin,
  8437. lights_fragment_maps: lights_fragment_maps,
  8438. lights_fragment_end: lights_fragment_end,
  8439. logdepthbuf_fragment: logdepthbuf_fragment,
  8440. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8441. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8442. logdepthbuf_vertex: logdepthbuf_vertex,
  8443. map_fragment: map_fragment,
  8444. map_pars_fragment: map_pars_fragment,
  8445. map_particle_fragment: map_particle_fragment,
  8446. map_particle_pars_fragment: map_particle_pars_fragment,
  8447. metalnessmap_fragment: metalnessmap_fragment,
  8448. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  8449. morphnormal_vertex: morphnormal_vertex,
  8450. morphtarget_pars_vertex: morphtarget_pars_vertex,
  8451. morphtarget_vertex: morphtarget_vertex,
  8452. normal_fragment_begin: normal_fragment_begin,
  8453. normal_fragment_maps: normal_fragment_maps,
  8454. normalmap_pars_fragment: normalmap_pars_fragment,
  8455. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  8456. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  8457. clearcoat_pars_fragment: clearcoat_pars_fragment,
  8458. packing: packing,
  8459. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  8460. project_vertex: project_vertex,
  8461. dithering_fragment: dithering_fragment,
  8462. dithering_pars_fragment: dithering_pars_fragment,
  8463. roughnessmap_fragment: roughnessmap_fragment,
  8464. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  8465. shadowmap_pars_fragment: shadowmap_pars_fragment,
  8466. shadowmap_pars_vertex: shadowmap_pars_vertex,
  8467. shadowmap_vertex: shadowmap_vertex,
  8468. shadowmask_pars_fragment: shadowmask_pars_fragment,
  8469. skinbase_vertex: skinbase_vertex,
  8470. skinning_pars_vertex: skinning_pars_vertex,
  8471. skinning_vertex: skinning_vertex,
  8472. skinnormal_vertex: skinnormal_vertex,
  8473. specularmap_fragment: specularmap_fragment,
  8474. specularmap_pars_fragment: specularmap_pars_fragment,
  8475. tonemapping_fragment: tonemapping_fragment,
  8476. tonemapping_pars_fragment: tonemapping_pars_fragment,
  8477. transmissionmap_fragment: transmissionmap_fragment,
  8478. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  8479. uv_pars_fragment: uv_pars_fragment,
  8480. uv_pars_vertex: uv_pars_vertex,
  8481. uv_vertex: uv_vertex,
  8482. uv2_pars_fragment: uv2_pars_fragment,
  8483. uv2_pars_vertex: uv2_pars_vertex,
  8484. uv2_vertex: uv2_vertex,
  8485. worldpos_vertex: worldpos_vertex,
  8486. background_frag: background_frag,
  8487. background_vert: background_vert,
  8488. cube_frag: cube_frag,
  8489. cube_vert: cube_vert,
  8490. depth_frag: depth_frag,
  8491. depth_vert: depth_vert,
  8492. distanceRGBA_frag: distanceRGBA_frag,
  8493. distanceRGBA_vert: distanceRGBA_vert,
  8494. equirect_frag: equirect_frag,
  8495. equirect_vert: equirect_vert,
  8496. linedashed_frag: linedashed_frag,
  8497. linedashed_vert: linedashed_vert,
  8498. meshbasic_frag: meshbasic_frag,
  8499. meshbasic_vert: meshbasic_vert,
  8500. meshlambert_frag: meshlambert_frag,
  8501. meshlambert_vert: meshlambert_vert,
  8502. meshmatcap_frag: meshmatcap_frag,
  8503. meshmatcap_vert: meshmatcap_vert,
  8504. meshtoon_frag: meshtoon_frag,
  8505. meshtoon_vert: meshtoon_vert,
  8506. meshphong_frag: meshphong_frag,
  8507. meshphong_vert: meshphong_vert,
  8508. meshphysical_frag: meshphysical_frag,
  8509. meshphysical_vert: meshphysical_vert,
  8510. normal_frag: normal_frag,
  8511. normal_vert: normal_vert,
  8512. points_frag: points_frag,
  8513. points_vert: points_vert,
  8514. shadow_frag: shadow_frag,
  8515. shadow_vert: shadow_vert,
  8516. sprite_frag: sprite_frag,
  8517. sprite_vert: sprite_vert
  8518. };
  8519. /**
  8520. * Uniforms library for shared webgl shaders
  8521. */
  8522. var UniformsLib = {
  8523. common: {
  8524. diffuse: {
  8525. value: new Color(0xeeeeee)
  8526. },
  8527. opacity: {
  8528. value: 1.0
  8529. },
  8530. map: {
  8531. value: null
  8532. },
  8533. uvTransform: {
  8534. value: new Matrix3()
  8535. },
  8536. uv2Transform: {
  8537. value: new Matrix3()
  8538. },
  8539. alphaMap: {
  8540. value: null
  8541. }
  8542. },
  8543. specularmap: {
  8544. specularMap: {
  8545. value: null
  8546. }
  8547. },
  8548. envmap: {
  8549. envMap: {
  8550. value: null
  8551. },
  8552. flipEnvMap: {
  8553. value: -1
  8554. },
  8555. reflectivity: {
  8556. value: 1.0
  8557. },
  8558. refractionRatio: {
  8559. value: 0.98
  8560. },
  8561. maxMipLevel: {
  8562. value: 0
  8563. }
  8564. },
  8565. aomap: {
  8566. aoMap: {
  8567. value: null
  8568. },
  8569. aoMapIntensity: {
  8570. value: 1
  8571. }
  8572. },
  8573. lightmap: {
  8574. lightMap: {
  8575. value: null
  8576. },
  8577. lightMapIntensity: {
  8578. value: 1
  8579. }
  8580. },
  8581. emissivemap: {
  8582. emissiveMap: {
  8583. value: null
  8584. }
  8585. },
  8586. bumpmap: {
  8587. bumpMap: {
  8588. value: null
  8589. },
  8590. bumpScale: {
  8591. value: 1
  8592. }
  8593. },
  8594. normalmap: {
  8595. normalMap: {
  8596. value: null
  8597. },
  8598. normalScale: {
  8599. value: new Vector2(1, 1)
  8600. }
  8601. },
  8602. displacementmap: {
  8603. displacementMap: {
  8604. value: null
  8605. },
  8606. displacementScale: {
  8607. value: 1
  8608. },
  8609. displacementBias: {
  8610. value: 0
  8611. }
  8612. },
  8613. roughnessmap: {
  8614. roughnessMap: {
  8615. value: null
  8616. }
  8617. },
  8618. metalnessmap: {
  8619. metalnessMap: {
  8620. value: null
  8621. }
  8622. },
  8623. gradientmap: {
  8624. gradientMap: {
  8625. value: null
  8626. }
  8627. },
  8628. fog: {
  8629. fogDensity: {
  8630. value: 0.00025
  8631. },
  8632. fogNear: {
  8633. value: 1
  8634. },
  8635. fogFar: {
  8636. value: 2000
  8637. },
  8638. fogColor: {
  8639. value: new Color(0xffffff)
  8640. }
  8641. },
  8642. lights: {
  8643. ambientLightColor: {
  8644. value: []
  8645. },
  8646. lightProbe: {
  8647. value: []
  8648. },
  8649. directionalLights: {
  8650. value: [],
  8651. properties: {
  8652. direction: {},
  8653. color: {}
  8654. }
  8655. },
  8656. directionalLightShadows: {
  8657. value: [],
  8658. properties: {
  8659. shadowBias: {},
  8660. shadowNormalBias: {},
  8661. shadowRadius: {},
  8662. shadowMapSize: {}
  8663. }
  8664. },
  8665. directionalShadowMap: {
  8666. value: []
  8667. },
  8668. directionalShadowMatrix: {
  8669. value: []
  8670. },
  8671. spotLights: {
  8672. value: [],
  8673. properties: {
  8674. color: {},
  8675. position: {},
  8676. direction: {},
  8677. distance: {},
  8678. coneCos: {},
  8679. penumbraCos: {},
  8680. decay: {}
  8681. }
  8682. },
  8683. spotLightShadows: {
  8684. value: [],
  8685. properties: {
  8686. shadowBias: {},
  8687. shadowNormalBias: {},
  8688. shadowRadius: {},
  8689. shadowMapSize: {}
  8690. }
  8691. },
  8692. spotShadowMap: {
  8693. value: []
  8694. },
  8695. spotShadowMatrix: {
  8696. value: []
  8697. },
  8698. pointLights: {
  8699. value: [],
  8700. properties: {
  8701. color: {},
  8702. position: {},
  8703. decay: {},
  8704. distance: {}
  8705. }
  8706. },
  8707. pointLightShadows: {
  8708. value: [],
  8709. properties: {
  8710. shadowBias: {},
  8711. shadowNormalBias: {},
  8712. shadowRadius: {},
  8713. shadowMapSize: {},
  8714. shadowCameraNear: {},
  8715. shadowCameraFar: {}
  8716. }
  8717. },
  8718. pointShadowMap: {
  8719. value: []
  8720. },
  8721. pointShadowMatrix: {
  8722. value: []
  8723. },
  8724. hemisphereLights: {
  8725. value: [],
  8726. properties: {
  8727. direction: {},
  8728. skyColor: {},
  8729. groundColor: {}
  8730. }
  8731. },
  8732. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8733. rectAreaLights: {
  8734. value: [],
  8735. properties: {
  8736. color: {},
  8737. position: {},
  8738. width: {},
  8739. height: {}
  8740. }
  8741. },
  8742. ltc_1: {
  8743. value: null
  8744. },
  8745. ltc_2: {
  8746. value: null
  8747. }
  8748. },
  8749. points: {
  8750. diffuse: {
  8751. value: new Color(0xeeeeee)
  8752. },
  8753. opacity: {
  8754. value: 1.0
  8755. },
  8756. size: {
  8757. value: 1.0
  8758. },
  8759. scale: {
  8760. value: 1.0
  8761. },
  8762. map: {
  8763. value: null
  8764. },
  8765. alphaMap: {
  8766. value: null
  8767. },
  8768. uvTransform: {
  8769. value: new Matrix3()
  8770. }
  8771. },
  8772. sprite: {
  8773. diffuse: {
  8774. value: new Color(0xeeeeee)
  8775. },
  8776. opacity: {
  8777. value: 1.0
  8778. },
  8779. center: {
  8780. value: new Vector2(0.5, 0.5)
  8781. },
  8782. rotation: {
  8783. value: 0.0
  8784. },
  8785. map: {
  8786. value: null
  8787. },
  8788. alphaMap: {
  8789. value: null
  8790. },
  8791. uvTransform: {
  8792. value: new Matrix3()
  8793. }
  8794. }
  8795. };
  8796. var ShaderLib = {
  8797. basic: {
  8798. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  8799. vertexShader: ShaderChunk.meshbasic_vert,
  8800. fragmentShader: ShaderChunk.meshbasic_frag
  8801. },
  8802. lambert: {
  8803. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  8804. emissive: {
  8805. value: new Color(0x000000)
  8806. }
  8807. }]),
  8808. vertexShader: ShaderChunk.meshlambert_vert,
  8809. fragmentShader: ShaderChunk.meshlambert_frag
  8810. },
  8811. phong: {
  8812. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  8813. emissive: {
  8814. value: new Color(0x000000)
  8815. },
  8816. specular: {
  8817. value: new Color(0x111111)
  8818. },
  8819. shininess: {
  8820. value: 30
  8821. }
  8822. }]),
  8823. vertexShader: ShaderChunk.meshphong_vert,
  8824. fragmentShader: ShaderChunk.meshphong_frag
  8825. },
  8826. standard: {
  8827. 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, {
  8828. emissive: {
  8829. value: new Color(0x000000)
  8830. },
  8831. roughness: {
  8832. value: 1.0
  8833. },
  8834. metalness: {
  8835. value: 0.0
  8836. },
  8837. envMapIntensity: {
  8838. value: 1
  8839. } // temporary
  8840. }]),
  8841. vertexShader: ShaderChunk.meshphysical_vert,
  8842. fragmentShader: ShaderChunk.meshphysical_frag
  8843. },
  8844. toon: {
  8845. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  8846. emissive: {
  8847. value: new Color(0x000000)
  8848. }
  8849. }]),
  8850. vertexShader: ShaderChunk.meshtoon_vert,
  8851. fragmentShader: ShaderChunk.meshtoon_frag
  8852. },
  8853. matcap: {
  8854. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  8855. matcap: {
  8856. value: null
  8857. }
  8858. }]),
  8859. vertexShader: ShaderChunk.meshmatcap_vert,
  8860. fragmentShader: ShaderChunk.meshmatcap_frag
  8861. },
  8862. points: {
  8863. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  8864. vertexShader: ShaderChunk.points_vert,
  8865. fragmentShader: ShaderChunk.points_frag
  8866. },
  8867. dashed: {
  8868. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  8869. scale: {
  8870. value: 1
  8871. },
  8872. dashSize: {
  8873. value: 1
  8874. },
  8875. totalSize: {
  8876. value: 2
  8877. }
  8878. }]),
  8879. vertexShader: ShaderChunk.linedashed_vert,
  8880. fragmentShader: ShaderChunk.linedashed_frag
  8881. },
  8882. depth: {
  8883. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  8884. vertexShader: ShaderChunk.depth_vert,
  8885. fragmentShader: ShaderChunk.depth_frag
  8886. },
  8887. normal: {
  8888. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  8889. opacity: {
  8890. value: 1.0
  8891. }
  8892. }]),
  8893. vertexShader: ShaderChunk.normal_vert,
  8894. fragmentShader: ShaderChunk.normal_frag
  8895. },
  8896. sprite: {
  8897. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  8898. vertexShader: ShaderChunk.sprite_vert,
  8899. fragmentShader: ShaderChunk.sprite_frag
  8900. },
  8901. background: {
  8902. uniforms: {
  8903. uvTransform: {
  8904. value: new Matrix3()
  8905. },
  8906. t2D: {
  8907. value: null
  8908. }
  8909. },
  8910. vertexShader: ShaderChunk.background_vert,
  8911. fragmentShader: ShaderChunk.background_frag
  8912. },
  8913. /* -------------------------------------------------------------------------
  8914. // Cube map shader
  8915. ------------------------------------------------------------------------- */
  8916. cube: {
  8917. uniforms: mergeUniforms([UniformsLib.envmap, {
  8918. opacity: {
  8919. value: 1.0
  8920. }
  8921. }]),
  8922. vertexShader: ShaderChunk.cube_vert,
  8923. fragmentShader: ShaderChunk.cube_frag
  8924. },
  8925. equirect: {
  8926. uniforms: {
  8927. tEquirect: {
  8928. value: null
  8929. }
  8930. },
  8931. vertexShader: ShaderChunk.equirect_vert,
  8932. fragmentShader: ShaderChunk.equirect_frag
  8933. },
  8934. distanceRGBA: {
  8935. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  8936. referencePosition: {
  8937. value: new Vector3()
  8938. },
  8939. nearDistance: {
  8940. value: 1
  8941. },
  8942. farDistance: {
  8943. value: 1000
  8944. }
  8945. }]),
  8946. vertexShader: ShaderChunk.distanceRGBA_vert,
  8947. fragmentShader: ShaderChunk.distanceRGBA_frag
  8948. },
  8949. shadow: {
  8950. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  8951. color: {
  8952. value: new Color(0x00000)
  8953. },
  8954. opacity: {
  8955. value: 1.0
  8956. }
  8957. }]),
  8958. vertexShader: ShaderChunk.shadow_vert,
  8959. fragmentShader: ShaderChunk.shadow_frag
  8960. }
  8961. };
  8962. ShaderLib.physical = {
  8963. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  8964. clearcoat: {
  8965. value: 0
  8966. },
  8967. clearcoatMap: {
  8968. value: null
  8969. },
  8970. clearcoatRoughness: {
  8971. value: 0
  8972. },
  8973. clearcoatRoughnessMap: {
  8974. value: null
  8975. },
  8976. clearcoatNormalScale: {
  8977. value: new Vector2(1, 1)
  8978. },
  8979. clearcoatNormalMap: {
  8980. value: null
  8981. },
  8982. sheen: {
  8983. value: new Color(0x000000)
  8984. },
  8985. transmission: {
  8986. value: 0
  8987. },
  8988. transmissionMap: {
  8989. value: null
  8990. }
  8991. }]),
  8992. vertexShader: ShaderChunk.meshphysical_vert,
  8993. fragmentShader: ShaderChunk.meshphysical_frag
  8994. };
  8995. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  8996. var clearColor = new Color(0x000000);
  8997. var clearAlpha = 0;
  8998. var planeMesh;
  8999. var boxMesh;
  9000. var currentBackground = null;
  9001. var currentBackgroundVersion = 0;
  9002. var currentTonemapping = null;
  9003. function render(renderList, scene, camera, forceClear) {
  9004. var background = scene.isScene === true ? scene.background : null;
  9005. if (background && background.isTexture) {
  9006. background = cubemaps.get(background);
  9007. } // Ignore background in AR
  9008. // TODO: Reconsider this.
  9009. var xr = renderer.xr;
  9010. var session = xr.getSession && xr.getSession();
  9011. if (session && session.environmentBlendMode === 'additive') {
  9012. background = null;
  9013. }
  9014. if (background === null) {
  9015. setClear(clearColor, clearAlpha);
  9016. } else if (background && background.isColor) {
  9017. setClear(background, 1);
  9018. forceClear = true;
  9019. }
  9020. if (renderer.autoClear || forceClear) {
  9021. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  9022. }
  9023. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  9024. if (boxMesh === undefined) {
  9025. boxMesh = new Mesh(new BoxBufferGeometry(1, 1, 1), new ShaderMaterial({
  9026. name: 'BackgroundCubeMaterial',
  9027. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  9028. vertexShader: ShaderLib.cube.vertexShader,
  9029. fragmentShader: ShaderLib.cube.fragmentShader,
  9030. side: BackSide,
  9031. depthTest: false,
  9032. depthWrite: false,
  9033. fog: false
  9034. }));
  9035. boxMesh.geometry.deleteAttribute('normal');
  9036. boxMesh.geometry.deleteAttribute('uv');
  9037. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  9038. this.matrixWorld.copyPosition(camera.matrixWorld);
  9039. }; // enable code injection for non-built-in material
  9040. Object.defineProperty(boxMesh.material, 'envMap', {
  9041. get: function get() {
  9042. return this.uniforms.envMap.value;
  9043. }
  9044. });
  9045. objects.update(boxMesh);
  9046. }
  9047. if (background.isWebGLCubeRenderTarget) {
  9048. // TODO Deprecate
  9049. background = background.texture;
  9050. }
  9051. boxMesh.material.uniforms.envMap.value = background;
  9052. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  9053. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9054. boxMesh.material.needsUpdate = true;
  9055. currentBackground = background;
  9056. currentBackgroundVersion = background.version;
  9057. currentTonemapping = renderer.toneMapping;
  9058. } // push to the pre-sorted opaque render list
  9059. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  9060. } else if (background && background.isTexture) {
  9061. if (planeMesh === undefined) {
  9062. planeMesh = new Mesh(new PlaneBufferGeometry(2, 2), new ShaderMaterial({
  9063. name: 'BackgroundMaterial',
  9064. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  9065. vertexShader: ShaderLib.background.vertexShader,
  9066. fragmentShader: ShaderLib.background.fragmentShader,
  9067. side: FrontSide,
  9068. depthTest: false,
  9069. depthWrite: false,
  9070. fog: false
  9071. }));
  9072. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9073. Object.defineProperty(planeMesh.material, 'map', {
  9074. get: function get() {
  9075. return this.uniforms.t2D.value;
  9076. }
  9077. });
  9078. objects.update(planeMesh);
  9079. }
  9080. planeMesh.material.uniforms.t2D.value = background;
  9081. if (background.matrixAutoUpdate === true) {
  9082. background.updateMatrix();
  9083. }
  9084. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9085. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9086. planeMesh.material.needsUpdate = true;
  9087. currentBackground = background;
  9088. currentBackgroundVersion = background.version;
  9089. currentTonemapping = renderer.toneMapping;
  9090. } // push to the pre-sorted opaque render list
  9091. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9092. }
  9093. }
  9094. function setClear(color, alpha) {
  9095. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9096. }
  9097. return {
  9098. getClearColor: function getClearColor() {
  9099. return clearColor;
  9100. },
  9101. setClearColor: function setClearColor(color, alpha) {
  9102. clearColor.set(color);
  9103. clearAlpha = alpha !== undefined ? alpha : 1;
  9104. setClear(clearColor, clearAlpha);
  9105. },
  9106. getClearAlpha: function getClearAlpha() {
  9107. return clearAlpha;
  9108. },
  9109. setClearAlpha: function setClearAlpha(alpha) {
  9110. clearAlpha = alpha;
  9111. setClear(clearColor, clearAlpha);
  9112. },
  9113. render: render
  9114. };
  9115. }
  9116. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9117. var maxVertexAttributes = gl.getParameter(34921);
  9118. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9119. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9120. var bindingStates = {};
  9121. var defaultState = createBindingState(null);
  9122. var currentState = defaultState;
  9123. function setup(object, material, program, geometry, index) {
  9124. var updateBuffers = false;
  9125. if (vaoAvailable) {
  9126. var state = getBindingState(geometry, program, material);
  9127. if (currentState !== state) {
  9128. currentState = state;
  9129. bindVertexArrayObject(currentState.object);
  9130. }
  9131. updateBuffers = needsUpdate(geometry, index);
  9132. if (updateBuffers) saveCache(geometry, index);
  9133. } else {
  9134. var wireframe = material.wireframe === true;
  9135. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9136. currentState.geometry = geometry.id;
  9137. currentState.program = program.id;
  9138. currentState.wireframe = wireframe;
  9139. updateBuffers = true;
  9140. }
  9141. }
  9142. if (object.isInstancedMesh === true) {
  9143. updateBuffers = true;
  9144. }
  9145. if (index !== null) {
  9146. attributes.update(index, 34963);
  9147. }
  9148. if (updateBuffers) {
  9149. setupVertexAttributes(object, material, program, geometry);
  9150. if (index !== null) {
  9151. gl.bindBuffer(34963, attributes.get(index).buffer);
  9152. }
  9153. }
  9154. }
  9155. function createVertexArrayObject() {
  9156. if (capabilities.isWebGL2) return gl.createVertexArray();
  9157. return extension.createVertexArrayOES();
  9158. }
  9159. function bindVertexArrayObject(vao) {
  9160. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9161. return extension.bindVertexArrayOES(vao);
  9162. }
  9163. function deleteVertexArrayObject(vao) {
  9164. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9165. return extension.deleteVertexArrayOES(vao);
  9166. }
  9167. function getBindingState(geometry, program, material) {
  9168. var wireframe = material.wireframe === true;
  9169. var programMap = bindingStates[geometry.id];
  9170. if (programMap === undefined) {
  9171. programMap = {};
  9172. bindingStates[geometry.id] = programMap;
  9173. }
  9174. var stateMap = programMap[program.id];
  9175. if (stateMap === undefined) {
  9176. stateMap = {};
  9177. programMap[program.id] = stateMap;
  9178. }
  9179. var state = stateMap[wireframe];
  9180. if (state === undefined) {
  9181. state = createBindingState(createVertexArrayObject());
  9182. stateMap[wireframe] = state;
  9183. }
  9184. return state;
  9185. }
  9186. function createBindingState(vao) {
  9187. var newAttributes = [];
  9188. var enabledAttributes = [];
  9189. var attributeDivisors = [];
  9190. for (var i = 0; i < maxVertexAttributes; i++) {
  9191. newAttributes[i] = 0;
  9192. enabledAttributes[i] = 0;
  9193. attributeDivisors[i] = 0;
  9194. }
  9195. return {
  9196. // for backward compatibility on non-VAO support browser
  9197. geometry: null,
  9198. program: null,
  9199. wireframe: false,
  9200. newAttributes: newAttributes,
  9201. enabledAttributes: enabledAttributes,
  9202. attributeDivisors: attributeDivisors,
  9203. object: vao,
  9204. attributes: {},
  9205. index: null
  9206. };
  9207. }
  9208. function needsUpdate(geometry, index) {
  9209. var cachedAttributes = currentState.attributes;
  9210. var geometryAttributes = geometry.attributes;
  9211. var attributesNum = 0;
  9212. for (var key in geometryAttributes) {
  9213. var cachedAttribute = cachedAttributes[key];
  9214. var geometryAttribute = geometryAttributes[key];
  9215. if (cachedAttribute === undefined) return true;
  9216. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9217. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9218. attributesNum++;
  9219. }
  9220. if (currentState.attributesNum !== attributesNum) return true;
  9221. if (currentState.index !== index) return true;
  9222. return false;
  9223. }
  9224. function saveCache(geometry, index) {
  9225. var cache = {};
  9226. var attributes = geometry.attributes;
  9227. var attributesNum = 0;
  9228. for (var key in attributes) {
  9229. var attribute = attributes[key];
  9230. var data = {};
  9231. data.attribute = attribute;
  9232. if (attribute.data) {
  9233. data.data = attribute.data;
  9234. }
  9235. cache[key] = data;
  9236. attributesNum++;
  9237. }
  9238. currentState.attributes = cache;
  9239. currentState.attributesNum = attributesNum;
  9240. currentState.index = index;
  9241. }
  9242. function initAttributes() {
  9243. var newAttributes = currentState.newAttributes;
  9244. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9245. newAttributes[i] = 0;
  9246. }
  9247. }
  9248. function enableAttribute(attribute) {
  9249. enableAttributeAndDivisor(attribute, 0);
  9250. }
  9251. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9252. var newAttributes = currentState.newAttributes;
  9253. var enabledAttributes = currentState.enabledAttributes;
  9254. var attributeDivisors = currentState.attributeDivisors;
  9255. newAttributes[attribute] = 1;
  9256. if (enabledAttributes[attribute] === 0) {
  9257. gl.enableVertexAttribArray(attribute);
  9258. enabledAttributes[attribute] = 1;
  9259. }
  9260. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9261. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9262. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9263. attributeDivisors[attribute] = meshPerAttribute;
  9264. }
  9265. }
  9266. function disableUnusedAttributes() {
  9267. var newAttributes = currentState.newAttributes;
  9268. var enabledAttributes = currentState.enabledAttributes;
  9269. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9270. if (enabledAttributes[i] !== newAttributes[i]) {
  9271. gl.disableVertexAttribArray(i);
  9272. enabledAttributes[i] = 0;
  9273. }
  9274. }
  9275. }
  9276. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9277. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9278. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9279. } else {
  9280. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9281. }
  9282. }
  9283. function setupVertexAttributes(object, material, program, geometry) {
  9284. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9285. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9286. }
  9287. initAttributes();
  9288. var geometryAttributes = geometry.attributes;
  9289. var programAttributes = program.getAttributes();
  9290. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9291. for (var name in programAttributes) {
  9292. var programAttribute = programAttributes[name];
  9293. if (programAttribute >= 0) {
  9294. var geometryAttribute = geometryAttributes[name];
  9295. if (geometryAttribute !== undefined) {
  9296. var normalized = geometryAttribute.normalized;
  9297. var size = geometryAttribute.itemSize;
  9298. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9299. if (attribute === undefined) continue;
  9300. var buffer = attribute.buffer;
  9301. var type = attribute.type;
  9302. var bytesPerElement = attribute.bytesPerElement;
  9303. if (geometryAttribute.isInterleavedBufferAttribute) {
  9304. var data = geometryAttribute.data;
  9305. var stride = data.stride;
  9306. var offset = geometryAttribute.offset;
  9307. if (data && data.isInstancedInterleavedBuffer) {
  9308. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9309. if (geometry._maxInstanceCount === undefined) {
  9310. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9311. }
  9312. } else {
  9313. enableAttribute(programAttribute);
  9314. }
  9315. gl.bindBuffer(34962, buffer);
  9316. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9317. } else {
  9318. if (geometryAttribute.isInstancedBufferAttribute) {
  9319. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9320. if (geometry._maxInstanceCount === undefined) {
  9321. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9322. }
  9323. } else {
  9324. enableAttribute(programAttribute);
  9325. }
  9326. gl.bindBuffer(34962, buffer);
  9327. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9328. }
  9329. } else if (name === 'instanceMatrix') {
  9330. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9331. if (_attribute === undefined) continue;
  9332. var _buffer = _attribute.buffer;
  9333. var _type = _attribute.type;
  9334. enableAttributeAndDivisor(programAttribute + 0, 1);
  9335. enableAttributeAndDivisor(programAttribute + 1, 1);
  9336. enableAttributeAndDivisor(programAttribute + 2, 1);
  9337. enableAttributeAndDivisor(programAttribute + 3, 1);
  9338. gl.bindBuffer(34962, _buffer);
  9339. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9340. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9341. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9342. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9343. } else if (name === 'instanceColor') {
  9344. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9345. if (_attribute2 === undefined) continue;
  9346. var _buffer2 = _attribute2.buffer;
  9347. var _type2 = _attribute2.type;
  9348. enableAttributeAndDivisor(programAttribute, 1);
  9349. gl.bindBuffer(34962, _buffer2);
  9350. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9351. } else if (materialDefaultAttributeValues !== undefined) {
  9352. var value = materialDefaultAttributeValues[name];
  9353. if (value !== undefined) {
  9354. switch (value.length) {
  9355. case 2:
  9356. gl.vertexAttrib2fv(programAttribute, value);
  9357. break;
  9358. case 3:
  9359. gl.vertexAttrib3fv(programAttribute, value);
  9360. break;
  9361. case 4:
  9362. gl.vertexAttrib4fv(programAttribute, value);
  9363. break;
  9364. default:
  9365. gl.vertexAttrib1fv(programAttribute, value);
  9366. }
  9367. }
  9368. }
  9369. }
  9370. }
  9371. disableUnusedAttributes();
  9372. }
  9373. function dispose() {
  9374. reset();
  9375. for (var geometryId in bindingStates) {
  9376. var programMap = bindingStates[geometryId];
  9377. for (var programId in programMap) {
  9378. var stateMap = programMap[programId];
  9379. for (var wireframe in stateMap) {
  9380. deleteVertexArrayObject(stateMap[wireframe].object);
  9381. delete stateMap[wireframe];
  9382. }
  9383. delete programMap[programId];
  9384. }
  9385. delete bindingStates[geometryId];
  9386. }
  9387. }
  9388. function releaseStatesOfGeometry(geometry) {
  9389. if (bindingStates[geometry.id] === undefined) return;
  9390. var programMap = bindingStates[geometry.id];
  9391. for (var programId in programMap) {
  9392. var stateMap = programMap[programId];
  9393. for (var wireframe in stateMap) {
  9394. deleteVertexArrayObject(stateMap[wireframe].object);
  9395. delete stateMap[wireframe];
  9396. }
  9397. delete programMap[programId];
  9398. }
  9399. delete bindingStates[geometry.id];
  9400. }
  9401. function releaseStatesOfProgram(program) {
  9402. for (var geometryId in bindingStates) {
  9403. var programMap = bindingStates[geometryId];
  9404. if (programMap[program.id] === undefined) continue;
  9405. var stateMap = programMap[program.id];
  9406. for (var wireframe in stateMap) {
  9407. deleteVertexArrayObject(stateMap[wireframe].object);
  9408. delete stateMap[wireframe];
  9409. }
  9410. delete programMap[program.id];
  9411. }
  9412. }
  9413. function reset() {
  9414. resetDefaultState();
  9415. if (currentState === defaultState) return;
  9416. currentState = defaultState;
  9417. bindVertexArrayObject(currentState.object);
  9418. } // for backward-compatilibity
  9419. function resetDefaultState() {
  9420. defaultState.geometry = null;
  9421. defaultState.program = null;
  9422. defaultState.wireframe = false;
  9423. }
  9424. return {
  9425. setup: setup,
  9426. reset: reset,
  9427. resetDefaultState: resetDefaultState,
  9428. dispose: dispose,
  9429. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9430. releaseStatesOfProgram: releaseStatesOfProgram,
  9431. initAttributes: initAttributes,
  9432. enableAttribute: enableAttribute,
  9433. disableUnusedAttributes: disableUnusedAttributes
  9434. };
  9435. }
  9436. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  9437. var isWebGL2 = capabilities.isWebGL2;
  9438. var mode;
  9439. function setMode(value) {
  9440. mode = value;
  9441. }
  9442. function render(start, count) {
  9443. gl.drawArrays(mode, start, count);
  9444. info.update(count, mode, 1);
  9445. }
  9446. function renderInstances(start, count, primcount) {
  9447. if (primcount === 0) return;
  9448. var extension, methodName;
  9449. if (isWebGL2) {
  9450. extension = gl;
  9451. methodName = 'drawArraysInstanced';
  9452. } else {
  9453. extension = extensions.get('ANGLE_instanced_arrays');
  9454. methodName = 'drawArraysInstancedANGLE';
  9455. if (extension === null) {
  9456. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9457. return;
  9458. }
  9459. }
  9460. extension[methodName](mode, start, count, primcount);
  9461. info.update(count, mode, primcount);
  9462. } //
  9463. this.setMode = setMode;
  9464. this.render = render;
  9465. this.renderInstances = renderInstances;
  9466. }
  9467. function WebGLCapabilities(gl, extensions, parameters) {
  9468. var maxAnisotropy;
  9469. function getMaxAnisotropy() {
  9470. if (maxAnisotropy !== undefined) return maxAnisotropy;
  9471. var extension = extensions.get('EXT_texture_filter_anisotropic');
  9472. if (extension !== null) {
  9473. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  9474. } else {
  9475. maxAnisotropy = 0;
  9476. }
  9477. return maxAnisotropy;
  9478. }
  9479. function getMaxPrecision(precision) {
  9480. if (precision === 'highp') {
  9481. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  9482. return 'highp';
  9483. }
  9484. precision = 'mediump';
  9485. }
  9486. if (precision === 'mediump') {
  9487. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  9488. return 'mediump';
  9489. }
  9490. }
  9491. return 'lowp';
  9492. }
  9493. /* eslint-disable no-undef */
  9494. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  9495. /* eslint-enable no-undef */
  9496. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9497. var maxPrecision = getMaxPrecision(precision);
  9498. if (maxPrecision !== precision) {
  9499. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  9500. precision = maxPrecision;
  9501. }
  9502. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9503. var maxTextures = gl.getParameter(34930);
  9504. var maxVertexTextures = gl.getParameter(35660);
  9505. var maxTextureSize = gl.getParameter(3379);
  9506. var maxCubemapSize = gl.getParameter(34076);
  9507. var maxAttributes = gl.getParameter(34921);
  9508. var maxVertexUniforms = gl.getParameter(36347);
  9509. var maxVaryings = gl.getParameter(36348);
  9510. var maxFragmentUniforms = gl.getParameter(36349);
  9511. var vertexTextures = maxVertexTextures > 0;
  9512. var floatFragmentTextures = isWebGL2 || !!extensions.get('OES_texture_float');
  9513. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9514. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  9515. return {
  9516. isWebGL2: isWebGL2,
  9517. getMaxAnisotropy: getMaxAnisotropy,
  9518. getMaxPrecision: getMaxPrecision,
  9519. precision: precision,
  9520. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9521. maxTextures: maxTextures,
  9522. maxVertexTextures: maxVertexTextures,
  9523. maxTextureSize: maxTextureSize,
  9524. maxCubemapSize: maxCubemapSize,
  9525. maxAttributes: maxAttributes,
  9526. maxVertexUniforms: maxVertexUniforms,
  9527. maxVaryings: maxVaryings,
  9528. maxFragmentUniforms: maxFragmentUniforms,
  9529. vertexTextures: vertexTextures,
  9530. floatFragmentTextures: floatFragmentTextures,
  9531. floatVertexTextures: floatVertexTextures,
  9532. maxSamples: maxSamples
  9533. };
  9534. }
  9535. function WebGLClipping(properties) {
  9536. var scope = this;
  9537. var globalState = null,
  9538. numGlobalPlanes = 0,
  9539. localClippingEnabled = false,
  9540. renderingShadows = false;
  9541. var plane = new Plane(),
  9542. viewNormalMatrix = new Matrix3(),
  9543. uniform = {
  9544. value: null,
  9545. needsUpdate: false
  9546. };
  9547. this.uniform = uniform;
  9548. this.numPlanes = 0;
  9549. this.numIntersection = 0;
  9550. this.init = function (planes, enableLocalClipping, camera) {
  9551. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  9552. // run another frame in order to reset the state:
  9553. numGlobalPlanes !== 0 || localClippingEnabled;
  9554. localClippingEnabled = enableLocalClipping;
  9555. globalState = projectPlanes(planes, camera, 0);
  9556. numGlobalPlanes = planes.length;
  9557. return enabled;
  9558. };
  9559. this.beginShadows = function () {
  9560. renderingShadows = true;
  9561. projectPlanes(null);
  9562. };
  9563. this.endShadows = function () {
  9564. renderingShadows = false;
  9565. resetGlobalState();
  9566. };
  9567. this.setState = function (material, camera, useCache) {
  9568. var planes = material.clippingPlanes,
  9569. clipIntersection = material.clipIntersection,
  9570. clipShadows = material.clipShadows;
  9571. var materialProperties = properties.get(material);
  9572. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  9573. // there's no local clipping
  9574. if (renderingShadows) {
  9575. // there's no global clipping
  9576. projectPlanes(null);
  9577. } else {
  9578. resetGlobalState();
  9579. }
  9580. } else {
  9581. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9582. lGlobal = nGlobal * 4;
  9583. var dstArray = materialProperties.clippingState || null;
  9584. uniform.value = dstArray; // ensure unique state
  9585. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  9586. for (var i = 0; i !== lGlobal; ++i) {
  9587. dstArray[i] = globalState[i];
  9588. }
  9589. materialProperties.clippingState = dstArray;
  9590. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9591. this.numPlanes += nGlobal;
  9592. }
  9593. };
  9594. function resetGlobalState() {
  9595. if (uniform.value !== globalState) {
  9596. uniform.value = globalState;
  9597. uniform.needsUpdate = numGlobalPlanes > 0;
  9598. }
  9599. scope.numPlanes = numGlobalPlanes;
  9600. scope.numIntersection = 0;
  9601. }
  9602. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  9603. var nPlanes = planes !== null ? planes.length : 0;
  9604. var dstArray = null;
  9605. if (nPlanes !== 0) {
  9606. dstArray = uniform.value;
  9607. if (skipTransform !== true || dstArray === null) {
  9608. var flatSize = dstOffset + nPlanes * 4,
  9609. viewMatrix = camera.matrixWorldInverse;
  9610. viewNormalMatrix.getNormalMatrix(viewMatrix);
  9611. if (dstArray === null || dstArray.length < flatSize) {
  9612. dstArray = new Float32Array(flatSize);
  9613. }
  9614. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  9615. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  9616. plane.normal.toArray(dstArray, i4);
  9617. dstArray[i4 + 3] = plane.constant;
  9618. }
  9619. }
  9620. uniform.value = dstArray;
  9621. uniform.needsUpdate = true;
  9622. }
  9623. scope.numPlanes = nPlanes;
  9624. scope.numIntersection = 0;
  9625. return dstArray;
  9626. }
  9627. }
  9628. function WebGLCubeMaps(renderer) {
  9629. var cubemaps = new WeakMap();
  9630. function mapTextureMapping(texture, mapping) {
  9631. if (mapping === EquirectangularReflectionMapping) {
  9632. texture.mapping = CubeReflectionMapping;
  9633. } else if (mapping === EquirectangularRefractionMapping) {
  9634. texture.mapping = CubeRefractionMapping;
  9635. }
  9636. return texture;
  9637. }
  9638. function get(texture) {
  9639. if (texture && texture.isTexture) {
  9640. var mapping = texture.mapping;
  9641. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  9642. if (cubemaps.has(texture)) {
  9643. var cubemap = cubemaps.get(texture).texture;
  9644. return mapTextureMapping(cubemap, texture.mapping);
  9645. } else {
  9646. var image = texture.image;
  9647. if (image && image.height > 0) {
  9648. var currentRenderList = renderer.getRenderList();
  9649. var currentRenderTarget = renderer.getRenderTarget();
  9650. var currentRenderState = renderer.getRenderState();
  9651. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  9652. renderTarget.fromEquirectangularTexture(renderer, texture);
  9653. cubemaps.set(texture, renderTarget);
  9654. renderer.setRenderTarget(currentRenderTarget);
  9655. renderer.setRenderList(currentRenderList);
  9656. renderer.setRenderState(currentRenderState);
  9657. texture.addEventListener('dispose', onTextureDispose);
  9658. return mapTextureMapping(renderTarget.texture, texture.mapping);
  9659. } else {
  9660. // image not yet ready. try the conversion next frame
  9661. return null;
  9662. }
  9663. }
  9664. }
  9665. }
  9666. return texture;
  9667. }
  9668. function onTextureDispose(event) {
  9669. var texture = event.target;
  9670. texture.removeEventListener('dispose', onTextureDispose);
  9671. var cubemap = cubemaps.get(texture);
  9672. if (cubemap !== undefined) {
  9673. cubemaps.delete(texture);
  9674. cubemap.dispose();
  9675. }
  9676. }
  9677. function dispose() {
  9678. cubemaps = new WeakMap();
  9679. }
  9680. return {
  9681. get: get,
  9682. dispose: dispose
  9683. };
  9684. }
  9685. function WebGLExtensions(gl) {
  9686. var extensions = {};
  9687. return {
  9688. has: function has(name) {
  9689. if (extensions[name] !== undefined) {
  9690. return extensions[name] !== null;
  9691. }
  9692. var extension;
  9693. switch (name) {
  9694. case 'WEBGL_depth_texture':
  9695. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  9696. break;
  9697. case 'EXT_texture_filter_anisotropic':
  9698. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  9699. break;
  9700. case 'WEBGL_compressed_texture_s3tc':
  9701. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  9702. break;
  9703. case 'WEBGL_compressed_texture_pvrtc':
  9704. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  9705. break;
  9706. default:
  9707. extension = gl.getExtension(name);
  9708. }
  9709. extensions[name] = extension;
  9710. return extension !== null;
  9711. },
  9712. get: function get(name) {
  9713. if (!this.has(name)) {
  9714. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  9715. }
  9716. return extensions[name];
  9717. }
  9718. };
  9719. }
  9720. function WebGLGeometries(gl, attributes, info, bindingStates) {
  9721. var geometries = new WeakMap();
  9722. var wireframeAttributes = new WeakMap();
  9723. function onGeometryDispose(event) {
  9724. var geometry = event.target;
  9725. var buffergeometry = geometries.get(geometry);
  9726. if (buffergeometry.index !== null) {
  9727. attributes.remove(buffergeometry.index);
  9728. }
  9729. for (var name in buffergeometry.attributes) {
  9730. attributes.remove(buffergeometry.attributes[name]);
  9731. }
  9732. geometry.removeEventListener('dispose', onGeometryDispose);
  9733. geometries.delete(geometry);
  9734. var attribute = wireframeAttributes.get(buffergeometry);
  9735. if (attribute) {
  9736. attributes.remove(attribute);
  9737. wireframeAttributes.delete(buffergeometry);
  9738. }
  9739. bindingStates.releaseStatesOfGeometry(buffergeometry);
  9740. if (geometry.isInstancedBufferGeometry === true) {
  9741. delete geometry._maxInstanceCount;
  9742. } //
  9743. info.memory.geometries--;
  9744. }
  9745. function get(object, geometry) {
  9746. var buffergeometry = geometries.get(geometry);
  9747. if (buffergeometry) return buffergeometry;
  9748. geometry.addEventListener('dispose', onGeometryDispose);
  9749. if (geometry.isBufferGeometry) {
  9750. buffergeometry = geometry;
  9751. } else if (geometry.isGeometry) {
  9752. if (geometry._bufferGeometry === undefined) {
  9753. geometry._bufferGeometry = new BufferGeometry().setFromObject(object);
  9754. }
  9755. buffergeometry = geometry._bufferGeometry;
  9756. }
  9757. geometries.set(geometry, buffergeometry);
  9758. info.memory.geometries++;
  9759. return buffergeometry;
  9760. }
  9761. function update(geometry) {
  9762. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  9763. for (var name in geometryAttributes) {
  9764. attributes.update(geometryAttributes[name], 34962);
  9765. } // morph targets
  9766. var morphAttributes = geometry.morphAttributes;
  9767. for (var _name in morphAttributes) {
  9768. var array = morphAttributes[_name];
  9769. for (var i = 0, l = array.length; i < l; i++) {
  9770. attributes.update(array[i], 34962);
  9771. }
  9772. }
  9773. }
  9774. function updateWireframeAttribute(geometry) {
  9775. var indices = [];
  9776. var geometryIndex = geometry.index;
  9777. var geometryPosition = geometry.attributes.position;
  9778. var version = 0;
  9779. if (geometryIndex !== null) {
  9780. var array = geometryIndex.array;
  9781. version = geometryIndex.version;
  9782. for (var i = 0, l = array.length; i < l; i += 3) {
  9783. var a = array[i + 0];
  9784. var b = array[i + 1];
  9785. var c = array[i + 2];
  9786. indices.push(a, b, b, c, c, a);
  9787. }
  9788. } else {
  9789. var _array = geometryPosition.array;
  9790. version = geometryPosition.version;
  9791. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  9792. var _a = _i + 0;
  9793. var _b = _i + 1;
  9794. var _c = _i + 2;
  9795. indices.push(_a, _b, _b, _c, _c, _a);
  9796. }
  9797. }
  9798. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  9799. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  9800. //
  9801. var previousAttribute = wireframeAttributes.get(geometry);
  9802. if (previousAttribute) attributes.remove(previousAttribute); //
  9803. wireframeAttributes.set(geometry, attribute);
  9804. }
  9805. function getWireframeAttribute(geometry) {
  9806. var currentAttribute = wireframeAttributes.get(geometry);
  9807. if (currentAttribute) {
  9808. var geometryIndex = geometry.index;
  9809. if (geometryIndex !== null) {
  9810. // if the attribute is obsolete, create a new one
  9811. if (currentAttribute.version < geometryIndex.version) {
  9812. updateWireframeAttribute(geometry);
  9813. }
  9814. }
  9815. } else {
  9816. updateWireframeAttribute(geometry);
  9817. }
  9818. return wireframeAttributes.get(geometry);
  9819. }
  9820. return {
  9821. get: get,
  9822. update: update,
  9823. getWireframeAttribute: getWireframeAttribute
  9824. };
  9825. }
  9826. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  9827. var isWebGL2 = capabilities.isWebGL2;
  9828. var mode;
  9829. function setMode(value) {
  9830. mode = value;
  9831. }
  9832. var type, bytesPerElement;
  9833. function setIndex(value) {
  9834. type = value.type;
  9835. bytesPerElement = value.bytesPerElement;
  9836. }
  9837. function render(start, count) {
  9838. gl.drawElements(mode, count, type, start * bytesPerElement);
  9839. info.update(count, mode, 1);
  9840. }
  9841. function renderInstances(start, count, primcount) {
  9842. if (primcount === 0) return;
  9843. var extension, methodName;
  9844. if (isWebGL2) {
  9845. extension = gl;
  9846. methodName = 'drawElementsInstanced';
  9847. } else {
  9848. extension = extensions.get('ANGLE_instanced_arrays');
  9849. methodName = 'drawElementsInstancedANGLE';
  9850. if (extension === null) {
  9851. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9852. return;
  9853. }
  9854. }
  9855. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  9856. info.update(count, mode, primcount);
  9857. } //
  9858. this.setMode = setMode;
  9859. this.setIndex = setIndex;
  9860. this.render = render;
  9861. this.renderInstances = renderInstances;
  9862. }
  9863. function WebGLInfo(gl) {
  9864. var memory = {
  9865. geometries: 0,
  9866. textures: 0
  9867. };
  9868. var render = {
  9869. frame: 0,
  9870. calls: 0,
  9871. triangles: 0,
  9872. points: 0,
  9873. lines: 0
  9874. };
  9875. function update(count, mode, instanceCount) {
  9876. render.calls++;
  9877. switch (mode) {
  9878. case 4:
  9879. render.triangles += instanceCount * (count / 3);
  9880. break;
  9881. case 1:
  9882. render.lines += instanceCount * (count / 2);
  9883. break;
  9884. case 3:
  9885. render.lines += instanceCount * (count - 1);
  9886. break;
  9887. case 2:
  9888. render.lines += instanceCount * count;
  9889. break;
  9890. case 0:
  9891. render.points += instanceCount * count;
  9892. break;
  9893. default:
  9894. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  9895. break;
  9896. }
  9897. }
  9898. function reset() {
  9899. render.frame++;
  9900. render.calls = 0;
  9901. render.triangles = 0;
  9902. render.points = 0;
  9903. render.lines = 0;
  9904. }
  9905. return {
  9906. memory: memory,
  9907. render: render,
  9908. programs: null,
  9909. autoReset: true,
  9910. reset: reset,
  9911. update: update
  9912. };
  9913. }
  9914. function numericalSort(a, b) {
  9915. return a[0] - b[0];
  9916. }
  9917. function absNumericalSort(a, b) {
  9918. return Math.abs(b[1]) - Math.abs(a[1]);
  9919. }
  9920. function WebGLMorphtargets(gl) {
  9921. var influencesList = {};
  9922. var morphInfluences = new Float32Array(8);
  9923. var workInfluences = [];
  9924. for (var i = 0; i < 8; i++) {
  9925. workInfluences[i] = [i, 0];
  9926. }
  9927. function update(object, geometry, material, program) {
  9928. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  9929. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  9930. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  9931. var influences = influencesList[geometry.id];
  9932. if (influences === undefined) {
  9933. // initialise list
  9934. influences = [];
  9935. for (var _i = 0; _i < length; _i++) {
  9936. influences[_i] = [_i, 0];
  9937. }
  9938. influencesList[geometry.id] = influences;
  9939. } // Collect influences
  9940. for (var _i2 = 0; _i2 < length; _i2++) {
  9941. var influence = influences[_i2];
  9942. influence[0] = _i2;
  9943. influence[1] = objectInfluences[_i2];
  9944. }
  9945. influences.sort(absNumericalSort);
  9946. for (var _i3 = 0; _i3 < 8; _i3++) {
  9947. if (_i3 < length && influences[_i3][1]) {
  9948. workInfluences[_i3][0] = influences[_i3][0];
  9949. workInfluences[_i3][1] = influences[_i3][1];
  9950. } else {
  9951. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  9952. workInfluences[_i3][1] = 0;
  9953. }
  9954. }
  9955. workInfluences.sort(numericalSort);
  9956. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9957. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9958. var morphInfluencesSum = 0;
  9959. for (var _i4 = 0; _i4 < 8; _i4++) {
  9960. var _influence = workInfluences[_i4];
  9961. var index = _influence[0];
  9962. var value = _influence[1];
  9963. if (index !== Number.MAX_SAFE_INTEGER && value) {
  9964. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  9965. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  9966. }
  9967. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  9968. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  9969. }
  9970. morphInfluences[_i4] = value;
  9971. morphInfluencesSum += value;
  9972. } else {
  9973. if (morphTargets && geometry.hasAttribute('morphTarget' + _i4) === true) {
  9974. geometry.deleteAttribute('morphTarget' + _i4);
  9975. }
  9976. if (morphNormals && geometry.hasAttribute('morphNormal' + _i4) === true) {
  9977. geometry.deleteAttribute('morphNormal' + _i4);
  9978. }
  9979. morphInfluences[_i4] = 0;
  9980. }
  9981. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  9982. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  9983. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  9984. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  9985. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  9986. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  9987. }
  9988. return {
  9989. update: update
  9990. };
  9991. }
  9992. function WebGLObjects(gl, geometries, attributes, info) {
  9993. var updateMap = new WeakMap();
  9994. function update(object) {
  9995. var frame = info.render.frame;
  9996. var geometry = object.geometry;
  9997. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  9998. if (updateMap.get(buffergeometry) !== frame) {
  9999. if (geometry.isGeometry) {
  10000. buffergeometry.updateFromObject(object);
  10001. }
  10002. geometries.update(buffergeometry);
  10003. updateMap.set(buffergeometry, frame);
  10004. }
  10005. if (object.isInstancedMesh) {
  10006. attributes.update(object.instanceMatrix, 34962);
  10007. if (object.instanceColor !== null) {
  10008. attributes.update(object.instanceColor, 34962);
  10009. }
  10010. }
  10011. return buffergeometry;
  10012. }
  10013. function dispose() {
  10014. updateMap = new WeakMap();
  10015. }
  10016. return {
  10017. update: update,
  10018. dispose: dispose
  10019. };
  10020. }
  10021. function DataTexture2DArray(data, width, height, depth) {
  10022. Texture.call(this, null);
  10023. this.image = {
  10024. data: data || null,
  10025. width: width || 1,
  10026. height: height || 1,
  10027. depth: depth || 1
  10028. };
  10029. this.magFilter = NearestFilter;
  10030. this.minFilter = NearestFilter;
  10031. this.wrapR = ClampToEdgeWrapping;
  10032. this.generateMipmaps = false;
  10033. this.flipY = false;
  10034. this.needsUpdate = true;
  10035. }
  10036. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  10037. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10038. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10039. function DataTexture3D(data, width, height, depth) {
  10040. // We're going to add .setXXX() methods for setting properties later.
  10041. // Users can still set in DataTexture3D directly.
  10042. //
  10043. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10044. // texture.anisotropy = 16;
  10045. //
  10046. // See #14839
  10047. Texture.call(this, null);
  10048. this.image = {
  10049. data: data || null,
  10050. width: width || 1,
  10051. height: height || 1,
  10052. depth: depth || 1
  10053. };
  10054. this.magFilter = NearestFilter;
  10055. this.minFilter = NearestFilter;
  10056. this.wrapR = ClampToEdgeWrapping;
  10057. this.generateMipmaps = false;
  10058. this.flipY = false;
  10059. this.needsUpdate = true;
  10060. }
  10061. DataTexture3D.prototype = Object.create(Texture.prototype);
  10062. DataTexture3D.prototype.constructor = DataTexture3D;
  10063. DataTexture3D.prototype.isDataTexture3D = true;
  10064. /**
  10065. * Uniforms of a program.
  10066. * Those form a tree structure with a special top-level container for the root,
  10067. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10068. *
  10069. *
  10070. * Properties of inner nodes including the top-level container:
  10071. *
  10072. * .seq - array of nested uniforms
  10073. * .map - nested uniforms by name
  10074. *
  10075. *
  10076. * Methods of all nodes except the top-level container:
  10077. *
  10078. * .setValue( gl, value, [textures] )
  10079. *
  10080. * uploads a uniform value(s)
  10081. * the 'textures' parameter is needed for sampler uniforms
  10082. *
  10083. *
  10084. * Static methods of the top-level container (textures factorizations):
  10085. *
  10086. * .upload( gl, seq, values, textures )
  10087. *
  10088. * sets uniforms in 'seq' to 'values[id].value'
  10089. *
  10090. * .seqWithValue( seq, values ) : filteredSeq
  10091. *
  10092. * filters 'seq' entries with corresponding entry in values
  10093. *
  10094. *
  10095. * Methods of the top-level container (textures factorizations):
  10096. *
  10097. * .setValue( gl, name, value, textures )
  10098. *
  10099. * sets uniform with name 'name' to 'value'
  10100. *
  10101. * .setOptional( gl, obj, prop )
  10102. *
  10103. * like .set for an optional property of the object
  10104. *
  10105. */
  10106. var emptyTexture = new Texture();
  10107. var emptyTexture2dArray = new DataTexture2DArray();
  10108. var emptyTexture3d = new DataTexture3D();
  10109. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10110. // Array Caches (provide typed arrays for temporary by size)
  10111. var arrayCacheF32 = [];
  10112. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10113. var mat4array = new Float32Array(16);
  10114. var mat3array = new Float32Array(9);
  10115. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10116. function flatten(array, nBlocks, blockSize) {
  10117. var firstElem = array[0];
  10118. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10119. // see http://jacksondunstan.com/articles/983
  10120. var n = nBlocks * blockSize;
  10121. var r = arrayCacheF32[n];
  10122. if (r === undefined) {
  10123. r = new Float32Array(n);
  10124. arrayCacheF32[n] = r;
  10125. }
  10126. if (nBlocks !== 0) {
  10127. firstElem.toArray(r, 0);
  10128. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10129. offset += blockSize;
  10130. array[i].toArray(r, offset);
  10131. }
  10132. }
  10133. return r;
  10134. }
  10135. function arraysEqual(a, b) {
  10136. if (a.length !== b.length) return false;
  10137. for (var i = 0, l = a.length; i < l; i++) {
  10138. if (a[i] !== b[i]) return false;
  10139. }
  10140. return true;
  10141. }
  10142. function copyArray(a, b) {
  10143. for (var i = 0, l = b.length; i < l; i++) {
  10144. a[i] = b[i];
  10145. }
  10146. } // Texture unit allocation
  10147. function allocTexUnits(textures, n) {
  10148. var r = arrayCacheI32[n];
  10149. if (r === undefined) {
  10150. r = new Int32Array(n);
  10151. arrayCacheI32[n] = r;
  10152. }
  10153. for (var i = 0; i !== n; ++i) {
  10154. r[i] = textures.allocateTextureUnit();
  10155. }
  10156. return r;
  10157. } // --- Setters ---
  10158. // Note: Defining these methods externally, because they come in a bunch
  10159. // and this way their names minify.
  10160. // Single scalar
  10161. function setValueV1f(gl, v) {
  10162. var cache = this.cache;
  10163. if (cache[0] === v) return;
  10164. gl.uniform1f(this.addr, v);
  10165. cache[0] = v;
  10166. } // Single float vector (from flat array or THREE.VectorN)
  10167. function setValueV2f(gl, v) {
  10168. var cache = this.cache;
  10169. if (v.x !== undefined) {
  10170. if (cache[0] !== v.x || cache[1] !== v.y) {
  10171. gl.uniform2f(this.addr, v.x, v.y);
  10172. cache[0] = v.x;
  10173. cache[1] = v.y;
  10174. }
  10175. } else {
  10176. if (arraysEqual(cache, v)) return;
  10177. gl.uniform2fv(this.addr, v);
  10178. copyArray(cache, v);
  10179. }
  10180. }
  10181. function setValueV3f(gl, v) {
  10182. var cache = this.cache;
  10183. if (v.x !== undefined) {
  10184. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10185. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10186. cache[0] = v.x;
  10187. cache[1] = v.y;
  10188. cache[2] = v.z;
  10189. }
  10190. } else if (v.r !== undefined) {
  10191. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10192. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10193. cache[0] = v.r;
  10194. cache[1] = v.g;
  10195. cache[2] = v.b;
  10196. }
  10197. } else {
  10198. if (arraysEqual(cache, v)) return;
  10199. gl.uniform3fv(this.addr, v);
  10200. copyArray(cache, v);
  10201. }
  10202. }
  10203. function setValueV4f(gl, v) {
  10204. var cache = this.cache;
  10205. if (v.x !== undefined) {
  10206. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10207. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10208. cache[0] = v.x;
  10209. cache[1] = v.y;
  10210. cache[2] = v.z;
  10211. cache[3] = v.w;
  10212. }
  10213. } else {
  10214. if (arraysEqual(cache, v)) return;
  10215. gl.uniform4fv(this.addr, v);
  10216. copyArray(cache, v);
  10217. }
  10218. } // Single matrix (from flat array or MatrixN)
  10219. function setValueM2(gl, v) {
  10220. var cache = this.cache;
  10221. var elements = v.elements;
  10222. if (elements === undefined) {
  10223. if (arraysEqual(cache, v)) return;
  10224. gl.uniformMatrix2fv(this.addr, false, v);
  10225. copyArray(cache, v);
  10226. } else {
  10227. if (arraysEqual(cache, elements)) return;
  10228. mat2array.set(elements);
  10229. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10230. copyArray(cache, elements);
  10231. }
  10232. }
  10233. function setValueM3(gl, v) {
  10234. var cache = this.cache;
  10235. var elements = v.elements;
  10236. if (elements === undefined) {
  10237. if (arraysEqual(cache, v)) return;
  10238. gl.uniformMatrix3fv(this.addr, false, v);
  10239. copyArray(cache, v);
  10240. } else {
  10241. if (arraysEqual(cache, elements)) return;
  10242. mat3array.set(elements);
  10243. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10244. copyArray(cache, elements);
  10245. }
  10246. }
  10247. function setValueM4(gl, v) {
  10248. var cache = this.cache;
  10249. var elements = v.elements;
  10250. if (elements === undefined) {
  10251. if (arraysEqual(cache, v)) return;
  10252. gl.uniformMatrix4fv(this.addr, false, v);
  10253. copyArray(cache, v);
  10254. } else {
  10255. if (arraysEqual(cache, elements)) return;
  10256. mat4array.set(elements);
  10257. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10258. copyArray(cache, elements);
  10259. }
  10260. } // Single texture (2D / Cube)
  10261. function setValueT1(gl, v, textures) {
  10262. var cache = this.cache;
  10263. var unit = textures.allocateTextureUnit();
  10264. if (cache[0] !== unit) {
  10265. gl.uniform1i(this.addr, unit);
  10266. cache[0] = unit;
  10267. }
  10268. textures.safeSetTexture2D(v || emptyTexture, unit);
  10269. }
  10270. function setValueT2DArray1(gl, v, textures) {
  10271. var cache = this.cache;
  10272. var unit = textures.allocateTextureUnit();
  10273. if (cache[0] !== unit) {
  10274. gl.uniform1i(this.addr, unit);
  10275. cache[0] = unit;
  10276. }
  10277. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10278. }
  10279. function setValueT3D1(gl, v, textures) {
  10280. var cache = this.cache;
  10281. var unit = textures.allocateTextureUnit();
  10282. if (cache[0] !== unit) {
  10283. gl.uniform1i(this.addr, unit);
  10284. cache[0] = unit;
  10285. }
  10286. textures.setTexture3D(v || emptyTexture3d, unit);
  10287. }
  10288. function setValueT6(gl, v, textures) {
  10289. var cache = this.cache;
  10290. var unit = textures.allocateTextureUnit();
  10291. if (cache[0] !== unit) {
  10292. gl.uniform1i(this.addr, unit);
  10293. cache[0] = unit;
  10294. }
  10295. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10296. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10297. function setValueV1i(gl, v) {
  10298. var cache = this.cache;
  10299. if (cache[0] === v) return;
  10300. gl.uniform1i(this.addr, v);
  10301. cache[0] = v;
  10302. }
  10303. function setValueV2i(gl, v) {
  10304. var cache = this.cache;
  10305. if (arraysEqual(cache, v)) return;
  10306. gl.uniform2iv(this.addr, v);
  10307. copyArray(cache, v);
  10308. }
  10309. function setValueV3i(gl, v) {
  10310. var cache = this.cache;
  10311. if (arraysEqual(cache, v)) return;
  10312. gl.uniform3iv(this.addr, v);
  10313. copyArray(cache, v);
  10314. }
  10315. function setValueV4i(gl, v) {
  10316. var cache = this.cache;
  10317. if (arraysEqual(cache, v)) return;
  10318. gl.uniform4iv(this.addr, v);
  10319. copyArray(cache, v);
  10320. } // uint
  10321. function setValueV1ui(gl, v) {
  10322. var cache = this.cache;
  10323. if (cache[0] === v) return;
  10324. gl.uniform1ui(this.addr, v);
  10325. cache[0] = v;
  10326. } // Helper to pick the right setter for the singular case
  10327. function getSingularSetter(type) {
  10328. switch (type) {
  10329. case 0x1406:
  10330. return setValueV1f;
  10331. // FLOAT
  10332. case 0x8b50:
  10333. return setValueV2f;
  10334. // _VEC2
  10335. case 0x8b51:
  10336. return setValueV3f;
  10337. // _VEC3
  10338. case 0x8b52:
  10339. return setValueV4f;
  10340. // _VEC4
  10341. case 0x8b5a:
  10342. return setValueM2;
  10343. // _MAT2
  10344. case 0x8b5b:
  10345. return setValueM3;
  10346. // _MAT3
  10347. case 0x8b5c:
  10348. return setValueM4;
  10349. // _MAT4
  10350. case 0x1404:
  10351. case 0x8b56:
  10352. return setValueV1i;
  10353. // INT, BOOL
  10354. case 0x8b53:
  10355. case 0x8b57:
  10356. return setValueV2i;
  10357. // _VEC2
  10358. case 0x8b54:
  10359. case 0x8b58:
  10360. return setValueV3i;
  10361. // _VEC3
  10362. case 0x8b55:
  10363. case 0x8b59:
  10364. return setValueV4i;
  10365. // _VEC4
  10366. case 0x1405:
  10367. return setValueV1ui;
  10368. // UINT
  10369. case 0x8b5e: // SAMPLER_2D
  10370. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10371. case 0x8dca: // INT_SAMPLER_2D
  10372. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10373. case 0x8b62:
  10374. // SAMPLER_2D_SHADOW
  10375. return setValueT1;
  10376. case 0x8b5f: // SAMPLER_3D
  10377. case 0x8dcb: // INT_SAMPLER_3D
  10378. case 0x8dd3:
  10379. // UNSIGNED_INT_SAMPLER_3D
  10380. return setValueT3D1;
  10381. case 0x8b60: // SAMPLER_CUBE
  10382. case 0x8dcc: // INT_SAMPLER_CUBE
  10383. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10384. case 0x8dc5:
  10385. // SAMPLER_CUBE_SHADOW
  10386. return setValueT6;
  10387. case 0x8dc1: // SAMPLER_2D_ARRAY
  10388. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10389. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10390. case 0x8dc4:
  10391. // SAMPLER_2D_ARRAY_SHADOW
  10392. return setValueT2DArray1;
  10393. }
  10394. } // Array of scalars
  10395. function setValueV1fArray(gl, v) {
  10396. gl.uniform1fv(this.addr, v);
  10397. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10398. function setValueV1iArray(gl, v) {
  10399. gl.uniform1iv(this.addr, v);
  10400. }
  10401. function setValueV2iArray(gl, v) {
  10402. gl.uniform2iv(this.addr, v);
  10403. }
  10404. function setValueV3iArray(gl, v) {
  10405. gl.uniform3iv(this.addr, v);
  10406. }
  10407. function setValueV4iArray(gl, v) {
  10408. gl.uniform4iv(this.addr, v);
  10409. } // Array of vectors (flat or from THREE classes)
  10410. function setValueV2fArray(gl, v) {
  10411. var data = flatten(v, this.size, 2);
  10412. gl.uniform2fv(this.addr, data);
  10413. }
  10414. function setValueV3fArray(gl, v) {
  10415. var data = flatten(v, this.size, 3);
  10416. gl.uniform3fv(this.addr, data);
  10417. }
  10418. function setValueV4fArray(gl, v) {
  10419. var data = flatten(v, this.size, 4);
  10420. gl.uniform4fv(this.addr, data);
  10421. } // Array of matrices (flat or from THREE clases)
  10422. function setValueM2Array(gl, v) {
  10423. var data = flatten(v, this.size, 4);
  10424. gl.uniformMatrix2fv(this.addr, false, data);
  10425. }
  10426. function setValueM3Array(gl, v) {
  10427. var data = flatten(v, this.size, 9);
  10428. gl.uniformMatrix3fv(this.addr, false, data);
  10429. }
  10430. function setValueM4Array(gl, v) {
  10431. var data = flatten(v, this.size, 16);
  10432. gl.uniformMatrix4fv(this.addr, false, data);
  10433. } // Array of textures (2D / Cube)
  10434. function setValueT1Array(gl, v, textures) {
  10435. var n = v.length;
  10436. var units = allocTexUnits(textures, n);
  10437. gl.uniform1iv(this.addr, units);
  10438. for (var i = 0; i !== n; ++i) {
  10439. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  10440. }
  10441. }
  10442. function setValueT6Array(gl, v, textures) {
  10443. var n = v.length;
  10444. var units = allocTexUnits(textures, n);
  10445. gl.uniform1iv(this.addr, units);
  10446. for (var i = 0; i !== n; ++i) {
  10447. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  10448. }
  10449. } // Helper to pick the right setter for a pure (bottom-level) array
  10450. function getPureArraySetter(type) {
  10451. switch (type) {
  10452. case 0x1406:
  10453. return setValueV1fArray;
  10454. // FLOAT
  10455. case 0x8b50:
  10456. return setValueV2fArray;
  10457. // _VEC2
  10458. case 0x8b51:
  10459. return setValueV3fArray;
  10460. // _VEC3
  10461. case 0x8b52:
  10462. return setValueV4fArray;
  10463. // _VEC4
  10464. case 0x8b5a:
  10465. return setValueM2Array;
  10466. // _MAT2
  10467. case 0x8b5b:
  10468. return setValueM3Array;
  10469. // _MAT3
  10470. case 0x8b5c:
  10471. return setValueM4Array;
  10472. // _MAT4
  10473. case 0x1404:
  10474. case 0x8b56:
  10475. return setValueV1iArray;
  10476. // INT, BOOL
  10477. case 0x8b53:
  10478. case 0x8b57:
  10479. return setValueV2iArray;
  10480. // _VEC2
  10481. case 0x8b54:
  10482. case 0x8b58:
  10483. return setValueV3iArray;
  10484. // _VEC3
  10485. case 0x8b55:
  10486. case 0x8b59:
  10487. return setValueV4iArray;
  10488. // _VEC4
  10489. case 0x8b5e: // SAMPLER_2D
  10490. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10491. case 0x8dca: // INT_SAMPLER_2D
  10492. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10493. case 0x8b62:
  10494. // SAMPLER_2D_SHADOW
  10495. return setValueT1Array;
  10496. case 0x8b60: // SAMPLER_CUBE
  10497. case 0x8dcc: // INT_SAMPLER_CUBE
  10498. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10499. case 0x8dc5:
  10500. // SAMPLER_CUBE_SHADOW
  10501. return setValueT6Array;
  10502. }
  10503. } // --- Uniform Classes ---
  10504. function SingleUniform(id, activeInfo, addr) {
  10505. this.id = id;
  10506. this.addr = addr;
  10507. this.cache = [];
  10508. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10509. }
  10510. function PureArrayUniform(id, activeInfo, addr) {
  10511. this.id = id;
  10512. this.addr = addr;
  10513. this.cache = [];
  10514. this.size = activeInfo.size;
  10515. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10516. }
  10517. PureArrayUniform.prototype.updateCache = function (data) {
  10518. var cache = this.cache;
  10519. if (data instanceof Float32Array && cache.length !== data.length) {
  10520. this.cache = new Float32Array(data.length);
  10521. }
  10522. copyArray(cache, data);
  10523. };
  10524. function StructuredUniform(id) {
  10525. this.id = id;
  10526. this.seq = [];
  10527. this.map = {};
  10528. }
  10529. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  10530. var seq = this.seq;
  10531. for (var i = 0, n = seq.length; i !== n; ++i) {
  10532. var u = seq[i];
  10533. u.setValue(gl, value[u.id], textures);
  10534. }
  10535. }; // --- Top-level ---
  10536. // Parser - builds up the property tree from the path strings
  10537. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g; // extracts
  10538. // - the identifier (member name or array index)
  10539. // - followed by an optional right bracket (found when array index)
  10540. // - followed by an optional left bracket or dot (type of subscript)
  10541. //
  10542. // Note: These portions can be read in a non-overlapping fashion and
  10543. // allow straightforward parsing of the hierarchy that WebGL encodes
  10544. // in the uniform names.
  10545. function addUniform(container, uniformObject) {
  10546. container.seq.push(uniformObject);
  10547. container.map[uniformObject.id] = uniformObject;
  10548. }
  10549. function parseUniform(activeInfo, addr, container) {
  10550. var path = activeInfo.name,
  10551. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  10552. RePathPart.lastIndex = 0;
  10553. while (true) {
  10554. var match = RePathPart.exec(path),
  10555. matchEnd = RePathPart.lastIndex;
  10556. var id = match[1];
  10557. var idIsIndex = match[2] === ']',
  10558. subscript = match[3];
  10559. if (idIsIndex) id = id | 0; // convert to integer
  10560. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  10561. // bare name or "pure" bottom-level array "[0]" suffix
  10562. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  10563. break;
  10564. } else {
  10565. // step into inner node / create it in case it doesn't exist
  10566. var map = container.map;
  10567. var next = map[id];
  10568. if (next === undefined) {
  10569. next = new StructuredUniform(id);
  10570. addUniform(container, next);
  10571. }
  10572. container = next;
  10573. }
  10574. }
  10575. } // Root Container
  10576. function WebGLUniforms(gl, program) {
  10577. this.seq = [];
  10578. this.map = {};
  10579. var n = gl.getProgramParameter(program, 35718);
  10580. for (var i = 0; i < n; ++i) {
  10581. var info = gl.getActiveUniform(program, i),
  10582. addr = gl.getUniformLocation(program, info.name);
  10583. parseUniform(info, addr, this);
  10584. }
  10585. }
  10586. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  10587. var u = this.map[name];
  10588. if (u !== undefined) u.setValue(gl, value, textures);
  10589. };
  10590. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  10591. var v = object[name];
  10592. if (v !== undefined) this.setValue(gl, name, v);
  10593. }; // Static interface
  10594. WebGLUniforms.upload = function (gl, seq, values, textures) {
  10595. for (var i = 0, n = seq.length; i !== n; ++i) {
  10596. var u = seq[i],
  10597. v = values[u.id];
  10598. if (v.needsUpdate !== false) {
  10599. // note: always updating when .needsUpdate is undefined
  10600. u.setValue(gl, v.value, textures);
  10601. }
  10602. }
  10603. };
  10604. WebGLUniforms.seqWithValue = function (seq, values) {
  10605. var r = [];
  10606. for (var i = 0, n = seq.length; i !== n; ++i) {
  10607. var u = seq[i];
  10608. if (u.id in values) r.push(u);
  10609. }
  10610. return r;
  10611. };
  10612. function WebGLShader(gl, type, string) {
  10613. var shader = gl.createShader(type);
  10614. gl.shaderSource(shader, string);
  10615. gl.compileShader(shader);
  10616. return shader;
  10617. }
  10618. var programIdCount = 0;
  10619. function addLineNumbers(string) {
  10620. var lines = string.split('\n');
  10621. for (var i = 0; i < lines.length; i++) {
  10622. lines[i] = i + 1 + ': ' + lines[i];
  10623. }
  10624. return lines.join('\n');
  10625. }
  10626. function getEncodingComponents(encoding) {
  10627. switch (encoding) {
  10628. case LinearEncoding:
  10629. return ['Linear', '( value )'];
  10630. case sRGBEncoding:
  10631. return ['sRGB', '( value )'];
  10632. case RGBEEncoding:
  10633. return ['RGBE', '( value )'];
  10634. case RGBM7Encoding:
  10635. return ['RGBM', '( value, 7.0 )'];
  10636. case RGBM16Encoding:
  10637. return ['RGBM', '( value, 16.0 )'];
  10638. case RGBDEncoding:
  10639. return ['RGBD', '( value, 256.0 )'];
  10640. case GammaEncoding:
  10641. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  10642. case LogLuvEncoding:
  10643. return ['LogLuv', '( value )'];
  10644. default:
  10645. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  10646. return ['Linear', '( value )'];
  10647. }
  10648. }
  10649. function getShaderErrors(gl, shader, type) {
  10650. var status = gl.getShaderParameter(shader, 35713);
  10651. var log = gl.getShaderInfoLog(shader).trim();
  10652. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  10653. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10654. var source = gl.getShaderSource(shader);
  10655. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  10656. }
  10657. function getTexelDecodingFunction(functionName, encoding) {
  10658. var components = getEncodingComponents(encoding);
  10659. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  10660. }
  10661. function getTexelEncodingFunction(functionName, encoding) {
  10662. var components = getEncodingComponents(encoding);
  10663. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  10664. }
  10665. function getToneMappingFunction(functionName, toneMapping) {
  10666. var toneMappingName;
  10667. switch (toneMapping) {
  10668. case LinearToneMapping:
  10669. toneMappingName = 'Linear';
  10670. break;
  10671. case ReinhardToneMapping:
  10672. toneMappingName = 'Reinhard';
  10673. break;
  10674. case CineonToneMapping:
  10675. toneMappingName = 'OptimizedCineon';
  10676. break;
  10677. case ACESFilmicToneMapping:
  10678. toneMappingName = 'ACESFilmic';
  10679. break;
  10680. case CustomToneMapping:
  10681. toneMappingName = 'Custom';
  10682. break;
  10683. default:
  10684. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  10685. toneMappingName = 'Linear';
  10686. }
  10687. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10688. }
  10689. function generateExtensions(parameters) {
  10690. 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' : ''];
  10691. return chunks.filter(filterEmptyLine).join('\n');
  10692. }
  10693. function generateDefines(defines) {
  10694. var chunks = [];
  10695. for (var name in defines) {
  10696. var value = defines[name];
  10697. if (value === false) continue;
  10698. chunks.push('#define ' + name + ' ' + value);
  10699. }
  10700. return chunks.join('\n');
  10701. }
  10702. function fetchAttributeLocations(gl, program) {
  10703. var attributes = {};
  10704. var n = gl.getProgramParameter(program, 35721);
  10705. for (var i = 0; i < n; i++) {
  10706. var info = gl.getActiveAttrib(program, i);
  10707. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10708. attributes[name] = gl.getAttribLocation(program, name);
  10709. }
  10710. return attributes;
  10711. }
  10712. function filterEmptyLine(string) {
  10713. return string !== '';
  10714. }
  10715. function replaceLightNums(string, parameters) {
  10716. 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);
  10717. }
  10718. function replaceClippingPlaneNums(string, parameters) {
  10719. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  10720. } // Resolve Includes
  10721. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10722. function resolveIncludes(string) {
  10723. return string.replace(includePattern, includeReplacer);
  10724. }
  10725. function includeReplacer(match, include) {
  10726. var string = ShaderChunk[include];
  10727. if (string === undefined) {
  10728. throw new Error('Can not resolve #include <' + include + '>');
  10729. }
  10730. return resolveIncludes(string);
  10731. } // Unroll Loops
  10732. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10733. 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;
  10734. function unrollLoops(string) {
  10735. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  10736. }
  10737. function deprecatedLoopReplacer(match, start, end, snippet) {
  10738. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  10739. return loopReplacer(match, start, end, snippet);
  10740. }
  10741. function loopReplacer(match, start, end, snippet) {
  10742. var string = '';
  10743. for (var i = parseInt(start); i < parseInt(end); i++) {
  10744. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  10745. }
  10746. return string;
  10747. } //
  10748. function generatePrecision(parameters) {
  10749. var precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;";
  10750. if (parameters.precision === "highp") {
  10751. precisionstring += "\n#define HIGH_PRECISION";
  10752. } else if (parameters.precision === "mediump") {
  10753. precisionstring += "\n#define MEDIUM_PRECISION";
  10754. } else if (parameters.precision === "lowp") {
  10755. precisionstring += "\n#define LOW_PRECISION";
  10756. }
  10757. return precisionstring;
  10758. }
  10759. function generateShadowMapTypeDefine(parameters) {
  10760. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10761. if (parameters.shadowMapType === PCFShadowMap) {
  10762. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10763. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  10764. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10765. } else if (parameters.shadowMapType === VSMShadowMap) {
  10766. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  10767. }
  10768. return shadowMapTypeDefine;
  10769. }
  10770. function generateEnvMapTypeDefine(parameters) {
  10771. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10772. if (parameters.envMap) {
  10773. switch (parameters.envMapMode) {
  10774. case CubeReflectionMapping:
  10775. case CubeRefractionMapping:
  10776. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10777. break;
  10778. case CubeUVReflectionMapping:
  10779. case CubeUVRefractionMapping:
  10780. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10781. break;
  10782. }
  10783. }
  10784. return envMapTypeDefine;
  10785. }
  10786. function generateEnvMapModeDefine(parameters) {
  10787. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10788. if (parameters.envMap) {
  10789. switch (parameters.envMapMode) {
  10790. case CubeRefractionMapping:
  10791. case CubeUVRefractionMapping:
  10792. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10793. break;
  10794. }
  10795. }
  10796. return envMapModeDefine;
  10797. }
  10798. function generateEnvMapBlendingDefine(parameters) {
  10799. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  10800. if (parameters.envMap) {
  10801. switch (parameters.combine) {
  10802. case MultiplyOperation:
  10803. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10804. break;
  10805. case MixOperation:
  10806. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10807. break;
  10808. case AddOperation:
  10809. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10810. break;
  10811. }
  10812. }
  10813. return envMapBlendingDefine;
  10814. }
  10815. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  10816. var gl = renderer.getContext();
  10817. var defines = parameters.defines;
  10818. var vertexShader = parameters.vertexShader;
  10819. var fragmentShader = parameters.fragmentShader;
  10820. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  10821. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  10822. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  10823. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  10824. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  10825. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  10826. var customDefines = generateDefines(defines);
  10827. var program = gl.createProgram();
  10828. var prefixVertex, prefixFragment;
  10829. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + "\n" : '';
  10830. if (parameters.isRawShaderMaterial) {
  10831. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  10832. if (prefixVertex.length > 0) {
  10833. prefixVertex += '\n';
  10834. }
  10835. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  10836. if (prefixFragment.length > 0) {
  10837. prefixFragment += '\n';
  10838. }
  10839. } else {
  10840. 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');
  10841. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  10842. '#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
  10843. 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
  10844. 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');
  10845. }
  10846. vertexShader = resolveIncludes(vertexShader);
  10847. vertexShader = replaceLightNums(vertexShader, parameters);
  10848. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  10849. fragmentShader = resolveIncludes(fragmentShader);
  10850. fragmentShader = replaceLightNums(fragmentShader, parameters);
  10851. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  10852. vertexShader = unrollLoops(vertexShader);
  10853. fragmentShader = unrollLoops(fragmentShader);
  10854. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  10855. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  10856. versionString = '#version 300 es\n';
  10857. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  10858. 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;
  10859. }
  10860. var vertexGlsl = versionString + prefixVertex + vertexShader;
  10861. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  10862. // console.log( '*FRAGMENT*', fragmentGlsl );
  10863. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  10864. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  10865. gl.attachShader(program, glVertexShader);
  10866. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  10867. if (parameters.index0AttributeName !== undefined) {
  10868. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  10869. } else if (parameters.morphTargets === true) {
  10870. // programs with morphTargets displace position out of attribute 0
  10871. gl.bindAttribLocation(program, 0, 'position');
  10872. }
  10873. gl.linkProgram(program); // check for link errors
  10874. if (renderer.debug.checkShaderErrors) {
  10875. var programLog = gl.getProgramInfoLog(program).trim();
  10876. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  10877. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  10878. var runnable = true;
  10879. var haveDiagnostics = true;
  10880. if (gl.getProgramParameter(program, 35714) === false) {
  10881. runnable = false;
  10882. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  10883. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  10884. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  10885. } else if (programLog !== '') {
  10886. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  10887. } else if (vertexLog === '' || fragmentLog === '') {
  10888. haveDiagnostics = false;
  10889. }
  10890. if (haveDiagnostics) {
  10891. this.diagnostics = {
  10892. runnable: runnable,
  10893. programLog: programLog,
  10894. vertexShader: {
  10895. log: vertexLog,
  10896. prefix: prefixVertex
  10897. },
  10898. fragmentShader: {
  10899. log: fragmentLog,
  10900. prefix: prefixFragment
  10901. }
  10902. };
  10903. }
  10904. } // Clean up
  10905. // Crashes in iOS9 and iOS10. #18402
  10906. // gl.detachShader( program, glVertexShader );
  10907. // gl.detachShader( program, glFragmentShader );
  10908. gl.deleteShader(glVertexShader);
  10909. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  10910. var cachedUniforms;
  10911. this.getUniforms = function () {
  10912. if (cachedUniforms === undefined) {
  10913. cachedUniforms = new WebGLUniforms(gl, program);
  10914. }
  10915. return cachedUniforms;
  10916. }; // set up caching for attribute locations
  10917. var cachedAttributes;
  10918. this.getAttributes = function () {
  10919. if (cachedAttributes === undefined) {
  10920. cachedAttributes = fetchAttributeLocations(gl, program);
  10921. }
  10922. return cachedAttributes;
  10923. }; // free resource
  10924. this.destroy = function () {
  10925. bindingStates.releaseStatesOfProgram(this);
  10926. gl.deleteProgram(program);
  10927. this.program = undefined;
  10928. }; //
  10929. this.name = parameters.shaderName;
  10930. this.id = programIdCount++;
  10931. this.cacheKey = cacheKey;
  10932. this.usedTimes = 1;
  10933. this.program = program;
  10934. this.vertexShader = glVertexShader;
  10935. this.fragmentShader = glFragmentShader;
  10936. return this;
  10937. }
  10938. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  10939. var programs = [];
  10940. var isWebGL2 = capabilities.isWebGL2;
  10941. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  10942. var floatVertexTextures = capabilities.floatVertexTextures;
  10943. var maxVertexUniforms = capabilities.maxVertexUniforms;
  10944. var vertexTextures = capabilities.vertexTextures;
  10945. var precision = capabilities.precision;
  10946. var shaderIDs = {
  10947. MeshDepthMaterial: 'depth',
  10948. MeshDistanceMaterial: 'distanceRGBA',
  10949. MeshNormalMaterial: 'normal',
  10950. MeshBasicMaterial: 'basic',
  10951. MeshLambertMaterial: 'lambert',
  10952. MeshPhongMaterial: 'phong',
  10953. MeshToonMaterial: 'toon',
  10954. MeshStandardMaterial: 'physical',
  10955. MeshPhysicalMaterial: 'physical',
  10956. MeshMatcapMaterial: 'matcap',
  10957. LineBasicMaterial: 'basic',
  10958. LineDashedMaterial: 'dashed',
  10959. PointsMaterial: 'points',
  10960. ShadowMaterial: 'shadow',
  10961. SpriteMaterial: 'sprite'
  10962. };
  10963. 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"];
  10964. function getMaxBones(object) {
  10965. var skeleton = object.skeleton;
  10966. var bones = skeleton.bones;
  10967. if (floatVertexTextures) {
  10968. return 1024;
  10969. } else {
  10970. // default for when object is not specified
  10971. // ( for example when prebuilding shader to be used with multiple objects )
  10972. //
  10973. // - leave some extra space for other uniforms
  10974. // - limit here is ANGLE's 254 max uniform vectors
  10975. // (up to 54 should be safe)
  10976. var nVertexUniforms = maxVertexUniforms;
  10977. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  10978. var maxBones = Math.min(nVertexMatrices, bones.length);
  10979. if (maxBones < bones.length) {
  10980. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  10981. return 0;
  10982. }
  10983. return maxBones;
  10984. }
  10985. }
  10986. function getTextureEncodingFromMap(map) {
  10987. var encoding;
  10988. if (!map) {
  10989. encoding = LinearEncoding;
  10990. } else if (map.isTexture) {
  10991. encoding = map.encoding;
  10992. } else if (map.isWebGLRenderTarget) {
  10993. console.warn("THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead.");
  10994. encoding = map.texture.encoding;
  10995. }
  10996. return encoding;
  10997. }
  10998. function getParameters(material, lights, shadows, scene, object) {
  10999. var fog = scene.fog;
  11000. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  11001. var envMap = cubemaps.get(material.envMap || environment);
  11002. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  11003. // (not to blow over maxLights budget)
  11004. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  11005. if (material.precision !== null) {
  11006. precision = capabilities.getMaxPrecision(material.precision);
  11007. if (precision !== material.precision) {
  11008. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  11009. }
  11010. }
  11011. var vertexShader, fragmentShader;
  11012. if (shaderID) {
  11013. var shader = ShaderLib[shaderID];
  11014. vertexShader = shader.vertexShader;
  11015. fragmentShader = shader.fragmentShader;
  11016. } else {
  11017. vertexShader = material.vertexShader;
  11018. fragmentShader = material.fragmentShader;
  11019. }
  11020. var currentRenderTarget = renderer.getRenderTarget();
  11021. var parameters = {
  11022. isWebGL2: isWebGL2,
  11023. shaderID: shaderID,
  11024. shaderName: material.type,
  11025. vertexShader: vertexShader,
  11026. fragmentShader: fragmentShader,
  11027. defines: material.defines,
  11028. isRawShaderMaterial: material.isRawShaderMaterial === true,
  11029. glslVersion: material.glslVersion,
  11030. precision: precision,
  11031. instancing: object.isInstancedMesh === true,
  11032. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  11033. supportsVertexTextures: vertexTextures,
  11034. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  11035. map: !!material.map,
  11036. mapEncoding: getTextureEncodingFromMap(material.map),
  11037. matcap: !!material.matcap,
  11038. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  11039. envMap: !!envMap,
  11040. envMapMode: envMap && envMap.mapping,
  11041. envMapEncoding: getTextureEncodingFromMap(envMap),
  11042. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  11043. lightMap: !!material.lightMap,
  11044. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  11045. aoMap: !!material.aoMap,
  11046. emissiveMap: !!material.emissiveMap,
  11047. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  11048. bumpMap: !!material.bumpMap,
  11049. normalMap: !!material.normalMap,
  11050. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11051. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11052. clearcoatMap: !!material.clearcoatMap,
  11053. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  11054. clearcoatNormalMap: !!material.clearcoatNormalMap,
  11055. displacementMap: !!material.displacementMap,
  11056. roughnessMap: !!material.roughnessMap,
  11057. metalnessMap: !!material.metalnessMap,
  11058. specularMap: !!material.specularMap,
  11059. alphaMap: !!material.alphaMap,
  11060. gradientMap: !!material.gradientMap,
  11061. sheen: !!material.sheen,
  11062. transmissionMap: !!material.transmissionMap,
  11063. combine: material.combine,
  11064. vertexTangents: material.normalMap && material.vertexTangents,
  11065. vertexColors: material.vertexColors,
  11066. 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,
  11067. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  11068. fog: !!fog,
  11069. useFog: material.fog,
  11070. fogExp2: fog && fog.isFogExp2,
  11071. flatShading: material.flatShading,
  11072. sizeAttenuation: material.sizeAttenuation,
  11073. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11074. skinning: material.skinning && maxBones > 0,
  11075. maxBones: maxBones,
  11076. useVertexTexture: floatVertexTextures,
  11077. morphTargets: material.morphTargets,
  11078. morphNormals: material.morphNormals,
  11079. maxMorphTargets: renderer.maxMorphTargets,
  11080. maxMorphNormals: renderer.maxMorphNormals,
  11081. numDirLights: lights.directional.length,
  11082. numPointLights: lights.point.length,
  11083. numSpotLights: lights.spot.length,
  11084. numRectAreaLights: lights.rectArea.length,
  11085. numHemiLights: lights.hemi.length,
  11086. numDirLightShadows: lights.directionalShadowMap.length,
  11087. numPointLightShadows: lights.pointShadowMap.length,
  11088. numSpotLightShadows: lights.spotShadowMap.length,
  11089. numClippingPlanes: clipping.numPlanes,
  11090. numClipIntersection: clipping.numIntersection,
  11091. dithering: material.dithering,
  11092. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11093. shadowMapType: renderer.shadowMap.type,
  11094. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11095. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11096. premultipliedAlpha: material.premultipliedAlpha,
  11097. alphaTest: material.alphaTest,
  11098. doubleSided: material.side === DoubleSide,
  11099. flipSided: material.side === BackSide,
  11100. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11101. index0AttributeName: material.index0AttributeName,
  11102. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11103. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11104. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11105. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11106. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11107. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11108. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11109. customProgramCacheKey: material.customProgramCacheKey()
  11110. };
  11111. return parameters;
  11112. }
  11113. function getProgramCacheKey(parameters) {
  11114. var array = [];
  11115. if (parameters.shaderID) {
  11116. array.push(parameters.shaderID);
  11117. } else {
  11118. array.push(parameters.fragmentShader);
  11119. array.push(parameters.vertexShader);
  11120. }
  11121. if (parameters.defines !== undefined) {
  11122. for (var name in parameters.defines) {
  11123. array.push(name);
  11124. array.push(parameters.defines[name]);
  11125. }
  11126. }
  11127. if (parameters.isRawShaderMaterial === false) {
  11128. for (var i = 0; i < parameterNames.length; i++) {
  11129. array.push(parameters[parameterNames[i]]);
  11130. }
  11131. array.push(renderer.outputEncoding);
  11132. array.push(renderer.gammaFactor);
  11133. }
  11134. array.push(parameters.customProgramCacheKey);
  11135. return array.join();
  11136. }
  11137. function getUniforms(material) {
  11138. var shaderID = shaderIDs[material.type];
  11139. var uniforms;
  11140. if (shaderID) {
  11141. var shader = ShaderLib[shaderID];
  11142. uniforms = UniformsUtils.clone(shader.uniforms);
  11143. } else {
  11144. uniforms = material.uniforms;
  11145. }
  11146. return uniforms;
  11147. }
  11148. function acquireProgram(parameters, cacheKey) {
  11149. var program; // Check if code has been already compiled
  11150. for (var p = 0, pl = programs.length; p < pl; p++) {
  11151. var preexistingProgram = programs[p];
  11152. if (preexistingProgram.cacheKey === cacheKey) {
  11153. program = preexistingProgram;
  11154. ++program.usedTimes;
  11155. break;
  11156. }
  11157. }
  11158. if (program === undefined) {
  11159. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11160. programs.push(program);
  11161. }
  11162. return program;
  11163. }
  11164. function releaseProgram(program) {
  11165. if (--program.usedTimes === 0) {
  11166. // Remove from unordered set
  11167. var i = programs.indexOf(program);
  11168. programs[i] = programs[programs.length - 1];
  11169. programs.pop(); // Free WebGL resources
  11170. program.destroy();
  11171. }
  11172. }
  11173. return {
  11174. getParameters: getParameters,
  11175. getProgramCacheKey: getProgramCacheKey,
  11176. getUniforms: getUniforms,
  11177. acquireProgram: acquireProgram,
  11178. releaseProgram: releaseProgram,
  11179. // Exposed for resource monitoring & error feedback via renderer.info:
  11180. programs: programs
  11181. };
  11182. }
  11183. function WebGLProperties() {
  11184. var properties = new WeakMap();
  11185. function get(object) {
  11186. var map = properties.get(object);
  11187. if (map === undefined) {
  11188. map = {};
  11189. properties.set(object, map);
  11190. }
  11191. return map;
  11192. }
  11193. function remove(object) {
  11194. properties.delete(object);
  11195. }
  11196. function update(object, key, value) {
  11197. properties.get(object)[key] = value;
  11198. }
  11199. function dispose() {
  11200. properties = new WeakMap();
  11201. }
  11202. return {
  11203. get: get,
  11204. remove: remove,
  11205. update: update,
  11206. dispose: dispose
  11207. };
  11208. }
  11209. function painterSortStable(a, b) {
  11210. if (a.groupOrder !== b.groupOrder) {
  11211. return a.groupOrder - b.groupOrder;
  11212. } else if (a.renderOrder !== b.renderOrder) {
  11213. return a.renderOrder - b.renderOrder;
  11214. } else if (a.program !== b.program) {
  11215. return a.program.id - b.program.id;
  11216. } else if (a.material.id !== b.material.id) {
  11217. return a.material.id - b.material.id;
  11218. } else if (a.z !== b.z) {
  11219. return a.z - b.z;
  11220. } else {
  11221. return a.id - b.id;
  11222. }
  11223. }
  11224. function reversePainterSortStable(a, b) {
  11225. if (a.groupOrder !== b.groupOrder) {
  11226. return a.groupOrder - b.groupOrder;
  11227. } else if (a.renderOrder !== b.renderOrder) {
  11228. return a.renderOrder - b.renderOrder;
  11229. } else if (a.z !== b.z) {
  11230. return b.z - a.z;
  11231. } else {
  11232. return a.id - b.id;
  11233. }
  11234. }
  11235. function WebGLRenderList(properties) {
  11236. var renderItems = [];
  11237. var renderItemsIndex = 0;
  11238. var opaque = [];
  11239. var transparent = [];
  11240. var defaultProgram = {
  11241. id: -1
  11242. };
  11243. function init() {
  11244. renderItemsIndex = 0;
  11245. opaque.length = 0;
  11246. transparent.length = 0;
  11247. }
  11248. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11249. var renderItem = renderItems[renderItemsIndex];
  11250. var materialProperties = properties.get(material);
  11251. if (renderItem === undefined) {
  11252. renderItem = {
  11253. id: object.id,
  11254. object: object,
  11255. geometry: geometry,
  11256. material: material,
  11257. program: materialProperties.program || defaultProgram,
  11258. groupOrder: groupOrder,
  11259. renderOrder: object.renderOrder,
  11260. z: z,
  11261. group: group
  11262. };
  11263. renderItems[renderItemsIndex] = renderItem;
  11264. } else {
  11265. renderItem.id = object.id;
  11266. renderItem.object = object;
  11267. renderItem.geometry = geometry;
  11268. renderItem.material = material;
  11269. renderItem.program = materialProperties.program || defaultProgram;
  11270. renderItem.groupOrder = groupOrder;
  11271. renderItem.renderOrder = object.renderOrder;
  11272. renderItem.z = z;
  11273. renderItem.group = group;
  11274. }
  11275. renderItemsIndex++;
  11276. return renderItem;
  11277. }
  11278. function push(object, geometry, material, groupOrder, z, group) {
  11279. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11280. (material.transparent === true ? transparent : opaque).push(renderItem);
  11281. }
  11282. function unshift(object, geometry, material, groupOrder, z, group) {
  11283. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11284. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11285. }
  11286. function sort(customOpaqueSort, customTransparentSort) {
  11287. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11288. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11289. }
  11290. function finish() {
  11291. // Clear references from inactive renderItems in the list
  11292. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11293. var renderItem = renderItems[i];
  11294. if (renderItem.id === null) break;
  11295. renderItem.id = null;
  11296. renderItem.object = null;
  11297. renderItem.geometry = null;
  11298. renderItem.material = null;
  11299. renderItem.program = null;
  11300. renderItem.group = null;
  11301. }
  11302. }
  11303. return {
  11304. opaque: opaque,
  11305. transparent: transparent,
  11306. init: init,
  11307. push: push,
  11308. unshift: unshift,
  11309. finish: finish,
  11310. sort: sort
  11311. };
  11312. }
  11313. function WebGLRenderLists(properties) {
  11314. var lists = new WeakMap();
  11315. function get(scene, camera) {
  11316. var cameras = lists.get(scene);
  11317. var list;
  11318. if (cameras === undefined) {
  11319. list = new WebGLRenderList(properties);
  11320. lists.set(scene, new WeakMap());
  11321. lists.get(scene).set(camera, list);
  11322. } else {
  11323. list = cameras.get(camera);
  11324. if (list === undefined) {
  11325. list = new WebGLRenderList(properties);
  11326. cameras.set(camera, list);
  11327. }
  11328. }
  11329. return list;
  11330. }
  11331. function dispose() {
  11332. lists = new WeakMap();
  11333. }
  11334. return {
  11335. get: get,
  11336. dispose: dispose
  11337. };
  11338. }
  11339. function UniformsCache() {
  11340. var lights = {};
  11341. return {
  11342. get: function get(light) {
  11343. if (lights[light.id] !== undefined) {
  11344. return lights[light.id];
  11345. }
  11346. var uniforms;
  11347. switch (light.type) {
  11348. case 'DirectionalLight':
  11349. uniforms = {
  11350. direction: new Vector3(),
  11351. color: new Color()
  11352. };
  11353. break;
  11354. case 'SpotLight':
  11355. uniforms = {
  11356. position: new Vector3(),
  11357. direction: new Vector3(),
  11358. color: new Color(),
  11359. distance: 0,
  11360. coneCos: 0,
  11361. penumbraCos: 0,
  11362. decay: 0
  11363. };
  11364. break;
  11365. case 'PointLight':
  11366. uniforms = {
  11367. position: new Vector3(),
  11368. color: new Color(),
  11369. distance: 0,
  11370. decay: 0
  11371. };
  11372. break;
  11373. case 'HemisphereLight':
  11374. uniforms = {
  11375. direction: new Vector3(),
  11376. skyColor: new Color(),
  11377. groundColor: new Color()
  11378. };
  11379. break;
  11380. case 'RectAreaLight':
  11381. uniforms = {
  11382. color: new Color(),
  11383. position: new Vector3(),
  11384. halfWidth: new Vector3(),
  11385. halfHeight: new Vector3()
  11386. };
  11387. break;
  11388. }
  11389. lights[light.id] = uniforms;
  11390. return uniforms;
  11391. }
  11392. };
  11393. }
  11394. function ShadowUniformsCache() {
  11395. var lights = {};
  11396. return {
  11397. get: function get(light) {
  11398. if (lights[light.id] !== undefined) {
  11399. return lights[light.id];
  11400. }
  11401. var uniforms;
  11402. switch (light.type) {
  11403. case 'DirectionalLight':
  11404. uniforms = {
  11405. shadowBias: 0,
  11406. shadowNormalBias: 0,
  11407. shadowRadius: 1,
  11408. shadowMapSize: new Vector2()
  11409. };
  11410. break;
  11411. case 'SpotLight':
  11412. uniforms = {
  11413. shadowBias: 0,
  11414. shadowNormalBias: 0,
  11415. shadowRadius: 1,
  11416. shadowMapSize: new Vector2()
  11417. };
  11418. break;
  11419. case 'PointLight':
  11420. uniforms = {
  11421. shadowBias: 0,
  11422. shadowNormalBias: 0,
  11423. shadowRadius: 1,
  11424. shadowMapSize: new Vector2(),
  11425. shadowCameraNear: 1,
  11426. shadowCameraFar: 1000
  11427. };
  11428. break;
  11429. // TODO (abelnation): set RectAreaLight shadow uniforms
  11430. }
  11431. lights[light.id] = uniforms;
  11432. return uniforms;
  11433. }
  11434. };
  11435. }
  11436. var nextVersion = 0;
  11437. function shadowCastingLightsFirst(lightA, lightB) {
  11438. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  11439. }
  11440. function WebGLLights(extensions, capabilities) {
  11441. var cache = new UniformsCache();
  11442. var shadowCache = ShadowUniformsCache();
  11443. var state = {
  11444. version: 0,
  11445. hash: {
  11446. directionalLength: -1,
  11447. pointLength: -1,
  11448. spotLength: -1,
  11449. rectAreaLength: -1,
  11450. hemiLength: -1,
  11451. numDirectionalShadows: -1,
  11452. numPointShadows: -1,
  11453. numSpotShadows: -1
  11454. },
  11455. ambient: [0, 0, 0],
  11456. probe: [],
  11457. directional: [],
  11458. directionalShadow: [],
  11459. directionalShadowMap: [],
  11460. directionalShadowMatrix: [],
  11461. spot: [],
  11462. spotShadow: [],
  11463. spotShadowMap: [],
  11464. spotShadowMatrix: [],
  11465. rectArea: [],
  11466. rectAreaLTC1: null,
  11467. rectAreaLTC2: null,
  11468. point: [],
  11469. pointShadow: [],
  11470. pointShadowMap: [],
  11471. pointShadowMatrix: [],
  11472. hemi: []
  11473. };
  11474. for (var i = 0; i < 9; i++) {
  11475. state.probe.push(new Vector3());
  11476. }
  11477. var vector3 = new Vector3();
  11478. var matrix4 = new Matrix4();
  11479. var matrix42 = new Matrix4();
  11480. function setup(lights, shadows, camera) {
  11481. var r = 0,
  11482. g = 0,
  11483. b = 0;
  11484. for (var _i = 0; _i < 9; _i++) {
  11485. state.probe[_i].set(0, 0, 0);
  11486. }
  11487. var directionalLength = 0;
  11488. var pointLength = 0;
  11489. var spotLength = 0;
  11490. var rectAreaLength = 0;
  11491. var hemiLength = 0;
  11492. var numDirectionalShadows = 0;
  11493. var numPointShadows = 0;
  11494. var numSpotShadows = 0;
  11495. var viewMatrix = camera.matrixWorldInverse;
  11496. lights.sort(shadowCastingLightsFirst);
  11497. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  11498. var light = lights[_i2];
  11499. var color = light.color;
  11500. var intensity = light.intensity;
  11501. var distance = light.distance;
  11502. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  11503. if (light.isAmbientLight) {
  11504. r += color.r * intensity;
  11505. g += color.g * intensity;
  11506. b += color.b * intensity;
  11507. } else if (light.isLightProbe) {
  11508. for (var j = 0; j < 9; j++) {
  11509. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  11510. }
  11511. } else if (light.isDirectionalLight) {
  11512. var uniforms = cache.get(light);
  11513. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  11514. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11515. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11516. uniforms.direction.sub(vector3);
  11517. uniforms.direction.transformDirection(viewMatrix);
  11518. if (light.castShadow) {
  11519. var shadow = light.shadow;
  11520. var shadowUniforms = shadowCache.get(light);
  11521. shadowUniforms.shadowBias = shadow.bias;
  11522. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11523. shadowUniforms.shadowRadius = shadow.radius;
  11524. shadowUniforms.shadowMapSize = shadow.mapSize;
  11525. state.directionalShadow[directionalLength] = shadowUniforms;
  11526. state.directionalShadowMap[directionalLength] = shadowMap;
  11527. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  11528. numDirectionalShadows++;
  11529. }
  11530. state.directional[directionalLength] = uniforms;
  11531. directionalLength++;
  11532. } else if (light.isSpotLight) {
  11533. var _uniforms = cache.get(light);
  11534. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  11535. _uniforms.position.applyMatrix4(viewMatrix);
  11536. _uniforms.color.copy(color).multiplyScalar(intensity);
  11537. _uniforms.distance = distance;
  11538. _uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11539. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11540. _uniforms.direction.sub(vector3);
  11541. _uniforms.direction.transformDirection(viewMatrix);
  11542. _uniforms.coneCos = Math.cos(light.angle);
  11543. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  11544. _uniforms.decay = light.decay;
  11545. if (light.castShadow) {
  11546. var _shadow = light.shadow;
  11547. var _shadowUniforms = shadowCache.get(light);
  11548. _shadowUniforms.shadowBias = _shadow.bias;
  11549. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  11550. _shadowUniforms.shadowRadius = _shadow.radius;
  11551. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  11552. state.spotShadow[spotLength] = _shadowUniforms;
  11553. state.spotShadowMap[spotLength] = shadowMap;
  11554. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  11555. numSpotShadows++;
  11556. }
  11557. state.spot[spotLength] = _uniforms;
  11558. spotLength++;
  11559. } else if (light.isRectAreaLight) {
  11560. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  11561. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11562. // (b) intensity is the brightness of the light
  11563. _uniforms2.color.copy(color).multiplyScalar(intensity);
  11564. _uniforms2.position.setFromMatrixPosition(light.matrixWorld);
  11565. _uniforms2.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  11566. matrix42.identity();
  11567. matrix4.copy(light.matrixWorld);
  11568. matrix4.premultiply(viewMatrix);
  11569. matrix42.extractRotation(matrix4);
  11570. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  11571. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  11572. _uniforms2.halfWidth.applyMatrix4(matrix42);
  11573. _uniforms2.halfHeight.applyMatrix4(matrix42); // TODO (abelnation): RectAreaLight distance?
  11574. // uniforms.distance = distance;
  11575. state.rectArea[rectAreaLength] = _uniforms2;
  11576. rectAreaLength++;
  11577. } else if (light.isPointLight) {
  11578. var _uniforms3 = cache.get(light);
  11579. _uniforms3.position.setFromMatrixPosition(light.matrixWorld);
  11580. _uniforms3.position.applyMatrix4(viewMatrix);
  11581. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  11582. _uniforms3.distance = light.distance;
  11583. _uniforms3.decay = light.decay;
  11584. if (light.castShadow) {
  11585. var _shadow2 = light.shadow;
  11586. var _shadowUniforms2 = shadowCache.get(light);
  11587. _shadowUniforms2.shadowBias = _shadow2.bias;
  11588. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  11589. _shadowUniforms2.shadowRadius = _shadow2.radius;
  11590. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  11591. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  11592. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  11593. state.pointShadow[pointLength] = _shadowUniforms2;
  11594. state.pointShadowMap[pointLength] = shadowMap;
  11595. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  11596. numPointShadows++;
  11597. }
  11598. state.point[pointLength] = _uniforms3;
  11599. pointLength++;
  11600. } else if (light.isHemisphereLight) {
  11601. var _uniforms4 = cache.get(light);
  11602. _uniforms4.direction.setFromMatrixPosition(light.matrixWorld);
  11603. _uniforms4.direction.transformDirection(viewMatrix);
  11604. _uniforms4.direction.normalize();
  11605. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  11606. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  11607. state.hemi[hemiLength] = _uniforms4;
  11608. hemiLength++;
  11609. }
  11610. }
  11611. if (rectAreaLength > 0) {
  11612. if (capabilities.isWebGL2) {
  11613. // WebGL 2
  11614. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11615. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11616. } else {
  11617. // WebGL 1
  11618. if (extensions.has('OES_texture_float_linear') === true) {
  11619. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11620. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11621. } else if (extensions.has('OES_texture_half_float_linear') === true) {
  11622. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  11623. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  11624. } else {
  11625. console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
  11626. }
  11627. }
  11628. }
  11629. state.ambient[0] = r;
  11630. state.ambient[1] = g;
  11631. state.ambient[2] = b;
  11632. var hash = state.hash;
  11633. 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) {
  11634. state.directional.length = directionalLength;
  11635. state.spot.length = spotLength;
  11636. state.rectArea.length = rectAreaLength;
  11637. state.point.length = pointLength;
  11638. state.hemi.length = hemiLength;
  11639. state.directionalShadow.length = numDirectionalShadows;
  11640. state.directionalShadowMap.length = numDirectionalShadows;
  11641. state.pointShadow.length = numPointShadows;
  11642. state.pointShadowMap.length = numPointShadows;
  11643. state.spotShadow.length = numSpotShadows;
  11644. state.spotShadowMap.length = numSpotShadows;
  11645. state.directionalShadowMatrix.length = numDirectionalShadows;
  11646. state.pointShadowMatrix.length = numPointShadows;
  11647. state.spotShadowMatrix.length = numSpotShadows;
  11648. hash.directionalLength = directionalLength;
  11649. hash.pointLength = pointLength;
  11650. hash.spotLength = spotLength;
  11651. hash.rectAreaLength = rectAreaLength;
  11652. hash.hemiLength = hemiLength;
  11653. hash.numDirectionalShadows = numDirectionalShadows;
  11654. hash.numPointShadows = numPointShadows;
  11655. hash.numSpotShadows = numSpotShadows;
  11656. state.version = nextVersion++;
  11657. }
  11658. }
  11659. return {
  11660. setup: setup,
  11661. state: state
  11662. };
  11663. }
  11664. function WebGLRenderState(extensions, capabilities) {
  11665. var lights = new WebGLLights(extensions, capabilities);
  11666. var lightsArray = [];
  11667. var shadowsArray = [];
  11668. function init() {
  11669. lightsArray.length = 0;
  11670. shadowsArray.length = 0;
  11671. }
  11672. function pushLight(light) {
  11673. lightsArray.push(light);
  11674. }
  11675. function pushShadow(shadowLight) {
  11676. shadowsArray.push(shadowLight);
  11677. }
  11678. function setupLights(camera) {
  11679. lights.setup(lightsArray, shadowsArray, camera);
  11680. }
  11681. var state = {
  11682. lightsArray: lightsArray,
  11683. shadowsArray: shadowsArray,
  11684. lights: lights
  11685. };
  11686. return {
  11687. init: init,
  11688. state: state,
  11689. setupLights: setupLights,
  11690. pushLight: pushLight,
  11691. pushShadow: pushShadow
  11692. };
  11693. }
  11694. function WebGLRenderStates(extensions, capabilities) {
  11695. var renderStates = new WeakMap();
  11696. function get(scene, camera) {
  11697. var renderState;
  11698. if (renderStates.has(scene) === false) {
  11699. renderState = new WebGLRenderState(extensions, capabilities);
  11700. renderStates.set(scene, new WeakMap());
  11701. renderStates.get(scene).set(camera, renderState);
  11702. } else {
  11703. if (renderStates.get(scene).has(camera) === false) {
  11704. renderState = new WebGLRenderState(extensions, capabilities);
  11705. renderStates.get(scene).set(camera, renderState);
  11706. } else {
  11707. renderState = renderStates.get(scene).get(camera);
  11708. }
  11709. }
  11710. return renderState;
  11711. }
  11712. function dispose() {
  11713. renderStates = new WeakMap();
  11714. }
  11715. return {
  11716. get: get,
  11717. dispose: dispose
  11718. };
  11719. }
  11720. /**
  11721. * parameters = {
  11722. *
  11723. * opacity: <float>,
  11724. *
  11725. * map: new THREE.Texture( <Image> ),
  11726. *
  11727. * alphaMap: new THREE.Texture( <Image> ),
  11728. *
  11729. * displacementMap: new THREE.Texture( <Image> ),
  11730. * displacementScale: <float>,
  11731. * displacementBias: <float>,
  11732. *
  11733. * wireframe: <boolean>,
  11734. * wireframeLinewidth: <float>
  11735. * }
  11736. */
  11737. function MeshDepthMaterial(parameters) {
  11738. Material.call(this);
  11739. this.type = 'MeshDepthMaterial';
  11740. this.depthPacking = BasicDepthPacking;
  11741. this.skinning = false;
  11742. this.morphTargets = false;
  11743. this.map = null;
  11744. this.alphaMap = null;
  11745. this.displacementMap = null;
  11746. this.displacementScale = 1;
  11747. this.displacementBias = 0;
  11748. this.wireframe = false;
  11749. this.wireframeLinewidth = 1;
  11750. this.fog = false;
  11751. this.setValues(parameters);
  11752. }
  11753. MeshDepthMaterial.prototype = Object.create(Material.prototype);
  11754. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11755. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11756. MeshDepthMaterial.prototype.copy = function (source) {
  11757. Material.prototype.copy.call(this, source);
  11758. this.depthPacking = source.depthPacking;
  11759. this.skinning = source.skinning;
  11760. this.morphTargets = source.morphTargets;
  11761. this.map = source.map;
  11762. this.alphaMap = source.alphaMap;
  11763. this.displacementMap = source.displacementMap;
  11764. this.displacementScale = source.displacementScale;
  11765. this.displacementBias = source.displacementBias;
  11766. this.wireframe = source.wireframe;
  11767. this.wireframeLinewidth = source.wireframeLinewidth;
  11768. return this;
  11769. };
  11770. /**
  11771. * parameters = {
  11772. *
  11773. * referencePosition: <float>,
  11774. * nearDistance: <float>,
  11775. * farDistance: <float>,
  11776. *
  11777. * skinning: <bool>,
  11778. * morphTargets: <bool>,
  11779. *
  11780. * map: new THREE.Texture( <Image> ),
  11781. *
  11782. * alphaMap: new THREE.Texture( <Image> ),
  11783. *
  11784. * displacementMap: new THREE.Texture( <Image> ),
  11785. * displacementScale: <float>,
  11786. * displacementBias: <float>
  11787. *
  11788. * }
  11789. */
  11790. function MeshDistanceMaterial(parameters) {
  11791. Material.call(this);
  11792. this.type = 'MeshDistanceMaterial';
  11793. this.referencePosition = new Vector3();
  11794. this.nearDistance = 1;
  11795. this.farDistance = 1000;
  11796. this.skinning = false;
  11797. this.morphTargets = false;
  11798. this.map = null;
  11799. this.alphaMap = null;
  11800. this.displacementMap = null;
  11801. this.displacementScale = 1;
  11802. this.displacementBias = 0;
  11803. this.fog = false;
  11804. this.setValues(parameters);
  11805. }
  11806. MeshDistanceMaterial.prototype = Object.create(Material.prototype);
  11807. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11808. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11809. MeshDistanceMaterial.prototype.copy = function (source) {
  11810. Material.prototype.copy.call(this, source);
  11811. this.referencePosition.copy(source.referencePosition);
  11812. this.nearDistance = source.nearDistance;
  11813. this.farDistance = source.farDistance;
  11814. this.skinning = source.skinning;
  11815. this.morphTargets = source.morphTargets;
  11816. this.map = source.map;
  11817. this.alphaMap = source.alphaMap;
  11818. this.displacementMap = source.displacementMap;
  11819. this.displacementScale = source.displacementScale;
  11820. this.displacementBias = source.displacementBias;
  11821. return this;
  11822. };
  11823. var vsm_frag = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n\tfor ( float i = -1.0; i < 1.0 ; i += SAMPLE_RATE) {\n\t\t#ifdef HORIZONAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, i ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean * HALF_SAMPLE_RATE;\n\tsquared_mean = squared_mean * HALF_SAMPLE_RATE;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";
  11824. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  11825. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  11826. var _frustum = new Frustum();
  11827. var _shadowMapSize = new Vector2(),
  11828. _viewportSize = new Vector2(),
  11829. _viewport = new Vector4(),
  11830. _depthMaterials = [],
  11831. _distanceMaterials = [],
  11832. _materialCache = {};
  11833. var shadowSide = {
  11834. 0: BackSide,
  11835. 1: FrontSide,
  11836. 2: DoubleSide
  11837. };
  11838. var shadowMaterialVertical = new ShaderMaterial({
  11839. defines: {
  11840. SAMPLE_RATE: 2.0 / 8.0,
  11841. HALF_SAMPLE_RATE: 1.0 / 8.0
  11842. },
  11843. uniforms: {
  11844. shadow_pass: {
  11845. value: null
  11846. },
  11847. resolution: {
  11848. value: new Vector2()
  11849. },
  11850. radius: {
  11851. value: 4.0
  11852. }
  11853. },
  11854. vertexShader: vsm_vert,
  11855. fragmentShader: vsm_frag
  11856. });
  11857. var shadowMaterialHorizonal = shadowMaterialVertical.clone();
  11858. shadowMaterialHorizonal.defines.HORIZONAL_PASS = 1;
  11859. var fullScreenTri = new BufferGeometry();
  11860. fullScreenTri.setAttribute("position", new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  11861. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  11862. var scope = this;
  11863. this.enabled = false;
  11864. this.autoUpdate = true;
  11865. this.needsUpdate = false;
  11866. this.type = PCFShadowMap;
  11867. this.render = function (lights, scene, camera) {
  11868. if (scope.enabled === false) return;
  11869. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  11870. if (lights.length === 0) return;
  11871. var currentRenderTarget = _renderer.getRenderTarget();
  11872. var activeCubeFace = _renderer.getActiveCubeFace();
  11873. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  11874. var _state = _renderer.state; // Set GL state for depth map.
  11875. _state.setBlending(NoBlending);
  11876. _state.buffers.color.setClear(1, 1, 1, 1);
  11877. _state.buffers.depth.setTest(true);
  11878. _state.setScissorTest(false); // render depth map
  11879. for (var i = 0, il = lights.length; i < il; i++) {
  11880. var light = lights[i];
  11881. var shadow = light.shadow;
  11882. if (shadow === undefined) {
  11883. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  11884. continue;
  11885. }
  11886. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  11887. _shadowMapSize.copy(shadow.mapSize);
  11888. var shadowFrameExtents = shadow.getFrameExtents();
  11889. _shadowMapSize.multiply(shadowFrameExtents);
  11890. _viewportSize.copy(shadow.mapSize);
  11891. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  11892. if (_shadowMapSize.x > maxTextureSize) {
  11893. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  11894. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  11895. shadow.mapSize.x = _viewportSize.x;
  11896. }
  11897. if (_shadowMapSize.y > maxTextureSize) {
  11898. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  11899. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  11900. shadow.mapSize.y = _viewportSize.y;
  11901. }
  11902. }
  11903. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  11904. var pars = {
  11905. minFilter: LinearFilter,
  11906. magFilter: LinearFilter,
  11907. format: RGBAFormat
  11908. };
  11909. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  11910. shadow.map.texture.name = light.name + ".shadowMap";
  11911. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  11912. shadow.camera.updateProjectionMatrix();
  11913. }
  11914. if (shadow.map === null) {
  11915. var _pars = {
  11916. minFilter: NearestFilter,
  11917. magFilter: NearestFilter,
  11918. format: RGBAFormat
  11919. };
  11920. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  11921. shadow.map.texture.name = light.name + ".shadowMap";
  11922. shadow.camera.updateProjectionMatrix();
  11923. }
  11924. _renderer.setRenderTarget(shadow.map);
  11925. _renderer.clear();
  11926. var viewportCount = shadow.getViewportCount();
  11927. for (var vp = 0; vp < viewportCount; vp++) {
  11928. var viewport = shadow.getViewport(vp);
  11929. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  11930. _state.viewport(_viewport);
  11931. shadow.updateMatrices(light, vp);
  11932. _frustum = shadow.getFrustum();
  11933. renderObject(scene, camera, shadow.camera, light, this.type);
  11934. } // do blur pass for VSM
  11935. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  11936. VSMPass(shadow, camera);
  11937. }
  11938. shadow.needsUpdate = false;
  11939. }
  11940. scope.needsUpdate = false;
  11941. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  11942. };
  11943. function VSMPass(shadow, camera) {
  11944. var geometry = _objects.update(fullScreenMesh); // vertical pass
  11945. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  11946. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  11947. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  11948. _renderer.setRenderTarget(shadow.mapPass);
  11949. _renderer.clear();
  11950. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizonal pass
  11951. shadowMaterialHorizonal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  11952. shadowMaterialHorizonal.uniforms.resolution.value = shadow.mapSize;
  11953. shadowMaterialHorizonal.uniforms.radius.value = shadow.radius;
  11954. _renderer.setRenderTarget(shadow.map);
  11955. _renderer.clear();
  11956. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizonal, fullScreenMesh, null);
  11957. }
  11958. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  11959. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11960. var material = _depthMaterials[index];
  11961. if (material === undefined) {
  11962. material = new MeshDepthMaterial({
  11963. depthPacking: RGBADepthPacking,
  11964. morphTargets: useMorphing,
  11965. skinning: useSkinning
  11966. });
  11967. _depthMaterials[index] = material;
  11968. }
  11969. return material;
  11970. }
  11971. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  11972. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11973. var material = _distanceMaterials[index];
  11974. if (material === undefined) {
  11975. material = new MeshDistanceMaterial({
  11976. morphTargets: useMorphing,
  11977. skinning: useSkinning
  11978. });
  11979. _distanceMaterials[index] = material;
  11980. }
  11981. return material;
  11982. }
  11983. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  11984. var result = null;
  11985. var getMaterialVariant = getDepthMaterialVariant;
  11986. var customMaterial = object.customDepthMaterial;
  11987. if (light.isPointLight === true) {
  11988. getMaterialVariant = getDistanceMaterialVariant;
  11989. customMaterial = object.customDistanceMaterial;
  11990. }
  11991. if (customMaterial === undefined) {
  11992. var useMorphing = false;
  11993. if (material.morphTargets === true) {
  11994. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11995. }
  11996. var useSkinning = false;
  11997. if (object.isSkinnedMesh === true) {
  11998. if (material.skinning === true) {
  11999. useSkinning = true;
  12000. } else {
  12001. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  12002. }
  12003. }
  12004. var useInstancing = object.isInstancedMesh === true;
  12005. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  12006. } else {
  12007. result = customMaterial;
  12008. }
  12009. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  12010. // in this case we need a unique material instance reflecting the
  12011. // appropriate state
  12012. var keyA = result.uuid,
  12013. keyB = material.uuid;
  12014. var materialsForVariant = _materialCache[keyA];
  12015. if (materialsForVariant === undefined) {
  12016. materialsForVariant = {};
  12017. _materialCache[keyA] = materialsForVariant;
  12018. }
  12019. var cachedMaterial = materialsForVariant[keyB];
  12020. if (cachedMaterial === undefined) {
  12021. cachedMaterial = result.clone();
  12022. materialsForVariant[keyB] = cachedMaterial;
  12023. }
  12024. result = cachedMaterial;
  12025. }
  12026. result.visible = material.visible;
  12027. result.wireframe = material.wireframe;
  12028. if (type === VSMShadowMap) {
  12029. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  12030. } else {
  12031. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  12032. }
  12033. result.clipShadows = material.clipShadows;
  12034. result.clippingPlanes = material.clippingPlanes;
  12035. result.clipIntersection = material.clipIntersection;
  12036. result.wireframeLinewidth = material.wireframeLinewidth;
  12037. result.linewidth = material.linewidth;
  12038. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  12039. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  12040. result.nearDistance = shadowCameraNear;
  12041. result.farDistance = shadowCameraFar;
  12042. }
  12043. return result;
  12044. }
  12045. function renderObject(object, camera, shadowCamera, light, type) {
  12046. if (object.visible === false) return;
  12047. var visible = object.layers.test(camera.layers);
  12048. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  12049. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  12050. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  12051. var geometry = _objects.update(object);
  12052. var material = object.material;
  12053. if (Array.isArray(material)) {
  12054. var groups = geometry.groups;
  12055. for (var k = 0, kl = groups.length; k < kl; k++) {
  12056. var group = groups[k];
  12057. var groupMaterial = material[group.materialIndex];
  12058. if (groupMaterial && groupMaterial.visible) {
  12059. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  12060. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  12061. }
  12062. }
  12063. } else if (material.visible) {
  12064. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  12065. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  12066. }
  12067. }
  12068. }
  12069. var children = object.children;
  12070. for (var i = 0, l = children.length; i < l; i++) {
  12071. renderObject(children[i], camera, shadowCamera, light, type);
  12072. }
  12073. }
  12074. }
  12075. function WebGLState(gl, extensions, capabilities) {
  12076. var _equationToGL, _factorToGL;
  12077. var isWebGL2 = capabilities.isWebGL2;
  12078. function ColorBuffer() {
  12079. var locked = false;
  12080. var color = new Vector4();
  12081. var currentColorMask = null;
  12082. var currentColorClear = new Vector4(0, 0, 0, 0);
  12083. return {
  12084. setMask: function setMask(colorMask) {
  12085. if (currentColorMask !== colorMask && !locked) {
  12086. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12087. currentColorMask = colorMask;
  12088. }
  12089. },
  12090. setLocked: function setLocked(lock) {
  12091. locked = lock;
  12092. },
  12093. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12094. if (premultipliedAlpha === true) {
  12095. r *= a;
  12096. g *= a;
  12097. b *= a;
  12098. }
  12099. color.set(r, g, b, a);
  12100. if (currentColorClear.equals(color) === false) {
  12101. gl.clearColor(r, g, b, a);
  12102. currentColorClear.copy(color);
  12103. }
  12104. },
  12105. reset: function reset() {
  12106. locked = false;
  12107. currentColorMask = null;
  12108. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12109. }
  12110. };
  12111. }
  12112. function DepthBuffer() {
  12113. var locked = false;
  12114. var currentDepthMask = null;
  12115. var currentDepthFunc = null;
  12116. var currentDepthClear = null;
  12117. return {
  12118. setTest: function setTest(depthTest) {
  12119. if (depthTest) {
  12120. enable(2929);
  12121. } else {
  12122. disable(2929);
  12123. }
  12124. },
  12125. setMask: function setMask(depthMask) {
  12126. if (currentDepthMask !== depthMask && !locked) {
  12127. gl.depthMask(depthMask);
  12128. currentDepthMask = depthMask;
  12129. }
  12130. },
  12131. setFunc: function setFunc(depthFunc) {
  12132. if (currentDepthFunc !== depthFunc) {
  12133. if (depthFunc) {
  12134. switch (depthFunc) {
  12135. case NeverDepth:
  12136. gl.depthFunc(512);
  12137. break;
  12138. case AlwaysDepth:
  12139. gl.depthFunc(519);
  12140. break;
  12141. case LessDepth:
  12142. gl.depthFunc(513);
  12143. break;
  12144. case LessEqualDepth:
  12145. gl.depthFunc(515);
  12146. break;
  12147. case EqualDepth:
  12148. gl.depthFunc(514);
  12149. break;
  12150. case GreaterEqualDepth:
  12151. gl.depthFunc(518);
  12152. break;
  12153. case GreaterDepth:
  12154. gl.depthFunc(516);
  12155. break;
  12156. case NotEqualDepth:
  12157. gl.depthFunc(517);
  12158. break;
  12159. default:
  12160. gl.depthFunc(515);
  12161. }
  12162. } else {
  12163. gl.depthFunc(515);
  12164. }
  12165. currentDepthFunc = depthFunc;
  12166. }
  12167. },
  12168. setLocked: function setLocked(lock) {
  12169. locked = lock;
  12170. },
  12171. setClear: function setClear(depth) {
  12172. if (currentDepthClear !== depth) {
  12173. gl.clearDepth(depth);
  12174. currentDepthClear = depth;
  12175. }
  12176. },
  12177. reset: function reset() {
  12178. locked = false;
  12179. currentDepthMask = null;
  12180. currentDepthFunc = null;
  12181. currentDepthClear = null;
  12182. }
  12183. };
  12184. }
  12185. function StencilBuffer() {
  12186. var locked = false;
  12187. var currentStencilMask = null;
  12188. var currentStencilFunc = null;
  12189. var currentStencilRef = null;
  12190. var currentStencilFuncMask = null;
  12191. var currentStencilFail = null;
  12192. var currentStencilZFail = null;
  12193. var currentStencilZPass = null;
  12194. var currentStencilClear = null;
  12195. return {
  12196. setTest: function setTest(stencilTest) {
  12197. if (!locked) {
  12198. if (stencilTest) {
  12199. enable(2960);
  12200. } else {
  12201. disable(2960);
  12202. }
  12203. }
  12204. },
  12205. setMask: function setMask(stencilMask) {
  12206. if (currentStencilMask !== stencilMask && !locked) {
  12207. gl.stencilMask(stencilMask);
  12208. currentStencilMask = stencilMask;
  12209. }
  12210. },
  12211. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12212. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12213. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12214. currentStencilFunc = stencilFunc;
  12215. currentStencilRef = stencilRef;
  12216. currentStencilFuncMask = stencilMask;
  12217. }
  12218. },
  12219. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12220. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12221. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12222. currentStencilFail = stencilFail;
  12223. currentStencilZFail = stencilZFail;
  12224. currentStencilZPass = stencilZPass;
  12225. }
  12226. },
  12227. setLocked: function setLocked(lock) {
  12228. locked = lock;
  12229. },
  12230. setClear: function setClear(stencil) {
  12231. if (currentStencilClear !== stencil) {
  12232. gl.clearStencil(stencil);
  12233. currentStencilClear = stencil;
  12234. }
  12235. },
  12236. reset: function reset() {
  12237. locked = false;
  12238. currentStencilMask = null;
  12239. currentStencilFunc = null;
  12240. currentStencilRef = null;
  12241. currentStencilFuncMask = null;
  12242. currentStencilFail = null;
  12243. currentStencilZFail = null;
  12244. currentStencilZPass = null;
  12245. currentStencilClear = null;
  12246. }
  12247. };
  12248. } //
  12249. var colorBuffer = new ColorBuffer();
  12250. var depthBuffer = new DepthBuffer();
  12251. var stencilBuffer = new StencilBuffer();
  12252. var enabledCapabilities = {};
  12253. var currentProgram = null;
  12254. var currentBlendingEnabled = null;
  12255. var currentBlending = null;
  12256. var currentBlendEquation = null;
  12257. var currentBlendSrc = null;
  12258. var currentBlendDst = null;
  12259. var currentBlendEquationAlpha = null;
  12260. var currentBlendSrcAlpha = null;
  12261. var currentBlendDstAlpha = null;
  12262. var currentPremultipledAlpha = false;
  12263. var currentFlipSided = null;
  12264. var currentCullFace = null;
  12265. var currentLineWidth = null;
  12266. var currentPolygonOffsetFactor = null;
  12267. var currentPolygonOffsetUnits = null;
  12268. var maxTextures = gl.getParameter(35661);
  12269. var lineWidthAvailable = false;
  12270. var version = 0;
  12271. var glVersion = gl.getParameter(7938);
  12272. if (glVersion.indexOf('WebGL') !== -1) {
  12273. version = parseFloat(/^WebGL\ ([0-9])/.exec(glVersion)[1]);
  12274. lineWidthAvailable = version >= 1.0;
  12275. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12276. version = parseFloat(/^OpenGL\ ES\ ([0-9])/.exec(glVersion)[1]);
  12277. lineWidthAvailable = version >= 2.0;
  12278. }
  12279. var currentTextureSlot = null;
  12280. var currentBoundTextures = {};
  12281. var currentScissor = new Vector4();
  12282. var currentViewport = new Vector4();
  12283. function createTexture(type, target, count) {
  12284. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12285. var texture = gl.createTexture();
  12286. gl.bindTexture(type, texture);
  12287. gl.texParameteri(type, 10241, 9728);
  12288. gl.texParameteri(type, 10240, 9728);
  12289. for (var i = 0; i < count; i++) {
  12290. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12291. }
  12292. return texture;
  12293. }
  12294. var emptyTextures = {};
  12295. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12296. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12297. colorBuffer.setClear(0, 0, 0, 1);
  12298. depthBuffer.setClear(1);
  12299. stencilBuffer.setClear(0);
  12300. enable(2929);
  12301. depthBuffer.setFunc(LessEqualDepth);
  12302. setFlipSided(false);
  12303. setCullFace(CullFaceBack);
  12304. enable(2884);
  12305. setBlending(NoBlending); //
  12306. function enable(id) {
  12307. if (enabledCapabilities[id] !== true) {
  12308. gl.enable(id);
  12309. enabledCapabilities[id] = true;
  12310. }
  12311. }
  12312. function disable(id) {
  12313. if (enabledCapabilities[id] !== false) {
  12314. gl.disable(id);
  12315. enabledCapabilities[id] = false;
  12316. }
  12317. }
  12318. function useProgram(program) {
  12319. if (currentProgram !== program) {
  12320. gl.useProgram(program);
  12321. currentProgram = program;
  12322. return true;
  12323. }
  12324. return false;
  12325. }
  12326. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12327. if (isWebGL2) {
  12328. equationToGL[MinEquation] = 32775;
  12329. equationToGL[MaxEquation] = 32776;
  12330. } else {
  12331. var extension = extensions.get('EXT_blend_minmax');
  12332. if (extension !== null) {
  12333. equationToGL[MinEquation] = extension.MIN_EXT;
  12334. equationToGL[MaxEquation] = extension.MAX_EXT;
  12335. }
  12336. }
  12337. 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);
  12338. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  12339. if (blending === NoBlending) {
  12340. if (currentBlendingEnabled) {
  12341. disable(3042);
  12342. currentBlendingEnabled = false;
  12343. }
  12344. return;
  12345. }
  12346. if (!currentBlendingEnabled) {
  12347. enable(3042);
  12348. currentBlendingEnabled = true;
  12349. }
  12350. if (blending !== CustomBlending) {
  12351. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  12352. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  12353. gl.blendEquation(32774);
  12354. currentBlendEquation = AddEquation;
  12355. currentBlendEquationAlpha = AddEquation;
  12356. }
  12357. if (premultipliedAlpha) {
  12358. switch (blending) {
  12359. case NormalBlending:
  12360. gl.blendFuncSeparate(1, 771, 1, 771);
  12361. break;
  12362. case AdditiveBlending:
  12363. gl.blendFunc(1, 1);
  12364. break;
  12365. case SubtractiveBlending:
  12366. gl.blendFuncSeparate(0, 0, 769, 771);
  12367. break;
  12368. case MultiplyBlending:
  12369. gl.blendFuncSeparate(0, 768, 0, 770);
  12370. break;
  12371. default:
  12372. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12373. break;
  12374. }
  12375. } else {
  12376. switch (blending) {
  12377. case NormalBlending:
  12378. gl.blendFuncSeparate(770, 771, 1, 771);
  12379. break;
  12380. case AdditiveBlending:
  12381. gl.blendFunc(770, 1);
  12382. break;
  12383. case SubtractiveBlending:
  12384. gl.blendFunc(0, 769);
  12385. break;
  12386. case MultiplyBlending:
  12387. gl.blendFunc(0, 768);
  12388. break;
  12389. default:
  12390. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12391. break;
  12392. }
  12393. }
  12394. currentBlendSrc = null;
  12395. currentBlendDst = null;
  12396. currentBlendSrcAlpha = null;
  12397. currentBlendDstAlpha = null;
  12398. currentBlending = blending;
  12399. currentPremultipledAlpha = premultipliedAlpha;
  12400. }
  12401. return;
  12402. } // custom blending
  12403. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12404. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12405. blendDstAlpha = blendDstAlpha || blendDst;
  12406. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  12407. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  12408. currentBlendEquation = blendEquation;
  12409. currentBlendEquationAlpha = blendEquationAlpha;
  12410. }
  12411. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  12412. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  12413. currentBlendSrc = blendSrc;
  12414. currentBlendDst = blendDst;
  12415. currentBlendSrcAlpha = blendSrcAlpha;
  12416. currentBlendDstAlpha = blendDstAlpha;
  12417. }
  12418. currentBlending = blending;
  12419. currentPremultipledAlpha = null;
  12420. }
  12421. function setMaterial(material, frontFaceCW) {
  12422. material.side === DoubleSide ? disable(2884) : enable(2884);
  12423. var flipSided = material.side === BackSide;
  12424. if (frontFaceCW) flipSided = !flipSided;
  12425. setFlipSided(flipSided);
  12426. 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);
  12427. depthBuffer.setFunc(material.depthFunc);
  12428. depthBuffer.setTest(material.depthTest);
  12429. depthBuffer.setMask(material.depthWrite);
  12430. colorBuffer.setMask(material.colorWrite);
  12431. var stencilWrite = material.stencilWrite;
  12432. stencilBuffer.setTest(stencilWrite);
  12433. if (stencilWrite) {
  12434. stencilBuffer.setMask(material.stencilWriteMask);
  12435. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  12436. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  12437. }
  12438. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  12439. } //
  12440. function setFlipSided(flipSided) {
  12441. if (currentFlipSided !== flipSided) {
  12442. if (flipSided) {
  12443. gl.frontFace(2304);
  12444. } else {
  12445. gl.frontFace(2305);
  12446. }
  12447. currentFlipSided = flipSided;
  12448. }
  12449. }
  12450. function setCullFace(cullFace) {
  12451. if (cullFace !== CullFaceNone) {
  12452. enable(2884);
  12453. if (cullFace !== currentCullFace) {
  12454. if (cullFace === CullFaceBack) {
  12455. gl.cullFace(1029);
  12456. } else if (cullFace === CullFaceFront) {
  12457. gl.cullFace(1028);
  12458. } else {
  12459. gl.cullFace(1032);
  12460. }
  12461. }
  12462. } else {
  12463. disable(2884);
  12464. }
  12465. currentCullFace = cullFace;
  12466. }
  12467. function setLineWidth(width) {
  12468. if (width !== currentLineWidth) {
  12469. if (lineWidthAvailable) gl.lineWidth(width);
  12470. currentLineWidth = width;
  12471. }
  12472. }
  12473. function setPolygonOffset(polygonOffset, factor, units) {
  12474. if (polygonOffset) {
  12475. enable(32823);
  12476. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  12477. gl.polygonOffset(factor, units);
  12478. currentPolygonOffsetFactor = factor;
  12479. currentPolygonOffsetUnits = units;
  12480. }
  12481. } else {
  12482. disable(32823);
  12483. }
  12484. }
  12485. function setScissorTest(scissorTest) {
  12486. if (scissorTest) {
  12487. enable(3089);
  12488. } else {
  12489. disable(3089);
  12490. }
  12491. } // texture
  12492. function activeTexture(webglSlot) {
  12493. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  12494. if (currentTextureSlot !== webglSlot) {
  12495. gl.activeTexture(webglSlot);
  12496. currentTextureSlot = webglSlot;
  12497. }
  12498. }
  12499. function bindTexture(webglType, webglTexture) {
  12500. if (currentTextureSlot === null) {
  12501. activeTexture();
  12502. }
  12503. var boundTexture = currentBoundTextures[currentTextureSlot];
  12504. if (boundTexture === undefined) {
  12505. boundTexture = {
  12506. type: undefined,
  12507. texture: undefined
  12508. };
  12509. currentBoundTextures[currentTextureSlot] = boundTexture;
  12510. }
  12511. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  12512. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  12513. boundTexture.type = webglType;
  12514. boundTexture.texture = webglTexture;
  12515. }
  12516. }
  12517. function unbindTexture() {
  12518. var boundTexture = currentBoundTextures[currentTextureSlot];
  12519. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  12520. gl.bindTexture(boundTexture.type, null);
  12521. boundTexture.type = undefined;
  12522. boundTexture.texture = undefined;
  12523. }
  12524. }
  12525. function compressedTexImage2D() {
  12526. try {
  12527. gl.compressedTexImage2D.apply(gl, arguments);
  12528. } catch (error) {
  12529. console.error('THREE.WebGLState:', error);
  12530. }
  12531. }
  12532. function texImage2D() {
  12533. try {
  12534. gl.texImage2D.apply(gl, arguments);
  12535. } catch (error) {
  12536. console.error('THREE.WebGLState:', error);
  12537. }
  12538. }
  12539. function texImage3D() {
  12540. try {
  12541. gl.texImage3D.apply(gl, arguments);
  12542. } catch (error) {
  12543. console.error('THREE.WebGLState:', error);
  12544. }
  12545. } //
  12546. function scissor(scissor) {
  12547. if (currentScissor.equals(scissor) === false) {
  12548. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  12549. currentScissor.copy(scissor);
  12550. }
  12551. }
  12552. function viewport(viewport) {
  12553. if (currentViewport.equals(viewport) === false) {
  12554. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  12555. currentViewport.copy(viewport);
  12556. }
  12557. } //
  12558. function reset() {
  12559. enabledCapabilities = {};
  12560. currentTextureSlot = null;
  12561. currentBoundTextures = {};
  12562. currentProgram = null;
  12563. currentBlendingEnabled = null;
  12564. currentBlending = null;
  12565. currentBlendEquation = null;
  12566. currentBlendSrc = null;
  12567. currentBlendDst = null;
  12568. currentBlendEquationAlpha = null;
  12569. currentBlendSrcAlpha = null;
  12570. currentBlendDstAlpha = null;
  12571. currentPremultipledAlpha = false;
  12572. currentFlipSided = null;
  12573. currentCullFace = null;
  12574. currentLineWidth = null;
  12575. currentPolygonOffsetFactor = null;
  12576. currentPolygonOffsetUnits = null;
  12577. colorBuffer.reset();
  12578. depthBuffer.reset();
  12579. stencilBuffer.reset();
  12580. }
  12581. return {
  12582. buffers: {
  12583. color: colorBuffer,
  12584. depth: depthBuffer,
  12585. stencil: stencilBuffer
  12586. },
  12587. enable: enable,
  12588. disable: disable,
  12589. useProgram: useProgram,
  12590. setBlending: setBlending,
  12591. setMaterial: setMaterial,
  12592. setFlipSided: setFlipSided,
  12593. setCullFace: setCullFace,
  12594. setLineWidth: setLineWidth,
  12595. setPolygonOffset: setPolygonOffset,
  12596. setScissorTest: setScissorTest,
  12597. activeTexture: activeTexture,
  12598. bindTexture: bindTexture,
  12599. unbindTexture: unbindTexture,
  12600. compressedTexImage2D: compressedTexImage2D,
  12601. texImage2D: texImage2D,
  12602. texImage3D: texImage3D,
  12603. scissor: scissor,
  12604. viewport: viewport,
  12605. reset: reset
  12606. };
  12607. }
  12608. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  12609. var _wrappingToGL, _filterToGL;
  12610. var isWebGL2 = capabilities.isWebGL2;
  12611. var maxTextures = capabilities.maxTextures;
  12612. var maxCubemapSize = capabilities.maxCubemapSize;
  12613. var maxTextureSize = capabilities.maxTextureSize;
  12614. var maxSamples = capabilities.maxSamples;
  12615. var _videoTextures = new WeakMap();
  12616. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  12617. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  12618. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  12619. var useOffscreenCanvas = false;
  12620. try {
  12621. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext("2d") !== null;
  12622. } catch (err) {// Ignore any errors
  12623. }
  12624. function createCanvas(width, height) {
  12625. // Use OffscreenCanvas when available. Specially needed in web workers
  12626. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  12627. }
  12628. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  12629. var scale = 1; // handle case if texture exceeds max size
  12630. if (image.width > maxSize || image.height > maxSize) {
  12631. scale = maxSize / Math.max(image.width, image.height);
  12632. } // only perform resize if necessary
  12633. if (scale < 1 || needsPowerOfTwo === true) {
  12634. // only perform resize for certain image types
  12635. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  12636. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  12637. var width = floor(scale * image.width);
  12638. var height = floor(scale * image.height);
  12639. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  12640. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  12641. canvas.width = width;
  12642. canvas.height = height;
  12643. var context = canvas.getContext('2d');
  12644. context.drawImage(image, 0, 0, width, height);
  12645. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  12646. return canvas;
  12647. } else {
  12648. if ('data' in image) {
  12649. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  12650. }
  12651. return image;
  12652. }
  12653. }
  12654. return image;
  12655. }
  12656. function isPowerOfTwo(image) {
  12657. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  12658. }
  12659. function textureNeedsPowerOfTwo(texture) {
  12660. if (isWebGL2) return false;
  12661. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12662. }
  12663. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  12664. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12665. }
  12666. function generateMipmap(target, texture, width, height) {
  12667. _gl.generateMipmap(target);
  12668. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12669. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  12670. }
  12671. function getInternalFormat(internalFormatName, glFormat, glType) {
  12672. if (isWebGL2 === false) return glFormat;
  12673. if (internalFormatName !== null) {
  12674. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  12675. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  12676. }
  12677. var internalFormat = glFormat;
  12678. if (glFormat === 6403) {
  12679. if (glType === 5126) internalFormat = 33326;
  12680. if (glType === 5131) internalFormat = 33325;
  12681. if (glType === 5121) internalFormat = 33321;
  12682. }
  12683. if (glFormat === 6407) {
  12684. if (glType === 5126) internalFormat = 34837;
  12685. if (glType === 5131) internalFormat = 34843;
  12686. if (glType === 5121) internalFormat = 32849;
  12687. }
  12688. if (glFormat === 6408) {
  12689. if (glType === 5126) internalFormat = 34836;
  12690. if (glType === 5131) internalFormat = 34842;
  12691. if (glType === 5121) internalFormat = 32856;
  12692. }
  12693. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  12694. extensions.get('EXT_color_buffer_float');
  12695. }
  12696. return internalFormat;
  12697. } // Fallback filters for non-power-of-2 textures
  12698. function filterFallback(f) {
  12699. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  12700. return 9728;
  12701. }
  12702. return 9729;
  12703. } //
  12704. function onTextureDispose(event) {
  12705. var texture = event.target;
  12706. texture.removeEventListener('dispose', onTextureDispose);
  12707. deallocateTexture(texture);
  12708. if (texture.isVideoTexture) {
  12709. _videoTextures.delete(texture);
  12710. }
  12711. info.memory.textures--;
  12712. }
  12713. function onRenderTargetDispose(event) {
  12714. var renderTarget = event.target;
  12715. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  12716. deallocateRenderTarget(renderTarget);
  12717. info.memory.textures--;
  12718. } //
  12719. function deallocateTexture(texture) {
  12720. var textureProperties = properties.get(texture);
  12721. if (textureProperties.__webglInit === undefined) return;
  12722. _gl.deleteTexture(textureProperties.__webglTexture);
  12723. properties.remove(texture);
  12724. }
  12725. function deallocateRenderTarget(renderTarget) {
  12726. var renderTargetProperties = properties.get(renderTarget);
  12727. var textureProperties = properties.get(renderTarget.texture);
  12728. if (!renderTarget) return;
  12729. if (textureProperties.__webglTexture !== undefined) {
  12730. _gl.deleteTexture(textureProperties.__webglTexture);
  12731. }
  12732. if (renderTarget.depthTexture) {
  12733. renderTarget.depthTexture.dispose();
  12734. }
  12735. if (renderTarget.isWebGLCubeRenderTarget) {
  12736. for (var i = 0; i < 6; i++) {
  12737. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  12738. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  12739. }
  12740. } else {
  12741. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  12742. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  12743. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  12744. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  12745. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  12746. }
  12747. properties.remove(renderTarget.texture);
  12748. properties.remove(renderTarget);
  12749. } //
  12750. var textureUnits = 0;
  12751. function resetTextureUnits() {
  12752. textureUnits = 0;
  12753. }
  12754. function allocateTextureUnit() {
  12755. var textureUnit = textureUnits;
  12756. if (textureUnit >= maxTextures) {
  12757. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  12758. }
  12759. textureUnits += 1;
  12760. return textureUnit;
  12761. } //
  12762. function setTexture2D(texture, slot) {
  12763. var textureProperties = properties.get(texture);
  12764. if (texture.isVideoTexture) updateVideoTexture(texture);
  12765. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12766. var image = texture.image;
  12767. if (image === undefined) {
  12768. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  12769. } else if (image.complete === false) {
  12770. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  12771. } else {
  12772. uploadTexture(textureProperties, texture, slot);
  12773. return;
  12774. }
  12775. }
  12776. state.activeTexture(33984 + slot);
  12777. state.bindTexture(3553, textureProperties.__webglTexture);
  12778. }
  12779. function setTexture2DArray(texture, slot) {
  12780. var textureProperties = properties.get(texture);
  12781. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12782. uploadTexture(textureProperties, texture, slot);
  12783. return;
  12784. }
  12785. state.activeTexture(33984 + slot);
  12786. state.bindTexture(35866, textureProperties.__webglTexture);
  12787. }
  12788. function setTexture3D(texture, slot) {
  12789. var textureProperties = properties.get(texture);
  12790. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12791. uploadTexture(textureProperties, texture, slot);
  12792. return;
  12793. }
  12794. state.activeTexture(33984 + slot);
  12795. state.bindTexture(32879, textureProperties.__webglTexture);
  12796. }
  12797. function setTextureCube(texture, slot) {
  12798. var textureProperties = properties.get(texture);
  12799. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12800. uploadCubeTexture(textureProperties, texture, slot);
  12801. return;
  12802. }
  12803. state.activeTexture(33984 + slot);
  12804. state.bindTexture(34067, textureProperties.__webglTexture);
  12805. }
  12806. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  12807. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  12808. function setTextureParameters(textureType, texture, supportsMips) {
  12809. if (supportsMips) {
  12810. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  12811. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  12812. if (textureType === 32879 || textureType === 35866) {
  12813. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  12814. }
  12815. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  12816. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  12817. } else {
  12818. _gl.texParameteri(textureType, 10242, 33071);
  12819. _gl.texParameteri(textureType, 10243, 33071);
  12820. if (textureType === 32879 || textureType === 35866) {
  12821. _gl.texParameteri(textureType, 32882, 33071);
  12822. }
  12823. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  12824. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  12825. }
  12826. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  12827. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  12828. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  12829. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  12830. }
  12831. }
  12832. var extension = extensions.get('EXT_texture_filter_anisotropic');
  12833. if (extension) {
  12834. if (texture.type === FloatType && extensions.get('OES_texture_float_linear') === null) return;
  12835. if (texture.type === HalfFloatType && (isWebGL2 || extensions.get('OES_texture_half_float_linear')) === null) return;
  12836. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  12837. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  12838. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  12839. }
  12840. }
  12841. }
  12842. function initTexture(textureProperties, texture) {
  12843. if (textureProperties.__webglInit === undefined) {
  12844. textureProperties.__webglInit = true;
  12845. texture.addEventListener('dispose', onTextureDispose);
  12846. textureProperties.__webglTexture = _gl.createTexture();
  12847. info.memory.textures++;
  12848. }
  12849. }
  12850. function uploadTexture(textureProperties, texture, slot) {
  12851. var textureType = 3553;
  12852. if (texture.isDataTexture2DArray) textureType = 35866;
  12853. if (texture.isDataTexture3D) textureType = 32879;
  12854. initTexture(textureProperties, texture);
  12855. state.activeTexture(33984 + slot);
  12856. state.bindTexture(textureType, textureProperties.__webglTexture);
  12857. _gl.pixelStorei(37440, texture.flipY);
  12858. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  12859. _gl.pixelStorei(3317, texture.unpackAlignment);
  12860. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  12861. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  12862. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  12863. glFormat = utils.convert(texture.format);
  12864. var glType = utils.convert(texture.type),
  12865. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  12866. setTextureParameters(textureType, texture, supportsMips);
  12867. var mipmap;
  12868. var mipmaps = texture.mipmaps;
  12869. if (texture.isDepthTexture) {
  12870. // populate depth texture with dummy data
  12871. glInternalFormat = 6402;
  12872. if (isWebGL2) {
  12873. if (texture.type === FloatType) {
  12874. glInternalFormat = 36012;
  12875. } else if (texture.type === UnsignedIntType) {
  12876. glInternalFormat = 33190;
  12877. } else if (texture.type === UnsignedInt248Type) {
  12878. glInternalFormat = 35056;
  12879. } else {
  12880. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  12881. }
  12882. } else {
  12883. if (texture.type === FloatType) {
  12884. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  12885. }
  12886. } // validation checks for WebGL 1
  12887. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  12888. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12889. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12890. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12891. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  12892. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  12893. texture.type = UnsignedShortType;
  12894. glType = utils.convert(texture.type);
  12895. }
  12896. }
  12897. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  12898. // Depth stencil textures need the DEPTH_STENCIL internal format
  12899. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12900. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12901. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12902. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12903. if (texture.type !== UnsignedInt248Type) {
  12904. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  12905. texture.type = UnsignedInt248Type;
  12906. glType = utils.convert(texture.type);
  12907. }
  12908. } //
  12909. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  12910. } else if (texture.isDataTexture) {
  12911. // use manually created mipmaps if available
  12912. // if there are no manual mipmaps
  12913. // set 0 level mipmap and then use GL to generate other mipmap levels
  12914. if (mipmaps.length > 0 && supportsMips) {
  12915. for (var i = 0, il = mipmaps.length; i < il; i++) {
  12916. mipmap = mipmaps[i];
  12917. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  12918. }
  12919. texture.generateMipmaps = false;
  12920. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12921. } else {
  12922. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  12923. textureProperties.__maxMipLevel = 0;
  12924. }
  12925. } else if (texture.isCompressedTexture) {
  12926. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  12927. mipmap = mipmaps[_i];
  12928. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  12929. if (glFormat !== null) {
  12930. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  12931. } else {
  12932. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  12933. }
  12934. } else {
  12935. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  12936. }
  12937. }
  12938. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12939. } else if (texture.isDataTexture2DArray) {
  12940. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  12941. textureProperties.__maxMipLevel = 0;
  12942. } else if (texture.isDataTexture3D) {
  12943. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  12944. textureProperties.__maxMipLevel = 0;
  12945. } else {
  12946. // regular Texture (image, video, canvas)
  12947. // use manually created mipmaps if available
  12948. // if there are no manual mipmaps
  12949. // set 0 level mipmap and then use GL to generate other mipmap levels
  12950. if (mipmaps.length > 0 && supportsMips) {
  12951. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  12952. mipmap = mipmaps[_i2];
  12953. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  12954. }
  12955. texture.generateMipmaps = false;
  12956. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12957. } else {
  12958. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  12959. textureProperties.__maxMipLevel = 0;
  12960. }
  12961. }
  12962. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  12963. generateMipmap(textureType, texture, image.width, image.height);
  12964. }
  12965. textureProperties.__version = texture.version;
  12966. if (texture.onUpdate) texture.onUpdate(texture);
  12967. }
  12968. function uploadCubeTexture(textureProperties, texture, slot) {
  12969. if (texture.image.length !== 6) return;
  12970. initTexture(textureProperties, texture);
  12971. state.activeTexture(33984 + slot);
  12972. state.bindTexture(34067, textureProperties.__webglTexture);
  12973. _gl.pixelStorei(37440, texture.flipY);
  12974. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  12975. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  12976. var cubeImage = [];
  12977. for (var i = 0; i < 6; i++) {
  12978. if (!isCompressed && !isDataTexture) {
  12979. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  12980. } else {
  12981. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  12982. }
  12983. }
  12984. var image = cubeImage[0],
  12985. supportsMips = isPowerOfTwo(image) || isWebGL2,
  12986. glFormat = utils.convert(texture.format),
  12987. glType = utils.convert(texture.type),
  12988. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  12989. setTextureParameters(34067, texture, supportsMips);
  12990. var mipmaps;
  12991. if (isCompressed) {
  12992. for (var _i3 = 0; _i3 < 6; _i3++) {
  12993. mipmaps = cubeImage[_i3].mipmaps;
  12994. for (var j = 0; j < mipmaps.length; j++) {
  12995. var mipmap = mipmaps[j];
  12996. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  12997. if (glFormat !== null) {
  12998. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  12999. } else {
  13000. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  13001. }
  13002. } else {
  13003. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13004. }
  13005. }
  13006. }
  13007. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13008. } else {
  13009. mipmaps = texture.mipmaps;
  13010. for (var _i4 = 0; _i4 < 6; _i4++) {
  13011. if (isDataTexture) {
  13012. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  13013. for (var _j = 0; _j < mipmaps.length; _j++) {
  13014. var _mipmap = mipmaps[_j];
  13015. var mipmapImage = _mipmap.image[_i4].image;
  13016. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  13017. }
  13018. } else {
  13019. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  13020. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  13021. var _mipmap2 = mipmaps[_j2];
  13022. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  13023. }
  13024. }
  13025. }
  13026. textureProperties.__maxMipLevel = mipmaps.length;
  13027. }
  13028. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13029. // We assume images for cube map have the same size.
  13030. generateMipmap(34067, texture, image.width, image.height);
  13031. }
  13032. textureProperties.__version = texture.version;
  13033. if (texture.onUpdate) texture.onUpdate(texture);
  13034. } // Render targets
  13035. // Setup storage for target texture and bind it to correct framebuffer
  13036. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  13037. var glFormat = utils.convert(renderTarget.texture.format);
  13038. var glType = utils.convert(renderTarget.texture.type);
  13039. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13040. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  13041. _gl.bindFramebuffer(36160, framebuffer);
  13042. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(renderTarget.texture).__webglTexture, 0);
  13043. _gl.bindFramebuffer(36160, null);
  13044. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13045. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  13046. _gl.bindRenderbuffer(36161, renderbuffer);
  13047. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  13048. var glInternalFormat = 33189;
  13049. if (isMultisample) {
  13050. var depthTexture = renderTarget.depthTexture;
  13051. if (depthTexture && depthTexture.isDepthTexture) {
  13052. if (depthTexture.type === FloatType) {
  13053. glInternalFormat = 36012;
  13054. } else if (depthTexture.type === UnsignedIntType) {
  13055. glInternalFormat = 33190;
  13056. }
  13057. }
  13058. var samples = getRenderTargetSamples(renderTarget);
  13059. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13060. } else {
  13061. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  13062. }
  13063. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  13064. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  13065. if (isMultisample) {
  13066. var _samples = getRenderTargetSamples(renderTarget);
  13067. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  13068. } else {
  13069. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  13070. }
  13071. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  13072. } else {
  13073. var glFormat = utils.convert(renderTarget.texture.format);
  13074. var glType = utils.convert(renderTarget.texture.type);
  13075. var _glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13076. if (isMultisample) {
  13077. var _samples2 = getRenderTargetSamples(renderTarget);
  13078. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  13079. } else {
  13080. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  13081. }
  13082. }
  13083. _gl.bindRenderbuffer(36161, null);
  13084. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  13085. function setupDepthTexture(framebuffer, renderTarget) {
  13086. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  13087. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  13088. _gl.bindFramebuffer(36160, framebuffer);
  13089. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  13090. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  13091. } // upload an empty depth texture with framebuffer size
  13092. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  13093. renderTarget.depthTexture.image.width = renderTarget.width;
  13094. renderTarget.depthTexture.image.height = renderTarget.height;
  13095. renderTarget.depthTexture.needsUpdate = true;
  13096. }
  13097. setTexture2D(renderTarget.depthTexture, 0);
  13098. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13099. if (renderTarget.depthTexture.format === DepthFormat) {
  13100. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13101. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13102. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13103. } else {
  13104. throw new Error('Unknown depthTexture format');
  13105. }
  13106. } // Setup GL resources for a non-texture depth buffer
  13107. function setupDepthRenderbuffer(renderTarget) {
  13108. var renderTargetProperties = properties.get(renderTarget);
  13109. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13110. if (renderTarget.depthTexture) {
  13111. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13112. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13113. } else {
  13114. if (isCube) {
  13115. renderTargetProperties.__webglDepthbuffer = [];
  13116. for (var i = 0; i < 6; i++) {
  13117. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13118. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13119. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13120. }
  13121. } else {
  13122. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13123. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13124. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13125. }
  13126. }
  13127. _gl.bindFramebuffer(36160, null);
  13128. } // Set up GL resources for the render target
  13129. function setupRenderTarget(renderTarget) {
  13130. var renderTargetProperties = properties.get(renderTarget);
  13131. var textureProperties = properties.get(renderTarget.texture);
  13132. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13133. textureProperties.__webglTexture = _gl.createTexture();
  13134. info.memory.textures++;
  13135. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13136. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13137. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13138. if (isWebGL2 && renderTarget.texture.format === RGBFormat && (renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType)) {
  13139. renderTarget.texture.format = RGBAFormat;
  13140. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13141. } // Setup framebuffer
  13142. if (isCube) {
  13143. renderTargetProperties.__webglFramebuffer = [];
  13144. for (var i = 0; i < 6; i++) {
  13145. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13146. }
  13147. } else {
  13148. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13149. if (isMultisample) {
  13150. if (isWebGL2) {
  13151. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13152. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13153. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13154. var glFormat = utils.convert(renderTarget.texture.format);
  13155. var glType = utils.convert(renderTarget.texture.type);
  13156. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13157. var samples = getRenderTargetSamples(renderTarget);
  13158. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13159. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13160. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13161. _gl.bindRenderbuffer(36161, null);
  13162. if (renderTarget.depthBuffer) {
  13163. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13164. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13165. }
  13166. _gl.bindFramebuffer(36160, null);
  13167. } else {
  13168. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13169. }
  13170. }
  13171. } // Setup color buffer
  13172. if (isCube) {
  13173. state.bindTexture(34067, textureProperties.__webglTexture);
  13174. setTextureParameters(34067, renderTarget.texture, supportsMips);
  13175. for (var _i5 = 0; _i5 < 6; _i5++) {
  13176. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13177. }
  13178. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13179. generateMipmap(34067, renderTarget.texture, renderTarget.width, renderTarget.height);
  13180. }
  13181. state.bindTexture(34067, null);
  13182. } else {
  13183. state.bindTexture(3553, textureProperties.__webglTexture);
  13184. setTextureParameters(3553, renderTarget.texture, supportsMips);
  13185. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553);
  13186. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13187. generateMipmap(3553, renderTarget.texture, renderTarget.width, renderTarget.height);
  13188. }
  13189. state.bindTexture(3553, null);
  13190. } // Setup depth and stencil buffers
  13191. if (renderTarget.depthBuffer) {
  13192. setupDepthRenderbuffer(renderTarget);
  13193. }
  13194. }
  13195. function updateRenderTargetMipmap(renderTarget) {
  13196. var texture = renderTarget.texture;
  13197. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13198. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13199. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13200. var webglTexture = properties.get(texture).__webglTexture;
  13201. state.bindTexture(target, webglTexture);
  13202. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13203. state.bindTexture(target, null);
  13204. }
  13205. }
  13206. function updateMultisampleRenderTarget(renderTarget) {
  13207. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13208. if (isWebGL2) {
  13209. var renderTargetProperties = properties.get(renderTarget);
  13210. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13211. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13212. var width = renderTarget.width;
  13213. var height = renderTarget.height;
  13214. var mask = 16384;
  13215. if (renderTarget.depthBuffer) mask |= 256;
  13216. if (renderTarget.stencilBuffer) mask |= 1024;
  13217. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13218. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13219. } else {
  13220. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13221. }
  13222. }
  13223. }
  13224. function getRenderTargetSamples(renderTarget) {
  13225. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13226. }
  13227. function updateVideoTexture(texture) {
  13228. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13229. if (_videoTextures.get(texture) !== frame) {
  13230. _videoTextures.set(texture, frame);
  13231. texture.update();
  13232. }
  13233. } // backwards compatibility
  13234. var warnedTexture2D = false;
  13235. var warnedTextureCube = false;
  13236. function safeSetTexture2D(texture, slot) {
  13237. if (texture && texture.isWebGLRenderTarget) {
  13238. if (warnedTexture2D === false) {
  13239. console.warn("THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead.");
  13240. warnedTexture2D = true;
  13241. }
  13242. texture = texture.texture;
  13243. }
  13244. setTexture2D(texture, slot);
  13245. }
  13246. function safeSetTextureCube(texture, slot) {
  13247. if (texture && texture.isWebGLCubeRenderTarget) {
  13248. if (warnedTextureCube === false) {
  13249. console.warn("THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead.");
  13250. warnedTextureCube = true;
  13251. }
  13252. texture = texture.texture;
  13253. }
  13254. setTextureCube(texture, slot);
  13255. } //
  13256. this.allocateTextureUnit = allocateTextureUnit;
  13257. this.resetTextureUnits = resetTextureUnits;
  13258. this.setTexture2D = setTexture2D;
  13259. this.setTexture2DArray = setTexture2DArray;
  13260. this.setTexture3D = setTexture3D;
  13261. this.setTextureCube = setTextureCube;
  13262. this.setupRenderTarget = setupRenderTarget;
  13263. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13264. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13265. this.safeSetTexture2D = safeSetTexture2D;
  13266. this.safeSetTextureCube = safeSetTextureCube;
  13267. }
  13268. function WebGLUtils(gl, extensions, capabilities) {
  13269. var isWebGL2 = capabilities.isWebGL2;
  13270. function convert(p) {
  13271. var extension;
  13272. if (p === UnsignedByteType) return 5121;
  13273. if (p === UnsignedShort4444Type) return 32819;
  13274. if (p === UnsignedShort5551Type) return 32820;
  13275. if (p === UnsignedShort565Type) return 33635;
  13276. if (p === ByteType) return 5120;
  13277. if (p === ShortType) return 5122;
  13278. if (p === UnsignedShortType) return 5123;
  13279. if (p === IntType) return 5124;
  13280. if (p === UnsignedIntType) return 5125;
  13281. if (p === FloatType) return 5126;
  13282. if (p === HalfFloatType) {
  13283. if (isWebGL2) return 5131;
  13284. extension = extensions.get('OES_texture_half_float');
  13285. if (extension !== null) {
  13286. return extension.HALF_FLOAT_OES;
  13287. } else {
  13288. return null;
  13289. }
  13290. }
  13291. if (p === AlphaFormat) return 6406;
  13292. if (p === RGBFormat) return 6407;
  13293. if (p === RGBAFormat) return 6408;
  13294. if (p === LuminanceFormat) return 6409;
  13295. if (p === LuminanceAlphaFormat) return 6410;
  13296. if (p === DepthFormat) return 6402;
  13297. if (p === DepthStencilFormat) return 34041;
  13298. if (p === RedFormat) return 6403; // WebGL2 formats.
  13299. if (p === RedIntegerFormat) return 36244;
  13300. if (p === RGFormat) return 33319;
  13301. if (p === RGIntegerFormat) return 33320;
  13302. if (p === RGBIntegerFormat) return 36248;
  13303. if (p === RGBAIntegerFormat) return 36249;
  13304. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13305. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13306. if (extension !== null) {
  13307. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13308. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13309. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13310. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13311. } else {
  13312. return null;
  13313. }
  13314. }
  13315. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13316. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13317. if (extension !== null) {
  13318. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13319. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13320. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13321. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13322. } else {
  13323. return null;
  13324. }
  13325. }
  13326. if (p === RGB_ETC1_Format) {
  13327. extension = extensions.get('WEBGL_compressed_texture_etc1');
  13328. if (extension !== null) {
  13329. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13330. } else {
  13331. return null;
  13332. }
  13333. }
  13334. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  13335. extension = extensions.get('WEBGL_compressed_texture_etc');
  13336. if (extension !== null) {
  13337. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  13338. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13339. }
  13340. }
  13341. 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) {
  13342. extension = extensions.get('WEBGL_compressed_texture_astc');
  13343. if (extension !== null) {
  13344. // TODO Complete?
  13345. return p;
  13346. } else {
  13347. return null;
  13348. }
  13349. }
  13350. if (p === RGBA_BPTC_Format) {
  13351. extension = extensions.get('EXT_texture_compression_bptc');
  13352. if (extension !== null) {
  13353. // TODO Complete?
  13354. return p;
  13355. } else {
  13356. return null;
  13357. }
  13358. }
  13359. if (p === UnsignedInt248Type) {
  13360. if (isWebGL2) return 34042;
  13361. extension = extensions.get('WEBGL_depth_texture');
  13362. if (extension !== null) {
  13363. return extension.UNSIGNED_INT_24_8_WEBGL;
  13364. } else {
  13365. return null;
  13366. }
  13367. }
  13368. }
  13369. return {
  13370. convert: convert
  13371. };
  13372. }
  13373. function ArrayCamera(array) {
  13374. PerspectiveCamera.call(this);
  13375. this.cameras = array || [];
  13376. }
  13377. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  13378. constructor: ArrayCamera,
  13379. isArrayCamera: true
  13380. });
  13381. function Group() {
  13382. Object3D.call(this);
  13383. this.type = 'Group';
  13384. }
  13385. Group.prototype = Object.assign(Object.create(Object3D.prototype), {
  13386. constructor: Group,
  13387. isGroup: true
  13388. });
  13389. function WebXRController() {
  13390. this._targetRay = null;
  13391. this._grip = null;
  13392. this._hand = null;
  13393. }
  13394. Object.assign(WebXRController.prototype, {
  13395. constructor: WebXRController,
  13396. getHandSpace: function getHandSpace() {
  13397. if (this._hand === null) {
  13398. this._hand = new Group();
  13399. this._hand.matrixAutoUpdate = false;
  13400. this._hand.visible = false;
  13401. this._hand.joints = [];
  13402. this._hand.inputState = {
  13403. pinching: false
  13404. };
  13405. if (window.XRHand) {
  13406. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13407. // The transform of this joint will be updated with the joint pose on each frame
  13408. var joint = new Group();
  13409. joint.matrixAutoUpdate = false;
  13410. joint.visible = false;
  13411. this._hand.joints.push(joint); // ??
  13412. this._hand.add(joint);
  13413. }
  13414. }
  13415. }
  13416. return this._hand;
  13417. },
  13418. getTargetRaySpace: function getTargetRaySpace() {
  13419. if (this._targetRay === null) {
  13420. this._targetRay = new Group();
  13421. this._targetRay.matrixAutoUpdate = false;
  13422. this._targetRay.visible = false;
  13423. }
  13424. return this._targetRay;
  13425. },
  13426. getGripSpace: function getGripSpace() {
  13427. if (this._grip === null) {
  13428. this._grip = new Group();
  13429. this._grip.matrixAutoUpdate = false;
  13430. this._grip.visible = false;
  13431. }
  13432. return this._grip;
  13433. },
  13434. dispatchEvent: function dispatchEvent(event) {
  13435. if (this._targetRay !== null) {
  13436. this._targetRay.dispatchEvent(event);
  13437. }
  13438. if (this._grip !== null) {
  13439. this._grip.dispatchEvent(event);
  13440. }
  13441. if (this._hand !== null) {
  13442. this._hand.dispatchEvent(event);
  13443. }
  13444. return this;
  13445. },
  13446. disconnect: function disconnect(inputSource) {
  13447. this.dispatchEvent({
  13448. type: 'disconnected',
  13449. data: inputSource
  13450. });
  13451. if (this._targetRay !== null) {
  13452. this._targetRay.visible = false;
  13453. }
  13454. if (this._grip !== null) {
  13455. this._grip.visible = false;
  13456. }
  13457. if (this._hand !== null) {
  13458. this._hand.visible = false;
  13459. }
  13460. return this;
  13461. },
  13462. update: function update(inputSource, frame, referenceSpace) {
  13463. var inputPose = null;
  13464. var gripPose = null;
  13465. var handPose = null;
  13466. var targetRay = this._targetRay;
  13467. var grip = this._grip;
  13468. var hand = this._hand;
  13469. if (inputSource && frame.session.visibilityState !== 'visible-blurred') {
  13470. if (hand && inputSource.hand) {
  13471. handPose = true;
  13472. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13473. if (inputSource.hand[i]) {
  13474. // Update the joints groups with the XRJoint poses
  13475. var jointPose = frame.getJointPose(inputSource.hand[i], referenceSpace);
  13476. var joint = hand.joints[i];
  13477. if (jointPose !== null) {
  13478. joint.matrix.fromArray(jointPose.transform.matrix);
  13479. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  13480. joint.jointRadius = jointPose.radius;
  13481. }
  13482. joint.visible = jointPose !== null; // Custom events
  13483. // Check pinch
  13484. var indexTip = hand.joints[window.XRHand.INDEX_PHALANX_TIP];
  13485. var thumbTip = hand.joints[window.XRHand.THUMB_PHALANX_TIP];
  13486. var distance = indexTip.position.distanceTo(thumbTip.position);
  13487. var distanceToPinch = 0.02;
  13488. var threshold = 0.005;
  13489. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  13490. hand.inputState.pinching = false;
  13491. this.dispatchEvent({
  13492. type: "pinchend",
  13493. handedness: inputSource.handedness,
  13494. target: this
  13495. });
  13496. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  13497. hand.inputState.pinching = true;
  13498. this.dispatchEvent({
  13499. type: "pinchstart",
  13500. handedness: inputSource.handedness,
  13501. target: this
  13502. });
  13503. }
  13504. }
  13505. }
  13506. } else {
  13507. if (targetRay !== null) {
  13508. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  13509. if (inputPose !== null) {
  13510. targetRay.matrix.fromArray(inputPose.transform.matrix);
  13511. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  13512. }
  13513. }
  13514. if (grip !== null && inputSource.gripSpace) {
  13515. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  13516. if (gripPose !== null) {
  13517. grip.matrix.fromArray(gripPose.transform.matrix);
  13518. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  13519. }
  13520. }
  13521. }
  13522. }
  13523. if (targetRay !== null) {
  13524. targetRay.visible = inputPose !== null;
  13525. }
  13526. if (grip !== null) {
  13527. grip.visible = gripPose !== null;
  13528. }
  13529. if (hand !== null) {
  13530. hand.visible = handPose !== null;
  13531. }
  13532. return this;
  13533. }
  13534. });
  13535. function WebXRManager(renderer, gl) {
  13536. var scope = this;
  13537. var session = null;
  13538. var framebufferScaleFactor = 1.0;
  13539. var referenceSpace = null;
  13540. var referenceSpaceType = 'local-floor';
  13541. var pose = null;
  13542. var controllers = [];
  13543. var inputSourcesMap = new Map(); //
  13544. var cameraL = new PerspectiveCamera();
  13545. cameraL.layers.enable(1);
  13546. cameraL.viewport = new Vector4();
  13547. var cameraR = new PerspectiveCamera();
  13548. cameraR.layers.enable(2);
  13549. cameraR.viewport = new Vector4();
  13550. var cameras = [cameraL, cameraR];
  13551. var cameraVR = new ArrayCamera();
  13552. cameraVR.layers.enable(1);
  13553. cameraVR.layers.enable(2);
  13554. var _currentDepthNear = null;
  13555. var _currentDepthFar = null; //
  13556. this.enabled = false;
  13557. this.isPresenting = false;
  13558. this.getController = function (index) {
  13559. var controller = controllers[index];
  13560. if (controller === undefined) {
  13561. controller = new WebXRController();
  13562. controllers[index] = controller;
  13563. }
  13564. return controller.getTargetRaySpace();
  13565. };
  13566. this.getControllerGrip = function (index) {
  13567. var controller = controllers[index];
  13568. if (controller === undefined) {
  13569. controller = new WebXRController();
  13570. controllers[index] = controller;
  13571. }
  13572. return controller.getGripSpace();
  13573. };
  13574. this.getHand = function (index) {
  13575. var controller = controllers[index];
  13576. if (controller === undefined) {
  13577. controller = new WebXRController();
  13578. controllers[index] = controller;
  13579. }
  13580. return controller.getHandSpace();
  13581. }; //
  13582. function onSessionEvent(event) {
  13583. var controller = inputSourcesMap.get(event.inputSource);
  13584. if (controller) {
  13585. controller.dispatchEvent({
  13586. type: event.type,
  13587. data: event.inputSource
  13588. });
  13589. }
  13590. }
  13591. function onSessionEnd() {
  13592. inputSourcesMap.forEach(function (controller, inputSource) {
  13593. controller.disconnect(inputSource);
  13594. });
  13595. inputSourcesMap.clear(); //
  13596. renderer.setFramebuffer(null);
  13597. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  13598. animation.stop();
  13599. scope.isPresenting = false;
  13600. scope.dispatchEvent({
  13601. type: 'sessionend'
  13602. });
  13603. }
  13604. function onRequestReferenceSpace(value) {
  13605. referenceSpace = value;
  13606. animation.setContext(session);
  13607. animation.start();
  13608. scope.isPresenting = true;
  13609. scope.dispatchEvent({
  13610. type: 'sessionstart'
  13611. });
  13612. }
  13613. this.setFramebufferScaleFactor = function (value) {
  13614. framebufferScaleFactor = value;
  13615. if (scope.isPresenting === true) {
  13616. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  13617. }
  13618. };
  13619. this.setReferenceSpaceType = function (value) {
  13620. referenceSpaceType = value;
  13621. if (scope.isPresenting === true) {
  13622. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  13623. }
  13624. };
  13625. this.getReferenceSpace = function () {
  13626. return referenceSpace;
  13627. };
  13628. this.getSession = function () {
  13629. return session;
  13630. };
  13631. this.setSession = function (value) {
  13632. session = value;
  13633. if (session !== null) {
  13634. session.addEventListener('select', onSessionEvent);
  13635. session.addEventListener('selectstart', onSessionEvent);
  13636. session.addEventListener('selectend', onSessionEvent);
  13637. session.addEventListener('squeeze', onSessionEvent);
  13638. session.addEventListener('squeezestart', onSessionEvent);
  13639. session.addEventListener('squeezeend', onSessionEvent);
  13640. session.addEventListener('end', onSessionEnd);
  13641. var attributes = gl.getContextAttributes();
  13642. if (attributes.xrCompatible !== true) {
  13643. gl.makeXRCompatible();
  13644. }
  13645. var layerInit = {
  13646. antialias: attributes.antialias,
  13647. alpha: attributes.alpha,
  13648. depth: attributes.depth,
  13649. stencil: attributes.stencil,
  13650. framebufferScaleFactor: framebufferScaleFactor
  13651. }; // eslint-disable-next-line no-undef
  13652. var baseLayer = new XRWebGLLayer(session, gl, layerInit);
  13653. session.updateRenderState({
  13654. baseLayer: baseLayer
  13655. });
  13656. session.requestReferenceSpace(referenceSpaceType).then(onRequestReferenceSpace); //
  13657. session.addEventListener('inputsourceschange', updateInputSources);
  13658. }
  13659. };
  13660. function updateInputSources(event) {
  13661. var inputSources = session.inputSources; // Assign inputSources to available controllers
  13662. for (var i = 0; i < controllers.length; i++) {
  13663. inputSourcesMap.set(inputSources[i], controllers[i]);
  13664. } // Notify disconnected
  13665. for (var _i = 0; _i < event.removed.length; _i++) {
  13666. var inputSource = event.removed[_i];
  13667. var controller = inputSourcesMap.get(inputSource);
  13668. if (controller) {
  13669. controller.dispatchEvent({
  13670. type: 'disconnected',
  13671. data: inputSource
  13672. });
  13673. inputSourcesMap.delete(inputSource);
  13674. }
  13675. } // Notify connected
  13676. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  13677. var _inputSource = event.added[_i2];
  13678. var _controller = inputSourcesMap.get(_inputSource);
  13679. if (_controller) {
  13680. _controller.dispatchEvent({
  13681. type: 'connected',
  13682. data: _inputSource
  13683. });
  13684. }
  13685. }
  13686. } //
  13687. var cameraLPos = new Vector3();
  13688. var cameraRPos = new Vector3();
  13689. /**
  13690. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13691. * the cameras' projection and world matrices have already been set.
  13692. * And that near and far planes are identical for both cameras.
  13693. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13694. */
  13695. function setProjectionFromUnion(camera, cameraL, cameraR) {
  13696. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  13697. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  13698. var ipd = cameraLPos.distanceTo(cameraRPos);
  13699. var projL = cameraL.projectionMatrix.elements;
  13700. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  13701. // most likely identical top and bottom frustum extents.
  13702. // Use the left camera for these values.
  13703. var near = projL[14] / (projL[10] - 1);
  13704. var far = projL[14] / (projL[10] + 1);
  13705. var topFov = (projL[9] + 1) / projL[5];
  13706. var bottomFov = (projL[9] - 1) / projL[5];
  13707. var leftFov = (projL[8] - 1) / projL[0];
  13708. var rightFov = (projR[8] + 1) / projR[0];
  13709. var left = near * leftFov;
  13710. var right = near * rightFov; // Calculate the new camera's position offset from the
  13711. // left camera. xOffset should be roughly half `ipd`.
  13712. var zOffset = ipd / (-leftFov + rightFov);
  13713. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  13714. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  13715. camera.translateX(xOffset);
  13716. camera.translateZ(zOffset);
  13717. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  13718. camera.matrixWorldInverse.copy(camera.matrixWorld).invert(); // Find the union of the frustum values of the cameras and scale
  13719. // the values so that the near plane's position does not change in world space,
  13720. // although must now be relative to the new union camera.
  13721. var near2 = near + zOffset;
  13722. var far2 = far + zOffset;
  13723. var left2 = left - xOffset;
  13724. var right2 = right + (ipd - xOffset);
  13725. var top2 = topFov * far / far2 * near2;
  13726. var bottom2 = bottomFov * far / far2 * near2;
  13727. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  13728. }
  13729. function updateCamera(camera, parent) {
  13730. if (parent === null) {
  13731. camera.matrixWorld.copy(camera.matrix);
  13732. } else {
  13733. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  13734. }
  13735. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  13736. }
  13737. this.getCamera = function (camera) {
  13738. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  13739. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  13740. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  13741. // Note that the new renderState won't apply until the next frame. See #18320
  13742. session.updateRenderState({
  13743. depthNear: cameraVR.near,
  13744. depthFar: cameraVR.far
  13745. });
  13746. _currentDepthNear = cameraVR.near;
  13747. _currentDepthFar = cameraVR.far;
  13748. }
  13749. var parent = camera.parent;
  13750. var cameras = cameraVR.cameras;
  13751. updateCamera(cameraVR, parent);
  13752. for (var i = 0; i < cameras.length; i++) {
  13753. updateCamera(cameras[i], parent);
  13754. } // update camera and its children
  13755. camera.matrixWorld.copy(cameraVR.matrixWorld);
  13756. var children = camera.children;
  13757. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  13758. children[_i3].updateMatrixWorld(true);
  13759. } // update projection matrix for proper view frustum culling
  13760. if (cameras.length === 2) {
  13761. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  13762. } else {
  13763. // assume single camera setup (AR)
  13764. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  13765. }
  13766. return cameraVR;
  13767. }; // Animation Loop
  13768. var onAnimationFrameCallback = null;
  13769. function onAnimationFrame(time, frame) {
  13770. pose = frame.getViewerPose(referenceSpace);
  13771. if (pose !== null) {
  13772. var views = pose.views;
  13773. var baseLayer = session.renderState.baseLayer;
  13774. renderer.setFramebuffer(baseLayer.framebuffer);
  13775. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  13776. if (views.length !== cameraVR.cameras.length) {
  13777. cameraVR.cameras.length = 0;
  13778. cameraVRNeedsUpdate = true;
  13779. }
  13780. for (var i = 0; i < views.length; i++) {
  13781. var view = views[i];
  13782. var viewport = baseLayer.getViewport(view);
  13783. var camera = cameras[i];
  13784. camera.matrix.fromArray(view.transform.matrix);
  13785. camera.projectionMatrix.fromArray(view.projectionMatrix);
  13786. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  13787. if (i === 0) {
  13788. cameraVR.matrix.copy(camera.matrix);
  13789. }
  13790. if (cameraVRNeedsUpdate === true) {
  13791. cameraVR.cameras.push(camera);
  13792. }
  13793. }
  13794. } //
  13795. var inputSources = session.inputSources;
  13796. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  13797. var controller = controllers[_i4];
  13798. var inputSource = inputSources[_i4];
  13799. controller.update(inputSource, frame, referenceSpace);
  13800. }
  13801. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  13802. }
  13803. var animation = new WebGLAnimation();
  13804. animation.setAnimationLoop(onAnimationFrame);
  13805. this.setAnimationLoop = function (callback) {
  13806. onAnimationFrameCallback = callback;
  13807. };
  13808. this.dispose = function () {};
  13809. }
  13810. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  13811. function WebGLMaterials(properties) {
  13812. function refreshFogUniforms(uniforms, fog) {
  13813. uniforms.fogColor.value.copy(fog.color);
  13814. if (fog.isFog) {
  13815. uniforms.fogNear.value = fog.near;
  13816. uniforms.fogFar.value = fog.far;
  13817. } else if (fog.isFogExp2) {
  13818. uniforms.fogDensity.value = fog.density;
  13819. }
  13820. }
  13821. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  13822. if (material.isMeshBasicMaterial) {
  13823. refreshUniformsCommon(uniforms, material);
  13824. } else if (material.isMeshLambertMaterial) {
  13825. refreshUniformsCommon(uniforms, material);
  13826. refreshUniformsLambert(uniforms, material);
  13827. } else if (material.isMeshToonMaterial) {
  13828. refreshUniformsCommon(uniforms, material);
  13829. refreshUniformsToon(uniforms, material);
  13830. } else if (material.isMeshPhongMaterial) {
  13831. refreshUniformsCommon(uniforms, material);
  13832. refreshUniformsPhong(uniforms, material);
  13833. } else if (material.isMeshStandardMaterial) {
  13834. refreshUniformsCommon(uniforms, material);
  13835. if (material.isMeshPhysicalMaterial) {
  13836. refreshUniformsPhysical(uniforms, material);
  13837. } else {
  13838. refreshUniformsStandard(uniforms, material);
  13839. }
  13840. } else if (material.isMeshMatcapMaterial) {
  13841. refreshUniformsCommon(uniforms, material);
  13842. refreshUniformsMatcap(uniforms, material);
  13843. } else if (material.isMeshDepthMaterial) {
  13844. refreshUniformsCommon(uniforms, material);
  13845. refreshUniformsDepth(uniforms, material);
  13846. } else if (material.isMeshDistanceMaterial) {
  13847. refreshUniformsCommon(uniforms, material);
  13848. refreshUniformsDistance(uniforms, material);
  13849. } else if (material.isMeshNormalMaterial) {
  13850. refreshUniformsCommon(uniforms, material);
  13851. refreshUniformsNormal(uniforms, material);
  13852. } else if (material.isLineBasicMaterial) {
  13853. refreshUniformsLine(uniforms, material);
  13854. if (material.isLineDashedMaterial) {
  13855. refreshUniformsDash(uniforms, material);
  13856. }
  13857. } else if (material.isPointsMaterial) {
  13858. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  13859. } else if (material.isSpriteMaterial) {
  13860. refreshUniformsSprites(uniforms, material);
  13861. } else if (material.isShadowMaterial) {
  13862. uniforms.color.value.copy(material.color);
  13863. uniforms.opacity.value = material.opacity;
  13864. } else if (material.isShaderMaterial) {
  13865. material.uniformsNeedUpdate = false; // #15581
  13866. }
  13867. }
  13868. function refreshUniformsCommon(uniforms, material) {
  13869. uniforms.opacity.value = material.opacity;
  13870. if (material.color) {
  13871. uniforms.diffuse.value.copy(material.color);
  13872. }
  13873. if (material.emissive) {
  13874. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  13875. }
  13876. if (material.map) {
  13877. uniforms.map.value = material.map;
  13878. }
  13879. if (material.alphaMap) {
  13880. uniforms.alphaMap.value = material.alphaMap;
  13881. }
  13882. if (material.specularMap) {
  13883. uniforms.specularMap.value = material.specularMap;
  13884. }
  13885. var envMap = properties.get(material).envMap;
  13886. if (envMap) {
  13887. uniforms.envMap.value = envMap;
  13888. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  13889. uniforms.reflectivity.value = material.reflectivity;
  13890. uniforms.refractionRatio.value = material.refractionRatio;
  13891. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  13892. if (maxMipLevel !== undefined) {
  13893. uniforms.maxMipLevel.value = maxMipLevel;
  13894. }
  13895. }
  13896. if (material.lightMap) {
  13897. uniforms.lightMap.value = material.lightMap;
  13898. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13899. }
  13900. if (material.aoMap) {
  13901. uniforms.aoMap.value = material.aoMap;
  13902. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13903. } // uv repeat and offset setting priorities
  13904. // 1. color map
  13905. // 2. specular map
  13906. // 3. displacementMap map
  13907. // 4. normal map
  13908. // 5. bump map
  13909. // 6. roughnessMap map
  13910. // 7. metalnessMap map
  13911. // 8. alphaMap map
  13912. // 9. emissiveMap map
  13913. // 10. clearcoat map
  13914. // 11. clearcoat normal map
  13915. // 12. clearcoat roughnessMap map
  13916. var uvScaleMap;
  13917. if (material.map) {
  13918. uvScaleMap = material.map;
  13919. } else if (material.specularMap) {
  13920. uvScaleMap = material.specularMap;
  13921. } else if (material.displacementMap) {
  13922. uvScaleMap = material.displacementMap;
  13923. } else if (material.normalMap) {
  13924. uvScaleMap = material.normalMap;
  13925. } else if (material.bumpMap) {
  13926. uvScaleMap = material.bumpMap;
  13927. } else if (material.roughnessMap) {
  13928. uvScaleMap = material.roughnessMap;
  13929. } else if (material.metalnessMap) {
  13930. uvScaleMap = material.metalnessMap;
  13931. } else if (material.alphaMap) {
  13932. uvScaleMap = material.alphaMap;
  13933. } else if (material.emissiveMap) {
  13934. uvScaleMap = material.emissiveMap;
  13935. } else if (material.clearcoatMap) {
  13936. uvScaleMap = material.clearcoatMap;
  13937. } else if (material.clearcoatNormalMap) {
  13938. uvScaleMap = material.clearcoatNormalMap;
  13939. } else if (material.clearcoatRoughnessMap) {
  13940. uvScaleMap = material.clearcoatRoughnessMap;
  13941. }
  13942. if (uvScaleMap !== undefined) {
  13943. // backwards compatibility
  13944. if (uvScaleMap.isWebGLRenderTarget) {
  13945. uvScaleMap = uvScaleMap.texture;
  13946. }
  13947. if (uvScaleMap.matrixAutoUpdate === true) {
  13948. uvScaleMap.updateMatrix();
  13949. }
  13950. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  13951. } // uv repeat and offset setting priorities for uv2
  13952. // 1. ao map
  13953. // 2. light map
  13954. var uv2ScaleMap;
  13955. if (material.aoMap) {
  13956. uv2ScaleMap = material.aoMap;
  13957. } else if (material.lightMap) {
  13958. uv2ScaleMap = material.lightMap;
  13959. }
  13960. if (uv2ScaleMap !== undefined) {
  13961. // backwards compatibility
  13962. if (uv2ScaleMap.isWebGLRenderTarget) {
  13963. uv2ScaleMap = uv2ScaleMap.texture;
  13964. }
  13965. if (uv2ScaleMap.matrixAutoUpdate === true) {
  13966. uv2ScaleMap.updateMatrix();
  13967. }
  13968. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  13969. }
  13970. }
  13971. function refreshUniformsLine(uniforms, material) {
  13972. uniforms.diffuse.value.copy(material.color);
  13973. uniforms.opacity.value = material.opacity;
  13974. }
  13975. function refreshUniformsDash(uniforms, material) {
  13976. uniforms.dashSize.value = material.dashSize;
  13977. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13978. uniforms.scale.value = material.scale;
  13979. }
  13980. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  13981. uniforms.diffuse.value.copy(material.color);
  13982. uniforms.opacity.value = material.opacity;
  13983. uniforms.size.value = material.size * pixelRatio;
  13984. uniforms.scale.value = height * 0.5;
  13985. if (material.map) {
  13986. uniforms.map.value = material.map;
  13987. }
  13988. if (material.alphaMap) {
  13989. uniforms.alphaMap.value = material.alphaMap;
  13990. } // uv repeat and offset setting priorities
  13991. // 1. color map
  13992. // 2. alpha map
  13993. var uvScaleMap;
  13994. if (material.map) {
  13995. uvScaleMap = material.map;
  13996. } else if (material.alphaMap) {
  13997. uvScaleMap = material.alphaMap;
  13998. }
  13999. if (uvScaleMap !== undefined) {
  14000. if (uvScaleMap.matrixAutoUpdate === true) {
  14001. uvScaleMap.updateMatrix();
  14002. }
  14003. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14004. }
  14005. }
  14006. function refreshUniformsSprites(uniforms, material) {
  14007. uniforms.diffuse.value.copy(material.color);
  14008. uniforms.opacity.value = material.opacity;
  14009. uniforms.rotation.value = material.rotation;
  14010. if (material.map) {
  14011. uniforms.map.value = material.map;
  14012. }
  14013. if (material.alphaMap) {
  14014. uniforms.alphaMap.value = material.alphaMap;
  14015. } // uv repeat and offset setting priorities
  14016. // 1. color map
  14017. // 2. alpha map
  14018. var uvScaleMap;
  14019. if (material.map) {
  14020. uvScaleMap = material.map;
  14021. } else if (material.alphaMap) {
  14022. uvScaleMap = material.alphaMap;
  14023. }
  14024. if (uvScaleMap !== undefined) {
  14025. if (uvScaleMap.matrixAutoUpdate === true) {
  14026. uvScaleMap.updateMatrix();
  14027. }
  14028. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14029. }
  14030. }
  14031. function refreshUniformsLambert(uniforms, material) {
  14032. if (material.emissiveMap) {
  14033. uniforms.emissiveMap.value = material.emissiveMap;
  14034. }
  14035. }
  14036. function refreshUniformsPhong(uniforms, material) {
  14037. uniforms.specular.value.copy(material.specular);
  14038. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  14039. if (material.emissiveMap) {
  14040. uniforms.emissiveMap.value = material.emissiveMap;
  14041. }
  14042. if (material.bumpMap) {
  14043. uniforms.bumpMap.value = material.bumpMap;
  14044. uniforms.bumpScale.value = material.bumpScale;
  14045. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14046. }
  14047. if (material.normalMap) {
  14048. uniforms.normalMap.value = material.normalMap;
  14049. uniforms.normalScale.value.copy(material.normalScale);
  14050. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14051. }
  14052. if (material.displacementMap) {
  14053. uniforms.displacementMap.value = material.displacementMap;
  14054. uniforms.displacementScale.value = material.displacementScale;
  14055. uniforms.displacementBias.value = material.displacementBias;
  14056. }
  14057. }
  14058. function refreshUniformsToon(uniforms, material) {
  14059. if (material.gradientMap) {
  14060. uniforms.gradientMap.value = material.gradientMap;
  14061. }
  14062. if (material.emissiveMap) {
  14063. uniforms.emissiveMap.value = material.emissiveMap;
  14064. }
  14065. if (material.bumpMap) {
  14066. uniforms.bumpMap.value = material.bumpMap;
  14067. uniforms.bumpScale.value = material.bumpScale;
  14068. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14069. }
  14070. if (material.normalMap) {
  14071. uniforms.normalMap.value = material.normalMap;
  14072. uniforms.normalScale.value.copy(material.normalScale);
  14073. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14074. }
  14075. if (material.displacementMap) {
  14076. uniforms.displacementMap.value = material.displacementMap;
  14077. uniforms.displacementScale.value = material.displacementScale;
  14078. uniforms.displacementBias.value = material.displacementBias;
  14079. }
  14080. }
  14081. function refreshUniformsStandard(uniforms, material) {
  14082. uniforms.roughness.value = material.roughness;
  14083. uniforms.metalness.value = material.metalness;
  14084. if (material.roughnessMap) {
  14085. uniforms.roughnessMap.value = material.roughnessMap;
  14086. }
  14087. if (material.metalnessMap) {
  14088. uniforms.metalnessMap.value = material.metalnessMap;
  14089. }
  14090. if (material.emissiveMap) {
  14091. uniforms.emissiveMap.value = material.emissiveMap;
  14092. }
  14093. if (material.bumpMap) {
  14094. uniforms.bumpMap.value = material.bumpMap;
  14095. uniforms.bumpScale.value = material.bumpScale;
  14096. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14097. }
  14098. if (material.normalMap) {
  14099. uniforms.normalMap.value = material.normalMap;
  14100. uniforms.normalScale.value.copy(material.normalScale);
  14101. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14102. }
  14103. if (material.displacementMap) {
  14104. uniforms.displacementMap.value = material.displacementMap;
  14105. uniforms.displacementScale.value = material.displacementScale;
  14106. uniforms.displacementBias.value = material.displacementBias;
  14107. }
  14108. var envMap = properties.get(material).envMap;
  14109. if (envMap) {
  14110. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14111. uniforms.envMapIntensity.value = material.envMapIntensity;
  14112. }
  14113. }
  14114. function refreshUniformsPhysical(uniforms, material) {
  14115. refreshUniformsStandard(uniforms, material);
  14116. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14117. uniforms.clearcoat.value = material.clearcoat;
  14118. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14119. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14120. if (material.clearcoatMap) {
  14121. uniforms.clearcoatMap.value = material.clearcoatMap;
  14122. }
  14123. if (material.clearcoatRoughnessMap) {
  14124. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14125. }
  14126. if (material.clearcoatNormalMap) {
  14127. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14128. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14129. if (material.side === BackSide) {
  14130. uniforms.clearcoatNormalScale.value.negate();
  14131. }
  14132. }
  14133. uniforms.transmission.value = material.transmission;
  14134. if (material.transmissionMap) {
  14135. uniforms.transmissionMap.value = material.transmissionMap;
  14136. }
  14137. }
  14138. function refreshUniformsMatcap(uniforms, material) {
  14139. if (material.matcap) {
  14140. uniforms.matcap.value = material.matcap;
  14141. }
  14142. if (material.bumpMap) {
  14143. uniforms.bumpMap.value = material.bumpMap;
  14144. uniforms.bumpScale.value = material.bumpScale;
  14145. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14146. }
  14147. if (material.normalMap) {
  14148. uniforms.normalMap.value = material.normalMap;
  14149. uniforms.normalScale.value.copy(material.normalScale);
  14150. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14151. }
  14152. if (material.displacementMap) {
  14153. uniforms.displacementMap.value = material.displacementMap;
  14154. uniforms.displacementScale.value = material.displacementScale;
  14155. uniforms.displacementBias.value = material.displacementBias;
  14156. }
  14157. }
  14158. function refreshUniformsDepth(uniforms, material) {
  14159. if (material.displacementMap) {
  14160. uniforms.displacementMap.value = material.displacementMap;
  14161. uniforms.displacementScale.value = material.displacementScale;
  14162. uniforms.displacementBias.value = material.displacementBias;
  14163. }
  14164. }
  14165. function refreshUniformsDistance(uniforms, material) {
  14166. if (material.displacementMap) {
  14167. uniforms.displacementMap.value = material.displacementMap;
  14168. uniforms.displacementScale.value = material.displacementScale;
  14169. uniforms.displacementBias.value = material.displacementBias;
  14170. }
  14171. uniforms.referencePosition.value.copy(material.referencePosition);
  14172. uniforms.nearDistance.value = material.nearDistance;
  14173. uniforms.farDistance.value = material.farDistance;
  14174. }
  14175. function refreshUniformsNormal(uniforms, material) {
  14176. if (material.bumpMap) {
  14177. uniforms.bumpMap.value = material.bumpMap;
  14178. uniforms.bumpScale.value = material.bumpScale;
  14179. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14180. }
  14181. if (material.normalMap) {
  14182. uniforms.normalMap.value = material.normalMap;
  14183. uniforms.normalScale.value.copy(material.normalScale);
  14184. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14185. }
  14186. if (material.displacementMap) {
  14187. uniforms.displacementMap.value = material.displacementMap;
  14188. uniforms.displacementScale.value = material.displacementScale;
  14189. uniforms.displacementBias.value = material.displacementBias;
  14190. }
  14191. }
  14192. return {
  14193. refreshFogUniforms: refreshFogUniforms,
  14194. refreshMaterialUniforms: refreshMaterialUniforms
  14195. };
  14196. }
  14197. function createCanvasElement() {
  14198. var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  14199. canvas.style.display = 'block';
  14200. return canvas;
  14201. }
  14202. function WebGLRenderer(parameters) {
  14203. parameters = parameters || {};
  14204. var _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  14205. _context = parameters.context !== undefined ? parameters.context : null,
  14206. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14207. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14208. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14209. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14210. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14211. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14212. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14213. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14214. var currentRenderList = null;
  14215. var currentRenderState = null; // public properties
  14216. this.domElement = _canvas; // Debug configuration container
  14217. this.debug = {
  14218. /**
  14219. * Enables error checking and reporting when shader programs are being compiled
  14220. * @type {boolean}
  14221. */
  14222. checkShaderErrors: true
  14223. }; // clearing
  14224. this.autoClear = true;
  14225. this.autoClearColor = true;
  14226. this.autoClearDepth = true;
  14227. this.autoClearStencil = true; // scene graph
  14228. this.sortObjects = true; // user-defined clipping
  14229. this.clippingPlanes = [];
  14230. this.localClippingEnabled = false; // physically based shading
  14231. this.gammaFactor = 2.0; // for backwards compatibility
  14232. this.outputEncoding = LinearEncoding; // physical lights
  14233. this.physicallyCorrectLights = false; // tone mapping
  14234. this.toneMapping = NoToneMapping;
  14235. this.toneMappingExposure = 1.0; // morphs
  14236. this.maxMorphTargets = 8;
  14237. this.maxMorphNormals = 4; // internal properties
  14238. var _this = this;
  14239. var _isContextLost = false; // internal state cache
  14240. var _framebuffer = null;
  14241. var _currentActiveCubeFace = 0;
  14242. var _currentActiveMipmapLevel = 0;
  14243. var _currentRenderTarget = null;
  14244. var _currentFramebuffer = null;
  14245. var _currentMaterialId = -1;
  14246. var _currentCamera = null;
  14247. var _currentArrayCamera = null;
  14248. var _currentViewport = new Vector4();
  14249. var _currentScissor = new Vector4();
  14250. var _currentScissorTest = null; //
  14251. var _width = _canvas.width;
  14252. var _height = _canvas.height;
  14253. var _pixelRatio = 1;
  14254. var _opaqueSort = null;
  14255. var _transparentSort = null;
  14256. var _viewport = new Vector4(0, 0, _width, _height);
  14257. var _scissor = new Vector4(0, 0, _width, _height);
  14258. var _scissorTest = false; // frustum
  14259. var _frustum = new Frustum(); // clipping
  14260. var _clippingEnabled = false;
  14261. var _localClippingEnabled = false; // camera matrices cache
  14262. var _projScreenMatrix = new Matrix4();
  14263. var _vector3 = new Vector3();
  14264. var _emptyScene = {
  14265. background: null,
  14266. fog: null,
  14267. environment: null,
  14268. overrideMaterial: null,
  14269. isScene: true
  14270. };
  14271. function getTargetPixelRatio() {
  14272. return _currentRenderTarget === null ? _pixelRatio : 1;
  14273. } // initialize
  14274. var _gl = _context;
  14275. function getContext(contextNames, contextAttributes) {
  14276. for (var i = 0; i < contextNames.length; i++) {
  14277. var contextName = contextNames[i];
  14278. var context = _canvas.getContext(contextName, contextAttributes);
  14279. if (context !== null) return context;
  14280. }
  14281. return null;
  14282. }
  14283. try {
  14284. var contextAttributes = {
  14285. alpha: _alpha,
  14286. depth: _depth,
  14287. stencil: _stencil,
  14288. antialias: _antialias,
  14289. premultipliedAlpha: _premultipliedAlpha,
  14290. preserveDrawingBuffer: _preserveDrawingBuffer,
  14291. powerPreference: _powerPreference,
  14292. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14293. }; // event listeners must be registered before WebGL context is created, see #12753
  14294. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  14295. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  14296. if (_gl === null) {
  14297. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  14298. if (_this.isWebGL1Renderer === true) {
  14299. contextNames.shift();
  14300. }
  14301. _gl = getContext(contextNames, contextAttributes);
  14302. if (_gl === null) {
  14303. if (getContext(contextNames)) {
  14304. throw new Error('Error creating WebGL context with your selected attributes.');
  14305. } else {
  14306. throw new Error('Error creating WebGL context.');
  14307. }
  14308. }
  14309. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14310. if (_gl.getShaderPrecisionFormat === undefined) {
  14311. _gl.getShaderPrecisionFormat = function () {
  14312. return {
  14313. 'rangeMin': 1,
  14314. 'rangeMax': 1,
  14315. 'precision': 1
  14316. };
  14317. };
  14318. }
  14319. } catch (error) {
  14320. console.error('THREE.WebGLRenderer: ' + error.message);
  14321. throw error;
  14322. }
  14323. var extensions, capabilities, state, info;
  14324. var properties, textures, cubemaps, attributes, geometries, objects;
  14325. var programCache, materials, renderLists, renderStates, clipping;
  14326. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14327. var utils, bindingStates;
  14328. function initGLContext() {
  14329. extensions = new WebGLExtensions(_gl);
  14330. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  14331. if (capabilities.isWebGL2 === false) {
  14332. extensions.get('WEBGL_depth_texture');
  14333. extensions.get('OES_texture_float');
  14334. extensions.get('OES_texture_half_float');
  14335. extensions.get('OES_texture_half_float_linear');
  14336. extensions.get('OES_standard_derivatives');
  14337. extensions.get('OES_element_index_uint');
  14338. extensions.get('OES_vertex_array_object');
  14339. extensions.get('ANGLE_instanced_arrays');
  14340. }
  14341. extensions.get('OES_texture_float_linear');
  14342. utils = new WebGLUtils(_gl, extensions, capabilities);
  14343. state = new WebGLState(_gl, extensions, capabilities);
  14344. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14345. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14346. info = new WebGLInfo(_gl);
  14347. properties = new WebGLProperties();
  14348. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  14349. cubemaps = new WebGLCubeMaps(_this);
  14350. attributes = new WebGLAttributes(_gl, capabilities);
  14351. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  14352. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  14353. objects = new WebGLObjects(_gl, geometries, attributes, info);
  14354. morphtargets = new WebGLMorphtargets(_gl);
  14355. clipping = new WebGLClipping(properties);
  14356. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  14357. materials = new WebGLMaterials(properties);
  14358. renderLists = new WebGLRenderLists(properties);
  14359. renderStates = new WebGLRenderStates(extensions, capabilities);
  14360. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  14361. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  14362. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  14363. info.programs = programCache.programs;
  14364. _this.capabilities = capabilities;
  14365. _this.extensions = extensions;
  14366. _this.properties = properties;
  14367. _this.renderLists = renderLists;
  14368. _this.state = state;
  14369. _this.info = info;
  14370. }
  14371. initGLContext(); // xr
  14372. var xr = new WebXRManager(_this, _gl);
  14373. this.xr = xr; // shadow map
  14374. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  14375. this.shadowMap = shadowMap; // API
  14376. this.getContext = function () {
  14377. return _gl;
  14378. };
  14379. this.getContextAttributes = function () {
  14380. return _gl.getContextAttributes();
  14381. };
  14382. this.forceContextLoss = function () {
  14383. var extension = extensions.get('WEBGL_lose_context');
  14384. if (extension) extension.loseContext();
  14385. };
  14386. this.forceContextRestore = function () {
  14387. var extension = extensions.get('WEBGL_lose_context');
  14388. if (extension) extension.restoreContext();
  14389. };
  14390. this.getPixelRatio = function () {
  14391. return _pixelRatio;
  14392. };
  14393. this.setPixelRatio = function (value) {
  14394. if (value === undefined) return;
  14395. _pixelRatio = value;
  14396. this.setSize(_width, _height, false);
  14397. };
  14398. this.getSize = function (target) {
  14399. if (target === undefined) {
  14400. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  14401. target = new Vector2();
  14402. }
  14403. return target.set(_width, _height);
  14404. };
  14405. this.setSize = function (width, height, updateStyle) {
  14406. if (xr.isPresenting) {
  14407. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  14408. return;
  14409. }
  14410. _width = width;
  14411. _height = height;
  14412. _canvas.width = Math.floor(width * _pixelRatio);
  14413. _canvas.height = Math.floor(height * _pixelRatio);
  14414. if (updateStyle !== false) {
  14415. _canvas.style.width = width + 'px';
  14416. _canvas.style.height = height + 'px';
  14417. }
  14418. this.setViewport(0, 0, width, height);
  14419. };
  14420. this.getDrawingBufferSize = function (target) {
  14421. if (target === undefined) {
  14422. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  14423. target = new Vector2();
  14424. }
  14425. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  14426. };
  14427. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  14428. _width = width;
  14429. _height = height;
  14430. _pixelRatio = pixelRatio;
  14431. _canvas.width = Math.floor(width * pixelRatio);
  14432. _canvas.height = Math.floor(height * pixelRatio);
  14433. this.setViewport(0, 0, width, height);
  14434. };
  14435. this.getCurrentViewport = function (target) {
  14436. if (target === undefined) {
  14437. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  14438. target = new Vector4();
  14439. }
  14440. return target.copy(_currentViewport);
  14441. };
  14442. this.getViewport = function (target) {
  14443. return target.copy(_viewport);
  14444. };
  14445. this.setViewport = function (x, y, width, height) {
  14446. if (x.isVector4) {
  14447. _viewport.set(x.x, x.y, x.z, x.w);
  14448. } else {
  14449. _viewport.set(x, y, width, height);
  14450. }
  14451. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14452. };
  14453. this.getScissor = function (target) {
  14454. return target.copy(_scissor);
  14455. };
  14456. this.setScissor = function (x, y, width, height) {
  14457. if (x.isVector4) {
  14458. _scissor.set(x.x, x.y, x.z, x.w);
  14459. } else {
  14460. _scissor.set(x, y, width, height);
  14461. }
  14462. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14463. };
  14464. this.getScissorTest = function () {
  14465. return _scissorTest;
  14466. };
  14467. this.setScissorTest = function (boolean) {
  14468. state.setScissorTest(_scissorTest = boolean);
  14469. };
  14470. this.setOpaqueSort = function (method) {
  14471. _opaqueSort = method;
  14472. };
  14473. this.setTransparentSort = function (method) {
  14474. _transparentSort = method;
  14475. }; // Clearing
  14476. this.getClearColor = function () {
  14477. return background.getClearColor();
  14478. };
  14479. this.setClearColor = function () {
  14480. background.setClearColor.apply(background, arguments);
  14481. };
  14482. this.getClearAlpha = function () {
  14483. return background.getClearAlpha();
  14484. };
  14485. this.setClearAlpha = function () {
  14486. background.setClearAlpha.apply(background, arguments);
  14487. };
  14488. this.clear = function (color, depth, stencil) {
  14489. var bits = 0;
  14490. if (color === undefined || color) bits |= 16384;
  14491. if (depth === undefined || depth) bits |= 256;
  14492. if (stencil === undefined || stencil) bits |= 1024;
  14493. _gl.clear(bits);
  14494. };
  14495. this.clearColor = function () {
  14496. this.clear(true, false, false);
  14497. };
  14498. this.clearDepth = function () {
  14499. this.clear(false, true, false);
  14500. };
  14501. this.clearStencil = function () {
  14502. this.clear(false, false, true);
  14503. }; //
  14504. this.dispose = function () {
  14505. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  14506. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  14507. renderLists.dispose();
  14508. renderStates.dispose();
  14509. properties.dispose();
  14510. cubemaps.dispose();
  14511. objects.dispose();
  14512. bindingStates.dispose();
  14513. xr.dispose();
  14514. animation.stop();
  14515. }; // Events
  14516. function onContextLost(event) {
  14517. event.preventDefault();
  14518. console.log('THREE.WebGLRenderer: Context Lost.');
  14519. _isContextLost = true;
  14520. }
  14521. function onContextRestore()
  14522. /* event */
  14523. {
  14524. console.log('THREE.WebGLRenderer: Context Restored.');
  14525. _isContextLost = false;
  14526. initGLContext();
  14527. }
  14528. function onMaterialDispose(event) {
  14529. var material = event.target;
  14530. material.removeEventListener('dispose', onMaterialDispose);
  14531. deallocateMaterial(material);
  14532. } // Buffer deallocation
  14533. function deallocateMaterial(material) {
  14534. releaseMaterialProgramReference(material);
  14535. properties.remove(material);
  14536. }
  14537. function releaseMaterialProgramReference(material) {
  14538. var programInfo = properties.get(material).program;
  14539. if (programInfo !== undefined) {
  14540. programCache.releaseProgram(programInfo);
  14541. }
  14542. } // Buffer rendering
  14543. function renderObjectImmediate(object, program) {
  14544. object.render(function (object) {
  14545. _this.renderBufferImmediate(object, program);
  14546. });
  14547. }
  14548. this.renderBufferImmediate = function (object, program) {
  14549. bindingStates.initAttributes();
  14550. var buffers = properties.get(object);
  14551. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  14552. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  14553. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  14554. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  14555. var programAttributes = program.getAttributes();
  14556. if (object.hasPositions) {
  14557. _gl.bindBuffer(34962, buffers.position);
  14558. _gl.bufferData(34962, object.positionArray, 35048);
  14559. bindingStates.enableAttribute(programAttributes.position);
  14560. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  14561. }
  14562. if (object.hasNormals) {
  14563. _gl.bindBuffer(34962, buffers.normal);
  14564. _gl.bufferData(34962, object.normalArray, 35048);
  14565. bindingStates.enableAttribute(programAttributes.normal);
  14566. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  14567. }
  14568. if (object.hasUvs) {
  14569. _gl.bindBuffer(34962, buffers.uv);
  14570. _gl.bufferData(34962, object.uvArray, 35048);
  14571. bindingStates.enableAttribute(programAttributes.uv);
  14572. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  14573. }
  14574. if (object.hasColors) {
  14575. _gl.bindBuffer(34962, buffers.color);
  14576. _gl.bufferData(34962, object.colorArray, 35048);
  14577. bindingStates.enableAttribute(programAttributes.color);
  14578. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  14579. }
  14580. bindingStates.disableUnusedAttributes();
  14581. _gl.drawArrays(4, 0, object.count);
  14582. object.count = 0;
  14583. };
  14584. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  14585. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  14586. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  14587. var program = setProgram(camera, scene, material, object);
  14588. state.setMaterial(material, frontFaceCW); //
  14589. var index = geometry.index;
  14590. var position = geometry.attributes.position; //
  14591. if (index === null) {
  14592. if (position === undefined || position.count === 0) return;
  14593. } else if (index.count === 0) {
  14594. return;
  14595. } //
  14596. var rangeFactor = 1;
  14597. if (material.wireframe === true) {
  14598. index = geometries.getWireframeAttribute(geometry);
  14599. rangeFactor = 2;
  14600. }
  14601. if (material.morphTargets || material.morphNormals) {
  14602. morphtargets.update(object, geometry, material, program);
  14603. }
  14604. bindingStates.setup(object, material, program, geometry, index);
  14605. var attribute;
  14606. var renderer = bufferRenderer;
  14607. if (index !== null) {
  14608. attribute = attributes.get(index);
  14609. renderer = indexedBufferRenderer;
  14610. renderer.setIndex(attribute);
  14611. } //
  14612. var dataCount = index !== null ? index.count : position.count;
  14613. var rangeStart = geometry.drawRange.start * rangeFactor;
  14614. var rangeCount = geometry.drawRange.count * rangeFactor;
  14615. var groupStart = group !== null ? group.start * rangeFactor : 0;
  14616. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14617. var drawStart = Math.max(rangeStart, groupStart);
  14618. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  14619. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  14620. if (drawCount === 0) return; //
  14621. if (object.isMesh) {
  14622. if (material.wireframe === true) {
  14623. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  14624. renderer.setMode(1);
  14625. } else {
  14626. renderer.setMode(4);
  14627. }
  14628. } else if (object.isLine) {
  14629. var lineWidth = material.linewidth;
  14630. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  14631. state.setLineWidth(lineWidth * getTargetPixelRatio());
  14632. if (object.isLineSegments) {
  14633. renderer.setMode(1);
  14634. } else if (object.isLineLoop) {
  14635. renderer.setMode(2);
  14636. } else {
  14637. renderer.setMode(3);
  14638. }
  14639. } else if (object.isPoints) {
  14640. renderer.setMode(0);
  14641. } else if (object.isSprite) {
  14642. renderer.setMode(4);
  14643. }
  14644. if (object.isInstancedMesh) {
  14645. renderer.renderInstances(drawStart, drawCount, object.count);
  14646. } else if (geometry.isInstancedBufferGeometry) {
  14647. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  14648. renderer.renderInstances(drawStart, drawCount, instanceCount);
  14649. } else {
  14650. renderer.render(drawStart, drawCount);
  14651. }
  14652. }; // Compile
  14653. this.compile = function (scene, camera) {
  14654. currentRenderState = renderStates.get(scene, camera);
  14655. currentRenderState.init();
  14656. scene.traverseVisible(function (object) {
  14657. if (object.isLight && object.layers.test(camera.layers)) {
  14658. currentRenderState.pushLight(object);
  14659. if (object.castShadow) {
  14660. currentRenderState.pushShadow(object);
  14661. }
  14662. }
  14663. });
  14664. currentRenderState.setupLights(camera);
  14665. var compiled = new WeakMap();
  14666. scene.traverse(function (object) {
  14667. var material = object.material;
  14668. if (material) {
  14669. if (Array.isArray(material)) {
  14670. for (var i = 0; i < material.length; i++) {
  14671. var material2 = material[i];
  14672. if (compiled.has(material2) === false) {
  14673. initMaterial(material2, scene, object);
  14674. compiled.set(material2);
  14675. }
  14676. }
  14677. } else if (compiled.has(material) === false) {
  14678. initMaterial(material, scene, object);
  14679. compiled.set(material);
  14680. }
  14681. }
  14682. });
  14683. }; // Animation Loop
  14684. var onAnimationFrameCallback = null;
  14685. function onAnimationFrame(time) {
  14686. if (xr.isPresenting) return;
  14687. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  14688. }
  14689. var animation = new WebGLAnimation();
  14690. animation.setAnimationLoop(onAnimationFrame);
  14691. if (typeof window !== 'undefined') animation.setContext(window);
  14692. this.setAnimationLoop = function (callback) {
  14693. onAnimationFrameCallback = callback;
  14694. xr.setAnimationLoop(callback);
  14695. callback === null ? animation.stop() : animation.start();
  14696. }; // Rendering
  14697. this.render = function (scene, camera) {
  14698. var renderTarget, forceClear;
  14699. if (arguments[2] !== undefined) {
  14700. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  14701. renderTarget = arguments[2];
  14702. }
  14703. if (arguments[3] !== undefined) {
  14704. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  14705. forceClear = arguments[3];
  14706. }
  14707. if (camera !== undefined && camera.isCamera !== true) {
  14708. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  14709. return;
  14710. }
  14711. if (_isContextLost === true) return; // reset caching for this frame
  14712. bindingStates.resetDefaultState();
  14713. _currentMaterialId = -1;
  14714. _currentCamera = null; // update scene graph
  14715. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  14716. if (camera.parent === null) camera.updateMatrixWorld();
  14717. if (xr.enabled === true && xr.isPresenting === true) {
  14718. camera = xr.getCamera(camera);
  14719. } //
  14720. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  14721. currentRenderState = renderStates.get(scene, camera);
  14722. currentRenderState.init();
  14723. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  14724. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  14725. _localClippingEnabled = this.localClippingEnabled;
  14726. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  14727. currentRenderList = renderLists.get(scene, camera);
  14728. currentRenderList.init();
  14729. projectObject(scene, camera, 0, _this.sortObjects);
  14730. currentRenderList.finish();
  14731. if (_this.sortObjects === true) {
  14732. currentRenderList.sort(_opaqueSort, _transparentSort);
  14733. } //
  14734. if (_clippingEnabled === true) clipping.beginShadows();
  14735. var shadowsArray = currentRenderState.state.shadowsArray;
  14736. shadowMap.render(shadowsArray, scene, camera);
  14737. currentRenderState.setupLights(camera);
  14738. if (_clippingEnabled === true) clipping.endShadows(); //
  14739. if (this.info.autoReset === true) this.info.reset();
  14740. if (renderTarget !== undefined) {
  14741. this.setRenderTarget(renderTarget);
  14742. } //
  14743. background.render(currentRenderList, scene, camera, forceClear); // render scene
  14744. var opaqueObjects = currentRenderList.opaque;
  14745. var transparentObjects = currentRenderList.transparent;
  14746. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  14747. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  14748. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  14749. if (_currentRenderTarget !== null) {
  14750. // Generate mipmap if we're using any kind of mipmap filtering
  14751. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  14752. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  14753. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  14754. state.buffers.depth.setTest(true);
  14755. state.buffers.depth.setMask(true);
  14756. state.buffers.color.setMask(true);
  14757. state.setPolygonOffset(false); // _gl.finish();
  14758. currentRenderList = null;
  14759. currentRenderState = null;
  14760. };
  14761. function projectObject(object, camera, groupOrder, sortObjects) {
  14762. if (object.visible === false) return;
  14763. var visible = object.layers.test(camera.layers);
  14764. if (visible) {
  14765. if (object.isGroup) {
  14766. groupOrder = object.renderOrder;
  14767. } else if (object.isLOD) {
  14768. if (object.autoUpdate === true) object.update(camera);
  14769. } else if (object.isLight) {
  14770. currentRenderState.pushLight(object);
  14771. if (object.castShadow) {
  14772. currentRenderState.pushShadow(object);
  14773. }
  14774. } else if (object.isSprite) {
  14775. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  14776. if (sortObjects) {
  14777. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14778. }
  14779. var geometry = objects.update(object);
  14780. var material = object.material;
  14781. if (material.visible) {
  14782. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  14783. }
  14784. }
  14785. } else if (object.isImmediateRenderObject) {
  14786. if (sortObjects) {
  14787. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14788. }
  14789. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  14790. } else if (object.isMesh || object.isLine || object.isPoints) {
  14791. if (object.isSkinnedMesh) {
  14792. // update skeleton only once in a frame
  14793. if (object.skeleton.frame !== info.render.frame) {
  14794. object.skeleton.update();
  14795. object.skeleton.frame = info.render.frame;
  14796. }
  14797. }
  14798. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  14799. if (sortObjects) {
  14800. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14801. }
  14802. var _geometry = objects.update(object);
  14803. var _material = object.material;
  14804. if (Array.isArray(_material)) {
  14805. var groups = _geometry.groups;
  14806. for (var i = 0, l = groups.length; i < l; i++) {
  14807. var group = groups[i];
  14808. var groupMaterial = _material[group.materialIndex];
  14809. if (groupMaterial && groupMaterial.visible) {
  14810. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  14811. }
  14812. }
  14813. } else if (_material.visible) {
  14814. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  14815. }
  14816. }
  14817. }
  14818. }
  14819. var children = object.children;
  14820. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  14821. projectObject(children[_i], camera, groupOrder, sortObjects);
  14822. }
  14823. }
  14824. function renderObjects(renderList, scene, camera) {
  14825. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  14826. for (var i = 0, l = renderList.length; i < l; i++) {
  14827. var renderItem = renderList[i];
  14828. var object = renderItem.object;
  14829. var geometry = renderItem.geometry;
  14830. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  14831. var group = renderItem.group;
  14832. if (camera.isArrayCamera) {
  14833. _currentArrayCamera = camera;
  14834. var cameras = camera.cameras;
  14835. for (var j = 0, jl = cameras.length; j < jl; j++) {
  14836. var camera2 = cameras[j];
  14837. if (object.layers.test(camera2.layers)) {
  14838. state.viewport(_currentViewport.copy(camera2.viewport));
  14839. currentRenderState.setupLights(camera2);
  14840. renderObject(object, scene, camera2, geometry, material, group);
  14841. }
  14842. }
  14843. } else {
  14844. _currentArrayCamera = null;
  14845. renderObject(object, scene, camera, geometry, material, group);
  14846. }
  14847. }
  14848. }
  14849. function renderObject(object, scene, camera, geometry, material, group) {
  14850. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  14851. currentRenderState = renderStates.get(scene, _currentArrayCamera || camera);
  14852. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  14853. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  14854. if (object.isImmediateRenderObject) {
  14855. var program = setProgram(camera, scene, material, object);
  14856. state.setMaterial(material);
  14857. bindingStates.reset();
  14858. renderObjectImmediate(object, program);
  14859. } else {
  14860. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  14861. }
  14862. object.onAfterRender(_this, scene, camera, geometry, material, group);
  14863. currentRenderState = renderStates.get(scene, _currentArrayCamera || camera);
  14864. }
  14865. function initMaterial(material, scene, object) {
  14866. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14867. var materialProperties = properties.get(material);
  14868. var lights = currentRenderState.state.lights;
  14869. var shadowsArray = currentRenderState.state.shadowsArray;
  14870. var lightsStateVersion = lights.state.version;
  14871. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  14872. var programCacheKey = programCache.getProgramCacheKey(parameters);
  14873. var program = materialProperties.program;
  14874. var programChange = true;
  14875. if (program === undefined) {
  14876. // new material
  14877. material.addEventListener('dispose', onMaterialDispose);
  14878. } else if (program.cacheKey !== programCacheKey) {
  14879. // changed glsl or parameters
  14880. releaseMaterialProgramReference(material);
  14881. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  14882. programChange = false;
  14883. } else if (parameters.shaderID !== undefined) {
  14884. // same glsl and uniform list, envMap still needs the update here to avoid a frame-late effect
  14885. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  14886. materialProperties.envMap = cubemaps.get(material.envMap || environment);
  14887. return;
  14888. } else {
  14889. // only rebuild uniform list
  14890. programChange = false;
  14891. }
  14892. if (programChange) {
  14893. parameters.uniforms = programCache.getUniforms(material);
  14894. material.onBeforeCompile(parameters, _this);
  14895. program = programCache.acquireProgram(parameters, programCacheKey);
  14896. materialProperties.program = program;
  14897. materialProperties.uniforms = parameters.uniforms;
  14898. materialProperties.outputEncoding = parameters.outputEncoding;
  14899. }
  14900. var uniforms = materialProperties.uniforms;
  14901. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  14902. materialProperties.numClippingPlanes = clipping.numPlanes;
  14903. materialProperties.numIntersection = clipping.numIntersection;
  14904. uniforms.clippingPlanes = clipping.uniform;
  14905. }
  14906. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  14907. materialProperties.fog = scene.fog;
  14908. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment); // store the light setup it was created for
  14909. materialProperties.needsLights = materialNeedsLights(material);
  14910. materialProperties.lightsStateVersion = lightsStateVersion;
  14911. if (materialProperties.needsLights) {
  14912. // wire up the material to this renderer's lighting state
  14913. uniforms.ambientLightColor.value = lights.state.ambient;
  14914. uniforms.lightProbe.value = lights.state.probe;
  14915. uniforms.directionalLights.value = lights.state.directional;
  14916. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  14917. uniforms.spotLights.value = lights.state.spot;
  14918. uniforms.spotLightShadows.value = lights.state.spotShadow;
  14919. uniforms.rectAreaLights.value = lights.state.rectArea;
  14920. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  14921. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  14922. uniforms.pointLights.value = lights.state.point;
  14923. uniforms.pointLightShadows.value = lights.state.pointShadow;
  14924. uniforms.hemisphereLights.value = lights.state.hemi;
  14925. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14926. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14927. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14928. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14929. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14930. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  14931. }
  14932. var progUniforms = materialProperties.program.getUniforms();
  14933. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  14934. materialProperties.uniformsList = uniformsList;
  14935. }
  14936. function setProgram(camera, scene, material, object) {
  14937. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14938. textures.resetTextureUnits();
  14939. var fog = scene.fog;
  14940. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  14941. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  14942. var envMap = cubemaps.get(material.envMap || environment);
  14943. var materialProperties = properties.get(material);
  14944. var lights = currentRenderState.state.lights;
  14945. if (_clippingEnabled === true) {
  14946. if (_localClippingEnabled === true || camera !== _currentCamera) {
  14947. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  14948. // object instead of the material, once it becomes feasible
  14949. // (#8465, #8379)
  14950. clipping.setState(material, camera, useCache);
  14951. }
  14952. }
  14953. if (material.version === materialProperties.__version) {
  14954. if (material.fog && materialProperties.fog !== fog) {
  14955. initMaterial(material, scene, object);
  14956. } else if (materialProperties.environment !== environment) {
  14957. initMaterial(material, scene, object);
  14958. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  14959. initMaterial(material, scene, object);
  14960. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  14961. initMaterial(material, scene, object);
  14962. } else if (materialProperties.outputEncoding !== encoding) {
  14963. initMaterial(material, scene, object);
  14964. } else if (materialProperties.envMap !== envMap) {
  14965. initMaterial(material, scene, object);
  14966. }
  14967. } else {
  14968. initMaterial(material, scene, object);
  14969. materialProperties.__version = material.version;
  14970. }
  14971. var refreshProgram = false;
  14972. var refreshMaterial = false;
  14973. var refreshLights = false;
  14974. var program = materialProperties.program,
  14975. p_uniforms = program.getUniforms(),
  14976. m_uniforms = materialProperties.uniforms;
  14977. if (state.useProgram(program.program)) {
  14978. refreshProgram = true;
  14979. refreshMaterial = true;
  14980. refreshLights = true;
  14981. }
  14982. if (material.id !== _currentMaterialId) {
  14983. _currentMaterialId = material.id;
  14984. refreshMaterial = true;
  14985. }
  14986. if (refreshProgram || _currentCamera !== camera) {
  14987. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  14988. if (capabilities.logarithmicDepthBuffer) {
  14989. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  14990. }
  14991. if (_currentCamera !== camera) {
  14992. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  14993. // now, in case this material supports lights - or later, when
  14994. // the next material that does gets activated:
  14995. refreshMaterial = true; // set to true on material change
  14996. refreshLights = true; // remains set until update done
  14997. } // load material specific uniforms
  14998. // (shader material also gets them for the sake of genericity)
  14999. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  15000. var uCamPos = p_uniforms.map.cameraPosition;
  15001. if (uCamPos !== undefined) {
  15002. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  15003. }
  15004. }
  15005. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  15006. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  15007. }
  15008. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  15009. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  15010. }
  15011. } // skinning uniforms must be set even if material didn't change
  15012. // auto-setting of texture unit for bone texture must go before other textures
  15013. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15014. if (material.skinning) {
  15015. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  15016. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  15017. var skeleton = object.skeleton;
  15018. if (skeleton) {
  15019. var bones = skeleton.bones;
  15020. if (capabilities.floatVertexTextures) {
  15021. if (skeleton.boneTexture === null) {
  15022. // layout (1 matrix = 4 pixels)
  15023. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15024. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15025. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15026. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15027. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15028. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  15029. size = MathUtils.ceilPowerOfTwo(size);
  15030. size = Math.max(size, 4);
  15031. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  15032. boneMatrices.set(skeleton.boneMatrices); // copy current values
  15033. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  15034. skeleton.boneMatrices = boneMatrices;
  15035. skeleton.boneTexture = boneTexture;
  15036. skeleton.boneTextureSize = size;
  15037. }
  15038. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  15039. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  15040. } else {
  15041. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  15042. }
  15043. }
  15044. }
  15045. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  15046. materialProperties.receiveShadow = object.receiveShadow;
  15047. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  15048. }
  15049. if (refreshMaterial) {
  15050. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  15051. if (materialProperties.needsLights) {
  15052. // the current material requires lighting info
  15053. // note: all lighting uniforms are always set correctly
  15054. // they simply reference the renderer's state for their
  15055. // values
  15056. //
  15057. // use the current material's .needsUpdate flags to set
  15058. // the GL state when required
  15059. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  15060. } // refresh uniforms common to several materials
  15061. if (fog && material.fog) {
  15062. materials.refreshFogUniforms(m_uniforms, fog);
  15063. }
  15064. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  15065. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15066. }
  15067. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  15068. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15069. material.uniformsNeedUpdate = false;
  15070. }
  15071. if (material.isSpriteMaterial) {
  15072. p_uniforms.setValue(_gl, 'center', object.center);
  15073. } // common matrices
  15074. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  15075. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  15076. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  15077. return program;
  15078. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15079. function markUniformsLightsNeedsUpdate(uniforms, value) {
  15080. uniforms.ambientLightColor.needsUpdate = value;
  15081. uniforms.lightProbe.needsUpdate = value;
  15082. uniforms.directionalLights.needsUpdate = value;
  15083. uniforms.directionalLightShadows.needsUpdate = value;
  15084. uniforms.pointLights.needsUpdate = value;
  15085. uniforms.pointLightShadows.needsUpdate = value;
  15086. uniforms.spotLights.needsUpdate = value;
  15087. uniforms.spotLightShadows.needsUpdate = value;
  15088. uniforms.rectAreaLights.needsUpdate = value;
  15089. uniforms.hemisphereLights.needsUpdate = value;
  15090. }
  15091. function materialNeedsLights(material) {
  15092. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  15093. } //
  15094. this.setFramebuffer = function (value) {
  15095. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  15096. _framebuffer = value;
  15097. };
  15098. this.getActiveCubeFace = function () {
  15099. return _currentActiveCubeFace;
  15100. };
  15101. this.getActiveMipmapLevel = function () {
  15102. return _currentActiveMipmapLevel;
  15103. };
  15104. this.getRenderList = function () {
  15105. return currentRenderList;
  15106. };
  15107. this.setRenderList = function (renderList) {
  15108. currentRenderList = renderList;
  15109. };
  15110. this.getRenderState = function () {
  15111. return currentRenderState;
  15112. };
  15113. this.setRenderState = function (renderState) {
  15114. currentRenderState = renderState;
  15115. };
  15116. this.getRenderTarget = function () {
  15117. return _currentRenderTarget;
  15118. };
  15119. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15120. if (activeCubeFace === void 0) {
  15121. activeCubeFace = 0;
  15122. }
  15123. if (activeMipmapLevel === void 0) {
  15124. activeMipmapLevel = 0;
  15125. }
  15126. _currentRenderTarget = renderTarget;
  15127. _currentActiveCubeFace = activeCubeFace;
  15128. _currentActiveMipmapLevel = activeMipmapLevel;
  15129. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15130. textures.setupRenderTarget(renderTarget);
  15131. }
  15132. var framebuffer = _framebuffer;
  15133. var isCube = false;
  15134. if (renderTarget) {
  15135. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15136. if (renderTarget.isWebGLCubeRenderTarget) {
  15137. framebuffer = __webglFramebuffer[activeCubeFace];
  15138. isCube = true;
  15139. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15140. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15141. } else {
  15142. framebuffer = __webglFramebuffer;
  15143. }
  15144. _currentViewport.copy(renderTarget.viewport);
  15145. _currentScissor.copy(renderTarget.scissor);
  15146. _currentScissorTest = renderTarget.scissorTest;
  15147. } else {
  15148. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15149. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15150. _currentScissorTest = _scissorTest;
  15151. }
  15152. if (_currentFramebuffer !== framebuffer) {
  15153. _gl.bindFramebuffer(36160, framebuffer);
  15154. _currentFramebuffer = framebuffer;
  15155. }
  15156. state.viewport(_currentViewport);
  15157. state.scissor(_currentScissor);
  15158. state.setScissorTest(_currentScissorTest);
  15159. if (isCube) {
  15160. var textureProperties = properties.get(renderTarget.texture);
  15161. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15162. }
  15163. };
  15164. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15165. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15166. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15167. return;
  15168. }
  15169. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15170. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15171. framebuffer = framebuffer[activeCubeFaceIndex];
  15172. }
  15173. if (framebuffer) {
  15174. var restore = false;
  15175. if (framebuffer !== _currentFramebuffer) {
  15176. _gl.bindFramebuffer(36160, framebuffer);
  15177. restore = true;
  15178. }
  15179. try {
  15180. var texture = renderTarget.texture;
  15181. var textureFormat = texture.format;
  15182. var textureType = texture.type;
  15183. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15184. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15185. return;
  15186. }
  15187. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15188. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.get('OES_texture_float') || extensions.get('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15189. !(textureType === HalfFloatType && (capabilities.isWebGL2 ? extensions.get('EXT_color_buffer_float') : extensions.get('EXT_color_buffer_half_float')))) {
  15190. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15191. return;
  15192. }
  15193. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15194. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15195. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15196. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15197. }
  15198. } else {
  15199. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15200. }
  15201. } finally {
  15202. if (restore) {
  15203. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15204. }
  15205. }
  15206. }
  15207. };
  15208. this.copyFramebufferToTexture = function (position, texture, level) {
  15209. if (level === void 0) {
  15210. level = 0;
  15211. }
  15212. var levelScale = Math.pow(2, -level);
  15213. var width = Math.floor(texture.image.width * levelScale);
  15214. var height = Math.floor(texture.image.height * levelScale);
  15215. var glFormat = utils.convert(texture.format);
  15216. textures.setTexture2D(texture, 0);
  15217. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15218. state.unbindTexture();
  15219. };
  15220. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15221. if (level === void 0) {
  15222. level = 0;
  15223. }
  15224. var width = srcTexture.image.width;
  15225. var height = srcTexture.image.height;
  15226. var glFormat = utils.convert(dstTexture.format);
  15227. var glType = utils.convert(dstTexture.type);
  15228. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15229. // parameters, make sure they are correct for the dstTexture
  15230. _gl.pixelStorei(37440, dstTexture.flipY);
  15231. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15232. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15233. if (srcTexture.isDataTexture) {
  15234. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15235. } else {
  15236. if (srcTexture.isCompressedTexture) {
  15237. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15238. } else {
  15239. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15240. }
  15241. } // Generate mipmaps only when copying level 0
  15242. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15243. state.unbindTexture();
  15244. };
  15245. this.initTexture = function (texture) {
  15246. textures.setTexture2D(texture, 0);
  15247. state.unbindTexture();
  15248. };
  15249. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15250. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15251. detail: this
  15252. })); // eslint-disable-line no-undef
  15253. }
  15254. }
  15255. function WebGL1Renderer(parameters) {
  15256. WebGLRenderer.call(this, parameters);
  15257. }
  15258. WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
  15259. constructor: WebGL1Renderer,
  15260. isWebGL1Renderer: true
  15261. });
  15262. var FogExp2 = /*#__PURE__*/function () {
  15263. function FogExp2(color, density) {
  15264. Object.defineProperty(this, 'isFogExp2', {
  15265. value: true
  15266. });
  15267. this.name = '';
  15268. this.color = new Color(color);
  15269. this.density = density !== undefined ? density : 0.00025;
  15270. }
  15271. var _proto = FogExp2.prototype;
  15272. _proto.clone = function clone() {
  15273. return new FogExp2(this.color, this.density);
  15274. };
  15275. _proto.toJSON = function toJSON()
  15276. /* meta */
  15277. {
  15278. return {
  15279. type: 'FogExp2',
  15280. color: this.color.getHex(),
  15281. density: this.density
  15282. };
  15283. };
  15284. return FogExp2;
  15285. }();
  15286. var Fog = /*#__PURE__*/function () {
  15287. function Fog(color, near, far) {
  15288. Object.defineProperty(this, 'isFog', {
  15289. value: true
  15290. });
  15291. this.name = '';
  15292. this.color = new Color(color);
  15293. this.near = near !== undefined ? near : 1;
  15294. this.far = far !== undefined ? far : 1000;
  15295. }
  15296. var _proto = Fog.prototype;
  15297. _proto.clone = function clone() {
  15298. return new Fog(this.color, this.near, this.far);
  15299. };
  15300. _proto.toJSON = function toJSON()
  15301. /* meta */
  15302. {
  15303. return {
  15304. type: 'Fog',
  15305. color: this.color.getHex(),
  15306. near: this.near,
  15307. far: this.far
  15308. };
  15309. };
  15310. return Fog;
  15311. }();
  15312. var Scene = /*#__PURE__*/function (_Object3D) {
  15313. _inheritsLoose(Scene, _Object3D);
  15314. function Scene() {
  15315. var _this;
  15316. _this = _Object3D.call(this) || this;
  15317. Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
  15318. value: true
  15319. });
  15320. _this.type = 'Scene';
  15321. _this.background = null;
  15322. _this.environment = null;
  15323. _this.fog = null;
  15324. _this.overrideMaterial = null;
  15325. _this.autoUpdate = true; // checked by the renderer
  15326. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15327. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15328. detail: _assertThisInitialized(_this)
  15329. })); // eslint-disable-line no-undef
  15330. }
  15331. return _this;
  15332. }
  15333. var _proto = Scene.prototype;
  15334. _proto.copy = function copy(source, recursive) {
  15335. _Object3D.prototype.copy.call(this, source, recursive);
  15336. if (source.background !== null) this.background = source.background.clone();
  15337. if (source.environment !== null) this.environment = source.environment.clone();
  15338. if (source.fog !== null) this.fog = source.fog.clone();
  15339. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  15340. this.autoUpdate = source.autoUpdate;
  15341. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15342. return this;
  15343. };
  15344. _proto.toJSON = function toJSON(meta) {
  15345. var data = _Object3D.prototype.toJSON.call(this, meta);
  15346. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  15347. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  15348. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  15349. return data;
  15350. };
  15351. return Scene;
  15352. }(Object3D);
  15353. function InterleavedBuffer(array, stride) {
  15354. this.array = array;
  15355. this.stride = stride;
  15356. this.count = array !== undefined ? array.length / stride : 0;
  15357. this.usage = StaticDrawUsage;
  15358. this.updateRange = {
  15359. offset: 0,
  15360. count: -1
  15361. };
  15362. this.version = 0;
  15363. this.uuid = MathUtils.generateUUID();
  15364. }
  15365. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  15366. set: function set(value) {
  15367. if (value === true) this.version++;
  15368. }
  15369. });
  15370. Object.assign(InterleavedBuffer.prototype, {
  15371. isInterleavedBuffer: true,
  15372. onUploadCallback: function onUploadCallback() {},
  15373. setUsage: function setUsage(value) {
  15374. this.usage = value;
  15375. return this;
  15376. },
  15377. copy: function copy(source) {
  15378. this.array = new source.array.constructor(source.array);
  15379. this.count = source.count;
  15380. this.stride = source.stride;
  15381. this.usage = source.usage;
  15382. return this;
  15383. },
  15384. copyAt: function copyAt(index1, attribute, index2) {
  15385. index1 *= this.stride;
  15386. index2 *= attribute.stride;
  15387. for (var i = 0, l = this.stride; i < l; i++) {
  15388. this.array[index1 + i] = attribute.array[index2 + i];
  15389. }
  15390. return this;
  15391. },
  15392. set: function set(value, offset) {
  15393. if (offset === void 0) {
  15394. offset = 0;
  15395. }
  15396. this.array.set(value, offset);
  15397. return this;
  15398. },
  15399. clone: function clone(data) {
  15400. if (data.arrayBuffers === undefined) {
  15401. data.arrayBuffers = {};
  15402. }
  15403. if (this.array.buffer._uuid === undefined) {
  15404. this.array.buffer._uuid = MathUtils.generateUUID();
  15405. }
  15406. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15407. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  15408. }
  15409. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  15410. var ib = new InterleavedBuffer(array, this.stride);
  15411. ib.setUsage(this.usage);
  15412. return ib;
  15413. },
  15414. onUpload: function onUpload(callback) {
  15415. this.onUploadCallback = callback;
  15416. return this;
  15417. },
  15418. toJSON: function toJSON(data) {
  15419. if (data.arrayBuffers === undefined) {
  15420. data.arrayBuffers = {};
  15421. } // generate UUID for array buffer if necessary
  15422. if (this.array.buffer._uuid === undefined) {
  15423. this.array.buffer._uuid = MathUtils.generateUUID();
  15424. }
  15425. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15426. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  15427. } //
  15428. return {
  15429. uuid: this.uuid,
  15430. buffer: this.array.buffer._uuid,
  15431. type: this.array.constructor.name,
  15432. stride: this.stride
  15433. };
  15434. }
  15435. });
  15436. var _vector$6 = new Vector3();
  15437. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  15438. this.name = '';
  15439. this.data = interleavedBuffer;
  15440. this.itemSize = itemSize;
  15441. this.offset = offset;
  15442. this.normalized = normalized === true;
  15443. }
  15444. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  15445. count: {
  15446. get: function get() {
  15447. return this.data.count;
  15448. }
  15449. },
  15450. array: {
  15451. get: function get() {
  15452. return this.data.array;
  15453. }
  15454. },
  15455. needsUpdate: {
  15456. set: function set(value) {
  15457. this.data.needsUpdate = value;
  15458. }
  15459. }
  15460. });
  15461. Object.assign(InterleavedBufferAttribute.prototype, {
  15462. isInterleavedBufferAttribute: true,
  15463. applyMatrix4: function applyMatrix4(m) {
  15464. for (var i = 0, l = this.data.count; i < l; i++) {
  15465. _vector$6.x = this.getX(i);
  15466. _vector$6.y = this.getY(i);
  15467. _vector$6.z = this.getZ(i);
  15468. _vector$6.applyMatrix4(m);
  15469. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  15470. }
  15471. return this;
  15472. },
  15473. setX: function setX(index, x) {
  15474. this.data.array[index * this.data.stride + this.offset] = x;
  15475. return this;
  15476. },
  15477. setY: function setY(index, y) {
  15478. this.data.array[index * this.data.stride + this.offset + 1] = y;
  15479. return this;
  15480. },
  15481. setZ: function setZ(index, z) {
  15482. this.data.array[index * this.data.stride + this.offset + 2] = z;
  15483. return this;
  15484. },
  15485. setW: function setW(index, w) {
  15486. this.data.array[index * this.data.stride + this.offset + 3] = w;
  15487. return this;
  15488. },
  15489. getX: function getX(index) {
  15490. return this.data.array[index * this.data.stride + this.offset];
  15491. },
  15492. getY: function getY(index) {
  15493. return this.data.array[index * this.data.stride + this.offset + 1];
  15494. },
  15495. getZ: function getZ(index) {
  15496. return this.data.array[index * this.data.stride + this.offset + 2];
  15497. },
  15498. getW: function getW(index) {
  15499. return this.data.array[index * this.data.stride + this.offset + 3];
  15500. },
  15501. setXY: function setXY(index, x, y) {
  15502. index = index * this.data.stride + this.offset;
  15503. this.data.array[index + 0] = x;
  15504. this.data.array[index + 1] = y;
  15505. return this;
  15506. },
  15507. setXYZ: function setXYZ(index, x, y, z) {
  15508. index = index * this.data.stride + this.offset;
  15509. this.data.array[index + 0] = x;
  15510. this.data.array[index + 1] = y;
  15511. this.data.array[index + 2] = z;
  15512. return this;
  15513. },
  15514. setXYZW: function setXYZW(index, x, y, z, w) {
  15515. index = index * this.data.stride + this.offset;
  15516. this.data.array[index + 0] = x;
  15517. this.data.array[index + 1] = y;
  15518. this.data.array[index + 2] = z;
  15519. this.data.array[index + 3] = w;
  15520. return this;
  15521. },
  15522. clone: function clone(data) {
  15523. if (data === undefined) {
  15524. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  15525. var array = [];
  15526. for (var i = 0; i < this.count; i++) {
  15527. var index = i * this.data.stride + this.offset;
  15528. for (var j = 0; j < this.itemSize; j++) {
  15529. array.push(this.data.array[index + j]);
  15530. }
  15531. }
  15532. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  15533. } else {
  15534. if (data.interleavedBuffers === undefined) {
  15535. data.interleavedBuffers = {};
  15536. }
  15537. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15538. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  15539. }
  15540. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  15541. }
  15542. },
  15543. toJSON: function toJSON(data) {
  15544. if (data === undefined) {
  15545. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  15546. var array = [];
  15547. for (var i = 0; i < this.count; i++) {
  15548. var index = i * this.data.stride + this.offset;
  15549. for (var j = 0; j < this.itemSize; j++) {
  15550. array.push(this.data.array[index + j]);
  15551. }
  15552. } // deinterleave data and save it as an ordinary buffer attribute for now
  15553. return {
  15554. itemSize: this.itemSize,
  15555. type: this.array.constructor.name,
  15556. array: array,
  15557. normalized: this.normalized
  15558. };
  15559. } else {
  15560. // save as true interlaved attribtue
  15561. if (data.interleavedBuffers === undefined) {
  15562. data.interleavedBuffers = {};
  15563. }
  15564. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15565. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  15566. }
  15567. return {
  15568. isInterleavedBufferAttribute: true,
  15569. itemSize: this.itemSize,
  15570. data: this.data.uuid,
  15571. offset: this.offset,
  15572. normalized: this.normalized
  15573. };
  15574. }
  15575. }
  15576. });
  15577. /**
  15578. * parameters = {
  15579. * color: <hex>,
  15580. * map: new THREE.Texture( <Image> ),
  15581. * alphaMap: new THREE.Texture( <Image> ),
  15582. * rotation: <float>,
  15583. * sizeAttenuation: <bool>
  15584. * }
  15585. */
  15586. function SpriteMaterial(parameters) {
  15587. Material.call(this);
  15588. this.type = 'SpriteMaterial';
  15589. this.color = new Color(0xffffff);
  15590. this.map = null;
  15591. this.alphaMap = null;
  15592. this.rotation = 0;
  15593. this.sizeAttenuation = true;
  15594. this.transparent = true;
  15595. this.setValues(parameters);
  15596. }
  15597. SpriteMaterial.prototype = Object.create(Material.prototype);
  15598. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15599. SpriteMaterial.prototype.isSpriteMaterial = true;
  15600. SpriteMaterial.prototype.copy = function (source) {
  15601. Material.prototype.copy.call(this, source);
  15602. this.color.copy(source.color);
  15603. this.map = source.map;
  15604. this.alphaMap = source.alphaMap;
  15605. this.rotation = source.rotation;
  15606. this.sizeAttenuation = source.sizeAttenuation;
  15607. return this;
  15608. };
  15609. var _geometry;
  15610. var _intersectPoint = new Vector3();
  15611. var _worldScale = new Vector3();
  15612. var _mvPosition = new Vector3();
  15613. var _alignedPosition = new Vector2();
  15614. var _rotatedPosition = new Vector2();
  15615. var _viewWorldMatrix = new Matrix4();
  15616. var _vA$1 = new Vector3();
  15617. var _vB$1 = new Vector3();
  15618. var _vC$1 = new Vector3();
  15619. var _uvA$1 = new Vector2();
  15620. var _uvB$1 = new Vector2();
  15621. var _uvC$1 = new Vector2();
  15622. function Sprite(material) {
  15623. Object3D.call(this);
  15624. this.type = 'Sprite';
  15625. if (_geometry === undefined) {
  15626. _geometry = new BufferGeometry();
  15627. 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]);
  15628. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  15629. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  15630. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  15631. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  15632. }
  15633. this.geometry = _geometry;
  15634. this.material = material !== undefined ? material : new SpriteMaterial();
  15635. this.center = new Vector2(0.5, 0.5);
  15636. }
  15637. Sprite.prototype = Object.assign(Object.create(Object3D.prototype), {
  15638. constructor: Sprite,
  15639. isSprite: true,
  15640. raycast: function raycast(raycaster, intersects) {
  15641. if (raycaster.camera === null) {
  15642. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  15643. }
  15644. _worldScale.setFromMatrixScale(this.matrixWorld);
  15645. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  15646. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  15647. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  15648. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  15649. _worldScale.multiplyScalar(-_mvPosition.z);
  15650. }
  15651. var rotation = this.material.rotation;
  15652. var sin, cos;
  15653. if (rotation !== 0) {
  15654. cos = Math.cos(rotation);
  15655. sin = Math.sin(rotation);
  15656. }
  15657. var center = this.center;
  15658. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15659. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15660. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15661. _uvA$1.set(0, 0);
  15662. _uvB$1.set(1, 0);
  15663. _uvC$1.set(1, 1); // check first triangle
  15664. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  15665. if (intersect === null) {
  15666. // check second triangle
  15667. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15668. _uvB$1.set(0, 1);
  15669. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  15670. if (intersect === null) {
  15671. return;
  15672. }
  15673. }
  15674. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  15675. if (distance < raycaster.near || distance > raycaster.far) return;
  15676. intersects.push({
  15677. distance: distance,
  15678. point: _intersectPoint.clone(),
  15679. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  15680. face: null,
  15681. object: this
  15682. });
  15683. },
  15684. copy: function copy(source) {
  15685. Object3D.prototype.copy.call(this, source);
  15686. if (source.center !== undefined) this.center.copy(source.center);
  15687. this.material = source.material;
  15688. return this;
  15689. }
  15690. });
  15691. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  15692. // compute position in camera space
  15693. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  15694. if (sin !== undefined) {
  15695. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  15696. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  15697. } else {
  15698. _rotatedPosition.copy(_alignedPosition);
  15699. }
  15700. vertexPosition.copy(mvPosition);
  15701. vertexPosition.x += _rotatedPosition.x;
  15702. vertexPosition.y += _rotatedPosition.y; // transform to world space
  15703. vertexPosition.applyMatrix4(_viewWorldMatrix);
  15704. }
  15705. var _v1$4 = new Vector3();
  15706. var _v2$2 = new Vector3();
  15707. function LOD() {
  15708. Object3D.call(this);
  15709. this._currentLevel = 0;
  15710. this.type = 'LOD';
  15711. Object.defineProperties(this, {
  15712. levels: {
  15713. enumerable: true,
  15714. value: []
  15715. }
  15716. });
  15717. this.autoUpdate = true;
  15718. }
  15719. LOD.prototype = Object.assign(Object.create(Object3D.prototype), {
  15720. constructor: LOD,
  15721. isLOD: true,
  15722. copy: function copy(source) {
  15723. Object3D.prototype.copy.call(this, source, false);
  15724. var levels = source.levels;
  15725. for (var i = 0, l = levels.length; i < l; i++) {
  15726. var level = levels[i];
  15727. this.addLevel(level.object.clone(), level.distance);
  15728. }
  15729. this.autoUpdate = source.autoUpdate;
  15730. return this;
  15731. },
  15732. addLevel: function addLevel(object, distance) {
  15733. if (distance === void 0) {
  15734. distance = 0;
  15735. }
  15736. distance = Math.abs(distance);
  15737. var levels = this.levels;
  15738. var l;
  15739. for (l = 0; l < levels.length; l++) {
  15740. if (distance < levels[l].distance) {
  15741. break;
  15742. }
  15743. }
  15744. levels.splice(l, 0, {
  15745. distance: distance,
  15746. object: object
  15747. });
  15748. this.add(object);
  15749. return this;
  15750. },
  15751. getCurrentLevel: function getCurrentLevel() {
  15752. return this._currentLevel;
  15753. },
  15754. getObjectForDistance: function getObjectForDistance(distance) {
  15755. var levels = this.levels;
  15756. if (levels.length > 0) {
  15757. var i, l;
  15758. for (i = 1, l = levels.length; i < l; i++) {
  15759. if (distance < levels[i].distance) {
  15760. break;
  15761. }
  15762. }
  15763. return levels[i - 1].object;
  15764. }
  15765. return null;
  15766. },
  15767. raycast: function raycast(raycaster, intersects) {
  15768. var levels = this.levels;
  15769. if (levels.length > 0) {
  15770. _v1$4.setFromMatrixPosition(this.matrixWorld);
  15771. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  15772. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  15773. }
  15774. },
  15775. update: function update(camera) {
  15776. var levels = this.levels;
  15777. if (levels.length > 1) {
  15778. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  15779. _v2$2.setFromMatrixPosition(this.matrixWorld);
  15780. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  15781. levels[0].object.visible = true;
  15782. var i, l;
  15783. for (i = 1, l = levels.length; i < l; i++) {
  15784. if (distance >= levels[i].distance) {
  15785. levels[i - 1].object.visible = false;
  15786. levels[i].object.visible = true;
  15787. } else {
  15788. break;
  15789. }
  15790. }
  15791. this._currentLevel = i - 1;
  15792. for (; i < l; i++) {
  15793. levels[i].object.visible = false;
  15794. }
  15795. }
  15796. },
  15797. toJSON: function toJSON(meta) {
  15798. var data = Object3D.prototype.toJSON.call(this, meta);
  15799. if (this.autoUpdate === false) data.object.autoUpdate = false;
  15800. data.object.levels = [];
  15801. var levels = this.levels;
  15802. for (var i = 0, l = levels.length; i < l; i++) {
  15803. var level = levels[i];
  15804. data.object.levels.push({
  15805. object: level.object.uuid,
  15806. distance: level.distance
  15807. });
  15808. }
  15809. return data;
  15810. }
  15811. });
  15812. function SkinnedMesh(geometry, material) {
  15813. if (geometry && geometry.isGeometry) {
  15814. console.error('THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  15815. }
  15816. Mesh.call(this, geometry, material);
  15817. this.type = 'SkinnedMesh';
  15818. this.bindMode = 'attached';
  15819. this.bindMatrix = new Matrix4();
  15820. this.bindMatrixInverse = new Matrix4();
  15821. }
  15822. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  15823. constructor: SkinnedMesh,
  15824. isSkinnedMesh: true,
  15825. copy: function copy(source) {
  15826. Mesh.prototype.copy.call(this, source);
  15827. this.bindMode = source.bindMode;
  15828. this.bindMatrix.copy(source.bindMatrix);
  15829. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  15830. this.skeleton = source.skeleton;
  15831. return this;
  15832. },
  15833. bind: function bind(skeleton, bindMatrix) {
  15834. this.skeleton = skeleton;
  15835. if (bindMatrix === undefined) {
  15836. this.updateMatrixWorld(true);
  15837. this.skeleton.calculateInverses();
  15838. bindMatrix = this.matrixWorld;
  15839. }
  15840. this.bindMatrix.copy(bindMatrix);
  15841. this.bindMatrixInverse.copy(bindMatrix).invert();
  15842. },
  15843. pose: function pose() {
  15844. this.skeleton.pose();
  15845. },
  15846. normalizeSkinWeights: function normalizeSkinWeights() {
  15847. var vector = new Vector4();
  15848. var skinWeight = this.geometry.attributes.skinWeight;
  15849. for (var i = 0, l = skinWeight.count; i < l; i++) {
  15850. vector.x = skinWeight.getX(i);
  15851. vector.y = skinWeight.getY(i);
  15852. vector.z = skinWeight.getZ(i);
  15853. vector.w = skinWeight.getW(i);
  15854. var scale = 1.0 / vector.manhattanLength();
  15855. if (scale !== Infinity) {
  15856. vector.multiplyScalar(scale);
  15857. } else {
  15858. vector.set(1, 0, 0, 0); // do something reasonable
  15859. }
  15860. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  15861. }
  15862. },
  15863. updateMatrixWorld: function updateMatrixWorld(force) {
  15864. Mesh.prototype.updateMatrixWorld.call(this, force);
  15865. if (this.bindMode === 'attached') {
  15866. this.bindMatrixInverse.copy(this.matrixWorld).invert();
  15867. } else if (this.bindMode === 'detached') {
  15868. this.bindMatrixInverse.copy(this.bindMatrix).invert();
  15869. } else {
  15870. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  15871. }
  15872. },
  15873. boneTransform: function () {
  15874. var basePosition = new Vector3();
  15875. var skinIndex = new Vector4();
  15876. var skinWeight = new Vector4();
  15877. var vector = new Vector3();
  15878. var matrix = new Matrix4();
  15879. return function (index, target) {
  15880. var skeleton = this.skeleton;
  15881. var geometry = this.geometry;
  15882. skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  15883. skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  15884. basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  15885. target.set(0, 0, 0);
  15886. for (var i = 0; i < 4; i++) {
  15887. var weight = skinWeight.getComponent(i);
  15888. if (weight !== 0) {
  15889. var boneIndex = skinIndex.getComponent(i);
  15890. matrix.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  15891. target.addScaledVector(vector.copy(basePosition).applyMatrix4(matrix), weight);
  15892. }
  15893. }
  15894. return target.applyMatrix4(this.bindMatrixInverse);
  15895. };
  15896. }()
  15897. });
  15898. function Bone() {
  15899. Object3D.call(this);
  15900. this.type = 'Bone';
  15901. }
  15902. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  15903. constructor: Bone,
  15904. isBone: true
  15905. });
  15906. var _offsetMatrix = new Matrix4();
  15907. var _identityMatrix = new Matrix4();
  15908. function Skeleton(bones, boneInverses) {
  15909. if (bones === void 0) {
  15910. bones = [];
  15911. }
  15912. if (boneInverses === void 0) {
  15913. boneInverses = [];
  15914. }
  15915. this.uuid = MathUtils.generateUUID();
  15916. this.bones = bones.slice(0);
  15917. this.boneInverses = boneInverses;
  15918. this.boneMatrices = null;
  15919. this.boneTexture = null;
  15920. this.boneTextureSize = 0;
  15921. this.frame = -1;
  15922. this.init();
  15923. }
  15924. Object.assign(Skeleton.prototype, {
  15925. init: function init() {
  15926. var bones = this.bones;
  15927. var boneInverses = this.boneInverses;
  15928. this.boneMatrices = new Float32Array(bones.length * 16); // calculate inverse bone matrices if necessary
  15929. if (boneInverses.length === 0) {
  15930. this.calculateInverses();
  15931. } else {
  15932. // handle special case
  15933. if (bones.length !== boneInverses.length) {
  15934. console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');
  15935. this.boneInverses = [];
  15936. for (var i = 0, il = this.bones.length; i < il; i++) {
  15937. this.boneInverses.push(new Matrix4());
  15938. }
  15939. }
  15940. }
  15941. },
  15942. calculateInverses: function calculateInverses() {
  15943. this.boneInverses.length = 0;
  15944. for (var i = 0, il = this.bones.length; i < il; i++) {
  15945. var inverse = new Matrix4();
  15946. if (this.bones[i]) {
  15947. inverse.copy(this.bones[i].matrixWorld).invert();
  15948. }
  15949. this.boneInverses.push(inverse);
  15950. }
  15951. },
  15952. pose: function pose() {
  15953. // recover the bind-time world matrices
  15954. for (var i = 0, il = this.bones.length; i < il; i++) {
  15955. var bone = this.bones[i];
  15956. if (bone) {
  15957. bone.matrixWorld.copy(this.boneInverses[i]).invert();
  15958. }
  15959. } // compute the local matrices, positions, rotations and scales
  15960. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  15961. var _bone = this.bones[_i];
  15962. if (_bone) {
  15963. if (_bone.parent && _bone.parent.isBone) {
  15964. _bone.matrix.copy(_bone.parent.matrixWorld).invert();
  15965. _bone.matrix.multiply(_bone.matrixWorld);
  15966. } else {
  15967. _bone.matrix.copy(_bone.matrixWorld);
  15968. }
  15969. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  15970. }
  15971. }
  15972. },
  15973. update: function update() {
  15974. var bones = this.bones;
  15975. var boneInverses = this.boneInverses;
  15976. var boneMatrices = this.boneMatrices;
  15977. var boneTexture = this.boneTexture; // flatten bone matrices to array
  15978. for (var i = 0, il = bones.length; i < il; i++) {
  15979. // compute the offset between the current and the original transform
  15980. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  15981. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  15982. _offsetMatrix.toArray(boneMatrices, i * 16);
  15983. }
  15984. if (boneTexture !== null) {
  15985. boneTexture.needsUpdate = true;
  15986. }
  15987. },
  15988. clone: function clone() {
  15989. return new Skeleton(this.bones, this.boneInverses);
  15990. },
  15991. getBoneByName: function getBoneByName(name) {
  15992. for (var i = 0, il = this.bones.length; i < il; i++) {
  15993. var bone = this.bones[i];
  15994. if (bone.name === name) {
  15995. return bone;
  15996. }
  15997. }
  15998. return undefined;
  15999. },
  16000. dispose: function dispose() {
  16001. if (this.boneTexture !== null) {
  16002. this.boneTexture.dispose();
  16003. this.boneTexture = null;
  16004. }
  16005. },
  16006. fromJSON: function fromJSON(json, bones) {
  16007. this.uuid = json.uuid;
  16008. for (var i = 0, l = json.bones.length; i < l; i++) {
  16009. var uuid = json.bones[i];
  16010. var bone = bones[uuid];
  16011. if (bone === undefined) {
  16012. console.warn('THREE.Skeleton: No bone found with UUID:', uuid);
  16013. bone = new Bone();
  16014. }
  16015. this.bones.push(bone);
  16016. this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
  16017. }
  16018. this.init();
  16019. return this;
  16020. },
  16021. toJSON: function toJSON() {
  16022. var data = {
  16023. metadata: {
  16024. version: 4.5,
  16025. type: 'Skeleton',
  16026. generator: 'Skeleton.toJSON'
  16027. },
  16028. bones: [],
  16029. boneInverses: []
  16030. };
  16031. data.uuid = this.uuid;
  16032. var bones = this.bones;
  16033. var boneInverses = this.boneInverses;
  16034. for (var i = 0, l = bones.length; i < l; i++) {
  16035. var bone = bones[i];
  16036. data.bones.push(bone.uuid);
  16037. var boneInverse = boneInverses[i];
  16038. data.boneInverses.push(boneInverse.toArray());
  16039. }
  16040. return data;
  16041. }
  16042. });
  16043. var _instanceLocalMatrix = new Matrix4();
  16044. var _instanceWorldMatrix = new Matrix4();
  16045. var _instanceIntersects = [];
  16046. var _mesh = new Mesh();
  16047. function InstancedMesh(geometry, material, count) {
  16048. Mesh.call(this, geometry, material);
  16049. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  16050. this.instanceColor = null;
  16051. this.count = count;
  16052. this.frustumCulled = false;
  16053. }
  16054. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16055. constructor: InstancedMesh,
  16056. isInstancedMesh: true,
  16057. copy: function copy(source) {
  16058. Mesh.prototype.copy.call(this, source);
  16059. this.instanceMatrix.copy(source.instanceMatrix);
  16060. this.count = source.count;
  16061. return this;
  16062. },
  16063. getColorAt: function getColorAt(index, color) {
  16064. color.fromArray(this.instanceColor.array, index * 3);
  16065. },
  16066. getMatrixAt: function getMatrixAt(index, matrix) {
  16067. matrix.fromArray(this.instanceMatrix.array, index * 16);
  16068. },
  16069. raycast: function raycast(raycaster, intersects) {
  16070. var matrixWorld = this.matrixWorld;
  16071. var raycastTimes = this.count;
  16072. _mesh.geometry = this.geometry;
  16073. _mesh.material = this.material;
  16074. if (_mesh.material === undefined) return;
  16075. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  16076. // calculate the world matrix for each instance
  16077. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  16078. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  16079. _mesh.matrixWorld = _instanceWorldMatrix;
  16080. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  16081. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  16082. var intersect = _instanceIntersects[i];
  16083. intersect.instanceId = instanceId;
  16084. intersect.object = this;
  16085. intersects.push(intersect);
  16086. }
  16087. _instanceIntersects.length = 0;
  16088. }
  16089. },
  16090. setColorAt: function setColorAt(index, color) {
  16091. if (this.instanceColor === null) {
  16092. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  16093. }
  16094. color.toArray(this.instanceColor.array, index * 3);
  16095. },
  16096. setMatrixAt: function setMatrixAt(index, matrix) {
  16097. matrix.toArray(this.instanceMatrix.array, index * 16);
  16098. },
  16099. updateMorphTargets: function updateMorphTargets() {}
  16100. });
  16101. /**
  16102. * parameters = {
  16103. * color: <hex>,
  16104. * opacity: <float>,
  16105. *
  16106. * linewidth: <float>,
  16107. * linecap: "round",
  16108. * linejoin: "round"
  16109. * }
  16110. */
  16111. function LineBasicMaterial(parameters) {
  16112. Material.call(this);
  16113. this.type = 'LineBasicMaterial';
  16114. this.color = new Color(0xffffff);
  16115. this.linewidth = 1;
  16116. this.linecap = 'round';
  16117. this.linejoin = 'round';
  16118. this.morphTargets = false;
  16119. this.setValues(parameters);
  16120. }
  16121. LineBasicMaterial.prototype = Object.create(Material.prototype);
  16122. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16123. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16124. LineBasicMaterial.prototype.copy = function (source) {
  16125. Material.prototype.copy.call(this, source);
  16126. this.color.copy(source.color);
  16127. this.linewidth = source.linewidth;
  16128. this.linecap = source.linecap;
  16129. this.linejoin = source.linejoin;
  16130. this.morphTargets = source.morphTargets;
  16131. return this;
  16132. };
  16133. var _start = new Vector3();
  16134. var _end = new Vector3();
  16135. var _inverseMatrix$1 = new Matrix4();
  16136. var _ray$1 = new Ray();
  16137. var _sphere$2 = new Sphere();
  16138. function Line(geometry, material, mode) {
  16139. if (mode === 1) {
  16140. console.error('THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.');
  16141. }
  16142. Object3D.call(this);
  16143. this.type = 'Line';
  16144. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16145. this.material = material !== undefined ? material : new LineBasicMaterial();
  16146. this.updateMorphTargets();
  16147. }
  16148. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  16149. constructor: Line,
  16150. isLine: true,
  16151. copy: function copy(source) {
  16152. Object3D.prototype.copy.call(this, source);
  16153. this.material = source.material;
  16154. this.geometry = source.geometry;
  16155. return this;
  16156. },
  16157. computeLineDistances: function computeLineDistances() {
  16158. var geometry = this.geometry;
  16159. if (geometry.isBufferGeometry) {
  16160. // we assume non-indexed geometry
  16161. if (geometry.index === null) {
  16162. var positionAttribute = geometry.attributes.position;
  16163. var lineDistances = [0];
  16164. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  16165. _start.fromBufferAttribute(positionAttribute, i - 1);
  16166. _end.fromBufferAttribute(positionAttribute, i);
  16167. lineDistances[i] = lineDistances[i - 1];
  16168. lineDistances[i] += _start.distanceTo(_end);
  16169. }
  16170. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16171. } else {
  16172. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16173. }
  16174. } else if (geometry.isGeometry) {
  16175. var vertices = geometry.vertices;
  16176. var _lineDistances = geometry.lineDistances;
  16177. _lineDistances[0] = 0;
  16178. for (var _i = 1, _l = vertices.length; _i < _l; _i++) {
  16179. _lineDistances[_i] = _lineDistances[_i - 1];
  16180. _lineDistances[_i] += vertices[_i - 1].distanceTo(vertices[_i]);
  16181. }
  16182. }
  16183. return this;
  16184. },
  16185. raycast: function raycast(raycaster, intersects) {
  16186. var geometry = this.geometry;
  16187. var matrixWorld = this.matrixWorld;
  16188. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  16189. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16190. _sphere$2.copy(geometry.boundingSphere);
  16191. _sphere$2.applyMatrix4(matrixWorld);
  16192. _sphere$2.radius += threshold;
  16193. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  16194. _inverseMatrix$1.copy(matrixWorld).invert();
  16195. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  16196. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16197. var localThresholdSq = localThreshold * localThreshold;
  16198. var vStart = new Vector3();
  16199. var vEnd = new Vector3();
  16200. var interSegment = new Vector3();
  16201. var interRay = new Vector3();
  16202. var step = this.isLineSegments ? 2 : 1;
  16203. if (geometry.isBufferGeometry) {
  16204. var index = geometry.index;
  16205. var attributes = geometry.attributes;
  16206. var positionAttribute = attributes.position;
  16207. if (index !== null) {
  16208. var indices = index.array;
  16209. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  16210. var a = indices[i];
  16211. var b = indices[i + 1];
  16212. vStart.fromBufferAttribute(positionAttribute, a);
  16213. vEnd.fromBufferAttribute(positionAttribute, b);
  16214. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16215. if (distSq > localThresholdSq) continue;
  16216. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16217. var distance = raycaster.ray.origin.distanceTo(interRay);
  16218. if (distance < raycaster.near || distance > raycaster.far) continue;
  16219. intersects.push({
  16220. distance: distance,
  16221. // What do we want? intersection point on the ray or on the segment??
  16222. // point: raycaster.ray.at( distance ),
  16223. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16224. index: i,
  16225. face: null,
  16226. faceIndex: null,
  16227. object: this
  16228. });
  16229. }
  16230. } else {
  16231. for (var _i2 = 0, _l2 = positionAttribute.count - 1; _i2 < _l2; _i2 += step) {
  16232. vStart.fromBufferAttribute(positionAttribute, _i2);
  16233. vEnd.fromBufferAttribute(positionAttribute, _i2 + 1);
  16234. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16235. if (_distSq > localThresholdSq) continue;
  16236. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16237. var _distance = raycaster.ray.origin.distanceTo(interRay);
  16238. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  16239. intersects.push({
  16240. distance: _distance,
  16241. // What do we want? intersection point on the ray or on the segment??
  16242. // point: raycaster.ray.at( distance ),
  16243. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16244. index: _i2,
  16245. face: null,
  16246. faceIndex: null,
  16247. object: this
  16248. });
  16249. }
  16250. }
  16251. } else if (geometry.isGeometry) {
  16252. var vertices = geometry.vertices;
  16253. var nbVertices = vertices.length;
  16254. for (var _i3 = 0; _i3 < nbVertices - 1; _i3 += step) {
  16255. var _distSq2 = _ray$1.distanceSqToSegment(vertices[_i3], vertices[_i3 + 1], interRay, interSegment);
  16256. if (_distSq2 > localThresholdSq) continue;
  16257. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16258. var _distance2 = raycaster.ray.origin.distanceTo(interRay);
  16259. if (_distance2 < raycaster.near || _distance2 > raycaster.far) continue;
  16260. intersects.push({
  16261. distance: _distance2,
  16262. // What do we want? intersection point on the ray or on the segment??
  16263. // point: raycaster.ray.at( distance ),
  16264. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16265. index: _i3,
  16266. face: null,
  16267. faceIndex: null,
  16268. object: this
  16269. });
  16270. }
  16271. }
  16272. },
  16273. updateMorphTargets: function updateMorphTargets() {
  16274. var geometry = this.geometry;
  16275. if (geometry.isBufferGeometry) {
  16276. var morphAttributes = geometry.morphAttributes;
  16277. var keys = Object.keys(morphAttributes);
  16278. if (keys.length > 0) {
  16279. var morphAttribute = morphAttributes[keys[0]];
  16280. if (morphAttribute !== undefined) {
  16281. this.morphTargetInfluences = [];
  16282. this.morphTargetDictionary = {};
  16283. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16284. var name = morphAttribute[m].name || String(m);
  16285. this.morphTargetInfluences.push(0);
  16286. this.morphTargetDictionary[name] = m;
  16287. }
  16288. }
  16289. }
  16290. } else {
  16291. var morphTargets = geometry.morphTargets;
  16292. if (morphTargets !== undefined && morphTargets.length > 0) {
  16293. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16294. }
  16295. }
  16296. }
  16297. });
  16298. var _start$1 = new Vector3();
  16299. var _end$1 = new Vector3();
  16300. function LineSegments(geometry, material) {
  16301. Line.call(this, geometry, material);
  16302. this.type = 'LineSegments';
  16303. }
  16304. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  16305. constructor: LineSegments,
  16306. isLineSegments: true,
  16307. computeLineDistances: function computeLineDistances() {
  16308. var geometry = this.geometry;
  16309. if (geometry.isBufferGeometry) {
  16310. // we assume non-indexed geometry
  16311. if (geometry.index === null) {
  16312. var positionAttribute = geometry.attributes.position;
  16313. var lineDistances = [];
  16314. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  16315. _start$1.fromBufferAttribute(positionAttribute, i);
  16316. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  16317. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  16318. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  16319. }
  16320. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16321. } else {
  16322. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16323. }
  16324. } else if (geometry.isGeometry) {
  16325. var vertices = geometry.vertices;
  16326. var _lineDistances = geometry.lineDistances;
  16327. for (var _i = 0, _l = vertices.length; _i < _l; _i += 2) {
  16328. _start$1.copy(vertices[_i]);
  16329. _end$1.copy(vertices[_i + 1]);
  16330. _lineDistances[_i] = _i === 0 ? 0 : _lineDistances[_i - 1];
  16331. _lineDistances[_i + 1] = _lineDistances[_i] + _start$1.distanceTo(_end$1);
  16332. }
  16333. }
  16334. return this;
  16335. }
  16336. });
  16337. function LineLoop(geometry, material) {
  16338. Line.call(this, geometry, material);
  16339. this.type = 'LineLoop';
  16340. }
  16341. LineLoop.prototype = Object.assign(Object.create(Line.prototype), {
  16342. constructor: LineLoop,
  16343. isLineLoop: true
  16344. });
  16345. /**
  16346. * parameters = {
  16347. * color: <hex>,
  16348. * opacity: <float>,
  16349. * map: new THREE.Texture( <Image> ),
  16350. * alphaMap: new THREE.Texture( <Image> ),
  16351. *
  16352. * size: <float>,
  16353. * sizeAttenuation: <bool>
  16354. *
  16355. * morphTargets: <bool>
  16356. * }
  16357. */
  16358. function PointsMaterial(parameters) {
  16359. Material.call(this);
  16360. this.type = 'PointsMaterial';
  16361. this.color = new Color(0xffffff);
  16362. this.map = null;
  16363. this.alphaMap = null;
  16364. this.size = 1;
  16365. this.sizeAttenuation = true;
  16366. this.morphTargets = false;
  16367. this.setValues(parameters);
  16368. }
  16369. PointsMaterial.prototype = Object.create(Material.prototype);
  16370. PointsMaterial.prototype.constructor = PointsMaterial;
  16371. PointsMaterial.prototype.isPointsMaterial = true;
  16372. PointsMaterial.prototype.copy = function (source) {
  16373. Material.prototype.copy.call(this, source);
  16374. this.color.copy(source.color);
  16375. this.map = source.map;
  16376. this.alphaMap = source.alphaMap;
  16377. this.size = source.size;
  16378. this.sizeAttenuation = source.sizeAttenuation;
  16379. this.morphTargets = source.morphTargets;
  16380. return this;
  16381. };
  16382. var _inverseMatrix$2 = new Matrix4();
  16383. var _ray$2 = new Ray();
  16384. var _sphere$3 = new Sphere();
  16385. var _position$1 = new Vector3();
  16386. function Points(geometry, material) {
  16387. Object3D.call(this);
  16388. this.type = 'Points';
  16389. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16390. this.material = material !== undefined ? material : new PointsMaterial();
  16391. this.updateMorphTargets();
  16392. }
  16393. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  16394. constructor: Points,
  16395. isPoints: true,
  16396. copy: function copy(source) {
  16397. Object3D.prototype.copy.call(this, source);
  16398. this.material = source.material;
  16399. this.geometry = source.geometry;
  16400. return this;
  16401. },
  16402. raycast: function raycast(raycaster, intersects) {
  16403. var geometry = this.geometry;
  16404. var matrixWorld = this.matrixWorld;
  16405. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  16406. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16407. _sphere$3.copy(geometry.boundingSphere);
  16408. _sphere$3.applyMatrix4(matrixWorld);
  16409. _sphere$3.radius += threshold;
  16410. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  16411. _inverseMatrix$2.copy(matrixWorld).invert();
  16412. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  16413. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16414. var localThresholdSq = localThreshold * localThreshold;
  16415. if (geometry.isBufferGeometry) {
  16416. var index = geometry.index;
  16417. var attributes = geometry.attributes;
  16418. var positionAttribute = attributes.position;
  16419. if (index !== null) {
  16420. var indices = index.array;
  16421. for (var i = 0, il = indices.length; i < il; i++) {
  16422. var a = indices[i];
  16423. _position$1.fromBufferAttribute(positionAttribute, a);
  16424. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16425. }
  16426. } else {
  16427. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  16428. _position$1.fromBufferAttribute(positionAttribute, _i);
  16429. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16430. }
  16431. }
  16432. } else {
  16433. var vertices = geometry.vertices;
  16434. for (var _i2 = 0, _l = vertices.length; _i2 < _l; _i2++) {
  16435. testPoint(vertices[_i2], _i2, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16436. }
  16437. }
  16438. },
  16439. updateMorphTargets: function updateMorphTargets() {
  16440. var geometry = this.geometry;
  16441. if (geometry.isBufferGeometry) {
  16442. var morphAttributes = geometry.morphAttributes;
  16443. var keys = Object.keys(morphAttributes);
  16444. if (keys.length > 0) {
  16445. var morphAttribute = morphAttributes[keys[0]];
  16446. if (morphAttribute !== undefined) {
  16447. this.morphTargetInfluences = [];
  16448. this.morphTargetDictionary = {};
  16449. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16450. var name = morphAttribute[m].name || String(m);
  16451. this.morphTargetInfluences.push(0);
  16452. this.morphTargetDictionary[name] = m;
  16453. }
  16454. }
  16455. }
  16456. } else {
  16457. var morphTargets = geometry.morphTargets;
  16458. if (morphTargets !== undefined && morphTargets.length > 0) {
  16459. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16460. }
  16461. }
  16462. }
  16463. });
  16464. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  16465. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  16466. if (rayPointDistanceSq < localThresholdSq) {
  16467. var intersectPoint = new Vector3();
  16468. _ray$2.closestPointToPoint(point, intersectPoint);
  16469. intersectPoint.applyMatrix4(matrixWorld);
  16470. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  16471. if (distance < raycaster.near || distance > raycaster.far) return;
  16472. intersects.push({
  16473. distance: distance,
  16474. distanceToRay: Math.sqrt(rayPointDistanceSq),
  16475. point: intersectPoint,
  16476. index: index,
  16477. face: null,
  16478. object: object
  16479. });
  16480. }
  16481. }
  16482. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16483. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16484. this.format = format !== undefined ? format : RGBFormat;
  16485. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16486. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16487. this.generateMipmaps = false;
  16488. var scope = this;
  16489. function updateVideo() {
  16490. scope.needsUpdate = true;
  16491. video.requestVideoFrameCallback(updateVideo);
  16492. }
  16493. if ('requestVideoFrameCallback' in video) {
  16494. video.requestVideoFrameCallback(updateVideo);
  16495. }
  16496. }
  16497. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  16498. constructor: VideoTexture,
  16499. clone: function clone() {
  16500. return new this.constructor(this.image).copy(this);
  16501. },
  16502. isVideoTexture: true,
  16503. update: function update() {
  16504. var video = this.image;
  16505. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  16506. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  16507. this.needsUpdate = true;
  16508. }
  16509. }
  16510. });
  16511. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  16512. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  16513. this.image = {
  16514. width: width,
  16515. height: height
  16516. };
  16517. this.mipmaps = mipmaps; // no flipping for cube textures
  16518. // (also flipping doesn't work for compressed textures )
  16519. this.flipY = false; // can't generate mipmaps for compressed textures
  16520. // mips must be embedded in DDS files
  16521. this.generateMipmaps = false;
  16522. }
  16523. CompressedTexture.prototype = Object.create(Texture.prototype);
  16524. CompressedTexture.prototype.constructor = CompressedTexture;
  16525. CompressedTexture.prototype.isCompressedTexture = true;
  16526. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16527. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16528. this.needsUpdate = true;
  16529. }
  16530. CanvasTexture.prototype = Object.create(Texture.prototype);
  16531. CanvasTexture.prototype.constructor = CanvasTexture;
  16532. CanvasTexture.prototype.isCanvasTexture = true;
  16533. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  16534. format = format !== undefined ? format : DepthFormat;
  16535. if (format !== DepthFormat && format !== DepthStencilFormat) {
  16536. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  16537. }
  16538. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  16539. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  16540. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16541. this.image = {
  16542. width: width,
  16543. height: height
  16544. };
  16545. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16546. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16547. this.flipY = false;
  16548. this.generateMipmaps = false;
  16549. }
  16550. DepthTexture.prototype = Object.create(Texture.prototype);
  16551. DepthTexture.prototype.constructor = DepthTexture;
  16552. DepthTexture.prototype.isDepthTexture = true;
  16553. var _geometryId = 0; // Geometry uses even numbers as Id
  16554. var _m1$3 = new Matrix4();
  16555. var _obj$1 = new Object3D();
  16556. var _offset$1 = new Vector3();
  16557. function Geometry() {
  16558. Object.defineProperty(this, 'id', {
  16559. value: _geometryId += 2
  16560. });
  16561. this.uuid = MathUtils.generateUUID();
  16562. this.name = '';
  16563. this.type = 'Geometry';
  16564. this.vertices = [];
  16565. this.colors = [];
  16566. this.faces = [];
  16567. this.faceVertexUvs = [[]];
  16568. this.morphTargets = [];
  16569. this.morphNormals = [];
  16570. this.skinWeights = [];
  16571. this.skinIndices = [];
  16572. this.lineDistances = [];
  16573. this.boundingBox = null;
  16574. this.boundingSphere = null; // update flags
  16575. this.elementsNeedUpdate = false;
  16576. this.verticesNeedUpdate = false;
  16577. this.uvsNeedUpdate = false;
  16578. this.normalsNeedUpdate = false;
  16579. this.colorsNeedUpdate = false;
  16580. this.lineDistancesNeedUpdate = false;
  16581. this.groupsNeedUpdate = false;
  16582. }
  16583. Geometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  16584. constructor: Geometry,
  16585. isGeometry: true,
  16586. applyMatrix4: function applyMatrix4(matrix) {
  16587. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  16588. for (var i = 0, il = this.vertices.length; i < il; i++) {
  16589. var vertex = this.vertices[i];
  16590. vertex.applyMatrix4(matrix);
  16591. }
  16592. for (var _i = 0, _il = this.faces.length; _i < _il; _i++) {
  16593. var face = this.faces[_i];
  16594. face.normal.applyMatrix3(normalMatrix).normalize();
  16595. for (var j = 0, jl = face.vertexNormals.length; j < jl; j++) {
  16596. face.vertexNormals[j].applyMatrix3(normalMatrix).normalize();
  16597. }
  16598. }
  16599. if (this.boundingBox !== null) {
  16600. this.computeBoundingBox();
  16601. }
  16602. if (this.boundingSphere !== null) {
  16603. this.computeBoundingSphere();
  16604. }
  16605. this.verticesNeedUpdate = true;
  16606. this.normalsNeedUpdate = true;
  16607. return this;
  16608. },
  16609. rotateX: function rotateX(angle) {
  16610. // rotate geometry around world x-axis
  16611. _m1$3.makeRotationX(angle);
  16612. this.applyMatrix4(_m1$3);
  16613. return this;
  16614. },
  16615. rotateY: function rotateY(angle) {
  16616. // rotate geometry around world y-axis
  16617. _m1$3.makeRotationY(angle);
  16618. this.applyMatrix4(_m1$3);
  16619. return this;
  16620. },
  16621. rotateZ: function rotateZ(angle) {
  16622. // rotate geometry around world z-axis
  16623. _m1$3.makeRotationZ(angle);
  16624. this.applyMatrix4(_m1$3);
  16625. return this;
  16626. },
  16627. translate: function translate(x, y, z) {
  16628. // translate geometry
  16629. _m1$3.makeTranslation(x, y, z);
  16630. this.applyMatrix4(_m1$3);
  16631. return this;
  16632. },
  16633. scale: function scale(x, y, z) {
  16634. // scale geometry
  16635. _m1$3.makeScale(x, y, z);
  16636. this.applyMatrix4(_m1$3);
  16637. return this;
  16638. },
  16639. lookAt: function lookAt(vector) {
  16640. _obj$1.lookAt(vector);
  16641. _obj$1.updateMatrix();
  16642. this.applyMatrix4(_obj$1.matrix);
  16643. return this;
  16644. },
  16645. fromBufferGeometry: function fromBufferGeometry(geometry) {
  16646. var scope = this;
  16647. var index = geometry.index !== null ? geometry.index : undefined;
  16648. var attributes = geometry.attributes;
  16649. if (attributes.position === undefined) {
  16650. console.error('THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.');
  16651. return this;
  16652. }
  16653. var position = attributes.position;
  16654. var normal = attributes.normal;
  16655. var color = attributes.color;
  16656. var uv = attributes.uv;
  16657. var uv2 = attributes.uv2;
  16658. if (uv2 !== undefined) this.faceVertexUvs[1] = [];
  16659. for (var i = 0; i < position.count; i++) {
  16660. scope.vertices.push(new Vector3().fromBufferAttribute(position, i));
  16661. if (color !== undefined) {
  16662. scope.colors.push(new Color().fromBufferAttribute(color, i));
  16663. }
  16664. }
  16665. function addFace(a, b, c, materialIndex) {
  16666. var vertexColors = color === undefined ? [] : [scope.colors[a].clone(), scope.colors[b].clone(), scope.colors[c].clone()];
  16667. var vertexNormals = normal === undefined ? [] : [new Vector3().fromBufferAttribute(normal, a), new Vector3().fromBufferAttribute(normal, b), new Vector3().fromBufferAttribute(normal, c)];
  16668. var face = new Face3(a, b, c, vertexNormals, vertexColors, materialIndex);
  16669. scope.faces.push(face);
  16670. if (uv !== undefined) {
  16671. scope.faceVertexUvs[0].push([new Vector2().fromBufferAttribute(uv, a), new Vector2().fromBufferAttribute(uv, b), new Vector2().fromBufferAttribute(uv, c)]);
  16672. }
  16673. if (uv2 !== undefined) {
  16674. scope.faceVertexUvs[1].push([new Vector2().fromBufferAttribute(uv2, a), new Vector2().fromBufferAttribute(uv2, b), new Vector2().fromBufferAttribute(uv2, c)]);
  16675. }
  16676. }
  16677. var groups = geometry.groups;
  16678. if (groups.length > 0) {
  16679. for (var _i2 = 0; _i2 < groups.length; _i2++) {
  16680. var group = groups[_i2];
  16681. var start = group.start;
  16682. var count = group.count;
  16683. for (var j = start, jl = start + count; j < jl; j += 3) {
  16684. if (index !== undefined) {
  16685. addFace(index.getX(j), index.getX(j + 1), index.getX(j + 2), group.materialIndex);
  16686. } else {
  16687. addFace(j, j + 1, j + 2, group.materialIndex);
  16688. }
  16689. }
  16690. }
  16691. } else {
  16692. if (index !== undefined) {
  16693. for (var _i3 = 0; _i3 < index.count; _i3 += 3) {
  16694. addFace(index.getX(_i3), index.getX(_i3 + 1), index.getX(_i3 + 2));
  16695. }
  16696. } else {
  16697. for (var _i4 = 0; _i4 < position.count; _i4 += 3) {
  16698. addFace(_i4, _i4 + 1, _i4 + 2);
  16699. }
  16700. }
  16701. }
  16702. this.computeFaceNormals();
  16703. if (geometry.boundingBox !== null) {
  16704. this.boundingBox = geometry.boundingBox.clone();
  16705. }
  16706. if (geometry.boundingSphere !== null) {
  16707. this.boundingSphere = geometry.boundingSphere.clone();
  16708. }
  16709. return this;
  16710. },
  16711. center: function center() {
  16712. this.computeBoundingBox();
  16713. this.boundingBox.getCenter(_offset$1).negate();
  16714. this.translate(_offset$1.x, _offset$1.y, _offset$1.z);
  16715. return this;
  16716. },
  16717. normalize: function normalize() {
  16718. this.computeBoundingSphere();
  16719. var center = this.boundingSphere.center;
  16720. var radius = this.boundingSphere.radius;
  16721. var s = radius === 0 ? 1 : 1.0 / radius;
  16722. var matrix = new Matrix4();
  16723. matrix.set(s, 0, 0, -s * center.x, 0, s, 0, -s * center.y, 0, 0, s, -s * center.z, 0, 0, 0, 1);
  16724. this.applyMatrix4(matrix);
  16725. return this;
  16726. },
  16727. computeFaceNormals: function computeFaceNormals() {
  16728. var cb = new Vector3(),
  16729. ab = new Vector3();
  16730. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16731. var face = this.faces[f];
  16732. var vA = this.vertices[face.a];
  16733. var vB = this.vertices[face.b];
  16734. var vC = this.vertices[face.c];
  16735. cb.subVectors(vC, vB);
  16736. ab.subVectors(vA, vB);
  16737. cb.cross(ab);
  16738. cb.normalize();
  16739. face.normal.copy(cb);
  16740. }
  16741. },
  16742. computeVertexNormals: function computeVertexNormals(areaWeighted) {
  16743. if (areaWeighted === void 0) {
  16744. areaWeighted = true;
  16745. }
  16746. var vertices = new Array(this.vertices.length);
  16747. for (var v = 0, vl = this.vertices.length; v < vl; v++) {
  16748. vertices[v] = new Vector3();
  16749. }
  16750. if (areaWeighted) {
  16751. // vertex normals weighted by triangle areas
  16752. // http://www.iquilezles.org/www/articles/normals/normals.htm
  16753. var cb = new Vector3(),
  16754. ab = new Vector3();
  16755. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16756. var face = this.faces[f];
  16757. var vA = this.vertices[face.a];
  16758. var vB = this.vertices[face.b];
  16759. var vC = this.vertices[face.c];
  16760. cb.subVectors(vC, vB);
  16761. ab.subVectors(vA, vB);
  16762. cb.cross(ab);
  16763. vertices[face.a].add(cb);
  16764. vertices[face.b].add(cb);
  16765. vertices[face.c].add(cb);
  16766. }
  16767. } else {
  16768. this.computeFaceNormals();
  16769. for (var _f = 0, _fl = this.faces.length; _f < _fl; _f++) {
  16770. var _face = this.faces[_f];
  16771. vertices[_face.a].add(_face.normal);
  16772. vertices[_face.b].add(_face.normal);
  16773. vertices[_face.c].add(_face.normal);
  16774. }
  16775. }
  16776. for (var _v = 0, _vl = this.vertices.length; _v < _vl; _v++) {
  16777. vertices[_v].normalize();
  16778. }
  16779. for (var _f2 = 0, _fl2 = this.faces.length; _f2 < _fl2; _f2++) {
  16780. var _face2 = this.faces[_f2];
  16781. var vertexNormals = _face2.vertexNormals;
  16782. if (vertexNormals.length === 3) {
  16783. vertexNormals[0].copy(vertices[_face2.a]);
  16784. vertexNormals[1].copy(vertices[_face2.b]);
  16785. vertexNormals[2].copy(vertices[_face2.c]);
  16786. } else {
  16787. vertexNormals[0] = vertices[_face2.a].clone();
  16788. vertexNormals[1] = vertices[_face2.b].clone();
  16789. vertexNormals[2] = vertices[_face2.c].clone();
  16790. }
  16791. }
  16792. if (this.faces.length > 0) {
  16793. this.normalsNeedUpdate = true;
  16794. }
  16795. },
  16796. computeFlatVertexNormals: function computeFlatVertexNormals() {
  16797. this.computeFaceNormals();
  16798. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16799. var face = this.faces[f];
  16800. var vertexNormals = face.vertexNormals;
  16801. if (vertexNormals.length === 3) {
  16802. vertexNormals[0].copy(face.normal);
  16803. vertexNormals[1].copy(face.normal);
  16804. vertexNormals[2].copy(face.normal);
  16805. } else {
  16806. vertexNormals[0] = face.normal.clone();
  16807. vertexNormals[1] = face.normal.clone();
  16808. vertexNormals[2] = face.normal.clone();
  16809. }
  16810. }
  16811. if (this.faces.length > 0) {
  16812. this.normalsNeedUpdate = true;
  16813. }
  16814. },
  16815. computeMorphNormals: function computeMorphNormals() {
  16816. // save original normals
  16817. // - create temp variables on first access
  16818. // otherwise just copy (for faster repeated calls)
  16819. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16820. var face = this.faces[f];
  16821. if (!face.__originalFaceNormal) {
  16822. face.__originalFaceNormal = face.normal.clone();
  16823. } else {
  16824. face.__originalFaceNormal.copy(face.normal);
  16825. }
  16826. if (!face.__originalVertexNormals) face.__originalVertexNormals = [];
  16827. for (var i = 0, il = face.vertexNormals.length; i < il; i++) {
  16828. if (!face.__originalVertexNormals[i]) {
  16829. face.__originalVertexNormals[i] = face.vertexNormals[i].clone();
  16830. } else {
  16831. face.__originalVertexNormals[i].copy(face.vertexNormals[i]);
  16832. }
  16833. }
  16834. } // use temp geometry to compute face and vertex normals for each morph
  16835. var tmpGeo = new Geometry();
  16836. tmpGeo.faces = this.faces;
  16837. for (var _i5 = 0, _il2 = this.morphTargets.length; _i5 < _il2; _i5++) {
  16838. // create on first access
  16839. if (!this.morphNormals[_i5]) {
  16840. this.morphNormals[_i5] = {};
  16841. this.morphNormals[_i5].faceNormals = [];
  16842. this.morphNormals[_i5].vertexNormals = [];
  16843. var dstNormalsFace = this.morphNormals[_i5].faceNormals;
  16844. var dstNormalsVertex = this.morphNormals[_i5].vertexNormals;
  16845. for (var _f3 = 0, _fl3 = this.faces.length; _f3 < _fl3; _f3++) {
  16846. var faceNormal = new Vector3();
  16847. var vertexNormals = {
  16848. a: new Vector3(),
  16849. b: new Vector3(),
  16850. c: new Vector3()
  16851. };
  16852. dstNormalsFace.push(faceNormal);
  16853. dstNormalsVertex.push(vertexNormals);
  16854. }
  16855. }
  16856. var morphNormals = this.morphNormals[_i5]; // set vertices to morph target
  16857. tmpGeo.vertices = this.morphTargets[_i5].vertices; // compute morph normals
  16858. tmpGeo.computeFaceNormals();
  16859. tmpGeo.computeVertexNormals(); // store morph normals
  16860. for (var _f4 = 0, _fl4 = this.faces.length; _f4 < _fl4; _f4++) {
  16861. var _face3 = this.faces[_f4];
  16862. var _faceNormal = morphNormals.faceNormals[_f4];
  16863. var _vertexNormals = morphNormals.vertexNormals[_f4];
  16864. _faceNormal.copy(_face3.normal);
  16865. _vertexNormals.a.copy(_face3.vertexNormals[0]);
  16866. _vertexNormals.b.copy(_face3.vertexNormals[1]);
  16867. _vertexNormals.c.copy(_face3.vertexNormals[2]);
  16868. }
  16869. } // restore original normals
  16870. for (var _f5 = 0, _fl5 = this.faces.length; _f5 < _fl5; _f5++) {
  16871. var _face4 = this.faces[_f5];
  16872. _face4.normal = _face4.__originalFaceNormal;
  16873. _face4.vertexNormals = _face4.__originalVertexNormals;
  16874. }
  16875. },
  16876. computeBoundingBox: function computeBoundingBox() {
  16877. if (this.boundingBox === null) {
  16878. this.boundingBox = new Box3();
  16879. }
  16880. this.boundingBox.setFromPoints(this.vertices);
  16881. },
  16882. computeBoundingSphere: function computeBoundingSphere() {
  16883. if (this.boundingSphere === null) {
  16884. this.boundingSphere = new Sphere();
  16885. }
  16886. this.boundingSphere.setFromPoints(this.vertices);
  16887. },
  16888. merge: function merge(geometry, matrix, materialIndexOffset) {
  16889. if (materialIndexOffset === void 0) {
  16890. materialIndexOffset = 0;
  16891. }
  16892. if (!(geometry && geometry.isGeometry)) {
  16893. console.error('THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry);
  16894. return;
  16895. }
  16896. var normalMatrix;
  16897. var vertexOffset = this.vertices.length,
  16898. vertices1 = this.vertices,
  16899. vertices2 = geometry.vertices,
  16900. faces1 = this.faces,
  16901. faces2 = geometry.faces,
  16902. colors1 = this.colors,
  16903. colors2 = geometry.colors;
  16904. if (matrix !== undefined) {
  16905. normalMatrix = new Matrix3().getNormalMatrix(matrix);
  16906. } // vertices
  16907. for (var i = 0, il = vertices2.length; i < il; i++) {
  16908. var vertex = vertices2[i];
  16909. var vertexCopy = vertex.clone();
  16910. if (matrix !== undefined) vertexCopy.applyMatrix4(matrix);
  16911. vertices1.push(vertexCopy);
  16912. } // colors
  16913. for (var _i6 = 0, _il3 = colors2.length; _i6 < _il3; _i6++) {
  16914. colors1.push(colors2[_i6].clone());
  16915. } // faces
  16916. for (var _i7 = 0, _il4 = faces2.length; _i7 < _il4; _i7++) {
  16917. var face = faces2[_i7];
  16918. var normal = void 0,
  16919. color = void 0;
  16920. var faceVertexNormals = face.vertexNormals,
  16921. faceVertexColors = face.vertexColors;
  16922. var faceCopy = new Face3(face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset);
  16923. faceCopy.normal.copy(face.normal);
  16924. if (normalMatrix !== undefined) {
  16925. faceCopy.normal.applyMatrix3(normalMatrix).normalize();
  16926. }
  16927. for (var j = 0, jl = faceVertexNormals.length; j < jl; j++) {
  16928. normal = faceVertexNormals[j].clone();
  16929. if (normalMatrix !== undefined) {
  16930. normal.applyMatrix3(normalMatrix).normalize();
  16931. }
  16932. faceCopy.vertexNormals.push(normal);
  16933. }
  16934. faceCopy.color.copy(face.color);
  16935. for (var _j = 0, _jl = faceVertexColors.length; _j < _jl; _j++) {
  16936. color = faceVertexColors[_j];
  16937. faceCopy.vertexColors.push(color.clone());
  16938. }
  16939. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  16940. faces1.push(faceCopy);
  16941. } // uvs
  16942. for (var _i8 = 0, _il5 = geometry.faceVertexUvs.length; _i8 < _il5; _i8++) {
  16943. var faceVertexUvs2 = geometry.faceVertexUvs[_i8];
  16944. if (this.faceVertexUvs[_i8] === undefined) this.faceVertexUvs[_i8] = [];
  16945. for (var _j2 = 0, _jl2 = faceVertexUvs2.length; _j2 < _jl2; _j2++) {
  16946. var uvs2 = faceVertexUvs2[_j2],
  16947. uvsCopy = [];
  16948. for (var k = 0, kl = uvs2.length; k < kl; k++) {
  16949. uvsCopy.push(uvs2[k].clone());
  16950. }
  16951. this.faceVertexUvs[_i8].push(uvsCopy);
  16952. }
  16953. }
  16954. },
  16955. mergeMesh: function mergeMesh(mesh) {
  16956. if (!(mesh && mesh.isMesh)) {
  16957. console.error('THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh);
  16958. return;
  16959. }
  16960. if (mesh.matrixAutoUpdate) mesh.updateMatrix();
  16961. this.merge(mesh.geometry, mesh.matrix);
  16962. },
  16963. /*
  16964. * Checks for duplicate vertices with hashmap.
  16965. * Duplicated vertices are removed
  16966. * and faces' vertices are updated.
  16967. */
  16968. mergeVertices: function mergeVertices(precisionPoints) {
  16969. if (precisionPoints === void 0) {
  16970. precisionPoints = 4;
  16971. }
  16972. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  16973. var unique = [],
  16974. changes = [];
  16975. var precision = Math.pow(10, precisionPoints);
  16976. for (var i = 0, il = this.vertices.length; i < il; i++) {
  16977. var v = this.vertices[i];
  16978. var key = Math.round(v.x * precision) + '_' + Math.round(v.y * precision) + '_' + Math.round(v.z * precision);
  16979. if (verticesMap[key] === undefined) {
  16980. verticesMap[key] = i;
  16981. unique.push(this.vertices[i]);
  16982. changes[i] = unique.length - 1;
  16983. } else {
  16984. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  16985. changes[i] = changes[verticesMap[key]];
  16986. }
  16987. } // if faces are completely degenerate after merging vertices, we
  16988. // have to remove them from the geometry.
  16989. var faceIndicesToRemove = [];
  16990. for (var _i9 = 0, _il6 = this.faces.length; _i9 < _il6; _i9++) {
  16991. var face = this.faces[_i9];
  16992. face.a = changes[face.a];
  16993. face.b = changes[face.b];
  16994. face.c = changes[face.c];
  16995. var indices = [face.a, face.b, face.c]; // if any duplicate vertices are found in a Face3
  16996. // we have to remove the face as nothing can be saved
  16997. for (var n = 0; n < 3; n++) {
  16998. if (indices[n] === indices[(n + 1) % 3]) {
  16999. faceIndicesToRemove.push(_i9);
  17000. break;
  17001. }
  17002. }
  17003. }
  17004. for (var _i10 = faceIndicesToRemove.length - 1; _i10 >= 0; _i10--) {
  17005. var idx = faceIndicesToRemove[_i10];
  17006. this.faces.splice(idx, 1);
  17007. for (var j = 0, jl = this.faceVertexUvs.length; j < jl; j++) {
  17008. this.faceVertexUvs[j].splice(idx, 1);
  17009. }
  17010. } // Use unique set of vertices
  17011. var diff = this.vertices.length - unique.length;
  17012. this.vertices = unique;
  17013. return diff;
  17014. },
  17015. setFromPoints: function setFromPoints(points) {
  17016. this.vertices = [];
  17017. for (var i = 0, l = points.length; i < l; i++) {
  17018. var point = points[i];
  17019. this.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  17020. }
  17021. return this;
  17022. },
  17023. sortFacesByMaterialIndex: function sortFacesByMaterialIndex() {
  17024. var faces = this.faces;
  17025. var length = faces.length; // tag faces
  17026. for (var i = 0; i < length; i++) {
  17027. faces[i]._id = i;
  17028. } // sort faces
  17029. function materialIndexSort(a, b) {
  17030. return a.materialIndex - b.materialIndex;
  17031. }
  17032. faces.sort(materialIndexSort); // sort uvs
  17033. var uvs1 = this.faceVertexUvs[0];
  17034. var uvs2 = this.faceVertexUvs[1];
  17035. var newUvs1, newUvs2;
  17036. if (uvs1 && uvs1.length === length) newUvs1 = [];
  17037. if (uvs2 && uvs2.length === length) newUvs2 = [];
  17038. for (var _i11 = 0; _i11 < length; _i11++) {
  17039. var id = faces[_i11]._id;
  17040. if (newUvs1) newUvs1.push(uvs1[id]);
  17041. if (newUvs2) newUvs2.push(uvs2[id]);
  17042. }
  17043. if (newUvs1) this.faceVertexUvs[0] = newUvs1;
  17044. if (newUvs2) this.faceVertexUvs[1] = newUvs2;
  17045. },
  17046. toJSON: function toJSON() {
  17047. var data = {
  17048. metadata: {
  17049. version: 4.5,
  17050. type: 'Geometry',
  17051. generator: 'Geometry.toJSON'
  17052. }
  17053. }; // standard Geometry serialization
  17054. data.uuid = this.uuid;
  17055. data.type = this.type;
  17056. if (this.name !== '') data.name = this.name;
  17057. if (this.parameters !== undefined) {
  17058. var parameters = this.parameters;
  17059. for (var key in parameters) {
  17060. if (parameters[key] !== undefined) data[key] = parameters[key];
  17061. }
  17062. return data;
  17063. }
  17064. var vertices = [];
  17065. for (var i = 0; i < this.vertices.length; i++) {
  17066. var vertex = this.vertices[i];
  17067. vertices.push(vertex.x, vertex.y, vertex.z);
  17068. }
  17069. var faces = [];
  17070. var normals = [];
  17071. var normalsHash = {};
  17072. var colors = [];
  17073. var colorsHash = {};
  17074. var uvs = [];
  17075. var uvsHash = {};
  17076. for (var _i12 = 0; _i12 < this.faces.length; _i12++) {
  17077. var face = this.faces[_i12];
  17078. var hasMaterial = true;
  17079. var hasFaceUv = false; // deprecated
  17080. var hasFaceVertexUv = this.faceVertexUvs[0][_i12] !== undefined;
  17081. var hasFaceNormal = face.normal.length() > 0;
  17082. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  17083. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  17084. var hasFaceVertexColor = face.vertexColors.length > 0;
  17085. var faceType = 0;
  17086. faceType = setBit(faceType, 0, 0); // isQuad
  17087. faceType = setBit(faceType, 1, hasMaterial);
  17088. faceType = setBit(faceType, 2, hasFaceUv);
  17089. faceType = setBit(faceType, 3, hasFaceVertexUv);
  17090. faceType = setBit(faceType, 4, hasFaceNormal);
  17091. faceType = setBit(faceType, 5, hasFaceVertexNormal);
  17092. faceType = setBit(faceType, 6, hasFaceColor);
  17093. faceType = setBit(faceType, 7, hasFaceVertexColor);
  17094. faces.push(faceType);
  17095. faces.push(face.a, face.b, face.c);
  17096. faces.push(face.materialIndex);
  17097. if (hasFaceVertexUv) {
  17098. var faceVertexUvs = this.faceVertexUvs[0][_i12];
  17099. faces.push(getUvIndex(faceVertexUvs[0]), getUvIndex(faceVertexUvs[1]), getUvIndex(faceVertexUvs[2]));
  17100. }
  17101. if (hasFaceNormal) {
  17102. faces.push(getNormalIndex(face.normal));
  17103. }
  17104. if (hasFaceVertexNormal) {
  17105. var vertexNormals = face.vertexNormals;
  17106. faces.push(getNormalIndex(vertexNormals[0]), getNormalIndex(vertexNormals[1]), getNormalIndex(vertexNormals[2]));
  17107. }
  17108. if (hasFaceColor) {
  17109. faces.push(getColorIndex(face.color));
  17110. }
  17111. if (hasFaceVertexColor) {
  17112. var vertexColors = face.vertexColors;
  17113. faces.push(getColorIndex(vertexColors[0]), getColorIndex(vertexColors[1]), getColorIndex(vertexColors[2]));
  17114. }
  17115. }
  17116. function setBit(value, position, enabled) {
  17117. return enabled ? value | 1 << position : value & ~(1 << position);
  17118. }
  17119. function getNormalIndex(normal) {
  17120. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  17121. if (normalsHash[hash] !== undefined) {
  17122. return normalsHash[hash];
  17123. }
  17124. normalsHash[hash] = normals.length / 3;
  17125. normals.push(normal.x, normal.y, normal.z);
  17126. return normalsHash[hash];
  17127. }
  17128. function getColorIndex(color) {
  17129. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  17130. if (colorsHash[hash] !== undefined) {
  17131. return colorsHash[hash];
  17132. }
  17133. colorsHash[hash] = colors.length;
  17134. colors.push(color.getHex());
  17135. return colorsHash[hash];
  17136. }
  17137. function getUvIndex(uv) {
  17138. var hash = uv.x.toString() + uv.y.toString();
  17139. if (uvsHash[hash] !== undefined) {
  17140. return uvsHash[hash];
  17141. }
  17142. uvsHash[hash] = uvs.length / 2;
  17143. uvs.push(uv.x, uv.y);
  17144. return uvsHash[hash];
  17145. }
  17146. data.data = {};
  17147. data.data.vertices = vertices;
  17148. data.data.normals = normals;
  17149. if (colors.length > 0) data.data.colors = colors;
  17150. if (uvs.length > 0) data.data.uvs = [uvs]; // temporal backward compatibility
  17151. data.data.faces = faces;
  17152. return data;
  17153. },
  17154. clone: function clone() {
  17155. /*
  17156. // Handle primitives
  17157. const parameters = this.parameters;
  17158. if ( parameters !== undefined ) {
  17159. const values = [];
  17160. for ( const key in parameters ) {
  17161. values.push( parameters[ key ] );
  17162. }
  17163. const geometry = Object.create( this.constructor.prototype );
  17164. this.constructor.apply( geometry, values );
  17165. return geometry;
  17166. }
  17167. return new this.constructor().copy( this );
  17168. */
  17169. return new Geometry().copy(this);
  17170. },
  17171. copy: function copy(source) {
  17172. // reset
  17173. this.vertices = [];
  17174. this.colors = [];
  17175. this.faces = [];
  17176. this.faceVertexUvs = [[]];
  17177. this.morphTargets = [];
  17178. this.morphNormals = [];
  17179. this.skinWeights = [];
  17180. this.skinIndices = [];
  17181. this.lineDistances = [];
  17182. this.boundingBox = null;
  17183. this.boundingSphere = null; // name
  17184. this.name = source.name; // vertices
  17185. var vertices = source.vertices;
  17186. for (var i = 0, il = vertices.length; i < il; i++) {
  17187. this.vertices.push(vertices[i].clone());
  17188. } // colors
  17189. var colors = source.colors;
  17190. for (var _i13 = 0, _il7 = colors.length; _i13 < _il7; _i13++) {
  17191. this.colors.push(colors[_i13].clone());
  17192. } // faces
  17193. var faces = source.faces;
  17194. for (var _i14 = 0, _il8 = faces.length; _i14 < _il8; _i14++) {
  17195. this.faces.push(faces[_i14].clone());
  17196. } // face vertex uvs
  17197. for (var _i15 = 0, _il9 = source.faceVertexUvs.length; _i15 < _il9; _i15++) {
  17198. var faceVertexUvs = source.faceVertexUvs[_i15];
  17199. if (this.faceVertexUvs[_i15] === undefined) {
  17200. this.faceVertexUvs[_i15] = [];
  17201. }
  17202. for (var j = 0, jl = faceVertexUvs.length; j < jl; j++) {
  17203. var uvs = faceVertexUvs[j],
  17204. uvsCopy = [];
  17205. for (var k = 0, kl = uvs.length; k < kl; k++) {
  17206. var uv = uvs[k];
  17207. uvsCopy.push(uv.clone());
  17208. }
  17209. this.faceVertexUvs[_i15].push(uvsCopy);
  17210. }
  17211. } // morph targets
  17212. var morphTargets = source.morphTargets;
  17213. for (var _i16 = 0, _il10 = morphTargets.length; _i16 < _il10; _i16++) {
  17214. var morphTarget = {};
  17215. morphTarget.name = morphTargets[_i16].name; // vertices
  17216. if (morphTargets[_i16].vertices !== undefined) {
  17217. morphTarget.vertices = [];
  17218. for (var _j3 = 0, _jl3 = morphTargets[_i16].vertices.length; _j3 < _jl3; _j3++) {
  17219. morphTarget.vertices.push(morphTargets[_i16].vertices[_j3].clone());
  17220. }
  17221. } // normals
  17222. if (morphTargets[_i16].normals !== undefined) {
  17223. morphTarget.normals = [];
  17224. for (var _j4 = 0, _jl4 = morphTargets[_i16].normals.length; _j4 < _jl4; _j4++) {
  17225. morphTarget.normals.push(morphTargets[_i16].normals[_j4].clone());
  17226. }
  17227. }
  17228. this.morphTargets.push(morphTarget);
  17229. } // morph normals
  17230. var morphNormals = source.morphNormals;
  17231. for (var _i17 = 0, _il11 = morphNormals.length; _i17 < _il11; _i17++) {
  17232. var morphNormal = {}; // vertex normals
  17233. if (morphNormals[_i17].vertexNormals !== undefined) {
  17234. morphNormal.vertexNormals = [];
  17235. for (var _j5 = 0, _jl5 = morphNormals[_i17].vertexNormals.length; _j5 < _jl5; _j5++) {
  17236. var srcVertexNormal = morphNormals[_i17].vertexNormals[_j5];
  17237. var destVertexNormal = {};
  17238. destVertexNormal.a = srcVertexNormal.a.clone();
  17239. destVertexNormal.b = srcVertexNormal.b.clone();
  17240. destVertexNormal.c = srcVertexNormal.c.clone();
  17241. morphNormal.vertexNormals.push(destVertexNormal);
  17242. }
  17243. } // face normals
  17244. if (morphNormals[_i17].faceNormals !== undefined) {
  17245. morphNormal.faceNormals = [];
  17246. for (var _j6 = 0, _jl6 = morphNormals[_i17].faceNormals.length; _j6 < _jl6; _j6++) {
  17247. morphNormal.faceNormals.push(morphNormals[_i17].faceNormals[_j6].clone());
  17248. }
  17249. }
  17250. this.morphNormals.push(morphNormal);
  17251. } // skin weights
  17252. var skinWeights = source.skinWeights;
  17253. for (var _i18 = 0, _il12 = skinWeights.length; _i18 < _il12; _i18++) {
  17254. this.skinWeights.push(skinWeights[_i18].clone());
  17255. } // skin indices
  17256. var skinIndices = source.skinIndices;
  17257. for (var _i19 = 0, _il13 = skinIndices.length; _i19 < _il13; _i19++) {
  17258. this.skinIndices.push(skinIndices[_i19].clone());
  17259. } // line distances
  17260. var lineDistances = source.lineDistances;
  17261. for (var _i20 = 0, _il14 = lineDistances.length; _i20 < _il14; _i20++) {
  17262. this.lineDistances.push(lineDistances[_i20]);
  17263. } // bounding box
  17264. var boundingBox = source.boundingBox;
  17265. if (boundingBox !== null) {
  17266. this.boundingBox = boundingBox.clone();
  17267. } // bounding sphere
  17268. var boundingSphere = source.boundingSphere;
  17269. if (boundingSphere !== null) {
  17270. this.boundingSphere = boundingSphere.clone();
  17271. } // update flags
  17272. this.elementsNeedUpdate = source.elementsNeedUpdate;
  17273. this.verticesNeedUpdate = source.verticesNeedUpdate;
  17274. this.uvsNeedUpdate = source.uvsNeedUpdate;
  17275. this.normalsNeedUpdate = source.normalsNeedUpdate;
  17276. this.colorsNeedUpdate = source.colorsNeedUpdate;
  17277. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  17278. this.groupsNeedUpdate = source.groupsNeedUpdate;
  17279. return this;
  17280. },
  17281. dispose: function dispose() {
  17282. this.dispatchEvent({
  17283. type: 'dispose'
  17284. });
  17285. }
  17286. });
  17287. var BoxGeometry = /*#__PURE__*/function (_Geometry) {
  17288. _inheritsLoose(BoxGeometry, _Geometry);
  17289. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  17290. var _this;
  17291. _this = _Geometry.call(this) || this;
  17292. _this.type = 'BoxGeometry';
  17293. _this.parameters = {
  17294. width: width,
  17295. height: height,
  17296. depth: depth,
  17297. widthSegments: widthSegments,
  17298. heightSegments: heightSegments,
  17299. depthSegments: depthSegments
  17300. };
  17301. _this.fromBufferGeometry(new BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments));
  17302. _this.mergeVertices();
  17303. return _this;
  17304. }
  17305. return BoxGeometry;
  17306. }(Geometry);
  17307. var CircleBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17308. _inheritsLoose(CircleBufferGeometry, _BufferGeometry);
  17309. function CircleBufferGeometry(radius, segments, thetaStart, thetaLength) {
  17310. var _this;
  17311. _this = _BufferGeometry.call(this) || this;
  17312. _this.type = 'CircleBufferGeometry';
  17313. _this.parameters = {
  17314. radius: radius,
  17315. segments: segments,
  17316. thetaStart: thetaStart,
  17317. thetaLength: thetaLength
  17318. };
  17319. radius = radius || 1;
  17320. segments = segments !== undefined ? Math.max(3, segments) : 8;
  17321. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17322. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2; // buffers
  17323. var indices = [];
  17324. var vertices = [];
  17325. var normals = [];
  17326. var uvs = []; // helper variables
  17327. var vertex = new Vector3();
  17328. var uv = new Vector2(); // center point
  17329. vertices.push(0, 0, 0);
  17330. normals.push(0, 0, 1);
  17331. uvs.push(0.5, 0.5);
  17332. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17333. var segment = thetaStart + s / segments * thetaLength; // vertex
  17334. vertex.x = radius * Math.cos(segment);
  17335. vertex.y = radius * Math.sin(segment);
  17336. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17337. normals.push(0, 0, 1); // uvs
  17338. uv.x = (vertices[i] / radius + 1) / 2;
  17339. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17340. uvs.push(uv.x, uv.y);
  17341. } // indices
  17342. for (var _i = 1; _i <= segments; _i++) {
  17343. indices.push(_i, _i + 1, 0);
  17344. } // build geometry
  17345. _this.setIndex(indices);
  17346. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17347. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17348. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17349. return _this;
  17350. }
  17351. return CircleBufferGeometry;
  17352. }(BufferGeometry);
  17353. var CircleGeometry = /*#__PURE__*/function (_Geometry) {
  17354. _inheritsLoose(CircleGeometry, _Geometry);
  17355. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17356. var _this;
  17357. _this = _Geometry.call(this) || this;
  17358. _this.type = 'CircleGeometry';
  17359. _this.parameters = {
  17360. radius: radius,
  17361. segments: segments,
  17362. thetaStart: thetaStart,
  17363. thetaLength: thetaLength
  17364. };
  17365. _this.fromBufferGeometry(new CircleBufferGeometry(radius, segments, thetaStart, thetaLength));
  17366. _this.mergeVertices();
  17367. return _this;
  17368. }
  17369. return CircleGeometry;
  17370. }(Geometry);
  17371. var CylinderBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17372. _inheritsLoose(CylinderBufferGeometry, _BufferGeometry);
  17373. function CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17374. var _this;
  17375. _this = _BufferGeometry.call(this) || this;
  17376. _this.type = 'CylinderBufferGeometry';
  17377. _this.parameters = {
  17378. radiusTop: radiusTop,
  17379. radiusBottom: radiusBottom,
  17380. height: height,
  17381. radialSegments: radialSegments,
  17382. heightSegments: heightSegments,
  17383. openEnded: openEnded,
  17384. thetaStart: thetaStart,
  17385. thetaLength: thetaLength
  17386. };
  17387. var scope = _assertThisInitialized(_this);
  17388. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  17389. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  17390. height = height || 1;
  17391. radialSegments = Math.floor(radialSegments) || 8;
  17392. heightSegments = Math.floor(heightSegments) || 1;
  17393. openEnded = openEnded !== undefined ? openEnded : false;
  17394. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  17395. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2; // buffers
  17396. var indices = [];
  17397. var vertices = [];
  17398. var normals = [];
  17399. var uvs = []; // helper variables
  17400. var index = 0;
  17401. var indexArray = [];
  17402. var halfHeight = height / 2;
  17403. var groupStart = 0; // generate geometry
  17404. generateTorso();
  17405. if (openEnded === false) {
  17406. if (radiusTop > 0) generateCap(true);
  17407. if (radiusBottom > 0) generateCap(false);
  17408. } // build geometry
  17409. _this.setIndex(indices);
  17410. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17411. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17412. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17413. function generateTorso() {
  17414. var normal = new Vector3();
  17415. var vertex = new Vector3();
  17416. var groupCount = 0; // this will be used to calculate the normal
  17417. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17418. for (var y = 0; y <= heightSegments; y++) {
  17419. var indexRow = [];
  17420. var v = y / heightSegments; // calculate the radius of the current row
  17421. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17422. for (var x = 0; x <= radialSegments; x++) {
  17423. var u = x / radialSegments;
  17424. var theta = u * thetaLength + thetaStart;
  17425. var sinTheta = Math.sin(theta);
  17426. var cosTheta = Math.cos(theta); // vertex
  17427. vertex.x = radius * sinTheta;
  17428. vertex.y = -v * height + halfHeight;
  17429. vertex.z = radius * cosTheta;
  17430. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17431. normal.set(sinTheta, slope, cosTheta).normalize();
  17432. normals.push(normal.x, normal.y, normal.z); // uv
  17433. uvs.push(u, 1 - v); // save index of vertex in respective row
  17434. indexRow.push(index++);
  17435. } // now save vertices of the row in our index array
  17436. indexArray.push(indexRow);
  17437. } // generate indices
  17438. for (var _x = 0; _x < radialSegments; _x++) {
  17439. for (var _y = 0; _y < heightSegments; _y++) {
  17440. // we use the index array to access the correct indices
  17441. var a = indexArray[_y][_x];
  17442. var b = indexArray[_y + 1][_x];
  17443. var c = indexArray[_y + 1][_x + 1];
  17444. var d = indexArray[_y][_x + 1]; // faces
  17445. indices.push(a, b, d);
  17446. indices.push(b, c, d); // update group counter
  17447. groupCount += 6;
  17448. }
  17449. } // add a group to the geometry. this will ensure multi material support
  17450. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17451. groupStart += groupCount;
  17452. }
  17453. function generateCap(top) {
  17454. // save the index of the first center vertex
  17455. var centerIndexStart = index;
  17456. var uv = new Vector2();
  17457. var vertex = new Vector3();
  17458. var groupCount = 0;
  17459. var radius = top === true ? radiusTop : radiusBottom;
  17460. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17461. // because the geometry needs one set of uvs per face,
  17462. // we must generate a center vertex per face/segment
  17463. for (var x = 1; x <= radialSegments; x++) {
  17464. // vertex
  17465. vertices.push(0, halfHeight * sign, 0); // normal
  17466. normals.push(0, sign, 0); // uv
  17467. uvs.push(0.5, 0.5); // increase index
  17468. index++;
  17469. } // save the index of the last center vertex
  17470. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17471. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17472. var u = _x2 / radialSegments;
  17473. var theta = u * thetaLength + thetaStart;
  17474. var cosTheta = Math.cos(theta);
  17475. var sinTheta = Math.sin(theta); // vertex
  17476. vertex.x = radius * sinTheta;
  17477. vertex.y = halfHeight * sign;
  17478. vertex.z = radius * cosTheta;
  17479. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17480. normals.push(0, sign, 0); // uv
  17481. uv.x = cosTheta * 0.5 + 0.5;
  17482. uv.y = sinTheta * 0.5 * sign + 0.5;
  17483. uvs.push(uv.x, uv.y); // increase index
  17484. index++;
  17485. } // generate indices
  17486. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17487. var c = centerIndexStart + _x3;
  17488. var i = centerIndexEnd + _x3;
  17489. if (top === true) {
  17490. // face top
  17491. indices.push(i, i + 1, c);
  17492. } else {
  17493. // face bottom
  17494. indices.push(i + 1, i, c);
  17495. }
  17496. groupCount += 3;
  17497. } // add a group to the geometry. this will ensure multi material support
  17498. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17499. groupStart += groupCount;
  17500. }
  17501. return _this;
  17502. }
  17503. return CylinderBufferGeometry;
  17504. }(BufferGeometry);
  17505. var CylinderGeometry = /*#__PURE__*/function (_Geometry) {
  17506. _inheritsLoose(CylinderGeometry, _Geometry);
  17507. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17508. var _this;
  17509. _this = _Geometry.call(this) || this;
  17510. _this.type = 'CylinderGeometry';
  17511. _this.parameters = {
  17512. radiusTop: radiusTop,
  17513. radiusBottom: radiusBottom,
  17514. height: height,
  17515. radialSegments: radialSegments,
  17516. heightSegments: heightSegments,
  17517. openEnded: openEnded,
  17518. thetaStart: thetaStart,
  17519. thetaLength: thetaLength
  17520. };
  17521. _this.fromBufferGeometry(new CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength));
  17522. _this.mergeVertices();
  17523. return _this;
  17524. }
  17525. return CylinderGeometry;
  17526. }(Geometry);
  17527. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17528. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17529. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17530. var _this;
  17531. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17532. _this.type = 'ConeGeometry';
  17533. _this.parameters = {
  17534. radius: radius,
  17535. height: height,
  17536. radialSegments: radialSegments,
  17537. heightSegments: heightSegments,
  17538. openEnded: openEnded,
  17539. thetaStart: thetaStart,
  17540. thetaLength: thetaLength
  17541. };
  17542. return _this;
  17543. }
  17544. return ConeGeometry;
  17545. }(CylinderGeometry);
  17546. var ConeBufferGeometry = /*#__PURE__*/function (_CylinderBufferGeomet) {
  17547. _inheritsLoose(ConeBufferGeometry, _CylinderBufferGeomet);
  17548. function ConeBufferGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17549. var _this;
  17550. _this = _CylinderBufferGeomet.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17551. _this.type = 'ConeBufferGeometry';
  17552. _this.parameters = {
  17553. radius: radius,
  17554. height: height,
  17555. radialSegments: radialSegments,
  17556. heightSegments: heightSegments,
  17557. openEnded: openEnded,
  17558. thetaStart: thetaStart,
  17559. thetaLength: thetaLength
  17560. };
  17561. return _this;
  17562. }
  17563. return ConeBufferGeometry;
  17564. }(CylinderBufferGeometry);
  17565. var PolyhedronBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17566. _inheritsLoose(PolyhedronBufferGeometry, _BufferGeometry);
  17567. function PolyhedronBufferGeometry(vertices, indices, radius, detail) {
  17568. var _this;
  17569. _this = _BufferGeometry.call(this) || this;
  17570. _this.type = 'PolyhedronBufferGeometry';
  17571. _this.parameters = {
  17572. vertices: vertices,
  17573. indices: indices,
  17574. radius: radius,
  17575. detail: detail
  17576. };
  17577. radius = radius || 1;
  17578. detail = detail || 0; // default buffer data
  17579. var vertexBuffer = [];
  17580. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17581. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17582. applyRadius(radius); // finally, create the uv data
  17583. generateUVs(); // build non-indexed geometry
  17584. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17585. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17586. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17587. if (detail === 0) {
  17588. _this.computeVertexNormals(); // flat normals
  17589. } else {
  17590. _this.normalizeNormals(); // smooth normals
  17591. } // helper functions
  17592. function subdivide(detail) {
  17593. var a = new Vector3();
  17594. var b = new Vector3();
  17595. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17596. for (var i = 0; i < indices.length; i += 3) {
  17597. // get the vertices of the face
  17598. getVertexByIndex(indices[i + 0], a);
  17599. getVertexByIndex(indices[i + 1], b);
  17600. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17601. subdivideFace(a, b, c, detail);
  17602. }
  17603. }
  17604. function subdivideFace(a, b, c, detail) {
  17605. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17606. var v = []; // construct all of the vertices for this subdivision
  17607. for (var i = 0; i <= cols; i++) {
  17608. v[i] = [];
  17609. var aj = a.clone().lerp(c, i / cols);
  17610. var bj = b.clone().lerp(c, i / cols);
  17611. var rows = cols - i;
  17612. for (var j = 0; j <= rows; j++) {
  17613. if (j === 0 && i === cols) {
  17614. v[i][j] = aj;
  17615. } else {
  17616. v[i][j] = aj.clone().lerp(bj, j / rows);
  17617. }
  17618. }
  17619. } // construct all of the faces
  17620. for (var _i = 0; _i < cols; _i++) {
  17621. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17622. var k = Math.floor(_j / 2);
  17623. if (_j % 2 === 0) {
  17624. pushVertex(v[_i][k + 1]);
  17625. pushVertex(v[_i + 1][k]);
  17626. pushVertex(v[_i][k]);
  17627. } else {
  17628. pushVertex(v[_i][k + 1]);
  17629. pushVertex(v[_i + 1][k + 1]);
  17630. pushVertex(v[_i + 1][k]);
  17631. }
  17632. }
  17633. }
  17634. }
  17635. function applyRadius(radius) {
  17636. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17637. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17638. vertex.x = vertexBuffer[i + 0];
  17639. vertex.y = vertexBuffer[i + 1];
  17640. vertex.z = vertexBuffer[i + 2];
  17641. vertex.normalize().multiplyScalar(radius);
  17642. vertexBuffer[i + 0] = vertex.x;
  17643. vertexBuffer[i + 1] = vertex.y;
  17644. vertexBuffer[i + 2] = vertex.z;
  17645. }
  17646. }
  17647. function generateUVs() {
  17648. var vertex = new Vector3();
  17649. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17650. vertex.x = vertexBuffer[i + 0];
  17651. vertex.y = vertexBuffer[i + 1];
  17652. vertex.z = vertexBuffer[i + 2];
  17653. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17654. var v = inclination(vertex) / Math.PI + 0.5;
  17655. uvBuffer.push(u, 1 - v);
  17656. }
  17657. correctUVs();
  17658. correctSeam();
  17659. }
  17660. function correctSeam() {
  17661. // handle case when face straddles the seam, see #3269
  17662. for (var i = 0; i < uvBuffer.length; i += 6) {
  17663. // uv data of a single face
  17664. var x0 = uvBuffer[i + 0];
  17665. var x1 = uvBuffer[i + 2];
  17666. var x2 = uvBuffer[i + 4];
  17667. var max = Math.max(x0, x1, x2);
  17668. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17669. if (max > 0.9 && min < 0.1) {
  17670. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17671. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17672. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17673. }
  17674. }
  17675. }
  17676. function pushVertex(vertex) {
  17677. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17678. }
  17679. function getVertexByIndex(index, vertex) {
  17680. var stride = index * 3;
  17681. vertex.x = vertices[stride + 0];
  17682. vertex.y = vertices[stride + 1];
  17683. vertex.z = vertices[stride + 2];
  17684. }
  17685. function correctUVs() {
  17686. var a = new Vector3();
  17687. var b = new Vector3();
  17688. var c = new Vector3();
  17689. var centroid = new Vector3();
  17690. var uvA = new Vector2();
  17691. var uvB = new Vector2();
  17692. var uvC = new Vector2();
  17693. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17694. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17695. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17696. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17697. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17698. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17699. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17700. centroid.copy(a).add(b).add(c).divideScalar(3);
  17701. var azi = azimuth(centroid);
  17702. correctUV(uvA, j + 0, a, azi);
  17703. correctUV(uvB, j + 2, b, azi);
  17704. correctUV(uvC, j + 4, c, azi);
  17705. }
  17706. }
  17707. function correctUV(uv, stride, vector, azimuth) {
  17708. if (azimuth < 0 && uv.x === 1) {
  17709. uvBuffer[stride] = uv.x - 1;
  17710. }
  17711. if (vector.x === 0 && vector.z === 0) {
  17712. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17713. }
  17714. } // Angle around the Y axis, counter-clockwise when looking from above.
  17715. function azimuth(vector) {
  17716. return Math.atan2(vector.z, -vector.x);
  17717. } // Angle above the XZ plane.
  17718. function inclination(vector) {
  17719. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17720. }
  17721. return _this;
  17722. }
  17723. return PolyhedronBufferGeometry;
  17724. }(BufferGeometry);
  17725. var DodecahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  17726. _inheritsLoose(DodecahedronBufferGeometry, _PolyhedronBufferGeom);
  17727. function DodecahedronBufferGeometry(radius, detail) {
  17728. var _this;
  17729. var t = (1 + Math.sqrt(5)) / 2;
  17730. var r = 1 / t;
  17731. var vertices = [// (±1, ±1, ±1)
  17732. -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/φ, ±φ)
  17733. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17734. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17735. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17736. 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];
  17737. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  17738. _this.type = 'DodecahedronBufferGeometry';
  17739. _this.parameters = {
  17740. radius: radius,
  17741. detail: detail
  17742. };
  17743. return _this;
  17744. }
  17745. return DodecahedronBufferGeometry;
  17746. }(PolyhedronBufferGeometry);
  17747. var DodecahedronGeometry = /*#__PURE__*/function (_Geometry) {
  17748. _inheritsLoose(DodecahedronGeometry, _Geometry);
  17749. function DodecahedronGeometry(radius, detail) {
  17750. var _this;
  17751. _this = _Geometry.call(this) || this;
  17752. _this.type = 'DodecahedronGeometry';
  17753. _this.parameters = {
  17754. radius: radius,
  17755. detail: detail
  17756. };
  17757. _this.fromBufferGeometry(new DodecahedronBufferGeometry(radius, detail));
  17758. _this.mergeVertices();
  17759. return _this;
  17760. }
  17761. return DodecahedronGeometry;
  17762. }(Geometry);
  17763. var _v0$2 = new Vector3();
  17764. var _v1$5 = new Vector3();
  17765. var _normal$1 = new Vector3();
  17766. var _triangle = new Triangle();
  17767. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17768. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17769. function EdgesGeometry(geometry, thresholdAngle) {
  17770. var _this;
  17771. _this = _BufferGeometry.call(this) || this;
  17772. _this.type = 'EdgesGeometry';
  17773. _this.parameters = {
  17774. thresholdAngle: thresholdAngle
  17775. };
  17776. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17777. if (geometry.isGeometry) {
  17778. geometry = new BufferGeometry().fromGeometry(geometry);
  17779. }
  17780. var precisionPoints = 4;
  17781. var precision = Math.pow(10, precisionPoints);
  17782. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17783. var indexAttr = geometry.getIndex();
  17784. var positionAttr = geometry.getAttribute('position');
  17785. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17786. var indexArr = [0, 0, 0];
  17787. var vertKeys = ['a', 'b', 'c'];
  17788. var hashes = new Array(3);
  17789. var edgeData = {};
  17790. var vertices = [];
  17791. for (var i = 0; i < indexCount; i += 3) {
  17792. if (indexAttr) {
  17793. indexArr[0] = indexAttr.getX(i);
  17794. indexArr[1] = indexAttr.getX(i + 1);
  17795. indexArr[2] = indexAttr.getX(i + 2);
  17796. } else {
  17797. indexArr[0] = i;
  17798. indexArr[1] = i + 1;
  17799. indexArr[2] = i + 2;
  17800. }
  17801. var a = _triangle.a,
  17802. b = _triangle.b,
  17803. c = _triangle.c;
  17804. a.fromBufferAttribute(positionAttr, indexArr[0]);
  17805. b.fromBufferAttribute(positionAttr, indexArr[1]);
  17806. c.fromBufferAttribute(positionAttr, indexArr[2]);
  17807. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  17808. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  17809. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  17810. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  17811. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  17812. continue;
  17813. } // iterate over every edge
  17814. for (var j = 0; j < 3; j++) {
  17815. // get the first and next vertex making up the edge
  17816. var jNext = (j + 1) % 3;
  17817. var vecHash0 = hashes[j];
  17818. var vecHash1 = hashes[jNext];
  17819. var v0 = _triangle[vertKeys[j]];
  17820. var v1 = _triangle[vertKeys[jNext]];
  17821. var hash = vecHash0 + "_" + vecHash1;
  17822. var reverseHash = vecHash1 + "_" + vecHash0;
  17823. if (reverseHash in edgeData && edgeData[reverseHash]) {
  17824. // if we found a sibling edge add it into the vertex array if
  17825. // it meets the angle threshold and delete the edge from the map.
  17826. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  17827. vertices.push(v0.x, v0.y, v0.z);
  17828. vertices.push(v1.x, v1.y, v1.z);
  17829. }
  17830. edgeData[reverseHash] = null;
  17831. } else if (!(hash in edgeData)) {
  17832. // if we've already got an edge here then skip adding a new one
  17833. edgeData[hash] = {
  17834. index0: indexArr[j],
  17835. index1: indexArr[jNext],
  17836. normal: _normal$1.clone()
  17837. };
  17838. }
  17839. }
  17840. } // iterate over all remaining, unmatched edges and add them to the vertex array
  17841. for (var key in edgeData) {
  17842. if (edgeData[key]) {
  17843. var _edgeData$key = edgeData[key],
  17844. index0 = _edgeData$key.index0,
  17845. index1 = _edgeData$key.index1;
  17846. _v0$2.fromBufferAttribute(positionAttr, index0);
  17847. _v1$5.fromBufferAttribute(positionAttr, index1);
  17848. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  17849. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  17850. }
  17851. }
  17852. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17853. return _this;
  17854. }
  17855. return EdgesGeometry;
  17856. }(BufferGeometry);
  17857. /**
  17858. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17859. */
  17860. var Earcut = {
  17861. triangulate: function triangulate(data, holeIndices, dim) {
  17862. dim = dim || 2;
  17863. var hasHoles = holeIndices && holeIndices.length;
  17864. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  17865. var outerNode = linkedList(data, 0, outerLen, dim, true);
  17866. var triangles = [];
  17867. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  17868. var minX, minY, maxX, maxY, x, y, invSize;
  17869. 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
  17870. if (data.length > 80 * dim) {
  17871. minX = maxX = data[0];
  17872. minY = maxY = data[1];
  17873. for (var i = dim; i < outerLen; i += dim) {
  17874. x = data[i];
  17875. y = data[i + 1];
  17876. if (x < minX) minX = x;
  17877. if (y < minY) minY = y;
  17878. if (x > maxX) maxX = x;
  17879. if (y > maxY) maxY = y;
  17880. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17881. invSize = Math.max(maxX - minX, maxY - minY);
  17882. invSize = invSize !== 0 ? 1 / invSize : 0;
  17883. }
  17884. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  17885. return triangles;
  17886. }
  17887. }; // create a circular doubly linked list from polygon points in the specified winding order
  17888. function linkedList(data, start, end, dim, clockwise) {
  17889. var i, last;
  17890. if (clockwise === signedArea(data, start, end, dim) > 0) {
  17891. for (i = start; i < end; i += dim) {
  17892. last = insertNode(i, data[i], data[i + 1], last);
  17893. }
  17894. } else {
  17895. for (i = end - dim; i >= start; i -= dim) {
  17896. last = insertNode(i, data[i], data[i + 1], last);
  17897. }
  17898. }
  17899. if (last && equals(last, last.next)) {
  17900. removeNode(last);
  17901. last = last.next;
  17902. }
  17903. return last;
  17904. } // eliminate colinear or duplicate points
  17905. function filterPoints(start, end) {
  17906. if (!start) return start;
  17907. if (!end) end = start;
  17908. var p = start,
  17909. again;
  17910. do {
  17911. again = false;
  17912. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  17913. removeNode(p);
  17914. p = end = p.prev;
  17915. if (p === p.next) break;
  17916. again = true;
  17917. } else {
  17918. p = p.next;
  17919. }
  17920. } while (again || p !== end);
  17921. return end;
  17922. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  17923. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  17924. if (!ear) return; // interlink polygon nodes in z-order
  17925. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  17926. var stop = ear,
  17927. prev,
  17928. next; // iterate through ears, slicing them one by one
  17929. while (ear.prev !== ear.next) {
  17930. prev = ear.prev;
  17931. next = ear.next;
  17932. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  17933. // cut off the triangle
  17934. triangles.push(prev.i / dim);
  17935. triangles.push(ear.i / dim);
  17936. triangles.push(next.i / dim);
  17937. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  17938. ear = next.next;
  17939. stop = next.next;
  17940. continue;
  17941. }
  17942. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  17943. if (ear === stop) {
  17944. // try filtering points and slicing again
  17945. if (!pass) {
  17946. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  17947. } else if (pass === 1) {
  17948. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  17949. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  17950. } else if (pass === 2) {
  17951. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  17952. }
  17953. break;
  17954. }
  17955. }
  17956. } // check whether a polygon node forms a valid ear with adjacent nodes
  17957. function isEar(ear) {
  17958. var a = ear.prev,
  17959. b = ear,
  17960. c = ear.next;
  17961. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17962. // now make sure we don't have other points inside the potential ear
  17963. var p = ear.next.next;
  17964. while (p !== ear.prev) {
  17965. 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;
  17966. p = p.next;
  17967. }
  17968. return true;
  17969. }
  17970. function isEarHashed(ear, minX, minY, invSize) {
  17971. var a = ear.prev,
  17972. b = ear,
  17973. c = ear.next;
  17974. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17975. // triangle bbox; min & max are calculated like this for speed
  17976. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  17977. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  17978. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  17979. 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;
  17980. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  17981. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  17982. var p = ear.prevZ,
  17983. n = ear.nextZ; // look for points inside the triangle in both directions
  17984. while (p && p.z >= minZ && n && n.z <= maxZ) {
  17985. 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;
  17986. p = p.prevZ;
  17987. 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;
  17988. n = n.nextZ;
  17989. } // look for remaining points in decreasing z-order
  17990. while (p && p.z >= minZ) {
  17991. 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;
  17992. p = p.prevZ;
  17993. } // look for remaining points in increasing z-order
  17994. while (n && n.z <= maxZ) {
  17995. 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;
  17996. n = n.nextZ;
  17997. }
  17998. return true;
  17999. } // go through all polygon nodes and cure small local self-intersections
  18000. function cureLocalIntersections(start, triangles, dim) {
  18001. var p = start;
  18002. do {
  18003. var a = p.prev,
  18004. b = p.next.next;
  18005. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  18006. triangles.push(a.i / dim);
  18007. triangles.push(p.i / dim);
  18008. triangles.push(b.i / dim); // remove two nodes involved
  18009. removeNode(p);
  18010. removeNode(p.next);
  18011. p = start = b;
  18012. }
  18013. p = p.next;
  18014. } while (p !== start);
  18015. return filterPoints(p);
  18016. } // try splitting polygon into two and triangulate them independently
  18017. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  18018. // look for a valid diagonal that divides the polygon into two
  18019. var a = start;
  18020. do {
  18021. var b = a.next.next;
  18022. while (b !== a.prev) {
  18023. if (a.i !== b.i && isValidDiagonal(a, b)) {
  18024. // split the polygon in two by the diagonal
  18025. var c = splitPolygon(a, b); // filter colinear points around the cuts
  18026. a = filterPoints(a, a.next);
  18027. c = filterPoints(c, c.next); // run earcut on each half
  18028. earcutLinked(a, triangles, dim, minX, minY, invSize);
  18029. earcutLinked(c, triangles, dim, minX, minY, invSize);
  18030. return;
  18031. }
  18032. b = b.next;
  18033. }
  18034. a = a.next;
  18035. } while (a !== start);
  18036. } // link every hole into the outer loop, producing a single-ring polygon without holes
  18037. function eliminateHoles(data, holeIndices, outerNode, dim) {
  18038. var queue = [];
  18039. var i, len, start, end, list;
  18040. for (i = 0, len = holeIndices.length; i < len; i++) {
  18041. start = holeIndices[i] * dim;
  18042. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  18043. list = linkedList(data, start, end, dim, false);
  18044. if (list === list.next) list.steiner = true;
  18045. queue.push(getLeftmost(list));
  18046. }
  18047. queue.sort(compareX); // process holes from left to right
  18048. for (i = 0; i < queue.length; i++) {
  18049. eliminateHole(queue[i], outerNode);
  18050. outerNode = filterPoints(outerNode, outerNode.next);
  18051. }
  18052. return outerNode;
  18053. }
  18054. function compareX(a, b) {
  18055. return a.x - b.x;
  18056. } // find a bridge between vertices that connects hole with an outer ring and and link it
  18057. function eliminateHole(hole, outerNode) {
  18058. outerNode = findHoleBridge(hole, outerNode);
  18059. if (outerNode) {
  18060. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  18061. filterPoints(outerNode, outerNode.next);
  18062. filterPoints(b, b.next);
  18063. }
  18064. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  18065. function findHoleBridge(hole, outerNode) {
  18066. var p = outerNode;
  18067. var hx = hole.x;
  18068. var hy = hole.y;
  18069. var qx = -Infinity,
  18070. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  18071. // segment's endpoint with lesser x will be potential connection point
  18072. do {
  18073. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  18074. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  18075. if (x <= hx && x > qx) {
  18076. qx = x;
  18077. if (x === hx) {
  18078. if (hy === p.y) return p;
  18079. if (hy === p.next.y) return p.next;
  18080. }
  18081. m = p.x < p.next.x ? p : p.next;
  18082. }
  18083. }
  18084. p = p.next;
  18085. } while (p !== outerNode);
  18086. if (!m) return null;
  18087. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  18088. // look for points inside the triangle of hole point, segment intersection and endpoint;
  18089. // if there are no points found, we have a valid connection;
  18090. // otherwise choose the point of the minimum angle with the ray as connection point
  18091. var stop = m,
  18092. mx = m.x,
  18093. my = m.y;
  18094. var tanMin = Infinity,
  18095. tan;
  18096. p = m;
  18097. do {
  18098. 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)) {
  18099. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  18100. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  18101. m = p;
  18102. tanMin = tan;
  18103. }
  18104. }
  18105. p = p.next;
  18106. } while (p !== stop);
  18107. return m;
  18108. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  18109. function sectorContainsSector(m, p) {
  18110. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  18111. } // interlink polygon nodes in z-order
  18112. function indexCurve(start, minX, minY, invSize) {
  18113. var p = start;
  18114. do {
  18115. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  18116. p.prevZ = p.prev;
  18117. p.nextZ = p.next;
  18118. p = p.next;
  18119. } while (p !== start);
  18120. p.prevZ.nextZ = null;
  18121. p.prevZ = null;
  18122. sortLinked(p);
  18123. } // Simon Tatham's linked list merge sort algorithm
  18124. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  18125. function sortLinked(list) {
  18126. var i,
  18127. p,
  18128. q,
  18129. e,
  18130. tail,
  18131. numMerges,
  18132. pSize,
  18133. qSize,
  18134. inSize = 1;
  18135. do {
  18136. p = list;
  18137. list = null;
  18138. tail = null;
  18139. numMerges = 0;
  18140. while (p) {
  18141. numMerges++;
  18142. q = p;
  18143. pSize = 0;
  18144. for (i = 0; i < inSize; i++) {
  18145. pSize++;
  18146. q = q.nextZ;
  18147. if (!q) break;
  18148. }
  18149. qSize = inSize;
  18150. while (pSize > 0 || qSize > 0 && q) {
  18151. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  18152. e = p;
  18153. p = p.nextZ;
  18154. pSize--;
  18155. } else {
  18156. e = q;
  18157. q = q.nextZ;
  18158. qSize--;
  18159. }
  18160. if (tail) tail.nextZ = e;else list = e;
  18161. e.prevZ = tail;
  18162. tail = e;
  18163. }
  18164. p = q;
  18165. }
  18166. tail.nextZ = null;
  18167. inSize *= 2;
  18168. } while (numMerges > 1);
  18169. return list;
  18170. } // z-order of a point given coords and inverse of the longer side of data bbox
  18171. function zOrder(x, y, minX, minY, invSize) {
  18172. // coords are transformed into non-negative 15-bit integer range
  18173. x = 32767 * (x - minX) * invSize;
  18174. y = 32767 * (y - minY) * invSize;
  18175. x = (x | x << 8) & 0x00FF00FF;
  18176. x = (x | x << 4) & 0x0F0F0F0F;
  18177. x = (x | x << 2) & 0x33333333;
  18178. x = (x | x << 1) & 0x55555555;
  18179. y = (y | y << 8) & 0x00FF00FF;
  18180. y = (y | y << 4) & 0x0F0F0F0F;
  18181. y = (y | y << 2) & 0x33333333;
  18182. y = (y | y << 1) & 0x55555555;
  18183. return x | y << 1;
  18184. } // find the leftmost node of a polygon ring
  18185. function getLeftmost(start) {
  18186. var p = start,
  18187. leftmost = start;
  18188. do {
  18189. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18190. p = p.next;
  18191. } while (p !== start);
  18192. return leftmost;
  18193. } // check if a point lies within a convex triangle
  18194. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18195. 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;
  18196. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18197. function isValidDiagonal(a, b) {
  18198. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18199. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18200. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18201. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18202. } // signed area of a triangle
  18203. function area(p, q, r) {
  18204. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18205. } // check if two points are equal
  18206. function equals(p1, p2) {
  18207. return p1.x === p2.x && p1.y === p2.y;
  18208. } // check if two segments intersect
  18209. function intersects(p1, q1, p2, q2) {
  18210. var o1 = sign(area(p1, q1, p2));
  18211. var o2 = sign(area(p1, q1, q2));
  18212. var o3 = sign(area(p2, q2, p1));
  18213. var o4 = sign(area(p2, q2, q1));
  18214. if (o1 !== o2 && o3 !== o4) return true; // general case
  18215. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18216. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18217. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18218. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18219. return false;
  18220. } // for collinear points p, q, r, check if point q lies on segment pr
  18221. function onSegment(p, q, r) {
  18222. 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);
  18223. }
  18224. function sign(num) {
  18225. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18226. } // check if a polygon diagonal intersects any polygon segments
  18227. function intersectsPolygon(a, b) {
  18228. var p = a;
  18229. do {
  18230. 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;
  18231. p = p.next;
  18232. } while (p !== a);
  18233. return false;
  18234. } // check if a polygon diagonal is locally inside the polygon
  18235. function locallyInside(a, b) {
  18236. 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;
  18237. } // check if the middle point of a polygon diagonal is inside the polygon
  18238. function middleInside(a, b) {
  18239. var p = a,
  18240. inside = false;
  18241. var px = (a.x + b.x) / 2,
  18242. py = (a.y + b.y) / 2;
  18243. do {
  18244. 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;
  18245. p = p.next;
  18246. } while (p !== a);
  18247. return inside;
  18248. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18249. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18250. function splitPolygon(a, b) {
  18251. var a2 = new Node(a.i, a.x, a.y),
  18252. b2 = new Node(b.i, b.x, b.y),
  18253. an = a.next,
  18254. bp = b.prev;
  18255. a.next = b;
  18256. b.prev = a;
  18257. a2.next = an;
  18258. an.prev = a2;
  18259. b2.next = a2;
  18260. a2.prev = b2;
  18261. bp.next = b2;
  18262. b2.prev = bp;
  18263. return b2;
  18264. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18265. function insertNode(i, x, y, last) {
  18266. var p = new Node(i, x, y);
  18267. if (!last) {
  18268. p.prev = p;
  18269. p.next = p;
  18270. } else {
  18271. p.next = last.next;
  18272. p.prev = last;
  18273. last.next.prev = p;
  18274. last.next = p;
  18275. }
  18276. return p;
  18277. }
  18278. function removeNode(p) {
  18279. p.next.prev = p.prev;
  18280. p.prev.next = p.next;
  18281. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18282. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18283. }
  18284. function Node(i, x, y) {
  18285. // vertex index in coordinates array
  18286. this.i = i; // vertex coordinates
  18287. this.x = x;
  18288. this.y = y; // previous and next vertex nodes in a polygon ring
  18289. this.prev = null;
  18290. this.next = null; // z-order curve value
  18291. this.z = null; // previous and next nodes in z-order
  18292. this.prevZ = null;
  18293. this.nextZ = null; // indicates whether this is a steiner point
  18294. this.steiner = false;
  18295. }
  18296. function signedArea(data, start, end, dim) {
  18297. var sum = 0;
  18298. for (var i = start, j = end - dim; i < end; i += dim) {
  18299. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18300. j = i;
  18301. }
  18302. return sum;
  18303. }
  18304. var ShapeUtils = {
  18305. // calculate area of the contour polygon
  18306. area: function area(contour) {
  18307. var n = contour.length;
  18308. var a = 0.0;
  18309. for (var p = n - 1, q = 0; q < n; p = q++) {
  18310. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18311. }
  18312. return a * 0.5;
  18313. },
  18314. isClockWise: function isClockWise(pts) {
  18315. return ShapeUtils.area(pts) < 0;
  18316. },
  18317. triangulateShape: function triangulateShape(contour, holes) {
  18318. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18319. var holeIndices = []; // array of hole indices
  18320. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18321. removeDupEndPts(contour);
  18322. addContour(vertices, contour); //
  18323. var holeIndex = contour.length;
  18324. holes.forEach(removeDupEndPts);
  18325. for (var i = 0; i < holes.length; i++) {
  18326. holeIndices.push(holeIndex);
  18327. holeIndex += holes[i].length;
  18328. addContour(vertices, holes[i]);
  18329. } //
  18330. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18331. for (var _i = 0; _i < triangles.length; _i += 3) {
  18332. faces.push(triangles.slice(_i, _i + 3));
  18333. }
  18334. return faces;
  18335. }
  18336. };
  18337. function removeDupEndPts(points) {
  18338. var l = points.length;
  18339. if (l > 2 && points[l - 1].equals(points[0])) {
  18340. points.pop();
  18341. }
  18342. }
  18343. function addContour(vertices, contour) {
  18344. for (var i = 0; i < contour.length; i++) {
  18345. vertices.push(contour[i].x);
  18346. vertices.push(contour[i].y);
  18347. }
  18348. }
  18349. var ExtrudeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18350. _inheritsLoose(ExtrudeBufferGeometry, _BufferGeometry);
  18351. function ExtrudeBufferGeometry(shapes, options) {
  18352. var _this;
  18353. _this = _BufferGeometry.call(this) || this;
  18354. _this.type = 'ExtrudeBufferGeometry';
  18355. _this.parameters = {
  18356. shapes: shapes,
  18357. options: options
  18358. };
  18359. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18360. var scope = _assertThisInitialized(_this);
  18361. var verticesArray = [];
  18362. var uvArray = [];
  18363. for (var i = 0, l = shapes.length; i < l; i++) {
  18364. var shape = shapes[i];
  18365. addShape(shape);
  18366. } // build geometry
  18367. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18368. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18369. _this.computeVertexNormals(); // functions
  18370. function addShape(shape) {
  18371. var placeholder = []; // options
  18372. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18373. var steps = options.steps !== undefined ? options.steps : 1;
  18374. var depth = options.depth !== undefined ? options.depth : 100;
  18375. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18376. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18377. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18378. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18379. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18380. var extrudePath = options.extrudePath;
  18381. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18382. if (options.amount !== undefined) {
  18383. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18384. depth = options.amount;
  18385. } //
  18386. var extrudePts,
  18387. extrudeByPath = false;
  18388. var splineTube, binormal, normal, position2;
  18389. if (extrudePath) {
  18390. extrudePts = extrudePath.getSpacedPoints(steps);
  18391. extrudeByPath = true;
  18392. bevelEnabled = false; // bevels not supported for path extrusion
  18393. // SETUP TNB variables
  18394. // TODO1 - have a .isClosed in spline?
  18395. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18396. binormal = new Vector3();
  18397. normal = new Vector3();
  18398. position2 = new Vector3();
  18399. } // Safeguards if bevels are not enabled
  18400. if (!bevelEnabled) {
  18401. bevelSegments = 0;
  18402. bevelThickness = 0;
  18403. bevelSize = 0;
  18404. bevelOffset = 0;
  18405. } // Variables initialization
  18406. var shapePoints = shape.extractPoints(curveSegments);
  18407. var vertices = shapePoints.shape;
  18408. var holes = shapePoints.holes;
  18409. var reverse = !ShapeUtils.isClockWise(vertices);
  18410. if (reverse) {
  18411. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18412. for (var h = 0, hl = holes.length; h < hl; h++) {
  18413. var ahole = holes[h];
  18414. if (ShapeUtils.isClockWise(ahole)) {
  18415. holes[h] = ahole.reverse();
  18416. }
  18417. }
  18418. }
  18419. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18420. /* Vertices */
  18421. var contour = vertices; // vertices has all points but contour has only points of circumference
  18422. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18423. var _ahole = holes[_h];
  18424. vertices = vertices.concat(_ahole);
  18425. }
  18426. function scalePt2(pt, vec, size) {
  18427. if (!vec) console.error("THREE.ExtrudeGeometry: vec does not exist");
  18428. return vec.clone().multiplyScalar(size).add(pt);
  18429. }
  18430. var vlen = vertices.length,
  18431. flen = faces.length; // Find directions for point movement
  18432. function getBevelVec(inPt, inPrev, inNext) {
  18433. // computes for inPt the corresponding point inPt' on a new contour
  18434. // shifted by 1 unit (length of normalized vector) to the left
  18435. // if we walk along contour clockwise, this new contour is outside the old one
  18436. //
  18437. // inPt' is the intersection of the two lines parallel to the two
  18438. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18439. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18440. // good reading for geometry algorithms (here: line-line intersection)
  18441. // http://geomalgorithms.com/a05-_intersect-1.html
  18442. var v_prev_x = inPt.x - inPrev.x,
  18443. v_prev_y = inPt.y - inPrev.y;
  18444. var v_next_x = inNext.x - inPt.x,
  18445. v_next_y = inNext.y - inPt.y;
  18446. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18447. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18448. if (Math.abs(collinear0) > Number.EPSILON) {
  18449. // not collinear
  18450. // length of vectors for normalizing
  18451. var v_prev_len = Math.sqrt(v_prev_lensq);
  18452. 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
  18453. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18454. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18455. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18456. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18457. 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
  18458. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18459. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18460. // but prevent crazy spikes
  18461. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18462. if (v_trans_lensq <= 2) {
  18463. return new Vector2(v_trans_x, v_trans_y);
  18464. } else {
  18465. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18466. }
  18467. } else {
  18468. // handle special case of collinear edges
  18469. var direction_eq = false; // assumes: opposite
  18470. if (v_prev_x > Number.EPSILON) {
  18471. if (v_next_x > Number.EPSILON) {
  18472. direction_eq = true;
  18473. }
  18474. } else {
  18475. if (v_prev_x < -Number.EPSILON) {
  18476. if (v_next_x < -Number.EPSILON) {
  18477. direction_eq = true;
  18478. }
  18479. } else {
  18480. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18481. direction_eq = true;
  18482. }
  18483. }
  18484. }
  18485. if (direction_eq) {
  18486. // console.log("Warning: lines are a straight sequence");
  18487. v_trans_x = -v_prev_y;
  18488. v_trans_y = v_prev_x;
  18489. shrink_by = Math.sqrt(v_prev_lensq);
  18490. } else {
  18491. // console.log("Warning: lines are a straight spike");
  18492. v_trans_x = v_prev_x;
  18493. v_trans_y = v_prev_y;
  18494. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18495. }
  18496. }
  18497. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18498. }
  18499. var contourMovements = [];
  18500. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18501. if (j === il) j = 0;
  18502. if (k === il) k = 0; // (j)---(i)---(k)
  18503. // console.log('i,j,k', i, j , k)
  18504. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18505. }
  18506. var holesMovements = [];
  18507. var oneHoleMovements,
  18508. verticesMovements = contourMovements.concat();
  18509. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18510. var _ahole2 = holes[_h2];
  18511. oneHoleMovements = [];
  18512. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18513. if (_j === _il) _j = 0;
  18514. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18515. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18516. }
  18517. holesMovements.push(oneHoleMovements);
  18518. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18519. } // Loop bevelSegments, 1 for the front, 1 for the back
  18520. for (var b = 0; b < bevelSegments; b++) {
  18521. //for ( b = bevelSegments; b > 0; b -- ) {
  18522. var t = b / bevelSegments;
  18523. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18524. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18525. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18526. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18527. v(vert.x, vert.y, -z);
  18528. } // expand holes
  18529. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18530. var _ahole3 = holes[_h3];
  18531. oneHoleMovements = holesMovements[_h3];
  18532. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18533. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18534. v(_vert.x, _vert.y, -z);
  18535. }
  18536. }
  18537. }
  18538. var bs = bevelSize + bevelOffset; // Back facing vertices
  18539. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18540. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18541. if (!extrudeByPath) {
  18542. v(_vert2.x, _vert2.y, 0);
  18543. } else {
  18544. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18545. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18546. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18547. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18548. v(position2.x, position2.y, position2.z);
  18549. }
  18550. } // Add stepped vertices...
  18551. // Including front facing vertices
  18552. for (var s = 1; s <= steps; s++) {
  18553. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18554. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18555. if (!extrudeByPath) {
  18556. v(_vert3.x, _vert3.y, depth / steps * s);
  18557. } else {
  18558. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18559. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18560. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18561. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18562. v(position2.x, position2.y, position2.z);
  18563. }
  18564. }
  18565. } // Add bevel segments planes
  18566. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18567. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18568. var _t = _b / bevelSegments;
  18569. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18570. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18571. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18572. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18573. v(_vert4.x, _vert4.y, depth + _z);
  18574. } // expand holes
  18575. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18576. var _ahole4 = holes[_h4];
  18577. oneHoleMovements = holesMovements[_h4];
  18578. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18579. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18580. if (!extrudeByPath) {
  18581. v(_vert5.x, _vert5.y, depth + _z);
  18582. } else {
  18583. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18584. }
  18585. }
  18586. }
  18587. }
  18588. /* Faces */
  18589. // Top and bottom faces
  18590. buildLidFaces(); // Sides faces
  18591. buildSideFaces(); ///// Internal functions
  18592. function buildLidFaces() {
  18593. var start = verticesArray.length / 3;
  18594. if (bevelEnabled) {
  18595. var layer = 0; // steps + 1
  18596. var offset = vlen * layer; // Bottom faces
  18597. for (var _i9 = 0; _i9 < flen; _i9++) {
  18598. var face = faces[_i9];
  18599. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18600. }
  18601. layer = steps + bevelSegments * 2;
  18602. offset = vlen * layer; // Top faces
  18603. for (var _i10 = 0; _i10 < flen; _i10++) {
  18604. var _face = faces[_i10];
  18605. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18606. }
  18607. } else {
  18608. // Bottom faces
  18609. for (var _i11 = 0; _i11 < flen; _i11++) {
  18610. var _face2 = faces[_i11];
  18611. f3(_face2[2], _face2[1], _face2[0]);
  18612. } // Top faces
  18613. for (var _i12 = 0; _i12 < flen; _i12++) {
  18614. var _face3 = faces[_i12];
  18615. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18616. }
  18617. }
  18618. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18619. } // Create faces for the z-sides of the shape
  18620. function buildSideFaces() {
  18621. var start = verticesArray.length / 3;
  18622. var layeroffset = 0;
  18623. sidewalls(contour, layeroffset);
  18624. layeroffset += contour.length;
  18625. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18626. var _ahole5 = holes[_h5];
  18627. sidewalls(_ahole5, layeroffset); //, true
  18628. layeroffset += _ahole5.length;
  18629. }
  18630. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18631. }
  18632. function sidewalls(contour, layeroffset) {
  18633. var i = contour.length;
  18634. while (--i >= 0) {
  18635. var _j2 = i;
  18636. var _k2 = i - 1;
  18637. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18638. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18639. var slen1 = vlen * _s;
  18640. var slen2 = vlen * (_s + 1);
  18641. var a = layeroffset + _j2 + slen1,
  18642. _b2 = layeroffset + _k2 + slen1,
  18643. c = layeroffset + _k2 + slen2,
  18644. d = layeroffset + _j2 + slen2;
  18645. f4(a, _b2, c, d);
  18646. }
  18647. }
  18648. }
  18649. function v(x, y, z) {
  18650. placeholder.push(x);
  18651. placeholder.push(y);
  18652. placeholder.push(z);
  18653. }
  18654. function f3(a, b, c) {
  18655. addVertex(a);
  18656. addVertex(b);
  18657. addVertex(c);
  18658. var nextIndex = verticesArray.length / 3;
  18659. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18660. addUV(uvs[0]);
  18661. addUV(uvs[1]);
  18662. addUV(uvs[2]);
  18663. }
  18664. function f4(a, b, c, d) {
  18665. addVertex(a);
  18666. addVertex(b);
  18667. addVertex(d);
  18668. addVertex(b);
  18669. addVertex(c);
  18670. addVertex(d);
  18671. var nextIndex = verticesArray.length / 3;
  18672. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18673. addUV(uvs[0]);
  18674. addUV(uvs[1]);
  18675. addUV(uvs[3]);
  18676. addUV(uvs[1]);
  18677. addUV(uvs[2]);
  18678. addUV(uvs[3]);
  18679. }
  18680. function addVertex(index) {
  18681. verticesArray.push(placeholder[index * 3 + 0]);
  18682. verticesArray.push(placeholder[index * 3 + 1]);
  18683. verticesArray.push(placeholder[index * 3 + 2]);
  18684. }
  18685. function addUV(vector2) {
  18686. uvArray.push(vector2.x);
  18687. uvArray.push(vector2.y);
  18688. }
  18689. }
  18690. return _this;
  18691. }
  18692. var _proto = ExtrudeBufferGeometry.prototype;
  18693. _proto.toJSON = function toJSON() {
  18694. var data = BufferGeometry.prototype.toJSON.call(this);
  18695. var shapes = this.parameters.shapes;
  18696. var options = this.parameters.options;
  18697. return _toJSON(shapes, options, data);
  18698. };
  18699. return ExtrudeBufferGeometry;
  18700. }(BufferGeometry);
  18701. var WorldUVGenerator = {
  18702. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18703. var a_x = vertices[indexA * 3];
  18704. var a_y = vertices[indexA * 3 + 1];
  18705. var b_x = vertices[indexB * 3];
  18706. var b_y = vertices[indexB * 3 + 1];
  18707. var c_x = vertices[indexC * 3];
  18708. var c_y = vertices[indexC * 3 + 1];
  18709. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18710. },
  18711. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18712. var a_x = vertices[indexA * 3];
  18713. var a_y = vertices[indexA * 3 + 1];
  18714. var a_z = vertices[indexA * 3 + 2];
  18715. var b_x = vertices[indexB * 3];
  18716. var b_y = vertices[indexB * 3 + 1];
  18717. var b_z = vertices[indexB * 3 + 2];
  18718. var c_x = vertices[indexC * 3];
  18719. var c_y = vertices[indexC * 3 + 1];
  18720. var c_z = vertices[indexC * 3 + 2];
  18721. var d_x = vertices[indexD * 3];
  18722. var d_y = vertices[indexD * 3 + 1];
  18723. var d_z = vertices[indexD * 3 + 2];
  18724. if (Math.abs(a_y - b_y) < 0.01) {
  18725. 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)];
  18726. } else {
  18727. 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)];
  18728. }
  18729. }
  18730. };
  18731. function _toJSON(shapes, options, data) {
  18732. data.shapes = [];
  18733. if (Array.isArray(shapes)) {
  18734. for (var i = 0, l = shapes.length; i < l; i++) {
  18735. var shape = shapes[i];
  18736. data.shapes.push(shape.uuid);
  18737. }
  18738. } else {
  18739. data.shapes.push(shapes.uuid);
  18740. }
  18741. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18742. return data;
  18743. }
  18744. var ExtrudeGeometry = /*#__PURE__*/function (_Geometry) {
  18745. _inheritsLoose(ExtrudeGeometry, _Geometry);
  18746. function ExtrudeGeometry(shapes, options) {
  18747. var _this;
  18748. _this = _Geometry.call(this) || this;
  18749. _this.type = 'ExtrudeGeometry';
  18750. _this.parameters = {
  18751. shapes: shapes,
  18752. options: options
  18753. };
  18754. _this.fromBufferGeometry(new ExtrudeBufferGeometry(shapes, options));
  18755. _this.mergeVertices();
  18756. return _this;
  18757. }
  18758. var _proto = ExtrudeGeometry.prototype;
  18759. _proto.toJSON = function toJSON() {
  18760. var data = _Geometry.prototype.toJSON.call(this);
  18761. var shapes = this.parameters.shapes;
  18762. var options = this.parameters.options;
  18763. return _toJSON$1(shapes, options, data);
  18764. };
  18765. return ExtrudeGeometry;
  18766. }(Geometry);
  18767. function _toJSON$1(shapes, options, data) {
  18768. data.shapes = [];
  18769. if (Array.isArray(shapes)) {
  18770. for (var i = 0, l = shapes.length; i < l; i++) {
  18771. var shape = shapes[i];
  18772. data.shapes.push(shape.uuid);
  18773. }
  18774. } else {
  18775. data.shapes.push(shapes.uuid);
  18776. }
  18777. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18778. return data;
  18779. }
  18780. var IcosahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  18781. _inheritsLoose(IcosahedronBufferGeometry, _PolyhedronBufferGeom);
  18782. function IcosahedronBufferGeometry(radius, detail) {
  18783. var _this;
  18784. var t = (1 + Math.sqrt(5)) / 2;
  18785. 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];
  18786. 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];
  18787. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  18788. _this.type = 'IcosahedronBufferGeometry';
  18789. _this.parameters = {
  18790. radius: radius,
  18791. detail: detail
  18792. };
  18793. return _this;
  18794. }
  18795. return IcosahedronBufferGeometry;
  18796. }(PolyhedronBufferGeometry);
  18797. var IcosahedronGeometry = /*#__PURE__*/function (_Geometry) {
  18798. _inheritsLoose(IcosahedronGeometry, _Geometry);
  18799. function IcosahedronGeometry(radius, detail) {
  18800. var _this;
  18801. _this = _Geometry.call(this) || this;
  18802. _this.type = 'IcosahedronGeometry';
  18803. _this.parameters = {
  18804. radius: radius,
  18805. detail: detail
  18806. };
  18807. _this.fromBufferGeometry(new IcosahedronBufferGeometry(radius, detail));
  18808. _this.mergeVertices();
  18809. return _this;
  18810. }
  18811. return IcosahedronGeometry;
  18812. }(Geometry);
  18813. var LatheBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18814. _inheritsLoose(LatheBufferGeometry, _BufferGeometry);
  18815. function LatheBufferGeometry(points, segments, phiStart, phiLength) {
  18816. var _this;
  18817. _this = _BufferGeometry.call(this) || this;
  18818. _this.type = 'LatheBufferGeometry';
  18819. _this.parameters = {
  18820. points: points,
  18821. segments: segments,
  18822. phiStart: phiStart,
  18823. phiLength: phiLength
  18824. };
  18825. segments = Math.floor(segments) || 12;
  18826. phiStart = phiStart || 0;
  18827. phiLength = phiLength || Math.PI * 2; // clamp phiLength so it's in range of [ 0, 2PI ]
  18828. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  18829. var indices = [];
  18830. var vertices = [];
  18831. var uvs = []; // helper variables
  18832. var inverseSegments = 1.0 / segments;
  18833. var vertex = new Vector3();
  18834. var uv = new Vector2(); // generate vertices and uvs
  18835. for (var i = 0; i <= segments; i++) {
  18836. var phi = phiStart + i * inverseSegments * phiLength;
  18837. var sin = Math.sin(phi);
  18838. var cos = Math.cos(phi);
  18839. for (var j = 0; j <= points.length - 1; j++) {
  18840. // vertex
  18841. vertex.x = points[j].x * sin;
  18842. vertex.y = points[j].y;
  18843. vertex.z = points[j].x * cos;
  18844. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  18845. uv.x = i / segments;
  18846. uv.y = j / (points.length - 1);
  18847. uvs.push(uv.x, uv.y);
  18848. }
  18849. } // indices
  18850. for (var _i = 0; _i < segments; _i++) {
  18851. for (var _j = 0; _j < points.length - 1; _j++) {
  18852. var base = _j + _i * points.length;
  18853. var a = base;
  18854. var b = base + points.length;
  18855. var c = base + points.length + 1;
  18856. var d = base + 1; // faces
  18857. indices.push(a, b, d);
  18858. indices.push(b, c, d);
  18859. }
  18860. } // build geometry
  18861. _this.setIndex(indices);
  18862. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18863. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  18864. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  18865. // because the corresponding vertices are identical (but still have different UVs).
  18866. if (phiLength === Math.PI * 2) {
  18867. var normals = _this.attributes.normal.array;
  18868. var n1 = new Vector3();
  18869. var n2 = new Vector3();
  18870. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  18871. var _base = segments * points.length * 3;
  18872. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  18873. // select the normal of the vertex in the first line
  18874. n1.x = normals[_j2 + 0];
  18875. n1.y = normals[_j2 + 1];
  18876. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  18877. n2.x = normals[_base + _j2 + 0];
  18878. n2.y = normals[_base + _j2 + 1];
  18879. n2.z = normals[_base + _j2 + 2]; // average normals
  18880. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  18881. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  18882. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  18883. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  18884. }
  18885. }
  18886. return _this;
  18887. }
  18888. return LatheBufferGeometry;
  18889. }(BufferGeometry);
  18890. var LatheGeometry = /*#__PURE__*/function (_Geometry) {
  18891. _inheritsLoose(LatheGeometry, _Geometry);
  18892. function LatheGeometry(points, segments, phiStart, phiLength) {
  18893. var _this;
  18894. _this = _Geometry.call(this) || this;
  18895. _this.type = 'LatheGeometry';
  18896. _this.parameters = {
  18897. points: points,
  18898. segments: segments,
  18899. phiStart: phiStart,
  18900. phiLength: phiLength
  18901. };
  18902. _this.fromBufferGeometry(new LatheBufferGeometry(points, segments, phiStart, phiLength));
  18903. _this.mergeVertices();
  18904. return _this;
  18905. }
  18906. return LatheGeometry;
  18907. }(Geometry);
  18908. var OctahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  18909. _inheritsLoose(OctahedronBufferGeometry, _PolyhedronBufferGeom);
  18910. function OctahedronBufferGeometry(radius, detail) {
  18911. var _this;
  18912. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  18913. 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];
  18914. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  18915. _this.type = 'OctahedronBufferGeometry';
  18916. _this.parameters = {
  18917. radius: radius,
  18918. detail: detail
  18919. };
  18920. return _this;
  18921. }
  18922. return OctahedronBufferGeometry;
  18923. }(PolyhedronBufferGeometry);
  18924. var OctahedronGeometry = /*#__PURE__*/function (_Geometry) {
  18925. _inheritsLoose(OctahedronGeometry, _Geometry);
  18926. function OctahedronGeometry(radius, detail) {
  18927. var _this;
  18928. _this = _Geometry.call(this) || this;
  18929. _this.type = 'OctahedronGeometry';
  18930. _this.parameters = {
  18931. radius: radius,
  18932. detail: detail
  18933. };
  18934. _this.fromBufferGeometry(new OctahedronBufferGeometry(radius, detail));
  18935. _this.mergeVertices();
  18936. return _this;
  18937. }
  18938. return OctahedronGeometry;
  18939. }(Geometry);
  18940. /**
  18941. * Parametric Surfaces Geometry
  18942. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18943. */
  18944. function ParametricBufferGeometry(func, slices, stacks) {
  18945. BufferGeometry.call(this);
  18946. this.type = 'ParametricBufferGeometry';
  18947. this.parameters = {
  18948. func: func,
  18949. slices: slices,
  18950. stacks: stacks
  18951. }; // buffers
  18952. var indices = [];
  18953. var vertices = [];
  18954. var normals = [];
  18955. var uvs = [];
  18956. var EPS = 0.00001;
  18957. var normal = new Vector3();
  18958. var p0 = new Vector3(),
  18959. p1 = new Vector3();
  18960. var pu = new Vector3(),
  18961. pv = new Vector3();
  18962. if (func.length < 3) {
  18963. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  18964. } // generate vertices, normals and uvs
  18965. var sliceCount = slices + 1;
  18966. for (var i = 0; i <= stacks; i++) {
  18967. var v = i / stacks;
  18968. for (var j = 0; j <= slices; j++) {
  18969. var u = j / slices; // vertex
  18970. func(u, v, p0);
  18971. vertices.push(p0.x, p0.y, p0.z); // normal
  18972. // approximate tangent vectors via finite differences
  18973. if (u - EPS >= 0) {
  18974. func(u - EPS, v, p1);
  18975. pu.subVectors(p0, p1);
  18976. } else {
  18977. func(u + EPS, v, p1);
  18978. pu.subVectors(p1, p0);
  18979. }
  18980. if (v - EPS >= 0) {
  18981. func(u, v - EPS, p1);
  18982. pv.subVectors(p0, p1);
  18983. } else {
  18984. func(u, v + EPS, p1);
  18985. pv.subVectors(p1, p0);
  18986. } // cross product of tangent vectors returns surface normal
  18987. normal.crossVectors(pu, pv).normalize();
  18988. normals.push(normal.x, normal.y, normal.z); // uv
  18989. uvs.push(u, v);
  18990. }
  18991. } // generate indices
  18992. for (var _i = 0; _i < stacks; _i++) {
  18993. for (var _j = 0; _j < slices; _j++) {
  18994. var a = _i * sliceCount + _j;
  18995. var b = _i * sliceCount + _j + 1;
  18996. var c = (_i + 1) * sliceCount + _j + 1;
  18997. var d = (_i + 1) * sliceCount + _j; // faces one and two
  18998. indices.push(a, b, d);
  18999. indices.push(b, c, d);
  19000. }
  19001. } // build geometry
  19002. this.setIndex(indices);
  19003. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19004. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19005. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19006. }
  19007. ParametricBufferGeometry.prototype = Object.create(BufferGeometry.prototype);
  19008. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  19009. /**
  19010. * Parametric Surfaces Geometry
  19011. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  19012. */
  19013. function ParametricGeometry(func, slices, stacks) {
  19014. Geometry.call(this);
  19015. this.type = 'ParametricGeometry';
  19016. this.parameters = {
  19017. func: func,
  19018. slices: slices,
  19019. stacks: stacks
  19020. };
  19021. this.fromBufferGeometry(new ParametricBufferGeometry(func, slices, stacks));
  19022. this.mergeVertices();
  19023. }
  19024. ParametricGeometry.prototype = Object.create(Geometry.prototype);
  19025. ParametricGeometry.prototype.constructor = ParametricGeometry;
  19026. var PlaneGeometry = /*#__PURE__*/function (_Geometry) {
  19027. _inheritsLoose(PlaneGeometry, _Geometry);
  19028. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  19029. var _this;
  19030. _this = _Geometry.call(this) || this;
  19031. _this.type = 'PlaneGeometry';
  19032. _this.parameters = {
  19033. width: width,
  19034. height: height,
  19035. widthSegments: widthSegments,
  19036. heightSegments: heightSegments
  19037. };
  19038. _this.fromBufferGeometry(new PlaneBufferGeometry(width, height, widthSegments, heightSegments));
  19039. _this.mergeVertices();
  19040. return _this;
  19041. }
  19042. return PlaneGeometry;
  19043. }(Geometry);
  19044. var PolyhedronGeometry = /*#__PURE__*/function (_Geometry) {
  19045. _inheritsLoose(PolyhedronGeometry, _Geometry);
  19046. function PolyhedronGeometry(vertices, indices, radius, detail) {
  19047. var _this;
  19048. _this = _Geometry.call(this) || this;
  19049. _this.type = 'PolyhedronGeometry';
  19050. _this.parameters = {
  19051. vertices: vertices,
  19052. indices: indices,
  19053. radius: radius,
  19054. detail: detail
  19055. };
  19056. _this.fromBufferGeometry(new PolyhedronBufferGeometry(vertices, indices, radius, detail));
  19057. _this.mergeVertices();
  19058. return _this;
  19059. }
  19060. return PolyhedronGeometry;
  19061. }(Geometry);
  19062. var RingBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19063. _inheritsLoose(RingBufferGeometry, _BufferGeometry);
  19064. function RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  19065. var _this;
  19066. _this = _BufferGeometry.call(this) || this;
  19067. _this.type = 'RingBufferGeometry';
  19068. _this.parameters = {
  19069. innerRadius: innerRadius,
  19070. outerRadius: outerRadius,
  19071. thetaSegments: thetaSegments,
  19072. phiSegments: phiSegments,
  19073. thetaStart: thetaStart,
  19074. thetaLength: thetaLength
  19075. };
  19076. innerRadius = innerRadius || 0.5;
  19077. outerRadius = outerRadius || 1;
  19078. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19079. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19080. thetaSegments = thetaSegments !== undefined ? Math.max(3, thetaSegments) : 8;
  19081. phiSegments = phiSegments !== undefined ? Math.max(1, phiSegments) : 1; // buffers
  19082. var indices = [];
  19083. var vertices = [];
  19084. var normals = [];
  19085. var uvs = []; // some helper variables
  19086. var radius = innerRadius;
  19087. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  19088. var vertex = new Vector3();
  19089. var uv = new Vector2(); // generate vertices, normals and uvs
  19090. for (var j = 0; j <= phiSegments; j++) {
  19091. for (var i = 0; i <= thetaSegments; i++) {
  19092. // values are generate from the inside of the ring to the outside
  19093. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  19094. vertex.x = radius * Math.cos(segment);
  19095. vertex.y = radius * Math.sin(segment);
  19096. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19097. normals.push(0, 0, 1); // uv
  19098. uv.x = (vertex.x / outerRadius + 1) / 2;
  19099. uv.y = (vertex.y / outerRadius + 1) / 2;
  19100. uvs.push(uv.x, uv.y);
  19101. } // increase the radius for next row of vertices
  19102. radius += radiusStep;
  19103. } // indices
  19104. for (var _j = 0; _j < phiSegments; _j++) {
  19105. var thetaSegmentLevel = _j * (thetaSegments + 1);
  19106. for (var _i = 0; _i < thetaSegments; _i++) {
  19107. var _segment = _i + thetaSegmentLevel;
  19108. var a = _segment;
  19109. var b = _segment + thetaSegments + 1;
  19110. var c = _segment + thetaSegments + 2;
  19111. var d = _segment + 1; // faces
  19112. indices.push(a, b, d);
  19113. indices.push(b, c, d);
  19114. }
  19115. } // build geometry
  19116. _this.setIndex(indices);
  19117. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19118. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19119. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19120. return _this;
  19121. }
  19122. return RingBufferGeometry;
  19123. }(BufferGeometry);
  19124. var RingGeometry = /*#__PURE__*/function (_Geometry) {
  19125. _inheritsLoose(RingGeometry, _Geometry);
  19126. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  19127. var _this;
  19128. _this = _Geometry.call(this) || this;
  19129. _this.type = 'RingGeometry';
  19130. _this.parameters = {
  19131. innerRadius: innerRadius,
  19132. outerRadius: outerRadius,
  19133. thetaSegments: thetaSegments,
  19134. phiSegments: phiSegments,
  19135. thetaStart: thetaStart,
  19136. thetaLength: thetaLength
  19137. };
  19138. _this.fromBufferGeometry(new RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength));
  19139. _this.mergeVertices();
  19140. return _this;
  19141. }
  19142. return RingGeometry;
  19143. }(Geometry);
  19144. var ShapeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19145. _inheritsLoose(ShapeBufferGeometry, _BufferGeometry);
  19146. function ShapeBufferGeometry(shapes, curveSegments) {
  19147. var _this;
  19148. _this = _BufferGeometry.call(this) || this;
  19149. _this.type = 'ShapeBufferGeometry';
  19150. _this.parameters = {
  19151. shapes: shapes,
  19152. curveSegments: curveSegments
  19153. };
  19154. curveSegments = curveSegments || 12; // buffers
  19155. var indices = [];
  19156. var vertices = [];
  19157. var normals = [];
  19158. var uvs = []; // helper variables
  19159. var groupStart = 0;
  19160. var groupCount = 0; // allow single and array values for "shapes" parameter
  19161. if (Array.isArray(shapes) === false) {
  19162. addShape(shapes);
  19163. } else {
  19164. for (var i = 0; i < shapes.length; i++) {
  19165. addShape(shapes[i]);
  19166. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  19167. groupStart += groupCount;
  19168. groupCount = 0;
  19169. }
  19170. } // build geometry
  19171. _this.setIndex(indices);
  19172. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19173. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19174. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  19175. function addShape(shape) {
  19176. var indexOffset = vertices.length / 3;
  19177. var points = shape.extractPoints(curveSegments);
  19178. var shapeVertices = points.shape;
  19179. var shapeHoles = points.holes; // check direction of vertices
  19180. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  19181. shapeVertices = shapeVertices.reverse();
  19182. }
  19183. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  19184. var shapeHole = shapeHoles[_i];
  19185. if (ShapeUtils.isClockWise(shapeHole) === true) {
  19186. shapeHoles[_i] = shapeHole.reverse();
  19187. }
  19188. }
  19189. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  19190. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  19191. var _shapeHole = shapeHoles[_i2];
  19192. shapeVertices = shapeVertices.concat(_shapeHole);
  19193. } // vertices, normals, uvs
  19194. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  19195. var vertex = shapeVertices[_i3];
  19196. vertices.push(vertex.x, vertex.y, 0);
  19197. normals.push(0, 0, 1);
  19198. uvs.push(vertex.x, vertex.y); // world uvs
  19199. } // incides
  19200. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  19201. var face = faces[_i4];
  19202. var a = face[0] + indexOffset;
  19203. var b = face[1] + indexOffset;
  19204. var c = face[2] + indexOffset;
  19205. indices.push(a, b, c);
  19206. groupCount += 3;
  19207. }
  19208. }
  19209. return _this;
  19210. }
  19211. var _proto = ShapeBufferGeometry.prototype;
  19212. _proto.toJSON = function toJSON() {
  19213. var data = BufferGeometry.prototype.toJSON.call(this);
  19214. var shapes = this.parameters.shapes;
  19215. return _toJSON$2(shapes, data);
  19216. };
  19217. return ShapeBufferGeometry;
  19218. }(BufferGeometry);
  19219. function _toJSON$2(shapes, data) {
  19220. data.shapes = [];
  19221. if (Array.isArray(shapes)) {
  19222. for (var i = 0, l = shapes.length; i < l; i++) {
  19223. var shape = shapes[i];
  19224. data.shapes.push(shape.uuid);
  19225. }
  19226. } else {
  19227. data.shapes.push(shapes.uuid);
  19228. }
  19229. return data;
  19230. }
  19231. var ShapeGeometry = /*#__PURE__*/function (_Geometry) {
  19232. _inheritsLoose(ShapeGeometry, _Geometry);
  19233. function ShapeGeometry(shapes, curveSegments) {
  19234. var _this;
  19235. _this = _Geometry.call(this) || this;
  19236. _this.type = 'ShapeGeometry';
  19237. if (typeof curveSegments === 'object') {
  19238. console.warn('THREE.ShapeGeometry: Options parameter has been removed.');
  19239. curveSegments = curveSegments.curveSegments;
  19240. }
  19241. _this.parameters = {
  19242. shapes: shapes,
  19243. curveSegments: curveSegments
  19244. };
  19245. _this.fromBufferGeometry(new ShapeBufferGeometry(shapes, curveSegments));
  19246. _this.mergeVertices();
  19247. return _this;
  19248. }
  19249. var _proto = ShapeGeometry.prototype;
  19250. _proto.toJSON = function toJSON() {
  19251. var data = Geometry.prototype.toJSON.call(this);
  19252. var shapes = this.parameters.shapes;
  19253. return _toJSON$3(shapes, data);
  19254. };
  19255. return ShapeGeometry;
  19256. }(Geometry);
  19257. function _toJSON$3(shapes, data) {
  19258. data.shapes = [];
  19259. if (Array.isArray(shapes)) {
  19260. for (var i = 0, l = shapes.length; i < l; i++) {
  19261. var shape = shapes[i];
  19262. data.shapes.push(shape.uuid);
  19263. }
  19264. } else {
  19265. data.shapes.push(shapes.uuid);
  19266. }
  19267. return data;
  19268. }
  19269. var SphereBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19270. _inheritsLoose(SphereBufferGeometry, _BufferGeometry);
  19271. function SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19272. var _this;
  19273. _this = _BufferGeometry.call(this) || this;
  19274. _this.type = 'SphereBufferGeometry';
  19275. _this.parameters = {
  19276. radius: radius,
  19277. widthSegments: widthSegments,
  19278. heightSegments: heightSegments,
  19279. phiStart: phiStart,
  19280. phiLength: phiLength,
  19281. thetaStart: thetaStart,
  19282. thetaLength: thetaLength
  19283. };
  19284. radius = radius || 1;
  19285. widthSegments = Math.max(3, Math.floor(widthSegments) || 8);
  19286. heightSegments = Math.max(2, Math.floor(heightSegments) || 6);
  19287. phiStart = phiStart !== undefined ? phiStart : 0;
  19288. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19289. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19290. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19291. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19292. var index = 0;
  19293. var grid = [];
  19294. var vertex = new Vector3();
  19295. var normal = new Vector3(); // buffers
  19296. var indices = [];
  19297. var vertices = [];
  19298. var normals = [];
  19299. var uvs = []; // generate vertices, normals and uvs
  19300. for (var iy = 0; iy <= heightSegments; iy++) {
  19301. var verticesRow = [];
  19302. var v = iy / heightSegments; // special case for the poles
  19303. var uOffset = 0;
  19304. if (iy == 0 && thetaStart == 0) {
  19305. uOffset = 0.5 / widthSegments;
  19306. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19307. uOffset = -0.5 / widthSegments;
  19308. }
  19309. for (var ix = 0; ix <= widthSegments; ix++) {
  19310. var u = ix / widthSegments; // vertex
  19311. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19312. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19313. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19314. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19315. normal.copy(vertex).normalize();
  19316. normals.push(normal.x, normal.y, normal.z); // uv
  19317. uvs.push(u + uOffset, 1 - v);
  19318. verticesRow.push(index++);
  19319. }
  19320. grid.push(verticesRow);
  19321. } // indices
  19322. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19323. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19324. var a = grid[_iy][_ix + 1];
  19325. var b = grid[_iy][_ix];
  19326. var c = grid[_iy + 1][_ix];
  19327. var d = grid[_iy + 1][_ix + 1];
  19328. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19329. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19330. }
  19331. } // build geometry
  19332. _this.setIndex(indices);
  19333. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19334. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19335. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19336. return _this;
  19337. }
  19338. return SphereBufferGeometry;
  19339. }(BufferGeometry);
  19340. var SphereGeometry = /*#__PURE__*/function (_Geometry) {
  19341. _inheritsLoose(SphereGeometry, _Geometry);
  19342. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19343. var _this;
  19344. _this = _Geometry.call(this) || this;
  19345. _this.type = 'SphereGeometry';
  19346. _this.parameters = {
  19347. radius: radius,
  19348. widthSegments: widthSegments,
  19349. heightSegments: heightSegments,
  19350. phiStart: phiStart,
  19351. phiLength: phiLength,
  19352. thetaStart: thetaStart,
  19353. thetaLength: thetaLength
  19354. };
  19355. _this.fromBufferGeometry(new SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength));
  19356. _this.mergeVertices();
  19357. return _this;
  19358. }
  19359. return SphereGeometry;
  19360. }(Geometry);
  19361. var TetrahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  19362. _inheritsLoose(TetrahedronBufferGeometry, _PolyhedronBufferGeom);
  19363. function TetrahedronBufferGeometry(radius, detail) {
  19364. var _this;
  19365. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19366. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19367. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  19368. _this.type = 'TetrahedronBufferGeometry';
  19369. _this.parameters = {
  19370. radius: radius,
  19371. detail: detail
  19372. };
  19373. return _this;
  19374. }
  19375. return TetrahedronBufferGeometry;
  19376. }(PolyhedronBufferGeometry);
  19377. var TetrahedronGeometry = /*#__PURE__*/function (_Geometry) {
  19378. _inheritsLoose(TetrahedronGeometry, _Geometry);
  19379. function TetrahedronGeometry(radius, detail) {
  19380. var _this;
  19381. _this = _Geometry.call(this) || this;
  19382. _this.type = 'TetrahedronGeometry';
  19383. _this.parameters = {
  19384. radius: radius,
  19385. detail: detail
  19386. };
  19387. _this.fromBufferGeometry(new TetrahedronBufferGeometry(radius, detail));
  19388. _this.mergeVertices();
  19389. return _this;
  19390. }
  19391. return TetrahedronGeometry;
  19392. }(Geometry);
  19393. var TextBufferGeometry = /*#__PURE__*/function (_ExtrudeBufferGeometr) {
  19394. _inheritsLoose(TextBufferGeometry, _ExtrudeBufferGeometr);
  19395. function TextBufferGeometry(text, parameters) {
  19396. var _this;
  19397. parameters = parameters || {};
  19398. var font = parameters.font;
  19399. if (!(font && font.isFont)) {
  19400. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19401. return new BufferGeometry() || _assertThisInitialized(_this);
  19402. }
  19403. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19404. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19405. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19406. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19407. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19408. _this = _ExtrudeBufferGeometr.call(this, shapes, parameters) || this;
  19409. _this.type = 'TextBufferGeometry';
  19410. return _this;
  19411. }
  19412. return TextBufferGeometry;
  19413. }(ExtrudeBufferGeometry);
  19414. var TextGeometry = /*#__PURE__*/function (_Geometry) {
  19415. _inheritsLoose(TextGeometry, _Geometry);
  19416. function TextGeometry(text, parameters) {
  19417. var _this;
  19418. _this = _Geometry.call(this) || this;
  19419. _this.type = 'TextGeometry';
  19420. _this.parameters = {
  19421. text: text,
  19422. parameters: parameters
  19423. };
  19424. _this.fromBufferGeometry(new TextBufferGeometry(text, parameters));
  19425. _this.mergeVertices();
  19426. return _this;
  19427. }
  19428. return TextGeometry;
  19429. }(Geometry);
  19430. var TorusBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19431. _inheritsLoose(TorusBufferGeometry, _BufferGeometry);
  19432. function TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19433. var _this;
  19434. _this = _BufferGeometry.call(this) || this;
  19435. _this.type = 'TorusBufferGeometry';
  19436. _this.parameters = {
  19437. radius: radius,
  19438. tube: tube,
  19439. radialSegments: radialSegments,
  19440. tubularSegments: tubularSegments,
  19441. arc: arc
  19442. };
  19443. radius = radius || 1;
  19444. tube = tube || 0.4;
  19445. radialSegments = Math.floor(radialSegments) || 8;
  19446. tubularSegments = Math.floor(tubularSegments) || 6;
  19447. arc = arc || Math.PI * 2; // buffers
  19448. var indices = [];
  19449. var vertices = [];
  19450. var normals = [];
  19451. var uvs = []; // helper variables
  19452. var center = new Vector3();
  19453. var vertex = new Vector3();
  19454. var normal = new Vector3(); // generate vertices, normals and uvs
  19455. for (var j = 0; j <= radialSegments; j++) {
  19456. for (var i = 0; i <= tubularSegments; i++) {
  19457. var u = i / tubularSegments * arc;
  19458. var v = j / radialSegments * Math.PI * 2; // vertex
  19459. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19460. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19461. vertex.z = tube * Math.sin(v);
  19462. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19463. center.x = radius * Math.cos(u);
  19464. center.y = radius * Math.sin(u);
  19465. normal.subVectors(vertex, center).normalize();
  19466. normals.push(normal.x, normal.y, normal.z); // uv
  19467. uvs.push(i / tubularSegments);
  19468. uvs.push(j / radialSegments);
  19469. }
  19470. } // generate indices
  19471. for (var _j = 1; _j <= radialSegments; _j++) {
  19472. for (var _i = 1; _i <= tubularSegments; _i++) {
  19473. // indices
  19474. var a = (tubularSegments + 1) * _j + _i - 1;
  19475. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19476. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19477. var d = (tubularSegments + 1) * _j + _i; // faces
  19478. indices.push(a, b, d);
  19479. indices.push(b, c, d);
  19480. }
  19481. } // build geometry
  19482. _this.setIndex(indices);
  19483. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19484. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19485. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19486. return _this;
  19487. }
  19488. return TorusBufferGeometry;
  19489. }(BufferGeometry);
  19490. var TorusGeometry = /*#__PURE__*/function (_Geometry) {
  19491. _inheritsLoose(TorusGeometry, _Geometry);
  19492. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19493. var _this;
  19494. _this = _Geometry.call(this) || this;
  19495. _this.type = 'TorusGeometry';
  19496. _this.parameters = {
  19497. radius: radius,
  19498. tube: tube,
  19499. radialSegments: radialSegments,
  19500. tubularSegments: tubularSegments,
  19501. arc: arc
  19502. };
  19503. _this.fromBufferGeometry(new TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc));
  19504. _this.mergeVertices();
  19505. return _this;
  19506. }
  19507. return TorusGeometry;
  19508. }(Geometry);
  19509. var TorusKnotBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19510. _inheritsLoose(TorusKnotBufferGeometry, _BufferGeometry);
  19511. function TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19512. var _this;
  19513. _this = _BufferGeometry.call(this) || this;
  19514. _this.type = 'TorusKnotBufferGeometry';
  19515. _this.parameters = {
  19516. radius: radius,
  19517. tube: tube,
  19518. tubularSegments: tubularSegments,
  19519. radialSegments: radialSegments,
  19520. p: p,
  19521. q: q
  19522. };
  19523. radius = radius || 1;
  19524. tube = tube || 0.4;
  19525. tubularSegments = Math.floor(tubularSegments) || 64;
  19526. radialSegments = Math.floor(radialSegments) || 8;
  19527. p = p || 2;
  19528. q = q || 3; // buffers
  19529. var indices = [];
  19530. var vertices = [];
  19531. var normals = [];
  19532. var uvs = []; // helper variables
  19533. var vertex = new Vector3();
  19534. var normal = new Vector3();
  19535. var P1 = new Vector3();
  19536. var P2 = new Vector3();
  19537. var B = new Vector3();
  19538. var T = new Vector3();
  19539. var N = new Vector3(); // generate vertices, normals and uvs
  19540. for (var i = 0; i <= tubularSegments; ++i) {
  19541. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19542. 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.
  19543. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19544. calculatePositionOnCurve(u, p, q, radius, P1);
  19545. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19546. T.subVectors(P2, P1);
  19547. N.addVectors(P2, P1);
  19548. B.crossVectors(T, N);
  19549. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19550. B.normalize();
  19551. N.normalize();
  19552. for (var j = 0; j <= radialSegments; ++j) {
  19553. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19554. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19555. var v = j / radialSegments * Math.PI * 2;
  19556. var cx = -tube * Math.cos(v);
  19557. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19558. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19559. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19560. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19561. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19562. 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)
  19563. normal.subVectors(vertex, P1).normalize();
  19564. normals.push(normal.x, normal.y, normal.z); // uv
  19565. uvs.push(i / tubularSegments);
  19566. uvs.push(j / radialSegments);
  19567. }
  19568. } // generate indices
  19569. for (var _j = 1; _j <= tubularSegments; _j++) {
  19570. for (var _i = 1; _i <= radialSegments; _i++) {
  19571. // indices
  19572. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19573. var b = (radialSegments + 1) * _j + (_i - 1);
  19574. var c = (radialSegments + 1) * _j + _i;
  19575. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19576. indices.push(a, b, d);
  19577. indices.push(b, c, d);
  19578. }
  19579. } // build geometry
  19580. _this.setIndex(indices);
  19581. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19582. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19583. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19584. function calculatePositionOnCurve(u, p, q, radius, position) {
  19585. var cu = Math.cos(u);
  19586. var su = Math.sin(u);
  19587. var quOverP = q / p * u;
  19588. var cs = Math.cos(quOverP);
  19589. position.x = radius * (2 + cs) * 0.5 * cu;
  19590. position.y = radius * (2 + cs) * su * 0.5;
  19591. position.z = radius * Math.sin(quOverP) * 0.5;
  19592. }
  19593. return _this;
  19594. }
  19595. return TorusKnotBufferGeometry;
  19596. }(BufferGeometry);
  19597. var TorusKnotGeometry = /*#__PURE__*/function (_Geometry) {
  19598. _inheritsLoose(TorusKnotGeometry, _Geometry);
  19599. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q, heightScale) {
  19600. var _this;
  19601. _this = _Geometry.call(this) || this;
  19602. _this.type = 'TorusKnotGeometry';
  19603. _this.parameters = {
  19604. radius: radius,
  19605. tube: tube,
  19606. tubularSegments: tubularSegments,
  19607. radialSegments: radialSegments,
  19608. p: p,
  19609. q: q
  19610. };
  19611. if (heightScale !== undefined) console.warn('THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.');
  19612. _this.fromBufferGeometry(new TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q));
  19613. _this.mergeVertices();
  19614. return _this;
  19615. }
  19616. return TorusKnotGeometry;
  19617. }(Geometry);
  19618. var TubeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19619. _inheritsLoose(TubeBufferGeometry, _BufferGeometry);
  19620. function TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19621. var _this;
  19622. _this = _BufferGeometry.call(this) || this;
  19623. _this.type = 'TubeBufferGeometry';
  19624. _this.parameters = {
  19625. path: path,
  19626. tubularSegments: tubularSegments,
  19627. radius: radius,
  19628. radialSegments: radialSegments,
  19629. closed: closed
  19630. };
  19631. tubularSegments = tubularSegments || 64;
  19632. radius = radius || 1;
  19633. radialSegments = radialSegments || 8;
  19634. closed = closed || false;
  19635. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19636. _this.tangents = frames.tangents;
  19637. _this.normals = frames.normals;
  19638. _this.binormals = frames.binormals; // helper variables
  19639. var vertex = new Vector3();
  19640. var normal = new Vector3();
  19641. var uv = new Vector2();
  19642. var P = new Vector3(); // buffer
  19643. var vertices = [];
  19644. var normals = [];
  19645. var uvs = [];
  19646. var indices = []; // create buffer data
  19647. generateBufferData(); // build geometry
  19648. _this.setIndex(indices);
  19649. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19650. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19651. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19652. function generateBufferData() {
  19653. for (var i = 0; i < tubularSegments; i++) {
  19654. generateSegment(i);
  19655. } // if the geometry is not closed, generate the last row of vertices and normals
  19656. // at the regular position on the given path
  19657. //
  19658. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19659. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19660. // this makes it easy compute correct values for closed geometries
  19661. generateUVs(); // finally create faces
  19662. generateIndices();
  19663. }
  19664. function generateSegment(i) {
  19665. // we use getPointAt to sample evenly distributed points from the given path
  19666. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19667. var N = frames.normals[i];
  19668. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19669. for (var j = 0; j <= radialSegments; j++) {
  19670. var v = j / radialSegments * Math.PI * 2;
  19671. var sin = Math.sin(v);
  19672. var cos = -Math.cos(v); // normal
  19673. normal.x = cos * N.x + sin * B.x;
  19674. normal.y = cos * N.y + sin * B.y;
  19675. normal.z = cos * N.z + sin * B.z;
  19676. normal.normalize();
  19677. normals.push(normal.x, normal.y, normal.z); // vertex
  19678. vertex.x = P.x + radius * normal.x;
  19679. vertex.y = P.y + radius * normal.y;
  19680. vertex.z = P.z + radius * normal.z;
  19681. vertices.push(vertex.x, vertex.y, vertex.z);
  19682. }
  19683. }
  19684. function generateIndices() {
  19685. for (var j = 1; j <= tubularSegments; j++) {
  19686. for (var i = 1; i <= radialSegments; i++) {
  19687. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  19688. var b = (radialSegments + 1) * j + (i - 1);
  19689. var c = (radialSegments + 1) * j + i;
  19690. var d = (radialSegments + 1) * (j - 1) + i; // faces
  19691. indices.push(a, b, d);
  19692. indices.push(b, c, d);
  19693. }
  19694. }
  19695. }
  19696. function generateUVs() {
  19697. for (var i = 0; i <= tubularSegments; i++) {
  19698. for (var j = 0; j <= radialSegments; j++) {
  19699. uv.x = i / tubularSegments;
  19700. uv.y = j / radialSegments;
  19701. uvs.push(uv.x, uv.y);
  19702. }
  19703. }
  19704. }
  19705. return _this;
  19706. }
  19707. var _proto = TubeBufferGeometry.prototype;
  19708. _proto.toJSON = function toJSON() {
  19709. var data = BufferGeometry.prototype.toJSON.call(this);
  19710. data.path = this.parameters.path.toJSON();
  19711. return data;
  19712. };
  19713. return TubeBufferGeometry;
  19714. }(BufferGeometry);
  19715. var TubeGeometry = /*#__PURE__*/function (_Geometry) {
  19716. _inheritsLoose(TubeGeometry, _Geometry);
  19717. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed, taper) {
  19718. var _this;
  19719. _this = _Geometry.call(this) || this;
  19720. _this.type = 'TubeGeometry';
  19721. _this.parameters = {
  19722. path: path,
  19723. tubularSegments: tubularSegments,
  19724. radius: radius,
  19725. radialSegments: radialSegments,
  19726. closed: closed
  19727. };
  19728. if (taper !== undefined) console.warn('THREE.TubeGeometry: taper has been removed.');
  19729. var bufferGeometry = new TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed); // expose internals
  19730. _this.tangents = bufferGeometry.tangents;
  19731. _this.normals = bufferGeometry.normals;
  19732. _this.binormals = bufferGeometry.binormals; // create geometry
  19733. _this.fromBufferGeometry(bufferGeometry);
  19734. _this.mergeVertices();
  19735. return _this;
  19736. }
  19737. return TubeGeometry;
  19738. }(Geometry);
  19739. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19740. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  19741. function WireframeGeometry(geometry) {
  19742. var _this;
  19743. _this = _BufferGeometry.call(this) || this;
  19744. _this.type = 'WireframeGeometry'; // buffer
  19745. var vertices = []; // helper variables
  19746. var edge = [0, 0],
  19747. edges = {};
  19748. var keys = ['a', 'b', 'c']; // different logic for Geometry and BufferGeometry
  19749. if (geometry && geometry.isGeometry) {
  19750. // create a data structure that contains all edges without duplicates
  19751. var faces = geometry.faces;
  19752. for (var i = 0, l = faces.length; i < l; i++) {
  19753. var face = faces[i];
  19754. for (var j = 0; j < 3; j++) {
  19755. var edge1 = face[keys[j]];
  19756. var edge2 = face[keys[(j + 1) % 3]];
  19757. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  19758. edge[1] = Math.max(edge1, edge2);
  19759. var key = edge[0] + ',' + edge[1];
  19760. if (edges[key] === undefined) {
  19761. edges[key] = {
  19762. index1: edge[0],
  19763. index2: edge[1]
  19764. };
  19765. }
  19766. }
  19767. } // generate vertices
  19768. for (var _key in edges) {
  19769. var e = edges[_key];
  19770. var vertex = geometry.vertices[e.index1];
  19771. vertices.push(vertex.x, vertex.y, vertex.z);
  19772. vertex = geometry.vertices[e.index2];
  19773. vertices.push(vertex.x, vertex.y, vertex.z);
  19774. }
  19775. } else if (geometry && geometry.isBufferGeometry) {
  19776. var _vertex = new Vector3();
  19777. if (geometry.index !== null) {
  19778. // indexed BufferGeometry
  19779. var position = geometry.attributes.position;
  19780. var indices = geometry.index;
  19781. var groups = geometry.groups;
  19782. if (groups.length === 0) {
  19783. groups = [{
  19784. start: 0,
  19785. count: indices.count,
  19786. materialIndex: 0
  19787. }];
  19788. } // create a data structure that contains all eges without duplicates
  19789. for (var o = 0, ol = groups.length; o < ol; ++o) {
  19790. var group = groups[o];
  19791. var start = group.start;
  19792. var count = group.count;
  19793. for (var _i = start, _l = start + count; _i < _l; _i += 3) {
  19794. for (var _j = 0; _j < 3; _j++) {
  19795. var _edge = indices.getX(_i + _j);
  19796. var _edge2 = indices.getX(_i + (_j + 1) % 3);
  19797. edge[0] = Math.min(_edge, _edge2); // sorting prevents duplicates
  19798. edge[1] = Math.max(_edge, _edge2);
  19799. var _key2 = edge[0] + ',' + edge[1];
  19800. if (edges[_key2] === undefined) {
  19801. edges[_key2] = {
  19802. index1: edge[0],
  19803. index2: edge[1]
  19804. };
  19805. }
  19806. }
  19807. }
  19808. } // generate vertices
  19809. for (var _key3 in edges) {
  19810. var _e = edges[_key3];
  19811. _vertex.fromBufferAttribute(position, _e.index1);
  19812. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19813. _vertex.fromBufferAttribute(position, _e.index2);
  19814. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19815. }
  19816. } else {
  19817. // non-indexed BufferGeometry
  19818. var _position = geometry.attributes.position;
  19819. for (var _i2 = 0, _l2 = _position.count / 3; _i2 < _l2; _i2++) {
  19820. for (var _j2 = 0; _j2 < 3; _j2++) {
  19821. // three edges per triangle, an edge is represented as (index1, index2)
  19822. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  19823. var index1 = 3 * _i2 + _j2;
  19824. _vertex.fromBufferAttribute(_position, index1);
  19825. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19826. var index2 = 3 * _i2 + (_j2 + 1) % 3;
  19827. _vertex.fromBufferAttribute(_position, index2);
  19828. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19829. }
  19830. }
  19831. }
  19832. } // build geometry
  19833. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19834. return _this;
  19835. }
  19836. return WireframeGeometry;
  19837. }(BufferGeometry);
  19838. var Geometries = /*#__PURE__*/Object.freeze({
  19839. __proto__: null,
  19840. BoxGeometry: BoxGeometry,
  19841. BoxBufferGeometry: BoxBufferGeometry,
  19842. CircleGeometry: CircleGeometry,
  19843. CircleBufferGeometry: CircleBufferGeometry,
  19844. ConeGeometry: ConeGeometry,
  19845. ConeBufferGeometry: ConeBufferGeometry,
  19846. CylinderGeometry: CylinderGeometry,
  19847. CylinderBufferGeometry: CylinderBufferGeometry,
  19848. DodecahedronGeometry: DodecahedronGeometry,
  19849. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  19850. EdgesGeometry: EdgesGeometry,
  19851. ExtrudeGeometry: ExtrudeGeometry,
  19852. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  19853. IcosahedronGeometry: IcosahedronGeometry,
  19854. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  19855. LatheGeometry: LatheGeometry,
  19856. LatheBufferGeometry: LatheBufferGeometry,
  19857. OctahedronGeometry: OctahedronGeometry,
  19858. OctahedronBufferGeometry: OctahedronBufferGeometry,
  19859. ParametricGeometry: ParametricGeometry,
  19860. ParametricBufferGeometry: ParametricBufferGeometry,
  19861. PlaneGeometry: PlaneGeometry,
  19862. PlaneBufferGeometry: PlaneBufferGeometry,
  19863. PolyhedronGeometry: PolyhedronGeometry,
  19864. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  19865. RingGeometry: RingGeometry,
  19866. RingBufferGeometry: RingBufferGeometry,
  19867. ShapeGeometry: ShapeGeometry,
  19868. ShapeBufferGeometry: ShapeBufferGeometry,
  19869. SphereGeometry: SphereGeometry,
  19870. SphereBufferGeometry: SphereBufferGeometry,
  19871. TetrahedronGeometry: TetrahedronGeometry,
  19872. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  19873. TextGeometry: TextGeometry,
  19874. TextBufferGeometry: TextBufferGeometry,
  19875. TorusGeometry: TorusGeometry,
  19876. TorusBufferGeometry: TorusBufferGeometry,
  19877. TorusKnotGeometry: TorusKnotGeometry,
  19878. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  19879. TubeGeometry: TubeGeometry,
  19880. TubeBufferGeometry: TubeBufferGeometry,
  19881. WireframeGeometry: WireframeGeometry
  19882. });
  19883. /**
  19884. * parameters = {
  19885. * color: <THREE.Color>
  19886. * }
  19887. */
  19888. function ShadowMaterial(parameters) {
  19889. Material.call(this);
  19890. this.type = 'ShadowMaterial';
  19891. this.color = new Color(0x000000);
  19892. this.transparent = true;
  19893. this.setValues(parameters);
  19894. }
  19895. ShadowMaterial.prototype = Object.create(Material.prototype);
  19896. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19897. ShadowMaterial.prototype.isShadowMaterial = true;
  19898. ShadowMaterial.prototype.copy = function (source) {
  19899. Material.prototype.copy.call(this, source);
  19900. this.color.copy(source.color);
  19901. return this;
  19902. };
  19903. function RawShaderMaterial(parameters) {
  19904. ShaderMaterial.call(this, parameters);
  19905. this.type = 'RawShaderMaterial';
  19906. }
  19907. RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
  19908. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19909. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19910. /**
  19911. * parameters = {
  19912. * color: <hex>,
  19913. * roughness: <float>,
  19914. * metalness: <float>,
  19915. * opacity: <float>,
  19916. *
  19917. * map: new THREE.Texture( <Image> ),
  19918. *
  19919. * lightMap: new THREE.Texture( <Image> ),
  19920. * lightMapIntensity: <float>
  19921. *
  19922. * aoMap: new THREE.Texture( <Image> ),
  19923. * aoMapIntensity: <float>
  19924. *
  19925. * emissive: <hex>,
  19926. * emissiveIntensity: <float>
  19927. * emissiveMap: new THREE.Texture( <Image> ),
  19928. *
  19929. * bumpMap: new THREE.Texture( <Image> ),
  19930. * bumpScale: <float>,
  19931. *
  19932. * normalMap: new THREE.Texture( <Image> ),
  19933. * normalMapType: THREE.TangentSpaceNormalMap,
  19934. * normalScale: <Vector2>,
  19935. *
  19936. * displacementMap: new THREE.Texture( <Image> ),
  19937. * displacementScale: <float>,
  19938. * displacementBias: <float>,
  19939. *
  19940. * roughnessMap: new THREE.Texture( <Image> ),
  19941. *
  19942. * metalnessMap: new THREE.Texture( <Image> ),
  19943. *
  19944. * alphaMap: new THREE.Texture( <Image> ),
  19945. *
  19946. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19947. * envMapIntensity: <float>
  19948. *
  19949. * refractionRatio: <float>,
  19950. *
  19951. * wireframe: <boolean>,
  19952. * wireframeLinewidth: <float>,
  19953. *
  19954. * skinning: <bool>,
  19955. * morphTargets: <bool>,
  19956. * morphNormals: <bool>
  19957. * }
  19958. */
  19959. function MeshStandardMaterial(parameters) {
  19960. Material.call(this);
  19961. this.defines = {
  19962. 'STANDARD': ''
  19963. };
  19964. this.type = 'MeshStandardMaterial';
  19965. this.color = new Color(0xffffff); // diffuse
  19966. this.roughness = 1.0;
  19967. this.metalness = 0.0;
  19968. this.map = null;
  19969. this.lightMap = null;
  19970. this.lightMapIntensity = 1.0;
  19971. this.aoMap = null;
  19972. this.aoMapIntensity = 1.0;
  19973. this.emissive = new Color(0x000000);
  19974. this.emissiveIntensity = 1.0;
  19975. this.emissiveMap = null;
  19976. this.bumpMap = null;
  19977. this.bumpScale = 1;
  19978. this.normalMap = null;
  19979. this.normalMapType = TangentSpaceNormalMap;
  19980. this.normalScale = new Vector2(1, 1);
  19981. this.displacementMap = null;
  19982. this.displacementScale = 1;
  19983. this.displacementBias = 0;
  19984. this.roughnessMap = null;
  19985. this.metalnessMap = null;
  19986. this.alphaMap = null;
  19987. this.envMap = null;
  19988. this.envMapIntensity = 1.0;
  19989. this.refractionRatio = 0.98;
  19990. this.wireframe = false;
  19991. this.wireframeLinewidth = 1;
  19992. this.wireframeLinecap = 'round';
  19993. this.wireframeLinejoin = 'round';
  19994. this.skinning = false;
  19995. this.morphTargets = false;
  19996. this.morphNormals = false;
  19997. this.vertexTangents = false;
  19998. this.setValues(parameters);
  19999. }
  20000. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  20001. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  20002. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  20003. MeshStandardMaterial.prototype.copy = function (source) {
  20004. Material.prototype.copy.call(this, source);
  20005. this.defines = {
  20006. 'STANDARD': ''
  20007. };
  20008. this.color.copy(source.color);
  20009. this.roughness = source.roughness;
  20010. this.metalness = source.metalness;
  20011. this.map = source.map;
  20012. this.lightMap = source.lightMap;
  20013. this.lightMapIntensity = source.lightMapIntensity;
  20014. this.aoMap = source.aoMap;
  20015. this.aoMapIntensity = source.aoMapIntensity;
  20016. this.emissive.copy(source.emissive);
  20017. this.emissiveMap = source.emissiveMap;
  20018. this.emissiveIntensity = source.emissiveIntensity;
  20019. this.bumpMap = source.bumpMap;
  20020. this.bumpScale = source.bumpScale;
  20021. this.normalMap = source.normalMap;
  20022. this.normalMapType = source.normalMapType;
  20023. this.normalScale.copy(source.normalScale);
  20024. this.displacementMap = source.displacementMap;
  20025. this.displacementScale = source.displacementScale;
  20026. this.displacementBias = source.displacementBias;
  20027. this.roughnessMap = source.roughnessMap;
  20028. this.metalnessMap = source.metalnessMap;
  20029. this.alphaMap = source.alphaMap;
  20030. this.envMap = source.envMap;
  20031. this.envMapIntensity = source.envMapIntensity;
  20032. this.refractionRatio = source.refractionRatio;
  20033. this.wireframe = source.wireframe;
  20034. this.wireframeLinewidth = source.wireframeLinewidth;
  20035. this.wireframeLinecap = source.wireframeLinecap;
  20036. this.wireframeLinejoin = source.wireframeLinejoin;
  20037. this.skinning = source.skinning;
  20038. this.morphTargets = source.morphTargets;
  20039. this.morphNormals = source.morphNormals;
  20040. this.vertexTangents = source.vertexTangents;
  20041. return this;
  20042. };
  20043. /**
  20044. * parameters = {
  20045. * clearcoat: <float>,
  20046. * clearcoatMap: new THREE.Texture( <Image> ),
  20047. * clearcoatRoughness: <float>,
  20048. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  20049. * clearcoatNormalScale: <Vector2>,
  20050. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  20051. *
  20052. * reflectivity: <float>,
  20053. * ior: <float>,
  20054. *
  20055. * sheen: <Color>,
  20056. *
  20057. * transmission: <float>,
  20058. * transmissionMap: new THREE.Texture( <Image> )
  20059. * }
  20060. */
  20061. function MeshPhysicalMaterial(parameters) {
  20062. MeshStandardMaterial.call(this);
  20063. this.defines = {
  20064. 'STANDARD': '',
  20065. 'PHYSICAL': ''
  20066. };
  20067. this.type = 'MeshPhysicalMaterial';
  20068. this.clearcoat = 0.0;
  20069. this.clearcoatMap = null;
  20070. this.clearcoatRoughness = 0.0;
  20071. this.clearcoatRoughnessMap = null;
  20072. this.clearcoatNormalScale = new Vector2(1, 1);
  20073. this.clearcoatNormalMap = null;
  20074. this.reflectivity = 0.5; // maps to F0 = 0.04
  20075. Object.defineProperty(this, 'ior', {
  20076. get: function get() {
  20077. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  20078. },
  20079. set: function set(ior) {
  20080. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  20081. }
  20082. });
  20083. this.sheen = null; // null will disable sheen bsdf
  20084. this.transmission = 0.0;
  20085. this.transmissionMap = null;
  20086. this.setValues(parameters);
  20087. }
  20088. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  20089. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  20090. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  20091. MeshPhysicalMaterial.prototype.copy = function (source) {
  20092. MeshStandardMaterial.prototype.copy.call(this, source);
  20093. this.defines = {
  20094. 'STANDARD': '',
  20095. 'PHYSICAL': ''
  20096. };
  20097. this.clearcoat = source.clearcoat;
  20098. this.clearcoatMap = source.clearcoatMap;
  20099. this.clearcoatRoughness = source.clearcoatRoughness;
  20100. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  20101. this.clearcoatNormalMap = source.clearcoatNormalMap;
  20102. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  20103. this.reflectivity = source.reflectivity;
  20104. if (source.sheen) {
  20105. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  20106. } else {
  20107. this.sheen = null;
  20108. }
  20109. this.transmission = source.transmission;
  20110. this.transmissionMap = source.transmissionMap;
  20111. return this;
  20112. };
  20113. /**
  20114. * parameters = {
  20115. * color: <hex>,
  20116. * specular: <hex>,
  20117. * shininess: <float>,
  20118. * opacity: <float>,
  20119. *
  20120. * map: new THREE.Texture( <Image> ),
  20121. *
  20122. * lightMap: new THREE.Texture( <Image> ),
  20123. * lightMapIntensity: <float>
  20124. *
  20125. * aoMap: new THREE.Texture( <Image> ),
  20126. * aoMapIntensity: <float>
  20127. *
  20128. * emissive: <hex>,
  20129. * emissiveIntensity: <float>
  20130. * emissiveMap: new THREE.Texture( <Image> ),
  20131. *
  20132. * bumpMap: new THREE.Texture( <Image> ),
  20133. * bumpScale: <float>,
  20134. *
  20135. * normalMap: new THREE.Texture( <Image> ),
  20136. * normalMapType: THREE.TangentSpaceNormalMap,
  20137. * normalScale: <Vector2>,
  20138. *
  20139. * displacementMap: new THREE.Texture( <Image> ),
  20140. * displacementScale: <float>,
  20141. * displacementBias: <float>,
  20142. *
  20143. * specularMap: new THREE.Texture( <Image> ),
  20144. *
  20145. * alphaMap: new THREE.Texture( <Image> ),
  20146. *
  20147. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20148. * combine: THREE.MultiplyOperation,
  20149. * reflectivity: <float>,
  20150. * refractionRatio: <float>,
  20151. *
  20152. * wireframe: <boolean>,
  20153. * wireframeLinewidth: <float>,
  20154. *
  20155. * skinning: <bool>,
  20156. * morphTargets: <bool>,
  20157. * morphNormals: <bool>
  20158. * }
  20159. */
  20160. function MeshPhongMaterial(parameters) {
  20161. Material.call(this);
  20162. this.type = 'MeshPhongMaterial';
  20163. this.color = new Color(0xffffff); // diffuse
  20164. this.specular = new Color(0x111111);
  20165. this.shininess = 30;
  20166. this.map = null;
  20167. this.lightMap = null;
  20168. this.lightMapIntensity = 1.0;
  20169. this.aoMap = null;
  20170. this.aoMapIntensity = 1.0;
  20171. this.emissive = new Color(0x000000);
  20172. this.emissiveIntensity = 1.0;
  20173. this.emissiveMap = null;
  20174. this.bumpMap = null;
  20175. this.bumpScale = 1;
  20176. this.normalMap = null;
  20177. this.normalMapType = TangentSpaceNormalMap;
  20178. this.normalScale = new Vector2(1, 1);
  20179. this.displacementMap = null;
  20180. this.displacementScale = 1;
  20181. this.displacementBias = 0;
  20182. this.specularMap = null;
  20183. this.alphaMap = null;
  20184. this.envMap = null;
  20185. this.combine = MultiplyOperation;
  20186. this.reflectivity = 1;
  20187. this.refractionRatio = 0.98;
  20188. this.wireframe = false;
  20189. this.wireframeLinewidth = 1;
  20190. this.wireframeLinecap = 'round';
  20191. this.wireframeLinejoin = 'round';
  20192. this.skinning = false;
  20193. this.morphTargets = false;
  20194. this.morphNormals = false;
  20195. this.setValues(parameters);
  20196. }
  20197. MeshPhongMaterial.prototype = Object.create(Material.prototype);
  20198. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  20199. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  20200. MeshPhongMaterial.prototype.copy = function (source) {
  20201. Material.prototype.copy.call(this, source);
  20202. this.color.copy(source.color);
  20203. this.specular.copy(source.specular);
  20204. this.shininess = source.shininess;
  20205. this.map = source.map;
  20206. this.lightMap = source.lightMap;
  20207. this.lightMapIntensity = source.lightMapIntensity;
  20208. this.aoMap = source.aoMap;
  20209. this.aoMapIntensity = source.aoMapIntensity;
  20210. this.emissive.copy(source.emissive);
  20211. this.emissiveMap = source.emissiveMap;
  20212. this.emissiveIntensity = source.emissiveIntensity;
  20213. this.bumpMap = source.bumpMap;
  20214. this.bumpScale = source.bumpScale;
  20215. this.normalMap = source.normalMap;
  20216. this.normalMapType = source.normalMapType;
  20217. this.normalScale.copy(source.normalScale);
  20218. this.displacementMap = source.displacementMap;
  20219. this.displacementScale = source.displacementScale;
  20220. this.displacementBias = source.displacementBias;
  20221. this.specularMap = source.specularMap;
  20222. this.alphaMap = source.alphaMap;
  20223. this.envMap = source.envMap;
  20224. this.combine = source.combine;
  20225. this.reflectivity = source.reflectivity;
  20226. this.refractionRatio = source.refractionRatio;
  20227. this.wireframe = source.wireframe;
  20228. this.wireframeLinewidth = source.wireframeLinewidth;
  20229. this.wireframeLinecap = source.wireframeLinecap;
  20230. this.wireframeLinejoin = source.wireframeLinejoin;
  20231. this.skinning = source.skinning;
  20232. this.morphTargets = source.morphTargets;
  20233. this.morphNormals = source.morphNormals;
  20234. return this;
  20235. };
  20236. /**
  20237. * parameters = {
  20238. * color: <hex>,
  20239. *
  20240. * map: new THREE.Texture( <Image> ),
  20241. * gradientMap: new THREE.Texture( <Image> ),
  20242. *
  20243. * lightMap: new THREE.Texture( <Image> ),
  20244. * lightMapIntensity: <float>
  20245. *
  20246. * aoMap: new THREE.Texture( <Image> ),
  20247. * aoMapIntensity: <float>
  20248. *
  20249. * emissive: <hex>,
  20250. * emissiveIntensity: <float>
  20251. * emissiveMap: new THREE.Texture( <Image> ),
  20252. *
  20253. * bumpMap: new THREE.Texture( <Image> ),
  20254. * bumpScale: <float>,
  20255. *
  20256. * normalMap: new THREE.Texture( <Image> ),
  20257. * normalMapType: THREE.TangentSpaceNormalMap,
  20258. * normalScale: <Vector2>,
  20259. *
  20260. * displacementMap: new THREE.Texture( <Image> ),
  20261. * displacementScale: <float>,
  20262. * displacementBias: <float>,
  20263. *
  20264. * alphaMap: new THREE.Texture( <Image> ),
  20265. *
  20266. * wireframe: <boolean>,
  20267. * wireframeLinewidth: <float>,
  20268. *
  20269. * skinning: <bool>,
  20270. * morphTargets: <bool>,
  20271. * morphNormals: <bool>
  20272. * }
  20273. */
  20274. function MeshToonMaterial(parameters) {
  20275. Material.call(this);
  20276. this.defines = {
  20277. 'TOON': ''
  20278. };
  20279. this.type = 'MeshToonMaterial';
  20280. this.color = new Color(0xffffff);
  20281. this.map = null;
  20282. this.gradientMap = null;
  20283. this.lightMap = null;
  20284. this.lightMapIntensity = 1.0;
  20285. this.aoMap = null;
  20286. this.aoMapIntensity = 1.0;
  20287. this.emissive = new Color(0x000000);
  20288. this.emissiveIntensity = 1.0;
  20289. this.emissiveMap = null;
  20290. this.bumpMap = null;
  20291. this.bumpScale = 1;
  20292. this.normalMap = null;
  20293. this.normalMapType = TangentSpaceNormalMap;
  20294. this.normalScale = new Vector2(1, 1);
  20295. this.displacementMap = null;
  20296. this.displacementScale = 1;
  20297. this.displacementBias = 0;
  20298. this.alphaMap = null;
  20299. this.wireframe = false;
  20300. this.wireframeLinewidth = 1;
  20301. this.wireframeLinecap = 'round';
  20302. this.wireframeLinejoin = 'round';
  20303. this.skinning = false;
  20304. this.morphTargets = false;
  20305. this.morphNormals = false;
  20306. this.setValues(parameters);
  20307. }
  20308. MeshToonMaterial.prototype = Object.create(Material.prototype);
  20309. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  20310. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20311. MeshToonMaterial.prototype.copy = function (source) {
  20312. Material.prototype.copy.call(this, source);
  20313. this.color.copy(source.color);
  20314. this.map = source.map;
  20315. this.gradientMap = source.gradientMap;
  20316. this.lightMap = source.lightMap;
  20317. this.lightMapIntensity = source.lightMapIntensity;
  20318. this.aoMap = source.aoMap;
  20319. this.aoMapIntensity = source.aoMapIntensity;
  20320. this.emissive.copy(source.emissive);
  20321. this.emissiveMap = source.emissiveMap;
  20322. this.emissiveIntensity = source.emissiveIntensity;
  20323. this.bumpMap = source.bumpMap;
  20324. this.bumpScale = source.bumpScale;
  20325. this.normalMap = source.normalMap;
  20326. this.normalMapType = source.normalMapType;
  20327. this.normalScale.copy(source.normalScale);
  20328. this.displacementMap = source.displacementMap;
  20329. this.displacementScale = source.displacementScale;
  20330. this.displacementBias = source.displacementBias;
  20331. this.alphaMap = source.alphaMap;
  20332. this.wireframe = source.wireframe;
  20333. this.wireframeLinewidth = source.wireframeLinewidth;
  20334. this.wireframeLinecap = source.wireframeLinecap;
  20335. this.wireframeLinejoin = source.wireframeLinejoin;
  20336. this.skinning = source.skinning;
  20337. this.morphTargets = source.morphTargets;
  20338. this.morphNormals = source.morphNormals;
  20339. return this;
  20340. };
  20341. /**
  20342. * parameters = {
  20343. * opacity: <float>,
  20344. *
  20345. * bumpMap: new THREE.Texture( <Image> ),
  20346. * bumpScale: <float>,
  20347. *
  20348. * normalMap: new THREE.Texture( <Image> ),
  20349. * normalMapType: THREE.TangentSpaceNormalMap,
  20350. * normalScale: <Vector2>,
  20351. *
  20352. * displacementMap: new THREE.Texture( <Image> ),
  20353. * displacementScale: <float>,
  20354. * displacementBias: <float>,
  20355. *
  20356. * wireframe: <boolean>,
  20357. * wireframeLinewidth: <float>
  20358. *
  20359. * skinning: <bool>,
  20360. * morphTargets: <bool>,
  20361. * morphNormals: <bool>
  20362. * }
  20363. */
  20364. function MeshNormalMaterial(parameters) {
  20365. Material.call(this);
  20366. this.type = 'MeshNormalMaterial';
  20367. this.bumpMap = null;
  20368. this.bumpScale = 1;
  20369. this.normalMap = null;
  20370. this.normalMapType = TangentSpaceNormalMap;
  20371. this.normalScale = new Vector2(1, 1);
  20372. this.displacementMap = null;
  20373. this.displacementScale = 1;
  20374. this.displacementBias = 0;
  20375. this.wireframe = false;
  20376. this.wireframeLinewidth = 1;
  20377. this.fog = false;
  20378. this.skinning = false;
  20379. this.morphTargets = false;
  20380. this.morphNormals = false;
  20381. this.setValues(parameters);
  20382. }
  20383. MeshNormalMaterial.prototype = Object.create(Material.prototype);
  20384. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20385. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20386. MeshNormalMaterial.prototype.copy = function (source) {
  20387. Material.prototype.copy.call(this, source);
  20388. this.bumpMap = source.bumpMap;
  20389. this.bumpScale = source.bumpScale;
  20390. this.normalMap = source.normalMap;
  20391. this.normalMapType = source.normalMapType;
  20392. this.normalScale.copy(source.normalScale);
  20393. this.displacementMap = source.displacementMap;
  20394. this.displacementScale = source.displacementScale;
  20395. this.displacementBias = source.displacementBias;
  20396. this.wireframe = source.wireframe;
  20397. this.wireframeLinewidth = source.wireframeLinewidth;
  20398. this.skinning = source.skinning;
  20399. this.morphTargets = source.morphTargets;
  20400. this.morphNormals = source.morphNormals;
  20401. return this;
  20402. };
  20403. /**
  20404. * parameters = {
  20405. * color: <hex>,
  20406. * opacity: <float>,
  20407. *
  20408. * map: new THREE.Texture( <Image> ),
  20409. *
  20410. * lightMap: new THREE.Texture( <Image> ),
  20411. * lightMapIntensity: <float>
  20412. *
  20413. * aoMap: new THREE.Texture( <Image> ),
  20414. * aoMapIntensity: <float>
  20415. *
  20416. * emissive: <hex>,
  20417. * emissiveIntensity: <float>
  20418. * emissiveMap: new THREE.Texture( <Image> ),
  20419. *
  20420. * specularMap: new THREE.Texture( <Image> ),
  20421. *
  20422. * alphaMap: new THREE.Texture( <Image> ),
  20423. *
  20424. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20425. * combine: THREE.Multiply,
  20426. * reflectivity: <float>,
  20427. * refractionRatio: <float>,
  20428. *
  20429. * wireframe: <boolean>,
  20430. * wireframeLinewidth: <float>,
  20431. *
  20432. * skinning: <bool>,
  20433. * morphTargets: <bool>,
  20434. * morphNormals: <bool>
  20435. * }
  20436. */
  20437. function MeshLambertMaterial(parameters) {
  20438. Material.call(this);
  20439. this.type = 'MeshLambertMaterial';
  20440. this.color = new Color(0xffffff); // diffuse
  20441. this.map = null;
  20442. this.lightMap = null;
  20443. this.lightMapIntensity = 1.0;
  20444. this.aoMap = null;
  20445. this.aoMapIntensity = 1.0;
  20446. this.emissive = new Color(0x000000);
  20447. this.emissiveIntensity = 1.0;
  20448. this.emissiveMap = null;
  20449. this.specularMap = null;
  20450. this.alphaMap = null;
  20451. this.envMap = null;
  20452. this.combine = MultiplyOperation;
  20453. this.reflectivity = 1;
  20454. this.refractionRatio = 0.98;
  20455. this.wireframe = false;
  20456. this.wireframeLinewidth = 1;
  20457. this.wireframeLinecap = 'round';
  20458. this.wireframeLinejoin = 'round';
  20459. this.skinning = false;
  20460. this.morphTargets = false;
  20461. this.morphNormals = false;
  20462. this.setValues(parameters);
  20463. }
  20464. MeshLambertMaterial.prototype = Object.create(Material.prototype);
  20465. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20466. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20467. MeshLambertMaterial.prototype.copy = function (source) {
  20468. Material.prototype.copy.call(this, source);
  20469. this.color.copy(source.color);
  20470. this.map = source.map;
  20471. this.lightMap = source.lightMap;
  20472. this.lightMapIntensity = source.lightMapIntensity;
  20473. this.aoMap = source.aoMap;
  20474. this.aoMapIntensity = source.aoMapIntensity;
  20475. this.emissive.copy(source.emissive);
  20476. this.emissiveMap = source.emissiveMap;
  20477. this.emissiveIntensity = source.emissiveIntensity;
  20478. this.specularMap = source.specularMap;
  20479. this.alphaMap = source.alphaMap;
  20480. this.envMap = source.envMap;
  20481. this.combine = source.combine;
  20482. this.reflectivity = source.reflectivity;
  20483. this.refractionRatio = source.refractionRatio;
  20484. this.wireframe = source.wireframe;
  20485. this.wireframeLinewidth = source.wireframeLinewidth;
  20486. this.wireframeLinecap = source.wireframeLinecap;
  20487. this.wireframeLinejoin = source.wireframeLinejoin;
  20488. this.skinning = source.skinning;
  20489. this.morphTargets = source.morphTargets;
  20490. this.morphNormals = source.morphNormals;
  20491. return this;
  20492. };
  20493. /**
  20494. * parameters = {
  20495. * color: <hex>,
  20496. * opacity: <float>,
  20497. *
  20498. * matcap: new THREE.Texture( <Image> ),
  20499. *
  20500. * map: new THREE.Texture( <Image> ),
  20501. *
  20502. * bumpMap: new THREE.Texture( <Image> ),
  20503. * bumpScale: <float>,
  20504. *
  20505. * normalMap: new THREE.Texture( <Image> ),
  20506. * normalMapType: THREE.TangentSpaceNormalMap,
  20507. * normalScale: <Vector2>,
  20508. *
  20509. * displacementMap: new THREE.Texture( <Image> ),
  20510. * displacementScale: <float>,
  20511. * displacementBias: <float>,
  20512. *
  20513. * alphaMap: new THREE.Texture( <Image> ),
  20514. *
  20515. * skinning: <bool>,
  20516. * morphTargets: <bool>,
  20517. * morphNormals: <bool>
  20518. * }
  20519. */
  20520. function MeshMatcapMaterial(parameters) {
  20521. Material.call(this);
  20522. this.defines = {
  20523. 'MATCAP': ''
  20524. };
  20525. this.type = 'MeshMatcapMaterial';
  20526. this.color = new Color(0xffffff); // diffuse
  20527. this.matcap = null;
  20528. this.map = null;
  20529. this.bumpMap = null;
  20530. this.bumpScale = 1;
  20531. this.normalMap = null;
  20532. this.normalMapType = TangentSpaceNormalMap;
  20533. this.normalScale = new Vector2(1, 1);
  20534. this.displacementMap = null;
  20535. this.displacementScale = 1;
  20536. this.displacementBias = 0;
  20537. this.alphaMap = null;
  20538. this.skinning = false;
  20539. this.morphTargets = false;
  20540. this.morphNormals = false;
  20541. this.setValues(parameters);
  20542. }
  20543. MeshMatcapMaterial.prototype = Object.create(Material.prototype);
  20544. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20545. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20546. MeshMatcapMaterial.prototype.copy = function (source) {
  20547. Material.prototype.copy.call(this, source);
  20548. this.defines = {
  20549. 'MATCAP': ''
  20550. };
  20551. this.color.copy(source.color);
  20552. this.matcap = source.matcap;
  20553. this.map = source.map;
  20554. this.bumpMap = source.bumpMap;
  20555. this.bumpScale = source.bumpScale;
  20556. this.normalMap = source.normalMap;
  20557. this.normalMapType = source.normalMapType;
  20558. this.normalScale.copy(source.normalScale);
  20559. this.displacementMap = source.displacementMap;
  20560. this.displacementScale = source.displacementScale;
  20561. this.displacementBias = source.displacementBias;
  20562. this.alphaMap = source.alphaMap;
  20563. this.skinning = source.skinning;
  20564. this.morphTargets = source.morphTargets;
  20565. this.morphNormals = source.morphNormals;
  20566. return this;
  20567. };
  20568. /**
  20569. * parameters = {
  20570. * color: <hex>,
  20571. * opacity: <float>,
  20572. *
  20573. * linewidth: <float>,
  20574. *
  20575. * scale: <float>,
  20576. * dashSize: <float>,
  20577. * gapSize: <float>
  20578. * }
  20579. */
  20580. function LineDashedMaterial(parameters) {
  20581. LineBasicMaterial.call(this);
  20582. this.type = 'LineDashedMaterial';
  20583. this.scale = 1;
  20584. this.dashSize = 3;
  20585. this.gapSize = 1;
  20586. this.setValues(parameters);
  20587. }
  20588. LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
  20589. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20590. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20591. LineDashedMaterial.prototype.copy = function (source) {
  20592. LineBasicMaterial.prototype.copy.call(this, source);
  20593. this.scale = source.scale;
  20594. this.dashSize = source.dashSize;
  20595. this.gapSize = source.gapSize;
  20596. return this;
  20597. };
  20598. var Materials = /*#__PURE__*/Object.freeze({
  20599. __proto__: null,
  20600. ShadowMaterial: ShadowMaterial,
  20601. SpriteMaterial: SpriteMaterial,
  20602. RawShaderMaterial: RawShaderMaterial,
  20603. ShaderMaterial: ShaderMaterial,
  20604. PointsMaterial: PointsMaterial,
  20605. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20606. MeshStandardMaterial: MeshStandardMaterial,
  20607. MeshPhongMaterial: MeshPhongMaterial,
  20608. MeshToonMaterial: MeshToonMaterial,
  20609. MeshNormalMaterial: MeshNormalMaterial,
  20610. MeshLambertMaterial: MeshLambertMaterial,
  20611. MeshDepthMaterial: MeshDepthMaterial,
  20612. MeshDistanceMaterial: MeshDistanceMaterial,
  20613. MeshBasicMaterial: MeshBasicMaterial,
  20614. MeshMatcapMaterial: MeshMatcapMaterial,
  20615. LineDashedMaterial: LineDashedMaterial,
  20616. LineBasicMaterial: LineBasicMaterial,
  20617. Material: Material
  20618. });
  20619. var AnimationUtils = {
  20620. // same as Array.prototype.slice, but also works on typed arrays
  20621. arraySlice: function arraySlice(array, from, to) {
  20622. if (AnimationUtils.isTypedArray(array)) {
  20623. // in ios9 array.subarray(from, undefined) will return empty array
  20624. // but array.subarray(from) or array.subarray(from, len) is correct
  20625. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20626. }
  20627. return array.slice(from, to);
  20628. },
  20629. // converts an array to a specific type
  20630. convertArray: function convertArray(array, type, forceClone) {
  20631. if (!array || // let 'undefined' and 'null' pass
  20632. !forceClone && array.constructor === type) return array;
  20633. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20634. return new type(array); // create typed array
  20635. }
  20636. return Array.prototype.slice.call(array); // create Array
  20637. },
  20638. isTypedArray: function isTypedArray(object) {
  20639. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20640. },
  20641. // returns an array by which times and values can be sorted
  20642. getKeyframeOrder: function getKeyframeOrder(times) {
  20643. function compareTime(i, j) {
  20644. return times[i] - times[j];
  20645. }
  20646. var n = times.length;
  20647. var result = new Array(n);
  20648. for (var i = 0; i !== n; ++i) {
  20649. result[i] = i;
  20650. }
  20651. result.sort(compareTime);
  20652. return result;
  20653. },
  20654. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20655. sortedArray: function sortedArray(values, stride, order) {
  20656. var nValues = values.length;
  20657. var result = new values.constructor(nValues);
  20658. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20659. var srcOffset = order[i] * stride;
  20660. for (var j = 0; j !== stride; ++j) {
  20661. result[dstOffset++] = values[srcOffset + j];
  20662. }
  20663. }
  20664. return result;
  20665. },
  20666. // function for parsing AOS keyframe formats
  20667. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20668. var i = 1,
  20669. key = jsonKeys[0];
  20670. while (key !== undefined && key[valuePropertyName] === undefined) {
  20671. key = jsonKeys[i++];
  20672. }
  20673. if (key === undefined) return; // no data
  20674. var value = key[valuePropertyName];
  20675. if (value === undefined) return; // no data
  20676. if (Array.isArray(value)) {
  20677. do {
  20678. value = key[valuePropertyName];
  20679. if (value !== undefined) {
  20680. times.push(key.time);
  20681. values.push.apply(values, value); // push all elements
  20682. }
  20683. key = jsonKeys[i++];
  20684. } while (key !== undefined);
  20685. } else if (value.toArray !== undefined) {
  20686. // ...assume THREE.Math-ish
  20687. do {
  20688. value = key[valuePropertyName];
  20689. if (value !== undefined) {
  20690. times.push(key.time);
  20691. value.toArray(values, values.length);
  20692. }
  20693. key = jsonKeys[i++];
  20694. } while (key !== undefined);
  20695. } else {
  20696. // otherwise push as-is
  20697. do {
  20698. value = key[valuePropertyName];
  20699. if (value !== undefined) {
  20700. times.push(key.time);
  20701. values.push(value);
  20702. }
  20703. key = jsonKeys[i++];
  20704. } while (key !== undefined);
  20705. }
  20706. },
  20707. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  20708. fps = fps || 30;
  20709. var clip = sourceClip.clone();
  20710. clip.name = name;
  20711. var tracks = [];
  20712. for (var i = 0; i < clip.tracks.length; ++i) {
  20713. var track = clip.tracks[i];
  20714. var valueSize = track.getValueSize();
  20715. var times = [];
  20716. var values = [];
  20717. for (var j = 0; j < track.times.length; ++j) {
  20718. var frame = track.times[j] * fps;
  20719. if (frame < startFrame || frame >= endFrame) continue;
  20720. times.push(track.times[j]);
  20721. for (var k = 0; k < valueSize; ++k) {
  20722. values.push(track.values[j * valueSize + k]);
  20723. }
  20724. }
  20725. if (times.length === 0) continue;
  20726. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  20727. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  20728. tracks.push(track);
  20729. }
  20730. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  20731. var minStartTime = Infinity;
  20732. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  20733. if (minStartTime > clip.tracks[_i].times[0]) {
  20734. minStartTime = clip.tracks[_i].times[0];
  20735. }
  20736. } // shift all tracks such that clip begins at t=0
  20737. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  20738. clip.tracks[_i2].shift(-1 * minStartTime);
  20739. }
  20740. clip.resetDuration();
  20741. return clip;
  20742. },
  20743. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  20744. if (referenceFrame === void 0) {
  20745. referenceFrame = 0;
  20746. }
  20747. if (referenceClip === void 0) {
  20748. referenceClip = targetClip;
  20749. }
  20750. if (fps === void 0) {
  20751. fps = 30;
  20752. }
  20753. if (fps <= 0) fps = 30;
  20754. var numTracks = referenceClip.tracks.length;
  20755. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  20756. var _loop = function _loop(i) {
  20757. var referenceTrack = referenceClip.tracks[i];
  20758. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  20759. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  20760. var targetTrack = targetClip.tracks.find(function (track) {
  20761. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  20762. });
  20763. if (targetTrack === undefined) return "continue";
  20764. var referenceOffset = 0;
  20765. var referenceValueSize = referenceTrack.getValueSize();
  20766. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20767. referenceOffset = referenceValueSize / 3;
  20768. }
  20769. var targetOffset = 0;
  20770. var targetValueSize = targetTrack.getValueSize();
  20771. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20772. targetOffset = targetValueSize / 3;
  20773. }
  20774. var lastIndex = referenceTrack.times.length - 1;
  20775. var referenceValue = void 0; // Find the value to subtract out of the track
  20776. if (referenceTime <= referenceTrack.times[0]) {
  20777. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20778. var startIndex = referenceOffset;
  20779. var endIndex = referenceValueSize - referenceOffset;
  20780. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  20781. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  20782. // Reference frame is after the last keyframe, so just use the last keyframe
  20783. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  20784. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  20785. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  20786. } else {
  20787. // Interpolate to the reference value
  20788. var interpolant = referenceTrack.createInterpolant();
  20789. var _startIndex2 = referenceOffset;
  20790. var _endIndex2 = referenceValueSize - referenceOffset;
  20791. interpolant.evaluate(referenceTime);
  20792. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  20793. } // Conjugate the quaternion
  20794. if (referenceTrackType === 'quaternion') {
  20795. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  20796. referenceQuat.toArray(referenceValue);
  20797. } // Subtract the reference value from all of the track values
  20798. var numTimes = targetTrack.times.length;
  20799. for (var j = 0; j < numTimes; ++j) {
  20800. var valueStart = j * targetValueSize + targetOffset;
  20801. if (referenceTrackType === 'quaternion') {
  20802. // Multiply the conjugate for quaternion track types
  20803. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  20804. } else {
  20805. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  20806. for (var k = 0; k < valueEnd; ++k) {
  20807. targetTrack.values[valueStart + k] -= referenceValue[k];
  20808. }
  20809. }
  20810. }
  20811. };
  20812. for (var i = 0; i < numTracks; ++i) {
  20813. var _ret = _loop(i);
  20814. if (_ret === "continue") continue;
  20815. }
  20816. targetClip.blendMode = AdditiveAnimationBlendMode;
  20817. return targetClip;
  20818. }
  20819. };
  20820. /**
  20821. * Abstract base class of interpolants over parametric samples.
  20822. *
  20823. * The parameter domain is one dimensional, typically the time or a path
  20824. * along a curve defined by the data.
  20825. *
  20826. * The sample values can have any dimensionality and derived classes may
  20827. * apply special interpretations to the data.
  20828. *
  20829. * This class provides the interval seek in a Template Method, deferring
  20830. * the actual interpolation to derived classes.
  20831. *
  20832. * Time complexity is O(1) for linear access crossing at most two points
  20833. * and O(log N) for random access, where N is the number of positions.
  20834. *
  20835. * References:
  20836. *
  20837. * http://www.oodesign.com/template-method-pattern.html
  20838. *
  20839. */
  20840. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20841. this.parameterPositions = parameterPositions;
  20842. this._cachedIndex = 0;
  20843. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  20844. this.sampleValues = sampleValues;
  20845. this.valueSize = sampleSize;
  20846. }
  20847. Object.assign(Interpolant.prototype, {
  20848. evaluate: function evaluate(t) {
  20849. var pp = this.parameterPositions;
  20850. var i1 = this._cachedIndex,
  20851. t1 = pp[i1],
  20852. t0 = pp[i1 - 1];
  20853. validate_interval: {
  20854. seek: {
  20855. var right;
  20856. linear_scan: {
  20857. //- See http://jsperf.com/comparison-to-undefined/3
  20858. //- slower code:
  20859. //-
  20860. //- if ( t >= t1 || t1 === undefined ) {
  20861. forward_scan: if (!(t < t1)) {
  20862. for (var giveUpAt = i1 + 2;;) {
  20863. if (t1 === undefined) {
  20864. if (t < t0) break forward_scan; // after end
  20865. i1 = pp.length;
  20866. this._cachedIndex = i1;
  20867. return this.afterEnd_(i1 - 1, t, t0);
  20868. }
  20869. if (i1 === giveUpAt) break; // this loop
  20870. t0 = t1;
  20871. t1 = pp[++i1];
  20872. if (t < t1) {
  20873. // we have arrived at the sought interval
  20874. break seek;
  20875. }
  20876. } // prepare binary search on the right side of the index
  20877. right = pp.length;
  20878. break linear_scan;
  20879. } //- slower code:
  20880. //- if ( t < t0 || t0 === undefined ) {
  20881. if (!(t >= t0)) {
  20882. // looping?
  20883. var t1global = pp[1];
  20884. if (t < t1global) {
  20885. i1 = 2; // + 1, using the scan for the details
  20886. t0 = t1global;
  20887. } // linear reverse scan
  20888. for (var _giveUpAt = i1 - 2;;) {
  20889. if (t0 === undefined) {
  20890. // before start
  20891. this._cachedIndex = 0;
  20892. return this.beforeStart_(0, t, t1);
  20893. }
  20894. if (i1 === _giveUpAt) break; // this loop
  20895. t1 = t0;
  20896. t0 = pp[--i1 - 1];
  20897. if (t >= t0) {
  20898. // we have arrived at the sought interval
  20899. break seek;
  20900. }
  20901. } // prepare binary search on the left side of the index
  20902. right = i1;
  20903. i1 = 0;
  20904. break linear_scan;
  20905. } // the interval is valid
  20906. break validate_interval;
  20907. } // linear scan
  20908. // binary search
  20909. while (i1 < right) {
  20910. var mid = i1 + right >>> 1;
  20911. if (t < pp[mid]) {
  20912. right = mid;
  20913. } else {
  20914. i1 = mid + 1;
  20915. }
  20916. }
  20917. t1 = pp[i1];
  20918. t0 = pp[i1 - 1]; // check boundary cases, again
  20919. if (t0 === undefined) {
  20920. this._cachedIndex = 0;
  20921. return this.beforeStart_(0, t, t1);
  20922. }
  20923. if (t1 === undefined) {
  20924. i1 = pp.length;
  20925. this._cachedIndex = i1;
  20926. return this.afterEnd_(i1 - 1, t0, t);
  20927. }
  20928. } // seek
  20929. this._cachedIndex = i1;
  20930. this.intervalChanged_(i1, t0, t1);
  20931. } // validate_interval
  20932. return this.interpolate_(i1, t0, t, t1);
  20933. },
  20934. settings: null,
  20935. // optional, subclass-specific settings structure
  20936. // Note: The indirection allows central control of many interpolants.
  20937. // --- Protected interface
  20938. DefaultSettings_: {},
  20939. getSettings_: function getSettings_() {
  20940. return this.settings || this.DefaultSettings_;
  20941. },
  20942. copySampleValue_: function copySampleValue_(index) {
  20943. // copies a sample value to the result buffer
  20944. var result = this.resultBuffer,
  20945. values = this.sampleValues,
  20946. stride = this.valueSize,
  20947. offset = index * stride;
  20948. for (var i = 0; i !== stride; ++i) {
  20949. result[i] = values[offset + i];
  20950. }
  20951. return result;
  20952. },
  20953. // Template methods for derived classes:
  20954. interpolate_: function interpolate_()
  20955. /* i1, t0, t, t1 */
  20956. {
  20957. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  20958. },
  20959. intervalChanged_: function intervalChanged_()
  20960. /* i1, t0, t1 */
  20961. {// empty
  20962. }
  20963. }); // DECLARE ALIAS AFTER assign prototype
  20964. Object.assign(Interpolant.prototype, {
  20965. //( 0, t, t0 ), returns this.resultBuffer
  20966. beforeStart_: Interpolant.prototype.copySampleValue_,
  20967. //( N-1, tN-1, t ), returns this.resultBuffer
  20968. afterEnd_: Interpolant.prototype.copySampleValue_
  20969. });
  20970. /**
  20971. * Fast and simple cubic spline interpolant.
  20972. *
  20973. * It was derived from a Hermitian construction setting the first derivative
  20974. * at each sample position to the linear slope between neighboring positions
  20975. * over their parameter interval.
  20976. */
  20977. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20978. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20979. this._weightPrev = -0;
  20980. this._offsetPrev = -0;
  20981. this._weightNext = -0;
  20982. this._offsetNext = -0;
  20983. }
  20984. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20985. constructor: CubicInterpolant,
  20986. DefaultSettings_: {
  20987. endingStart: ZeroCurvatureEnding,
  20988. endingEnd: ZeroCurvatureEnding
  20989. },
  20990. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  20991. var pp = this.parameterPositions;
  20992. var iPrev = i1 - 2,
  20993. iNext = i1 + 1,
  20994. tPrev = pp[iPrev],
  20995. tNext = pp[iNext];
  20996. if (tPrev === undefined) {
  20997. switch (this.getSettings_().endingStart) {
  20998. case ZeroSlopeEnding:
  20999. // f'(t0) = 0
  21000. iPrev = i1;
  21001. tPrev = 2 * t0 - t1;
  21002. break;
  21003. case WrapAroundEnding:
  21004. // use the other end of the curve
  21005. iPrev = pp.length - 2;
  21006. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  21007. break;
  21008. default:
  21009. // ZeroCurvatureEnding
  21010. // f''(t0) = 0 a.k.a. Natural Spline
  21011. iPrev = i1;
  21012. tPrev = t1;
  21013. }
  21014. }
  21015. if (tNext === undefined) {
  21016. switch (this.getSettings_().endingEnd) {
  21017. case ZeroSlopeEnding:
  21018. // f'(tN) = 0
  21019. iNext = i1;
  21020. tNext = 2 * t1 - t0;
  21021. break;
  21022. case WrapAroundEnding:
  21023. // use the other end of the curve
  21024. iNext = 1;
  21025. tNext = t1 + pp[1] - pp[0];
  21026. break;
  21027. default:
  21028. // ZeroCurvatureEnding
  21029. // f''(tN) = 0, a.k.a. Natural Spline
  21030. iNext = i1 - 1;
  21031. tNext = t0;
  21032. }
  21033. }
  21034. var halfDt = (t1 - t0) * 0.5,
  21035. stride = this.valueSize;
  21036. this._weightPrev = halfDt / (t0 - tPrev);
  21037. this._weightNext = halfDt / (tNext - t1);
  21038. this._offsetPrev = iPrev * stride;
  21039. this._offsetNext = iNext * stride;
  21040. },
  21041. interpolate_: function interpolate_(i1, t0, t, t1) {
  21042. var result = this.resultBuffer,
  21043. values = this.sampleValues,
  21044. stride = this.valueSize,
  21045. o1 = i1 * stride,
  21046. o0 = o1 - stride,
  21047. oP = this._offsetPrev,
  21048. oN = this._offsetNext,
  21049. wP = this._weightPrev,
  21050. wN = this._weightNext,
  21051. p = (t - t0) / (t1 - t0),
  21052. pp = p * p,
  21053. ppp = pp * p; // evaluate polynomials
  21054. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  21055. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  21056. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  21057. var sN = wN * ppp - wN * pp; // combine data linearly
  21058. for (var i = 0; i !== stride; ++i) {
  21059. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  21060. }
  21061. return result;
  21062. }
  21063. });
  21064. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21065. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21066. }
  21067. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21068. constructor: LinearInterpolant,
  21069. interpolate_: function interpolate_(i1, t0, t, t1) {
  21070. var result = this.resultBuffer,
  21071. values = this.sampleValues,
  21072. stride = this.valueSize,
  21073. offset1 = i1 * stride,
  21074. offset0 = offset1 - stride,
  21075. weight1 = (t - t0) / (t1 - t0),
  21076. weight0 = 1 - weight1;
  21077. for (var i = 0; i !== stride; ++i) {
  21078. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  21079. }
  21080. return result;
  21081. }
  21082. });
  21083. /**
  21084. *
  21085. * Interpolant that evaluates to the sample value at the position preceeding
  21086. * the parameter.
  21087. */
  21088. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21089. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21090. }
  21091. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21092. constructor: DiscreteInterpolant,
  21093. interpolate_: function interpolate_(i1
  21094. /*, t0, t, t1 */
  21095. ) {
  21096. return this.copySampleValue_(i1 - 1);
  21097. }
  21098. });
  21099. function KeyframeTrack(name, times, values, interpolation) {
  21100. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  21101. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  21102. this.name = name;
  21103. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  21104. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  21105. this.setInterpolation(interpolation || this.DefaultInterpolation);
  21106. } // Static methods
  21107. Object.assign(KeyframeTrack, {
  21108. // Serialization (in static context, because of constructor invocation
  21109. // and automatic invocation of .toJSON):
  21110. toJSON: function toJSON(track) {
  21111. var trackType = track.constructor;
  21112. var json; // derived classes can define a static toJSON method
  21113. if (trackType.toJSON !== undefined) {
  21114. json = trackType.toJSON(track);
  21115. } else {
  21116. // by default, we assume the data can be serialized as-is
  21117. json = {
  21118. 'name': track.name,
  21119. 'times': AnimationUtils.convertArray(track.times, Array),
  21120. 'values': AnimationUtils.convertArray(track.values, Array)
  21121. };
  21122. var interpolation = track.getInterpolation();
  21123. if (interpolation !== track.DefaultInterpolation) {
  21124. json.interpolation = interpolation;
  21125. }
  21126. }
  21127. json.type = track.ValueTypeName; // mandatory
  21128. return json;
  21129. }
  21130. });
  21131. Object.assign(KeyframeTrack.prototype, {
  21132. constructor: KeyframeTrack,
  21133. TimeBufferType: Float32Array,
  21134. ValueBufferType: Float32Array,
  21135. DefaultInterpolation: InterpolateLinear,
  21136. InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
  21137. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  21138. },
  21139. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21140. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21141. },
  21142. InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
  21143. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  21144. },
  21145. setInterpolation: function setInterpolation(interpolation) {
  21146. var factoryMethod;
  21147. switch (interpolation) {
  21148. case InterpolateDiscrete:
  21149. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  21150. break;
  21151. case InterpolateLinear:
  21152. factoryMethod = this.InterpolantFactoryMethodLinear;
  21153. break;
  21154. case InterpolateSmooth:
  21155. factoryMethod = this.InterpolantFactoryMethodSmooth;
  21156. break;
  21157. }
  21158. if (factoryMethod === undefined) {
  21159. var message = "unsupported interpolation for " + this.ValueTypeName + " keyframe track named " + this.name;
  21160. if (this.createInterpolant === undefined) {
  21161. // fall back to default, unless the default itself is messed up
  21162. if (interpolation !== this.DefaultInterpolation) {
  21163. this.setInterpolation(this.DefaultInterpolation);
  21164. } else {
  21165. throw new Error(message); // fatal, in this case
  21166. }
  21167. }
  21168. console.warn('THREE.KeyframeTrack:', message);
  21169. return this;
  21170. }
  21171. this.createInterpolant = factoryMethod;
  21172. return this;
  21173. },
  21174. getInterpolation: function getInterpolation() {
  21175. switch (this.createInterpolant) {
  21176. case this.InterpolantFactoryMethodDiscrete:
  21177. return InterpolateDiscrete;
  21178. case this.InterpolantFactoryMethodLinear:
  21179. return InterpolateLinear;
  21180. case this.InterpolantFactoryMethodSmooth:
  21181. return InterpolateSmooth;
  21182. }
  21183. },
  21184. getValueSize: function getValueSize() {
  21185. return this.values.length / this.times.length;
  21186. },
  21187. // move all keyframes either forwards or backwards in time
  21188. shift: function shift(timeOffset) {
  21189. if (timeOffset !== 0.0) {
  21190. var times = this.times;
  21191. for (var i = 0, n = times.length; i !== n; ++i) {
  21192. times[i] += timeOffset;
  21193. }
  21194. }
  21195. return this;
  21196. },
  21197. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21198. scale: function scale(timeScale) {
  21199. if (timeScale !== 1.0) {
  21200. var times = this.times;
  21201. for (var i = 0, n = times.length; i !== n; ++i) {
  21202. times[i] *= timeScale;
  21203. }
  21204. }
  21205. return this;
  21206. },
  21207. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21208. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21209. trim: function trim(startTime, endTime) {
  21210. var times = this.times,
  21211. nKeys = times.length;
  21212. var from = 0,
  21213. to = nKeys - 1;
  21214. while (from !== nKeys && times[from] < startTime) {
  21215. ++from;
  21216. }
  21217. while (to !== -1 && times[to] > endTime) {
  21218. --to;
  21219. }
  21220. ++to; // inclusive -> exclusive bound
  21221. if (from !== 0 || to !== nKeys) {
  21222. // empty tracks are forbidden, so keep at least one keyframe
  21223. if (from >= to) {
  21224. to = Math.max(to, 1);
  21225. from = to - 1;
  21226. }
  21227. var stride = this.getValueSize();
  21228. this.times = AnimationUtils.arraySlice(times, from, to);
  21229. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  21230. }
  21231. return this;
  21232. },
  21233. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21234. validate: function validate() {
  21235. var valid = true;
  21236. var valueSize = this.getValueSize();
  21237. if (valueSize - Math.floor(valueSize) !== 0) {
  21238. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  21239. valid = false;
  21240. }
  21241. var times = this.times,
  21242. values = this.values,
  21243. nKeys = times.length;
  21244. if (nKeys === 0) {
  21245. console.error('THREE.KeyframeTrack: Track is empty.', this);
  21246. valid = false;
  21247. }
  21248. var prevTime = null;
  21249. for (var i = 0; i !== nKeys; i++) {
  21250. var currTime = times[i];
  21251. if (typeof currTime === 'number' && isNaN(currTime)) {
  21252. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  21253. valid = false;
  21254. break;
  21255. }
  21256. if (prevTime !== null && prevTime > currTime) {
  21257. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  21258. valid = false;
  21259. break;
  21260. }
  21261. prevTime = currTime;
  21262. }
  21263. if (values !== undefined) {
  21264. if (AnimationUtils.isTypedArray(values)) {
  21265. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  21266. var value = values[_i];
  21267. if (isNaN(value)) {
  21268. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  21269. valid = false;
  21270. break;
  21271. }
  21272. }
  21273. }
  21274. }
  21275. return valid;
  21276. },
  21277. // removes equivalent sequential keys as common in morph target sequences
  21278. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21279. optimize: function optimize() {
  21280. // times or values may be shared with other tracks, so overwriting is unsafe
  21281. var times = AnimationUtils.arraySlice(this.times),
  21282. values = AnimationUtils.arraySlice(this.values),
  21283. stride = this.getValueSize(),
  21284. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21285. lastIndex = times.length - 1;
  21286. var writeIndex = 1;
  21287. for (var i = 1; i < lastIndex; ++i) {
  21288. var keep = false;
  21289. var time = times[i];
  21290. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  21291. if (time !== timeNext && (i !== 1 || time !== time[0])) {
  21292. if (!smoothInterpolation) {
  21293. // remove unnecessary keyframes same as their neighbors
  21294. var offset = i * stride,
  21295. offsetP = offset - stride,
  21296. offsetN = offset + stride;
  21297. for (var j = 0; j !== stride; ++j) {
  21298. var value = values[offset + j];
  21299. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  21300. keep = true;
  21301. break;
  21302. }
  21303. }
  21304. } else {
  21305. keep = true;
  21306. }
  21307. } // in-place compaction
  21308. if (keep) {
  21309. if (i !== writeIndex) {
  21310. times[writeIndex] = times[i];
  21311. var readOffset = i * stride,
  21312. writeOffset = writeIndex * stride;
  21313. for (var _j = 0; _j !== stride; ++_j) {
  21314. values[writeOffset + _j] = values[readOffset + _j];
  21315. }
  21316. }
  21317. ++writeIndex;
  21318. }
  21319. } // flush last keyframe (compaction looks ahead)
  21320. if (lastIndex > 0) {
  21321. times[writeIndex] = times[lastIndex];
  21322. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  21323. values[_writeOffset + _j2] = values[_readOffset + _j2];
  21324. }
  21325. ++writeIndex;
  21326. }
  21327. if (writeIndex !== times.length) {
  21328. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  21329. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  21330. } else {
  21331. this.times = times;
  21332. this.values = values;
  21333. }
  21334. return this;
  21335. },
  21336. clone: function clone() {
  21337. var times = AnimationUtils.arraySlice(this.times, 0);
  21338. var values = AnimationUtils.arraySlice(this.values, 0);
  21339. var TypedKeyframeTrack = this.constructor;
  21340. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21341. track.createInterpolant = this.createInterpolant;
  21342. return track;
  21343. }
  21344. });
  21345. /**
  21346. * A Track of Boolean keyframe values.
  21347. */
  21348. function BooleanKeyframeTrack(name, times, values) {
  21349. KeyframeTrack.call(this, name, times, values);
  21350. }
  21351. BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21352. constructor: BooleanKeyframeTrack,
  21353. ValueTypeName: 'bool',
  21354. ValueBufferType: Array,
  21355. DefaultInterpolation: InterpolateDiscrete,
  21356. InterpolantFactoryMethodLinear: undefined,
  21357. InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
  21358. // representation of a single value and a custom interpolant that
  21359. // computes "firstValue ^ isOdd( index )".
  21360. });
  21361. /**
  21362. * A Track of keyframe values that represent color.
  21363. */
  21364. function ColorKeyframeTrack(name, times, values, interpolation) {
  21365. KeyframeTrack.call(this, name, times, values, interpolation);
  21366. }
  21367. ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21368. constructor: ColorKeyframeTrack,
  21369. ValueTypeName: 'color' // ValueBufferType is inherited
  21370. // DefaultInterpolation is inherited
  21371. // Note: Very basic implementation and nothing special yet.
  21372. // However, this is the place for color space parameterization.
  21373. });
  21374. /**
  21375. * A Track of numeric keyframe values.
  21376. */
  21377. function NumberKeyframeTrack(name, times, values, interpolation) {
  21378. KeyframeTrack.call(this, name, times, values, interpolation);
  21379. }
  21380. NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21381. constructor: NumberKeyframeTrack,
  21382. ValueTypeName: 'number' // ValueBufferType is inherited
  21383. // DefaultInterpolation is inherited
  21384. });
  21385. /**
  21386. * Spherical linear unit quaternion interpolant.
  21387. */
  21388. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21389. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21390. }
  21391. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21392. constructor: QuaternionLinearInterpolant,
  21393. interpolate_: function interpolate_(i1, t0, t, t1) {
  21394. var result = this.resultBuffer,
  21395. values = this.sampleValues,
  21396. stride = this.valueSize,
  21397. alpha = (t - t0) / (t1 - t0);
  21398. var offset = i1 * stride;
  21399. for (var end = offset + stride; offset !== end; offset += 4) {
  21400. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21401. }
  21402. return result;
  21403. }
  21404. });
  21405. /**
  21406. * A Track of quaternion keyframe values.
  21407. */
  21408. function QuaternionKeyframeTrack(name, times, values, interpolation) {
  21409. KeyframeTrack.call(this, name, times, values, interpolation);
  21410. }
  21411. QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21412. constructor: QuaternionKeyframeTrack,
  21413. ValueTypeName: 'quaternion',
  21414. // ValueBufferType is inherited
  21415. DefaultInterpolation: InterpolateLinear,
  21416. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21417. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21418. },
  21419. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21420. });
  21421. /**
  21422. * A Track that interpolates Strings
  21423. */
  21424. function StringKeyframeTrack(name, times, values, interpolation) {
  21425. KeyframeTrack.call(this, name, times, values, interpolation);
  21426. }
  21427. StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21428. constructor: StringKeyframeTrack,
  21429. ValueTypeName: 'string',
  21430. ValueBufferType: Array,
  21431. DefaultInterpolation: InterpolateDiscrete,
  21432. InterpolantFactoryMethodLinear: undefined,
  21433. InterpolantFactoryMethodSmooth: undefined
  21434. });
  21435. /**
  21436. * A Track of vectored keyframe values.
  21437. */
  21438. function VectorKeyframeTrack(name, times, values, interpolation) {
  21439. KeyframeTrack.call(this, name, times, values, interpolation);
  21440. }
  21441. VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21442. constructor: VectorKeyframeTrack,
  21443. ValueTypeName: 'vector' // ValueBufferType is inherited
  21444. // DefaultInterpolation is inherited
  21445. });
  21446. function AnimationClip(name, duration, tracks, blendMode) {
  21447. this.name = name;
  21448. this.tracks = tracks;
  21449. this.duration = duration !== undefined ? duration : -1;
  21450. this.blendMode = blendMode !== undefined ? blendMode : NormalAnimationBlendMode;
  21451. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21452. if (this.duration < 0) {
  21453. this.resetDuration();
  21454. }
  21455. }
  21456. function getTrackTypeForValueTypeName(typeName) {
  21457. switch (typeName.toLowerCase()) {
  21458. case 'scalar':
  21459. case 'double':
  21460. case 'float':
  21461. case 'number':
  21462. case 'integer':
  21463. return NumberKeyframeTrack;
  21464. case 'vector':
  21465. case 'vector2':
  21466. case 'vector3':
  21467. case 'vector4':
  21468. return VectorKeyframeTrack;
  21469. case 'color':
  21470. return ColorKeyframeTrack;
  21471. case 'quaternion':
  21472. return QuaternionKeyframeTrack;
  21473. case 'bool':
  21474. case 'boolean':
  21475. return BooleanKeyframeTrack;
  21476. case 'string':
  21477. return StringKeyframeTrack;
  21478. }
  21479. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21480. }
  21481. function parseKeyframeTrack(json) {
  21482. if (json.type === undefined) {
  21483. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21484. }
  21485. var trackType = getTrackTypeForValueTypeName(json.type);
  21486. if (json.times === undefined) {
  21487. var times = [],
  21488. values = [];
  21489. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21490. json.times = times;
  21491. json.values = values;
  21492. } // derived classes can define a static parse method
  21493. if (trackType.parse !== undefined) {
  21494. return trackType.parse(json);
  21495. } else {
  21496. // by default, we assume a constructor compatible with the base
  21497. return new trackType(json.name, json.times, json.values, json.interpolation);
  21498. }
  21499. }
  21500. Object.assign(AnimationClip, {
  21501. parse: function parse(json) {
  21502. var tracks = [],
  21503. jsonTracks = json.tracks,
  21504. frameTime = 1.0 / (json.fps || 1.0);
  21505. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21506. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21507. }
  21508. return new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21509. },
  21510. toJSON: function toJSON(clip) {
  21511. var tracks = [],
  21512. clipTracks = clip.tracks;
  21513. var json = {
  21514. 'name': clip.name,
  21515. 'duration': clip.duration,
  21516. 'tracks': tracks,
  21517. 'uuid': clip.uuid,
  21518. 'blendMode': clip.blendMode
  21519. };
  21520. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21521. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21522. }
  21523. return json;
  21524. },
  21525. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21526. var numMorphTargets = morphTargetSequence.length;
  21527. var tracks = [];
  21528. for (var i = 0; i < numMorphTargets; i++) {
  21529. var times = [];
  21530. var values = [];
  21531. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21532. values.push(0, 1, 0);
  21533. var order = AnimationUtils.getKeyframeOrder(times);
  21534. times = AnimationUtils.sortedArray(times, 1, order);
  21535. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21536. // last frame as well for perfect loop.
  21537. if (!noLoop && times[0] === 0) {
  21538. times.push(numMorphTargets);
  21539. values.push(values[0]);
  21540. }
  21541. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21542. }
  21543. return new AnimationClip(name, -1, tracks);
  21544. },
  21545. findByName: function findByName(objectOrClipArray, name) {
  21546. var clipArray = objectOrClipArray;
  21547. if (!Array.isArray(objectOrClipArray)) {
  21548. var o = objectOrClipArray;
  21549. clipArray = o.geometry && o.geometry.animations || o.animations;
  21550. }
  21551. for (var i = 0; i < clipArray.length; i++) {
  21552. if (clipArray[i].name === name) {
  21553. return clipArray[i];
  21554. }
  21555. }
  21556. return null;
  21557. },
  21558. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21559. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21560. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21561. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21562. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21563. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21564. var morphTarget = morphTargets[i];
  21565. var parts = morphTarget.name.match(pattern);
  21566. if (parts && parts.length > 1) {
  21567. var name = parts[1];
  21568. var animationMorphTargets = animationToMorphTargets[name];
  21569. if (!animationMorphTargets) {
  21570. animationToMorphTargets[name] = animationMorphTargets = [];
  21571. }
  21572. animationMorphTargets.push(morphTarget);
  21573. }
  21574. }
  21575. var clips = [];
  21576. for (var _name in animationToMorphTargets) {
  21577. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21578. }
  21579. return clips;
  21580. },
  21581. // parse the animation.hierarchy format
  21582. parseAnimation: function parseAnimation(animation, bones) {
  21583. if (!animation) {
  21584. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21585. return null;
  21586. }
  21587. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21588. // only return track if there are actually keys.
  21589. if (animationKeys.length !== 0) {
  21590. var times = [];
  21591. var values = [];
  21592. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21593. if (times.length !== 0) {
  21594. destTracks.push(new trackType(trackName, times, values));
  21595. }
  21596. }
  21597. };
  21598. var tracks = [];
  21599. var clipName = animation.name || 'default';
  21600. var fps = animation.fps || 30;
  21601. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21602. var duration = animation.length || -1;
  21603. var hierarchyTracks = animation.hierarchy || [];
  21604. for (var h = 0; h < hierarchyTracks.length; h++) {
  21605. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21606. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21607. if (animationKeys[0].morphTargets) {
  21608. // figure out all morph targets used in this track
  21609. var morphTargetNames = {};
  21610. var k = void 0;
  21611. for (k = 0; k < animationKeys.length; k++) {
  21612. if (animationKeys[k].morphTargets) {
  21613. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21614. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21615. }
  21616. }
  21617. } // create a track for each morph target with all zero
  21618. // morphTargetInfluences except for the keys in which
  21619. // the morphTarget is named.
  21620. for (var morphTargetName in morphTargetNames) {
  21621. var times = [];
  21622. var values = [];
  21623. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21624. var animationKey = animationKeys[k];
  21625. times.push(animationKey.time);
  21626. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21627. }
  21628. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21629. }
  21630. duration = morphTargetNames.length * (fps || 1.0);
  21631. } else {
  21632. // ...assume skeletal animation
  21633. var boneName = '.bones[' + bones[h].name + ']';
  21634. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21635. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21636. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21637. }
  21638. }
  21639. if (tracks.length === 0) {
  21640. return null;
  21641. }
  21642. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21643. return clip;
  21644. }
  21645. });
  21646. Object.assign(AnimationClip.prototype, {
  21647. resetDuration: function resetDuration() {
  21648. var tracks = this.tracks;
  21649. var duration = 0;
  21650. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21651. var track = this.tracks[i];
  21652. duration = Math.max(duration, track.times[track.times.length - 1]);
  21653. }
  21654. this.duration = duration;
  21655. return this;
  21656. },
  21657. trim: function trim() {
  21658. for (var i = 0; i < this.tracks.length; i++) {
  21659. this.tracks[i].trim(0, this.duration);
  21660. }
  21661. return this;
  21662. },
  21663. validate: function validate() {
  21664. var valid = true;
  21665. for (var i = 0; i < this.tracks.length; i++) {
  21666. valid = valid && this.tracks[i].validate();
  21667. }
  21668. return valid;
  21669. },
  21670. optimize: function optimize() {
  21671. for (var i = 0; i < this.tracks.length; i++) {
  21672. this.tracks[i].optimize();
  21673. }
  21674. return this;
  21675. },
  21676. clone: function clone() {
  21677. var tracks = [];
  21678. for (var i = 0; i < this.tracks.length; i++) {
  21679. tracks.push(this.tracks[i].clone());
  21680. }
  21681. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  21682. }
  21683. });
  21684. var Cache = {
  21685. enabled: false,
  21686. files: {},
  21687. add: function add(key, file) {
  21688. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  21689. this.files[key] = file;
  21690. },
  21691. get: function get(key) {
  21692. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  21693. return this.files[key];
  21694. },
  21695. remove: function remove(key) {
  21696. delete this.files[key];
  21697. },
  21698. clear: function clear() {
  21699. this.files = {};
  21700. }
  21701. };
  21702. function LoadingManager(onLoad, onProgress, onError) {
  21703. var scope = this;
  21704. var isLoading = false;
  21705. var itemsLoaded = 0;
  21706. var itemsTotal = 0;
  21707. var urlModifier = undefined;
  21708. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  21709. // in the constructor
  21710. this.onStart = undefined;
  21711. this.onLoad = onLoad;
  21712. this.onProgress = onProgress;
  21713. this.onError = onError;
  21714. this.itemStart = function (url) {
  21715. itemsTotal++;
  21716. if (isLoading === false) {
  21717. if (scope.onStart !== undefined) {
  21718. scope.onStart(url, itemsLoaded, itemsTotal);
  21719. }
  21720. }
  21721. isLoading = true;
  21722. };
  21723. this.itemEnd = function (url) {
  21724. itemsLoaded++;
  21725. if (scope.onProgress !== undefined) {
  21726. scope.onProgress(url, itemsLoaded, itemsTotal);
  21727. }
  21728. if (itemsLoaded === itemsTotal) {
  21729. isLoading = false;
  21730. if (scope.onLoad !== undefined) {
  21731. scope.onLoad();
  21732. }
  21733. }
  21734. };
  21735. this.itemError = function (url) {
  21736. if (scope.onError !== undefined) {
  21737. scope.onError(url);
  21738. }
  21739. };
  21740. this.resolveURL = function (url) {
  21741. if (urlModifier) {
  21742. return urlModifier(url);
  21743. }
  21744. return url;
  21745. };
  21746. this.setURLModifier = function (transform) {
  21747. urlModifier = transform;
  21748. return this;
  21749. };
  21750. this.addHandler = function (regex, loader) {
  21751. handlers.push(regex, loader);
  21752. return this;
  21753. };
  21754. this.removeHandler = function (regex) {
  21755. var index = handlers.indexOf(regex);
  21756. if (index !== -1) {
  21757. handlers.splice(index, 2);
  21758. }
  21759. return this;
  21760. };
  21761. this.getHandler = function (file) {
  21762. for (var i = 0, l = handlers.length; i < l; i += 2) {
  21763. var regex = handlers[i];
  21764. var loader = handlers[i + 1];
  21765. if (regex.global) regex.lastIndex = 0; // see #17920
  21766. if (regex.test(file)) {
  21767. return loader;
  21768. }
  21769. }
  21770. return null;
  21771. };
  21772. }
  21773. var DefaultLoadingManager = new LoadingManager();
  21774. function Loader(manager) {
  21775. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  21776. this.crossOrigin = 'anonymous';
  21777. this.withCredentials = false;
  21778. this.path = '';
  21779. this.resourcePath = '';
  21780. this.requestHeader = {};
  21781. }
  21782. Object.assign(Loader.prototype, {
  21783. load: function load()
  21784. /* url, onLoad, onProgress, onError */
  21785. {},
  21786. loadAsync: function loadAsync(url, onProgress) {
  21787. var scope = this;
  21788. return new Promise(function (resolve, reject) {
  21789. scope.load(url, resolve, onProgress, reject);
  21790. });
  21791. },
  21792. parse: function parse()
  21793. /* data */
  21794. {},
  21795. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  21796. this.crossOrigin = crossOrigin;
  21797. return this;
  21798. },
  21799. setWithCredentials: function setWithCredentials(value) {
  21800. this.withCredentials = value;
  21801. return this;
  21802. },
  21803. setPath: function setPath(path) {
  21804. this.path = path;
  21805. return this;
  21806. },
  21807. setResourcePath: function setResourcePath(resourcePath) {
  21808. this.resourcePath = resourcePath;
  21809. return this;
  21810. },
  21811. setRequestHeader: function setRequestHeader(requestHeader) {
  21812. this.requestHeader = requestHeader;
  21813. return this;
  21814. }
  21815. });
  21816. var loading = {};
  21817. function FileLoader(manager) {
  21818. Loader.call(this, manager);
  21819. }
  21820. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21821. constructor: FileLoader,
  21822. load: function load(url, onLoad, onProgress, onError) {
  21823. if (url === undefined) url = '';
  21824. if (this.path !== undefined) url = this.path + url;
  21825. url = this.manager.resolveURL(url);
  21826. var scope = this;
  21827. var cached = Cache.get(url);
  21828. if (cached !== undefined) {
  21829. scope.manager.itemStart(url);
  21830. setTimeout(function () {
  21831. if (onLoad) onLoad(cached);
  21832. scope.manager.itemEnd(url);
  21833. }, 0);
  21834. return cached;
  21835. } // Check if request is duplicate
  21836. if (loading[url] !== undefined) {
  21837. loading[url].push({
  21838. onLoad: onLoad,
  21839. onProgress: onProgress,
  21840. onError: onError
  21841. });
  21842. return;
  21843. } // Check for data: URI
  21844. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21845. var dataUriRegexResult = url.match(dataUriRegex);
  21846. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21847. if (dataUriRegexResult) {
  21848. var mimeType = dataUriRegexResult[1];
  21849. var isBase64 = !!dataUriRegexResult[2];
  21850. var data = dataUriRegexResult[3];
  21851. data = decodeURIComponent(data);
  21852. if (isBase64) data = atob(data);
  21853. try {
  21854. var response;
  21855. var responseType = (this.responseType || '').toLowerCase();
  21856. switch (responseType) {
  21857. case 'arraybuffer':
  21858. case 'blob':
  21859. var view = new Uint8Array(data.length);
  21860. for (var i = 0; i < data.length; i++) {
  21861. view[i] = data.charCodeAt(i);
  21862. }
  21863. if (responseType === 'blob') {
  21864. response = new Blob([view.buffer], {
  21865. type: mimeType
  21866. });
  21867. } else {
  21868. response = view.buffer;
  21869. }
  21870. break;
  21871. case 'document':
  21872. var parser = new DOMParser();
  21873. response = parser.parseFromString(data, mimeType);
  21874. break;
  21875. case 'json':
  21876. response = JSON.parse(data);
  21877. break;
  21878. default:
  21879. // 'text' or other
  21880. response = data;
  21881. break;
  21882. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21883. setTimeout(function () {
  21884. if (onLoad) onLoad(response);
  21885. scope.manager.itemEnd(url);
  21886. }, 0);
  21887. } catch (error) {
  21888. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21889. setTimeout(function () {
  21890. if (onError) onError(error);
  21891. scope.manager.itemError(url);
  21892. scope.manager.itemEnd(url);
  21893. }, 0);
  21894. }
  21895. } else {
  21896. // Initialise array for duplicate requests
  21897. loading[url] = [];
  21898. loading[url].push({
  21899. onLoad: onLoad,
  21900. onProgress: onProgress,
  21901. onError: onError
  21902. });
  21903. request = new XMLHttpRequest();
  21904. request.open('GET', url, true);
  21905. request.addEventListener('load', function (event) {
  21906. var response = this.response;
  21907. var callbacks = loading[url];
  21908. delete loading[url];
  21909. if (this.status === 200 || this.status === 0) {
  21910. // Some browsers return HTTP Status 0 when using non-http protocol
  21911. // e.g. 'file://' or 'data://'. Handle as success.
  21912. 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
  21913. // error response bodies as proper responses to requests.
  21914. Cache.add(url, response);
  21915. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  21916. var callback = callbacks[_i];
  21917. if (callback.onLoad) callback.onLoad(response);
  21918. }
  21919. scope.manager.itemEnd(url);
  21920. } else {
  21921. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  21922. var _callback = callbacks[_i2];
  21923. if (_callback.onError) _callback.onError(event);
  21924. }
  21925. scope.manager.itemError(url);
  21926. scope.manager.itemEnd(url);
  21927. }
  21928. }, false);
  21929. request.addEventListener('progress', function (event) {
  21930. var callbacks = loading[url];
  21931. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  21932. var callback = callbacks[_i3];
  21933. if (callback.onProgress) callback.onProgress(event);
  21934. }
  21935. }, false);
  21936. request.addEventListener('error', function (event) {
  21937. var callbacks = loading[url];
  21938. delete loading[url];
  21939. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  21940. var callback = callbacks[_i4];
  21941. if (callback.onError) callback.onError(event);
  21942. }
  21943. scope.manager.itemError(url);
  21944. scope.manager.itemEnd(url);
  21945. }, false);
  21946. request.addEventListener('abort', function (event) {
  21947. var callbacks = loading[url];
  21948. delete loading[url];
  21949. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  21950. var callback = callbacks[_i5];
  21951. if (callback.onError) callback.onError(event);
  21952. }
  21953. scope.manager.itemError(url);
  21954. scope.manager.itemEnd(url);
  21955. }, false);
  21956. if (this.responseType !== undefined) request.responseType = this.responseType;
  21957. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  21958. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  21959. for (var header in this.requestHeader) {
  21960. request.setRequestHeader(header, this.requestHeader[header]);
  21961. }
  21962. request.send(null);
  21963. }
  21964. scope.manager.itemStart(url);
  21965. return request;
  21966. },
  21967. setResponseType: function setResponseType(value) {
  21968. this.responseType = value;
  21969. return this;
  21970. },
  21971. setMimeType: function setMimeType(value) {
  21972. this.mimeType = value;
  21973. return this;
  21974. }
  21975. });
  21976. function AnimationLoader(manager) {
  21977. Loader.call(this, manager);
  21978. }
  21979. AnimationLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21980. constructor: AnimationLoader,
  21981. load: function load(url, onLoad, onProgress, onError) {
  21982. var scope = this;
  21983. var loader = new FileLoader(scope.manager);
  21984. loader.setPath(scope.path);
  21985. loader.setRequestHeader(scope.requestHeader);
  21986. loader.setWithCredentials(scope.withCredentials);
  21987. loader.load(url, function (text) {
  21988. try {
  21989. onLoad(scope.parse(JSON.parse(text)));
  21990. } catch (e) {
  21991. if (onError) {
  21992. onError(e);
  21993. } else {
  21994. console.error(e);
  21995. }
  21996. scope.manager.itemError(url);
  21997. }
  21998. }, onProgress, onError);
  21999. },
  22000. parse: function parse(json) {
  22001. var animations = [];
  22002. for (var i = 0; i < json.length; i++) {
  22003. var clip = AnimationClip.parse(json[i]);
  22004. animations.push(clip);
  22005. }
  22006. return animations;
  22007. }
  22008. });
  22009. /**
  22010. * Abstract Base class to block based textures loader (dds, pvr, ...)
  22011. *
  22012. * Sub classes have to implement the parse() method which will be used in load().
  22013. */
  22014. function CompressedTextureLoader(manager) {
  22015. Loader.call(this, manager);
  22016. }
  22017. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22018. constructor: CompressedTextureLoader,
  22019. load: function load(url, onLoad, onProgress, onError) {
  22020. var scope = this;
  22021. var images = [];
  22022. var texture = new CompressedTexture();
  22023. texture.image = images;
  22024. var loader = new FileLoader(this.manager);
  22025. loader.setPath(this.path);
  22026. loader.setResponseType('arraybuffer');
  22027. loader.setRequestHeader(this.requestHeader);
  22028. loader.setWithCredentials(scope.withCredentials);
  22029. var loaded = 0;
  22030. function loadTexture(i) {
  22031. loader.load(url[i], function (buffer) {
  22032. var texDatas = scope.parse(buffer, true);
  22033. images[i] = {
  22034. width: texDatas.width,
  22035. height: texDatas.height,
  22036. format: texDatas.format,
  22037. mipmaps: texDatas.mipmaps
  22038. };
  22039. loaded += 1;
  22040. if (loaded === 6) {
  22041. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  22042. texture.format = texDatas.format;
  22043. texture.needsUpdate = true;
  22044. if (onLoad) onLoad(texture);
  22045. }
  22046. }, onProgress, onError);
  22047. }
  22048. if (Array.isArray(url)) {
  22049. for (var i = 0, il = url.length; i < il; ++i) {
  22050. loadTexture(i);
  22051. }
  22052. } else {
  22053. // compressed cubemap texture stored in a single DDS file
  22054. loader.load(url, function (buffer) {
  22055. var texDatas = scope.parse(buffer, true);
  22056. if (texDatas.isCubemap) {
  22057. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  22058. for (var f = 0; f < faces; f++) {
  22059. images[f] = {
  22060. mipmaps: []
  22061. };
  22062. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  22063. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  22064. images[f].format = texDatas.format;
  22065. images[f].width = texDatas.width;
  22066. images[f].height = texDatas.height;
  22067. }
  22068. }
  22069. } else {
  22070. texture.image.width = texDatas.width;
  22071. texture.image.height = texDatas.height;
  22072. texture.mipmaps = texDatas.mipmaps;
  22073. }
  22074. if (texDatas.mipmapCount === 1) {
  22075. texture.minFilter = LinearFilter;
  22076. }
  22077. texture.format = texDatas.format;
  22078. texture.needsUpdate = true;
  22079. if (onLoad) onLoad(texture);
  22080. }, onProgress, onError);
  22081. }
  22082. return texture;
  22083. }
  22084. });
  22085. function ImageLoader(manager) {
  22086. Loader.call(this, manager);
  22087. }
  22088. ImageLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22089. constructor: ImageLoader,
  22090. load: function load(url, onLoad, onProgress, onError) {
  22091. if (this.path !== undefined) url = this.path + url;
  22092. url = this.manager.resolveURL(url);
  22093. var scope = this;
  22094. var cached = Cache.get(url);
  22095. if (cached !== undefined) {
  22096. scope.manager.itemStart(url);
  22097. setTimeout(function () {
  22098. if (onLoad) onLoad(cached);
  22099. scope.manager.itemEnd(url);
  22100. }, 0);
  22101. return cached;
  22102. }
  22103. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  22104. function onImageLoad() {
  22105. image.removeEventListener('load', onImageLoad, false);
  22106. image.removeEventListener('error', onImageError, false);
  22107. Cache.add(url, this);
  22108. if (onLoad) onLoad(this);
  22109. scope.manager.itemEnd(url);
  22110. }
  22111. function onImageError(event) {
  22112. image.removeEventListener('load', onImageLoad, false);
  22113. image.removeEventListener('error', onImageError, false);
  22114. if (onError) onError(event);
  22115. scope.manager.itemError(url);
  22116. scope.manager.itemEnd(url);
  22117. }
  22118. image.addEventListener('load', onImageLoad, false);
  22119. image.addEventListener('error', onImageError, false);
  22120. if (url.substr(0, 5) !== 'data:') {
  22121. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  22122. }
  22123. scope.manager.itemStart(url);
  22124. image.src = url;
  22125. return image;
  22126. }
  22127. });
  22128. function CubeTextureLoader(manager) {
  22129. Loader.call(this, manager);
  22130. }
  22131. CubeTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22132. constructor: CubeTextureLoader,
  22133. load: function load(urls, onLoad, onProgress, onError) {
  22134. var texture = new CubeTexture();
  22135. var loader = new ImageLoader(this.manager);
  22136. loader.setCrossOrigin(this.crossOrigin);
  22137. loader.setPath(this.path);
  22138. var loaded = 0;
  22139. function loadTexture(i) {
  22140. loader.load(urls[i], function (image) {
  22141. texture.images[i] = image;
  22142. loaded++;
  22143. if (loaded === 6) {
  22144. texture.needsUpdate = true;
  22145. if (onLoad) onLoad(texture);
  22146. }
  22147. }, undefined, onError);
  22148. }
  22149. for (var i = 0; i < urls.length; ++i) {
  22150. loadTexture(i);
  22151. }
  22152. return texture;
  22153. }
  22154. });
  22155. /**
  22156. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  22157. *
  22158. * Sub classes have to implement the parse() method which will be used in load().
  22159. */
  22160. function DataTextureLoader(manager) {
  22161. Loader.call(this, manager);
  22162. }
  22163. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22164. constructor: DataTextureLoader,
  22165. load: function load(url, onLoad, onProgress, onError) {
  22166. var scope = this;
  22167. var texture = new DataTexture();
  22168. var loader = new FileLoader(this.manager);
  22169. loader.setResponseType('arraybuffer');
  22170. loader.setRequestHeader(this.requestHeader);
  22171. loader.setPath(this.path);
  22172. loader.setWithCredentials(scope.withCredentials);
  22173. loader.load(url, function (buffer) {
  22174. var texData = scope.parse(buffer);
  22175. if (!texData) return;
  22176. if (texData.image !== undefined) {
  22177. texture.image = texData.image;
  22178. } else if (texData.data !== undefined) {
  22179. texture.image.width = texData.width;
  22180. texture.image.height = texData.height;
  22181. texture.image.data = texData.data;
  22182. }
  22183. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  22184. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  22185. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  22186. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  22187. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  22188. if (texData.format !== undefined) {
  22189. texture.format = texData.format;
  22190. }
  22191. if (texData.type !== undefined) {
  22192. texture.type = texData.type;
  22193. }
  22194. if (texData.mipmaps !== undefined) {
  22195. texture.mipmaps = texData.mipmaps;
  22196. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  22197. }
  22198. if (texData.mipmapCount === 1) {
  22199. texture.minFilter = LinearFilter;
  22200. }
  22201. texture.needsUpdate = true;
  22202. if (onLoad) onLoad(texture, texData);
  22203. }, onProgress, onError);
  22204. return texture;
  22205. }
  22206. });
  22207. function TextureLoader(manager) {
  22208. Loader.call(this, manager);
  22209. }
  22210. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22211. constructor: TextureLoader,
  22212. load: function load(url, onLoad, onProgress, onError) {
  22213. var texture = new Texture();
  22214. var loader = new ImageLoader(this.manager);
  22215. loader.setCrossOrigin(this.crossOrigin);
  22216. loader.setPath(this.path);
  22217. loader.load(url, function (image) {
  22218. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  22219. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  22220. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  22221. texture.needsUpdate = true;
  22222. if (onLoad !== undefined) {
  22223. onLoad(texture);
  22224. }
  22225. }, onProgress, onError);
  22226. return texture;
  22227. }
  22228. });
  22229. /**
  22230. * Extensible curve object.
  22231. *
  22232. * Some common of curve methods:
  22233. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  22234. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  22235. * .getPoints(), .getSpacedPoints()
  22236. * .getLength()
  22237. * .updateArcLengths()
  22238. *
  22239. * This following curves inherit from THREE.Curve:
  22240. *
  22241. * -- 2D curves --
  22242. * THREE.ArcCurve
  22243. * THREE.CubicBezierCurve
  22244. * THREE.EllipseCurve
  22245. * THREE.LineCurve
  22246. * THREE.QuadraticBezierCurve
  22247. * THREE.SplineCurve
  22248. *
  22249. * -- 3D curves --
  22250. * THREE.CatmullRomCurve3
  22251. * THREE.CubicBezierCurve3
  22252. * THREE.LineCurve3
  22253. * THREE.QuadraticBezierCurve3
  22254. *
  22255. * A series of curves can be represented as a THREE.CurvePath.
  22256. *
  22257. **/
  22258. function Curve() {
  22259. this.type = 'Curve';
  22260. this.arcLengthDivisions = 200;
  22261. }
  22262. Object.assign(Curve.prototype, {
  22263. // Virtual base class method to overwrite and implement in subclasses
  22264. // - t [0 .. 1]
  22265. getPoint: function getPoint()
  22266. /* t, optionalTarget */
  22267. {
  22268. console.warn('THREE.Curve: .getPoint() not implemented.');
  22269. return null;
  22270. },
  22271. // Get point at relative position in curve according to arc length
  22272. // - u [0 .. 1]
  22273. getPointAt: function getPointAt(u, optionalTarget) {
  22274. var t = this.getUtoTmapping(u);
  22275. return this.getPoint(t, optionalTarget);
  22276. },
  22277. // Get sequence of points using getPoint( t )
  22278. getPoints: function getPoints(divisions) {
  22279. if (divisions === void 0) {
  22280. divisions = 5;
  22281. }
  22282. var points = [];
  22283. for (var d = 0; d <= divisions; d++) {
  22284. points.push(this.getPoint(d / divisions));
  22285. }
  22286. return points;
  22287. },
  22288. // Get sequence of points using getPointAt( u )
  22289. getSpacedPoints: function getSpacedPoints(divisions) {
  22290. if (divisions === void 0) {
  22291. divisions = 5;
  22292. }
  22293. var points = [];
  22294. for (var d = 0; d <= divisions; d++) {
  22295. points.push(this.getPointAt(d / divisions));
  22296. }
  22297. return points;
  22298. },
  22299. // Get total curve arc length
  22300. getLength: function getLength() {
  22301. var lengths = this.getLengths();
  22302. return lengths[lengths.length - 1];
  22303. },
  22304. // Get list of cumulative segment lengths
  22305. getLengths: function getLengths(divisions) {
  22306. if (divisions === undefined) divisions = this.arcLengthDivisions;
  22307. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  22308. return this.cacheArcLengths;
  22309. }
  22310. this.needsUpdate = false;
  22311. var cache = [];
  22312. var current,
  22313. last = this.getPoint(0);
  22314. var sum = 0;
  22315. cache.push(0);
  22316. for (var p = 1; p <= divisions; p++) {
  22317. current = this.getPoint(p / divisions);
  22318. sum += current.distanceTo(last);
  22319. cache.push(sum);
  22320. last = current;
  22321. }
  22322. this.cacheArcLengths = cache;
  22323. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22324. },
  22325. updateArcLengths: function updateArcLengths() {
  22326. this.needsUpdate = true;
  22327. this.getLengths();
  22328. },
  22329. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22330. getUtoTmapping: function getUtoTmapping(u, distance) {
  22331. var arcLengths = this.getLengths();
  22332. var i = 0;
  22333. var il = arcLengths.length;
  22334. var targetArcLength; // The targeted u distance value to get
  22335. if (distance) {
  22336. targetArcLength = distance;
  22337. } else {
  22338. targetArcLength = u * arcLengths[il - 1];
  22339. } // binary search for the index with largest value smaller than target u distance
  22340. var low = 0,
  22341. high = il - 1,
  22342. comparison;
  22343. while (low <= high) {
  22344. 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
  22345. comparison = arcLengths[i] - targetArcLength;
  22346. if (comparison < 0) {
  22347. low = i + 1;
  22348. } else if (comparison > 0) {
  22349. high = i - 1;
  22350. } else {
  22351. high = i;
  22352. break; // DONE
  22353. }
  22354. }
  22355. i = high;
  22356. if (arcLengths[i] === targetArcLength) {
  22357. return i / (il - 1);
  22358. } // we could get finer grain at lengths, or use simple interpolation between two points
  22359. var lengthBefore = arcLengths[i];
  22360. var lengthAfter = arcLengths[i + 1];
  22361. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  22362. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  22363. var t = (i + segmentFraction) / (il - 1);
  22364. return t;
  22365. },
  22366. // Returns a unit vector tangent at t
  22367. // In case any sub curve does not implement its tangent derivation,
  22368. // 2 points a small delta apart will be used to find its gradient
  22369. // which seems to give a reasonable approximation
  22370. getTangent: function getTangent(t, optionalTarget) {
  22371. var delta = 0.0001;
  22372. var t1 = t - delta;
  22373. var t2 = t + delta; // Capping in case of danger
  22374. if (t1 < 0) t1 = 0;
  22375. if (t2 > 1) t2 = 1;
  22376. var pt1 = this.getPoint(t1);
  22377. var pt2 = this.getPoint(t2);
  22378. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22379. tangent.copy(pt2).sub(pt1).normalize();
  22380. return tangent;
  22381. },
  22382. getTangentAt: function getTangentAt(u, optionalTarget) {
  22383. var t = this.getUtoTmapping(u);
  22384. return this.getTangent(t, optionalTarget);
  22385. },
  22386. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22387. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22388. var normal = new Vector3();
  22389. var tangents = [];
  22390. var normals = [];
  22391. var binormals = [];
  22392. var vec = new Vector3();
  22393. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22394. for (var i = 0; i <= segments; i++) {
  22395. var u = i / segments;
  22396. tangents[i] = this.getTangentAt(u, new Vector3());
  22397. tangents[i].normalize();
  22398. } // select an initial normal vector perpendicular to the first tangent vector,
  22399. // and in the direction of the minimum tangent xyz component
  22400. normals[0] = new Vector3();
  22401. binormals[0] = new Vector3();
  22402. var min = Number.MAX_VALUE;
  22403. var tx = Math.abs(tangents[0].x);
  22404. var ty = Math.abs(tangents[0].y);
  22405. var tz = Math.abs(tangents[0].z);
  22406. if (tx <= min) {
  22407. min = tx;
  22408. normal.set(1, 0, 0);
  22409. }
  22410. if (ty <= min) {
  22411. min = ty;
  22412. normal.set(0, 1, 0);
  22413. }
  22414. if (tz <= min) {
  22415. normal.set(0, 0, 1);
  22416. }
  22417. vec.crossVectors(tangents[0], normal).normalize();
  22418. normals[0].crossVectors(tangents[0], vec);
  22419. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22420. for (var _i = 1; _i <= segments; _i++) {
  22421. normals[_i] = normals[_i - 1].clone();
  22422. binormals[_i] = binormals[_i - 1].clone();
  22423. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22424. if (vec.length() > Number.EPSILON) {
  22425. vec.normalize();
  22426. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22427. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22428. }
  22429. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22430. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22431. if (closed === true) {
  22432. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22433. _theta /= segments;
  22434. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22435. _theta = -_theta;
  22436. }
  22437. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22438. // twist a little...
  22439. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22440. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22441. }
  22442. }
  22443. return {
  22444. tangents: tangents,
  22445. normals: normals,
  22446. binormals: binormals
  22447. };
  22448. },
  22449. clone: function clone() {
  22450. return new this.constructor().copy(this);
  22451. },
  22452. copy: function copy(source) {
  22453. this.arcLengthDivisions = source.arcLengthDivisions;
  22454. return this;
  22455. },
  22456. toJSON: function toJSON() {
  22457. var data = {
  22458. metadata: {
  22459. version: 4.5,
  22460. type: 'Curve',
  22461. generator: 'Curve.toJSON'
  22462. }
  22463. };
  22464. data.arcLengthDivisions = this.arcLengthDivisions;
  22465. data.type = this.type;
  22466. return data;
  22467. },
  22468. fromJSON: function fromJSON(json) {
  22469. this.arcLengthDivisions = json.arcLengthDivisions;
  22470. return this;
  22471. }
  22472. });
  22473. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22474. Curve.call(this);
  22475. this.type = 'EllipseCurve';
  22476. this.aX = aX || 0;
  22477. this.aY = aY || 0;
  22478. this.xRadius = xRadius || 1;
  22479. this.yRadius = yRadius || 1;
  22480. this.aStartAngle = aStartAngle || 0;
  22481. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22482. this.aClockwise = aClockwise || false;
  22483. this.aRotation = aRotation || 0;
  22484. }
  22485. EllipseCurve.prototype = Object.create(Curve.prototype);
  22486. EllipseCurve.prototype.constructor = EllipseCurve;
  22487. EllipseCurve.prototype.isEllipseCurve = true;
  22488. EllipseCurve.prototype.getPoint = function (t, optionalTarget) {
  22489. var point = optionalTarget || new Vector2();
  22490. var twoPi = Math.PI * 2;
  22491. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22492. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22493. while (deltaAngle < 0) {
  22494. deltaAngle += twoPi;
  22495. }
  22496. while (deltaAngle > twoPi) {
  22497. deltaAngle -= twoPi;
  22498. }
  22499. if (deltaAngle < Number.EPSILON) {
  22500. if (samePoints) {
  22501. deltaAngle = 0;
  22502. } else {
  22503. deltaAngle = twoPi;
  22504. }
  22505. }
  22506. if (this.aClockwise === true && !samePoints) {
  22507. if (deltaAngle === twoPi) {
  22508. deltaAngle = -twoPi;
  22509. } else {
  22510. deltaAngle = deltaAngle - twoPi;
  22511. }
  22512. }
  22513. var angle = this.aStartAngle + t * deltaAngle;
  22514. var x = this.aX + this.xRadius * Math.cos(angle);
  22515. var y = this.aY + this.yRadius * Math.sin(angle);
  22516. if (this.aRotation !== 0) {
  22517. var cos = Math.cos(this.aRotation);
  22518. var sin = Math.sin(this.aRotation);
  22519. var tx = x - this.aX;
  22520. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22521. x = tx * cos - ty * sin + this.aX;
  22522. y = tx * sin + ty * cos + this.aY;
  22523. }
  22524. return point.set(x, y);
  22525. };
  22526. EllipseCurve.prototype.copy = function (source) {
  22527. Curve.prototype.copy.call(this, source);
  22528. this.aX = source.aX;
  22529. this.aY = source.aY;
  22530. this.xRadius = source.xRadius;
  22531. this.yRadius = source.yRadius;
  22532. this.aStartAngle = source.aStartAngle;
  22533. this.aEndAngle = source.aEndAngle;
  22534. this.aClockwise = source.aClockwise;
  22535. this.aRotation = source.aRotation;
  22536. return this;
  22537. };
  22538. EllipseCurve.prototype.toJSON = function () {
  22539. var data = Curve.prototype.toJSON.call(this);
  22540. data.aX = this.aX;
  22541. data.aY = this.aY;
  22542. data.xRadius = this.xRadius;
  22543. data.yRadius = this.yRadius;
  22544. data.aStartAngle = this.aStartAngle;
  22545. data.aEndAngle = this.aEndAngle;
  22546. data.aClockwise = this.aClockwise;
  22547. data.aRotation = this.aRotation;
  22548. return data;
  22549. };
  22550. EllipseCurve.prototype.fromJSON = function (json) {
  22551. Curve.prototype.fromJSON.call(this, json);
  22552. this.aX = json.aX;
  22553. this.aY = json.aY;
  22554. this.xRadius = json.xRadius;
  22555. this.yRadius = json.yRadius;
  22556. this.aStartAngle = json.aStartAngle;
  22557. this.aEndAngle = json.aEndAngle;
  22558. this.aClockwise = json.aClockwise;
  22559. this.aRotation = json.aRotation;
  22560. return this;
  22561. };
  22562. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22563. EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  22564. this.type = 'ArcCurve';
  22565. }
  22566. ArcCurve.prototype = Object.create(EllipseCurve.prototype);
  22567. ArcCurve.prototype.constructor = ArcCurve;
  22568. ArcCurve.prototype.isArcCurve = true;
  22569. /**
  22570. * Centripetal CatmullRom Curve - which is useful for avoiding
  22571. * cusps and self-intersections in non-uniform catmull rom curves.
  22572. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22573. *
  22574. * curve.type accepts centripetal(default), chordal and catmullrom
  22575. * curve.tension is used for catmullrom which defaults to 0.5
  22576. */
  22577. /*
  22578. Based on an optimized c++ solution in
  22579. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22580. - http://ideone.com/NoEbVM
  22581. This CubicPoly class could be used for reusing some variables and calculations,
  22582. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22583. which can be placed in CurveUtils.
  22584. */
  22585. function CubicPoly() {
  22586. var c0 = 0,
  22587. c1 = 0,
  22588. c2 = 0,
  22589. c3 = 0;
  22590. /*
  22591. * Compute coefficients for a cubic polynomial
  22592. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22593. * such that
  22594. * p(0) = x0, p(1) = x1
  22595. * and
  22596. * p'(0) = t0, p'(1) = t1.
  22597. */
  22598. function init(x0, x1, t0, t1) {
  22599. c0 = x0;
  22600. c1 = t0;
  22601. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22602. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22603. }
  22604. return {
  22605. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22606. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22607. },
  22608. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22609. // compute tangents when parameterized in [t1,t2]
  22610. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22611. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22612. t1 *= dt1;
  22613. t2 *= dt1;
  22614. init(x1, x2, t1, t2);
  22615. },
  22616. calc: function calc(t) {
  22617. var t2 = t * t;
  22618. var t3 = t2 * t;
  22619. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22620. }
  22621. };
  22622. } //
  22623. var tmp = new Vector3();
  22624. var px = new CubicPoly(),
  22625. py = new CubicPoly(),
  22626. pz = new CubicPoly();
  22627. function CatmullRomCurve3(points, closed, curveType, tension) {
  22628. Curve.call(this);
  22629. this.type = 'CatmullRomCurve3';
  22630. this.points = points || [];
  22631. this.closed = closed || false;
  22632. this.curveType = curveType || 'centripetal';
  22633. this.tension = tension !== undefined ? tension : 0.5;
  22634. }
  22635. CatmullRomCurve3.prototype = Object.create(Curve.prototype);
  22636. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22637. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22638. CatmullRomCurve3.prototype.getPoint = function (t, optionalTarget) {
  22639. var point = optionalTarget || new Vector3();
  22640. var points = this.points;
  22641. var l = points.length;
  22642. var p = (l - (this.closed ? 0 : 1)) * t;
  22643. var intPoint = Math.floor(p);
  22644. var weight = p - intPoint;
  22645. if (this.closed) {
  22646. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22647. } else if (weight === 0 && intPoint === l - 1) {
  22648. intPoint = l - 2;
  22649. weight = 1;
  22650. }
  22651. var p0, p3; // 4 points (p1 & p2 defined below)
  22652. if (this.closed || intPoint > 0) {
  22653. p0 = points[(intPoint - 1) % l];
  22654. } else {
  22655. // extrapolate first point
  22656. tmp.subVectors(points[0], points[1]).add(points[0]);
  22657. p0 = tmp;
  22658. }
  22659. var p1 = points[intPoint % l];
  22660. var p2 = points[(intPoint + 1) % l];
  22661. if (this.closed || intPoint + 2 < l) {
  22662. p3 = points[(intPoint + 2) % l];
  22663. } else {
  22664. // extrapolate last point
  22665. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  22666. p3 = tmp;
  22667. }
  22668. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  22669. // init Centripetal / Chordal Catmull-Rom
  22670. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22671. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  22672. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  22673. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  22674. if (dt1 < 1e-4) dt1 = 1.0;
  22675. if (dt0 < 1e-4) dt0 = dt1;
  22676. if (dt2 < 1e-4) dt2 = dt1;
  22677. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  22678. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  22679. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  22680. } else if (this.curveType === 'catmullrom') {
  22681. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  22682. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  22683. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  22684. }
  22685. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  22686. return point;
  22687. };
  22688. CatmullRomCurve3.prototype.copy = function (source) {
  22689. Curve.prototype.copy.call(this, source);
  22690. this.points = [];
  22691. for (var i = 0, l = source.points.length; i < l; i++) {
  22692. var point = source.points[i];
  22693. this.points.push(point.clone());
  22694. }
  22695. this.closed = source.closed;
  22696. this.curveType = source.curveType;
  22697. this.tension = source.tension;
  22698. return this;
  22699. };
  22700. CatmullRomCurve3.prototype.toJSON = function () {
  22701. var data = Curve.prototype.toJSON.call(this);
  22702. data.points = [];
  22703. for (var i = 0, l = this.points.length; i < l; i++) {
  22704. var point = this.points[i];
  22705. data.points.push(point.toArray());
  22706. }
  22707. data.closed = this.closed;
  22708. data.curveType = this.curveType;
  22709. data.tension = this.tension;
  22710. return data;
  22711. };
  22712. CatmullRomCurve3.prototype.fromJSON = function (json) {
  22713. Curve.prototype.fromJSON.call(this, json);
  22714. this.points = [];
  22715. for (var i = 0, l = json.points.length; i < l; i++) {
  22716. var point = json.points[i];
  22717. this.points.push(new Vector3().fromArray(point));
  22718. }
  22719. this.closed = json.closed;
  22720. this.curveType = json.curveType;
  22721. this.tension = json.tension;
  22722. return this;
  22723. };
  22724. /**
  22725. * Bezier Curves formulas obtained from
  22726. * http://en.wikipedia.org/wiki/Bézier_curve
  22727. */
  22728. function CatmullRom(t, p0, p1, p2, p3) {
  22729. var v0 = (p2 - p0) * 0.5;
  22730. var v1 = (p3 - p1) * 0.5;
  22731. var t2 = t * t;
  22732. var t3 = t * t2;
  22733. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  22734. } //
  22735. function QuadraticBezierP0(t, p) {
  22736. var k = 1 - t;
  22737. return k * k * p;
  22738. }
  22739. function QuadraticBezierP1(t, p) {
  22740. return 2 * (1 - t) * t * p;
  22741. }
  22742. function QuadraticBezierP2(t, p) {
  22743. return t * t * p;
  22744. }
  22745. function QuadraticBezier(t, p0, p1, p2) {
  22746. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  22747. } //
  22748. function CubicBezierP0(t, p) {
  22749. var k = 1 - t;
  22750. return k * k * k * p;
  22751. }
  22752. function CubicBezierP1(t, p) {
  22753. var k = 1 - t;
  22754. return 3 * k * k * t * p;
  22755. }
  22756. function CubicBezierP2(t, p) {
  22757. return 3 * (1 - t) * t * t * p;
  22758. }
  22759. function CubicBezierP3(t, p) {
  22760. return t * t * t * p;
  22761. }
  22762. function CubicBezier(t, p0, p1, p2, p3) {
  22763. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  22764. }
  22765. function CubicBezierCurve(v0, v1, v2, v3) {
  22766. Curve.call(this);
  22767. this.type = 'CubicBezierCurve';
  22768. this.v0 = v0 || new Vector2();
  22769. this.v1 = v1 || new Vector2();
  22770. this.v2 = v2 || new Vector2();
  22771. this.v3 = v3 || new Vector2();
  22772. }
  22773. CubicBezierCurve.prototype = Object.create(Curve.prototype);
  22774. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  22775. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  22776. CubicBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22777. var point = optionalTarget || new Vector2();
  22778. var v0 = this.v0,
  22779. v1 = this.v1,
  22780. v2 = this.v2,
  22781. v3 = this.v3;
  22782. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  22783. return point;
  22784. };
  22785. CubicBezierCurve.prototype.copy = function (source) {
  22786. Curve.prototype.copy.call(this, source);
  22787. this.v0.copy(source.v0);
  22788. this.v1.copy(source.v1);
  22789. this.v2.copy(source.v2);
  22790. this.v3.copy(source.v3);
  22791. return this;
  22792. };
  22793. CubicBezierCurve.prototype.toJSON = function () {
  22794. var data = Curve.prototype.toJSON.call(this);
  22795. data.v0 = this.v0.toArray();
  22796. data.v1 = this.v1.toArray();
  22797. data.v2 = this.v2.toArray();
  22798. data.v3 = this.v3.toArray();
  22799. return data;
  22800. };
  22801. CubicBezierCurve.prototype.fromJSON = function (json) {
  22802. Curve.prototype.fromJSON.call(this, json);
  22803. this.v0.fromArray(json.v0);
  22804. this.v1.fromArray(json.v1);
  22805. this.v2.fromArray(json.v2);
  22806. this.v3.fromArray(json.v3);
  22807. return this;
  22808. };
  22809. function CubicBezierCurve3(v0, v1, v2, v3) {
  22810. Curve.call(this);
  22811. this.type = 'CubicBezierCurve3';
  22812. this.v0 = v0 || new Vector3();
  22813. this.v1 = v1 || new Vector3();
  22814. this.v2 = v2 || new Vector3();
  22815. this.v3 = v3 || new Vector3();
  22816. }
  22817. CubicBezierCurve3.prototype = Object.create(Curve.prototype);
  22818. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  22819. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  22820. CubicBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22821. var point = optionalTarget || new Vector3();
  22822. var v0 = this.v0,
  22823. v1 = this.v1,
  22824. v2 = this.v2,
  22825. v3 = this.v3;
  22826. 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));
  22827. return point;
  22828. };
  22829. CubicBezierCurve3.prototype.copy = function (source) {
  22830. Curve.prototype.copy.call(this, source);
  22831. this.v0.copy(source.v0);
  22832. this.v1.copy(source.v1);
  22833. this.v2.copy(source.v2);
  22834. this.v3.copy(source.v3);
  22835. return this;
  22836. };
  22837. CubicBezierCurve3.prototype.toJSON = function () {
  22838. var data = Curve.prototype.toJSON.call(this);
  22839. data.v0 = this.v0.toArray();
  22840. data.v1 = this.v1.toArray();
  22841. data.v2 = this.v2.toArray();
  22842. data.v3 = this.v3.toArray();
  22843. return data;
  22844. };
  22845. CubicBezierCurve3.prototype.fromJSON = function (json) {
  22846. Curve.prototype.fromJSON.call(this, json);
  22847. this.v0.fromArray(json.v0);
  22848. this.v1.fromArray(json.v1);
  22849. this.v2.fromArray(json.v2);
  22850. this.v3.fromArray(json.v3);
  22851. return this;
  22852. };
  22853. function LineCurve(v1, v2) {
  22854. Curve.call(this);
  22855. this.type = 'LineCurve';
  22856. this.v1 = v1 || new Vector2();
  22857. this.v2 = v2 || new Vector2();
  22858. }
  22859. LineCurve.prototype = Object.create(Curve.prototype);
  22860. LineCurve.prototype.constructor = LineCurve;
  22861. LineCurve.prototype.isLineCurve = true;
  22862. LineCurve.prototype.getPoint = function (t, optionalTarget) {
  22863. var point = optionalTarget || new Vector2();
  22864. if (t === 1) {
  22865. point.copy(this.v2);
  22866. } else {
  22867. point.copy(this.v2).sub(this.v1);
  22868. point.multiplyScalar(t).add(this.v1);
  22869. }
  22870. return point;
  22871. }; // Line curve is linear, so we can overwrite default getPointAt
  22872. LineCurve.prototype.getPointAt = function (u, optionalTarget) {
  22873. return this.getPoint(u, optionalTarget);
  22874. };
  22875. LineCurve.prototype.getTangent = function (t, optionalTarget) {
  22876. var tangent = optionalTarget || new Vector2();
  22877. tangent.copy(this.v2).sub(this.v1).normalize();
  22878. return tangent;
  22879. };
  22880. LineCurve.prototype.copy = function (source) {
  22881. Curve.prototype.copy.call(this, source);
  22882. this.v1.copy(source.v1);
  22883. this.v2.copy(source.v2);
  22884. return this;
  22885. };
  22886. LineCurve.prototype.toJSON = function () {
  22887. var data = Curve.prototype.toJSON.call(this);
  22888. data.v1 = this.v1.toArray();
  22889. data.v2 = this.v2.toArray();
  22890. return data;
  22891. };
  22892. LineCurve.prototype.fromJSON = function (json) {
  22893. Curve.prototype.fromJSON.call(this, json);
  22894. this.v1.fromArray(json.v1);
  22895. this.v2.fromArray(json.v2);
  22896. return this;
  22897. };
  22898. function LineCurve3(v1, v2) {
  22899. Curve.call(this);
  22900. this.type = 'LineCurve3';
  22901. this.v1 = v1 || new Vector3();
  22902. this.v2 = v2 || new Vector3();
  22903. }
  22904. LineCurve3.prototype = Object.create(Curve.prototype);
  22905. LineCurve3.prototype.constructor = LineCurve3;
  22906. LineCurve3.prototype.isLineCurve3 = true;
  22907. LineCurve3.prototype.getPoint = function (t, optionalTarget) {
  22908. var point = optionalTarget || new Vector3();
  22909. if (t === 1) {
  22910. point.copy(this.v2);
  22911. } else {
  22912. point.copy(this.v2).sub(this.v1);
  22913. point.multiplyScalar(t).add(this.v1);
  22914. }
  22915. return point;
  22916. }; // Line curve is linear, so we can overwrite default getPointAt
  22917. LineCurve3.prototype.getPointAt = function (u, optionalTarget) {
  22918. return this.getPoint(u, optionalTarget);
  22919. };
  22920. LineCurve3.prototype.copy = function (source) {
  22921. Curve.prototype.copy.call(this, source);
  22922. this.v1.copy(source.v1);
  22923. this.v2.copy(source.v2);
  22924. return this;
  22925. };
  22926. LineCurve3.prototype.toJSON = function () {
  22927. var data = Curve.prototype.toJSON.call(this);
  22928. data.v1 = this.v1.toArray();
  22929. data.v2 = this.v2.toArray();
  22930. return data;
  22931. };
  22932. LineCurve3.prototype.fromJSON = function (json) {
  22933. Curve.prototype.fromJSON.call(this, json);
  22934. this.v1.fromArray(json.v1);
  22935. this.v2.fromArray(json.v2);
  22936. return this;
  22937. };
  22938. function QuadraticBezierCurve(v0, v1, v2) {
  22939. Curve.call(this);
  22940. this.type = 'QuadraticBezierCurve';
  22941. this.v0 = v0 || new Vector2();
  22942. this.v1 = v1 || new Vector2();
  22943. this.v2 = v2 || new Vector2();
  22944. }
  22945. QuadraticBezierCurve.prototype = Object.create(Curve.prototype);
  22946. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  22947. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22948. QuadraticBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22949. var point = optionalTarget || new Vector2();
  22950. var v0 = this.v0,
  22951. v1 = this.v1,
  22952. v2 = this.v2;
  22953. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  22954. return point;
  22955. };
  22956. QuadraticBezierCurve.prototype.copy = function (source) {
  22957. Curve.prototype.copy.call(this, source);
  22958. this.v0.copy(source.v0);
  22959. this.v1.copy(source.v1);
  22960. this.v2.copy(source.v2);
  22961. return this;
  22962. };
  22963. QuadraticBezierCurve.prototype.toJSON = function () {
  22964. var data = Curve.prototype.toJSON.call(this);
  22965. data.v0 = this.v0.toArray();
  22966. data.v1 = this.v1.toArray();
  22967. data.v2 = this.v2.toArray();
  22968. return data;
  22969. };
  22970. QuadraticBezierCurve.prototype.fromJSON = function (json) {
  22971. Curve.prototype.fromJSON.call(this, json);
  22972. this.v0.fromArray(json.v0);
  22973. this.v1.fromArray(json.v1);
  22974. this.v2.fromArray(json.v2);
  22975. return this;
  22976. };
  22977. function QuadraticBezierCurve3(v0, v1, v2) {
  22978. Curve.call(this);
  22979. this.type = 'QuadraticBezierCurve3';
  22980. this.v0 = v0 || new Vector3();
  22981. this.v1 = v1 || new Vector3();
  22982. this.v2 = v2 || new Vector3();
  22983. }
  22984. QuadraticBezierCurve3.prototype = Object.create(Curve.prototype);
  22985. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22986. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22987. QuadraticBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22988. var point = optionalTarget || new Vector3();
  22989. var v0 = this.v0,
  22990. v1 = this.v1,
  22991. v2 = this.v2;
  22992. 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));
  22993. return point;
  22994. };
  22995. QuadraticBezierCurve3.prototype.copy = function (source) {
  22996. Curve.prototype.copy.call(this, source);
  22997. this.v0.copy(source.v0);
  22998. this.v1.copy(source.v1);
  22999. this.v2.copy(source.v2);
  23000. return this;
  23001. };
  23002. QuadraticBezierCurve3.prototype.toJSON = function () {
  23003. var data = Curve.prototype.toJSON.call(this);
  23004. data.v0 = this.v0.toArray();
  23005. data.v1 = this.v1.toArray();
  23006. data.v2 = this.v2.toArray();
  23007. return data;
  23008. };
  23009. QuadraticBezierCurve3.prototype.fromJSON = function (json) {
  23010. Curve.prototype.fromJSON.call(this, json);
  23011. this.v0.fromArray(json.v0);
  23012. this.v1.fromArray(json.v1);
  23013. this.v2.fromArray(json.v2);
  23014. return this;
  23015. };
  23016. function SplineCurve(points) {
  23017. Curve.call(this);
  23018. this.type = 'SplineCurve';
  23019. this.points = points || [];
  23020. }
  23021. SplineCurve.prototype = Object.create(Curve.prototype);
  23022. SplineCurve.prototype.constructor = SplineCurve;
  23023. SplineCurve.prototype.isSplineCurve = true;
  23024. SplineCurve.prototype.getPoint = function (t, optionalTarget) {
  23025. var point = optionalTarget || new Vector2();
  23026. var points = this.points;
  23027. var p = (points.length - 1) * t;
  23028. var intPoint = Math.floor(p);
  23029. var weight = p - intPoint;
  23030. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  23031. var p1 = points[intPoint];
  23032. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  23033. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  23034. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  23035. return point;
  23036. };
  23037. SplineCurve.prototype.copy = function (source) {
  23038. Curve.prototype.copy.call(this, source);
  23039. this.points = [];
  23040. for (var i = 0, l = source.points.length; i < l; i++) {
  23041. var point = source.points[i];
  23042. this.points.push(point.clone());
  23043. }
  23044. return this;
  23045. };
  23046. SplineCurve.prototype.toJSON = function () {
  23047. var data = Curve.prototype.toJSON.call(this);
  23048. data.points = [];
  23049. for (var i = 0, l = this.points.length; i < l; i++) {
  23050. var point = this.points[i];
  23051. data.points.push(point.toArray());
  23052. }
  23053. return data;
  23054. };
  23055. SplineCurve.prototype.fromJSON = function (json) {
  23056. Curve.prototype.fromJSON.call(this, json);
  23057. this.points = [];
  23058. for (var i = 0, l = json.points.length; i < l; i++) {
  23059. var point = json.points[i];
  23060. this.points.push(new Vector2().fromArray(point));
  23061. }
  23062. return this;
  23063. };
  23064. var Curves = /*#__PURE__*/Object.freeze({
  23065. __proto__: null,
  23066. ArcCurve: ArcCurve,
  23067. CatmullRomCurve3: CatmullRomCurve3,
  23068. CubicBezierCurve: CubicBezierCurve,
  23069. CubicBezierCurve3: CubicBezierCurve3,
  23070. EllipseCurve: EllipseCurve,
  23071. LineCurve: LineCurve,
  23072. LineCurve3: LineCurve3,
  23073. QuadraticBezierCurve: QuadraticBezierCurve,
  23074. QuadraticBezierCurve3: QuadraticBezierCurve3,
  23075. SplineCurve: SplineCurve
  23076. });
  23077. /**************************************************************
  23078. * Curved Path - a curve path is simply a array of connected
  23079. * curves, but retains the api of a curve
  23080. **************************************************************/
  23081. function CurvePath() {
  23082. Curve.call(this);
  23083. this.type = 'CurvePath';
  23084. this.curves = [];
  23085. this.autoClose = false; // Automatically closes the path
  23086. }
  23087. CurvePath.prototype = Object.assign(Object.create(Curve.prototype), {
  23088. constructor: CurvePath,
  23089. add: function add(curve) {
  23090. this.curves.push(curve);
  23091. },
  23092. closePath: function closePath() {
  23093. // Add a line curve if start and end of lines are not connected
  23094. var startPoint = this.curves[0].getPoint(0);
  23095. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  23096. if (!startPoint.equals(endPoint)) {
  23097. this.curves.push(new LineCurve(endPoint, startPoint));
  23098. }
  23099. },
  23100. // To get accurate point with reference to
  23101. // entire path distance at time t,
  23102. // following has to be done:
  23103. // 1. Length of each sub path have to be known
  23104. // 2. Locate and identify type of curve
  23105. // 3. Get t for the curve
  23106. // 4. Return curve.getPointAt(t')
  23107. getPoint: function getPoint(t) {
  23108. var d = t * this.getLength();
  23109. var curveLengths = this.getCurveLengths();
  23110. var i = 0; // To think about boundaries points.
  23111. while (i < curveLengths.length) {
  23112. if (curveLengths[i] >= d) {
  23113. var diff = curveLengths[i] - d;
  23114. var curve = this.curves[i];
  23115. var segmentLength = curve.getLength();
  23116. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  23117. return curve.getPointAt(u);
  23118. }
  23119. i++;
  23120. }
  23121. return null; // loop where sum != 0, sum > d , sum+1 <d
  23122. },
  23123. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  23124. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  23125. // getPoint() depends on getLength
  23126. getLength: function getLength() {
  23127. var lens = this.getCurveLengths();
  23128. return lens[lens.length - 1];
  23129. },
  23130. // cacheLengths must be recalculated.
  23131. updateArcLengths: function updateArcLengths() {
  23132. this.needsUpdate = true;
  23133. this.cacheLengths = null;
  23134. this.getCurveLengths();
  23135. },
  23136. // Compute lengths and cache them
  23137. // We cannot overwrite getLengths() because UtoT mapping uses it.
  23138. getCurveLengths: function getCurveLengths() {
  23139. // We use cache values if curves and cache array are same length
  23140. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  23141. return this.cacheLengths;
  23142. } // Get length of sub-curve
  23143. // Push sums into cached array
  23144. var lengths = [];
  23145. var sums = 0;
  23146. for (var i = 0, l = this.curves.length; i < l; i++) {
  23147. sums += this.curves[i].getLength();
  23148. lengths.push(sums);
  23149. }
  23150. this.cacheLengths = lengths;
  23151. return lengths;
  23152. },
  23153. getSpacedPoints: function getSpacedPoints(divisions) {
  23154. if (divisions === void 0) {
  23155. divisions = 40;
  23156. }
  23157. var points = [];
  23158. for (var i = 0; i <= divisions; i++) {
  23159. points.push(this.getPoint(i / divisions));
  23160. }
  23161. if (this.autoClose) {
  23162. points.push(points[0]);
  23163. }
  23164. return points;
  23165. },
  23166. getPoints: function getPoints(divisions) {
  23167. divisions = divisions || 12;
  23168. var points = [];
  23169. var last;
  23170. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  23171. var curve = curves[i];
  23172. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  23173. var pts = curve.getPoints(resolution);
  23174. for (var j = 0; j < pts.length; j++) {
  23175. var point = pts[j];
  23176. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  23177. points.push(point);
  23178. last = point;
  23179. }
  23180. }
  23181. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  23182. points.push(points[0]);
  23183. }
  23184. return points;
  23185. },
  23186. copy: function copy(source) {
  23187. Curve.prototype.copy.call(this, source);
  23188. this.curves = [];
  23189. for (var i = 0, l = source.curves.length; i < l; i++) {
  23190. var curve = source.curves[i];
  23191. this.curves.push(curve.clone());
  23192. }
  23193. this.autoClose = source.autoClose;
  23194. return this;
  23195. },
  23196. toJSON: function toJSON() {
  23197. var data = Curve.prototype.toJSON.call(this);
  23198. data.autoClose = this.autoClose;
  23199. data.curves = [];
  23200. for (var i = 0, l = this.curves.length; i < l; i++) {
  23201. var curve = this.curves[i];
  23202. data.curves.push(curve.toJSON());
  23203. }
  23204. return data;
  23205. },
  23206. fromJSON: function fromJSON(json) {
  23207. Curve.prototype.fromJSON.call(this, json);
  23208. this.autoClose = json.autoClose;
  23209. this.curves = [];
  23210. for (var i = 0, l = json.curves.length; i < l; i++) {
  23211. var curve = json.curves[i];
  23212. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  23213. }
  23214. return this;
  23215. }
  23216. });
  23217. function Path(points) {
  23218. CurvePath.call(this);
  23219. this.type = 'Path';
  23220. this.currentPoint = new Vector2();
  23221. if (points) {
  23222. this.setFromPoints(points);
  23223. }
  23224. }
  23225. Path.prototype = Object.assign(Object.create(CurvePath.prototype), {
  23226. constructor: Path,
  23227. setFromPoints: function setFromPoints(points) {
  23228. this.moveTo(points[0].x, points[0].y);
  23229. for (var i = 1, l = points.length; i < l; i++) {
  23230. this.lineTo(points[i].x, points[i].y);
  23231. }
  23232. return this;
  23233. },
  23234. moveTo: function moveTo(x, y) {
  23235. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  23236. return this;
  23237. },
  23238. lineTo: function lineTo(x, y) {
  23239. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  23240. this.curves.push(curve);
  23241. this.currentPoint.set(x, y);
  23242. return this;
  23243. },
  23244. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  23245. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  23246. this.curves.push(curve);
  23247. this.currentPoint.set(aX, aY);
  23248. return this;
  23249. },
  23250. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  23251. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  23252. this.curves.push(curve);
  23253. this.currentPoint.set(aX, aY);
  23254. return this;
  23255. },
  23256. splineThru: function splineThru(pts
  23257. /*Array of Vector*/
  23258. ) {
  23259. var npts = [this.currentPoint.clone()].concat(pts);
  23260. var curve = new SplineCurve(npts);
  23261. this.curves.push(curve);
  23262. this.currentPoint.copy(pts[pts.length - 1]);
  23263. return this;
  23264. },
  23265. arc: function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23266. var x0 = this.currentPoint.x;
  23267. var y0 = this.currentPoint.y;
  23268. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  23269. return this;
  23270. },
  23271. absarc: function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23272. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  23273. return this;
  23274. },
  23275. ellipse: function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23276. var x0 = this.currentPoint.x;
  23277. var y0 = this.currentPoint.y;
  23278. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23279. return this;
  23280. },
  23281. absellipse: function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23282. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23283. if (this.curves.length > 0) {
  23284. // if a previous curve is present, attempt to join
  23285. var firstPoint = curve.getPoint(0);
  23286. if (!firstPoint.equals(this.currentPoint)) {
  23287. this.lineTo(firstPoint.x, firstPoint.y);
  23288. }
  23289. }
  23290. this.curves.push(curve);
  23291. var lastPoint = curve.getPoint(1);
  23292. this.currentPoint.copy(lastPoint);
  23293. return this;
  23294. },
  23295. copy: function copy(source) {
  23296. CurvePath.prototype.copy.call(this, source);
  23297. this.currentPoint.copy(source.currentPoint);
  23298. return this;
  23299. },
  23300. toJSON: function toJSON() {
  23301. var data = CurvePath.prototype.toJSON.call(this);
  23302. data.currentPoint = this.currentPoint.toArray();
  23303. return data;
  23304. },
  23305. fromJSON: function fromJSON(json) {
  23306. CurvePath.prototype.fromJSON.call(this, json);
  23307. this.currentPoint.fromArray(json.currentPoint);
  23308. return this;
  23309. }
  23310. });
  23311. function Shape(points) {
  23312. Path.call(this, points);
  23313. this.uuid = MathUtils.generateUUID();
  23314. this.type = 'Shape';
  23315. this.holes = [];
  23316. }
  23317. Shape.prototype = Object.assign(Object.create(Path.prototype), {
  23318. constructor: Shape,
  23319. getPointsHoles: function getPointsHoles(divisions) {
  23320. var holesPts = [];
  23321. for (var i = 0, l = this.holes.length; i < l; i++) {
  23322. holesPts[i] = this.holes[i].getPoints(divisions);
  23323. }
  23324. return holesPts;
  23325. },
  23326. // get points of shape and holes (keypoints based on segments parameter)
  23327. extractPoints: function extractPoints(divisions) {
  23328. return {
  23329. shape: this.getPoints(divisions),
  23330. holes: this.getPointsHoles(divisions)
  23331. };
  23332. },
  23333. copy: function copy(source) {
  23334. Path.prototype.copy.call(this, source);
  23335. this.holes = [];
  23336. for (var i = 0, l = source.holes.length; i < l; i++) {
  23337. var hole = source.holes[i];
  23338. this.holes.push(hole.clone());
  23339. }
  23340. return this;
  23341. },
  23342. toJSON: function toJSON() {
  23343. var data = Path.prototype.toJSON.call(this);
  23344. data.uuid = this.uuid;
  23345. data.holes = [];
  23346. for (var i = 0, l = this.holes.length; i < l; i++) {
  23347. var hole = this.holes[i];
  23348. data.holes.push(hole.toJSON());
  23349. }
  23350. return data;
  23351. },
  23352. fromJSON: function fromJSON(json) {
  23353. Path.prototype.fromJSON.call(this, json);
  23354. this.uuid = json.uuid;
  23355. this.holes = [];
  23356. for (var i = 0, l = json.holes.length; i < l; i++) {
  23357. var hole = json.holes[i];
  23358. this.holes.push(new Path().fromJSON(hole));
  23359. }
  23360. return this;
  23361. }
  23362. });
  23363. function Light(color, intensity) {
  23364. Object3D.call(this);
  23365. this.type = 'Light';
  23366. this.color = new Color(color);
  23367. this.intensity = intensity !== undefined ? intensity : 1;
  23368. }
  23369. Light.prototype = Object.assign(Object.create(Object3D.prototype), {
  23370. constructor: Light,
  23371. isLight: true,
  23372. copy: function copy(source) {
  23373. Object3D.prototype.copy.call(this, source);
  23374. this.color.copy(source.color);
  23375. this.intensity = source.intensity;
  23376. return this;
  23377. },
  23378. toJSON: function toJSON(meta) {
  23379. var data = Object3D.prototype.toJSON.call(this, meta);
  23380. data.object.color = this.color.getHex();
  23381. data.object.intensity = this.intensity;
  23382. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23383. if (this.distance !== undefined) data.object.distance = this.distance;
  23384. if (this.angle !== undefined) data.object.angle = this.angle;
  23385. if (this.decay !== undefined) data.object.decay = this.decay;
  23386. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23387. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23388. return data;
  23389. }
  23390. });
  23391. function HemisphereLight(skyColor, groundColor, intensity) {
  23392. Light.call(this, skyColor, intensity);
  23393. this.type = 'HemisphereLight';
  23394. this.position.copy(Object3D.DefaultUp);
  23395. this.updateMatrix();
  23396. this.groundColor = new Color(groundColor);
  23397. }
  23398. HemisphereLight.prototype = Object.assign(Object.create(Light.prototype), {
  23399. constructor: HemisphereLight,
  23400. isHemisphereLight: true,
  23401. copy: function copy(source) {
  23402. Light.prototype.copy.call(this, source);
  23403. this.groundColor.copy(source.groundColor);
  23404. return this;
  23405. }
  23406. });
  23407. function LightShadow(camera) {
  23408. this.camera = camera;
  23409. this.bias = 0;
  23410. this.normalBias = 0;
  23411. this.radius = 1;
  23412. this.mapSize = new Vector2(512, 512);
  23413. this.map = null;
  23414. this.mapPass = null;
  23415. this.matrix = new Matrix4();
  23416. this.autoUpdate = true;
  23417. this.needsUpdate = false;
  23418. this._frustum = new Frustum();
  23419. this._frameExtents = new Vector2(1, 1);
  23420. this._viewportCount = 1;
  23421. this._viewports = [new Vector4(0, 0, 1, 1)];
  23422. }
  23423. Object.assign(LightShadow.prototype, {
  23424. _projScreenMatrix: new Matrix4(),
  23425. _lightPositionWorld: new Vector3(),
  23426. _lookTarget: new Vector3(),
  23427. getViewportCount: function getViewportCount() {
  23428. return this._viewportCount;
  23429. },
  23430. getFrustum: function getFrustum() {
  23431. return this._frustum;
  23432. },
  23433. updateMatrices: function updateMatrices(light) {
  23434. var shadowCamera = this.camera,
  23435. shadowMatrix = this.matrix,
  23436. projScreenMatrix = this._projScreenMatrix,
  23437. lookTarget = this._lookTarget,
  23438. lightPositionWorld = this._lightPositionWorld;
  23439. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23440. shadowCamera.position.copy(lightPositionWorld);
  23441. lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23442. shadowCamera.lookAt(lookTarget);
  23443. shadowCamera.updateMatrixWorld();
  23444. projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23445. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23446. 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);
  23447. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23448. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23449. },
  23450. getViewport: function getViewport(viewportIndex) {
  23451. return this._viewports[viewportIndex];
  23452. },
  23453. getFrameExtents: function getFrameExtents() {
  23454. return this._frameExtents;
  23455. },
  23456. copy: function copy(source) {
  23457. this.camera = source.camera.clone();
  23458. this.bias = source.bias;
  23459. this.radius = source.radius;
  23460. this.mapSize.copy(source.mapSize);
  23461. return this;
  23462. },
  23463. clone: function clone() {
  23464. return new this.constructor().copy(this);
  23465. },
  23466. toJSON: function toJSON() {
  23467. var object = {};
  23468. if (this.bias !== 0) object.bias = this.bias;
  23469. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23470. if (this.radius !== 1) object.radius = this.radius;
  23471. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23472. object.camera = this.camera.toJSON(false).object;
  23473. delete object.camera.matrix;
  23474. return object;
  23475. }
  23476. });
  23477. function SpotLightShadow() {
  23478. LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500));
  23479. this.focus = 1;
  23480. }
  23481. SpotLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23482. constructor: SpotLightShadow,
  23483. isSpotLightShadow: true,
  23484. updateMatrices: function updateMatrices(light) {
  23485. var camera = this.camera;
  23486. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23487. var aspect = this.mapSize.width / this.mapSize.height;
  23488. var far = light.distance || camera.far;
  23489. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23490. camera.fov = fov;
  23491. camera.aspect = aspect;
  23492. camera.far = far;
  23493. camera.updateProjectionMatrix();
  23494. }
  23495. LightShadow.prototype.updateMatrices.call(this, light);
  23496. }
  23497. });
  23498. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23499. Light.call(this, color, intensity);
  23500. this.type = 'SpotLight';
  23501. this.position.copy(Object3D.DefaultUp);
  23502. this.updateMatrix();
  23503. this.target = new Object3D();
  23504. Object.defineProperty(this, 'power', {
  23505. get: function get() {
  23506. // intensity = power per solid angle.
  23507. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23508. return this.intensity * Math.PI;
  23509. },
  23510. set: function set(power) {
  23511. // intensity = power per solid angle.
  23512. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23513. this.intensity = power / Math.PI;
  23514. }
  23515. });
  23516. this.distance = distance !== undefined ? distance : 0;
  23517. this.angle = angle !== undefined ? angle : Math.PI / 3;
  23518. this.penumbra = penumbra !== undefined ? penumbra : 0;
  23519. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23520. this.shadow = new SpotLightShadow();
  23521. }
  23522. SpotLight.prototype = Object.assign(Object.create(Light.prototype), {
  23523. constructor: SpotLight,
  23524. isSpotLight: true,
  23525. copy: function copy(source) {
  23526. Light.prototype.copy.call(this, source);
  23527. this.distance = source.distance;
  23528. this.angle = source.angle;
  23529. this.penumbra = source.penumbra;
  23530. this.decay = source.decay;
  23531. this.target = source.target.clone();
  23532. this.shadow = source.shadow.clone();
  23533. return this;
  23534. }
  23535. });
  23536. function PointLightShadow() {
  23537. LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500));
  23538. this._frameExtents = new Vector2(4, 2);
  23539. this._viewportCount = 6;
  23540. this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23541. // following orientation:
  23542. //
  23543. // xzXZ
  23544. // y Y
  23545. //
  23546. // X - Positive x direction
  23547. // x - Negative x direction
  23548. // Y - Positive y direction
  23549. // y - Negative y direction
  23550. // Z - Positive z direction
  23551. // z - Negative z direction
  23552. // positive X
  23553. new Vector4(2, 1, 1, 1), // negative X
  23554. new Vector4(0, 1, 1, 1), // positive Z
  23555. new Vector4(3, 1, 1, 1), // negative Z
  23556. new Vector4(1, 1, 1, 1), // positive Y
  23557. new Vector4(3, 0, 1, 1), // negative Y
  23558. new Vector4(1, 0, 1, 1)];
  23559. 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)];
  23560. 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)];
  23561. }
  23562. PointLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23563. constructor: PointLightShadow,
  23564. isPointLightShadow: true,
  23565. updateMatrices: function updateMatrices(light, viewportIndex) {
  23566. if (viewportIndex === void 0) {
  23567. viewportIndex = 0;
  23568. }
  23569. var camera = this.camera,
  23570. shadowMatrix = this.matrix,
  23571. lightPositionWorld = this._lightPositionWorld,
  23572. lookTarget = this._lookTarget,
  23573. projScreenMatrix = this._projScreenMatrix;
  23574. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23575. camera.position.copy(lightPositionWorld);
  23576. lookTarget.copy(camera.position);
  23577. lookTarget.add(this._cubeDirections[viewportIndex]);
  23578. camera.up.copy(this._cubeUps[viewportIndex]);
  23579. camera.lookAt(lookTarget);
  23580. camera.updateMatrixWorld();
  23581. shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
  23582. projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  23583. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23584. }
  23585. });
  23586. function PointLight(color, intensity, distance, decay) {
  23587. Light.call(this, color, intensity);
  23588. this.type = 'PointLight';
  23589. Object.defineProperty(this, 'power', {
  23590. get: function get() {
  23591. // intensity = power per solid angle.
  23592. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23593. return this.intensity * 4 * Math.PI;
  23594. },
  23595. set: function set(power) {
  23596. // intensity = power per solid angle.
  23597. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23598. this.intensity = power / (4 * Math.PI);
  23599. }
  23600. });
  23601. this.distance = distance !== undefined ? distance : 0;
  23602. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23603. this.shadow = new PointLightShadow();
  23604. }
  23605. PointLight.prototype = Object.assign(Object.create(Light.prototype), {
  23606. constructor: PointLight,
  23607. isPointLight: true,
  23608. copy: function copy(source) {
  23609. Light.prototype.copy.call(this, source);
  23610. this.distance = source.distance;
  23611. this.decay = source.decay;
  23612. this.shadow = source.shadow.clone();
  23613. return this;
  23614. }
  23615. });
  23616. function OrthographicCamera(left, right, top, bottom, near, far) {
  23617. Camera.call(this);
  23618. this.type = 'OrthographicCamera';
  23619. this.zoom = 1;
  23620. this.view = null;
  23621. this.left = left !== undefined ? left : -1;
  23622. this.right = right !== undefined ? right : 1;
  23623. this.top = top !== undefined ? top : 1;
  23624. this.bottom = bottom !== undefined ? bottom : -1;
  23625. this.near = near !== undefined ? near : 0.1;
  23626. this.far = far !== undefined ? far : 2000;
  23627. this.updateProjectionMatrix();
  23628. }
  23629. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  23630. constructor: OrthographicCamera,
  23631. isOrthographicCamera: true,
  23632. copy: function copy(source, recursive) {
  23633. Camera.prototype.copy.call(this, source, recursive);
  23634. this.left = source.left;
  23635. this.right = source.right;
  23636. this.top = source.top;
  23637. this.bottom = source.bottom;
  23638. this.near = source.near;
  23639. this.far = source.far;
  23640. this.zoom = source.zoom;
  23641. this.view = source.view === null ? null : Object.assign({}, source.view);
  23642. return this;
  23643. },
  23644. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  23645. if (this.view === null) {
  23646. this.view = {
  23647. enabled: true,
  23648. fullWidth: 1,
  23649. fullHeight: 1,
  23650. offsetX: 0,
  23651. offsetY: 0,
  23652. width: 1,
  23653. height: 1
  23654. };
  23655. }
  23656. this.view.enabled = true;
  23657. this.view.fullWidth = fullWidth;
  23658. this.view.fullHeight = fullHeight;
  23659. this.view.offsetX = x;
  23660. this.view.offsetY = y;
  23661. this.view.width = width;
  23662. this.view.height = height;
  23663. this.updateProjectionMatrix();
  23664. },
  23665. clearViewOffset: function clearViewOffset() {
  23666. if (this.view !== null) {
  23667. this.view.enabled = false;
  23668. }
  23669. this.updateProjectionMatrix();
  23670. },
  23671. updateProjectionMatrix: function updateProjectionMatrix() {
  23672. var dx = (this.right - this.left) / (2 * this.zoom);
  23673. var dy = (this.top - this.bottom) / (2 * this.zoom);
  23674. var cx = (this.right + this.left) / 2;
  23675. var cy = (this.top + this.bottom) / 2;
  23676. var left = cx - dx;
  23677. var right = cx + dx;
  23678. var top = cy + dy;
  23679. var bottom = cy - dy;
  23680. if (this.view !== null && this.view.enabled) {
  23681. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  23682. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  23683. left += scaleW * this.view.offsetX;
  23684. right = left + scaleW * this.view.width;
  23685. top -= scaleH * this.view.offsetY;
  23686. bottom = top - scaleH * this.view.height;
  23687. }
  23688. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  23689. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  23690. },
  23691. toJSON: function toJSON(meta) {
  23692. var data = Object3D.prototype.toJSON.call(this, meta);
  23693. data.object.zoom = this.zoom;
  23694. data.object.left = this.left;
  23695. data.object.right = this.right;
  23696. data.object.top = this.top;
  23697. data.object.bottom = this.bottom;
  23698. data.object.near = this.near;
  23699. data.object.far = this.far;
  23700. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  23701. return data;
  23702. }
  23703. });
  23704. function DirectionalLightShadow() {
  23705. LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
  23706. }
  23707. DirectionalLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23708. constructor: DirectionalLightShadow,
  23709. isDirectionalLightShadow: true,
  23710. updateMatrices: function updateMatrices(light) {
  23711. LightShadow.prototype.updateMatrices.call(this, light);
  23712. }
  23713. });
  23714. function DirectionalLight(color, intensity) {
  23715. Light.call(this, color, intensity);
  23716. this.type = 'DirectionalLight';
  23717. this.position.copy(Object3D.DefaultUp);
  23718. this.updateMatrix();
  23719. this.target = new Object3D();
  23720. this.shadow = new DirectionalLightShadow();
  23721. }
  23722. DirectionalLight.prototype = Object.assign(Object.create(Light.prototype), {
  23723. constructor: DirectionalLight,
  23724. isDirectionalLight: true,
  23725. copy: function copy(source) {
  23726. Light.prototype.copy.call(this, source);
  23727. this.target = source.target.clone();
  23728. this.shadow = source.shadow.clone();
  23729. return this;
  23730. }
  23731. });
  23732. function AmbientLight(color, intensity) {
  23733. Light.call(this, color, intensity);
  23734. this.type = 'AmbientLight';
  23735. }
  23736. AmbientLight.prototype = Object.assign(Object.create(Light.prototype), {
  23737. constructor: AmbientLight,
  23738. isAmbientLight: true
  23739. });
  23740. function RectAreaLight(color, intensity, width, height) {
  23741. Light.call(this, color, intensity);
  23742. this.type = 'RectAreaLight';
  23743. this.width = width !== undefined ? width : 10;
  23744. this.height = height !== undefined ? height : 10;
  23745. }
  23746. RectAreaLight.prototype = Object.assign(Object.create(Light.prototype), {
  23747. constructor: RectAreaLight,
  23748. isRectAreaLight: true,
  23749. copy: function copy(source) {
  23750. Light.prototype.copy.call(this, source);
  23751. this.width = source.width;
  23752. this.height = source.height;
  23753. return this;
  23754. },
  23755. toJSON: function toJSON(meta) {
  23756. var data = Light.prototype.toJSON.call(this, meta);
  23757. data.object.width = this.width;
  23758. data.object.height = this.height;
  23759. return data;
  23760. }
  23761. });
  23762. /**
  23763. * Primary reference:
  23764. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23765. *
  23766. * Secondary reference:
  23767. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23768. */
  23769. // 3-band SH defined by 9 coefficients
  23770. var SphericalHarmonics3 = /*#__PURE__*/function () {
  23771. function SphericalHarmonics3() {
  23772. Object.defineProperty(this, 'isSphericalHarmonics3', {
  23773. value: true
  23774. });
  23775. this.coefficients = [];
  23776. for (var i = 0; i < 9; i++) {
  23777. this.coefficients.push(new Vector3());
  23778. }
  23779. }
  23780. var _proto = SphericalHarmonics3.prototype;
  23781. _proto.set = function set(coefficients) {
  23782. for (var i = 0; i < 9; i++) {
  23783. this.coefficients[i].copy(coefficients[i]);
  23784. }
  23785. return this;
  23786. };
  23787. _proto.zero = function zero() {
  23788. for (var i = 0; i < 9; i++) {
  23789. this.coefficients[i].set(0, 0, 0);
  23790. }
  23791. return this;
  23792. } // get the radiance in the direction of the normal
  23793. // target is a Vector3
  23794. ;
  23795. _proto.getAt = function getAt(normal, target) {
  23796. // normal is assumed to be unit length
  23797. var x = normal.x,
  23798. y = normal.y,
  23799. z = normal.z;
  23800. var coeff = this.coefficients; // band 0
  23801. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  23802. target.addScaledVector(coeff[1], 0.488603 * y);
  23803. target.addScaledVector(coeff[2], 0.488603 * z);
  23804. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  23805. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  23806. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  23807. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  23808. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  23809. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  23810. return target;
  23811. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23812. // target is a Vector3
  23813. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23814. ;
  23815. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  23816. // normal is assumed to be unit length
  23817. var x = normal.x,
  23818. y = normal.y,
  23819. z = normal.z;
  23820. var coeff = this.coefficients; // band 0
  23821. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  23822. // band 1
  23823. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  23824. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  23825. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  23826. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  23827. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  23828. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  23829. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  23830. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  23831. return target;
  23832. };
  23833. _proto.add = function add(sh) {
  23834. for (var i = 0; i < 9; i++) {
  23835. this.coefficients[i].add(sh.coefficients[i]);
  23836. }
  23837. return this;
  23838. };
  23839. _proto.addScaledSH = function addScaledSH(sh, s) {
  23840. for (var i = 0; i < 9; i++) {
  23841. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  23842. }
  23843. return this;
  23844. };
  23845. _proto.scale = function scale(s) {
  23846. for (var i = 0; i < 9; i++) {
  23847. this.coefficients[i].multiplyScalar(s);
  23848. }
  23849. return this;
  23850. };
  23851. _proto.lerp = function lerp(sh, alpha) {
  23852. for (var i = 0; i < 9; i++) {
  23853. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  23854. }
  23855. return this;
  23856. };
  23857. _proto.equals = function equals(sh) {
  23858. for (var i = 0; i < 9; i++) {
  23859. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  23860. return false;
  23861. }
  23862. }
  23863. return true;
  23864. };
  23865. _proto.copy = function copy(sh) {
  23866. return this.set(sh.coefficients);
  23867. };
  23868. _proto.clone = function clone() {
  23869. return new this.constructor().copy(this);
  23870. };
  23871. _proto.fromArray = function fromArray(array, offset) {
  23872. if (offset === void 0) {
  23873. offset = 0;
  23874. }
  23875. var coefficients = this.coefficients;
  23876. for (var i = 0; i < 9; i++) {
  23877. coefficients[i].fromArray(array, offset + i * 3);
  23878. }
  23879. return this;
  23880. };
  23881. _proto.toArray = function toArray(array, offset) {
  23882. if (array === void 0) {
  23883. array = [];
  23884. }
  23885. if (offset === void 0) {
  23886. offset = 0;
  23887. }
  23888. var coefficients = this.coefficients;
  23889. for (var i = 0; i < 9; i++) {
  23890. coefficients[i].toArray(array, offset + i * 3);
  23891. }
  23892. return array;
  23893. } // evaluate the basis functions
  23894. // shBasis is an Array[ 9 ]
  23895. ;
  23896. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  23897. // normal is assumed to be unit length
  23898. var x = normal.x,
  23899. y = normal.y,
  23900. z = normal.z; // band 0
  23901. shBasis[0] = 0.282095; // band 1
  23902. shBasis[1] = 0.488603 * y;
  23903. shBasis[2] = 0.488603 * z;
  23904. shBasis[3] = 0.488603 * x; // band 2
  23905. shBasis[4] = 1.092548 * x * y;
  23906. shBasis[5] = 1.092548 * y * z;
  23907. shBasis[6] = 0.315392 * (3 * z * z - 1);
  23908. shBasis[7] = 1.092548 * x * z;
  23909. shBasis[8] = 0.546274 * (x * x - y * y);
  23910. };
  23911. return SphericalHarmonics3;
  23912. }();
  23913. function LightProbe(sh, intensity) {
  23914. Light.call(this, undefined, intensity);
  23915. this.type = 'LightProbe';
  23916. this.sh = sh !== undefined ? sh : new SphericalHarmonics3();
  23917. }
  23918. LightProbe.prototype = Object.assign(Object.create(Light.prototype), {
  23919. constructor: LightProbe,
  23920. isLightProbe: true,
  23921. copy: function copy(source) {
  23922. Light.prototype.copy.call(this, source);
  23923. this.sh.copy(source.sh);
  23924. return this;
  23925. },
  23926. fromJSON: function fromJSON(json) {
  23927. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  23928. this.sh.fromArray(json.sh);
  23929. return this;
  23930. },
  23931. toJSON: function toJSON(meta) {
  23932. var data = Light.prototype.toJSON.call(this, meta);
  23933. data.object.sh = this.sh.toArray();
  23934. return data;
  23935. }
  23936. });
  23937. function MaterialLoader(manager) {
  23938. Loader.call(this, manager);
  23939. this.textures = {};
  23940. }
  23941. MaterialLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  23942. constructor: MaterialLoader,
  23943. load: function load(url, onLoad, onProgress, onError) {
  23944. var scope = this;
  23945. var loader = new FileLoader(scope.manager);
  23946. loader.setPath(scope.path);
  23947. loader.setRequestHeader(scope.requestHeader);
  23948. loader.setWithCredentials(scope.withCredentials);
  23949. loader.load(url, function (text) {
  23950. try {
  23951. onLoad(scope.parse(JSON.parse(text)));
  23952. } catch (e) {
  23953. if (onError) {
  23954. onError(e);
  23955. } else {
  23956. console.error(e);
  23957. }
  23958. scope.manager.itemError(url);
  23959. }
  23960. }, onProgress, onError);
  23961. },
  23962. parse: function parse(json) {
  23963. var textures = this.textures;
  23964. function getTexture(name) {
  23965. if (textures[name] === undefined) {
  23966. console.warn('THREE.MaterialLoader: Undefined texture', name);
  23967. }
  23968. return textures[name];
  23969. }
  23970. var material = new Materials[json.type]();
  23971. if (json.uuid !== undefined) material.uuid = json.uuid;
  23972. if (json.name !== undefined) material.name = json.name;
  23973. if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
  23974. if (json.roughness !== undefined) material.roughness = json.roughness;
  23975. if (json.metalness !== undefined) material.metalness = json.metalness;
  23976. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  23977. if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
  23978. if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
  23979. if (json.shininess !== undefined) material.shininess = json.shininess;
  23980. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  23981. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  23982. if (json.fog !== undefined) material.fog = json.fog;
  23983. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  23984. if (json.blending !== undefined) material.blending = json.blending;
  23985. if (json.combine !== undefined) material.combine = json.combine;
  23986. if (json.side !== undefined) material.side = json.side;
  23987. if (json.opacity !== undefined) material.opacity = json.opacity;
  23988. if (json.transparent !== undefined) material.transparent = json.transparent;
  23989. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  23990. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  23991. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  23992. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  23993. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  23994. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  23995. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  23996. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  23997. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  23998. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  23999. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  24000. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  24001. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  24002. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  24003. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  24004. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  24005. if (json.rotation !== undefined) material.rotation = json.rotation;
  24006. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  24007. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  24008. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  24009. if (json.scale !== undefined) material.scale = json.scale;
  24010. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  24011. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  24012. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  24013. if (json.skinning !== undefined) material.skinning = json.skinning;
  24014. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  24015. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  24016. if (json.dithering !== undefined) material.dithering = json.dithering;
  24017. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  24018. if (json.visible !== undefined) material.visible = json.visible;
  24019. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  24020. if (json.userData !== undefined) material.userData = json.userData;
  24021. if (json.vertexColors !== undefined) {
  24022. if (typeof json.vertexColors === 'number') {
  24023. material.vertexColors = json.vertexColors > 0 ? true : false;
  24024. } else {
  24025. material.vertexColors = json.vertexColors;
  24026. }
  24027. } // Shader Material
  24028. if (json.uniforms !== undefined) {
  24029. for (var name in json.uniforms) {
  24030. var uniform = json.uniforms[name];
  24031. material.uniforms[name] = {};
  24032. switch (uniform.type) {
  24033. case 't':
  24034. material.uniforms[name].value = getTexture(uniform.value);
  24035. break;
  24036. case 'c':
  24037. material.uniforms[name].value = new Color().setHex(uniform.value);
  24038. break;
  24039. case 'v2':
  24040. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  24041. break;
  24042. case 'v3':
  24043. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  24044. break;
  24045. case 'v4':
  24046. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  24047. break;
  24048. case 'm3':
  24049. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  24050. break;
  24051. case 'm4':
  24052. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  24053. break;
  24054. default:
  24055. material.uniforms[name].value = uniform.value;
  24056. }
  24057. }
  24058. }
  24059. if (json.defines !== undefined) material.defines = json.defines;
  24060. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  24061. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  24062. if (json.extensions !== undefined) {
  24063. for (var key in json.extensions) {
  24064. material.extensions[key] = json.extensions[key];
  24065. }
  24066. } // Deprecated
  24067. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  24068. // for PointsMaterial
  24069. if (json.size !== undefined) material.size = json.size;
  24070. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  24071. if (json.map !== undefined) material.map = getTexture(json.map);
  24072. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  24073. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  24074. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  24075. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  24076. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  24077. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  24078. if (json.normalScale !== undefined) {
  24079. var normalScale = json.normalScale;
  24080. if (Array.isArray(normalScale) === false) {
  24081. // Blender exporter used to export a scalar. See #7459
  24082. normalScale = [normalScale, normalScale];
  24083. }
  24084. material.normalScale = new Vector2().fromArray(normalScale);
  24085. }
  24086. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  24087. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  24088. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  24089. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  24090. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  24091. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  24092. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  24093. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  24094. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  24095. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  24096. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  24097. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  24098. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  24099. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  24100. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  24101. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  24102. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  24103. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  24104. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  24105. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  24106. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  24107. if (json.transmission !== undefined) material.transmission = json.transmission;
  24108. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  24109. return material;
  24110. },
  24111. setTextures: function setTextures(value) {
  24112. this.textures = value;
  24113. return this;
  24114. }
  24115. });
  24116. var LoaderUtils = {
  24117. decodeText: function decodeText(array) {
  24118. if (typeof TextDecoder !== 'undefined') {
  24119. return new TextDecoder().decode(array);
  24120. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  24121. // throws a "maximum call stack size exceeded" error for large arrays.
  24122. var s = '';
  24123. for (var i = 0, il = array.length; i < il; i++) {
  24124. // Implicitly assumes little-endian.
  24125. s += String.fromCharCode(array[i]);
  24126. }
  24127. try {
  24128. // merges multi-byte utf-8 characters.
  24129. return decodeURIComponent(escape(s));
  24130. } catch (e) {
  24131. // see #16358
  24132. return s;
  24133. }
  24134. },
  24135. extractUrlBase: function extractUrlBase(url) {
  24136. var index = url.lastIndexOf('/');
  24137. if (index === -1) return './';
  24138. return url.substr(0, index + 1);
  24139. }
  24140. };
  24141. function InstancedBufferGeometry() {
  24142. BufferGeometry.call(this);
  24143. this.type = 'InstancedBufferGeometry';
  24144. this.instanceCount = Infinity;
  24145. }
  24146. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  24147. constructor: InstancedBufferGeometry,
  24148. isInstancedBufferGeometry: true,
  24149. copy: function copy(source) {
  24150. BufferGeometry.prototype.copy.call(this, source);
  24151. this.instanceCount = source.instanceCount;
  24152. return this;
  24153. },
  24154. clone: function clone() {
  24155. return new this.constructor().copy(this);
  24156. },
  24157. toJSON: function toJSON() {
  24158. var data = BufferGeometry.prototype.toJSON.call(this);
  24159. data.instanceCount = this.instanceCount;
  24160. data.isInstancedBufferGeometry = true;
  24161. return data;
  24162. }
  24163. });
  24164. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  24165. if (typeof normalized === 'number') {
  24166. meshPerAttribute = normalized;
  24167. normalized = false;
  24168. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  24169. }
  24170. BufferAttribute.call(this, array, itemSize, normalized);
  24171. this.meshPerAttribute = meshPerAttribute || 1;
  24172. }
  24173. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  24174. constructor: InstancedBufferAttribute,
  24175. isInstancedBufferAttribute: true,
  24176. copy: function copy(source) {
  24177. BufferAttribute.prototype.copy.call(this, source);
  24178. this.meshPerAttribute = source.meshPerAttribute;
  24179. return this;
  24180. },
  24181. toJSON: function toJSON() {
  24182. var data = BufferAttribute.prototype.toJSON.call(this);
  24183. data.meshPerAttribute = this.meshPerAttribute;
  24184. data.isInstancedBufferAttribute = true;
  24185. return data;
  24186. }
  24187. });
  24188. function BufferGeometryLoader(manager) {
  24189. Loader.call(this, manager);
  24190. }
  24191. BufferGeometryLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24192. constructor: BufferGeometryLoader,
  24193. load: function load(url, onLoad, onProgress, onError) {
  24194. var scope = this;
  24195. var loader = new FileLoader(scope.manager);
  24196. loader.setPath(scope.path);
  24197. loader.setRequestHeader(scope.requestHeader);
  24198. loader.setWithCredentials(scope.withCredentials);
  24199. loader.load(url, function (text) {
  24200. try {
  24201. onLoad(scope.parse(JSON.parse(text)));
  24202. } catch (e) {
  24203. if (onError) {
  24204. onError(e);
  24205. } else {
  24206. console.error(e);
  24207. }
  24208. scope.manager.itemError(url);
  24209. }
  24210. }, onProgress, onError);
  24211. },
  24212. parse: function parse(json) {
  24213. var interleavedBufferMap = {};
  24214. var arrayBufferMap = {};
  24215. function getInterleavedBuffer(json, uuid) {
  24216. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  24217. var interleavedBuffers = json.interleavedBuffers;
  24218. var interleavedBuffer = interleavedBuffers[uuid];
  24219. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  24220. var array = getTypedArray(interleavedBuffer.type, buffer);
  24221. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  24222. ib.uuid = interleavedBuffer.uuid;
  24223. interleavedBufferMap[uuid] = ib;
  24224. return ib;
  24225. }
  24226. function getArrayBuffer(json, uuid) {
  24227. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  24228. var arrayBuffers = json.arrayBuffers;
  24229. var arrayBuffer = arrayBuffers[uuid];
  24230. var ab = new Uint32Array(arrayBuffer).buffer;
  24231. arrayBufferMap[uuid] = ab;
  24232. return ab;
  24233. }
  24234. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24235. var index = json.data.index;
  24236. if (index !== undefined) {
  24237. var typedArray = getTypedArray(index.type, index.array);
  24238. geometry.setIndex(new BufferAttribute(typedArray, 1));
  24239. }
  24240. var attributes = json.data.attributes;
  24241. for (var key in attributes) {
  24242. var attribute = attributes[key];
  24243. var bufferAttribute = void 0;
  24244. if (attribute.isInterleavedBufferAttribute) {
  24245. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  24246. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  24247. } else {
  24248. var _typedArray = getTypedArray(attribute.type, attribute.array);
  24249. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24250. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  24251. }
  24252. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  24253. geometry.setAttribute(key, bufferAttribute);
  24254. }
  24255. var morphAttributes = json.data.morphAttributes;
  24256. if (morphAttributes) {
  24257. for (var _key in morphAttributes) {
  24258. var attributeArray = morphAttributes[_key];
  24259. var array = [];
  24260. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24261. var _attribute = attributeArray[i];
  24262. var _bufferAttribute = void 0;
  24263. if (_attribute.isInterleavedBufferAttribute) {
  24264. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24265. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24266. } else {
  24267. var _typedArray2 = getTypedArray(_attribute.type, _attribute.array);
  24268. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24269. }
  24270. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24271. array.push(_bufferAttribute);
  24272. }
  24273. geometry.morphAttributes[_key] = array;
  24274. }
  24275. }
  24276. var morphTargetsRelative = json.data.morphTargetsRelative;
  24277. if (morphTargetsRelative) {
  24278. geometry.morphTargetsRelative = true;
  24279. }
  24280. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24281. if (groups !== undefined) {
  24282. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24283. var group = groups[_i];
  24284. geometry.addGroup(group.start, group.count, group.materialIndex);
  24285. }
  24286. }
  24287. var boundingSphere = json.data.boundingSphere;
  24288. if (boundingSphere !== undefined) {
  24289. var center = new Vector3();
  24290. if (boundingSphere.center !== undefined) {
  24291. center.fromArray(boundingSphere.center);
  24292. }
  24293. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24294. }
  24295. if (json.name) geometry.name = json.name;
  24296. if (json.userData) geometry.userData = json.userData;
  24297. return geometry;
  24298. }
  24299. });
  24300. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24301. _inheritsLoose(ObjectLoader, _Loader);
  24302. function ObjectLoader(manager) {
  24303. return _Loader.call(this, manager) || this;
  24304. }
  24305. var _proto = ObjectLoader.prototype;
  24306. _proto.load = function load(url, onLoad, onProgress, onError) {
  24307. var scope = this;
  24308. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24309. this.resourcePath = this.resourcePath || path;
  24310. var loader = new FileLoader(this.manager);
  24311. loader.setPath(this.path);
  24312. loader.setRequestHeader(this.requestHeader);
  24313. loader.setWithCredentials(this.withCredentials);
  24314. loader.load(url, function (text) {
  24315. var json = null;
  24316. try {
  24317. json = JSON.parse(text);
  24318. } catch (error) {
  24319. if (onError !== undefined) onError(error);
  24320. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24321. return;
  24322. }
  24323. var metadata = json.metadata;
  24324. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24325. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24326. return;
  24327. }
  24328. scope.parse(json, onLoad);
  24329. }, onProgress, onError);
  24330. };
  24331. _proto.parse = function parse(json, onLoad) {
  24332. var shapes = this.parseShapes(json.shapes);
  24333. var geometries = this.parseGeometries(json.geometries, shapes);
  24334. var images = this.parseImages(json.images, function () {
  24335. if (onLoad !== undefined) onLoad(object);
  24336. });
  24337. var textures = this.parseTextures(json.textures, images);
  24338. var materials = this.parseMaterials(json.materials, textures);
  24339. var object = this.parseObject(json.object, geometries, materials);
  24340. var skeletons = this.parseSkeletons(json.skeletons, object);
  24341. this.bindSkeletons(object, skeletons);
  24342. if (json.animations) {
  24343. object.animations = this.parseAnimations(json.animations);
  24344. } //
  24345. if (onLoad !== undefined) {
  24346. var hasImages = false;
  24347. for (var uuid in images) {
  24348. if (images[uuid] instanceof HTMLImageElement) {
  24349. hasImages = true;
  24350. break;
  24351. }
  24352. }
  24353. if (hasImages === false) onLoad(object);
  24354. }
  24355. return object;
  24356. };
  24357. _proto.parseShapes = function parseShapes(json) {
  24358. var shapes = {};
  24359. if (json !== undefined) {
  24360. for (var i = 0, l = json.length; i < l; i++) {
  24361. var shape = new Shape().fromJSON(json[i]);
  24362. shapes[shape.uuid] = shape;
  24363. }
  24364. }
  24365. return shapes;
  24366. };
  24367. _proto.parseSkeletons = function parseSkeletons(json, object) {
  24368. var skeletons = {};
  24369. var bones = {}; // generate bone lookup table
  24370. object.traverse(function (child) {
  24371. if (child.isBone) bones[child.uuid] = child;
  24372. }); // create skeletons
  24373. if (json !== undefined) {
  24374. for (var i = 0, l = json.length; i < l; i++) {
  24375. var skeleton = new Skeleton().fromJSON(json[i], bones);
  24376. skeletons[skeleton.uuid] = skeleton;
  24377. }
  24378. }
  24379. return skeletons;
  24380. };
  24381. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24382. var geometries = {};
  24383. var geometryShapes;
  24384. if (json !== undefined) {
  24385. var bufferGeometryLoader = new BufferGeometryLoader();
  24386. for (var i = 0, l = json.length; i < l; i++) {
  24387. var geometry = void 0;
  24388. var data = json[i];
  24389. switch (data.type) {
  24390. case 'PlaneGeometry':
  24391. case 'PlaneBufferGeometry':
  24392. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24393. break;
  24394. case 'BoxGeometry':
  24395. case 'BoxBufferGeometry':
  24396. case 'CubeGeometry':
  24397. // backwards compatible
  24398. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24399. break;
  24400. case 'CircleGeometry':
  24401. case 'CircleBufferGeometry':
  24402. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24403. break;
  24404. case 'CylinderGeometry':
  24405. case 'CylinderBufferGeometry':
  24406. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24407. break;
  24408. case 'ConeGeometry':
  24409. case 'ConeBufferGeometry':
  24410. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24411. break;
  24412. case 'SphereGeometry':
  24413. case 'SphereBufferGeometry':
  24414. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24415. break;
  24416. case 'DodecahedronGeometry':
  24417. case 'DodecahedronBufferGeometry':
  24418. case 'IcosahedronGeometry':
  24419. case 'IcosahedronBufferGeometry':
  24420. case 'OctahedronGeometry':
  24421. case 'OctahedronBufferGeometry':
  24422. case 'TetrahedronGeometry':
  24423. case 'TetrahedronBufferGeometry':
  24424. geometry = new Geometries[data.type](data.radius, data.detail);
  24425. break;
  24426. case 'RingGeometry':
  24427. case 'RingBufferGeometry':
  24428. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24429. break;
  24430. case 'TorusGeometry':
  24431. case 'TorusBufferGeometry':
  24432. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24433. break;
  24434. case 'TorusKnotGeometry':
  24435. case 'TorusKnotBufferGeometry':
  24436. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24437. break;
  24438. case 'TubeGeometry':
  24439. case 'TubeBufferGeometry':
  24440. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24441. // User defined curves or instances of CurvePath will not be deserialized.
  24442. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24443. break;
  24444. case 'LatheGeometry':
  24445. case 'LatheBufferGeometry':
  24446. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24447. break;
  24448. case 'PolyhedronGeometry':
  24449. case 'PolyhedronBufferGeometry':
  24450. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24451. break;
  24452. case 'ShapeGeometry':
  24453. case 'ShapeBufferGeometry':
  24454. geometryShapes = [];
  24455. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24456. var shape = shapes[data.shapes[j]];
  24457. geometryShapes.push(shape);
  24458. }
  24459. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24460. break;
  24461. case 'ExtrudeGeometry':
  24462. case 'ExtrudeBufferGeometry':
  24463. geometryShapes = [];
  24464. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24465. var _shape = shapes[data.shapes[_j]];
  24466. geometryShapes.push(_shape);
  24467. }
  24468. var extrudePath = data.options.extrudePath;
  24469. if (extrudePath !== undefined) {
  24470. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24471. }
  24472. geometry = new Geometries[data.type](geometryShapes, data.options);
  24473. break;
  24474. case 'BufferGeometry':
  24475. case 'InstancedBufferGeometry':
  24476. geometry = bufferGeometryLoader.parse(data);
  24477. break;
  24478. case 'Geometry':
  24479. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24480. break;
  24481. default:
  24482. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24483. continue;
  24484. }
  24485. geometry.uuid = data.uuid;
  24486. if (data.name !== undefined) geometry.name = data.name;
  24487. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24488. geometries[data.uuid] = geometry;
  24489. }
  24490. }
  24491. return geometries;
  24492. };
  24493. _proto.parseMaterials = function parseMaterials(json, textures) {
  24494. var cache = {}; // MultiMaterial
  24495. var materials = {};
  24496. if (json !== undefined) {
  24497. var loader = new MaterialLoader();
  24498. loader.setTextures(textures);
  24499. for (var i = 0, l = json.length; i < l; i++) {
  24500. var data = json[i];
  24501. if (data.type === 'MultiMaterial') {
  24502. // Deprecated
  24503. var array = [];
  24504. for (var j = 0; j < data.materials.length; j++) {
  24505. var material = data.materials[j];
  24506. if (cache[material.uuid] === undefined) {
  24507. cache[material.uuid] = loader.parse(material);
  24508. }
  24509. array.push(cache[material.uuid]);
  24510. }
  24511. materials[data.uuid] = array;
  24512. } else {
  24513. if (cache[data.uuid] === undefined) {
  24514. cache[data.uuid] = loader.parse(data);
  24515. }
  24516. materials[data.uuid] = cache[data.uuid];
  24517. }
  24518. }
  24519. }
  24520. return materials;
  24521. };
  24522. _proto.parseAnimations = function parseAnimations(json) {
  24523. var animations = [];
  24524. for (var i = 0; i < json.length; i++) {
  24525. var data = json[i];
  24526. var clip = AnimationClip.parse(data);
  24527. if (data.uuid !== undefined) clip.uuid = data.uuid;
  24528. animations.push(clip);
  24529. }
  24530. return animations;
  24531. };
  24532. _proto.parseImages = function parseImages(json, onLoad) {
  24533. var scope = this;
  24534. var images = {};
  24535. var loader;
  24536. function loadImage(url) {
  24537. scope.manager.itemStart(url);
  24538. return loader.load(url, function () {
  24539. scope.manager.itemEnd(url);
  24540. }, undefined, function () {
  24541. scope.manager.itemError(url);
  24542. scope.manager.itemEnd(url);
  24543. });
  24544. }
  24545. function deserializeImage(image) {
  24546. if (typeof image === 'string') {
  24547. var url = image;
  24548. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
  24549. return loadImage(path);
  24550. } else {
  24551. if (image.data) {
  24552. return {
  24553. data: getTypedArray(image.type, image.data),
  24554. width: image.width,
  24555. height: image.height
  24556. };
  24557. } else {
  24558. return null;
  24559. }
  24560. }
  24561. }
  24562. if (json !== undefined && json.length > 0) {
  24563. var manager = new LoadingManager(onLoad);
  24564. loader = new ImageLoader(manager);
  24565. loader.setCrossOrigin(this.crossOrigin);
  24566. for (var i = 0, il = json.length; i < il; i++) {
  24567. var image = json[i];
  24568. var url = image.url;
  24569. if (Array.isArray(url)) {
  24570. // load array of images e.g CubeTexture
  24571. images[image.uuid] = [];
  24572. for (var j = 0, jl = url.length; j < jl; j++) {
  24573. var currentUrl = url[j];
  24574. var deserializedImage = deserializeImage(currentUrl);
  24575. if (deserializedImage !== null) {
  24576. if (deserializedImage instanceof HTMLImageElement) {
  24577. images[image.uuid].push(deserializedImage);
  24578. } else {
  24579. // special case: handle array of data textures for cube textures
  24580. images[image.uuid].push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
  24581. }
  24582. }
  24583. }
  24584. } else {
  24585. // load single image
  24586. var _deserializedImage = deserializeImage(image.url);
  24587. if (_deserializedImage !== null) {
  24588. images[image.uuid] = _deserializedImage;
  24589. }
  24590. }
  24591. }
  24592. }
  24593. return images;
  24594. };
  24595. _proto.parseTextures = function parseTextures(json, images) {
  24596. function parseConstant(value, type) {
  24597. if (typeof value === 'number') return value;
  24598. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  24599. return type[value];
  24600. }
  24601. var textures = {};
  24602. if (json !== undefined) {
  24603. for (var i = 0, l = json.length; i < l; i++) {
  24604. var data = json[i];
  24605. if (data.image === undefined) {
  24606. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  24607. }
  24608. if (images[data.image] === undefined) {
  24609. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  24610. }
  24611. var texture = void 0;
  24612. var image = images[data.image];
  24613. if (Array.isArray(image)) {
  24614. texture = new CubeTexture(image);
  24615. if (image.length === 6) texture.needsUpdate = true;
  24616. } else {
  24617. if (image && image.data) {
  24618. texture = new DataTexture(image.data, image.width, image.height);
  24619. } else {
  24620. texture = new Texture(image);
  24621. }
  24622. if (image) texture.needsUpdate = true; // textures can have undefined image data
  24623. }
  24624. texture.uuid = data.uuid;
  24625. if (data.name !== undefined) texture.name = data.name;
  24626. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  24627. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  24628. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  24629. if (data.center !== undefined) texture.center.fromArray(data.center);
  24630. if (data.rotation !== undefined) texture.rotation = data.rotation;
  24631. if (data.wrap !== undefined) {
  24632. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  24633. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  24634. }
  24635. if (data.format !== undefined) texture.format = data.format;
  24636. if (data.type !== undefined) texture.type = data.type;
  24637. if (data.encoding !== undefined) texture.encoding = data.encoding;
  24638. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  24639. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  24640. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  24641. if (data.flipY !== undefined) texture.flipY = data.flipY;
  24642. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  24643. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  24644. textures[data.uuid] = texture;
  24645. }
  24646. }
  24647. return textures;
  24648. };
  24649. _proto.parseObject = function parseObject(data, geometries, materials) {
  24650. var object;
  24651. function getGeometry(name) {
  24652. if (geometries[name] === undefined) {
  24653. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  24654. }
  24655. return geometries[name];
  24656. }
  24657. function getMaterial(name) {
  24658. if (name === undefined) return undefined;
  24659. if (Array.isArray(name)) {
  24660. var array = [];
  24661. for (var i = 0, l = name.length; i < l; i++) {
  24662. var uuid = name[i];
  24663. if (materials[uuid] === undefined) {
  24664. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  24665. }
  24666. array.push(materials[uuid]);
  24667. }
  24668. return array;
  24669. }
  24670. if (materials[name] === undefined) {
  24671. console.warn('THREE.ObjectLoader: Undefined material', name);
  24672. }
  24673. return materials[name];
  24674. }
  24675. var geometry, material;
  24676. switch (data.type) {
  24677. case 'Scene':
  24678. object = new Scene();
  24679. if (data.background !== undefined) {
  24680. if (Number.isInteger(data.background)) {
  24681. object.background = new Color(data.background);
  24682. }
  24683. }
  24684. if (data.fog !== undefined) {
  24685. if (data.fog.type === 'Fog') {
  24686. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  24687. } else if (data.fog.type === 'FogExp2') {
  24688. object.fog = new FogExp2(data.fog.color, data.fog.density);
  24689. }
  24690. }
  24691. break;
  24692. case 'PerspectiveCamera':
  24693. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  24694. if (data.focus !== undefined) object.focus = data.focus;
  24695. if (data.zoom !== undefined) object.zoom = data.zoom;
  24696. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  24697. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  24698. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24699. break;
  24700. case 'OrthographicCamera':
  24701. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  24702. if (data.zoom !== undefined) object.zoom = data.zoom;
  24703. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24704. break;
  24705. case 'AmbientLight':
  24706. object = new AmbientLight(data.color, data.intensity);
  24707. break;
  24708. case 'DirectionalLight':
  24709. object = new DirectionalLight(data.color, data.intensity);
  24710. break;
  24711. case 'PointLight':
  24712. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  24713. break;
  24714. case 'RectAreaLight':
  24715. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  24716. break;
  24717. case 'SpotLight':
  24718. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  24719. break;
  24720. case 'HemisphereLight':
  24721. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  24722. break;
  24723. case 'LightProbe':
  24724. object = new LightProbe().fromJSON(data);
  24725. break;
  24726. case 'SkinnedMesh':
  24727. geometry = getGeometry(data.geometry);
  24728. material = getMaterial(data.material);
  24729. object = new SkinnedMesh(geometry, material);
  24730. if (data.bindMode !== undefined) object.bindMode = data.bindMode;
  24731. if (data.bindMatrix !== undefined) object.bindMatrix.fromArray(data.bindMatrix);
  24732. if (data.skeleton !== undefined) object.skeleton = data.skeleton;
  24733. break;
  24734. case 'Mesh':
  24735. geometry = getGeometry(data.geometry);
  24736. material = getMaterial(data.material);
  24737. object = new Mesh(geometry, material);
  24738. break;
  24739. case 'InstancedMesh':
  24740. geometry = getGeometry(data.geometry);
  24741. material = getMaterial(data.material);
  24742. var count = data.count;
  24743. var instanceMatrix = data.instanceMatrix;
  24744. object = new InstancedMesh(geometry, material, count);
  24745. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  24746. break;
  24747. case 'LOD':
  24748. object = new LOD();
  24749. break;
  24750. case 'Line':
  24751. object = new Line(getGeometry(data.geometry), getMaterial(data.material), data.mode);
  24752. break;
  24753. case 'LineLoop':
  24754. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  24755. break;
  24756. case 'LineSegments':
  24757. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  24758. break;
  24759. case 'PointCloud':
  24760. case 'Points':
  24761. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  24762. break;
  24763. case 'Sprite':
  24764. object = new Sprite(getMaterial(data.material));
  24765. break;
  24766. case 'Group':
  24767. object = new Group();
  24768. break;
  24769. case 'Bone':
  24770. object = new Bone();
  24771. break;
  24772. default:
  24773. object = new Object3D();
  24774. }
  24775. object.uuid = data.uuid;
  24776. if (data.name !== undefined) object.name = data.name;
  24777. if (data.matrix !== undefined) {
  24778. object.matrix.fromArray(data.matrix);
  24779. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24780. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  24781. } else {
  24782. if (data.position !== undefined) object.position.fromArray(data.position);
  24783. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  24784. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  24785. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  24786. }
  24787. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  24788. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  24789. if (data.shadow) {
  24790. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  24791. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  24792. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  24793. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  24794. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  24795. }
  24796. if (data.visible !== undefined) object.visible = data.visible;
  24797. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  24798. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  24799. if (data.userData !== undefined) object.userData = data.userData;
  24800. if (data.layers !== undefined) object.layers.mask = data.layers;
  24801. if (data.children !== undefined) {
  24802. var children = data.children;
  24803. for (var i = 0; i < children.length; i++) {
  24804. object.add(this.parseObject(children[i], geometries, materials));
  24805. }
  24806. }
  24807. if (data.type === 'LOD') {
  24808. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  24809. var levels = data.levels;
  24810. for (var l = 0; l < levels.length; l++) {
  24811. var level = levels[l];
  24812. var child = object.getObjectByProperty('uuid', level.object);
  24813. if (child !== undefined) {
  24814. object.addLevel(child, level.distance);
  24815. }
  24816. }
  24817. }
  24818. return object;
  24819. };
  24820. _proto.bindSkeletons = function bindSkeletons(object, skeletons) {
  24821. if (Object.keys(skeletons).length === 0) return;
  24822. object.traverse(function (child) {
  24823. if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
  24824. var skeleton = skeletons[child.skeleton];
  24825. if (skeleton === undefined) {
  24826. console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton);
  24827. } else {
  24828. child.bind(skeleton, child.bindMatrix);
  24829. }
  24830. }
  24831. });
  24832. }
  24833. /* DEPRECATED */
  24834. ;
  24835. _proto.setTexturePath = function setTexturePath(value) {
  24836. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  24837. return this.setResourcePath(value);
  24838. };
  24839. return ObjectLoader;
  24840. }(Loader);
  24841. var TEXTURE_MAPPING = {
  24842. UVMapping: UVMapping,
  24843. CubeReflectionMapping: CubeReflectionMapping,
  24844. CubeRefractionMapping: CubeRefractionMapping,
  24845. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24846. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24847. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24848. CubeUVRefractionMapping: CubeUVRefractionMapping
  24849. };
  24850. var TEXTURE_WRAPPING = {
  24851. RepeatWrapping: RepeatWrapping,
  24852. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24853. MirroredRepeatWrapping: MirroredRepeatWrapping
  24854. };
  24855. var TEXTURE_FILTER = {
  24856. NearestFilter: NearestFilter,
  24857. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24858. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24859. LinearFilter: LinearFilter,
  24860. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24861. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24862. };
  24863. function ImageBitmapLoader(manager) {
  24864. if (typeof createImageBitmap === 'undefined') {
  24865. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  24866. }
  24867. if (typeof fetch === 'undefined') {
  24868. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  24869. }
  24870. Loader.call(this, manager);
  24871. this.options = {
  24872. premultiplyAlpha: 'none'
  24873. };
  24874. }
  24875. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24876. constructor: ImageBitmapLoader,
  24877. isImageBitmapLoader: true,
  24878. setOptions: function setOptions(options) {
  24879. this.options = options;
  24880. return this;
  24881. },
  24882. load: function load(url, onLoad, onProgress, onError) {
  24883. if (url === undefined) url = '';
  24884. if (this.path !== undefined) url = this.path + url;
  24885. url = this.manager.resolveURL(url);
  24886. var scope = this;
  24887. var cached = Cache.get(url);
  24888. if (cached !== undefined) {
  24889. scope.manager.itemStart(url);
  24890. setTimeout(function () {
  24891. if (onLoad) onLoad(cached);
  24892. scope.manager.itemEnd(url);
  24893. }, 0);
  24894. return cached;
  24895. }
  24896. var fetchOptions = {};
  24897. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  24898. fetch(url, fetchOptions).then(function (res) {
  24899. return res.blob();
  24900. }).then(function (blob) {
  24901. return createImageBitmap(blob, scope.options);
  24902. }).then(function (imageBitmap) {
  24903. Cache.add(url, imageBitmap);
  24904. if (onLoad) onLoad(imageBitmap);
  24905. scope.manager.itemEnd(url);
  24906. }).catch(function (e) {
  24907. if (onError) onError(e);
  24908. scope.manager.itemError(url);
  24909. scope.manager.itemEnd(url);
  24910. });
  24911. scope.manager.itemStart(url);
  24912. }
  24913. });
  24914. function ShapePath() {
  24915. this.type = 'ShapePath';
  24916. this.color = new Color();
  24917. this.subPaths = [];
  24918. this.currentPath = null;
  24919. }
  24920. Object.assign(ShapePath.prototype, {
  24921. moveTo: function moveTo(x, y) {
  24922. this.currentPath = new Path();
  24923. this.subPaths.push(this.currentPath);
  24924. this.currentPath.moveTo(x, y);
  24925. return this;
  24926. },
  24927. lineTo: function lineTo(x, y) {
  24928. this.currentPath.lineTo(x, y);
  24929. return this;
  24930. },
  24931. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  24932. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  24933. return this;
  24934. },
  24935. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  24936. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  24937. return this;
  24938. },
  24939. splineThru: function splineThru(pts) {
  24940. this.currentPath.splineThru(pts);
  24941. return this;
  24942. },
  24943. toShapes: function toShapes(isCCW, noHoles) {
  24944. function toShapesNoHoles(inSubpaths) {
  24945. var shapes = [];
  24946. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  24947. var _tmpPath = inSubpaths[i];
  24948. var _tmpShape = new Shape();
  24949. _tmpShape.curves = _tmpPath.curves;
  24950. shapes.push(_tmpShape);
  24951. }
  24952. return shapes;
  24953. }
  24954. function isPointInsidePolygon(inPt, inPolygon) {
  24955. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  24956. // toggling of inside/outside at every single! intersection point of an edge
  24957. // with the horizontal line through inPt, left of inPt
  24958. // not counting lowerY endpoints of edges and whole edges on that line
  24959. var inside = false;
  24960. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  24961. var edgeLowPt = inPolygon[p];
  24962. var edgeHighPt = inPolygon[q];
  24963. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  24964. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  24965. if (Math.abs(edgeDy) > Number.EPSILON) {
  24966. // not parallel
  24967. if (edgeDy < 0) {
  24968. edgeLowPt = inPolygon[q];
  24969. edgeDx = -edgeDx;
  24970. edgeHighPt = inPolygon[p];
  24971. edgeDy = -edgeDy;
  24972. }
  24973. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  24974. if (inPt.y === edgeLowPt.y) {
  24975. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  24976. // continue; // no intersection or edgeLowPt => doesn't count !!!
  24977. } else {
  24978. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  24979. if (perpEdge === 0) return true; // inPt is on contour ?
  24980. if (perpEdge < 0) continue;
  24981. inside = !inside; // true intersection left of inPt
  24982. }
  24983. } else {
  24984. // parallel or collinear
  24985. if (inPt.y !== edgeLowPt.y) continue; // parallel
  24986. // edge lies on the same horizontal line as inPt
  24987. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  24988. // continue;
  24989. }
  24990. }
  24991. return inside;
  24992. }
  24993. var isClockWise = ShapeUtils.isClockWise;
  24994. var subPaths = this.subPaths;
  24995. if (subPaths.length === 0) return [];
  24996. if (noHoles === true) return toShapesNoHoles(subPaths);
  24997. var solid, tmpPath, tmpShape;
  24998. var shapes = [];
  24999. if (subPaths.length === 1) {
  25000. tmpPath = subPaths[0];
  25001. tmpShape = new Shape();
  25002. tmpShape.curves = tmpPath.curves;
  25003. shapes.push(tmpShape);
  25004. return shapes;
  25005. }
  25006. var holesFirst = !isClockWise(subPaths[0].getPoints());
  25007. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  25008. var betterShapeHoles = [];
  25009. var newShapes = [];
  25010. var newShapeHoles = [];
  25011. var mainIdx = 0;
  25012. var tmpPoints;
  25013. newShapes[mainIdx] = undefined;
  25014. newShapeHoles[mainIdx] = [];
  25015. for (var i = 0, l = subPaths.length; i < l; i++) {
  25016. tmpPath = subPaths[i];
  25017. tmpPoints = tmpPath.getPoints();
  25018. solid = isClockWise(tmpPoints);
  25019. solid = isCCW ? !solid : solid;
  25020. if (solid) {
  25021. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  25022. newShapes[mainIdx] = {
  25023. s: new Shape(),
  25024. p: tmpPoints
  25025. };
  25026. newShapes[mainIdx].s.curves = tmpPath.curves;
  25027. if (holesFirst) mainIdx++;
  25028. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  25029. } else {
  25030. newShapeHoles[mainIdx].push({
  25031. h: tmpPath,
  25032. p: tmpPoints[0]
  25033. }); //console.log('ccw', i);
  25034. }
  25035. } // only Holes? -> probably all Shapes with wrong orientation
  25036. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  25037. if (newShapes.length > 1) {
  25038. var ambiguous = false;
  25039. var toChange = [];
  25040. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  25041. betterShapeHoles[sIdx] = [];
  25042. }
  25043. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  25044. var sho = newShapeHoles[_sIdx];
  25045. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  25046. var ho = sho[hIdx];
  25047. var hole_unassigned = true;
  25048. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  25049. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  25050. if (_sIdx !== s2Idx) toChange.push({
  25051. froms: _sIdx,
  25052. tos: s2Idx,
  25053. hole: hIdx
  25054. });
  25055. if (hole_unassigned) {
  25056. hole_unassigned = false;
  25057. betterShapeHoles[s2Idx].push(ho);
  25058. } else {
  25059. ambiguous = true;
  25060. }
  25061. }
  25062. }
  25063. if (hole_unassigned) {
  25064. betterShapeHoles[_sIdx].push(ho);
  25065. }
  25066. }
  25067. } // console.log("ambiguous: ", ambiguous);
  25068. if (toChange.length > 0) {
  25069. // console.log("to change: ", toChange);
  25070. if (!ambiguous) newShapeHoles = betterShapeHoles;
  25071. }
  25072. }
  25073. var tmpHoles;
  25074. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  25075. tmpShape = newShapes[_i].s;
  25076. shapes.push(tmpShape);
  25077. tmpHoles = newShapeHoles[_i];
  25078. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  25079. tmpShape.holes.push(tmpHoles[j].h);
  25080. }
  25081. } //console.log("shape", shapes);
  25082. return shapes;
  25083. }
  25084. });
  25085. function Font(data) {
  25086. this.type = 'Font';
  25087. this.data = data;
  25088. }
  25089. Object.assign(Font.prototype, {
  25090. isFont: true,
  25091. generateShapes: function generateShapes(text, size) {
  25092. if (size === void 0) {
  25093. size = 100;
  25094. }
  25095. var shapes = [];
  25096. var paths = createPaths(text, size, this.data);
  25097. for (var p = 0, pl = paths.length; p < pl; p++) {
  25098. Array.prototype.push.apply(shapes, paths[p].toShapes());
  25099. }
  25100. return shapes;
  25101. }
  25102. });
  25103. function createPaths(text, size, data) {
  25104. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  25105. var scale = size / data.resolution;
  25106. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  25107. var paths = [];
  25108. var offsetX = 0,
  25109. offsetY = 0;
  25110. for (var i = 0; i < chars.length; i++) {
  25111. var char = chars[i];
  25112. if (char === '\n') {
  25113. offsetX = 0;
  25114. offsetY -= line_height;
  25115. } else {
  25116. var ret = createPath(char, scale, offsetX, offsetY, data);
  25117. offsetX += ret.offsetX;
  25118. paths.push(ret.path);
  25119. }
  25120. }
  25121. return paths;
  25122. }
  25123. function createPath(char, scale, offsetX, offsetY, data) {
  25124. var glyph = data.glyphs[char] || data.glyphs['?'];
  25125. if (!glyph) {
  25126. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  25127. return;
  25128. }
  25129. var path = new ShapePath();
  25130. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  25131. if (glyph.o) {
  25132. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  25133. for (var i = 0, l = outline.length; i < l;) {
  25134. var action = outline[i++];
  25135. switch (action) {
  25136. case 'm':
  25137. // moveTo
  25138. x = outline[i++] * scale + offsetX;
  25139. y = outline[i++] * scale + offsetY;
  25140. path.moveTo(x, y);
  25141. break;
  25142. case 'l':
  25143. // lineTo
  25144. x = outline[i++] * scale + offsetX;
  25145. y = outline[i++] * scale + offsetY;
  25146. path.lineTo(x, y);
  25147. break;
  25148. case 'q':
  25149. // quadraticCurveTo
  25150. cpx = outline[i++] * scale + offsetX;
  25151. cpy = outline[i++] * scale + offsetY;
  25152. cpx1 = outline[i++] * scale + offsetX;
  25153. cpy1 = outline[i++] * scale + offsetY;
  25154. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  25155. break;
  25156. case 'b':
  25157. // bezierCurveTo
  25158. cpx = outline[i++] * scale + offsetX;
  25159. cpy = outline[i++] * scale + offsetY;
  25160. cpx1 = outline[i++] * scale + offsetX;
  25161. cpy1 = outline[i++] * scale + offsetY;
  25162. cpx2 = outline[i++] * scale + offsetX;
  25163. cpy2 = outline[i++] * scale + offsetY;
  25164. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  25165. break;
  25166. }
  25167. }
  25168. }
  25169. return {
  25170. offsetX: glyph.ha * scale,
  25171. path: path
  25172. };
  25173. }
  25174. function FontLoader(manager) {
  25175. Loader.call(this, manager);
  25176. }
  25177. FontLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25178. constructor: FontLoader,
  25179. load: function load(url, onLoad, onProgress, onError) {
  25180. var scope = this;
  25181. var loader = new FileLoader(this.manager);
  25182. loader.setPath(this.path);
  25183. loader.setRequestHeader(this.requestHeader);
  25184. loader.setWithCredentials(scope.withCredentials);
  25185. loader.load(url, function (text) {
  25186. var json;
  25187. try {
  25188. json = JSON.parse(text);
  25189. } catch (e) {
  25190. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  25191. json = JSON.parse(text.substring(65, text.length - 2));
  25192. }
  25193. var font = scope.parse(json);
  25194. if (onLoad) onLoad(font);
  25195. }, onProgress, onError);
  25196. },
  25197. parse: function parse(json) {
  25198. return new Font(json);
  25199. }
  25200. });
  25201. var _context;
  25202. var AudioContext = {
  25203. getContext: function getContext() {
  25204. if (_context === undefined) {
  25205. _context = new (window.AudioContext || window.webkitAudioContext)();
  25206. }
  25207. return _context;
  25208. },
  25209. setContext: function setContext(value) {
  25210. _context = value;
  25211. }
  25212. };
  25213. function AudioLoader(manager) {
  25214. Loader.call(this, manager);
  25215. }
  25216. AudioLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25217. constructor: AudioLoader,
  25218. load: function load(url, onLoad, onProgress, onError) {
  25219. var scope = this;
  25220. var loader = new FileLoader(scope.manager);
  25221. loader.setResponseType('arraybuffer');
  25222. loader.setPath(scope.path);
  25223. loader.setRequestHeader(scope.requestHeader);
  25224. loader.setWithCredentials(scope.withCredentials);
  25225. loader.load(url, function (buffer) {
  25226. try {
  25227. // Create a copy of the buffer. The `decodeAudioData` method
  25228. // detaches the buffer when complete, preventing reuse.
  25229. var bufferCopy = buffer.slice(0);
  25230. var context = AudioContext.getContext();
  25231. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  25232. onLoad(audioBuffer);
  25233. });
  25234. } catch (e) {
  25235. if (onError) {
  25236. onError(e);
  25237. } else {
  25238. console.error(e);
  25239. }
  25240. scope.manager.itemError(url);
  25241. }
  25242. }, onProgress, onError);
  25243. }
  25244. });
  25245. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  25246. LightProbe.call(this, undefined, intensity);
  25247. var color1 = new Color().set(skyColor);
  25248. var color2 = new Color().set(groundColor);
  25249. var sky = new Vector3(color1.r, color1.g, color1.b);
  25250. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25251. var c0 = Math.sqrt(Math.PI);
  25252. var c1 = c0 * Math.sqrt(0.75);
  25253. this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  25254. this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  25255. }
  25256. HemisphereLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25257. constructor: HemisphereLightProbe,
  25258. isHemisphereLightProbe: true,
  25259. copy: function copy(source) {
  25260. // modifying colors not currently supported
  25261. LightProbe.prototype.copy.call(this, source);
  25262. return this;
  25263. },
  25264. toJSON: function toJSON(meta) {
  25265. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25266. return data;
  25267. }
  25268. });
  25269. function AmbientLightProbe(color, intensity) {
  25270. LightProbe.call(this, undefined, intensity);
  25271. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25272. this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  25273. }
  25274. AmbientLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25275. constructor: AmbientLightProbe,
  25276. isAmbientLightProbe: true,
  25277. copy: function copy(source) {
  25278. // modifying color not currently supported
  25279. LightProbe.prototype.copy.call(this, source);
  25280. return this;
  25281. },
  25282. toJSON: function toJSON(meta) {
  25283. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25284. return data;
  25285. }
  25286. });
  25287. var _eyeRight = new Matrix4();
  25288. var _eyeLeft = new Matrix4();
  25289. function StereoCamera() {
  25290. this.type = 'StereoCamera';
  25291. this.aspect = 1;
  25292. this.eyeSep = 0.064;
  25293. this.cameraL = new PerspectiveCamera();
  25294. this.cameraL.layers.enable(1);
  25295. this.cameraL.matrixAutoUpdate = false;
  25296. this.cameraR = new PerspectiveCamera();
  25297. this.cameraR.layers.enable(2);
  25298. this.cameraR.matrixAutoUpdate = false;
  25299. this._cache = {
  25300. focus: null,
  25301. fov: null,
  25302. aspect: null,
  25303. near: null,
  25304. far: null,
  25305. zoom: null,
  25306. eyeSep: null
  25307. };
  25308. }
  25309. Object.assign(StereoCamera.prototype, {
  25310. update: function update(camera) {
  25311. var cache = this._cache;
  25312. 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;
  25313. if (needsUpdate) {
  25314. cache.focus = camera.focus;
  25315. cache.fov = camera.fov;
  25316. cache.aspect = camera.aspect * this.aspect;
  25317. cache.near = camera.near;
  25318. cache.far = camera.far;
  25319. cache.zoom = camera.zoom;
  25320. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25321. // http://paulbourke.net/stereographics/stereorender/
  25322. var projectionMatrix = camera.projectionMatrix.clone();
  25323. var eyeSepHalf = cache.eyeSep / 2;
  25324. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25325. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25326. var xmin, xmax; // translate xOffset
  25327. _eyeLeft.elements[12] = -eyeSepHalf;
  25328. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25329. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25330. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25331. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25332. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25333. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25334. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25335. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25336. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25337. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25338. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25339. }
  25340. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25341. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25342. }
  25343. });
  25344. var Clock = /*#__PURE__*/function () {
  25345. function Clock(autoStart) {
  25346. this.autoStart = autoStart !== undefined ? autoStart : true;
  25347. this.startTime = 0;
  25348. this.oldTime = 0;
  25349. this.elapsedTime = 0;
  25350. this.running = false;
  25351. }
  25352. var _proto = Clock.prototype;
  25353. _proto.start = function start() {
  25354. this.startTime = (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25355. this.oldTime = this.startTime;
  25356. this.elapsedTime = 0;
  25357. this.running = true;
  25358. };
  25359. _proto.stop = function stop() {
  25360. this.getElapsedTime();
  25361. this.running = false;
  25362. this.autoStart = false;
  25363. };
  25364. _proto.getElapsedTime = function getElapsedTime() {
  25365. this.getDelta();
  25366. return this.elapsedTime;
  25367. };
  25368. _proto.getDelta = function getDelta() {
  25369. var diff = 0;
  25370. if (this.autoStart && !this.running) {
  25371. this.start();
  25372. return 0;
  25373. }
  25374. if (this.running) {
  25375. var newTime = (typeof performance === 'undefined' ? Date : performance).now();
  25376. diff = (newTime - this.oldTime) / 1000;
  25377. this.oldTime = newTime;
  25378. this.elapsedTime += diff;
  25379. }
  25380. return diff;
  25381. };
  25382. return Clock;
  25383. }();
  25384. var _position$2 = /*@__PURE__*/new Vector3();
  25385. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25386. var _scale$1 = /*@__PURE__*/new Vector3();
  25387. var _orientation = /*@__PURE__*/new Vector3();
  25388. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25389. _inheritsLoose(AudioListener, _Object3D);
  25390. function AudioListener() {
  25391. var _this;
  25392. _this = _Object3D.call(this) || this;
  25393. _this.type = 'AudioListener';
  25394. _this.context = AudioContext.getContext();
  25395. _this.gain = _this.context.createGain();
  25396. _this.gain.connect(_this.context.destination);
  25397. _this.filter = null;
  25398. _this.timeDelta = 0; // private
  25399. _this._clock = new Clock();
  25400. return _this;
  25401. }
  25402. var _proto = AudioListener.prototype;
  25403. _proto.getInput = function getInput() {
  25404. return this.gain;
  25405. };
  25406. _proto.removeFilter = function removeFilter() {
  25407. if (this.filter !== null) {
  25408. this.gain.disconnect(this.filter);
  25409. this.filter.disconnect(this.context.destination);
  25410. this.gain.connect(this.context.destination);
  25411. this.filter = null;
  25412. }
  25413. return this;
  25414. };
  25415. _proto.getFilter = function getFilter() {
  25416. return this.filter;
  25417. };
  25418. _proto.setFilter = function setFilter(value) {
  25419. if (this.filter !== null) {
  25420. this.gain.disconnect(this.filter);
  25421. this.filter.disconnect(this.context.destination);
  25422. } else {
  25423. this.gain.disconnect(this.context.destination);
  25424. }
  25425. this.filter = value;
  25426. this.gain.connect(this.filter);
  25427. this.filter.connect(this.context.destination);
  25428. return this;
  25429. };
  25430. _proto.getMasterVolume = function getMasterVolume() {
  25431. return this.gain.gain.value;
  25432. };
  25433. _proto.setMasterVolume = function setMasterVolume(value) {
  25434. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25435. return this;
  25436. };
  25437. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25438. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25439. var listener = this.context.listener;
  25440. var up = this.up;
  25441. this.timeDelta = this._clock.getDelta();
  25442. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25443. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25444. if (listener.positionX) {
  25445. // code path for Chrome (see #14393)
  25446. var endTime = this.context.currentTime + this.timeDelta;
  25447. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25448. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25449. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25450. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25451. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25452. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25453. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25454. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25455. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25456. } else {
  25457. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25458. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25459. }
  25460. };
  25461. return AudioListener;
  25462. }(Object3D);
  25463. var Audio = /*#__PURE__*/function (_Object3D) {
  25464. _inheritsLoose(Audio, _Object3D);
  25465. function Audio(listener) {
  25466. var _this;
  25467. _this = _Object3D.call(this) || this;
  25468. _this.type = 'Audio';
  25469. _this.listener = listener;
  25470. _this.context = listener.context;
  25471. _this.gain = _this.context.createGain();
  25472. _this.gain.connect(listener.getInput());
  25473. _this.autoplay = false;
  25474. _this.buffer = null;
  25475. _this.detune = 0;
  25476. _this.loop = false;
  25477. _this.loopStart = 0;
  25478. _this.loopEnd = 0;
  25479. _this.offset = 0;
  25480. _this.duration = undefined;
  25481. _this.playbackRate = 1;
  25482. _this.isPlaying = false;
  25483. _this.hasPlaybackControl = true;
  25484. _this.source = null;
  25485. _this.sourceType = 'empty';
  25486. _this._startedAt = 0;
  25487. _this._progress = 0;
  25488. _this._connected = false;
  25489. _this.filters = [];
  25490. return _this;
  25491. }
  25492. var _proto = Audio.prototype;
  25493. _proto.getOutput = function getOutput() {
  25494. return this.gain;
  25495. };
  25496. _proto.setNodeSource = function setNodeSource(audioNode) {
  25497. this.hasPlaybackControl = false;
  25498. this.sourceType = 'audioNode';
  25499. this.source = audioNode;
  25500. this.connect();
  25501. return this;
  25502. };
  25503. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25504. this.hasPlaybackControl = false;
  25505. this.sourceType = 'mediaNode';
  25506. this.source = this.context.createMediaElementSource(mediaElement);
  25507. this.connect();
  25508. return this;
  25509. };
  25510. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25511. this.hasPlaybackControl = false;
  25512. this.sourceType = 'mediaStreamNode';
  25513. this.source = this.context.createMediaStreamSource(mediaStream);
  25514. this.connect();
  25515. return this;
  25516. };
  25517. _proto.setBuffer = function setBuffer(audioBuffer) {
  25518. this.buffer = audioBuffer;
  25519. this.sourceType = 'buffer';
  25520. if (this.autoplay) this.play();
  25521. return this;
  25522. };
  25523. _proto.play = function play(delay) {
  25524. if (delay === void 0) {
  25525. delay = 0;
  25526. }
  25527. if (this.isPlaying === true) {
  25528. console.warn('THREE.Audio: Audio is already playing.');
  25529. return;
  25530. }
  25531. if (this.hasPlaybackControl === false) {
  25532. console.warn('THREE.Audio: this Audio has no playback control.');
  25533. return;
  25534. }
  25535. this._startedAt = this.context.currentTime + delay;
  25536. var source = this.context.createBufferSource();
  25537. source.buffer = this.buffer;
  25538. source.loop = this.loop;
  25539. source.loopStart = this.loopStart;
  25540. source.loopEnd = this.loopEnd;
  25541. source.onended = this.onEnded.bind(this);
  25542. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25543. this.isPlaying = true;
  25544. this.source = source;
  25545. this.setDetune(this.detune);
  25546. this.setPlaybackRate(this.playbackRate);
  25547. return this.connect();
  25548. };
  25549. _proto.pause = function pause() {
  25550. if (this.hasPlaybackControl === false) {
  25551. console.warn('THREE.Audio: this Audio has no playback control.');
  25552. return;
  25553. }
  25554. if (this.isPlaying === true) {
  25555. // update current progress
  25556. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  25557. if (this.loop === true) {
  25558. // ensure _progress does not exceed duration with looped audios
  25559. this._progress = this._progress % (this.duration || this.buffer.duration);
  25560. }
  25561. this.source.stop();
  25562. this.source.onended = null;
  25563. this.isPlaying = false;
  25564. }
  25565. return this;
  25566. };
  25567. _proto.stop = function stop() {
  25568. if (this.hasPlaybackControl === false) {
  25569. console.warn('THREE.Audio: this Audio has no playback control.');
  25570. return;
  25571. }
  25572. this._progress = 0;
  25573. this.source.stop();
  25574. this.source.onended = null;
  25575. this.isPlaying = false;
  25576. return this;
  25577. };
  25578. _proto.connect = function connect() {
  25579. if (this.filters.length > 0) {
  25580. this.source.connect(this.filters[0]);
  25581. for (var i = 1, l = this.filters.length; i < l; i++) {
  25582. this.filters[i - 1].connect(this.filters[i]);
  25583. }
  25584. this.filters[this.filters.length - 1].connect(this.getOutput());
  25585. } else {
  25586. this.source.connect(this.getOutput());
  25587. }
  25588. this._connected = true;
  25589. return this;
  25590. };
  25591. _proto.disconnect = function disconnect() {
  25592. if (this.filters.length > 0) {
  25593. this.source.disconnect(this.filters[0]);
  25594. for (var i = 1, l = this.filters.length; i < l; i++) {
  25595. this.filters[i - 1].disconnect(this.filters[i]);
  25596. }
  25597. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  25598. } else {
  25599. this.source.disconnect(this.getOutput());
  25600. }
  25601. this._connected = false;
  25602. return this;
  25603. };
  25604. _proto.getFilters = function getFilters() {
  25605. return this.filters;
  25606. };
  25607. _proto.setFilters = function setFilters(value) {
  25608. if (!value) value = [];
  25609. if (this._connected === true) {
  25610. this.disconnect();
  25611. this.filters = value.slice();
  25612. this.connect();
  25613. } else {
  25614. this.filters = value.slice();
  25615. }
  25616. return this;
  25617. };
  25618. _proto.setDetune = function setDetune(value) {
  25619. this.detune = value;
  25620. if (this.source.detune === undefined) return; // only set detune when available
  25621. if (this.isPlaying === true) {
  25622. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  25623. }
  25624. return this;
  25625. };
  25626. _proto.getDetune = function getDetune() {
  25627. return this.detune;
  25628. };
  25629. _proto.getFilter = function getFilter() {
  25630. return this.getFilters()[0];
  25631. };
  25632. _proto.setFilter = function setFilter(filter) {
  25633. return this.setFilters(filter ? [filter] : []);
  25634. };
  25635. _proto.setPlaybackRate = function setPlaybackRate(value) {
  25636. if (this.hasPlaybackControl === false) {
  25637. console.warn('THREE.Audio: this Audio has no playback control.');
  25638. return;
  25639. }
  25640. this.playbackRate = value;
  25641. if (this.isPlaying === true) {
  25642. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  25643. }
  25644. return this;
  25645. };
  25646. _proto.getPlaybackRate = function getPlaybackRate() {
  25647. return this.playbackRate;
  25648. };
  25649. _proto.onEnded = function onEnded() {
  25650. this.isPlaying = false;
  25651. };
  25652. _proto.getLoop = function getLoop() {
  25653. if (this.hasPlaybackControl === false) {
  25654. console.warn('THREE.Audio: this Audio has no playback control.');
  25655. return false;
  25656. }
  25657. return this.loop;
  25658. };
  25659. _proto.setLoop = function setLoop(value) {
  25660. if (this.hasPlaybackControl === false) {
  25661. console.warn('THREE.Audio: this Audio has no playback control.');
  25662. return;
  25663. }
  25664. this.loop = value;
  25665. if (this.isPlaying === true) {
  25666. this.source.loop = this.loop;
  25667. }
  25668. return this;
  25669. };
  25670. _proto.setLoopStart = function setLoopStart(value) {
  25671. this.loopStart = value;
  25672. return this;
  25673. };
  25674. _proto.setLoopEnd = function setLoopEnd(value) {
  25675. this.loopEnd = value;
  25676. return this;
  25677. };
  25678. _proto.getVolume = function getVolume() {
  25679. return this.gain.gain.value;
  25680. };
  25681. _proto.setVolume = function setVolume(value) {
  25682. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25683. return this;
  25684. };
  25685. return Audio;
  25686. }(Object3D);
  25687. var _position$3 = /*@__PURE__*/new Vector3();
  25688. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  25689. var _scale$2 = /*@__PURE__*/new Vector3();
  25690. var _orientation$1 = /*@__PURE__*/new Vector3();
  25691. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  25692. _inheritsLoose(PositionalAudio, _Audio);
  25693. function PositionalAudio(listener) {
  25694. var _this;
  25695. _this = _Audio.call(this, listener) || this;
  25696. _this.panner = _this.context.createPanner();
  25697. _this.panner.panningModel = 'HRTF';
  25698. _this.panner.connect(_this.gain);
  25699. return _this;
  25700. }
  25701. var _proto = PositionalAudio.prototype;
  25702. _proto.getOutput = function getOutput() {
  25703. return this.panner;
  25704. };
  25705. _proto.getRefDistance = function getRefDistance() {
  25706. return this.panner.refDistance;
  25707. };
  25708. _proto.setRefDistance = function setRefDistance(value) {
  25709. this.panner.refDistance = value;
  25710. return this;
  25711. };
  25712. _proto.getRolloffFactor = function getRolloffFactor() {
  25713. return this.panner.rolloffFactor;
  25714. };
  25715. _proto.setRolloffFactor = function setRolloffFactor(value) {
  25716. this.panner.rolloffFactor = value;
  25717. return this;
  25718. };
  25719. _proto.getDistanceModel = function getDistanceModel() {
  25720. return this.panner.distanceModel;
  25721. };
  25722. _proto.setDistanceModel = function setDistanceModel(value) {
  25723. this.panner.distanceModel = value;
  25724. return this;
  25725. };
  25726. _proto.getMaxDistance = function getMaxDistance() {
  25727. return this.panner.maxDistance;
  25728. };
  25729. _proto.setMaxDistance = function setMaxDistance(value) {
  25730. this.panner.maxDistance = value;
  25731. return this;
  25732. };
  25733. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  25734. this.panner.coneInnerAngle = coneInnerAngle;
  25735. this.panner.coneOuterAngle = coneOuterAngle;
  25736. this.panner.coneOuterGain = coneOuterGain;
  25737. return this;
  25738. };
  25739. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25740. _Audio.prototype.updateMatrixWorld.call(this, force);
  25741. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  25742. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  25743. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  25744. var panner = this.panner;
  25745. if (panner.positionX) {
  25746. // code path for Chrome and Firefox (see #14393)
  25747. var endTime = this.context.currentTime + this.listener.timeDelta;
  25748. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  25749. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  25750. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  25751. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  25752. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  25753. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  25754. } else {
  25755. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  25756. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  25757. }
  25758. };
  25759. return PositionalAudio;
  25760. }(Audio);
  25761. var AudioAnalyser = /*#__PURE__*/function () {
  25762. function AudioAnalyser(audio, fftSize) {
  25763. this.analyser = audio.context.createAnalyser();
  25764. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  25765. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  25766. audio.getOutput().connect(this.analyser);
  25767. }
  25768. var _proto = AudioAnalyser.prototype;
  25769. _proto.getFrequencyData = function getFrequencyData() {
  25770. this.analyser.getByteFrequencyData(this.data);
  25771. return this.data;
  25772. };
  25773. _proto.getAverageFrequency = function getAverageFrequency() {
  25774. var value = 0;
  25775. var data = this.getFrequencyData();
  25776. for (var i = 0; i < data.length; i++) {
  25777. value += data[i];
  25778. }
  25779. return value / data.length;
  25780. };
  25781. return AudioAnalyser;
  25782. }();
  25783. function PropertyMixer(binding, typeName, valueSize) {
  25784. this.binding = binding;
  25785. this.valueSize = valueSize;
  25786. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25787. //
  25788. // interpolators can use .buffer as their .result
  25789. // the data then goes to 'incoming'
  25790. //
  25791. // 'accu0' and 'accu1' are used frame-interleaved for
  25792. // the cumulative result and are compared to detect
  25793. // changes
  25794. //
  25795. // 'orig' stores the original state of the property
  25796. //
  25797. // 'add' is used for additive cumulative results
  25798. //
  25799. // 'work' is optional and is only present for quaternion types. It is used
  25800. // to store intermediate quaternion multiplication results
  25801. switch (typeName) {
  25802. case 'quaternion':
  25803. mixFunction = this._slerp;
  25804. mixFunctionAdditive = this._slerpAdditive;
  25805. setIdentity = this._setAdditiveIdentityQuaternion;
  25806. this.buffer = new Float64Array(valueSize * 6);
  25807. this._workIndex = 5;
  25808. break;
  25809. case 'string':
  25810. case 'bool':
  25811. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  25812. // additive is not relevant for non-numeric types
  25813. mixFunctionAdditive = this._select;
  25814. setIdentity = this._setAdditiveIdentityOther;
  25815. this.buffer = new Array(valueSize * 5);
  25816. break;
  25817. default:
  25818. mixFunction = this._lerp;
  25819. mixFunctionAdditive = this._lerpAdditive;
  25820. setIdentity = this._setAdditiveIdentityNumeric;
  25821. this.buffer = new Float64Array(valueSize * 5);
  25822. }
  25823. this._mixBufferRegion = mixFunction;
  25824. this._mixBufferRegionAdditive = mixFunctionAdditive;
  25825. this._setIdentity = setIdentity;
  25826. this._origIndex = 3;
  25827. this._addIndex = 4;
  25828. this.cumulativeWeight = 0;
  25829. this.cumulativeWeightAdditive = 0;
  25830. this.useCount = 0;
  25831. this.referenceCount = 0;
  25832. }
  25833. Object.assign(PropertyMixer.prototype, {
  25834. // accumulate data in the 'incoming' region into 'accu<i>'
  25835. accumulate: function accumulate(accuIndex, weight) {
  25836. // note: happily accumulating nothing when weight = 0, the caller knows
  25837. // the weight and shouldn't have made the call in the first place
  25838. var buffer = this.buffer,
  25839. stride = this.valueSize,
  25840. offset = accuIndex * stride + stride;
  25841. var currentWeight = this.cumulativeWeight;
  25842. if (currentWeight === 0) {
  25843. // accuN := incoming * weight
  25844. for (var i = 0; i !== stride; ++i) {
  25845. buffer[offset + i] = buffer[i];
  25846. }
  25847. currentWeight = weight;
  25848. } else {
  25849. // accuN := accuN + incoming * weight
  25850. currentWeight += weight;
  25851. var mix = weight / currentWeight;
  25852. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  25853. }
  25854. this.cumulativeWeight = currentWeight;
  25855. },
  25856. // accumulate data in the 'incoming' region into 'add'
  25857. accumulateAdditive: function accumulateAdditive(weight) {
  25858. var buffer = this.buffer,
  25859. stride = this.valueSize,
  25860. offset = stride * this._addIndex;
  25861. if (this.cumulativeWeightAdditive === 0) {
  25862. // add = identity
  25863. this._setIdentity();
  25864. } // add := add + incoming * weight
  25865. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  25866. this.cumulativeWeightAdditive += weight;
  25867. },
  25868. // apply the state of 'accu<i>' to the binding when accus differ
  25869. apply: function apply(accuIndex) {
  25870. var stride = this.valueSize,
  25871. buffer = this.buffer,
  25872. offset = accuIndex * stride + stride,
  25873. weight = this.cumulativeWeight,
  25874. weightAdditive = this.cumulativeWeightAdditive,
  25875. binding = this.binding;
  25876. this.cumulativeWeight = 0;
  25877. this.cumulativeWeightAdditive = 0;
  25878. if (weight < 1) {
  25879. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25880. var originalValueOffset = stride * this._origIndex;
  25881. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  25882. }
  25883. if (weightAdditive > 0) {
  25884. // accuN := accuN + additive accuN
  25885. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  25886. }
  25887. for (var i = stride, e = stride + stride; i !== e; ++i) {
  25888. if (buffer[i] !== buffer[i + stride]) {
  25889. // value has changed -> update scene graph
  25890. binding.setValue(buffer, offset);
  25891. break;
  25892. }
  25893. }
  25894. },
  25895. // remember the state of the bound property and copy it to both accus
  25896. saveOriginalState: function saveOriginalState() {
  25897. var binding = this.binding;
  25898. var buffer = this.buffer,
  25899. stride = this.valueSize,
  25900. originalValueOffset = stride * this._origIndex;
  25901. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  25902. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  25903. buffer[i] = buffer[originalValueOffset + i % stride];
  25904. } // Add to identity for additive
  25905. this._setIdentity();
  25906. this.cumulativeWeight = 0;
  25907. this.cumulativeWeightAdditive = 0;
  25908. },
  25909. // apply the state previously taken via 'saveOriginalState' to the binding
  25910. restoreOriginalState: function restoreOriginalState() {
  25911. var originalValueOffset = this.valueSize * 3;
  25912. this.binding.setValue(this.buffer, originalValueOffset);
  25913. },
  25914. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  25915. var startIndex = this._addIndex * this.valueSize;
  25916. var endIndex = startIndex + this.valueSize;
  25917. for (var i = startIndex; i < endIndex; i++) {
  25918. this.buffer[i] = 0;
  25919. }
  25920. },
  25921. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  25922. this._setAdditiveIdentityNumeric();
  25923. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  25924. },
  25925. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  25926. var startIndex = this._origIndex * this.valueSize;
  25927. var targetIndex = this._addIndex * this.valueSize;
  25928. for (var i = 0; i < this.valueSize; i++) {
  25929. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  25930. }
  25931. },
  25932. // mix functions
  25933. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  25934. if (t >= 0.5) {
  25935. for (var i = 0; i !== stride; ++i) {
  25936. buffer[dstOffset + i] = buffer[srcOffset + i];
  25937. }
  25938. }
  25939. },
  25940. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  25941. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  25942. },
  25943. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25944. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  25945. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  25946. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  25947. },
  25948. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  25949. var s = 1 - t;
  25950. for (var i = 0; i !== stride; ++i) {
  25951. var j = dstOffset + i;
  25952. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  25953. }
  25954. },
  25955. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25956. for (var i = 0; i !== stride; ++i) {
  25957. var j = dstOffset + i;
  25958. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  25959. }
  25960. }
  25961. });
  25962. // Characters [].:/ are reserved for track binding syntax.
  25963. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25964. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25965. // only latin characters, and the unicode \p{L} is not yet supported. So
  25966. // instead, we exclude reserved characters and match everything else.
  25967. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  25968. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25969. // be matched to parse the rest of the track name.
  25970. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25971. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  25972. // characters. Accessor may contain any character except closing bracket.
  25973. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  25974. // contain any non-bracket characters.
  25975. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  25976. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  25977. var _supportedObjectNames = ['material', 'materials', 'bones'];
  25978. function Composite(targetGroup, path, optionalParsedPath) {
  25979. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  25980. this._targetGroup = targetGroup;
  25981. this._bindings = targetGroup.subscribe_(path, parsedPath);
  25982. }
  25983. Object.assign(Composite.prototype, {
  25984. getValue: function getValue(array, offset) {
  25985. this.bind(); // bind all binding
  25986. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25987. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  25988. if (binding !== undefined) binding.getValue(array, offset);
  25989. },
  25990. setValue: function setValue(array, offset) {
  25991. var bindings = this._bindings;
  25992. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25993. bindings[i].setValue(array, offset);
  25994. }
  25995. },
  25996. bind: function bind() {
  25997. var bindings = this._bindings;
  25998. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25999. bindings[i].bind();
  26000. }
  26001. },
  26002. unbind: function unbind() {
  26003. var bindings = this._bindings;
  26004. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26005. bindings[i].unbind();
  26006. }
  26007. }
  26008. });
  26009. function PropertyBinding(rootNode, path, parsedPath) {
  26010. this.path = path;
  26011. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  26012. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  26013. this.rootNode = rootNode;
  26014. }
  26015. Object.assign(PropertyBinding, {
  26016. Composite: Composite,
  26017. create: function create(root, path, parsedPath) {
  26018. if (!(root && root.isAnimationObjectGroup)) {
  26019. return new PropertyBinding(root, path, parsedPath);
  26020. } else {
  26021. return new PropertyBinding.Composite(root, path, parsedPath);
  26022. }
  26023. },
  26024. /**
  26025. * Replaces spaces with underscores and removes unsupported characters from
  26026. * node names, to ensure compatibility with parseTrackName().
  26027. *
  26028. * @param {string} name Node name to be sanitized.
  26029. * @return {string}
  26030. */
  26031. sanitizeNodeName: function sanitizeNodeName(name) {
  26032. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  26033. },
  26034. parseTrackName: function parseTrackName(trackName) {
  26035. var matches = _trackRe.exec(trackName);
  26036. if (!matches) {
  26037. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  26038. }
  26039. var results = {
  26040. // directoryName: matches[ 1 ], // (tschw) currently unused
  26041. nodeName: matches[2],
  26042. objectName: matches[3],
  26043. objectIndex: matches[4],
  26044. propertyName: matches[5],
  26045. // required
  26046. propertyIndex: matches[6]
  26047. };
  26048. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  26049. if (lastDot !== undefined && lastDot !== -1) {
  26050. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  26051. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  26052. // 'bar' could be the objectName, or part of a nodeName (which can
  26053. // include '.' characters).
  26054. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  26055. results.nodeName = results.nodeName.substring(0, lastDot);
  26056. results.objectName = objectName;
  26057. }
  26058. }
  26059. if (results.propertyName === null || results.propertyName.length === 0) {
  26060. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  26061. }
  26062. return results;
  26063. },
  26064. findNode: function findNode(root, nodeName) {
  26065. if (!nodeName || nodeName === "" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  26066. return root;
  26067. } // search into skeleton bones.
  26068. if (root.skeleton) {
  26069. var bone = root.skeleton.getBoneByName(nodeName);
  26070. if (bone !== undefined) {
  26071. return bone;
  26072. }
  26073. } // search into node subtree.
  26074. if (root.children) {
  26075. var searchNodeSubtree = function searchNodeSubtree(children) {
  26076. for (var i = 0; i < children.length; i++) {
  26077. var childNode = children[i];
  26078. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  26079. return childNode;
  26080. }
  26081. var result = searchNodeSubtree(childNode.children);
  26082. if (result) return result;
  26083. }
  26084. return null;
  26085. };
  26086. var subTreeNode = searchNodeSubtree(root.children);
  26087. if (subTreeNode) {
  26088. return subTreeNode;
  26089. }
  26090. }
  26091. return null;
  26092. }
  26093. });
  26094. Object.assign(PropertyBinding.prototype, {
  26095. // prototype, continued
  26096. // these are used to "bind" a nonexistent property
  26097. _getValue_unavailable: function _getValue_unavailable() {},
  26098. _setValue_unavailable: function _setValue_unavailable() {},
  26099. BindingType: {
  26100. Direct: 0,
  26101. EntireArray: 1,
  26102. ArrayElement: 2,
  26103. HasFromToArray: 3
  26104. },
  26105. Versioning: {
  26106. None: 0,
  26107. NeedsUpdate: 1,
  26108. MatrixWorldNeedsUpdate: 2
  26109. },
  26110. GetterByBindingType: [function getValue_direct(buffer, offset) {
  26111. buffer[offset] = this.node[this.propertyName];
  26112. }, function getValue_array(buffer, offset) {
  26113. var source = this.resolvedProperty;
  26114. for (var i = 0, n = source.length; i !== n; ++i) {
  26115. buffer[offset++] = source[i];
  26116. }
  26117. }, function getValue_arrayElement(buffer, offset) {
  26118. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  26119. }, function getValue_toArray(buffer, offset) {
  26120. this.resolvedProperty.toArray(buffer, offset);
  26121. }],
  26122. SetterByBindingTypeAndVersioning: [[// Direct
  26123. function setValue_direct(buffer, offset) {
  26124. this.targetObject[this.propertyName] = buffer[offset];
  26125. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  26126. this.targetObject[this.propertyName] = buffer[offset];
  26127. this.targetObject.needsUpdate = true;
  26128. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  26129. this.targetObject[this.propertyName] = buffer[offset];
  26130. this.targetObject.matrixWorldNeedsUpdate = true;
  26131. }], [// EntireArray
  26132. function setValue_array(buffer, offset) {
  26133. var dest = this.resolvedProperty;
  26134. for (var i = 0, n = dest.length; i !== n; ++i) {
  26135. dest[i] = buffer[offset++];
  26136. }
  26137. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  26138. var dest = this.resolvedProperty;
  26139. for (var i = 0, n = dest.length; i !== n; ++i) {
  26140. dest[i] = buffer[offset++];
  26141. }
  26142. this.targetObject.needsUpdate = true;
  26143. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  26144. var dest = this.resolvedProperty;
  26145. for (var i = 0, n = dest.length; i !== n; ++i) {
  26146. dest[i] = buffer[offset++];
  26147. }
  26148. this.targetObject.matrixWorldNeedsUpdate = true;
  26149. }], [// ArrayElement
  26150. function setValue_arrayElement(buffer, offset) {
  26151. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26152. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  26153. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26154. this.targetObject.needsUpdate = true;
  26155. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  26156. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26157. this.targetObject.matrixWorldNeedsUpdate = true;
  26158. }], [// HasToFromArray
  26159. function setValue_fromArray(buffer, offset) {
  26160. this.resolvedProperty.fromArray(buffer, offset);
  26161. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  26162. this.resolvedProperty.fromArray(buffer, offset);
  26163. this.targetObject.needsUpdate = true;
  26164. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  26165. this.resolvedProperty.fromArray(buffer, offset);
  26166. this.targetObject.matrixWorldNeedsUpdate = true;
  26167. }]],
  26168. getValue: function getValue_unbound(targetArray, offset) {
  26169. this.bind();
  26170. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  26171. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26172. // prototype version of these methods with one that represents
  26173. // the bound state. When the property is not found, the methods
  26174. // become no-ops.
  26175. },
  26176. setValue: function getValue_unbound(sourceArray, offset) {
  26177. this.bind();
  26178. this.setValue(sourceArray, offset);
  26179. },
  26180. // create getter / setter pair for a property in the scene graph
  26181. bind: function bind() {
  26182. var targetObject = this.node;
  26183. var parsedPath = this.parsedPath;
  26184. var objectName = parsedPath.objectName;
  26185. var propertyName = parsedPath.propertyName;
  26186. var propertyIndex = parsedPath.propertyIndex;
  26187. if (!targetObject) {
  26188. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  26189. this.node = targetObject;
  26190. } // set fail state so we can just 'return' on error
  26191. this.getValue = this._getValue_unavailable;
  26192. this.setValue = this._setValue_unavailable; // ensure there is a value node
  26193. if (!targetObject) {
  26194. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  26195. return;
  26196. }
  26197. if (objectName) {
  26198. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26199. switch (objectName) {
  26200. case 'materials':
  26201. if (!targetObject.material) {
  26202. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  26203. return;
  26204. }
  26205. if (!targetObject.material.materials) {
  26206. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  26207. return;
  26208. }
  26209. targetObject = targetObject.material.materials;
  26210. break;
  26211. case 'bones':
  26212. if (!targetObject.skeleton) {
  26213. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  26214. return;
  26215. } // potential future optimization: skip this if propertyIndex is already an integer
  26216. // and convert the integer string to a true integer.
  26217. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  26218. for (var i = 0; i < targetObject.length; i++) {
  26219. if (targetObject[i].name === objectIndex) {
  26220. objectIndex = i;
  26221. break;
  26222. }
  26223. }
  26224. break;
  26225. default:
  26226. if (targetObject[objectName] === undefined) {
  26227. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  26228. return;
  26229. }
  26230. targetObject = targetObject[objectName];
  26231. }
  26232. if (objectIndex !== undefined) {
  26233. if (targetObject[objectIndex] === undefined) {
  26234. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  26235. return;
  26236. }
  26237. targetObject = targetObject[objectIndex];
  26238. }
  26239. } // resolve property
  26240. var nodeProperty = targetObject[propertyName];
  26241. if (nodeProperty === undefined) {
  26242. var nodeName = parsedPath.nodeName;
  26243. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  26244. return;
  26245. } // determine versioning scheme
  26246. var versioning = this.Versioning.None;
  26247. this.targetObject = targetObject;
  26248. if (targetObject.needsUpdate !== undefined) {
  26249. // material
  26250. versioning = this.Versioning.NeedsUpdate;
  26251. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  26252. // node transform
  26253. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26254. } // determine how the property gets bound
  26255. var bindingType = this.BindingType.Direct;
  26256. if (propertyIndex !== undefined) {
  26257. // access a sub element of the property array (only primitives are supported right now)
  26258. if (propertyName === "morphTargetInfluences") {
  26259. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26260. // support resolving morphTarget names into indices.
  26261. if (!targetObject.geometry) {
  26262. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  26263. return;
  26264. }
  26265. if (targetObject.geometry.isBufferGeometry) {
  26266. if (!targetObject.geometry.morphAttributes) {
  26267. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  26268. return;
  26269. }
  26270. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  26271. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  26272. }
  26273. } else {
  26274. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  26275. return;
  26276. }
  26277. }
  26278. bindingType = this.BindingType.ArrayElement;
  26279. this.resolvedProperty = nodeProperty;
  26280. this.propertyIndex = propertyIndex;
  26281. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26282. // must use copy for Object3D.Euler/Quaternion
  26283. bindingType = this.BindingType.HasFromToArray;
  26284. this.resolvedProperty = nodeProperty;
  26285. } else if (Array.isArray(nodeProperty)) {
  26286. bindingType = this.BindingType.EntireArray;
  26287. this.resolvedProperty = nodeProperty;
  26288. } else {
  26289. this.propertyName = propertyName;
  26290. } // select getter / setter
  26291. this.getValue = this.GetterByBindingType[bindingType];
  26292. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26293. },
  26294. unbind: function unbind() {
  26295. this.node = null; // back to the prototype version of getValue / setValue
  26296. // note: avoiding to mutate the shape of 'this' via 'delete'
  26297. this.getValue = this._getValue_unbound;
  26298. this.setValue = this._setValue_unbound;
  26299. }
  26300. }); // DECLARE ALIAS AFTER assign prototype
  26301. Object.assign(PropertyBinding.prototype, {
  26302. // initial state of these methods that calls 'bind'
  26303. _getValue_unbound: PropertyBinding.prototype.getValue,
  26304. _setValue_unbound: PropertyBinding.prototype.setValue
  26305. });
  26306. /**
  26307. *
  26308. * A group of objects that receives a shared animation state.
  26309. *
  26310. * Usage:
  26311. *
  26312. * - Add objects you would otherwise pass as 'root' to the
  26313. * constructor or the .clipAction method of AnimationMixer.
  26314. *
  26315. * - Instead pass this object as 'root'.
  26316. *
  26317. * - You can also add and remove objects later when the mixer
  26318. * is running.
  26319. *
  26320. * Note:
  26321. *
  26322. * Objects of this class appear as one object to the mixer,
  26323. * so cache control of the individual objects must be done
  26324. * on the group.
  26325. *
  26326. * Limitation:
  26327. *
  26328. * - The animated properties must be compatible among the
  26329. * all objects in the group.
  26330. *
  26331. * - A single property can either be controlled through a
  26332. * target group or directly, but not both.
  26333. */
  26334. function AnimationObjectGroup() {
  26335. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26336. this._objects = Array.prototype.slice.call(arguments);
  26337. this.nCachedObjects_ = 0; // threshold
  26338. // note: read by PropertyBinding.Composite
  26339. var indices = {};
  26340. this._indicesByUUID = indices; // for bookkeeping
  26341. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26342. indices[arguments[i].uuid] = i;
  26343. }
  26344. this._paths = []; // inside: string
  26345. this._parsedPaths = []; // inside: { we don't care, here }
  26346. this._bindings = []; // inside: Array< PropertyBinding >
  26347. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26348. var scope = this;
  26349. this.stats = {
  26350. objects: {
  26351. get total() {
  26352. return scope._objects.length;
  26353. },
  26354. get inUse() {
  26355. return this.total - scope.nCachedObjects_;
  26356. }
  26357. },
  26358. get bindingsPerObject() {
  26359. return scope._bindings.length;
  26360. }
  26361. };
  26362. }
  26363. Object.assign(AnimationObjectGroup.prototype, {
  26364. isAnimationObjectGroup: true,
  26365. add: function add() {
  26366. var objects = this._objects,
  26367. indicesByUUID = this._indicesByUUID,
  26368. paths = this._paths,
  26369. parsedPaths = this._parsedPaths,
  26370. bindings = this._bindings,
  26371. nBindings = bindings.length;
  26372. var knownObject = undefined,
  26373. nObjects = objects.length,
  26374. nCachedObjects = this.nCachedObjects_;
  26375. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26376. var object = arguments[i],
  26377. uuid = object.uuid;
  26378. var index = indicesByUUID[uuid];
  26379. if (index === undefined) {
  26380. // unknown object -> add it to the ACTIVE region
  26381. index = nObjects++;
  26382. indicesByUUID[uuid] = index;
  26383. objects.push(object); // accounting is done, now do the same for all bindings
  26384. for (var j = 0, m = nBindings; j !== m; ++j) {
  26385. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26386. }
  26387. } else if (index < nCachedObjects) {
  26388. knownObject = objects[index]; // move existing object to the ACTIVE region
  26389. var firstActiveIndex = --nCachedObjects,
  26390. lastCachedObject = objects[firstActiveIndex];
  26391. indicesByUUID[lastCachedObject.uuid] = index;
  26392. objects[index] = lastCachedObject;
  26393. indicesByUUID[uuid] = firstActiveIndex;
  26394. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26395. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26396. var bindingsForPath = bindings[_j],
  26397. lastCached = bindingsForPath[firstActiveIndex];
  26398. var binding = bindingsForPath[index];
  26399. bindingsForPath[index] = lastCached;
  26400. if (binding === undefined) {
  26401. // since we do not bother to create new bindings
  26402. // for objects that are cached, the binding may
  26403. // or may not exist
  26404. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26405. }
  26406. bindingsForPath[firstActiveIndex] = binding;
  26407. }
  26408. } else if (objects[index] !== knownObject) {
  26409. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26410. } // else the object is already where we want it to be
  26411. } // for arguments
  26412. this.nCachedObjects_ = nCachedObjects;
  26413. },
  26414. remove: function remove() {
  26415. var objects = this._objects,
  26416. indicesByUUID = this._indicesByUUID,
  26417. bindings = this._bindings,
  26418. nBindings = bindings.length;
  26419. var nCachedObjects = this.nCachedObjects_;
  26420. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26421. var object = arguments[i],
  26422. uuid = object.uuid,
  26423. index = indicesByUUID[uuid];
  26424. if (index !== undefined && index >= nCachedObjects) {
  26425. // move existing object into the CACHED region
  26426. var lastCachedIndex = nCachedObjects++,
  26427. firstActiveObject = objects[lastCachedIndex];
  26428. indicesByUUID[firstActiveObject.uuid] = index;
  26429. objects[index] = firstActiveObject;
  26430. indicesByUUID[uuid] = lastCachedIndex;
  26431. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26432. for (var j = 0, m = nBindings; j !== m; ++j) {
  26433. var bindingsForPath = bindings[j],
  26434. firstActive = bindingsForPath[lastCachedIndex],
  26435. binding = bindingsForPath[index];
  26436. bindingsForPath[index] = firstActive;
  26437. bindingsForPath[lastCachedIndex] = binding;
  26438. }
  26439. }
  26440. } // for arguments
  26441. this.nCachedObjects_ = nCachedObjects;
  26442. },
  26443. // remove & forget
  26444. uncache: function uncache() {
  26445. var objects = this._objects,
  26446. indicesByUUID = this._indicesByUUID,
  26447. bindings = this._bindings,
  26448. nBindings = bindings.length;
  26449. var nCachedObjects = this.nCachedObjects_,
  26450. nObjects = objects.length;
  26451. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26452. var object = arguments[i],
  26453. uuid = object.uuid,
  26454. index = indicesByUUID[uuid];
  26455. if (index !== undefined) {
  26456. delete indicesByUUID[uuid];
  26457. if (index < nCachedObjects) {
  26458. // object is cached, shrink the CACHED region
  26459. var firstActiveIndex = --nCachedObjects,
  26460. lastCachedObject = objects[firstActiveIndex],
  26461. lastIndex = --nObjects,
  26462. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26463. indicesByUUID[lastCachedObject.uuid] = index;
  26464. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26465. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26466. objects[firstActiveIndex] = lastObject;
  26467. objects.pop(); // accounting is done, now do the same for all bindings
  26468. for (var j = 0, m = nBindings; j !== m; ++j) {
  26469. var bindingsForPath = bindings[j],
  26470. lastCached = bindingsForPath[firstActiveIndex],
  26471. last = bindingsForPath[lastIndex];
  26472. bindingsForPath[index] = lastCached;
  26473. bindingsForPath[firstActiveIndex] = last;
  26474. bindingsForPath.pop();
  26475. }
  26476. } else {
  26477. // object is active, just swap with the last and pop
  26478. var _lastIndex = --nObjects,
  26479. _lastObject = objects[_lastIndex];
  26480. if (_lastIndex > 0) {
  26481. indicesByUUID[_lastObject.uuid] = index;
  26482. }
  26483. objects[index] = _lastObject;
  26484. objects.pop(); // accounting is done, now do the same for all bindings
  26485. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26486. var _bindingsForPath = bindings[_j2];
  26487. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26488. _bindingsForPath.pop();
  26489. }
  26490. } // cached or active
  26491. } // if object is known
  26492. } // for arguments
  26493. this.nCachedObjects_ = nCachedObjects;
  26494. },
  26495. // Internal interface used by befriended PropertyBinding.Composite:
  26496. subscribe_: function subscribe_(path, parsedPath) {
  26497. // returns an array of bindings for the given path that is changed
  26498. // according to the contained objects in the group
  26499. var indicesByPath = this._bindingsIndicesByPath;
  26500. var index = indicesByPath[path];
  26501. var bindings = this._bindings;
  26502. if (index !== undefined) return bindings[index];
  26503. var paths = this._paths,
  26504. parsedPaths = this._parsedPaths,
  26505. objects = this._objects,
  26506. nObjects = objects.length,
  26507. nCachedObjects = this.nCachedObjects_,
  26508. bindingsForPath = new Array(nObjects);
  26509. index = bindings.length;
  26510. indicesByPath[path] = index;
  26511. paths.push(path);
  26512. parsedPaths.push(parsedPath);
  26513. bindings.push(bindingsForPath);
  26514. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26515. var object = objects[i];
  26516. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26517. }
  26518. return bindingsForPath;
  26519. },
  26520. unsubscribe_: function unsubscribe_(path) {
  26521. // tells the group to forget about a property path and no longer
  26522. // update the array previously obtained with 'subscribe_'
  26523. var indicesByPath = this._bindingsIndicesByPath,
  26524. index = indicesByPath[path];
  26525. if (index !== undefined) {
  26526. var paths = this._paths,
  26527. parsedPaths = this._parsedPaths,
  26528. bindings = this._bindings,
  26529. lastBindingsIndex = bindings.length - 1,
  26530. lastBindings = bindings[lastBindingsIndex],
  26531. lastBindingsPath = path[lastBindingsIndex];
  26532. indicesByPath[lastBindingsPath] = index;
  26533. bindings[index] = lastBindings;
  26534. bindings.pop();
  26535. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26536. parsedPaths.pop();
  26537. paths[index] = paths[lastBindingsIndex];
  26538. paths.pop();
  26539. }
  26540. }
  26541. });
  26542. var AnimationAction = /*#__PURE__*/function () {
  26543. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26544. this._mixer = mixer;
  26545. this._clip = clip;
  26546. this._localRoot = localRoot || null;
  26547. this.blendMode = blendMode || clip.blendMode;
  26548. var tracks = clip.tracks,
  26549. nTracks = tracks.length,
  26550. interpolants = new Array(nTracks);
  26551. var interpolantSettings = {
  26552. endingStart: ZeroCurvatureEnding,
  26553. endingEnd: ZeroCurvatureEnding
  26554. };
  26555. for (var i = 0; i !== nTracks; ++i) {
  26556. var interpolant = tracks[i].createInterpolant(null);
  26557. interpolants[i] = interpolant;
  26558. interpolant.settings = interpolantSettings;
  26559. }
  26560. this._interpolantSettings = interpolantSettings;
  26561. this._interpolants = interpolants; // bound by the mixer
  26562. // inside: PropertyMixer (managed by the mixer)
  26563. this._propertyBindings = new Array(nTracks);
  26564. this._cacheIndex = null; // for the memory manager
  26565. this._byClipCacheIndex = null; // for the memory manager
  26566. this._timeScaleInterpolant = null;
  26567. this._weightInterpolant = null;
  26568. this.loop = LoopRepeat;
  26569. this._loopCount = -1; // global mixer time when the action is to be started
  26570. // it's set back to 'null' upon start of the action
  26571. this._startTime = null; // scaled local time of the action
  26572. // gets clamped or wrapped to 0..clip.duration according to loop
  26573. this.time = 0;
  26574. this.timeScale = 1;
  26575. this._effectiveTimeScale = 1;
  26576. this.weight = 1;
  26577. this._effectiveWeight = 1;
  26578. this.repetitions = Infinity; // no. of repetitions when looping
  26579. this.paused = false; // true -> zero effective time scale
  26580. this.enabled = true; // false -> zero effective weight
  26581. this.clampWhenFinished = false; // keep feeding the last frame?
  26582. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  26583. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  26584. } // State & Scheduling
  26585. var _proto = AnimationAction.prototype;
  26586. _proto.play = function play() {
  26587. this._mixer._activateAction(this);
  26588. return this;
  26589. };
  26590. _proto.stop = function stop() {
  26591. this._mixer._deactivateAction(this);
  26592. return this.reset();
  26593. };
  26594. _proto.reset = function reset() {
  26595. this.paused = false;
  26596. this.enabled = true;
  26597. this.time = 0; // restart clip
  26598. this._loopCount = -1; // forget previous loops
  26599. this._startTime = null; // forget scheduling
  26600. return this.stopFading().stopWarping();
  26601. };
  26602. _proto.isRunning = function isRunning() {
  26603. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  26604. } // return true when play has been called
  26605. ;
  26606. _proto.isScheduled = function isScheduled() {
  26607. return this._mixer._isActiveAction(this);
  26608. };
  26609. _proto.startAt = function startAt(time) {
  26610. this._startTime = time;
  26611. return this;
  26612. };
  26613. _proto.setLoop = function setLoop(mode, repetitions) {
  26614. this.loop = mode;
  26615. this.repetitions = repetitions;
  26616. return this;
  26617. } // Weight
  26618. // set the weight stopping any scheduled fading
  26619. // although .enabled = false yields an effective weight of zero, this
  26620. // method does *not* change .enabled, because it would be confusing
  26621. ;
  26622. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  26623. this.weight = weight; // note: same logic as when updated at runtime
  26624. this._effectiveWeight = this.enabled ? weight : 0;
  26625. return this.stopFading();
  26626. } // return the weight considering fading and .enabled
  26627. ;
  26628. _proto.getEffectiveWeight = function getEffectiveWeight() {
  26629. return this._effectiveWeight;
  26630. };
  26631. _proto.fadeIn = function fadeIn(duration) {
  26632. return this._scheduleFading(duration, 0, 1);
  26633. };
  26634. _proto.fadeOut = function fadeOut(duration) {
  26635. return this._scheduleFading(duration, 1, 0);
  26636. };
  26637. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  26638. fadeOutAction.fadeOut(duration);
  26639. this.fadeIn(duration);
  26640. if (warp) {
  26641. var fadeInDuration = this._clip.duration,
  26642. fadeOutDuration = fadeOutAction._clip.duration,
  26643. startEndRatio = fadeOutDuration / fadeInDuration,
  26644. endStartRatio = fadeInDuration / fadeOutDuration;
  26645. fadeOutAction.warp(1.0, startEndRatio, duration);
  26646. this.warp(endStartRatio, 1.0, duration);
  26647. }
  26648. return this;
  26649. };
  26650. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  26651. return fadeInAction.crossFadeFrom(this, duration, warp);
  26652. };
  26653. _proto.stopFading = function stopFading() {
  26654. var weightInterpolant = this._weightInterpolant;
  26655. if (weightInterpolant !== null) {
  26656. this._weightInterpolant = null;
  26657. this._mixer._takeBackControlInterpolant(weightInterpolant);
  26658. }
  26659. return this;
  26660. } // Time Scale Control
  26661. // set the time scale stopping any scheduled warping
  26662. // although .paused = true yields an effective time scale of zero, this
  26663. // method does *not* change .paused, because it would be confusing
  26664. ;
  26665. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  26666. this.timeScale = timeScale;
  26667. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26668. return this.stopWarping();
  26669. } // return the time scale considering warping and .paused
  26670. ;
  26671. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  26672. return this._effectiveTimeScale;
  26673. };
  26674. _proto.setDuration = function setDuration(duration) {
  26675. this.timeScale = this._clip.duration / duration;
  26676. return this.stopWarping();
  26677. };
  26678. _proto.syncWith = function syncWith(action) {
  26679. this.time = action.time;
  26680. this.timeScale = action.timeScale;
  26681. return this.stopWarping();
  26682. };
  26683. _proto.halt = function halt(duration) {
  26684. return this.warp(this._effectiveTimeScale, 0, duration);
  26685. };
  26686. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  26687. var mixer = this._mixer,
  26688. now = mixer.time,
  26689. timeScale = this.timeScale;
  26690. var interpolant = this._timeScaleInterpolant;
  26691. if (interpolant === null) {
  26692. interpolant = mixer._lendControlInterpolant();
  26693. this._timeScaleInterpolant = interpolant;
  26694. }
  26695. var times = interpolant.parameterPositions,
  26696. values = interpolant.sampleValues;
  26697. times[0] = now;
  26698. times[1] = now + duration;
  26699. values[0] = startTimeScale / timeScale;
  26700. values[1] = endTimeScale / timeScale;
  26701. return this;
  26702. };
  26703. _proto.stopWarping = function stopWarping() {
  26704. var timeScaleInterpolant = this._timeScaleInterpolant;
  26705. if (timeScaleInterpolant !== null) {
  26706. this._timeScaleInterpolant = null;
  26707. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  26708. }
  26709. return this;
  26710. } // Object Accessors
  26711. ;
  26712. _proto.getMixer = function getMixer() {
  26713. return this._mixer;
  26714. };
  26715. _proto.getClip = function getClip() {
  26716. return this._clip;
  26717. };
  26718. _proto.getRoot = function getRoot() {
  26719. return this._localRoot || this._mixer._root;
  26720. } // Interna
  26721. ;
  26722. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  26723. // called by the mixer
  26724. if (!this.enabled) {
  26725. // call ._updateWeight() to update ._effectiveWeight
  26726. this._updateWeight(time);
  26727. return;
  26728. }
  26729. var startTime = this._startTime;
  26730. if (startTime !== null) {
  26731. // check for scheduled start of action
  26732. var timeRunning = (time - startTime) * timeDirection;
  26733. if (timeRunning < 0 || timeDirection === 0) {
  26734. return; // yet to come / don't decide when delta = 0
  26735. } // start
  26736. this._startTime = null; // unschedule
  26737. deltaTime = timeDirection * timeRunning;
  26738. } // apply time scale and advance time
  26739. deltaTime *= this._updateTimeScale(time);
  26740. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  26741. // an effective weight of 0
  26742. var weight = this._updateWeight(time);
  26743. if (weight > 0) {
  26744. var _interpolants = this._interpolants;
  26745. var propertyMixers = this._propertyBindings;
  26746. switch (this.blendMode) {
  26747. case AdditiveAnimationBlendMode:
  26748. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  26749. _interpolants[j].evaluate(clipTime);
  26750. propertyMixers[j].accumulateAdditive(weight);
  26751. }
  26752. break;
  26753. case NormalAnimationBlendMode:
  26754. default:
  26755. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  26756. _interpolants[_j].evaluate(clipTime);
  26757. propertyMixers[_j].accumulate(accuIndex, weight);
  26758. }
  26759. }
  26760. }
  26761. };
  26762. _proto._updateWeight = function _updateWeight(time) {
  26763. var weight = 0;
  26764. if (this.enabled) {
  26765. weight = this.weight;
  26766. var interpolant = this._weightInterpolant;
  26767. if (interpolant !== null) {
  26768. var interpolantValue = interpolant.evaluate(time)[0];
  26769. weight *= interpolantValue;
  26770. if (time > interpolant.parameterPositions[1]) {
  26771. this.stopFading();
  26772. if (interpolantValue === 0) {
  26773. // faded out, disable
  26774. this.enabled = false;
  26775. }
  26776. }
  26777. }
  26778. }
  26779. this._effectiveWeight = weight;
  26780. return weight;
  26781. };
  26782. _proto._updateTimeScale = function _updateTimeScale(time) {
  26783. var timeScale = 0;
  26784. if (!this.paused) {
  26785. timeScale = this.timeScale;
  26786. var interpolant = this._timeScaleInterpolant;
  26787. if (interpolant !== null) {
  26788. var interpolantValue = interpolant.evaluate(time)[0];
  26789. timeScale *= interpolantValue;
  26790. if (time > interpolant.parameterPositions[1]) {
  26791. this.stopWarping();
  26792. if (timeScale === 0) {
  26793. // motion has halted, pause
  26794. this.paused = true;
  26795. } else {
  26796. // warp done - apply final time scale
  26797. this.timeScale = timeScale;
  26798. }
  26799. }
  26800. }
  26801. }
  26802. this._effectiveTimeScale = timeScale;
  26803. return timeScale;
  26804. };
  26805. _proto._updateTime = function _updateTime(deltaTime) {
  26806. var duration = this._clip.duration;
  26807. var loop = this.loop;
  26808. var time = this.time + deltaTime;
  26809. var loopCount = this._loopCount;
  26810. var pingPong = loop === LoopPingPong;
  26811. if (deltaTime === 0) {
  26812. if (loopCount === -1) return time;
  26813. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  26814. }
  26815. if (loop === LoopOnce) {
  26816. if (loopCount === -1) {
  26817. // just started
  26818. this._loopCount = 0;
  26819. this._setEndings(true, true, false);
  26820. }
  26821. handle_stop: {
  26822. if (time >= duration) {
  26823. time = duration;
  26824. } else if (time < 0) {
  26825. time = 0;
  26826. } else {
  26827. this.time = time;
  26828. break handle_stop;
  26829. }
  26830. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26831. this.time = time;
  26832. this._mixer.dispatchEvent({
  26833. type: 'finished',
  26834. action: this,
  26835. direction: deltaTime < 0 ? -1 : 1
  26836. });
  26837. }
  26838. } else {
  26839. // repetitive Repeat or PingPong
  26840. if (loopCount === -1) {
  26841. // just started
  26842. if (deltaTime >= 0) {
  26843. loopCount = 0;
  26844. this._setEndings(true, this.repetitions === 0, pingPong);
  26845. } else {
  26846. // when looping in reverse direction, the initial
  26847. // transition through zero counts as a repetition,
  26848. // so leave loopCount at -1
  26849. this._setEndings(this.repetitions === 0, true, pingPong);
  26850. }
  26851. }
  26852. if (time >= duration || time < 0) {
  26853. // wrap around
  26854. var loopDelta = Math.floor(time / duration); // signed
  26855. time -= duration * loopDelta;
  26856. loopCount += Math.abs(loopDelta);
  26857. var pending = this.repetitions - loopCount;
  26858. if (pending <= 0) {
  26859. // have to stop (switch state, clamp time, fire event)
  26860. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26861. time = deltaTime > 0 ? duration : 0;
  26862. this.time = time;
  26863. this._mixer.dispatchEvent({
  26864. type: 'finished',
  26865. action: this,
  26866. direction: deltaTime > 0 ? 1 : -1
  26867. });
  26868. } else {
  26869. // keep running
  26870. if (pending === 1) {
  26871. // entering the last round
  26872. var atStart = deltaTime < 0;
  26873. this._setEndings(atStart, !atStart, pingPong);
  26874. } else {
  26875. this._setEndings(false, false, pingPong);
  26876. }
  26877. this._loopCount = loopCount;
  26878. this.time = time;
  26879. this._mixer.dispatchEvent({
  26880. type: 'loop',
  26881. action: this,
  26882. loopDelta: loopDelta
  26883. });
  26884. }
  26885. } else {
  26886. this.time = time;
  26887. }
  26888. if (pingPong && (loopCount & 1) === 1) {
  26889. // invert time for the "pong round"
  26890. return duration - time;
  26891. }
  26892. }
  26893. return time;
  26894. };
  26895. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  26896. var settings = this._interpolantSettings;
  26897. if (pingPong) {
  26898. settings.endingStart = ZeroSlopeEnding;
  26899. settings.endingEnd = ZeroSlopeEnding;
  26900. } else {
  26901. // assuming for LoopOnce atStart == atEnd == true
  26902. if (atStart) {
  26903. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26904. } else {
  26905. settings.endingStart = WrapAroundEnding;
  26906. }
  26907. if (atEnd) {
  26908. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26909. } else {
  26910. settings.endingEnd = WrapAroundEnding;
  26911. }
  26912. }
  26913. };
  26914. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  26915. var mixer = this._mixer,
  26916. now = mixer.time;
  26917. var interpolant = this._weightInterpolant;
  26918. if (interpolant === null) {
  26919. interpolant = mixer._lendControlInterpolant();
  26920. this._weightInterpolant = interpolant;
  26921. }
  26922. var times = interpolant.parameterPositions,
  26923. values = interpolant.sampleValues;
  26924. times[0] = now;
  26925. values[0] = weightNow;
  26926. times[1] = now + duration;
  26927. values[1] = weightThen;
  26928. return this;
  26929. };
  26930. return AnimationAction;
  26931. }();
  26932. function AnimationMixer(root) {
  26933. this._root = root;
  26934. this._initMemoryManager();
  26935. this._accuIndex = 0;
  26936. this.time = 0;
  26937. this.timeScale = 1.0;
  26938. }
  26939. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  26940. constructor: AnimationMixer,
  26941. _bindAction: function _bindAction(action, prototypeAction) {
  26942. var root = action._localRoot || this._root,
  26943. tracks = action._clip.tracks,
  26944. nTracks = tracks.length,
  26945. bindings = action._propertyBindings,
  26946. interpolants = action._interpolants,
  26947. rootUuid = root.uuid,
  26948. bindingsByRoot = this._bindingsByRootAndName;
  26949. var bindingsByName = bindingsByRoot[rootUuid];
  26950. if (bindingsByName === undefined) {
  26951. bindingsByName = {};
  26952. bindingsByRoot[rootUuid] = bindingsByName;
  26953. }
  26954. for (var i = 0; i !== nTracks; ++i) {
  26955. var track = tracks[i],
  26956. trackName = track.name;
  26957. var binding = bindingsByName[trackName];
  26958. if (binding !== undefined) {
  26959. bindings[i] = binding;
  26960. } else {
  26961. binding = bindings[i];
  26962. if (binding !== undefined) {
  26963. // existing binding, make sure the cache knows
  26964. if (binding._cacheIndex === null) {
  26965. ++binding.referenceCount;
  26966. this._addInactiveBinding(binding, rootUuid, trackName);
  26967. }
  26968. continue;
  26969. }
  26970. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  26971. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  26972. ++binding.referenceCount;
  26973. this._addInactiveBinding(binding, rootUuid, trackName);
  26974. bindings[i] = binding;
  26975. }
  26976. interpolants[i].resultBuffer = binding.buffer;
  26977. }
  26978. },
  26979. _activateAction: function _activateAction(action) {
  26980. if (!this._isActiveAction(action)) {
  26981. if (action._cacheIndex === null) {
  26982. // this action has been forgotten by the cache, but the user
  26983. // appears to be still using it -> rebind
  26984. var rootUuid = (action._localRoot || this._root).uuid,
  26985. clipUuid = action._clip.uuid,
  26986. actionsForClip = this._actionsByClip[clipUuid];
  26987. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  26988. this._addInactiveAction(action, clipUuid, rootUuid);
  26989. }
  26990. var bindings = action._propertyBindings; // increment reference counts / sort out state
  26991. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26992. var binding = bindings[i];
  26993. if (binding.useCount++ === 0) {
  26994. this._lendBinding(binding);
  26995. binding.saveOriginalState();
  26996. }
  26997. }
  26998. this._lendAction(action);
  26999. }
  27000. },
  27001. _deactivateAction: function _deactivateAction(action) {
  27002. if (this._isActiveAction(action)) {
  27003. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  27004. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27005. var binding = bindings[i];
  27006. if (--binding.useCount === 0) {
  27007. binding.restoreOriginalState();
  27008. this._takeBackBinding(binding);
  27009. }
  27010. }
  27011. this._takeBackAction(action);
  27012. }
  27013. },
  27014. // Memory manager
  27015. _initMemoryManager: function _initMemoryManager() {
  27016. this._actions = []; // 'nActiveActions' followed by inactive ones
  27017. this._nActiveActions = 0;
  27018. this._actionsByClip = {}; // inside:
  27019. // {
  27020. // knownActions: Array< AnimationAction > - used as prototypes
  27021. // actionByRoot: AnimationAction - lookup
  27022. // }
  27023. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  27024. this._nActiveBindings = 0;
  27025. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  27026. this._controlInterpolants = []; // same game as above
  27027. this._nActiveControlInterpolants = 0;
  27028. var scope = this;
  27029. this.stats = {
  27030. actions: {
  27031. get total() {
  27032. return scope._actions.length;
  27033. },
  27034. get inUse() {
  27035. return scope._nActiveActions;
  27036. }
  27037. },
  27038. bindings: {
  27039. get total() {
  27040. return scope._bindings.length;
  27041. },
  27042. get inUse() {
  27043. return scope._nActiveBindings;
  27044. }
  27045. },
  27046. controlInterpolants: {
  27047. get total() {
  27048. return scope._controlInterpolants.length;
  27049. },
  27050. get inUse() {
  27051. return scope._nActiveControlInterpolants;
  27052. }
  27053. }
  27054. };
  27055. },
  27056. // Memory management for AnimationAction objects
  27057. _isActiveAction: function _isActiveAction(action) {
  27058. var index = action._cacheIndex;
  27059. return index !== null && index < this._nActiveActions;
  27060. },
  27061. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  27062. var actions = this._actions,
  27063. actionsByClip = this._actionsByClip;
  27064. var actionsForClip = actionsByClip[clipUuid];
  27065. if (actionsForClip === undefined) {
  27066. actionsForClip = {
  27067. knownActions: [action],
  27068. actionByRoot: {}
  27069. };
  27070. action._byClipCacheIndex = 0;
  27071. actionsByClip[clipUuid] = actionsForClip;
  27072. } else {
  27073. var knownActions = actionsForClip.knownActions;
  27074. action._byClipCacheIndex = knownActions.length;
  27075. knownActions.push(action);
  27076. }
  27077. action._cacheIndex = actions.length;
  27078. actions.push(action);
  27079. actionsForClip.actionByRoot[rootUuid] = action;
  27080. },
  27081. _removeInactiveAction: function _removeInactiveAction(action) {
  27082. var actions = this._actions,
  27083. lastInactiveAction = actions[actions.length - 1],
  27084. cacheIndex = action._cacheIndex;
  27085. lastInactiveAction._cacheIndex = cacheIndex;
  27086. actions[cacheIndex] = lastInactiveAction;
  27087. actions.pop();
  27088. action._cacheIndex = null;
  27089. var clipUuid = action._clip.uuid,
  27090. actionsByClip = this._actionsByClip,
  27091. actionsForClip = actionsByClip[clipUuid],
  27092. knownActionsForClip = actionsForClip.knownActions,
  27093. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  27094. byClipCacheIndex = action._byClipCacheIndex;
  27095. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  27096. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  27097. knownActionsForClip.pop();
  27098. action._byClipCacheIndex = null;
  27099. var actionByRoot = actionsForClip.actionByRoot,
  27100. rootUuid = (action._localRoot || this._root).uuid;
  27101. delete actionByRoot[rootUuid];
  27102. if (knownActionsForClip.length === 0) {
  27103. delete actionsByClip[clipUuid];
  27104. }
  27105. this._removeInactiveBindingsForAction(action);
  27106. },
  27107. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  27108. var bindings = action._propertyBindings;
  27109. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27110. var binding = bindings[i];
  27111. if (--binding.referenceCount === 0) {
  27112. this._removeInactiveBinding(binding);
  27113. }
  27114. }
  27115. },
  27116. _lendAction: function _lendAction(action) {
  27117. // [ active actions | inactive actions ]
  27118. // [ active actions >| inactive actions ]
  27119. // s a
  27120. // <-swap->
  27121. // a s
  27122. var actions = this._actions,
  27123. prevIndex = action._cacheIndex,
  27124. lastActiveIndex = this._nActiveActions++,
  27125. firstInactiveAction = actions[lastActiveIndex];
  27126. action._cacheIndex = lastActiveIndex;
  27127. actions[lastActiveIndex] = action;
  27128. firstInactiveAction._cacheIndex = prevIndex;
  27129. actions[prevIndex] = firstInactiveAction;
  27130. },
  27131. _takeBackAction: function _takeBackAction(action) {
  27132. // [ active actions | inactive actions ]
  27133. // [ active actions |< inactive actions ]
  27134. // a s
  27135. // <-swap->
  27136. // s a
  27137. var actions = this._actions,
  27138. prevIndex = action._cacheIndex,
  27139. firstInactiveIndex = --this._nActiveActions,
  27140. lastActiveAction = actions[firstInactiveIndex];
  27141. action._cacheIndex = firstInactiveIndex;
  27142. actions[firstInactiveIndex] = action;
  27143. lastActiveAction._cacheIndex = prevIndex;
  27144. actions[prevIndex] = lastActiveAction;
  27145. },
  27146. // Memory management for PropertyMixer objects
  27147. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  27148. var bindingsByRoot = this._bindingsByRootAndName,
  27149. bindings = this._bindings;
  27150. var bindingByName = bindingsByRoot[rootUuid];
  27151. if (bindingByName === undefined) {
  27152. bindingByName = {};
  27153. bindingsByRoot[rootUuid] = bindingByName;
  27154. }
  27155. bindingByName[trackName] = binding;
  27156. binding._cacheIndex = bindings.length;
  27157. bindings.push(binding);
  27158. },
  27159. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  27160. var bindings = this._bindings,
  27161. propBinding = binding.binding,
  27162. rootUuid = propBinding.rootNode.uuid,
  27163. trackName = propBinding.path,
  27164. bindingsByRoot = this._bindingsByRootAndName,
  27165. bindingByName = bindingsByRoot[rootUuid],
  27166. lastInactiveBinding = bindings[bindings.length - 1],
  27167. cacheIndex = binding._cacheIndex;
  27168. lastInactiveBinding._cacheIndex = cacheIndex;
  27169. bindings[cacheIndex] = lastInactiveBinding;
  27170. bindings.pop();
  27171. delete bindingByName[trackName];
  27172. if (Object.keys(bindingByName).length === 0) {
  27173. delete bindingsByRoot[rootUuid];
  27174. }
  27175. },
  27176. _lendBinding: function _lendBinding(binding) {
  27177. var bindings = this._bindings,
  27178. prevIndex = binding._cacheIndex,
  27179. lastActiveIndex = this._nActiveBindings++,
  27180. firstInactiveBinding = bindings[lastActiveIndex];
  27181. binding._cacheIndex = lastActiveIndex;
  27182. bindings[lastActiveIndex] = binding;
  27183. firstInactiveBinding._cacheIndex = prevIndex;
  27184. bindings[prevIndex] = firstInactiveBinding;
  27185. },
  27186. _takeBackBinding: function _takeBackBinding(binding) {
  27187. var bindings = this._bindings,
  27188. prevIndex = binding._cacheIndex,
  27189. firstInactiveIndex = --this._nActiveBindings,
  27190. lastActiveBinding = bindings[firstInactiveIndex];
  27191. binding._cacheIndex = firstInactiveIndex;
  27192. bindings[firstInactiveIndex] = binding;
  27193. lastActiveBinding._cacheIndex = prevIndex;
  27194. bindings[prevIndex] = lastActiveBinding;
  27195. },
  27196. // Memory management of Interpolants for weight and time scale
  27197. _lendControlInterpolant: function _lendControlInterpolant() {
  27198. var interpolants = this._controlInterpolants,
  27199. lastActiveIndex = this._nActiveControlInterpolants++;
  27200. var interpolant = interpolants[lastActiveIndex];
  27201. if (interpolant === undefined) {
  27202. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  27203. interpolant.__cacheIndex = lastActiveIndex;
  27204. interpolants[lastActiveIndex] = interpolant;
  27205. }
  27206. return interpolant;
  27207. },
  27208. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  27209. var interpolants = this._controlInterpolants,
  27210. prevIndex = interpolant.__cacheIndex,
  27211. firstInactiveIndex = --this._nActiveControlInterpolants,
  27212. lastActiveInterpolant = interpolants[firstInactiveIndex];
  27213. interpolant.__cacheIndex = firstInactiveIndex;
  27214. interpolants[firstInactiveIndex] = interpolant;
  27215. lastActiveInterpolant.__cacheIndex = prevIndex;
  27216. interpolants[prevIndex] = lastActiveInterpolant;
  27217. },
  27218. _controlInterpolantsResultBuffer: new Float32Array(1),
  27219. // return an action for a clip optionally using a custom root target
  27220. // object (this method allocates a lot of dynamic memory in case a
  27221. // previously unknown clip/root combination is specified)
  27222. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  27223. var root = optionalRoot || this._root,
  27224. rootUuid = root.uuid;
  27225. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  27226. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  27227. var actionsForClip = this._actionsByClip[clipUuid];
  27228. var prototypeAction = null;
  27229. if (blendMode === undefined) {
  27230. if (clipObject !== null) {
  27231. blendMode = clipObject.blendMode;
  27232. } else {
  27233. blendMode = NormalAnimationBlendMode;
  27234. }
  27235. }
  27236. if (actionsForClip !== undefined) {
  27237. var existingAction = actionsForClip.actionByRoot[rootUuid];
  27238. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  27239. return existingAction;
  27240. } // we know the clip, so we don't have to parse all
  27241. // the bindings again but can just copy
  27242. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  27243. if (clipObject === null) clipObject = prototypeAction._clip;
  27244. } // clip must be known when specified via string
  27245. if (clipObject === null) return null; // allocate all resources required to run it
  27246. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  27247. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  27248. this._addInactiveAction(newAction, clipUuid, rootUuid);
  27249. return newAction;
  27250. },
  27251. // get an existing action
  27252. existingAction: function existingAction(clip, optionalRoot) {
  27253. var root = optionalRoot || this._root,
  27254. rootUuid = root.uuid,
  27255. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  27256. clipUuid = clipObject ? clipObject.uuid : clip,
  27257. actionsForClip = this._actionsByClip[clipUuid];
  27258. if (actionsForClip !== undefined) {
  27259. return actionsForClip.actionByRoot[rootUuid] || null;
  27260. }
  27261. return null;
  27262. },
  27263. // deactivates all previously scheduled actions
  27264. stopAllAction: function stopAllAction() {
  27265. var actions = this._actions,
  27266. nActions = this._nActiveActions;
  27267. for (var i = nActions - 1; i >= 0; --i) {
  27268. actions[i].stop();
  27269. }
  27270. return this;
  27271. },
  27272. // advance the time and update apply the animation
  27273. update: function update(deltaTime) {
  27274. deltaTime *= this.timeScale;
  27275. var actions = this._actions,
  27276. nActions = this._nActiveActions,
  27277. time = this.time += deltaTime,
  27278. timeDirection = Math.sign(deltaTime),
  27279. accuIndex = this._accuIndex ^= 1; // run active actions
  27280. for (var i = 0; i !== nActions; ++i) {
  27281. var action = actions[i];
  27282. action._update(time, deltaTime, timeDirection, accuIndex);
  27283. } // update scene graph
  27284. var bindings = this._bindings,
  27285. nBindings = this._nActiveBindings;
  27286. for (var _i = 0; _i !== nBindings; ++_i) {
  27287. bindings[_i].apply(accuIndex);
  27288. }
  27289. return this;
  27290. },
  27291. // Allows you to seek to a specific time in an animation.
  27292. setTime: function setTime(timeInSeconds) {
  27293. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27294. for (var i = 0; i < this._actions.length; i++) {
  27295. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27296. }
  27297. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27298. },
  27299. // return this mixer's root target object
  27300. getRoot: function getRoot() {
  27301. return this._root;
  27302. },
  27303. // free all resources specific to a particular clip
  27304. uncacheClip: function uncacheClip(clip) {
  27305. var actions = this._actions,
  27306. clipUuid = clip.uuid,
  27307. actionsByClip = this._actionsByClip,
  27308. actionsForClip = actionsByClip[clipUuid];
  27309. if (actionsForClip !== undefined) {
  27310. // note: just calling _removeInactiveAction would mess up the
  27311. // iteration state and also require updating the state we can
  27312. // just throw away
  27313. var actionsToRemove = actionsForClip.knownActions;
  27314. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27315. var action = actionsToRemove[i];
  27316. this._deactivateAction(action);
  27317. var cacheIndex = action._cacheIndex,
  27318. lastInactiveAction = actions[actions.length - 1];
  27319. action._cacheIndex = null;
  27320. action._byClipCacheIndex = null;
  27321. lastInactiveAction._cacheIndex = cacheIndex;
  27322. actions[cacheIndex] = lastInactiveAction;
  27323. actions.pop();
  27324. this._removeInactiveBindingsForAction(action);
  27325. }
  27326. delete actionsByClip[clipUuid];
  27327. }
  27328. },
  27329. // free all resources specific to a particular root target object
  27330. uncacheRoot: function uncacheRoot(root) {
  27331. var rootUuid = root.uuid,
  27332. actionsByClip = this._actionsByClip;
  27333. for (var clipUuid in actionsByClip) {
  27334. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27335. action = actionByRoot[rootUuid];
  27336. if (action !== undefined) {
  27337. this._deactivateAction(action);
  27338. this._removeInactiveAction(action);
  27339. }
  27340. }
  27341. var bindingsByRoot = this._bindingsByRootAndName,
  27342. bindingByName = bindingsByRoot[rootUuid];
  27343. if (bindingByName !== undefined) {
  27344. for (var trackName in bindingByName) {
  27345. var binding = bindingByName[trackName];
  27346. binding.restoreOriginalState();
  27347. this._removeInactiveBinding(binding);
  27348. }
  27349. }
  27350. },
  27351. // remove a targeted clip from the cache
  27352. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27353. var action = this.existingAction(clip, optionalRoot);
  27354. if (action !== null) {
  27355. this._deactivateAction(action);
  27356. this._removeInactiveAction(action);
  27357. }
  27358. }
  27359. });
  27360. var Uniform = /*#__PURE__*/function () {
  27361. function Uniform(value) {
  27362. if (typeof value === 'string') {
  27363. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27364. value = arguments[1];
  27365. }
  27366. this.value = value;
  27367. }
  27368. var _proto = Uniform.prototype;
  27369. _proto.clone = function clone() {
  27370. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27371. };
  27372. return Uniform;
  27373. }();
  27374. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27375. InterleavedBuffer.call(this, array, stride);
  27376. this.meshPerAttribute = meshPerAttribute || 1;
  27377. }
  27378. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27379. constructor: InstancedInterleavedBuffer,
  27380. isInstancedInterleavedBuffer: true,
  27381. copy: function copy(source) {
  27382. InterleavedBuffer.prototype.copy.call(this, source);
  27383. this.meshPerAttribute = source.meshPerAttribute;
  27384. return this;
  27385. },
  27386. clone: function clone(data) {
  27387. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27388. ib.meshPerAttribute = this.meshPerAttribute;
  27389. return ib;
  27390. },
  27391. toJSON: function toJSON(data) {
  27392. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27393. json.isInstancedInterleavedBuffer = true;
  27394. json.meshPerAttribute = this.meshPerAttribute;
  27395. return json;
  27396. }
  27397. });
  27398. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27399. this.buffer = buffer;
  27400. this.type = type;
  27401. this.itemSize = itemSize;
  27402. this.elementSize = elementSize;
  27403. this.count = count;
  27404. this.version = 0;
  27405. }
  27406. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27407. set: function set(value) {
  27408. if (value === true) this.version++;
  27409. }
  27410. });
  27411. Object.assign(GLBufferAttribute.prototype, {
  27412. isGLBufferAttribute: true,
  27413. setBuffer: function setBuffer(buffer) {
  27414. this.buffer = buffer;
  27415. return this;
  27416. },
  27417. setType: function setType(type, elementSize) {
  27418. this.type = type;
  27419. this.elementSize = elementSize;
  27420. return this;
  27421. },
  27422. setItemSize: function setItemSize(itemSize) {
  27423. this.itemSize = itemSize;
  27424. return this;
  27425. },
  27426. setCount: function setCount(count) {
  27427. this.count = count;
  27428. return this;
  27429. }
  27430. });
  27431. function Raycaster(origin, direction, near, far) {
  27432. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27433. this.near = near || 0;
  27434. this.far = far || Infinity;
  27435. this.camera = null;
  27436. this.layers = new Layers();
  27437. this.params = {
  27438. Mesh: {},
  27439. Line: {
  27440. threshold: 1
  27441. },
  27442. LOD: {},
  27443. Points: {
  27444. threshold: 1
  27445. },
  27446. Sprite: {}
  27447. };
  27448. Object.defineProperties(this.params, {
  27449. PointCloud: {
  27450. get: function get() {
  27451. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27452. return this.Points;
  27453. }
  27454. }
  27455. });
  27456. }
  27457. function ascSort(a, b) {
  27458. return a.distance - b.distance;
  27459. }
  27460. function _intersectObject(object, raycaster, intersects, recursive) {
  27461. if (object.layers.test(raycaster.layers)) {
  27462. object.raycast(raycaster, intersects);
  27463. }
  27464. if (recursive === true) {
  27465. var children = object.children;
  27466. for (var i = 0, l = children.length; i < l; i++) {
  27467. _intersectObject(children[i], raycaster, intersects, true);
  27468. }
  27469. }
  27470. }
  27471. Object.assign(Raycaster.prototype, {
  27472. set: function set(origin, direction) {
  27473. // direction is assumed to be normalized (for accurate distance calculations)
  27474. this.ray.set(origin, direction);
  27475. },
  27476. setFromCamera: function setFromCamera(coords, camera) {
  27477. if (camera && camera.isPerspectiveCamera) {
  27478. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27479. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27480. this.camera = camera;
  27481. } else if (camera && camera.isOrthographicCamera) {
  27482. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27483. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27484. this.camera = camera;
  27485. } else {
  27486. console.error('THREE.Raycaster: Unsupported camera type.');
  27487. }
  27488. },
  27489. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27490. var intersects = optionalTarget || [];
  27491. _intersectObject(object, this, intersects, recursive);
  27492. intersects.sort(ascSort);
  27493. return intersects;
  27494. },
  27495. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27496. var intersects = optionalTarget || [];
  27497. if (Array.isArray(objects) === false) {
  27498. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27499. return intersects;
  27500. }
  27501. for (var i = 0, l = objects.length; i < l; i++) {
  27502. _intersectObject(objects[i], this, intersects, recursive);
  27503. }
  27504. intersects.sort(ascSort);
  27505. return intersects;
  27506. }
  27507. });
  27508. /**
  27509. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27510. *
  27511. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27512. * The azimuthal angle (theta) is measured from the positive z-axis.
  27513. */
  27514. var Spherical = /*#__PURE__*/function () {
  27515. function Spherical(radius, phi, theta) {
  27516. if (radius === void 0) {
  27517. radius = 1;
  27518. }
  27519. if (phi === void 0) {
  27520. phi = 0;
  27521. }
  27522. if (theta === void 0) {
  27523. theta = 0;
  27524. }
  27525. this.radius = radius;
  27526. this.phi = phi; // polar angle
  27527. this.theta = theta; // azimuthal angle
  27528. return this;
  27529. }
  27530. var _proto = Spherical.prototype;
  27531. _proto.set = function set(radius, phi, theta) {
  27532. this.radius = radius;
  27533. this.phi = phi;
  27534. this.theta = theta;
  27535. return this;
  27536. };
  27537. _proto.clone = function clone() {
  27538. return new this.constructor().copy(this);
  27539. };
  27540. _proto.copy = function copy(other) {
  27541. this.radius = other.radius;
  27542. this.phi = other.phi;
  27543. this.theta = other.theta;
  27544. return this;
  27545. } // restrict phi to be betwee EPS and PI-EPS
  27546. ;
  27547. _proto.makeSafe = function makeSafe() {
  27548. var EPS = 0.000001;
  27549. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27550. return this;
  27551. };
  27552. _proto.setFromVector3 = function setFromVector3(v) {
  27553. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27554. };
  27555. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27556. this.radius = Math.sqrt(x * x + y * y + z * z);
  27557. if (this.radius === 0) {
  27558. this.theta = 0;
  27559. this.phi = 0;
  27560. } else {
  27561. this.theta = Math.atan2(x, z);
  27562. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27563. }
  27564. return this;
  27565. };
  27566. return Spherical;
  27567. }();
  27568. /**
  27569. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27570. */
  27571. var Cylindrical = /*#__PURE__*/function () {
  27572. function Cylindrical(radius, theta, y) {
  27573. this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27574. this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27575. this.y = y !== undefined ? y : 0; // height above the x-z plane
  27576. return this;
  27577. }
  27578. var _proto = Cylindrical.prototype;
  27579. _proto.set = function set(radius, theta, y) {
  27580. this.radius = radius;
  27581. this.theta = theta;
  27582. this.y = y;
  27583. return this;
  27584. };
  27585. _proto.clone = function clone() {
  27586. return new this.constructor().copy(this);
  27587. };
  27588. _proto.copy = function copy(other) {
  27589. this.radius = other.radius;
  27590. this.theta = other.theta;
  27591. this.y = other.y;
  27592. return this;
  27593. };
  27594. _proto.setFromVector3 = function setFromVector3(v) {
  27595. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27596. };
  27597. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27598. this.radius = Math.sqrt(x * x + z * z);
  27599. this.theta = Math.atan2(x, z);
  27600. this.y = y;
  27601. return this;
  27602. };
  27603. return Cylindrical;
  27604. }();
  27605. var _vector$7 = /*@__PURE__*/new Vector2();
  27606. var Box2 = /*#__PURE__*/function () {
  27607. function Box2(min, max) {
  27608. Object.defineProperty(this, 'isBox2', {
  27609. value: true
  27610. });
  27611. this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
  27612. this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
  27613. }
  27614. var _proto = Box2.prototype;
  27615. _proto.set = function set(min, max) {
  27616. this.min.copy(min);
  27617. this.max.copy(max);
  27618. return this;
  27619. };
  27620. _proto.setFromPoints = function setFromPoints(points) {
  27621. this.makeEmpty();
  27622. for (var i = 0, il = points.length; i < il; i++) {
  27623. this.expandByPoint(points[i]);
  27624. }
  27625. return this;
  27626. };
  27627. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  27628. var halfSize = _vector$7.copy(size).multiplyScalar(0.5);
  27629. this.min.copy(center).sub(halfSize);
  27630. this.max.copy(center).add(halfSize);
  27631. return this;
  27632. };
  27633. _proto.clone = function clone() {
  27634. return new this.constructor().copy(this);
  27635. };
  27636. _proto.copy = function copy(box) {
  27637. this.min.copy(box.min);
  27638. this.max.copy(box.max);
  27639. return this;
  27640. };
  27641. _proto.makeEmpty = function makeEmpty() {
  27642. this.min.x = this.min.y = +Infinity;
  27643. this.max.x = this.max.y = -Infinity;
  27644. return this;
  27645. };
  27646. _proto.isEmpty = function isEmpty() {
  27647. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27648. return this.max.x < this.min.x || this.max.y < this.min.y;
  27649. };
  27650. _proto.getCenter = function getCenter(target) {
  27651. if (target === undefined) {
  27652. console.warn('THREE.Box2: .getCenter() target is now required');
  27653. target = new Vector2();
  27654. }
  27655. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  27656. };
  27657. _proto.getSize = function getSize(target) {
  27658. if (target === undefined) {
  27659. console.warn('THREE.Box2: .getSize() target is now required');
  27660. target = new Vector2();
  27661. }
  27662. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  27663. };
  27664. _proto.expandByPoint = function expandByPoint(point) {
  27665. this.min.min(point);
  27666. this.max.max(point);
  27667. return this;
  27668. };
  27669. _proto.expandByVector = function expandByVector(vector) {
  27670. this.min.sub(vector);
  27671. this.max.add(vector);
  27672. return this;
  27673. };
  27674. _proto.expandByScalar = function expandByScalar(scalar) {
  27675. this.min.addScalar(-scalar);
  27676. this.max.addScalar(scalar);
  27677. return this;
  27678. };
  27679. _proto.containsPoint = function containsPoint(point) {
  27680. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  27681. };
  27682. _proto.containsBox = function containsBox(box) {
  27683. 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;
  27684. };
  27685. _proto.getParameter = function getParameter(point, target) {
  27686. // This can potentially have a divide by zero if the box
  27687. // has a size dimension of 0.
  27688. if (target === undefined) {
  27689. console.warn('THREE.Box2: .getParameter() target is now required');
  27690. target = new Vector2();
  27691. }
  27692. 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));
  27693. };
  27694. _proto.intersectsBox = function intersectsBox(box) {
  27695. // using 4 splitting planes to rule out intersections
  27696. 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;
  27697. };
  27698. _proto.clampPoint = function clampPoint(point, target) {
  27699. if (target === undefined) {
  27700. console.warn('THREE.Box2: .clampPoint() target is now required');
  27701. target = new Vector2();
  27702. }
  27703. return target.copy(point).clamp(this.min, this.max);
  27704. };
  27705. _proto.distanceToPoint = function distanceToPoint(point) {
  27706. var clampedPoint = _vector$7.copy(point).clamp(this.min, this.max);
  27707. return clampedPoint.sub(point).length();
  27708. };
  27709. _proto.intersect = function intersect(box) {
  27710. this.min.max(box.min);
  27711. this.max.min(box.max);
  27712. return this;
  27713. };
  27714. _proto.union = function union(box) {
  27715. this.min.min(box.min);
  27716. this.max.max(box.max);
  27717. return this;
  27718. };
  27719. _proto.translate = function translate(offset) {
  27720. this.min.add(offset);
  27721. this.max.add(offset);
  27722. return this;
  27723. };
  27724. _proto.equals = function equals(box) {
  27725. return box.min.equals(this.min) && box.max.equals(this.max);
  27726. };
  27727. return Box2;
  27728. }();
  27729. var _startP = /*@__PURE__*/new Vector3();
  27730. var _startEnd = /*@__PURE__*/new Vector3();
  27731. var Line3 = /*#__PURE__*/function () {
  27732. function Line3(start, end) {
  27733. this.start = start !== undefined ? start : new Vector3();
  27734. this.end = end !== undefined ? end : new Vector3();
  27735. }
  27736. var _proto = Line3.prototype;
  27737. _proto.set = function set(start, end) {
  27738. this.start.copy(start);
  27739. this.end.copy(end);
  27740. return this;
  27741. };
  27742. _proto.clone = function clone() {
  27743. return new this.constructor().copy(this);
  27744. };
  27745. _proto.copy = function copy(line) {
  27746. this.start.copy(line.start);
  27747. this.end.copy(line.end);
  27748. return this;
  27749. };
  27750. _proto.getCenter = function getCenter(target) {
  27751. if (target === undefined) {
  27752. console.warn('THREE.Line3: .getCenter() target is now required');
  27753. target = new Vector3();
  27754. }
  27755. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  27756. };
  27757. _proto.delta = function delta(target) {
  27758. if (target === undefined) {
  27759. console.warn('THREE.Line3: .delta() target is now required');
  27760. target = new Vector3();
  27761. }
  27762. return target.subVectors(this.end, this.start);
  27763. };
  27764. _proto.distanceSq = function distanceSq() {
  27765. return this.start.distanceToSquared(this.end);
  27766. };
  27767. _proto.distance = function distance() {
  27768. return this.start.distanceTo(this.end);
  27769. };
  27770. _proto.at = function at(t, target) {
  27771. if (target === undefined) {
  27772. console.warn('THREE.Line3: .at() target is now required');
  27773. target = new Vector3();
  27774. }
  27775. return this.delta(target).multiplyScalar(t).add(this.start);
  27776. };
  27777. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  27778. _startP.subVectors(point, this.start);
  27779. _startEnd.subVectors(this.end, this.start);
  27780. var startEnd2 = _startEnd.dot(_startEnd);
  27781. var startEnd_startP = _startEnd.dot(_startP);
  27782. var t = startEnd_startP / startEnd2;
  27783. if (clampToLine) {
  27784. t = MathUtils.clamp(t, 0, 1);
  27785. }
  27786. return t;
  27787. };
  27788. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  27789. var t = this.closestPointToPointParameter(point, clampToLine);
  27790. if (target === undefined) {
  27791. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  27792. target = new Vector3();
  27793. }
  27794. return this.delta(target).multiplyScalar(t).add(this.start);
  27795. };
  27796. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  27797. this.start.applyMatrix4(matrix);
  27798. this.end.applyMatrix4(matrix);
  27799. return this;
  27800. };
  27801. _proto.equals = function equals(line) {
  27802. return line.start.equals(this.start) && line.end.equals(this.end);
  27803. };
  27804. return Line3;
  27805. }();
  27806. function ImmediateRenderObject(material) {
  27807. Object3D.call(this);
  27808. this.material = material;
  27809. this.render = function ()
  27810. /* renderCallback */
  27811. {};
  27812. this.hasPositions = false;
  27813. this.hasNormals = false;
  27814. this.hasColors = false;
  27815. this.hasUvs = false;
  27816. this.positionArray = null;
  27817. this.normalArray = null;
  27818. this.colorArray = null;
  27819. this.uvArray = null;
  27820. this.count = 0;
  27821. }
  27822. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  27823. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27824. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27825. var _vector$8 = /*@__PURE__*/new Vector3();
  27826. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  27827. _inheritsLoose(SpotLightHelper, _Object3D);
  27828. function SpotLightHelper(light, color) {
  27829. var _this;
  27830. _this = _Object3D.call(this) || this;
  27831. _this.light = light;
  27832. _this.light.updateMatrixWorld();
  27833. _this.matrix = light.matrixWorld;
  27834. _this.matrixAutoUpdate = false;
  27835. _this.color = color;
  27836. var geometry = new BufferGeometry();
  27837. 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];
  27838. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  27839. var p1 = i / l * Math.PI * 2;
  27840. var p2 = j / l * Math.PI * 2;
  27841. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  27842. }
  27843. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  27844. var material = new LineBasicMaterial({
  27845. fog: false,
  27846. toneMapped: false
  27847. });
  27848. _this.cone = new LineSegments(geometry, material);
  27849. _this.add(_this.cone);
  27850. _this.update();
  27851. return _this;
  27852. }
  27853. var _proto = SpotLightHelper.prototype;
  27854. _proto.dispose = function dispose() {
  27855. this.cone.geometry.dispose();
  27856. this.cone.material.dispose();
  27857. };
  27858. _proto.update = function update() {
  27859. this.light.updateMatrixWorld();
  27860. var coneLength = this.light.distance ? this.light.distance : 1000;
  27861. var coneWidth = coneLength * Math.tan(this.light.angle);
  27862. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  27863. _vector$8.setFromMatrixPosition(this.light.target.matrixWorld);
  27864. this.cone.lookAt(_vector$8);
  27865. if (this.color !== undefined) {
  27866. this.cone.material.color.set(this.color);
  27867. } else {
  27868. this.cone.material.color.copy(this.light.color);
  27869. }
  27870. };
  27871. return SpotLightHelper;
  27872. }(Object3D);
  27873. var _vector$9 = /*@__PURE__*/new Vector3();
  27874. var _boneMatrix = /*@__PURE__*/new Matrix4();
  27875. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  27876. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  27877. _inheritsLoose(SkeletonHelper, _LineSegments);
  27878. function SkeletonHelper(object) {
  27879. var _this;
  27880. var bones = getBoneList(object);
  27881. var geometry = new BufferGeometry();
  27882. var vertices = [];
  27883. var colors = [];
  27884. var color1 = new Color(0, 0, 1);
  27885. var color2 = new Color(0, 1, 0);
  27886. for (var i = 0; i < bones.length; i++) {
  27887. var bone = bones[i];
  27888. if (bone.parent && bone.parent.isBone) {
  27889. vertices.push(0, 0, 0);
  27890. vertices.push(0, 0, 0);
  27891. colors.push(color1.r, color1.g, color1.b);
  27892. colors.push(color2.r, color2.g, color2.b);
  27893. }
  27894. }
  27895. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27896. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27897. var material = new LineBasicMaterial({
  27898. vertexColors: true,
  27899. depthTest: false,
  27900. depthWrite: false,
  27901. toneMapped: false,
  27902. transparent: true
  27903. });
  27904. _this = _LineSegments.call(this, geometry, material) || this;
  27905. _this.type = 'SkeletonHelper';
  27906. _this.isSkeletonHelper = true;
  27907. _this.root = object;
  27908. _this.bones = bones;
  27909. _this.matrix = object.matrixWorld;
  27910. _this.matrixAutoUpdate = false;
  27911. return _this;
  27912. }
  27913. var _proto = SkeletonHelper.prototype;
  27914. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  27915. var bones = this.bones;
  27916. var geometry = this.geometry;
  27917. var position = geometry.getAttribute('position');
  27918. _matrixWorldInv.copy(this.root.matrixWorld).invert();
  27919. for (var i = 0, j = 0; i < bones.length; i++) {
  27920. var bone = bones[i];
  27921. if (bone.parent && bone.parent.isBone) {
  27922. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  27923. _vector$9.setFromMatrixPosition(_boneMatrix);
  27924. position.setXYZ(j, _vector$9.x, _vector$9.y, _vector$9.z);
  27925. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  27926. _vector$9.setFromMatrixPosition(_boneMatrix);
  27927. position.setXYZ(j + 1, _vector$9.x, _vector$9.y, _vector$9.z);
  27928. j += 2;
  27929. }
  27930. }
  27931. geometry.getAttribute('position').needsUpdate = true;
  27932. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  27933. };
  27934. return SkeletonHelper;
  27935. }(LineSegments);
  27936. function getBoneList(object) {
  27937. var boneList = [];
  27938. if (object && object.isBone) {
  27939. boneList.push(object);
  27940. }
  27941. for (var i = 0; i < object.children.length; i++) {
  27942. boneList.push.apply(boneList, getBoneList(object.children[i]));
  27943. }
  27944. return boneList;
  27945. }
  27946. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  27947. _inheritsLoose(PointLightHelper, _Mesh);
  27948. function PointLightHelper(light, sphereSize, color) {
  27949. var _this;
  27950. var geometry = new SphereBufferGeometry(sphereSize, 4, 2);
  27951. var material = new MeshBasicMaterial({
  27952. wireframe: true,
  27953. fog: false,
  27954. toneMapped: false
  27955. });
  27956. _this = _Mesh.call(this, geometry, material) || this;
  27957. _this.light = light;
  27958. _this.light.updateMatrixWorld();
  27959. _this.color = color;
  27960. _this.type = 'PointLightHelper';
  27961. _this.matrix = _this.light.matrixWorld;
  27962. _this.matrixAutoUpdate = false;
  27963. _this.update();
  27964. /*
  27965. // TODO: delete this comment?
  27966. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27967. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27968. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27969. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27970. const d = light.distance;
  27971. if ( d === 0.0 ) {
  27972. this.lightDistance.visible = false;
  27973. } else {
  27974. this.lightDistance.scale.set( d, d, d );
  27975. }
  27976. this.add( this.lightDistance );
  27977. */
  27978. return _this;
  27979. }
  27980. var _proto = PointLightHelper.prototype;
  27981. _proto.dispose = function dispose() {
  27982. this.geometry.dispose();
  27983. this.material.dispose();
  27984. };
  27985. _proto.update = function update() {
  27986. if (this.color !== undefined) {
  27987. this.material.color.set(this.color);
  27988. } else {
  27989. this.material.color.copy(this.light.color);
  27990. }
  27991. /*
  27992. const d = this.light.distance;
  27993. if ( d === 0.0 ) {
  27994. this.lightDistance.visible = false;
  27995. } else {
  27996. this.lightDistance.visible = true;
  27997. this.lightDistance.scale.set( d, d, d );
  27998. }
  27999. */
  28000. };
  28001. return PointLightHelper;
  28002. }(Mesh);
  28003. var _vector$a = /*@__PURE__*/new Vector3();
  28004. var _color1 = /*@__PURE__*/new Color();
  28005. var _color2 = /*@__PURE__*/new Color();
  28006. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  28007. _inheritsLoose(HemisphereLightHelper, _Object3D);
  28008. function HemisphereLightHelper(light, size, color) {
  28009. var _this;
  28010. _this = _Object3D.call(this) || this;
  28011. _this.light = light;
  28012. _this.light.updateMatrixWorld();
  28013. _this.matrix = light.matrixWorld;
  28014. _this.matrixAutoUpdate = false;
  28015. _this.color = color;
  28016. var geometry = new OctahedronBufferGeometry(size);
  28017. geometry.rotateY(Math.PI * 0.5);
  28018. _this.material = new MeshBasicMaterial({
  28019. wireframe: true,
  28020. fog: false,
  28021. toneMapped: false
  28022. });
  28023. if (_this.color === undefined) _this.material.vertexColors = true;
  28024. var position = geometry.getAttribute('position');
  28025. var colors = new Float32Array(position.count * 3);
  28026. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  28027. _this.add(new Mesh(geometry, _this.material));
  28028. _this.update();
  28029. return _this;
  28030. }
  28031. var _proto = HemisphereLightHelper.prototype;
  28032. _proto.dispose = function dispose() {
  28033. this.children[0].geometry.dispose();
  28034. this.children[0].material.dispose();
  28035. };
  28036. _proto.update = function update() {
  28037. var mesh = this.children[0];
  28038. if (this.color !== undefined) {
  28039. this.material.color.set(this.color);
  28040. } else {
  28041. var colors = mesh.geometry.getAttribute('color');
  28042. _color1.copy(this.light.color);
  28043. _color2.copy(this.light.groundColor);
  28044. for (var i = 0, l = colors.count; i < l; i++) {
  28045. var color = i < l / 2 ? _color1 : _color2;
  28046. colors.setXYZ(i, color.r, color.g, color.b);
  28047. }
  28048. colors.needsUpdate = true;
  28049. }
  28050. mesh.lookAt(_vector$a.setFromMatrixPosition(this.light.matrixWorld).negate());
  28051. };
  28052. return HemisphereLightHelper;
  28053. }(Object3D);
  28054. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  28055. _inheritsLoose(GridHelper, _LineSegments);
  28056. function GridHelper(size, divisions, color1, color2) {
  28057. var _this;
  28058. size = size || 10;
  28059. divisions = divisions || 10;
  28060. color1 = new Color(color1 !== undefined ? color1 : 0x444444);
  28061. color2 = new Color(color2 !== undefined ? color2 : 0x888888);
  28062. var center = divisions / 2;
  28063. var step = size / divisions;
  28064. var halfSize = size / 2;
  28065. var vertices = [],
  28066. colors = [];
  28067. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  28068. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  28069. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  28070. var color = i === center ? color1 : color2;
  28071. color.toArray(colors, j);
  28072. j += 3;
  28073. color.toArray(colors, j);
  28074. j += 3;
  28075. color.toArray(colors, j);
  28076. j += 3;
  28077. color.toArray(colors, j);
  28078. j += 3;
  28079. }
  28080. var geometry = new BufferGeometry();
  28081. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28082. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28083. var material = new LineBasicMaterial({
  28084. vertexColors: true,
  28085. toneMapped: false
  28086. });
  28087. _this = _LineSegments.call(this, geometry, material) || this;
  28088. _this.type = 'GridHelper';
  28089. return _this;
  28090. }
  28091. return GridHelper;
  28092. }(LineSegments);
  28093. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  28094. _inheritsLoose(PolarGridHelper, _LineSegments);
  28095. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  28096. var _this;
  28097. radius = radius || 10;
  28098. radials = radials || 16;
  28099. circles = circles || 8;
  28100. divisions = divisions || 64;
  28101. color1 = new Color(color1 !== undefined ? color1 : 0x444444);
  28102. color2 = new Color(color2 !== undefined ? color2 : 0x888888);
  28103. var vertices = [];
  28104. var colors = []; // create the radials
  28105. for (var i = 0; i <= radials; i++) {
  28106. var v = i / radials * (Math.PI * 2);
  28107. var x = Math.sin(v) * radius;
  28108. var z = Math.cos(v) * radius;
  28109. vertices.push(0, 0, 0);
  28110. vertices.push(x, 0, z);
  28111. var color = i & 1 ? color1 : color2;
  28112. colors.push(color.r, color.g, color.b);
  28113. colors.push(color.r, color.g, color.b);
  28114. } // create the circles
  28115. for (var _i = 0; _i <= circles; _i++) {
  28116. var _color = _i & 1 ? color1 : color2;
  28117. var r = radius - radius / circles * _i;
  28118. for (var j = 0; j < divisions; j++) {
  28119. // first vertex
  28120. var _v = j / divisions * (Math.PI * 2);
  28121. var _x = Math.sin(_v) * r;
  28122. var _z = Math.cos(_v) * r;
  28123. vertices.push(_x, 0, _z);
  28124. colors.push(_color.r, _color.g, _color.b); // second vertex
  28125. _v = (j + 1) / divisions * (Math.PI * 2);
  28126. _x = Math.sin(_v) * r;
  28127. _z = Math.cos(_v) * r;
  28128. vertices.push(_x, 0, _z);
  28129. colors.push(_color.r, _color.g, _color.b);
  28130. }
  28131. }
  28132. var geometry = new BufferGeometry();
  28133. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28134. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28135. var material = new LineBasicMaterial({
  28136. vertexColors: true,
  28137. toneMapped: false
  28138. });
  28139. _this = _LineSegments.call(this, geometry, material) || this;
  28140. _this.type = 'PolarGridHelper';
  28141. return _this;
  28142. }
  28143. return PolarGridHelper;
  28144. }(LineSegments);
  28145. var _v1$6 = /*@__PURE__*/new Vector3();
  28146. var _v2$3 = /*@__PURE__*/new Vector3();
  28147. var _v3$1 = /*@__PURE__*/new Vector3();
  28148. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  28149. _inheritsLoose(DirectionalLightHelper, _Object3D);
  28150. function DirectionalLightHelper(light, size, color) {
  28151. var _this;
  28152. _this = _Object3D.call(this) || this;
  28153. _this.light = light;
  28154. _this.light.updateMatrixWorld();
  28155. _this.matrix = light.matrixWorld;
  28156. _this.matrixAutoUpdate = false;
  28157. _this.color = color;
  28158. if (size === undefined) size = 1;
  28159. var geometry = new BufferGeometry();
  28160. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  28161. var material = new LineBasicMaterial({
  28162. fog: false,
  28163. toneMapped: false
  28164. });
  28165. _this.lightPlane = new Line(geometry, material);
  28166. _this.add(_this.lightPlane);
  28167. geometry = new BufferGeometry();
  28168. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  28169. _this.targetLine = new Line(geometry, material);
  28170. _this.add(_this.targetLine);
  28171. _this.update();
  28172. return _this;
  28173. }
  28174. var _proto = DirectionalLightHelper.prototype;
  28175. _proto.dispose = function dispose() {
  28176. this.lightPlane.geometry.dispose();
  28177. this.lightPlane.material.dispose();
  28178. this.targetLine.geometry.dispose();
  28179. this.targetLine.material.dispose();
  28180. };
  28181. _proto.update = function update() {
  28182. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  28183. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  28184. _v3$1.subVectors(_v2$3, _v1$6);
  28185. this.lightPlane.lookAt(_v2$3);
  28186. if (this.color !== undefined) {
  28187. this.lightPlane.material.color.set(this.color);
  28188. this.targetLine.material.color.set(this.color);
  28189. } else {
  28190. this.lightPlane.material.color.copy(this.light.color);
  28191. this.targetLine.material.color.copy(this.light.color);
  28192. }
  28193. this.targetLine.lookAt(_v2$3);
  28194. this.targetLine.scale.z = _v3$1.length();
  28195. };
  28196. return DirectionalLightHelper;
  28197. }(Object3D);
  28198. var _vector$b = /*@__PURE__*/new Vector3();
  28199. var _camera = /*@__PURE__*/new Camera();
  28200. /**
  28201. * - shows frustum, line of sight and up of the camera
  28202. * - suitable for fast updates
  28203. * - based on frustum visualization in lightgl.js shadowmap example
  28204. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28205. */
  28206. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  28207. _inheritsLoose(CameraHelper, _LineSegments);
  28208. function CameraHelper(camera) {
  28209. var _this;
  28210. var geometry = new BufferGeometry();
  28211. var material = new LineBasicMaterial({
  28212. color: 0xffffff,
  28213. vertexColors: true,
  28214. toneMapped: false
  28215. });
  28216. var vertices = [];
  28217. var colors = [];
  28218. var pointMap = {}; // colors
  28219. var colorFrustum = new Color(0xffaa00);
  28220. var colorCone = new Color(0xff0000);
  28221. var colorUp = new Color(0x00aaff);
  28222. var colorTarget = new Color(0xffffff);
  28223. var colorCross = new Color(0x333333); // near
  28224. addLine('n1', 'n2', colorFrustum);
  28225. addLine('n2', 'n4', colorFrustum);
  28226. addLine('n4', 'n3', colorFrustum);
  28227. addLine('n3', 'n1', colorFrustum); // far
  28228. addLine('f1', 'f2', colorFrustum);
  28229. addLine('f2', 'f4', colorFrustum);
  28230. addLine('f4', 'f3', colorFrustum);
  28231. addLine('f3', 'f1', colorFrustum); // sides
  28232. addLine('n1', 'f1', colorFrustum);
  28233. addLine('n2', 'f2', colorFrustum);
  28234. addLine('n3', 'f3', colorFrustum);
  28235. addLine('n4', 'f4', colorFrustum); // cone
  28236. addLine('p', 'n1', colorCone);
  28237. addLine('p', 'n2', colorCone);
  28238. addLine('p', 'n3', colorCone);
  28239. addLine('p', 'n4', colorCone); // up
  28240. addLine('u1', 'u2', colorUp);
  28241. addLine('u2', 'u3', colorUp);
  28242. addLine('u3', 'u1', colorUp); // target
  28243. addLine('c', 't', colorTarget);
  28244. addLine('p', 'c', colorCross); // cross
  28245. addLine('cn1', 'cn2', colorCross);
  28246. addLine('cn3', 'cn4', colorCross);
  28247. addLine('cf1', 'cf2', colorCross);
  28248. addLine('cf3', 'cf4', colorCross);
  28249. function addLine(a, b, color) {
  28250. addPoint(a, color);
  28251. addPoint(b, color);
  28252. }
  28253. function addPoint(id, color) {
  28254. vertices.push(0, 0, 0);
  28255. colors.push(color.r, color.g, color.b);
  28256. if (pointMap[id] === undefined) {
  28257. pointMap[id] = [];
  28258. }
  28259. pointMap[id].push(vertices.length / 3 - 1);
  28260. }
  28261. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28262. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28263. _this = _LineSegments.call(this, geometry, material) || this;
  28264. _this.type = 'CameraHelper';
  28265. _this.camera = camera;
  28266. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28267. _this.matrix = camera.matrixWorld;
  28268. _this.matrixAutoUpdate = false;
  28269. _this.pointMap = pointMap;
  28270. _this.update();
  28271. return _this;
  28272. }
  28273. var _proto = CameraHelper.prototype;
  28274. _proto.update = function update() {
  28275. var geometry = this.geometry;
  28276. var pointMap = this.pointMap;
  28277. var w = 1,
  28278. h = 1; // we need just camera projection matrix inverse
  28279. // world matrix must be identity
  28280. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28281. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28282. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28283. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28284. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28285. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28286. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28287. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28288. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28289. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28290. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28291. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28292. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28293. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28294. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28295. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28296. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28297. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28298. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28299. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28300. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28301. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28302. geometry.getAttribute('position').needsUpdate = true;
  28303. };
  28304. return CameraHelper;
  28305. }(LineSegments);
  28306. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28307. _vector$b.set(x, y, z).unproject(camera);
  28308. var points = pointMap[point];
  28309. if (points !== undefined) {
  28310. var position = geometry.getAttribute('position');
  28311. for (var i = 0, l = points.length; i < l; i++) {
  28312. position.setXYZ(points[i], _vector$b.x, _vector$b.y, _vector$b.z);
  28313. }
  28314. }
  28315. }
  28316. var _box$3 = /*@__PURE__*/new Box3();
  28317. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28318. _inheritsLoose(BoxHelper, _LineSegments);
  28319. function BoxHelper(object, color) {
  28320. var _this;
  28321. if (color === void 0) {
  28322. color = 0xffff00;
  28323. }
  28324. 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]);
  28325. var positions = new Float32Array(8 * 3);
  28326. var geometry = new BufferGeometry();
  28327. geometry.setIndex(new BufferAttribute(indices, 1));
  28328. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28329. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28330. color: color,
  28331. toneMapped: false
  28332. })) || this;
  28333. _this.object = object;
  28334. _this.type = 'BoxHelper';
  28335. _this.matrixAutoUpdate = false;
  28336. _this.update();
  28337. return _this;
  28338. }
  28339. var _proto = BoxHelper.prototype;
  28340. _proto.update = function update(object) {
  28341. if (object !== undefined) {
  28342. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28343. }
  28344. if (this.object !== undefined) {
  28345. _box$3.setFromObject(this.object);
  28346. }
  28347. if (_box$3.isEmpty()) return;
  28348. var min = _box$3.min;
  28349. var max = _box$3.max;
  28350. /*
  28351. 5____4
  28352. 1/___0/|
  28353. | 6__|_7
  28354. 2/___3/
  28355. 0: max.x, max.y, max.z
  28356. 1: min.x, max.y, max.z
  28357. 2: min.x, min.y, max.z
  28358. 3: max.x, min.y, max.z
  28359. 4: max.x, max.y, min.z
  28360. 5: min.x, max.y, min.z
  28361. 6: min.x, min.y, min.z
  28362. 7: max.x, min.y, min.z
  28363. */
  28364. var position = this.geometry.attributes.position;
  28365. var array = position.array;
  28366. array[0] = max.x;
  28367. array[1] = max.y;
  28368. array[2] = max.z;
  28369. array[3] = min.x;
  28370. array[4] = max.y;
  28371. array[5] = max.z;
  28372. array[6] = min.x;
  28373. array[7] = min.y;
  28374. array[8] = max.z;
  28375. array[9] = max.x;
  28376. array[10] = min.y;
  28377. array[11] = max.z;
  28378. array[12] = max.x;
  28379. array[13] = max.y;
  28380. array[14] = min.z;
  28381. array[15] = min.x;
  28382. array[16] = max.y;
  28383. array[17] = min.z;
  28384. array[18] = min.x;
  28385. array[19] = min.y;
  28386. array[20] = min.z;
  28387. array[21] = max.x;
  28388. array[22] = min.y;
  28389. array[23] = min.z;
  28390. position.needsUpdate = true;
  28391. this.geometry.computeBoundingSphere();
  28392. };
  28393. _proto.setFromObject = function setFromObject(object) {
  28394. this.object = object;
  28395. this.update();
  28396. return this;
  28397. };
  28398. _proto.copy = function copy(source) {
  28399. LineSegments.prototype.copy.call(this, source);
  28400. this.object = source.object;
  28401. return this;
  28402. };
  28403. return BoxHelper;
  28404. }(LineSegments);
  28405. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28406. _inheritsLoose(Box3Helper, _LineSegments);
  28407. function Box3Helper(box, color) {
  28408. var _this;
  28409. if (color === void 0) {
  28410. color = 0xffff00;
  28411. }
  28412. 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]);
  28413. 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];
  28414. var geometry = new BufferGeometry();
  28415. geometry.setIndex(new BufferAttribute(indices, 1));
  28416. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28417. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28418. color: color,
  28419. toneMapped: false
  28420. })) || this;
  28421. _this.box = box;
  28422. _this.type = 'Box3Helper';
  28423. _this.geometry.computeBoundingSphere();
  28424. return _this;
  28425. }
  28426. var _proto = Box3Helper.prototype;
  28427. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28428. var box = this.box;
  28429. if (box.isEmpty()) return;
  28430. box.getCenter(this.position);
  28431. box.getSize(this.scale);
  28432. this.scale.multiplyScalar(0.5);
  28433. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28434. };
  28435. return Box3Helper;
  28436. }(LineSegments);
  28437. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28438. _inheritsLoose(PlaneHelper, _Line);
  28439. function PlaneHelper(plane, size, hex) {
  28440. var _this;
  28441. if (size === void 0) {
  28442. size = 1;
  28443. }
  28444. if (hex === void 0) {
  28445. hex = 0xffff00;
  28446. }
  28447. var color = hex;
  28448. 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];
  28449. var geometry = new BufferGeometry();
  28450. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28451. geometry.computeBoundingSphere();
  28452. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28453. color: color,
  28454. toneMapped: false
  28455. })) || this;
  28456. _this.type = 'PlaneHelper';
  28457. _this.plane = plane;
  28458. _this.size = size;
  28459. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28460. var geometry2 = new BufferGeometry();
  28461. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28462. geometry2.computeBoundingSphere();
  28463. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28464. color: color,
  28465. opacity: 0.2,
  28466. transparent: true,
  28467. depthWrite: false,
  28468. toneMapped: false
  28469. })));
  28470. return _this;
  28471. }
  28472. var _proto = PlaneHelper.prototype;
  28473. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28474. var scale = -this.plane.constant;
  28475. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28476. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28477. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28478. this.lookAt(this.plane.normal);
  28479. _Line.prototype.updateMatrixWorld.call(this, force);
  28480. };
  28481. return PlaneHelper;
  28482. }(Line);
  28483. var _axis = /*@__PURE__*/new Vector3();
  28484. var _lineGeometry, _coneGeometry;
  28485. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28486. _inheritsLoose(ArrowHelper, _Object3D);
  28487. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28488. var _this;
  28489. _this = _Object3D.call(this) || this; // dir is assumed to be normalized
  28490. _this.type = 'ArrowHelper';
  28491. if (dir === undefined) dir = new Vector3(0, 0, 1);
  28492. if (origin === undefined) origin = new Vector3(0, 0, 0);
  28493. if (length === undefined) length = 1;
  28494. if (color === undefined) color = 0xffff00;
  28495. if (headLength === undefined) headLength = 0.2 * length;
  28496. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28497. if (_lineGeometry === undefined) {
  28498. _lineGeometry = new BufferGeometry();
  28499. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28500. _coneGeometry = new CylinderBufferGeometry(0, 0.5, 1, 5, 1);
  28501. _coneGeometry.translate(0, -0.5, 0);
  28502. }
  28503. _this.position.copy(origin);
  28504. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28505. color: color,
  28506. toneMapped: false
  28507. }));
  28508. _this.line.matrixAutoUpdate = false;
  28509. _this.add(_this.line);
  28510. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28511. color: color,
  28512. toneMapped: false
  28513. }));
  28514. _this.cone.matrixAutoUpdate = false;
  28515. _this.add(_this.cone);
  28516. _this.setDirection(dir);
  28517. _this.setLength(length, headLength, headWidth);
  28518. return _this;
  28519. }
  28520. var _proto = ArrowHelper.prototype;
  28521. _proto.setDirection = function setDirection(dir) {
  28522. // dir is assumed to be normalized
  28523. if (dir.y > 0.99999) {
  28524. this.quaternion.set(0, 0, 0, 1);
  28525. } else if (dir.y < -0.99999) {
  28526. this.quaternion.set(1, 0, 0, 0);
  28527. } else {
  28528. _axis.set(dir.z, 0, -dir.x).normalize();
  28529. var radians = Math.acos(dir.y);
  28530. this.quaternion.setFromAxisAngle(_axis, radians);
  28531. }
  28532. };
  28533. _proto.setLength = function setLength(length, headLength, headWidth) {
  28534. if (headLength === undefined) headLength = 0.2 * length;
  28535. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28536. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28537. this.line.updateMatrix();
  28538. this.cone.scale.set(headWidth, headLength, headWidth);
  28539. this.cone.position.y = length;
  28540. this.cone.updateMatrix();
  28541. };
  28542. _proto.setColor = function setColor(color) {
  28543. this.line.material.color.set(color);
  28544. this.cone.material.color.set(color);
  28545. };
  28546. _proto.copy = function copy(source) {
  28547. _Object3D.prototype.copy.call(this, source, false);
  28548. this.line.copy(source.line);
  28549. this.cone.copy(source.cone);
  28550. return this;
  28551. };
  28552. return ArrowHelper;
  28553. }(Object3D);
  28554. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  28555. _inheritsLoose(AxesHelper, _LineSegments);
  28556. function AxesHelper(size) {
  28557. var _this;
  28558. if (size === void 0) {
  28559. size = 1;
  28560. }
  28561. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  28562. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  28563. var geometry = new BufferGeometry();
  28564. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28565. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28566. var material = new LineBasicMaterial({
  28567. vertexColors: true,
  28568. toneMapped: false
  28569. });
  28570. _this = _LineSegments.call(this, geometry, material) || this;
  28571. _this.type = 'AxesHelper';
  28572. return _this;
  28573. }
  28574. return AxesHelper;
  28575. }(LineSegments);
  28576. var _floatView = new Float32Array(1);
  28577. var _int32View = new Int32Array(_floatView.buffer);
  28578. var DataUtils = {
  28579. // Converts float32 to float16 (stored as uint16 value).
  28580. toHalfFloat: function toHalfFloat(val) {
  28581. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  28582. /* This method is faster than the OpenEXR implementation (very often
  28583. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  28584. * by James Tursa?s half-precision code. */
  28585. _floatView[0] = val;
  28586. var x = _int32View[0];
  28587. var bits = x >> 16 & 0x8000;
  28588. /* Get the sign */
  28589. var m = x >> 12 & 0x07ff;
  28590. /* Keep one extra bit for rounding */
  28591. var e = x >> 23 & 0xff;
  28592. /* Using int is faster here */
  28593. /* If zero, or denormal, or exponent underflows too much for a denormal
  28594. * half, return signed zero. */
  28595. if (e < 103) return bits;
  28596. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  28597. if (e > 142) {
  28598. bits |= 0x7c00;
  28599. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  28600. * not Inf, so make sure we set one mantissa bit too. */
  28601. bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
  28602. return bits;
  28603. }
  28604. /* If exponent underflows but not too much, return a denormal */
  28605. if (e < 113) {
  28606. m |= 0x0800;
  28607. /* Extra rounding may overflow and set mantissa to 0 and exponent
  28608. * to 1, which is OK. */
  28609. bits |= (m >> 114 - e) + (m >> 113 - e & 1);
  28610. return bits;
  28611. }
  28612. bits |= e - 112 << 10 | m >> 1;
  28613. /* Extra rounding. An overflow will set mantissa to 0 and increment
  28614. * the exponent, which is OK. */
  28615. bits += m & 1;
  28616. return bits;
  28617. }
  28618. };
  28619. var _ENCODINGS;
  28620. var LOD_MIN = 4;
  28621. var LOD_MAX = 8;
  28622. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  28623. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28624. // geometric shadowing function. These sigma values squared must match the
  28625. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28626. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  28627. 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
  28628. // samples and exit early, but not recompile the shader.
  28629. var MAX_SAMPLES = 20;
  28630. 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);
  28631. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  28632. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  28633. _lodPlanes = _createPlanes2._lodPlanes,
  28634. _sizeLods = _createPlanes2._sizeLods,
  28635. _sigmas = _createPlanes2._sigmas;
  28636. var _oldTarget = null; // Golden Ratio
  28637. var PHI = (1 + Math.sqrt(5)) / 2;
  28638. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  28639. // same axis), used as axis directions evenly spread on a sphere.
  28640. 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)];
  28641. /**
  28642. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28643. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28644. * blur to be quickly accessed based on material roughness. It is packed into a
  28645. * special CubeUV format that allows us to perform custom interpolation so that
  28646. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28647. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28648. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28649. * higher roughness levels. In this way we maintain resolution to smoothly
  28650. * interpolate diffuse lighting while limiting sampling computation.
  28651. */
  28652. var PMREMGenerator = /*#__PURE__*/function () {
  28653. function PMREMGenerator(renderer) {
  28654. this._renderer = renderer;
  28655. this._pingPongRenderTarget = null;
  28656. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  28657. this._equirectShader = null;
  28658. this._cubemapShader = null;
  28659. this._compileMaterial(this._blurMaterial);
  28660. }
  28661. /**
  28662. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28663. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28664. * in radians to be applied to the scene before PMREM generation. Optional near
  28665. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28666. * is placed at the origin).
  28667. */
  28668. var _proto = PMREMGenerator.prototype;
  28669. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  28670. if (sigma === void 0) {
  28671. sigma = 0;
  28672. }
  28673. if (near === void 0) {
  28674. near = 0.1;
  28675. }
  28676. if (far === void 0) {
  28677. far = 100;
  28678. }
  28679. _oldTarget = this._renderer.getRenderTarget();
  28680. var cubeUVRenderTarget = this._allocateTargets();
  28681. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  28682. if (sigma > 0) {
  28683. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  28684. }
  28685. this._applyPMREM(cubeUVRenderTarget);
  28686. this._cleanup(cubeUVRenderTarget);
  28687. return cubeUVRenderTarget;
  28688. }
  28689. /**
  28690. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28691. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28692. * as this matches best with the 256 x 256 cubemap output.
  28693. */
  28694. ;
  28695. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  28696. return this._fromTexture(equirectangular);
  28697. }
  28698. /**
  28699. * Generates a PMREM from an cubemap texture, which can be either LDR
  28700. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28701. * as this matches best with the 256 x 256 cubemap output.
  28702. */
  28703. ;
  28704. _proto.fromCubemap = function fromCubemap(cubemap) {
  28705. return this._fromTexture(cubemap);
  28706. }
  28707. /**
  28708. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28709. * your texture's network fetch for increased concurrency.
  28710. */
  28711. ;
  28712. _proto.compileCubemapShader = function compileCubemapShader() {
  28713. if (this._cubemapShader === null) {
  28714. this._cubemapShader = _getCubemapShader();
  28715. this._compileMaterial(this._cubemapShader);
  28716. }
  28717. }
  28718. /**
  28719. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28720. * your texture's network fetch for increased concurrency.
  28721. */
  28722. ;
  28723. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  28724. if (this._equirectShader === null) {
  28725. this._equirectShader = _getEquirectShader();
  28726. this._compileMaterial(this._equirectShader);
  28727. }
  28728. }
  28729. /**
  28730. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  28731. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  28732. * one of them will cause any others to also become unusable.
  28733. */
  28734. ;
  28735. _proto.dispose = function dispose() {
  28736. this._blurMaterial.dispose();
  28737. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  28738. if (this._equirectShader !== null) this._equirectShader.dispose();
  28739. for (var i = 0; i < _lodPlanes.length; i++) {
  28740. _lodPlanes[i].dispose();
  28741. }
  28742. } // private interface
  28743. ;
  28744. _proto._cleanup = function _cleanup(outputTarget) {
  28745. this._pingPongRenderTarget.dispose();
  28746. this._renderer.setRenderTarget(_oldTarget);
  28747. outputTarget.scissorTest = false;
  28748. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  28749. };
  28750. _proto._fromTexture = function _fromTexture(texture) {
  28751. _oldTarget = this._renderer.getRenderTarget();
  28752. var cubeUVRenderTarget = this._allocateTargets(texture);
  28753. this._textureToCubeUV(texture, cubeUVRenderTarget);
  28754. this._applyPMREM(cubeUVRenderTarget);
  28755. this._cleanup(cubeUVRenderTarget);
  28756. return cubeUVRenderTarget;
  28757. };
  28758. _proto._allocateTargets = function _allocateTargets(texture) {
  28759. // warning: null texture is valid
  28760. var params = {
  28761. magFilter: NearestFilter,
  28762. minFilter: NearestFilter,
  28763. generateMipmaps: false,
  28764. type: UnsignedByteType,
  28765. format: RGBEFormat,
  28766. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  28767. depthBuffer: false
  28768. };
  28769. var cubeUVRenderTarget = _createRenderTarget(params);
  28770. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  28771. this._pingPongRenderTarget = _createRenderTarget(params);
  28772. return cubeUVRenderTarget;
  28773. };
  28774. _proto._compileMaterial = function _compileMaterial(material) {
  28775. var tmpMesh = new Mesh(_lodPlanes[0], material);
  28776. this._renderer.compile(tmpMesh, _flatCamera);
  28777. };
  28778. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  28779. var fov = 90;
  28780. var aspect = 1;
  28781. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  28782. var upSign = [1, -1, 1, 1, 1, 1];
  28783. var forwardSign = [1, 1, 1, -1, -1, -1];
  28784. var renderer = this._renderer;
  28785. var outputEncoding = renderer.outputEncoding;
  28786. var toneMapping = renderer.toneMapping;
  28787. var clearColor = renderer.getClearColor();
  28788. var clearAlpha = renderer.getClearAlpha();
  28789. renderer.toneMapping = NoToneMapping;
  28790. renderer.outputEncoding = LinearEncoding;
  28791. var background = scene.background;
  28792. if (background && background.isColor) {
  28793. background.convertSRGBToLinear(); // Convert linear to RGBE
  28794. var maxComponent = Math.max(background.r, background.g, background.b);
  28795. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  28796. background = background.multiplyScalar(Math.pow(2.0, -fExp));
  28797. var alpha = (fExp + 128.0) / 255.0;
  28798. renderer.setClearColor(background, alpha);
  28799. scene.background = null;
  28800. }
  28801. for (var i = 0; i < 6; i++) {
  28802. var col = i % 3;
  28803. if (col == 0) {
  28804. cubeCamera.up.set(0, upSign[i], 0);
  28805. cubeCamera.lookAt(forwardSign[i], 0, 0);
  28806. } else if (col == 1) {
  28807. cubeCamera.up.set(0, 0, upSign[i]);
  28808. cubeCamera.lookAt(0, forwardSign[i], 0);
  28809. } else {
  28810. cubeCamera.up.set(0, upSign[i], 0);
  28811. cubeCamera.lookAt(0, 0, forwardSign[i]);
  28812. }
  28813. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  28814. renderer.setRenderTarget(cubeUVRenderTarget);
  28815. renderer.render(scene, cubeCamera);
  28816. }
  28817. renderer.toneMapping = toneMapping;
  28818. renderer.outputEncoding = outputEncoding;
  28819. renderer.setClearColor(clearColor, clearAlpha);
  28820. };
  28821. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  28822. var renderer = this._renderer;
  28823. if (texture.isCubeTexture) {
  28824. if (this._cubemapShader == null) {
  28825. this._cubemapShader = _getCubemapShader();
  28826. }
  28827. } else {
  28828. if (this._equirectShader == null) {
  28829. this._equirectShader = _getEquirectShader();
  28830. }
  28831. }
  28832. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  28833. var mesh = new Mesh(_lodPlanes[0], material);
  28834. var uniforms = material.uniforms;
  28835. uniforms['envMap'].value = texture;
  28836. if (!texture.isCubeTexture) {
  28837. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  28838. }
  28839. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  28840. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  28841. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  28842. renderer.setRenderTarget(cubeUVRenderTarget);
  28843. renderer.render(mesh, _flatCamera);
  28844. };
  28845. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  28846. var renderer = this._renderer;
  28847. var autoClear = renderer.autoClear;
  28848. renderer.autoClear = false;
  28849. for (var i = 1; i < TOTAL_LODS; i++) {
  28850. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  28851. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  28852. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  28853. }
  28854. renderer.autoClear = autoClear;
  28855. }
  28856. /**
  28857. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  28858. * vertically and horizontally, but this breaks down on a cube. Here we apply
  28859. * the blur latitudinally (around the poles), and then longitudinally (towards
  28860. * the poles) to approximate the orthogonally-separable blur. It is least
  28861. * accurate at the poles, but still does a decent job.
  28862. */
  28863. ;
  28864. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  28865. var pingPongRenderTarget = this._pingPongRenderTarget;
  28866. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  28867. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  28868. };
  28869. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  28870. var renderer = this._renderer;
  28871. var blurMaterial = this._blurMaterial;
  28872. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  28873. console.error('blur direction must be either latitudinal or longitudinal!');
  28874. } // Number of standard deviations at which to cut off the discrete approximation.
  28875. var STANDARD_DEVIATIONS = 3;
  28876. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  28877. var blurUniforms = blurMaterial.uniforms;
  28878. var pixels = _sizeLods[lodIn] - 1;
  28879. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  28880. var sigmaPixels = sigmaRadians / radiansPerPixel;
  28881. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  28882. if (samples > MAX_SAMPLES) {
  28883. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  28884. }
  28885. var weights = [];
  28886. var sum = 0;
  28887. for (var i = 0; i < MAX_SAMPLES; ++i) {
  28888. var _x = i / sigmaPixels;
  28889. var weight = Math.exp(-_x * _x / 2);
  28890. weights.push(weight);
  28891. if (i == 0) {
  28892. sum += weight;
  28893. } else if (i < samples) {
  28894. sum += 2 * weight;
  28895. }
  28896. }
  28897. for (var _i = 0; _i < weights.length; _i++) {
  28898. weights[_i] = weights[_i] / sum;
  28899. }
  28900. blurUniforms['envMap'].value = targetIn.texture;
  28901. blurUniforms['samples'].value = samples;
  28902. blurUniforms['weights'].value = weights;
  28903. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  28904. if (poleAxis) {
  28905. blurUniforms['poleAxis'].value = poleAxis;
  28906. }
  28907. blurUniforms['dTheta'].value = radiansPerPixel;
  28908. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  28909. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28910. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28911. var outputSize = _sizeLods[lodOut];
  28912. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  28913. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  28914. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  28915. renderer.setRenderTarget(targetOut);
  28916. renderer.render(blurMesh, _flatCamera);
  28917. };
  28918. return PMREMGenerator;
  28919. }();
  28920. function _isLDR(texture) {
  28921. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  28922. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  28923. }
  28924. function _createPlanes() {
  28925. var _lodPlanes = [];
  28926. var _sizeLods = [];
  28927. var _sigmas = [];
  28928. var lod = LOD_MAX;
  28929. for (var i = 0; i < TOTAL_LODS; i++) {
  28930. var sizeLod = Math.pow(2, lod);
  28931. _sizeLods.push(sizeLod);
  28932. var sigma = 1.0 / sizeLod;
  28933. if (i > LOD_MAX - LOD_MIN) {
  28934. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  28935. } else if (i == 0) {
  28936. sigma = 0;
  28937. }
  28938. _sigmas.push(sigma);
  28939. var texelSize = 1.0 / (sizeLod - 1);
  28940. var min = -texelSize / 2;
  28941. var max = 1 + texelSize / 2;
  28942. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  28943. var cubeFaces = 6;
  28944. var vertices = 6;
  28945. var positionSize = 3;
  28946. var uvSize = 2;
  28947. var faceIndexSize = 1;
  28948. var position = new Float32Array(positionSize * vertices * cubeFaces);
  28949. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  28950. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  28951. for (var face = 0; face < cubeFaces; face++) {
  28952. var x = face % 3 * 2 / 3 - 1;
  28953. var y = face > 2 ? 0 : -1;
  28954. 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];
  28955. position.set(coordinates, positionSize * vertices * face);
  28956. uv.set(uv1, uvSize * vertices * face);
  28957. var fill = [face, face, face, face, face, face];
  28958. faceIndex.set(fill, faceIndexSize * vertices * face);
  28959. }
  28960. var planes = new BufferGeometry();
  28961. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  28962. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  28963. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  28964. _lodPlanes.push(planes);
  28965. if (lod > LOD_MIN) {
  28966. lod--;
  28967. }
  28968. }
  28969. return {
  28970. _lodPlanes: _lodPlanes,
  28971. _sizeLods: _sizeLods,
  28972. _sigmas: _sigmas
  28973. };
  28974. }
  28975. function _createRenderTarget(params) {
  28976. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  28977. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  28978. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  28979. cubeUVRenderTarget.scissorTest = true;
  28980. return cubeUVRenderTarget;
  28981. }
  28982. function _setViewport(target, x, y, width, height) {
  28983. target.viewport.set(x, y, width, height);
  28984. target.scissor.set(x, y, width, height);
  28985. }
  28986. function _getBlurShader(maxSamples) {
  28987. var weights = new Float32Array(maxSamples);
  28988. var poleAxis = new Vector3(0, 1, 0);
  28989. var shaderMaterial = new RawShaderMaterial({
  28990. name: 'SphericalGaussianBlur',
  28991. defines: {
  28992. 'n': maxSamples
  28993. },
  28994. uniforms: {
  28995. 'envMap': {
  28996. value: null
  28997. },
  28998. 'samples': {
  28999. value: 1
  29000. },
  29001. 'weights': {
  29002. value: weights
  29003. },
  29004. 'latitudinal': {
  29005. value: false
  29006. },
  29007. 'dTheta': {
  29008. value: 0
  29009. },
  29010. 'mipInt': {
  29011. value: 0
  29012. },
  29013. 'poleAxis': {
  29014. value: poleAxis
  29015. },
  29016. 'inputEncoding': {
  29017. value: ENCODINGS[LinearEncoding]
  29018. },
  29019. 'outputEncoding': {
  29020. value: ENCODINGS[LinearEncoding]
  29021. }
  29022. },
  29023. vertexShader: _getCommonVertexShader(),
  29024. fragmentShader:
  29025. /* glsl */
  29026. "\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",
  29027. blending: NoBlending,
  29028. depthTest: false,
  29029. depthWrite: false
  29030. });
  29031. return shaderMaterial;
  29032. }
  29033. function _getEquirectShader() {
  29034. var texelSize = new Vector2(1, 1);
  29035. var shaderMaterial = new RawShaderMaterial({
  29036. name: 'EquirectangularToCubeUV',
  29037. uniforms: {
  29038. 'envMap': {
  29039. value: null
  29040. },
  29041. 'texelSize': {
  29042. value: texelSize
  29043. },
  29044. 'inputEncoding': {
  29045. value: ENCODINGS[LinearEncoding]
  29046. },
  29047. 'outputEncoding': {
  29048. value: ENCODINGS[LinearEncoding]
  29049. }
  29050. },
  29051. vertexShader: _getCommonVertexShader(),
  29052. fragmentShader:
  29053. /* glsl */
  29054. "\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",
  29055. blending: NoBlending,
  29056. depthTest: false,
  29057. depthWrite: false
  29058. });
  29059. return shaderMaterial;
  29060. }
  29061. function _getCubemapShader() {
  29062. var shaderMaterial = new RawShaderMaterial({
  29063. name: 'CubemapToCubeUV',
  29064. uniforms: {
  29065. 'envMap': {
  29066. value: null
  29067. },
  29068. 'inputEncoding': {
  29069. value: ENCODINGS[LinearEncoding]
  29070. },
  29071. 'outputEncoding': {
  29072. value: ENCODINGS[LinearEncoding]
  29073. }
  29074. },
  29075. vertexShader: _getCommonVertexShader(),
  29076. fragmentShader:
  29077. /* glsl */
  29078. "\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",
  29079. blending: NoBlending,
  29080. depthTest: false,
  29081. depthWrite: false
  29082. });
  29083. return shaderMaterial;
  29084. }
  29085. function _getCommonVertexShader() {
  29086. return (
  29087. /* glsl */
  29088. "\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"
  29089. );
  29090. }
  29091. function _getEncodings() {
  29092. return (
  29093. /* glsl */
  29094. "\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"
  29095. );
  29096. }
  29097. function Face4(a, b, c, d, normal, color, materialIndex) {
  29098. console.warn('THREE.Face4 has been removed. A THREE.Face3 will be created instead.');
  29099. return new Face3(a, b, c, normal, color, materialIndex);
  29100. }
  29101. var LineStrip = 0;
  29102. var LinePieces = 1;
  29103. var NoColors = 0;
  29104. var FaceColors = 1;
  29105. var VertexColors = 2;
  29106. function MeshFaceMaterial(materials) {
  29107. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  29108. return materials;
  29109. }
  29110. function MultiMaterial(materials) {
  29111. if (materials === void 0) {
  29112. materials = [];
  29113. }
  29114. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  29115. materials.isMultiMaterial = true;
  29116. materials.materials = materials;
  29117. materials.clone = function () {
  29118. return materials.slice();
  29119. };
  29120. return materials;
  29121. }
  29122. function PointCloud(geometry, material) {
  29123. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  29124. return new Points(geometry, material);
  29125. }
  29126. function Particle(material) {
  29127. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  29128. return new Sprite(material);
  29129. }
  29130. function ParticleSystem(geometry, material) {
  29131. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  29132. return new Points(geometry, material);
  29133. }
  29134. function PointCloudMaterial(parameters) {
  29135. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  29136. return new PointsMaterial(parameters);
  29137. }
  29138. function ParticleBasicMaterial(parameters) {
  29139. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  29140. return new PointsMaterial(parameters);
  29141. }
  29142. function ParticleSystemMaterial(parameters) {
  29143. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  29144. return new PointsMaterial(parameters);
  29145. }
  29146. function Vertex(x, y, z) {
  29147. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  29148. return new Vector3(x, y, z);
  29149. } //
  29150. function DynamicBufferAttribute(array, itemSize) {
  29151. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  29152. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  29153. }
  29154. function Int8Attribute(array, itemSize) {
  29155. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  29156. return new Int8BufferAttribute(array, itemSize);
  29157. }
  29158. function Uint8Attribute(array, itemSize) {
  29159. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  29160. return new Uint8BufferAttribute(array, itemSize);
  29161. }
  29162. function Uint8ClampedAttribute(array, itemSize) {
  29163. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  29164. return new Uint8ClampedBufferAttribute(array, itemSize);
  29165. }
  29166. function Int16Attribute(array, itemSize) {
  29167. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  29168. return new Int16BufferAttribute(array, itemSize);
  29169. }
  29170. function Uint16Attribute(array, itemSize) {
  29171. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  29172. return new Uint16BufferAttribute(array, itemSize);
  29173. }
  29174. function Int32Attribute(array, itemSize) {
  29175. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  29176. return new Int32BufferAttribute(array, itemSize);
  29177. }
  29178. function Uint32Attribute(array, itemSize) {
  29179. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  29180. return new Uint32BufferAttribute(array, itemSize);
  29181. }
  29182. function Float32Attribute(array, itemSize) {
  29183. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  29184. return new Float32BufferAttribute(array, itemSize);
  29185. }
  29186. function Float64Attribute(array, itemSize) {
  29187. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  29188. return new Float64BufferAttribute(array, itemSize);
  29189. } //
  29190. Curve.create = function (construct, getPoint) {
  29191. console.log('THREE.Curve.create() has been deprecated');
  29192. construct.prototype = Object.create(Curve.prototype);
  29193. construct.prototype.constructor = construct;
  29194. construct.prototype.getPoint = getPoint;
  29195. return construct;
  29196. }; //
  29197. Object.assign(CurvePath.prototype, {
  29198. createPointsGeometry: function createPointsGeometry(divisions) {
  29199. 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)
  29200. var pts = this.getPoints(divisions);
  29201. return this.createGeometry(pts);
  29202. },
  29203. createSpacedPointsGeometry: function createSpacedPointsGeometry(divisions) {
  29204. console.warn('THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.'); // generate geometry from equidistant sampling along the path
  29205. var pts = this.getSpacedPoints(divisions);
  29206. return this.createGeometry(pts);
  29207. },
  29208. createGeometry: function createGeometry(points) {
  29209. console.warn('THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');
  29210. var geometry = new Geometry();
  29211. for (var i = 0, l = points.length; i < l; i++) {
  29212. var point = points[i];
  29213. geometry.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  29214. }
  29215. return geometry;
  29216. }
  29217. }); //
  29218. Object.assign(Path.prototype, {
  29219. fromPoints: function fromPoints(points) {
  29220. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  29221. return this.setFromPoints(points);
  29222. }
  29223. }); //
  29224. function ClosedSplineCurve3(points) {
  29225. console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29226. CatmullRomCurve3.call(this, points);
  29227. this.type = 'catmullrom';
  29228. this.closed = true;
  29229. }
  29230. ClosedSplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29231. function SplineCurve3(points) {
  29232. console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29233. CatmullRomCurve3.call(this, points);
  29234. this.type = 'catmullrom';
  29235. }
  29236. SplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29237. function Spline(points) {
  29238. console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');
  29239. CatmullRomCurve3.call(this, points);
  29240. this.type = 'catmullrom';
  29241. }
  29242. Spline.prototype = Object.create(CatmullRomCurve3.prototype);
  29243. Object.assign(Spline.prototype, {
  29244. initFromArray: function initFromArray()
  29245. /* a */
  29246. {
  29247. console.error('THREE.Spline: .initFromArray() has been removed.');
  29248. },
  29249. getControlPointsArray: function getControlPointsArray()
  29250. /* optionalTarget */
  29251. {
  29252. console.error('THREE.Spline: .getControlPointsArray() has been removed.');
  29253. },
  29254. reparametrizeByArcLength: function reparametrizeByArcLength()
  29255. /* samplingCoef */
  29256. {
  29257. console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');
  29258. }
  29259. }); //
  29260. function AxisHelper(size) {
  29261. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  29262. return new AxesHelper(size);
  29263. }
  29264. function BoundingBoxHelper(object, color) {
  29265. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  29266. return new BoxHelper(object, color);
  29267. }
  29268. function EdgesHelper(object, hex) {
  29269. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  29270. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  29271. color: hex !== undefined ? hex : 0xffffff
  29272. }));
  29273. }
  29274. GridHelper.prototype.setColors = function () {
  29275. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  29276. };
  29277. SkeletonHelper.prototype.update = function () {
  29278. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  29279. };
  29280. function WireframeHelper(object, hex) {
  29281. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  29282. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  29283. color: hex !== undefined ? hex : 0xffffff
  29284. }));
  29285. } //
  29286. Object.assign(Loader.prototype, {
  29287. extractUrlBase: function extractUrlBase(url) {
  29288. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  29289. return LoaderUtils.extractUrlBase(url);
  29290. }
  29291. });
  29292. Loader.Handlers = {
  29293. add: function add()
  29294. /* regex, loader */
  29295. {
  29296. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  29297. },
  29298. get: function get()
  29299. /* file */
  29300. {
  29301. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  29302. }
  29303. };
  29304. function XHRLoader(manager) {
  29305. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  29306. return new FileLoader(manager);
  29307. }
  29308. function BinaryTextureLoader(manager) {
  29309. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29310. return new DataTextureLoader(manager);
  29311. } //
  29312. Object.assign(Box2.prototype, {
  29313. center: function center(optionalTarget) {
  29314. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29315. return this.getCenter(optionalTarget);
  29316. },
  29317. empty: function empty() {
  29318. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29319. return this.isEmpty();
  29320. },
  29321. isIntersectionBox: function isIntersectionBox(box) {
  29322. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29323. return this.intersectsBox(box);
  29324. },
  29325. size: function size(optionalTarget) {
  29326. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29327. return this.getSize(optionalTarget);
  29328. }
  29329. });
  29330. Object.assign(Box3.prototype, {
  29331. center: function center(optionalTarget) {
  29332. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29333. return this.getCenter(optionalTarget);
  29334. },
  29335. empty: function empty() {
  29336. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29337. return this.isEmpty();
  29338. },
  29339. isIntersectionBox: function isIntersectionBox(box) {
  29340. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29341. return this.intersectsBox(box);
  29342. },
  29343. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29344. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29345. return this.intersectsSphere(sphere);
  29346. },
  29347. size: function size(optionalTarget) {
  29348. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29349. return this.getSize(optionalTarget);
  29350. }
  29351. });
  29352. Object.assign(Sphere.prototype, {
  29353. empty: function empty() {
  29354. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29355. return this.isEmpty();
  29356. }
  29357. });
  29358. Frustum.prototype.setFromMatrix = function (m) {
  29359. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29360. return this.setFromProjectionMatrix(m);
  29361. };
  29362. Line3.prototype.center = function (optionalTarget) {
  29363. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29364. return this.getCenter(optionalTarget);
  29365. };
  29366. Object.assign(MathUtils, {
  29367. random16: function random16() {
  29368. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29369. return Math.random();
  29370. },
  29371. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29372. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29373. return MathUtils.floorPowerOfTwo(value);
  29374. },
  29375. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29376. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29377. return MathUtils.ceilPowerOfTwo(value);
  29378. }
  29379. });
  29380. Object.assign(Matrix3.prototype, {
  29381. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29382. console.warn("THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");
  29383. return this.toArray(array, offset);
  29384. },
  29385. multiplyVector3: function multiplyVector3(vector) {
  29386. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29387. return vector.applyMatrix3(this);
  29388. },
  29389. multiplyVector3Array: function multiplyVector3Array()
  29390. /* a */
  29391. {
  29392. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29393. },
  29394. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29395. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29396. return attribute.applyMatrix3(this);
  29397. },
  29398. applyToVector3Array: function applyToVector3Array()
  29399. /* array, offset, length */
  29400. {
  29401. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29402. },
  29403. getInverse: function getInverse(matrix) {
  29404. console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29405. return this.copy(matrix).invert();
  29406. }
  29407. });
  29408. Object.assign(Matrix4.prototype, {
  29409. extractPosition: function extractPosition(m) {
  29410. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29411. return this.copyPosition(m);
  29412. },
  29413. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29414. console.warn("THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");
  29415. return this.toArray(array, offset);
  29416. },
  29417. getPosition: function getPosition() {
  29418. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29419. return new Vector3().setFromMatrixColumn(this, 3);
  29420. },
  29421. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29422. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29423. return this.makeRotationFromQuaternion(q);
  29424. },
  29425. multiplyToArray: function multiplyToArray() {
  29426. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29427. },
  29428. multiplyVector3: function multiplyVector3(vector) {
  29429. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29430. return vector.applyMatrix4(this);
  29431. },
  29432. multiplyVector4: function multiplyVector4(vector) {
  29433. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29434. return vector.applyMatrix4(this);
  29435. },
  29436. multiplyVector3Array: function multiplyVector3Array()
  29437. /* a */
  29438. {
  29439. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29440. },
  29441. rotateAxis: function rotateAxis(v) {
  29442. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29443. v.transformDirection(this);
  29444. },
  29445. crossVector: function crossVector(vector) {
  29446. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29447. return vector.applyMatrix4(this);
  29448. },
  29449. translate: function translate() {
  29450. console.error('THREE.Matrix4: .translate() has been removed.');
  29451. },
  29452. rotateX: function rotateX() {
  29453. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29454. },
  29455. rotateY: function rotateY() {
  29456. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29457. },
  29458. rotateZ: function rotateZ() {
  29459. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29460. },
  29461. rotateByAxis: function rotateByAxis() {
  29462. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29463. },
  29464. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29465. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29466. return attribute.applyMatrix4(this);
  29467. },
  29468. applyToVector3Array: function applyToVector3Array()
  29469. /* array, offset, length */
  29470. {
  29471. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29472. },
  29473. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29474. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29475. return this.makePerspective(left, right, top, bottom, near, far);
  29476. },
  29477. getInverse: function getInverse(matrix) {
  29478. console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29479. return this.copy(matrix).invert();
  29480. }
  29481. });
  29482. Plane.prototype.isIntersectionLine = function (line) {
  29483. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29484. return this.intersectsLine(line);
  29485. };
  29486. Object.assign(Quaternion.prototype, {
  29487. multiplyVector3: function multiplyVector3(vector) {
  29488. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29489. return vector.applyQuaternion(this);
  29490. },
  29491. inverse: function inverse() {
  29492. console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');
  29493. return this.invert();
  29494. }
  29495. });
  29496. Object.assign(Ray.prototype, {
  29497. isIntersectionBox: function isIntersectionBox(box) {
  29498. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29499. return this.intersectsBox(box);
  29500. },
  29501. isIntersectionPlane: function isIntersectionPlane(plane) {
  29502. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29503. return this.intersectsPlane(plane);
  29504. },
  29505. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29506. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29507. return this.intersectsSphere(sphere);
  29508. }
  29509. });
  29510. Object.assign(Triangle.prototype, {
  29511. area: function area() {
  29512. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29513. return this.getArea();
  29514. },
  29515. barycoordFromPoint: function barycoordFromPoint(point, target) {
  29516. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29517. return this.getBarycoord(point, target);
  29518. },
  29519. midpoint: function midpoint(target) {
  29520. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29521. return this.getMidpoint(target);
  29522. },
  29523. normal: function normal(target) {
  29524. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29525. return this.getNormal(target);
  29526. },
  29527. plane: function plane(target) {
  29528. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29529. return this.getPlane(target);
  29530. }
  29531. });
  29532. Object.assign(Triangle, {
  29533. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  29534. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29535. return Triangle.getBarycoord(point, a, b, c, target);
  29536. },
  29537. normal: function normal(a, b, c, target) {
  29538. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29539. return Triangle.getNormal(a, b, c, target);
  29540. }
  29541. });
  29542. Object.assign(Shape.prototype, {
  29543. extractAllPoints: function extractAllPoints(divisions) {
  29544. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29545. return this.extractPoints(divisions);
  29546. },
  29547. extrude: function extrude(options) {
  29548. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  29549. return new ExtrudeGeometry(this, options);
  29550. },
  29551. makeGeometry: function makeGeometry(options) {
  29552. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  29553. return new ShapeGeometry(this, options);
  29554. }
  29555. });
  29556. Object.assign(Vector2.prototype, {
  29557. fromAttribute: function fromAttribute(attribute, index, offset) {
  29558. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29559. return this.fromBufferAttribute(attribute, index, offset);
  29560. },
  29561. distanceToManhattan: function distanceToManhattan(v) {
  29562. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29563. return this.manhattanDistanceTo(v);
  29564. },
  29565. lengthManhattan: function lengthManhattan() {
  29566. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  29567. return this.manhattanLength();
  29568. }
  29569. });
  29570. Object.assign(Vector3.prototype, {
  29571. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  29572. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  29573. },
  29574. setEulerFromQuaternion: function setEulerFromQuaternion() {
  29575. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  29576. },
  29577. getPositionFromMatrix: function getPositionFromMatrix(m) {
  29578. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  29579. return this.setFromMatrixPosition(m);
  29580. },
  29581. getScaleFromMatrix: function getScaleFromMatrix(m) {
  29582. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  29583. return this.setFromMatrixScale(m);
  29584. },
  29585. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  29586. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  29587. return this.setFromMatrixColumn(matrix, index);
  29588. },
  29589. applyProjection: function applyProjection(m) {
  29590. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  29591. return this.applyMatrix4(m);
  29592. },
  29593. fromAttribute: function fromAttribute(attribute, index, offset) {
  29594. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29595. return this.fromBufferAttribute(attribute, index, offset);
  29596. },
  29597. distanceToManhattan: function distanceToManhattan(v) {
  29598. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29599. return this.manhattanDistanceTo(v);
  29600. },
  29601. lengthManhattan: function lengthManhattan() {
  29602. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  29603. return this.manhattanLength();
  29604. }
  29605. });
  29606. Object.assign(Vector4.prototype, {
  29607. fromAttribute: function fromAttribute(attribute, index, offset) {
  29608. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29609. return this.fromBufferAttribute(attribute, index, offset);
  29610. },
  29611. lengthManhattan: function lengthManhattan() {
  29612. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  29613. return this.manhattanLength();
  29614. }
  29615. }); //
  29616. Object.assign(Geometry.prototype, {
  29617. computeTangents: function computeTangents() {
  29618. console.error('THREE.Geometry: .computeTangents() has been removed.');
  29619. },
  29620. computeLineDistances: function computeLineDistances() {
  29621. console.error('THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.');
  29622. },
  29623. applyMatrix: function applyMatrix(matrix) {
  29624. console.warn('THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29625. return this.applyMatrix4(matrix);
  29626. }
  29627. });
  29628. Object.assign(Object3D.prototype, {
  29629. getChildByName: function getChildByName(name) {
  29630. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  29631. return this.getObjectByName(name);
  29632. },
  29633. renderDepth: function renderDepth() {
  29634. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  29635. },
  29636. translate: function translate(distance, axis) {
  29637. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  29638. return this.translateOnAxis(axis, distance);
  29639. },
  29640. getWorldRotation: function getWorldRotation() {
  29641. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  29642. },
  29643. applyMatrix: function applyMatrix(matrix) {
  29644. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  29645. return this.applyMatrix4(matrix);
  29646. }
  29647. });
  29648. Object.defineProperties(Object3D.prototype, {
  29649. eulerOrder: {
  29650. get: function get() {
  29651. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29652. return this.rotation.order;
  29653. },
  29654. set: function set(value) {
  29655. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29656. this.rotation.order = value;
  29657. }
  29658. },
  29659. useQuaternion: {
  29660. get: function get() {
  29661. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29662. },
  29663. set: function set() {
  29664. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29665. }
  29666. }
  29667. });
  29668. Object.assign(Mesh.prototype, {
  29669. setDrawMode: function setDrawMode() {
  29670. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29671. }
  29672. });
  29673. Object.defineProperties(Mesh.prototype, {
  29674. drawMode: {
  29675. get: function get() {
  29676. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  29677. return TrianglesDrawMode;
  29678. },
  29679. set: function set() {
  29680. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29681. }
  29682. }
  29683. });
  29684. Object.defineProperties(LOD.prototype, {
  29685. objects: {
  29686. get: function get() {
  29687. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  29688. return this.levels;
  29689. }
  29690. }
  29691. });
  29692. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  29693. get: function get() {
  29694. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29695. },
  29696. set: function set() {
  29697. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29698. }
  29699. });
  29700. SkinnedMesh.prototype.initBones = function () {
  29701. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  29702. };
  29703. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  29704. get: function get() {
  29705. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29706. return this.arcLengthDivisions;
  29707. },
  29708. set: function set(value) {
  29709. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29710. this.arcLengthDivisions = value;
  29711. }
  29712. }); //
  29713. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  29714. console.warn("THREE.PerspectiveCamera.setLens is deprecated. " + "Use .setFocalLength and .filmGauge for a photographic setup.");
  29715. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  29716. this.setFocalLength(focalLength);
  29717. }; //
  29718. Object.defineProperties(Light.prototype, {
  29719. onlyShadow: {
  29720. set: function set() {
  29721. console.warn('THREE.Light: .onlyShadow has been removed.');
  29722. }
  29723. },
  29724. shadowCameraFov: {
  29725. set: function set(value) {
  29726. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  29727. this.shadow.camera.fov = value;
  29728. }
  29729. },
  29730. shadowCameraLeft: {
  29731. set: function set(value) {
  29732. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  29733. this.shadow.camera.left = value;
  29734. }
  29735. },
  29736. shadowCameraRight: {
  29737. set: function set(value) {
  29738. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  29739. this.shadow.camera.right = value;
  29740. }
  29741. },
  29742. shadowCameraTop: {
  29743. set: function set(value) {
  29744. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  29745. this.shadow.camera.top = value;
  29746. }
  29747. },
  29748. shadowCameraBottom: {
  29749. set: function set(value) {
  29750. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  29751. this.shadow.camera.bottom = value;
  29752. }
  29753. },
  29754. shadowCameraNear: {
  29755. set: function set(value) {
  29756. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  29757. this.shadow.camera.near = value;
  29758. }
  29759. },
  29760. shadowCameraFar: {
  29761. set: function set(value) {
  29762. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  29763. this.shadow.camera.far = value;
  29764. }
  29765. },
  29766. shadowCameraVisible: {
  29767. set: function set() {
  29768. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  29769. }
  29770. },
  29771. shadowBias: {
  29772. set: function set(value) {
  29773. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  29774. this.shadow.bias = value;
  29775. }
  29776. },
  29777. shadowDarkness: {
  29778. set: function set() {
  29779. console.warn('THREE.Light: .shadowDarkness has been removed.');
  29780. }
  29781. },
  29782. shadowMapWidth: {
  29783. set: function set(value) {
  29784. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  29785. this.shadow.mapSize.width = value;
  29786. }
  29787. },
  29788. shadowMapHeight: {
  29789. set: function set(value) {
  29790. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  29791. this.shadow.mapSize.height = value;
  29792. }
  29793. }
  29794. }); //
  29795. Object.defineProperties(BufferAttribute.prototype, {
  29796. length: {
  29797. get: function get() {
  29798. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  29799. return this.array.length;
  29800. }
  29801. },
  29802. dynamic: {
  29803. get: function get() {
  29804. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29805. return this.usage === DynamicDrawUsage;
  29806. },
  29807. set: function set()
  29808. /* value */
  29809. {
  29810. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29811. this.setUsage(DynamicDrawUsage);
  29812. }
  29813. }
  29814. });
  29815. Object.assign(BufferAttribute.prototype, {
  29816. setDynamic: function setDynamic(value) {
  29817. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29818. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29819. return this;
  29820. },
  29821. copyIndicesArray: function copyIndicesArray()
  29822. /* indices */
  29823. {
  29824. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  29825. },
  29826. setArray: function setArray()
  29827. /* array */
  29828. {
  29829. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29830. }
  29831. });
  29832. Object.assign(BufferGeometry.prototype, {
  29833. addIndex: function addIndex(index) {
  29834. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  29835. this.setIndex(index);
  29836. },
  29837. addAttribute: function addAttribute(name, attribute) {
  29838. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  29839. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  29840. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  29841. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  29842. }
  29843. if (name === 'index') {
  29844. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  29845. this.setIndex(attribute);
  29846. return this;
  29847. }
  29848. return this.setAttribute(name, attribute);
  29849. },
  29850. addDrawCall: function addDrawCall(start, count, indexOffset) {
  29851. if (indexOffset !== undefined) {
  29852. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  29853. }
  29854. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  29855. this.addGroup(start, count);
  29856. },
  29857. clearDrawCalls: function clearDrawCalls() {
  29858. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  29859. this.clearGroups();
  29860. },
  29861. computeTangents: function computeTangents() {
  29862. console.warn('THREE.BufferGeometry: .computeTangents() has been removed.');
  29863. },
  29864. computeOffsets: function computeOffsets() {
  29865. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  29866. },
  29867. removeAttribute: function removeAttribute(name) {
  29868. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  29869. return this.deleteAttribute(name);
  29870. },
  29871. applyMatrix: function applyMatrix(matrix) {
  29872. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29873. return this.applyMatrix4(matrix);
  29874. }
  29875. });
  29876. Object.defineProperties(BufferGeometry.prototype, {
  29877. drawcalls: {
  29878. get: function get() {
  29879. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  29880. return this.groups;
  29881. }
  29882. },
  29883. offsets: {
  29884. get: function get() {
  29885. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  29886. return this.groups;
  29887. }
  29888. }
  29889. });
  29890. Object.defineProperties(InstancedBufferGeometry.prototype, {
  29891. maxInstancedCount: {
  29892. get: function get() {
  29893. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29894. return this.instanceCount;
  29895. },
  29896. set: function set(value) {
  29897. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29898. this.instanceCount = value;
  29899. }
  29900. }
  29901. });
  29902. Object.defineProperties(Raycaster.prototype, {
  29903. linePrecision: {
  29904. get: function get() {
  29905. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29906. return this.params.Line.threshold;
  29907. },
  29908. set: function set(value) {
  29909. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29910. this.params.Line.threshold = value;
  29911. }
  29912. }
  29913. });
  29914. Object.defineProperties(InterleavedBuffer.prototype, {
  29915. dynamic: {
  29916. get: function get() {
  29917. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29918. return this.usage === DynamicDrawUsage;
  29919. },
  29920. set: function set(value) {
  29921. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29922. this.setUsage(value);
  29923. }
  29924. }
  29925. });
  29926. Object.assign(InterleavedBuffer.prototype, {
  29927. setDynamic: function setDynamic(value) {
  29928. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29929. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29930. return this;
  29931. },
  29932. setArray: function setArray()
  29933. /* array */
  29934. {
  29935. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29936. }
  29937. }); //
  29938. Object.assign(ExtrudeBufferGeometry.prototype, {
  29939. getArrays: function getArrays() {
  29940. console.error('THREE.ExtrudeBufferGeometry: .getArrays() has been removed.');
  29941. },
  29942. addShapeList: function addShapeList() {
  29943. console.error('THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.');
  29944. },
  29945. addShape: function addShape() {
  29946. console.error('THREE.ExtrudeBufferGeometry: .addShape() has been removed.');
  29947. }
  29948. }); //
  29949. Object.assign(Scene.prototype, {
  29950. dispose: function dispose() {
  29951. console.error('THREE.Scene: .dispose() has been removed.');
  29952. }
  29953. }); //
  29954. Object.defineProperties(Uniform.prototype, {
  29955. dynamic: {
  29956. set: function set() {
  29957. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  29958. }
  29959. },
  29960. onUpdate: {
  29961. value: function value() {
  29962. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  29963. return this;
  29964. }
  29965. }
  29966. }); //
  29967. Object.defineProperties(Material.prototype, {
  29968. wrapAround: {
  29969. get: function get() {
  29970. console.warn('THREE.Material: .wrapAround has been removed.');
  29971. },
  29972. set: function set() {
  29973. console.warn('THREE.Material: .wrapAround has been removed.');
  29974. }
  29975. },
  29976. overdraw: {
  29977. get: function get() {
  29978. console.warn('THREE.Material: .overdraw has been removed.');
  29979. },
  29980. set: function set() {
  29981. console.warn('THREE.Material: .overdraw has been removed.');
  29982. }
  29983. },
  29984. wrapRGB: {
  29985. get: function get() {
  29986. console.warn('THREE.Material: .wrapRGB has been removed.');
  29987. return new Color();
  29988. }
  29989. },
  29990. shading: {
  29991. get: function get() {
  29992. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29993. },
  29994. set: function set(value) {
  29995. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29996. this.flatShading = value === FlatShading;
  29997. }
  29998. },
  29999. stencilMask: {
  30000. get: function get() {
  30001. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30002. return this.stencilFuncMask;
  30003. },
  30004. set: function set(value) {
  30005. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30006. this.stencilFuncMask = value;
  30007. }
  30008. }
  30009. });
  30010. Object.defineProperties(MeshPhongMaterial.prototype, {
  30011. metal: {
  30012. get: function get() {
  30013. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  30014. return false;
  30015. },
  30016. set: function set() {
  30017. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  30018. }
  30019. }
  30020. });
  30021. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  30022. transparency: {
  30023. get: function get() {
  30024. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30025. return this.transmission;
  30026. },
  30027. set: function set(value) {
  30028. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30029. this.transmission = value;
  30030. }
  30031. }
  30032. });
  30033. Object.defineProperties(ShaderMaterial.prototype, {
  30034. derivatives: {
  30035. get: function get() {
  30036. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30037. return this.extensions.derivatives;
  30038. },
  30039. set: function set(value) {
  30040. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30041. this.extensions.derivatives = value;
  30042. }
  30043. }
  30044. }); //
  30045. Object.assign(WebGLRenderer.prototype, {
  30046. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  30047. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  30048. this.setRenderTarget(renderTarget);
  30049. this.clear(color, depth, stencil);
  30050. },
  30051. animate: function animate(callback) {
  30052. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  30053. this.setAnimationLoop(callback);
  30054. },
  30055. getCurrentRenderTarget: function getCurrentRenderTarget() {
  30056. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  30057. return this.getRenderTarget();
  30058. },
  30059. getMaxAnisotropy: function getMaxAnisotropy() {
  30060. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  30061. return this.capabilities.getMaxAnisotropy();
  30062. },
  30063. getPrecision: function getPrecision() {
  30064. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  30065. return this.capabilities.precision;
  30066. },
  30067. resetGLState: function resetGLState() {
  30068. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  30069. return this.state.reset();
  30070. },
  30071. supportsFloatTextures: function supportsFloatTextures() {
  30072. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  30073. return this.extensions.get('OES_texture_float');
  30074. },
  30075. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  30076. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  30077. return this.extensions.get('OES_texture_half_float');
  30078. },
  30079. supportsStandardDerivatives: function supportsStandardDerivatives() {
  30080. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  30081. return this.extensions.get('OES_standard_derivatives');
  30082. },
  30083. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  30084. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  30085. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  30086. },
  30087. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  30088. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  30089. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  30090. },
  30091. supportsBlendMinMax: function supportsBlendMinMax() {
  30092. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  30093. return this.extensions.get('EXT_blend_minmax');
  30094. },
  30095. supportsVertexTextures: function supportsVertexTextures() {
  30096. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  30097. return this.capabilities.vertexTextures;
  30098. },
  30099. supportsInstancedArrays: function supportsInstancedArrays() {
  30100. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  30101. return this.extensions.get('ANGLE_instanced_arrays');
  30102. },
  30103. enableScissorTest: function enableScissorTest(boolean) {
  30104. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  30105. this.setScissorTest(boolean);
  30106. },
  30107. initMaterial: function initMaterial() {
  30108. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  30109. },
  30110. addPrePlugin: function addPrePlugin() {
  30111. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  30112. },
  30113. addPostPlugin: function addPostPlugin() {
  30114. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  30115. },
  30116. updateShadowMap: function updateShadowMap() {
  30117. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  30118. },
  30119. setFaceCulling: function setFaceCulling() {
  30120. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  30121. },
  30122. allocTextureUnit: function allocTextureUnit() {
  30123. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  30124. },
  30125. setTexture: function setTexture() {
  30126. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  30127. },
  30128. setTexture2D: function setTexture2D() {
  30129. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  30130. },
  30131. setTextureCube: function setTextureCube() {
  30132. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  30133. },
  30134. getActiveMipMapLevel: function getActiveMipMapLevel() {
  30135. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  30136. return this.getActiveMipmapLevel();
  30137. }
  30138. });
  30139. Object.defineProperties(WebGLRenderer.prototype, {
  30140. shadowMapEnabled: {
  30141. get: function get() {
  30142. return this.shadowMap.enabled;
  30143. },
  30144. set: function set(value) {
  30145. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  30146. this.shadowMap.enabled = value;
  30147. }
  30148. },
  30149. shadowMapType: {
  30150. get: function get() {
  30151. return this.shadowMap.type;
  30152. },
  30153. set: function set(value) {
  30154. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  30155. this.shadowMap.type = value;
  30156. }
  30157. },
  30158. shadowMapCullFace: {
  30159. get: function get() {
  30160. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30161. return undefined;
  30162. },
  30163. set: function set()
  30164. /* value */
  30165. {
  30166. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30167. }
  30168. },
  30169. context: {
  30170. get: function get() {
  30171. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  30172. return this.getContext();
  30173. }
  30174. },
  30175. vr: {
  30176. get: function get() {
  30177. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  30178. return this.xr;
  30179. }
  30180. },
  30181. gammaInput: {
  30182. get: function get() {
  30183. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30184. return false;
  30185. },
  30186. set: function set() {
  30187. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30188. }
  30189. },
  30190. gammaOutput: {
  30191. get: function get() {
  30192. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30193. return false;
  30194. },
  30195. set: function set(value) {
  30196. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30197. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  30198. }
  30199. },
  30200. toneMappingWhitePoint: {
  30201. get: function get() {
  30202. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30203. return 1.0;
  30204. },
  30205. set: function set() {
  30206. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30207. }
  30208. }
  30209. });
  30210. Object.defineProperties(WebGLShadowMap.prototype, {
  30211. cullFace: {
  30212. get: function get() {
  30213. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30214. return undefined;
  30215. },
  30216. set: function set()
  30217. /* cullFace */
  30218. {
  30219. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30220. }
  30221. },
  30222. renderReverseSided: {
  30223. get: function get() {
  30224. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30225. return undefined;
  30226. },
  30227. set: function set() {
  30228. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30229. }
  30230. },
  30231. renderSingleSided: {
  30232. get: function get() {
  30233. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30234. return undefined;
  30235. },
  30236. set: function set() {
  30237. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30238. }
  30239. }
  30240. });
  30241. function WebGLRenderTargetCube(width, height, options) {
  30242. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  30243. return new WebGLCubeRenderTarget(width, options);
  30244. } //
  30245. Object.defineProperties(WebGLRenderTarget.prototype, {
  30246. wrapS: {
  30247. get: function get() {
  30248. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30249. return this.texture.wrapS;
  30250. },
  30251. set: function set(value) {
  30252. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30253. this.texture.wrapS = value;
  30254. }
  30255. },
  30256. wrapT: {
  30257. get: function get() {
  30258. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30259. return this.texture.wrapT;
  30260. },
  30261. set: function set(value) {
  30262. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30263. this.texture.wrapT = value;
  30264. }
  30265. },
  30266. magFilter: {
  30267. get: function get() {
  30268. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30269. return this.texture.magFilter;
  30270. },
  30271. set: function set(value) {
  30272. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30273. this.texture.magFilter = value;
  30274. }
  30275. },
  30276. minFilter: {
  30277. get: function get() {
  30278. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30279. return this.texture.minFilter;
  30280. },
  30281. set: function set(value) {
  30282. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30283. this.texture.minFilter = value;
  30284. }
  30285. },
  30286. anisotropy: {
  30287. get: function get() {
  30288. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30289. return this.texture.anisotropy;
  30290. },
  30291. set: function set(value) {
  30292. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30293. this.texture.anisotropy = value;
  30294. }
  30295. },
  30296. offset: {
  30297. get: function get() {
  30298. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30299. return this.texture.offset;
  30300. },
  30301. set: function set(value) {
  30302. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30303. this.texture.offset = value;
  30304. }
  30305. },
  30306. repeat: {
  30307. get: function get() {
  30308. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30309. return this.texture.repeat;
  30310. },
  30311. set: function set(value) {
  30312. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30313. this.texture.repeat = value;
  30314. }
  30315. },
  30316. format: {
  30317. get: function get() {
  30318. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30319. return this.texture.format;
  30320. },
  30321. set: function set(value) {
  30322. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30323. this.texture.format = value;
  30324. }
  30325. },
  30326. type: {
  30327. get: function get() {
  30328. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30329. return this.texture.type;
  30330. },
  30331. set: function set(value) {
  30332. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30333. this.texture.type = value;
  30334. }
  30335. },
  30336. generateMipmaps: {
  30337. get: function get() {
  30338. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30339. return this.texture.generateMipmaps;
  30340. },
  30341. set: function set(value) {
  30342. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30343. this.texture.generateMipmaps = value;
  30344. }
  30345. }
  30346. }); //
  30347. Object.defineProperties(Audio.prototype, {
  30348. load: {
  30349. value: function value(file) {
  30350. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30351. var scope = this;
  30352. var audioLoader = new AudioLoader();
  30353. audioLoader.load(file, function (buffer) {
  30354. scope.setBuffer(buffer);
  30355. });
  30356. return this;
  30357. }
  30358. },
  30359. startTime: {
  30360. set: function set() {
  30361. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30362. }
  30363. }
  30364. });
  30365. AudioAnalyser.prototype.getData = function () {
  30366. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30367. return this.getFrequencyData();
  30368. }; //
  30369. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30370. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30371. return this.update(renderer, scene);
  30372. };
  30373. CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
  30374. console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
  30375. return this.renderTarget.clear(renderer, color, depth, stencil);
  30376. }; //
  30377. var GeometryUtils = {
  30378. merge: function merge(geometry1, geometry2, materialIndexOffset) {
  30379. console.warn('THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.');
  30380. var matrix;
  30381. if (geometry2.isMesh) {
  30382. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30383. matrix = geometry2.matrix;
  30384. geometry2 = geometry2.geometry;
  30385. }
  30386. geometry1.merge(geometry2, matrix, materialIndexOffset);
  30387. },
  30388. center: function center(geometry) {
  30389. console.warn('THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.');
  30390. return geometry.center();
  30391. }
  30392. };
  30393. ImageUtils.crossOrigin = undefined;
  30394. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30395. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30396. var loader = new TextureLoader();
  30397. loader.setCrossOrigin(this.crossOrigin);
  30398. var texture = loader.load(url, onLoad, undefined, onError);
  30399. if (mapping) texture.mapping = mapping;
  30400. return texture;
  30401. };
  30402. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30403. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30404. var loader = new CubeTextureLoader();
  30405. loader.setCrossOrigin(this.crossOrigin);
  30406. var texture = loader.load(urls, onLoad, undefined, onError);
  30407. if (mapping) texture.mapping = mapping;
  30408. return texture;
  30409. };
  30410. ImageUtils.loadCompressedTexture = function () {
  30411. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30412. };
  30413. ImageUtils.loadCompressedTextureCube = function () {
  30414. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30415. }; //
  30416. function CanvasRenderer() {
  30417. console.error('THREE.CanvasRenderer has been removed');
  30418. } //
  30419. function JSONLoader() {
  30420. console.error('THREE.JSONLoader has been removed.');
  30421. } //
  30422. var SceneUtils = {
  30423. createMultiMaterialObject: function createMultiMaterialObject()
  30424. /* geometry, materials */
  30425. {
  30426. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30427. },
  30428. detach: function detach()
  30429. /* child, parent, scene */
  30430. {
  30431. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30432. },
  30433. attach: function attach()
  30434. /* child, scene, parent */
  30435. {
  30436. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30437. }
  30438. }; //
  30439. function LensFlare() {
  30440. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30441. }
  30442. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30443. /* eslint-disable no-undef */
  30444. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30445. detail: {
  30446. revision: REVISION
  30447. }
  30448. }));
  30449. /* eslint-enable no-undef */
  30450. }
  30451. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30452. exports.AddEquation = AddEquation;
  30453. exports.AddOperation = AddOperation;
  30454. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30455. exports.AdditiveBlending = AdditiveBlending;
  30456. exports.AlphaFormat = AlphaFormat;
  30457. exports.AlwaysDepth = AlwaysDepth;
  30458. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30459. exports.AmbientLight = AmbientLight;
  30460. exports.AmbientLightProbe = AmbientLightProbe;
  30461. exports.AnimationClip = AnimationClip;
  30462. exports.AnimationLoader = AnimationLoader;
  30463. exports.AnimationMixer = AnimationMixer;
  30464. exports.AnimationObjectGroup = AnimationObjectGroup;
  30465. exports.AnimationUtils = AnimationUtils;
  30466. exports.ArcCurve = ArcCurve;
  30467. exports.ArrayCamera = ArrayCamera;
  30468. exports.ArrowHelper = ArrowHelper;
  30469. exports.Audio = Audio;
  30470. exports.AudioAnalyser = AudioAnalyser;
  30471. exports.AudioContext = AudioContext;
  30472. exports.AudioListener = AudioListener;
  30473. exports.AudioLoader = AudioLoader;
  30474. exports.AxesHelper = AxesHelper;
  30475. exports.AxisHelper = AxisHelper;
  30476. exports.BackSide = BackSide;
  30477. exports.BasicDepthPacking = BasicDepthPacking;
  30478. exports.BasicShadowMap = BasicShadowMap;
  30479. exports.BinaryTextureLoader = BinaryTextureLoader;
  30480. exports.Bone = Bone;
  30481. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30482. exports.BoundingBoxHelper = BoundingBoxHelper;
  30483. exports.Box2 = Box2;
  30484. exports.Box3 = Box3;
  30485. exports.Box3Helper = Box3Helper;
  30486. exports.BoxBufferGeometry = BoxBufferGeometry;
  30487. exports.BoxGeometry = BoxGeometry;
  30488. exports.BoxHelper = BoxHelper;
  30489. exports.BufferAttribute = BufferAttribute;
  30490. exports.BufferGeometry = BufferGeometry;
  30491. exports.BufferGeometryLoader = BufferGeometryLoader;
  30492. exports.ByteType = ByteType;
  30493. exports.Cache = Cache;
  30494. exports.Camera = Camera;
  30495. exports.CameraHelper = CameraHelper;
  30496. exports.CanvasRenderer = CanvasRenderer;
  30497. exports.CanvasTexture = CanvasTexture;
  30498. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30499. exports.CineonToneMapping = CineonToneMapping;
  30500. exports.CircleBufferGeometry = CircleBufferGeometry;
  30501. exports.CircleGeometry = CircleGeometry;
  30502. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30503. exports.Clock = Clock;
  30504. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  30505. exports.Color = Color;
  30506. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30507. exports.CompressedTexture = CompressedTexture;
  30508. exports.CompressedTextureLoader = CompressedTextureLoader;
  30509. exports.ConeBufferGeometry = ConeBufferGeometry;
  30510. exports.ConeGeometry = ConeGeometry;
  30511. exports.CubeCamera = CubeCamera;
  30512. exports.CubeGeometry = BoxGeometry;
  30513. exports.CubeReflectionMapping = CubeReflectionMapping;
  30514. exports.CubeRefractionMapping = CubeRefractionMapping;
  30515. exports.CubeTexture = CubeTexture;
  30516. exports.CubeTextureLoader = CubeTextureLoader;
  30517. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30518. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30519. exports.CubicBezierCurve = CubicBezierCurve;
  30520. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30521. exports.CubicInterpolant = CubicInterpolant;
  30522. exports.CullFaceBack = CullFaceBack;
  30523. exports.CullFaceFront = CullFaceFront;
  30524. exports.CullFaceFrontBack = CullFaceFrontBack;
  30525. exports.CullFaceNone = CullFaceNone;
  30526. exports.Curve = Curve;
  30527. exports.CurvePath = CurvePath;
  30528. exports.CustomBlending = CustomBlending;
  30529. exports.CustomToneMapping = CustomToneMapping;
  30530. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  30531. exports.CylinderGeometry = CylinderGeometry;
  30532. exports.Cylindrical = Cylindrical;
  30533. exports.DataTexture = DataTexture;
  30534. exports.DataTexture2DArray = DataTexture2DArray;
  30535. exports.DataTexture3D = DataTexture3D;
  30536. exports.DataTextureLoader = DataTextureLoader;
  30537. exports.DataUtils = DataUtils;
  30538. exports.DecrementStencilOp = DecrementStencilOp;
  30539. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30540. exports.DefaultLoadingManager = DefaultLoadingManager;
  30541. exports.DepthFormat = DepthFormat;
  30542. exports.DepthStencilFormat = DepthStencilFormat;
  30543. exports.DepthTexture = DepthTexture;
  30544. exports.DirectionalLight = DirectionalLight;
  30545. exports.DirectionalLightHelper = DirectionalLightHelper;
  30546. exports.DiscreteInterpolant = DiscreteInterpolant;
  30547. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  30548. exports.DodecahedronGeometry = DodecahedronGeometry;
  30549. exports.DoubleSide = DoubleSide;
  30550. exports.DstAlphaFactor = DstAlphaFactor;
  30551. exports.DstColorFactor = DstColorFactor;
  30552. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30553. exports.DynamicCopyUsage = DynamicCopyUsage;
  30554. exports.DynamicDrawUsage = DynamicDrawUsage;
  30555. exports.DynamicReadUsage = DynamicReadUsage;
  30556. exports.EdgesGeometry = EdgesGeometry;
  30557. exports.EdgesHelper = EdgesHelper;
  30558. exports.EllipseCurve = EllipseCurve;
  30559. exports.EqualDepth = EqualDepth;
  30560. exports.EqualStencilFunc = EqualStencilFunc;
  30561. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30562. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30563. exports.Euler = Euler;
  30564. exports.EventDispatcher = EventDispatcher;
  30565. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  30566. exports.ExtrudeGeometry = ExtrudeGeometry;
  30567. exports.Face3 = Face3;
  30568. exports.Face4 = Face4;
  30569. exports.FaceColors = FaceColors;
  30570. exports.FileLoader = FileLoader;
  30571. exports.FlatShading = FlatShading;
  30572. exports.Float16BufferAttribute = Float16BufferAttribute;
  30573. exports.Float32Attribute = Float32Attribute;
  30574. exports.Float32BufferAttribute = Float32BufferAttribute;
  30575. exports.Float64Attribute = Float64Attribute;
  30576. exports.Float64BufferAttribute = Float64BufferAttribute;
  30577. exports.FloatType = FloatType;
  30578. exports.Fog = Fog;
  30579. exports.FogExp2 = FogExp2;
  30580. exports.Font = Font;
  30581. exports.FontLoader = FontLoader;
  30582. exports.FrontSide = FrontSide;
  30583. exports.Frustum = Frustum;
  30584. exports.GLBufferAttribute = GLBufferAttribute;
  30585. exports.GLSL1 = GLSL1;
  30586. exports.GLSL3 = GLSL3;
  30587. exports.GammaEncoding = GammaEncoding;
  30588. exports.Geometry = Geometry;
  30589. exports.GeometryUtils = GeometryUtils;
  30590. exports.GreaterDepth = GreaterDepth;
  30591. exports.GreaterEqualDepth = GreaterEqualDepth;
  30592. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30593. exports.GreaterStencilFunc = GreaterStencilFunc;
  30594. exports.GridHelper = GridHelper;
  30595. exports.Group = Group;
  30596. exports.HalfFloatType = HalfFloatType;
  30597. exports.HemisphereLight = HemisphereLight;
  30598. exports.HemisphereLightHelper = HemisphereLightHelper;
  30599. exports.HemisphereLightProbe = HemisphereLightProbe;
  30600. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  30601. exports.IcosahedronGeometry = IcosahedronGeometry;
  30602. exports.ImageBitmapLoader = ImageBitmapLoader;
  30603. exports.ImageLoader = ImageLoader;
  30604. exports.ImageUtils = ImageUtils;
  30605. exports.ImmediateRenderObject = ImmediateRenderObject;
  30606. exports.IncrementStencilOp = IncrementStencilOp;
  30607. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  30608. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  30609. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  30610. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  30611. exports.InstancedMesh = InstancedMesh;
  30612. exports.Int16Attribute = Int16Attribute;
  30613. exports.Int16BufferAttribute = Int16BufferAttribute;
  30614. exports.Int32Attribute = Int32Attribute;
  30615. exports.Int32BufferAttribute = Int32BufferAttribute;
  30616. exports.Int8Attribute = Int8Attribute;
  30617. exports.Int8BufferAttribute = Int8BufferAttribute;
  30618. exports.IntType = IntType;
  30619. exports.InterleavedBuffer = InterleavedBuffer;
  30620. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  30621. exports.Interpolant = Interpolant;
  30622. exports.InterpolateDiscrete = InterpolateDiscrete;
  30623. exports.InterpolateLinear = InterpolateLinear;
  30624. exports.InterpolateSmooth = InterpolateSmooth;
  30625. exports.InvertStencilOp = InvertStencilOp;
  30626. exports.JSONLoader = JSONLoader;
  30627. exports.KeepStencilOp = KeepStencilOp;
  30628. exports.KeyframeTrack = KeyframeTrack;
  30629. exports.LOD = LOD;
  30630. exports.LatheBufferGeometry = LatheBufferGeometry;
  30631. exports.LatheGeometry = LatheGeometry;
  30632. exports.Layers = Layers;
  30633. exports.LensFlare = LensFlare;
  30634. exports.LessDepth = LessDepth;
  30635. exports.LessEqualDepth = LessEqualDepth;
  30636. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  30637. exports.LessStencilFunc = LessStencilFunc;
  30638. exports.Light = Light;
  30639. exports.LightProbe = LightProbe;
  30640. exports.Line = Line;
  30641. exports.Line3 = Line3;
  30642. exports.LineBasicMaterial = LineBasicMaterial;
  30643. exports.LineCurve = LineCurve;
  30644. exports.LineCurve3 = LineCurve3;
  30645. exports.LineDashedMaterial = LineDashedMaterial;
  30646. exports.LineLoop = LineLoop;
  30647. exports.LinePieces = LinePieces;
  30648. exports.LineSegments = LineSegments;
  30649. exports.LineStrip = LineStrip;
  30650. exports.LinearEncoding = LinearEncoding;
  30651. exports.LinearFilter = LinearFilter;
  30652. exports.LinearInterpolant = LinearInterpolant;
  30653. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  30654. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  30655. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  30656. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  30657. exports.LinearToneMapping = LinearToneMapping;
  30658. exports.Loader = Loader;
  30659. exports.LoaderUtils = LoaderUtils;
  30660. exports.LoadingManager = LoadingManager;
  30661. exports.LogLuvEncoding = LogLuvEncoding;
  30662. exports.LoopOnce = LoopOnce;
  30663. exports.LoopPingPong = LoopPingPong;
  30664. exports.LoopRepeat = LoopRepeat;
  30665. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  30666. exports.LuminanceFormat = LuminanceFormat;
  30667. exports.MOUSE = MOUSE;
  30668. exports.Material = Material;
  30669. exports.MaterialLoader = MaterialLoader;
  30670. exports.Math = MathUtils;
  30671. exports.MathUtils = MathUtils;
  30672. exports.Matrix3 = Matrix3;
  30673. exports.Matrix4 = Matrix4;
  30674. exports.MaxEquation = MaxEquation;
  30675. exports.Mesh = Mesh;
  30676. exports.MeshBasicMaterial = MeshBasicMaterial;
  30677. exports.MeshDepthMaterial = MeshDepthMaterial;
  30678. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  30679. exports.MeshFaceMaterial = MeshFaceMaterial;
  30680. exports.MeshLambertMaterial = MeshLambertMaterial;
  30681. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  30682. exports.MeshNormalMaterial = MeshNormalMaterial;
  30683. exports.MeshPhongMaterial = MeshPhongMaterial;
  30684. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  30685. exports.MeshStandardMaterial = MeshStandardMaterial;
  30686. exports.MeshToonMaterial = MeshToonMaterial;
  30687. exports.MinEquation = MinEquation;
  30688. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  30689. exports.MixOperation = MixOperation;
  30690. exports.MultiMaterial = MultiMaterial;
  30691. exports.MultiplyBlending = MultiplyBlending;
  30692. exports.MultiplyOperation = MultiplyOperation;
  30693. exports.NearestFilter = NearestFilter;
  30694. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  30695. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  30696. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  30697. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  30698. exports.NeverDepth = NeverDepth;
  30699. exports.NeverStencilFunc = NeverStencilFunc;
  30700. exports.NoBlending = NoBlending;
  30701. exports.NoColors = NoColors;
  30702. exports.NoToneMapping = NoToneMapping;
  30703. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  30704. exports.NormalBlending = NormalBlending;
  30705. exports.NotEqualDepth = NotEqualDepth;
  30706. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  30707. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  30708. exports.Object3D = Object3D;
  30709. exports.ObjectLoader = ObjectLoader;
  30710. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  30711. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  30712. exports.OctahedronGeometry = OctahedronGeometry;
  30713. exports.OneFactor = OneFactor;
  30714. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  30715. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  30716. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  30717. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  30718. exports.OrthographicCamera = OrthographicCamera;
  30719. exports.PCFShadowMap = PCFShadowMap;
  30720. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  30721. exports.PMREMGenerator = PMREMGenerator;
  30722. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  30723. exports.ParametricGeometry = ParametricGeometry;
  30724. exports.Particle = Particle;
  30725. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  30726. exports.ParticleSystem = ParticleSystem;
  30727. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  30728. exports.Path = Path;
  30729. exports.PerspectiveCamera = PerspectiveCamera;
  30730. exports.Plane = Plane;
  30731. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  30732. exports.PlaneGeometry = PlaneGeometry;
  30733. exports.PlaneHelper = PlaneHelper;
  30734. exports.PointCloud = PointCloud;
  30735. exports.PointCloudMaterial = PointCloudMaterial;
  30736. exports.PointLight = PointLight;
  30737. exports.PointLightHelper = PointLightHelper;
  30738. exports.Points = Points;
  30739. exports.PointsMaterial = PointsMaterial;
  30740. exports.PolarGridHelper = PolarGridHelper;
  30741. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  30742. exports.PolyhedronGeometry = PolyhedronGeometry;
  30743. exports.PositionalAudio = PositionalAudio;
  30744. exports.PropertyBinding = PropertyBinding;
  30745. exports.PropertyMixer = PropertyMixer;
  30746. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  30747. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  30748. exports.Quaternion = Quaternion;
  30749. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  30750. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  30751. exports.REVISION = REVISION;
  30752. exports.RGBADepthPacking = RGBADepthPacking;
  30753. exports.RGBAFormat = RGBAFormat;
  30754. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  30755. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  30756. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  30757. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  30758. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  30759. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  30760. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  30761. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  30762. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  30763. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  30764. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  30765. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  30766. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  30767. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  30768. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  30769. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  30770. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  30771. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  30772. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  30773. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  30774. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  30775. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  30776. exports.RGBDEncoding = RGBDEncoding;
  30777. exports.RGBEEncoding = RGBEEncoding;
  30778. exports.RGBEFormat = RGBEFormat;
  30779. exports.RGBFormat = RGBFormat;
  30780. exports.RGBIntegerFormat = RGBIntegerFormat;
  30781. exports.RGBM16Encoding = RGBM16Encoding;
  30782. exports.RGBM7Encoding = RGBM7Encoding;
  30783. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  30784. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  30785. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  30786. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  30787. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  30788. exports.RGFormat = RGFormat;
  30789. exports.RGIntegerFormat = RGIntegerFormat;
  30790. exports.RawShaderMaterial = RawShaderMaterial;
  30791. exports.Ray = Ray;
  30792. exports.Raycaster = Raycaster;
  30793. exports.RectAreaLight = RectAreaLight;
  30794. exports.RedFormat = RedFormat;
  30795. exports.RedIntegerFormat = RedIntegerFormat;
  30796. exports.ReinhardToneMapping = ReinhardToneMapping;
  30797. exports.RepeatWrapping = RepeatWrapping;
  30798. exports.ReplaceStencilOp = ReplaceStencilOp;
  30799. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  30800. exports.RingBufferGeometry = RingBufferGeometry;
  30801. exports.RingGeometry = RingGeometry;
  30802. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  30803. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  30804. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  30805. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  30806. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  30807. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  30808. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  30809. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  30810. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  30811. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  30812. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  30813. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  30814. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  30815. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  30816. exports.Scene = Scene;
  30817. exports.SceneUtils = SceneUtils;
  30818. exports.ShaderChunk = ShaderChunk;
  30819. exports.ShaderLib = ShaderLib;
  30820. exports.ShaderMaterial = ShaderMaterial;
  30821. exports.ShadowMaterial = ShadowMaterial;
  30822. exports.Shape = Shape;
  30823. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  30824. exports.ShapeGeometry = ShapeGeometry;
  30825. exports.ShapePath = ShapePath;
  30826. exports.ShapeUtils = ShapeUtils;
  30827. exports.ShortType = ShortType;
  30828. exports.Skeleton = Skeleton;
  30829. exports.SkeletonHelper = SkeletonHelper;
  30830. exports.SkinnedMesh = SkinnedMesh;
  30831. exports.SmoothShading = SmoothShading;
  30832. exports.Sphere = Sphere;
  30833. exports.SphereBufferGeometry = SphereBufferGeometry;
  30834. exports.SphereGeometry = SphereGeometry;
  30835. exports.Spherical = Spherical;
  30836. exports.SphericalHarmonics3 = SphericalHarmonics3;
  30837. exports.Spline = Spline;
  30838. exports.SplineCurve = SplineCurve;
  30839. exports.SplineCurve3 = SplineCurve3;
  30840. exports.SpotLight = SpotLight;
  30841. exports.SpotLightHelper = SpotLightHelper;
  30842. exports.Sprite = Sprite;
  30843. exports.SpriteMaterial = SpriteMaterial;
  30844. exports.SrcAlphaFactor = SrcAlphaFactor;
  30845. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  30846. exports.SrcColorFactor = SrcColorFactor;
  30847. exports.StaticCopyUsage = StaticCopyUsage;
  30848. exports.StaticDrawUsage = StaticDrawUsage;
  30849. exports.StaticReadUsage = StaticReadUsage;
  30850. exports.StereoCamera = StereoCamera;
  30851. exports.StreamCopyUsage = StreamCopyUsage;
  30852. exports.StreamDrawUsage = StreamDrawUsage;
  30853. exports.StreamReadUsage = StreamReadUsage;
  30854. exports.StringKeyframeTrack = StringKeyframeTrack;
  30855. exports.SubtractEquation = SubtractEquation;
  30856. exports.SubtractiveBlending = SubtractiveBlending;
  30857. exports.TOUCH = TOUCH;
  30858. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  30859. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  30860. exports.TetrahedronGeometry = TetrahedronGeometry;
  30861. exports.TextBufferGeometry = TextBufferGeometry;
  30862. exports.TextGeometry = TextGeometry;
  30863. exports.Texture = Texture;
  30864. exports.TextureLoader = TextureLoader;
  30865. exports.TorusBufferGeometry = TorusBufferGeometry;
  30866. exports.TorusGeometry = TorusGeometry;
  30867. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  30868. exports.TorusKnotGeometry = TorusKnotGeometry;
  30869. exports.Triangle = Triangle;
  30870. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  30871. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  30872. exports.TrianglesDrawMode = TrianglesDrawMode;
  30873. exports.TubeBufferGeometry = TubeBufferGeometry;
  30874. exports.TubeGeometry = TubeGeometry;
  30875. exports.UVMapping = UVMapping;
  30876. exports.Uint16Attribute = Uint16Attribute;
  30877. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  30878. exports.Uint32Attribute = Uint32Attribute;
  30879. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  30880. exports.Uint8Attribute = Uint8Attribute;
  30881. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  30882. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  30883. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  30884. exports.Uniform = Uniform;
  30885. exports.UniformsLib = UniformsLib;
  30886. exports.UniformsUtils = UniformsUtils;
  30887. exports.UnsignedByteType = UnsignedByteType;
  30888. exports.UnsignedInt248Type = UnsignedInt248Type;
  30889. exports.UnsignedIntType = UnsignedIntType;
  30890. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  30891. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  30892. exports.UnsignedShort565Type = UnsignedShort565Type;
  30893. exports.UnsignedShortType = UnsignedShortType;
  30894. exports.VSMShadowMap = VSMShadowMap;
  30895. exports.Vector2 = Vector2;
  30896. exports.Vector3 = Vector3;
  30897. exports.Vector4 = Vector4;
  30898. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  30899. exports.Vertex = Vertex;
  30900. exports.VertexColors = VertexColors;
  30901. exports.VideoTexture = VideoTexture;
  30902. exports.WebGL1Renderer = WebGL1Renderer;
  30903. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  30904. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  30905. exports.WebGLRenderTarget = WebGLRenderTarget;
  30906. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  30907. exports.WebGLRenderer = WebGLRenderer;
  30908. exports.WebGLUtils = WebGLUtils;
  30909. exports.WireframeGeometry = WireframeGeometry;
  30910. exports.WireframeHelper = WireframeHelper;
  30911. exports.WrapAroundEnding = WrapAroundEnding;
  30912. exports.XHRLoader = XHRLoader;
  30913. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  30914. exports.ZeroFactor = ZeroFactor;
  30915. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  30916. exports.ZeroStencilOp = ZeroStencilOp;
  30917. exports.sRGBEncoding = sRGBEncoding;
  30918. Object.defineProperty(exports, '__esModule', { value: true });
  30919. })));
粤ICP备19079148号