three.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680
  1. // threejs.org/license
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.THREE = {}));
  6. }(this, (function (exports) { 'use strict';
  7. // Polyfills
  8. if (Number.EPSILON === undefined) {
  9. Number.EPSILON = Math.pow(2, -52);
  10. }
  11. if (Number.isInteger === undefined) {
  12. // Missing in IE
  13. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  14. Number.isInteger = function (value) {
  15. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  16. };
  17. } //
  18. if (Math.sign === undefined) {
  19. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  20. Math.sign = function (x) {
  21. return x < 0 ? -1 : x > 0 ? 1 : +x;
  22. };
  23. }
  24. if ('name' in Function.prototype === false) {
  25. // Missing in IE
  26. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  27. Object.defineProperty(Function.prototype, 'name', {
  28. get: function get() {
  29. return this.toString().match(/^\s*function\s*([^\(\s]*)/)[1];
  30. }
  31. });
  32. }
  33. if (Object.assign === undefined) {
  34. // Missing in IE
  35. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  36. Object.assign = function (target) {
  37. if (target === undefined || target === null) {
  38. throw new TypeError('Cannot convert undefined or null to object');
  39. }
  40. var output = Object(target);
  41. for (var index = 1; index < arguments.length; index++) {
  42. var source = arguments[index];
  43. if (source !== undefined && source !== null) {
  44. for (var nextKey in source) {
  45. if (Object.prototype.hasOwnProperty.call(source, nextKey)) {
  46. output[nextKey] = source[nextKey];
  47. }
  48. }
  49. }
  50. }
  51. return output;
  52. };
  53. }
  54. var REVISION = '125dev';
  55. var MOUSE = {
  56. LEFT: 0,
  57. MIDDLE: 1,
  58. RIGHT: 2,
  59. ROTATE: 0,
  60. DOLLY: 1,
  61. PAN: 2
  62. };
  63. var TOUCH = {
  64. ROTATE: 0,
  65. PAN: 1,
  66. DOLLY_PAN: 2,
  67. DOLLY_ROTATE: 3
  68. };
  69. var CullFaceNone = 0;
  70. var CullFaceBack = 1;
  71. var CullFaceFront = 2;
  72. var CullFaceFrontBack = 3;
  73. var BasicShadowMap = 0;
  74. var PCFShadowMap = 1;
  75. var PCFSoftShadowMap = 2;
  76. var VSMShadowMap = 3;
  77. var FrontSide = 0;
  78. var BackSide = 1;
  79. var DoubleSide = 2;
  80. var FlatShading = 1;
  81. var SmoothShading = 2;
  82. var NoBlending = 0;
  83. var NormalBlending = 1;
  84. var AdditiveBlending = 2;
  85. var SubtractiveBlending = 3;
  86. var MultiplyBlending = 4;
  87. var CustomBlending = 5;
  88. var AddEquation = 100;
  89. var SubtractEquation = 101;
  90. var ReverseSubtractEquation = 102;
  91. var MinEquation = 103;
  92. var MaxEquation = 104;
  93. var ZeroFactor = 200;
  94. var OneFactor = 201;
  95. var SrcColorFactor = 202;
  96. var OneMinusSrcColorFactor = 203;
  97. var SrcAlphaFactor = 204;
  98. var OneMinusSrcAlphaFactor = 205;
  99. var DstAlphaFactor = 206;
  100. var OneMinusDstAlphaFactor = 207;
  101. var DstColorFactor = 208;
  102. var OneMinusDstColorFactor = 209;
  103. var SrcAlphaSaturateFactor = 210;
  104. var NeverDepth = 0;
  105. var AlwaysDepth = 1;
  106. var LessDepth = 2;
  107. var LessEqualDepth = 3;
  108. var EqualDepth = 4;
  109. var GreaterEqualDepth = 5;
  110. var GreaterDepth = 6;
  111. var NotEqualDepth = 7;
  112. var MultiplyOperation = 0;
  113. var MixOperation = 1;
  114. var AddOperation = 2;
  115. var NoToneMapping = 0;
  116. var LinearToneMapping = 1;
  117. var ReinhardToneMapping = 2;
  118. var CineonToneMapping = 3;
  119. var ACESFilmicToneMapping = 4;
  120. var CustomToneMapping = 5;
  121. var UVMapping = 300;
  122. var CubeReflectionMapping = 301;
  123. var CubeRefractionMapping = 302;
  124. var EquirectangularReflectionMapping = 303;
  125. var EquirectangularRefractionMapping = 304;
  126. var CubeUVReflectionMapping = 306;
  127. var CubeUVRefractionMapping = 307;
  128. var RepeatWrapping = 1000;
  129. var ClampToEdgeWrapping = 1001;
  130. var MirroredRepeatWrapping = 1002;
  131. var NearestFilter = 1003;
  132. var NearestMipmapNearestFilter = 1004;
  133. var NearestMipMapNearestFilter = 1004;
  134. var NearestMipmapLinearFilter = 1005;
  135. var NearestMipMapLinearFilter = 1005;
  136. var LinearFilter = 1006;
  137. var LinearMipmapNearestFilter = 1007;
  138. var LinearMipMapNearestFilter = 1007;
  139. var LinearMipmapLinearFilter = 1008;
  140. var LinearMipMapLinearFilter = 1008;
  141. var UnsignedByteType = 1009;
  142. var ByteType = 1010;
  143. var ShortType = 1011;
  144. var UnsignedShortType = 1012;
  145. var IntType = 1013;
  146. var UnsignedIntType = 1014;
  147. var FloatType = 1015;
  148. var HalfFloatType = 1016;
  149. var UnsignedShort4444Type = 1017;
  150. var UnsignedShort5551Type = 1018;
  151. var UnsignedShort565Type = 1019;
  152. var UnsignedInt248Type = 1020;
  153. var AlphaFormat = 1021;
  154. var RGBFormat = 1022;
  155. var RGBAFormat = 1023;
  156. var LuminanceFormat = 1024;
  157. var LuminanceAlphaFormat = 1025;
  158. var RGBEFormat = RGBAFormat;
  159. var DepthFormat = 1026;
  160. var DepthStencilFormat = 1027;
  161. var RedFormat = 1028;
  162. var RedIntegerFormat = 1029;
  163. var RGFormat = 1030;
  164. var RGIntegerFormat = 1031;
  165. var RGBIntegerFormat = 1032;
  166. var RGBAIntegerFormat = 1033;
  167. var RGB_S3TC_DXT1_Format = 33776;
  168. var RGBA_S3TC_DXT1_Format = 33777;
  169. var RGBA_S3TC_DXT3_Format = 33778;
  170. var RGBA_S3TC_DXT5_Format = 33779;
  171. var RGB_PVRTC_4BPPV1_Format = 35840;
  172. var RGB_PVRTC_2BPPV1_Format = 35841;
  173. var RGBA_PVRTC_4BPPV1_Format = 35842;
  174. var RGBA_PVRTC_2BPPV1_Format = 35843;
  175. var RGB_ETC1_Format = 36196;
  176. var RGB_ETC2_Format = 37492;
  177. var RGBA_ETC2_EAC_Format = 37496;
  178. var RGBA_ASTC_4x4_Format = 37808;
  179. var RGBA_ASTC_5x4_Format = 37809;
  180. var RGBA_ASTC_5x5_Format = 37810;
  181. var RGBA_ASTC_6x5_Format = 37811;
  182. var RGBA_ASTC_6x6_Format = 37812;
  183. var RGBA_ASTC_8x5_Format = 37813;
  184. var RGBA_ASTC_8x6_Format = 37814;
  185. var RGBA_ASTC_8x8_Format = 37815;
  186. var RGBA_ASTC_10x5_Format = 37816;
  187. var RGBA_ASTC_10x6_Format = 37817;
  188. var RGBA_ASTC_10x8_Format = 37818;
  189. var RGBA_ASTC_10x10_Format = 37819;
  190. var RGBA_ASTC_12x10_Format = 37820;
  191. var RGBA_ASTC_12x12_Format = 37821;
  192. var RGBA_BPTC_Format = 36492;
  193. var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  194. var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  195. var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  196. var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  197. var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  198. var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  199. var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  200. var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  201. var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  202. var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  203. var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  204. var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  205. var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  206. var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  207. var LoopOnce = 2200;
  208. var LoopRepeat = 2201;
  209. var LoopPingPong = 2202;
  210. var InterpolateDiscrete = 2300;
  211. var InterpolateLinear = 2301;
  212. var InterpolateSmooth = 2302;
  213. var ZeroCurvatureEnding = 2400;
  214. var ZeroSlopeEnding = 2401;
  215. var WrapAroundEnding = 2402;
  216. var NormalAnimationBlendMode = 2500;
  217. var AdditiveAnimationBlendMode = 2501;
  218. var TrianglesDrawMode = 0;
  219. var TriangleStripDrawMode = 1;
  220. var TriangleFanDrawMode = 2;
  221. var LinearEncoding = 3000;
  222. var sRGBEncoding = 3001;
  223. var GammaEncoding = 3007;
  224. var RGBEEncoding = 3002;
  225. var LogLuvEncoding = 3003;
  226. var RGBM7Encoding = 3004;
  227. var RGBM16Encoding = 3005;
  228. var RGBDEncoding = 3006;
  229. var BasicDepthPacking = 3200;
  230. var RGBADepthPacking = 3201;
  231. var TangentSpaceNormalMap = 0;
  232. var ObjectSpaceNormalMap = 1;
  233. var ZeroStencilOp = 0;
  234. var KeepStencilOp = 7680;
  235. var ReplaceStencilOp = 7681;
  236. var IncrementStencilOp = 7682;
  237. var DecrementStencilOp = 7683;
  238. var IncrementWrapStencilOp = 34055;
  239. var DecrementWrapStencilOp = 34056;
  240. var InvertStencilOp = 5386;
  241. var NeverStencilFunc = 512;
  242. var LessStencilFunc = 513;
  243. var EqualStencilFunc = 514;
  244. var LessEqualStencilFunc = 515;
  245. var GreaterStencilFunc = 516;
  246. var NotEqualStencilFunc = 517;
  247. var GreaterEqualStencilFunc = 518;
  248. var AlwaysStencilFunc = 519;
  249. var StaticDrawUsage = 35044;
  250. var DynamicDrawUsage = 35048;
  251. var StreamDrawUsage = 35040;
  252. var StaticReadUsage = 35045;
  253. var DynamicReadUsage = 35049;
  254. var StreamReadUsage = 35041;
  255. var StaticCopyUsage = 35046;
  256. var DynamicCopyUsage = 35050;
  257. var StreamCopyUsage = 35042;
  258. var GLSL1 = '100';
  259. var GLSL3 = '300 es';
  260. /**
  261. * https://github.com/mrdoob/eventdispatcher.js/
  262. */
  263. function EventDispatcher() {}
  264. Object.assign(EventDispatcher.prototype, {
  265. addEventListener: function addEventListener(type, listener) {
  266. if (this._listeners === undefined) this._listeners = {};
  267. var listeners = this._listeners;
  268. if (listeners[type] === undefined) {
  269. listeners[type] = [];
  270. }
  271. if (listeners[type].indexOf(listener) === -1) {
  272. listeners[type].push(listener);
  273. }
  274. },
  275. hasEventListener: function hasEventListener(type, listener) {
  276. if (this._listeners === undefined) return false;
  277. var listeners = this._listeners;
  278. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
  279. },
  280. removeEventListener: function removeEventListener(type, listener) {
  281. if (this._listeners === undefined) return;
  282. var listeners = this._listeners;
  283. var listenerArray = listeners[type];
  284. if (listenerArray !== undefined) {
  285. var index = listenerArray.indexOf(listener);
  286. if (index !== -1) {
  287. listenerArray.splice(index, 1);
  288. }
  289. }
  290. },
  291. dispatchEvent: function dispatchEvent(event) {
  292. if (this._listeners === undefined) return;
  293. var listeners = this._listeners;
  294. var listenerArray = listeners[event.type];
  295. if (listenerArray !== undefined) {
  296. event.target = this; // Make a copy, in case listeners are removed while iterating.
  297. var array = listenerArray.slice(0);
  298. for (var i = 0, l = array.length; i < l; i++) {
  299. array[i].call(this, event);
  300. }
  301. }
  302. }
  303. });
  304. var _lut = [];
  305. for (var i = 0; i < 256; i++) {
  306. _lut[i] = (i < 16 ? '0' : '') + i.toString(16);
  307. }
  308. var _seed = 1234567;
  309. var MathUtils = {
  310. DEG2RAD: Math.PI / 180,
  311. RAD2DEG: 180 / Math.PI,
  312. generateUUID: function generateUUID() {
  313. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  314. var d0 = Math.random() * 0xffffffff | 0;
  315. var d1 = Math.random() * 0xffffffff | 0;
  316. var d2 = Math.random() * 0xffffffff | 0;
  317. var d3 = Math.random() * 0xffffffff | 0;
  318. var uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' + _lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' + _lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] + _lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff]; // .toUpperCase() here flattens concatenated strings to save heap memory space.
  319. return uuid.toUpperCase();
  320. },
  321. clamp: function clamp(value, min, max) {
  322. return Math.max(min, Math.min(max, value));
  323. },
  324. // compute euclidian modulo of m % n
  325. // https://en.wikipedia.org/wiki/Modulo_operation
  326. euclideanModulo: function euclideanModulo(n, m) {
  327. return (n % m + m) % m;
  328. },
  329. // Linear mapping from range <a1, a2> to range <b1, b2>
  330. mapLinear: function mapLinear(x, a1, a2, b1, b2) {
  331. return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
  332. },
  333. // https://en.wikipedia.org/wiki/Linear_interpolation
  334. lerp: function lerp(x, y, t) {
  335. return (1 - t) * x + t * y;
  336. },
  337. // http://en.wikipedia.org/wiki/Smoothstep
  338. smoothstep: function smoothstep(x, min, max) {
  339. if (x <= min) return 0;
  340. if (x >= max) return 1;
  341. x = (x - min) / (max - min);
  342. return x * x * (3 - 2 * x);
  343. },
  344. smootherstep: function smootherstep(x, min, max) {
  345. if (x <= min) return 0;
  346. if (x >= max) return 1;
  347. x = (x - min) / (max - min);
  348. return x * x * x * (x * (x * 6 - 15) + 10);
  349. },
  350. // Random integer from <low, high> interval
  351. randInt: function randInt(low, high) {
  352. return low + Math.floor(Math.random() * (high - low + 1));
  353. },
  354. // Random float from <low, high> interval
  355. randFloat: function randFloat(low, high) {
  356. return low + Math.random() * (high - low);
  357. },
  358. // Random float from <-range/2, range/2> interval
  359. randFloatSpread: function randFloatSpread(range) {
  360. return range * (0.5 - Math.random());
  361. },
  362. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  363. seededRandom: function seededRandom(s) {
  364. if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
  365. _seed = _seed * 16807 % 2147483647;
  366. return (_seed - 1) / 2147483646;
  367. },
  368. degToRad: function degToRad(degrees) {
  369. return degrees * MathUtils.DEG2RAD;
  370. },
  371. radToDeg: function radToDeg(radians) {
  372. return radians * MathUtils.RAD2DEG;
  373. },
  374. isPowerOfTwo: function isPowerOfTwo(value) {
  375. return (value & value - 1) === 0 && value !== 0;
  376. },
  377. ceilPowerOfTwo: function ceilPowerOfTwo(value) {
  378. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  379. },
  380. floorPowerOfTwo: function floorPowerOfTwo(value) {
  381. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  382. },
  383. setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
  384. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  385. // rotations are applied to the axes in the order specified by 'order'
  386. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  387. // angles are in radians
  388. var cos = Math.cos;
  389. var sin = Math.sin;
  390. var c2 = cos(b / 2);
  391. var s2 = sin(b / 2);
  392. var c13 = cos((a + c) / 2);
  393. var s13 = sin((a + c) / 2);
  394. var c1_3 = cos((a - c) / 2);
  395. var s1_3 = sin((a - c) / 2);
  396. var c3_1 = cos((c - a) / 2);
  397. var s3_1 = sin((c - a) / 2);
  398. switch (order) {
  399. case 'XYX':
  400. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  401. break;
  402. case 'YZY':
  403. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  404. break;
  405. case 'ZXZ':
  406. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  407. break;
  408. case 'XZX':
  409. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  410. break;
  411. case 'YXY':
  412. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  413. break;
  414. case 'ZYZ':
  415. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  416. break;
  417. default:
  418. console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
  419. }
  420. }
  421. };
  422. function _defineProperties(target, props) {
  423. for (var i = 0; i < props.length; i++) {
  424. var descriptor = props[i];
  425. descriptor.enumerable = descriptor.enumerable || false;
  426. descriptor.configurable = true;
  427. if ("value" in descriptor) descriptor.writable = true;
  428. Object.defineProperty(target, descriptor.key, descriptor);
  429. }
  430. }
  431. function _createClass(Constructor, protoProps, staticProps) {
  432. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  433. if (staticProps) _defineProperties(Constructor, staticProps);
  434. return Constructor;
  435. }
  436. function _inheritsLoose(subClass, superClass) {
  437. subClass.prototype = Object.create(superClass.prototype);
  438. subClass.prototype.constructor = subClass;
  439. subClass.__proto__ = superClass;
  440. }
  441. function _assertThisInitialized(self) {
  442. if (self === void 0) {
  443. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  444. }
  445. return self;
  446. }
  447. var Vector2 = /*#__PURE__*/function () {
  448. function Vector2(x, y) {
  449. if (x === void 0) {
  450. x = 0;
  451. }
  452. if (y === void 0) {
  453. y = 0;
  454. }
  455. Object.defineProperty(this, 'isVector2', {
  456. value: true
  457. });
  458. this.x = x;
  459. this.y = y;
  460. }
  461. var _proto = Vector2.prototype;
  462. _proto.set = function set(x, y) {
  463. this.x = x;
  464. this.y = y;
  465. return this;
  466. };
  467. _proto.setScalar = function setScalar(scalar) {
  468. this.x = scalar;
  469. this.y = scalar;
  470. return this;
  471. };
  472. _proto.setX = function setX(x) {
  473. this.x = x;
  474. return this;
  475. };
  476. _proto.setY = function setY(y) {
  477. this.y = y;
  478. return this;
  479. };
  480. _proto.setComponent = function setComponent(index, value) {
  481. switch (index) {
  482. case 0:
  483. this.x = value;
  484. break;
  485. case 1:
  486. this.y = value;
  487. break;
  488. default:
  489. throw new Error('index is out of range: ' + index);
  490. }
  491. return this;
  492. };
  493. _proto.getComponent = function getComponent(index) {
  494. switch (index) {
  495. case 0:
  496. return this.x;
  497. case 1:
  498. return this.y;
  499. default:
  500. throw new Error('index is out of range: ' + index);
  501. }
  502. };
  503. _proto.clone = function clone() {
  504. return new this.constructor(this.x, this.y);
  505. };
  506. _proto.copy = function copy(v) {
  507. this.x = v.x;
  508. this.y = v.y;
  509. return this;
  510. };
  511. _proto.add = function add(v, w) {
  512. if (w !== undefined) {
  513. console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  514. return this.addVectors(v, w);
  515. }
  516. this.x += v.x;
  517. this.y += v.y;
  518. return this;
  519. };
  520. _proto.addScalar = function addScalar(s) {
  521. this.x += s;
  522. this.y += s;
  523. return this;
  524. };
  525. _proto.addVectors = function addVectors(a, b) {
  526. this.x = a.x + b.x;
  527. this.y = a.y + b.y;
  528. return this;
  529. };
  530. _proto.addScaledVector = function addScaledVector(v, s) {
  531. this.x += v.x * s;
  532. this.y += v.y * s;
  533. return this;
  534. };
  535. _proto.sub = function sub(v, w) {
  536. if (w !== undefined) {
  537. console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  538. return this.subVectors(v, w);
  539. }
  540. this.x -= v.x;
  541. this.y -= v.y;
  542. return this;
  543. };
  544. _proto.subScalar = function subScalar(s) {
  545. this.x -= s;
  546. this.y -= s;
  547. return this;
  548. };
  549. _proto.subVectors = function subVectors(a, b) {
  550. this.x = a.x - b.x;
  551. this.y = a.y - b.y;
  552. return this;
  553. };
  554. _proto.multiply = function multiply(v) {
  555. this.x *= v.x;
  556. this.y *= v.y;
  557. return this;
  558. };
  559. _proto.multiplyScalar = function multiplyScalar(scalar) {
  560. this.x *= scalar;
  561. this.y *= scalar;
  562. return this;
  563. };
  564. _proto.divide = function divide(v) {
  565. this.x /= v.x;
  566. this.y /= v.y;
  567. return this;
  568. };
  569. _proto.divideScalar = function divideScalar(scalar) {
  570. return this.multiplyScalar(1 / scalar);
  571. };
  572. _proto.applyMatrix3 = function applyMatrix3(m) {
  573. var x = this.x,
  574. y = this.y;
  575. var e = m.elements;
  576. this.x = e[0] * x + e[3] * y + e[6];
  577. this.y = e[1] * x + e[4] * y + e[7];
  578. return this;
  579. };
  580. _proto.min = function min(v) {
  581. this.x = Math.min(this.x, v.x);
  582. this.y = Math.min(this.y, v.y);
  583. return this;
  584. };
  585. _proto.max = function max(v) {
  586. this.x = Math.max(this.x, v.x);
  587. this.y = Math.max(this.y, v.y);
  588. return this;
  589. };
  590. _proto.clamp = function clamp(min, max) {
  591. // assumes min < max, componentwise
  592. this.x = Math.max(min.x, Math.min(max.x, this.x));
  593. this.y = Math.max(min.y, Math.min(max.y, this.y));
  594. return this;
  595. };
  596. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  597. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  598. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  599. return this;
  600. };
  601. _proto.clampLength = function clampLength(min, max) {
  602. var length = this.length();
  603. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  604. };
  605. _proto.floor = function floor() {
  606. this.x = Math.floor(this.x);
  607. this.y = Math.floor(this.y);
  608. return this;
  609. };
  610. _proto.ceil = function ceil() {
  611. this.x = Math.ceil(this.x);
  612. this.y = Math.ceil(this.y);
  613. return this;
  614. };
  615. _proto.round = function round() {
  616. this.x = Math.round(this.x);
  617. this.y = Math.round(this.y);
  618. return this;
  619. };
  620. _proto.roundToZero = function roundToZero() {
  621. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  622. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  623. return this;
  624. };
  625. _proto.negate = function negate() {
  626. this.x = -this.x;
  627. this.y = -this.y;
  628. return this;
  629. };
  630. _proto.dot = function dot(v) {
  631. return this.x * v.x + this.y * v.y;
  632. };
  633. _proto.cross = function cross(v) {
  634. return this.x * v.y - this.y * v.x;
  635. };
  636. _proto.lengthSq = function lengthSq() {
  637. return this.x * this.x + this.y * this.y;
  638. };
  639. _proto.length = function length() {
  640. return Math.sqrt(this.x * this.x + this.y * this.y);
  641. };
  642. _proto.manhattanLength = function manhattanLength() {
  643. return Math.abs(this.x) + Math.abs(this.y);
  644. };
  645. _proto.normalize = function normalize() {
  646. return this.divideScalar(this.length() || 1);
  647. };
  648. _proto.angle = function angle() {
  649. // computes the angle in radians with respect to the positive x-axis
  650. var angle = Math.atan2(-this.y, -this.x) + Math.PI;
  651. return angle;
  652. };
  653. _proto.distanceTo = function distanceTo(v) {
  654. return Math.sqrt(this.distanceToSquared(v));
  655. };
  656. _proto.distanceToSquared = function distanceToSquared(v) {
  657. var dx = this.x - v.x,
  658. dy = this.y - v.y;
  659. return dx * dx + dy * dy;
  660. };
  661. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  662. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
  663. };
  664. _proto.setLength = function setLength(length) {
  665. return this.normalize().multiplyScalar(length);
  666. };
  667. _proto.lerp = function lerp(v, alpha) {
  668. this.x += (v.x - this.x) * alpha;
  669. this.y += (v.y - this.y) * alpha;
  670. return this;
  671. };
  672. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  673. this.x = v1.x + (v2.x - v1.x) * alpha;
  674. this.y = v1.y + (v2.y - v1.y) * alpha;
  675. return this;
  676. };
  677. _proto.equals = function equals(v) {
  678. return v.x === this.x && v.y === this.y;
  679. };
  680. _proto.fromArray = function fromArray(array, offset) {
  681. if (offset === void 0) {
  682. offset = 0;
  683. }
  684. this.x = array[offset];
  685. this.y = array[offset + 1];
  686. return this;
  687. };
  688. _proto.toArray = function toArray(array, offset) {
  689. if (array === void 0) {
  690. array = [];
  691. }
  692. if (offset === void 0) {
  693. offset = 0;
  694. }
  695. array[offset] = this.x;
  696. array[offset + 1] = this.y;
  697. return array;
  698. };
  699. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  700. if (offset !== undefined) {
  701. console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
  702. }
  703. this.x = attribute.getX(index);
  704. this.y = attribute.getY(index);
  705. return this;
  706. };
  707. _proto.rotateAround = function rotateAround(center, angle) {
  708. var c = Math.cos(angle),
  709. s = Math.sin(angle);
  710. var x = this.x - center.x;
  711. var y = this.y - center.y;
  712. this.x = x * c - y * s + center.x;
  713. this.y = x * s + y * c + center.y;
  714. return this;
  715. };
  716. _proto.random = function random() {
  717. this.x = Math.random();
  718. this.y = Math.random();
  719. return this;
  720. };
  721. _createClass(Vector2, [{
  722. key: "width",
  723. get: function get() {
  724. return this.x;
  725. },
  726. set: function set(value) {
  727. this.x = value;
  728. }
  729. }, {
  730. key: "height",
  731. get: function get() {
  732. return this.y;
  733. },
  734. set: function set(value) {
  735. this.y = value;
  736. }
  737. }]);
  738. return Vector2;
  739. }();
  740. var Matrix3 = /*#__PURE__*/function () {
  741. function Matrix3() {
  742. Object.defineProperty(this, 'isMatrix3', {
  743. value: true
  744. });
  745. this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  746. if (arguments.length > 0) {
  747. console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
  748. }
  749. }
  750. var _proto = Matrix3.prototype;
  751. _proto.set = function set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
  752. var te = this.elements;
  753. te[0] = n11;
  754. te[1] = n21;
  755. te[2] = n31;
  756. te[3] = n12;
  757. te[4] = n22;
  758. te[5] = n32;
  759. te[6] = n13;
  760. te[7] = n23;
  761. te[8] = n33;
  762. return this;
  763. };
  764. _proto.identity = function identity() {
  765. this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
  766. return this;
  767. };
  768. _proto.clone = function clone() {
  769. return new this.constructor().fromArray(this.elements);
  770. };
  771. _proto.copy = function copy(m) {
  772. var te = this.elements;
  773. var me = m.elements;
  774. te[0] = me[0];
  775. te[1] = me[1];
  776. te[2] = me[2];
  777. te[3] = me[3];
  778. te[4] = me[4];
  779. te[5] = me[5];
  780. te[6] = me[6];
  781. te[7] = me[7];
  782. te[8] = me[8];
  783. return this;
  784. };
  785. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  786. xAxis.setFromMatrix3Column(this, 0);
  787. yAxis.setFromMatrix3Column(this, 1);
  788. zAxis.setFromMatrix3Column(this, 2);
  789. return this;
  790. };
  791. _proto.setFromMatrix4 = function setFromMatrix4(m) {
  792. var me = m.elements;
  793. this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
  794. return this;
  795. };
  796. _proto.multiply = function multiply(m) {
  797. return this.multiplyMatrices(this, m);
  798. };
  799. _proto.premultiply = function premultiply(m) {
  800. return this.multiplyMatrices(m, this);
  801. };
  802. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  803. var ae = a.elements;
  804. var be = b.elements;
  805. var te = this.elements;
  806. var a11 = ae[0],
  807. a12 = ae[3],
  808. a13 = ae[6];
  809. var a21 = ae[1],
  810. a22 = ae[4],
  811. a23 = ae[7];
  812. var a31 = ae[2],
  813. a32 = ae[5],
  814. a33 = ae[8];
  815. var b11 = be[0],
  816. b12 = be[3],
  817. b13 = be[6];
  818. var b21 = be[1],
  819. b22 = be[4],
  820. b23 = be[7];
  821. var b31 = be[2],
  822. b32 = be[5],
  823. b33 = be[8];
  824. te[0] = a11 * b11 + a12 * b21 + a13 * b31;
  825. te[3] = a11 * b12 + a12 * b22 + a13 * b32;
  826. te[6] = a11 * b13 + a12 * b23 + a13 * b33;
  827. te[1] = a21 * b11 + a22 * b21 + a23 * b31;
  828. te[4] = a21 * b12 + a22 * b22 + a23 * b32;
  829. te[7] = a21 * b13 + a22 * b23 + a23 * b33;
  830. te[2] = a31 * b11 + a32 * b21 + a33 * b31;
  831. te[5] = a31 * b12 + a32 * b22 + a33 * b32;
  832. te[8] = a31 * b13 + a32 * b23 + a33 * b33;
  833. return this;
  834. };
  835. _proto.multiplyScalar = function multiplyScalar(s) {
  836. var te = this.elements;
  837. te[0] *= s;
  838. te[3] *= s;
  839. te[6] *= s;
  840. te[1] *= s;
  841. te[4] *= s;
  842. te[7] *= s;
  843. te[2] *= s;
  844. te[5] *= s;
  845. te[8] *= s;
  846. return this;
  847. };
  848. _proto.determinant = function determinant() {
  849. var te = this.elements;
  850. var a = te[0],
  851. b = te[1],
  852. c = te[2],
  853. d = te[3],
  854. e = te[4],
  855. f = te[5],
  856. g = te[6],
  857. h = te[7],
  858. i = te[8];
  859. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  860. };
  861. _proto.invert = function invert() {
  862. var te = this.elements,
  863. n11 = te[0],
  864. n21 = te[1],
  865. n31 = te[2],
  866. n12 = te[3],
  867. n22 = te[4],
  868. n32 = te[5],
  869. n13 = te[6],
  870. n23 = te[7],
  871. n33 = te[8],
  872. t11 = n33 * n22 - n32 * n23,
  873. t12 = n32 * n13 - n33 * n12,
  874. t13 = n23 * n12 - n22 * n13,
  875. det = n11 * t11 + n21 * t12 + n31 * t13;
  876. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  877. var detInv = 1 / det;
  878. te[0] = t11 * detInv;
  879. te[1] = (n31 * n23 - n33 * n21) * detInv;
  880. te[2] = (n32 * n21 - n31 * n22) * detInv;
  881. te[3] = t12 * detInv;
  882. te[4] = (n33 * n11 - n31 * n13) * detInv;
  883. te[5] = (n31 * n12 - n32 * n11) * detInv;
  884. te[6] = t13 * detInv;
  885. te[7] = (n21 * n13 - n23 * n11) * detInv;
  886. te[8] = (n22 * n11 - n21 * n12) * detInv;
  887. return this;
  888. };
  889. _proto.transpose = function transpose() {
  890. var tmp;
  891. var m = this.elements;
  892. tmp = m[1];
  893. m[1] = m[3];
  894. m[3] = tmp;
  895. tmp = m[2];
  896. m[2] = m[6];
  897. m[6] = tmp;
  898. tmp = m[5];
  899. m[5] = m[7];
  900. m[7] = tmp;
  901. return this;
  902. };
  903. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  904. return this.setFromMatrix4(matrix4).copy(this).invert().transpose();
  905. };
  906. _proto.transposeIntoArray = function transposeIntoArray(r) {
  907. var m = this.elements;
  908. r[0] = m[0];
  909. r[1] = m[3];
  910. r[2] = m[6];
  911. r[3] = m[1];
  912. r[4] = m[4];
  913. r[5] = m[7];
  914. r[6] = m[2];
  915. r[7] = m[5];
  916. r[8] = m[8];
  917. return this;
  918. };
  919. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  920. var c = Math.cos(rotation);
  921. var s = Math.sin(rotation);
  922. this.set(sx * c, sx * s, -sx * (c * cx + s * cy) + cx + tx, -sy * s, sy * c, -sy * (-s * cx + c * cy) + cy + ty, 0, 0, 1);
  923. return this;
  924. };
  925. _proto.scale = function scale(sx, sy) {
  926. var te = this.elements;
  927. te[0] *= sx;
  928. te[3] *= sx;
  929. te[6] *= sx;
  930. te[1] *= sy;
  931. te[4] *= sy;
  932. te[7] *= sy;
  933. return this;
  934. };
  935. _proto.rotate = function rotate(theta) {
  936. var c = Math.cos(theta);
  937. var s = Math.sin(theta);
  938. var te = this.elements;
  939. var a11 = te[0],
  940. a12 = te[3],
  941. a13 = te[6];
  942. var a21 = te[1],
  943. a22 = te[4],
  944. a23 = te[7];
  945. te[0] = c * a11 + s * a21;
  946. te[3] = c * a12 + s * a22;
  947. te[6] = c * a13 + s * a23;
  948. te[1] = -s * a11 + c * a21;
  949. te[4] = -s * a12 + c * a22;
  950. te[7] = -s * a13 + c * a23;
  951. return this;
  952. };
  953. _proto.translate = function translate(tx, ty) {
  954. var te = this.elements;
  955. te[0] += tx * te[2];
  956. te[3] += tx * te[5];
  957. te[6] += tx * te[8];
  958. te[1] += ty * te[2];
  959. te[4] += ty * te[5];
  960. te[7] += ty * te[8];
  961. return this;
  962. };
  963. _proto.equals = function equals(matrix) {
  964. var te = this.elements;
  965. var me = matrix.elements;
  966. for (var i = 0; i < 9; i++) {
  967. if (te[i] !== me[i]) return false;
  968. }
  969. return true;
  970. };
  971. _proto.fromArray = function fromArray(array, offset) {
  972. if (offset === void 0) {
  973. offset = 0;
  974. }
  975. for (var i = 0; i < 9; i++) {
  976. this.elements[i] = array[i + offset];
  977. }
  978. return this;
  979. };
  980. _proto.toArray = function toArray(array, offset) {
  981. if (array === void 0) {
  982. array = [];
  983. }
  984. if (offset === void 0) {
  985. offset = 0;
  986. }
  987. var te = this.elements;
  988. array[offset] = te[0];
  989. array[offset + 1] = te[1];
  990. array[offset + 2] = te[2];
  991. array[offset + 3] = te[3];
  992. array[offset + 4] = te[4];
  993. array[offset + 5] = te[5];
  994. array[offset + 6] = te[6];
  995. array[offset + 7] = te[7];
  996. array[offset + 8] = te[8];
  997. return array;
  998. };
  999. return Matrix3;
  1000. }();
  1001. var _canvas;
  1002. var ImageUtils = {
  1003. getDataURL: function getDataURL(image) {
  1004. if (/^data:/i.test(image.src)) {
  1005. return image.src;
  1006. }
  1007. if (typeof HTMLCanvasElement == 'undefined') {
  1008. return image.src;
  1009. }
  1010. var canvas;
  1011. if (image instanceof HTMLCanvasElement) {
  1012. canvas = image;
  1013. } else {
  1014. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1015. _canvas.width = image.width;
  1016. _canvas.height = image.height;
  1017. var context = _canvas.getContext('2d');
  1018. if (image instanceof ImageData) {
  1019. context.putImageData(image, 0, 0);
  1020. } else {
  1021. context.drawImage(image, 0, 0, image.width, image.height);
  1022. }
  1023. canvas = _canvas;
  1024. }
  1025. if (canvas.width > 2048 || canvas.height > 2048) {
  1026. return canvas.toDataURL('image/jpeg', 0.6);
  1027. } else {
  1028. return canvas.toDataURL('image/png');
  1029. }
  1030. }
  1031. };
  1032. var textureId = 0;
  1033. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1034. if (image === void 0) {
  1035. image = Texture.DEFAULT_IMAGE;
  1036. }
  1037. if (mapping === void 0) {
  1038. mapping = Texture.DEFAULT_MAPPING;
  1039. }
  1040. if (wrapS === void 0) {
  1041. wrapS = ClampToEdgeWrapping;
  1042. }
  1043. if (wrapT === void 0) {
  1044. wrapT = ClampToEdgeWrapping;
  1045. }
  1046. if (magFilter === void 0) {
  1047. magFilter = LinearFilter;
  1048. }
  1049. if (minFilter === void 0) {
  1050. minFilter = LinearMipmapLinearFilter;
  1051. }
  1052. if (format === void 0) {
  1053. format = RGBAFormat;
  1054. }
  1055. if (type === void 0) {
  1056. type = UnsignedByteType;
  1057. }
  1058. if (anisotropy === void 0) {
  1059. anisotropy = 1;
  1060. }
  1061. if (encoding === void 0) {
  1062. encoding = LinearEncoding;
  1063. }
  1064. Object.defineProperty(this, 'id', {
  1065. value: textureId++
  1066. });
  1067. this.uuid = MathUtils.generateUUID();
  1068. this.name = '';
  1069. this.image = image;
  1070. this.mipmaps = [];
  1071. this.mapping = mapping;
  1072. this.wrapS = wrapS;
  1073. this.wrapT = wrapT;
  1074. this.magFilter = magFilter;
  1075. this.minFilter = minFilter;
  1076. this.anisotropy = anisotropy;
  1077. this.format = format;
  1078. this.internalFormat = null;
  1079. this.type = type;
  1080. this.offset = new Vector2(0, 0);
  1081. this.repeat = new Vector2(1, 1);
  1082. this.center = new Vector2(0, 0);
  1083. this.rotation = 0;
  1084. this.matrixAutoUpdate = true;
  1085. this.matrix = new Matrix3();
  1086. this.generateMipmaps = true;
  1087. this.premultiplyAlpha = false;
  1088. this.flipY = true;
  1089. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1090. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1091. //
  1092. // Also changing the encoding after already used by a Material will not automatically make the Material
  1093. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1094. this.encoding = encoding;
  1095. this.version = 0;
  1096. this.onUpdate = null;
  1097. }
  1098. Texture.DEFAULT_IMAGE = undefined;
  1099. Texture.DEFAULT_MAPPING = UVMapping;
  1100. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1101. constructor: Texture,
  1102. isTexture: true,
  1103. updateMatrix: function updateMatrix() {
  1104. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1105. },
  1106. clone: function clone() {
  1107. return new this.constructor().copy(this);
  1108. },
  1109. copy: function copy(source) {
  1110. this.name = source.name;
  1111. this.image = source.image;
  1112. this.mipmaps = source.mipmaps.slice(0);
  1113. this.mapping = source.mapping;
  1114. this.wrapS = source.wrapS;
  1115. this.wrapT = source.wrapT;
  1116. this.magFilter = source.magFilter;
  1117. this.minFilter = source.minFilter;
  1118. this.anisotropy = source.anisotropy;
  1119. this.format = source.format;
  1120. this.internalFormat = source.internalFormat;
  1121. this.type = source.type;
  1122. this.offset.copy(source.offset);
  1123. this.repeat.copy(source.repeat);
  1124. this.center.copy(source.center);
  1125. this.rotation = source.rotation;
  1126. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1127. this.matrix.copy(source.matrix);
  1128. this.generateMipmaps = source.generateMipmaps;
  1129. this.premultiplyAlpha = source.premultiplyAlpha;
  1130. this.flipY = source.flipY;
  1131. this.unpackAlignment = source.unpackAlignment;
  1132. this.encoding = source.encoding;
  1133. return this;
  1134. },
  1135. toJSON: function toJSON(meta) {
  1136. var isRootObject = meta === undefined || typeof meta === 'string';
  1137. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1138. return meta.textures[this.uuid];
  1139. }
  1140. var output = {
  1141. metadata: {
  1142. version: 4.5,
  1143. type: 'Texture',
  1144. generator: 'Texture.toJSON'
  1145. },
  1146. uuid: this.uuid,
  1147. name: this.name,
  1148. mapping: this.mapping,
  1149. repeat: [this.repeat.x, this.repeat.y],
  1150. offset: [this.offset.x, this.offset.y],
  1151. center: [this.center.x, this.center.y],
  1152. rotation: this.rotation,
  1153. wrap: [this.wrapS, this.wrapT],
  1154. format: this.format,
  1155. type: this.type,
  1156. encoding: this.encoding,
  1157. minFilter: this.minFilter,
  1158. magFilter: this.magFilter,
  1159. anisotropy: this.anisotropy,
  1160. flipY: this.flipY,
  1161. premultiplyAlpha: this.premultiplyAlpha,
  1162. unpackAlignment: this.unpackAlignment
  1163. };
  1164. if (this.image !== undefined) {
  1165. // TODO: Move to THREE.Image
  1166. var image = this.image;
  1167. if (image.uuid === undefined) {
  1168. image.uuid = MathUtils.generateUUID(); // UGH
  1169. }
  1170. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1171. var url;
  1172. if (Array.isArray(image)) {
  1173. // process array of images e.g. CubeTexture
  1174. url = [];
  1175. for (var i = 0, l = image.length; i < l; i++) {
  1176. // check cube texture with data textures
  1177. if (image[i].isDataTexture) {
  1178. url.push(serializeImage(image[i].image));
  1179. } else {
  1180. url.push(serializeImage(image[i]));
  1181. }
  1182. }
  1183. } else {
  1184. // process single image
  1185. url = serializeImage(image);
  1186. }
  1187. meta.images[image.uuid] = {
  1188. uuid: image.uuid,
  1189. url: url
  1190. };
  1191. }
  1192. output.image = image.uuid;
  1193. }
  1194. if (!isRootObject) {
  1195. meta.textures[this.uuid] = output;
  1196. }
  1197. return output;
  1198. },
  1199. dispose: function dispose() {
  1200. this.dispatchEvent({
  1201. type: 'dispose'
  1202. });
  1203. },
  1204. transformUv: function transformUv(uv) {
  1205. if (this.mapping !== UVMapping) return uv;
  1206. uv.applyMatrix3(this.matrix);
  1207. if (uv.x < 0 || uv.x > 1) {
  1208. switch (this.wrapS) {
  1209. case RepeatWrapping:
  1210. uv.x = uv.x - Math.floor(uv.x);
  1211. break;
  1212. case ClampToEdgeWrapping:
  1213. uv.x = uv.x < 0 ? 0 : 1;
  1214. break;
  1215. case MirroredRepeatWrapping:
  1216. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1217. uv.x = Math.ceil(uv.x) - uv.x;
  1218. } else {
  1219. uv.x = uv.x - Math.floor(uv.x);
  1220. }
  1221. break;
  1222. }
  1223. }
  1224. if (uv.y < 0 || uv.y > 1) {
  1225. switch (this.wrapT) {
  1226. case RepeatWrapping:
  1227. uv.y = uv.y - Math.floor(uv.y);
  1228. break;
  1229. case ClampToEdgeWrapping:
  1230. uv.y = uv.y < 0 ? 0 : 1;
  1231. break;
  1232. case MirroredRepeatWrapping:
  1233. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1234. uv.y = Math.ceil(uv.y) - uv.y;
  1235. } else {
  1236. uv.y = uv.y - Math.floor(uv.y);
  1237. }
  1238. break;
  1239. }
  1240. }
  1241. if (this.flipY) {
  1242. uv.y = 1 - uv.y;
  1243. }
  1244. return uv;
  1245. }
  1246. });
  1247. Object.defineProperty(Texture.prototype, 'needsUpdate', {
  1248. set: function set(value) {
  1249. if (value === true) this.version++;
  1250. }
  1251. });
  1252. function serializeImage(image) {
  1253. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  1254. // default images
  1255. return ImageUtils.getDataURL(image);
  1256. } else {
  1257. if (image.data) {
  1258. // images of DataTexture
  1259. return {
  1260. data: Array.prototype.slice.call(image.data),
  1261. width: image.width,
  1262. height: image.height,
  1263. type: image.data.constructor.name
  1264. };
  1265. } else {
  1266. console.warn('THREE.Texture: Unable to serialize Texture.');
  1267. return {};
  1268. }
  1269. }
  1270. }
  1271. var Vector4 = /*#__PURE__*/function () {
  1272. function Vector4(x, y, z, w) {
  1273. if (x === void 0) {
  1274. x = 0;
  1275. }
  1276. if (y === void 0) {
  1277. y = 0;
  1278. }
  1279. if (z === void 0) {
  1280. z = 0;
  1281. }
  1282. if (w === void 0) {
  1283. w = 1;
  1284. }
  1285. Object.defineProperty(this, 'isVector4', {
  1286. value: true
  1287. });
  1288. this.x = x;
  1289. this.y = y;
  1290. this.z = z;
  1291. this.w = w;
  1292. }
  1293. var _proto = Vector4.prototype;
  1294. _proto.set = function set(x, y, z, w) {
  1295. this.x = x;
  1296. this.y = y;
  1297. this.z = z;
  1298. this.w = w;
  1299. return this;
  1300. };
  1301. _proto.setScalar = function setScalar(scalar) {
  1302. this.x = scalar;
  1303. this.y = scalar;
  1304. this.z = scalar;
  1305. this.w = scalar;
  1306. return this;
  1307. };
  1308. _proto.setX = function setX(x) {
  1309. this.x = x;
  1310. return this;
  1311. };
  1312. _proto.setY = function setY(y) {
  1313. this.y = y;
  1314. return this;
  1315. };
  1316. _proto.setZ = function setZ(z) {
  1317. this.z = z;
  1318. return this;
  1319. };
  1320. _proto.setW = function setW(w) {
  1321. this.w = w;
  1322. return this;
  1323. };
  1324. _proto.setComponent = function setComponent(index, value) {
  1325. switch (index) {
  1326. case 0:
  1327. this.x = value;
  1328. break;
  1329. case 1:
  1330. this.y = value;
  1331. break;
  1332. case 2:
  1333. this.z = value;
  1334. break;
  1335. case 3:
  1336. this.w = value;
  1337. break;
  1338. default:
  1339. throw new Error('index is out of range: ' + index);
  1340. }
  1341. return this;
  1342. };
  1343. _proto.getComponent = function getComponent(index) {
  1344. switch (index) {
  1345. case 0:
  1346. return this.x;
  1347. case 1:
  1348. return this.y;
  1349. case 2:
  1350. return this.z;
  1351. case 3:
  1352. return this.w;
  1353. default:
  1354. throw new Error('index is out of range: ' + index);
  1355. }
  1356. };
  1357. _proto.clone = function clone() {
  1358. return new this.constructor(this.x, this.y, this.z, this.w);
  1359. };
  1360. _proto.copy = function copy(v) {
  1361. this.x = v.x;
  1362. this.y = v.y;
  1363. this.z = v.z;
  1364. this.w = v.w !== undefined ? v.w : 1;
  1365. return this;
  1366. };
  1367. _proto.add = function add(v, w) {
  1368. if (w !== undefined) {
  1369. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1370. return this.addVectors(v, w);
  1371. }
  1372. this.x += v.x;
  1373. this.y += v.y;
  1374. this.z += v.z;
  1375. this.w += v.w;
  1376. return this;
  1377. };
  1378. _proto.addScalar = function addScalar(s) {
  1379. this.x += s;
  1380. this.y += s;
  1381. this.z += s;
  1382. this.w += s;
  1383. return this;
  1384. };
  1385. _proto.addVectors = function addVectors(a, b) {
  1386. this.x = a.x + b.x;
  1387. this.y = a.y + b.y;
  1388. this.z = a.z + b.z;
  1389. this.w = a.w + b.w;
  1390. return this;
  1391. };
  1392. _proto.addScaledVector = function addScaledVector(v, s) {
  1393. this.x += v.x * s;
  1394. this.y += v.y * s;
  1395. this.z += v.z * s;
  1396. this.w += v.w * s;
  1397. return this;
  1398. };
  1399. _proto.sub = function sub(v, w) {
  1400. if (w !== undefined) {
  1401. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1402. return this.subVectors(v, w);
  1403. }
  1404. this.x -= v.x;
  1405. this.y -= v.y;
  1406. this.z -= v.z;
  1407. this.w -= v.w;
  1408. return this;
  1409. };
  1410. _proto.subScalar = function subScalar(s) {
  1411. this.x -= s;
  1412. this.y -= s;
  1413. this.z -= s;
  1414. this.w -= s;
  1415. return this;
  1416. };
  1417. _proto.subVectors = function subVectors(a, b) {
  1418. this.x = a.x - b.x;
  1419. this.y = a.y - b.y;
  1420. this.z = a.z - b.z;
  1421. this.w = a.w - b.w;
  1422. return this;
  1423. };
  1424. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1425. this.x *= scalar;
  1426. this.y *= scalar;
  1427. this.z *= scalar;
  1428. this.w *= scalar;
  1429. return this;
  1430. };
  1431. _proto.applyMatrix4 = function applyMatrix4(m) {
  1432. var x = this.x,
  1433. y = this.y,
  1434. z = this.z,
  1435. w = this.w;
  1436. var e = m.elements;
  1437. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  1438. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  1439. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  1440. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  1441. return this;
  1442. };
  1443. _proto.divideScalar = function divideScalar(scalar) {
  1444. return this.multiplyScalar(1 / scalar);
  1445. };
  1446. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  1447. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1448. // q is assumed to be normalized
  1449. this.w = 2 * Math.acos(q.w);
  1450. var s = Math.sqrt(1 - q.w * q.w);
  1451. if (s < 0.0001) {
  1452. this.x = 1;
  1453. this.y = 0;
  1454. this.z = 0;
  1455. } else {
  1456. this.x = q.x / s;
  1457. this.y = q.y / s;
  1458. this.z = q.z / s;
  1459. }
  1460. return this;
  1461. };
  1462. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  1463. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1464. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1465. var angle, x, y, z; // variables for result
  1466. var epsilon = 0.01,
  1467. // margin to allow for rounding errors
  1468. epsilon2 = 0.1,
  1469. // margin to distinguish between 0 and 180 degrees
  1470. te = m.elements,
  1471. m11 = te[0],
  1472. m12 = te[4],
  1473. m13 = te[8],
  1474. m21 = te[1],
  1475. m22 = te[5],
  1476. m23 = te[9],
  1477. m31 = te[2],
  1478. m32 = te[6],
  1479. m33 = te[10];
  1480. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  1481. // singularity found
  1482. // first check for identity matrix which must have +1 for all terms
  1483. // in leading diagonal and zero in other terms
  1484. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  1485. // this singularity is identity matrix so angle = 0
  1486. this.set(1, 0, 0, 0);
  1487. return this; // zero angle, arbitrary axis
  1488. } // otherwise this singularity is angle = 180
  1489. angle = Math.PI;
  1490. var xx = (m11 + 1) / 2;
  1491. var yy = (m22 + 1) / 2;
  1492. var zz = (m33 + 1) / 2;
  1493. var xy = (m12 + m21) / 4;
  1494. var xz = (m13 + m31) / 4;
  1495. var yz = (m23 + m32) / 4;
  1496. if (xx > yy && xx > zz) {
  1497. // m11 is the largest diagonal term
  1498. if (xx < epsilon) {
  1499. x = 0;
  1500. y = 0.707106781;
  1501. z = 0.707106781;
  1502. } else {
  1503. x = Math.sqrt(xx);
  1504. y = xy / x;
  1505. z = xz / x;
  1506. }
  1507. } else if (yy > zz) {
  1508. // m22 is the largest diagonal term
  1509. if (yy < epsilon) {
  1510. x = 0.707106781;
  1511. y = 0;
  1512. z = 0.707106781;
  1513. } else {
  1514. y = Math.sqrt(yy);
  1515. x = xy / y;
  1516. z = yz / y;
  1517. }
  1518. } else {
  1519. // m33 is the largest diagonal term so base result on this
  1520. if (zz < epsilon) {
  1521. x = 0.707106781;
  1522. y = 0.707106781;
  1523. z = 0;
  1524. } else {
  1525. z = Math.sqrt(zz);
  1526. x = xz / z;
  1527. y = yz / z;
  1528. }
  1529. }
  1530. this.set(x, y, z, angle);
  1531. return this; // return 180 deg rotation
  1532. } // as we have reached here there are no singularities so we can handle normally
  1533. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  1534. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1535. // caught by singularity test above, but I've left it in just in case
  1536. this.x = (m32 - m23) / s;
  1537. this.y = (m13 - m31) / s;
  1538. this.z = (m21 - m12) / s;
  1539. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  1540. return this;
  1541. };
  1542. _proto.min = function min(v) {
  1543. this.x = Math.min(this.x, v.x);
  1544. this.y = Math.min(this.y, v.y);
  1545. this.z = Math.min(this.z, v.z);
  1546. this.w = Math.min(this.w, v.w);
  1547. return this;
  1548. };
  1549. _proto.max = function max(v) {
  1550. this.x = Math.max(this.x, v.x);
  1551. this.y = Math.max(this.y, v.y);
  1552. this.z = Math.max(this.z, v.z);
  1553. this.w = Math.max(this.w, v.w);
  1554. return this;
  1555. };
  1556. _proto.clamp = function clamp(min, max) {
  1557. // assumes min < max, componentwise
  1558. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1559. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1560. this.z = Math.max(min.z, Math.min(max.z, this.z));
  1561. this.w = Math.max(min.w, Math.min(max.w, this.w));
  1562. return this;
  1563. };
  1564. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1565. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1566. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1567. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  1568. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  1569. return this;
  1570. };
  1571. _proto.clampLength = function clampLength(min, max) {
  1572. var length = this.length();
  1573. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1574. };
  1575. _proto.floor = function floor() {
  1576. this.x = Math.floor(this.x);
  1577. this.y = Math.floor(this.y);
  1578. this.z = Math.floor(this.z);
  1579. this.w = Math.floor(this.w);
  1580. return this;
  1581. };
  1582. _proto.ceil = function ceil() {
  1583. this.x = Math.ceil(this.x);
  1584. this.y = Math.ceil(this.y);
  1585. this.z = Math.ceil(this.z);
  1586. this.w = Math.ceil(this.w);
  1587. return this;
  1588. };
  1589. _proto.round = function round() {
  1590. this.x = Math.round(this.x);
  1591. this.y = Math.round(this.y);
  1592. this.z = Math.round(this.z);
  1593. this.w = Math.round(this.w);
  1594. return this;
  1595. };
  1596. _proto.roundToZero = function roundToZero() {
  1597. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1598. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1599. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  1600. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  1601. return this;
  1602. };
  1603. _proto.negate = function negate() {
  1604. this.x = -this.x;
  1605. this.y = -this.y;
  1606. this.z = -this.z;
  1607. this.w = -this.w;
  1608. return this;
  1609. };
  1610. _proto.dot = function dot(v) {
  1611. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1612. };
  1613. _proto.lengthSq = function lengthSq() {
  1614. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1615. };
  1616. _proto.length = function length() {
  1617. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  1618. };
  1619. _proto.manhattanLength = function manhattanLength() {
  1620. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  1621. };
  1622. _proto.normalize = function normalize() {
  1623. return this.divideScalar(this.length() || 1);
  1624. };
  1625. _proto.setLength = function setLength(length) {
  1626. return this.normalize().multiplyScalar(length);
  1627. };
  1628. _proto.lerp = function lerp(v, alpha) {
  1629. this.x += (v.x - this.x) * alpha;
  1630. this.y += (v.y - this.y) * alpha;
  1631. this.z += (v.z - this.z) * alpha;
  1632. this.w += (v.w - this.w) * alpha;
  1633. return this;
  1634. };
  1635. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1636. this.x = v1.x + (v2.x - v1.x) * alpha;
  1637. this.y = v1.y + (v2.y - v1.y) * alpha;
  1638. this.z = v1.z + (v2.z - v1.z) * alpha;
  1639. this.w = v1.w + (v2.w - v1.w) * alpha;
  1640. return this;
  1641. };
  1642. _proto.equals = function equals(v) {
  1643. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  1644. };
  1645. _proto.fromArray = function fromArray(array, offset) {
  1646. if (offset === void 0) {
  1647. offset = 0;
  1648. }
  1649. this.x = array[offset];
  1650. this.y = array[offset + 1];
  1651. this.z = array[offset + 2];
  1652. this.w = array[offset + 3];
  1653. return this;
  1654. };
  1655. _proto.toArray = function toArray(array, offset) {
  1656. if (array === void 0) {
  1657. array = [];
  1658. }
  1659. if (offset === void 0) {
  1660. offset = 0;
  1661. }
  1662. array[offset] = this.x;
  1663. array[offset + 1] = this.y;
  1664. array[offset + 2] = this.z;
  1665. array[offset + 3] = this.w;
  1666. return array;
  1667. };
  1668. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1669. if (offset !== undefined) {
  1670. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  1671. }
  1672. this.x = attribute.getX(index);
  1673. this.y = attribute.getY(index);
  1674. this.z = attribute.getZ(index);
  1675. this.w = attribute.getW(index);
  1676. return this;
  1677. };
  1678. _proto.random = function random() {
  1679. this.x = Math.random();
  1680. this.y = Math.random();
  1681. this.z = Math.random();
  1682. this.w = Math.random();
  1683. return this;
  1684. };
  1685. _createClass(Vector4, [{
  1686. key: "width",
  1687. get: function get() {
  1688. return this.z;
  1689. },
  1690. set: function set(value) {
  1691. this.z = value;
  1692. }
  1693. }, {
  1694. key: "height",
  1695. get: function get() {
  1696. return this.w;
  1697. },
  1698. set: function set(value) {
  1699. this.w = value;
  1700. }
  1701. }]);
  1702. return Vector4;
  1703. }();
  1704. /*
  1705. In options, we can specify:
  1706. * Texture parameters for an auto-generated target texture
  1707. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1708. */
  1709. function WebGLRenderTarget(width, height, options) {
  1710. this.width = width;
  1711. this.height = height;
  1712. this.scissor = new Vector4(0, 0, width, height);
  1713. this.scissorTest = false;
  1714. this.viewport = new Vector4(0, 0, width, height);
  1715. options = options || {};
  1716. this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  1717. this.texture.image = {};
  1718. this.texture.image.width = width;
  1719. this.texture.image.height = height;
  1720. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  1721. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  1722. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1723. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  1724. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1725. }
  1726. WebGLRenderTarget.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1727. constructor: WebGLRenderTarget,
  1728. isWebGLRenderTarget: true,
  1729. setSize: function setSize(width, height) {
  1730. if (this.width !== width || this.height !== height) {
  1731. this.width = width;
  1732. this.height = height;
  1733. this.texture.image.width = width;
  1734. this.texture.image.height = height;
  1735. this.dispose();
  1736. }
  1737. this.viewport.set(0, 0, width, height);
  1738. this.scissor.set(0, 0, width, height);
  1739. },
  1740. clone: function clone() {
  1741. return new this.constructor().copy(this);
  1742. },
  1743. copy: function copy(source) {
  1744. this.width = source.width;
  1745. this.height = source.height;
  1746. this.viewport.copy(source.viewport);
  1747. this.texture = source.texture.clone();
  1748. this.depthBuffer = source.depthBuffer;
  1749. this.stencilBuffer = source.stencilBuffer;
  1750. this.depthTexture = source.depthTexture;
  1751. return this;
  1752. },
  1753. dispose: function dispose() {
  1754. this.dispatchEvent({
  1755. type: 'dispose'
  1756. });
  1757. }
  1758. });
  1759. function WebGLMultisampleRenderTarget(width, height, options) {
  1760. WebGLRenderTarget.call(this, width, height, options);
  1761. this.samples = 4;
  1762. }
  1763. WebGLMultisampleRenderTarget.prototype = Object.assign(Object.create(WebGLRenderTarget.prototype), {
  1764. constructor: WebGLMultisampleRenderTarget,
  1765. isWebGLMultisampleRenderTarget: true,
  1766. copy: function copy(source) {
  1767. WebGLRenderTarget.prototype.copy.call(this, source);
  1768. this.samples = source.samples;
  1769. return this;
  1770. }
  1771. });
  1772. var Quaternion = /*#__PURE__*/function () {
  1773. function Quaternion(x, y, z, w) {
  1774. if (x === void 0) {
  1775. x = 0;
  1776. }
  1777. if (y === void 0) {
  1778. y = 0;
  1779. }
  1780. if (z === void 0) {
  1781. z = 0;
  1782. }
  1783. if (w === void 0) {
  1784. w = 1;
  1785. }
  1786. Object.defineProperty(this, 'isQuaternion', {
  1787. value: true
  1788. });
  1789. this._x = x;
  1790. this._y = y;
  1791. this._z = z;
  1792. this._w = w;
  1793. }
  1794. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  1795. return qm.copy(qa).slerp(qb, t);
  1796. };
  1797. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  1798. // fuzz-free, array-based Quaternion SLERP operation
  1799. var x0 = src0[srcOffset0 + 0],
  1800. y0 = src0[srcOffset0 + 1],
  1801. z0 = src0[srcOffset0 + 2],
  1802. w0 = src0[srcOffset0 + 3];
  1803. var x1 = src1[srcOffset1 + 0],
  1804. y1 = src1[srcOffset1 + 1],
  1805. z1 = src1[srcOffset1 + 2],
  1806. w1 = src1[srcOffset1 + 3];
  1807. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  1808. var s = 1 - t;
  1809. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1810. dir = cos >= 0 ? 1 : -1,
  1811. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  1812. if (sqrSin > Number.EPSILON) {
  1813. var sin = Math.sqrt(sqrSin),
  1814. len = Math.atan2(sin, cos * dir);
  1815. s = Math.sin(s * len) / sin;
  1816. t = Math.sin(t * len) / sin;
  1817. }
  1818. var tDir = t * dir;
  1819. x0 = x0 * s + x1 * tDir;
  1820. y0 = y0 * s + y1 * tDir;
  1821. z0 = z0 * s + z1 * tDir;
  1822. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  1823. if (s === 1 - t) {
  1824. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  1825. x0 *= f;
  1826. y0 *= f;
  1827. z0 *= f;
  1828. w0 *= f;
  1829. }
  1830. }
  1831. dst[dstOffset] = x0;
  1832. dst[dstOffset + 1] = y0;
  1833. dst[dstOffset + 2] = z0;
  1834. dst[dstOffset + 3] = w0;
  1835. };
  1836. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  1837. var x0 = src0[srcOffset0];
  1838. var y0 = src0[srcOffset0 + 1];
  1839. var z0 = src0[srcOffset0 + 2];
  1840. var w0 = src0[srcOffset0 + 3];
  1841. var x1 = src1[srcOffset1];
  1842. var y1 = src1[srcOffset1 + 1];
  1843. var z1 = src1[srcOffset1 + 2];
  1844. var w1 = src1[srcOffset1 + 3];
  1845. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  1846. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  1847. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  1848. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  1849. return dst;
  1850. };
  1851. var _proto = Quaternion.prototype;
  1852. _proto.set = function set(x, y, z, w) {
  1853. this._x = x;
  1854. this._y = y;
  1855. this._z = z;
  1856. this._w = w;
  1857. this._onChangeCallback();
  1858. return this;
  1859. };
  1860. _proto.clone = function clone() {
  1861. return new this.constructor(this._x, this._y, this._z, this._w);
  1862. };
  1863. _proto.copy = function copy(quaternion) {
  1864. this._x = quaternion.x;
  1865. this._y = quaternion.y;
  1866. this._z = quaternion.z;
  1867. this._w = quaternion.w;
  1868. this._onChangeCallback();
  1869. return this;
  1870. };
  1871. _proto.setFromEuler = function setFromEuler(euler, update) {
  1872. if (!(euler && euler.isEuler)) {
  1873. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  1874. }
  1875. var x = euler._x,
  1876. y = euler._y,
  1877. z = euler._z,
  1878. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  1879. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1880. // content/SpinCalc.m
  1881. var cos = Math.cos;
  1882. var sin = Math.sin;
  1883. var c1 = cos(x / 2);
  1884. var c2 = cos(y / 2);
  1885. var c3 = cos(z / 2);
  1886. var s1 = sin(x / 2);
  1887. var s2 = sin(y / 2);
  1888. var s3 = sin(z / 2);
  1889. switch (order) {
  1890. case 'XYZ':
  1891. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1892. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1893. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1894. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1895. break;
  1896. case 'YXZ':
  1897. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1898. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1899. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1900. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1901. break;
  1902. case 'ZXY':
  1903. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1904. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1905. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1906. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1907. break;
  1908. case 'ZYX':
  1909. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1910. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1911. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1912. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1913. break;
  1914. case 'YZX':
  1915. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1916. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1917. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1918. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1919. break;
  1920. case 'XZY':
  1921. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1922. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1923. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1924. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1925. break;
  1926. default:
  1927. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  1928. }
  1929. if (update !== false) this._onChangeCallback();
  1930. return this;
  1931. };
  1932. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  1933. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1934. // assumes axis is normalized
  1935. var halfAngle = angle / 2,
  1936. s = Math.sin(halfAngle);
  1937. this._x = axis.x * s;
  1938. this._y = axis.y * s;
  1939. this._z = axis.z * s;
  1940. this._w = Math.cos(halfAngle);
  1941. this._onChangeCallback();
  1942. return this;
  1943. };
  1944. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  1945. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1946. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1947. var te = m.elements,
  1948. m11 = te[0],
  1949. m12 = te[4],
  1950. m13 = te[8],
  1951. m21 = te[1],
  1952. m22 = te[5],
  1953. m23 = te[9],
  1954. m31 = te[2],
  1955. m32 = te[6],
  1956. m33 = te[10],
  1957. trace = m11 + m22 + m33;
  1958. if (trace > 0) {
  1959. var s = 0.5 / Math.sqrt(trace + 1.0);
  1960. this._w = 0.25 / s;
  1961. this._x = (m32 - m23) * s;
  1962. this._y = (m13 - m31) * s;
  1963. this._z = (m21 - m12) * s;
  1964. } else if (m11 > m22 && m11 > m33) {
  1965. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  1966. this._w = (m32 - m23) / _s;
  1967. this._x = 0.25 * _s;
  1968. this._y = (m12 + m21) / _s;
  1969. this._z = (m13 + m31) / _s;
  1970. } else if (m22 > m33) {
  1971. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  1972. this._w = (m13 - m31) / _s2;
  1973. this._x = (m12 + m21) / _s2;
  1974. this._y = 0.25 * _s2;
  1975. this._z = (m23 + m32) / _s2;
  1976. } else {
  1977. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  1978. this._w = (m21 - m12) / _s3;
  1979. this._x = (m13 + m31) / _s3;
  1980. this._y = (m23 + m32) / _s3;
  1981. this._z = 0.25 * _s3;
  1982. }
  1983. this._onChangeCallback();
  1984. return this;
  1985. };
  1986. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  1987. // assumes direction vectors vFrom and vTo are normalized
  1988. var EPS = 0.000001;
  1989. var r = vFrom.dot(vTo) + 1;
  1990. if (r < EPS) {
  1991. r = 0;
  1992. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  1993. this._x = -vFrom.y;
  1994. this._y = vFrom.x;
  1995. this._z = 0;
  1996. this._w = r;
  1997. } else {
  1998. this._x = 0;
  1999. this._y = -vFrom.z;
  2000. this._z = vFrom.y;
  2001. this._w = r;
  2002. }
  2003. } else {
  2004. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  2005. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  2006. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  2007. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  2008. this._w = r;
  2009. }
  2010. return this.normalize();
  2011. };
  2012. _proto.angleTo = function angleTo(q) {
  2013. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  2014. };
  2015. _proto.rotateTowards = function rotateTowards(q, step) {
  2016. var angle = this.angleTo(q);
  2017. if (angle === 0) return this;
  2018. var t = Math.min(1, step / angle);
  2019. this.slerp(q, t);
  2020. return this;
  2021. };
  2022. _proto.identity = function identity() {
  2023. return this.set(0, 0, 0, 1);
  2024. };
  2025. _proto.invert = function invert() {
  2026. // quaternion is assumed to have unit length
  2027. return this.conjugate();
  2028. };
  2029. _proto.conjugate = function conjugate() {
  2030. this._x *= -1;
  2031. this._y *= -1;
  2032. this._z *= -1;
  2033. this._onChangeCallback();
  2034. return this;
  2035. };
  2036. _proto.dot = function dot(v) {
  2037. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2038. };
  2039. _proto.lengthSq = function lengthSq() {
  2040. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2041. };
  2042. _proto.length = function length() {
  2043. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  2044. };
  2045. _proto.normalize = function normalize() {
  2046. var l = this.length();
  2047. if (l === 0) {
  2048. this._x = 0;
  2049. this._y = 0;
  2050. this._z = 0;
  2051. this._w = 1;
  2052. } else {
  2053. l = 1 / l;
  2054. this._x = this._x * l;
  2055. this._y = this._y * l;
  2056. this._z = this._z * l;
  2057. this._w = this._w * l;
  2058. }
  2059. this._onChangeCallback();
  2060. return this;
  2061. };
  2062. _proto.multiply = function multiply(q, p) {
  2063. if (p !== undefined) {
  2064. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2065. return this.multiplyQuaternions(q, p);
  2066. }
  2067. return this.multiplyQuaternions(this, q);
  2068. };
  2069. _proto.premultiply = function premultiply(q) {
  2070. return this.multiplyQuaternions(q, this);
  2071. };
  2072. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2073. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2074. var qax = a._x,
  2075. qay = a._y,
  2076. qaz = a._z,
  2077. qaw = a._w;
  2078. var qbx = b._x,
  2079. qby = b._y,
  2080. qbz = b._z,
  2081. qbw = b._w;
  2082. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2083. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2084. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2085. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2086. this._onChangeCallback();
  2087. return this;
  2088. };
  2089. _proto.slerp = function slerp(qb, t) {
  2090. if (t === 0) return this;
  2091. if (t === 1) return this.copy(qb);
  2092. var x = this._x,
  2093. y = this._y,
  2094. z = this._z,
  2095. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2096. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2097. if (cosHalfTheta < 0) {
  2098. this._w = -qb._w;
  2099. this._x = -qb._x;
  2100. this._y = -qb._y;
  2101. this._z = -qb._z;
  2102. cosHalfTheta = -cosHalfTheta;
  2103. } else {
  2104. this.copy(qb);
  2105. }
  2106. if (cosHalfTheta >= 1.0) {
  2107. this._w = w;
  2108. this._x = x;
  2109. this._y = y;
  2110. this._z = z;
  2111. return this;
  2112. }
  2113. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2114. if (sqrSinHalfTheta <= Number.EPSILON) {
  2115. var s = 1 - t;
  2116. this._w = s * w + t * this._w;
  2117. this._x = s * x + t * this._x;
  2118. this._y = s * y + t * this._y;
  2119. this._z = s * z + t * this._z;
  2120. this.normalize();
  2121. this._onChangeCallback();
  2122. return this;
  2123. }
  2124. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2125. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2126. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2127. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2128. this._w = w * ratioA + this._w * ratioB;
  2129. this._x = x * ratioA + this._x * ratioB;
  2130. this._y = y * ratioA + this._y * ratioB;
  2131. this._z = z * ratioA + this._z * ratioB;
  2132. this._onChangeCallback();
  2133. return this;
  2134. };
  2135. _proto.equals = function equals(quaternion) {
  2136. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2137. };
  2138. _proto.fromArray = function fromArray(array, offset) {
  2139. if (offset === void 0) {
  2140. offset = 0;
  2141. }
  2142. this._x = array[offset];
  2143. this._y = array[offset + 1];
  2144. this._z = array[offset + 2];
  2145. this._w = array[offset + 3];
  2146. this._onChangeCallback();
  2147. return this;
  2148. };
  2149. _proto.toArray = function toArray(array, offset) {
  2150. if (array === void 0) {
  2151. array = [];
  2152. }
  2153. if (offset === void 0) {
  2154. offset = 0;
  2155. }
  2156. array[offset] = this._x;
  2157. array[offset + 1] = this._y;
  2158. array[offset + 2] = this._z;
  2159. array[offset + 3] = this._w;
  2160. return array;
  2161. };
  2162. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2163. this._x = attribute.getX(index);
  2164. this._y = attribute.getY(index);
  2165. this._z = attribute.getZ(index);
  2166. this._w = attribute.getW(index);
  2167. return this;
  2168. };
  2169. _proto._onChange = function _onChange(callback) {
  2170. this._onChangeCallback = callback;
  2171. return this;
  2172. };
  2173. _proto._onChangeCallback = function _onChangeCallback() {};
  2174. _createClass(Quaternion, [{
  2175. key: "x",
  2176. get: function get() {
  2177. return this._x;
  2178. },
  2179. set: function set(value) {
  2180. this._x = value;
  2181. this._onChangeCallback();
  2182. }
  2183. }, {
  2184. key: "y",
  2185. get: function get() {
  2186. return this._y;
  2187. },
  2188. set: function set(value) {
  2189. this._y = value;
  2190. this._onChangeCallback();
  2191. }
  2192. }, {
  2193. key: "z",
  2194. get: function get() {
  2195. return this._z;
  2196. },
  2197. set: function set(value) {
  2198. this._z = value;
  2199. this._onChangeCallback();
  2200. }
  2201. }, {
  2202. key: "w",
  2203. get: function get() {
  2204. return this._w;
  2205. },
  2206. set: function set(value) {
  2207. this._w = value;
  2208. this._onChangeCallback();
  2209. }
  2210. }]);
  2211. return Quaternion;
  2212. }();
  2213. var Vector3 = /*#__PURE__*/function () {
  2214. function Vector3(x, y, z) {
  2215. if (x === void 0) {
  2216. x = 0;
  2217. }
  2218. if (y === void 0) {
  2219. y = 0;
  2220. }
  2221. if (z === void 0) {
  2222. z = 0;
  2223. }
  2224. Object.defineProperty(this, 'isVector3', {
  2225. value: true
  2226. });
  2227. this.x = x;
  2228. this.y = y;
  2229. this.z = z;
  2230. }
  2231. var _proto = Vector3.prototype;
  2232. _proto.set = function set(x, y, z) {
  2233. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2234. this.x = x;
  2235. this.y = y;
  2236. this.z = z;
  2237. return this;
  2238. };
  2239. _proto.setScalar = function setScalar(scalar) {
  2240. this.x = scalar;
  2241. this.y = scalar;
  2242. this.z = scalar;
  2243. return this;
  2244. };
  2245. _proto.setX = function setX(x) {
  2246. this.x = x;
  2247. return this;
  2248. };
  2249. _proto.setY = function setY(y) {
  2250. this.y = y;
  2251. return this;
  2252. };
  2253. _proto.setZ = function setZ(z) {
  2254. this.z = z;
  2255. return this;
  2256. };
  2257. _proto.setComponent = function setComponent(index, value) {
  2258. switch (index) {
  2259. case 0:
  2260. this.x = value;
  2261. break;
  2262. case 1:
  2263. this.y = value;
  2264. break;
  2265. case 2:
  2266. this.z = value;
  2267. break;
  2268. default:
  2269. throw new Error('index is out of range: ' + index);
  2270. }
  2271. return this;
  2272. };
  2273. _proto.getComponent = function getComponent(index) {
  2274. switch (index) {
  2275. case 0:
  2276. return this.x;
  2277. case 1:
  2278. return this.y;
  2279. case 2:
  2280. return this.z;
  2281. default:
  2282. throw new Error('index is out of range: ' + index);
  2283. }
  2284. };
  2285. _proto.clone = function clone() {
  2286. return new this.constructor(this.x, this.y, this.z);
  2287. };
  2288. _proto.copy = function copy(v) {
  2289. this.x = v.x;
  2290. this.y = v.y;
  2291. this.z = v.z;
  2292. return this;
  2293. };
  2294. _proto.add = function add(v, w) {
  2295. if (w !== undefined) {
  2296. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2297. return this.addVectors(v, w);
  2298. }
  2299. this.x += v.x;
  2300. this.y += v.y;
  2301. this.z += v.z;
  2302. return this;
  2303. };
  2304. _proto.addScalar = function addScalar(s) {
  2305. this.x += s;
  2306. this.y += s;
  2307. this.z += s;
  2308. return this;
  2309. };
  2310. _proto.addVectors = function addVectors(a, b) {
  2311. this.x = a.x + b.x;
  2312. this.y = a.y + b.y;
  2313. this.z = a.z + b.z;
  2314. return this;
  2315. };
  2316. _proto.addScaledVector = function addScaledVector(v, s) {
  2317. this.x += v.x * s;
  2318. this.y += v.y * s;
  2319. this.z += v.z * s;
  2320. return this;
  2321. };
  2322. _proto.sub = function sub(v, w) {
  2323. if (w !== undefined) {
  2324. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2325. return this.subVectors(v, w);
  2326. }
  2327. this.x -= v.x;
  2328. this.y -= v.y;
  2329. this.z -= v.z;
  2330. return this;
  2331. };
  2332. _proto.subScalar = function subScalar(s) {
  2333. this.x -= s;
  2334. this.y -= s;
  2335. this.z -= s;
  2336. return this;
  2337. };
  2338. _proto.subVectors = function subVectors(a, b) {
  2339. this.x = a.x - b.x;
  2340. this.y = a.y - b.y;
  2341. this.z = a.z - b.z;
  2342. return this;
  2343. };
  2344. _proto.multiply = function multiply(v, w) {
  2345. if (w !== undefined) {
  2346. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  2347. return this.multiplyVectors(v, w);
  2348. }
  2349. this.x *= v.x;
  2350. this.y *= v.y;
  2351. this.z *= v.z;
  2352. return this;
  2353. };
  2354. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2355. this.x *= scalar;
  2356. this.y *= scalar;
  2357. this.z *= scalar;
  2358. return this;
  2359. };
  2360. _proto.multiplyVectors = function multiplyVectors(a, b) {
  2361. this.x = a.x * b.x;
  2362. this.y = a.y * b.y;
  2363. this.z = a.z * b.z;
  2364. return this;
  2365. };
  2366. _proto.applyEuler = function applyEuler(euler) {
  2367. if (!(euler && euler.isEuler)) {
  2368. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2369. }
  2370. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  2371. };
  2372. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  2373. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  2374. };
  2375. _proto.applyMatrix3 = function applyMatrix3(m) {
  2376. var x = this.x,
  2377. y = this.y,
  2378. z = this.z;
  2379. var e = m.elements;
  2380. this.x = e[0] * x + e[3] * y + e[6] * z;
  2381. this.y = e[1] * x + e[4] * y + e[7] * z;
  2382. this.z = e[2] * x + e[5] * y + e[8] * z;
  2383. return this;
  2384. };
  2385. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  2386. return this.applyMatrix3(m).normalize();
  2387. };
  2388. _proto.applyMatrix4 = function applyMatrix4(m) {
  2389. var x = this.x,
  2390. y = this.y,
  2391. z = this.z;
  2392. var e = m.elements;
  2393. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  2394. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  2395. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  2396. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  2397. return this;
  2398. };
  2399. _proto.applyQuaternion = function applyQuaternion(q) {
  2400. var x = this.x,
  2401. y = this.y,
  2402. z = this.z;
  2403. var qx = q.x,
  2404. qy = q.y,
  2405. qz = q.z,
  2406. qw = q.w; // calculate quat * vector
  2407. var ix = qw * x + qy * z - qz * y;
  2408. var iy = qw * y + qz * x - qx * z;
  2409. var iz = qw * z + qx * y - qy * x;
  2410. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  2411. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  2412. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  2413. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  2414. return this;
  2415. };
  2416. _proto.project = function project(camera) {
  2417. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  2418. };
  2419. _proto.unproject = function unproject(camera) {
  2420. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  2421. };
  2422. _proto.transformDirection = function transformDirection(m) {
  2423. // input: THREE.Matrix4 affine matrix
  2424. // vector interpreted as a direction
  2425. var x = this.x,
  2426. y = this.y,
  2427. z = this.z;
  2428. var e = m.elements;
  2429. this.x = e[0] * x + e[4] * y + e[8] * z;
  2430. this.y = e[1] * x + e[5] * y + e[9] * z;
  2431. this.z = e[2] * x + e[6] * y + e[10] * z;
  2432. return this.normalize();
  2433. };
  2434. _proto.divide = function divide(v) {
  2435. this.x /= v.x;
  2436. this.y /= v.y;
  2437. this.z /= v.z;
  2438. return this;
  2439. };
  2440. _proto.divideScalar = function divideScalar(scalar) {
  2441. return this.multiplyScalar(1 / scalar);
  2442. };
  2443. _proto.min = function min(v) {
  2444. this.x = Math.min(this.x, v.x);
  2445. this.y = Math.min(this.y, v.y);
  2446. this.z = Math.min(this.z, v.z);
  2447. return this;
  2448. };
  2449. _proto.max = function max(v) {
  2450. this.x = Math.max(this.x, v.x);
  2451. this.y = Math.max(this.y, v.y);
  2452. this.z = Math.max(this.z, v.z);
  2453. return this;
  2454. };
  2455. _proto.clamp = function clamp(min, max) {
  2456. // assumes min < max, componentwise
  2457. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2458. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2459. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2460. return this;
  2461. };
  2462. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2463. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2464. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2465. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2466. return this;
  2467. };
  2468. _proto.clampLength = function clampLength(min, max) {
  2469. var length = this.length();
  2470. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2471. };
  2472. _proto.floor = function floor() {
  2473. this.x = Math.floor(this.x);
  2474. this.y = Math.floor(this.y);
  2475. this.z = Math.floor(this.z);
  2476. return this;
  2477. };
  2478. _proto.ceil = function ceil() {
  2479. this.x = Math.ceil(this.x);
  2480. this.y = Math.ceil(this.y);
  2481. this.z = Math.ceil(this.z);
  2482. return this;
  2483. };
  2484. _proto.round = function round() {
  2485. this.x = Math.round(this.x);
  2486. this.y = Math.round(this.y);
  2487. this.z = Math.round(this.z);
  2488. return this;
  2489. };
  2490. _proto.roundToZero = function roundToZero() {
  2491. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2492. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2493. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2494. return this;
  2495. };
  2496. _proto.negate = function negate() {
  2497. this.x = -this.x;
  2498. this.y = -this.y;
  2499. this.z = -this.z;
  2500. return this;
  2501. };
  2502. _proto.dot = function dot(v) {
  2503. return this.x * v.x + this.y * v.y + this.z * v.z;
  2504. } // TODO lengthSquared?
  2505. ;
  2506. _proto.lengthSq = function lengthSq() {
  2507. return this.x * this.x + this.y * this.y + this.z * this.z;
  2508. };
  2509. _proto.length = function length() {
  2510. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  2511. };
  2512. _proto.manhattanLength = function manhattanLength() {
  2513. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  2514. };
  2515. _proto.normalize = function normalize() {
  2516. return this.divideScalar(this.length() || 1);
  2517. };
  2518. _proto.setLength = function setLength(length) {
  2519. return this.normalize().multiplyScalar(length);
  2520. };
  2521. _proto.lerp = function lerp(v, alpha) {
  2522. this.x += (v.x - this.x) * alpha;
  2523. this.y += (v.y - this.y) * alpha;
  2524. this.z += (v.z - this.z) * alpha;
  2525. return this;
  2526. };
  2527. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2528. this.x = v1.x + (v2.x - v1.x) * alpha;
  2529. this.y = v1.y + (v2.y - v1.y) * alpha;
  2530. this.z = v1.z + (v2.z - v1.z) * alpha;
  2531. return this;
  2532. };
  2533. _proto.cross = function cross(v, w) {
  2534. if (w !== undefined) {
  2535. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  2536. return this.crossVectors(v, w);
  2537. }
  2538. return this.crossVectors(this, v);
  2539. };
  2540. _proto.crossVectors = function crossVectors(a, b) {
  2541. var ax = a.x,
  2542. ay = a.y,
  2543. az = a.z;
  2544. var bx = b.x,
  2545. by = b.y,
  2546. bz = b.z;
  2547. this.x = ay * bz - az * by;
  2548. this.y = az * bx - ax * bz;
  2549. this.z = ax * by - ay * bx;
  2550. return this;
  2551. };
  2552. _proto.projectOnVector = function projectOnVector(v) {
  2553. var denominator = v.lengthSq();
  2554. if (denominator === 0) return this.set(0, 0, 0);
  2555. var scalar = v.dot(this) / denominator;
  2556. return this.copy(v).multiplyScalar(scalar);
  2557. };
  2558. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  2559. _vector.copy(this).projectOnVector(planeNormal);
  2560. return this.sub(_vector);
  2561. };
  2562. _proto.reflect = function reflect(normal) {
  2563. // reflect incident vector off plane orthogonal to normal
  2564. // normal is assumed to have unit length
  2565. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  2566. };
  2567. _proto.angleTo = function angleTo(v) {
  2568. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  2569. if (denominator === 0) return Math.PI / 2;
  2570. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  2571. return Math.acos(MathUtils.clamp(theta, -1, 1));
  2572. };
  2573. _proto.distanceTo = function distanceTo(v) {
  2574. return Math.sqrt(this.distanceToSquared(v));
  2575. };
  2576. _proto.distanceToSquared = function distanceToSquared(v) {
  2577. var dx = this.x - v.x,
  2578. dy = this.y - v.y,
  2579. dz = this.z - v.z;
  2580. return dx * dx + dy * dy + dz * dz;
  2581. };
  2582. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  2583. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  2584. };
  2585. _proto.setFromSpherical = function setFromSpherical(s) {
  2586. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  2587. };
  2588. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  2589. var sinPhiRadius = Math.sin(phi) * radius;
  2590. this.x = sinPhiRadius * Math.sin(theta);
  2591. this.y = Math.cos(phi) * radius;
  2592. this.z = sinPhiRadius * Math.cos(theta);
  2593. return this;
  2594. };
  2595. _proto.setFromCylindrical = function setFromCylindrical(c) {
  2596. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  2597. };
  2598. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  2599. this.x = radius * Math.sin(theta);
  2600. this.y = y;
  2601. this.z = radius * Math.cos(theta);
  2602. return this;
  2603. };
  2604. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  2605. var e = m.elements;
  2606. this.x = e[12];
  2607. this.y = e[13];
  2608. this.z = e[14];
  2609. return this;
  2610. };
  2611. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  2612. var sx = this.setFromMatrixColumn(m, 0).length();
  2613. var sy = this.setFromMatrixColumn(m, 1).length();
  2614. var sz = this.setFromMatrixColumn(m, 2).length();
  2615. this.x = sx;
  2616. this.y = sy;
  2617. this.z = sz;
  2618. return this;
  2619. };
  2620. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  2621. return this.fromArray(m.elements, index * 4);
  2622. };
  2623. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  2624. return this.fromArray(m.elements, index * 3);
  2625. };
  2626. _proto.equals = function equals(v) {
  2627. return v.x === this.x && v.y === this.y && v.z === this.z;
  2628. };
  2629. _proto.fromArray = function fromArray(array, offset) {
  2630. if (offset === void 0) {
  2631. offset = 0;
  2632. }
  2633. this.x = array[offset];
  2634. this.y = array[offset + 1];
  2635. this.z = array[offset + 2];
  2636. return this;
  2637. };
  2638. _proto.toArray = function toArray(array, offset) {
  2639. if (array === void 0) {
  2640. array = [];
  2641. }
  2642. if (offset === void 0) {
  2643. offset = 0;
  2644. }
  2645. array[offset] = this.x;
  2646. array[offset + 1] = this.y;
  2647. array[offset + 2] = this.z;
  2648. return array;
  2649. };
  2650. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2651. if (offset !== undefined) {
  2652. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  2653. }
  2654. this.x = attribute.getX(index);
  2655. this.y = attribute.getY(index);
  2656. this.z = attribute.getZ(index);
  2657. return this;
  2658. };
  2659. _proto.random = function random() {
  2660. this.x = Math.random();
  2661. this.y = Math.random();
  2662. this.z = Math.random();
  2663. return this;
  2664. };
  2665. return Vector3;
  2666. }();
  2667. var _vector = /*@__PURE__*/new Vector3();
  2668. var _quaternion = /*@__PURE__*/new Quaternion();
  2669. var Box3 = /*#__PURE__*/function () {
  2670. function Box3(min, max) {
  2671. Object.defineProperty(this, 'isBox3', {
  2672. value: true
  2673. });
  2674. this.min = min !== undefined ? min : new Vector3(+Infinity, +Infinity, +Infinity);
  2675. this.max = max !== undefined ? max : new Vector3(-Infinity, -Infinity, -Infinity);
  2676. }
  2677. var _proto = Box3.prototype;
  2678. _proto.set = function set(min, max) {
  2679. this.min.copy(min);
  2680. this.max.copy(max);
  2681. return this;
  2682. };
  2683. _proto.setFromArray = function setFromArray(array) {
  2684. var minX = +Infinity;
  2685. var minY = +Infinity;
  2686. var minZ = +Infinity;
  2687. var maxX = -Infinity;
  2688. var maxY = -Infinity;
  2689. var maxZ = -Infinity;
  2690. for (var i = 0, l = array.length; i < l; i += 3) {
  2691. var x = array[i];
  2692. var y = array[i + 1];
  2693. var z = array[i + 2];
  2694. if (x < minX) minX = x;
  2695. if (y < minY) minY = y;
  2696. if (z < minZ) minZ = z;
  2697. if (x > maxX) maxX = x;
  2698. if (y > maxY) maxY = y;
  2699. if (z > maxZ) maxZ = z;
  2700. }
  2701. this.min.set(minX, minY, minZ);
  2702. this.max.set(maxX, maxY, maxZ);
  2703. return this;
  2704. };
  2705. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  2706. var minX = +Infinity;
  2707. var minY = +Infinity;
  2708. var minZ = +Infinity;
  2709. var maxX = -Infinity;
  2710. var maxY = -Infinity;
  2711. var maxZ = -Infinity;
  2712. for (var i = 0, l = attribute.count; i < l; i++) {
  2713. var x = attribute.getX(i);
  2714. var y = attribute.getY(i);
  2715. var z = attribute.getZ(i);
  2716. if (x < minX) minX = x;
  2717. if (y < minY) minY = y;
  2718. if (z < minZ) minZ = z;
  2719. if (x > maxX) maxX = x;
  2720. if (y > maxY) maxY = y;
  2721. if (z > maxZ) maxZ = z;
  2722. }
  2723. this.min.set(minX, minY, minZ);
  2724. this.max.set(maxX, maxY, maxZ);
  2725. return this;
  2726. };
  2727. _proto.setFromPoints = function setFromPoints(points) {
  2728. this.makeEmpty();
  2729. for (var i = 0, il = points.length; i < il; i++) {
  2730. this.expandByPoint(points[i]);
  2731. }
  2732. return this;
  2733. };
  2734. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  2735. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  2736. this.min.copy(center).sub(halfSize);
  2737. this.max.copy(center).add(halfSize);
  2738. return this;
  2739. };
  2740. _proto.setFromObject = function setFromObject(object) {
  2741. this.makeEmpty();
  2742. return this.expandByObject(object);
  2743. };
  2744. _proto.clone = function clone() {
  2745. return new this.constructor().copy(this);
  2746. };
  2747. _proto.copy = function copy(box) {
  2748. this.min.copy(box.min);
  2749. this.max.copy(box.max);
  2750. return this;
  2751. };
  2752. _proto.makeEmpty = function makeEmpty() {
  2753. this.min.x = this.min.y = this.min.z = +Infinity;
  2754. this.max.x = this.max.y = this.max.z = -Infinity;
  2755. return this;
  2756. };
  2757. _proto.isEmpty = function isEmpty() {
  2758. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2759. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  2760. };
  2761. _proto.getCenter = function getCenter(target) {
  2762. if (target === undefined) {
  2763. console.warn('THREE.Box3: .getCenter() target is now required');
  2764. target = new Vector3();
  2765. }
  2766. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  2767. };
  2768. _proto.getSize = function getSize(target) {
  2769. if (target === undefined) {
  2770. console.warn('THREE.Box3: .getSize() target is now required');
  2771. target = new Vector3();
  2772. }
  2773. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  2774. };
  2775. _proto.expandByPoint = function expandByPoint(point) {
  2776. this.min.min(point);
  2777. this.max.max(point);
  2778. return this;
  2779. };
  2780. _proto.expandByVector = function expandByVector(vector) {
  2781. this.min.sub(vector);
  2782. this.max.add(vector);
  2783. return this;
  2784. };
  2785. _proto.expandByScalar = function expandByScalar(scalar) {
  2786. this.min.addScalar(-scalar);
  2787. this.max.addScalar(scalar);
  2788. return this;
  2789. };
  2790. _proto.expandByObject = function expandByObject(object) {
  2791. // Computes the world-axis-aligned bounding box of an object (including its children),
  2792. // accounting for both the object's, and children's, world transforms
  2793. object.updateWorldMatrix(false, false);
  2794. var geometry = object.geometry;
  2795. if (geometry !== undefined) {
  2796. if (geometry.boundingBox === null) {
  2797. geometry.computeBoundingBox();
  2798. }
  2799. _box.copy(geometry.boundingBox);
  2800. _box.applyMatrix4(object.matrixWorld);
  2801. this.union(_box);
  2802. }
  2803. var children = object.children;
  2804. for (var i = 0, l = children.length; i < l; i++) {
  2805. this.expandByObject(children[i]);
  2806. }
  2807. return this;
  2808. };
  2809. _proto.containsPoint = function containsPoint(point) {
  2810. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y || point.z < this.min.z || point.z > this.max.z ? false : true;
  2811. };
  2812. _proto.containsBox = function containsBox(box) {
  2813. return this.min.x <= box.min.x && box.max.x <= this.max.x && this.min.y <= box.min.y && box.max.y <= this.max.y && this.min.z <= box.min.z && box.max.z <= this.max.z;
  2814. };
  2815. _proto.getParameter = function getParameter(point, target) {
  2816. // This can potentially have a divide by zero if the box
  2817. // has a size dimension of 0.
  2818. if (target === undefined) {
  2819. console.warn('THREE.Box3: .getParameter() target is now required');
  2820. target = new Vector3();
  2821. }
  2822. return target.set((point.x - this.min.x) / (this.max.x - this.min.x), (point.y - this.min.y) / (this.max.y - this.min.y), (point.z - this.min.z) / (this.max.z - this.min.z));
  2823. };
  2824. _proto.intersectsBox = function intersectsBox(box) {
  2825. // using 6 splitting planes to rule out intersections.
  2826. return box.max.x < this.min.x || box.min.x > this.max.x || box.max.y < this.min.y || box.min.y > this.max.y || box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  2827. };
  2828. _proto.intersectsSphere = function intersectsSphere(sphere) {
  2829. // Find the point on the AABB closest to the sphere center.
  2830. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  2831. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  2832. };
  2833. _proto.intersectsPlane = function intersectsPlane(plane) {
  2834. // We compute the minimum and maximum dot product values. If those values
  2835. // are on the same side (back or front) of the plane, then there is no intersection.
  2836. var min, max;
  2837. if (plane.normal.x > 0) {
  2838. min = plane.normal.x * this.min.x;
  2839. max = plane.normal.x * this.max.x;
  2840. } else {
  2841. min = plane.normal.x * this.max.x;
  2842. max = plane.normal.x * this.min.x;
  2843. }
  2844. if (plane.normal.y > 0) {
  2845. min += plane.normal.y * this.min.y;
  2846. max += plane.normal.y * this.max.y;
  2847. } else {
  2848. min += plane.normal.y * this.max.y;
  2849. max += plane.normal.y * this.min.y;
  2850. }
  2851. if (plane.normal.z > 0) {
  2852. min += plane.normal.z * this.min.z;
  2853. max += plane.normal.z * this.max.z;
  2854. } else {
  2855. min += plane.normal.z * this.max.z;
  2856. max += plane.normal.z * this.min.z;
  2857. }
  2858. return min <= -plane.constant && max >= -plane.constant;
  2859. };
  2860. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  2861. if (this.isEmpty()) {
  2862. return false;
  2863. } // compute box center and extents
  2864. this.getCenter(_center);
  2865. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  2866. _v0.subVectors(triangle.a, _center);
  2867. _v1.subVectors(triangle.b, _center);
  2868. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  2869. _f0.subVectors(_v1, _v0);
  2870. _f1.subVectors(_v2, _v1);
  2871. _f2.subVectors(_v0, _v2); // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  2872. // make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation
  2873. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  2874. var axes = [0, -_f0.z, _f0.y, 0, -_f1.z, _f1.y, 0, -_f2.z, _f2.y, _f0.z, 0, -_f0.x, _f1.z, 0, -_f1.x, _f2.z, 0, -_f2.x, -_f0.y, _f0.x, 0, -_f1.y, _f1.x, 0, -_f2.y, _f2.x, 0];
  2875. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2876. return false;
  2877. } // test 3 face normals from the aabb
  2878. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  2879. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2880. return false;
  2881. } // finally testing the face normal of the triangle
  2882. // use already existing triangle edge vectors here
  2883. _triangleNormal.crossVectors(_f0, _f1);
  2884. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  2885. return satForAxes(axes, _v0, _v1, _v2, _extents);
  2886. };
  2887. _proto.clampPoint = function clampPoint(point, target) {
  2888. if (target === undefined) {
  2889. console.warn('THREE.Box3: .clampPoint() target is now required');
  2890. target = new Vector3();
  2891. }
  2892. return target.copy(point).clamp(this.min, this.max);
  2893. };
  2894. _proto.distanceToPoint = function distanceToPoint(point) {
  2895. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  2896. return clampedPoint.sub(point).length();
  2897. };
  2898. _proto.getBoundingSphere = function getBoundingSphere(target) {
  2899. if (target === undefined) {
  2900. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  2901. }
  2902. this.getCenter(target.center);
  2903. target.radius = this.getSize(_vector$1).length() * 0.5;
  2904. return target;
  2905. };
  2906. _proto.intersect = function intersect(box) {
  2907. this.min.max(box.min);
  2908. this.max.min(box.max); // ensure that if there is no overlap, the result is fully empty, not slightly empty with non-inf/+inf values that will cause subsequence intersects to erroneously return valid values.
  2909. if (this.isEmpty()) this.makeEmpty();
  2910. return this;
  2911. };
  2912. _proto.union = function union(box) {
  2913. this.min.min(box.min);
  2914. this.max.max(box.max);
  2915. return this;
  2916. };
  2917. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  2918. // transform of empty box is an empty box.
  2919. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2920. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  2921. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  2922. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  2923. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  2924. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  2925. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  2926. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  2927. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  2928. this.setFromPoints(_points);
  2929. return this;
  2930. };
  2931. _proto.translate = function translate(offset) {
  2932. this.min.add(offset);
  2933. this.max.add(offset);
  2934. return this;
  2935. };
  2936. _proto.equals = function equals(box) {
  2937. return box.min.equals(this.min) && box.max.equals(this.max);
  2938. };
  2939. return Box3;
  2940. }();
  2941. function satForAxes(axes, v0, v1, v2, extents) {
  2942. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  2943. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  2944. var r = extents.x * Math.abs(_testAxis.x) + extents.y * Math.abs(_testAxis.y) + extents.z * Math.abs(_testAxis.z); // project all 3 vertices of the triangle onto the seperating axis
  2945. var p0 = v0.dot(_testAxis);
  2946. var p1 = v1.dot(_testAxis);
  2947. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  2948. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  2949. // points of the projected triangle are outside the projected half-length of the aabb
  2950. // the axis is seperating and we can exit
  2951. return false;
  2952. }
  2953. }
  2954. return true;
  2955. }
  2956. var _points = [/*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3()];
  2957. var _vector$1 = /*@__PURE__*/new Vector3();
  2958. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  2959. var _v0 = /*@__PURE__*/new Vector3();
  2960. var _v1 = /*@__PURE__*/new Vector3();
  2961. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  2962. var _f0 = /*@__PURE__*/new Vector3();
  2963. var _f1 = /*@__PURE__*/new Vector3();
  2964. var _f2 = /*@__PURE__*/new Vector3();
  2965. var _center = /*@__PURE__*/new Vector3();
  2966. var _extents = /*@__PURE__*/new Vector3();
  2967. var _triangleNormal = /*@__PURE__*/new Vector3();
  2968. var _testAxis = /*@__PURE__*/new Vector3();
  2969. var _box$1 = /*@__PURE__*/new Box3();
  2970. var Sphere = /*#__PURE__*/function () {
  2971. function Sphere(center, radius) {
  2972. this.center = center !== undefined ? center : new Vector3();
  2973. this.radius = radius !== undefined ? radius : -1;
  2974. }
  2975. var _proto = Sphere.prototype;
  2976. _proto.set = function set(center, radius) {
  2977. this.center.copy(center);
  2978. this.radius = radius;
  2979. return this;
  2980. };
  2981. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  2982. var center = this.center;
  2983. if (optionalCenter !== undefined) {
  2984. center.copy(optionalCenter);
  2985. } else {
  2986. _box$1.setFromPoints(points).getCenter(center);
  2987. }
  2988. var maxRadiusSq = 0;
  2989. for (var i = 0, il = points.length; i < il; i++) {
  2990. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  2991. }
  2992. this.radius = Math.sqrt(maxRadiusSq);
  2993. return this;
  2994. };
  2995. _proto.clone = function clone() {
  2996. return new this.constructor().copy(this);
  2997. };
  2998. _proto.copy = function copy(sphere) {
  2999. this.center.copy(sphere.center);
  3000. this.radius = sphere.radius;
  3001. return this;
  3002. };
  3003. _proto.isEmpty = function isEmpty() {
  3004. return this.radius < 0;
  3005. };
  3006. _proto.makeEmpty = function makeEmpty() {
  3007. this.center.set(0, 0, 0);
  3008. this.radius = -1;
  3009. return this;
  3010. };
  3011. _proto.containsPoint = function containsPoint(point) {
  3012. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  3013. };
  3014. _proto.distanceToPoint = function distanceToPoint(point) {
  3015. return point.distanceTo(this.center) - this.radius;
  3016. };
  3017. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3018. var radiusSum = this.radius + sphere.radius;
  3019. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  3020. };
  3021. _proto.intersectsBox = function intersectsBox(box) {
  3022. return box.intersectsSphere(this);
  3023. };
  3024. _proto.intersectsPlane = function intersectsPlane(plane) {
  3025. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  3026. };
  3027. _proto.clampPoint = function clampPoint(point, target) {
  3028. var deltaLengthSq = this.center.distanceToSquared(point);
  3029. if (target === undefined) {
  3030. console.warn('THREE.Sphere: .clampPoint() target is now required');
  3031. target = new Vector3();
  3032. }
  3033. target.copy(point);
  3034. if (deltaLengthSq > this.radius * this.radius) {
  3035. target.sub(this.center).normalize();
  3036. target.multiplyScalar(this.radius).add(this.center);
  3037. }
  3038. return target;
  3039. };
  3040. _proto.getBoundingBox = function getBoundingBox(target) {
  3041. if (target === undefined) {
  3042. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  3043. target = new Box3();
  3044. }
  3045. if (this.isEmpty()) {
  3046. // Empty sphere produces empty bounding box
  3047. target.makeEmpty();
  3048. return target;
  3049. }
  3050. target.set(this.center, this.center);
  3051. target.expandByScalar(this.radius);
  3052. return target;
  3053. };
  3054. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3055. this.center.applyMatrix4(matrix);
  3056. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3057. return this;
  3058. };
  3059. _proto.translate = function translate(offset) {
  3060. this.center.add(offset);
  3061. return this;
  3062. };
  3063. _proto.equals = function equals(sphere) {
  3064. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3065. };
  3066. return Sphere;
  3067. }();
  3068. var _vector$2 = /*@__PURE__*/new Vector3();
  3069. var _segCenter = /*@__PURE__*/new Vector3();
  3070. var _segDir = /*@__PURE__*/new Vector3();
  3071. var _diff = /*@__PURE__*/new Vector3();
  3072. var _edge1 = /*@__PURE__*/new Vector3();
  3073. var _edge2 = /*@__PURE__*/new Vector3();
  3074. var _normal = /*@__PURE__*/new Vector3();
  3075. var Ray = /*#__PURE__*/function () {
  3076. function Ray(origin, direction) {
  3077. this.origin = origin !== undefined ? origin : new Vector3();
  3078. this.direction = direction !== undefined ? direction : new Vector3(0, 0, -1);
  3079. }
  3080. var _proto = Ray.prototype;
  3081. _proto.set = function set(origin, direction) {
  3082. this.origin.copy(origin);
  3083. this.direction.copy(direction);
  3084. return this;
  3085. };
  3086. _proto.clone = function clone() {
  3087. return new this.constructor().copy(this);
  3088. };
  3089. _proto.copy = function copy(ray) {
  3090. this.origin.copy(ray.origin);
  3091. this.direction.copy(ray.direction);
  3092. return this;
  3093. };
  3094. _proto.at = function at(t, target) {
  3095. if (target === undefined) {
  3096. console.warn('THREE.Ray: .at() target is now required');
  3097. target = new Vector3();
  3098. }
  3099. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3100. };
  3101. _proto.lookAt = function lookAt(v) {
  3102. this.direction.copy(v).sub(this.origin).normalize();
  3103. return this;
  3104. };
  3105. _proto.recast = function recast(t) {
  3106. this.origin.copy(this.at(t, _vector$2));
  3107. return this;
  3108. };
  3109. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3110. if (target === undefined) {
  3111. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3112. target = new Vector3();
  3113. }
  3114. target.subVectors(point, this.origin);
  3115. var directionDistance = target.dot(this.direction);
  3116. if (directionDistance < 0) {
  3117. return target.copy(this.origin);
  3118. }
  3119. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3120. };
  3121. _proto.distanceToPoint = function distanceToPoint(point) {
  3122. return Math.sqrt(this.distanceSqToPoint(point));
  3123. };
  3124. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3125. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3126. if (directionDistance < 0) {
  3127. return this.origin.distanceToSquared(point);
  3128. }
  3129. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3130. return _vector$2.distanceToSquared(point);
  3131. };
  3132. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3133. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3134. // It returns the min distance between the ray and the segment
  3135. // defined by v0 and v1
  3136. // It can also set two optional targets :
  3137. // - The closest point on the ray
  3138. // - The closest point on the segment
  3139. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3140. _segDir.copy(v1).sub(v0).normalize();
  3141. _diff.copy(this.origin).sub(_segCenter);
  3142. var segExtent = v0.distanceTo(v1) * 0.5;
  3143. var a01 = -this.direction.dot(_segDir);
  3144. var b0 = _diff.dot(this.direction);
  3145. var b1 = -_diff.dot(_segDir);
  3146. var c = _diff.lengthSq();
  3147. var det = Math.abs(1 - a01 * a01);
  3148. var s0, s1, sqrDist, extDet;
  3149. if (det > 0) {
  3150. // The ray and segment are not parallel.
  3151. s0 = a01 * b1 - b0;
  3152. s1 = a01 * b0 - b1;
  3153. extDet = segExtent * det;
  3154. if (s0 >= 0) {
  3155. if (s1 >= -extDet) {
  3156. if (s1 <= extDet) {
  3157. // region 0
  3158. // Minimum at interior points of ray and segment.
  3159. var invDet = 1 / det;
  3160. s0 *= invDet;
  3161. s1 *= invDet;
  3162. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3163. } else {
  3164. // region 1
  3165. s1 = segExtent;
  3166. s0 = Math.max(0, -(a01 * s1 + b0));
  3167. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3168. }
  3169. } else {
  3170. // region 5
  3171. s1 = -segExtent;
  3172. s0 = Math.max(0, -(a01 * s1 + b0));
  3173. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3174. }
  3175. } else {
  3176. if (s1 <= -extDet) {
  3177. // region 4
  3178. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3179. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3180. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3181. } else if (s1 <= extDet) {
  3182. // region 3
  3183. s0 = 0;
  3184. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3185. sqrDist = s1 * (s1 + 2 * b1) + c;
  3186. } else {
  3187. // region 2
  3188. s0 = Math.max(0, -(a01 * segExtent + b0));
  3189. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3190. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3191. }
  3192. }
  3193. } else {
  3194. // Ray and segment are parallel.
  3195. s1 = a01 > 0 ? -segExtent : segExtent;
  3196. s0 = Math.max(0, -(a01 * s1 + b0));
  3197. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3198. }
  3199. if (optionalPointOnRay) {
  3200. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3201. }
  3202. if (optionalPointOnSegment) {
  3203. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3204. }
  3205. return sqrDist;
  3206. };
  3207. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3208. _vector$2.subVectors(sphere.center, this.origin);
  3209. var tca = _vector$2.dot(this.direction);
  3210. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3211. var radius2 = sphere.radius * sphere.radius;
  3212. if (d2 > radius2) return null;
  3213. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3214. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3215. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3216. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3217. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3218. // in order to always return an intersect point that is in front of the ray.
  3219. if (t0 < 0) return this.at(t1, target); // else t0 is in front of the ray, so return the first collision point scaled by t0
  3220. return this.at(t0, target);
  3221. };
  3222. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3223. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3224. };
  3225. _proto.distanceToPlane = function distanceToPlane(plane) {
  3226. var denominator = plane.normal.dot(this.direction);
  3227. if (denominator === 0) {
  3228. // line is coplanar, return origin
  3229. if (plane.distanceToPoint(this.origin) === 0) {
  3230. return 0;
  3231. } // Null is preferable to undefined since undefined means.... it is undefined
  3232. return null;
  3233. }
  3234. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3235. return t >= 0 ? t : null;
  3236. };
  3237. _proto.intersectPlane = function intersectPlane(plane, target) {
  3238. var t = this.distanceToPlane(plane);
  3239. if (t === null) {
  3240. return null;
  3241. }
  3242. return this.at(t, target);
  3243. };
  3244. _proto.intersectsPlane = function intersectsPlane(plane) {
  3245. // check if the ray lies on the plane first
  3246. var distToPoint = plane.distanceToPoint(this.origin);
  3247. if (distToPoint === 0) {
  3248. return true;
  3249. }
  3250. var denominator = plane.normal.dot(this.direction);
  3251. if (denominator * distToPoint < 0) {
  3252. return true;
  3253. } // ray origin is behind the plane (and is pointing behind it)
  3254. return false;
  3255. };
  3256. _proto.intersectBox = function intersectBox(box, target) {
  3257. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3258. var invdirx = 1 / this.direction.x,
  3259. invdiry = 1 / this.direction.y,
  3260. invdirz = 1 / this.direction.z;
  3261. var origin = this.origin;
  3262. if (invdirx >= 0) {
  3263. tmin = (box.min.x - origin.x) * invdirx;
  3264. tmax = (box.max.x - origin.x) * invdirx;
  3265. } else {
  3266. tmin = (box.max.x - origin.x) * invdirx;
  3267. tmax = (box.min.x - origin.x) * invdirx;
  3268. }
  3269. if (invdiry >= 0) {
  3270. tymin = (box.min.y - origin.y) * invdiry;
  3271. tymax = (box.max.y - origin.y) * invdiry;
  3272. } else {
  3273. tymin = (box.max.y - origin.y) * invdiry;
  3274. tymax = (box.min.y - origin.y) * invdiry;
  3275. }
  3276. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  3277. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3278. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  3279. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  3280. if (invdirz >= 0) {
  3281. tzmin = (box.min.z - origin.z) * invdirz;
  3282. tzmax = (box.max.z - origin.z) * invdirz;
  3283. } else {
  3284. tzmin = (box.max.z - origin.z) * invdirz;
  3285. tzmax = (box.min.z - origin.z) * invdirz;
  3286. }
  3287. if (tmin > tzmax || tzmin > tmax) return null;
  3288. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  3289. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  3290. if (tmax < 0) return null;
  3291. return this.at(tmin >= 0 ? tmin : tmax, target);
  3292. };
  3293. _proto.intersectsBox = function intersectsBox(box) {
  3294. return this.intersectBox(box, _vector$2) !== null;
  3295. };
  3296. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  3297. // Compute the offset origin, edges, and normal.
  3298. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3299. _edge1.subVectors(b, a);
  3300. _edge2.subVectors(c, a);
  3301. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3302. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3303. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3304. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3305. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3306. var DdN = this.direction.dot(_normal);
  3307. var sign;
  3308. if (DdN > 0) {
  3309. if (backfaceCulling) return null;
  3310. sign = 1;
  3311. } else if (DdN < 0) {
  3312. sign = -1;
  3313. DdN = -DdN;
  3314. } else {
  3315. return null;
  3316. }
  3317. _diff.subVectors(this.origin, a);
  3318. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  3319. if (DdQxE2 < 0) {
  3320. return null;
  3321. }
  3322. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  3323. if (DdE1xQ < 0) {
  3324. return null;
  3325. } // b1+b2 > 1, no intersection
  3326. if (DdQxE2 + DdE1xQ > DdN) {
  3327. return null;
  3328. } // Line intersects triangle, check if ray does.
  3329. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  3330. if (QdN < 0) {
  3331. return null;
  3332. } // Ray intersects triangle.
  3333. return this.at(QdN / DdN, target);
  3334. };
  3335. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  3336. this.origin.applyMatrix4(matrix4);
  3337. this.direction.transformDirection(matrix4);
  3338. return this;
  3339. };
  3340. _proto.equals = function equals(ray) {
  3341. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  3342. };
  3343. return Ray;
  3344. }();
  3345. var Matrix4 = /*#__PURE__*/function () {
  3346. function Matrix4() {
  3347. Object.defineProperty(this, 'isMatrix4', {
  3348. value: true
  3349. });
  3350. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  3351. if (arguments.length > 0) {
  3352. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  3353. }
  3354. }
  3355. var _proto = Matrix4.prototype;
  3356. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  3357. var te = this.elements;
  3358. te[0] = n11;
  3359. te[4] = n12;
  3360. te[8] = n13;
  3361. te[12] = n14;
  3362. te[1] = n21;
  3363. te[5] = n22;
  3364. te[9] = n23;
  3365. te[13] = n24;
  3366. te[2] = n31;
  3367. te[6] = n32;
  3368. te[10] = n33;
  3369. te[14] = n34;
  3370. te[3] = n41;
  3371. te[7] = n42;
  3372. te[11] = n43;
  3373. te[15] = n44;
  3374. return this;
  3375. };
  3376. _proto.identity = function identity() {
  3377. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3378. return this;
  3379. };
  3380. _proto.clone = function clone() {
  3381. return new Matrix4().fromArray(this.elements);
  3382. };
  3383. _proto.copy = function copy(m) {
  3384. var te = this.elements;
  3385. var me = m.elements;
  3386. te[0] = me[0];
  3387. te[1] = me[1];
  3388. te[2] = me[2];
  3389. te[3] = me[3];
  3390. te[4] = me[4];
  3391. te[5] = me[5];
  3392. te[6] = me[6];
  3393. te[7] = me[7];
  3394. te[8] = me[8];
  3395. te[9] = me[9];
  3396. te[10] = me[10];
  3397. te[11] = me[11];
  3398. te[12] = me[12];
  3399. te[13] = me[13];
  3400. te[14] = me[14];
  3401. te[15] = me[15];
  3402. return this;
  3403. };
  3404. _proto.copyPosition = function copyPosition(m) {
  3405. var te = this.elements,
  3406. me = m.elements;
  3407. te[12] = me[12];
  3408. te[13] = me[13];
  3409. te[14] = me[14];
  3410. return this;
  3411. };
  3412. _proto.setFromMatrix3 = function setFromMatrix3(m) {
  3413. var me = m.elements;
  3414. this.set(me[0], me[3], me[6], 0, me[1], me[4], me[7], 0, me[2], me[5], me[8], 0, 0, 0, 0, 1);
  3415. return this;
  3416. };
  3417. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  3418. xAxis.setFromMatrixColumn(this, 0);
  3419. yAxis.setFromMatrixColumn(this, 1);
  3420. zAxis.setFromMatrixColumn(this, 2);
  3421. return this;
  3422. };
  3423. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  3424. this.set(xAxis.x, yAxis.x, zAxis.x, 0, xAxis.y, yAxis.y, zAxis.y, 0, xAxis.z, yAxis.z, zAxis.z, 0, 0, 0, 0, 1);
  3425. return this;
  3426. };
  3427. _proto.extractRotation = function extractRotation(m) {
  3428. // this method does not support reflection matrices
  3429. var te = this.elements;
  3430. var me = m.elements;
  3431. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  3432. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  3433. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  3434. te[0] = me[0] * scaleX;
  3435. te[1] = me[1] * scaleX;
  3436. te[2] = me[2] * scaleX;
  3437. te[3] = 0;
  3438. te[4] = me[4] * scaleY;
  3439. te[5] = me[5] * scaleY;
  3440. te[6] = me[6] * scaleY;
  3441. te[7] = 0;
  3442. te[8] = me[8] * scaleZ;
  3443. te[9] = me[9] * scaleZ;
  3444. te[10] = me[10] * scaleZ;
  3445. te[11] = 0;
  3446. te[12] = 0;
  3447. te[13] = 0;
  3448. te[14] = 0;
  3449. te[15] = 1;
  3450. return this;
  3451. };
  3452. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  3453. if (!(euler && euler.isEuler)) {
  3454. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  3455. }
  3456. var te = this.elements;
  3457. var x = euler.x,
  3458. y = euler.y,
  3459. z = euler.z;
  3460. var a = Math.cos(x),
  3461. b = Math.sin(x);
  3462. var c = Math.cos(y),
  3463. d = Math.sin(y);
  3464. var e = Math.cos(z),
  3465. f = Math.sin(z);
  3466. if (euler.order === 'XYZ') {
  3467. var ae = a * e,
  3468. af = a * f,
  3469. be = b * e,
  3470. bf = b * f;
  3471. te[0] = c * e;
  3472. te[4] = -c * f;
  3473. te[8] = d;
  3474. te[1] = af + be * d;
  3475. te[5] = ae - bf * d;
  3476. te[9] = -b * c;
  3477. te[2] = bf - ae * d;
  3478. te[6] = be + af * d;
  3479. te[10] = a * c;
  3480. } else if (euler.order === 'YXZ') {
  3481. var ce = c * e,
  3482. cf = c * f,
  3483. de = d * e,
  3484. df = d * f;
  3485. te[0] = ce + df * b;
  3486. te[4] = de * b - cf;
  3487. te[8] = a * d;
  3488. te[1] = a * f;
  3489. te[5] = a * e;
  3490. te[9] = -b;
  3491. te[2] = cf * b - de;
  3492. te[6] = df + ce * b;
  3493. te[10] = a * c;
  3494. } else if (euler.order === 'ZXY') {
  3495. var _ce = c * e,
  3496. _cf = c * f,
  3497. _de = d * e,
  3498. _df = d * f;
  3499. te[0] = _ce - _df * b;
  3500. te[4] = -a * f;
  3501. te[8] = _de + _cf * b;
  3502. te[1] = _cf + _de * b;
  3503. te[5] = a * e;
  3504. te[9] = _df - _ce * b;
  3505. te[2] = -a * d;
  3506. te[6] = b;
  3507. te[10] = a * c;
  3508. } else if (euler.order === 'ZYX') {
  3509. var _ae = a * e,
  3510. _af = a * f,
  3511. _be = b * e,
  3512. _bf = b * f;
  3513. te[0] = c * e;
  3514. te[4] = _be * d - _af;
  3515. te[8] = _ae * d + _bf;
  3516. te[1] = c * f;
  3517. te[5] = _bf * d + _ae;
  3518. te[9] = _af * d - _be;
  3519. te[2] = -d;
  3520. te[6] = b * c;
  3521. te[10] = a * c;
  3522. } else if (euler.order === 'YZX') {
  3523. var ac = a * c,
  3524. ad = a * d,
  3525. bc = b * c,
  3526. bd = b * d;
  3527. te[0] = c * e;
  3528. te[4] = bd - ac * f;
  3529. te[8] = bc * f + ad;
  3530. te[1] = f;
  3531. te[5] = a * e;
  3532. te[9] = -b * e;
  3533. te[2] = -d * e;
  3534. te[6] = ad * f + bc;
  3535. te[10] = ac - bd * f;
  3536. } else if (euler.order === 'XZY') {
  3537. var _ac = a * c,
  3538. _ad = a * d,
  3539. _bc = b * c,
  3540. _bd = b * d;
  3541. te[0] = c * e;
  3542. te[4] = -f;
  3543. te[8] = d * e;
  3544. te[1] = _ac * f + _bd;
  3545. te[5] = a * e;
  3546. te[9] = _ad * f - _bc;
  3547. te[2] = _bc * f - _ad;
  3548. te[6] = b * e;
  3549. te[10] = _bd * f + _ac;
  3550. } // bottom row
  3551. te[3] = 0;
  3552. te[7] = 0;
  3553. te[11] = 0; // last column
  3554. te[12] = 0;
  3555. te[13] = 0;
  3556. te[14] = 0;
  3557. te[15] = 1;
  3558. return this;
  3559. };
  3560. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  3561. return this.compose(_zero, q, _one);
  3562. };
  3563. _proto.lookAt = function lookAt(eye, target, up) {
  3564. var te = this.elements;
  3565. _z.subVectors(eye, target);
  3566. if (_z.lengthSq() === 0) {
  3567. // eye and target are in the same position
  3568. _z.z = 1;
  3569. }
  3570. _z.normalize();
  3571. _x.crossVectors(up, _z);
  3572. if (_x.lengthSq() === 0) {
  3573. // up and z are parallel
  3574. if (Math.abs(up.z) === 1) {
  3575. _z.x += 0.0001;
  3576. } else {
  3577. _z.z += 0.0001;
  3578. }
  3579. _z.normalize();
  3580. _x.crossVectors(up, _z);
  3581. }
  3582. _x.normalize();
  3583. _y.crossVectors(_z, _x);
  3584. te[0] = _x.x;
  3585. te[4] = _y.x;
  3586. te[8] = _z.x;
  3587. te[1] = _x.y;
  3588. te[5] = _y.y;
  3589. te[9] = _z.y;
  3590. te[2] = _x.z;
  3591. te[6] = _y.z;
  3592. te[10] = _z.z;
  3593. return this;
  3594. };
  3595. _proto.multiply = function multiply(m, n) {
  3596. if (n !== undefined) {
  3597. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  3598. return this.multiplyMatrices(m, n);
  3599. }
  3600. return this.multiplyMatrices(this, m);
  3601. };
  3602. _proto.premultiply = function premultiply(m) {
  3603. return this.multiplyMatrices(m, this);
  3604. };
  3605. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  3606. var ae = a.elements;
  3607. var be = b.elements;
  3608. var te = this.elements;
  3609. var a11 = ae[0],
  3610. a12 = ae[4],
  3611. a13 = ae[8],
  3612. a14 = ae[12];
  3613. var a21 = ae[1],
  3614. a22 = ae[5],
  3615. a23 = ae[9],
  3616. a24 = ae[13];
  3617. var a31 = ae[2],
  3618. a32 = ae[6],
  3619. a33 = ae[10],
  3620. a34 = ae[14];
  3621. var a41 = ae[3],
  3622. a42 = ae[7],
  3623. a43 = ae[11],
  3624. a44 = ae[15];
  3625. var b11 = be[0],
  3626. b12 = be[4],
  3627. b13 = be[8],
  3628. b14 = be[12];
  3629. var b21 = be[1],
  3630. b22 = be[5],
  3631. b23 = be[9],
  3632. b24 = be[13];
  3633. var b31 = be[2],
  3634. b32 = be[6],
  3635. b33 = be[10],
  3636. b34 = be[14];
  3637. var b41 = be[3],
  3638. b42 = be[7],
  3639. b43 = be[11],
  3640. b44 = be[15];
  3641. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3642. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3643. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3644. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3645. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3646. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3647. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3648. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3649. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3650. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3651. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3652. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3653. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3654. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3655. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3656. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3657. return this;
  3658. };
  3659. _proto.multiplyScalar = function multiplyScalar(s) {
  3660. var te = this.elements;
  3661. te[0] *= s;
  3662. te[4] *= s;
  3663. te[8] *= s;
  3664. te[12] *= s;
  3665. te[1] *= s;
  3666. te[5] *= s;
  3667. te[9] *= s;
  3668. te[13] *= s;
  3669. te[2] *= s;
  3670. te[6] *= s;
  3671. te[10] *= s;
  3672. te[14] *= s;
  3673. te[3] *= s;
  3674. te[7] *= s;
  3675. te[11] *= s;
  3676. te[15] *= s;
  3677. return this;
  3678. };
  3679. _proto.determinant = function determinant() {
  3680. var te = this.elements;
  3681. var n11 = te[0],
  3682. n12 = te[4],
  3683. n13 = te[8],
  3684. n14 = te[12];
  3685. var n21 = te[1],
  3686. n22 = te[5],
  3687. n23 = te[9],
  3688. n24 = te[13];
  3689. var n31 = te[2],
  3690. n32 = te[6],
  3691. n33 = te[10],
  3692. n34 = te[14];
  3693. var n41 = te[3],
  3694. n42 = te[7],
  3695. n43 = te[11],
  3696. n44 = te[15]; //TODO: make this more efficient
  3697. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3698. return n41 * (+n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34) + n42 * (+n11 * n23 * n34 - n11 * n24 * n33 + n14 * n21 * n33 - n13 * n21 * n34 + n13 * n24 * n31 - n14 * n23 * n31) + n43 * (+n11 * n24 * n32 - n11 * n22 * n34 - n14 * n21 * n32 + n12 * n21 * n34 + n14 * n22 * n31 - n12 * n24 * n31) + n44 * (-n13 * n22 * n31 - n11 * n23 * n32 + n11 * n22 * n33 + n13 * n21 * n32 - n12 * n21 * n33 + n12 * n23 * n31);
  3699. };
  3700. _proto.transpose = function transpose() {
  3701. var te = this.elements;
  3702. var tmp;
  3703. tmp = te[1];
  3704. te[1] = te[4];
  3705. te[4] = tmp;
  3706. tmp = te[2];
  3707. te[2] = te[8];
  3708. te[8] = tmp;
  3709. tmp = te[6];
  3710. te[6] = te[9];
  3711. te[9] = tmp;
  3712. tmp = te[3];
  3713. te[3] = te[12];
  3714. te[12] = tmp;
  3715. tmp = te[7];
  3716. te[7] = te[13];
  3717. te[13] = tmp;
  3718. tmp = te[11];
  3719. te[11] = te[14];
  3720. te[14] = tmp;
  3721. return this;
  3722. };
  3723. _proto.setPosition = function setPosition(x, y, z) {
  3724. var te = this.elements;
  3725. if (x.isVector3) {
  3726. te[12] = x.x;
  3727. te[13] = x.y;
  3728. te[14] = x.z;
  3729. } else {
  3730. te[12] = x;
  3731. te[13] = y;
  3732. te[14] = z;
  3733. }
  3734. return this;
  3735. };
  3736. _proto.invert = function invert() {
  3737. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3738. var te = this.elements,
  3739. n11 = te[0],
  3740. n21 = te[1],
  3741. n31 = te[2],
  3742. n41 = te[3],
  3743. n12 = te[4],
  3744. n22 = te[5],
  3745. n32 = te[6],
  3746. n42 = te[7],
  3747. n13 = te[8],
  3748. n23 = te[9],
  3749. n33 = te[10],
  3750. n43 = te[11],
  3751. n14 = te[12],
  3752. n24 = te[13],
  3753. n34 = te[14],
  3754. n44 = te[15],
  3755. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3756. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3757. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3758. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3759. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3760. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  3761. var detInv = 1 / det;
  3762. te[0] = t11 * detInv;
  3763. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  3764. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  3765. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  3766. te[4] = t12 * detInv;
  3767. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  3768. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  3769. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  3770. te[8] = t13 * detInv;
  3771. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  3772. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  3773. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  3774. te[12] = t14 * detInv;
  3775. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  3776. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  3777. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  3778. return this;
  3779. };
  3780. _proto.scale = function scale(v) {
  3781. var te = this.elements;
  3782. var x = v.x,
  3783. y = v.y,
  3784. z = v.z;
  3785. te[0] *= x;
  3786. te[4] *= y;
  3787. te[8] *= z;
  3788. te[1] *= x;
  3789. te[5] *= y;
  3790. te[9] *= z;
  3791. te[2] *= x;
  3792. te[6] *= y;
  3793. te[10] *= z;
  3794. te[3] *= x;
  3795. te[7] *= y;
  3796. te[11] *= z;
  3797. return this;
  3798. };
  3799. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  3800. var te = this.elements;
  3801. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  3802. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  3803. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  3804. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  3805. };
  3806. _proto.makeTranslation = function makeTranslation(x, y, z) {
  3807. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  3808. return this;
  3809. };
  3810. _proto.makeRotationX = function makeRotationX(theta) {
  3811. var c = Math.cos(theta),
  3812. s = Math.sin(theta);
  3813. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  3814. return this;
  3815. };
  3816. _proto.makeRotationY = function makeRotationY(theta) {
  3817. var c = Math.cos(theta),
  3818. s = Math.sin(theta);
  3819. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  3820. return this;
  3821. };
  3822. _proto.makeRotationZ = function makeRotationZ(theta) {
  3823. var c = Math.cos(theta),
  3824. s = Math.sin(theta);
  3825. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3826. return this;
  3827. };
  3828. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  3829. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3830. var c = Math.cos(angle);
  3831. var s = Math.sin(angle);
  3832. var t = 1 - c;
  3833. var x = axis.x,
  3834. y = axis.y,
  3835. z = axis.z;
  3836. var tx = t * x,
  3837. ty = t * y;
  3838. this.set(tx * x + c, tx * y - s * z, tx * z + s * y, 0, tx * y + s * z, ty * y + c, ty * z - s * x, 0, tx * z - s * y, ty * z + s * x, t * z * z + c, 0, 0, 0, 0, 1);
  3839. return this;
  3840. };
  3841. _proto.makeScale = function makeScale(x, y, z) {
  3842. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  3843. return this;
  3844. };
  3845. _proto.makeShear = function makeShear(x, y, z) {
  3846. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  3847. return this;
  3848. };
  3849. _proto.compose = function compose(position, quaternion, scale) {
  3850. var te = this.elements;
  3851. var x = quaternion._x,
  3852. y = quaternion._y,
  3853. z = quaternion._z,
  3854. w = quaternion._w;
  3855. var x2 = x + x,
  3856. y2 = y + y,
  3857. z2 = z + z;
  3858. var xx = x * x2,
  3859. xy = x * y2,
  3860. xz = x * z2;
  3861. var yy = y * y2,
  3862. yz = y * z2,
  3863. zz = z * z2;
  3864. var wx = w * x2,
  3865. wy = w * y2,
  3866. wz = w * z2;
  3867. var sx = scale.x,
  3868. sy = scale.y,
  3869. sz = scale.z;
  3870. te[0] = (1 - (yy + zz)) * sx;
  3871. te[1] = (xy + wz) * sx;
  3872. te[2] = (xz - wy) * sx;
  3873. te[3] = 0;
  3874. te[4] = (xy - wz) * sy;
  3875. te[5] = (1 - (xx + zz)) * sy;
  3876. te[6] = (yz + wx) * sy;
  3877. te[7] = 0;
  3878. te[8] = (xz + wy) * sz;
  3879. te[9] = (yz - wx) * sz;
  3880. te[10] = (1 - (xx + yy)) * sz;
  3881. te[11] = 0;
  3882. te[12] = position.x;
  3883. te[13] = position.y;
  3884. te[14] = position.z;
  3885. te[15] = 1;
  3886. return this;
  3887. };
  3888. _proto.decompose = function decompose(position, quaternion, scale) {
  3889. var te = this.elements;
  3890. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  3891. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  3892. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  3893. var det = this.determinant();
  3894. if (det < 0) sx = -sx;
  3895. position.x = te[12];
  3896. position.y = te[13];
  3897. position.z = te[14]; // scale the rotation part
  3898. _m1.copy(this);
  3899. var invSX = 1 / sx;
  3900. var invSY = 1 / sy;
  3901. var invSZ = 1 / sz;
  3902. _m1.elements[0] *= invSX;
  3903. _m1.elements[1] *= invSX;
  3904. _m1.elements[2] *= invSX;
  3905. _m1.elements[4] *= invSY;
  3906. _m1.elements[5] *= invSY;
  3907. _m1.elements[6] *= invSY;
  3908. _m1.elements[8] *= invSZ;
  3909. _m1.elements[9] *= invSZ;
  3910. _m1.elements[10] *= invSZ;
  3911. quaternion.setFromRotationMatrix(_m1);
  3912. scale.x = sx;
  3913. scale.y = sy;
  3914. scale.z = sz;
  3915. return this;
  3916. };
  3917. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  3918. if (far === undefined) {
  3919. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  3920. }
  3921. var te = this.elements;
  3922. var x = 2 * near / (right - left);
  3923. var y = 2 * near / (top - bottom);
  3924. var a = (right + left) / (right - left);
  3925. var b = (top + bottom) / (top - bottom);
  3926. var c = -(far + near) / (far - near);
  3927. var d = -2 * far * near / (far - near);
  3928. te[0] = x;
  3929. te[4] = 0;
  3930. te[8] = a;
  3931. te[12] = 0;
  3932. te[1] = 0;
  3933. te[5] = y;
  3934. te[9] = b;
  3935. te[13] = 0;
  3936. te[2] = 0;
  3937. te[6] = 0;
  3938. te[10] = c;
  3939. te[14] = d;
  3940. te[3] = 0;
  3941. te[7] = 0;
  3942. te[11] = -1;
  3943. te[15] = 0;
  3944. return this;
  3945. };
  3946. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  3947. var te = this.elements;
  3948. var w = 1.0 / (right - left);
  3949. var h = 1.0 / (top - bottom);
  3950. var p = 1.0 / (far - near);
  3951. var x = (right + left) * w;
  3952. var y = (top + bottom) * h;
  3953. var z = (far + near) * p;
  3954. te[0] = 2 * w;
  3955. te[4] = 0;
  3956. te[8] = 0;
  3957. te[12] = -x;
  3958. te[1] = 0;
  3959. te[5] = 2 * h;
  3960. te[9] = 0;
  3961. te[13] = -y;
  3962. te[2] = 0;
  3963. te[6] = 0;
  3964. te[10] = -2 * p;
  3965. te[14] = -z;
  3966. te[3] = 0;
  3967. te[7] = 0;
  3968. te[11] = 0;
  3969. te[15] = 1;
  3970. return this;
  3971. };
  3972. _proto.equals = function equals(matrix) {
  3973. var te = this.elements;
  3974. var me = matrix.elements;
  3975. for (var i = 0; i < 16; i++) {
  3976. if (te[i] !== me[i]) return false;
  3977. }
  3978. return true;
  3979. };
  3980. _proto.fromArray = function fromArray(array, offset) {
  3981. if (offset === void 0) {
  3982. offset = 0;
  3983. }
  3984. for (var i = 0; i < 16; i++) {
  3985. this.elements[i] = array[i + offset];
  3986. }
  3987. return this;
  3988. };
  3989. _proto.toArray = function toArray(array, offset) {
  3990. if (array === void 0) {
  3991. array = [];
  3992. }
  3993. if (offset === void 0) {
  3994. offset = 0;
  3995. }
  3996. var te = this.elements;
  3997. array[offset] = te[0];
  3998. array[offset + 1] = te[1];
  3999. array[offset + 2] = te[2];
  4000. array[offset + 3] = te[3];
  4001. array[offset + 4] = te[4];
  4002. array[offset + 5] = te[5];
  4003. array[offset + 6] = te[6];
  4004. array[offset + 7] = te[7];
  4005. array[offset + 8] = te[8];
  4006. array[offset + 9] = te[9];
  4007. array[offset + 10] = te[10];
  4008. array[offset + 11] = te[11];
  4009. array[offset + 12] = te[12];
  4010. array[offset + 13] = te[13];
  4011. array[offset + 14] = te[14];
  4012. array[offset + 15] = te[15];
  4013. return array;
  4014. };
  4015. return Matrix4;
  4016. }();
  4017. var _v1$1 = /*@__PURE__*/new Vector3();
  4018. var _m1 = /*@__PURE__*/new Matrix4();
  4019. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  4020. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  4021. var _x = /*@__PURE__*/new Vector3();
  4022. var _y = /*@__PURE__*/new Vector3();
  4023. var _z = /*@__PURE__*/new Vector3();
  4024. var Euler = /*#__PURE__*/function () {
  4025. function Euler(x, y, z, order) {
  4026. if (x === void 0) {
  4027. x = 0;
  4028. }
  4029. if (y === void 0) {
  4030. y = 0;
  4031. }
  4032. if (z === void 0) {
  4033. z = 0;
  4034. }
  4035. if (order === void 0) {
  4036. order = Euler.DefaultOrder;
  4037. }
  4038. Object.defineProperty(this, 'isEuler', {
  4039. value: true
  4040. });
  4041. this._x = x;
  4042. this._y = y;
  4043. this._z = z;
  4044. this._order = order;
  4045. }
  4046. var _proto = Euler.prototype;
  4047. _proto.set = function set(x, y, z, order) {
  4048. this._x = x;
  4049. this._y = y;
  4050. this._z = z;
  4051. this._order = order || this._order;
  4052. this._onChangeCallback();
  4053. return this;
  4054. };
  4055. _proto.clone = function clone() {
  4056. return new this.constructor(this._x, this._y, this._z, this._order);
  4057. };
  4058. _proto.copy = function copy(euler) {
  4059. this._x = euler._x;
  4060. this._y = euler._y;
  4061. this._z = euler._z;
  4062. this._order = euler._order;
  4063. this._onChangeCallback();
  4064. return this;
  4065. };
  4066. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4067. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4068. var te = m.elements;
  4069. var m11 = te[0],
  4070. m12 = te[4],
  4071. m13 = te[8];
  4072. var m21 = te[1],
  4073. m22 = te[5],
  4074. m23 = te[9];
  4075. var m31 = te[2],
  4076. m32 = te[6],
  4077. m33 = te[10];
  4078. order = order || this._order;
  4079. switch (order) {
  4080. case 'XYZ':
  4081. this._y = Math.asin(clamp(m13, -1, 1));
  4082. if (Math.abs(m13) < 0.9999999) {
  4083. this._x = Math.atan2(-m23, m33);
  4084. this._z = Math.atan2(-m12, m11);
  4085. } else {
  4086. this._x = Math.atan2(m32, m22);
  4087. this._z = 0;
  4088. }
  4089. break;
  4090. case 'YXZ':
  4091. this._x = Math.asin(-clamp(m23, -1, 1));
  4092. if (Math.abs(m23) < 0.9999999) {
  4093. this._y = Math.atan2(m13, m33);
  4094. this._z = Math.atan2(m21, m22);
  4095. } else {
  4096. this._y = Math.atan2(-m31, m11);
  4097. this._z = 0;
  4098. }
  4099. break;
  4100. case 'ZXY':
  4101. this._x = Math.asin(clamp(m32, -1, 1));
  4102. if (Math.abs(m32) < 0.9999999) {
  4103. this._y = Math.atan2(-m31, m33);
  4104. this._z = Math.atan2(-m12, m22);
  4105. } else {
  4106. this._y = 0;
  4107. this._z = Math.atan2(m21, m11);
  4108. }
  4109. break;
  4110. case 'ZYX':
  4111. this._y = Math.asin(-clamp(m31, -1, 1));
  4112. if (Math.abs(m31) < 0.9999999) {
  4113. this._x = Math.atan2(m32, m33);
  4114. this._z = Math.atan2(m21, m11);
  4115. } else {
  4116. this._x = 0;
  4117. this._z = Math.atan2(-m12, m22);
  4118. }
  4119. break;
  4120. case 'YZX':
  4121. this._z = Math.asin(clamp(m21, -1, 1));
  4122. if (Math.abs(m21) < 0.9999999) {
  4123. this._x = Math.atan2(-m23, m22);
  4124. this._y = Math.atan2(-m31, m11);
  4125. } else {
  4126. this._x = 0;
  4127. this._y = Math.atan2(m13, m33);
  4128. }
  4129. break;
  4130. case 'XZY':
  4131. this._z = Math.asin(-clamp(m12, -1, 1));
  4132. if (Math.abs(m12) < 0.9999999) {
  4133. this._x = Math.atan2(m32, m22);
  4134. this._y = Math.atan2(m13, m11);
  4135. } else {
  4136. this._x = Math.atan2(-m23, m33);
  4137. this._y = 0;
  4138. }
  4139. break;
  4140. default:
  4141. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4142. }
  4143. this._order = order;
  4144. if (update !== false) this._onChangeCallback();
  4145. return this;
  4146. };
  4147. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4148. _matrix.makeRotationFromQuaternion(q);
  4149. return this.setFromRotationMatrix(_matrix, order, update);
  4150. };
  4151. _proto.setFromVector3 = function setFromVector3(v, order) {
  4152. return this.set(v.x, v.y, v.z, order || this._order);
  4153. };
  4154. _proto.reorder = function reorder(newOrder) {
  4155. // WARNING: this discards revolution information -bhouston
  4156. _quaternion$1.setFromEuler(this);
  4157. return this.setFromQuaternion(_quaternion$1, newOrder);
  4158. };
  4159. _proto.equals = function equals(euler) {
  4160. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4161. };
  4162. _proto.fromArray = function fromArray(array) {
  4163. this._x = array[0];
  4164. this._y = array[1];
  4165. this._z = array[2];
  4166. if (array[3] !== undefined) this._order = array[3];
  4167. this._onChangeCallback();
  4168. return this;
  4169. };
  4170. _proto.toArray = function toArray(array, offset) {
  4171. if (array === void 0) {
  4172. array = [];
  4173. }
  4174. if (offset === void 0) {
  4175. offset = 0;
  4176. }
  4177. array[offset] = this._x;
  4178. array[offset + 1] = this._y;
  4179. array[offset + 2] = this._z;
  4180. array[offset + 3] = this._order;
  4181. return array;
  4182. };
  4183. _proto.toVector3 = function toVector3(optionalResult) {
  4184. if (optionalResult) {
  4185. return optionalResult.set(this._x, this._y, this._z);
  4186. } else {
  4187. return new Vector3(this._x, this._y, this._z);
  4188. }
  4189. };
  4190. _proto._onChange = function _onChange(callback) {
  4191. this._onChangeCallback = callback;
  4192. return this;
  4193. };
  4194. _proto._onChangeCallback = function _onChangeCallback() {};
  4195. _createClass(Euler, [{
  4196. key: "x",
  4197. get: function get() {
  4198. return this._x;
  4199. },
  4200. set: function set(value) {
  4201. this._x = value;
  4202. this._onChangeCallback();
  4203. }
  4204. }, {
  4205. key: "y",
  4206. get: function get() {
  4207. return this._y;
  4208. },
  4209. set: function set(value) {
  4210. this._y = value;
  4211. this._onChangeCallback();
  4212. }
  4213. }, {
  4214. key: "z",
  4215. get: function get() {
  4216. return this._z;
  4217. },
  4218. set: function set(value) {
  4219. this._z = value;
  4220. this._onChangeCallback();
  4221. }
  4222. }, {
  4223. key: "order",
  4224. get: function get() {
  4225. return this._order;
  4226. },
  4227. set: function set(value) {
  4228. this._order = value;
  4229. this._onChangeCallback();
  4230. }
  4231. }]);
  4232. return Euler;
  4233. }();
  4234. Euler.DefaultOrder = 'XYZ';
  4235. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4236. var _matrix = /*@__PURE__*/new Matrix4();
  4237. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4238. var Layers = /*#__PURE__*/function () {
  4239. function Layers() {
  4240. this.mask = 1 | 0;
  4241. }
  4242. var _proto = Layers.prototype;
  4243. _proto.set = function set(channel) {
  4244. this.mask = 1 << channel | 0;
  4245. };
  4246. _proto.enable = function enable(channel) {
  4247. this.mask |= 1 << channel | 0;
  4248. };
  4249. _proto.enableAll = function enableAll() {
  4250. this.mask = 0xffffffff | 0;
  4251. };
  4252. _proto.toggle = function toggle(channel) {
  4253. this.mask ^= 1 << channel | 0;
  4254. };
  4255. _proto.disable = function disable(channel) {
  4256. this.mask &= ~(1 << channel | 0);
  4257. };
  4258. _proto.disableAll = function disableAll() {
  4259. this.mask = 0;
  4260. };
  4261. _proto.test = function test(layers) {
  4262. return (this.mask & layers.mask) !== 0;
  4263. };
  4264. return Layers;
  4265. }();
  4266. var _object3DId = 0;
  4267. var _v1$2 = new Vector3();
  4268. var _q1 = new Quaternion();
  4269. var _m1$1 = new Matrix4();
  4270. var _target = new Vector3();
  4271. var _position = new Vector3();
  4272. var _scale = new Vector3();
  4273. var _quaternion$2 = new Quaternion();
  4274. var _xAxis = new Vector3(1, 0, 0);
  4275. var _yAxis = new Vector3(0, 1, 0);
  4276. var _zAxis = new Vector3(0, 0, 1);
  4277. var _addedEvent = {
  4278. type: 'added'
  4279. };
  4280. var _removedEvent = {
  4281. type: 'removed'
  4282. };
  4283. function Object3D() {
  4284. Object.defineProperty(this, 'id', {
  4285. value: _object3DId++
  4286. });
  4287. this.uuid = MathUtils.generateUUID();
  4288. this.name = '';
  4289. this.type = 'Object3D';
  4290. this.parent = null;
  4291. this.children = [];
  4292. this.up = Object3D.DefaultUp.clone();
  4293. var position = new Vector3();
  4294. var rotation = new Euler();
  4295. var quaternion = new Quaternion();
  4296. var scale = new Vector3(1, 1, 1);
  4297. function onRotationChange() {
  4298. quaternion.setFromEuler(rotation, false);
  4299. }
  4300. function onQuaternionChange() {
  4301. rotation.setFromQuaternion(quaternion, undefined, false);
  4302. }
  4303. rotation._onChange(onRotationChange);
  4304. quaternion._onChange(onQuaternionChange);
  4305. Object.defineProperties(this, {
  4306. position: {
  4307. configurable: true,
  4308. enumerable: true,
  4309. value: position
  4310. },
  4311. rotation: {
  4312. configurable: true,
  4313. enumerable: true,
  4314. value: rotation
  4315. },
  4316. quaternion: {
  4317. configurable: true,
  4318. enumerable: true,
  4319. value: quaternion
  4320. },
  4321. scale: {
  4322. configurable: true,
  4323. enumerable: true,
  4324. value: scale
  4325. },
  4326. modelViewMatrix: {
  4327. value: new Matrix4()
  4328. },
  4329. normalMatrix: {
  4330. value: new Matrix3()
  4331. }
  4332. });
  4333. this.matrix = new Matrix4();
  4334. this.matrixWorld = new Matrix4();
  4335. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  4336. this.matrixWorldNeedsUpdate = false;
  4337. this.layers = new Layers();
  4338. this.visible = true;
  4339. this.castShadow = false;
  4340. this.receiveShadow = false;
  4341. this.frustumCulled = true;
  4342. this.renderOrder = 0;
  4343. this.animations = [];
  4344. this.userData = {};
  4345. }
  4346. Object3D.DefaultUp = new Vector3(0, 1, 0);
  4347. Object3D.DefaultMatrixAutoUpdate = true;
  4348. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  4349. constructor: Object3D,
  4350. isObject3D: true,
  4351. onBeforeRender: function onBeforeRender() {},
  4352. onAfterRender: function onAfterRender() {},
  4353. applyMatrix4: function applyMatrix4(matrix) {
  4354. if (this.matrixAutoUpdate) this.updateMatrix();
  4355. this.matrix.premultiply(matrix);
  4356. this.matrix.decompose(this.position, this.quaternion, this.scale);
  4357. },
  4358. applyQuaternion: function applyQuaternion(q) {
  4359. this.quaternion.premultiply(q);
  4360. return this;
  4361. },
  4362. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  4363. // assumes axis is normalized
  4364. this.quaternion.setFromAxisAngle(axis, angle);
  4365. },
  4366. setRotationFromEuler: function setRotationFromEuler(euler) {
  4367. this.quaternion.setFromEuler(euler, true);
  4368. },
  4369. setRotationFromMatrix: function setRotationFromMatrix(m) {
  4370. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4371. this.quaternion.setFromRotationMatrix(m);
  4372. },
  4373. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  4374. // assumes q is normalized
  4375. this.quaternion.copy(q);
  4376. },
  4377. rotateOnAxis: function rotateOnAxis(axis, angle) {
  4378. // rotate object on axis in object space
  4379. // axis is assumed to be normalized
  4380. _q1.setFromAxisAngle(axis, angle);
  4381. this.quaternion.multiply(_q1);
  4382. return this;
  4383. },
  4384. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  4385. // rotate object on axis in world space
  4386. // axis is assumed to be normalized
  4387. // method assumes no rotated parent
  4388. _q1.setFromAxisAngle(axis, angle);
  4389. this.quaternion.premultiply(_q1);
  4390. return this;
  4391. },
  4392. rotateX: function rotateX(angle) {
  4393. return this.rotateOnAxis(_xAxis, angle);
  4394. },
  4395. rotateY: function rotateY(angle) {
  4396. return this.rotateOnAxis(_yAxis, angle);
  4397. },
  4398. rotateZ: function rotateZ(angle) {
  4399. return this.rotateOnAxis(_zAxis, angle);
  4400. },
  4401. translateOnAxis: function translateOnAxis(axis, distance) {
  4402. // translate object by distance along axis in object space
  4403. // axis is assumed to be normalized
  4404. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  4405. this.position.add(_v1$2.multiplyScalar(distance));
  4406. return this;
  4407. },
  4408. translateX: function translateX(distance) {
  4409. return this.translateOnAxis(_xAxis, distance);
  4410. },
  4411. translateY: function translateY(distance) {
  4412. return this.translateOnAxis(_yAxis, distance);
  4413. },
  4414. translateZ: function translateZ(distance) {
  4415. return this.translateOnAxis(_zAxis, distance);
  4416. },
  4417. localToWorld: function localToWorld(vector) {
  4418. return vector.applyMatrix4(this.matrixWorld);
  4419. },
  4420. worldToLocal: function worldToLocal(vector) {
  4421. return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());
  4422. },
  4423. lookAt: function lookAt(x, y, z) {
  4424. // This method does not support objects having non-uniformly-scaled parent(s)
  4425. if (x.isVector3) {
  4426. _target.copy(x);
  4427. } else {
  4428. _target.set(x, y, z);
  4429. }
  4430. var parent = this.parent;
  4431. this.updateWorldMatrix(true, false);
  4432. _position.setFromMatrixPosition(this.matrixWorld);
  4433. if (this.isCamera || this.isLight) {
  4434. _m1$1.lookAt(_position, _target, this.up);
  4435. } else {
  4436. _m1$1.lookAt(_target, _position, this.up);
  4437. }
  4438. this.quaternion.setFromRotationMatrix(_m1$1);
  4439. if (parent) {
  4440. _m1$1.extractRotation(parent.matrixWorld);
  4441. _q1.setFromRotationMatrix(_m1$1);
  4442. this.quaternion.premultiply(_q1.invert());
  4443. }
  4444. },
  4445. add: function add(object) {
  4446. if (arguments.length > 1) {
  4447. for (var i = 0; i < arguments.length; i++) {
  4448. this.add(arguments[i]);
  4449. }
  4450. return this;
  4451. }
  4452. if (object === this) {
  4453. console.error('THREE.Object3D.add: object can\'t be added as a child of itself.', object);
  4454. return this;
  4455. }
  4456. if (object && object.isObject3D) {
  4457. if (object.parent !== null) {
  4458. object.parent.remove(object);
  4459. }
  4460. object.parent = this;
  4461. this.children.push(object);
  4462. object.dispatchEvent(_addedEvent);
  4463. } else {
  4464. console.error('THREE.Object3D.add: object not an instance of THREE.Object3D.', object);
  4465. }
  4466. return this;
  4467. },
  4468. remove: function remove(object) {
  4469. if (arguments.length > 1) {
  4470. for (var i = 0; i < arguments.length; i++) {
  4471. this.remove(arguments[i]);
  4472. }
  4473. return this;
  4474. }
  4475. var index = this.children.indexOf(object);
  4476. if (index !== -1) {
  4477. object.parent = null;
  4478. this.children.splice(index, 1);
  4479. object.dispatchEvent(_removedEvent);
  4480. }
  4481. return this;
  4482. },
  4483. clear: function clear() {
  4484. for (var i = 0; i < this.children.length; i++) {
  4485. var object = this.children[i];
  4486. object.parent = null;
  4487. object.dispatchEvent(_removedEvent);
  4488. }
  4489. this.children.length = 0;
  4490. return this;
  4491. },
  4492. attach: function attach(object) {
  4493. // adds object as a child of this, while maintaining the object's world transform
  4494. this.updateWorldMatrix(true, false);
  4495. _m1$1.copy(this.matrixWorld).invert();
  4496. if (object.parent !== null) {
  4497. object.parent.updateWorldMatrix(true, false);
  4498. _m1$1.multiply(object.parent.matrixWorld);
  4499. }
  4500. object.applyMatrix4(_m1$1);
  4501. object.updateWorldMatrix(false, false);
  4502. this.add(object);
  4503. return this;
  4504. },
  4505. getObjectById: function getObjectById(id) {
  4506. return this.getObjectByProperty('id', id);
  4507. },
  4508. getObjectByName: function getObjectByName(name) {
  4509. return this.getObjectByProperty('name', name);
  4510. },
  4511. getObjectByProperty: function getObjectByProperty(name, value) {
  4512. if (this[name] === value) return this;
  4513. for (var i = 0, l = this.children.length; i < l; i++) {
  4514. var child = this.children[i];
  4515. var object = child.getObjectByProperty(name, value);
  4516. if (object !== undefined) {
  4517. return object;
  4518. }
  4519. }
  4520. return undefined;
  4521. },
  4522. getWorldPosition: function getWorldPosition(target) {
  4523. if (target === undefined) {
  4524. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  4525. target = new Vector3();
  4526. }
  4527. this.updateWorldMatrix(true, false);
  4528. return target.setFromMatrixPosition(this.matrixWorld);
  4529. },
  4530. getWorldQuaternion: function getWorldQuaternion(target) {
  4531. if (target === undefined) {
  4532. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  4533. target = new Quaternion();
  4534. }
  4535. this.updateWorldMatrix(true, false);
  4536. this.matrixWorld.decompose(_position, target, _scale);
  4537. return target;
  4538. },
  4539. getWorldScale: function getWorldScale(target) {
  4540. if (target === undefined) {
  4541. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  4542. target = new Vector3();
  4543. }
  4544. this.updateWorldMatrix(true, false);
  4545. this.matrixWorld.decompose(_position, _quaternion$2, target);
  4546. return target;
  4547. },
  4548. getWorldDirection: function getWorldDirection(target) {
  4549. if (target === undefined) {
  4550. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  4551. target = new Vector3();
  4552. }
  4553. this.updateWorldMatrix(true, false);
  4554. var e = this.matrixWorld.elements;
  4555. return target.set(e[8], e[9], e[10]).normalize();
  4556. },
  4557. raycast: function raycast() {},
  4558. traverse: function traverse(callback) {
  4559. callback(this);
  4560. var children = this.children;
  4561. for (var i = 0, l = children.length; i < l; i++) {
  4562. children[i].traverse(callback);
  4563. }
  4564. },
  4565. traverseVisible: function traverseVisible(callback) {
  4566. if (this.visible === false) return;
  4567. callback(this);
  4568. var children = this.children;
  4569. for (var i = 0, l = children.length; i < l; i++) {
  4570. children[i].traverseVisible(callback);
  4571. }
  4572. },
  4573. traverseAncestors: function traverseAncestors(callback) {
  4574. var parent = this.parent;
  4575. if (parent !== null) {
  4576. callback(parent);
  4577. parent.traverseAncestors(callback);
  4578. }
  4579. },
  4580. updateMatrix: function updateMatrix() {
  4581. this.matrix.compose(this.position, this.quaternion, this.scale);
  4582. this.matrixWorldNeedsUpdate = true;
  4583. },
  4584. updateMatrixWorld: function updateMatrixWorld(force) {
  4585. if (this.matrixAutoUpdate) this.updateMatrix();
  4586. if (this.matrixWorldNeedsUpdate || force) {
  4587. if (this.parent === null) {
  4588. this.matrixWorld.copy(this.matrix);
  4589. } else {
  4590. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4591. }
  4592. this.matrixWorldNeedsUpdate = false;
  4593. force = true;
  4594. } // update children
  4595. var children = this.children;
  4596. for (var i = 0, l = children.length; i < l; i++) {
  4597. children[i].updateMatrixWorld(force);
  4598. }
  4599. },
  4600. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  4601. var parent = this.parent;
  4602. if (updateParents === true && parent !== null) {
  4603. parent.updateWorldMatrix(true, false);
  4604. }
  4605. if (this.matrixAutoUpdate) this.updateMatrix();
  4606. if (this.parent === null) {
  4607. this.matrixWorld.copy(this.matrix);
  4608. } else {
  4609. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4610. } // update children
  4611. if (updateChildren === true) {
  4612. var children = this.children;
  4613. for (var i = 0, l = children.length; i < l; i++) {
  4614. children[i].updateWorldMatrix(false, true);
  4615. }
  4616. }
  4617. },
  4618. toJSON: function toJSON(meta) {
  4619. // meta is a string when called from JSON.stringify
  4620. var isRootObject = meta === undefined || typeof meta === 'string';
  4621. var output = {}; // meta is a hash used to collect geometries, materials.
  4622. // not providing it implies that this is the root object
  4623. // being serialized.
  4624. if (isRootObject) {
  4625. // initialize meta obj
  4626. meta = {
  4627. geometries: {},
  4628. materials: {},
  4629. textures: {},
  4630. images: {},
  4631. shapes: {},
  4632. skeletons: {},
  4633. animations: {}
  4634. };
  4635. output.metadata = {
  4636. version: 4.5,
  4637. type: 'Object',
  4638. generator: 'Object3D.toJSON'
  4639. };
  4640. } // standard Object3D serialization
  4641. var object = {};
  4642. object.uuid = this.uuid;
  4643. object.type = this.type;
  4644. if (this.name !== '') object.name = this.name;
  4645. if (this.castShadow === true) object.castShadow = true;
  4646. if (this.receiveShadow === true) object.receiveShadow = true;
  4647. if (this.visible === false) object.visible = false;
  4648. if (this.frustumCulled === false) object.frustumCulled = false;
  4649. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  4650. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  4651. object.layers = this.layers.mask;
  4652. object.matrix = this.matrix.toArray();
  4653. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  4654. if (this.isInstancedMesh) {
  4655. object.type = 'InstancedMesh';
  4656. object.count = this.count;
  4657. object.instanceMatrix = this.instanceMatrix.toJSON();
  4658. } //
  4659. function serialize(library, element) {
  4660. if (library[element.uuid] === undefined) {
  4661. library[element.uuid] = element.toJSON(meta);
  4662. }
  4663. return element.uuid;
  4664. }
  4665. if (this.isMesh || this.isLine || this.isPoints) {
  4666. object.geometry = serialize(meta.geometries, this.geometry);
  4667. var parameters = this.geometry.parameters;
  4668. if (parameters !== undefined && parameters.shapes !== undefined) {
  4669. var shapes = parameters.shapes;
  4670. if (Array.isArray(shapes)) {
  4671. for (var i = 0, l = shapes.length; i < l; i++) {
  4672. var shape = shapes[i];
  4673. serialize(meta.shapes, shape);
  4674. }
  4675. } else {
  4676. serialize(meta.shapes, shapes);
  4677. }
  4678. }
  4679. }
  4680. if (this.isSkinnedMesh) {
  4681. object.bindMode = this.bindMode;
  4682. object.bindMatrix = this.bindMatrix.toArray();
  4683. if (this.skeleton !== undefined) {
  4684. serialize(meta.skeletons, this.skeleton);
  4685. object.skeleton = this.skeleton.uuid;
  4686. }
  4687. }
  4688. if (this.material !== undefined) {
  4689. if (Array.isArray(this.material)) {
  4690. var uuids = [];
  4691. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  4692. uuids.push(serialize(meta.materials, this.material[_i]));
  4693. }
  4694. object.material = uuids;
  4695. } else {
  4696. object.material = serialize(meta.materials, this.material);
  4697. }
  4698. } //
  4699. if (this.children.length > 0) {
  4700. object.children = [];
  4701. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  4702. object.children.push(this.children[_i2].toJSON(meta).object);
  4703. }
  4704. } //
  4705. if (this.animations.length > 0) {
  4706. object.animations = [];
  4707. for (var _i3 = 0; _i3 < this.animations.length; _i3++) {
  4708. var animation = this.animations[_i3];
  4709. object.animations.push(serialize(meta.animations, animation));
  4710. }
  4711. }
  4712. if (isRootObject) {
  4713. var geometries = extractFromCache(meta.geometries);
  4714. var materials = extractFromCache(meta.materials);
  4715. var textures = extractFromCache(meta.textures);
  4716. var images = extractFromCache(meta.images);
  4717. var _shapes = extractFromCache(meta.shapes);
  4718. var skeletons = extractFromCache(meta.skeletons);
  4719. var animations = extractFromCache(meta.animations);
  4720. if (geometries.length > 0) output.geometries = geometries;
  4721. if (materials.length > 0) output.materials = materials;
  4722. if (textures.length > 0) output.textures = textures;
  4723. if (images.length > 0) output.images = images;
  4724. if (_shapes.length > 0) output.shapes = _shapes;
  4725. if (skeletons.length > 0) output.skeletons = skeletons;
  4726. if (animations.length > 0) output.animations = animations;
  4727. }
  4728. output.object = object;
  4729. return output; // extract data from the cache hash
  4730. // remove metadata on each item
  4731. // and return as array
  4732. function extractFromCache(cache) {
  4733. var values = [];
  4734. for (var key in cache) {
  4735. var data = cache[key];
  4736. delete data.metadata;
  4737. values.push(data);
  4738. }
  4739. return values;
  4740. }
  4741. },
  4742. clone: function clone(recursive) {
  4743. return new this.constructor().copy(this, recursive);
  4744. },
  4745. copy: function copy(source, recursive) {
  4746. if (recursive === void 0) {
  4747. recursive = true;
  4748. }
  4749. this.name = source.name;
  4750. this.up.copy(source.up);
  4751. this.position.copy(source.position);
  4752. this.rotation.order = source.rotation.order;
  4753. this.quaternion.copy(source.quaternion);
  4754. this.scale.copy(source.scale);
  4755. this.matrix.copy(source.matrix);
  4756. this.matrixWorld.copy(source.matrixWorld);
  4757. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4758. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4759. this.layers.mask = source.layers.mask;
  4760. this.visible = source.visible;
  4761. this.castShadow = source.castShadow;
  4762. this.receiveShadow = source.receiveShadow;
  4763. this.frustumCulled = source.frustumCulled;
  4764. this.renderOrder = source.renderOrder;
  4765. this.userData = JSON.parse(JSON.stringify(source.userData));
  4766. if (recursive === true) {
  4767. for (var i = 0; i < source.children.length; i++) {
  4768. var child = source.children[i];
  4769. this.add(child.clone());
  4770. }
  4771. }
  4772. return this;
  4773. }
  4774. });
  4775. var _vector1 = /*@__PURE__*/new Vector3();
  4776. var _vector2 = /*@__PURE__*/new Vector3();
  4777. var _normalMatrix = /*@__PURE__*/new Matrix3();
  4778. var Plane = /*#__PURE__*/function () {
  4779. function Plane(normal, constant) {
  4780. Object.defineProperty(this, 'isPlane', {
  4781. value: true
  4782. }); // normal is assumed to be normalized
  4783. this.normal = normal !== undefined ? normal : new Vector3(1, 0, 0);
  4784. this.constant = constant !== undefined ? constant : 0;
  4785. }
  4786. var _proto = Plane.prototype;
  4787. _proto.set = function set(normal, constant) {
  4788. this.normal.copy(normal);
  4789. this.constant = constant;
  4790. return this;
  4791. };
  4792. _proto.setComponents = function setComponents(x, y, z, w) {
  4793. this.normal.set(x, y, z);
  4794. this.constant = w;
  4795. return this;
  4796. };
  4797. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  4798. this.normal.copy(normal);
  4799. this.constant = -point.dot(this.normal);
  4800. return this;
  4801. };
  4802. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  4803. var normal = _vector1.subVectors(c, b).cross(_vector2.subVectors(a, b)).normalize(); // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  4804. this.setFromNormalAndCoplanarPoint(normal, a);
  4805. return this;
  4806. };
  4807. _proto.clone = function clone() {
  4808. return new this.constructor().copy(this);
  4809. };
  4810. _proto.copy = function copy(plane) {
  4811. this.normal.copy(plane.normal);
  4812. this.constant = plane.constant;
  4813. return this;
  4814. };
  4815. _proto.normalize = function normalize() {
  4816. // Note: will lead to a divide by zero if the plane is invalid.
  4817. var inverseNormalLength = 1.0 / this.normal.length();
  4818. this.normal.multiplyScalar(inverseNormalLength);
  4819. this.constant *= inverseNormalLength;
  4820. return this;
  4821. };
  4822. _proto.negate = function negate() {
  4823. this.constant *= -1;
  4824. this.normal.negate();
  4825. return this;
  4826. };
  4827. _proto.distanceToPoint = function distanceToPoint(point) {
  4828. return this.normal.dot(point) + this.constant;
  4829. };
  4830. _proto.distanceToSphere = function distanceToSphere(sphere) {
  4831. return this.distanceToPoint(sphere.center) - sphere.radius;
  4832. };
  4833. _proto.projectPoint = function projectPoint(point, target) {
  4834. if (target === undefined) {
  4835. console.warn('THREE.Plane: .projectPoint() target is now required');
  4836. target = new Vector3();
  4837. }
  4838. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  4839. };
  4840. _proto.intersectLine = function intersectLine(line, target) {
  4841. if (target === undefined) {
  4842. console.warn('THREE.Plane: .intersectLine() target is now required');
  4843. target = new Vector3();
  4844. }
  4845. var direction = line.delta(_vector1);
  4846. var denominator = this.normal.dot(direction);
  4847. if (denominator === 0) {
  4848. // line is coplanar, return origin
  4849. if (this.distanceToPoint(line.start) === 0) {
  4850. return target.copy(line.start);
  4851. } // Unsure if this is the correct method to handle this case.
  4852. return undefined;
  4853. }
  4854. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  4855. if (t < 0 || t > 1) {
  4856. return undefined;
  4857. }
  4858. return target.copy(direction).multiplyScalar(t).add(line.start);
  4859. };
  4860. _proto.intersectsLine = function intersectsLine(line) {
  4861. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4862. var startSign = this.distanceToPoint(line.start);
  4863. var endSign = this.distanceToPoint(line.end);
  4864. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  4865. };
  4866. _proto.intersectsBox = function intersectsBox(box) {
  4867. return box.intersectsPlane(this);
  4868. };
  4869. _proto.intersectsSphere = function intersectsSphere(sphere) {
  4870. return sphere.intersectsPlane(this);
  4871. };
  4872. _proto.coplanarPoint = function coplanarPoint(target) {
  4873. if (target === undefined) {
  4874. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  4875. target = new Vector3();
  4876. }
  4877. return target.copy(this.normal).multiplyScalar(-this.constant);
  4878. };
  4879. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  4880. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  4881. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  4882. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  4883. this.constant = -referencePoint.dot(normal);
  4884. return this;
  4885. };
  4886. _proto.translate = function translate(offset) {
  4887. this.constant -= offset.dot(this.normal);
  4888. return this;
  4889. };
  4890. _proto.equals = function equals(plane) {
  4891. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  4892. };
  4893. return Plane;
  4894. }();
  4895. var _v0$1 = /*@__PURE__*/new Vector3();
  4896. var _v1$3 = /*@__PURE__*/new Vector3();
  4897. var _v2$1 = /*@__PURE__*/new Vector3();
  4898. var _v3 = /*@__PURE__*/new Vector3();
  4899. var _vab = /*@__PURE__*/new Vector3();
  4900. var _vac = /*@__PURE__*/new Vector3();
  4901. var _vbc = /*@__PURE__*/new Vector3();
  4902. var _vap = /*@__PURE__*/new Vector3();
  4903. var _vbp = /*@__PURE__*/new Vector3();
  4904. var _vcp = /*@__PURE__*/new Vector3();
  4905. var Triangle = /*#__PURE__*/function () {
  4906. function Triangle(a, b, c) {
  4907. this.a = a !== undefined ? a : new Vector3();
  4908. this.b = b !== undefined ? b : new Vector3();
  4909. this.c = c !== undefined ? c : new Vector3();
  4910. }
  4911. Triangle.getNormal = function getNormal(a, b, c, target) {
  4912. if (target === undefined) {
  4913. console.warn('THREE.Triangle: .getNormal() target is now required');
  4914. target = new Vector3();
  4915. }
  4916. target.subVectors(c, b);
  4917. _v0$1.subVectors(a, b);
  4918. target.cross(_v0$1);
  4919. var targetLengthSq = target.lengthSq();
  4920. if (targetLengthSq > 0) {
  4921. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  4922. }
  4923. return target.set(0, 0, 0);
  4924. } // static/instance method to calculate barycentric coordinates
  4925. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4926. ;
  4927. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  4928. _v0$1.subVectors(c, a);
  4929. _v1$3.subVectors(b, a);
  4930. _v2$1.subVectors(point, a);
  4931. var dot00 = _v0$1.dot(_v0$1);
  4932. var dot01 = _v0$1.dot(_v1$3);
  4933. var dot02 = _v0$1.dot(_v2$1);
  4934. var dot11 = _v1$3.dot(_v1$3);
  4935. var dot12 = _v1$3.dot(_v2$1);
  4936. var denom = dot00 * dot11 - dot01 * dot01;
  4937. if (target === undefined) {
  4938. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  4939. target = new Vector3();
  4940. } // collinear or singular triangle
  4941. if (denom === 0) {
  4942. // arbitrary location outside of triangle?
  4943. // not sure if this is the best idea, maybe should be returning undefined
  4944. return target.set(-2, -1, -1);
  4945. }
  4946. var invDenom = 1 / denom;
  4947. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  4948. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  4949. return target.set(1 - u - v, v, u);
  4950. };
  4951. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  4952. this.getBarycoord(point, a, b, c, _v3);
  4953. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  4954. };
  4955. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  4956. this.getBarycoord(point, p1, p2, p3, _v3);
  4957. target.set(0, 0);
  4958. target.addScaledVector(uv1, _v3.x);
  4959. target.addScaledVector(uv2, _v3.y);
  4960. target.addScaledVector(uv3, _v3.z);
  4961. return target;
  4962. };
  4963. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  4964. _v0$1.subVectors(c, b);
  4965. _v1$3.subVectors(a, b); // strictly front facing
  4966. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  4967. };
  4968. var _proto = Triangle.prototype;
  4969. _proto.set = function set(a, b, c) {
  4970. this.a.copy(a);
  4971. this.b.copy(b);
  4972. this.c.copy(c);
  4973. return this;
  4974. };
  4975. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  4976. this.a.copy(points[i0]);
  4977. this.b.copy(points[i1]);
  4978. this.c.copy(points[i2]);
  4979. return this;
  4980. };
  4981. _proto.clone = function clone() {
  4982. return new this.constructor().copy(this);
  4983. };
  4984. _proto.copy = function copy(triangle) {
  4985. this.a.copy(triangle.a);
  4986. this.b.copy(triangle.b);
  4987. this.c.copy(triangle.c);
  4988. return this;
  4989. };
  4990. _proto.getArea = function getArea() {
  4991. _v0$1.subVectors(this.c, this.b);
  4992. _v1$3.subVectors(this.a, this.b);
  4993. return _v0$1.cross(_v1$3).length() * 0.5;
  4994. };
  4995. _proto.getMidpoint = function getMidpoint(target) {
  4996. if (target === undefined) {
  4997. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  4998. target = new Vector3();
  4999. }
  5000. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  5001. };
  5002. _proto.getNormal = function getNormal(target) {
  5003. return Triangle.getNormal(this.a, this.b, this.c, target);
  5004. };
  5005. _proto.getPlane = function getPlane(target) {
  5006. if (target === undefined) {
  5007. console.warn('THREE.Triangle: .getPlane() target is now required');
  5008. target = new Plane();
  5009. }
  5010. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  5011. };
  5012. _proto.getBarycoord = function getBarycoord(point, target) {
  5013. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  5014. };
  5015. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  5016. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  5017. };
  5018. _proto.containsPoint = function containsPoint(point) {
  5019. return Triangle.containsPoint(point, this.a, this.b, this.c);
  5020. };
  5021. _proto.isFrontFacing = function isFrontFacing(direction) {
  5022. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  5023. };
  5024. _proto.intersectsBox = function intersectsBox(box) {
  5025. return box.intersectsTriangle(this);
  5026. };
  5027. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  5028. if (target === undefined) {
  5029. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  5030. target = new Vector3();
  5031. }
  5032. var a = this.a,
  5033. b = this.b,
  5034. c = this.c;
  5035. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  5036. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  5037. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  5038. // basically, we're distinguishing which of the voronoi regions of the triangle
  5039. // the point lies in with the minimum amount of redundant computation.
  5040. _vab.subVectors(b, a);
  5041. _vac.subVectors(c, a);
  5042. _vap.subVectors(p, a);
  5043. var d1 = _vab.dot(_vap);
  5044. var d2 = _vac.dot(_vap);
  5045. if (d1 <= 0 && d2 <= 0) {
  5046. // vertex region of A; barycentric coords (1, 0, 0)
  5047. return target.copy(a);
  5048. }
  5049. _vbp.subVectors(p, b);
  5050. var d3 = _vab.dot(_vbp);
  5051. var d4 = _vac.dot(_vbp);
  5052. if (d3 >= 0 && d4 <= d3) {
  5053. // vertex region of B; barycentric coords (0, 1, 0)
  5054. return target.copy(b);
  5055. }
  5056. var vc = d1 * d4 - d3 * d2;
  5057. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  5058. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  5059. return target.copy(a).addScaledVector(_vab, v);
  5060. }
  5061. _vcp.subVectors(p, c);
  5062. var d5 = _vab.dot(_vcp);
  5063. var d6 = _vac.dot(_vcp);
  5064. if (d6 >= 0 && d5 <= d6) {
  5065. // vertex region of C; barycentric coords (0, 0, 1)
  5066. return target.copy(c);
  5067. }
  5068. var vb = d5 * d2 - d1 * d6;
  5069. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  5070. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  5071. return target.copy(a).addScaledVector(_vac, w);
  5072. }
  5073. var va = d3 * d6 - d5 * d4;
  5074. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  5075. _vbc.subVectors(c, b);
  5076. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5077. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5078. } // face region
  5079. var denom = 1 / (va + vb + vc); // u = va * denom
  5080. v = vb * denom;
  5081. w = vc * denom;
  5082. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5083. };
  5084. _proto.equals = function equals(triangle) {
  5085. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5086. };
  5087. return Triangle;
  5088. }();
  5089. var _colorKeywords = {
  5090. 'aliceblue': 0xF0F8FF,
  5091. 'antiquewhite': 0xFAEBD7,
  5092. 'aqua': 0x00FFFF,
  5093. 'aquamarine': 0x7FFFD4,
  5094. 'azure': 0xF0FFFF,
  5095. 'beige': 0xF5F5DC,
  5096. 'bisque': 0xFFE4C4,
  5097. 'black': 0x000000,
  5098. 'blanchedalmond': 0xFFEBCD,
  5099. 'blue': 0x0000FF,
  5100. 'blueviolet': 0x8A2BE2,
  5101. 'brown': 0xA52A2A,
  5102. 'burlywood': 0xDEB887,
  5103. 'cadetblue': 0x5F9EA0,
  5104. 'chartreuse': 0x7FFF00,
  5105. 'chocolate': 0xD2691E,
  5106. 'coral': 0xFF7F50,
  5107. 'cornflowerblue': 0x6495ED,
  5108. 'cornsilk': 0xFFF8DC,
  5109. 'crimson': 0xDC143C,
  5110. 'cyan': 0x00FFFF,
  5111. 'darkblue': 0x00008B,
  5112. 'darkcyan': 0x008B8B,
  5113. 'darkgoldenrod': 0xB8860B,
  5114. 'darkgray': 0xA9A9A9,
  5115. 'darkgreen': 0x006400,
  5116. 'darkgrey': 0xA9A9A9,
  5117. 'darkkhaki': 0xBDB76B,
  5118. 'darkmagenta': 0x8B008B,
  5119. 'darkolivegreen': 0x556B2F,
  5120. 'darkorange': 0xFF8C00,
  5121. 'darkorchid': 0x9932CC,
  5122. 'darkred': 0x8B0000,
  5123. 'darksalmon': 0xE9967A,
  5124. 'darkseagreen': 0x8FBC8F,
  5125. 'darkslateblue': 0x483D8B,
  5126. 'darkslategray': 0x2F4F4F,
  5127. 'darkslategrey': 0x2F4F4F,
  5128. 'darkturquoise': 0x00CED1,
  5129. 'darkviolet': 0x9400D3,
  5130. 'deeppink': 0xFF1493,
  5131. 'deepskyblue': 0x00BFFF,
  5132. 'dimgray': 0x696969,
  5133. 'dimgrey': 0x696969,
  5134. 'dodgerblue': 0x1E90FF,
  5135. 'firebrick': 0xB22222,
  5136. 'floralwhite': 0xFFFAF0,
  5137. 'forestgreen': 0x228B22,
  5138. 'fuchsia': 0xFF00FF,
  5139. 'gainsboro': 0xDCDCDC,
  5140. 'ghostwhite': 0xF8F8FF,
  5141. 'gold': 0xFFD700,
  5142. 'goldenrod': 0xDAA520,
  5143. 'gray': 0x808080,
  5144. 'green': 0x008000,
  5145. 'greenyellow': 0xADFF2F,
  5146. 'grey': 0x808080,
  5147. 'honeydew': 0xF0FFF0,
  5148. 'hotpink': 0xFF69B4,
  5149. 'indianred': 0xCD5C5C,
  5150. 'indigo': 0x4B0082,
  5151. 'ivory': 0xFFFFF0,
  5152. 'khaki': 0xF0E68C,
  5153. 'lavender': 0xE6E6FA,
  5154. 'lavenderblush': 0xFFF0F5,
  5155. 'lawngreen': 0x7CFC00,
  5156. 'lemonchiffon': 0xFFFACD,
  5157. 'lightblue': 0xADD8E6,
  5158. 'lightcoral': 0xF08080,
  5159. 'lightcyan': 0xE0FFFF,
  5160. 'lightgoldenrodyellow': 0xFAFAD2,
  5161. 'lightgray': 0xD3D3D3,
  5162. 'lightgreen': 0x90EE90,
  5163. 'lightgrey': 0xD3D3D3,
  5164. 'lightpink': 0xFFB6C1,
  5165. 'lightsalmon': 0xFFA07A,
  5166. 'lightseagreen': 0x20B2AA,
  5167. 'lightskyblue': 0x87CEFA,
  5168. 'lightslategray': 0x778899,
  5169. 'lightslategrey': 0x778899,
  5170. 'lightsteelblue': 0xB0C4DE,
  5171. 'lightyellow': 0xFFFFE0,
  5172. 'lime': 0x00FF00,
  5173. 'limegreen': 0x32CD32,
  5174. 'linen': 0xFAF0E6,
  5175. 'magenta': 0xFF00FF,
  5176. 'maroon': 0x800000,
  5177. 'mediumaquamarine': 0x66CDAA,
  5178. 'mediumblue': 0x0000CD,
  5179. 'mediumorchid': 0xBA55D3,
  5180. 'mediumpurple': 0x9370DB,
  5181. 'mediumseagreen': 0x3CB371,
  5182. 'mediumslateblue': 0x7B68EE,
  5183. 'mediumspringgreen': 0x00FA9A,
  5184. 'mediumturquoise': 0x48D1CC,
  5185. 'mediumvioletred': 0xC71585,
  5186. 'midnightblue': 0x191970,
  5187. 'mintcream': 0xF5FFFA,
  5188. 'mistyrose': 0xFFE4E1,
  5189. 'moccasin': 0xFFE4B5,
  5190. 'navajowhite': 0xFFDEAD,
  5191. 'navy': 0x000080,
  5192. 'oldlace': 0xFDF5E6,
  5193. 'olive': 0x808000,
  5194. 'olivedrab': 0x6B8E23,
  5195. 'orange': 0xFFA500,
  5196. 'orangered': 0xFF4500,
  5197. 'orchid': 0xDA70D6,
  5198. 'palegoldenrod': 0xEEE8AA,
  5199. 'palegreen': 0x98FB98,
  5200. 'paleturquoise': 0xAFEEEE,
  5201. 'palevioletred': 0xDB7093,
  5202. 'papayawhip': 0xFFEFD5,
  5203. 'peachpuff': 0xFFDAB9,
  5204. 'peru': 0xCD853F,
  5205. 'pink': 0xFFC0CB,
  5206. 'plum': 0xDDA0DD,
  5207. 'powderblue': 0xB0E0E6,
  5208. 'purple': 0x800080,
  5209. 'rebeccapurple': 0x663399,
  5210. 'red': 0xFF0000,
  5211. 'rosybrown': 0xBC8F8F,
  5212. 'royalblue': 0x4169E1,
  5213. 'saddlebrown': 0x8B4513,
  5214. 'salmon': 0xFA8072,
  5215. 'sandybrown': 0xF4A460,
  5216. 'seagreen': 0x2E8B57,
  5217. 'seashell': 0xFFF5EE,
  5218. 'sienna': 0xA0522D,
  5219. 'silver': 0xC0C0C0,
  5220. 'skyblue': 0x87CEEB,
  5221. 'slateblue': 0x6A5ACD,
  5222. 'slategray': 0x708090,
  5223. 'slategrey': 0x708090,
  5224. 'snow': 0xFFFAFA,
  5225. 'springgreen': 0x00FF7F,
  5226. 'steelblue': 0x4682B4,
  5227. 'tan': 0xD2B48C,
  5228. 'teal': 0x008080,
  5229. 'thistle': 0xD8BFD8,
  5230. 'tomato': 0xFF6347,
  5231. 'turquoise': 0x40E0D0,
  5232. 'violet': 0xEE82EE,
  5233. 'wheat': 0xF5DEB3,
  5234. 'white': 0xFFFFFF,
  5235. 'whitesmoke': 0xF5F5F5,
  5236. 'yellow': 0xFFFF00,
  5237. 'yellowgreen': 0x9ACD32
  5238. };
  5239. var _hslA = {
  5240. h: 0,
  5241. s: 0,
  5242. l: 0
  5243. };
  5244. var _hslB = {
  5245. h: 0,
  5246. s: 0,
  5247. l: 0
  5248. };
  5249. function hue2rgb(p, q, t) {
  5250. if (t < 0) t += 1;
  5251. if (t > 1) t -= 1;
  5252. if (t < 1 / 6) return p + (q - p) * 6 * t;
  5253. if (t < 1 / 2) return q;
  5254. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  5255. return p;
  5256. }
  5257. function SRGBToLinear(c) {
  5258. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  5259. }
  5260. function LinearToSRGB(c) {
  5261. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  5262. }
  5263. var Color = /*#__PURE__*/function () {
  5264. function Color(r, g, b) {
  5265. Object.defineProperty(this, 'isColor', {
  5266. value: true
  5267. });
  5268. if (g === undefined && b === undefined) {
  5269. // r is THREE.Color, hex or string
  5270. return this.set(r);
  5271. }
  5272. return this.setRGB(r, g, b);
  5273. }
  5274. var _proto = Color.prototype;
  5275. _proto.set = function set(value) {
  5276. if (value && value.isColor) {
  5277. this.copy(value);
  5278. } else if (typeof value === 'number') {
  5279. this.setHex(value);
  5280. } else if (typeof value === 'string') {
  5281. this.setStyle(value);
  5282. }
  5283. return this;
  5284. };
  5285. _proto.setScalar = function setScalar(scalar) {
  5286. this.r = scalar;
  5287. this.g = scalar;
  5288. this.b = scalar;
  5289. return this;
  5290. };
  5291. _proto.setHex = function setHex(hex) {
  5292. hex = Math.floor(hex);
  5293. this.r = (hex >> 16 & 255) / 255;
  5294. this.g = (hex >> 8 & 255) / 255;
  5295. this.b = (hex & 255) / 255;
  5296. return this;
  5297. };
  5298. _proto.setRGB = function setRGB(r, g, b) {
  5299. this.r = r;
  5300. this.g = g;
  5301. this.b = b;
  5302. return this;
  5303. };
  5304. _proto.setHSL = function setHSL(h, s, l) {
  5305. // h,s,l ranges are in 0.0 - 1.0
  5306. h = MathUtils.euclideanModulo(h, 1);
  5307. s = MathUtils.clamp(s, 0, 1);
  5308. l = MathUtils.clamp(l, 0, 1);
  5309. if (s === 0) {
  5310. this.r = this.g = this.b = l;
  5311. } else {
  5312. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  5313. var q = 2 * l - p;
  5314. this.r = hue2rgb(q, p, h + 1 / 3);
  5315. this.g = hue2rgb(q, p, h);
  5316. this.b = hue2rgb(q, p, h - 1 / 3);
  5317. }
  5318. return this;
  5319. };
  5320. _proto.setStyle = function setStyle(style) {
  5321. function handleAlpha(string) {
  5322. if (string === undefined) return;
  5323. if (parseFloat(string) < 1) {
  5324. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  5325. }
  5326. }
  5327. var m;
  5328. if (m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(style)) {
  5329. // rgb / hsl
  5330. var color;
  5331. var name = m[1];
  5332. var components = m[2];
  5333. switch (name) {
  5334. case 'rgb':
  5335. case 'rgba':
  5336. if (color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  5337. // rgb(255,0,0) rgba(255,0,0,0.5)
  5338. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  5339. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  5340. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  5341. handleAlpha(color[4]);
  5342. return this;
  5343. }
  5344. if (color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  5345. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5346. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  5347. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  5348. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  5349. handleAlpha(color[4]);
  5350. return this;
  5351. }
  5352. break;
  5353. case 'hsl':
  5354. case 'hsla':
  5355. if (color = /^(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  5356. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  5357. var h = parseFloat(color[1]) / 360;
  5358. var s = parseInt(color[2], 10) / 100;
  5359. var l = parseInt(color[3], 10) / 100;
  5360. handleAlpha(color[4]);
  5361. return this.setHSL(h, s, l);
  5362. }
  5363. break;
  5364. }
  5365. } else if (m = /^\#([A-Fa-f\d]+)$/.exec(style)) {
  5366. // hex color
  5367. var hex = m[1];
  5368. var size = hex.length;
  5369. if (size === 3) {
  5370. // #ff0
  5371. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  5372. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  5373. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  5374. return this;
  5375. } else if (size === 6) {
  5376. // #ff0000
  5377. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  5378. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  5379. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  5380. return this;
  5381. }
  5382. }
  5383. if (style && style.length > 0) {
  5384. return this.setColorName(style);
  5385. }
  5386. return this;
  5387. };
  5388. _proto.setColorName = function setColorName(style) {
  5389. // color keywords
  5390. var hex = _colorKeywords[style];
  5391. if (hex !== undefined) {
  5392. // red
  5393. this.setHex(hex);
  5394. } else {
  5395. // unknown color
  5396. console.warn('THREE.Color: Unknown color ' + style);
  5397. }
  5398. return this;
  5399. };
  5400. _proto.clone = function clone() {
  5401. return new this.constructor(this.r, this.g, this.b);
  5402. };
  5403. _proto.copy = function copy(color) {
  5404. this.r = color.r;
  5405. this.g = color.g;
  5406. this.b = color.b;
  5407. return this;
  5408. };
  5409. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  5410. if (gammaFactor === void 0) {
  5411. gammaFactor = 2.0;
  5412. }
  5413. this.r = Math.pow(color.r, gammaFactor);
  5414. this.g = Math.pow(color.g, gammaFactor);
  5415. this.b = Math.pow(color.b, gammaFactor);
  5416. return this;
  5417. };
  5418. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  5419. if (gammaFactor === void 0) {
  5420. gammaFactor = 2.0;
  5421. }
  5422. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  5423. this.r = Math.pow(color.r, safeInverse);
  5424. this.g = Math.pow(color.g, safeInverse);
  5425. this.b = Math.pow(color.b, safeInverse);
  5426. return this;
  5427. };
  5428. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  5429. this.copyGammaToLinear(this, gammaFactor);
  5430. return this;
  5431. };
  5432. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  5433. this.copyLinearToGamma(this, gammaFactor);
  5434. return this;
  5435. };
  5436. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  5437. this.r = SRGBToLinear(color.r);
  5438. this.g = SRGBToLinear(color.g);
  5439. this.b = SRGBToLinear(color.b);
  5440. return this;
  5441. };
  5442. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  5443. this.r = LinearToSRGB(color.r);
  5444. this.g = LinearToSRGB(color.g);
  5445. this.b = LinearToSRGB(color.b);
  5446. return this;
  5447. };
  5448. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  5449. this.copySRGBToLinear(this);
  5450. return this;
  5451. };
  5452. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  5453. this.copyLinearToSRGB(this);
  5454. return this;
  5455. };
  5456. _proto.getHex = function getHex() {
  5457. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  5458. };
  5459. _proto.getHexString = function getHexString() {
  5460. return ('000000' + this.getHex().toString(16)).slice(-6);
  5461. };
  5462. _proto.getHSL = function getHSL(target) {
  5463. // h,s,l ranges are in 0.0 - 1.0
  5464. if (target === undefined) {
  5465. console.warn('THREE.Color: .getHSL() target is now required');
  5466. target = {
  5467. h: 0,
  5468. s: 0,
  5469. l: 0
  5470. };
  5471. }
  5472. var r = this.r,
  5473. g = this.g,
  5474. b = this.b;
  5475. var max = Math.max(r, g, b);
  5476. var min = Math.min(r, g, b);
  5477. var hue, saturation;
  5478. var lightness = (min + max) / 2.0;
  5479. if (min === max) {
  5480. hue = 0;
  5481. saturation = 0;
  5482. } else {
  5483. var delta = max - min;
  5484. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  5485. switch (max) {
  5486. case r:
  5487. hue = (g - b) / delta + (g < b ? 6 : 0);
  5488. break;
  5489. case g:
  5490. hue = (b - r) / delta + 2;
  5491. break;
  5492. case b:
  5493. hue = (r - g) / delta + 4;
  5494. break;
  5495. }
  5496. hue /= 6;
  5497. }
  5498. target.h = hue;
  5499. target.s = saturation;
  5500. target.l = lightness;
  5501. return target;
  5502. };
  5503. _proto.getStyle = function getStyle() {
  5504. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  5505. };
  5506. _proto.offsetHSL = function offsetHSL(h, s, l) {
  5507. this.getHSL(_hslA);
  5508. _hslA.h += h;
  5509. _hslA.s += s;
  5510. _hslA.l += l;
  5511. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  5512. return this;
  5513. };
  5514. _proto.add = function add(color) {
  5515. this.r += color.r;
  5516. this.g += color.g;
  5517. this.b += color.b;
  5518. return this;
  5519. };
  5520. _proto.addColors = function addColors(color1, color2) {
  5521. this.r = color1.r + color2.r;
  5522. this.g = color1.g + color2.g;
  5523. this.b = color1.b + color2.b;
  5524. return this;
  5525. };
  5526. _proto.addScalar = function addScalar(s) {
  5527. this.r += s;
  5528. this.g += s;
  5529. this.b += s;
  5530. return this;
  5531. };
  5532. _proto.sub = function sub(color) {
  5533. this.r = Math.max(0, this.r - color.r);
  5534. this.g = Math.max(0, this.g - color.g);
  5535. this.b = Math.max(0, this.b - color.b);
  5536. return this;
  5537. };
  5538. _proto.multiply = function multiply(color) {
  5539. this.r *= color.r;
  5540. this.g *= color.g;
  5541. this.b *= color.b;
  5542. return this;
  5543. };
  5544. _proto.multiplyScalar = function multiplyScalar(s) {
  5545. this.r *= s;
  5546. this.g *= s;
  5547. this.b *= s;
  5548. return this;
  5549. };
  5550. _proto.lerp = function lerp(color, alpha) {
  5551. this.r += (color.r - this.r) * alpha;
  5552. this.g += (color.g - this.g) * alpha;
  5553. this.b += (color.b - this.b) * alpha;
  5554. return this;
  5555. };
  5556. _proto.lerpHSL = function lerpHSL(color, alpha) {
  5557. this.getHSL(_hslA);
  5558. color.getHSL(_hslB);
  5559. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  5560. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  5561. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  5562. this.setHSL(h, s, l);
  5563. return this;
  5564. };
  5565. _proto.equals = function equals(c) {
  5566. return c.r === this.r && c.g === this.g && c.b === this.b;
  5567. };
  5568. _proto.fromArray = function fromArray(array, offset) {
  5569. if (offset === void 0) {
  5570. offset = 0;
  5571. }
  5572. this.r = array[offset];
  5573. this.g = array[offset + 1];
  5574. this.b = array[offset + 2];
  5575. return this;
  5576. };
  5577. _proto.toArray = function toArray(array, offset) {
  5578. if (array === void 0) {
  5579. array = [];
  5580. }
  5581. if (offset === void 0) {
  5582. offset = 0;
  5583. }
  5584. array[offset] = this.r;
  5585. array[offset + 1] = this.g;
  5586. array[offset + 2] = this.b;
  5587. return array;
  5588. };
  5589. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  5590. this.r = attribute.getX(index);
  5591. this.g = attribute.getY(index);
  5592. this.b = attribute.getZ(index);
  5593. if (attribute.normalized === true) {
  5594. // assuming Uint8Array
  5595. this.r /= 255;
  5596. this.g /= 255;
  5597. this.b /= 255;
  5598. }
  5599. return this;
  5600. };
  5601. _proto.toJSON = function toJSON() {
  5602. return this.getHex();
  5603. };
  5604. return Color;
  5605. }();
  5606. Color.NAMES = _colorKeywords;
  5607. Color.prototype.r = 1;
  5608. Color.prototype.g = 1;
  5609. Color.prototype.b = 1;
  5610. var Face3 = /*#__PURE__*/function () {
  5611. function Face3(a, b, c, normal, color, materialIndex) {
  5612. if (materialIndex === void 0) {
  5613. materialIndex = 0;
  5614. }
  5615. this.a = a;
  5616. this.b = b;
  5617. this.c = c;
  5618. this.normal = normal && normal.isVector3 ? normal : new Vector3();
  5619. this.vertexNormals = Array.isArray(normal) ? normal : [];
  5620. this.color = color && color.isColor ? color : new Color();
  5621. this.vertexColors = Array.isArray(color) ? color : [];
  5622. this.materialIndex = materialIndex;
  5623. }
  5624. var _proto = Face3.prototype;
  5625. _proto.clone = function clone() {
  5626. return new this.constructor().copy(this);
  5627. };
  5628. _proto.copy = function copy(source) {
  5629. this.a = source.a;
  5630. this.b = source.b;
  5631. this.c = source.c;
  5632. this.normal.copy(source.normal);
  5633. this.color.copy(source.color);
  5634. this.materialIndex = source.materialIndex;
  5635. for (var i = 0, il = source.vertexNormals.length; i < il; i++) {
  5636. this.vertexNormals[i] = source.vertexNormals[i].clone();
  5637. }
  5638. for (var _i = 0, _il = source.vertexColors.length; _i < _il; _i++) {
  5639. this.vertexColors[_i] = source.vertexColors[_i].clone();
  5640. }
  5641. return this;
  5642. };
  5643. return Face3;
  5644. }();
  5645. var materialId = 0;
  5646. function Material() {
  5647. Object.defineProperty(this, 'id', {
  5648. value: materialId++
  5649. });
  5650. this.uuid = MathUtils.generateUUID();
  5651. this.name = '';
  5652. this.type = 'Material';
  5653. this.fog = true;
  5654. this.blending = NormalBlending;
  5655. this.side = FrontSide;
  5656. this.flatShading = false;
  5657. this.vertexColors = false;
  5658. this.opacity = 1;
  5659. this.transparent = false;
  5660. this.blendSrc = SrcAlphaFactor;
  5661. this.blendDst = OneMinusSrcAlphaFactor;
  5662. this.blendEquation = AddEquation;
  5663. this.blendSrcAlpha = null;
  5664. this.blendDstAlpha = null;
  5665. this.blendEquationAlpha = null;
  5666. this.depthFunc = LessEqualDepth;
  5667. this.depthTest = true;
  5668. this.depthWrite = true;
  5669. this.stencilWriteMask = 0xff;
  5670. this.stencilFunc = AlwaysStencilFunc;
  5671. this.stencilRef = 0;
  5672. this.stencilFuncMask = 0xff;
  5673. this.stencilFail = KeepStencilOp;
  5674. this.stencilZFail = KeepStencilOp;
  5675. this.stencilZPass = KeepStencilOp;
  5676. this.stencilWrite = false;
  5677. this.clippingPlanes = null;
  5678. this.clipIntersection = false;
  5679. this.clipShadows = false;
  5680. this.shadowSide = null;
  5681. this.colorWrite = true;
  5682. this.precision = null; // override the renderer's default precision for this material
  5683. this.polygonOffset = false;
  5684. this.polygonOffsetFactor = 0;
  5685. this.polygonOffsetUnits = 0;
  5686. this.dithering = false;
  5687. this.alphaTest = 0;
  5688. this.premultipliedAlpha = false;
  5689. this.visible = true;
  5690. this.toneMapped = true;
  5691. this.userData = {};
  5692. this.version = 0;
  5693. }
  5694. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5695. constructor: Material,
  5696. isMaterial: true,
  5697. onBeforeCompile: function onBeforeCompile()
  5698. /* shaderobject, renderer */
  5699. {},
  5700. customProgramCacheKey: function customProgramCacheKey() {
  5701. return this.onBeforeCompile.toString();
  5702. },
  5703. setValues: function setValues(values) {
  5704. if (values === undefined) return;
  5705. for (var key in values) {
  5706. var newValue = values[key];
  5707. if (newValue === undefined) {
  5708. console.warn('THREE.Material: \'' + key + '\' parameter is undefined.');
  5709. continue;
  5710. } // for backward compatability if shading is set in the constructor
  5711. if (key === 'shading') {
  5712. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  5713. this.flatShading = newValue === FlatShading ? true : false;
  5714. continue;
  5715. }
  5716. var currentValue = this[key];
  5717. if (currentValue === undefined) {
  5718. console.warn('THREE.' + this.type + ': \'' + key + '\' is not a property of this material.');
  5719. continue;
  5720. }
  5721. if (currentValue && currentValue.isColor) {
  5722. currentValue.set(newValue);
  5723. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  5724. currentValue.copy(newValue);
  5725. } else {
  5726. this[key] = newValue;
  5727. }
  5728. }
  5729. },
  5730. toJSON: function toJSON(meta) {
  5731. var isRoot = meta === undefined || typeof meta === 'string';
  5732. if (isRoot) {
  5733. meta = {
  5734. textures: {},
  5735. images: {}
  5736. };
  5737. }
  5738. var data = {
  5739. metadata: {
  5740. version: 4.5,
  5741. type: 'Material',
  5742. generator: 'Material.toJSON'
  5743. }
  5744. }; // standard Material serialization
  5745. data.uuid = this.uuid;
  5746. data.type = this.type;
  5747. if (this.name !== '') data.name = this.name;
  5748. if (this.color && this.color.isColor) data.color = this.color.getHex();
  5749. if (this.roughness !== undefined) data.roughness = this.roughness;
  5750. if (this.metalness !== undefined) data.metalness = this.metalness;
  5751. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  5752. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  5753. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  5754. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  5755. if (this.shininess !== undefined) data.shininess = this.shininess;
  5756. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  5757. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  5758. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  5759. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  5760. }
  5761. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  5762. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  5763. }
  5764. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  5765. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  5766. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5767. }
  5768. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  5769. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  5770. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  5771. if (this.lightMap && this.lightMap.isTexture) data.lightMap = this.lightMap.toJSON(meta).uuid;
  5772. if (this.aoMap && this.aoMap.isTexture) {
  5773. data.aoMap = this.aoMap.toJSON(meta).uuid;
  5774. data.aoMapIntensity = this.aoMapIntensity;
  5775. }
  5776. if (this.bumpMap && this.bumpMap.isTexture) {
  5777. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  5778. data.bumpScale = this.bumpScale;
  5779. }
  5780. if (this.normalMap && this.normalMap.isTexture) {
  5781. data.normalMap = this.normalMap.toJSON(meta).uuid;
  5782. data.normalMapType = this.normalMapType;
  5783. data.normalScale = this.normalScale.toArray();
  5784. }
  5785. if (this.displacementMap && this.displacementMap.isTexture) {
  5786. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  5787. data.displacementScale = this.displacementScale;
  5788. data.displacementBias = this.displacementBias;
  5789. }
  5790. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  5791. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  5792. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  5793. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  5794. if (this.envMap && this.envMap.isTexture) {
  5795. data.envMap = this.envMap.toJSON(meta).uuid;
  5796. data.reflectivity = this.reflectivity; // Scale behind envMap
  5797. data.refractionRatio = this.refractionRatio;
  5798. if (this.combine !== undefined) data.combine = this.combine;
  5799. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  5800. }
  5801. if (this.gradientMap && this.gradientMap.isTexture) {
  5802. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  5803. }
  5804. if (this.size !== undefined) data.size = this.size;
  5805. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  5806. if (this.blending !== NormalBlending) data.blending = this.blending;
  5807. if (this.flatShading === true) data.flatShading = this.flatShading;
  5808. if (this.side !== FrontSide) data.side = this.side;
  5809. if (this.vertexColors) data.vertexColors = true;
  5810. if (this.opacity < 1) data.opacity = this.opacity;
  5811. if (this.transparent === true) data.transparent = this.transparent;
  5812. data.depthFunc = this.depthFunc;
  5813. data.depthTest = this.depthTest;
  5814. data.depthWrite = this.depthWrite;
  5815. data.stencilWrite = this.stencilWrite;
  5816. data.stencilWriteMask = this.stencilWriteMask;
  5817. data.stencilFunc = this.stencilFunc;
  5818. data.stencilRef = this.stencilRef;
  5819. data.stencilFuncMask = this.stencilFuncMask;
  5820. data.stencilFail = this.stencilFail;
  5821. data.stencilZFail = this.stencilZFail;
  5822. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  5823. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  5824. if (this.polygonOffset === true) data.polygonOffset = true;
  5825. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5826. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5827. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  5828. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  5829. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  5830. if (this.scale !== undefined) data.scale = this.scale;
  5831. if (this.dithering === true) data.dithering = true;
  5832. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  5833. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  5834. if (this.wireframe === true) data.wireframe = this.wireframe;
  5835. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  5836. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  5837. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  5838. if (this.morphTargets === true) data.morphTargets = true;
  5839. if (this.morphNormals === true) data.morphNormals = true;
  5840. if (this.skinning === true) data.skinning = true;
  5841. if (this.visible === false) data.visible = false;
  5842. if (this.toneMapped === false) data.toneMapped = false;
  5843. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  5844. function extractFromCache(cache) {
  5845. var values = [];
  5846. for (var key in cache) {
  5847. var _data = cache[key];
  5848. delete _data.metadata;
  5849. values.push(_data);
  5850. }
  5851. return values;
  5852. }
  5853. if (isRoot) {
  5854. var textures = extractFromCache(meta.textures);
  5855. var images = extractFromCache(meta.images);
  5856. if (textures.length > 0) data.textures = textures;
  5857. if (images.length > 0) data.images = images;
  5858. }
  5859. return data;
  5860. },
  5861. clone: function clone() {
  5862. return new this.constructor().copy(this);
  5863. },
  5864. copy: function copy(source) {
  5865. this.name = source.name;
  5866. this.fog = source.fog;
  5867. this.blending = source.blending;
  5868. this.side = source.side;
  5869. this.flatShading = source.flatShading;
  5870. this.vertexColors = source.vertexColors;
  5871. this.opacity = source.opacity;
  5872. this.transparent = source.transparent;
  5873. this.blendSrc = source.blendSrc;
  5874. this.blendDst = source.blendDst;
  5875. this.blendEquation = source.blendEquation;
  5876. this.blendSrcAlpha = source.blendSrcAlpha;
  5877. this.blendDstAlpha = source.blendDstAlpha;
  5878. this.blendEquationAlpha = source.blendEquationAlpha;
  5879. this.depthFunc = source.depthFunc;
  5880. this.depthTest = source.depthTest;
  5881. this.depthWrite = source.depthWrite;
  5882. this.stencilWriteMask = source.stencilWriteMask;
  5883. this.stencilFunc = source.stencilFunc;
  5884. this.stencilRef = source.stencilRef;
  5885. this.stencilFuncMask = source.stencilFuncMask;
  5886. this.stencilFail = source.stencilFail;
  5887. this.stencilZFail = source.stencilZFail;
  5888. this.stencilZPass = source.stencilZPass;
  5889. this.stencilWrite = source.stencilWrite;
  5890. var srcPlanes = source.clippingPlanes;
  5891. var dstPlanes = null;
  5892. if (srcPlanes !== null) {
  5893. var n = srcPlanes.length;
  5894. dstPlanes = new Array(n);
  5895. for (var i = 0; i !== n; ++i) {
  5896. dstPlanes[i] = srcPlanes[i].clone();
  5897. }
  5898. }
  5899. this.clippingPlanes = dstPlanes;
  5900. this.clipIntersection = source.clipIntersection;
  5901. this.clipShadows = source.clipShadows;
  5902. this.shadowSide = source.shadowSide;
  5903. this.colorWrite = source.colorWrite;
  5904. this.precision = source.precision;
  5905. this.polygonOffset = source.polygonOffset;
  5906. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5907. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5908. this.dithering = source.dithering;
  5909. this.alphaTest = source.alphaTest;
  5910. this.premultipliedAlpha = source.premultipliedAlpha;
  5911. this.visible = source.visible;
  5912. this.toneMapped = source.toneMapped;
  5913. this.userData = JSON.parse(JSON.stringify(source.userData));
  5914. return this;
  5915. },
  5916. dispose: function dispose() {
  5917. this.dispatchEvent({
  5918. type: 'dispose'
  5919. });
  5920. }
  5921. });
  5922. Object.defineProperty(Material.prototype, 'needsUpdate', {
  5923. set: function set(value) {
  5924. if (value === true) this.version++;
  5925. }
  5926. });
  5927. /**
  5928. * parameters = {
  5929. * color: <hex>,
  5930. * opacity: <float>,
  5931. * map: new THREE.Texture( <Image> ),
  5932. *
  5933. * lightMap: new THREE.Texture( <Image> ),
  5934. * lightMapIntensity: <float>
  5935. *
  5936. * aoMap: new THREE.Texture( <Image> ),
  5937. * aoMapIntensity: <float>
  5938. *
  5939. * specularMap: new THREE.Texture( <Image> ),
  5940. *
  5941. * alphaMap: new THREE.Texture( <Image> ),
  5942. *
  5943. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5944. * combine: THREE.Multiply,
  5945. * reflectivity: <float>,
  5946. * refractionRatio: <float>,
  5947. *
  5948. * depthTest: <bool>,
  5949. * depthWrite: <bool>,
  5950. *
  5951. * wireframe: <boolean>,
  5952. * wireframeLinewidth: <float>,
  5953. *
  5954. * skinning: <bool>,
  5955. * morphTargets: <bool>
  5956. * }
  5957. */
  5958. function MeshBasicMaterial(parameters) {
  5959. Material.call(this);
  5960. this.type = 'MeshBasicMaterial';
  5961. this.color = new Color(0xffffff); // emissive
  5962. this.map = null;
  5963. this.lightMap = null;
  5964. this.lightMapIntensity = 1.0;
  5965. this.aoMap = null;
  5966. this.aoMapIntensity = 1.0;
  5967. this.specularMap = null;
  5968. this.alphaMap = null;
  5969. this.envMap = null;
  5970. this.combine = MultiplyOperation;
  5971. this.reflectivity = 1;
  5972. this.refractionRatio = 0.98;
  5973. this.wireframe = false;
  5974. this.wireframeLinewidth = 1;
  5975. this.wireframeLinecap = 'round';
  5976. this.wireframeLinejoin = 'round';
  5977. this.skinning = false;
  5978. this.morphTargets = false;
  5979. this.setValues(parameters);
  5980. }
  5981. MeshBasicMaterial.prototype = Object.create(Material.prototype);
  5982. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5983. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5984. MeshBasicMaterial.prototype.copy = function (source) {
  5985. Material.prototype.copy.call(this, source);
  5986. this.color.copy(source.color);
  5987. this.map = source.map;
  5988. this.lightMap = source.lightMap;
  5989. this.lightMapIntensity = source.lightMapIntensity;
  5990. this.aoMap = source.aoMap;
  5991. this.aoMapIntensity = source.aoMapIntensity;
  5992. this.specularMap = source.specularMap;
  5993. this.alphaMap = source.alphaMap;
  5994. this.envMap = source.envMap;
  5995. this.combine = source.combine;
  5996. this.reflectivity = source.reflectivity;
  5997. this.refractionRatio = source.refractionRatio;
  5998. this.wireframe = source.wireframe;
  5999. this.wireframeLinewidth = source.wireframeLinewidth;
  6000. this.wireframeLinecap = source.wireframeLinecap;
  6001. this.wireframeLinejoin = source.wireframeLinejoin;
  6002. this.skinning = source.skinning;
  6003. this.morphTargets = source.morphTargets;
  6004. return this;
  6005. };
  6006. var _vector$3 = new Vector3();
  6007. var _vector2$1 = new Vector2();
  6008. function BufferAttribute(array, itemSize, normalized) {
  6009. if (Array.isArray(array)) {
  6010. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  6011. }
  6012. this.name = '';
  6013. this.array = array;
  6014. this.itemSize = itemSize;
  6015. this.count = array !== undefined ? array.length / itemSize : 0;
  6016. this.normalized = normalized === true;
  6017. this.usage = StaticDrawUsage;
  6018. this.updateRange = {
  6019. offset: 0,
  6020. count: -1
  6021. };
  6022. this.version = 0;
  6023. }
  6024. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  6025. set: function set(value) {
  6026. if (value === true) this.version++;
  6027. }
  6028. });
  6029. Object.assign(BufferAttribute.prototype, {
  6030. isBufferAttribute: true,
  6031. onUploadCallback: function onUploadCallback() {},
  6032. setUsage: function setUsage(value) {
  6033. this.usage = value;
  6034. return this;
  6035. },
  6036. copy: function copy(source) {
  6037. this.name = source.name;
  6038. this.array = new source.array.constructor(source.array);
  6039. this.itemSize = source.itemSize;
  6040. this.count = source.count;
  6041. this.normalized = source.normalized;
  6042. this.usage = source.usage;
  6043. return this;
  6044. },
  6045. copyAt: function copyAt(index1, attribute, index2) {
  6046. index1 *= this.itemSize;
  6047. index2 *= attribute.itemSize;
  6048. for (var i = 0, l = this.itemSize; i < l; i++) {
  6049. this.array[index1 + i] = attribute.array[index2 + i];
  6050. }
  6051. return this;
  6052. },
  6053. copyArray: function copyArray(array) {
  6054. this.array.set(array);
  6055. return this;
  6056. },
  6057. copyColorsArray: function copyColorsArray(colors) {
  6058. var array = this.array;
  6059. var offset = 0;
  6060. for (var i = 0, l = colors.length; i < l; i++) {
  6061. var color = colors[i];
  6062. if (color === undefined) {
  6063. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  6064. color = new Color();
  6065. }
  6066. array[offset++] = color.r;
  6067. array[offset++] = color.g;
  6068. array[offset++] = color.b;
  6069. }
  6070. return this;
  6071. },
  6072. copyVector2sArray: function copyVector2sArray(vectors) {
  6073. var array = this.array;
  6074. var offset = 0;
  6075. for (var i = 0, l = vectors.length; i < l; i++) {
  6076. var vector = vectors[i];
  6077. if (vector === undefined) {
  6078. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  6079. vector = new Vector2();
  6080. }
  6081. array[offset++] = vector.x;
  6082. array[offset++] = vector.y;
  6083. }
  6084. return this;
  6085. },
  6086. copyVector3sArray: function copyVector3sArray(vectors) {
  6087. var array = this.array;
  6088. var offset = 0;
  6089. for (var i = 0, l = vectors.length; i < l; i++) {
  6090. var vector = vectors[i];
  6091. if (vector === undefined) {
  6092. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  6093. vector = new Vector3();
  6094. }
  6095. array[offset++] = vector.x;
  6096. array[offset++] = vector.y;
  6097. array[offset++] = vector.z;
  6098. }
  6099. return this;
  6100. },
  6101. copyVector4sArray: function copyVector4sArray(vectors) {
  6102. var array = this.array;
  6103. var offset = 0;
  6104. for (var i = 0, l = vectors.length; i < l; i++) {
  6105. var vector = vectors[i];
  6106. if (vector === undefined) {
  6107. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  6108. vector = new Vector4();
  6109. }
  6110. array[offset++] = vector.x;
  6111. array[offset++] = vector.y;
  6112. array[offset++] = vector.z;
  6113. array[offset++] = vector.w;
  6114. }
  6115. return this;
  6116. },
  6117. applyMatrix3: function applyMatrix3(m) {
  6118. if (this.itemSize === 2) {
  6119. for (var i = 0, l = this.count; i < l; i++) {
  6120. _vector2$1.fromBufferAttribute(this, i);
  6121. _vector2$1.applyMatrix3(m);
  6122. this.setXY(i, _vector2$1.x, _vector2$1.y);
  6123. }
  6124. } else if (this.itemSize === 3) {
  6125. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  6126. _vector$3.fromBufferAttribute(this, _i);
  6127. _vector$3.applyMatrix3(m);
  6128. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  6129. }
  6130. }
  6131. return this;
  6132. },
  6133. applyMatrix4: function applyMatrix4(m) {
  6134. for (var i = 0, l = this.count; i < l; i++) {
  6135. _vector$3.x = this.getX(i);
  6136. _vector$3.y = this.getY(i);
  6137. _vector$3.z = this.getZ(i);
  6138. _vector$3.applyMatrix4(m);
  6139. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6140. }
  6141. return this;
  6142. },
  6143. applyNormalMatrix: function applyNormalMatrix(m) {
  6144. for (var i = 0, l = this.count; i < l; i++) {
  6145. _vector$3.x = this.getX(i);
  6146. _vector$3.y = this.getY(i);
  6147. _vector$3.z = this.getZ(i);
  6148. _vector$3.applyNormalMatrix(m);
  6149. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6150. }
  6151. return this;
  6152. },
  6153. transformDirection: function transformDirection(m) {
  6154. for (var i = 0, l = this.count; i < l; i++) {
  6155. _vector$3.x = this.getX(i);
  6156. _vector$3.y = this.getY(i);
  6157. _vector$3.z = this.getZ(i);
  6158. _vector$3.transformDirection(m);
  6159. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6160. }
  6161. return this;
  6162. },
  6163. set: function set(value, offset) {
  6164. if (offset === void 0) {
  6165. offset = 0;
  6166. }
  6167. this.array.set(value, offset);
  6168. return this;
  6169. },
  6170. getX: function getX(index) {
  6171. return this.array[index * this.itemSize];
  6172. },
  6173. setX: function setX(index, x) {
  6174. this.array[index * this.itemSize] = x;
  6175. return this;
  6176. },
  6177. getY: function getY(index) {
  6178. return this.array[index * this.itemSize + 1];
  6179. },
  6180. setY: function setY(index, y) {
  6181. this.array[index * this.itemSize + 1] = y;
  6182. return this;
  6183. },
  6184. getZ: function getZ(index) {
  6185. return this.array[index * this.itemSize + 2];
  6186. },
  6187. setZ: function setZ(index, z) {
  6188. this.array[index * this.itemSize + 2] = z;
  6189. return this;
  6190. },
  6191. getW: function getW(index) {
  6192. return this.array[index * this.itemSize + 3];
  6193. },
  6194. setW: function setW(index, w) {
  6195. this.array[index * this.itemSize + 3] = w;
  6196. return this;
  6197. },
  6198. setXY: function setXY(index, x, y) {
  6199. index *= this.itemSize;
  6200. this.array[index + 0] = x;
  6201. this.array[index + 1] = y;
  6202. return this;
  6203. },
  6204. setXYZ: function setXYZ(index, x, y, z) {
  6205. index *= this.itemSize;
  6206. this.array[index + 0] = x;
  6207. this.array[index + 1] = y;
  6208. this.array[index + 2] = z;
  6209. return this;
  6210. },
  6211. setXYZW: function setXYZW(index, x, y, z, w) {
  6212. index *= this.itemSize;
  6213. this.array[index + 0] = x;
  6214. this.array[index + 1] = y;
  6215. this.array[index + 2] = z;
  6216. this.array[index + 3] = w;
  6217. return this;
  6218. },
  6219. onUpload: function onUpload(callback) {
  6220. this.onUploadCallback = callback;
  6221. return this;
  6222. },
  6223. clone: function clone() {
  6224. return new this.constructor(this.array, this.itemSize).copy(this);
  6225. },
  6226. toJSON: function toJSON() {
  6227. return {
  6228. itemSize: this.itemSize,
  6229. type: this.array.constructor.name,
  6230. array: Array.prototype.slice.call(this.array),
  6231. normalized: this.normalized
  6232. };
  6233. }
  6234. }); //
  6235. function Int8BufferAttribute(array, itemSize, normalized) {
  6236. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6237. }
  6238. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6239. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6240. function Uint8BufferAttribute(array, itemSize, normalized) {
  6241. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6242. }
  6243. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6244. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6245. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6246. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6247. }
  6248. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6249. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6250. function Int16BufferAttribute(array, itemSize, normalized) {
  6251. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6252. }
  6253. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6254. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6255. function Uint16BufferAttribute(array, itemSize, normalized) {
  6256. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6257. }
  6258. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6259. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6260. function Int32BufferAttribute(array, itemSize, normalized) {
  6261. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6262. }
  6263. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6264. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6265. function Uint32BufferAttribute(array, itemSize, normalized) {
  6266. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6267. }
  6268. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6269. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6270. function Float16BufferAttribute(array, itemSize, normalized) {
  6271. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6272. }
  6273. Float16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6274. Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
  6275. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  6276. function Float32BufferAttribute(array, itemSize, normalized) {
  6277. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6278. }
  6279. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6280. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6281. function Float64BufferAttribute(array, itemSize, normalized) {
  6282. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6283. }
  6284. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6285. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  6286. var DirectGeometry = /*#__PURE__*/function () {
  6287. function DirectGeometry() {
  6288. this.vertices = [];
  6289. this.normals = [];
  6290. this.colors = [];
  6291. this.uvs = [];
  6292. this.uvs2 = [];
  6293. this.groups = [];
  6294. this.morphTargets = {};
  6295. this.skinWeights = [];
  6296. this.skinIndices = []; // this.lineDistances = [];
  6297. this.boundingBox = null;
  6298. this.boundingSphere = null; // update flags
  6299. this.verticesNeedUpdate = false;
  6300. this.normalsNeedUpdate = false;
  6301. this.colorsNeedUpdate = false;
  6302. this.uvsNeedUpdate = false;
  6303. this.groupsNeedUpdate = false;
  6304. }
  6305. var _proto = DirectGeometry.prototype;
  6306. _proto.computeGroups = function computeGroups(geometry) {
  6307. var groups = [];
  6308. var group, i;
  6309. var materialIndex = undefined;
  6310. var faces = geometry.faces;
  6311. for (i = 0; i < faces.length; i++) {
  6312. var face = faces[i]; // materials
  6313. if (face.materialIndex !== materialIndex) {
  6314. materialIndex = face.materialIndex;
  6315. if (group !== undefined) {
  6316. group.count = i * 3 - group.start;
  6317. groups.push(group);
  6318. }
  6319. group = {
  6320. start: i * 3,
  6321. materialIndex: materialIndex
  6322. };
  6323. }
  6324. }
  6325. if (group !== undefined) {
  6326. group.count = i * 3 - group.start;
  6327. groups.push(group);
  6328. }
  6329. this.groups = groups;
  6330. };
  6331. _proto.fromGeometry = function fromGeometry(geometry) {
  6332. var faces = geometry.faces;
  6333. var vertices = geometry.vertices;
  6334. var faceVertexUvs = geometry.faceVertexUvs;
  6335. var hasFaceVertexUv = faceVertexUvs[0] && faceVertexUvs[0].length > 0;
  6336. var hasFaceVertexUv2 = faceVertexUvs[1] && faceVertexUvs[1].length > 0; // morphs
  6337. var morphTargets = geometry.morphTargets;
  6338. var morphTargetsLength = morphTargets.length;
  6339. var morphTargetsPosition;
  6340. if (morphTargetsLength > 0) {
  6341. morphTargetsPosition = [];
  6342. for (var i = 0; i < morphTargetsLength; i++) {
  6343. morphTargetsPosition[i] = {
  6344. name: morphTargets[i].name,
  6345. data: []
  6346. };
  6347. }
  6348. this.morphTargets.position = morphTargetsPosition;
  6349. }
  6350. var morphNormals = geometry.morphNormals;
  6351. var morphNormalsLength = morphNormals.length;
  6352. var morphTargetsNormal;
  6353. if (morphNormalsLength > 0) {
  6354. morphTargetsNormal = [];
  6355. for (var _i = 0; _i < morphNormalsLength; _i++) {
  6356. morphTargetsNormal[_i] = {
  6357. name: morphNormals[_i].name,
  6358. data: []
  6359. };
  6360. }
  6361. this.morphTargets.normal = morphTargetsNormal;
  6362. } // skins
  6363. var skinIndices = geometry.skinIndices;
  6364. var skinWeights = geometry.skinWeights;
  6365. var hasSkinIndices = skinIndices.length === vertices.length;
  6366. var hasSkinWeights = skinWeights.length === vertices.length; //
  6367. if (vertices.length > 0 && faces.length === 0) {
  6368. console.error('THREE.DirectGeometry: Faceless geometries are not supported.');
  6369. }
  6370. for (var _i2 = 0; _i2 < faces.length; _i2++) {
  6371. var face = faces[_i2];
  6372. this.vertices.push(vertices[face.a], vertices[face.b], vertices[face.c]);
  6373. var vertexNormals = face.vertexNormals;
  6374. if (vertexNormals.length === 3) {
  6375. this.normals.push(vertexNormals[0], vertexNormals[1], vertexNormals[2]);
  6376. } else {
  6377. var normal = face.normal;
  6378. this.normals.push(normal, normal, normal);
  6379. }
  6380. var vertexColors = face.vertexColors;
  6381. if (vertexColors.length === 3) {
  6382. this.colors.push(vertexColors[0], vertexColors[1], vertexColors[2]);
  6383. } else {
  6384. var color = face.color;
  6385. this.colors.push(color, color, color);
  6386. }
  6387. if (hasFaceVertexUv === true) {
  6388. var vertexUvs = faceVertexUvs[0][_i2];
  6389. if (vertexUvs !== undefined) {
  6390. this.uvs.push(vertexUvs[0], vertexUvs[1], vertexUvs[2]);
  6391. } else {
  6392. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', _i2);
  6393. this.uvs.push(new Vector2(), new Vector2(), new Vector2());
  6394. }
  6395. }
  6396. if (hasFaceVertexUv2 === true) {
  6397. var _vertexUvs = faceVertexUvs[1][_i2];
  6398. if (_vertexUvs !== undefined) {
  6399. this.uvs2.push(_vertexUvs[0], _vertexUvs[1], _vertexUvs[2]);
  6400. } else {
  6401. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', _i2);
  6402. this.uvs2.push(new Vector2(), new Vector2(), new Vector2());
  6403. }
  6404. } // morphs
  6405. for (var j = 0; j < morphTargetsLength; j++) {
  6406. var morphTarget = morphTargets[j].vertices;
  6407. morphTargetsPosition[j].data.push(morphTarget[face.a], morphTarget[face.b], morphTarget[face.c]);
  6408. }
  6409. for (var _j = 0; _j < morphNormalsLength; _j++) {
  6410. var morphNormal = morphNormals[_j].vertexNormals[_i2];
  6411. morphTargetsNormal[_j].data.push(morphNormal.a, morphNormal.b, morphNormal.c);
  6412. } // skins
  6413. if (hasSkinIndices) {
  6414. this.skinIndices.push(skinIndices[face.a], skinIndices[face.b], skinIndices[face.c]);
  6415. }
  6416. if (hasSkinWeights) {
  6417. this.skinWeights.push(skinWeights[face.a], skinWeights[face.b], skinWeights[face.c]);
  6418. }
  6419. }
  6420. this.computeGroups(geometry);
  6421. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6422. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6423. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6424. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6425. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6426. if (geometry.boundingSphere !== null) {
  6427. this.boundingSphere = geometry.boundingSphere.clone();
  6428. }
  6429. if (geometry.boundingBox !== null) {
  6430. this.boundingBox = geometry.boundingBox.clone();
  6431. }
  6432. return this;
  6433. };
  6434. return DirectGeometry;
  6435. }();
  6436. function arrayMax(array) {
  6437. if (array.length === 0) return -Infinity;
  6438. var max = array[0];
  6439. for (var i = 1, l = array.length; i < l; ++i) {
  6440. if (array[i] > max) max = array[i];
  6441. }
  6442. return max;
  6443. }
  6444. var TYPED_ARRAYS = {
  6445. Int8Array: Int8Array,
  6446. Uint8Array: Uint8Array,
  6447. // Workaround for IE11 pre KB2929437. See #11440
  6448. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  6449. Int16Array: Int16Array,
  6450. Uint16Array: Uint16Array,
  6451. Int32Array: Int32Array,
  6452. Uint32Array: Uint32Array,
  6453. Float32Array: Float32Array,
  6454. Float64Array: Float64Array
  6455. };
  6456. function getTypedArray(type, buffer) {
  6457. return new TYPED_ARRAYS[type](buffer);
  6458. }
  6459. var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6460. var _m1$2 = new Matrix4();
  6461. var _obj = new Object3D();
  6462. var _offset = new Vector3();
  6463. var _box$2 = new Box3();
  6464. var _boxMorphTargets = new Box3();
  6465. var _vector$4 = new Vector3();
  6466. function BufferGeometry() {
  6467. Object.defineProperty(this, 'id', {
  6468. value: _bufferGeometryId += 2
  6469. });
  6470. this.uuid = MathUtils.generateUUID();
  6471. this.name = '';
  6472. this.type = 'BufferGeometry';
  6473. this.index = null;
  6474. this.attributes = {};
  6475. this.morphAttributes = {};
  6476. this.morphTargetsRelative = false;
  6477. this.groups = [];
  6478. this.boundingBox = null;
  6479. this.boundingSphere = null;
  6480. this.drawRange = {
  6481. start: 0,
  6482. count: Infinity
  6483. };
  6484. this.userData = {};
  6485. }
  6486. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  6487. constructor: BufferGeometry,
  6488. isBufferGeometry: true,
  6489. getIndex: function getIndex() {
  6490. return this.index;
  6491. },
  6492. setIndex: function setIndex(index) {
  6493. if (Array.isArray(index)) {
  6494. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  6495. } else {
  6496. this.index = index;
  6497. }
  6498. return this;
  6499. },
  6500. getAttribute: function getAttribute(name) {
  6501. return this.attributes[name];
  6502. },
  6503. setAttribute: function setAttribute(name, attribute) {
  6504. this.attributes[name] = attribute;
  6505. return this;
  6506. },
  6507. deleteAttribute: function deleteAttribute(name) {
  6508. delete this.attributes[name];
  6509. return this;
  6510. },
  6511. hasAttribute: function hasAttribute(name) {
  6512. return this.attributes[name] !== undefined;
  6513. },
  6514. addGroup: function addGroup(start, count, materialIndex) {
  6515. if (materialIndex === void 0) {
  6516. materialIndex = 0;
  6517. }
  6518. this.groups.push({
  6519. start: start,
  6520. count: count,
  6521. materialIndex: materialIndex
  6522. });
  6523. },
  6524. clearGroups: function clearGroups() {
  6525. this.groups = [];
  6526. },
  6527. setDrawRange: function setDrawRange(start, count) {
  6528. this.drawRange.start = start;
  6529. this.drawRange.count = count;
  6530. },
  6531. applyMatrix4: function applyMatrix4(matrix) {
  6532. var position = this.attributes.position;
  6533. if (position !== undefined) {
  6534. position.applyMatrix4(matrix);
  6535. position.needsUpdate = true;
  6536. }
  6537. var normal = this.attributes.normal;
  6538. if (normal !== undefined) {
  6539. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  6540. normal.applyNormalMatrix(normalMatrix);
  6541. normal.needsUpdate = true;
  6542. }
  6543. var tangent = this.attributes.tangent;
  6544. if (tangent !== undefined) {
  6545. tangent.transformDirection(matrix);
  6546. tangent.needsUpdate = true;
  6547. }
  6548. if (this.boundingBox !== null) {
  6549. this.computeBoundingBox();
  6550. }
  6551. if (this.boundingSphere !== null) {
  6552. this.computeBoundingSphere();
  6553. }
  6554. return this;
  6555. },
  6556. rotateX: function rotateX(angle) {
  6557. // rotate geometry around world x-axis
  6558. _m1$2.makeRotationX(angle);
  6559. this.applyMatrix4(_m1$2);
  6560. return this;
  6561. },
  6562. rotateY: function rotateY(angle) {
  6563. // rotate geometry around world y-axis
  6564. _m1$2.makeRotationY(angle);
  6565. this.applyMatrix4(_m1$2);
  6566. return this;
  6567. },
  6568. rotateZ: function rotateZ(angle) {
  6569. // rotate geometry around world z-axis
  6570. _m1$2.makeRotationZ(angle);
  6571. this.applyMatrix4(_m1$2);
  6572. return this;
  6573. },
  6574. translate: function translate(x, y, z) {
  6575. // translate geometry
  6576. _m1$2.makeTranslation(x, y, z);
  6577. this.applyMatrix4(_m1$2);
  6578. return this;
  6579. },
  6580. scale: function scale(x, y, z) {
  6581. // scale geometry
  6582. _m1$2.makeScale(x, y, z);
  6583. this.applyMatrix4(_m1$2);
  6584. return this;
  6585. },
  6586. lookAt: function lookAt(vector) {
  6587. _obj.lookAt(vector);
  6588. _obj.updateMatrix();
  6589. this.applyMatrix4(_obj.matrix);
  6590. return this;
  6591. },
  6592. center: function center() {
  6593. this.computeBoundingBox();
  6594. this.boundingBox.getCenter(_offset).negate();
  6595. this.translate(_offset.x, _offset.y, _offset.z);
  6596. return this;
  6597. },
  6598. setFromObject: function setFromObject(object) {
  6599. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6600. var geometry = object.geometry;
  6601. if (object.isPoints || object.isLine) {
  6602. var positions = new Float32BufferAttribute(geometry.vertices.length * 3, 3);
  6603. var colors = new Float32BufferAttribute(geometry.colors.length * 3, 3);
  6604. this.setAttribute('position', positions.copyVector3sArray(geometry.vertices));
  6605. this.setAttribute('color', colors.copyColorsArray(geometry.colors));
  6606. if (geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length) {
  6607. var lineDistances = new Float32BufferAttribute(geometry.lineDistances.length, 1);
  6608. this.setAttribute('lineDistance', lineDistances.copyArray(geometry.lineDistances));
  6609. }
  6610. if (geometry.boundingSphere !== null) {
  6611. this.boundingSphere = geometry.boundingSphere.clone();
  6612. }
  6613. if (geometry.boundingBox !== null) {
  6614. this.boundingBox = geometry.boundingBox.clone();
  6615. }
  6616. } else if (object.isMesh) {
  6617. if (geometry && geometry.isGeometry) {
  6618. this.fromGeometry(geometry);
  6619. }
  6620. }
  6621. return this;
  6622. },
  6623. setFromPoints: function setFromPoints(points) {
  6624. var position = [];
  6625. for (var i = 0, l = points.length; i < l; i++) {
  6626. var point = points[i];
  6627. position.push(point.x, point.y, point.z || 0);
  6628. }
  6629. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  6630. return this;
  6631. },
  6632. updateFromObject: function updateFromObject(object) {
  6633. var geometry = object.geometry;
  6634. if (object.isMesh) {
  6635. var direct = geometry.__directGeometry;
  6636. if (geometry.elementsNeedUpdate === true) {
  6637. direct = undefined;
  6638. geometry.elementsNeedUpdate = false;
  6639. }
  6640. if (direct === undefined) {
  6641. return this.fromGeometry(geometry);
  6642. }
  6643. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6644. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6645. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6646. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6647. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6648. geometry.verticesNeedUpdate = false;
  6649. geometry.normalsNeedUpdate = false;
  6650. geometry.colorsNeedUpdate = false;
  6651. geometry.uvsNeedUpdate = false;
  6652. geometry.groupsNeedUpdate = false;
  6653. geometry = direct;
  6654. }
  6655. if (geometry.verticesNeedUpdate === true) {
  6656. var attribute = this.attributes.position;
  6657. if (attribute !== undefined) {
  6658. attribute.copyVector3sArray(geometry.vertices);
  6659. attribute.needsUpdate = true;
  6660. }
  6661. geometry.verticesNeedUpdate = false;
  6662. }
  6663. if (geometry.normalsNeedUpdate === true) {
  6664. var _attribute = this.attributes.normal;
  6665. if (_attribute !== undefined) {
  6666. _attribute.copyVector3sArray(geometry.normals);
  6667. _attribute.needsUpdate = true;
  6668. }
  6669. geometry.normalsNeedUpdate = false;
  6670. }
  6671. if (geometry.colorsNeedUpdate === true) {
  6672. var _attribute2 = this.attributes.color;
  6673. if (_attribute2 !== undefined) {
  6674. _attribute2.copyColorsArray(geometry.colors);
  6675. _attribute2.needsUpdate = true;
  6676. }
  6677. geometry.colorsNeedUpdate = false;
  6678. }
  6679. if (geometry.uvsNeedUpdate) {
  6680. var _attribute3 = this.attributes.uv;
  6681. if (_attribute3 !== undefined) {
  6682. _attribute3.copyVector2sArray(geometry.uvs);
  6683. _attribute3.needsUpdate = true;
  6684. }
  6685. geometry.uvsNeedUpdate = false;
  6686. }
  6687. if (geometry.lineDistancesNeedUpdate) {
  6688. var _attribute4 = this.attributes.lineDistance;
  6689. if (_attribute4 !== undefined) {
  6690. _attribute4.copyArray(geometry.lineDistances);
  6691. _attribute4.needsUpdate = true;
  6692. }
  6693. geometry.lineDistancesNeedUpdate = false;
  6694. }
  6695. if (geometry.groupsNeedUpdate) {
  6696. geometry.computeGroups(object.geometry);
  6697. this.groups = geometry.groups;
  6698. geometry.groupsNeedUpdate = false;
  6699. }
  6700. return this;
  6701. },
  6702. fromGeometry: function fromGeometry(geometry) {
  6703. geometry.__directGeometry = new DirectGeometry().fromGeometry(geometry);
  6704. return this.fromDirectGeometry(geometry.__directGeometry);
  6705. },
  6706. fromDirectGeometry: function fromDirectGeometry(geometry) {
  6707. var positions = new Float32Array(geometry.vertices.length * 3);
  6708. this.setAttribute('position', new BufferAttribute(positions, 3).copyVector3sArray(geometry.vertices));
  6709. if (geometry.normals.length > 0) {
  6710. var normals = new Float32Array(geometry.normals.length * 3);
  6711. this.setAttribute('normal', new BufferAttribute(normals, 3).copyVector3sArray(geometry.normals));
  6712. }
  6713. if (geometry.colors.length > 0) {
  6714. var colors = new Float32Array(geometry.colors.length * 3);
  6715. this.setAttribute('color', new BufferAttribute(colors, 3).copyColorsArray(geometry.colors));
  6716. }
  6717. if (geometry.uvs.length > 0) {
  6718. var uvs = new Float32Array(geometry.uvs.length * 2);
  6719. this.setAttribute('uv', new BufferAttribute(uvs, 2).copyVector2sArray(geometry.uvs));
  6720. }
  6721. if (geometry.uvs2.length > 0) {
  6722. var uvs2 = new Float32Array(geometry.uvs2.length * 2);
  6723. this.setAttribute('uv2', new BufferAttribute(uvs2, 2).copyVector2sArray(geometry.uvs2));
  6724. } // groups
  6725. this.groups = geometry.groups; // morphs
  6726. for (var name in geometry.morphTargets) {
  6727. var array = [];
  6728. var morphTargets = geometry.morphTargets[name];
  6729. for (var i = 0, l = morphTargets.length; i < l; i++) {
  6730. var morphTarget = morphTargets[i];
  6731. var attribute = new Float32BufferAttribute(morphTarget.data.length * 3, 3);
  6732. attribute.name = morphTarget.name;
  6733. array.push(attribute.copyVector3sArray(morphTarget.data));
  6734. }
  6735. this.morphAttributes[name] = array;
  6736. } // skinning
  6737. if (geometry.skinIndices.length > 0) {
  6738. var skinIndices = new Float32BufferAttribute(geometry.skinIndices.length * 4, 4);
  6739. this.setAttribute('skinIndex', skinIndices.copyVector4sArray(geometry.skinIndices));
  6740. }
  6741. if (geometry.skinWeights.length > 0) {
  6742. var skinWeights = new Float32BufferAttribute(geometry.skinWeights.length * 4, 4);
  6743. this.setAttribute('skinWeight', skinWeights.copyVector4sArray(geometry.skinWeights));
  6744. } //
  6745. if (geometry.boundingSphere !== null) {
  6746. this.boundingSphere = geometry.boundingSphere.clone();
  6747. }
  6748. if (geometry.boundingBox !== null) {
  6749. this.boundingBox = geometry.boundingBox.clone();
  6750. }
  6751. return this;
  6752. },
  6753. computeBoundingBox: function computeBoundingBox() {
  6754. if (this.boundingBox === null) {
  6755. this.boundingBox = new Box3();
  6756. }
  6757. var position = this.attributes.position;
  6758. var morphAttributesPosition = this.morphAttributes.position;
  6759. if (position && position.isGLBufferAttribute) {
  6760. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  6761. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  6762. return;
  6763. }
  6764. if (position !== undefined) {
  6765. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  6766. if (morphAttributesPosition) {
  6767. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6768. var morphAttribute = morphAttributesPosition[i];
  6769. _box$2.setFromBufferAttribute(morphAttribute);
  6770. if (this.morphTargetsRelative) {
  6771. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  6772. this.boundingBox.expandByPoint(_vector$4);
  6773. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  6774. this.boundingBox.expandByPoint(_vector$4);
  6775. } else {
  6776. this.boundingBox.expandByPoint(_box$2.min);
  6777. this.boundingBox.expandByPoint(_box$2.max);
  6778. }
  6779. }
  6780. }
  6781. } else {
  6782. this.boundingBox.makeEmpty();
  6783. }
  6784. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  6785. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  6786. }
  6787. },
  6788. computeBoundingSphere: function computeBoundingSphere() {
  6789. if (this.boundingSphere === null) {
  6790. this.boundingSphere = new Sphere();
  6791. }
  6792. var position = this.attributes.position;
  6793. var morphAttributesPosition = this.morphAttributes.position;
  6794. if (position && position.isGLBufferAttribute) {
  6795. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  6796. this.boundingSphere.set(new Vector3(), Infinity);
  6797. return;
  6798. }
  6799. if (position) {
  6800. // first, find the center of the bounding sphere
  6801. var center = this.boundingSphere.center;
  6802. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  6803. if (morphAttributesPosition) {
  6804. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6805. var morphAttribute = morphAttributesPosition[i];
  6806. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  6807. if (this.morphTargetsRelative) {
  6808. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  6809. _box$2.expandByPoint(_vector$4);
  6810. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  6811. _box$2.expandByPoint(_vector$4);
  6812. } else {
  6813. _box$2.expandByPoint(_boxMorphTargets.min);
  6814. _box$2.expandByPoint(_boxMorphTargets.max);
  6815. }
  6816. }
  6817. }
  6818. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  6819. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6820. var maxRadiusSq = 0;
  6821. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  6822. _vector$4.fromBufferAttribute(position, _i);
  6823. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6824. } // process morph attributes if present
  6825. if (morphAttributesPosition) {
  6826. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  6827. var _morphAttribute = morphAttributesPosition[_i2];
  6828. var morphTargetsRelative = this.morphTargetsRelative;
  6829. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  6830. _vector$4.fromBufferAttribute(_morphAttribute, j);
  6831. if (morphTargetsRelative) {
  6832. _offset.fromBufferAttribute(position, j);
  6833. _vector$4.add(_offset);
  6834. }
  6835. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6836. }
  6837. }
  6838. }
  6839. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  6840. if (isNaN(this.boundingSphere.radius)) {
  6841. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  6842. }
  6843. }
  6844. },
  6845. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  6846. },
  6847. computeVertexNormals: function computeVertexNormals() {
  6848. var index = this.index;
  6849. var positionAttribute = this.getAttribute('position');
  6850. if (positionAttribute !== undefined) {
  6851. var normalAttribute = this.getAttribute('normal');
  6852. if (normalAttribute === undefined) {
  6853. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  6854. this.setAttribute('normal', normalAttribute);
  6855. } else {
  6856. // reset existing normals to zero
  6857. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  6858. normalAttribute.setXYZ(i, 0, 0, 0);
  6859. }
  6860. }
  6861. var pA = new Vector3(),
  6862. pB = new Vector3(),
  6863. pC = new Vector3();
  6864. var nA = new Vector3(),
  6865. nB = new Vector3(),
  6866. nC = new Vector3();
  6867. var cb = new Vector3(),
  6868. ab = new Vector3(); // indexed elements
  6869. if (index) {
  6870. for (var _i3 = 0, _il3 = index.count; _i3 < _il3; _i3 += 3) {
  6871. var vA = index.getX(_i3 + 0);
  6872. var vB = index.getX(_i3 + 1);
  6873. var vC = index.getX(_i3 + 2);
  6874. pA.fromBufferAttribute(positionAttribute, vA);
  6875. pB.fromBufferAttribute(positionAttribute, vB);
  6876. pC.fromBufferAttribute(positionAttribute, vC);
  6877. cb.subVectors(pC, pB);
  6878. ab.subVectors(pA, pB);
  6879. cb.cross(ab);
  6880. nA.fromBufferAttribute(normalAttribute, vA);
  6881. nB.fromBufferAttribute(normalAttribute, vB);
  6882. nC.fromBufferAttribute(normalAttribute, vC);
  6883. nA.add(cb);
  6884. nB.add(cb);
  6885. nC.add(cb);
  6886. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  6887. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  6888. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  6889. }
  6890. } else {
  6891. // non-indexed elements (unconnected triangle soup)
  6892. for (var _i4 = 0, _il4 = positionAttribute.count; _i4 < _il4; _i4 += 3) {
  6893. pA.fromBufferAttribute(positionAttribute, _i4 + 0);
  6894. pB.fromBufferAttribute(positionAttribute, _i4 + 1);
  6895. pC.fromBufferAttribute(positionAttribute, _i4 + 2);
  6896. cb.subVectors(pC, pB);
  6897. ab.subVectors(pA, pB);
  6898. cb.cross(ab);
  6899. normalAttribute.setXYZ(_i4 + 0, cb.x, cb.y, cb.z);
  6900. normalAttribute.setXYZ(_i4 + 1, cb.x, cb.y, cb.z);
  6901. normalAttribute.setXYZ(_i4 + 2, cb.x, cb.y, cb.z);
  6902. }
  6903. }
  6904. this.normalizeNormals();
  6905. normalAttribute.needsUpdate = true;
  6906. }
  6907. },
  6908. merge: function merge(geometry, offset) {
  6909. if (!(geometry && geometry.isBufferGeometry)) {
  6910. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  6911. return;
  6912. }
  6913. if (offset === undefined) {
  6914. offset = 0;
  6915. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  6916. }
  6917. var attributes = this.attributes;
  6918. for (var key in attributes) {
  6919. if (geometry.attributes[key] === undefined) continue;
  6920. var attribute1 = attributes[key];
  6921. var attributeArray1 = attribute1.array;
  6922. var attribute2 = geometry.attributes[key];
  6923. var attributeArray2 = attribute2.array;
  6924. var attributeOffset = attribute2.itemSize * offset;
  6925. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  6926. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  6927. attributeArray1[j] = attributeArray2[i];
  6928. }
  6929. }
  6930. return this;
  6931. },
  6932. normalizeNormals: function normalizeNormals() {
  6933. var normals = this.attributes.normal;
  6934. for (var i = 0, il = normals.count; i < il; i++) {
  6935. _vector$4.fromBufferAttribute(normals, i);
  6936. _vector$4.normalize();
  6937. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  6938. }
  6939. },
  6940. toNonIndexed: function toNonIndexed() {
  6941. function convertBufferAttribute(attribute, indices) {
  6942. var array = attribute.array;
  6943. var itemSize = attribute.itemSize;
  6944. var normalized = attribute.normalized;
  6945. var array2 = new array.constructor(indices.length * itemSize);
  6946. var index = 0,
  6947. index2 = 0;
  6948. for (var i = 0, l = indices.length; i < l; i++) {
  6949. index = indices[i] * itemSize;
  6950. for (var j = 0; j < itemSize; j++) {
  6951. array2[index2++] = array[index++];
  6952. }
  6953. }
  6954. return new BufferAttribute(array2, itemSize, normalized);
  6955. } //
  6956. if (this.index === null) {
  6957. console.warn('THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.');
  6958. return this;
  6959. }
  6960. var geometry2 = new BufferGeometry();
  6961. var indices = this.index.array;
  6962. var attributes = this.attributes; // attributes
  6963. for (var name in attributes) {
  6964. var attribute = attributes[name];
  6965. var newAttribute = convertBufferAttribute(attribute, indices);
  6966. geometry2.setAttribute(name, newAttribute);
  6967. } // morph attributes
  6968. var morphAttributes = this.morphAttributes;
  6969. for (var _name in morphAttributes) {
  6970. var morphArray = [];
  6971. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  6972. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  6973. var _attribute5 = morphAttribute[i];
  6974. var _newAttribute = convertBufferAttribute(_attribute5, indices);
  6975. morphArray.push(_newAttribute);
  6976. }
  6977. geometry2.morphAttributes[_name] = morphArray;
  6978. }
  6979. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  6980. var groups = this.groups;
  6981. for (var _i5 = 0, l = groups.length; _i5 < l; _i5++) {
  6982. var group = groups[_i5];
  6983. geometry2.addGroup(group.start, group.count, group.materialIndex);
  6984. }
  6985. return geometry2;
  6986. },
  6987. toJSON: function toJSON() {
  6988. var data = {
  6989. metadata: {
  6990. version: 4.5,
  6991. type: 'BufferGeometry',
  6992. generator: 'BufferGeometry.toJSON'
  6993. }
  6994. }; // standard BufferGeometry serialization
  6995. data.uuid = this.uuid;
  6996. data.type = this.type;
  6997. if (this.name !== '') data.name = this.name;
  6998. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  6999. if (this.parameters !== undefined) {
  7000. var parameters = this.parameters;
  7001. for (var key in parameters) {
  7002. if (parameters[key] !== undefined) data[key] = parameters[key];
  7003. }
  7004. return data;
  7005. }
  7006. data.data = {
  7007. attributes: {}
  7008. };
  7009. var index = this.index;
  7010. if (index !== null) {
  7011. data.data.index = {
  7012. type: index.array.constructor.name,
  7013. array: Array.prototype.slice.call(index.array)
  7014. };
  7015. }
  7016. var attributes = this.attributes;
  7017. for (var _key in attributes) {
  7018. var attribute = attributes[_key];
  7019. var attributeData = attribute.toJSON(data.data);
  7020. if (attribute.name !== '') attributeData.name = attribute.name;
  7021. data.data.attributes[_key] = attributeData;
  7022. }
  7023. var morphAttributes = {};
  7024. var hasMorphAttributes = false;
  7025. for (var _key2 in this.morphAttributes) {
  7026. var attributeArray = this.morphAttributes[_key2];
  7027. var array = [];
  7028. for (var i = 0, il = attributeArray.length; i < il; i++) {
  7029. var _attribute6 = attributeArray[i];
  7030. var _attributeData = _attribute6.toJSON(data.data);
  7031. if (_attribute6.name !== '') _attributeData.name = _attribute6.name;
  7032. array.push(_attributeData);
  7033. }
  7034. if (array.length > 0) {
  7035. morphAttributes[_key2] = array;
  7036. hasMorphAttributes = true;
  7037. }
  7038. }
  7039. if (hasMorphAttributes) {
  7040. data.data.morphAttributes = morphAttributes;
  7041. data.data.morphTargetsRelative = this.morphTargetsRelative;
  7042. }
  7043. var groups = this.groups;
  7044. if (groups.length > 0) {
  7045. data.data.groups = JSON.parse(JSON.stringify(groups));
  7046. }
  7047. var boundingSphere = this.boundingSphere;
  7048. if (boundingSphere !== null) {
  7049. data.data.boundingSphere = {
  7050. center: boundingSphere.center.toArray(),
  7051. radius: boundingSphere.radius
  7052. };
  7053. }
  7054. return data;
  7055. },
  7056. clone: function clone() {
  7057. /*
  7058. // Handle primitives
  7059. const parameters = this.parameters;
  7060. if ( parameters !== undefined ) {
  7061. const values = [];
  7062. for ( const key in parameters ) {
  7063. values.push( parameters[ key ] );
  7064. }
  7065. const geometry = Object.create( this.constructor.prototype );
  7066. this.constructor.apply( geometry, values );
  7067. return geometry;
  7068. }
  7069. return new this.constructor().copy( this );
  7070. */
  7071. return new BufferGeometry().copy(this);
  7072. },
  7073. copy: function copy(source) {
  7074. // reset
  7075. this.index = null;
  7076. this.attributes = {};
  7077. this.morphAttributes = {};
  7078. this.groups = [];
  7079. this.boundingBox = null;
  7080. this.boundingSphere = null; // used for storing cloned, shared data
  7081. var data = {}; // name
  7082. this.name = source.name; // index
  7083. var index = source.index;
  7084. if (index !== null) {
  7085. this.setIndex(index.clone(data));
  7086. } // attributes
  7087. var attributes = source.attributes;
  7088. for (var name in attributes) {
  7089. var attribute = attributes[name];
  7090. this.setAttribute(name, attribute.clone(data));
  7091. } // morph attributes
  7092. var morphAttributes = source.morphAttributes;
  7093. for (var _name2 in morphAttributes) {
  7094. var array = [];
  7095. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  7096. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  7097. array.push(morphAttribute[i].clone(data));
  7098. }
  7099. this.morphAttributes[_name2] = array;
  7100. }
  7101. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  7102. var groups = source.groups;
  7103. for (var _i6 = 0, _l = groups.length; _i6 < _l; _i6++) {
  7104. var group = groups[_i6];
  7105. this.addGroup(group.start, group.count, group.materialIndex);
  7106. } // bounding box
  7107. var boundingBox = source.boundingBox;
  7108. if (boundingBox !== null) {
  7109. this.boundingBox = boundingBox.clone();
  7110. } // bounding sphere
  7111. var boundingSphere = source.boundingSphere;
  7112. if (boundingSphere !== null) {
  7113. this.boundingSphere = boundingSphere.clone();
  7114. } // draw range
  7115. this.drawRange.start = source.drawRange.start;
  7116. this.drawRange.count = source.drawRange.count; // user data
  7117. this.userData = source.userData;
  7118. return this;
  7119. },
  7120. dispose: function dispose() {
  7121. this.dispatchEvent({
  7122. type: 'dispose'
  7123. });
  7124. }
  7125. });
  7126. var _inverseMatrix = new Matrix4();
  7127. var _ray = new Ray();
  7128. var _sphere = new Sphere();
  7129. var _vA = new Vector3();
  7130. var _vB = new Vector3();
  7131. var _vC = new Vector3();
  7132. var _tempA = new Vector3();
  7133. var _tempB = new Vector3();
  7134. var _tempC = new Vector3();
  7135. var _morphA = new Vector3();
  7136. var _morphB = new Vector3();
  7137. var _morphC = new Vector3();
  7138. var _uvA = new Vector2();
  7139. var _uvB = new Vector2();
  7140. var _uvC = new Vector2();
  7141. var _intersectionPoint = new Vector3();
  7142. var _intersectionPointWorld = new Vector3();
  7143. function Mesh(geometry, material) {
  7144. if (geometry === void 0) {
  7145. geometry = new BufferGeometry();
  7146. }
  7147. if (material === void 0) {
  7148. material = new MeshBasicMaterial();
  7149. }
  7150. Object3D.call(this);
  7151. this.type = 'Mesh';
  7152. this.geometry = geometry;
  7153. this.material = material;
  7154. this.updateMorphTargets();
  7155. }
  7156. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7157. constructor: Mesh,
  7158. isMesh: true,
  7159. copy: function copy(source) {
  7160. Object3D.prototype.copy.call(this, source);
  7161. if (source.morphTargetInfluences !== undefined) {
  7162. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7163. }
  7164. if (source.morphTargetDictionary !== undefined) {
  7165. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7166. }
  7167. this.material = source.material;
  7168. this.geometry = source.geometry;
  7169. return this;
  7170. },
  7171. updateMorphTargets: function updateMorphTargets() {
  7172. var geometry = this.geometry;
  7173. if (geometry.isBufferGeometry) {
  7174. var morphAttributes = geometry.morphAttributes;
  7175. var keys = Object.keys(morphAttributes);
  7176. if (keys.length > 0) {
  7177. var morphAttribute = morphAttributes[keys[0]];
  7178. if (morphAttribute !== undefined) {
  7179. this.morphTargetInfluences = [];
  7180. this.morphTargetDictionary = {};
  7181. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7182. var name = morphAttribute[m].name || String(m);
  7183. this.morphTargetInfluences.push(0);
  7184. this.morphTargetDictionary[name] = m;
  7185. }
  7186. }
  7187. }
  7188. } else {
  7189. var morphTargets = geometry.morphTargets;
  7190. if (morphTargets !== undefined && morphTargets.length > 0) {
  7191. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7192. }
  7193. }
  7194. },
  7195. raycast: function raycast(raycaster, intersects) {
  7196. var geometry = this.geometry;
  7197. var material = this.material;
  7198. var matrixWorld = this.matrixWorld;
  7199. if (material === undefined) return; // Checking boundingSphere distance to ray
  7200. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7201. _sphere.copy(geometry.boundingSphere);
  7202. _sphere.applyMatrix4(matrixWorld);
  7203. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7204. _inverseMatrix.copy(matrixWorld).invert();
  7205. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7206. if (geometry.boundingBox !== null) {
  7207. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7208. }
  7209. var intersection;
  7210. if (geometry.isBufferGeometry) {
  7211. var index = geometry.index;
  7212. var position = geometry.attributes.position;
  7213. var morphPosition = geometry.morphAttributes.position;
  7214. var morphTargetsRelative = geometry.morphTargetsRelative;
  7215. var uv = geometry.attributes.uv;
  7216. var uv2 = geometry.attributes.uv2;
  7217. var groups = geometry.groups;
  7218. var drawRange = geometry.drawRange;
  7219. if (index !== null) {
  7220. // indexed buffer geometry
  7221. if (Array.isArray(material)) {
  7222. for (var i = 0, il = groups.length; i < il; i++) {
  7223. var group = groups[i];
  7224. var groupMaterial = material[group.materialIndex];
  7225. var start = Math.max(group.start, drawRange.start);
  7226. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7227. for (var j = start, jl = end; j < jl; j += 3) {
  7228. var a = index.getX(j);
  7229. var b = index.getX(j + 1);
  7230. var c = index.getX(j + 2);
  7231. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7232. if (intersection) {
  7233. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7234. intersection.face.materialIndex = group.materialIndex;
  7235. intersects.push(intersection);
  7236. }
  7237. }
  7238. }
  7239. } else {
  7240. var _start = Math.max(0, drawRange.start);
  7241. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7242. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7243. var _a = index.getX(_i);
  7244. var _b = index.getX(_i + 1);
  7245. var _c = index.getX(_i + 2);
  7246. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7247. if (intersection) {
  7248. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7249. intersects.push(intersection);
  7250. }
  7251. }
  7252. }
  7253. } else if (position !== undefined) {
  7254. // non-indexed buffer geometry
  7255. if (Array.isArray(material)) {
  7256. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7257. var _group = groups[_i2];
  7258. var _groupMaterial = material[_group.materialIndex];
  7259. var _start2 = Math.max(_group.start, drawRange.start);
  7260. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7261. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7262. var _a2 = _j;
  7263. var _b2 = _j + 1;
  7264. var _c2 = _j + 2;
  7265. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7266. if (intersection) {
  7267. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7268. intersection.face.materialIndex = _group.materialIndex;
  7269. intersects.push(intersection);
  7270. }
  7271. }
  7272. }
  7273. } else {
  7274. var _start3 = Math.max(0, drawRange.start);
  7275. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7276. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7277. var _a3 = _i3;
  7278. var _b3 = _i3 + 1;
  7279. var _c3 = _i3 + 2;
  7280. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7281. if (intersection) {
  7282. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7283. intersects.push(intersection);
  7284. }
  7285. }
  7286. }
  7287. }
  7288. } else if (geometry.isGeometry) {
  7289. console.error('THREE.Mesh.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7290. }
  7291. }
  7292. });
  7293. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7294. var intersect;
  7295. if (material.side === BackSide) {
  7296. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7297. } else {
  7298. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7299. }
  7300. if (intersect === null) return null;
  7301. _intersectionPointWorld.copy(point);
  7302. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7303. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7304. if (distance < raycaster.near || distance > raycaster.far) return null;
  7305. return {
  7306. distance: distance,
  7307. point: _intersectionPointWorld.clone(),
  7308. object: object
  7309. };
  7310. }
  7311. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7312. _vA.fromBufferAttribute(position, a);
  7313. _vB.fromBufferAttribute(position, b);
  7314. _vC.fromBufferAttribute(position, c);
  7315. var morphInfluences = object.morphTargetInfluences;
  7316. if (material.morphTargets && morphPosition && morphInfluences) {
  7317. _morphA.set(0, 0, 0);
  7318. _morphB.set(0, 0, 0);
  7319. _morphC.set(0, 0, 0);
  7320. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7321. var influence = morphInfluences[i];
  7322. var morphAttribute = morphPosition[i];
  7323. if (influence === 0) continue;
  7324. _tempA.fromBufferAttribute(morphAttribute, a);
  7325. _tempB.fromBufferAttribute(morphAttribute, b);
  7326. _tempC.fromBufferAttribute(morphAttribute, c);
  7327. if (morphTargetsRelative) {
  7328. _morphA.addScaledVector(_tempA, influence);
  7329. _morphB.addScaledVector(_tempB, influence);
  7330. _morphC.addScaledVector(_tempC, influence);
  7331. } else {
  7332. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7333. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7334. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7335. }
  7336. }
  7337. _vA.add(_morphA);
  7338. _vB.add(_morphB);
  7339. _vC.add(_morphC);
  7340. }
  7341. if (object.isSkinnedMesh) {
  7342. object.boneTransform(a, _vA);
  7343. object.boneTransform(b, _vB);
  7344. object.boneTransform(c, _vC);
  7345. }
  7346. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7347. if (intersection) {
  7348. if (uv) {
  7349. _uvA.fromBufferAttribute(uv, a);
  7350. _uvB.fromBufferAttribute(uv, b);
  7351. _uvC.fromBufferAttribute(uv, c);
  7352. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7353. }
  7354. if (uv2) {
  7355. _uvA.fromBufferAttribute(uv2, a);
  7356. _uvB.fromBufferAttribute(uv2, b);
  7357. _uvC.fromBufferAttribute(uv2, c);
  7358. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7359. }
  7360. var face = new Face3(a, b, c);
  7361. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7362. intersection.face = face;
  7363. }
  7364. return intersection;
  7365. }
  7366. var BoxGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7367. _inheritsLoose(BoxGeometry, _BufferGeometry);
  7368. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7369. var _this;
  7370. if (width === void 0) {
  7371. width = 1;
  7372. }
  7373. if (height === void 0) {
  7374. height = 1;
  7375. }
  7376. if (depth === void 0) {
  7377. depth = 1;
  7378. }
  7379. if (widthSegments === void 0) {
  7380. widthSegments = 1;
  7381. }
  7382. if (heightSegments === void 0) {
  7383. heightSegments = 1;
  7384. }
  7385. if (depthSegments === void 0) {
  7386. depthSegments = 1;
  7387. }
  7388. _this = _BufferGeometry.call(this) || this;
  7389. _this.type = 'BoxGeometry';
  7390. _this.parameters = {
  7391. width: width,
  7392. height: height,
  7393. depth: depth,
  7394. widthSegments: widthSegments,
  7395. heightSegments: heightSegments,
  7396. depthSegments: depthSegments
  7397. };
  7398. var scope = _assertThisInitialized(_this); // segments
  7399. widthSegments = Math.floor(widthSegments);
  7400. heightSegments = Math.floor(heightSegments);
  7401. depthSegments = Math.floor(depthSegments); // buffers
  7402. var indices = [];
  7403. var vertices = [];
  7404. var normals = [];
  7405. var uvs = []; // helper variables
  7406. var numberOfVertices = 0;
  7407. var groupStart = 0; // build each side of the box geometry
  7408. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7409. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7410. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7411. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7412. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7413. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7414. // build geometry
  7415. _this.setIndex(indices);
  7416. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7417. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7418. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7419. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7420. var segmentWidth = width / gridX;
  7421. var segmentHeight = height / gridY;
  7422. var widthHalf = width / 2;
  7423. var heightHalf = height / 2;
  7424. var depthHalf = depth / 2;
  7425. var gridX1 = gridX + 1;
  7426. var gridY1 = gridY + 1;
  7427. var vertexCounter = 0;
  7428. var groupCount = 0;
  7429. var vector = new Vector3(); // generate vertices, normals and uvs
  7430. for (var iy = 0; iy < gridY1; iy++) {
  7431. var y = iy * segmentHeight - heightHalf;
  7432. for (var ix = 0; ix < gridX1; ix++) {
  7433. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7434. vector[u] = x * udir;
  7435. vector[v] = y * vdir;
  7436. vector[w] = depthHalf; // now apply vector to vertex buffer
  7437. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7438. vector[u] = 0;
  7439. vector[v] = 0;
  7440. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7441. normals.push(vector.x, vector.y, vector.z); // uvs
  7442. uvs.push(ix / gridX);
  7443. uvs.push(1 - iy / gridY); // counters
  7444. vertexCounter += 1;
  7445. }
  7446. } // indices
  7447. // 1. you need three indices to draw a single face
  7448. // 2. a single segment consists of two faces
  7449. // 3. so we need to generate six (2*3) indices per segment
  7450. for (var _iy = 0; _iy < gridY; _iy++) {
  7451. for (var _ix = 0; _ix < gridX; _ix++) {
  7452. var a = numberOfVertices + _ix + gridX1 * _iy;
  7453. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7454. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7455. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7456. indices.push(a, b, d);
  7457. indices.push(b, c, d); // increase counter
  7458. groupCount += 6;
  7459. }
  7460. } // add a group to the geometry. this will ensure multi material support
  7461. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7462. groupStart += groupCount; // update total number of vertices
  7463. numberOfVertices += vertexCounter;
  7464. }
  7465. return _this;
  7466. }
  7467. return BoxGeometry;
  7468. }(BufferGeometry);
  7469. /**
  7470. * Uniform Utilities
  7471. */
  7472. function cloneUniforms(src) {
  7473. var dst = {};
  7474. for (var u in src) {
  7475. dst[u] = {};
  7476. for (var p in src[u]) {
  7477. var property = src[u][p];
  7478. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture)) {
  7479. dst[u][p] = property.clone();
  7480. } else if (Array.isArray(property)) {
  7481. dst[u][p] = property.slice();
  7482. } else {
  7483. dst[u][p] = property;
  7484. }
  7485. }
  7486. }
  7487. return dst;
  7488. }
  7489. function mergeUniforms(uniforms) {
  7490. var merged = {};
  7491. for (var u = 0; u < uniforms.length; u++) {
  7492. var tmp = cloneUniforms(uniforms[u]);
  7493. for (var p in tmp) {
  7494. merged[p] = tmp[p];
  7495. }
  7496. }
  7497. return merged;
  7498. } // Legacy
  7499. var UniformsUtils = {
  7500. clone: cloneUniforms,
  7501. merge: mergeUniforms
  7502. };
  7503. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7504. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7505. /**
  7506. * parameters = {
  7507. * defines: { "label" : "value" },
  7508. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7509. *
  7510. * fragmentShader: <string>,
  7511. * vertexShader: <string>,
  7512. *
  7513. * wireframe: <boolean>,
  7514. * wireframeLinewidth: <float>,
  7515. *
  7516. * lights: <bool>,
  7517. *
  7518. * skinning: <bool>,
  7519. * morphTargets: <bool>,
  7520. * morphNormals: <bool>
  7521. * }
  7522. */
  7523. function ShaderMaterial(parameters) {
  7524. Material.call(this);
  7525. this.type = 'ShaderMaterial';
  7526. this.defines = {};
  7527. this.uniforms = {};
  7528. this.vertexShader = default_vertex;
  7529. this.fragmentShader = default_fragment;
  7530. this.linewidth = 1;
  7531. this.wireframe = false;
  7532. this.wireframeLinewidth = 1;
  7533. this.fog = false; // set to use scene fog
  7534. this.lights = false; // set to use scene lights
  7535. this.clipping = false; // set to use user-defined clipping planes
  7536. this.skinning = false; // set to use skinning attribute streams
  7537. this.morphTargets = false; // set to use morph targets
  7538. this.morphNormals = false; // set to use morph normals
  7539. this.extensions = {
  7540. derivatives: false,
  7541. // set to use derivatives
  7542. fragDepth: false,
  7543. // set to use fragment depth values
  7544. drawBuffers: false,
  7545. // set to use draw buffers
  7546. shaderTextureLOD: false // set to use shader texture LOD
  7547. }; // When rendered geometry doesn't include these attributes but the material does,
  7548. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7549. this.defaultAttributeValues = {
  7550. 'color': [1, 1, 1],
  7551. 'uv': [0, 0],
  7552. 'uv2': [0, 0]
  7553. };
  7554. this.index0AttributeName = undefined;
  7555. this.uniformsNeedUpdate = false;
  7556. this.glslVersion = null;
  7557. if (parameters !== undefined) {
  7558. if (parameters.attributes !== undefined) {
  7559. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  7560. }
  7561. this.setValues(parameters);
  7562. }
  7563. }
  7564. ShaderMaterial.prototype = Object.create(Material.prototype);
  7565. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7566. ShaderMaterial.prototype.isShaderMaterial = true;
  7567. ShaderMaterial.prototype.copy = function (source) {
  7568. Material.prototype.copy.call(this, source);
  7569. this.fragmentShader = source.fragmentShader;
  7570. this.vertexShader = source.vertexShader;
  7571. this.uniforms = cloneUniforms(source.uniforms);
  7572. this.defines = Object.assign({}, source.defines);
  7573. this.wireframe = source.wireframe;
  7574. this.wireframeLinewidth = source.wireframeLinewidth;
  7575. this.lights = source.lights;
  7576. this.clipping = source.clipping;
  7577. this.skinning = source.skinning;
  7578. this.morphTargets = source.morphTargets;
  7579. this.morphNormals = source.morphNormals;
  7580. this.extensions = Object.assign({}, source.extensions);
  7581. this.glslVersion = source.glslVersion;
  7582. return this;
  7583. };
  7584. ShaderMaterial.prototype.toJSON = function (meta) {
  7585. var data = Material.prototype.toJSON.call(this, meta);
  7586. data.glslVersion = this.glslVersion;
  7587. data.uniforms = {};
  7588. for (var name in this.uniforms) {
  7589. var uniform = this.uniforms[name];
  7590. var value = uniform.value;
  7591. if (value && value.isTexture) {
  7592. data.uniforms[name] = {
  7593. type: 't',
  7594. value: value.toJSON(meta).uuid
  7595. };
  7596. } else if (value && value.isColor) {
  7597. data.uniforms[name] = {
  7598. type: 'c',
  7599. value: value.getHex()
  7600. };
  7601. } else if (value && value.isVector2) {
  7602. data.uniforms[name] = {
  7603. type: 'v2',
  7604. value: value.toArray()
  7605. };
  7606. } else if (value && value.isVector3) {
  7607. data.uniforms[name] = {
  7608. type: 'v3',
  7609. value: value.toArray()
  7610. };
  7611. } else if (value && value.isVector4) {
  7612. data.uniforms[name] = {
  7613. type: 'v4',
  7614. value: value.toArray()
  7615. };
  7616. } else if (value && value.isMatrix3) {
  7617. data.uniforms[name] = {
  7618. type: 'm3',
  7619. value: value.toArray()
  7620. };
  7621. } else if (value && value.isMatrix4) {
  7622. data.uniforms[name] = {
  7623. type: 'm4',
  7624. value: value.toArray()
  7625. };
  7626. } else {
  7627. data.uniforms[name] = {
  7628. value: value
  7629. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7630. }
  7631. }
  7632. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  7633. data.vertexShader = this.vertexShader;
  7634. data.fragmentShader = this.fragmentShader;
  7635. var extensions = {};
  7636. for (var key in this.extensions) {
  7637. if (this.extensions[key] === true) extensions[key] = true;
  7638. }
  7639. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  7640. return data;
  7641. };
  7642. function Camera() {
  7643. Object3D.call(this);
  7644. this.type = 'Camera';
  7645. this.matrixWorldInverse = new Matrix4();
  7646. this.projectionMatrix = new Matrix4();
  7647. this.projectionMatrixInverse = new Matrix4();
  7648. }
  7649. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  7650. constructor: Camera,
  7651. isCamera: true,
  7652. copy: function copy(source, recursive) {
  7653. Object3D.prototype.copy.call(this, source, recursive);
  7654. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  7655. this.projectionMatrix.copy(source.projectionMatrix);
  7656. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  7657. return this;
  7658. },
  7659. getWorldDirection: function getWorldDirection(target) {
  7660. if (target === undefined) {
  7661. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  7662. target = new Vector3();
  7663. }
  7664. this.updateWorldMatrix(true, false);
  7665. var e = this.matrixWorld.elements;
  7666. return target.set(-e[8], -e[9], -e[10]).normalize();
  7667. },
  7668. updateMatrixWorld: function updateMatrixWorld(force) {
  7669. Object3D.prototype.updateMatrixWorld.call(this, force);
  7670. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  7671. },
  7672. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  7673. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  7674. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  7675. },
  7676. clone: function clone() {
  7677. return new this.constructor().copy(this);
  7678. }
  7679. });
  7680. function PerspectiveCamera(fov, aspect, near, far) {
  7681. if (fov === void 0) {
  7682. fov = 50;
  7683. }
  7684. if (aspect === void 0) {
  7685. aspect = 1;
  7686. }
  7687. if (near === void 0) {
  7688. near = 0.1;
  7689. }
  7690. if (far === void 0) {
  7691. far = 2000;
  7692. }
  7693. Camera.call(this);
  7694. this.type = 'PerspectiveCamera';
  7695. this.fov = fov;
  7696. this.zoom = 1;
  7697. this.near = near;
  7698. this.far = far;
  7699. this.focus = 10;
  7700. this.aspect = aspect;
  7701. this.view = null;
  7702. this.filmGauge = 35; // width of the film (default in millimeters)
  7703. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7704. this.updateProjectionMatrix();
  7705. }
  7706. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  7707. constructor: PerspectiveCamera,
  7708. isPerspectiveCamera: true,
  7709. copy: function copy(source, recursive) {
  7710. Camera.prototype.copy.call(this, source, recursive);
  7711. this.fov = source.fov;
  7712. this.zoom = source.zoom;
  7713. this.near = source.near;
  7714. this.far = source.far;
  7715. this.focus = source.focus;
  7716. this.aspect = source.aspect;
  7717. this.view = source.view === null ? null : Object.assign({}, source.view);
  7718. this.filmGauge = source.filmGauge;
  7719. this.filmOffset = source.filmOffset;
  7720. return this;
  7721. },
  7722. /**
  7723. * Sets the FOV by focal length in respect to the current .filmGauge.
  7724. *
  7725. * The default film gauge is 35, so that the focal length can be specified for
  7726. * a 35mm (full frame) camera.
  7727. *
  7728. * Values for focal length and film gauge must have the same unit.
  7729. */
  7730. setFocalLength: function setFocalLength(focalLength) {
  7731. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7732. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7733. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  7734. this.updateProjectionMatrix();
  7735. },
  7736. /**
  7737. * Calculates the focal length from the current .fov and .filmGauge.
  7738. */
  7739. getFocalLength: function getFocalLength() {
  7740. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  7741. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7742. },
  7743. getEffectiveFOV: function getEffectiveFOV() {
  7744. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  7745. },
  7746. getFilmWidth: function getFilmWidth() {
  7747. // film not completely covered in portrait format (aspect < 1)
  7748. return this.filmGauge * Math.min(this.aspect, 1);
  7749. },
  7750. getFilmHeight: function getFilmHeight() {
  7751. // film not completely covered in landscape format (aspect > 1)
  7752. return this.filmGauge / Math.max(this.aspect, 1);
  7753. },
  7754. /**
  7755. * Sets an offset in a larger frustum. This is useful for multi-window or
  7756. * multi-monitor/multi-machine setups.
  7757. *
  7758. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7759. * the monitors are in grid like this
  7760. *
  7761. * +---+---+---+
  7762. * | A | B | C |
  7763. * +---+---+---+
  7764. * | D | E | F |
  7765. * +---+---+---+
  7766. *
  7767. * then for each monitor you would call it like this
  7768. *
  7769. * const w = 1920;
  7770. * const h = 1080;
  7771. * const fullWidth = w * 3;
  7772. * const fullHeight = h * 2;
  7773. *
  7774. * --A--
  7775. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7776. * --B--
  7777. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7778. * --C--
  7779. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7780. * --D--
  7781. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7782. * --E--
  7783. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7784. * --F--
  7785. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7786. *
  7787. * Note there is no reason monitors have to be the same size or in a grid.
  7788. */
  7789. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  7790. this.aspect = fullWidth / fullHeight;
  7791. if (this.view === null) {
  7792. this.view = {
  7793. enabled: true,
  7794. fullWidth: 1,
  7795. fullHeight: 1,
  7796. offsetX: 0,
  7797. offsetY: 0,
  7798. width: 1,
  7799. height: 1
  7800. };
  7801. }
  7802. this.view.enabled = true;
  7803. this.view.fullWidth = fullWidth;
  7804. this.view.fullHeight = fullHeight;
  7805. this.view.offsetX = x;
  7806. this.view.offsetY = y;
  7807. this.view.width = width;
  7808. this.view.height = height;
  7809. this.updateProjectionMatrix();
  7810. },
  7811. clearViewOffset: function clearViewOffset() {
  7812. if (this.view !== null) {
  7813. this.view.enabled = false;
  7814. }
  7815. this.updateProjectionMatrix();
  7816. },
  7817. updateProjectionMatrix: function updateProjectionMatrix() {
  7818. var near = this.near;
  7819. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  7820. var height = 2 * top;
  7821. var width = this.aspect * height;
  7822. var left = -0.5 * width;
  7823. var view = this.view;
  7824. if (this.view !== null && this.view.enabled) {
  7825. var fullWidth = view.fullWidth,
  7826. fullHeight = view.fullHeight;
  7827. left += view.offsetX * width / fullWidth;
  7828. top -= view.offsetY * height / fullHeight;
  7829. width *= view.width / fullWidth;
  7830. height *= view.height / fullHeight;
  7831. }
  7832. var skew = this.filmOffset;
  7833. if (skew !== 0) left += near * skew / this.getFilmWidth();
  7834. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  7835. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  7836. },
  7837. toJSON: function toJSON(meta) {
  7838. var data = Object3D.prototype.toJSON.call(this, meta);
  7839. data.object.fov = this.fov;
  7840. data.object.zoom = this.zoom;
  7841. data.object.near = this.near;
  7842. data.object.far = this.far;
  7843. data.object.focus = this.focus;
  7844. data.object.aspect = this.aspect;
  7845. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  7846. data.object.filmGauge = this.filmGauge;
  7847. data.object.filmOffset = this.filmOffset;
  7848. return data;
  7849. }
  7850. });
  7851. var fov = 90,
  7852. aspect = 1;
  7853. function CubeCamera(near, far, renderTarget) {
  7854. Object3D.call(this);
  7855. this.type = 'CubeCamera';
  7856. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  7857. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  7858. return;
  7859. }
  7860. this.renderTarget = renderTarget;
  7861. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  7862. cameraPX.layers = this.layers;
  7863. cameraPX.up.set(0, -1, 0);
  7864. cameraPX.lookAt(new Vector3(1, 0, 0));
  7865. this.add(cameraPX);
  7866. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  7867. cameraNX.layers = this.layers;
  7868. cameraNX.up.set(0, -1, 0);
  7869. cameraNX.lookAt(new Vector3(-1, 0, 0));
  7870. this.add(cameraNX);
  7871. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  7872. cameraPY.layers = this.layers;
  7873. cameraPY.up.set(0, 0, 1);
  7874. cameraPY.lookAt(new Vector3(0, 1, 0));
  7875. this.add(cameraPY);
  7876. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  7877. cameraNY.layers = this.layers;
  7878. cameraNY.up.set(0, 0, -1);
  7879. cameraNY.lookAt(new Vector3(0, -1, 0));
  7880. this.add(cameraNY);
  7881. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  7882. cameraPZ.layers = this.layers;
  7883. cameraPZ.up.set(0, -1, 0);
  7884. cameraPZ.lookAt(new Vector3(0, 0, 1));
  7885. this.add(cameraPZ);
  7886. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  7887. cameraNZ.layers = this.layers;
  7888. cameraNZ.up.set(0, -1, 0);
  7889. cameraNZ.lookAt(new Vector3(0, 0, -1));
  7890. this.add(cameraNZ);
  7891. this.update = function (renderer, scene) {
  7892. if (this.parent === null) this.updateMatrixWorld();
  7893. var currentXrEnabled = renderer.xr.enabled;
  7894. var currentRenderTarget = renderer.getRenderTarget();
  7895. renderer.xr.enabled = false;
  7896. var generateMipmaps = renderTarget.texture.generateMipmaps;
  7897. renderTarget.texture.generateMipmaps = false;
  7898. renderer.setRenderTarget(renderTarget, 0);
  7899. renderer.render(scene, cameraPX);
  7900. renderer.setRenderTarget(renderTarget, 1);
  7901. renderer.render(scene, cameraNX);
  7902. renderer.setRenderTarget(renderTarget, 2);
  7903. renderer.render(scene, cameraPY);
  7904. renderer.setRenderTarget(renderTarget, 3);
  7905. renderer.render(scene, cameraNY);
  7906. renderer.setRenderTarget(renderTarget, 4);
  7907. renderer.render(scene, cameraPZ);
  7908. renderTarget.texture.generateMipmaps = generateMipmaps;
  7909. renderer.setRenderTarget(renderTarget, 5);
  7910. renderer.render(scene, cameraNZ);
  7911. renderer.setRenderTarget(currentRenderTarget);
  7912. renderer.xr.enabled = currentXrEnabled;
  7913. };
  7914. }
  7915. CubeCamera.prototype = Object.create(Object3D.prototype);
  7916. CubeCamera.prototype.constructor = CubeCamera;
  7917. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  7918. images = images !== undefined ? images : [];
  7919. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7920. format = format !== undefined ? format : RGBFormat;
  7921. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  7922. this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
  7923. //
  7924. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7925. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7926. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7927. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7928. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  7929. // when using WebGLCubeRenderTarget.texture as a cube texture.
  7930. this._needsFlipEnvMap = true;
  7931. }
  7932. CubeTexture.prototype = Object.create(Texture.prototype);
  7933. CubeTexture.prototype.constructor = CubeTexture;
  7934. CubeTexture.prototype.isCubeTexture = true;
  7935. Object.defineProperty(CubeTexture.prototype, 'images', {
  7936. get: function get() {
  7937. return this.image;
  7938. },
  7939. set: function set(value) {
  7940. this.image = value;
  7941. }
  7942. });
  7943. function WebGLCubeRenderTarget(size, options, dummy) {
  7944. if (Number.isInteger(options)) {
  7945. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  7946. options = dummy;
  7947. }
  7948. WebGLRenderTarget.call(this, size, size, options);
  7949. options = options || {};
  7950. this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  7951. this.texture._needsFlipEnvMap = false;
  7952. }
  7953. WebGLCubeRenderTarget.prototype = Object.create(WebGLRenderTarget.prototype);
  7954. WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
  7955. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  7956. WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function (renderer, texture) {
  7957. this.texture.type = texture.type;
  7958. this.texture.format = RGBAFormat; // see #18859
  7959. this.texture.encoding = texture.encoding;
  7960. this.texture.generateMipmaps = texture.generateMipmaps;
  7961. this.texture.minFilter = texture.minFilter;
  7962. this.texture.magFilter = texture.magFilter;
  7963. var shader = {
  7964. uniforms: {
  7965. tEquirect: {
  7966. value: null
  7967. }
  7968. },
  7969. vertexShader:
  7970. /* glsl */
  7971. "\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",
  7972. fragmentShader:
  7973. /* glsl */
  7974. "\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"
  7975. };
  7976. var geometry = new BoxGeometry(5, 5, 5);
  7977. var material = new ShaderMaterial({
  7978. name: 'CubemapFromEquirect',
  7979. uniforms: cloneUniforms(shader.uniforms),
  7980. vertexShader: shader.vertexShader,
  7981. fragmentShader: shader.fragmentShader,
  7982. side: BackSide,
  7983. blending: NoBlending
  7984. });
  7985. material.uniforms.tEquirect.value = texture;
  7986. var mesh = new Mesh(geometry, material);
  7987. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  7988. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  7989. var camera = new CubeCamera(1, 10, this);
  7990. camera.update(renderer, mesh);
  7991. texture.minFilter = currentMinFilter;
  7992. mesh.geometry.dispose();
  7993. mesh.material.dispose();
  7994. return this;
  7995. };
  7996. WebGLCubeRenderTarget.prototype.clear = function (renderer, color, depth, stencil) {
  7997. var currentRenderTarget = renderer.getRenderTarget();
  7998. for (var i = 0; i < 6; i++) {
  7999. renderer.setRenderTarget(this, i);
  8000. renderer.clear(color, depth, stencil);
  8001. }
  8002. renderer.setRenderTarget(currentRenderTarget);
  8003. };
  8004. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  8005. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8006. this.image = {
  8007. data: data || null,
  8008. width: width || 1,
  8009. height: height || 1
  8010. };
  8011. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8012. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8013. this.generateMipmaps = false;
  8014. this.flipY = false;
  8015. this.unpackAlignment = 1;
  8016. this.needsUpdate = true;
  8017. }
  8018. DataTexture.prototype = Object.create(Texture.prototype);
  8019. DataTexture.prototype.constructor = DataTexture;
  8020. DataTexture.prototype.isDataTexture = true;
  8021. var _sphere$1 = /*@__PURE__*/new Sphere();
  8022. var _vector$5 = /*@__PURE__*/new Vector3();
  8023. var Frustum = /*#__PURE__*/function () {
  8024. function Frustum(p0, p1, p2, p3, p4, p5) {
  8025. 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()];
  8026. }
  8027. var _proto = Frustum.prototype;
  8028. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  8029. var planes = this.planes;
  8030. planes[0].copy(p0);
  8031. planes[1].copy(p1);
  8032. planes[2].copy(p2);
  8033. planes[3].copy(p3);
  8034. planes[4].copy(p4);
  8035. planes[5].copy(p5);
  8036. return this;
  8037. };
  8038. _proto.clone = function clone() {
  8039. return new this.constructor().copy(this);
  8040. };
  8041. _proto.copy = function copy(frustum) {
  8042. var planes = this.planes;
  8043. for (var i = 0; i < 6; i++) {
  8044. planes[i].copy(frustum.planes[i]);
  8045. }
  8046. return this;
  8047. };
  8048. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  8049. var planes = this.planes;
  8050. var me = m.elements;
  8051. var me0 = me[0],
  8052. me1 = me[1],
  8053. me2 = me[2],
  8054. me3 = me[3];
  8055. var me4 = me[4],
  8056. me5 = me[5],
  8057. me6 = me[6],
  8058. me7 = me[7];
  8059. var me8 = me[8],
  8060. me9 = me[9],
  8061. me10 = me[10],
  8062. me11 = me[11];
  8063. var me12 = me[12],
  8064. me13 = me[13],
  8065. me14 = me[14],
  8066. me15 = me[15];
  8067. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  8068. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  8069. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  8070. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  8071. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  8072. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  8073. return this;
  8074. };
  8075. _proto.intersectsObject = function intersectsObject(object) {
  8076. var geometry = object.geometry;
  8077. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  8078. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  8079. return this.intersectsSphere(_sphere$1);
  8080. };
  8081. _proto.intersectsSprite = function intersectsSprite(sprite) {
  8082. _sphere$1.center.set(0, 0, 0);
  8083. _sphere$1.radius = 0.7071067811865476;
  8084. _sphere$1.applyMatrix4(sprite.matrixWorld);
  8085. return this.intersectsSphere(_sphere$1);
  8086. };
  8087. _proto.intersectsSphere = function intersectsSphere(sphere) {
  8088. var planes = this.planes;
  8089. var center = sphere.center;
  8090. var negRadius = -sphere.radius;
  8091. for (var i = 0; i < 6; i++) {
  8092. var distance = planes[i].distanceToPoint(center);
  8093. if (distance < negRadius) {
  8094. return false;
  8095. }
  8096. }
  8097. return true;
  8098. };
  8099. _proto.intersectsBox = function intersectsBox(box) {
  8100. var planes = this.planes;
  8101. for (var i = 0; i < 6; i++) {
  8102. var plane = planes[i]; // corner at max distance
  8103. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8104. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8105. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8106. if (plane.distanceToPoint(_vector$5) < 0) {
  8107. return false;
  8108. }
  8109. }
  8110. return true;
  8111. };
  8112. _proto.containsPoint = function containsPoint(point) {
  8113. var planes = this.planes;
  8114. for (var i = 0; i < 6; i++) {
  8115. if (planes[i].distanceToPoint(point) < 0) {
  8116. return false;
  8117. }
  8118. }
  8119. return true;
  8120. };
  8121. return Frustum;
  8122. }();
  8123. function WebGLAnimation() {
  8124. var context = null;
  8125. var isAnimating = false;
  8126. var animationLoop = null;
  8127. var requestId = null;
  8128. function onAnimationFrame(time, frame) {
  8129. animationLoop(time, frame);
  8130. requestId = context.requestAnimationFrame(onAnimationFrame);
  8131. }
  8132. return {
  8133. start: function start() {
  8134. if (isAnimating === true) return;
  8135. if (animationLoop === null) return;
  8136. requestId = context.requestAnimationFrame(onAnimationFrame);
  8137. isAnimating = true;
  8138. },
  8139. stop: function stop() {
  8140. context.cancelAnimationFrame(requestId);
  8141. isAnimating = false;
  8142. },
  8143. setAnimationLoop: function setAnimationLoop(callback) {
  8144. animationLoop = callback;
  8145. },
  8146. setContext: function setContext(value) {
  8147. context = value;
  8148. }
  8149. };
  8150. }
  8151. function WebGLAttributes(gl, capabilities) {
  8152. var isWebGL2 = capabilities.isWebGL2;
  8153. var buffers = new WeakMap();
  8154. function createBuffer(attribute, bufferType) {
  8155. var array = attribute.array;
  8156. var usage = attribute.usage;
  8157. var buffer = gl.createBuffer();
  8158. gl.bindBuffer(bufferType, buffer);
  8159. gl.bufferData(bufferType, array, usage);
  8160. attribute.onUploadCallback();
  8161. var type = 5126;
  8162. if (array instanceof Float32Array) {
  8163. type = 5126;
  8164. } else if (array instanceof Float64Array) {
  8165. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8166. } else if (array instanceof Uint16Array) {
  8167. if (attribute.isFloat16BufferAttribute) {
  8168. if (isWebGL2) {
  8169. type = 5131;
  8170. } else {
  8171. console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
  8172. }
  8173. } else {
  8174. type = 5123;
  8175. }
  8176. } else if (array instanceof Int16Array) {
  8177. type = 5122;
  8178. } else if (array instanceof Uint32Array) {
  8179. type = 5125;
  8180. } else if (array instanceof Int32Array) {
  8181. type = 5124;
  8182. } else if (array instanceof Int8Array) {
  8183. type = 5120;
  8184. } else if (array instanceof Uint8Array) {
  8185. type = 5121;
  8186. }
  8187. return {
  8188. buffer: buffer,
  8189. type: type,
  8190. bytesPerElement: array.BYTES_PER_ELEMENT,
  8191. version: attribute.version
  8192. };
  8193. }
  8194. function updateBuffer(buffer, attribute, bufferType) {
  8195. var array = attribute.array;
  8196. var updateRange = attribute.updateRange;
  8197. gl.bindBuffer(bufferType, buffer);
  8198. if (updateRange.count === -1) {
  8199. // Not using update ranges
  8200. gl.bufferSubData(bufferType, 0, array);
  8201. } else {
  8202. if (isWebGL2) {
  8203. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8204. } else {
  8205. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8206. }
  8207. updateRange.count = -1; // reset range
  8208. }
  8209. } //
  8210. function get(attribute) {
  8211. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8212. return buffers.get(attribute);
  8213. }
  8214. function remove(attribute) {
  8215. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8216. var data = buffers.get(attribute);
  8217. if (data) {
  8218. gl.deleteBuffer(data.buffer);
  8219. buffers.delete(attribute);
  8220. }
  8221. }
  8222. function update(attribute, bufferType) {
  8223. if (attribute.isGLBufferAttribute) {
  8224. var cached = buffers.get(attribute);
  8225. if (!cached || cached.version < attribute.version) {
  8226. buffers.set(attribute, {
  8227. buffer: attribute.buffer,
  8228. type: attribute.type,
  8229. bytesPerElement: attribute.elementSize,
  8230. version: attribute.version
  8231. });
  8232. }
  8233. return;
  8234. }
  8235. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8236. var data = buffers.get(attribute);
  8237. if (data === undefined) {
  8238. buffers.set(attribute, createBuffer(attribute, bufferType));
  8239. } else if (data.version < attribute.version) {
  8240. updateBuffer(data.buffer, attribute, bufferType);
  8241. data.version = attribute.version;
  8242. }
  8243. }
  8244. return {
  8245. get: get,
  8246. remove: remove,
  8247. update: update
  8248. };
  8249. }
  8250. var PlaneGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8251. _inheritsLoose(PlaneGeometry, _BufferGeometry);
  8252. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  8253. var _this;
  8254. if (width === void 0) {
  8255. width = 1;
  8256. }
  8257. if (height === void 0) {
  8258. height = 1;
  8259. }
  8260. if (widthSegments === void 0) {
  8261. widthSegments = 1;
  8262. }
  8263. if (heightSegments === void 0) {
  8264. heightSegments = 1;
  8265. }
  8266. _this = _BufferGeometry.call(this) || this;
  8267. _this.type = 'PlaneGeometry';
  8268. _this.parameters = {
  8269. width: width,
  8270. height: height,
  8271. widthSegments: widthSegments,
  8272. heightSegments: heightSegments
  8273. };
  8274. var width_half = width / 2;
  8275. var height_half = height / 2;
  8276. var gridX = Math.floor(widthSegments);
  8277. var gridY = Math.floor(heightSegments);
  8278. var gridX1 = gridX + 1;
  8279. var gridY1 = gridY + 1;
  8280. var segment_width = width / gridX;
  8281. var segment_height = height / gridY; //
  8282. var indices = [];
  8283. var vertices = [];
  8284. var normals = [];
  8285. var uvs = [];
  8286. for (var iy = 0; iy < gridY1; iy++) {
  8287. var y = iy * segment_height - height_half;
  8288. for (var ix = 0; ix < gridX1; ix++) {
  8289. var x = ix * segment_width - width_half;
  8290. vertices.push(x, -y, 0);
  8291. normals.push(0, 0, 1);
  8292. uvs.push(ix / gridX);
  8293. uvs.push(1 - iy / gridY);
  8294. }
  8295. }
  8296. for (var _iy = 0; _iy < gridY; _iy++) {
  8297. for (var _ix = 0; _ix < gridX; _ix++) {
  8298. var a = _ix + gridX1 * _iy;
  8299. var b = _ix + gridX1 * (_iy + 1);
  8300. var c = _ix + 1 + gridX1 * (_iy + 1);
  8301. var d = _ix + 1 + gridX1 * _iy;
  8302. indices.push(a, b, d);
  8303. indices.push(b, c, d);
  8304. }
  8305. }
  8306. _this.setIndex(indices);
  8307. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8308. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8309. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8310. return _this;
  8311. }
  8312. return PlaneGeometry;
  8313. }(BufferGeometry);
  8314. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8315. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8316. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8317. 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";
  8318. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8319. var begin_vertex = "vec3 transformed = vec3( position );";
  8320. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8321. 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";
  8322. 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";
  8323. 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";
  8324. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8325. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8326. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8327. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8328. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8329. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8330. 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";
  8331. 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}";
  8332. 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";
  8333. 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";
  8334. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8335. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8336. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8337. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8338. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8339. 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}";
  8340. 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";
  8341. 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";
  8342. 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";
  8343. 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";
  8344. 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";
  8345. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8346. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8347. 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";
  8348. 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";
  8349. 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}";
  8350. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8351. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8352. 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";
  8353. 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";
  8354. 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";
  8355. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8356. 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)";
  8357. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8358. 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)";
  8359. 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";
  8360. 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}";
  8361. 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";
  8362. 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";
  8363. 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";
  8364. 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";
  8365. 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";
  8366. 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";
  8367. 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";
  8368. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8369. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8370. 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";
  8371. 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";
  8372. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8373. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8374. 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";
  8375. 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";
  8376. 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";
  8377. 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;";
  8378. 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";
  8379. 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";
  8380. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8381. 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";
  8382. 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";
  8383. 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}";
  8384. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8385. 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;";
  8386. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8387. 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";
  8388. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8389. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8390. 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";
  8391. 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";
  8392. 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";
  8393. 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}";
  8394. 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";
  8395. 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";
  8396. 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";
  8397. 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";
  8398. 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";
  8399. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8400. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8401. 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; }";
  8402. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8403. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8404. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8405. 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";
  8406. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8407. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8408. 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";
  8409. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8410. 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";
  8411. 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}";
  8412. 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}";
  8413. 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}";
  8414. 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}";
  8415. 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}";
  8416. 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}";
  8417. 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}";
  8418. 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}";
  8419. 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}";
  8420. 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}";
  8421. 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}";
  8422. 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}";
  8423. 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}";
  8424. 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}";
  8425. 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}";
  8426. 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}";
  8427. 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}";
  8428. 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}";
  8429. 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}";
  8430. 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}";
  8431. 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}";
  8432. 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}";
  8433. 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}";
  8434. 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}";
  8435. 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}";
  8436. 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}";
  8437. 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}";
  8438. 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}";
  8439. 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}";
  8440. 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}";
  8441. 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}";
  8442. 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}";
  8443. var ShaderChunk = {
  8444. alphamap_fragment: alphamap_fragment,
  8445. alphamap_pars_fragment: alphamap_pars_fragment,
  8446. alphatest_fragment: alphatest_fragment,
  8447. aomap_fragment: aomap_fragment,
  8448. aomap_pars_fragment: aomap_pars_fragment,
  8449. begin_vertex: begin_vertex,
  8450. beginnormal_vertex: beginnormal_vertex,
  8451. bsdfs: bsdfs,
  8452. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8453. clipping_planes_fragment: clipping_planes_fragment,
  8454. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8455. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8456. clipping_planes_vertex: clipping_planes_vertex,
  8457. color_fragment: color_fragment,
  8458. color_pars_fragment: color_pars_fragment,
  8459. color_pars_vertex: color_pars_vertex,
  8460. color_vertex: color_vertex,
  8461. common: common,
  8462. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8463. defaultnormal_vertex: defaultnormal_vertex,
  8464. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8465. displacementmap_vertex: displacementmap_vertex,
  8466. emissivemap_fragment: emissivemap_fragment,
  8467. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8468. encodings_fragment: encodings_fragment,
  8469. encodings_pars_fragment: encodings_pars_fragment,
  8470. envmap_fragment: envmap_fragment,
  8471. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8472. envmap_pars_fragment: envmap_pars_fragment,
  8473. envmap_pars_vertex: envmap_pars_vertex,
  8474. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8475. envmap_vertex: envmap_vertex,
  8476. fog_vertex: fog_vertex,
  8477. fog_pars_vertex: fog_pars_vertex,
  8478. fog_fragment: fog_fragment,
  8479. fog_pars_fragment: fog_pars_fragment,
  8480. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8481. lightmap_fragment: lightmap_fragment,
  8482. lightmap_pars_fragment: lightmap_pars_fragment,
  8483. lights_lambert_vertex: lights_lambert_vertex,
  8484. lights_pars_begin: lights_pars_begin,
  8485. lights_toon_fragment: lights_toon_fragment,
  8486. lights_toon_pars_fragment: lights_toon_pars_fragment,
  8487. lights_phong_fragment: lights_phong_fragment,
  8488. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8489. lights_physical_fragment: lights_physical_fragment,
  8490. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8491. lights_fragment_begin: lights_fragment_begin,
  8492. lights_fragment_maps: lights_fragment_maps,
  8493. lights_fragment_end: lights_fragment_end,
  8494. logdepthbuf_fragment: logdepthbuf_fragment,
  8495. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8496. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8497. logdepthbuf_vertex: logdepthbuf_vertex,
  8498. map_fragment: map_fragment,
  8499. map_pars_fragment: map_pars_fragment,
  8500. map_particle_fragment: map_particle_fragment,
  8501. map_particle_pars_fragment: map_particle_pars_fragment,
  8502. metalnessmap_fragment: metalnessmap_fragment,
  8503. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  8504. morphnormal_vertex: morphnormal_vertex,
  8505. morphtarget_pars_vertex: morphtarget_pars_vertex,
  8506. morphtarget_vertex: morphtarget_vertex,
  8507. normal_fragment_begin: normal_fragment_begin,
  8508. normal_fragment_maps: normal_fragment_maps,
  8509. normalmap_pars_fragment: normalmap_pars_fragment,
  8510. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  8511. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  8512. clearcoat_pars_fragment: clearcoat_pars_fragment,
  8513. packing: packing,
  8514. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  8515. project_vertex: project_vertex,
  8516. dithering_fragment: dithering_fragment,
  8517. dithering_pars_fragment: dithering_pars_fragment,
  8518. roughnessmap_fragment: roughnessmap_fragment,
  8519. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  8520. shadowmap_pars_fragment: shadowmap_pars_fragment,
  8521. shadowmap_pars_vertex: shadowmap_pars_vertex,
  8522. shadowmap_vertex: shadowmap_vertex,
  8523. shadowmask_pars_fragment: shadowmask_pars_fragment,
  8524. skinbase_vertex: skinbase_vertex,
  8525. skinning_pars_vertex: skinning_pars_vertex,
  8526. skinning_vertex: skinning_vertex,
  8527. skinnormal_vertex: skinnormal_vertex,
  8528. specularmap_fragment: specularmap_fragment,
  8529. specularmap_pars_fragment: specularmap_pars_fragment,
  8530. tonemapping_fragment: tonemapping_fragment,
  8531. tonemapping_pars_fragment: tonemapping_pars_fragment,
  8532. transmissionmap_fragment: transmissionmap_fragment,
  8533. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  8534. uv_pars_fragment: uv_pars_fragment,
  8535. uv_pars_vertex: uv_pars_vertex,
  8536. uv_vertex: uv_vertex,
  8537. uv2_pars_fragment: uv2_pars_fragment,
  8538. uv2_pars_vertex: uv2_pars_vertex,
  8539. uv2_vertex: uv2_vertex,
  8540. worldpos_vertex: worldpos_vertex,
  8541. background_frag: background_frag,
  8542. background_vert: background_vert,
  8543. cube_frag: cube_frag,
  8544. cube_vert: cube_vert,
  8545. depth_frag: depth_frag,
  8546. depth_vert: depth_vert,
  8547. distanceRGBA_frag: distanceRGBA_frag,
  8548. distanceRGBA_vert: distanceRGBA_vert,
  8549. equirect_frag: equirect_frag,
  8550. equirect_vert: equirect_vert,
  8551. linedashed_frag: linedashed_frag,
  8552. linedashed_vert: linedashed_vert,
  8553. meshbasic_frag: meshbasic_frag,
  8554. meshbasic_vert: meshbasic_vert,
  8555. meshlambert_frag: meshlambert_frag,
  8556. meshlambert_vert: meshlambert_vert,
  8557. meshmatcap_frag: meshmatcap_frag,
  8558. meshmatcap_vert: meshmatcap_vert,
  8559. meshtoon_frag: meshtoon_frag,
  8560. meshtoon_vert: meshtoon_vert,
  8561. meshphong_frag: meshphong_frag,
  8562. meshphong_vert: meshphong_vert,
  8563. meshphysical_frag: meshphysical_frag,
  8564. meshphysical_vert: meshphysical_vert,
  8565. normal_frag: normal_frag,
  8566. normal_vert: normal_vert,
  8567. points_frag: points_frag,
  8568. points_vert: points_vert,
  8569. shadow_frag: shadow_frag,
  8570. shadow_vert: shadow_vert,
  8571. sprite_frag: sprite_frag,
  8572. sprite_vert: sprite_vert
  8573. };
  8574. /**
  8575. * Uniforms library for shared webgl shaders
  8576. */
  8577. var UniformsLib = {
  8578. common: {
  8579. diffuse: {
  8580. value: new Color(0xeeeeee)
  8581. },
  8582. opacity: {
  8583. value: 1.0
  8584. },
  8585. map: {
  8586. value: null
  8587. },
  8588. uvTransform: {
  8589. value: new Matrix3()
  8590. },
  8591. uv2Transform: {
  8592. value: new Matrix3()
  8593. },
  8594. alphaMap: {
  8595. value: null
  8596. }
  8597. },
  8598. specularmap: {
  8599. specularMap: {
  8600. value: null
  8601. }
  8602. },
  8603. envmap: {
  8604. envMap: {
  8605. value: null
  8606. },
  8607. flipEnvMap: {
  8608. value: -1
  8609. },
  8610. reflectivity: {
  8611. value: 1.0
  8612. },
  8613. refractionRatio: {
  8614. value: 0.98
  8615. },
  8616. maxMipLevel: {
  8617. value: 0
  8618. }
  8619. },
  8620. aomap: {
  8621. aoMap: {
  8622. value: null
  8623. },
  8624. aoMapIntensity: {
  8625. value: 1
  8626. }
  8627. },
  8628. lightmap: {
  8629. lightMap: {
  8630. value: null
  8631. },
  8632. lightMapIntensity: {
  8633. value: 1
  8634. }
  8635. },
  8636. emissivemap: {
  8637. emissiveMap: {
  8638. value: null
  8639. }
  8640. },
  8641. bumpmap: {
  8642. bumpMap: {
  8643. value: null
  8644. },
  8645. bumpScale: {
  8646. value: 1
  8647. }
  8648. },
  8649. normalmap: {
  8650. normalMap: {
  8651. value: null
  8652. },
  8653. normalScale: {
  8654. value: new Vector2(1, 1)
  8655. }
  8656. },
  8657. displacementmap: {
  8658. displacementMap: {
  8659. value: null
  8660. },
  8661. displacementScale: {
  8662. value: 1
  8663. },
  8664. displacementBias: {
  8665. value: 0
  8666. }
  8667. },
  8668. roughnessmap: {
  8669. roughnessMap: {
  8670. value: null
  8671. }
  8672. },
  8673. metalnessmap: {
  8674. metalnessMap: {
  8675. value: null
  8676. }
  8677. },
  8678. gradientmap: {
  8679. gradientMap: {
  8680. value: null
  8681. }
  8682. },
  8683. fog: {
  8684. fogDensity: {
  8685. value: 0.00025
  8686. },
  8687. fogNear: {
  8688. value: 1
  8689. },
  8690. fogFar: {
  8691. value: 2000
  8692. },
  8693. fogColor: {
  8694. value: new Color(0xffffff)
  8695. }
  8696. },
  8697. lights: {
  8698. ambientLightColor: {
  8699. value: []
  8700. },
  8701. lightProbe: {
  8702. value: []
  8703. },
  8704. directionalLights: {
  8705. value: [],
  8706. properties: {
  8707. direction: {},
  8708. color: {}
  8709. }
  8710. },
  8711. directionalLightShadows: {
  8712. value: [],
  8713. properties: {
  8714. shadowBias: {},
  8715. shadowNormalBias: {},
  8716. shadowRadius: {},
  8717. shadowMapSize: {}
  8718. }
  8719. },
  8720. directionalShadowMap: {
  8721. value: []
  8722. },
  8723. directionalShadowMatrix: {
  8724. value: []
  8725. },
  8726. spotLights: {
  8727. value: [],
  8728. properties: {
  8729. color: {},
  8730. position: {},
  8731. direction: {},
  8732. distance: {},
  8733. coneCos: {},
  8734. penumbraCos: {},
  8735. decay: {}
  8736. }
  8737. },
  8738. spotLightShadows: {
  8739. value: [],
  8740. properties: {
  8741. shadowBias: {},
  8742. shadowNormalBias: {},
  8743. shadowRadius: {},
  8744. shadowMapSize: {}
  8745. }
  8746. },
  8747. spotShadowMap: {
  8748. value: []
  8749. },
  8750. spotShadowMatrix: {
  8751. value: []
  8752. },
  8753. pointLights: {
  8754. value: [],
  8755. properties: {
  8756. color: {},
  8757. position: {},
  8758. decay: {},
  8759. distance: {}
  8760. }
  8761. },
  8762. pointLightShadows: {
  8763. value: [],
  8764. properties: {
  8765. shadowBias: {},
  8766. shadowNormalBias: {},
  8767. shadowRadius: {},
  8768. shadowMapSize: {},
  8769. shadowCameraNear: {},
  8770. shadowCameraFar: {}
  8771. }
  8772. },
  8773. pointShadowMap: {
  8774. value: []
  8775. },
  8776. pointShadowMatrix: {
  8777. value: []
  8778. },
  8779. hemisphereLights: {
  8780. value: [],
  8781. properties: {
  8782. direction: {},
  8783. skyColor: {},
  8784. groundColor: {}
  8785. }
  8786. },
  8787. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8788. rectAreaLights: {
  8789. value: [],
  8790. properties: {
  8791. color: {},
  8792. position: {},
  8793. width: {},
  8794. height: {}
  8795. }
  8796. },
  8797. ltc_1: {
  8798. value: null
  8799. },
  8800. ltc_2: {
  8801. value: null
  8802. }
  8803. },
  8804. points: {
  8805. diffuse: {
  8806. value: new Color(0xeeeeee)
  8807. },
  8808. opacity: {
  8809. value: 1.0
  8810. },
  8811. size: {
  8812. value: 1.0
  8813. },
  8814. scale: {
  8815. value: 1.0
  8816. },
  8817. map: {
  8818. value: null
  8819. },
  8820. alphaMap: {
  8821. value: null
  8822. },
  8823. uvTransform: {
  8824. value: new Matrix3()
  8825. }
  8826. },
  8827. sprite: {
  8828. diffuse: {
  8829. value: new Color(0xeeeeee)
  8830. },
  8831. opacity: {
  8832. value: 1.0
  8833. },
  8834. center: {
  8835. value: new Vector2(0.5, 0.5)
  8836. },
  8837. rotation: {
  8838. value: 0.0
  8839. },
  8840. map: {
  8841. value: null
  8842. },
  8843. alphaMap: {
  8844. value: null
  8845. },
  8846. uvTransform: {
  8847. value: new Matrix3()
  8848. }
  8849. }
  8850. };
  8851. var ShaderLib = {
  8852. basic: {
  8853. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  8854. vertexShader: ShaderChunk.meshbasic_vert,
  8855. fragmentShader: ShaderChunk.meshbasic_frag
  8856. },
  8857. lambert: {
  8858. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  8859. emissive: {
  8860. value: new Color(0x000000)
  8861. }
  8862. }]),
  8863. vertexShader: ShaderChunk.meshlambert_vert,
  8864. fragmentShader: ShaderChunk.meshlambert_frag
  8865. },
  8866. phong: {
  8867. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  8868. emissive: {
  8869. value: new Color(0x000000)
  8870. },
  8871. specular: {
  8872. value: new Color(0x111111)
  8873. },
  8874. shininess: {
  8875. value: 30
  8876. }
  8877. }]),
  8878. vertexShader: ShaderChunk.meshphong_vert,
  8879. fragmentShader: ShaderChunk.meshphong_frag
  8880. },
  8881. standard: {
  8882. 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, {
  8883. emissive: {
  8884. value: new Color(0x000000)
  8885. },
  8886. roughness: {
  8887. value: 1.0
  8888. },
  8889. metalness: {
  8890. value: 0.0
  8891. },
  8892. envMapIntensity: {
  8893. value: 1
  8894. } // temporary
  8895. }]),
  8896. vertexShader: ShaderChunk.meshphysical_vert,
  8897. fragmentShader: ShaderChunk.meshphysical_frag
  8898. },
  8899. toon: {
  8900. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  8901. emissive: {
  8902. value: new Color(0x000000)
  8903. }
  8904. }]),
  8905. vertexShader: ShaderChunk.meshtoon_vert,
  8906. fragmentShader: ShaderChunk.meshtoon_frag
  8907. },
  8908. matcap: {
  8909. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  8910. matcap: {
  8911. value: null
  8912. }
  8913. }]),
  8914. vertexShader: ShaderChunk.meshmatcap_vert,
  8915. fragmentShader: ShaderChunk.meshmatcap_frag
  8916. },
  8917. points: {
  8918. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  8919. vertexShader: ShaderChunk.points_vert,
  8920. fragmentShader: ShaderChunk.points_frag
  8921. },
  8922. dashed: {
  8923. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  8924. scale: {
  8925. value: 1
  8926. },
  8927. dashSize: {
  8928. value: 1
  8929. },
  8930. totalSize: {
  8931. value: 2
  8932. }
  8933. }]),
  8934. vertexShader: ShaderChunk.linedashed_vert,
  8935. fragmentShader: ShaderChunk.linedashed_frag
  8936. },
  8937. depth: {
  8938. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  8939. vertexShader: ShaderChunk.depth_vert,
  8940. fragmentShader: ShaderChunk.depth_frag
  8941. },
  8942. normal: {
  8943. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  8944. opacity: {
  8945. value: 1.0
  8946. }
  8947. }]),
  8948. vertexShader: ShaderChunk.normal_vert,
  8949. fragmentShader: ShaderChunk.normal_frag
  8950. },
  8951. sprite: {
  8952. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  8953. vertexShader: ShaderChunk.sprite_vert,
  8954. fragmentShader: ShaderChunk.sprite_frag
  8955. },
  8956. background: {
  8957. uniforms: {
  8958. uvTransform: {
  8959. value: new Matrix3()
  8960. },
  8961. t2D: {
  8962. value: null
  8963. }
  8964. },
  8965. vertexShader: ShaderChunk.background_vert,
  8966. fragmentShader: ShaderChunk.background_frag
  8967. },
  8968. /* -------------------------------------------------------------------------
  8969. // Cube map shader
  8970. ------------------------------------------------------------------------- */
  8971. cube: {
  8972. uniforms: mergeUniforms([UniformsLib.envmap, {
  8973. opacity: {
  8974. value: 1.0
  8975. }
  8976. }]),
  8977. vertexShader: ShaderChunk.cube_vert,
  8978. fragmentShader: ShaderChunk.cube_frag
  8979. },
  8980. equirect: {
  8981. uniforms: {
  8982. tEquirect: {
  8983. value: null
  8984. }
  8985. },
  8986. vertexShader: ShaderChunk.equirect_vert,
  8987. fragmentShader: ShaderChunk.equirect_frag
  8988. },
  8989. distanceRGBA: {
  8990. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  8991. referencePosition: {
  8992. value: new Vector3()
  8993. },
  8994. nearDistance: {
  8995. value: 1
  8996. },
  8997. farDistance: {
  8998. value: 1000
  8999. }
  9000. }]),
  9001. vertexShader: ShaderChunk.distanceRGBA_vert,
  9002. fragmentShader: ShaderChunk.distanceRGBA_frag
  9003. },
  9004. shadow: {
  9005. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  9006. color: {
  9007. value: new Color(0x00000)
  9008. },
  9009. opacity: {
  9010. value: 1.0
  9011. }
  9012. }]),
  9013. vertexShader: ShaderChunk.shadow_vert,
  9014. fragmentShader: ShaderChunk.shadow_frag
  9015. }
  9016. };
  9017. ShaderLib.physical = {
  9018. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  9019. clearcoat: {
  9020. value: 0
  9021. },
  9022. clearcoatMap: {
  9023. value: null
  9024. },
  9025. clearcoatRoughness: {
  9026. value: 0
  9027. },
  9028. clearcoatRoughnessMap: {
  9029. value: null
  9030. },
  9031. clearcoatNormalScale: {
  9032. value: new Vector2(1, 1)
  9033. },
  9034. clearcoatNormalMap: {
  9035. value: null
  9036. },
  9037. sheen: {
  9038. value: new Color(0x000000)
  9039. },
  9040. transmission: {
  9041. value: 0
  9042. },
  9043. transmissionMap: {
  9044. value: null
  9045. }
  9046. }]),
  9047. vertexShader: ShaderChunk.meshphysical_vert,
  9048. fragmentShader: ShaderChunk.meshphysical_frag
  9049. };
  9050. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  9051. var clearColor = new Color(0x000000);
  9052. var clearAlpha = 0;
  9053. var planeMesh;
  9054. var boxMesh;
  9055. var currentBackground = null;
  9056. var currentBackgroundVersion = 0;
  9057. var currentTonemapping = null;
  9058. function render(renderList, scene, camera, forceClear) {
  9059. var background = scene.isScene === true ? scene.background : null;
  9060. if (background && background.isTexture) {
  9061. background = cubemaps.get(background);
  9062. } // Ignore background in AR
  9063. // TODO: Reconsider this.
  9064. var xr = renderer.xr;
  9065. var session = xr.getSession && xr.getSession();
  9066. if (session && session.environmentBlendMode === 'additive') {
  9067. background = null;
  9068. }
  9069. if (background === null) {
  9070. setClear(clearColor, clearAlpha);
  9071. } else if (background && background.isColor) {
  9072. setClear(background, 1);
  9073. forceClear = true;
  9074. }
  9075. if (renderer.autoClear || forceClear) {
  9076. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  9077. }
  9078. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  9079. if (boxMesh === undefined) {
  9080. boxMesh = new Mesh(new BoxGeometry(1, 1, 1), new ShaderMaterial({
  9081. name: 'BackgroundCubeMaterial',
  9082. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  9083. vertexShader: ShaderLib.cube.vertexShader,
  9084. fragmentShader: ShaderLib.cube.fragmentShader,
  9085. side: BackSide,
  9086. depthTest: false,
  9087. depthWrite: false,
  9088. fog: false
  9089. }));
  9090. boxMesh.geometry.deleteAttribute('normal');
  9091. boxMesh.geometry.deleteAttribute('uv');
  9092. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  9093. this.matrixWorld.copyPosition(camera.matrixWorld);
  9094. }; // enable code injection for non-built-in material
  9095. Object.defineProperty(boxMesh.material, 'envMap', {
  9096. get: function get() {
  9097. return this.uniforms.envMap.value;
  9098. }
  9099. });
  9100. objects.update(boxMesh);
  9101. }
  9102. if (background.isWebGLCubeRenderTarget) {
  9103. // TODO Deprecate
  9104. background = background.texture;
  9105. }
  9106. boxMesh.material.uniforms.envMap.value = background;
  9107. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  9108. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9109. boxMesh.material.needsUpdate = true;
  9110. currentBackground = background;
  9111. currentBackgroundVersion = background.version;
  9112. currentTonemapping = renderer.toneMapping;
  9113. } // push to the pre-sorted opaque render list
  9114. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  9115. } else if (background && background.isTexture) {
  9116. if (planeMesh === undefined) {
  9117. planeMesh = new Mesh(new PlaneGeometry(2, 2), new ShaderMaterial({
  9118. name: 'BackgroundMaterial',
  9119. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  9120. vertexShader: ShaderLib.background.vertexShader,
  9121. fragmentShader: ShaderLib.background.fragmentShader,
  9122. side: FrontSide,
  9123. depthTest: false,
  9124. depthWrite: false,
  9125. fog: false
  9126. }));
  9127. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9128. Object.defineProperty(planeMesh.material, 'map', {
  9129. get: function get() {
  9130. return this.uniforms.t2D.value;
  9131. }
  9132. });
  9133. objects.update(planeMesh);
  9134. }
  9135. planeMesh.material.uniforms.t2D.value = background;
  9136. if (background.matrixAutoUpdate === true) {
  9137. background.updateMatrix();
  9138. }
  9139. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9140. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9141. planeMesh.material.needsUpdate = true;
  9142. currentBackground = background;
  9143. currentBackgroundVersion = background.version;
  9144. currentTonemapping = renderer.toneMapping;
  9145. } // push to the pre-sorted opaque render list
  9146. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9147. }
  9148. }
  9149. function setClear(color, alpha) {
  9150. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9151. }
  9152. return {
  9153. getClearColor: function getClearColor() {
  9154. return clearColor;
  9155. },
  9156. setClearColor: function setClearColor(color, alpha) {
  9157. if (alpha === void 0) {
  9158. alpha = 1;
  9159. }
  9160. clearColor.set(color);
  9161. clearAlpha = alpha;
  9162. setClear(clearColor, clearAlpha);
  9163. },
  9164. getClearAlpha: function getClearAlpha() {
  9165. return clearAlpha;
  9166. },
  9167. setClearAlpha: function setClearAlpha(alpha) {
  9168. clearAlpha = alpha;
  9169. setClear(clearColor, clearAlpha);
  9170. },
  9171. render: render
  9172. };
  9173. }
  9174. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9175. var maxVertexAttributes = gl.getParameter(34921);
  9176. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9177. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9178. var bindingStates = {};
  9179. var defaultState = createBindingState(null);
  9180. var currentState = defaultState;
  9181. function setup(object, material, program, geometry, index) {
  9182. var updateBuffers = false;
  9183. if (vaoAvailable) {
  9184. var state = getBindingState(geometry, program, material);
  9185. if (currentState !== state) {
  9186. currentState = state;
  9187. bindVertexArrayObject(currentState.object);
  9188. }
  9189. updateBuffers = needsUpdate(geometry, index);
  9190. if (updateBuffers) saveCache(geometry, index);
  9191. } else {
  9192. var wireframe = material.wireframe === true;
  9193. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9194. currentState.geometry = geometry.id;
  9195. currentState.program = program.id;
  9196. currentState.wireframe = wireframe;
  9197. updateBuffers = true;
  9198. }
  9199. }
  9200. if (object.isInstancedMesh === true) {
  9201. updateBuffers = true;
  9202. }
  9203. if (index !== null) {
  9204. attributes.update(index, 34963);
  9205. }
  9206. if (updateBuffers) {
  9207. setupVertexAttributes(object, material, program, geometry);
  9208. if (index !== null) {
  9209. gl.bindBuffer(34963, attributes.get(index).buffer);
  9210. }
  9211. }
  9212. }
  9213. function createVertexArrayObject() {
  9214. if (capabilities.isWebGL2) return gl.createVertexArray();
  9215. return extension.createVertexArrayOES();
  9216. }
  9217. function bindVertexArrayObject(vao) {
  9218. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9219. return extension.bindVertexArrayOES(vao);
  9220. }
  9221. function deleteVertexArrayObject(vao) {
  9222. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9223. return extension.deleteVertexArrayOES(vao);
  9224. }
  9225. function getBindingState(geometry, program, material) {
  9226. var wireframe = material.wireframe === true;
  9227. var programMap = bindingStates[geometry.id];
  9228. if (programMap === undefined) {
  9229. programMap = {};
  9230. bindingStates[geometry.id] = programMap;
  9231. }
  9232. var stateMap = programMap[program.id];
  9233. if (stateMap === undefined) {
  9234. stateMap = {};
  9235. programMap[program.id] = stateMap;
  9236. }
  9237. var state = stateMap[wireframe];
  9238. if (state === undefined) {
  9239. state = createBindingState(createVertexArrayObject());
  9240. stateMap[wireframe] = state;
  9241. }
  9242. return state;
  9243. }
  9244. function createBindingState(vao) {
  9245. var newAttributes = [];
  9246. var enabledAttributes = [];
  9247. var attributeDivisors = [];
  9248. for (var i = 0; i < maxVertexAttributes; i++) {
  9249. newAttributes[i] = 0;
  9250. enabledAttributes[i] = 0;
  9251. attributeDivisors[i] = 0;
  9252. }
  9253. return {
  9254. // for backward compatibility on non-VAO support browser
  9255. geometry: null,
  9256. program: null,
  9257. wireframe: false,
  9258. newAttributes: newAttributes,
  9259. enabledAttributes: enabledAttributes,
  9260. attributeDivisors: attributeDivisors,
  9261. object: vao,
  9262. attributes: {},
  9263. index: null
  9264. };
  9265. }
  9266. function needsUpdate(geometry, index) {
  9267. var cachedAttributes = currentState.attributes;
  9268. var geometryAttributes = geometry.attributes;
  9269. var attributesNum = 0;
  9270. for (var key in geometryAttributes) {
  9271. var cachedAttribute = cachedAttributes[key];
  9272. var geometryAttribute = geometryAttributes[key];
  9273. if (cachedAttribute === undefined) return true;
  9274. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9275. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9276. attributesNum++;
  9277. }
  9278. if (currentState.attributesNum !== attributesNum) return true;
  9279. if (currentState.index !== index) return true;
  9280. return false;
  9281. }
  9282. function saveCache(geometry, index) {
  9283. var cache = {};
  9284. var attributes = geometry.attributes;
  9285. var attributesNum = 0;
  9286. for (var key in attributes) {
  9287. var attribute = attributes[key];
  9288. var data = {};
  9289. data.attribute = attribute;
  9290. if (attribute.data) {
  9291. data.data = attribute.data;
  9292. }
  9293. cache[key] = data;
  9294. attributesNum++;
  9295. }
  9296. currentState.attributes = cache;
  9297. currentState.attributesNum = attributesNum;
  9298. currentState.index = index;
  9299. }
  9300. function initAttributes() {
  9301. var newAttributes = currentState.newAttributes;
  9302. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9303. newAttributes[i] = 0;
  9304. }
  9305. }
  9306. function enableAttribute(attribute) {
  9307. enableAttributeAndDivisor(attribute, 0);
  9308. }
  9309. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9310. var newAttributes = currentState.newAttributes;
  9311. var enabledAttributes = currentState.enabledAttributes;
  9312. var attributeDivisors = currentState.attributeDivisors;
  9313. newAttributes[attribute] = 1;
  9314. if (enabledAttributes[attribute] === 0) {
  9315. gl.enableVertexAttribArray(attribute);
  9316. enabledAttributes[attribute] = 1;
  9317. }
  9318. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9319. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9320. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9321. attributeDivisors[attribute] = meshPerAttribute;
  9322. }
  9323. }
  9324. function disableUnusedAttributes() {
  9325. var newAttributes = currentState.newAttributes;
  9326. var enabledAttributes = currentState.enabledAttributes;
  9327. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9328. if (enabledAttributes[i] !== newAttributes[i]) {
  9329. gl.disableVertexAttribArray(i);
  9330. enabledAttributes[i] = 0;
  9331. }
  9332. }
  9333. }
  9334. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9335. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9336. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9337. } else {
  9338. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9339. }
  9340. }
  9341. function setupVertexAttributes(object, material, program, geometry) {
  9342. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9343. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9344. }
  9345. initAttributes();
  9346. var geometryAttributes = geometry.attributes;
  9347. var programAttributes = program.getAttributes();
  9348. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9349. for (var name in programAttributes) {
  9350. var programAttribute = programAttributes[name];
  9351. if (programAttribute >= 0) {
  9352. var geometryAttribute = geometryAttributes[name];
  9353. if (geometryAttribute !== undefined) {
  9354. var normalized = geometryAttribute.normalized;
  9355. var size = geometryAttribute.itemSize;
  9356. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9357. if (attribute === undefined) continue;
  9358. var buffer = attribute.buffer;
  9359. var type = attribute.type;
  9360. var bytesPerElement = attribute.bytesPerElement;
  9361. if (geometryAttribute.isInterleavedBufferAttribute) {
  9362. var data = geometryAttribute.data;
  9363. var stride = data.stride;
  9364. var offset = geometryAttribute.offset;
  9365. if (data && data.isInstancedInterleavedBuffer) {
  9366. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9367. if (geometry._maxInstanceCount === undefined) {
  9368. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9369. }
  9370. } else {
  9371. enableAttribute(programAttribute);
  9372. }
  9373. gl.bindBuffer(34962, buffer);
  9374. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9375. } else {
  9376. if (geometryAttribute.isInstancedBufferAttribute) {
  9377. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9378. if (geometry._maxInstanceCount === undefined) {
  9379. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9380. }
  9381. } else {
  9382. enableAttribute(programAttribute);
  9383. }
  9384. gl.bindBuffer(34962, buffer);
  9385. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9386. }
  9387. } else if (name === 'instanceMatrix') {
  9388. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9389. if (_attribute === undefined) continue;
  9390. var _buffer = _attribute.buffer;
  9391. var _type = _attribute.type;
  9392. enableAttributeAndDivisor(programAttribute + 0, 1);
  9393. enableAttributeAndDivisor(programAttribute + 1, 1);
  9394. enableAttributeAndDivisor(programAttribute + 2, 1);
  9395. enableAttributeAndDivisor(programAttribute + 3, 1);
  9396. gl.bindBuffer(34962, _buffer);
  9397. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9398. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9399. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9400. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9401. } else if (name === 'instanceColor') {
  9402. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9403. if (_attribute2 === undefined) continue;
  9404. var _buffer2 = _attribute2.buffer;
  9405. var _type2 = _attribute2.type;
  9406. enableAttributeAndDivisor(programAttribute, 1);
  9407. gl.bindBuffer(34962, _buffer2);
  9408. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9409. } else if (materialDefaultAttributeValues !== undefined) {
  9410. var value = materialDefaultAttributeValues[name];
  9411. if (value !== undefined) {
  9412. switch (value.length) {
  9413. case 2:
  9414. gl.vertexAttrib2fv(programAttribute, value);
  9415. break;
  9416. case 3:
  9417. gl.vertexAttrib3fv(programAttribute, value);
  9418. break;
  9419. case 4:
  9420. gl.vertexAttrib4fv(programAttribute, value);
  9421. break;
  9422. default:
  9423. gl.vertexAttrib1fv(programAttribute, value);
  9424. }
  9425. }
  9426. }
  9427. }
  9428. }
  9429. disableUnusedAttributes();
  9430. }
  9431. function dispose() {
  9432. reset();
  9433. for (var geometryId in bindingStates) {
  9434. var programMap = bindingStates[geometryId];
  9435. for (var programId in programMap) {
  9436. var stateMap = programMap[programId];
  9437. for (var wireframe in stateMap) {
  9438. deleteVertexArrayObject(stateMap[wireframe].object);
  9439. delete stateMap[wireframe];
  9440. }
  9441. delete programMap[programId];
  9442. }
  9443. delete bindingStates[geometryId];
  9444. }
  9445. }
  9446. function releaseStatesOfGeometry(geometry) {
  9447. if (bindingStates[geometry.id] === undefined) return;
  9448. var programMap = bindingStates[geometry.id];
  9449. for (var programId in programMap) {
  9450. var stateMap = programMap[programId];
  9451. for (var wireframe in stateMap) {
  9452. deleteVertexArrayObject(stateMap[wireframe].object);
  9453. delete stateMap[wireframe];
  9454. }
  9455. delete programMap[programId];
  9456. }
  9457. delete bindingStates[geometry.id];
  9458. }
  9459. function releaseStatesOfProgram(program) {
  9460. for (var geometryId in bindingStates) {
  9461. var programMap = bindingStates[geometryId];
  9462. if (programMap[program.id] === undefined) continue;
  9463. var stateMap = programMap[program.id];
  9464. for (var wireframe in stateMap) {
  9465. deleteVertexArrayObject(stateMap[wireframe].object);
  9466. delete stateMap[wireframe];
  9467. }
  9468. delete programMap[program.id];
  9469. }
  9470. }
  9471. function reset() {
  9472. resetDefaultState();
  9473. if (currentState === defaultState) return;
  9474. currentState = defaultState;
  9475. bindVertexArrayObject(currentState.object);
  9476. } // for backward-compatilibity
  9477. function resetDefaultState() {
  9478. defaultState.geometry = null;
  9479. defaultState.program = null;
  9480. defaultState.wireframe = false;
  9481. }
  9482. return {
  9483. setup: setup,
  9484. reset: reset,
  9485. resetDefaultState: resetDefaultState,
  9486. dispose: dispose,
  9487. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9488. releaseStatesOfProgram: releaseStatesOfProgram,
  9489. initAttributes: initAttributes,
  9490. enableAttribute: enableAttribute,
  9491. disableUnusedAttributes: disableUnusedAttributes
  9492. };
  9493. }
  9494. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  9495. var isWebGL2 = capabilities.isWebGL2;
  9496. var mode;
  9497. function setMode(value) {
  9498. mode = value;
  9499. }
  9500. function render(start, count) {
  9501. gl.drawArrays(mode, start, count);
  9502. info.update(count, mode, 1);
  9503. }
  9504. function renderInstances(start, count, primcount) {
  9505. if (primcount === 0) return;
  9506. var extension, methodName;
  9507. if (isWebGL2) {
  9508. extension = gl;
  9509. methodName = 'drawArraysInstanced';
  9510. } else {
  9511. extension = extensions.get('ANGLE_instanced_arrays');
  9512. methodName = 'drawArraysInstancedANGLE';
  9513. if (extension === null) {
  9514. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9515. return;
  9516. }
  9517. }
  9518. extension[methodName](mode, start, count, primcount);
  9519. info.update(count, mode, primcount);
  9520. } //
  9521. this.setMode = setMode;
  9522. this.render = render;
  9523. this.renderInstances = renderInstances;
  9524. }
  9525. function WebGLCapabilities(gl, extensions, parameters) {
  9526. var maxAnisotropy;
  9527. function getMaxAnisotropy() {
  9528. if (maxAnisotropy !== undefined) return maxAnisotropy;
  9529. var extension = extensions.get('EXT_texture_filter_anisotropic');
  9530. if (extension !== null) {
  9531. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  9532. } else {
  9533. maxAnisotropy = 0;
  9534. }
  9535. return maxAnisotropy;
  9536. }
  9537. function getMaxPrecision(precision) {
  9538. if (precision === 'highp') {
  9539. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  9540. return 'highp';
  9541. }
  9542. precision = 'mediump';
  9543. }
  9544. if (precision === 'mediump') {
  9545. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  9546. return 'mediump';
  9547. }
  9548. }
  9549. return 'lowp';
  9550. }
  9551. /* eslint-disable no-undef */
  9552. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  9553. /* eslint-enable no-undef */
  9554. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9555. var maxPrecision = getMaxPrecision(precision);
  9556. if (maxPrecision !== precision) {
  9557. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  9558. precision = maxPrecision;
  9559. }
  9560. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9561. var maxTextures = gl.getParameter(34930);
  9562. var maxVertexTextures = gl.getParameter(35660);
  9563. var maxTextureSize = gl.getParameter(3379);
  9564. var maxCubemapSize = gl.getParameter(34076);
  9565. var maxAttributes = gl.getParameter(34921);
  9566. var maxVertexUniforms = gl.getParameter(36347);
  9567. var maxVaryings = gl.getParameter(36348);
  9568. var maxFragmentUniforms = gl.getParameter(36349);
  9569. var vertexTextures = maxVertexTextures > 0;
  9570. var floatFragmentTextures = isWebGL2 || !!extensions.get('OES_texture_float');
  9571. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9572. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  9573. return {
  9574. isWebGL2: isWebGL2,
  9575. getMaxAnisotropy: getMaxAnisotropy,
  9576. getMaxPrecision: getMaxPrecision,
  9577. precision: precision,
  9578. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9579. maxTextures: maxTextures,
  9580. maxVertexTextures: maxVertexTextures,
  9581. maxTextureSize: maxTextureSize,
  9582. maxCubemapSize: maxCubemapSize,
  9583. maxAttributes: maxAttributes,
  9584. maxVertexUniforms: maxVertexUniforms,
  9585. maxVaryings: maxVaryings,
  9586. maxFragmentUniforms: maxFragmentUniforms,
  9587. vertexTextures: vertexTextures,
  9588. floatFragmentTextures: floatFragmentTextures,
  9589. floatVertexTextures: floatVertexTextures,
  9590. maxSamples: maxSamples
  9591. };
  9592. }
  9593. function WebGLClipping(properties) {
  9594. var scope = this;
  9595. var globalState = null,
  9596. numGlobalPlanes = 0,
  9597. localClippingEnabled = false,
  9598. renderingShadows = false;
  9599. var plane = new Plane(),
  9600. viewNormalMatrix = new Matrix3(),
  9601. uniform = {
  9602. value: null,
  9603. needsUpdate: false
  9604. };
  9605. this.uniform = uniform;
  9606. this.numPlanes = 0;
  9607. this.numIntersection = 0;
  9608. this.init = function (planes, enableLocalClipping, camera) {
  9609. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  9610. // run another frame in order to reset the state:
  9611. numGlobalPlanes !== 0 || localClippingEnabled;
  9612. localClippingEnabled = enableLocalClipping;
  9613. globalState = projectPlanes(planes, camera, 0);
  9614. numGlobalPlanes = planes.length;
  9615. return enabled;
  9616. };
  9617. this.beginShadows = function () {
  9618. renderingShadows = true;
  9619. projectPlanes(null);
  9620. };
  9621. this.endShadows = function () {
  9622. renderingShadows = false;
  9623. resetGlobalState();
  9624. };
  9625. this.setState = function (material, camera, useCache) {
  9626. var planes = material.clippingPlanes,
  9627. clipIntersection = material.clipIntersection,
  9628. clipShadows = material.clipShadows;
  9629. var materialProperties = properties.get(material);
  9630. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  9631. // there's no local clipping
  9632. if (renderingShadows) {
  9633. // there's no global clipping
  9634. projectPlanes(null);
  9635. } else {
  9636. resetGlobalState();
  9637. }
  9638. } else {
  9639. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9640. lGlobal = nGlobal * 4;
  9641. var dstArray = materialProperties.clippingState || null;
  9642. uniform.value = dstArray; // ensure unique state
  9643. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  9644. for (var i = 0; i !== lGlobal; ++i) {
  9645. dstArray[i] = globalState[i];
  9646. }
  9647. materialProperties.clippingState = dstArray;
  9648. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9649. this.numPlanes += nGlobal;
  9650. }
  9651. };
  9652. function resetGlobalState() {
  9653. if (uniform.value !== globalState) {
  9654. uniform.value = globalState;
  9655. uniform.needsUpdate = numGlobalPlanes > 0;
  9656. }
  9657. scope.numPlanes = numGlobalPlanes;
  9658. scope.numIntersection = 0;
  9659. }
  9660. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  9661. var nPlanes = planes !== null ? planes.length : 0;
  9662. var dstArray = null;
  9663. if (nPlanes !== 0) {
  9664. dstArray = uniform.value;
  9665. if (skipTransform !== true || dstArray === null) {
  9666. var flatSize = dstOffset + nPlanes * 4,
  9667. viewMatrix = camera.matrixWorldInverse;
  9668. viewNormalMatrix.getNormalMatrix(viewMatrix);
  9669. if (dstArray === null || dstArray.length < flatSize) {
  9670. dstArray = new Float32Array(flatSize);
  9671. }
  9672. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  9673. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  9674. plane.normal.toArray(dstArray, i4);
  9675. dstArray[i4 + 3] = plane.constant;
  9676. }
  9677. }
  9678. uniform.value = dstArray;
  9679. uniform.needsUpdate = true;
  9680. }
  9681. scope.numPlanes = nPlanes;
  9682. scope.numIntersection = 0;
  9683. return dstArray;
  9684. }
  9685. }
  9686. function WebGLCubeMaps(renderer) {
  9687. var cubemaps = new WeakMap();
  9688. function mapTextureMapping(texture, mapping) {
  9689. if (mapping === EquirectangularReflectionMapping) {
  9690. texture.mapping = CubeReflectionMapping;
  9691. } else if (mapping === EquirectangularRefractionMapping) {
  9692. texture.mapping = CubeRefractionMapping;
  9693. }
  9694. return texture;
  9695. }
  9696. function get(texture) {
  9697. if (texture && texture.isTexture) {
  9698. var mapping = texture.mapping;
  9699. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  9700. if (cubemaps.has(texture)) {
  9701. var cubemap = cubemaps.get(texture).texture;
  9702. return mapTextureMapping(cubemap, texture.mapping);
  9703. } else {
  9704. var image = texture.image;
  9705. if (image && image.height > 0) {
  9706. var currentRenderList = renderer.getRenderList();
  9707. var currentRenderTarget = renderer.getRenderTarget();
  9708. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  9709. renderTarget.fromEquirectangularTexture(renderer, texture);
  9710. cubemaps.set(texture, renderTarget);
  9711. renderer.setRenderTarget(currentRenderTarget);
  9712. renderer.setRenderList(currentRenderList);
  9713. texture.addEventListener('dispose', onTextureDispose);
  9714. return mapTextureMapping(renderTarget.texture, texture.mapping);
  9715. } else {
  9716. // image not yet ready. try the conversion next frame
  9717. return null;
  9718. }
  9719. }
  9720. }
  9721. }
  9722. return texture;
  9723. }
  9724. function onTextureDispose(event) {
  9725. var texture = event.target;
  9726. texture.removeEventListener('dispose', onTextureDispose);
  9727. var cubemap = cubemaps.get(texture);
  9728. if (cubemap !== undefined) {
  9729. cubemaps.delete(texture);
  9730. cubemap.dispose();
  9731. }
  9732. }
  9733. function dispose() {
  9734. cubemaps = new WeakMap();
  9735. }
  9736. return {
  9737. get: get,
  9738. dispose: dispose
  9739. };
  9740. }
  9741. function WebGLExtensions(gl) {
  9742. var extensions = {};
  9743. return {
  9744. has: function has(name) {
  9745. if (extensions[name] !== undefined) {
  9746. return extensions[name] !== null;
  9747. }
  9748. var extension;
  9749. switch (name) {
  9750. case 'WEBGL_depth_texture':
  9751. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  9752. break;
  9753. case 'EXT_texture_filter_anisotropic':
  9754. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  9755. break;
  9756. case 'WEBGL_compressed_texture_s3tc':
  9757. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  9758. break;
  9759. case 'WEBGL_compressed_texture_pvrtc':
  9760. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  9761. break;
  9762. default:
  9763. extension = gl.getExtension(name);
  9764. }
  9765. extensions[name] = extension;
  9766. return extension !== null;
  9767. },
  9768. get: function get(name) {
  9769. if (!this.has(name)) {
  9770. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  9771. }
  9772. return extensions[name];
  9773. }
  9774. };
  9775. }
  9776. function WebGLGeometries(gl, attributes, info, bindingStates) {
  9777. var geometries = new WeakMap();
  9778. var wireframeAttributes = new WeakMap();
  9779. function onGeometryDispose(event) {
  9780. var geometry = event.target;
  9781. var buffergeometry = geometries.get(geometry);
  9782. if (buffergeometry.index !== null) {
  9783. attributes.remove(buffergeometry.index);
  9784. }
  9785. for (var name in buffergeometry.attributes) {
  9786. attributes.remove(buffergeometry.attributes[name]);
  9787. }
  9788. geometry.removeEventListener('dispose', onGeometryDispose);
  9789. geometries.delete(geometry);
  9790. var attribute = wireframeAttributes.get(buffergeometry);
  9791. if (attribute) {
  9792. attributes.remove(attribute);
  9793. wireframeAttributes.delete(buffergeometry);
  9794. }
  9795. bindingStates.releaseStatesOfGeometry(buffergeometry);
  9796. if (geometry.isInstancedBufferGeometry === true) {
  9797. delete geometry._maxInstanceCount;
  9798. } //
  9799. info.memory.geometries--;
  9800. }
  9801. function get(object, geometry) {
  9802. var buffergeometry = geometries.get(geometry);
  9803. if (buffergeometry) return buffergeometry;
  9804. geometry.addEventListener('dispose', onGeometryDispose);
  9805. if (geometry.isBufferGeometry) {
  9806. buffergeometry = geometry;
  9807. } else if (geometry.isGeometry) {
  9808. if (geometry._bufferGeometry === undefined) {
  9809. geometry._bufferGeometry = new BufferGeometry().setFromObject(object);
  9810. }
  9811. buffergeometry = geometry._bufferGeometry;
  9812. }
  9813. geometries.set(geometry, buffergeometry);
  9814. info.memory.geometries++;
  9815. return buffergeometry;
  9816. }
  9817. function update(geometry) {
  9818. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  9819. for (var name in geometryAttributes) {
  9820. attributes.update(geometryAttributes[name], 34962);
  9821. } // morph targets
  9822. var morphAttributes = geometry.morphAttributes;
  9823. for (var _name in morphAttributes) {
  9824. var array = morphAttributes[_name];
  9825. for (var i = 0, l = array.length; i < l; i++) {
  9826. attributes.update(array[i], 34962);
  9827. }
  9828. }
  9829. }
  9830. function updateWireframeAttribute(geometry) {
  9831. var indices = [];
  9832. var geometryIndex = geometry.index;
  9833. var geometryPosition = geometry.attributes.position;
  9834. var version = 0;
  9835. if (geometryIndex !== null) {
  9836. var array = geometryIndex.array;
  9837. version = geometryIndex.version;
  9838. for (var i = 0, l = array.length; i < l; i += 3) {
  9839. var a = array[i + 0];
  9840. var b = array[i + 1];
  9841. var c = array[i + 2];
  9842. indices.push(a, b, b, c, c, a);
  9843. }
  9844. } else {
  9845. var _array = geometryPosition.array;
  9846. version = geometryPosition.version;
  9847. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  9848. var _a = _i + 0;
  9849. var _b = _i + 1;
  9850. var _c = _i + 2;
  9851. indices.push(_a, _b, _b, _c, _c, _a);
  9852. }
  9853. }
  9854. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  9855. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  9856. //
  9857. var previousAttribute = wireframeAttributes.get(geometry);
  9858. if (previousAttribute) attributes.remove(previousAttribute); //
  9859. wireframeAttributes.set(geometry, attribute);
  9860. }
  9861. function getWireframeAttribute(geometry) {
  9862. var currentAttribute = wireframeAttributes.get(geometry);
  9863. if (currentAttribute) {
  9864. var geometryIndex = geometry.index;
  9865. if (geometryIndex !== null) {
  9866. // if the attribute is obsolete, create a new one
  9867. if (currentAttribute.version < geometryIndex.version) {
  9868. updateWireframeAttribute(geometry);
  9869. }
  9870. }
  9871. } else {
  9872. updateWireframeAttribute(geometry);
  9873. }
  9874. return wireframeAttributes.get(geometry);
  9875. }
  9876. return {
  9877. get: get,
  9878. update: update,
  9879. getWireframeAttribute: getWireframeAttribute
  9880. };
  9881. }
  9882. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  9883. var isWebGL2 = capabilities.isWebGL2;
  9884. var mode;
  9885. function setMode(value) {
  9886. mode = value;
  9887. }
  9888. var type, bytesPerElement;
  9889. function setIndex(value) {
  9890. type = value.type;
  9891. bytesPerElement = value.bytesPerElement;
  9892. }
  9893. function render(start, count) {
  9894. gl.drawElements(mode, count, type, start * bytesPerElement);
  9895. info.update(count, mode, 1);
  9896. }
  9897. function renderInstances(start, count, primcount) {
  9898. if (primcount === 0) return;
  9899. var extension, methodName;
  9900. if (isWebGL2) {
  9901. extension = gl;
  9902. methodName = 'drawElementsInstanced';
  9903. } else {
  9904. extension = extensions.get('ANGLE_instanced_arrays');
  9905. methodName = 'drawElementsInstancedANGLE';
  9906. if (extension === null) {
  9907. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9908. return;
  9909. }
  9910. }
  9911. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  9912. info.update(count, mode, primcount);
  9913. } //
  9914. this.setMode = setMode;
  9915. this.setIndex = setIndex;
  9916. this.render = render;
  9917. this.renderInstances = renderInstances;
  9918. }
  9919. function WebGLInfo(gl) {
  9920. var memory = {
  9921. geometries: 0,
  9922. textures: 0
  9923. };
  9924. var render = {
  9925. frame: 0,
  9926. calls: 0,
  9927. triangles: 0,
  9928. points: 0,
  9929. lines: 0
  9930. };
  9931. function update(count, mode, instanceCount) {
  9932. render.calls++;
  9933. switch (mode) {
  9934. case 4:
  9935. render.triangles += instanceCount * (count / 3);
  9936. break;
  9937. case 1:
  9938. render.lines += instanceCount * (count / 2);
  9939. break;
  9940. case 3:
  9941. render.lines += instanceCount * (count - 1);
  9942. break;
  9943. case 2:
  9944. render.lines += instanceCount * count;
  9945. break;
  9946. case 0:
  9947. render.points += instanceCount * count;
  9948. break;
  9949. default:
  9950. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  9951. break;
  9952. }
  9953. }
  9954. function reset() {
  9955. render.frame++;
  9956. render.calls = 0;
  9957. render.triangles = 0;
  9958. render.points = 0;
  9959. render.lines = 0;
  9960. }
  9961. return {
  9962. memory: memory,
  9963. render: render,
  9964. programs: null,
  9965. autoReset: true,
  9966. reset: reset,
  9967. update: update
  9968. };
  9969. }
  9970. function numericalSort(a, b) {
  9971. return a[0] - b[0];
  9972. }
  9973. function absNumericalSort(a, b) {
  9974. return Math.abs(b[1]) - Math.abs(a[1]);
  9975. }
  9976. function WebGLMorphtargets(gl) {
  9977. var influencesList = {};
  9978. var morphInfluences = new Float32Array(8);
  9979. var workInfluences = [];
  9980. for (var i = 0; i < 8; i++) {
  9981. workInfluences[i] = [i, 0];
  9982. }
  9983. function update(object, geometry, material, program) {
  9984. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  9985. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  9986. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  9987. var influences = influencesList[geometry.id];
  9988. if (influences === undefined) {
  9989. // initialise list
  9990. influences = [];
  9991. for (var _i = 0; _i < length; _i++) {
  9992. influences[_i] = [_i, 0];
  9993. }
  9994. influencesList[geometry.id] = influences;
  9995. } // Collect influences
  9996. for (var _i2 = 0; _i2 < length; _i2++) {
  9997. var influence = influences[_i2];
  9998. influence[0] = _i2;
  9999. influence[1] = objectInfluences[_i2];
  10000. }
  10001. influences.sort(absNumericalSort);
  10002. for (var _i3 = 0; _i3 < 8; _i3++) {
  10003. if (_i3 < length && influences[_i3][1]) {
  10004. workInfluences[_i3][0] = influences[_i3][0];
  10005. workInfluences[_i3][1] = influences[_i3][1];
  10006. } else {
  10007. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  10008. workInfluences[_i3][1] = 0;
  10009. }
  10010. }
  10011. workInfluences.sort(numericalSort);
  10012. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  10013. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  10014. var morphInfluencesSum = 0;
  10015. for (var _i4 = 0; _i4 < 8; _i4++) {
  10016. var _influence = workInfluences[_i4];
  10017. var index = _influence[0];
  10018. var value = _influence[1];
  10019. if (index !== Number.MAX_SAFE_INTEGER && value) {
  10020. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  10021. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  10022. }
  10023. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  10024. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  10025. }
  10026. morphInfluences[_i4] = value;
  10027. morphInfluencesSum += value;
  10028. } else {
  10029. if (morphTargets && geometry.hasAttribute('morphTarget' + _i4) === true) {
  10030. geometry.deleteAttribute('morphTarget' + _i4);
  10031. }
  10032. if (morphNormals && geometry.hasAttribute('morphNormal' + _i4) === true) {
  10033. geometry.deleteAttribute('morphNormal' + _i4);
  10034. }
  10035. morphInfluences[_i4] = 0;
  10036. }
  10037. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  10038. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  10039. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  10040. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10041. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  10042. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  10043. }
  10044. return {
  10045. update: update
  10046. };
  10047. }
  10048. function WebGLObjects(gl, geometries, attributes, info) {
  10049. var updateMap = new WeakMap();
  10050. function update(object) {
  10051. var frame = info.render.frame;
  10052. var geometry = object.geometry;
  10053. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  10054. if (updateMap.get(buffergeometry) !== frame) {
  10055. if (geometry.isGeometry) {
  10056. buffergeometry.updateFromObject(object);
  10057. }
  10058. geometries.update(buffergeometry);
  10059. updateMap.set(buffergeometry, frame);
  10060. }
  10061. if (object.isInstancedMesh) {
  10062. if (object.hasEventListener('dispose', onInstancedMeshDispose) === false) {
  10063. object.addEventListener('dispose', onInstancedMeshDispose);
  10064. }
  10065. attributes.update(object.instanceMatrix, 34962);
  10066. if (object.instanceColor !== null) {
  10067. attributes.update(object.instanceColor, 34962);
  10068. }
  10069. }
  10070. return buffergeometry;
  10071. }
  10072. function dispose() {
  10073. updateMap = new WeakMap();
  10074. }
  10075. function onInstancedMeshDispose(event) {
  10076. var instancedMesh = event.target;
  10077. instancedMesh.removeEventListener('dispose', onInstancedMeshDispose);
  10078. attributes.remove(instancedMesh.instanceMatrix);
  10079. if (instancedMesh.instanceColor !== null) attributes.remove(instancedMesh.instanceColor);
  10080. }
  10081. return {
  10082. update: update,
  10083. dispose: dispose
  10084. };
  10085. }
  10086. function DataTexture2DArray(data, width, height, depth) {
  10087. if (data === void 0) {
  10088. data = null;
  10089. }
  10090. if (width === void 0) {
  10091. width = 1;
  10092. }
  10093. if (height === void 0) {
  10094. height = 1;
  10095. }
  10096. if (depth === void 0) {
  10097. depth = 1;
  10098. }
  10099. Texture.call(this, null);
  10100. this.image = {
  10101. data: data,
  10102. width: width,
  10103. height: height,
  10104. depth: depth
  10105. };
  10106. this.magFilter = NearestFilter;
  10107. this.minFilter = NearestFilter;
  10108. this.wrapR = ClampToEdgeWrapping;
  10109. this.generateMipmaps = false;
  10110. this.flipY = false;
  10111. this.needsUpdate = true;
  10112. }
  10113. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  10114. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10115. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10116. function DataTexture3D(data, width, height, depth) {
  10117. if (data === void 0) {
  10118. data = null;
  10119. }
  10120. if (width === void 0) {
  10121. width = 1;
  10122. }
  10123. if (height === void 0) {
  10124. height = 1;
  10125. }
  10126. if (depth === void 0) {
  10127. depth = 1;
  10128. }
  10129. // We're going to add .setXXX() methods for setting properties later.
  10130. // Users can still set in DataTexture3D directly.
  10131. //
  10132. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10133. // texture.anisotropy = 16;
  10134. //
  10135. // See #14839
  10136. Texture.call(this, null);
  10137. this.image = {
  10138. data: data,
  10139. width: width,
  10140. height: height,
  10141. depth: depth
  10142. };
  10143. this.magFilter = NearestFilter;
  10144. this.minFilter = NearestFilter;
  10145. this.wrapR = ClampToEdgeWrapping;
  10146. this.generateMipmaps = false;
  10147. this.flipY = false;
  10148. this.needsUpdate = true;
  10149. }
  10150. DataTexture3D.prototype = Object.create(Texture.prototype);
  10151. DataTexture3D.prototype.constructor = DataTexture3D;
  10152. DataTexture3D.prototype.isDataTexture3D = true;
  10153. /**
  10154. * Uniforms of a program.
  10155. * Those form a tree structure with a special top-level container for the root,
  10156. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10157. *
  10158. *
  10159. * Properties of inner nodes including the top-level container:
  10160. *
  10161. * .seq - array of nested uniforms
  10162. * .map - nested uniforms by name
  10163. *
  10164. *
  10165. * Methods of all nodes except the top-level container:
  10166. *
  10167. * .setValue( gl, value, [textures] )
  10168. *
  10169. * uploads a uniform value(s)
  10170. * the 'textures' parameter is needed for sampler uniforms
  10171. *
  10172. *
  10173. * Static methods of the top-level container (textures factorizations):
  10174. *
  10175. * .upload( gl, seq, values, textures )
  10176. *
  10177. * sets uniforms in 'seq' to 'values[id].value'
  10178. *
  10179. * .seqWithValue( seq, values ) : filteredSeq
  10180. *
  10181. * filters 'seq' entries with corresponding entry in values
  10182. *
  10183. *
  10184. * Methods of the top-level container (textures factorizations):
  10185. *
  10186. * .setValue( gl, name, value, textures )
  10187. *
  10188. * sets uniform with name 'name' to 'value'
  10189. *
  10190. * .setOptional( gl, obj, prop )
  10191. *
  10192. * like .set for an optional property of the object
  10193. *
  10194. */
  10195. var emptyTexture = new Texture();
  10196. var emptyTexture2dArray = new DataTexture2DArray();
  10197. var emptyTexture3d = new DataTexture3D();
  10198. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10199. // Array Caches (provide typed arrays for temporary by size)
  10200. var arrayCacheF32 = [];
  10201. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10202. var mat4array = new Float32Array(16);
  10203. var mat3array = new Float32Array(9);
  10204. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10205. function flatten(array, nBlocks, blockSize) {
  10206. var firstElem = array[0];
  10207. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10208. // see http://jacksondunstan.com/articles/983
  10209. var n = nBlocks * blockSize;
  10210. var r = arrayCacheF32[n];
  10211. if (r === undefined) {
  10212. r = new Float32Array(n);
  10213. arrayCacheF32[n] = r;
  10214. }
  10215. if (nBlocks !== 0) {
  10216. firstElem.toArray(r, 0);
  10217. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10218. offset += blockSize;
  10219. array[i].toArray(r, offset);
  10220. }
  10221. }
  10222. return r;
  10223. }
  10224. function arraysEqual(a, b) {
  10225. if (a.length !== b.length) return false;
  10226. for (var i = 0, l = a.length; i < l; i++) {
  10227. if (a[i] !== b[i]) return false;
  10228. }
  10229. return true;
  10230. }
  10231. function copyArray(a, b) {
  10232. for (var i = 0, l = b.length; i < l; i++) {
  10233. a[i] = b[i];
  10234. }
  10235. } // Texture unit allocation
  10236. function allocTexUnits(textures, n) {
  10237. var r = arrayCacheI32[n];
  10238. if (r === undefined) {
  10239. r = new Int32Array(n);
  10240. arrayCacheI32[n] = r;
  10241. }
  10242. for (var i = 0; i !== n; ++i) {
  10243. r[i] = textures.allocateTextureUnit();
  10244. }
  10245. return r;
  10246. } // --- Setters ---
  10247. // Note: Defining these methods externally, because they come in a bunch
  10248. // and this way their names minify.
  10249. // Single scalar
  10250. function setValueV1f(gl, v) {
  10251. var cache = this.cache;
  10252. if (cache[0] === v) return;
  10253. gl.uniform1f(this.addr, v);
  10254. cache[0] = v;
  10255. } // Single float vector (from flat array or THREE.VectorN)
  10256. function setValueV2f(gl, v) {
  10257. var cache = this.cache;
  10258. if (v.x !== undefined) {
  10259. if (cache[0] !== v.x || cache[1] !== v.y) {
  10260. gl.uniform2f(this.addr, v.x, v.y);
  10261. cache[0] = v.x;
  10262. cache[1] = v.y;
  10263. }
  10264. } else {
  10265. if (arraysEqual(cache, v)) return;
  10266. gl.uniform2fv(this.addr, v);
  10267. copyArray(cache, v);
  10268. }
  10269. }
  10270. function setValueV3f(gl, v) {
  10271. var cache = this.cache;
  10272. if (v.x !== undefined) {
  10273. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10274. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10275. cache[0] = v.x;
  10276. cache[1] = v.y;
  10277. cache[2] = v.z;
  10278. }
  10279. } else if (v.r !== undefined) {
  10280. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10281. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10282. cache[0] = v.r;
  10283. cache[1] = v.g;
  10284. cache[2] = v.b;
  10285. }
  10286. } else {
  10287. if (arraysEqual(cache, v)) return;
  10288. gl.uniform3fv(this.addr, v);
  10289. copyArray(cache, v);
  10290. }
  10291. }
  10292. function setValueV4f(gl, v) {
  10293. var cache = this.cache;
  10294. if (v.x !== undefined) {
  10295. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10296. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10297. cache[0] = v.x;
  10298. cache[1] = v.y;
  10299. cache[2] = v.z;
  10300. cache[3] = v.w;
  10301. }
  10302. } else {
  10303. if (arraysEqual(cache, v)) return;
  10304. gl.uniform4fv(this.addr, v);
  10305. copyArray(cache, v);
  10306. }
  10307. } // Single matrix (from flat array or MatrixN)
  10308. function setValueM2(gl, v) {
  10309. var cache = this.cache;
  10310. var elements = v.elements;
  10311. if (elements === undefined) {
  10312. if (arraysEqual(cache, v)) return;
  10313. gl.uniformMatrix2fv(this.addr, false, v);
  10314. copyArray(cache, v);
  10315. } else {
  10316. if (arraysEqual(cache, elements)) return;
  10317. mat2array.set(elements);
  10318. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10319. copyArray(cache, elements);
  10320. }
  10321. }
  10322. function setValueM3(gl, v) {
  10323. var cache = this.cache;
  10324. var elements = v.elements;
  10325. if (elements === undefined) {
  10326. if (arraysEqual(cache, v)) return;
  10327. gl.uniformMatrix3fv(this.addr, false, v);
  10328. copyArray(cache, v);
  10329. } else {
  10330. if (arraysEqual(cache, elements)) return;
  10331. mat3array.set(elements);
  10332. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10333. copyArray(cache, elements);
  10334. }
  10335. }
  10336. function setValueM4(gl, v) {
  10337. var cache = this.cache;
  10338. var elements = v.elements;
  10339. if (elements === undefined) {
  10340. if (arraysEqual(cache, v)) return;
  10341. gl.uniformMatrix4fv(this.addr, false, v);
  10342. copyArray(cache, v);
  10343. } else {
  10344. if (arraysEqual(cache, elements)) return;
  10345. mat4array.set(elements);
  10346. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10347. copyArray(cache, elements);
  10348. }
  10349. } // Single texture (2D / Cube)
  10350. function setValueT1(gl, v, textures) {
  10351. var cache = this.cache;
  10352. var unit = textures.allocateTextureUnit();
  10353. if (cache[0] !== unit) {
  10354. gl.uniform1i(this.addr, unit);
  10355. cache[0] = unit;
  10356. }
  10357. textures.safeSetTexture2D(v || emptyTexture, unit);
  10358. }
  10359. function setValueT2DArray1(gl, v, textures) {
  10360. var cache = this.cache;
  10361. var unit = textures.allocateTextureUnit();
  10362. if (cache[0] !== unit) {
  10363. gl.uniform1i(this.addr, unit);
  10364. cache[0] = unit;
  10365. }
  10366. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10367. }
  10368. function setValueT3D1(gl, v, textures) {
  10369. var cache = this.cache;
  10370. var unit = textures.allocateTextureUnit();
  10371. if (cache[0] !== unit) {
  10372. gl.uniform1i(this.addr, unit);
  10373. cache[0] = unit;
  10374. }
  10375. textures.setTexture3D(v || emptyTexture3d, unit);
  10376. }
  10377. function setValueT6(gl, v, textures) {
  10378. var cache = this.cache;
  10379. var unit = textures.allocateTextureUnit();
  10380. if (cache[0] !== unit) {
  10381. gl.uniform1i(this.addr, unit);
  10382. cache[0] = unit;
  10383. }
  10384. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10385. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10386. function setValueV1i(gl, v) {
  10387. var cache = this.cache;
  10388. if (cache[0] === v) return;
  10389. gl.uniform1i(this.addr, v);
  10390. cache[0] = v;
  10391. }
  10392. function setValueV2i(gl, v) {
  10393. var cache = this.cache;
  10394. if (arraysEqual(cache, v)) return;
  10395. gl.uniform2iv(this.addr, v);
  10396. copyArray(cache, v);
  10397. }
  10398. function setValueV3i(gl, v) {
  10399. var cache = this.cache;
  10400. if (arraysEqual(cache, v)) return;
  10401. gl.uniform3iv(this.addr, v);
  10402. copyArray(cache, v);
  10403. }
  10404. function setValueV4i(gl, v) {
  10405. var cache = this.cache;
  10406. if (arraysEqual(cache, v)) return;
  10407. gl.uniform4iv(this.addr, v);
  10408. copyArray(cache, v);
  10409. } // uint
  10410. function setValueV1ui(gl, v) {
  10411. var cache = this.cache;
  10412. if (cache[0] === v) return;
  10413. gl.uniform1ui(this.addr, v);
  10414. cache[0] = v;
  10415. } // Helper to pick the right setter for the singular case
  10416. function getSingularSetter(type) {
  10417. switch (type) {
  10418. case 0x1406:
  10419. return setValueV1f;
  10420. // FLOAT
  10421. case 0x8b50:
  10422. return setValueV2f;
  10423. // _VEC2
  10424. case 0x8b51:
  10425. return setValueV3f;
  10426. // _VEC3
  10427. case 0x8b52:
  10428. return setValueV4f;
  10429. // _VEC4
  10430. case 0x8b5a:
  10431. return setValueM2;
  10432. // _MAT2
  10433. case 0x8b5b:
  10434. return setValueM3;
  10435. // _MAT3
  10436. case 0x8b5c:
  10437. return setValueM4;
  10438. // _MAT4
  10439. case 0x1404:
  10440. case 0x8b56:
  10441. return setValueV1i;
  10442. // INT, BOOL
  10443. case 0x8b53:
  10444. case 0x8b57:
  10445. return setValueV2i;
  10446. // _VEC2
  10447. case 0x8b54:
  10448. case 0x8b58:
  10449. return setValueV3i;
  10450. // _VEC3
  10451. case 0x8b55:
  10452. case 0x8b59:
  10453. return setValueV4i;
  10454. // _VEC4
  10455. case 0x1405:
  10456. return setValueV1ui;
  10457. // UINT
  10458. case 0x8b5e: // SAMPLER_2D
  10459. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10460. case 0x8dca: // INT_SAMPLER_2D
  10461. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10462. case 0x8b62:
  10463. // SAMPLER_2D_SHADOW
  10464. return setValueT1;
  10465. case 0x8b5f: // SAMPLER_3D
  10466. case 0x8dcb: // INT_SAMPLER_3D
  10467. case 0x8dd3:
  10468. // UNSIGNED_INT_SAMPLER_3D
  10469. return setValueT3D1;
  10470. case 0x8b60: // SAMPLER_CUBE
  10471. case 0x8dcc: // INT_SAMPLER_CUBE
  10472. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10473. case 0x8dc5:
  10474. // SAMPLER_CUBE_SHADOW
  10475. return setValueT6;
  10476. case 0x8dc1: // SAMPLER_2D_ARRAY
  10477. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10478. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10479. case 0x8dc4:
  10480. // SAMPLER_2D_ARRAY_SHADOW
  10481. return setValueT2DArray1;
  10482. }
  10483. } // Array of scalars
  10484. function setValueV1fArray(gl, v) {
  10485. gl.uniform1fv(this.addr, v);
  10486. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10487. function setValueV1iArray(gl, v) {
  10488. gl.uniform1iv(this.addr, v);
  10489. }
  10490. function setValueV2iArray(gl, v) {
  10491. gl.uniform2iv(this.addr, v);
  10492. }
  10493. function setValueV3iArray(gl, v) {
  10494. gl.uniform3iv(this.addr, v);
  10495. }
  10496. function setValueV4iArray(gl, v) {
  10497. gl.uniform4iv(this.addr, v);
  10498. } // Array of vectors (flat or from THREE classes)
  10499. function setValueV2fArray(gl, v) {
  10500. var data = flatten(v, this.size, 2);
  10501. gl.uniform2fv(this.addr, data);
  10502. }
  10503. function setValueV3fArray(gl, v) {
  10504. var data = flatten(v, this.size, 3);
  10505. gl.uniform3fv(this.addr, data);
  10506. }
  10507. function setValueV4fArray(gl, v) {
  10508. var data = flatten(v, this.size, 4);
  10509. gl.uniform4fv(this.addr, data);
  10510. } // Array of matrices (flat or from THREE clases)
  10511. function setValueM2Array(gl, v) {
  10512. var data = flatten(v, this.size, 4);
  10513. gl.uniformMatrix2fv(this.addr, false, data);
  10514. }
  10515. function setValueM3Array(gl, v) {
  10516. var data = flatten(v, this.size, 9);
  10517. gl.uniformMatrix3fv(this.addr, false, data);
  10518. }
  10519. function setValueM4Array(gl, v) {
  10520. var data = flatten(v, this.size, 16);
  10521. gl.uniformMatrix4fv(this.addr, false, data);
  10522. } // Array of textures (2D / Cube)
  10523. function setValueT1Array(gl, v, textures) {
  10524. var n = v.length;
  10525. var units = allocTexUnits(textures, n);
  10526. gl.uniform1iv(this.addr, units);
  10527. for (var i = 0; i !== n; ++i) {
  10528. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  10529. }
  10530. }
  10531. function setValueT6Array(gl, v, textures) {
  10532. var n = v.length;
  10533. var units = allocTexUnits(textures, n);
  10534. gl.uniform1iv(this.addr, units);
  10535. for (var i = 0; i !== n; ++i) {
  10536. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  10537. }
  10538. } // Helper to pick the right setter for a pure (bottom-level) array
  10539. function getPureArraySetter(type) {
  10540. switch (type) {
  10541. case 0x1406:
  10542. return setValueV1fArray;
  10543. // FLOAT
  10544. case 0x8b50:
  10545. return setValueV2fArray;
  10546. // _VEC2
  10547. case 0x8b51:
  10548. return setValueV3fArray;
  10549. // _VEC3
  10550. case 0x8b52:
  10551. return setValueV4fArray;
  10552. // _VEC4
  10553. case 0x8b5a:
  10554. return setValueM2Array;
  10555. // _MAT2
  10556. case 0x8b5b:
  10557. return setValueM3Array;
  10558. // _MAT3
  10559. case 0x8b5c:
  10560. return setValueM4Array;
  10561. // _MAT4
  10562. case 0x1404:
  10563. case 0x8b56:
  10564. return setValueV1iArray;
  10565. // INT, BOOL
  10566. case 0x8b53:
  10567. case 0x8b57:
  10568. return setValueV2iArray;
  10569. // _VEC2
  10570. case 0x8b54:
  10571. case 0x8b58:
  10572. return setValueV3iArray;
  10573. // _VEC3
  10574. case 0x8b55:
  10575. case 0x8b59:
  10576. return setValueV4iArray;
  10577. // _VEC4
  10578. case 0x8b5e: // SAMPLER_2D
  10579. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10580. case 0x8dca: // INT_SAMPLER_2D
  10581. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10582. case 0x8b62:
  10583. // SAMPLER_2D_SHADOW
  10584. return setValueT1Array;
  10585. case 0x8b60: // SAMPLER_CUBE
  10586. case 0x8dcc: // INT_SAMPLER_CUBE
  10587. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10588. case 0x8dc5:
  10589. // SAMPLER_CUBE_SHADOW
  10590. return setValueT6Array;
  10591. }
  10592. } // --- Uniform Classes ---
  10593. function SingleUniform(id, activeInfo, addr) {
  10594. this.id = id;
  10595. this.addr = addr;
  10596. this.cache = [];
  10597. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10598. }
  10599. function PureArrayUniform(id, activeInfo, addr) {
  10600. this.id = id;
  10601. this.addr = addr;
  10602. this.cache = [];
  10603. this.size = activeInfo.size;
  10604. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10605. }
  10606. PureArrayUniform.prototype.updateCache = function (data) {
  10607. var cache = this.cache;
  10608. if (data instanceof Float32Array && cache.length !== data.length) {
  10609. this.cache = new Float32Array(data.length);
  10610. }
  10611. copyArray(cache, data);
  10612. };
  10613. function StructuredUniform(id) {
  10614. this.id = id;
  10615. this.seq = [];
  10616. this.map = {};
  10617. }
  10618. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  10619. var seq = this.seq;
  10620. for (var i = 0, n = seq.length; i !== n; ++i) {
  10621. var u = seq[i];
  10622. u.setValue(gl, value[u.id], textures);
  10623. }
  10624. }; // --- Top-level ---
  10625. // Parser - builds up the property tree from the path strings
  10626. var RePathPart = /(\w+)(\])?(\[|\.)?/g; // extracts
  10627. // - the identifier (member name or array index)
  10628. // - followed by an optional right bracket (found when array index)
  10629. // - followed by an optional left bracket or dot (type of subscript)
  10630. //
  10631. // Note: These portions can be read in a non-overlapping fashion and
  10632. // allow straightforward parsing of the hierarchy that WebGL encodes
  10633. // in the uniform names.
  10634. function addUniform(container, uniformObject) {
  10635. container.seq.push(uniformObject);
  10636. container.map[uniformObject.id] = uniformObject;
  10637. }
  10638. function parseUniform(activeInfo, addr, container) {
  10639. var path = activeInfo.name,
  10640. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  10641. RePathPart.lastIndex = 0;
  10642. while (true) {
  10643. var match = RePathPart.exec(path),
  10644. matchEnd = RePathPart.lastIndex;
  10645. var id = match[1];
  10646. var idIsIndex = match[2] === ']',
  10647. subscript = match[3];
  10648. if (idIsIndex) id = id | 0; // convert to integer
  10649. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  10650. // bare name or "pure" bottom-level array "[0]" suffix
  10651. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  10652. break;
  10653. } else {
  10654. // step into inner node / create it in case it doesn't exist
  10655. var map = container.map;
  10656. var next = map[id];
  10657. if (next === undefined) {
  10658. next = new StructuredUniform(id);
  10659. addUniform(container, next);
  10660. }
  10661. container = next;
  10662. }
  10663. }
  10664. } // Root Container
  10665. function WebGLUniforms(gl, program) {
  10666. this.seq = [];
  10667. this.map = {};
  10668. var n = gl.getProgramParameter(program, 35718);
  10669. for (var i = 0; i < n; ++i) {
  10670. var info = gl.getActiveUniform(program, i),
  10671. addr = gl.getUniformLocation(program, info.name);
  10672. parseUniform(info, addr, this);
  10673. }
  10674. }
  10675. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  10676. var u = this.map[name];
  10677. if (u !== undefined) u.setValue(gl, value, textures);
  10678. };
  10679. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  10680. var v = object[name];
  10681. if (v !== undefined) this.setValue(gl, name, v);
  10682. }; // Static interface
  10683. WebGLUniforms.upload = function (gl, seq, values, textures) {
  10684. for (var i = 0, n = seq.length; i !== n; ++i) {
  10685. var u = seq[i],
  10686. v = values[u.id];
  10687. if (v.needsUpdate !== false) {
  10688. // note: always updating when .needsUpdate is undefined
  10689. u.setValue(gl, v.value, textures);
  10690. }
  10691. }
  10692. };
  10693. WebGLUniforms.seqWithValue = function (seq, values) {
  10694. var r = [];
  10695. for (var i = 0, n = seq.length; i !== n; ++i) {
  10696. var u = seq[i];
  10697. if (u.id in values) r.push(u);
  10698. }
  10699. return r;
  10700. };
  10701. function WebGLShader(gl, type, string) {
  10702. var shader = gl.createShader(type);
  10703. gl.shaderSource(shader, string);
  10704. gl.compileShader(shader);
  10705. return shader;
  10706. }
  10707. var programIdCount = 0;
  10708. function addLineNumbers(string) {
  10709. var lines = string.split('\n');
  10710. for (var i = 0; i < lines.length; i++) {
  10711. lines[i] = i + 1 + ': ' + lines[i];
  10712. }
  10713. return lines.join('\n');
  10714. }
  10715. function getEncodingComponents(encoding) {
  10716. switch (encoding) {
  10717. case LinearEncoding:
  10718. return ['Linear', '( value )'];
  10719. case sRGBEncoding:
  10720. return ['sRGB', '( value )'];
  10721. case RGBEEncoding:
  10722. return ['RGBE', '( value )'];
  10723. case RGBM7Encoding:
  10724. return ['RGBM', '( value, 7.0 )'];
  10725. case RGBM16Encoding:
  10726. return ['RGBM', '( value, 16.0 )'];
  10727. case RGBDEncoding:
  10728. return ['RGBD', '( value, 256.0 )'];
  10729. case GammaEncoding:
  10730. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  10731. case LogLuvEncoding:
  10732. return ['LogLuv', '( value )'];
  10733. default:
  10734. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  10735. return ['Linear', '( value )'];
  10736. }
  10737. }
  10738. function getShaderErrors(gl, shader, type) {
  10739. var status = gl.getShaderParameter(shader, 35713);
  10740. var log = gl.getShaderInfoLog(shader).trim();
  10741. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  10742. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10743. var source = gl.getShaderSource(shader);
  10744. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  10745. }
  10746. function getTexelDecodingFunction(functionName, encoding) {
  10747. var components = getEncodingComponents(encoding);
  10748. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  10749. }
  10750. function getTexelEncodingFunction(functionName, encoding) {
  10751. var components = getEncodingComponents(encoding);
  10752. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  10753. }
  10754. function getToneMappingFunction(functionName, toneMapping) {
  10755. var toneMappingName;
  10756. switch (toneMapping) {
  10757. case LinearToneMapping:
  10758. toneMappingName = 'Linear';
  10759. break;
  10760. case ReinhardToneMapping:
  10761. toneMappingName = 'Reinhard';
  10762. break;
  10763. case CineonToneMapping:
  10764. toneMappingName = 'OptimizedCineon';
  10765. break;
  10766. case ACESFilmicToneMapping:
  10767. toneMappingName = 'ACESFilmic';
  10768. break;
  10769. case CustomToneMapping:
  10770. toneMappingName = 'Custom';
  10771. break;
  10772. default:
  10773. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  10774. toneMappingName = 'Linear';
  10775. }
  10776. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10777. }
  10778. function generateExtensions(parameters) {
  10779. 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' : ''];
  10780. return chunks.filter(filterEmptyLine).join('\n');
  10781. }
  10782. function generateDefines(defines) {
  10783. var chunks = [];
  10784. for (var name in defines) {
  10785. var value = defines[name];
  10786. if (value === false) continue;
  10787. chunks.push('#define ' + name + ' ' + value);
  10788. }
  10789. return chunks.join('\n');
  10790. }
  10791. function fetchAttributeLocations(gl, program) {
  10792. var attributes = {};
  10793. var n = gl.getProgramParameter(program, 35721);
  10794. for (var i = 0; i < n; i++) {
  10795. var info = gl.getActiveAttrib(program, i);
  10796. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10797. attributes[name] = gl.getAttribLocation(program, name);
  10798. }
  10799. return attributes;
  10800. }
  10801. function filterEmptyLine(string) {
  10802. return string !== '';
  10803. }
  10804. function replaceLightNums(string, parameters) {
  10805. 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);
  10806. }
  10807. function replaceClippingPlaneNums(string, parameters) {
  10808. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  10809. } // Resolve Includes
  10810. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10811. function resolveIncludes(string) {
  10812. return string.replace(includePattern, includeReplacer);
  10813. }
  10814. function includeReplacer(match, include) {
  10815. var string = ShaderChunk[include];
  10816. if (string === undefined) {
  10817. throw new Error('Can not resolve #include <' + include + '>');
  10818. }
  10819. return resolveIncludes(string);
  10820. } // Unroll Loops
  10821. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10822. 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;
  10823. function unrollLoops(string) {
  10824. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  10825. }
  10826. function deprecatedLoopReplacer(match, start, end, snippet) {
  10827. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  10828. return loopReplacer(match, start, end, snippet);
  10829. }
  10830. function loopReplacer(match, start, end, snippet) {
  10831. var string = '';
  10832. for (var i = parseInt(start); i < parseInt(end); i++) {
  10833. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  10834. }
  10835. return string;
  10836. } //
  10837. function generatePrecision(parameters) {
  10838. var precisionstring = 'precision ' + parameters.precision + ' float;\nprecision ' + parameters.precision + ' int;';
  10839. if (parameters.precision === 'highp') {
  10840. precisionstring += '\n#define HIGH_PRECISION';
  10841. } else if (parameters.precision === 'mediump') {
  10842. precisionstring += '\n#define MEDIUM_PRECISION';
  10843. } else if (parameters.precision === 'lowp') {
  10844. precisionstring += '\n#define LOW_PRECISION';
  10845. }
  10846. return precisionstring;
  10847. }
  10848. function generateShadowMapTypeDefine(parameters) {
  10849. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10850. if (parameters.shadowMapType === PCFShadowMap) {
  10851. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10852. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  10853. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10854. } else if (parameters.shadowMapType === VSMShadowMap) {
  10855. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  10856. }
  10857. return shadowMapTypeDefine;
  10858. }
  10859. function generateEnvMapTypeDefine(parameters) {
  10860. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10861. if (parameters.envMap) {
  10862. switch (parameters.envMapMode) {
  10863. case CubeReflectionMapping:
  10864. case CubeRefractionMapping:
  10865. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10866. break;
  10867. case CubeUVReflectionMapping:
  10868. case CubeUVRefractionMapping:
  10869. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10870. break;
  10871. }
  10872. }
  10873. return envMapTypeDefine;
  10874. }
  10875. function generateEnvMapModeDefine(parameters) {
  10876. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10877. if (parameters.envMap) {
  10878. switch (parameters.envMapMode) {
  10879. case CubeRefractionMapping:
  10880. case CubeUVRefractionMapping:
  10881. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10882. break;
  10883. }
  10884. }
  10885. return envMapModeDefine;
  10886. }
  10887. function generateEnvMapBlendingDefine(parameters) {
  10888. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  10889. if (parameters.envMap) {
  10890. switch (parameters.combine) {
  10891. case MultiplyOperation:
  10892. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10893. break;
  10894. case MixOperation:
  10895. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10896. break;
  10897. case AddOperation:
  10898. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10899. break;
  10900. }
  10901. }
  10902. return envMapBlendingDefine;
  10903. }
  10904. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  10905. var gl = renderer.getContext();
  10906. var defines = parameters.defines;
  10907. var vertexShader = parameters.vertexShader;
  10908. var fragmentShader = parameters.fragmentShader;
  10909. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  10910. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  10911. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  10912. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  10913. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  10914. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  10915. var customDefines = generateDefines(defines);
  10916. var program = gl.createProgram();
  10917. var prefixVertex, prefixFragment;
  10918. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
  10919. if (parameters.isRawShaderMaterial) {
  10920. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  10921. if (prefixVertex.length > 0) {
  10922. prefixVertex += '\n';
  10923. }
  10924. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  10925. if (prefixFragment.length > 0) {
  10926. prefixFragment += '\n';
  10927. }
  10928. } else {
  10929. 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');
  10930. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  10931. '#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
  10932. 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
  10933. 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');
  10934. }
  10935. vertexShader = resolveIncludes(vertexShader);
  10936. vertexShader = replaceLightNums(vertexShader, parameters);
  10937. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  10938. fragmentShader = resolveIncludes(fragmentShader);
  10939. fragmentShader = replaceLightNums(fragmentShader, parameters);
  10940. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  10941. vertexShader = unrollLoops(vertexShader);
  10942. fragmentShader = unrollLoops(fragmentShader);
  10943. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  10944. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  10945. versionString = '#version 300 es\n';
  10946. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  10947. 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;
  10948. }
  10949. var vertexGlsl = versionString + prefixVertex + vertexShader;
  10950. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  10951. // console.log( '*FRAGMENT*', fragmentGlsl );
  10952. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  10953. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  10954. gl.attachShader(program, glVertexShader);
  10955. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  10956. if (parameters.index0AttributeName !== undefined) {
  10957. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  10958. } else if (parameters.morphTargets === true) {
  10959. // programs with morphTargets displace position out of attribute 0
  10960. gl.bindAttribLocation(program, 0, 'position');
  10961. }
  10962. gl.linkProgram(program); // check for link errors
  10963. if (renderer.debug.checkShaderErrors) {
  10964. var programLog = gl.getProgramInfoLog(program).trim();
  10965. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  10966. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  10967. var runnable = true;
  10968. var haveDiagnostics = true;
  10969. if (gl.getProgramParameter(program, 35714) === false) {
  10970. runnable = false;
  10971. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  10972. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  10973. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  10974. } else if (programLog !== '') {
  10975. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  10976. } else if (vertexLog === '' || fragmentLog === '') {
  10977. haveDiagnostics = false;
  10978. }
  10979. if (haveDiagnostics) {
  10980. this.diagnostics = {
  10981. runnable: runnable,
  10982. programLog: programLog,
  10983. vertexShader: {
  10984. log: vertexLog,
  10985. prefix: prefixVertex
  10986. },
  10987. fragmentShader: {
  10988. log: fragmentLog,
  10989. prefix: prefixFragment
  10990. }
  10991. };
  10992. }
  10993. } // Clean up
  10994. // Crashes in iOS9 and iOS10. #18402
  10995. // gl.detachShader( program, glVertexShader );
  10996. // gl.detachShader( program, glFragmentShader );
  10997. gl.deleteShader(glVertexShader);
  10998. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  10999. var cachedUniforms;
  11000. this.getUniforms = function () {
  11001. if (cachedUniforms === undefined) {
  11002. cachedUniforms = new WebGLUniforms(gl, program);
  11003. }
  11004. return cachedUniforms;
  11005. }; // set up caching for attribute locations
  11006. var cachedAttributes;
  11007. this.getAttributes = function () {
  11008. if (cachedAttributes === undefined) {
  11009. cachedAttributes = fetchAttributeLocations(gl, program);
  11010. }
  11011. return cachedAttributes;
  11012. }; // free resource
  11013. this.destroy = function () {
  11014. bindingStates.releaseStatesOfProgram(this);
  11015. gl.deleteProgram(program);
  11016. this.program = undefined;
  11017. }; //
  11018. this.name = parameters.shaderName;
  11019. this.id = programIdCount++;
  11020. this.cacheKey = cacheKey;
  11021. this.usedTimes = 1;
  11022. this.program = program;
  11023. this.vertexShader = glVertexShader;
  11024. this.fragmentShader = glFragmentShader;
  11025. return this;
  11026. }
  11027. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  11028. var programs = [];
  11029. var isWebGL2 = capabilities.isWebGL2;
  11030. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11031. var floatVertexTextures = capabilities.floatVertexTextures;
  11032. var maxVertexUniforms = capabilities.maxVertexUniforms;
  11033. var vertexTextures = capabilities.vertexTextures;
  11034. var precision = capabilities.precision;
  11035. var shaderIDs = {
  11036. MeshDepthMaterial: 'depth',
  11037. MeshDistanceMaterial: 'distanceRGBA',
  11038. MeshNormalMaterial: 'normal',
  11039. MeshBasicMaterial: 'basic',
  11040. MeshLambertMaterial: 'lambert',
  11041. MeshPhongMaterial: 'phong',
  11042. MeshToonMaterial: 'toon',
  11043. MeshStandardMaterial: 'physical',
  11044. MeshPhysicalMaterial: 'physical',
  11045. MeshMatcapMaterial: 'matcap',
  11046. LineBasicMaterial: 'basic',
  11047. LineDashedMaterial: 'dashed',
  11048. PointsMaterial: 'points',
  11049. ShadowMaterial: 'shadow',
  11050. SpriteMaterial: 'sprite'
  11051. };
  11052. 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'];
  11053. function getMaxBones(object) {
  11054. var skeleton = object.skeleton;
  11055. var bones = skeleton.bones;
  11056. if (floatVertexTextures) {
  11057. return 1024;
  11058. } else {
  11059. // default for when object is not specified
  11060. // ( for example when prebuilding shader to be used with multiple objects )
  11061. //
  11062. // - leave some extra space for other uniforms
  11063. // - limit here is ANGLE's 254 max uniform vectors
  11064. // (up to 54 should be safe)
  11065. var nVertexUniforms = maxVertexUniforms;
  11066. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  11067. var maxBones = Math.min(nVertexMatrices, bones.length);
  11068. if (maxBones < bones.length) {
  11069. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  11070. return 0;
  11071. }
  11072. return maxBones;
  11073. }
  11074. }
  11075. function getTextureEncodingFromMap(map) {
  11076. var encoding;
  11077. if (map && map.isTexture) {
  11078. encoding = map.encoding;
  11079. } else if (map && map.isWebGLRenderTarget) {
  11080. console.warn('THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.');
  11081. encoding = map.texture.encoding;
  11082. } else {
  11083. encoding = LinearEncoding;
  11084. }
  11085. return encoding;
  11086. }
  11087. function getParameters(material, lights, shadows, scene, object) {
  11088. var fog = scene.fog;
  11089. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  11090. var envMap = cubemaps.get(material.envMap || environment);
  11091. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  11092. // (not to blow over maxLights budget)
  11093. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  11094. if (material.precision !== null) {
  11095. precision = capabilities.getMaxPrecision(material.precision);
  11096. if (precision !== material.precision) {
  11097. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  11098. }
  11099. }
  11100. var vertexShader, fragmentShader;
  11101. if (shaderID) {
  11102. var shader = ShaderLib[shaderID];
  11103. vertexShader = shader.vertexShader;
  11104. fragmentShader = shader.fragmentShader;
  11105. } else {
  11106. vertexShader = material.vertexShader;
  11107. fragmentShader = material.fragmentShader;
  11108. }
  11109. var currentRenderTarget = renderer.getRenderTarget();
  11110. var parameters = {
  11111. isWebGL2: isWebGL2,
  11112. shaderID: shaderID,
  11113. shaderName: material.type,
  11114. vertexShader: vertexShader,
  11115. fragmentShader: fragmentShader,
  11116. defines: material.defines,
  11117. isRawShaderMaterial: material.isRawShaderMaterial === true,
  11118. glslVersion: material.glslVersion,
  11119. precision: precision,
  11120. instancing: object.isInstancedMesh === true,
  11121. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  11122. supportsVertexTextures: vertexTextures,
  11123. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  11124. map: !!material.map,
  11125. mapEncoding: getTextureEncodingFromMap(material.map),
  11126. matcap: !!material.matcap,
  11127. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  11128. envMap: !!envMap,
  11129. envMapMode: envMap && envMap.mapping,
  11130. envMapEncoding: getTextureEncodingFromMap(envMap),
  11131. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  11132. lightMap: !!material.lightMap,
  11133. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  11134. aoMap: !!material.aoMap,
  11135. emissiveMap: !!material.emissiveMap,
  11136. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  11137. bumpMap: !!material.bumpMap,
  11138. normalMap: !!material.normalMap,
  11139. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11140. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11141. clearcoatMap: !!material.clearcoatMap,
  11142. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  11143. clearcoatNormalMap: !!material.clearcoatNormalMap,
  11144. displacementMap: !!material.displacementMap,
  11145. roughnessMap: !!material.roughnessMap,
  11146. metalnessMap: !!material.metalnessMap,
  11147. specularMap: !!material.specularMap,
  11148. alphaMap: !!material.alphaMap,
  11149. gradientMap: !!material.gradientMap,
  11150. sheen: !!material.sheen,
  11151. transmissionMap: !!material.transmissionMap,
  11152. combine: material.combine,
  11153. vertexTangents: material.normalMap && material.vertexTangents,
  11154. vertexColors: material.vertexColors,
  11155. 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,
  11156. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  11157. fog: !!fog,
  11158. useFog: material.fog,
  11159. fogExp2: fog && fog.isFogExp2,
  11160. flatShading: material.flatShading,
  11161. sizeAttenuation: material.sizeAttenuation,
  11162. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11163. skinning: material.skinning && maxBones > 0,
  11164. maxBones: maxBones,
  11165. useVertexTexture: floatVertexTextures,
  11166. morphTargets: material.morphTargets,
  11167. morphNormals: material.morphNormals,
  11168. maxMorphTargets: renderer.maxMorphTargets,
  11169. maxMorphNormals: renderer.maxMorphNormals,
  11170. numDirLights: lights.directional.length,
  11171. numPointLights: lights.point.length,
  11172. numSpotLights: lights.spot.length,
  11173. numRectAreaLights: lights.rectArea.length,
  11174. numHemiLights: lights.hemi.length,
  11175. numDirLightShadows: lights.directionalShadowMap.length,
  11176. numPointLightShadows: lights.pointShadowMap.length,
  11177. numSpotLightShadows: lights.spotShadowMap.length,
  11178. numClippingPlanes: clipping.numPlanes,
  11179. numClipIntersection: clipping.numIntersection,
  11180. dithering: material.dithering,
  11181. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11182. shadowMapType: renderer.shadowMap.type,
  11183. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11184. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11185. premultipliedAlpha: material.premultipliedAlpha,
  11186. alphaTest: material.alphaTest,
  11187. doubleSided: material.side === DoubleSide,
  11188. flipSided: material.side === BackSide,
  11189. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11190. index0AttributeName: material.index0AttributeName,
  11191. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11192. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11193. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11194. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11195. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11196. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11197. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11198. customProgramCacheKey: material.customProgramCacheKey()
  11199. };
  11200. return parameters;
  11201. }
  11202. function getProgramCacheKey(parameters) {
  11203. var array = [];
  11204. if (parameters.shaderID) {
  11205. array.push(parameters.shaderID);
  11206. } else {
  11207. array.push(parameters.fragmentShader);
  11208. array.push(parameters.vertexShader);
  11209. }
  11210. if (parameters.defines !== undefined) {
  11211. for (var name in parameters.defines) {
  11212. array.push(name);
  11213. array.push(parameters.defines[name]);
  11214. }
  11215. }
  11216. if (parameters.isRawShaderMaterial === false) {
  11217. for (var i = 0; i < parameterNames.length; i++) {
  11218. array.push(parameters[parameterNames[i]]);
  11219. }
  11220. array.push(renderer.outputEncoding);
  11221. array.push(renderer.gammaFactor);
  11222. }
  11223. array.push(parameters.customProgramCacheKey);
  11224. return array.join();
  11225. }
  11226. function getUniforms(material) {
  11227. var shaderID = shaderIDs[material.type];
  11228. var uniforms;
  11229. if (shaderID) {
  11230. var shader = ShaderLib[shaderID];
  11231. uniforms = UniformsUtils.clone(shader.uniforms);
  11232. } else {
  11233. uniforms = material.uniforms;
  11234. }
  11235. return uniforms;
  11236. }
  11237. function acquireProgram(parameters, cacheKey) {
  11238. var program; // Check if code has been already compiled
  11239. for (var p = 0, pl = programs.length; p < pl; p++) {
  11240. var preexistingProgram = programs[p];
  11241. if (preexistingProgram.cacheKey === cacheKey) {
  11242. program = preexistingProgram;
  11243. ++program.usedTimes;
  11244. break;
  11245. }
  11246. }
  11247. if (program === undefined) {
  11248. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11249. programs.push(program);
  11250. }
  11251. return program;
  11252. }
  11253. function releaseProgram(program) {
  11254. if (--program.usedTimes === 0) {
  11255. // Remove from unordered set
  11256. var i = programs.indexOf(program);
  11257. programs[i] = programs[programs.length - 1];
  11258. programs.pop(); // Free WebGL resources
  11259. program.destroy();
  11260. }
  11261. }
  11262. return {
  11263. getParameters: getParameters,
  11264. getProgramCacheKey: getProgramCacheKey,
  11265. getUniforms: getUniforms,
  11266. acquireProgram: acquireProgram,
  11267. releaseProgram: releaseProgram,
  11268. // Exposed for resource monitoring & error feedback via renderer.info:
  11269. programs: programs
  11270. };
  11271. }
  11272. function WebGLProperties() {
  11273. var properties = new WeakMap();
  11274. function get(object) {
  11275. var map = properties.get(object);
  11276. if (map === undefined) {
  11277. map = {};
  11278. properties.set(object, map);
  11279. }
  11280. return map;
  11281. }
  11282. function remove(object) {
  11283. properties.delete(object);
  11284. }
  11285. function update(object, key, value) {
  11286. properties.get(object)[key] = value;
  11287. }
  11288. function dispose() {
  11289. properties = new WeakMap();
  11290. }
  11291. return {
  11292. get: get,
  11293. remove: remove,
  11294. update: update,
  11295. dispose: dispose
  11296. };
  11297. }
  11298. function painterSortStable(a, b) {
  11299. if (a.groupOrder !== b.groupOrder) {
  11300. return a.groupOrder - b.groupOrder;
  11301. } else if (a.renderOrder !== b.renderOrder) {
  11302. return a.renderOrder - b.renderOrder;
  11303. } else if (a.program !== b.program) {
  11304. return a.program.id - b.program.id;
  11305. } else if (a.material.id !== b.material.id) {
  11306. return a.material.id - b.material.id;
  11307. } else if (a.z !== b.z) {
  11308. return a.z - b.z;
  11309. } else {
  11310. return a.id - b.id;
  11311. }
  11312. }
  11313. function reversePainterSortStable(a, b) {
  11314. if (a.groupOrder !== b.groupOrder) {
  11315. return a.groupOrder - b.groupOrder;
  11316. } else if (a.renderOrder !== b.renderOrder) {
  11317. return a.renderOrder - b.renderOrder;
  11318. } else if (a.z !== b.z) {
  11319. return b.z - a.z;
  11320. } else {
  11321. return a.id - b.id;
  11322. }
  11323. }
  11324. function WebGLRenderList(properties) {
  11325. var renderItems = [];
  11326. var renderItemsIndex = 0;
  11327. var opaque = [];
  11328. var transparent = [];
  11329. var defaultProgram = {
  11330. id: -1
  11331. };
  11332. function init() {
  11333. renderItemsIndex = 0;
  11334. opaque.length = 0;
  11335. transparent.length = 0;
  11336. }
  11337. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11338. var renderItem = renderItems[renderItemsIndex];
  11339. var materialProperties = properties.get(material);
  11340. if (renderItem === undefined) {
  11341. renderItem = {
  11342. id: object.id,
  11343. object: object,
  11344. geometry: geometry,
  11345. material: material,
  11346. program: materialProperties.program || defaultProgram,
  11347. groupOrder: groupOrder,
  11348. renderOrder: object.renderOrder,
  11349. z: z,
  11350. group: group
  11351. };
  11352. renderItems[renderItemsIndex] = renderItem;
  11353. } else {
  11354. renderItem.id = object.id;
  11355. renderItem.object = object;
  11356. renderItem.geometry = geometry;
  11357. renderItem.material = material;
  11358. renderItem.program = materialProperties.program || defaultProgram;
  11359. renderItem.groupOrder = groupOrder;
  11360. renderItem.renderOrder = object.renderOrder;
  11361. renderItem.z = z;
  11362. renderItem.group = group;
  11363. }
  11364. renderItemsIndex++;
  11365. return renderItem;
  11366. }
  11367. function push(object, geometry, material, groupOrder, z, group) {
  11368. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11369. (material.transparent === true ? transparent : opaque).push(renderItem);
  11370. }
  11371. function unshift(object, geometry, material, groupOrder, z, group) {
  11372. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11373. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11374. }
  11375. function sort(customOpaqueSort, customTransparentSort) {
  11376. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11377. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11378. }
  11379. function finish() {
  11380. // Clear references from inactive renderItems in the list
  11381. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11382. var renderItem = renderItems[i];
  11383. if (renderItem.id === null) break;
  11384. renderItem.id = null;
  11385. renderItem.object = null;
  11386. renderItem.geometry = null;
  11387. renderItem.material = null;
  11388. renderItem.program = null;
  11389. renderItem.group = null;
  11390. }
  11391. }
  11392. return {
  11393. opaque: opaque,
  11394. transparent: transparent,
  11395. init: init,
  11396. push: push,
  11397. unshift: unshift,
  11398. finish: finish,
  11399. sort: sort
  11400. };
  11401. }
  11402. function WebGLRenderLists(properties) {
  11403. var lists = new WeakMap();
  11404. function get(scene, camera) {
  11405. var cameras = lists.get(scene);
  11406. var list;
  11407. if (cameras === undefined) {
  11408. list = new WebGLRenderList(properties);
  11409. lists.set(scene, new WeakMap());
  11410. lists.get(scene).set(camera, list);
  11411. } else {
  11412. list = cameras.get(camera);
  11413. if (list === undefined) {
  11414. list = new WebGLRenderList(properties);
  11415. cameras.set(camera, list);
  11416. }
  11417. }
  11418. return list;
  11419. }
  11420. function dispose() {
  11421. lists = new WeakMap();
  11422. }
  11423. return {
  11424. get: get,
  11425. dispose: dispose
  11426. };
  11427. }
  11428. function UniformsCache() {
  11429. var lights = {};
  11430. return {
  11431. get: function get(light) {
  11432. if (lights[light.id] !== undefined) {
  11433. return lights[light.id];
  11434. }
  11435. var uniforms;
  11436. switch (light.type) {
  11437. case 'DirectionalLight':
  11438. uniforms = {
  11439. direction: new Vector3(),
  11440. color: new Color()
  11441. };
  11442. break;
  11443. case 'SpotLight':
  11444. uniforms = {
  11445. position: new Vector3(),
  11446. direction: new Vector3(),
  11447. color: new Color(),
  11448. distance: 0,
  11449. coneCos: 0,
  11450. penumbraCos: 0,
  11451. decay: 0
  11452. };
  11453. break;
  11454. case 'PointLight':
  11455. uniforms = {
  11456. position: new Vector3(),
  11457. color: new Color(),
  11458. distance: 0,
  11459. decay: 0
  11460. };
  11461. break;
  11462. case 'HemisphereLight':
  11463. uniforms = {
  11464. direction: new Vector3(),
  11465. skyColor: new Color(),
  11466. groundColor: new Color()
  11467. };
  11468. break;
  11469. case 'RectAreaLight':
  11470. uniforms = {
  11471. color: new Color(),
  11472. position: new Vector3(),
  11473. halfWidth: new Vector3(),
  11474. halfHeight: new Vector3()
  11475. };
  11476. break;
  11477. }
  11478. lights[light.id] = uniforms;
  11479. return uniforms;
  11480. }
  11481. };
  11482. }
  11483. function ShadowUniformsCache() {
  11484. var lights = {};
  11485. return {
  11486. get: function get(light) {
  11487. if (lights[light.id] !== undefined) {
  11488. return lights[light.id];
  11489. }
  11490. var uniforms;
  11491. switch (light.type) {
  11492. case 'DirectionalLight':
  11493. uniforms = {
  11494. shadowBias: 0,
  11495. shadowNormalBias: 0,
  11496. shadowRadius: 1,
  11497. shadowMapSize: new Vector2()
  11498. };
  11499. break;
  11500. case 'SpotLight':
  11501. uniforms = {
  11502. shadowBias: 0,
  11503. shadowNormalBias: 0,
  11504. shadowRadius: 1,
  11505. shadowMapSize: new Vector2()
  11506. };
  11507. break;
  11508. case 'PointLight':
  11509. uniforms = {
  11510. shadowBias: 0,
  11511. shadowNormalBias: 0,
  11512. shadowRadius: 1,
  11513. shadowMapSize: new Vector2(),
  11514. shadowCameraNear: 1,
  11515. shadowCameraFar: 1000
  11516. };
  11517. break;
  11518. // TODO (abelnation): set RectAreaLight shadow uniforms
  11519. }
  11520. lights[light.id] = uniforms;
  11521. return uniforms;
  11522. }
  11523. };
  11524. }
  11525. var nextVersion = 0;
  11526. function shadowCastingLightsFirst(lightA, lightB) {
  11527. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  11528. }
  11529. function WebGLLights(extensions, capabilities) {
  11530. var cache = new UniformsCache();
  11531. var shadowCache = ShadowUniformsCache();
  11532. var state = {
  11533. version: 0,
  11534. hash: {
  11535. directionalLength: -1,
  11536. pointLength: -1,
  11537. spotLength: -1,
  11538. rectAreaLength: -1,
  11539. hemiLength: -1,
  11540. numDirectionalShadows: -1,
  11541. numPointShadows: -1,
  11542. numSpotShadows: -1
  11543. },
  11544. ambient: [0, 0, 0],
  11545. probe: [],
  11546. directional: [],
  11547. directionalShadow: [],
  11548. directionalShadowMap: [],
  11549. directionalShadowMatrix: [],
  11550. spot: [],
  11551. spotShadow: [],
  11552. spotShadowMap: [],
  11553. spotShadowMatrix: [],
  11554. rectArea: [],
  11555. rectAreaLTC1: null,
  11556. rectAreaLTC2: null,
  11557. point: [],
  11558. pointShadow: [],
  11559. pointShadowMap: [],
  11560. pointShadowMatrix: [],
  11561. hemi: []
  11562. };
  11563. for (var i = 0; i < 9; i++) {
  11564. state.probe.push(new Vector3());
  11565. }
  11566. var vector3 = new Vector3();
  11567. var matrix4 = new Matrix4();
  11568. var matrix42 = new Matrix4();
  11569. function setup(lights) {
  11570. var r = 0,
  11571. g = 0,
  11572. b = 0;
  11573. for (var _i = 0; _i < 9; _i++) {
  11574. state.probe[_i].set(0, 0, 0);
  11575. }
  11576. var directionalLength = 0;
  11577. var pointLength = 0;
  11578. var spotLength = 0;
  11579. var rectAreaLength = 0;
  11580. var hemiLength = 0;
  11581. var numDirectionalShadows = 0;
  11582. var numPointShadows = 0;
  11583. var numSpotShadows = 0;
  11584. lights.sort(shadowCastingLightsFirst);
  11585. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  11586. var light = lights[_i2];
  11587. var color = light.color;
  11588. var intensity = light.intensity;
  11589. var distance = light.distance;
  11590. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  11591. if (light.isAmbientLight) {
  11592. r += color.r * intensity;
  11593. g += color.g * intensity;
  11594. b += color.b * intensity;
  11595. } else if (light.isLightProbe) {
  11596. for (var j = 0; j < 9; j++) {
  11597. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  11598. }
  11599. } else if (light.isDirectionalLight) {
  11600. var uniforms = cache.get(light);
  11601. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  11602. if (light.castShadow) {
  11603. var shadow = light.shadow;
  11604. var shadowUniforms = shadowCache.get(light);
  11605. shadowUniforms.shadowBias = shadow.bias;
  11606. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11607. shadowUniforms.shadowRadius = shadow.radius;
  11608. shadowUniforms.shadowMapSize = shadow.mapSize;
  11609. state.directionalShadow[directionalLength] = shadowUniforms;
  11610. state.directionalShadowMap[directionalLength] = shadowMap;
  11611. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  11612. numDirectionalShadows++;
  11613. }
  11614. state.directional[directionalLength] = uniforms;
  11615. directionalLength++;
  11616. } else if (light.isSpotLight) {
  11617. var _uniforms = cache.get(light);
  11618. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  11619. _uniforms.color.copy(color).multiplyScalar(intensity);
  11620. _uniforms.distance = distance;
  11621. _uniforms.coneCos = Math.cos(light.angle);
  11622. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  11623. _uniforms.decay = light.decay;
  11624. if (light.castShadow) {
  11625. var _shadow = light.shadow;
  11626. var _shadowUniforms = shadowCache.get(light);
  11627. _shadowUniforms.shadowBias = _shadow.bias;
  11628. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  11629. _shadowUniforms.shadowRadius = _shadow.radius;
  11630. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  11631. state.spotShadow[spotLength] = _shadowUniforms;
  11632. state.spotShadowMap[spotLength] = shadowMap;
  11633. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  11634. numSpotShadows++;
  11635. }
  11636. state.spot[spotLength] = _uniforms;
  11637. spotLength++;
  11638. } else if (light.isRectAreaLight) {
  11639. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  11640. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11641. // (b) intensity is the brightness of the light
  11642. _uniforms2.color.copy(color).multiplyScalar(intensity);
  11643. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  11644. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  11645. state.rectArea[rectAreaLength] = _uniforms2;
  11646. rectAreaLength++;
  11647. } else if (light.isPointLight) {
  11648. var _uniforms3 = cache.get(light);
  11649. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  11650. _uniforms3.distance = light.distance;
  11651. _uniforms3.decay = light.decay;
  11652. if (light.castShadow) {
  11653. var _shadow2 = light.shadow;
  11654. var _shadowUniforms2 = shadowCache.get(light);
  11655. _shadowUniforms2.shadowBias = _shadow2.bias;
  11656. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  11657. _shadowUniforms2.shadowRadius = _shadow2.radius;
  11658. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  11659. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  11660. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  11661. state.pointShadow[pointLength] = _shadowUniforms2;
  11662. state.pointShadowMap[pointLength] = shadowMap;
  11663. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  11664. numPointShadows++;
  11665. }
  11666. state.point[pointLength] = _uniforms3;
  11667. pointLength++;
  11668. } else if (light.isHemisphereLight) {
  11669. var _uniforms4 = cache.get(light);
  11670. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  11671. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  11672. state.hemi[hemiLength] = _uniforms4;
  11673. hemiLength++;
  11674. }
  11675. }
  11676. if (rectAreaLength > 0) {
  11677. if (capabilities.isWebGL2) {
  11678. // WebGL 2
  11679. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11680. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11681. } else {
  11682. // WebGL 1
  11683. if (extensions.has('OES_texture_float_linear') === true) {
  11684. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11685. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11686. } else if (extensions.has('OES_texture_half_float_linear') === true) {
  11687. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  11688. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  11689. } else {
  11690. console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
  11691. }
  11692. }
  11693. }
  11694. state.ambient[0] = r;
  11695. state.ambient[1] = g;
  11696. state.ambient[2] = b;
  11697. var hash = state.hash;
  11698. 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) {
  11699. state.directional.length = directionalLength;
  11700. state.spot.length = spotLength;
  11701. state.rectArea.length = rectAreaLength;
  11702. state.point.length = pointLength;
  11703. state.hemi.length = hemiLength;
  11704. state.directionalShadow.length = numDirectionalShadows;
  11705. state.directionalShadowMap.length = numDirectionalShadows;
  11706. state.pointShadow.length = numPointShadows;
  11707. state.pointShadowMap.length = numPointShadows;
  11708. state.spotShadow.length = numSpotShadows;
  11709. state.spotShadowMap.length = numSpotShadows;
  11710. state.directionalShadowMatrix.length = numDirectionalShadows;
  11711. state.pointShadowMatrix.length = numPointShadows;
  11712. state.spotShadowMatrix.length = numSpotShadows;
  11713. hash.directionalLength = directionalLength;
  11714. hash.pointLength = pointLength;
  11715. hash.spotLength = spotLength;
  11716. hash.rectAreaLength = rectAreaLength;
  11717. hash.hemiLength = hemiLength;
  11718. hash.numDirectionalShadows = numDirectionalShadows;
  11719. hash.numPointShadows = numPointShadows;
  11720. hash.numSpotShadows = numSpotShadows;
  11721. state.version = nextVersion++;
  11722. }
  11723. }
  11724. function setupView(lights, camera) {
  11725. var directionalLength = 0;
  11726. var pointLength = 0;
  11727. var spotLength = 0;
  11728. var rectAreaLength = 0;
  11729. var hemiLength = 0;
  11730. var viewMatrix = camera.matrixWorldInverse;
  11731. for (var _i3 = 0, l = lights.length; _i3 < l; _i3++) {
  11732. var light = lights[_i3];
  11733. if (light.isDirectionalLight) {
  11734. var uniforms = state.directional[directionalLength];
  11735. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11736. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11737. uniforms.direction.sub(vector3);
  11738. uniforms.direction.transformDirection(viewMatrix);
  11739. directionalLength++;
  11740. } else if (light.isSpotLight) {
  11741. var _uniforms5 = state.spot[spotLength];
  11742. _uniforms5.position.setFromMatrixPosition(light.matrixWorld);
  11743. _uniforms5.position.applyMatrix4(viewMatrix);
  11744. _uniforms5.direction.setFromMatrixPosition(light.matrixWorld);
  11745. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11746. _uniforms5.direction.sub(vector3);
  11747. _uniforms5.direction.transformDirection(viewMatrix);
  11748. spotLength++;
  11749. } else if (light.isRectAreaLight) {
  11750. var _uniforms6 = state.rectArea[rectAreaLength];
  11751. _uniforms6.position.setFromMatrixPosition(light.matrixWorld);
  11752. _uniforms6.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  11753. matrix42.identity();
  11754. matrix4.copy(light.matrixWorld);
  11755. matrix4.premultiply(viewMatrix);
  11756. matrix42.extractRotation(matrix4);
  11757. _uniforms6.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  11758. _uniforms6.halfHeight.set(0.0, light.height * 0.5, 0.0);
  11759. _uniforms6.halfWidth.applyMatrix4(matrix42);
  11760. _uniforms6.halfHeight.applyMatrix4(matrix42);
  11761. rectAreaLength++;
  11762. } else if (light.isPointLight) {
  11763. var _uniforms7 = state.point[pointLength];
  11764. _uniforms7.position.setFromMatrixPosition(light.matrixWorld);
  11765. _uniforms7.position.applyMatrix4(viewMatrix);
  11766. pointLength++;
  11767. } else if (light.isHemisphereLight) {
  11768. var _uniforms8 = state.hemi[hemiLength];
  11769. _uniforms8.direction.setFromMatrixPosition(light.matrixWorld);
  11770. _uniforms8.direction.transformDirection(viewMatrix);
  11771. _uniforms8.direction.normalize();
  11772. hemiLength++;
  11773. }
  11774. }
  11775. }
  11776. return {
  11777. setup: setup,
  11778. setupView: setupView,
  11779. state: state
  11780. };
  11781. }
  11782. function WebGLRenderState(extensions, capabilities) {
  11783. var lights = new WebGLLights(extensions, capabilities);
  11784. var lightsArray = [];
  11785. var shadowsArray = [];
  11786. function init() {
  11787. lightsArray.length = 0;
  11788. shadowsArray.length = 0;
  11789. }
  11790. function pushLight(light) {
  11791. lightsArray.push(light);
  11792. }
  11793. function pushShadow(shadowLight) {
  11794. shadowsArray.push(shadowLight);
  11795. }
  11796. function setupLights() {
  11797. lights.setup(lightsArray);
  11798. }
  11799. function setupLightsView(camera) {
  11800. lights.setupView(lightsArray, camera);
  11801. }
  11802. var state = {
  11803. lightsArray: lightsArray,
  11804. shadowsArray: shadowsArray,
  11805. lights: lights
  11806. };
  11807. return {
  11808. init: init,
  11809. state: state,
  11810. setupLights: setupLights,
  11811. setupLightsView: setupLightsView,
  11812. pushLight: pushLight,
  11813. pushShadow: pushShadow
  11814. };
  11815. }
  11816. function WebGLRenderStates(extensions, capabilities) {
  11817. var renderStates = new WeakMap();
  11818. function get(scene, renderCallDepth) {
  11819. if (renderCallDepth === void 0) {
  11820. renderCallDepth = 0;
  11821. }
  11822. var renderState;
  11823. if (renderStates.has(scene) === false) {
  11824. renderState = new WebGLRenderState(extensions, capabilities);
  11825. renderStates.set(scene, []);
  11826. renderStates.get(scene).push(renderState);
  11827. } else {
  11828. if (renderCallDepth >= renderStates.get(scene).length) {
  11829. renderState = new WebGLRenderState(extensions, capabilities);
  11830. renderStates.get(scene).push(renderState);
  11831. } else {
  11832. renderState = renderStates.get(scene)[renderCallDepth];
  11833. }
  11834. }
  11835. return renderState;
  11836. }
  11837. function dispose() {
  11838. renderStates = new WeakMap();
  11839. }
  11840. return {
  11841. get: get,
  11842. dispose: dispose
  11843. };
  11844. }
  11845. /**
  11846. * parameters = {
  11847. *
  11848. * opacity: <float>,
  11849. *
  11850. * map: new THREE.Texture( <Image> ),
  11851. *
  11852. * alphaMap: new THREE.Texture( <Image> ),
  11853. *
  11854. * displacementMap: new THREE.Texture( <Image> ),
  11855. * displacementScale: <float>,
  11856. * displacementBias: <float>,
  11857. *
  11858. * wireframe: <boolean>,
  11859. * wireframeLinewidth: <float>
  11860. * }
  11861. */
  11862. function MeshDepthMaterial(parameters) {
  11863. Material.call(this);
  11864. this.type = 'MeshDepthMaterial';
  11865. this.depthPacking = BasicDepthPacking;
  11866. this.skinning = false;
  11867. this.morphTargets = false;
  11868. this.map = null;
  11869. this.alphaMap = null;
  11870. this.displacementMap = null;
  11871. this.displacementScale = 1;
  11872. this.displacementBias = 0;
  11873. this.wireframe = false;
  11874. this.wireframeLinewidth = 1;
  11875. this.fog = false;
  11876. this.setValues(parameters);
  11877. }
  11878. MeshDepthMaterial.prototype = Object.create(Material.prototype);
  11879. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11880. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11881. MeshDepthMaterial.prototype.copy = function (source) {
  11882. Material.prototype.copy.call(this, source);
  11883. this.depthPacking = source.depthPacking;
  11884. this.skinning = source.skinning;
  11885. this.morphTargets = source.morphTargets;
  11886. this.map = source.map;
  11887. this.alphaMap = source.alphaMap;
  11888. this.displacementMap = source.displacementMap;
  11889. this.displacementScale = source.displacementScale;
  11890. this.displacementBias = source.displacementBias;
  11891. this.wireframe = source.wireframe;
  11892. this.wireframeLinewidth = source.wireframeLinewidth;
  11893. return this;
  11894. };
  11895. /**
  11896. * parameters = {
  11897. *
  11898. * referencePosition: <float>,
  11899. * nearDistance: <float>,
  11900. * farDistance: <float>,
  11901. *
  11902. * skinning: <bool>,
  11903. * morphTargets: <bool>,
  11904. *
  11905. * map: new THREE.Texture( <Image> ),
  11906. *
  11907. * alphaMap: new THREE.Texture( <Image> ),
  11908. *
  11909. * displacementMap: new THREE.Texture( <Image> ),
  11910. * displacementScale: <float>,
  11911. * displacementBias: <float>
  11912. *
  11913. * }
  11914. */
  11915. function MeshDistanceMaterial(parameters) {
  11916. Material.call(this);
  11917. this.type = 'MeshDistanceMaterial';
  11918. this.referencePosition = new Vector3();
  11919. this.nearDistance = 1;
  11920. this.farDistance = 1000;
  11921. this.skinning = false;
  11922. this.morphTargets = false;
  11923. this.map = null;
  11924. this.alphaMap = null;
  11925. this.displacementMap = null;
  11926. this.displacementScale = 1;
  11927. this.displacementBias = 0;
  11928. this.fog = false;
  11929. this.setValues(parameters);
  11930. }
  11931. MeshDistanceMaterial.prototype = Object.create(Material.prototype);
  11932. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11933. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11934. MeshDistanceMaterial.prototype.copy = function (source) {
  11935. Material.prototype.copy.call(this, source);
  11936. this.referencePosition.copy(source.referencePosition);
  11937. this.nearDistance = source.nearDistance;
  11938. this.farDistance = source.farDistance;
  11939. this.skinning = source.skinning;
  11940. this.morphTargets = source.morphTargets;
  11941. this.map = source.map;
  11942. this.alphaMap = source.alphaMap;
  11943. this.displacementMap = source.displacementMap;
  11944. this.displacementScale = source.displacementScale;
  11945. this.displacementBias = source.displacementBias;
  11946. return this;
  11947. };
  11948. var vsm_frag = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n\tfor ( float i = -1.0; i < 1.0 ; i += SAMPLE_RATE) {\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, i ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean * HALF_SAMPLE_RATE;\n\tsquared_mean = squared_mean * HALF_SAMPLE_RATE;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";
  11949. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  11950. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  11951. var _frustum = new Frustum();
  11952. var _shadowMapSize = new Vector2(),
  11953. _viewportSize = new Vector2(),
  11954. _viewport = new Vector4(),
  11955. _depthMaterials = [],
  11956. _distanceMaterials = [],
  11957. _materialCache = {};
  11958. var shadowSide = {
  11959. 0: BackSide,
  11960. 1: FrontSide,
  11961. 2: DoubleSide
  11962. };
  11963. var shadowMaterialVertical = new ShaderMaterial({
  11964. defines: {
  11965. SAMPLE_RATE: 2.0 / 8.0,
  11966. HALF_SAMPLE_RATE: 1.0 / 8.0
  11967. },
  11968. uniforms: {
  11969. shadow_pass: {
  11970. value: null
  11971. },
  11972. resolution: {
  11973. value: new Vector2()
  11974. },
  11975. radius: {
  11976. value: 4.0
  11977. }
  11978. },
  11979. vertexShader: vsm_vert,
  11980. fragmentShader: vsm_frag
  11981. });
  11982. var shadowMaterialHorizontal = shadowMaterialVertical.clone();
  11983. shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
  11984. var fullScreenTri = new BufferGeometry();
  11985. fullScreenTri.setAttribute('position', new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  11986. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  11987. var scope = this;
  11988. this.enabled = false;
  11989. this.autoUpdate = true;
  11990. this.needsUpdate = false;
  11991. this.type = PCFShadowMap;
  11992. this.render = function (lights, scene, camera) {
  11993. if (scope.enabled === false) return;
  11994. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  11995. if (lights.length === 0) return;
  11996. var currentRenderTarget = _renderer.getRenderTarget();
  11997. var activeCubeFace = _renderer.getActiveCubeFace();
  11998. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  11999. var _state = _renderer.state; // Set GL state for depth map.
  12000. _state.setBlending(NoBlending);
  12001. _state.buffers.color.setClear(1, 1, 1, 1);
  12002. _state.buffers.depth.setTest(true);
  12003. _state.setScissorTest(false); // render depth map
  12004. for (var i = 0, il = lights.length; i < il; i++) {
  12005. var light = lights[i];
  12006. var shadow = light.shadow;
  12007. if (shadow === undefined) {
  12008. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  12009. continue;
  12010. }
  12011. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  12012. _shadowMapSize.copy(shadow.mapSize);
  12013. var shadowFrameExtents = shadow.getFrameExtents();
  12014. _shadowMapSize.multiply(shadowFrameExtents);
  12015. _viewportSize.copy(shadow.mapSize);
  12016. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  12017. if (_shadowMapSize.x > maxTextureSize) {
  12018. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  12019. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  12020. shadow.mapSize.x = _viewportSize.x;
  12021. }
  12022. if (_shadowMapSize.y > maxTextureSize) {
  12023. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  12024. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  12025. shadow.mapSize.y = _viewportSize.y;
  12026. }
  12027. }
  12028. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12029. var pars = {
  12030. minFilter: LinearFilter,
  12031. magFilter: LinearFilter,
  12032. format: RGBAFormat
  12033. };
  12034. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12035. shadow.map.texture.name = light.name + '.shadowMap';
  12036. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12037. shadow.camera.updateProjectionMatrix();
  12038. }
  12039. if (shadow.map === null) {
  12040. var _pars = {
  12041. minFilter: NearestFilter,
  12042. magFilter: NearestFilter,
  12043. format: RGBAFormat
  12044. };
  12045. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  12046. shadow.map.texture.name = light.name + '.shadowMap';
  12047. shadow.camera.updateProjectionMatrix();
  12048. }
  12049. _renderer.setRenderTarget(shadow.map);
  12050. _renderer.clear();
  12051. var viewportCount = shadow.getViewportCount();
  12052. for (var vp = 0; vp < viewportCount; vp++) {
  12053. var viewport = shadow.getViewport(vp);
  12054. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  12055. _state.viewport(_viewport);
  12056. shadow.updateMatrices(light, vp);
  12057. _frustum = shadow.getFrustum();
  12058. renderObject(scene, camera, shadow.camera, light, this.type);
  12059. } // do blur pass for VSM
  12060. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12061. VSMPass(shadow, camera);
  12062. }
  12063. shadow.needsUpdate = false;
  12064. }
  12065. scope.needsUpdate = false;
  12066. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  12067. };
  12068. function VSMPass(shadow, camera) {
  12069. var geometry = _objects.update(fullScreenMesh); // vertical pass
  12070. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12071. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12072. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12073. _renderer.setRenderTarget(shadow.mapPass);
  12074. _renderer.clear();
  12075. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizontal pass
  12076. shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12077. shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
  12078. shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
  12079. _renderer.setRenderTarget(shadow.map);
  12080. _renderer.clear();
  12081. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null);
  12082. }
  12083. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12084. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12085. var material = _depthMaterials[index];
  12086. if (material === undefined) {
  12087. material = new MeshDepthMaterial({
  12088. depthPacking: RGBADepthPacking,
  12089. morphTargets: useMorphing,
  12090. skinning: useSkinning
  12091. });
  12092. _depthMaterials[index] = material;
  12093. }
  12094. return material;
  12095. }
  12096. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12097. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12098. var material = _distanceMaterials[index];
  12099. if (material === undefined) {
  12100. material = new MeshDistanceMaterial({
  12101. morphTargets: useMorphing,
  12102. skinning: useSkinning
  12103. });
  12104. _distanceMaterials[index] = material;
  12105. }
  12106. return material;
  12107. }
  12108. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  12109. var result = null;
  12110. var getMaterialVariant = getDepthMaterialVariant;
  12111. var customMaterial = object.customDepthMaterial;
  12112. if (light.isPointLight === true) {
  12113. getMaterialVariant = getDistanceMaterialVariant;
  12114. customMaterial = object.customDistanceMaterial;
  12115. }
  12116. if (customMaterial === undefined) {
  12117. var useMorphing = false;
  12118. if (material.morphTargets === true) {
  12119. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12120. }
  12121. var useSkinning = false;
  12122. if (object.isSkinnedMesh === true) {
  12123. if (material.skinning === true) {
  12124. useSkinning = true;
  12125. } else {
  12126. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  12127. }
  12128. }
  12129. var useInstancing = object.isInstancedMesh === true;
  12130. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  12131. } else {
  12132. result = customMaterial;
  12133. }
  12134. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  12135. // in this case we need a unique material instance reflecting the
  12136. // appropriate state
  12137. var keyA = result.uuid,
  12138. keyB = material.uuid;
  12139. var materialsForVariant = _materialCache[keyA];
  12140. if (materialsForVariant === undefined) {
  12141. materialsForVariant = {};
  12142. _materialCache[keyA] = materialsForVariant;
  12143. }
  12144. var cachedMaterial = materialsForVariant[keyB];
  12145. if (cachedMaterial === undefined) {
  12146. cachedMaterial = result.clone();
  12147. materialsForVariant[keyB] = cachedMaterial;
  12148. }
  12149. result = cachedMaterial;
  12150. }
  12151. result.visible = material.visible;
  12152. result.wireframe = material.wireframe;
  12153. if (type === VSMShadowMap) {
  12154. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  12155. } else {
  12156. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  12157. }
  12158. result.clipShadows = material.clipShadows;
  12159. result.clippingPlanes = material.clippingPlanes;
  12160. result.clipIntersection = material.clipIntersection;
  12161. result.wireframeLinewidth = material.wireframeLinewidth;
  12162. result.linewidth = material.linewidth;
  12163. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  12164. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  12165. result.nearDistance = shadowCameraNear;
  12166. result.farDistance = shadowCameraFar;
  12167. }
  12168. return result;
  12169. }
  12170. function renderObject(object, camera, shadowCamera, light, type) {
  12171. if (object.visible === false) return;
  12172. var visible = object.layers.test(camera.layers);
  12173. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  12174. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  12175. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  12176. var geometry = _objects.update(object);
  12177. var material = object.material;
  12178. if (Array.isArray(material)) {
  12179. var groups = geometry.groups;
  12180. for (var k = 0, kl = groups.length; k < kl; k++) {
  12181. var group = groups[k];
  12182. var groupMaterial = material[group.materialIndex];
  12183. if (groupMaterial && groupMaterial.visible) {
  12184. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  12185. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  12186. }
  12187. }
  12188. } else if (material.visible) {
  12189. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  12190. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  12191. }
  12192. }
  12193. }
  12194. var children = object.children;
  12195. for (var i = 0, l = children.length; i < l; i++) {
  12196. renderObject(children[i], camera, shadowCamera, light, type);
  12197. }
  12198. }
  12199. }
  12200. function WebGLState(gl, extensions, capabilities) {
  12201. var _equationToGL, _factorToGL;
  12202. var isWebGL2 = capabilities.isWebGL2;
  12203. function ColorBuffer() {
  12204. var locked = false;
  12205. var color = new Vector4();
  12206. var currentColorMask = null;
  12207. var currentColorClear = new Vector4(0, 0, 0, 0);
  12208. return {
  12209. setMask: function setMask(colorMask) {
  12210. if (currentColorMask !== colorMask && !locked) {
  12211. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12212. currentColorMask = colorMask;
  12213. }
  12214. },
  12215. setLocked: function setLocked(lock) {
  12216. locked = lock;
  12217. },
  12218. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12219. if (premultipliedAlpha === true) {
  12220. r *= a;
  12221. g *= a;
  12222. b *= a;
  12223. }
  12224. color.set(r, g, b, a);
  12225. if (currentColorClear.equals(color) === false) {
  12226. gl.clearColor(r, g, b, a);
  12227. currentColorClear.copy(color);
  12228. }
  12229. },
  12230. reset: function reset() {
  12231. locked = false;
  12232. currentColorMask = null;
  12233. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12234. }
  12235. };
  12236. }
  12237. function DepthBuffer() {
  12238. var locked = false;
  12239. var currentDepthMask = null;
  12240. var currentDepthFunc = null;
  12241. var currentDepthClear = null;
  12242. return {
  12243. setTest: function setTest(depthTest) {
  12244. if (depthTest) {
  12245. enable(2929);
  12246. } else {
  12247. disable(2929);
  12248. }
  12249. },
  12250. setMask: function setMask(depthMask) {
  12251. if (currentDepthMask !== depthMask && !locked) {
  12252. gl.depthMask(depthMask);
  12253. currentDepthMask = depthMask;
  12254. }
  12255. },
  12256. setFunc: function setFunc(depthFunc) {
  12257. if (currentDepthFunc !== depthFunc) {
  12258. if (depthFunc) {
  12259. switch (depthFunc) {
  12260. case NeverDepth:
  12261. gl.depthFunc(512);
  12262. break;
  12263. case AlwaysDepth:
  12264. gl.depthFunc(519);
  12265. break;
  12266. case LessDepth:
  12267. gl.depthFunc(513);
  12268. break;
  12269. case LessEqualDepth:
  12270. gl.depthFunc(515);
  12271. break;
  12272. case EqualDepth:
  12273. gl.depthFunc(514);
  12274. break;
  12275. case GreaterEqualDepth:
  12276. gl.depthFunc(518);
  12277. break;
  12278. case GreaterDepth:
  12279. gl.depthFunc(516);
  12280. break;
  12281. case NotEqualDepth:
  12282. gl.depthFunc(517);
  12283. break;
  12284. default:
  12285. gl.depthFunc(515);
  12286. }
  12287. } else {
  12288. gl.depthFunc(515);
  12289. }
  12290. currentDepthFunc = depthFunc;
  12291. }
  12292. },
  12293. setLocked: function setLocked(lock) {
  12294. locked = lock;
  12295. },
  12296. setClear: function setClear(depth) {
  12297. if (currentDepthClear !== depth) {
  12298. gl.clearDepth(depth);
  12299. currentDepthClear = depth;
  12300. }
  12301. },
  12302. reset: function reset() {
  12303. locked = false;
  12304. currentDepthMask = null;
  12305. currentDepthFunc = null;
  12306. currentDepthClear = null;
  12307. }
  12308. };
  12309. }
  12310. function StencilBuffer() {
  12311. var locked = false;
  12312. var currentStencilMask = null;
  12313. var currentStencilFunc = null;
  12314. var currentStencilRef = null;
  12315. var currentStencilFuncMask = null;
  12316. var currentStencilFail = null;
  12317. var currentStencilZFail = null;
  12318. var currentStencilZPass = null;
  12319. var currentStencilClear = null;
  12320. return {
  12321. setTest: function setTest(stencilTest) {
  12322. if (!locked) {
  12323. if (stencilTest) {
  12324. enable(2960);
  12325. } else {
  12326. disable(2960);
  12327. }
  12328. }
  12329. },
  12330. setMask: function setMask(stencilMask) {
  12331. if (currentStencilMask !== stencilMask && !locked) {
  12332. gl.stencilMask(stencilMask);
  12333. currentStencilMask = stencilMask;
  12334. }
  12335. },
  12336. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12337. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12338. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12339. currentStencilFunc = stencilFunc;
  12340. currentStencilRef = stencilRef;
  12341. currentStencilFuncMask = stencilMask;
  12342. }
  12343. },
  12344. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12345. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12346. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12347. currentStencilFail = stencilFail;
  12348. currentStencilZFail = stencilZFail;
  12349. currentStencilZPass = stencilZPass;
  12350. }
  12351. },
  12352. setLocked: function setLocked(lock) {
  12353. locked = lock;
  12354. },
  12355. setClear: function setClear(stencil) {
  12356. if (currentStencilClear !== stencil) {
  12357. gl.clearStencil(stencil);
  12358. currentStencilClear = stencil;
  12359. }
  12360. },
  12361. reset: function reset() {
  12362. locked = false;
  12363. currentStencilMask = null;
  12364. currentStencilFunc = null;
  12365. currentStencilRef = null;
  12366. currentStencilFuncMask = null;
  12367. currentStencilFail = null;
  12368. currentStencilZFail = null;
  12369. currentStencilZPass = null;
  12370. currentStencilClear = null;
  12371. }
  12372. };
  12373. } //
  12374. var colorBuffer = new ColorBuffer();
  12375. var depthBuffer = new DepthBuffer();
  12376. var stencilBuffer = new StencilBuffer();
  12377. var enabledCapabilities = {};
  12378. var currentProgram = null;
  12379. var currentBlendingEnabled = null;
  12380. var currentBlending = null;
  12381. var currentBlendEquation = null;
  12382. var currentBlendSrc = null;
  12383. var currentBlendDst = null;
  12384. var currentBlendEquationAlpha = null;
  12385. var currentBlendSrcAlpha = null;
  12386. var currentBlendDstAlpha = null;
  12387. var currentPremultipledAlpha = false;
  12388. var currentFlipSided = null;
  12389. var currentCullFace = null;
  12390. var currentLineWidth = null;
  12391. var currentPolygonOffsetFactor = null;
  12392. var currentPolygonOffsetUnits = null;
  12393. var maxTextures = gl.getParameter(35661);
  12394. var lineWidthAvailable = false;
  12395. var version = 0;
  12396. var glVersion = gl.getParameter(7938);
  12397. if (glVersion.indexOf('WebGL') !== -1) {
  12398. version = parseFloat(/^WebGL (\d)/.exec(glVersion)[1]);
  12399. lineWidthAvailable = version >= 1.0;
  12400. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12401. version = parseFloat(/^OpenGL ES (\d)/.exec(glVersion)[1]);
  12402. lineWidthAvailable = version >= 2.0;
  12403. }
  12404. var currentTextureSlot = null;
  12405. var currentBoundTextures = {};
  12406. var currentScissor = new Vector4();
  12407. var currentViewport = new Vector4();
  12408. function createTexture(type, target, count) {
  12409. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12410. var texture = gl.createTexture();
  12411. gl.bindTexture(type, texture);
  12412. gl.texParameteri(type, 10241, 9728);
  12413. gl.texParameteri(type, 10240, 9728);
  12414. for (var i = 0; i < count; i++) {
  12415. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12416. }
  12417. return texture;
  12418. }
  12419. var emptyTextures = {};
  12420. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12421. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12422. colorBuffer.setClear(0, 0, 0, 1);
  12423. depthBuffer.setClear(1);
  12424. stencilBuffer.setClear(0);
  12425. enable(2929);
  12426. depthBuffer.setFunc(LessEqualDepth);
  12427. setFlipSided(false);
  12428. setCullFace(CullFaceBack);
  12429. enable(2884);
  12430. setBlending(NoBlending); //
  12431. function enable(id) {
  12432. if (enabledCapabilities[id] !== true) {
  12433. gl.enable(id);
  12434. enabledCapabilities[id] = true;
  12435. }
  12436. }
  12437. function disable(id) {
  12438. if (enabledCapabilities[id] !== false) {
  12439. gl.disable(id);
  12440. enabledCapabilities[id] = false;
  12441. }
  12442. }
  12443. function useProgram(program) {
  12444. if (currentProgram !== program) {
  12445. gl.useProgram(program);
  12446. currentProgram = program;
  12447. return true;
  12448. }
  12449. return false;
  12450. }
  12451. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12452. if (isWebGL2) {
  12453. equationToGL[MinEquation] = 32775;
  12454. equationToGL[MaxEquation] = 32776;
  12455. } else {
  12456. var extension = extensions.get('EXT_blend_minmax');
  12457. if (extension !== null) {
  12458. equationToGL[MinEquation] = extension.MIN_EXT;
  12459. equationToGL[MaxEquation] = extension.MAX_EXT;
  12460. }
  12461. }
  12462. 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);
  12463. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  12464. if (blending === NoBlending) {
  12465. if (currentBlendingEnabled) {
  12466. disable(3042);
  12467. currentBlendingEnabled = false;
  12468. }
  12469. return;
  12470. }
  12471. if (!currentBlendingEnabled) {
  12472. enable(3042);
  12473. currentBlendingEnabled = true;
  12474. }
  12475. if (blending !== CustomBlending) {
  12476. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  12477. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  12478. gl.blendEquation(32774);
  12479. currentBlendEquation = AddEquation;
  12480. currentBlendEquationAlpha = AddEquation;
  12481. }
  12482. if (premultipliedAlpha) {
  12483. switch (blending) {
  12484. case NormalBlending:
  12485. gl.blendFuncSeparate(1, 771, 1, 771);
  12486. break;
  12487. case AdditiveBlending:
  12488. gl.blendFunc(1, 1);
  12489. break;
  12490. case SubtractiveBlending:
  12491. gl.blendFuncSeparate(0, 0, 769, 771);
  12492. break;
  12493. case MultiplyBlending:
  12494. gl.blendFuncSeparate(0, 768, 0, 770);
  12495. break;
  12496. default:
  12497. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12498. break;
  12499. }
  12500. } else {
  12501. switch (blending) {
  12502. case NormalBlending:
  12503. gl.blendFuncSeparate(770, 771, 1, 771);
  12504. break;
  12505. case AdditiveBlending:
  12506. gl.blendFunc(770, 1);
  12507. break;
  12508. case SubtractiveBlending:
  12509. gl.blendFunc(0, 769);
  12510. break;
  12511. case MultiplyBlending:
  12512. gl.blendFunc(0, 768);
  12513. break;
  12514. default:
  12515. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12516. break;
  12517. }
  12518. }
  12519. currentBlendSrc = null;
  12520. currentBlendDst = null;
  12521. currentBlendSrcAlpha = null;
  12522. currentBlendDstAlpha = null;
  12523. currentBlending = blending;
  12524. currentPremultipledAlpha = premultipliedAlpha;
  12525. }
  12526. return;
  12527. } // custom blending
  12528. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12529. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12530. blendDstAlpha = blendDstAlpha || blendDst;
  12531. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  12532. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  12533. currentBlendEquation = blendEquation;
  12534. currentBlendEquationAlpha = blendEquationAlpha;
  12535. }
  12536. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  12537. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  12538. currentBlendSrc = blendSrc;
  12539. currentBlendDst = blendDst;
  12540. currentBlendSrcAlpha = blendSrcAlpha;
  12541. currentBlendDstAlpha = blendDstAlpha;
  12542. }
  12543. currentBlending = blending;
  12544. currentPremultipledAlpha = null;
  12545. }
  12546. function setMaterial(material, frontFaceCW) {
  12547. material.side === DoubleSide ? disable(2884) : enable(2884);
  12548. var flipSided = material.side === BackSide;
  12549. if (frontFaceCW) flipSided = !flipSided;
  12550. setFlipSided(flipSided);
  12551. 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);
  12552. depthBuffer.setFunc(material.depthFunc);
  12553. depthBuffer.setTest(material.depthTest);
  12554. depthBuffer.setMask(material.depthWrite);
  12555. colorBuffer.setMask(material.colorWrite);
  12556. var stencilWrite = material.stencilWrite;
  12557. stencilBuffer.setTest(stencilWrite);
  12558. if (stencilWrite) {
  12559. stencilBuffer.setMask(material.stencilWriteMask);
  12560. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  12561. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  12562. }
  12563. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  12564. } //
  12565. function setFlipSided(flipSided) {
  12566. if (currentFlipSided !== flipSided) {
  12567. if (flipSided) {
  12568. gl.frontFace(2304);
  12569. } else {
  12570. gl.frontFace(2305);
  12571. }
  12572. currentFlipSided = flipSided;
  12573. }
  12574. }
  12575. function setCullFace(cullFace) {
  12576. if (cullFace !== CullFaceNone) {
  12577. enable(2884);
  12578. if (cullFace !== currentCullFace) {
  12579. if (cullFace === CullFaceBack) {
  12580. gl.cullFace(1029);
  12581. } else if (cullFace === CullFaceFront) {
  12582. gl.cullFace(1028);
  12583. } else {
  12584. gl.cullFace(1032);
  12585. }
  12586. }
  12587. } else {
  12588. disable(2884);
  12589. }
  12590. currentCullFace = cullFace;
  12591. }
  12592. function setLineWidth(width) {
  12593. if (width !== currentLineWidth) {
  12594. if (lineWidthAvailable) gl.lineWidth(width);
  12595. currentLineWidth = width;
  12596. }
  12597. }
  12598. function setPolygonOffset(polygonOffset, factor, units) {
  12599. if (polygonOffset) {
  12600. enable(32823);
  12601. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  12602. gl.polygonOffset(factor, units);
  12603. currentPolygonOffsetFactor = factor;
  12604. currentPolygonOffsetUnits = units;
  12605. }
  12606. } else {
  12607. disable(32823);
  12608. }
  12609. }
  12610. function setScissorTest(scissorTest) {
  12611. if (scissorTest) {
  12612. enable(3089);
  12613. } else {
  12614. disable(3089);
  12615. }
  12616. } // texture
  12617. function activeTexture(webglSlot) {
  12618. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  12619. if (currentTextureSlot !== webglSlot) {
  12620. gl.activeTexture(webglSlot);
  12621. currentTextureSlot = webglSlot;
  12622. }
  12623. }
  12624. function bindTexture(webglType, webglTexture) {
  12625. if (currentTextureSlot === null) {
  12626. activeTexture();
  12627. }
  12628. var boundTexture = currentBoundTextures[currentTextureSlot];
  12629. if (boundTexture === undefined) {
  12630. boundTexture = {
  12631. type: undefined,
  12632. texture: undefined
  12633. };
  12634. currentBoundTextures[currentTextureSlot] = boundTexture;
  12635. }
  12636. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  12637. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  12638. boundTexture.type = webglType;
  12639. boundTexture.texture = webglTexture;
  12640. }
  12641. }
  12642. function unbindTexture() {
  12643. var boundTexture = currentBoundTextures[currentTextureSlot];
  12644. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  12645. gl.bindTexture(boundTexture.type, null);
  12646. boundTexture.type = undefined;
  12647. boundTexture.texture = undefined;
  12648. }
  12649. }
  12650. function compressedTexImage2D() {
  12651. try {
  12652. gl.compressedTexImage2D.apply(gl, arguments);
  12653. } catch (error) {
  12654. console.error('THREE.WebGLState:', error);
  12655. }
  12656. }
  12657. function texImage2D() {
  12658. try {
  12659. gl.texImage2D.apply(gl, arguments);
  12660. } catch (error) {
  12661. console.error('THREE.WebGLState:', error);
  12662. }
  12663. }
  12664. function texImage3D() {
  12665. try {
  12666. gl.texImage3D.apply(gl, arguments);
  12667. } catch (error) {
  12668. console.error('THREE.WebGLState:', error);
  12669. }
  12670. } //
  12671. function scissor(scissor) {
  12672. if (currentScissor.equals(scissor) === false) {
  12673. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  12674. currentScissor.copy(scissor);
  12675. }
  12676. }
  12677. function viewport(viewport) {
  12678. if (currentViewport.equals(viewport) === false) {
  12679. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  12680. currentViewport.copy(viewport);
  12681. }
  12682. } //
  12683. function reset() {
  12684. enabledCapabilities = {};
  12685. currentTextureSlot = null;
  12686. currentBoundTextures = {};
  12687. currentProgram = null;
  12688. currentBlendingEnabled = null;
  12689. currentBlending = null;
  12690. currentBlendEquation = null;
  12691. currentBlendSrc = null;
  12692. currentBlendDst = null;
  12693. currentBlendEquationAlpha = null;
  12694. currentBlendSrcAlpha = null;
  12695. currentBlendDstAlpha = null;
  12696. currentPremultipledAlpha = false;
  12697. currentFlipSided = null;
  12698. currentCullFace = null;
  12699. currentLineWidth = null;
  12700. currentPolygonOffsetFactor = null;
  12701. currentPolygonOffsetUnits = null;
  12702. colorBuffer.reset();
  12703. depthBuffer.reset();
  12704. stencilBuffer.reset();
  12705. }
  12706. return {
  12707. buffers: {
  12708. color: colorBuffer,
  12709. depth: depthBuffer,
  12710. stencil: stencilBuffer
  12711. },
  12712. enable: enable,
  12713. disable: disable,
  12714. useProgram: useProgram,
  12715. setBlending: setBlending,
  12716. setMaterial: setMaterial,
  12717. setFlipSided: setFlipSided,
  12718. setCullFace: setCullFace,
  12719. setLineWidth: setLineWidth,
  12720. setPolygonOffset: setPolygonOffset,
  12721. setScissorTest: setScissorTest,
  12722. activeTexture: activeTexture,
  12723. bindTexture: bindTexture,
  12724. unbindTexture: unbindTexture,
  12725. compressedTexImage2D: compressedTexImage2D,
  12726. texImage2D: texImage2D,
  12727. texImage3D: texImage3D,
  12728. scissor: scissor,
  12729. viewport: viewport,
  12730. reset: reset
  12731. };
  12732. }
  12733. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  12734. var _wrappingToGL, _filterToGL;
  12735. var isWebGL2 = capabilities.isWebGL2;
  12736. var maxTextures = capabilities.maxTextures;
  12737. var maxCubemapSize = capabilities.maxCubemapSize;
  12738. var maxTextureSize = capabilities.maxTextureSize;
  12739. var maxSamples = capabilities.maxSamples;
  12740. var _videoTextures = new WeakMap();
  12741. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  12742. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  12743. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  12744. var useOffscreenCanvas = false;
  12745. try {
  12746. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext('2d') !== null;
  12747. } catch (err) {// Ignore any errors
  12748. }
  12749. function createCanvas(width, height) {
  12750. // Use OffscreenCanvas when available. Specially needed in web workers
  12751. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  12752. }
  12753. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  12754. var scale = 1; // handle case if texture exceeds max size
  12755. if (image.width > maxSize || image.height > maxSize) {
  12756. scale = maxSize / Math.max(image.width, image.height);
  12757. } // only perform resize if necessary
  12758. if (scale < 1 || needsPowerOfTwo === true) {
  12759. // only perform resize for certain image types
  12760. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  12761. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  12762. var width = floor(scale * image.width);
  12763. var height = floor(scale * image.height);
  12764. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  12765. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  12766. canvas.width = width;
  12767. canvas.height = height;
  12768. var context = canvas.getContext('2d');
  12769. context.drawImage(image, 0, 0, width, height);
  12770. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  12771. return canvas;
  12772. } else {
  12773. if ('data' in image) {
  12774. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  12775. }
  12776. return image;
  12777. }
  12778. }
  12779. return image;
  12780. }
  12781. function isPowerOfTwo(image) {
  12782. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  12783. }
  12784. function textureNeedsPowerOfTwo(texture) {
  12785. if (isWebGL2) return false;
  12786. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12787. }
  12788. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  12789. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12790. }
  12791. function generateMipmap(target, texture, width, height) {
  12792. _gl.generateMipmap(target);
  12793. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12794. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  12795. }
  12796. function getInternalFormat(internalFormatName, glFormat, glType) {
  12797. if (isWebGL2 === false) return glFormat;
  12798. if (internalFormatName !== null) {
  12799. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  12800. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  12801. }
  12802. var internalFormat = glFormat;
  12803. if (glFormat === 6403) {
  12804. if (glType === 5126) internalFormat = 33326;
  12805. if (glType === 5131) internalFormat = 33325;
  12806. if (glType === 5121) internalFormat = 33321;
  12807. }
  12808. if (glFormat === 6407) {
  12809. if (glType === 5126) internalFormat = 34837;
  12810. if (glType === 5131) internalFormat = 34843;
  12811. if (glType === 5121) internalFormat = 32849;
  12812. }
  12813. if (glFormat === 6408) {
  12814. if (glType === 5126) internalFormat = 34836;
  12815. if (glType === 5131) internalFormat = 34842;
  12816. if (glType === 5121) internalFormat = 32856;
  12817. }
  12818. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  12819. extensions.get('EXT_color_buffer_float');
  12820. }
  12821. return internalFormat;
  12822. } // Fallback filters for non-power-of-2 textures
  12823. function filterFallback(f) {
  12824. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  12825. return 9728;
  12826. }
  12827. return 9729;
  12828. } //
  12829. function onTextureDispose(event) {
  12830. var texture = event.target;
  12831. texture.removeEventListener('dispose', onTextureDispose);
  12832. deallocateTexture(texture);
  12833. if (texture.isVideoTexture) {
  12834. _videoTextures.delete(texture);
  12835. }
  12836. info.memory.textures--;
  12837. }
  12838. function onRenderTargetDispose(event) {
  12839. var renderTarget = event.target;
  12840. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  12841. deallocateRenderTarget(renderTarget);
  12842. info.memory.textures--;
  12843. } //
  12844. function deallocateTexture(texture) {
  12845. var textureProperties = properties.get(texture);
  12846. if (textureProperties.__webglInit === undefined) return;
  12847. _gl.deleteTexture(textureProperties.__webglTexture);
  12848. properties.remove(texture);
  12849. }
  12850. function deallocateRenderTarget(renderTarget) {
  12851. var renderTargetProperties = properties.get(renderTarget);
  12852. var textureProperties = properties.get(renderTarget.texture);
  12853. if (!renderTarget) return;
  12854. if (textureProperties.__webglTexture !== undefined) {
  12855. _gl.deleteTexture(textureProperties.__webglTexture);
  12856. }
  12857. if (renderTarget.depthTexture) {
  12858. renderTarget.depthTexture.dispose();
  12859. }
  12860. if (renderTarget.isWebGLCubeRenderTarget) {
  12861. for (var i = 0; i < 6; i++) {
  12862. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  12863. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  12864. }
  12865. } else {
  12866. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  12867. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  12868. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  12869. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  12870. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  12871. }
  12872. properties.remove(renderTarget.texture);
  12873. properties.remove(renderTarget);
  12874. } //
  12875. var textureUnits = 0;
  12876. function resetTextureUnits() {
  12877. textureUnits = 0;
  12878. }
  12879. function allocateTextureUnit() {
  12880. var textureUnit = textureUnits;
  12881. if (textureUnit >= maxTextures) {
  12882. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  12883. }
  12884. textureUnits += 1;
  12885. return textureUnit;
  12886. } //
  12887. function setTexture2D(texture, slot) {
  12888. var textureProperties = properties.get(texture);
  12889. if (texture.isVideoTexture) updateVideoTexture(texture);
  12890. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12891. var image = texture.image;
  12892. if (image === undefined) {
  12893. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  12894. } else if (image.complete === false) {
  12895. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  12896. } else {
  12897. uploadTexture(textureProperties, texture, slot);
  12898. return;
  12899. }
  12900. }
  12901. state.activeTexture(33984 + slot);
  12902. state.bindTexture(3553, textureProperties.__webglTexture);
  12903. }
  12904. function setTexture2DArray(texture, slot) {
  12905. var textureProperties = properties.get(texture);
  12906. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12907. uploadTexture(textureProperties, texture, slot);
  12908. return;
  12909. }
  12910. state.activeTexture(33984 + slot);
  12911. state.bindTexture(35866, textureProperties.__webglTexture);
  12912. }
  12913. function setTexture3D(texture, slot) {
  12914. var textureProperties = properties.get(texture);
  12915. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12916. uploadTexture(textureProperties, texture, slot);
  12917. return;
  12918. }
  12919. state.activeTexture(33984 + slot);
  12920. state.bindTexture(32879, textureProperties.__webglTexture);
  12921. }
  12922. function setTextureCube(texture, slot) {
  12923. var textureProperties = properties.get(texture);
  12924. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12925. uploadCubeTexture(textureProperties, texture, slot);
  12926. return;
  12927. }
  12928. state.activeTexture(33984 + slot);
  12929. state.bindTexture(34067, textureProperties.__webglTexture);
  12930. }
  12931. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  12932. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  12933. function setTextureParameters(textureType, texture, supportsMips) {
  12934. if (supportsMips) {
  12935. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  12936. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  12937. if (textureType === 32879 || textureType === 35866) {
  12938. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  12939. }
  12940. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  12941. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  12942. } else {
  12943. _gl.texParameteri(textureType, 10242, 33071);
  12944. _gl.texParameteri(textureType, 10243, 33071);
  12945. if (textureType === 32879 || textureType === 35866) {
  12946. _gl.texParameteri(textureType, 32882, 33071);
  12947. }
  12948. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  12949. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  12950. }
  12951. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  12952. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  12953. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  12954. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  12955. }
  12956. }
  12957. var extension = extensions.get('EXT_texture_filter_anisotropic');
  12958. if (extension) {
  12959. if (texture.type === FloatType && extensions.get('OES_texture_float_linear') === null) return;
  12960. if (texture.type === HalfFloatType && (isWebGL2 || extensions.get('OES_texture_half_float_linear')) === null) return;
  12961. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  12962. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  12963. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  12964. }
  12965. }
  12966. }
  12967. function initTexture(textureProperties, texture) {
  12968. if (textureProperties.__webglInit === undefined) {
  12969. textureProperties.__webglInit = true;
  12970. texture.addEventListener('dispose', onTextureDispose);
  12971. textureProperties.__webglTexture = _gl.createTexture();
  12972. info.memory.textures++;
  12973. }
  12974. }
  12975. function uploadTexture(textureProperties, texture, slot) {
  12976. var textureType = 3553;
  12977. if (texture.isDataTexture2DArray) textureType = 35866;
  12978. if (texture.isDataTexture3D) textureType = 32879;
  12979. initTexture(textureProperties, texture);
  12980. state.activeTexture(33984 + slot);
  12981. state.bindTexture(textureType, textureProperties.__webglTexture);
  12982. _gl.pixelStorei(37440, texture.flipY);
  12983. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  12984. _gl.pixelStorei(3317, texture.unpackAlignment);
  12985. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  12986. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  12987. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  12988. glFormat = utils.convert(texture.format);
  12989. var glType = utils.convert(texture.type),
  12990. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  12991. setTextureParameters(textureType, texture, supportsMips);
  12992. var mipmap;
  12993. var mipmaps = texture.mipmaps;
  12994. if (texture.isDepthTexture) {
  12995. // populate depth texture with dummy data
  12996. glInternalFormat = 6402;
  12997. if (isWebGL2) {
  12998. if (texture.type === FloatType) {
  12999. glInternalFormat = 36012;
  13000. } else if (texture.type === UnsignedIntType) {
  13001. glInternalFormat = 33190;
  13002. } else if (texture.type === UnsignedInt248Type) {
  13003. glInternalFormat = 35056;
  13004. } else {
  13005. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  13006. }
  13007. } else {
  13008. if (texture.type === FloatType) {
  13009. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  13010. }
  13011. } // validation checks for WebGL 1
  13012. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  13013. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13014. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13015. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13016. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  13017. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  13018. texture.type = UnsignedShortType;
  13019. glType = utils.convert(texture.type);
  13020. }
  13021. }
  13022. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  13023. // Depth stencil textures need the DEPTH_STENCIL internal format
  13024. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13025. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13026. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13027. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13028. if (texture.type !== UnsignedInt248Type) {
  13029. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  13030. texture.type = UnsignedInt248Type;
  13031. glType = utils.convert(texture.type);
  13032. }
  13033. } //
  13034. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  13035. } else if (texture.isDataTexture) {
  13036. // use manually created mipmaps if available
  13037. // if there are no manual mipmaps
  13038. // set 0 level mipmap and then use GL to generate other mipmap levels
  13039. if (mipmaps.length > 0 && supportsMips) {
  13040. for (var i = 0, il = mipmaps.length; i < il; i++) {
  13041. mipmap = mipmaps[i];
  13042. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13043. }
  13044. texture.generateMipmaps = false;
  13045. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13046. } else {
  13047. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  13048. textureProperties.__maxMipLevel = 0;
  13049. }
  13050. } else if (texture.isCompressedTexture) {
  13051. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  13052. mipmap = mipmaps[_i];
  13053. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13054. if (glFormat !== null) {
  13055. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13056. } else {
  13057. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  13058. }
  13059. } else {
  13060. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13061. }
  13062. }
  13063. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13064. } else if (texture.isDataTexture2DArray) {
  13065. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13066. textureProperties.__maxMipLevel = 0;
  13067. } else if (texture.isDataTexture3D) {
  13068. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13069. textureProperties.__maxMipLevel = 0;
  13070. } else {
  13071. // regular Texture (image, video, canvas)
  13072. // use manually created mipmaps if available
  13073. // if there are no manual mipmaps
  13074. // set 0 level mipmap and then use GL to generate other mipmap levels
  13075. if (mipmaps.length > 0 && supportsMips) {
  13076. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  13077. mipmap = mipmaps[_i2];
  13078. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  13079. }
  13080. texture.generateMipmaps = false;
  13081. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13082. } else {
  13083. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  13084. textureProperties.__maxMipLevel = 0;
  13085. }
  13086. }
  13087. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13088. generateMipmap(textureType, texture, image.width, image.height);
  13089. }
  13090. textureProperties.__version = texture.version;
  13091. if (texture.onUpdate) texture.onUpdate(texture);
  13092. }
  13093. function uploadCubeTexture(textureProperties, texture, slot) {
  13094. if (texture.image.length !== 6) return;
  13095. initTexture(textureProperties, texture);
  13096. state.activeTexture(33984 + slot);
  13097. state.bindTexture(34067, textureProperties.__webglTexture);
  13098. _gl.pixelStorei(37440, texture.flipY);
  13099. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13100. _gl.pixelStorei(3317, texture.unpackAlignment);
  13101. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  13102. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  13103. var cubeImage = [];
  13104. for (var i = 0; i < 6; i++) {
  13105. if (!isCompressed && !isDataTexture) {
  13106. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  13107. } else {
  13108. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  13109. }
  13110. }
  13111. var image = cubeImage[0],
  13112. supportsMips = isPowerOfTwo(image) || isWebGL2,
  13113. glFormat = utils.convert(texture.format),
  13114. glType = utils.convert(texture.type),
  13115. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13116. setTextureParameters(34067, texture, supportsMips);
  13117. var mipmaps;
  13118. if (isCompressed) {
  13119. for (var _i3 = 0; _i3 < 6; _i3++) {
  13120. mipmaps = cubeImage[_i3].mipmaps;
  13121. for (var j = 0; j < mipmaps.length; j++) {
  13122. var mipmap = mipmaps[j];
  13123. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13124. if (glFormat !== null) {
  13125. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13126. } else {
  13127. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  13128. }
  13129. } else {
  13130. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13131. }
  13132. }
  13133. }
  13134. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13135. } else {
  13136. mipmaps = texture.mipmaps;
  13137. for (var _i4 = 0; _i4 < 6; _i4++) {
  13138. if (isDataTexture) {
  13139. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  13140. for (var _j = 0; _j < mipmaps.length; _j++) {
  13141. var _mipmap = mipmaps[_j];
  13142. var mipmapImage = _mipmap.image[_i4].image;
  13143. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  13144. }
  13145. } else {
  13146. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  13147. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  13148. var _mipmap2 = mipmaps[_j2];
  13149. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  13150. }
  13151. }
  13152. }
  13153. textureProperties.__maxMipLevel = mipmaps.length;
  13154. }
  13155. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13156. // We assume images for cube map have the same size.
  13157. generateMipmap(34067, texture, image.width, image.height);
  13158. }
  13159. textureProperties.__version = texture.version;
  13160. if (texture.onUpdate) texture.onUpdate(texture);
  13161. } // Render targets
  13162. // Setup storage for target texture and bind it to correct framebuffer
  13163. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  13164. var glFormat = utils.convert(renderTarget.texture.format);
  13165. var glType = utils.convert(renderTarget.texture.type);
  13166. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13167. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  13168. _gl.bindFramebuffer(36160, framebuffer);
  13169. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(renderTarget.texture).__webglTexture, 0);
  13170. _gl.bindFramebuffer(36160, null);
  13171. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13172. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  13173. _gl.bindRenderbuffer(36161, renderbuffer);
  13174. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  13175. var glInternalFormat = 33189;
  13176. if (isMultisample) {
  13177. var depthTexture = renderTarget.depthTexture;
  13178. if (depthTexture && depthTexture.isDepthTexture) {
  13179. if (depthTexture.type === FloatType) {
  13180. glInternalFormat = 36012;
  13181. } else if (depthTexture.type === UnsignedIntType) {
  13182. glInternalFormat = 33190;
  13183. }
  13184. }
  13185. var samples = getRenderTargetSamples(renderTarget);
  13186. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13187. } else {
  13188. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  13189. }
  13190. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  13191. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  13192. if (isMultisample) {
  13193. var _samples = getRenderTargetSamples(renderTarget);
  13194. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  13195. } else {
  13196. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  13197. }
  13198. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  13199. } else {
  13200. var glFormat = utils.convert(renderTarget.texture.format);
  13201. var glType = utils.convert(renderTarget.texture.type);
  13202. var _glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13203. if (isMultisample) {
  13204. var _samples2 = getRenderTargetSamples(renderTarget);
  13205. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  13206. } else {
  13207. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  13208. }
  13209. }
  13210. _gl.bindRenderbuffer(36161, null);
  13211. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  13212. function setupDepthTexture(framebuffer, renderTarget) {
  13213. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  13214. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  13215. _gl.bindFramebuffer(36160, framebuffer);
  13216. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  13217. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  13218. } // upload an empty depth texture with framebuffer size
  13219. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  13220. renderTarget.depthTexture.image.width = renderTarget.width;
  13221. renderTarget.depthTexture.image.height = renderTarget.height;
  13222. renderTarget.depthTexture.needsUpdate = true;
  13223. }
  13224. setTexture2D(renderTarget.depthTexture, 0);
  13225. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13226. if (renderTarget.depthTexture.format === DepthFormat) {
  13227. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13228. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13229. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13230. } else {
  13231. throw new Error('Unknown depthTexture format');
  13232. }
  13233. } // Setup GL resources for a non-texture depth buffer
  13234. function setupDepthRenderbuffer(renderTarget) {
  13235. var renderTargetProperties = properties.get(renderTarget);
  13236. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13237. if (renderTarget.depthTexture) {
  13238. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13239. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13240. } else {
  13241. if (isCube) {
  13242. renderTargetProperties.__webglDepthbuffer = [];
  13243. for (var i = 0; i < 6; i++) {
  13244. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13245. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13246. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13247. }
  13248. } else {
  13249. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13250. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13251. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13252. }
  13253. }
  13254. _gl.bindFramebuffer(36160, null);
  13255. } // Set up GL resources for the render target
  13256. function setupRenderTarget(renderTarget) {
  13257. var renderTargetProperties = properties.get(renderTarget);
  13258. var textureProperties = properties.get(renderTarget.texture);
  13259. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13260. textureProperties.__webglTexture = _gl.createTexture();
  13261. info.memory.textures++;
  13262. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13263. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13264. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13265. if (isWebGL2 && renderTarget.texture.format === RGBFormat && (renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType)) {
  13266. renderTarget.texture.format = RGBAFormat;
  13267. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13268. } // Setup framebuffer
  13269. if (isCube) {
  13270. renderTargetProperties.__webglFramebuffer = [];
  13271. for (var i = 0; i < 6; i++) {
  13272. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13273. }
  13274. } else {
  13275. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13276. if (isMultisample) {
  13277. if (isWebGL2) {
  13278. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13279. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13280. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13281. var glFormat = utils.convert(renderTarget.texture.format);
  13282. var glType = utils.convert(renderTarget.texture.type);
  13283. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13284. var samples = getRenderTargetSamples(renderTarget);
  13285. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13286. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13287. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13288. _gl.bindRenderbuffer(36161, null);
  13289. if (renderTarget.depthBuffer) {
  13290. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13291. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13292. }
  13293. _gl.bindFramebuffer(36160, null);
  13294. } else {
  13295. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13296. }
  13297. }
  13298. } // Setup color buffer
  13299. if (isCube) {
  13300. state.bindTexture(34067, textureProperties.__webglTexture);
  13301. setTextureParameters(34067, renderTarget.texture, supportsMips);
  13302. for (var _i5 = 0; _i5 < 6; _i5++) {
  13303. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13304. }
  13305. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13306. generateMipmap(34067, renderTarget.texture, renderTarget.width, renderTarget.height);
  13307. }
  13308. state.bindTexture(34067, null);
  13309. } else {
  13310. state.bindTexture(3553, textureProperties.__webglTexture);
  13311. setTextureParameters(3553, renderTarget.texture, supportsMips);
  13312. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553);
  13313. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13314. generateMipmap(3553, renderTarget.texture, renderTarget.width, renderTarget.height);
  13315. }
  13316. state.bindTexture(3553, null);
  13317. } // Setup depth and stencil buffers
  13318. if (renderTarget.depthBuffer) {
  13319. setupDepthRenderbuffer(renderTarget);
  13320. }
  13321. }
  13322. function updateRenderTargetMipmap(renderTarget) {
  13323. var texture = renderTarget.texture;
  13324. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13325. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13326. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13327. var webglTexture = properties.get(texture).__webglTexture;
  13328. state.bindTexture(target, webglTexture);
  13329. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13330. state.bindTexture(target, null);
  13331. }
  13332. }
  13333. function updateMultisampleRenderTarget(renderTarget) {
  13334. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13335. if (isWebGL2) {
  13336. var renderTargetProperties = properties.get(renderTarget);
  13337. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13338. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13339. var width = renderTarget.width;
  13340. var height = renderTarget.height;
  13341. var mask = 16384;
  13342. if (renderTarget.depthBuffer) mask |= 256;
  13343. if (renderTarget.stencilBuffer) mask |= 1024;
  13344. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13345. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13346. } else {
  13347. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13348. }
  13349. }
  13350. }
  13351. function getRenderTargetSamples(renderTarget) {
  13352. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13353. }
  13354. function updateVideoTexture(texture) {
  13355. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13356. if (_videoTextures.get(texture) !== frame) {
  13357. _videoTextures.set(texture, frame);
  13358. texture.update();
  13359. }
  13360. } // backwards compatibility
  13361. var warnedTexture2D = false;
  13362. var warnedTextureCube = false;
  13363. function safeSetTexture2D(texture, slot) {
  13364. if (texture && texture.isWebGLRenderTarget) {
  13365. if (warnedTexture2D === false) {
  13366. console.warn('THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.');
  13367. warnedTexture2D = true;
  13368. }
  13369. texture = texture.texture;
  13370. }
  13371. setTexture2D(texture, slot);
  13372. }
  13373. function safeSetTextureCube(texture, slot) {
  13374. if (texture && texture.isWebGLCubeRenderTarget) {
  13375. if (warnedTextureCube === false) {
  13376. console.warn('THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.');
  13377. warnedTextureCube = true;
  13378. }
  13379. texture = texture.texture;
  13380. }
  13381. setTextureCube(texture, slot);
  13382. } //
  13383. this.allocateTextureUnit = allocateTextureUnit;
  13384. this.resetTextureUnits = resetTextureUnits;
  13385. this.setTexture2D = setTexture2D;
  13386. this.setTexture2DArray = setTexture2DArray;
  13387. this.setTexture3D = setTexture3D;
  13388. this.setTextureCube = setTextureCube;
  13389. this.setupRenderTarget = setupRenderTarget;
  13390. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13391. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13392. this.safeSetTexture2D = safeSetTexture2D;
  13393. this.safeSetTextureCube = safeSetTextureCube;
  13394. }
  13395. function WebGLUtils(gl, extensions, capabilities) {
  13396. var isWebGL2 = capabilities.isWebGL2;
  13397. function convert(p) {
  13398. var extension;
  13399. if (p === UnsignedByteType) return 5121;
  13400. if (p === UnsignedShort4444Type) return 32819;
  13401. if (p === UnsignedShort5551Type) return 32820;
  13402. if (p === UnsignedShort565Type) return 33635;
  13403. if (p === ByteType) return 5120;
  13404. if (p === ShortType) return 5122;
  13405. if (p === UnsignedShortType) return 5123;
  13406. if (p === IntType) return 5124;
  13407. if (p === UnsignedIntType) return 5125;
  13408. if (p === FloatType) return 5126;
  13409. if (p === HalfFloatType) {
  13410. if (isWebGL2) return 5131;
  13411. extension = extensions.get('OES_texture_half_float');
  13412. if (extension !== null) {
  13413. return extension.HALF_FLOAT_OES;
  13414. } else {
  13415. return null;
  13416. }
  13417. }
  13418. if (p === AlphaFormat) return 6406;
  13419. if (p === RGBFormat) return 6407;
  13420. if (p === RGBAFormat) return 6408;
  13421. if (p === LuminanceFormat) return 6409;
  13422. if (p === LuminanceAlphaFormat) return 6410;
  13423. if (p === DepthFormat) return 6402;
  13424. if (p === DepthStencilFormat) return 34041;
  13425. if (p === RedFormat) return 6403; // WebGL2 formats.
  13426. if (p === RedIntegerFormat) return 36244;
  13427. if (p === RGFormat) return 33319;
  13428. if (p === RGIntegerFormat) return 33320;
  13429. if (p === RGBIntegerFormat) return 36248;
  13430. if (p === RGBAIntegerFormat) return 36249;
  13431. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13432. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13433. if (extension !== null) {
  13434. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13435. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13436. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13437. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13438. } else {
  13439. return null;
  13440. }
  13441. }
  13442. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13443. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13444. if (extension !== null) {
  13445. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13446. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13447. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13448. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13449. } else {
  13450. return null;
  13451. }
  13452. }
  13453. if (p === RGB_ETC1_Format) {
  13454. extension = extensions.get('WEBGL_compressed_texture_etc1');
  13455. if (extension !== null) {
  13456. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13457. } else {
  13458. return null;
  13459. }
  13460. }
  13461. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  13462. extension = extensions.get('WEBGL_compressed_texture_etc');
  13463. if (extension !== null) {
  13464. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  13465. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13466. }
  13467. }
  13468. 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) {
  13469. extension = extensions.get('WEBGL_compressed_texture_astc');
  13470. if (extension !== null) {
  13471. // TODO Complete?
  13472. return p;
  13473. } else {
  13474. return null;
  13475. }
  13476. }
  13477. if (p === RGBA_BPTC_Format) {
  13478. extension = extensions.get('EXT_texture_compression_bptc');
  13479. if (extension !== null) {
  13480. // TODO Complete?
  13481. return p;
  13482. } else {
  13483. return null;
  13484. }
  13485. }
  13486. if (p === UnsignedInt248Type) {
  13487. if (isWebGL2) return 34042;
  13488. extension = extensions.get('WEBGL_depth_texture');
  13489. if (extension !== null) {
  13490. return extension.UNSIGNED_INT_24_8_WEBGL;
  13491. } else {
  13492. return null;
  13493. }
  13494. }
  13495. }
  13496. return {
  13497. convert: convert
  13498. };
  13499. }
  13500. function ArrayCamera(array) {
  13501. if (array === void 0) {
  13502. array = [];
  13503. }
  13504. PerspectiveCamera.call(this);
  13505. this.cameras = array;
  13506. }
  13507. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  13508. constructor: ArrayCamera,
  13509. isArrayCamera: true
  13510. });
  13511. function Group() {
  13512. Object3D.call(this);
  13513. this.type = 'Group';
  13514. }
  13515. Group.prototype = Object.assign(Object.create(Object3D.prototype), {
  13516. constructor: Group,
  13517. isGroup: true
  13518. });
  13519. function WebXRController() {
  13520. this._targetRay = null;
  13521. this._grip = null;
  13522. this._hand = null;
  13523. }
  13524. Object.assign(WebXRController.prototype, {
  13525. constructor: WebXRController,
  13526. getHandSpace: function getHandSpace() {
  13527. if (this._hand === null) {
  13528. this._hand = new Group();
  13529. this._hand.matrixAutoUpdate = false;
  13530. this._hand.visible = false;
  13531. this._hand.joints = [];
  13532. this._hand.inputState = {
  13533. pinching: false
  13534. };
  13535. if (window.XRHand) {
  13536. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13537. // The transform of this joint will be updated with the joint pose on each frame
  13538. var joint = new Group();
  13539. joint.matrixAutoUpdate = false;
  13540. joint.visible = false;
  13541. this._hand.joints.push(joint); // ??
  13542. this._hand.add(joint);
  13543. }
  13544. }
  13545. }
  13546. return this._hand;
  13547. },
  13548. getTargetRaySpace: function getTargetRaySpace() {
  13549. if (this._targetRay === null) {
  13550. this._targetRay = new Group();
  13551. this._targetRay.matrixAutoUpdate = false;
  13552. this._targetRay.visible = false;
  13553. }
  13554. return this._targetRay;
  13555. },
  13556. getGripSpace: function getGripSpace() {
  13557. if (this._grip === null) {
  13558. this._grip = new Group();
  13559. this._grip.matrixAutoUpdate = false;
  13560. this._grip.visible = false;
  13561. }
  13562. return this._grip;
  13563. },
  13564. dispatchEvent: function dispatchEvent(event) {
  13565. if (this._targetRay !== null) {
  13566. this._targetRay.dispatchEvent(event);
  13567. }
  13568. if (this._grip !== null) {
  13569. this._grip.dispatchEvent(event);
  13570. }
  13571. if (this._hand !== null) {
  13572. this._hand.dispatchEvent(event);
  13573. }
  13574. return this;
  13575. },
  13576. disconnect: function disconnect(inputSource) {
  13577. this.dispatchEvent({
  13578. type: 'disconnected',
  13579. data: inputSource
  13580. });
  13581. if (this._targetRay !== null) {
  13582. this._targetRay.visible = false;
  13583. }
  13584. if (this._grip !== null) {
  13585. this._grip.visible = false;
  13586. }
  13587. if (this._hand !== null) {
  13588. this._hand.visible = false;
  13589. }
  13590. return this;
  13591. },
  13592. update: function update(inputSource, frame, referenceSpace) {
  13593. var inputPose = null;
  13594. var gripPose = null;
  13595. var handPose = null;
  13596. var targetRay = this._targetRay;
  13597. var grip = this._grip;
  13598. var hand = this._hand;
  13599. if (inputSource && frame.session.visibilityState !== 'visible-blurred') {
  13600. if (hand && inputSource.hand) {
  13601. handPose = true;
  13602. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13603. if (inputSource.hand[i]) {
  13604. // Update the joints groups with the XRJoint poses
  13605. var jointPose = frame.getJointPose(inputSource.hand[i], referenceSpace);
  13606. var joint = hand.joints[i];
  13607. if (jointPose !== null) {
  13608. joint.matrix.fromArray(jointPose.transform.matrix);
  13609. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  13610. joint.jointRadius = jointPose.radius;
  13611. }
  13612. joint.visible = jointPose !== null; // Custom events
  13613. // Check pinch
  13614. var indexTip = hand.joints[window.XRHand.INDEX_PHALANX_TIP];
  13615. var thumbTip = hand.joints[window.XRHand.THUMB_PHALANX_TIP];
  13616. var distance = indexTip.position.distanceTo(thumbTip.position);
  13617. var distanceToPinch = 0.02;
  13618. var threshold = 0.005;
  13619. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  13620. hand.inputState.pinching = false;
  13621. this.dispatchEvent({
  13622. type: 'pinchend',
  13623. handedness: inputSource.handedness,
  13624. target: this
  13625. });
  13626. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  13627. hand.inputState.pinching = true;
  13628. this.dispatchEvent({
  13629. type: 'pinchstart',
  13630. handedness: inputSource.handedness,
  13631. target: this
  13632. });
  13633. }
  13634. }
  13635. }
  13636. } else {
  13637. if (targetRay !== null) {
  13638. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  13639. if (inputPose !== null) {
  13640. targetRay.matrix.fromArray(inputPose.transform.matrix);
  13641. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  13642. }
  13643. }
  13644. if (grip !== null && inputSource.gripSpace) {
  13645. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  13646. if (gripPose !== null) {
  13647. grip.matrix.fromArray(gripPose.transform.matrix);
  13648. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  13649. }
  13650. }
  13651. }
  13652. }
  13653. if (targetRay !== null) {
  13654. targetRay.visible = inputPose !== null;
  13655. }
  13656. if (grip !== null) {
  13657. grip.visible = gripPose !== null;
  13658. }
  13659. if (hand !== null) {
  13660. hand.visible = handPose !== null;
  13661. }
  13662. return this;
  13663. }
  13664. });
  13665. function WebXRManager(renderer, gl) {
  13666. var scope = this;
  13667. var session = null;
  13668. var framebufferScaleFactor = 1.0;
  13669. var referenceSpace = null;
  13670. var referenceSpaceType = 'local-floor';
  13671. var pose = null;
  13672. var controllers = [];
  13673. var inputSourcesMap = new Map(); //
  13674. var cameraL = new PerspectiveCamera();
  13675. cameraL.layers.enable(1);
  13676. cameraL.viewport = new Vector4();
  13677. var cameraR = new PerspectiveCamera();
  13678. cameraR.layers.enable(2);
  13679. cameraR.viewport = new Vector4();
  13680. var cameras = [cameraL, cameraR];
  13681. var cameraVR = new ArrayCamera();
  13682. cameraVR.layers.enable(1);
  13683. cameraVR.layers.enable(2);
  13684. var _currentDepthNear = null;
  13685. var _currentDepthFar = null; //
  13686. this.enabled = false;
  13687. this.isPresenting = false;
  13688. this.getController = function (index) {
  13689. var controller = controllers[index];
  13690. if (controller === undefined) {
  13691. controller = new WebXRController();
  13692. controllers[index] = controller;
  13693. }
  13694. return controller.getTargetRaySpace();
  13695. };
  13696. this.getControllerGrip = function (index) {
  13697. var controller = controllers[index];
  13698. if (controller === undefined) {
  13699. controller = new WebXRController();
  13700. controllers[index] = controller;
  13701. }
  13702. return controller.getGripSpace();
  13703. };
  13704. this.getHand = function (index) {
  13705. var controller = controllers[index];
  13706. if (controller === undefined) {
  13707. controller = new WebXRController();
  13708. controllers[index] = controller;
  13709. }
  13710. return controller.getHandSpace();
  13711. }; //
  13712. function onSessionEvent(event) {
  13713. var controller = inputSourcesMap.get(event.inputSource);
  13714. if (controller) {
  13715. controller.dispatchEvent({
  13716. type: event.type,
  13717. data: event.inputSource
  13718. });
  13719. }
  13720. }
  13721. function onSessionEnd() {
  13722. inputSourcesMap.forEach(function (controller, inputSource) {
  13723. controller.disconnect(inputSource);
  13724. });
  13725. inputSourcesMap.clear(); //
  13726. renderer.setFramebuffer(null);
  13727. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  13728. animation.stop();
  13729. scope.isPresenting = false;
  13730. scope.dispatchEvent({
  13731. type: 'sessionend'
  13732. });
  13733. }
  13734. function onRequestReferenceSpace(value) {
  13735. referenceSpace = value;
  13736. animation.setContext(session);
  13737. animation.start();
  13738. scope.isPresenting = true;
  13739. scope.dispatchEvent({
  13740. type: 'sessionstart'
  13741. });
  13742. }
  13743. this.setFramebufferScaleFactor = function (value) {
  13744. framebufferScaleFactor = value;
  13745. if (scope.isPresenting === true) {
  13746. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  13747. }
  13748. };
  13749. this.setReferenceSpaceType = function (value) {
  13750. referenceSpaceType = value;
  13751. if (scope.isPresenting === true) {
  13752. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  13753. }
  13754. };
  13755. this.getReferenceSpace = function () {
  13756. return referenceSpace;
  13757. };
  13758. this.getSession = function () {
  13759. return session;
  13760. };
  13761. this.setSession = function (value) {
  13762. session = value;
  13763. if (session !== null) {
  13764. session.addEventListener('select', onSessionEvent);
  13765. session.addEventListener('selectstart', onSessionEvent);
  13766. session.addEventListener('selectend', onSessionEvent);
  13767. session.addEventListener('squeeze', onSessionEvent);
  13768. session.addEventListener('squeezestart', onSessionEvent);
  13769. session.addEventListener('squeezeend', onSessionEvent);
  13770. session.addEventListener('end', onSessionEnd);
  13771. var attributes = gl.getContextAttributes();
  13772. if (attributes.xrCompatible !== true) {
  13773. gl.makeXRCompatible();
  13774. }
  13775. var layerInit = {
  13776. antialias: attributes.antialias,
  13777. alpha: attributes.alpha,
  13778. depth: attributes.depth,
  13779. stencil: attributes.stencil,
  13780. framebufferScaleFactor: framebufferScaleFactor
  13781. }; // eslint-disable-next-line no-undef
  13782. var baseLayer = new XRWebGLLayer(session, gl, layerInit);
  13783. session.updateRenderState({
  13784. baseLayer: baseLayer
  13785. });
  13786. session.requestReferenceSpace(referenceSpaceType).then(onRequestReferenceSpace); //
  13787. session.addEventListener('inputsourceschange', updateInputSources);
  13788. }
  13789. };
  13790. function updateInputSources(event) {
  13791. var inputSources = session.inputSources; // Assign inputSources to available controllers
  13792. for (var i = 0; i < controllers.length; i++) {
  13793. inputSourcesMap.set(inputSources[i], controllers[i]);
  13794. } // Notify disconnected
  13795. for (var _i = 0; _i < event.removed.length; _i++) {
  13796. var inputSource = event.removed[_i];
  13797. var controller = inputSourcesMap.get(inputSource);
  13798. if (controller) {
  13799. controller.dispatchEvent({
  13800. type: 'disconnected',
  13801. data: inputSource
  13802. });
  13803. inputSourcesMap.delete(inputSource);
  13804. }
  13805. } // Notify connected
  13806. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  13807. var _inputSource = event.added[_i2];
  13808. var _controller = inputSourcesMap.get(_inputSource);
  13809. if (_controller) {
  13810. _controller.dispatchEvent({
  13811. type: 'connected',
  13812. data: _inputSource
  13813. });
  13814. }
  13815. }
  13816. } //
  13817. var cameraLPos = new Vector3();
  13818. var cameraRPos = new Vector3();
  13819. /**
  13820. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13821. * the cameras' projection and world matrices have already been set.
  13822. * And that near and far planes are identical for both cameras.
  13823. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13824. */
  13825. function setProjectionFromUnion(camera, cameraL, cameraR) {
  13826. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  13827. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  13828. var ipd = cameraLPos.distanceTo(cameraRPos);
  13829. var projL = cameraL.projectionMatrix.elements;
  13830. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  13831. // most likely identical top and bottom frustum extents.
  13832. // Use the left camera for these values.
  13833. var near = projL[14] / (projL[10] - 1);
  13834. var far = projL[14] / (projL[10] + 1);
  13835. var topFov = (projL[9] + 1) / projL[5];
  13836. var bottomFov = (projL[9] - 1) / projL[5];
  13837. var leftFov = (projL[8] - 1) / projL[0];
  13838. var rightFov = (projR[8] + 1) / projR[0];
  13839. var left = near * leftFov;
  13840. var right = near * rightFov; // Calculate the new camera's position offset from the
  13841. // left camera. xOffset should be roughly half `ipd`.
  13842. var zOffset = ipd / (-leftFov + rightFov);
  13843. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  13844. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  13845. camera.translateX(xOffset);
  13846. camera.translateZ(zOffset);
  13847. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  13848. camera.matrixWorldInverse.copy(camera.matrixWorld).invert(); // Find the union of the frustum values of the cameras and scale
  13849. // the values so that the near plane's position does not change in world space,
  13850. // although must now be relative to the new union camera.
  13851. var near2 = near + zOffset;
  13852. var far2 = far + zOffset;
  13853. var left2 = left - xOffset;
  13854. var right2 = right + (ipd - xOffset);
  13855. var top2 = topFov * far / far2 * near2;
  13856. var bottom2 = bottomFov * far / far2 * near2;
  13857. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  13858. }
  13859. function updateCamera(camera, parent) {
  13860. if (parent === null) {
  13861. camera.matrixWorld.copy(camera.matrix);
  13862. } else {
  13863. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  13864. }
  13865. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  13866. }
  13867. this.getCamera = function (camera) {
  13868. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  13869. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  13870. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  13871. // Note that the new renderState won't apply until the next frame. See #18320
  13872. session.updateRenderState({
  13873. depthNear: cameraVR.near,
  13874. depthFar: cameraVR.far
  13875. });
  13876. _currentDepthNear = cameraVR.near;
  13877. _currentDepthFar = cameraVR.far;
  13878. }
  13879. var parent = camera.parent;
  13880. var cameras = cameraVR.cameras;
  13881. updateCamera(cameraVR, parent);
  13882. for (var i = 0; i < cameras.length; i++) {
  13883. updateCamera(cameras[i], parent);
  13884. } // update camera and its children
  13885. camera.matrixWorld.copy(cameraVR.matrixWorld);
  13886. var children = camera.children;
  13887. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  13888. children[_i3].updateMatrixWorld(true);
  13889. } // update projection matrix for proper view frustum culling
  13890. if (cameras.length === 2) {
  13891. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  13892. } else {
  13893. // assume single camera setup (AR)
  13894. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  13895. }
  13896. return cameraVR;
  13897. }; // Animation Loop
  13898. var onAnimationFrameCallback = null;
  13899. function onAnimationFrame(time, frame) {
  13900. pose = frame.getViewerPose(referenceSpace);
  13901. if (pose !== null) {
  13902. var views = pose.views;
  13903. var baseLayer = session.renderState.baseLayer;
  13904. renderer.setFramebuffer(baseLayer.framebuffer);
  13905. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  13906. if (views.length !== cameraVR.cameras.length) {
  13907. cameraVR.cameras.length = 0;
  13908. cameraVRNeedsUpdate = true;
  13909. }
  13910. for (var i = 0; i < views.length; i++) {
  13911. var view = views[i];
  13912. var viewport = baseLayer.getViewport(view);
  13913. var camera = cameras[i];
  13914. camera.matrix.fromArray(view.transform.matrix);
  13915. camera.projectionMatrix.fromArray(view.projectionMatrix);
  13916. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  13917. if (i === 0) {
  13918. cameraVR.matrix.copy(camera.matrix);
  13919. }
  13920. if (cameraVRNeedsUpdate === true) {
  13921. cameraVR.cameras.push(camera);
  13922. }
  13923. }
  13924. } //
  13925. var inputSources = session.inputSources;
  13926. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  13927. var controller = controllers[_i4];
  13928. var inputSource = inputSources[_i4];
  13929. controller.update(inputSource, frame, referenceSpace);
  13930. }
  13931. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  13932. }
  13933. var animation = new WebGLAnimation();
  13934. animation.setAnimationLoop(onAnimationFrame);
  13935. this.setAnimationLoop = function (callback) {
  13936. onAnimationFrameCallback = callback;
  13937. };
  13938. this.dispose = function () {};
  13939. }
  13940. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  13941. function WebGLMaterials(properties) {
  13942. function refreshFogUniforms(uniforms, fog) {
  13943. uniforms.fogColor.value.copy(fog.color);
  13944. if (fog.isFog) {
  13945. uniforms.fogNear.value = fog.near;
  13946. uniforms.fogFar.value = fog.far;
  13947. } else if (fog.isFogExp2) {
  13948. uniforms.fogDensity.value = fog.density;
  13949. }
  13950. }
  13951. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  13952. if (material.isMeshBasicMaterial) {
  13953. refreshUniformsCommon(uniforms, material);
  13954. } else if (material.isMeshLambertMaterial) {
  13955. refreshUniformsCommon(uniforms, material);
  13956. refreshUniformsLambert(uniforms, material);
  13957. } else if (material.isMeshToonMaterial) {
  13958. refreshUniformsCommon(uniforms, material);
  13959. refreshUniformsToon(uniforms, material);
  13960. } else if (material.isMeshPhongMaterial) {
  13961. refreshUniformsCommon(uniforms, material);
  13962. refreshUniformsPhong(uniforms, material);
  13963. } else if (material.isMeshStandardMaterial) {
  13964. refreshUniformsCommon(uniforms, material);
  13965. if (material.isMeshPhysicalMaterial) {
  13966. refreshUniformsPhysical(uniforms, material);
  13967. } else {
  13968. refreshUniformsStandard(uniforms, material);
  13969. }
  13970. } else if (material.isMeshMatcapMaterial) {
  13971. refreshUniformsCommon(uniforms, material);
  13972. refreshUniformsMatcap(uniforms, material);
  13973. } else if (material.isMeshDepthMaterial) {
  13974. refreshUniformsCommon(uniforms, material);
  13975. refreshUniformsDepth(uniforms, material);
  13976. } else if (material.isMeshDistanceMaterial) {
  13977. refreshUniformsCommon(uniforms, material);
  13978. refreshUniformsDistance(uniforms, material);
  13979. } else if (material.isMeshNormalMaterial) {
  13980. refreshUniformsCommon(uniforms, material);
  13981. refreshUniformsNormal(uniforms, material);
  13982. } else if (material.isLineBasicMaterial) {
  13983. refreshUniformsLine(uniforms, material);
  13984. if (material.isLineDashedMaterial) {
  13985. refreshUniformsDash(uniforms, material);
  13986. }
  13987. } else if (material.isPointsMaterial) {
  13988. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  13989. } else if (material.isSpriteMaterial) {
  13990. refreshUniformsSprites(uniforms, material);
  13991. } else if (material.isShadowMaterial) {
  13992. uniforms.color.value.copy(material.color);
  13993. uniforms.opacity.value = material.opacity;
  13994. } else if (material.isShaderMaterial) {
  13995. material.uniformsNeedUpdate = false; // #15581
  13996. }
  13997. }
  13998. function refreshUniformsCommon(uniforms, material) {
  13999. uniforms.opacity.value = material.opacity;
  14000. if (material.color) {
  14001. uniforms.diffuse.value.copy(material.color);
  14002. }
  14003. if (material.emissive) {
  14004. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  14005. }
  14006. if (material.map) {
  14007. uniforms.map.value = material.map;
  14008. }
  14009. if (material.alphaMap) {
  14010. uniforms.alphaMap.value = material.alphaMap;
  14011. }
  14012. if (material.specularMap) {
  14013. uniforms.specularMap.value = material.specularMap;
  14014. }
  14015. var envMap = properties.get(material).envMap;
  14016. if (envMap) {
  14017. uniforms.envMap.value = envMap;
  14018. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  14019. uniforms.reflectivity.value = material.reflectivity;
  14020. uniforms.refractionRatio.value = material.refractionRatio;
  14021. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  14022. if (maxMipLevel !== undefined) {
  14023. uniforms.maxMipLevel.value = maxMipLevel;
  14024. }
  14025. }
  14026. if (material.lightMap) {
  14027. uniforms.lightMap.value = material.lightMap;
  14028. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14029. }
  14030. if (material.aoMap) {
  14031. uniforms.aoMap.value = material.aoMap;
  14032. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14033. } // uv repeat and offset setting priorities
  14034. // 1. color map
  14035. // 2. specular map
  14036. // 3. displacementMap map
  14037. // 4. normal map
  14038. // 5. bump map
  14039. // 6. roughnessMap map
  14040. // 7. metalnessMap map
  14041. // 8. alphaMap map
  14042. // 9. emissiveMap map
  14043. // 10. clearcoat map
  14044. // 11. clearcoat normal map
  14045. // 12. clearcoat roughnessMap map
  14046. var uvScaleMap;
  14047. if (material.map) {
  14048. uvScaleMap = material.map;
  14049. } else if (material.specularMap) {
  14050. uvScaleMap = material.specularMap;
  14051. } else if (material.displacementMap) {
  14052. uvScaleMap = material.displacementMap;
  14053. } else if (material.normalMap) {
  14054. uvScaleMap = material.normalMap;
  14055. } else if (material.bumpMap) {
  14056. uvScaleMap = material.bumpMap;
  14057. } else if (material.roughnessMap) {
  14058. uvScaleMap = material.roughnessMap;
  14059. } else if (material.metalnessMap) {
  14060. uvScaleMap = material.metalnessMap;
  14061. } else if (material.alphaMap) {
  14062. uvScaleMap = material.alphaMap;
  14063. } else if (material.emissiveMap) {
  14064. uvScaleMap = material.emissiveMap;
  14065. } else if (material.clearcoatMap) {
  14066. uvScaleMap = material.clearcoatMap;
  14067. } else if (material.clearcoatNormalMap) {
  14068. uvScaleMap = material.clearcoatNormalMap;
  14069. } else if (material.clearcoatRoughnessMap) {
  14070. uvScaleMap = material.clearcoatRoughnessMap;
  14071. }
  14072. if (uvScaleMap !== undefined) {
  14073. // backwards compatibility
  14074. if (uvScaleMap.isWebGLRenderTarget) {
  14075. uvScaleMap = uvScaleMap.texture;
  14076. }
  14077. if (uvScaleMap.matrixAutoUpdate === true) {
  14078. uvScaleMap.updateMatrix();
  14079. }
  14080. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14081. } // uv repeat and offset setting priorities for uv2
  14082. // 1. ao map
  14083. // 2. light map
  14084. var uv2ScaleMap;
  14085. if (material.aoMap) {
  14086. uv2ScaleMap = material.aoMap;
  14087. } else if (material.lightMap) {
  14088. uv2ScaleMap = material.lightMap;
  14089. }
  14090. if (uv2ScaleMap !== undefined) {
  14091. // backwards compatibility
  14092. if (uv2ScaleMap.isWebGLRenderTarget) {
  14093. uv2ScaleMap = uv2ScaleMap.texture;
  14094. }
  14095. if (uv2ScaleMap.matrixAutoUpdate === true) {
  14096. uv2ScaleMap.updateMatrix();
  14097. }
  14098. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  14099. }
  14100. }
  14101. function refreshUniformsLine(uniforms, material) {
  14102. uniforms.diffuse.value.copy(material.color);
  14103. uniforms.opacity.value = material.opacity;
  14104. }
  14105. function refreshUniformsDash(uniforms, material) {
  14106. uniforms.dashSize.value = material.dashSize;
  14107. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14108. uniforms.scale.value = material.scale;
  14109. }
  14110. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  14111. uniforms.diffuse.value.copy(material.color);
  14112. uniforms.opacity.value = material.opacity;
  14113. uniforms.size.value = material.size * pixelRatio;
  14114. uniforms.scale.value = height * 0.5;
  14115. if (material.map) {
  14116. uniforms.map.value = material.map;
  14117. }
  14118. if (material.alphaMap) {
  14119. uniforms.alphaMap.value = material.alphaMap;
  14120. } // uv repeat and offset setting priorities
  14121. // 1. color map
  14122. // 2. alpha map
  14123. var uvScaleMap;
  14124. if (material.map) {
  14125. uvScaleMap = material.map;
  14126. } else if (material.alphaMap) {
  14127. uvScaleMap = material.alphaMap;
  14128. }
  14129. if (uvScaleMap !== undefined) {
  14130. if (uvScaleMap.matrixAutoUpdate === true) {
  14131. uvScaleMap.updateMatrix();
  14132. }
  14133. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14134. }
  14135. }
  14136. function refreshUniformsSprites(uniforms, material) {
  14137. uniforms.diffuse.value.copy(material.color);
  14138. uniforms.opacity.value = material.opacity;
  14139. uniforms.rotation.value = material.rotation;
  14140. if (material.map) {
  14141. uniforms.map.value = material.map;
  14142. }
  14143. if (material.alphaMap) {
  14144. uniforms.alphaMap.value = material.alphaMap;
  14145. } // uv repeat and offset setting priorities
  14146. // 1. color map
  14147. // 2. alpha map
  14148. var uvScaleMap;
  14149. if (material.map) {
  14150. uvScaleMap = material.map;
  14151. } else if (material.alphaMap) {
  14152. uvScaleMap = material.alphaMap;
  14153. }
  14154. if (uvScaleMap !== undefined) {
  14155. if (uvScaleMap.matrixAutoUpdate === true) {
  14156. uvScaleMap.updateMatrix();
  14157. }
  14158. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14159. }
  14160. }
  14161. function refreshUniformsLambert(uniforms, material) {
  14162. if (material.emissiveMap) {
  14163. uniforms.emissiveMap.value = material.emissiveMap;
  14164. }
  14165. }
  14166. function refreshUniformsPhong(uniforms, material) {
  14167. uniforms.specular.value.copy(material.specular);
  14168. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  14169. if (material.emissiveMap) {
  14170. uniforms.emissiveMap.value = material.emissiveMap;
  14171. }
  14172. if (material.bumpMap) {
  14173. uniforms.bumpMap.value = material.bumpMap;
  14174. uniforms.bumpScale.value = material.bumpScale;
  14175. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14176. }
  14177. if (material.normalMap) {
  14178. uniforms.normalMap.value = material.normalMap;
  14179. uniforms.normalScale.value.copy(material.normalScale);
  14180. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14181. }
  14182. if (material.displacementMap) {
  14183. uniforms.displacementMap.value = material.displacementMap;
  14184. uniforms.displacementScale.value = material.displacementScale;
  14185. uniforms.displacementBias.value = material.displacementBias;
  14186. }
  14187. }
  14188. function refreshUniformsToon(uniforms, material) {
  14189. if (material.gradientMap) {
  14190. uniforms.gradientMap.value = material.gradientMap;
  14191. }
  14192. if (material.emissiveMap) {
  14193. uniforms.emissiveMap.value = material.emissiveMap;
  14194. }
  14195. if (material.bumpMap) {
  14196. uniforms.bumpMap.value = material.bumpMap;
  14197. uniforms.bumpScale.value = material.bumpScale;
  14198. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14199. }
  14200. if (material.normalMap) {
  14201. uniforms.normalMap.value = material.normalMap;
  14202. uniforms.normalScale.value.copy(material.normalScale);
  14203. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14204. }
  14205. if (material.displacementMap) {
  14206. uniforms.displacementMap.value = material.displacementMap;
  14207. uniforms.displacementScale.value = material.displacementScale;
  14208. uniforms.displacementBias.value = material.displacementBias;
  14209. }
  14210. }
  14211. function refreshUniformsStandard(uniforms, material) {
  14212. uniforms.roughness.value = material.roughness;
  14213. uniforms.metalness.value = material.metalness;
  14214. if (material.roughnessMap) {
  14215. uniforms.roughnessMap.value = material.roughnessMap;
  14216. }
  14217. if (material.metalnessMap) {
  14218. uniforms.metalnessMap.value = material.metalnessMap;
  14219. }
  14220. if (material.emissiveMap) {
  14221. uniforms.emissiveMap.value = material.emissiveMap;
  14222. }
  14223. if (material.bumpMap) {
  14224. uniforms.bumpMap.value = material.bumpMap;
  14225. uniforms.bumpScale.value = material.bumpScale;
  14226. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14227. }
  14228. if (material.normalMap) {
  14229. uniforms.normalMap.value = material.normalMap;
  14230. uniforms.normalScale.value.copy(material.normalScale);
  14231. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14232. }
  14233. if (material.displacementMap) {
  14234. uniforms.displacementMap.value = material.displacementMap;
  14235. uniforms.displacementScale.value = material.displacementScale;
  14236. uniforms.displacementBias.value = material.displacementBias;
  14237. }
  14238. var envMap = properties.get(material).envMap;
  14239. if (envMap) {
  14240. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14241. uniforms.envMapIntensity.value = material.envMapIntensity;
  14242. }
  14243. }
  14244. function refreshUniformsPhysical(uniforms, material) {
  14245. refreshUniformsStandard(uniforms, material);
  14246. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14247. uniforms.clearcoat.value = material.clearcoat;
  14248. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14249. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14250. if (material.clearcoatMap) {
  14251. uniforms.clearcoatMap.value = material.clearcoatMap;
  14252. }
  14253. if (material.clearcoatRoughnessMap) {
  14254. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14255. }
  14256. if (material.clearcoatNormalMap) {
  14257. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14258. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14259. if (material.side === BackSide) {
  14260. uniforms.clearcoatNormalScale.value.negate();
  14261. }
  14262. }
  14263. uniforms.transmission.value = material.transmission;
  14264. if (material.transmissionMap) {
  14265. uniforms.transmissionMap.value = material.transmissionMap;
  14266. }
  14267. }
  14268. function refreshUniformsMatcap(uniforms, material) {
  14269. if (material.matcap) {
  14270. uniforms.matcap.value = material.matcap;
  14271. }
  14272. if (material.bumpMap) {
  14273. uniforms.bumpMap.value = material.bumpMap;
  14274. uniforms.bumpScale.value = material.bumpScale;
  14275. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14276. }
  14277. if (material.normalMap) {
  14278. uniforms.normalMap.value = material.normalMap;
  14279. uniforms.normalScale.value.copy(material.normalScale);
  14280. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14281. }
  14282. if (material.displacementMap) {
  14283. uniforms.displacementMap.value = material.displacementMap;
  14284. uniforms.displacementScale.value = material.displacementScale;
  14285. uniforms.displacementBias.value = material.displacementBias;
  14286. }
  14287. }
  14288. function refreshUniformsDepth(uniforms, material) {
  14289. if (material.displacementMap) {
  14290. uniforms.displacementMap.value = material.displacementMap;
  14291. uniforms.displacementScale.value = material.displacementScale;
  14292. uniforms.displacementBias.value = material.displacementBias;
  14293. }
  14294. }
  14295. function refreshUniformsDistance(uniforms, material) {
  14296. if (material.displacementMap) {
  14297. uniforms.displacementMap.value = material.displacementMap;
  14298. uniforms.displacementScale.value = material.displacementScale;
  14299. uniforms.displacementBias.value = material.displacementBias;
  14300. }
  14301. uniforms.referencePosition.value.copy(material.referencePosition);
  14302. uniforms.nearDistance.value = material.nearDistance;
  14303. uniforms.farDistance.value = material.farDistance;
  14304. }
  14305. function refreshUniformsNormal(uniforms, material) {
  14306. if (material.bumpMap) {
  14307. uniforms.bumpMap.value = material.bumpMap;
  14308. uniforms.bumpScale.value = material.bumpScale;
  14309. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14310. }
  14311. if (material.normalMap) {
  14312. uniforms.normalMap.value = material.normalMap;
  14313. uniforms.normalScale.value.copy(material.normalScale);
  14314. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14315. }
  14316. if (material.displacementMap) {
  14317. uniforms.displacementMap.value = material.displacementMap;
  14318. uniforms.displacementScale.value = material.displacementScale;
  14319. uniforms.displacementBias.value = material.displacementBias;
  14320. }
  14321. }
  14322. return {
  14323. refreshFogUniforms: refreshFogUniforms,
  14324. refreshMaterialUniforms: refreshMaterialUniforms
  14325. };
  14326. }
  14327. function createCanvasElement() {
  14328. var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  14329. canvas.style.display = 'block';
  14330. return canvas;
  14331. }
  14332. function WebGLRenderer(parameters) {
  14333. parameters = parameters || {};
  14334. var _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  14335. _context = parameters.context !== undefined ? parameters.context : null,
  14336. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14337. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14338. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14339. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14340. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14341. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14342. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14343. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14344. var currentRenderList = null;
  14345. var currentRenderState = null; // render() can be called from within a callback triggered by another render.
  14346. // We track this so that the nested render call gets its state isolated from the parent render call.
  14347. var renderStateStack = []; // public properties
  14348. this.domElement = _canvas; // Debug configuration container
  14349. this.debug = {
  14350. /**
  14351. * Enables error checking and reporting when shader programs are being compiled
  14352. * @type {boolean}
  14353. */
  14354. checkShaderErrors: true
  14355. }; // clearing
  14356. this.autoClear = true;
  14357. this.autoClearColor = true;
  14358. this.autoClearDepth = true;
  14359. this.autoClearStencil = true; // scene graph
  14360. this.sortObjects = true; // user-defined clipping
  14361. this.clippingPlanes = [];
  14362. this.localClippingEnabled = false; // physically based shading
  14363. this.gammaFactor = 2.0; // for backwards compatibility
  14364. this.outputEncoding = LinearEncoding; // physical lights
  14365. this.physicallyCorrectLights = false; // tone mapping
  14366. this.toneMapping = NoToneMapping;
  14367. this.toneMappingExposure = 1.0; // morphs
  14368. this.maxMorphTargets = 8;
  14369. this.maxMorphNormals = 4; // internal properties
  14370. var _this = this;
  14371. var _isContextLost = false; // internal state cache
  14372. var _framebuffer = null;
  14373. var _currentActiveCubeFace = 0;
  14374. var _currentActiveMipmapLevel = 0;
  14375. var _currentRenderTarget = null;
  14376. var _currentFramebuffer = null;
  14377. var _currentMaterialId = -1;
  14378. var _currentCamera = null;
  14379. var _currentViewport = new Vector4();
  14380. var _currentScissor = new Vector4();
  14381. var _currentScissorTest = null; //
  14382. var _width = _canvas.width;
  14383. var _height = _canvas.height;
  14384. var _pixelRatio = 1;
  14385. var _opaqueSort = null;
  14386. var _transparentSort = null;
  14387. var _viewport = new Vector4(0, 0, _width, _height);
  14388. var _scissor = new Vector4(0, 0, _width, _height);
  14389. var _scissorTest = false; // frustum
  14390. var _frustum = new Frustum(); // clipping
  14391. var _clippingEnabled = false;
  14392. var _localClippingEnabled = false; // camera matrices cache
  14393. var _projScreenMatrix = new Matrix4();
  14394. var _vector3 = new Vector3();
  14395. var _emptyScene = {
  14396. background: null,
  14397. fog: null,
  14398. environment: null,
  14399. overrideMaterial: null,
  14400. isScene: true
  14401. };
  14402. function getTargetPixelRatio() {
  14403. return _currentRenderTarget === null ? _pixelRatio : 1;
  14404. } // initialize
  14405. var _gl = _context;
  14406. function getContext(contextNames, contextAttributes) {
  14407. for (var i = 0; i < contextNames.length; i++) {
  14408. var contextName = contextNames[i];
  14409. var context = _canvas.getContext(contextName, contextAttributes);
  14410. if (context !== null) return context;
  14411. }
  14412. return null;
  14413. }
  14414. try {
  14415. var contextAttributes = {
  14416. alpha: _alpha,
  14417. depth: _depth,
  14418. stencil: _stencil,
  14419. antialias: _antialias,
  14420. premultipliedAlpha: _premultipliedAlpha,
  14421. preserveDrawingBuffer: _preserveDrawingBuffer,
  14422. powerPreference: _powerPreference,
  14423. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14424. }; // event listeners must be registered before WebGL context is created, see #12753
  14425. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  14426. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  14427. if (_gl === null) {
  14428. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  14429. if (_this.isWebGL1Renderer === true) {
  14430. contextNames.shift();
  14431. }
  14432. _gl = getContext(contextNames, contextAttributes);
  14433. if (_gl === null) {
  14434. if (getContext(contextNames)) {
  14435. throw new Error('Error creating WebGL context with your selected attributes.');
  14436. } else {
  14437. throw new Error('Error creating WebGL context.');
  14438. }
  14439. }
  14440. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14441. if (_gl.getShaderPrecisionFormat === undefined) {
  14442. _gl.getShaderPrecisionFormat = function () {
  14443. return {
  14444. 'rangeMin': 1,
  14445. 'rangeMax': 1,
  14446. 'precision': 1
  14447. };
  14448. };
  14449. }
  14450. } catch (error) {
  14451. console.error('THREE.WebGLRenderer: ' + error.message);
  14452. throw error;
  14453. }
  14454. var extensions, capabilities, state, info;
  14455. var properties, textures, cubemaps, attributes, geometries, objects;
  14456. var programCache, materials, renderLists, renderStates, clipping;
  14457. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14458. var utils, bindingStates;
  14459. function initGLContext() {
  14460. extensions = new WebGLExtensions(_gl);
  14461. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  14462. if (capabilities.isWebGL2 === false) {
  14463. extensions.get('WEBGL_depth_texture');
  14464. extensions.get('OES_texture_float');
  14465. extensions.get('OES_texture_half_float');
  14466. extensions.get('OES_texture_half_float_linear');
  14467. extensions.get('OES_standard_derivatives');
  14468. extensions.get('OES_element_index_uint');
  14469. extensions.get('OES_vertex_array_object');
  14470. extensions.get('ANGLE_instanced_arrays');
  14471. }
  14472. extensions.get('OES_texture_float_linear');
  14473. utils = new WebGLUtils(_gl, extensions, capabilities);
  14474. state = new WebGLState(_gl, extensions, capabilities);
  14475. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14476. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14477. info = new WebGLInfo(_gl);
  14478. properties = new WebGLProperties();
  14479. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  14480. cubemaps = new WebGLCubeMaps(_this);
  14481. attributes = new WebGLAttributes(_gl, capabilities);
  14482. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  14483. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  14484. objects = new WebGLObjects(_gl, geometries, attributes, info);
  14485. morphtargets = new WebGLMorphtargets(_gl);
  14486. clipping = new WebGLClipping(properties);
  14487. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  14488. materials = new WebGLMaterials(properties);
  14489. renderLists = new WebGLRenderLists(properties);
  14490. renderStates = new WebGLRenderStates(extensions, capabilities);
  14491. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  14492. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  14493. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  14494. info.programs = programCache.programs;
  14495. _this.capabilities = capabilities;
  14496. _this.extensions = extensions;
  14497. _this.properties = properties;
  14498. _this.renderLists = renderLists;
  14499. _this.state = state;
  14500. _this.info = info;
  14501. }
  14502. initGLContext(); // xr
  14503. var xr = new WebXRManager(_this, _gl);
  14504. this.xr = xr; // shadow map
  14505. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  14506. this.shadowMap = shadowMap; // API
  14507. this.getContext = function () {
  14508. return _gl;
  14509. };
  14510. this.getContextAttributes = function () {
  14511. return _gl.getContextAttributes();
  14512. };
  14513. this.forceContextLoss = function () {
  14514. var extension = extensions.get('WEBGL_lose_context');
  14515. if (extension) extension.loseContext();
  14516. };
  14517. this.forceContextRestore = function () {
  14518. var extension = extensions.get('WEBGL_lose_context');
  14519. if (extension) extension.restoreContext();
  14520. };
  14521. this.getPixelRatio = function () {
  14522. return _pixelRatio;
  14523. };
  14524. this.setPixelRatio = function (value) {
  14525. if (value === undefined) return;
  14526. _pixelRatio = value;
  14527. this.setSize(_width, _height, false);
  14528. };
  14529. this.getSize = function (target) {
  14530. if (target === undefined) {
  14531. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  14532. target = new Vector2();
  14533. }
  14534. return target.set(_width, _height);
  14535. };
  14536. this.setSize = function (width, height, updateStyle) {
  14537. if (xr.isPresenting) {
  14538. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  14539. return;
  14540. }
  14541. _width = width;
  14542. _height = height;
  14543. _canvas.width = Math.floor(width * _pixelRatio);
  14544. _canvas.height = Math.floor(height * _pixelRatio);
  14545. if (updateStyle !== false) {
  14546. _canvas.style.width = width + 'px';
  14547. _canvas.style.height = height + 'px';
  14548. }
  14549. this.setViewport(0, 0, width, height);
  14550. };
  14551. this.getDrawingBufferSize = function (target) {
  14552. if (target === undefined) {
  14553. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  14554. target = new Vector2();
  14555. }
  14556. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  14557. };
  14558. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  14559. _width = width;
  14560. _height = height;
  14561. _pixelRatio = pixelRatio;
  14562. _canvas.width = Math.floor(width * pixelRatio);
  14563. _canvas.height = Math.floor(height * pixelRatio);
  14564. this.setViewport(0, 0, width, height);
  14565. };
  14566. this.getCurrentViewport = function (target) {
  14567. if (target === undefined) {
  14568. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  14569. target = new Vector4();
  14570. }
  14571. return target.copy(_currentViewport);
  14572. };
  14573. this.getViewport = function (target) {
  14574. return target.copy(_viewport);
  14575. };
  14576. this.setViewport = function (x, y, width, height) {
  14577. if (x.isVector4) {
  14578. _viewport.set(x.x, x.y, x.z, x.w);
  14579. } else {
  14580. _viewport.set(x, y, width, height);
  14581. }
  14582. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14583. };
  14584. this.getScissor = function (target) {
  14585. return target.copy(_scissor);
  14586. };
  14587. this.setScissor = function (x, y, width, height) {
  14588. if (x.isVector4) {
  14589. _scissor.set(x.x, x.y, x.z, x.w);
  14590. } else {
  14591. _scissor.set(x, y, width, height);
  14592. }
  14593. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14594. };
  14595. this.getScissorTest = function () {
  14596. return _scissorTest;
  14597. };
  14598. this.setScissorTest = function (boolean) {
  14599. state.setScissorTest(_scissorTest = boolean);
  14600. };
  14601. this.setOpaqueSort = function (method) {
  14602. _opaqueSort = method;
  14603. };
  14604. this.setTransparentSort = function (method) {
  14605. _transparentSort = method;
  14606. }; // Clearing
  14607. this.getClearColor = function (target) {
  14608. if (target === undefined) {
  14609. console.warn('WebGLRenderer: .getClearColor() now requires a Color as an argument');
  14610. target = new Color();
  14611. }
  14612. return target.copy(background.getClearColor());
  14613. };
  14614. this.setClearColor = function () {
  14615. background.setClearColor.apply(background, arguments);
  14616. };
  14617. this.getClearAlpha = function () {
  14618. return background.getClearAlpha();
  14619. };
  14620. this.setClearAlpha = function () {
  14621. background.setClearAlpha.apply(background, arguments);
  14622. };
  14623. this.clear = function (color, depth, stencil) {
  14624. var bits = 0;
  14625. if (color === undefined || color) bits |= 16384;
  14626. if (depth === undefined || depth) bits |= 256;
  14627. if (stencil === undefined || stencil) bits |= 1024;
  14628. _gl.clear(bits);
  14629. };
  14630. this.clearColor = function () {
  14631. this.clear(true, false, false);
  14632. };
  14633. this.clearDepth = function () {
  14634. this.clear(false, true, false);
  14635. };
  14636. this.clearStencil = function () {
  14637. this.clear(false, false, true);
  14638. }; //
  14639. this.dispose = function () {
  14640. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  14641. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  14642. renderLists.dispose();
  14643. renderStates.dispose();
  14644. properties.dispose();
  14645. cubemaps.dispose();
  14646. objects.dispose();
  14647. bindingStates.dispose();
  14648. xr.dispose();
  14649. animation.stop();
  14650. }; // Events
  14651. function onContextLost(event) {
  14652. event.preventDefault();
  14653. console.log('THREE.WebGLRenderer: Context Lost.');
  14654. _isContextLost = true;
  14655. }
  14656. function onContextRestore()
  14657. /* event */
  14658. {
  14659. console.log('THREE.WebGLRenderer: Context Restored.');
  14660. _isContextLost = false;
  14661. initGLContext();
  14662. }
  14663. function onMaterialDispose(event) {
  14664. var material = event.target;
  14665. material.removeEventListener('dispose', onMaterialDispose);
  14666. deallocateMaterial(material);
  14667. } // Buffer deallocation
  14668. function deallocateMaterial(material) {
  14669. releaseMaterialProgramReference(material);
  14670. properties.remove(material);
  14671. }
  14672. function releaseMaterialProgramReference(material) {
  14673. var programInfo = properties.get(material).program;
  14674. if (programInfo !== undefined) {
  14675. programCache.releaseProgram(programInfo);
  14676. }
  14677. } // Buffer rendering
  14678. function renderObjectImmediate(object, program) {
  14679. object.render(function (object) {
  14680. _this.renderBufferImmediate(object, program);
  14681. });
  14682. }
  14683. this.renderBufferImmediate = function (object, program) {
  14684. bindingStates.initAttributes();
  14685. var buffers = properties.get(object);
  14686. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  14687. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  14688. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  14689. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  14690. var programAttributes = program.getAttributes();
  14691. if (object.hasPositions) {
  14692. _gl.bindBuffer(34962, buffers.position);
  14693. _gl.bufferData(34962, object.positionArray, 35048);
  14694. bindingStates.enableAttribute(programAttributes.position);
  14695. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  14696. }
  14697. if (object.hasNormals) {
  14698. _gl.bindBuffer(34962, buffers.normal);
  14699. _gl.bufferData(34962, object.normalArray, 35048);
  14700. bindingStates.enableAttribute(programAttributes.normal);
  14701. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  14702. }
  14703. if (object.hasUvs) {
  14704. _gl.bindBuffer(34962, buffers.uv);
  14705. _gl.bufferData(34962, object.uvArray, 35048);
  14706. bindingStates.enableAttribute(programAttributes.uv);
  14707. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  14708. }
  14709. if (object.hasColors) {
  14710. _gl.bindBuffer(34962, buffers.color);
  14711. _gl.bufferData(34962, object.colorArray, 35048);
  14712. bindingStates.enableAttribute(programAttributes.color);
  14713. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  14714. }
  14715. bindingStates.disableUnusedAttributes();
  14716. _gl.drawArrays(4, 0, object.count);
  14717. object.count = 0;
  14718. };
  14719. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  14720. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  14721. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  14722. var program = setProgram(camera, scene, material, object);
  14723. state.setMaterial(material, frontFaceCW); //
  14724. var index = geometry.index;
  14725. var position = geometry.attributes.position; //
  14726. if (index === null) {
  14727. if (position === undefined || position.count === 0) return;
  14728. } else if (index.count === 0) {
  14729. return;
  14730. } //
  14731. var rangeFactor = 1;
  14732. if (material.wireframe === true) {
  14733. index = geometries.getWireframeAttribute(geometry);
  14734. rangeFactor = 2;
  14735. }
  14736. if (material.morphTargets || material.morphNormals) {
  14737. morphtargets.update(object, geometry, material, program);
  14738. }
  14739. bindingStates.setup(object, material, program, geometry, index);
  14740. var attribute;
  14741. var renderer = bufferRenderer;
  14742. if (index !== null) {
  14743. attribute = attributes.get(index);
  14744. renderer = indexedBufferRenderer;
  14745. renderer.setIndex(attribute);
  14746. } //
  14747. var dataCount = index !== null ? index.count : position.count;
  14748. var rangeStart = geometry.drawRange.start * rangeFactor;
  14749. var rangeCount = geometry.drawRange.count * rangeFactor;
  14750. var groupStart = group !== null ? group.start * rangeFactor : 0;
  14751. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14752. var drawStart = Math.max(rangeStart, groupStart);
  14753. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  14754. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  14755. if (drawCount === 0) return; //
  14756. if (object.isMesh) {
  14757. if (material.wireframe === true) {
  14758. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  14759. renderer.setMode(1);
  14760. } else {
  14761. renderer.setMode(4);
  14762. }
  14763. } else if (object.isLine) {
  14764. var lineWidth = material.linewidth;
  14765. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  14766. state.setLineWidth(lineWidth * getTargetPixelRatio());
  14767. if (object.isLineSegments) {
  14768. renderer.setMode(1);
  14769. } else if (object.isLineLoop) {
  14770. renderer.setMode(2);
  14771. } else {
  14772. renderer.setMode(3);
  14773. }
  14774. } else if (object.isPoints) {
  14775. renderer.setMode(0);
  14776. } else if (object.isSprite) {
  14777. renderer.setMode(4);
  14778. }
  14779. if (object.isInstancedMesh) {
  14780. renderer.renderInstances(drawStart, drawCount, object.count);
  14781. } else if (geometry.isInstancedBufferGeometry) {
  14782. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  14783. renderer.renderInstances(drawStart, drawCount, instanceCount);
  14784. } else {
  14785. renderer.render(drawStart, drawCount);
  14786. }
  14787. }; // Compile
  14788. this.compile = function (scene, camera) {
  14789. currentRenderState = renderStates.get(scene);
  14790. currentRenderState.init();
  14791. scene.traverseVisible(function (object) {
  14792. if (object.isLight && object.layers.test(camera.layers)) {
  14793. currentRenderState.pushLight(object);
  14794. if (object.castShadow) {
  14795. currentRenderState.pushShadow(object);
  14796. }
  14797. }
  14798. });
  14799. currentRenderState.setupLights();
  14800. var compiled = new WeakMap();
  14801. scene.traverse(function (object) {
  14802. var material = object.material;
  14803. if (material) {
  14804. if (Array.isArray(material)) {
  14805. for (var i = 0; i < material.length; i++) {
  14806. var material2 = material[i];
  14807. if (compiled.has(material2) === false) {
  14808. initMaterial(material2, scene, object);
  14809. compiled.set(material2);
  14810. }
  14811. }
  14812. } else if (compiled.has(material) === false) {
  14813. initMaterial(material, scene, object);
  14814. compiled.set(material);
  14815. }
  14816. }
  14817. });
  14818. }; // Animation Loop
  14819. var onAnimationFrameCallback = null;
  14820. function onAnimationFrame(time) {
  14821. if (xr.isPresenting) return;
  14822. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  14823. }
  14824. var animation = new WebGLAnimation();
  14825. animation.setAnimationLoop(onAnimationFrame);
  14826. if (typeof window !== 'undefined') animation.setContext(window);
  14827. this.setAnimationLoop = function (callback) {
  14828. onAnimationFrameCallback = callback;
  14829. xr.setAnimationLoop(callback);
  14830. callback === null ? animation.stop() : animation.start();
  14831. }; // Rendering
  14832. this.render = function (scene, camera) {
  14833. var renderTarget, forceClear;
  14834. if (arguments[2] !== undefined) {
  14835. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  14836. renderTarget = arguments[2];
  14837. }
  14838. if (arguments[3] !== undefined) {
  14839. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  14840. forceClear = arguments[3];
  14841. }
  14842. if (camera !== undefined && camera.isCamera !== true) {
  14843. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  14844. return;
  14845. }
  14846. if (_isContextLost === true) return; // reset caching for this frame
  14847. bindingStates.resetDefaultState();
  14848. _currentMaterialId = -1;
  14849. _currentCamera = null; // update scene graph
  14850. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  14851. if (camera.parent === null) camera.updateMatrixWorld();
  14852. if (xr.enabled === true && xr.isPresenting === true) {
  14853. camera = xr.getCamera(camera);
  14854. } //
  14855. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  14856. currentRenderState = renderStates.get(scene, renderStateStack.length);
  14857. currentRenderState.init();
  14858. renderStateStack.push(currentRenderState);
  14859. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  14860. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  14861. _localClippingEnabled = this.localClippingEnabled;
  14862. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  14863. currentRenderList = renderLists.get(scene, camera);
  14864. currentRenderList.init();
  14865. projectObject(scene, camera, 0, _this.sortObjects);
  14866. currentRenderList.finish();
  14867. if (_this.sortObjects === true) {
  14868. currentRenderList.sort(_opaqueSort, _transparentSort);
  14869. } //
  14870. if (_clippingEnabled === true) clipping.beginShadows();
  14871. var shadowsArray = currentRenderState.state.shadowsArray;
  14872. shadowMap.render(shadowsArray, scene, camera);
  14873. currentRenderState.setupLights();
  14874. currentRenderState.setupLightsView(camera);
  14875. if (_clippingEnabled === true) clipping.endShadows(); //
  14876. if (this.info.autoReset === true) this.info.reset();
  14877. if (renderTarget !== undefined) {
  14878. this.setRenderTarget(renderTarget);
  14879. } //
  14880. background.render(currentRenderList, scene, camera, forceClear); // render scene
  14881. var opaqueObjects = currentRenderList.opaque;
  14882. var transparentObjects = currentRenderList.transparent;
  14883. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  14884. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  14885. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  14886. if (_currentRenderTarget !== null) {
  14887. // Generate mipmap if we're using any kind of mipmap filtering
  14888. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  14889. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  14890. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  14891. state.buffers.depth.setTest(true);
  14892. state.buffers.depth.setMask(true);
  14893. state.buffers.color.setMask(true);
  14894. state.setPolygonOffset(false); // _gl.finish();
  14895. renderStateStack.pop();
  14896. if (renderStateStack.length > 0) {
  14897. currentRenderState = renderStateStack[renderStateStack.length - 1];
  14898. } else {
  14899. currentRenderState = null;
  14900. }
  14901. currentRenderList = null;
  14902. };
  14903. function projectObject(object, camera, groupOrder, sortObjects) {
  14904. if (object.visible === false) return;
  14905. var visible = object.layers.test(camera.layers);
  14906. if (visible) {
  14907. if (object.isGroup) {
  14908. groupOrder = object.renderOrder;
  14909. } else if (object.isLOD) {
  14910. if (object.autoUpdate === true) object.update(camera);
  14911. } else if (object.isLight) {
  14912. currentRenderState.pushLight(object);
  14913. if (object.castShadow) {
  14914. currentRenderState.pushShadow(object);
  14915. }
  14916. } else if (object.isSprite) {
  14917. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  14918. if (sortObjects) {
  14919. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14920. }
  14921. var geometry = objects.update(object);
  14922. var material = object.material;
  14923. if (material.visible) {
  14924. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  14925. }
  14926. }
  14927. } else if (object.isImmediateRenderObject) {
  14928. if (sortObjects) {
  14929. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14930. }
  14931. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  14932. } else if (object.isMesh || object.isLine || object.isPoints) {
  14933. if (object.isSkinnedMesh) {
  14934. // update skeleton only once in a frame
  14935. if (object.skeleton.frame !== info.render.frame) {
  14936. object.skeleton.update();
  14937. object.skeleton.frame = info.render.frame;
  14938. }
  14939. }
  14940. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  14941. if (sortObjects) {
  14942. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14943. }
  14944. var _geometry = objects.update(object);
  14945. var _material = object.material;
  14946. if (Array.isArray(_material)) {
  14947. var groups = _geometry.groups;
  14948. for (var i = 0, l = groups.length; i < l; i++) {
  14949. var group = groups[i];
  14950. var groupMaterial = _material[group.materialIndex];
  14951. if (groupMaterial && groupMaterial.visible) {
  14952. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  14953. }
  14954. }
  14955. } else if (_material.visible) {
  14956. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  14957. }
  14958. }
  14959. }
  14960. }
  14961. var children = object.children;
  14962. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  14963. projectObject(children[_i], camera, groupOrder, sortObjects);
  14964. }
  14965. }
  14966. function renderObjects(renderList, scene, camera) {
  14967. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  14968. for (var i = 0, l = renderList.length; i < l; i++) {
  14969. var renderItem = renderList[i];
  14970. var object = renderItem.object;
  14971. var geometry = renderItem.geometry;
  14972. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  14973. var group = renderItem.group;
  14974. if (camera.isArrayCamera) {
  14975. var cameras = camera.cameras;
  14976. for (var j = 0, jl = cameras.length; j < jl; j++) {
  14977. var camera2 = cameras[j];
  14978. if (object.layers.test(camera2.layers)) {
  14979. state.viewport(_currentViewport.copy(camera2.viewport));
  14980. currentRenderState.setupLightsView(camera2);
  14981. renderObject(object, scene, camera2, geometry, material, group);
  14982. }
  14983. }
  14984. } else {
  14985. renderObject(object, scene, camera, geometry, material, group);
  14986. }
  14987. }
  14988. }
  14989. function renderObject(object, scene, camera, geometry, material, group) {
  14990. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  14991. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  14992. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  14993. if (object.isImmediateRenderObject) {
  14994. var program = setProgram(camera, scene, material, object);
  14995. state.setMaterial(material);
  14996. bindingStates.reset();
  14997. renderObjectImmediate(object, program);
  14998. } else {
  14999. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  15000. }
  15001. object.onAfterRender(_this, scene, camera, geometry, material, group);
  15002. }
  15003. function initMaterial(material, scene, object) {
  15004. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15005. var materialProperties = properties.get(material);
  15006. var lights = currentRenderState.state.lights;
  15007. var shadowsArray = currentRenderState.state.shadowsArray;
  15008. var lightsStateVersion = lights.state.version;
  15009. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  15010. var programCacheKey = programCache.getProgramCacheKey(parameters);
  15011. var program = materialProperties.program;
  15012. var programChange = true; // always update environment and fog - changing these trigger an initMaterial call, but it's possible that the program doesn't change
  15013. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15014. materialProperties.fog = scene.fog;
  15015. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment);
  15016. if (program === undefined) {
  15017. // new material
  15018. material.addEventListener('dispose', onMaterialDispose);
  15019. } else if (program.cacheKey !== programCacheKey) {
  15020. // changed glsl or parameters
  15021. releaseMaterialProgramReference(material);
  15022. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  15023. programChange = false;
  15024. } else if (parameters.shaderID !== undefined) {
  15025. // same glsl and uniform list
  15026. return;
  15027. } else {
  15028. // only rebuild uniform list
  15029. programChange = false;
  15030. }
  15031. if (programChange) {
  15032. parameters.uniforms = programCache.getUniforms(material);
  15033. material.onBeforeCompile(parameters, _this);
  15034. program = programCache.acquireProgram(parameters, programCacheKey);
  15035. materialProperties.program = program;
  15036. materialProperties.uniforms = parameters.uniforms;
  15037. materialProperties.outputEncoding = parameters.outputEncoding;
  15038. }
  15039. var uniforms = materialProperties.uniforms;
  15040. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  15041. materialProperties.numClippingPlanes = clipping.numPlanes;
  15042. materialProperties.numIntersection = clipping.numIntersection;
  15043. uniforms.clippingPlanes = clipping.uniform;
  15044. } // store the light setup it was created for
  15045. materialProperties.needsLights = materialNeedsLights(material);
  15046. materialProperties.lightsStateVersion = lightsStateVersion;
  15047. if (materialProperties.needsLights) {
  15048. // wire up the material to this renderer's lighting state
  15049. uniforms.ambientLightColor.value = lights.state.ambient;
  15050. uniforms.lightProbe.value = lights.state.probe;
  15051. uniforms.directionalLights.value = lights.state.directional;
  15052. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15053. uniforms.spotLights.value = lights.state.spot;
  15054. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15055. uniforms.rectAreaLights.value = lights.state.rectArea;
  15056. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  15057. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  15058. uniforms.pointLights.value = lights.state.point;
  15059. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15060. uniforms.hemisphereLights.value = lights.state.hemi;
  15061. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15062. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15063. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15064. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15065. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15066. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  15067. }
  15068. var progUniforms = materialProperties.program.getUniforms();
  15069. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  15070. materialProperties.uniformsList = uniformsList;
  15071. }
  15072. function setProgram(camera, scene, material, object) {
  15073. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15074. textures.resetTextureUnits();
  15075. var fog = scene.fog;
  15076. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15077. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15078. var envMap = cubemaps.get(material.envMap || environment);
  15079. var materialProperties = properties.get(material);
  15080. var lights = currentRenderState.state.lights;
  15081. if (_clippingEnabled === true) {
  15082. if (_localClippingEnabled === true || camera !== _currentCamera) {
  15083. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  15084. // object instead of the material, once it becomes feasible
  15085. // (#8465, #8379)
  15086. clipping.setState(material, camera, useCache);
  15087. }
  15088. }
  15089. if (material.version === materialProperties.__version) {
  15090. if (material.fog && materialProperties.fog !== fog) {
  15091. initMaterial(material, scene, object);
  15092. } else if (materialProperties.environment !== environment) {
  15093. initMaterial(material, scene, object);
  15094. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  15095. initMaterial(material, scene, object);
  15096. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  15097. initMaterial(material, scene, object);
  15098. } else if (materialProperties.outputEncoding !== encoding) {
  15099. initMaterial(material, scene, object);
  15100. } else if (materialProperties.envMap !== envMap) {
  15101. initMaterial(material, scene, object);
  15102. }
  15103. } else {
  15104. initMaterial(material, scene, object);
  15105. materialProperties.__version = material.version;
  15106. }
  15107. var refreshProgram = false;
  15108. var refreshMaterial = false;
  15109. var refreshLights = false;
  15110. var program = materialProperties.program,
  15111. p_uniforms = program.getUniforms(),
  15112. m_uniforms = materialProperties.uniforms;
  15113. if (state.useProgram(program.program)) {
  15114. refreshProgram = true;
  15115. refreshMaterial = true;
  15116. refreshLights = true;
  15117. }
  15118. if (material.id !== _currentMaterialId) {
  15119. _currentMaterialId = material.id;
  15120. refreshMaterial = true;
  15121. }
  15122. if (refreshProgram || _currentCamera !== camera) {
  15123. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  15124. if (capabilities.logarithmicDepthBuffer) {
  15125. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  15126. }
  15127. if (_currentCamera !== camera) {
  15128. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  15129. // now, in case this material supports lights - or later, when
  15130. // the next material that does gets activated:
  15131. refreshMaterial = true; // set to true on material change
  15132. refreshLights = true; // remains set until update done
  15133. } // load material specific uniforms
  15134. // (shader material also gets them for the sake of genericity)
  15135. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  15136. var uCamPos = p_uniforms.map.cameraPosition;
  15137. if (uCamPos !== undefined) {
  15138. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  15139. }
  15140. }
  15141. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  15142. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  15143. }
  15144. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  15145. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  15146. }
  15147. } // skinning uniforms must be set even if material didn't change
  15148. // auto-setting of texture unit for bone texture must go before other textures
  15149. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15150. if (material.skinning) {
  15151. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  15152. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  15153. var skeleton = object.skeleton;
  15154. if (skeleton) {
  15155. var bones = skeleton.bones;
  15156. if (capabilities.floatVertexTextures) {
  15157. if (skeleton.boneTexture === null) {
  15158. // layout (1 matrix = 4 pixels)
  15159. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15160. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15161. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15162. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15163. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15164. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  15165. size = MathUtils.ceilPowerOfTwo(size);
  15166. size = Math.max(size, 4);
  15167. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  15168. boneMatrices.set(skeleton.boneMatrices); // copy current values
  15169. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  15170. skeleton.boneMatrices = boneMatrices;
  15171. skeleton.boneTexture = boneTexture;
  15172. skeleton.boneTextureSize = size;
  15173. }
  15174. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  15175. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  15176. } else {
  15177. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  15178. }
  15179. }
  15180. }
  15181. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  15182. materialProperties.receiveShadow = object.receiveShadow;
  15183. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  15184. }
  15185. if (refreshMaterial) {
  15186. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  15187. if (materialProperties.needsLights) {
  15188. // the current material requires lighting info
  15189. // note: all lighting uniforms are always set correctly
  15190. // they simply reference the renderer's state for their
  15191. // values
  15192. //
  15193. // use the current material's .needsUpdate flags to set
  15194. // the GL state when required
  15195. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  15196. } // refresh uniforms common to several materials
  15197. if (fog && material.fog) {
  15198. materials.refreshFogUniforms(m_uniforms, fog);
  15199. }
  15200. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  15201. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15202. }
  15203. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  15204. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15205. material.uniformsNeedUpdate = false;
  15206. }
  15207. if (material.isSpriteMaterial) {
  15208. p_uniforms.setValue(_gl, 'center', object.center);
  15209. } // common matrices
  15210. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  15211. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  15212. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  15213. return program;
  15214. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15215. function markUniformsLightsNeedsUpdate(uniforms, value) {
  15216. uniforms.ambientLightColor.needsUpdate = value;
  15217. uniforms.lightProbe.needsUpdate = value;
  15218. uniforms.directionalLights.needsUpdate = value;
  15219. uniforms.directionalLightShadows.needsUpdate = value;
  15220. uniforms.pointLights.needsUpdate = value;
  15221. uniforms.pointLightShadows.needsUpdate = value;
  15222. uniforms.spotLights.needsUpdate = value;
  15223. uniforms.spotLightShadows.needsUpdate = value;
  15224. uniforms.rectAreaLights.needsUpdate = value;
  15225. uniforms.hemisphereLights.needsUpdate = value;
  15226. }
  15227. function materialNeedsLights(material) {
  15228. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  15229. } //
  15230. this.setFramebuffer = function (value) {
  15231. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  15232. _framebuffer = value;
  15233. };
  15234. this.getActiveCubeFace = function () {
  15235. return _currentActiveCubeFace;
  15236. };
  15237. this.getActiveMipmapLevel = function () {
  15238. return _currentActiveMipmapLevel;
  15239. };
  15240. this.getRenderList = function () {
  15241. return currentRenderList;
  15242. };
  15243. this.setRenderList = function (renderList) {
  15244. currentRenderList = renderList;
  15245. };
  15246. this.getRenderTarget = function () {
  15247. return _currentRenderTarget;
  15248. };
  15249. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15250. if (activeCubeFace === void 0) {
  15251. activeCubeFace = 0;
  15252. }
  15253. if (activeMipmapLevel === void 0) {
  15254. activeMipmapLevel = 0;
  15255. }
  15256. _currentRenderTarget = renderTarget;
  15257. _currentActiveCubeFace = activeCubeFace;
  15258. _currentActiveMipmapLevel = activeMipmapLevel;
  15259. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15260. textures.setupRenderTarget(renderTarget);
  15261. }
  15262. var framebuffer = _framebuffer;
  15263. var isCube = false;
  15264. if (renderTarget) {
  15265. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15266. if (renderTarget.isWebGLCubeRenderTarget) {
  15267. framebuffer = __webglFramebuffer[activeCubeFace];
  15268. isCube = true;
  15269. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15270. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15271. } else {
  15272. framebuffer = __webglFramebuffer;
  15273. }
  15274. _currentViewport.copy(renderTarget.viewport);
  15275. _currentScissor.copy(renderTarget.scissor);
  15276. _currentScissorTest = renderTarget.scissorTest;
  15277. } else {
  15278. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15279. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15280. _currentScissorTest = _scissorTest;
  15281. }
  15282. if (_currentFramebuffer !== framebuffer) {
  15283. _gl.bindFramebuffer(36160, framebuffer);
  15284. _currentFramebuffer = framebuffer;
  15285. }
  15286. state.viewport(_currentViewport);
  15287. state.scissor(_currentScissor);
  15288. state.setScissorTest(_currentScissorTest);
  15289. if (isCube) {
  15290. var textureProperties = properties.get(renderTarget.texture);
  15291. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15292. }
  15293. };
  15294. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15295. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15296. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15297. return;
  15298. }
  15299. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15300. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15301. framebuffer = framebuffer[activeCubeFaceIndex];
  15302. }
  15303. if (framebuffer) {
  15304. var restore = false;
  15305. if (framebuffer !== _currentFramebuffer) {
  15306. _gl.bindFramebuffer(36160, framebuffer);
  15307. restore = true;
  15308. }
  15309. try {
  15310. var texture = renderTarget.texture;
  15311. var textureFormat = texture.format;
  15312. var textureType = texture.type;
  15313. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15314. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15315. return;
  15316. }
  15317. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15318. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.get('OES_texture_float') || extensions.get('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15319. !(textureType === HalfFloatType && (capabilities.isWebGL2 ? extensions.get('EXT_color_buffer_float') : extensions.get('EXT_color_buffer_half_float')))) {
  15320. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15321. return;
  15322. }
  15323. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15324. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15325. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15326. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15327. }
  15328. } else {
  15329. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15330. }
  15331. } finally {
  15332. if (restore) {
  15333. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15334. }
  15335. }
  15336. }
  15337. };
  15338. this.copyFramebufferToTexture = function (position, texture, level) {
  15339. if (level === void 0) {
  15340. level = 0;
  15341. }
  15342. var levelScale = Math.pow(2, -level);
  15343. var width = Math.floor(texture.image.width * levelScale);
  15344. var height = Math.floor(texture.image.height * levelScale);
  15345. var glFormat = utils.convert(texture.format);
  15346. textures.setTexture2D(texture, 0);
  15347. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15348. state.unbindTexture();
  15349. };
  15350. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15351. if (level === void 0) {
  15352. level = 0;
  15353. }
  15354. var width = srcTexture.image.width;
  15355. var height = srcTexture.image.height;
  15356. var glFormat = utils.convert(dstTexture.format);
  15357. var glType = utils.convert(dstTexture.type);
  15358. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15359. // parameters, make sure they are correct for the dstTexture
  15360. _gl.pixelStorei(37440, dstTexture.flipY);
  15361. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15362. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15363. if (srcTexture.isDataTexture) {
  15364. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15365. } else {
  15366. if (srcTexture.isCompressedTexture) {
  15367. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15368. } else {
  15369. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15370. }
  15371. } // Generate mipmaps only when copying level 0
  15372. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15373. state.unbindTexture();
  15374. };
  15375. this.initTexture = function (texture) {
  15376. textures.setTexture2D(texture, 0);
  15377. state.unbindTexture();
  15378. };
  15379. this.resetState = function () {
  15380. state.reset();
  15381. bindingStates.reset();
  15382. };
  15383. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15384. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15385. detail: this
  15386. })); // eslint-disable-line no-undef
  15387. }
  15388. }
  15389. function WebGL1Renderer(parameters) {
  15390. WebGLRenderer.call(this, parameters);
  15391. }
  15392. WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
  15393. constructor: WebGL1Renderer,
  15394. isWebGL1Renderer: true
  15395. });
  15396. var FogExp2 = /*#__PURE__*/function () {
  15397. function FogExp2(color, density) {
  15398. Object.defineProperty(this, 'isFogExp2', {
  15399. value: true
  15400. });
  15401. this.name = '';
  15402. this.color = new Color(color);
  15403. this.density = density !== undefined ? density : 0.00025;
  15404. }
  15405. var _proto = FogExp2.prototype;
  15406. _proto.clone = function clone() {
  15407. return new FogExp2(this.color, this.density);
  15408. };
  15409. _proto.toJSON = function toJSON()
  15410. /* meta */
  15411. {
  15412. return {
  15413. type: 'FogExp2',
  15414. color: this.color.getHex(),
  15415. density: this.density
  15416. };
  15417. };
  15418. return FogExp2;
  15419. }();
  15420. var Fog = /*#__PURE__*/function () {
  15421. function Fog(color, near, far) {
  15422. Object.defineProperty(this, 'isFog', {
  15423. value: true
  15424. });
  15425. this.name = '';
  15426. this.color = new Color(color);
  15427. this.near = near !== undefined ? near : 1;
  15428. this.far = far !== undefined ? far : 1000;
  15429. }
  15430. var _proto = Fog.prototype;
  15431. _proto.clone = function clone() {
  15432. return new Fog(this.color, this.near, this.far);
  15433. };
  15434. _proto.toJSON = function toJSON()
  15435. /* meta */
  15436. {
  15437. return {
  15438. type: 'Fog',
  15439. color: this.color.getHex(),
  15440. near: this.near,
  15441. far: this.far
  15442. };
  15443. };
  15444. return Fog;
  15445. }();
  15446. var Scene = /*#__PURE__*/function (_Object3D) {
  15447. _inheritsLoose(Scene, _Object3D);
  15448. function Scene() {
  15449. var _this;
  15450. _this = _Object3D.call(this) || this;
  15451. Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
  15452. value: true
  15453. });
  15454. _this.type = 'Scene';
  15455. _this.background = null;
  15456. _this.environment = null;
  15457. _this.fog = null;
  15458. _this.overrideMaterial = null;
  15459. _this.autoUpdate = true; // checked by the renderer
  15460. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15461. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15462. detail: _assertThisInitialized(_this)
  15463. })); // eslint-disable-line no-undef
  15464. }
  15465. return _this;
  15466. }
  15467. var _proto = Scene.prototype;
  15468. _proto.copy = function copy(source, recursive) {
  15469. _Object3D.prototype.copy.call(this, source, recursive);
  15470. if (source.background !== null) this.background = source.background.clone();
  15471. if (source.environment !== null) this.environment = source.environment.clone();
  15472. if (source.fog !== null) this.fog = source.fog.clone();
  15473. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  15474. this.autoUpdate = source.autoUpdate;
  15475. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15476. return this;
  15477. };
  15478. _proto.toJSON = function toJSON(meta) {
  15479. var data = _Object3D.prototype.toJSON.call(this, meta);
  15480. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  15481. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  15482. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  15483. return data;
  15484. };
  15485. return Scene;
  15486. }(Object3D);
  15487. function InterleavedBuffer(array, stride) {
  15488. this.array = array;
  15489. this.stride = stride;
  15490. this.count = array !== undefined ? array.length / stride : 0;
  15491. this.usage = StaticDrawUsage;
  15492. this.updateRange = {
  15493. offset: 0,
  15494. count: -1
  15495. };
  15496. this.version = 0;
  15497. this.uuid = MathUtils.generateUUID();
  15498. }
  15499. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  15500. set: function set(value) {
  15501. if (value === true) this.version++;
  15502. }
  15503. });
  15504. Object.assign(InterleavedBuffer.prototype, {
  15505. isInterleavedBuffer: true,
  15506. onUploadCallback: function onUploadCallback() {},
  15507. setUsage: function setUsage(value) {
  15508. this.usage = value;
  15509. return this;
  15510. },
  15511. copy: function copy(source) {
  15512. this.array = new source.array.constructor(source.array);
  15513. this.count = source.count;
  15514. this.stride = source.stride;
  15515. this.usage = source.usage;
  15516. return this;
  15517. },
  15518. copyAt: function copyAt(index1, attribute, index2) {
  15519. index1 *= this.stride;
  15520. index2 *= attribute.stride;
  15521. for (var i = 0, l = this.stride; i < l; i++) {
  15522. this.array[index1 + i] = attribute.array[index2 + i];
  15523. }
  15524. return this;
  15525. },
  15526. set: function set(value, offset) {
  15527. if (offset === void 0) {
  15528. offset = 0;
  15529. }
  15530. this.array.set(value, offset);
  15531. return this;
  15532. },
  15533. clone: function clone(data) {
  15534. if (data.arrayBuffers === undefined) {
  15535. data.arrayBuffers = {};
  15536. }
  15537. if (this.array.buffer._uuid === undefined) {
  15538. this.array.buffer._uuid = MathUtils.generateUUID();
  15539. }
  15540. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15541. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  15542. }
  15543. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  15544. var ib = new InterleavedBuffer(array, this.stride);
  15545. ib.setUsage(this.usage);
  15546. return ib;
  15547. },
  15548. onUpload: function onUpload(callback) {
  15549. this.onUploadCallback = callback;
  15550. return this;
  15551. },
  15552. toJSON: function toJSON(data) {
  15553. if (data.arrayBuffers === undefined) {
  15554. data.arrayBuffers = {};
  15555. } // generate UUID for array buffer if necessary
  15556. if (this.array.buffer._uuid === undefined) {
  15557. this.array.buffer._uuid = MathUtils.generateUUID();
  15558. }
  15559. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15560. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  15561. } //
  15562. return {
  15563. uuid: this.uuid,
  15564. buffer: this.array.buffer._uuid,
  15565. type: this.array.constructor.name,
  15566. stride: this.stride
  15567. };
  15568. }
  15569. });
  15570. var _vector$6 = new Vector3();
  15571. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  15572. this.name = '';
  15573. this.data = interleavedBuffer;
  15574. this.itemSize = itemSize;
  15575. this.offset = offset;
  15576. this.normalized = normalized === true;
  15577. }
  15578. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  15579. count: {
  15580. get: function get() {
  15581. return this.data.count;
  15582. }
  15583. },
  15584. array: {
  15585. get: function get() {
  15586. return this.data.array;
  15587. }
  15588. },
  15589. needsUpdate: {
  15590. set: function set(value) {
  15591. this.data.needsUpdate = value;
  15592. }
  15593. }
  15594. });
  15595. Object.assign(InterleavedBufferAttribute.prototype, {
  15596. isInterleavedBufferAttribute: true,
  15597. applyMatrix4: function applyMatrix4(m) {
  15598. for (var i = 0, l = this.data.count; i < l; i++) {
  15599. _vector$6.x = this.getX(i);
  15600. _vector$6.y = this.getY(i);
  15601. _vector$6.z = this.getZ(i);
  15602. _vector$6.applyMatrix4(m);
  15603. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  15604. }
  15605. return this;
  15606. },
  15607. setX: function setX(index, x) {
  15608. this.data.array[index * this.data.stride + this.offset] = x;
  15609. return this;
  15610. },
  15611. setY: function setY(index, y) {
  15612. this.data.array[index * this.data.stride + this.offset + 1] = y;
  15613. return this;
  15614. },
  15615. setZ: function setZ(index, z) {
  15616. this.data.array[index * this.data.stride + this.offset + 2] = z;
  15617. return this;
  15618. },
  15619. setW: function setW(index, w) {
  15620. this.data.array[index * this.data.stride + this.offset + 3] = w;
  15621. return this;
  15622. },
  15623. getX: function getX(index) {
  15624. return this.data.array[index * this.data.stride + this.offset];
  15625. },
  15626. getY: function getY(index) {
  15627. return this.data.array[index * this.data.stride + this.offset + 1];
  15628. },
  15629. getZ: function getZ(index) {
  15630. return this.data.array[index * this.data.stride + this.offset + 2];
  15631. },
  15632. getW: function getW(index) {
  15633. return this.data.array[index * this.data.stride + this.offset + 3];
  15634. },
  15635. setXY: function setXY(index, x, y) {
  15636. index = index * this.data.stride + this.offset;
  15637. this.data.array[index + 0] = x;
  15638. this.data.array[index + 1] = y;
  15639. return this;
  15640. },
  15641. setXYZ: function setXYZ(index, x, y, z) {
  15642. index = index * this.data.stride + this.offset;
  15643. this.data.array[index + 0] = x;
  15644. this.data.array[index + 1] = y;
  15645. this.data.array[index + 2] = z;
  15646. return this;
  15647. },
  15648. setXYZW: function setXYZW(index, x, y, z, w) {
  15649. index = index * this.data.stride + this.offset;
  15650. this.data.array[index + 0] = x;
  15651. this.data.array[index + 1] = y;
  15652. this.data.array[index + 2] = z;
  15653. this.data.array[index + 3] = w;
  15654. return this;
  15655. },
  15656. clone: function clone(data) {
  15657. if (data === undefined) {
  15658. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  15659. var array = [];
  15660. for (var i = 0; i < this.count; i++) {
  15661. var index = i * this.data.stride + this.offset;
  15662. for (var j = 0; j < this.itemSize; j++) {
  15663. array.push(this.data.array[index + j]);
  15664. }
  15665. }
  15666. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  15667. } else {
  15668. if (data.interleavedBuffers === undefined) {
  15669. data.interleavedBuffers = {};
  15670. }
  15671. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15672. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  15673. }
  15674. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  15675. }
  15676. },
  15677. toJSON: function toJSON(data) {
  15678. if (data === undefined) {
  15679. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  15680. var array = [];
  15681. for (var i = 0; i < this.count; i++) {
  15682. var index = i * this.data.stride + this.offset;
  15683. for (var j = 0; j < this.itemSize; j++) {
  15684. array.push(this.data.array[index + j]);
  15685. }
  15686. } // deinterleave data and save it as an ordinary buffer attribute for now
  15687. return {
  15688. itemSize: this.itemSize,
  15689. type: this.array.constructor.name,
  15690. array: array,
  15691. normalized: this.normalized
  15692. };
  15693. } else {
  15694. // save as true interlaved attribtue
  15695. if (data.interleavedBuffers === undefined) {
  15696. data.interleavedBuffers = {};
  15697. }
  15698. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15699. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  15700. }
  15701. return {
  15702. isInterleavedBufferAttribute: true,
  15703. itemSize: this.itemSize,
  15704. data: this.data.uuid,
  15705. offset: this.offset,
  15706. normalized: this.normalized
  15707. };
  15708. }
  15709. }
  15710. });
  15711. /**
  15712. * parameters = {
  15713. * color: <hex>,
  15714. * map: new THREE.Texture( <Image> ),
  15715. * alphaMap: new THREE.Texture( <Image> ),
  15716. * rotation: <float>,
  15717. * sizeAttenuation: <bool>
  15718. * }
  15719. */
  15720. function SpriteMaterial(parameters) {
  15721. Material.call(this);
  15722. this.type = 'SpriteMaterial';
  15723. this.color = new Color(0xffffff);
  15724. this.map = null;
  15725. this.alphaMap = null;
  15726. this.rotation = 0;
  15727. this.sizeAttenuation = true;
  15728. this.transparent = true;
  15729. this.setValues(parameters);
  15730. }
  15731. SpriteMaterial.prototype = Object.create(Material.prototype);
  15732. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15733. SpriteMaterial.prototype.isSpriteMaterial = true;
  15734. SpriteMaterial.prototype.copy = function (source) {
  15735. Material.prototype.copy.call(this, source);
  15736. this.color.copy(source.color);
  15737. this.map = source.map;
  15738. this.alphaMap = source.alphaMap;
  15739. this.rotation = source.rotation;
  15740. this.sizeAttenuation = source.sizeAttenuation;
  15741. return this;
  15742. };
  15743. var _geometry;
  15744. var _intersectPoint = new Vector3();
  15745. var _worldScale = new Vector3();
  15746. var _mvPosition = new Vector3();
  15747. var _alignedPosition = new Vector2();
  15748. var _rotatedPosition = new Vector2();
  15749. var _viewWorldMatrix = new Matrix4();
  15750. var _vA$1 = new Vector3();
  15751. var _vB$1 = new Vector3();
  15752. var _vC$1 = new Vector3();
  15753. var _uvA$1 = new Vector2();
  15754. var _uvB$1 = new Vector2();
  15755. var _uvC$1 = new Vector2();
  15756. function Sprite(material) {
  15757. Object3D.call(this);
  15758. this.type = 'Sprite';
  15759. if (_geometry === undefined) {
  15760. _geometry = new BufferGeometry();
  15761. 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]);
  15762. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  15763. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  15764. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  15765. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  15766. }
  15767. this.geometry = _geometry;
  15768. this.material = material !== undefined ? material : new SpriteMaterial();
  15769. this.center = new Vector2(0.5, 0.5);
  15770. }
  15771. Sprite.prototype = Object.assign(Object.create(Object3D.prototype), {
  15772. constructor: Sprite,
  15773. isSprite: true,
  15774. raycast: function raycast(raycaster, intersects) {
  15775. if (raycaster.camera === null) {
  15776. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  15777. }
  15778. _worldScale.setFromMatrixScale(this.matrixWorld);
  15779. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  15780. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  15781. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  15782. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  15783. _worldScale.multiplyScalar(-_mvPosition.z);
  15784. }
  15785. var rotation = this.material.rotation;
  15786. var sin, cos;
  15787. if (rotation !== 0) {
  15788. cos = Math.cos(rotation);
  15789. sin = Math.sin(rotation);
  15790. }
  15791. var center = this.center;
  15792. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15793. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15794. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15795. _uvA$1.set(0, 0);
  15796. _uvB$1.set(1, 0);
  15797. _uvC$1.set(1, 1); // check first triangle
  15798. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  15799. if (intersect === null) {
  15800. // check second triangle
  15801. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15802. _uvB$1.set(0, 1);
  15803. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  15804. if (intersect === null) {
  15805. return;
  15806. }
  15807. }
  15808. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  15809. if (distance < raycaster.near || distance > raycaster.far) return;
  15810. intersects.push({
  15811. distance: distance,
  15812. point: _intersectPoint.clone(),
  15813. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  15814. face: null,
  15815. object: this
  15816. });
  15817. },
  15818. copy: function copy(source) {
  15819. Object3D.prototype.copy.call(this, source);
  15820. if (source.center !== undefined) this.center.copy(source.center);
  15821. this.material = source.material;
  15822. return this;
  15823. }
  15824. });
  15825. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  15826. // compute position in camera space
  15827. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  15828. if (sin !== undefined) {
  15829. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  15830. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  15831. } else {
  15832. _rotatedPosition.copy(_alignedPosition);
  15833. }
  15834. vertexPosition.copy(mvPosition);
  15835. vertexPosition.x += _rotatedPosition.x;
  15836. vertexPosition.y += _rotatedPosition.y; // transform to world space
  15837. vertexPosition.applyMatrix4(_viewWorldMatrix);
  15838. }
  15839. var _v1$4 = new Vector3();
  15840. var _v2$2 = new Vector3();
  15841. function LOD() {
  15842. Object3D.call(this);
  15843. this._currentLevel = 0;
  15844. this.type = 'LOD';
  15845. Object.defineProperties(this, {
  15846. levels: {
  15847. enumerable: true,
  15848. value: []
  15849. }
  15850. });
  15851. this.autoUpdate = true;
  15852. }
  15853. LOD.prototype = Object.assign(Object.create(Object3D.prototype), {
  15854. constructor: LOD,
  15855. isLOD: true,
  15856. copy: function copy(source) {
  15857. Object3D.prototype.copy.call(this, source, false);
  15858. var levels = source.levels;
  15859. for (var i = 0, l = levels.length; i < l; i++) {
  15860. var level = levels[i];
  15861. this.addLevel(level.object.clone(), level.distance);
  15862. }
  15863. this.autoUpdate = source.autoUpdate;
  15864. return this;
  15865. },
  15866. addLevel: function addLevel(object, distance) {
  15867. if (distance === void 0) {
  15868. distance = 0;
  15869. }
  15870. distance = Math.abs(distance);
  15871. var levels = this.levels;
  15872. var l;
  15873. for (l = 0; l < levels.length; l++) {
  15874. if (distance < levels[l].distance) {
  15875. break;
  15876. }
  15877. }
  15878. levels.splice(l, 0, {
  15879. distance: distance,
  15880. object: object
  15881. });
  15882. this.add(object);
  15883. return this;
  15884. },
  15885. getCurrentLevel: function getCurrentLevel() {
  15886. return this._currentLevel;
  15887. },
  15888. getObjectForDistance: function getObjectForDistance(distance) {
  15889. var levels = this.levels;
  15890. if (levels.length > 0) {
  15891. var i, l;
  15892. for (i = 1, l = levels.length; i < l; i++) {
  15893. if (distance < levels[i].distance) {
  15894. break;
  15895. }
  15896. }
  15897. return levels[i - 1].object;
  15898. }
  15899. return null;
  15900. },
  15901. raycast: function raycast(raycaster, intersects) {
  15902. var levels = this.levels;
  15903. if (levels.length > 0) {
  15904. _v1$4.setFromMatrixPosition(this.matrixWorld);
  15905. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  15906. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  15907. }
  15908. },
  15909. update: function update(camera) {
  15910. var levels = this.levels;
  15911. if (levels.length > 1) {
  15912. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  15913. _v2$2.setFromMatrixPosition(this.matrixWorld);
  15914. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  15915. levels[0].object.visible = true;
  15916. var i, l;
  15917. for (i = 1, l = levels.length; i < l; i++) {
  15918. if (distance >= levels[i].distance) {
  15919. levels[i - 1].object.visible = false;
  15920. levels[i].object.visible = true;
  15921. } else {
  15922. break;
  15923. }
  15924. }
  15925. this._currentLevel = i - 1;
  15926. for (; i < l; i++) {
  15927. levels[i].object.visible = false;
  15928. }
  15929. }
  15930. },
  15931. toJSON: function toJSON(meta) {
  15932. var data = Object3D.prototype.toJSON.call(this, meta);
  15933. if (this.autoUpdate === false) data.object.autoUpdate = false;
  15934. data.object.levels = [];
  15935. var levels = this.levels;
  15936. for (var i = 0, l = levels.length; i < l; i++) {
  15937. var level = levels[i];
  15938. data.object.levels.push({
  15939. object: level.object.uuid,
  15940. distance: level.distance
  15941. });
  15942. }
  15943. return data;
  15944. }
  15945. });
  15946. var _basePosition = new Vector3();
  15947. var _skinIndex = new Vector4();
  15948. var _skinWeight = new Vector4();
  15949. var _vector$7 = new Vector3();
  15950. var _matrix$1 = new Matrix4();
  15951. function SkinnedMesh(geometry, material) {
  15952. if (geometry && geometry.isGeometry) {
  15953. console.error('THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  15954. }
  15955. Mesh.call(this, geometry, material);
  15956. this.type = 'SkinnedMesh';
  15957. this.bindMode = 'attached';
  15958. this.bindMatrix = new Matrix4();
  15959. this.bindMatrixInverse = new Matrix4();
  15960. }
  15961. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  15962. constructor: SkinnedMesh,
  15963. isSkinnedMesh: true,
  15964. copy: function copy(source) {
  15965. Mesh.prototype.copy.call(this, source);
  15966. this.bindMode = source.bindMode;
  15967. this.bindMatrix.copy(source.bindMatrix);
  15968. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  15969. this.skeleton = source.skeleton;
  15970. return this;
  15971. },
  15972. bind: function bind(skeleton, bindMatrix) {
  15973. this.skeleton = skeleton;
  15974. if (bindMatrix === undefined) {
  15975. this.updateMatrixWorld(true);
  15976. this.skeleton.calculateInverses();
  15977. bindMatrix = this.matrixWorld;
  15978. }
  15979. this.bindMatrix.copy(bindMatrix);
  15980. this.bindMatrixInverse.copy(bindMatrix).invert();
  15981. },
  15982. pose: function pose() {
  15983. this.skeleton.pose();
  15984. },
  15985. normalizeSkinWeights: function normalizeSkinWeights() {
  15986. var vector = new Vector4();
  15987. var skinWeight = this.geometry.attributes.skinWeight;
  15988. for (var i = 0, l = skinWeight.count; i < l; i++) {
  15989. vector.x = skinWeight.getX(i);
  15990. vector.y = skinWeight.getY(i);
  15991. vector.z = skinWeight.getZ(i);
  15992. vector.w = skinWeight.getW(i);
  15993. var scale = 1.0 / vector.manhattanLength();
  15994. if (scale !== Infinity) {
  15995. vector.multiplyScalar(scale);
  15996. } else {
  15997. vector.set(1, 0, 0, 0); // do something reasonable
  15998. }
  15999. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  16000. }
  16001. },
  16002. updateMatrixWorld: function updateMatrixWorld(force) {
  16003. Mesh.prototype.updateMatrixWorld.call(this, force);
  16004. if (this.bindMode === 'attached') {
  16005. this.bindMatrixInverse.copy(this.matrixWorld).invert();
  16006. } else if (this.bindMode === 'detached') {
  16007. this.bindMatrixInverse.copy(this.bindMatrix).invert();
  16008. } else {
  16009. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  16010. }
  16011. },
  16012. boneTransform: function boneTransform(index, target) {
  16013. var skeleton = this.skeleton;
  16014. var geometry = this.geometry;
  16015. _skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  16016. _skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  16017. _basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  16018. target.set(0, 0, 0);
  16019. for (var i = 0; i < 4; i++) {
  16020. var weight = _skinWeight.getComponent(i);
  16021. if (weight !== 0) {
  16022. var boneIndex = _skinIndex.getComponent(i);
  16023. _matrix$1.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  16024. target.addScaledVector(_vector$7.copy(_basePosition).applyMatrix4(_matrix$1), weight);
  16025. }
  16026. }
  16027. return target.applyMatrix4(this.bindMatrixInverse);
  16028. }
  16029. });
  16030. function Bone() {
  16031. Object3D.call(this);
  16032. this.type = 'Bone';
  16033. }
  16034. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  16035. constructor: Bone,
  16036. isBone: true
  16037. });
  16038. var _offsetMatrix = new Matrix4();
  16039. var _identityMatrix = new Matrix4();
  16040. function Skeleton(bones, boneInverses) {
  16041. if (bones === void 0) {
  16042. bones = [];
  16043. }
  16044. if (boneInverses === void 0) {
  16045. boneInverses = [];
  16046. }
  16047. this.uuid = MathUtils.generateUUID();
  16048. this.bones = bones.slice(0);
  16049. this.boneInverses = boneInverses;
  16050. this.boneMatrices = null;
  16051. this.boneTexture = null;
  16052. this.boneTextureSize = 0;
  16053. this.frame = -1;
  16054. this.init();
  16055. }
  16056. Object.assign(Skeleton.prototype, {
  16057. init: function init() {
  16058. var bones = this.bones;
  16059. var boneInverses = this.boneInverses;
  16060. this.boneMatrices = new Float32Array(bones.length * 16); // calculate inverse bone matrices if necessary
  16061. if (boneInverses.length === 0) {
  16062. this.calculateInverses();
  16063. } else {
  16064. // handle special case
  16065. if (bones.length !== boneInverses.length) {
  16066. console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');
  16067. this.boneInverses = [];
  16068. for (var i = 0, il = this.bones.length; i < il; i++) {
  16069. this.boneInverses.push(new Matrix4());
  16070. }
  16071. }
  16072. }
  16073. },
  16074. calculateInverses: function calculateInverses() {
  16075. this.boneInverses.length = 0;
  16076. for (var i = 0, il = this.bones.length; i < il; i++) {
  16077. var inverse = new Matrix4();
  16078. if (this.bones[i]) {
  16079. inverse.copy(this.bones[i].matrixWorld).invert();
  16080. }
  16081. this.boneInverses.push(inverse);
  16082. }
  16083. },
  16084. pose: function pose() {
  16085. // recover the bind-time world matrices
  16086. for (var i = 0, il = this.bones.length; i < il; i++) {
  16087. var bone = this.bones[i];
  16088. if (bone) {
  16089. bone.matrixWorld.copy(this.boneInverses[i]).invert();
  16090. }
  16091. } // compute the local matrices, positions, rotations and scales
  16092. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  16093. var _bone = this.bones[_i];
  16094. if (_bone) {
  16095. if (_bone.parent && _bone.parent.isBone) {
  16096. _bone.matrix.copy(_bone.parent.matrixWorld).invert();
  16097. _bone.matrix.multiply(_bone.matrixWorld);
  16098. } else {
  16099. _bone.matrix.copy(_bone.matrixWorld);
  16100. }
  16101. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  16102. }
  16103. }
  16104. },
  16105. update: function update() {
  16106. var bones = this.bones;
  16107. var boneInverses = this.boneInverses;
  16108. var boneMatrices = this.boneMatrices;
  16109. var boneTexture = this.boneTexture; // flatten bone matrices to array
  16110. for (var i = 0, il = bones.length; i < il; i++) {
  16111. // compute the offset between the current and the original transform
  16112. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  16113. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  16114. _offsetMatrix.toArray(boneMatrices, i * 16);
  16115. }
  16116. if (boneTexture !== null) {
  16117. boneTexture.needsUpdate = true;
  16118. }
  16119. },
  16120. clone: function clone() {
  16121. return new Skeleton(this.bones, this.boneInverses);
  16122. },
  16123. getBoneByName: function getBoneByName(name) {
  16124. for (var i = 0, il = this.bones.length; i < il; i++) {
  16125. var bone = this.bones[i];
  16126. if (bone.name === name) {
  16127. return bone;
  16128. }
  16129. }
  16130. return undefined;
  16131. },
  16132. dispose: function dispose() {
  16133. if (this.boneTexture !== null) {
  16134. this.boneTexture.dispose();
  16135. this.boneTexture = null;
  16136. }
  16137. },
  16138. fromJSON: function fromJSON(json, bones) {
  16139. this.uuid = json.uuid;
  16140. for (var i = 0, l = json.bones.length; i < l; i++) {
  16141. var uuid = json.bones[i];
  16142. var bone = bones[uuid];
  16143. if (bone === undefined) {
  16144. console.warn('THREE.Skeleton: No bone found with UUID:', uuid);
  16145. bone = new Bone();
  16146. }
  16147. this.bones.push(bone);
  16148. this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
  16149. }
  16150. this.init();
  16151. return this;
  16152. },
  16153. toJSON: function toJSON() {
  16154. var data = {
  16155. metadata: {
  16156. version: 4.5,
  16157. type: 'Skeleton',
  16158. generator: 'Skeleton.toJSON'
  16159. },
  16160. bones: [],
  16161. boneInverses: []
  16162. };
  16163. data.uuid = this.uuid;
  16164. var bones = this.bones;
  16165. var boneInverses = this.boneInverses;
  16166. for (var i = 0, l = bones.length; i < l; i++) {
  16167. var bone = bones[i];
  16168. data.bones.push(bone.uuid);
  16169. var boneInverse = boneInverses[i];
  16170. data.boneInverses.push(boneInverse.toArray());
  16171. }
  16172. return data;
  16173. }
  16174. });
  16175. var _instanceLocalMatrix = new Matrix4();
  16176. var _instanceWorldMatrix = new Matrix4();
  16177. var _instanceIntersects = [];
  16178. var _mesh = new Mesh();
  16179. function InstancedMesh(geometry, material, count) {
  16180. Mesh.call(this, geometry, material);
  16181. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  16182. this.instanceColor = null;
  16183. this.count = count;
  16184. this.frustumCulled = false;
  16185. }
  16186. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16187. constructor: InstancedMesh,
  16188. isInstancedMesh: true,
  16189. copy: function copy(source) {
  16190. Mesh.prototype.copy.call(this, source);
  16191. this.instanceMatrix.copy(source.instanceMatrix);
  16192. if (source.instanceColor !== null) this.instanceColor = source.instanceColor.clone();
  16193. this.count = source.count;
  16194. return this;
  16195. },
  16196. getColorAt: function getColorAt(index, color) {
  16197. color.fromArray(this.instanceColor.array, index * 3);
  16198. },
  16199. getMatrixAt: function getMatrixAt(index, matrix) {
  16200. matrix.fromArray(this.instanceMatrix.array, index * 16);
  16201. },
  16202. raycast: function raycast(raycaster, intersects) {
  16203. var matrixWorld = this.matrixWorld;
  16204. var raycastTimes = this.count;
  16205. _mesh.geometry = this.geometry;
  16206. _mesh.material = this.material;
  16207. if (_mesh.material === undefined) return;
  16208. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  16209. // calculate the world matrix for each instance
  16210. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  16211. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  16212. _mesh.matrixWorld = _instanceWorldMatrix;
  16213. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  16214. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  16215. var intersect = _instanceIntersects[i];
  16216. intersect.instanceId = instanceId;
  16217. intersect.object = this;
  16218. intersects.push(intersect);
  16219. }
  16220. _instanceIntersects.length = 0;
  16221. }
  16222. },
  16223. setColorAt: function setColorAt(index, color) {
  16224. if (this.instanceColor === null) {
  16225. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  16226. }
  16227. color.toArray(this.instanceColor.array, index * 3);
  16228. },
  16229. setMatrixAt: function setMatrixAt(index, matrix) {
  16230. matrix.toArray(this.instanceMatrix.array, index * 16);
  16231. },
  16232. updateMorphTargets: function updateMorphTargets() {},
  16233. dispose: function dispose() {
  16234. this.dispatchEvent({
  16235. type: 'dispose'
  16236. });
  16237. }
  16238. });
  16239. /**
  16240. * parameters = {
  16241. * color: <hex>,
  16242. * opacity: <float>,
  16243. *
  16244. * linewidth: <float>,
  16245. * linecap: "round",
  16246. * linejoin: "round"
  16247. * }
  16248. */
  16249. function LineBasicMaterial(parameters) {
  16250. Material.call(this);
  16251. this.type = 'LineBasicMaterial';
  16252. this.color = new Color(0xffffff);
  16253. this.linewidth = 1;
  16254. this.linecap = 'round';
  16255. this.linejoin = 'round';
  16256. this.morphTargets = false;
  16257. this.setValues(parameters);
  16258. }
  16259. LineBasicMaterial.prototype = Object.create(Material.prototype);
  16260. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16261. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16262. LineBasicMaterial.prototype.copy = function (source) {
  16263. Material.prototype.copy.call(this, source);
  16264. this.color.copy(source.color);
  16265. this.linewidth = source.linewidth;
  16266. this.linecap = source.linecap;
  16267. this.linejoin = source.linejoin;
  16268. this.morphTargets = source.morphTargets;
  16269. return this;
  16270. };
  16271. var _start = new Vector3();
  16272. var _end = new Vector3();
  16273. var _inverseMatrix$1 = new Matrix4();
  16274. var _ray$1 = new Ray();
  16275. var _sphere$2 = new Sphere();
  16276. function Line(geometry, material) {
  16277. if (geometry === void 0) {
  16278. geometry = new BufferGeometry();
  16279. }
  16280. if (material === void 0) {
  16281. material = new LineBasicMaterial();
  16282. }
  16283. Object3D.call(this);
  16284. this.type = 'Line';
  16285. this.geometry = geometry;
  16286. this.material = material;
  16287. this.updateMorphTargets();
  16288. }
  16289. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  16290. constructor: Line,
  16291. isLine: true,
  16292. copy: function copy(source) {
  16293. Object3D.prototype.copy.call(this, source);
  16294. this.material = source.material;
  16295. this.geometry = source.geometry;
  16296. return this;
  16297. },
  16298. computeLineDistances: function computeLineDistances() {
  16299. var geometry = this.geometry;
  16300. if (geometry.isBufferGeometry) {
  16301. // we assume non-indexed geometry
  16302. if (geometry.index === null) {
  16303. var positionAttribute = geometry.attributes.position;
  16304. var lineDistances = [0];
  16305. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  16306. _start.fromBufferAttribute(positionAttribute, i - 1);
  16307. _end.fromBufferAttribute(positionAttribute, i);
  16308. lineDistances[i] = lineDistances[i - 1];
  16309. lineDistances[i] += _start.distanceTo(_end);
  16310. }
  16311. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16312. } else {
  16313. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16314. }
  16315. } else if (geometry.isGeometry) {
  16316. console.error('THREE.Line.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16317. }
  16318. return this;
  16319. },
  16320. raycast: function raycast(raycaster, intersects) {
  16321. var geometry = this.geometry;
  16322. var matrixWorld = this.matrixWorld;
  16323. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  16324. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16325. _sphere$2.copy(geometry.boundingSphere);
  16326. _sphere$2.applyMatrix4(matrixWorld);
  16327. _sphere$2.radius += threshold;
  16328. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  16329. _inverseMatrix$1.copy(matrixWorld).invert();
  16330. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  16331. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16332. var localThresholdSq = localThreshold * localThreshold;
  16333. var vStart = new Vector3();
  16334. var vEnd = new Vector3();
  16335. var interSegment = new Vector3();
  16336. var interRay = new Vector3();
  16337. var step = this.isLineSegments ? 2 : 1;
  16338. if (geometry.isBufferGeometry) {
  16339. var index = geometry.index;
  16340. var attributes = geometry.attributes;
  16341. var positionAttribute = attributes.position;
  16342. if (index !== null) {
  16343. var indices = index.array;
  16344. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  16345. var a = indices[i];
  16346. var b = indices[i + 1];
  16347. vStart.fromBufferAttribute(positionAttribute, a);
  16348. vEnd.fromBufferAttribute(positionAttribute, b);
  16349. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16350. if (distSq > localThresholdSq) continue;
  16351. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16352. var distance = raycaster.ray.origin.distanceTo(interRay);
  16353. if (distance < raycaster.near || distance > raycaster.far) continue;
  16354. intersects.push({
  16355. distance: distance,
  16356. // What do we want? intersection point on the ray or on the segment??
  16357. // point: raycaster.ray.at( distance ),
  16358. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16359. index: i,
  16360. face: null,
  16361. faceIndex: null,
  16362. object: this
  16363. });
  16364. }
  16365. } else {
  16366. for (var _i = 0, _l = positionAttribute.count - 1; _i < _l; _i += step) {
  16367. vStart.fromBufferAttribute(positionAttribute, _i);
  16368. vEnd.fromBufferAttribute(positionAttribute, _i + 1);
  16369. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16370. if (_distSq > localThresholdSq) continue;
  16371. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16372. var _distance = raycaster.ray.origin.distanceTo(interRay);
  16373. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  16374. intersects.push({
  16375. distance: _distance,
  16376. // What do we want? intersection point on the ray or on the segment??
  16377. // point: raycaster.ray.at( distance ),
  16378. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16379. index: _i,
  16380. face: null,
  16381. faceIndex: null,
  16382. object: this
  16383. });
  16384. }
  16385. }
  16386. } else if (geometry.isGeometry) {
  16387. console.error('THREE.Line.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16388. }
  16389. },
  16390. updateMorphTargets: function updateMorphTargets() {
  16391. var geometry = this.geometry;
  16392. if (geometry.isBufferGeometry) {
  16393. var morphAttributes = geometry.morphAttributes;
  16394. var keys = Object.keys(morphAttributes);
  16395. if (keys.length > 0) {
  16396. var morphAttribute = morphAttributes[keys[0]];
  16397. if (morphAttribute !== undefined) {
  16398. this.morphTargetInfluences = [];
  16399. this.morphTargetDictionary = {};
  16400. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16401. var name = morphAttribute[m].name || String(m);
  16402. this.morphTargetInfluences.push(0);
  16403. this.morphTargetDictionary[name] = m;
  16404. }
  16405. }
  16406. }
  16407. } else {
  16408. var morphTargets = geometry.morphTargets;
  16409. if (morphTargets !== undefined && morphTargets.length > 0) {
  16410. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16411. }
  16412. }
  16413. }
  16414. });
  16415. var _start$1 = new Vector3();
  16416. var _end$1 = new Vector3();
  16417. function LineSegments(geometry, material) {
  16418. Line.call(this, geometry, material);
  16419. this.type = 'LineSegments';
  16420. }
  16421. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  16422. constructor: LineSegments,
  16423. isLineSegments: true,
  16424. computeLineDistances: function computeLineDistances() {
  16425. var geometry = this.geometry;
  16426. if (geometry.isBufferGeometry) {
  16427. // we assume non-indexed geometry
  16428. if (geometry.index === null) {
  16429. var positionAttribute = geometry.attributes.position;
  16430. var lineDistances = [];
  16431. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  16432. _start$1.fromBufferAttribute(positionAttribute, i);
  16433. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  16434. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  16435. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  16436. }
  16437. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16438. } else {
  16439. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16440. }
  16441. } else if (geometry.isGeometry) {
  16442. console.error('THREE.LineSegments.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16443. }
  16444. return this;
  16445. }
  16446. });
  16447. function LineLoop(geometry, material) {
  16448. Line.call(this, geometry, material);
  16449. this.type = 'LineLoop';
  16450. }
  16451. LineLoop.prototype = Object.assign(Object.create(Line.prototype), {
  16452. constructor: LineLoop,
  16453. isLineLoop: true
  16454. });
  16455. /**
  16456. * parameters = {
  16457. * color: <hex>,
  16458. * opacity: <float>,
  16459. * map: new THREE.Texture( <Image> ),
  16460. * alphaMap: new THREE.Texture( <Image> ),
  16461. *
  16462. * size: <float>,
  16463. * sizeAttenuation: <bool>
  16464. *
  16465. * morphTargets: <bool>
  16466. * }
  16467. */
  16468. function PointsMaterial(parameters) {
  16469. Material.call(this);
  16470. this.type = 'PointsMaterial';
  16471. this.color = new Color(0xffffff);
  16472. this.map = null;
  16473. this.alphaMap = null;
  16474. this.size = 1;
  16475. this.sizeAttenuation = true;
  16476. this.morphTargets = false;
  16477. this.setValues(parameters);
  16478. }
  16479. PointsMaterial.prototype = Object.create(Material.prototype);
  16480. PointsMaterial.prototype.constructor = PointsMaterial;
  16481. PointsMaterial.prototype.isPointsMaterial = true;
  16482. PointsMaterial.prototype.copy = function (source) {
  16483. Material.prototype.copy.call(this, source);
  16484. this.color.copy(source.color);
  16485. this.map = source.map;
  16486. this.alphaMap = source.alphaMap;
  16487. this.size = source.size;
  16488. this.sizeAttenuation = source.sizeAttenuation;
  16489. this.morphTargets = source.morphTargets;
  16490. return this;
  16491. };
  16492. var _inverseMatrix$2 = new Matrix4();
  16493. var _ray$2 = new Ray();
  16494. var _sphere$3 = new Sphere();
  16495. var _position$1 = new Vector3();
  16496. function Points(geometry, material) {
  16497. if (geometry === void 0) {
  16498. geometry = new BufferGeometry();
  16499. }
  16500. if (material === void 0) {
  16501. material = new PointsMaterial();
  16502. }
  16503. Object3D.call(this);
  16504. this.type = 'Points';
  16505. this.geometry = geometry;
  16506. this.material = material;
  16507. this.updateMorphTargets();
  16508. }
  16509. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  16510. constructor: Points,
  16511. isPoints: true,
  16512. copy: function copy(source) {
  16513. Object3D.prototype.copy.call(this, source);
  16514. this.material = source.material;
  16515. this.geometry = source.geometry;
  16516. return this;
  16517. },
  16518. raycast: function raycast(raycaster, intersects) {
  16519. var geometry = this.geometry;
  16520. var matrixWorld = this.matrixWorld;
  16521. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  16522. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16523. _sphere$3.copy(geometry.boundingSphere);
  16524. _sphere$3.applyMatrix4(matrixWorld);
  16525. _sphere$3.radius += threshold;
  16526. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  16527. _inverseMatrix$2.copy(matrixWorld).invert();
  16528. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  16529. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16530. var localThresholdSq = localThreshold * localThreshold;
  16531. if (geometry.isBufferGeometry) {
  16532. var index = geometry.index;
  16533. var attributes = geometry.attributes;
  16534. var positionAttribute = attributes.position;
  16535. if (index !== null) {
  16536. var indices = index.array;
  16537. for (var i = 0, il = indices.length; i < il; i++) {
  16538. var a = indices[i];
  16539. _position$1.fromBufferAttribute(positionAttribute, a);
  16540. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16541. }
  16542. } else {
  16543. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  16544. _position$1.fromBufferAttribute(positionAttribute, _i);
  16545. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16546. }
  16547. }
  16548. } else {
  16549. console.error('THREE.Points.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16550. }
  16551. },
  16552. updateMorphTargets: function updateMorphTargets() {
  16553. var geometry = this.geometry;
  16554. if (geometry.isBufferGeometry) {
  16555. var morphAttributes = geometry.morphAttributes;
  16556. var keys = Object.keys(morphAttributes);
  16557. if (keys.length > 0) {
  16558. var morphAttribute = morphAttributes[keys[0]];
  16559. if (morphAttribute !== undefined) {
  16560. this.morphTargetInfluences = [];
  16561. this.morphTargetDictionary = {};
  16562. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16563. var name = morphAttribute[m].name || String(m);
  16564. this.morphTargetInfluences.push(0);
  16565. this.morphTargetDictionary[name] = m;
  16566. }
  16567. }
  16568. }
  16569. } else {
  16570. var morphTargets = geometry.morphTargets;
  16571. if (morphTargets !== undefined && morphTargets.length > 0) {
  16572. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16573. }
  16574. }
  16575. }
  16576. });
  16577. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  16578. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  16579. if (rayPointDistanceSq < localThresholdSq) {
  16580. var intersectPoint = new Vector3();
  16581. _ray$2.closestPointToPoint(point, intersectPoint);
  16582. intersectPoint.applyMatrix4(matrixWorld);
  16583. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  16584. if (distance < raycaster.near || distance > raycaster.far) return;
  16585. intersects.push({
  16586. distance: distance,
  16587. distanceToRay: Math.sqrt(rayPointDistanceSq),
  16588. point: intersectPoint,
  16589. index: index,
  16590. face: null,
  16591. object: object
  16592. });
  16593. }
  16594. }
  16595. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16596. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16597. this.format = format !== undefined ? format : RGBFormat;
  16598. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16599. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16600. this.generateMipmaps = false;
  16601. var scope = this;
  16602. function updateVideo() {
  16603. scope.needsUpdate = true;
  16604. video.requestVideoFrameCallback(updateVideo);
  16605. }
  16606. if ('requestVideoFrameCallback' in video) {
  16607. video.requestVideoFrameCallback(updateVideo);
  16608. }
  16609. }
  16610. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  16611. constructor: VideoTexture,
  16612. clone: function clone() {
  16613. return new this.constructor(this.image).copy(this);
  16614. },
  16615. isVideoTexture: true,
  16616. update: function update() {
  16617. var video = this.image;
  16618. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  16619. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  16620. this.needsUpdate = true;
  16621. }
  16622. }
  16623. });
  16624. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  16625. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  16626. this.image = {
  16627. width: width,
  16628. height: height
  16629. };
  16630. this.mipmaps = mipmaps; // no flipping for cube textures
  16631. // (also flipping doesn't work for compressed textures )
  16632. this.flipY = false; // can't generate mipmaps for compressed textures
  16633. // mips must be embedded in DDS files
  16634. this.generateMipmaps = false;
  16635. }
  16636. CompressedTexture.prototype = Object.create(Texture.prototype);
  16637. CompressedTexture.prototype.constructor = CompressedTexture;
  16638. CompressedTexture.prototype.isCompressedTexture = true;
  16639. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16640. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16641. this.needsUpdate = true;
  16642. }
  16643. CanvasTexture.prototype = Object.create(Texture.prototype);
  16644. CanvasTexture.prototype.constructor = CanvasTexture;
  16645. CanvasTexture.prototype.isCanvasTexture = true;
  16646. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  16647. format = format !== undefined ? format : DepthFormat;
  16648. if (format !== DepthFormat && format !== DepthStencilFormat) {
  16649. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  16650. }
  16651. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  16652. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  16653. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16654. this.image = {
  16655. width: width,
  16656. height: height
  16657. };
  16658. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16659. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16660. this.flipY = false;
  16661. this.generateMipmaps = false;
  16662. }
  16663. DepthTexture.prototype = Object.create(Texture.prototype);
  16664. DepthTexture.prototype.constructor = DepthTexture;
  16665. DepthTexture.prototype.isDepthTexture = true;
  16666. var CircleGeometry = /*#__PURE__*/function (_BufferGeometry) {
  16667. _inheritsLoose(CircleGeometry, _BufferGeometry);
  16668. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  16669. var _this;
  16670. if (radius === void 0) {
  16671. radius = 1;
  16672. }
  16673. if (segments === void 0) {
  16674. segments = 8;
  16675. }
  16676. if (thetaStart === void 0) {
  16677. thetaStart = 0;
  16678. }
  16679. if (thetaLength === void 0) {
  16680. thetaLength = Math.PI * 2;
  16681. }
  16682. _this = _BufferGeometry.call(this) || this;
  16683. _this.type = 'CircleGeometry';
  16684. _this.parameters = {
  16685. radius: radius,
  16686. segments: segments,
  16687. thetaStart: thetaStart,
  16688. thetaLength: thetaLength
  16689. };
  16690. segments = Math.max(3, segments); // buffers
  16691. var indices = [];
  16692. var vertices = [];
  16693. var normals = [];
  16694. var uvs = []; // helper variables
  16695. var vertex = new Vector3();
  16696. var uv = new Vector2(); // center point
  16697. vertices.push(0, 0, 0);
  16698. normals.push(0, 0, 1);
  16699. uvs.push(0.5, 0.5);
  16700. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  16701. var segment = thetaStart + s / segments * thetaLength; // vertex
  16702. vertex.x = radius * Math.cos(segment);
  16703. vertex.y = radius * Math.sin(segment);
  16704. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  16705. normals.push(0, 0, 1); // uvs
  16706. uv.x = (vertices[i] / radius + 1) / 2;
  16707. uv.y = (vertices[i + 1] / radius + 1) / 2;
  16708. uvs.push(uv.x, uv.y);
  16709. } // indices
  16710. for (var _i = 1; _i <= segments; _i++) {
  16711. indices.push(_i, _i + 1, 0);
  16712. } // build geometry
  16713. _this.setIndex(indices);
  16714. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  16715. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  16716. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  16717. return _this;
  16718. }
  16719. return CircleGeometry;
  16720. }(BufferGeometry);
  16721. var CylinderGeometry = /*#__PURE__*/function (_BufferGeometry) {
  16722. _inheritsLoose(CylinderGeometry, _BufferGeometry);
  16723. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  16724. var _this;
  16725. if (radiusTop === void 0) {
  16726. radiusTop = 1;
  16727. }
  16728. if (radiusBottom === void 0) {
  16729. radiusBottom = 1;
  16730. }
  16731. if (height === void 0) {
  16732. height = 1;
  16733. }
  16734. if (radialSegments === void 0) {
  16735. radialSegments = 8;
  16736. }
  16737. if (heightSegments === void 0) {
  16738. heightSegments = 1;
  16739. }
  16740. if (openEnded === void 0) {
  16741. openEnded = false;
  16742. }
  16743. if (thetaStart === void 0) {
  16744. thetaStart = 0;
  16745. }
  16746. if (thetaLength === void 0) {
  16747. thetaLength = Math.PI * 2;
  16748. }
  16749. _this = _BufferGeometry.call(this) || this;
  16750. _this.type = 'CylinderGeometry';
  16751. _this.parameters = {
  16752. radiusTop: radiusTop,
  16753. radiusBottom: radiusBottom,
  16754. height: height,
  16755. radialSegments: radialSegments,
  16756. heightSegments: heightSegments,
  16757. openEnded: openEnded,
  16758. thetaStart: thetaStart,
  16759. thetaLength: thetaLength
  16760. };
  16761. var scope = _assertThisInitialized(_this);
  16762. radialSegments = Math.floor(radialSegments);
  16763. heightSegments = Math.floor(heightSegments); // buffers
  16764. var indices = [];
  16765. var vertices = [];
  16766. var normals = [];
  16767. var uvs = []; // helper variables
  16768. var index = 0;
  16769. var indexArray = [];
  16770. var halfHeight = height / 2;
  16771. var groupStart = 0; // generate geometry
  16772. generateTorso();
  16773. if (openEnded === false) {
  16774. if (radiusTop > 0) generateCap(true);
  16775. if (radiusBottom > 0) generateCap(false);
  16776. } // build geometry
  16777. _this.setIndex(indices);
  16778. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  16779. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  16780. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  16781. function generateTorso() {
  16782. var normal = new Vector3();
  16783. var vertex = new Vector3();
  16784. var groupCount = 0; // this will be used to calculate the normal
  16785. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  16786. for (var y = 0; y <= heightSegments; y++) {
  16787. var indexRow = [];
  16788. var v = y / heightSegments; // calculate the radius of the current row
  16789. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  16790. for (var x = 0; x <= radialSegments; x++) {
  16791. var u = x / radialSegments;
  16792. var theta = u * thetaLength + thetaStart;
  16793. var sinTheta = Math.sin(theta);
  16794. var cosTheta = Math.cos(theta); // vertex
  16795. vertex.x = radius * sinTheta;
  16796. vertex.y = -v * height + halfHeight;
  16797. vertex.z = radius * cosTheta;
  16798. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  16799. normal.set(sinTheta, slope, cosTheta).normalize();
  16800. normals.push(normal.x, normal.y, normal.z); // uv
  16801. uvs.push(u, 1 - v); // save index of vertex in respective row
  16802. indexRow.push(index++);
  16803. } // now save vertices of the row in our index array
  16804. indexArray.push(indexRow);
  16805. } // generate indices
  16806. for (var _x = 0; _x < radialSegments; _x++) {
  16807. for (var _y = 0; _y < heightSegments; _y++) {
  16808. // we use the index array to access the correct indices
  16809. var a = indexArray[_y][_x];
  16810. var b = indexArray[_y + 1][_x];
  16811. var c = indexArray[_y + 1][_x + 1];
  16812. var d = indexArray[_y][_x + 1]; // faces
  16813. indices.push(a, b, d);
  16814. indices.push(b, c, d); // update group counter
  16815. groupCount += 6;
  16816. }
  16817. } // add a group to the geometry. this will ensure multi material support
  16818. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  16819. groupStart += groupCount;
  16820. }
  16821. function generateCap(top) {
  16822. // save the index of the first center vertex
  16823. var centerIndexStart = index;
  16824. var uv = new Vector2();
  16825. var vertex = new Vector3();
  16826. var groupCount = 0;
  16827. var radius = top === true ? radiusTop : radiusBottom;
  16828. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  16829. // because the geometry needs one set of uvs per face,
  16830. // we must generate a center vertex per face/segment
  16831. for (var x = 1; x <= radialSegments; x++) {
  16832. // vertex
  16833. vertices.push(0, halfHeight * sign, 0); // normal
  16834. normals.push(0, sign, 0); // uv
  16835. uvs.push(0.5, 0.5); // increase index
  16836. index++;
  16837. } // save the index of the last center vertex
  16838. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  16839. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  16840. var u = _x2 / radialSegments;
  16841. var theta = u * thetaLength + thetaStart;
  16842. var cosTheta = Math.cos(theta);
  16843. var sinTheta = Math.sin(theta); // vertex
  16844. vertex.x = radius * sinTheta;
  16845. vertex.y = halfHeight * sign;
  16846. vertex.z = radius * cosTheta;
  16847. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  16848. normals.push(0, sign, 0); // uv
  16849. uv.x = cosTheta * 0.5 + 0.5;
  16850. uv.y = sinTheta * 0.5 * sign + 0.5;
  16851. uvs.push(uv.x, uv.y); // increase index
  16852. index++;
  16853. } // generate indices
  16854. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  16855. var c = centerIndexStart + _x3;
  16856. var i = centerIndexEnd + _x3;
  16857. if (top === true) {
  16858. // face top
  16859. indices.push(i, i + 1, c);
  16860. } else {
  16861. // face bottom
  16862. indices.push(i + 1, i, c);
  16863. }
  16864. groupCount += 3;
  16865. } // add a group to the geometry. this will ensure multi material support
  16866. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  16867. groupStart += groupCount;
  16868. }
  16869. return _this;
  16870. }
  16871. return CylinderGeometry;
  16872. }(BufferGeometry);
  16873. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  16874. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  16875. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  16876. var _this;
  16877. if (radius === void 0) {
  16878. radius = 1;
  16879. }
  16880. if (height === void 0) {
  16881. height = 1;
  16882. }
  16883. if (radialSegments === void 0) {
  16884. radialSegments = 8;
  16885. }
  16886. if (heightSegments === void 0) {
  16887. heightSegments = 1;
  16888. }
  16889. if (openEnded === void 0) {
  16890. openEnded = false;
  16891. }
  16892. if (thetaStart === void 0) {
  16893. thetaStart = 0;
  16894. }
  16895. if (thetaLength === void 0) {
  16896. thetaLength = Math.PI * 2;
  16897. }
  16898. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  16899. _this.type = 'ConeGeometry';
  16900. _this.parameters = {
  16901. radius: radius,
  16902. height: height,
  16903. radialSegments: radialSegments,
  16904. heightSegments: heightSegments,
  16905. openEnded: openEnded,
  16906. thetaStart: thetaStart,
  16907. thetaLength: thetaLength
  16908. };
  16909. return _this;
  16910. }
  16911. return ConeGeometry;
  16912. }(CylinderGeometry);
  16913. var PolyhedronGeometry = /*#__PURE__*/function (_BufferGeometry) {
  16914. _inheritsLoose(PolyhedronGeometry, _BufferGeometry);
  16915. function PolyhedronGeometry(vertices, indices, radius, detail) {
  16916. var _this;
  16917. if (radius === void 0) {
  16918. radius = 1;
  16919. }
  16920. if (detail === void 0) {
  16921. detail = 0;
  16922. }
  16923. _this = _BufferGeometry.call(this) || this;
  16924. _this.type = 'PolyhedronGeometry';
  16925. _this.parameters = {
  16926. vertices: vertices,
  16927. indices: indices,
  16928. radius: radius,
  16929. detail: detail
  16930. }; // default buffer data
  16931. var vertexBuffer = [];
  16932. var uvBuffer = []; // the subdivision creates the vertex buffer data
  16933. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  16934. applyRadius(radius); // finally, create the uv data
  16935. generateUVs(); // build non-indexed geometry
  16936. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  16937. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  16938. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  16939. if (detail === 0) {
  16940. _this.computeVertexNormals(); // flat normals
  16941. } else {
  16942. _this.normalizeNormals(); // smooth normals
  16943. } // helper functions
  16944. function subdivide(detail) {
  16945. var a = new Vector3();
  16946. var b = new Vector3();
  16947. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  16948. for (var i = 0; i < indices.length; i += 3) {
  16949. // get the vertices of the face
  16950. getVertexByIndex(indices[i + 0], a);
  16951. getVertexByIndex(indices[i + 1], b);
  16952. getVertexByIndex(indices[i + 2], c); // perform subdivision
  16953. subdivideFace(a, b, c, detail);
  16954. }
  16955. }
  16956. function subdivideFace(a, b, c, detail) {
  16957. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  16958. var v = []; // construct all of the vertices for this subdivision
  16959. for (var i = 0; i <= cols; i++) {
  16960. v[i] = [];
  16961. var aj = a.clone().lerp(c, i / cols);
  16962. var bj = b.clone().lerp(c, i / cols);
  16963. var rows = cols - i;
  16964. for (var j = 0; j <= rows; j++) {
  16965. if (j === 0 && i === cols) {
  16966. v[i][j] = aj;
  16967. } else {
  16968. v[i][j] = aj.clone().lerp(bj, j / rows);
  16969. }
  16970. }
  16971. } // construct all of the faces
  16972. for (var _i = 0; _i < cols; _i++) {
  16973. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  16974. var k = Math.floor(_j / 2);
  16975. if (_j % 2 === 0) {
  16976. pushVertex(v[_i][k + 1]);
  16977. pushVertex(v[_i + 1][k]);
  16978. pushVertex(v[_i][k]);
  16979. } else {
  16980. pushVertex(v[_i][k + 1]);
  16981. pushVertex(v[_i + 1][k + 1]);
  16982. pushVertex(v[_i + 1][k]);
  16983. }
  16984. }
  16985. }
  16986. }
  16987. function applyRadius(radius) {
  16988. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  16989. for (var i = 0; i < vertexBuffer.length; i += 3) {
  16990. vertex.x = vertexBuffer[i + 0];
  16991. vertex.y = vertexBuffer[i + 1];
  16992. vertex.z = vertexBuffer[i + 2];
  16993. vertex.normalize().multiplyScalar(radius);
  16994. vertexBuffer[i + 0] = vertex.x;
  16995. vertexBuffer[i + 1] = vertex.y;
  16996. vertexBuffer[i + 2] = vertex.z;
  16997. }
  16998. }
  16999. function generateUVs() {
  17000. var vertex = new Vector3();
  17001. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17002. vertex.x = vertexBuffer[i + 0];
  17003. vertex.y = vertexBuffer[i + 1];
  17004. vertex.z = vertexBuffer[i + 2];
  17005. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17006. var v = inclination(vertex) / Math.PI + 0.5;
  17007. uvBuffer.push(u, 1 - v);
  17008. }
  17009. correctUVs();
  17010. correctSeam();
  17011. }
  17012. function correctSeam() {
  17013. // handle case when face straddles the seam, see #3269
  17014. for (var i = 0; i < uvBuffer.length; i += 6) {
  17015. // uv data of a single face
  17016. var x0 = uvBuffer[i + 0];
  17017. var x1 = uvBuffer[i + 2];
  17018. var x2 = uvBuffer[i + 4];
  17019. var max = Math.max(x0, x1, x2);
  17020. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17021. if (max > 0.9 && min < 0.1) {
  17022. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17023. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17024. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17025. }
  17026. }
  17027. }
  17028. function pushVertex(vertex) {
  17029. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17030. }
  17031. function getVertexByIndex(index, vertex) {
  17032. var stride = index * 3;
  17033. vertex.x = vertices[stride + 0];
  17034. vertex.y = vertices[stride + 1];
  17035. vertex.z = vertices[stride + 2];
  17036. }
  17037. function correctUVs() {
  17038. var a = new Vector3();
  17039. var b = new Vector3();
  17040. var c = new Vector3();
  17041. var centroid = new Vector3();
  17042. var uvA = new Vector2();
  17043. var uvB = new Vector2();
  17044. var uvC = new Vector2();
  17045. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17046. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17047. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17048. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17049. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17050. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17051. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17052. centroid.copy(a).add(b).add(c).divideScalar(3);
  17053. var azi = azimuth(centroid);
  17054. correctUV(uvA, j + 0, a, azi);
  17055. correctUV(uvB, j + 2, b, azi);
  17056. correctUV(uvC, j + 4, c, azi);
  17057. }
  17058. }
  17059. function correctUV(uv, stride, vector, azimuth) {
  17060. if (azimuth < 0 && uv.x === 1) {
  17061. uvBuffer[stride] = uv.x - 1;
  17062. }
  17063. if (vector.x === 0 && vector.z === 0) {
  17064. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17065. }
  17066. } // Angle around the Y axis, counter-clockwise when looking from above.
  17067. function azimuth(vector) {
  17068. return Math.atan2(vector.z, -vector.x);
  17069. } // Angle above the XZ plane.
  17070. function inclination(vector) {
  17071. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17072. }
  17073. return _this;
  17074. }
  17075. return PolyhedronGeometry;
  17076. }(BufferGeometry);
  17077. var DodecahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  17078. _inheritsLoose(DodecahedronGeometry, _PolyhedronGeometry);
  17079. function DodecahedronGeometry(radius, detail) {
  17080. var _this;
  17081. if (radius === void 0) {
  17082. radius = 1;
  17083. }
  17084. if (detail === void 0) {
  17085. detail = 0;
  17086. }
  17087. var t = (1 + Math.sqrt(5)) / 2;
  17088. var r = 1 / t;
  17089. var vertices = [// (±1, ±1, ±1)
  17090. -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/φ, ±φ)
  17091. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17092. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17093. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17094. 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];
  17095. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  17096. _this.type = 'DodecahedronGeometry';
  17097. _this.parameters = {
  17098. radius: radius,
  17099. detail: detail
  17100. };
  17101. return _this;
  17102. }
  17103. return DodecahedronGeometry;
  17104. }(PolyhedronGeometry);
  17105. var _v0$2 = new Vector3();
  17106. var _v1$5 = new Vector3();
  17107. var _normal$1 = new Vector3();
  17108. var _triangle = new Triangle();
  17109. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17110. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17111. function EdgesGeometry(geometry, thresholdAngle) {
  17112. var _this;
  17113. _this = _BufferGeometry.call(this) || this;
  17114. _this.type = 'EdgesGeometry';
  17115. _this.parameters = {
  17116. thresholdAngle: thresholdAngle
  17117. };
  17118. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17119. if (geometry.isGeometry === true) {
  17120. console.error('THREE.EdgesGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17121. return _assertThisInitialized(_this);
  17122. }
  17123. var precisionPoints = 4;
  17124. var precision = Math.pow(10, precisionPoints);
  17125. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17126. var indexAttr = geometry.getIndex();
  17127. var positionAttr = geometry.getAttribute('position');
  17128. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17129. var indexArr = [0, 0, 0];
  17130. var vertKeys = ['a', 'b', 'c'];
  17131. var hashes = new Array(3);
  17132. var edgeData = {};
  17133. var vertices = [];
  17134. for (var i = 0; i < indexCount; i += 3) {
  17135. if (indexAttr) {
  17136. indexArr[0] = indexAttr.getX(i);
  17137. indexArr[1] = indexAttr.getX(i + 1);
  17138. indexArr[2] = indexAttr.getX(i + 2);
  17139. } else {
  17140. indexArr[0] = i;
  17141. indexArr[1] = i + 1;
  17142. indexArr[2] = i + 2;
  17143. }
  17144. var a = _triangle.a,
  17145. b = _triangle.b,
  17146. c = _triangle.c;
  17147. a.fromBufferAttribute(positionAttr, indexArr[0]);
  17148. b.fromBufferAttribute(positionAttr, indexArr[1]);
  17149. c.fromBufferAttribute(positionAttr, indexArr[2]);
  17150. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  17151. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  17152. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  17153. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  17154. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  17155. continue;
  17156. } // iterate over every edge
  17157. for (var j = 0; j < 3; j++) {
  17158. // get the first and next vertex making up the edge
  17159. var jNext = (j + 1) % 3;
  17160. var vecHash0 = hashes[j];
  17161. var vecHash1 = hashes[jNext];
  17162. var v0 = _triangle[vertKeys[j]];
  17163. var v1 = _triangle[vertKeys[jNext]];
  17164. var hash = vecHash0 + "_" + vecHash1;
  17165. var reverseHash = vecHash1 + "_" + vecHash0;
  17166. if (reverseHash in edgeData && edgeData[reverseHash]) {
  17167. // if we found a sibling edge add it into the vertex array if
  17168. // it meets the angle threshold and delete the edge from the map.
  17169. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  17170. vertices.push(v0.x, v0.y, v0.z);
  17171. vertices.push(v1.x, v1.y, v1.z);
  17172. }
  17173. edgeData[reverseHash] = null;
  17174. } else if (!(hash in edgeData)) {
  17175. // if we've already got an edge here then skip adding a new one
  17176. edgeData[hash] = {
  17177. index0: indexArr[j],
  17178. index1: indexArr[jNext],
  17179. normal: _normal$1.clone()
  17180. };
  17181. }
  17182. }
  17183. } // iterate over all remaining, unmatched edges and add them to the vertex array
  17184. for (var key in edgeData) {
  17185. if (edgeData[key]) {
  17186. var _edgeData$key = edgeData[key],
  17187. index0 = _edgeData$key.index0,
  17188. index1 = _edgeData$key.index1;
  17189. _v0$2.fromBufferAttribute(positionAttr, index0);
  17190. _v1$5.fromBufferAttribute(positionAttr, index1);
  17191. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  17192. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  17193. }
  17194. }
  17195. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17196. return _this;
  17197. }
  17198. return EdgesGeometry;
  17199. }(BufferGeometry);
  17200. /**
  17201. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17202. */
  17203. var Earcut = {
  17204. triangulate: function triangulate(data, holeIndices, dim) {
  17205. dim = dim || 2;
  17206. var hasHoles = holeIndices && holeIndices.length;
  17207. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  17208. var outerNode = linkedList(data, 0, outerLen, dim, true);
  17209. var triangles = [];
  17210. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  17211. var minX, minY, maxX, maxY, x, y, invSize;
  17212. 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
  17213. if (data.length > 80 * dim) {
  17214. minX = maxX = data[0];
  17215. minY = maxY = data[1];
  17216. for (var i = dim; i < outerLen; i += dim) {
  17217. x = data[i];
  17218. y = data[i + 1];
  17219. if (x < minX) minX = x;
  17220. if (y < minY) minY = y;
  17221. if (x > maxX) maxX = x;
  17222. if (y > maxY) maxY = y;
  17223. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17224. invSize = Math.max(maxX - minX, maxY - minY);
  17225. invSize = invSize !== 0 ? 1 / invSize : 0;
  17226. }
  17227. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  17228. return triangles;
  17229. }
  17230. }; // create a circular doubly linked list from polygon points in the specified winding order
  17231. function linkedList(data, start, end, dim, clockwise) {
  17232. var i, last;
  17233. if (clockwise === signedArea(data, start, end, dim) > 0) {
  17234. for (i = start; i < end; i += dim) {
  17235. last = insertNode(i, data[i], data[i + 1], last);
  17236. }
  17237. } else {
  17238. for (i = end - dim; i >= start; i -= dim) {
  17239. last = insertNode(i, data[i], data[i + 1], last);
  17240. }
  17241. }
  17242. if (last && equals(last, last.next)) {
  17243. removeNode(last);
  17244. last = last.next;
  17245. }
  17246. return last;
  17247. } // eliminate colinear or duplicate points
  17248. function filterPoints(start, end) {
  17249. if (!start) return start;
  17250. if (!end) end = start;
  17251. var p = start,
  17252. again;
  17253. do {
  17254. again = false;
  17255. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  17256. removeNode(p);
  17257. p = end = p.prev;
  17258. if (p === p.next) break;
  17259. again = true;
  17260. } else {
  17261. p = p.next;
  17262. }
  17263. } while (again || p !== end);
  17264. return end;
  17265. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  17266. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  17267. if (!ear) return; // interlink polygon nodes in z-order
  17268. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  17269. var stop = ear,
  17270. prev,
  17271. next; // iterate through ears, slicing them one by one
  17272. while (ear.prev !== ear.next) {
  17273. prev = ear.prev;
  17274. next = ear.next;
  17275. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  17276. // cut off the triangle
  17277. triangles.push(prev.i / dim);
  17278. triangles.push(ear.i / dim);
  17279. triangles.push(next.i / dim);
  17280. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  17281. ear = next.next;
  17282. stop = next.next;
  17283. continue;
  17284. }
  17285. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  17286. if (ear === stop) {
  17287. // try filtering points and slicing again
  17288. if (!pass) {
  17289. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  17290. } else if (pass === 1) {
  17291. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  17292. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  17293. } else if (pass === 2) {
  17294. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  17295. }
  17296. break;
  17297. }
  17298. }
  17299. } // check whether a polygon node forms a valid ear with adjacent nodes
  17300. function isEar(ear) {
  17301. var a = ear.prev,
  17302. b = ear,
  17303. c = ear.next;
  17304. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17305. // now make sure we don't have other points inside the potential ear
  17306. var p = ear.next.next;
  17307. while (p !== ear.prev) {
  17308. 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;
  17309. p = p.next;
  17310. }
  17311. return true;
  17312. }
  17313. function isEarHashed(ear, minX, minY, invSize) {
  17314. var a = ear.prev,
  17315. b = ear,
  17316. c = ear.next;
  17317. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17318. // triangle bbox; min & max are calculated like this for speed
  17319. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  17320. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  17321. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  17322. 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;
  17323. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  17324. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  17325. var p = ear.prevZ,
  17326. n = ear.nextZ; // look for points inside the triangle in both directions
  17327. while (p && p.z >= minZ && n && n.z <= maxZ) {
  17328. 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;
  17329. p = p.prevZ;
  17330. 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;
  17331. n = n.nextZ;
  17332. } // look for remaining points in decreasing z-order
  17333. while (p && p.z >= minZ) {
  17334. 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;
  17335. p = p.prevZ;
  17336. } // look for remaining points in increasing z-order
  17337. while (n && n.z <= maxZ) {
  17338. 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;
  17339. n = n.nextZ;
  17340. }
  17341. return true;
  17342. } // go through all polygon nodes and cure small local self-intersections
  17343. function cureLocalIntersections(start, triangles, dim) {
  17344. var p = start;
  17345. do {
  17346. var a = p.prev,
  17347. b = p.next.next;
  17348. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  17349. triangles.push(a.i / dim);
  17350. triangles.push(p.i / dim);
  17351. triangles.push(b.i / dim); // remove two nodes involved
  17352. removeNode(p);
  17353. removeNode(p.next);
  17354. p = start = b;
  17355. }
  17356. p = p.next;
  17357. } while (p !== start);
  17358. return filterPoints(p);
  17359. } // try splitting polygon into two and triangulate them independently
  17360. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  17361. // look for a valid diagonal that divides the polygon into two
  17362. var a = start;
  17363. do {
  17364. var b = a.next.next;
  17365. while (b !== a.prev) {
  17366. if (a.i !== b.i && isValidDiagonal(a, b)) {
  17367. // split the polygon in two by the diagonal
  17368. var c = splitPolygon(a, b); // filter colinear points around the cuts
  17369. a = filterPoints(a, a.next);
  17370. c = filterPoints(c, c.next); // run earcut on each half
  17371. earcutLinked(a, triangles, dim, minX, minY, invSize);
  17372. earcutLinked(c, triangles, dim, minX, minY, invSize);
  17373. return;
  17374. }
  17375. b = b.next;
  17376. }
  17377. a = a.next;
  17378. } while (a !== start);
  17379. } // link every hole into the outer loop, producing a single-ring polygon without holes
  17380. function eliminateHoles(data, holeIndices, outerNode, dim) {
  17381. var queue = [];
  17382. var i, len, start, end, list;
  17383. for (i = 0, len = holeIndices.length; i < len; i++) {
  17384. start = holeIndices[i] * dim;
  17385. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  17386. list = linkedList(data, start, end, dim, false);
  17387. if (list === list.next) list.steiner = true;
  17388. queue.push(getLeftmost(list));
  17389. }
  17390. queue.sort(compareX); // process holes from left to right
  17391. for (i = 0; i < queue.length; i++) {
  17392. eliminateHole(queue[i], outerNode);
  17393. outerNode = filterPoints(outerNode, outerNode.next);
  17394. }
  17395. return outerNode;
  17396. }
  17397. function compareX(a, b) {
  17398. return a.x - b.x;
  17399. } // find a bridge between vertices that connects hole with an outer ring and and link it
  17400. function eliminateHole(hole, outerNode) {
  17401. outerNode = findHoleBridge(hole, outerNode);
  17402. if (outerNode) {
  17403. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  17404. filterPoints(outerNode, outerNode.next);
  17405. filterPoints(b, b.next);
  17406. }
  17407. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17408. function findHoleBridge(hole, outerNode) {
  17409. var p = outerNode;
  17410. var hx = hole.x;
  17411. var hy = hole.y;
  17412. var qx = -Infinity,
  17413. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  17414. // segment's endpoint with lesser x will be potential connection point
  17415. do {
  17416. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  17417. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  17418. if (x <= hx && x > qx) {
  17419. qx = x;
  17420. if (x === hx) {
  17421. if (hy === p.y) return p;
  17422. if (hy === p.next.y) return p.next;
  17423. }
  17424. m = p.x < p.next.x ? p : p.next;
  17425. }
  17426. }
  17427. p = p.next;
  17428. } while (p !== outerNode);
  17429. if (!m) return null;
  17430. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  17431. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17432. // if there are no points found, we have a valid connection;
  17433. // otherwise choose the point of the minimum angle with the ray as connection point
  17434. var stop = m,
  17435. mx = m.x,
  17436. my = m.y;
  17437. var tanMin = Infinity,
  17438. tan;
  17439. p = m;
  17440. do {
  17441. 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)) {
  17442. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  17443. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  17444. m = p;
  17445. tanMin = tan;
  17446. }
  17447. }
  17448. p = p.next;
  17449. } while (p !== stop);
  17450. return m;
  17451. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  17452. function sectorContainsSector(m, p) {
  17453. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  17454. } // interlink polygon nodes in z-order
  17455. function indexCurve(start, minX, minY, invSize) {
  17456. var p = start;
  17457. do {
  17458. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  17459. p.prevZ = p.prev;
  17460. p.nextZ = p.next;
  17461. p = p.next;
  17462. } while (p !== start);
  17463. p.prevZ.nextZ = null;
  17464. p.prevZ = null;
  17465. sortLinked(p);
  17466. } // Simon Tatham's linked list merge sort algorithm
  17467. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17468. function sortLinked(list) {
  17469. var i,
  17470. p,
  17471. q,
  17472. e,
  17473. tail,
  17474. numMerges,
  17475. pSize,
  17476. qSize,
  17477. inSize = 1;
  17478. do {
  17479. p = list;
  17480. list = null;
  17481. tail = null;
  17482. numMerges = 0;
  17483. while (p) {
  17484. numMerges++;
  17485. q = p;
  17486. pSize = 0;
  17487. for (i = 0; i < inSize; i++) {
  17488. pSize++;
  17489. q = q.nextZ;
  17490. if (!q) break;
  17491. }
  17492. qSize = inSize;
  17493. while (pSize > 0 || qSize > 0 && q) {
  17494. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  17495. e = p;
  17496. p = p.nextZ;
  17497. pSize--;
  17498. } else {
  17499. e = q;
  17500. q = q.nextZ;
  17501. qSize--;
  17502. }
  17503. if (tail) tail.nextZ = e;else list = e;
  17504. e.prevZ = tail;
  17505. tail = e;
  17506. }
  17507. p = q;
  17508. }
  17509. tail.nextZ = null;
  17510. inSize *= 2;
  17511. } while (numMerges > 1);
  17512. return list;
  17513. } // z-order of a point given coords and inverse of the longer side of data bbox
  17514. function zOrder(x, y, minX, minY, invSize) {
  17515. // coords are transformed into non-negative 15-bit integer range
  17516. x = 32767 * (x - minX) * invSize;
  17517. y = 32767 * (y - minY) * invSize;
  17518. x = (x | x << 8) & 0x00FF00FF;
  17519. x = (x | x << 4) & 0x0F0F0F0F;
  17520. x = (x | x << 2) & 0x33333333;
  17521. x = (x | x << 1) & 0x55555555;
  17522. y = (y | y << 8) & 0x00FF00FF;
  17523. y = (y | y << 4) & 0x0F0F0F0F;
  17524. y = (y | y << 2) & 0x33333333;
  17525. y = (y | y << 1) & 0x55555555;
  17526. return x | y << 1;
  17527. } // find the leftmost node of a polygon ring
  17528. function getLeftmost(start) {
  17529. var p = start,
  17530. leftmost = start;
  17531. do {
  17532. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  17533. p = p.next;
  17534. } while (p !== start);
  17535. return leftmost;
  17536. } // check if a point lies within a convex triangle
  17537. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  17538. 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;
  17539. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  17540. function isValidDiagonal(a, b) {
  17541. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  17542. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  17543. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  17544. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  17545. } // signed area of a triangle
  17546. function area(p, q, r) {
  17547. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  17548. } // check if two points are equal
  17549. function equals(p1, p2) {
  17550. return p1.x === p2.x && p1.y === p2.y;
  17551. } // check if two segments intersect
  17552. function intersects(p1, q1, p2, q2) {
  17553. var o1 = sign(area(p1, q1, p2));
  17554. var o2 = sign(area(p1, q1, q2));
  17555. var o3 = sign(area(p2, q2, p1));
  17556. var o4 = sign(area(p2, q2, q1));
  17557. if (o1 !== o2 && o3 !== o4) return true; // general case
  17558. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  17559. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  17560. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  17561. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  17562. return false;
  17563. } // for collinear points p, q, r, check if point q lies on segment pr
  17564. function onSegment(p, q, r) {
  17565. 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);
  17566. }
  17567. function sign(num) {
  17568. return num > 0 ? 1 : num < 0 ? -1 : 0;
  17569. } // check if a polygon diagonal intersects any polygon segments
  17570. function intersectsPolygon(a, b) {
  17571. var p = a;
  17572. do {
  17573. 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;
  17574. p = p.next;
  17575. } while (p !== a);
  17576. return false;
  17577. } // check if a polygon diagonal is locally inside the polygon
  17578. function locallyInside(a, b) {
  17579. 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;
  17580. } // check if the middle point of a polygon diagonal is inside the polygon
  17581. function middleInside(a, b) {
  17582. var p = a,
  17583. inside = false;
  17584. var px = (a.x + b.x) / 2,
  17585. py = (a.y + b.y) / 2;
  17586. do {
  17587. 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;
  17588. p = p.next;
  17589. } while (p !== a);
  17590. return inside;
  17591. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  17592. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  17593. function splitPolygon(a, b) {
  17594. var a2 = new Node(a.i, a.x, a.y),
  17595. b2 = new Node(b.i, b.x, b.y),
  17596. an = a.next,
  17597. bp = b.prev;
  17598. a.next = b;
  17599. b.prev = a;
  17600. a2.next = an;
  17601. an.prev = a2;
  17602. b2.next = a2;
  17603. a2.prev = b2;
  17604. bp.next = b2;
  17605. b2.prev = bp;
  17606. return b2;
  17607. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  17608. function insertNode(i, x, y, last) {
  17609. var p = new Node(i, x, y);
  17610. if (!last) {
  17611. p.prev = p;
  17612. p.next = p;
  17613. } else {
  17614. p.next = last.next;
  17615. p.prev = last;
  17616. last.next.prev = p;
  17617. last.next = p;
  17618. }
  17619. return p;
  17620. }
  17621. function removeNode(p) {
  17622. p.next.prev = p.prev;
  17623. p.prev.next = p.next;
  17624. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  17625. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  17626. }
  17627. function Node(i, x, y) {
  17628. // vertex index in coordinates array
  17629. this.i = i; // vertex coordinates
  17630. this.x = x;
  17631. this.y = y; // previous and next vertex nodes in a polygon ring
  17632. this.prev = null;
  17633. this.next = null; // z-order curve value
  17634. this.z = null; // previous and next nodes in z-order
  17635. this.prevZ = null;
  17636. this.nextZ = null; // indicates whether this is a steiner point
  17637. this.steiner = false;
  17638. }
  17639. function signedArea(data, start, end, dim) {
  17640. var sum = 0;
  17641. for (var i = start, j = end - dim; i < end; i += dim) {
  17642. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  17643. j = i;
  17644. }
  17645. return sum;
  17646. }
  17647. var ShapeUtils = {
  17648. // calculate area of the contour polygon
  17649. area: function area(contour) {
  17650. var n = contour.length;
  17651. var a = 0.0;
  17652. for (var p = n - 1, q = 0; q < n; p = q++) {
  17653. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  17654. }
  17655. return a * 0.5;
  17656. },
  17657. isClockWise: function isClockWise(pts) {
  17658. return ShapeUtils.area(pts) < 0;
  17659. },
  17660. triangulateShape: function triangulateShape(contour, holes) {
  17661. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  17662. var holeIndices = []; // array of hole indices
  17663. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  17664. removeDupEndPts(contour);
  17665. addContour(vertices, contour); //
  17666. var holeIndex = contour.length;
  17667. holes.forEach(removeDupEndPts);
  17668. for (var i = 0; i < holes.length; i++) {
  17669. holeIndices.push(holeIndex);
  17670. holeIndex += holes[i].length;
  17671. addContour(vertices, holes[i]);
  17672. } //
  17673. var triangles = Earcut.triangulate(vertices, holeIndices); //
  17674. for (var _i = 0; _i < triangles.length; _i += 3) {
  17675. faces.push(triangles.slice(_i, _i + 3));
  17676. }
  17677. return faces;
  17678. }
  17679. };
  17680. function removeDupEndPts(points) {
  17681. var l = points.length;
  17682. if (l > 2 && points[l - 1].equals(points[0])) {
  17683. points.pop();
  17684. }
  17685. }
  17686. function addContour(vertices, contour) {
  17687. for (var i = 0; i < contour.length; i++) {
  17688. vertices.push(contour[i].x);
  17689. vertices.push(contour[i].y);
  17690. }
  17691. }
  17692. var ExtrudeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17693. _inheritsLoose(ExtrudeGeometry, _BufferGeometry);
  17694. function ExtrudeGeometry(shapes, options) {
  17695. var _this;
  17696. _this = _BufferGeometry.call(this) || this;
  17697. _this.type = 'ExtrudeGeometry';
  17698. _this.parameters = {
  17699. shapes: shapes,
  17700. options: options
  17701. };
  17702. shapes = Array.isArray(shapes) ? shapes : [shapes];
  17703. var scope = _assertThisInitialized(_this);
  17704. var verticesArray = [];
  17705. var uvArray = [];
  17706. for (var i = 0, l = shapes.length; i < l; i++) {
  17707. var shape = shapes[i];
  17708. addShape(shape);
  17709. } // build geometry
  17710. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  17711. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  17712. _this.computeVertexNormals(); // functions
  17713. function addShape(shape) {
  17714. var placeholder = []; // options
  17715. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  17716. var steps = options.steps !== undefined ? options.steps : 1;
  17717. var depth = options.depth !== undefined ? options.depth : 100;
  17718. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  17719. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  17720. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  17721. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  17722. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  17723. var extrudePath = options.extrudePath;
  17724. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  17725. if (options.amount !== undefined) {
  17726. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  17727. depth = options.amount;
  17728. } //
  17729. var extrudePts,
  17730. extrudeByPath = false;
  17731. var splineTube, binormal, normal, position2;
  17732. if (extrudePath) {
  17733. extrudePts = extrudePath.getSpacedPoints(steps);
  17734. extrudeByPath = true;
  17735. bevelEnabled = false; // bevels not supported for path extrusion
  17736. // SETUP TNB variables
  17737. // TODO1 - have a .isClosed in spline?
  17738. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  17739. binormal = new Vector3();
  17740. normal = new Vector3();
  17741. position2 = new Vector3();
  17742. } // Safeguards if bevels are not enabled
  17743. if (!bevelEnabled) {
  17744. bevelSegments = 0;
  17745. bevelThickness = 0;
  17746. bevelSize = 0;
  17747. bevelOffset = 0;
  17748. } // Variables initialization
  17749. var shapePoints = shape.extractPoints(curveSegments);
  17750. var vertices = shapePoints.shape;
  17751. var holes = shapePoints.holes;
  17752. var reverse = !ShapeUtils.isClockWise(vertices);
  17753. if (reverse) {
  17754. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  17755. for (var h = 0, hl = holes.length; h < hl; h++) {
  17756. var ahole = holes[h];
  17757. if (ShapeUtils.isClockWise(ahole)) {
  17758. holes[h] = ahole.reverse();
  17759. }
  17760. }
  17761. }
  17762. var faces = ShapeUtils.triangulateShape(vertices, holes);
  17763. /* Vertices */
  17764. var contour = vertices; // vertices has all points but contour has only points of circumference
  17765. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  17766. var _ahole = holes[_h];
  17767. vertices = vertices.concat(_ahole);
  17768. }
  17769. function scalePt2(pt, vec, size) {
  17770. if (!vec) console.error('THREE.ExtrudeGeometry: vec does not exist');
  17771. return vec.clone().multiplyScalar(size).add(pt);
  17772. }
  17773. var vlen = vertices.length,
  17774. flen = faces.length; // Find directions for point movement
  17775. function getBevelVec(inPt, inPrev, inNext) {
  17776. // computes for inPt the corresponding point inPt' on a new contour
  17777. // shifted by 1 unit (length of normalized vector) to the left
  17778. // if we walk along contour clockwise, this new contour is outside the old one
  17779. //
  17780. // inPt' is the intersection of the two lines parallel to the two
  17781. // adjacent edges of inPt at a distance of 1 unit on the left side.
  17782. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  17783. // good reading for geometry algorithms (here: line-line intersection)
  17784. // http://geomalgorithms.com/a05-_intersect-1.html
  17785. var v_prev_x = inPt.x - inPrev.x,
  17786. v_prev_y = inPt.y - inPrev.y;
  17787. var v_next_x = inNext.x - inPt.x,
  17788. v_next_y = inNext.y - inPt.y;
  17789. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  17790. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  17791. if (Math.abs(collinear0) > Number.EPSILON) {
  17792. // not collinear
  17793. // length of vectors for normalizing
  17794. var v_prev_len = Math.sqrt(v_prev_lensq);
  17795. 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
  17796. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  17797. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  17798. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  17799. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  17800. 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
  17801. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  17802. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  17803. // but prevent crazy spikes
  17804. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  17805. if (v_trans_lensq <= 2) {
  17806. return new Vector2(v_trans_x, v_trans_y);
  17807. } else {
  17808. shrink_by = Math.sqrt(v_trans_lensq / 2);
  17809. }
  17810. } else {
  17811. // handle special case of collinear edges
  17812. var direction_eq = false; // assumes: opposite
  17813. if (v_prev_x > Number.EPSILON) {
  17814. if (v_next_x > Number.EPSILON) {
  17815. direction_eq = true;
  17816. }
  17817. } else {
  17818. if (v_prev_x < -Number.EPSILON) {
  17819. if (v_next_x < -Number.EPSILON) {
  17820. direction_eq = true;
  17821. }
  17822. } else {
  17823. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  17824. direction_eq = true;
  17825. }
  17826. }
  17827. }
  17828. if (direction_eq) {
  17829. // console.log("Warning: lines are a straight sequence");
  17830. v_trans_x = -v_prev_y;
  17831. v_trans_y = v_prev_x;
  17832. shrink_by = Math.sqrt(v_prev_lensq);
  17833. } else {
  17834. // console.log("Warning: lines are a straight spike");
  17835. v_trans_x = v_prev_x;
  17836. v_trans_y = v_prev_y;
  17837. shrink_by = Math.sqrt(v_prev_lensq / 2);
  17838. }
  17839. }
  17840. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  17841. }
  17842. var contourMovements = [];
  17843. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  17844. if (j === il) j = 0;
  17845. if (k === il) k = 0; // (j)---(i)---(k)
  17846. // console.log('i,j,k', i, j , k)
  17847. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  17848. }
  17849. var holesMovements = [];
  17850. var oneHoleMovements,
  17851. verticesMovements = contourMovements.concat();
  17852. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  17853. var _ahole2 = holes[_h2];
  17854. oneHoleMovements = [];
  17855. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  17856. if (_j === _il) _j = 0;
  17857. if (_k === _il) _k = 0; // (j)---(i)---(k)
  17858. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  17859. }
  17860. holesMovements.push(oneHoleMovements);
  17861. verticesMovements = verticesMovements.concat(oneHoleMovements);
  17862. } // Loop bevelSegments, 1 for the front, 1 for the back
  17863. for (var b = 0; b < bevelSegments; b++) {
  17864. //for ( b = bevelSegments; b > 0; b -- ) {
  17865. var t = b / bevelSegments;
  17866. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  17867. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  17868. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  17869. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  17870. v(vert.x, vert.y, -z);
  17871. } // expand holes
  17872. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  17873. var _ahole3 = holes[_h3];
  17874. oneHoleMovements = holesMovements[_h3];
  17875. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  17876. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  17877. v(_vert.x, _vert.y, -z);
  17878. }
  17879. }
  17880. }
  17881. var bs = bevelSize + bevelOffset; // Back facing vertices
  17882. for (var _i5 = 0; _i5 < vlen; _i5++) {
  17883. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  17884. if (!extrudeByPath) {
  17885. v(_vert2.x, _vert2.y, 0);
  17886. } else {
  17887. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  17888. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  17889. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  17890. position2.copy(extrudePts[0]).add(normal).add(binormal);
  17891. v(position2.x, position2.y, position2.z);
  17892. }
  17893. } // Add stepped vertices...
  17894. // Including front facing vertices
  17895. for (var s = 1; s <= steps; s++) {
  17896. for (var _i6 = 0; _i6 < vlen; _i6++) {
  17897. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  17898. if (!extrudeByPath) {
  17899. v(_vert3.x, _vert3.y, depth / steps * s);
  17900. } else {
  17901. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  17902. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  17903. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  17904. position2.copy(extrudePts[s]).add(normal).add(binormal);
  17905. v(position2.x, position2.y, position2.z);
  17906. }
  17907. }
  17908. } // Add bevel segments planes
  17909. //for ( b = 1; b <= bevelSegments; b ++ ) {
  17910. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  17911. var _t = _b / bevelSegments;
  17912. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  17913. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  17914. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  17915. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  17916. v(_vert4.x, _vert4.y, depth + _z);
  17917. } // expand holes
  17918. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  17919. var _ahole4 = holes[_h4];
  17920. oneHoleMovements = holesMovements[_h4];
  17921. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  17922. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  17923. if (!extrudeByPath) {
  17924. v(_vert5.x, _vert5.y, depth + _z);
  17925. } else {
  17926. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  17927. }
  17928. }
  17929. }
  17930. }
  17931. /* Faces */
  17932. // Top and bottom faces
  17933. buildLidFaces(); // Sides faces
  17934. buildSideFaces(); ///// Internal functions
  17935. function buildLidFaces() {
  17936. var start = verticesArray.length / 3;
  17937. if (bevelEnabled) {
  17938. var layer = 0; // steps + 1
  17939. var offset = vlen * layer; // Bottom faces
  17940. for (var _i9 = 0; _i9 < flen; _i9++) {
  17941. var face = faces[_i9];
  17942. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  17943. }
  17944. layer = steps + bevelSegments * 2;
  17945. offset = vlen * layer; // Top faces
  17946. for (var _i10 = 0; _i10 < flen; _i10++) {
  17947. var _face = faces[_i10];
  17948. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  17949. }
  17950. } else {
  17951. // Bottom faces
  17952. for (var _i11 = 0; _i11 < flen; _i11++) {
  17953. var _face2 = faces[_i11];
  17954. f3(_face2[2], _face2[1], _face2[0]);
  17955. } // Top faces
  17956. for (var _i12 = 0; _i12 < flen; _i12++) {
  17957. var _face3 = faces[_i12];
  17958. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  17959. }
  17960. }
  17961. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  17962. } // Create faces for the z-sides of the shape
  17963. function buildSideFaces() {
  17964. var start = verticesArray.length / 3;
  17965. var layeroffset = 0;
  17966. sidewalls(contour, layeroffset);
  17967. layeroffset += contour.length;
  17968. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  17969. var _ahole5 = holes[_h5];
  17970. sidewalls(_ahole5, layeroffset); //, true
  17971. layeroffset += _ahole5.length;
  17972. }
  17973. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  17974. }
  17975. function sidewalls(contour, layeroffset) {
  17976. var i = contour.length;
  17977. while (--i >= 0) {
  17978. var _j2 = i;
  17979. var _k2 = i - 1;
  17980. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  17981. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  17982. var slen1 = vlen * _s;
  17983. var slen2 = vlen * (_s + 1);
  17984. var a = layeroffset + _j2 + slen1,
  17985. _b2 = layeroffset + _k2 + slen1,
  17986. c = layeroffset + _k2 + slen2,
  17987. d = layeroffset + _j2 + slen2;
  17988. f4(a, _b2, c, d);
  17989. }
  17990. }
  17991. }
  17992. function v(x, y, z) {
  17993. placeholder.push(x);
  17994. placeholder.push(y);
  17995. placeholder.push(z);
  17996. }
  17997. function f3(a, b, c) {
  17998. addVertex(a);
  17999. addVertex(b);
  18000. addVertex(c);
  18001. var nextIndex = verticesArray.length / 3;
  18002. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18003. addUV(uvs[0]);
  18004. addUV(uvs[1]);
  18005. addUV(uvs[2]);
  18006. }
  18007. function f4(a, b, c, d) {
  18008. addVertex(a);
  18009. addVertex(b);
  18010. addVertex(d);
  18011. addVertex(b);
  18012. addVertex(c);
  18013. addVertex(d);
  18014. var nextIndex = verticesArray.length / 3;
  18015. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18016. addUV(uvs[0]);
  18017. addUV(uvs[1]);
  18018. addUV(uvs[3]);
  18019. addUV(uvs[1]);
  18020. addUV(uvs[2]);
  18021. addUV(uvs[3]);
  18022. }
  18023. function addVertex(index) {
  18024. verticesArray.push(placeholder[index * 3 + 0]);
  18025. verticesArray.push(placeholder[index * 3 + 1]);
  18026. verticesArray.push(placeholder[index * 3 + 2]);
  18027. }
  18028. function addUV(vector2) {
  18029. uvArray.push(vector2.x);
  18030. uvArray.push(vector2.y);
  18031. }
  18032. }
  18033. return _this;
  18034. }
  18035. var _proto = ExtrudeGeometry.prototype;
  18036. _proto.toJSON = function toJSON() {
  18037. var data = BufferGeometry.prototype.toJSON.call(this);
  18038. var shapes = this.parameters.shapes;
  18039. var options = this.parameters.options;
  18040. return _toJSON(shapes, options, data);
  18041. };
  18042. return ExtrudeGeometry;
  18043. }(BufferGeometry);
  18044. var WorldUVGenerator = {
  18045. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18046. var a_x = vertices[indexA * 3];
  18047. var a_y = vertices[indexA * 3 + 1];
  18048. var b_x = vertices[indexB * 3];
  18049. var b_y = vertices[indexB * 3 + 1];
  18050. var c_x = vertices[indexC * 3];
  18051. var c_y = vertices[indexC * 3 + 1];
  18052. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18053. },
  18054. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18055. var a_x = vertices[indexA * 3];
  18056. var a_y = vertices[indexA * 3 + 1];
  18057. var a_z = vertices[indexA * 3 + 2];
  18058. var b_x = vertices[indexB * 3];
  18059. var b_y = vertices[indexB * 3 + 1];
  18060. var b_z = vertices[indexB * 3 + 2];
  18061. var c_x = vertices[indexC * 3];
  18062. var c_y = vertices[indexC * 3 + 1];
  18063. var c_z = vertices[indexC * 3 + 2];
  18064. var d_x = vertices[indexD * 3];
  18065. var d_y = vertices[indexD * 3 + 1];
  18066. var d_z = vertices[indexD * 3 + 2];
  18067. if (Math.abs(a_y - b_y) < 0.01) {
  18068. 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)];
  18069. } else {
  18070. 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)];
  18071. }
  18072. }
  18073. };
  18074. function _toJSON(shapes, options, data) {
  18075. data.shapes = [];
  18076. if (Array.isArray(shapes)) {
  18077. for (var i = 0, l = shapes.length; i < l; i++) {
  18078. var shape = shapes[i];
  18079. data.shapes.push(shape.uuid);
  18080. }
  18081. } else {
  18082. data.shapes.push(shapes.uuid);
  18083. }
  18084. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18085. return data;
  18086. }
  18087. var IcosahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18088. _inheritsLoose(IcosahedronGeometry, _PolyhedronGeometry);
  18089. function IcosahedronGeometry(radius, detail) {
  18090. var _this;
  18091. if (radius === void 0) {
  18092. radius = 1;
  18093. }
  18094. if (detail === void 0) {
  18095. detail = 0;
  18096. }
  18097. var t = (1 + Math.sqrt(5)) / 2;
  18098. 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];
  18099. 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];
  18100. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18101. _this.type = 'IcosahedronGeometry';
  18102. _this.parameters = {
  18103. radius: radius,
  18104. detail: detail
  18105. };
  18106. return _this;
  18107. }
  18108. return IcosahedronGeometry;
  18109. }(PolyhedronGeometry);
  18110. var LatheGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18111. _inheritsLoose(LatheGeometry, _BufferGeometry);
  18112. function LatheGeometry(points, segments, phiStart, phiLength) {
  18113. var _this;
  18114. if (segments === void 0) {
  18115. segments = 12;
  18116. }
  18117. if (phiStart === void 0) {
  18118. phiStart = 0;
  18119. }
  18120. if (phiLength === void 0) {
  18121. phiLength = Math.PI * 2;
  18122. }
  18123. _this = _BufferGeometry.call(this) || this;
  18124. _this.type = 'LatheGeometry';
  18125. _this.parameters = {
  18126. points: points,
  18127. segments: segments,
  18128. phiStart: phiStart,
  18129. phiLength: phiLength
  18130. };
  18131. segments = Math.floor(segments); // clamp phiLength so it's in range of [ 0, 2PI ]
  18132. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  18133. var indices = [];
  18134. var vertices = [];
  18135. var uvs = []; // helper variables
  18136. var inverseSegments = 1.0 / segments;
  18137. var vertex = new Vector3();
  18138. var uv = new Vector2(); // generate vertices and uvs
  18139. for (var i = 0; i <= segments; i++) {
  18140. var phi = phiStart + i * inverseSegments * phiLength;
  18141. var sin = Math.sin(phi);
  18142. var cos = Math.cos(phi);
  18143. for (var j = 0; j <= points.length - 1; j++) {
  18144. // vertex
  18145. vertex.x = points[j].x * sin;
  18146. vertex.y = points[j].y;
  18147. vertex.z = points[j].x * cos;
  18148. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  18149. uv.x = i / segments;
  18150. uv.y = j / (points.length - 1);
  18151. uvs.push(uv.x, uv.y);
  18152. }
  18153. } // indices
  18154. for (var _i = 0; _i < segments; _i++) {
  18155. for (var _j = 0; _j < points.length - 1; _j++) {
  18156. var base = _j + _i * points.length;
  18157. var a = base;
  18158. var b = base + points.length;
  18159. var c = base + points.length + 1;
  18160. var d = base + 1; // faces
  18161. indices.push(a, b, d);
  18162. indices.push(b, c, d);
  18163. }
  18164. } // build geometry
  18165. _this.setIndex(indices);
  18166. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18167. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  18168. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  18169. // because the corresponding vertices are identical (but still have different UVs).
  18170. if (phiLength === Math.PI * 2) {
  18171. var normals = _this.attributes.normal.array;
  18172. var n1 = new Vector3();
  18173. var n2 = new Vector3();
  18174. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  18175. var _base = segments * points.length * 3;
  18176. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  18177. // select the normal of the vertex in the first line
  18178. n1.x = normals[_j2 + 0];
  18179. n1.y = normals[_j2 + 1];
  18180. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  18181. n2.x = normals[_base + _j2 + 0];
  18182. n2.y = normals[_base + _j2 + 1];
  18183. n2.z = normals[_base + _j2 + 2]; // average normals
  18184. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  18185. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  18186. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  18187. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  18188. }
  18189. }
  18190. return _this;
  18191. }
  18192. return LatheGeometry;
  18193. }(BufferGeometry);
  18194. var OctahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18195. _inheritsLoose(OctahedronGeometry, _PolyhedronGeometry);
  18196. function OctahedronGeometry(radius, detail) {
  18197. var _this;
  18198. if (radius === void 0) {
  18199. radius = 1;
  18200. }
  18201. if (detail === void 0) {
  18202. detail = 0;
  18203. }
  18204. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  18205. 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];
  18206. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18207. _this.type = 'OctahedronGeometry';
  18208. _this.parameters = {
  18209. radius: radius,
  18210. detail: detail
  18211. };
  18212. return _this;
  18213. }
  18214. return OctahedronGeometry;
  18215. }(PolyhedronGeometry);
  18216. /**
  18217. * Parametric Surfaces Geometry
  18218. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18219. */
  18220. function ParametricGeometry(func, slices, stacks) {
  18221. BufferGeometry.call(this);
  18222. this.type = 'ParametricGeometry';
  18223. this.parameters = {
  18224. func: func,
  18225. slices: slices,
  18226. stacks: stacks
  18227. }; // buffers
  18228. var indices = [];
  18229. var vertices = [];
  18230. var normals = [];
  18231. var uvs = [];
  18232. var EPS = 0.00001;
  18233. var normal = new Vector3();
  18234. var p0 = new Vector3(),
  18235. p1 = new Vector3();
  18236. var pu = new Vector3(),
  18237. pv = new Vector3();
  18238. if (func.length < 3) {
  18239. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  18240. } // generate vertices, normals and uvs
  18241. var sliceCount = slices + 1;
  18242. for (var i = 0; i <= stacks; i++) {
  18243. var v = i / stacks;
  18244. for (var j = 0; j <= slices; j++) {
  18245. var u = j / slices; // vertex
  18246. func(u, v, p0);
  18247. vertices.push(p0.x, p0.y, p0.z); // normal
  18248. // approximate tangent vectors via finite differences
  18249. if (u - EPS >= 0) {
  18250. func(u - EPS, v, p1);
  18251. pu.subVectors(p0, p1);
  18252. } else {
  18253. func(u + EPS, v, p1);
  18254. pu.subVectors(p1, p0);
  18255. }
  18256. if (v - EPS >= 0) {
  18257. func(u, v - EPS, p1);
  18258. pv.subVectors(p0, p1);
  18259. } else {
  18260. func(u, v + EPS, p1);
  18261. pv.subVectors(p1, p0);
  18262. } // cross product of tangent vectors returns surface normal
  18263. normal.crossVectors(pu, pv).normalize();
  18264. normals.push(normal.x, normal.y, normal.z); // uv
  18265. uvs.push(u, v);
  18266. }
  18267. } // generate indices
  18268. for (var _i = 0; _i < stacks; _i++) {
  18269. for (var _j = 0; _j < slices; _j++) {
  18270. var a = _i * sliceCount + _j;
  18271. var b = _i * sliceCount + _j + 1;
  18272. var c = (_i + 1) * sliceCount + _j + 1;
  18273. var d = (_i + 1) * sliceCount + _j; // faces one and two
  18274. indices.push(a, b, d);
  18275. indices.push(b, c, d);
  18276. }
  18277. } // build geometry
  18278. this.setIndex(indices);
  18279. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18280. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18281. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18282. }
  18283. ParametricGeometry.prototype = Object.create(BufferGeometry.prototype);
  18284. ParametricGeometry.prototype.constructor = ParametricGeometry;
  18285. var RingGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18286. _inheritsLoose(RingGeometry, _BufferGeometry);
  18287. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18288. var _this;
  18289. if (innerRadius === void 0) {
  18290. innerRadius = 0.5;
  18291. }
  18292. if (outerRadius === void 0) {
  18293. outerRadius = 1;
  18294. }
  18295. if (thetaSegments === void 0) {
  18296. thetaSegments = 8;
  18297. }
  18298. if (phiSegments === void 0) {
  18299. phiSegments = 1;
  18300. }
  18301. if (thetaStart === void 0) {
  18302. thetaStart = 0;
  18303. }
  18304. if (thetaLength === void 0) {
  18305. thetaLength = Math.PI * 2;
  18306. }
  18307. _this = _BufferGeometry.call(this) || this;
  18308. _this.type = 'RingGeometry';
  18309. _this.parameters = {
  18310. innerRadius: innerRadius,
  18311. outerRadius: outerRadius,
  18312. thetaSegments: thetaSegments,
  18313. phiSegments: phiSegments,
  18314. thetaStart: thetaStart,
  18315. thetaLength: thetaLength
  18316. };
  18317. thetaSegments = Math.max(3, thetaSegments);
  18318. phiSegments = Math.max(1, phiSegments); // buffers
  18319. var indices = [];
  18320. var vertices = [];
  18321. var normals = [];
  18322. var uvs = []; // some helper variables
  18323. var radius = innerRadius;
  18324. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  18325. var vertex = new Vector3();
  18326. var uv = new Vector2(); // generate vertices, normals and uvs
  18327. for (var j = 0; j <= phiSegments; j++) {
  18328. for (var i = 0; i <= thetaSegments; i++) {
  18329. // values are generate from the inside of the ring to the outside
  18330. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  18331. vertex.x = radius * Math.cos(segment);
  18332. vertex.y = radius * Math.sin(segment);
  18333. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  18334. normals.push(0, 0, 1); // uv
  18335. uv.x = (vertex.x / outerRadius + 1) / 2;
  18336. uv.y = (vertex.y / outerRadius + 1) / 2;
  18337. uvs.push(uv.x, uv.y);
  18338. } // increase the radius for next row of vertices
  18339. radius += radiusStep;
  18340. } // indices
  18341. for (var _j = 0; _j < phiSegments; _j++) {
  18342. var thetaSegmentLevel = _j * (thetaSegments + 1);
  18343. for (var _i = 0; _i < thetaSegments; _i++) {
  18344. var _segment = _i + thetaSegmentLevel;
  18345. var a = _segment;
  18346. var b = _segment + thetaSegments + 1;
  18347. var c = _segment + thetaSegments + 2;
  18348. var d = _segment + 1; // faces
  18349. indices.push(a, b, d);
  18350. indices.push(b, c, d);
  18351. }
  18352. } // build geometry
  18353. _this.setIndex(indices);
  18354. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18355. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18356. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18357. return _this;
  18358. }
  18359. return RingGeometry;
  18360. }(BufferGeometry);
  18361. var ShapeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18362. _inheritsLoose(ShapeGeometry, _BufferGeometry);
  18363. function ShapeGeometry(shapes, curveSegments) {
  18364. var _this;
  18365. if (curveSegments === void 0) {
  18366. curveSegments = 12;
  18367. }
  18368. _this = _BufferGeometry.call(this) || this;
  18369. _this.type = 'ShapeGeometry';
  18370. _this.parameters = {
  18371. shapes: shapes,
  18372. curveSegments: curveSegments
  18373. }; // buffers
  18374. var indices = [];
  18375. var vertices = [];
  18376. var normals = [];
  18377. var uvs = []; // helper variables
  18378. var groupStart = 0;
  18379. var groupCount = 0; // allow single and array values for "shapes" parameter
  18380. if (Array.isArray(shapes) === false) {
  18381. addShape(shapes);
  18382. } else {
  18383. for (var i = 0; i < shapes.length; i++) {
  18384. addShape(shapes[i]);
  18385. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  18386. groupStart += groupCount;
  18387. groupCount = 0;
  18388. }
  18389. } // build geometry
  18390. _this.setIndex(indices);
  18391. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18392. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18393. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  18394. function addShape(shape) {
  18395. var indexOffset = vertices.length / 3;
  18396. var points = shape.extractPoints(curveSegments);
  18397. var shapeVertices = points.shape;
  18398. var shapeHoles = points.holes; // check direction of vertices
  18399. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  18400. shapeVertices = shapeVertices.reverse();
  18401. }
  18402. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  18403. var shapeHole = shapeHoles[_i];
  18404. if (ShapeUtils.isClockWise(shapeHole) === true) {
  18405. shapeHoles[_i] = shapeHole.reverse();
  18406. }
  18407. }
  18408. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  18409. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  18410. var _shapeHole = shapeHoles[_i2];
  18411. shapeVertices = shapeVertices.concat(_shapeHole);
  18412. } // vertices, normals, uvs
  18413. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  18414. var vertex = shapeVertices[_i3];
  18415. vertices.push(vertex.x, vertex.y, 0);
  18416. normals.push(0, 0, 1);
  18417. uvs.push(vertex.x, vertex.y); // world uvs
  18418. } // incides
  18419. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  18420. var face = faces[_i4];
  18421. var a = face[0] + indexOffset;
  18422. var b = face[1] + indexOffset;
  18423. var c = face[2] + indexOffset;
  18424. indices.push(a, b, c);
  18425. groupCount += 3;
  18426. }
  18427. }
  18428. return _this;
  18429. }
  18430. var _proto = ShapeGeometry.prototype;
  18431. _proto.toJSON = function toJSON() {
  18432. var data = BufferGeometry.prototype.toJSON.call(this);
  18433. var shapes = this.parameters.shapes;
  18434. return _toJSON$1(shapes, data);
  18435. };
  18436. return ShapeGeometry;
  18437. }(BufferGeometry);
  18438. function _toJSON$1(shapes, data) {
  18439. data.shapes = [];
  18440. if (Array.isArray(shapes)) {
  18441. for (var i = 0, l = shapes.length; i < l; i++) {
  18442. var shape = shapes[i];
  18443. data.shapes.push(shape.uuid);
  18444. }
  18445. } else {
  18446. data.shapes.push(shapes.uuid);
  18447. }
  18448. return data;
  18449. }
  18450. var SphereGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18451. _inheritsLoose(SphereGeometry, _BufferGeometry);
  18452. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  18453. var _this;
  18454. if (radius === void 0) {
  18455. radius = 1;
  18456. }
  18457. if (widthSegments === void 0) {
  18458. widthSegments = 8;
  18459. }
  18460. if (heightSegments === void 0) {
  18461. heightSegments = 6;
  18462. }
  18463. if (phiStart === void 0) {
  18464. phiStart = 0;
  18465. }
  18466. if (phiLength === void 0) {
  18467. phiLength = Math.PI * 2;
  18468. }
  18469. if (thetaStart === void 0) {
  18470. thetaStart = 0;
  18471. }
  18472. if (thetaLength === void 0) {
  18473. thetaLength = Math.PI;
  18474. }
  18475. _this = _BufferGeometry.call(this) || this;
  18476. _this.type = 'SphereGeometry';
  18477. _this.parameters = {
  18478. radius: radius,
  18479. widthSegments: widthSegments,
  18480. heightSegments: heightSegments,
  18481. phiStart: phiStart,
  18482. phiLength: phiLength,
  18483. thetaStart: thetaStart,
  18484. thetaLength: thetaLength
  18485. };
  18486. widthSegments = Math.max(3, Math.floor(widthSegments));
  18487. heightSegments = Math.max(2, Math.floor(heightSegments));
  18488. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  18489. var index = 0;
  18490. var grid = [];
  18491. var vertex = new Vector3();
  18492. var normal = new Vector3(); // buffers
  18493. var indices = [];
  18494. var vertices = [];
  18495. var normals = [];
  18496. var uvs = []; // generate vertices, normals and uvs
  18497. for (var iy = 0; iy <= heightSegments; iy++) {
  18498. var verticesRow = [];
  18499. var v = iy / heightSegments; // special case for the poles
  18500. var uOffset = 0;
  18501. if (iy == 0 && thetaStart == 0) {
  18502. uOffset = 0.5 / widthSegments;
  18503. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  18504. uOffset = -0.5 / widthSegments;
  18505. }
  18506. for (var ix = 0; ix <= widthSegments; ix++) {
  18507. var u = ix / widthSegments; // vertex
  18508. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  18509. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  18510. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  18511. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  18512. normal.copy(vertex).normalize();
  18513. normals.push(normal.x, normal.y, normal.z); // uv
  18514. uvs.push(u + uOffset, 1 - v);
  18515. verticesRow.push(index++);
  18516. }
  18517. grid.push(verticesRow);
  18518. } // indices
  18519. for (var _iy = 0; _iy < heightSegments; _iy++) {
  18520. for (var _ix = 0; _ix < widthSegments; _ix++) {
  18521. var a = grid[_iy][_ix + 1];
  18522. var b = grid[_iy][_ix];
  18523. var c = grid[_iy + 1][_ix];
  18524. var d = grid[_iy + 1][_ix + 1];
  18525. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  18526. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  18527. }
  18528. } // build geometry
  18529. _this.setIndex(indices);
  18530. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18531. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18532. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18533. return _this;
  18534. }
  18535. return SphereGeometry;
  18536. }(BufferGeometry);
  18537. var TetrahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18538. _inheritsLoose(TetrahedronGeometry, _PolyhedronGeometry);
  18539. function TetrahedronGeometry(radius, detail) {
  18540. var _this;
  18541. if (radius === void 0) {
  18542. radius = 1;
  18543. }
  18544. if (detail === void 0) {
  18545. detail = 0;
  18546. }
  18547. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  18548. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  18549. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18550. _this.type = 'TetrahedronGeometry';
  18551. _this.parameters = {
  18552. radius: radius,
  18553. detail: detail
  18554. };
  18555. return _this;
  18556. }
  18557. return TetrahedronGeometry;
  18558. }(PolyhedronGeometry);
  18559. var TextGeometry = /*#__PURE__*/function (_ExtrudeGeometry) {
  18560. _inheritsLoose(TextGeometry, _ExtrudeGeometry);
  18561. function TextGeometry(text, parameters) {
  18562. var _this;
  18563. if (parameters === void 0) {
  18564. parameters = {};
  18565. }
  18566. var font = parameters.font;
  18567. if (!(font && font.isFont)) {
  18568. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  18569. return new BufferGeometry() || _assertThisInitialized(_this);
  18570. }
  18571. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  18572. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  18573. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  18574. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  18575. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  18576. _this = _ExtrudeGeometry.call(this, shapes, parameters) || this;
  18577. _this.type = 'TextGeometry';
  18578. return _this;
  18579. }
  18580. return TextGeometry;
  18581. }(ExtrudeGeometry);
  18582. var TorusGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18583. _inheritsLoose(TorusGeometry, _BufferGeometry);
  18584. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  18585. var _this;
  18586. if (radius === void 0) {
  18587. radius = 1;
  18588. }
  18589. if (tube === void 0) {
  18590. tube = 0.4;
  18591. }
  18592. if (radialSegments === void 0) {
  18593. radialSegments = 8;
  18594. }
  18595. if (tubularSegments === void 0) {
  18596. tubularSegments = 6;
  18597. }
  18598. if (arc === void 0) {
  18599. arc = Math.PI * 2;
  18600. }
  18601. _this = _BufferGeometry.call(this) || this;
  18602. _this.type = 'TorusGeometry';
  18603. _this.parameters = {
  18604. radius: radius,
  18605. tube: tube,
  18606. radialSegments: radialSegments,
  18607. tubularSegments: tubularSegments,
  18608. arc: arc
  18609. };
  18610. radialSegments = Math.floor(radialSegments);
  18611. tubularSegments = Math.floor(tubularSegments); // buffers
  18612. var indices = [];
  18613. var vertices = [];
  18614. var normals = [];
  18615. var uvs = []; // helper variables
  18616. var center = new Vector3();
  18617. var vertex = new Vector3();
  18618. var normal = new Vector3(); // generate vertices, normals and uvs
  18619. for (var j = 0; j <= radialSegments; j++) {
  18620. for (var i = 0; i <= tubularSegments; i++) {
  18621. var u = i / tubularSegments * arc;
  18622. var v = j / radialSegments * Math.PI * 2; // vertex
  18623. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  18624. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  18625. vertex.z = tube * Math.sin(v);
  18626. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  18627. center.x = radius * Math.cos(u);
  18628. center.y = radius * Math.sin(u);
  18629. normal.subVectors(vertex, center).normalize();
  18630. normals.push(normal.x, normal.y, normal.z); // uv
  18631. uvs.push(i / tubularSegments);
  18632. uvs.push(j / radialSegments);
  18633. }
  18634. } // generate indices
  18635. for (var _j = 1; _j <= radialSegments; _j++) {
  18636. for (var _i = 1; _i <= tubularSegments; _i++) {
  18637. // indices
  18638. var a = (tubularSegments + 1) * _j + _i - 1;
  18639. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  18640. var c = (tubularSegments + 1) * (_j - 1) + _i;
  18641. var d = (tubularSegments + 1) * _j + _i; // faces
  18642. indices.push(a, b, d);
  18643. indices.push(b, c, d);
  18644. }
  18645. } // build geometry
  18646. _this.setIndex(indices);
  18647. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18648. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18649. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18650. return _this;
  18651. }
  18652. return TorusGeometry;
  18653. }(BufferGeometry);
  18654. var TorusKnotGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18655. _inheritsLoose(TorusKnotGeometry, _BufferGeometry);
  18656. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  18657. var _this;
  18658. if (radius === void 0) {
  18659. radius = 1;
  18660. }
  18661. if (tube === void 0) {
  18662. tube = 0.4;
  18663. }
  18664. if (tubularSegments === void 0) {
  18665. tubularSegments = 64;
  18666. }
  18667. if (radialSegments === void 0) {
  18668. radialSegments = 8;
  18669. }
  18670. if (p === void 0) {
  18671. p = 2;
  18672. }
  18673. if (q === void 0) {
  18674. q = 3;
  18675. }
  18676. _this = _BufferGeometry.call(this) || this;
  18677. _this.type = 'TorusKnotGeometry';
  18678. _this.parameters = {
  18679. radius: radius,
  18680. tube: tube,
  18681. tubularSegments: tubularSegments,
  18682. radialSegments: radialSegments,
  18683. p: p,
  18684. q: q
  18685. };
  18686. tubularSegments = Math.floor(tubularSegments);
  18687. radialSegments = Math.floor(radialSegments); // buffers
  18688. var indices = [];
  18689. var vertices = [];
  18690. var normals = [];
  18691. var uvs = []; // helper variables
  18692. var vertex = new Vector3();
  18693. var normal = new Vector3();
  18694. var P1 = new Vector3();
  18695. var P2 = new Vector3();
  18696. var B = new Vector3();
  18697. var T = new Vector3();
  18698. var N = new Vector3(); // generate vertices, normals and uvs
  18699. for (var i = 0; i <= tubularSegments; ++i) {
  18700. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  18701. 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.
  18702. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  18703. calculatePositionOnCurve(u, p, q, radius, P1);
  18704. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  18705. T.subVectors(P2, P1);
  18706. N.addVectors(P2, P1);
  18707. B.crossVectors(T, N);
  18708. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  18709. B.normalize();
  18710. N.normalize();
  18711. for (var j = 0; j <= radialSegments; ++j) {
  18712. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  18713. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  18714. var v = j / radialSegments * Math.PI * 2;
  18715. var cx = -tube * Math.cos(v);
  18716. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  18717. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  18718. vertex.x = P1.x + (cx * N.x + cy * B.x);
  18719. vertex.y = P1.y + (cx * N.y + cy * B.y);
  18720. vertex.z = P1.z + (cx * N.z + cy * B.z);
  18721. 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)
  18722. normal.subVectors(vertex, P1).normalize();
  18723. normals.push(normal.x, normal.y, normal.z); // uv
  18724. uvs.push(i / tubularSegments);
  18725. uvs.push(j / radialSegments);
  18726. }
  18727. } // generate indices
  18728. for (var _j = 1; _j <= tubularSegments; _j++) {
  18729. for (var _i = 1; _i <= radialSegments; _i++) {
  18730. // indices
  18731. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  18732. var b = (radialSegments + 1) * _j + (_i - 1);
  18733. var c = (radialSegments + 1) * _j + _i;
  18734. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  18735. indices.push(a, b, d);
  18736. indices.push(b, c, d);
  18737. }
  18738. } // build geometry
  18739. _this.setIndex(indices);
  18740. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18741. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18742. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  18743. function calculatePositionOnCurve(u, p, q, radius, position) {
  18744. var cu = Math.cos(u);
  18745. var su = Math.sin(u);
  18746. var quOverP = q / p * u;
  18747. var cs = Math.cos(quOverP);
  18748. position.x = radius * (2 + cs) * 0.5 * cu;
  18749. position.y = radius * (2 + cs) * su * 0.5;
  18750. position.z = radius * Math.sin(quOverP) * 0.5;
  18751. }
  18752. return _this;
  18753. }
  18754. return TorusKnotGeometry;
  18755. }(BufferGeometry);
  18756. var TubeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18757. _inheritsLoose(TubeGeometry, _BufferGeometry);
  18758. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed) {
  18759. var _this;
  18760. if (tubularSegments === void 0) {
  18761. tubularSegments = 64;
  18762. }
  18763. if (radius === void 0) {
  18764. radius = 1;
  18765. }
  18766. if (radialSegments === void 0) {
  18767. radialSegments = 8;
  18768. }
  18769. if (closed === void 0) {
  18770. closed = false;
  18771. }
  18772. _this = _BufferGeometry.call(this) || this;
  18773. _this.type = 'TubeGeometry';
  18774. _this.parameters = {
  18775. path: path,
  18776. tubularSegments: tubularSegments,
  18777. radius: radius,
  18778. radialSegments: radialSegments,
  18779. closed: closed
  18780. };
  18781. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  18782. _this.tangents = frames.tangents;
  18783. _this.normals = frames.normals;
  18784. _this.binormals = frames.binormals; // helper variables
  18785. var vertex = new Vector3();
  18786. var normal = new Vector3();
  18787. var uv = new Vector2();
  18788. var P = new Vector3(); // buffer
  18789. var vertices = [];
  18790. var normals = [];
  18791. var uvs = [];
  18792. var indices = []; // create buffer data
  18793. generateBufferData(); // build geometry
  18794. _this.setIndex(indices);
  18795. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18796. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18797. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  18798. function generateBufferData() {
  18799. for (var i = 0; i < tubularSegments; i++) {
  18800. generateSegment(i);
  18801. } // if the geometry is not closed, generate the last row of vertices and normals
  18802. // at the regular position on the given path
  18803. //
  18804. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  18805. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  18806. // this makes it easy compute correct values for closed geometries
  18807. generateUVs(); // finally create faces
  18808. generateIndices();
  18809. }
  18810. function generateSegment(i) {
  18811. // we use getPointAt to sample evenly distributed points from the given path
  18812. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  18813. var N = frames.normals[i];
  18814. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  18815. for (var j = 0; j <= radialSegments; j++) {
  18816. var v = j / radialSegments * Math.PI * 2;
  18817. var sin = Math.sin(v);
  18818. var cos = -Math.cos(v); // normal
  18819. normal.x = cos * N.x + sin * B.x;
  18820. normal.y = cos * N.y + sin * B.y;
  18821. normal.z = cos * N.z + sin * B.z;
  18822. normal.normalize();
  18823. normals.push(normal.x, normal.y, normal.z); // vertex
  18824. vertex.x = P.x + radius * normal.x;
  18825. vertex.y = P.y + radius * normal.y;
  18826. vertex.z = P.z + radius * normal.z;
  18827. vertices.push(vertex.x, vertex.y, vertex.z);
  18828. }
  18829. }
  18830. function generateIndices() {
  18831. for (var j = 1; j <= tubularSegments; j++) {
  18832. for (var i = 1; i <= radialSegments; i++) {
  18833. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  18834. var b = (radialSegments + 1) * j + (i - 1);
  18835. var c = (radialSegments + 1) * j + i;
  18836. var d = (radialSegments + 1) * (j - 1) + i; // faces
  18837. indices.push(a, b, d);
  18838. indices.push(b, c, d);
  18839. }
  18840. }
  18841. }
  18842. function generateUVs() {
  18843. for (var i = 0; i <= tubularSegments; i++) {
  18844. for (var j = 0; j <= radialSegments; j++) {
  18845. uv.x = i / tubularSegments;
  18846. uv.y = j / radialSegments;
  18847. uvs.push(uv.x, uv.y);
  18848. }
  18849. }
  18850. }
  18851. return _this;
  18852. }
  18853. var _proto = TubeGeometry.prototype;
  18854. _proto.toJSON = function toJSON() {
  18855. var data = BufferGeometry.prototype.toJSON.call(this);
  18856. data.path = this.parameters.path.toJSON();
  18857. return data;
  18858. };
  18859. return TubeGeometry;
  18860. }(BufferGeometry);
  18861. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18862. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  18863. function WireframeGeometry(geometry) {
  18864. var _this;
  18865. _this = _BufferGeometry.call(this) || this;
  18866. _this.type = 'WireframeGeometry';
  18867. if (geometry.isGeometry === true) {
  18868. console.error('THREE.WireframeGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  18869. return _assertThisInitialized(_this);
  18870. } // buffer
  18871. var vertices = []; // helper variables
  18872. var edge = [0, 0],
  18873. edges = {};
  18874. var vertex = new Vector3();
  18875. if (geometry.index !== null) {
  18876. // indexed BufferGeometry
  18877. var position = geometry.attributes.position;
  18878. var indices = geometry.index;
  18879. var groups = geometry.groups;
  18880. if (groups.length === 0) {
  18881. groups = [{
  18882. start: 0,
  18883. count: indices.count,
  18884. materialIndex: 0
  18885. }];
  18886. } // create a data structure that contains all eges without duplicates
  18887. for (var o = 0, ol = groups.length; o < ol; ++o) {
  18888. var group = groups[o];
  18889. var start = group.start;
  18890. var count = group.count;
  18891. for (var i = start, l = start + count; i < l; i += 3) {
  18892. for (var j = 0; j < 3; j++) {
  18893. var edge1 = indices.getX(i + j);
  18894. var edge2 = indices.getX(i + (j + 1) % 3);
  18895. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  18896. edge[1] = Math.max(edge1, edge2);
  18897. var key = edge[0] + ',' + edge[1];
  18898. if (edges[key] === undefined) {
  18899. edges[key] = {
  18900. index1: edge[0],
  18901. index2: edge[1]
  18902. };
  18903. }
  18904. }
  18905. }
  18906. } // generate vertices
  18907. for (var _key in edges) {
  18908. var e = edges[_key];
  18909. vertex.fromBufferAttribute(position, e.index1);
  18910. vertices.push(vertex.x, vertex.y, vertex.z);
  18911. vertex.fromBufferAttribute(position, e.index2);
  18912. vertices.push(vertex.x, vertex.y, vertex.z);
  18913. }
  18914. } else {
  18915. // non-indexed BufferGeometry
  18916. var _position = geometry.attributes.position;
  18917. for (var _i = 0, _l = _position.count / 3; _i < _l; _i++) {
  18918. for (var _j = 0; _j < 3; _j++) {
  18919. // three edges per triangle, an edge is represented as (index1, index2)
  18920. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  18921. var index1 = 3 * _i + _j;
  18922. vertex.fromBufferAttribute(_position, index1);
  18923. vertices.push(vertex.x, vertex.y, vertex.z);
  18924. var index2 = 3 * _i + (_j + 1) % 3;
  18925. vertex.fromBufferAttribute(_position, index2);
  18926. vertices.push(vertex.x, vertex.y, vertex.z);
  18927. }
  18928. }
  18929. } // build geometry
  18930. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18931. return _this;
  18932. }
  18933. return WireframeGeometry;
  18934. }(BufferGeometry);
  18935. var Geometries = /*#__PURE__*/Object.freeze({
  18936. __proto__: null,
  18937. BoxGeometry: BoxGeometry,
  18938. BoxBufferGeometry: BoxGeometry,
  18939. CircleGeometry: CircleGeometry,
  18940. CircleBufferGeometry: CircleGeometry,
  18941. ConeGeometry: ConeGeometry,
  18942. ConeBufferGeometry: ConeGeometry,
  18943. CylinderGeometry: CylinderGeometry,
  18944. CylinderBufferGeometry: CylinderGeometry,
  18945. DodecahedronGeometry: DodecahedronGeometry,
  18946. DodecahedronBufferGeometry: DodecahedronGeometry,
  18947. EdgesGeometry: EdgesGeometry,
  18948. ExtrudeGeometry: ExtrudeGeometry,
  18949. ExtrudeBufferGeometry: ExtrudeGeometry,
  18950. IcosahedronGeometry: IcosahedronGeometry,
  18951. IcosahedronBufferGeometry: IcosahedronGeometry,
  18952. LatheGeometry: LatheGeometry,
  18953. LatheBufferGeometry: LatheGeometry,
  18954. OctahedronGeometry: OctahedronGeometry,
  18955. OctahedronBufferGeometry: OctahedronGeometry,
  18956. ParametricGeometry: ParametricGeometry,
  18957. ParametricBufferGeometry: ParametricGeometry,
  18958. PlaneGeometry: PlaneGeometry,
  18959. PlaneBufferGeometry: PlaneGeometry,
  18960. PolyhedronGeometry: PolyhedronGeometry,
  18961. PolyhedronBufferGeometry: PolyhedronGeometry,
  18962. RingGeometry: RingGeometry,
  18963. RingBufferGeometry: RingGeometry,
  18964. ShapeGeometry: ShapeGeometry,
  18965. ShapeBufferGeometry: ShapeGeometry,
  18966. SphereGeometry: SphereGeometry,
  18967. SphereBufferGeometry: SphereGeometry,
  18968. TetrahedronGeometry: TetrahedronGeometry,
  18969. TetrahedronBufferGeometry: TetrahedronGeometry,
  18970. TextGeometry: TextGeometry,
  18971. TextBufferGeometry: TextGeometry,
  18972. TorusGeometry: TorusGeometry,
  18973. TorusBufferGeometry: TorusGeometry,
  18974. TorusKnotGeometry: TorusKnotGeometry,
  18975. TorusKnotBufferGeometry: TorusKnotGeometry,
  18976. TubeGeometry: TubeGeometry,
  18977. TubeBufferGeometry: TubeGeometry,
  18978. WireframeGeometry: WireframeGeometry
  18979. });
  18980. /**
  18981. * parameters = {
  18982. * color: <THREE.Color>
  18983. * }
  18984. */
  18985. function ShadowMaterial(parameters) {
  18986. Material.call(this);
  18987. this.type = 'ShadowMaterial';
  18988. this.color = new Color(0x000000);
  18989. this.transparent = true;
  18990. this.setValues(parameters);
  18991. }
  18992. ShadowMaterial.prototype = Object.create(Material.prototype);
  18993. ShadowMaterial.prototype.constructor = ShadowMaterial;
  18994. ShadowMaterial.prototype.isShadowMaterial = true;
  18995. ShadowMaterial.prototype.copy = function (source) {
  18996. Material.prototype.copy.call(this, source);
  18997. this.color.copy(source.color);
  18998. return this;
  18999. };
  19000. function RawShaderMaterial(parameters) {
  19001. ShaderMaterial.call(this, parameters);
  19002. this.type = 'RawShaderMaterial';
  19003. }
  19004. RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
  19005. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19006. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19007. /**
  19008. * parameters = {
  19009. * color: <hex>,
  19010. * roughness: <float>,
  19011. * metalness: <float>,
  19012. * opacity: <float>,
  19013. *
  19014. * map: new THREE.Texture( <Image> ),
  19015. *
  19016. * lightMap: new THREE.Texture( <Image> ),
  19017. * lightMapIntensity: <float>
  19018. *
  19019. * aoMap: new THREE.Texture( <Image> ),
  19020. * aoMapIntensity: <float>
  19021. *
  19022. * emissive: <hex>,
  19023. * emissiveIntensity: <float>
  19024. * emissiveMap: new THREE.Texture( <Image> ),
  19025. *
  19026. * bumpMap: new THREE.Texture( <Image> ),
  19027. * bumpScale: <float>,
  19028. *
  19029. * normalMap: new THREE.Texture( <Image> ),
  19030. * normalMapType: THREE.TangentSpaceNormalMap,
  19031. * normalScale: <Vector2>,
  19032. *
  19033. * displacementMap: new THREE.Texture( <Image> ),
  19034. * displacementScale: <float>,
  19035. * displacementBias: <float>,
  19036. *
  19037. * roughnessMap: new THREE.Texture( <Image> ),
  19038. *
  19039. * metalnessMap: new THREE.Texture( <Image> ),
  19040. *
  19041. * alphaMap: new THREE.Texture( <Image> ),
  19042. *
  19043. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19044. * envMapIntensity: <float>
  19045. *
  19046. * refractionRatio: <float>,
  19047. *
  19048. * wireframe: <boolean>,
  19049. * wireframeLinewidth: <float>,
  19050. *
  19051. * skinning: <bool>,
  19052. * morphTargets: <bool>,
  19053. * morphNormals: <bool>
  19054. * }
  19055. */
  19056. function MeshStandardMaterial(parameters) {
  19057. Material.call(this);
  19058. this.defines = {
  19059. 'STANDARD': ''
  19060. };
  19061. this.type = 'MeshStandardMaterial';
  19062. this.color = new Color(0xffffff); // diffuse
  19063. this.roughness = 1.0;
  19064. this.metalness = 0.0;
  19065. this.map = null;
  19066. this.lightMap = null;
  19067. this.lightMapIntensity = 1.0;
  19068. this.aoMap = null;
  19069. this.aoMapIntensity = 1.0;
  19070. this.emissive = new Color(0x000000);
  19071. this.emissiveIntensity = 1.0;
  19072. this.emissiveMap = null;
  19073. this.bumpMap = null;
  19074. this.bumpScale = 1;
  19075. this.normalMap = null;
  19076. this.normalMapType = TangentSpaceNormalMap;
  19077. this.normalScale = new Vector2(1, 1);
  19078. this.displacementMap = null;
  19079. this.displacementScale = 1;
  19080. this.displacementBias = 0;
  19081. this.roughnessMap = null;
  19082. this.metalnessMap = null;
  19083. this.alphaMap = null;
  19084. this.envMap = null;
  19085. this.envMapIntensity = 1.0;
  19086. this.refractionRatio = 0.98;
  19087. this.wireframe = false;
  19088. this.wireframeLinewidth = 1;
  19089. this.wireframeLinecap = 'round';
  19090. this.wireframeLinejoin = 'round';
  19091. this.skinning = false;
  19092. this.morphTargets = false;
  19093. this.morphNormals = false;
  19094. this.vertexTangents = false;
  19095. this.setValues(parameters);
  19096. }
  19097. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  19098. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19099. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19100. MeshStandardMaterial.prototype.copy = function (source) {
  19101. Material.prototype.copy.call(this, source);
  19102. this.defines = {
  19103. 'STANDARD': ''
  19104. };
  19105. this.color.copy(source.color);
  19106. this.roughness = source.roughness;
  19107. this.metalness = source.metalness;
  19108. this.map = source.map;
  19109. this.lightMap = source.lightMap;
  19110. this.lightMapIntensity = source.lightMapIntensity;
  19111. this.aoMap = source.aoMap;
  19112. this.aoMapIntensity = source.aoMapIntensity;
  19113. this.emissive.copy(source.emissive);
  19114. this.emissiveMap = source.emissiveMap;
  19115. this.emissiveIntensity = source.emissiveIntensity;
  19116. this.bumpMap = source.bumpMap;
  19117. this.bumpScale = source.bumpScale;
  19118. this.normalMap = source.normalMap;
  19119. this.normalMapType = source.normalMapType;
  19120. this.normalScale.copy(source.normalScale);
  19121. this.displacementMap = source.displacementMap;
  19122. this.displacementScale = source.displacementScale;
  19123. this.displacementBias = source.displacementBias;
  19124. this.roughnessMap = source.roughnessMap;
  19125. this.metalnessMap = source.metalnessMap;
  19126. this.alphaMap = source.alphaMap;
  19127. this.envMap = source.envMap;
  19128. this.envMapIntensity = source.envMapIntensity;
  19129. this.refractionRatio = source.refractionRatio;
  19130. this.wireframe = source.wireframe;
  19131. this.wireframeLinewidth = source.wireframeLinewidth;
  19132. this.wireframeLinecap = source.wireframeLinecap;
  19133. this.wireframeLinejoin = source.wireframeLinejoin;
  19134. this.skinning = source.skinning;
  19135. this.morphTargets = source.morphTargets;
  19136. this.morphNormals = source.morphNormals;
  19137. this.vertexTangents = source.vertexTangents;
  19138. return this;
  19139. };
  19140. /**
  19141. * parameters = {
  19142. * clearcoat: <float>,
  19143. * clearcoatMap: new THREE.Texture( <Image> ),
  19144. * clearcoatRoughness: <float>,
  19145. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  19146. * clearcoatNormalScale: <Vector2>,
  19147. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19148. *
  19149. * reflectivity: <float>,
  19150. * ior: <float>,
  19151. *
  19152. * sheen: <Color>,
  19153. *
  19154. * transmission: <float>,
  19155. * transmissionMap: new THREE.Texture( <Image> )
  19156. * }
  19157. */
  19158. function MeshPhysicalMaterial(parameters) {
  19159. MeshStandardMaterial.call(this);
  19160. this.defines = {
  19161. 'STANDARD': '',
  19162. 'PHYSICAL': ''
  19163. };
  19164. this.type = 'MeshPhysicalMaterial';
  19165. this.clearcoat = 0.0;
  19166. this.clearcoatMap = null;
  19167. this.clearcoatRoughness = 0.0;
  19168. this.clearcoatRoughnessMap = null;
  19169. this.clearcoatNormalScale = new Vector2(1, 1);
  19170. this.clearcoatNormalMap = null;
  19171. this.reflectivity = 0.5; // maps to F0 = 0.04
  19172. Object.defineProperty(this, 'ior', {
  19173. get: function get() {
  19174. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  19175. },
  19176. set: function set(ior) {
  19177. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  19178. }
  19179. });
  19180. this.sheen = null; // null will disable sheen bsdf
  19181. this.transmission = 0.0;
  19182. this.transmissionMap = null;
  19183. this.setValues(parameters);
  19184. }
  19185. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  19186. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19187. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19188. MeshPhysicalMaterial.prototype.copy = function (source) {
  19189. MeshStandardMaterial.prototype.copy.call(this, source);
  19190. this.defines = {
  19191. 'STANDARD': '',
  19192. 'PHYSICAL': ''
  19193. };
  19194. this.clearcoat = source.clearcoat;
  19195. this.clearcoatMap = source.clearcoatMap;
  19196. this.clearcoatRoughness = source.clearcoatRoughness;
  19197. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  19198. this.clearcoatNormalMap = source.clearcoatNormalMap;
  19199. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  19200. this.reflectivity = source.reflectivity;
  19201. if (source.sheen) {
  19202. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  19203. } else {
  19204. this.sheen = null;
  19205. }
  19206. this.transmission = source.transmission;
  19207. this.transmissionMap = source.transmissionMap;
  19208. return this;
  19209. };
  19210. /**
  19211. * parameters = {
  19212. * color: <hex>,
  19213. * specular: <hex>,
  19214. * shininess: <float>,
  19215. * opacity: <float>,
  19216. *
  19217. * map: new THREE.Texture( <Image> ),
  19218. *
  19219. * lightMap: new THREE.Texture( <Image> ),
  19220. * lightMapIntensity: <float>
  19221. *
  19222. * aoMap: new THREE.Texture( <Image> ),
  19223. * aoMapIntensity: <float>
  19224. *
  19225. * emissive: <hex>,
  19226. * emissiveIntensity: <float>
  19227. * emissiveMap: new THREE.Texture( <Image> ),
  19228. *
  19229. * bumpMap: new THREE.Texture( <Image> ),
  19230. * bumpScale: <float>,
  19231. *
  19232. * normalMap: new THREE.Texture( <Image> ),
  19233. * normalMapType: THREE.TangentSpaceNormalMap,
  19234. * normalScale: <Vector2>,
  19235. *
  19236. * displacementMap: new THREE.Texture( <Image> ),
  19237. * displacementScale: <float>,
  19238. * displacementBias: <float>,
  19239. *
  19240. * specularMap: new THREE.Texture( <Image> ),
  19241. *
  19242. * alphaMap: new THREE.Texture( <Image> ),
  19243. *
  19244. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19245. * combine: THREE.MultiplyOperation,
  19246. * reflectivity: <float>,
  19247. * refractionRatio: <float>,
  19248. *
  19249. * wireframe: <boolean>,
  19250. * wireframeLinewidth: <float>,
  19251. *
  19252. * skinning: <bool>,
  19253. * morphTargets: <bool>,
  19254. * morphNormals: <bool>
  19255. * }
  19256. */
  19257. function MeshPhongMaterial(parameters) {
  19258. Material.call(this);
  19259. this.type = 'MeshPhongMaterial';
  19260. this.color = new Color(0xffffff); // diffuse
  19261. this.specular = new Color(0x111111);
  19262. this.shininess = 30;
  19263. this.map = null;
  19264. this.lightMap = null;
  19265. this.lightMapIntensity = 1.0;
  19266. this.aoMap = null;
  19267. this.aoMapIntensity = 1.0;
  19268. this.emissive = new Color(0x000000);
  19269. this.emissiveIntensity = 1.0;
  19270. this.emissiveMap = null;
  19271. this.bumpMap = null;
  19272. this.bumpScale = 1;
  19273. this.normalMap = null;
  19274. this.normalMapType = TangentSpaceNormalMap;
  19275. this.normalScale = new Vector2(1, 1);
  19276. this.displacementMap = null;
  19277. this.displacementScale = 1;
  19278. this.displacementBias = 0;
  19279. this.specularMap = null;
  19280. this.alphaMap = null;
  19281. this.envMap = null;
  19282. this.combine = MultiplyOperation;
  19283. this.reflectivity = 1;
  19284. this.refractionRatio = 0.98;
  19285. this.wireframe = false;
  19286. this.wireframeLinewidth = 1;
  19287. this.wireframeLinecap = 'round';
  19288. this.wireframeLinejoin = 'round';
  19289. this.skinning = false;
  19290. this.morphTargets = false;
  19291. this.morphNormals = false;
  19292. this.setValues(parameters);
  19293. }
  19294. MeshPhongMaterial.prototype = Object.create(Material.prototype);
  19295. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  19296. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  19297. MeshPhongMaterial.prototype.copy = function (source) {
  19298. Material.prototype.copy.call(this, source);
  19299. this.color.copy(source.color);
  19300. this.specular.copy(source.specular);
  19301. this.shininess = source.shininess;
  19302. this.map = source.map;
  19303. this.lightMap = source.lightMap;
  19304. this.lightMapIntensity = source.lightMapIntensity;
  19305. this.aoMap = source.aoMap;
  19306. this.aoMapIntensity = source.aoMapIntensity;
  19307. this.emissive.copy(source.emissive);
  19308. this.emissiveMap = source.emissiveMap;
  19309. this.emissiveIntensity = source.emissiveIntensity;
  19310. this.bumpMap = source.bumpMap;
  19311. this.bumpScale = source.bumpScale;
  19312. this.normalMap = source.normalMap;
  19313. this.normalMapType = source.normalMapType;
  19314. this.normalScale.copy(source.normalScale);
  19315. this.displacementMap = source.displacementMap;
  19316. this.displacementScale = source.displacementScale;
  19317. this.displacementBias = source.displacementBias;
  19318. this.specularMap = source.specularMap;
  19319. this.alphaMap = source.alphaMap;
  19320. this.envMap = source.envMap;
  19321. this.combine = source.combine;
  19322. this.reflectivity = source.reflectivity;
  19323. this.refractionRatio = source.refractionRatio;
  19324. this.wireframe = source.wireframe;
  19325. this.wireframeLinewidth = source.wireframeLinewidth;
  19326. this.wireframeLinecap = source.wireframeLinecap;
  19327. this.wireframeLinejoin = source.wireframeLinejoin;
  19328. this.skinning = source.skinning;
  19329. this.morphTargets = source.morphTargets;
  19330. this.morphNormals = source.morphNormals;
  19331. return this;
  19332. };
  19333. /**
  19334. * parameters = {
  19335. * color: <hex>,
  19336. *
  19337. * map: new THREE.Texture( <Image> ),
  19338. * gradientMap: new THREE.Texture( <Image> ),
  19339. *
  19340. * lightMap: new THREE.Texture( <Image> ),
  19341. * lightMapIntensity: <float>
  19342. *
  19343. * aoMap: new THREE.Texture( <Image> ),
  19344. * aoMapIntensity: <float>
  19345. *
  19346. * emissive: <hex>,
  19347. * emissiveIntensity: <float>
  19348. * emissiveMap: new THREE.Texture( <Image> ),
  19349. *
  19350. * bumpMap: new THREE.Texture( <Image> ),
  19351. * bumpScale: <float>,
  19352. *
  19353. * normalMap: new THREE.Texture( <Image> ),
  19354. * normalMapType: THREE.TangentSpaceNormalMap,
  19355. * normalScale: <Vector2>,
  19356. *
  19357. * displacementMap: new THREE.Texture( <Image> ),
  19358. * displacementScale: <float>,
  19359. * displacementBias: <float>,
  19360. *
  19361. * alphaMap: new THREE.Texture( <Image> ),
  19362. *
  19363. * wireframe: <boolean>,
  19364. * wireframeLinewidth: <float>,
  19365. *
  19366. * skinning: <bool>,
  19367. * morphTargets: <bool>,
  19368. * morphNormals: <bool>
  19369. * }
  19370. */
  19371. function MeshToonMaterial(parameters) {
  19372. Material.call(this);
  19373. this.defines = {
  19374. 'TOON': ''
  19375. };
  19376. this.type = 'MeshToonMaterial';
  19377. this.color = new Color(0xffffff);
  19378. this.map = null;
  19379. this.gradientMap = null;
  19380. this.lightMap = null;
  19381. this.lightMapIntensity = 1.0;
  19382. this.aoMap = null;
  19383. this.aoMapIntensity = 1.0;
  19384. this.emissive = new Color(0x000000);
  19385. this.emissiveIntensity = 1.0;
  19386. this.emissiveMap = null;
  19387. this.bumpMap = null;
  19388. this.bumpScale = 1;
  19389. this.normalMap = null;
  19390. this.normalMapType = TangentSpaceNormalMap;
  19391. this.normalScale = new Vector2(1, 1);
  19392. this.displacementMap = null;
  19393. this.displacementScale = 1;
  19394. this.displacementBias = 0;
  19395. this.alphaMap = null;
  19396. this.wireframe = false;
  19397. this.wireframeLinewidth = 1;
  19398. this.wireframeLinecap = 'round';
  19399. this.wireframeLinejoin = 'round';
  19400. this.skinning = false;
  19401. this.morphTargets = false;
  19402. this.morphNormals = false;
  19403. this.setValues(parameters);
  19404. }
  19405. MeshToonMaterial.prototype = Object.create(Material.prototype);
  19406. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19407. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19408. MeshToonMaterial.prototype.copy = function (source) {
  19409. Material.prototype.copy.call(this, source);
  19410. this.color.copy(source.color);
  19411. this.map = source.map;
  19412. this.gradientMap = source.gradientMap;
  19413. this.lightMap = source.lightMap;
  19414. this.lightMapIntensity = source.lightMapIntensity;
  19415. this.aoMap = source.aoMap;
  19416. this.aoMapIntensity = source.aoMapIntensity;
  19417. this.emissive.copy(source.emissive);
  19418. this.emissiveMap = source.emissiveMap;
  19419. this.emissiveIntensity = source.emissiveIntensity;
  19420. this.bumpMap = source.bumpMap;
  19421. this.bumpScale = source.bumpScale;
  19422. this.normalMap = source.normalMap;
  19423. this.normalMapType = source.normalMapType;
  19424. this.normalScale.copy(source.normalScale);
  19425. this.displacementMap = source.displacementMap;
  19426. this.displacementScale = source.displacementScale;
  19427. this.displacementBias = source.displacementBias;
  19428. this.alphaMap = source.alphaMap;
  19429. this.wireframe = source.wireframe;
  19430. this.wireframeLinewidth = source.wireframeLinewidth;
  19431. this.wireframeLinecap = source.wireframeLinecap;
  19432. this.wireframeLinejoin = source.wireframeLinejoin;
  19433. this.skinning = source.skinning;
  19434. this.morphTargets = source.morphTargets;
  19435. this.morphNormals = source.morphNormals;
  19436. return this;
  19437. };
  19438. /**
  19439. * parameters = {
  19440. * opacity: <float>,
  19441. *
  19442. * bumpMap: new THREE.Texture( <Image> ),
  19443. * bumpScale: <float>,
  19444. *
  19445. * normalMap: new THREE.Texture( <Image> ),
  19446. * normalMapType: THREE.TangentSpaceNormalMap,
  19447. * normalScale: <Vector2>,
  19448. *
  19449. * displacementMap: new THREE.Texture( <Image> ),
  19450. * displacementScale: <float>,
  19451. * displacementBias: <float>,
  19452. *
  19453. * wireframe: <boolean>,
  19454. * wireframeLinewidth: <float>
  19455. *
  19456. * skinning: <bool>,
  19457. * morphTargets: <bool>,
  19458. * morphNormals: <bool>
  19459. * }
  19460. */
  19461. function MeshNormalMaterial(parameters) {
  19462. Material.call(this);
  19463. this.type = 'MeshNormalMaterial';
  19464. this.bumpMap = null;
  19465. this.bumpScale = 1;
  19466. this.normalMap = null;
  19467. this.normalMapType = TangentSpaceNormalMap;
  19468. this.normalScale = new Vector2(1, 1);
  19469. this.displacementMap = null;
  19470. this.displacementScale = 1;
  19471. this.displacementBias = 0;
  19472. this.wireframe = false;
  19473. this.wireframeLinewidth = 1;
  19474. this.fog = false;
  19475. this.skinning = false;
  19476. this.morphTargets = false;
  19477. this.morphNormals = false;
  19478. this.setValues(parameters);
  19479. }
  19480. MeshNormalMaterial.prototype = Object.create(Material.prototype);
  19481. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  19482. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  19483. MeshNormalMaterial.prototype.copy = function (source) {
  19484. Material.prototype.copy.call(this, source);
  19485. this.bumpMap = source.bumpMap;
  19486. this.bumpScale = source.bumpScale;
  19487. this.normalMap = source.normalMap;
  19488. this.normalMapType = source.normalMapType;
  19489. this.normalScale.copy(source.normalScale);
  19490. this.displacementMap = source.displacementMap;
  19491. this.displacementScale = source.displacementScale;
  19492. this.displacementBias = source.displacementBias;
  19493. this.wireframe = source.wireframe;
  19494. this.wireframeLinewidth = source.wireframeLinewidth;
  19495. this.skinning = source.skinning;
  19496. this.morphTargets = source.morphTargets;
  19497. this.morphNormals = source.morphNormals;
  19498. return this;
  19499. };
  19500. /**
  19501. * parameters = {
  19502. * color: <hex>,
  19503. * opacity: <float>,
  19504. *
  19505. * map: new THREE.Texture( <Image> ),
  19506. *
  19507. * lightMap: new THREE.Texture( <Image> ),
  19508. * lightMapIntensity: <float>
  19509. *
  19510. * aoMap: new THREE.Texture( <Image> ),
  19511. * aoMapIntensity: <float>
  19512. *
  19513. * emissive: <hex>,
  19514. * emissiveIntensity: <float>
  19515. * emissiveMap: new THREE.Texture( <Image> ),
  19516. *
  19517. * specularMap: new THREE.Texture( <Image> ),
  19518. *
  19519. * alphaMap: new THREE.Texture( <Image> ),
  19520. *
  19521. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19522. * combine: THREE.Multiply,
  19523. * reflectivity: <float>,
  19524. * refractionRatio: <float>,
  19525. *
  19526. * wireframe: <boolean>,
  19527. * wireframeLinewidth: <float>,
  19528. *
  19529. * skinning: <bool>,
  19530. * morphTargets: <bool>,
  19531. * morphNormals: <bool>
  19532. * }
  19533. */
  19534. function MeshLambertMaterial(parameters) {
  19535. Material.call(this);
  19536. this.type = 'MeshLambertMaterial';
  19537. this.color = new Color(0xffffff); // diffuse
  19538. this.map = null;
  19539. this.lightMap = null;
  19540. this.lightMapIntensity = 1.0;
  19541. this.aoMap = null;
  19542. this.aoMapIntensity = 1.0;
  19543. this.emissive = new Color(0x000000);
  19544. this.emissiveIntensity = 1.0;
  19545. this.emissiveMap = null;
  19546. this.specularMap = null;
  19547. this.alphaMap = null;
  19548. this.envMap = null;
  19549. this.combine = MultiplyOperation;
  19550. this.reflectivity = 1;
  19551. this.refractionRatio = 0.98;
  19552. this.wireframe = false;
  19553. this.wireframeLinewidth = 1;
  19554. this.wireframeLinecap = 'round';
  19555. this.wireframeLinejoin = 'round';
  19556. this.skinning = false;
  19557. this.morphTargets = false;
  19558. this.morphNormals = false;
  19559. this.setValues(parameters);
  19560. }
  19561. MeshLambertMaterial.prototype = Object.create(Material.prototype);
  19562. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  19563. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  19564. MeshLambertMaterial.prototype.copy = function (source) {
  19565. Material.prototype.copy.call(this, source);
  19566. this.color.copy(source.color);
  19567. this.map = source.map;
  19568. this.lightMap = source.lightMap;
  19569. this.lightMapIntensity = source.lightMapIntensity;
  19570. this.aoMap = source.aoMap;
  19571. this.aoMapIntensity = source.aoMapIntensity;
  19572. this.emissive.copy(source.emissive);
  19573. this.emissiveMap = source.emissiveMap;
  19574. this.emissiveIntensity = source.emissiveIntensity;
  19575. this.specularMap = source.specularMap;
  19576. this.alphaMap = source.alphaMap;
  19577. this.envMap = source.envMap;
  19578. this.combine = source.combine;
  19579. this.reflectivity = source.reflectivity;
  19580. this.refractionRatio = source.refractionRatio;
  19581. this.wireframe = source.wireframe;
  19582. this.wireframeLinewidth = source.wireframeLinewidth;
  19583. this.wireframeLinecap = source.wireframeLinecap;
  19584. this.wireframeLinejoin = source.wireframeLinejoin;
  19585. this.skinning = source.skinning;
  19586. this.morphTargets = source.morphTargets;
  19587. this.morphNormals = source.morphNormals;
  19588. return this;
  19589. };
  19590. /**
  19591. * parameters = {
  19592. * color: <hex>,
  19593. * opacity: <float>,
  19594. *
  19595. * matcap: new THREE.Texture( <Image> ),
  19596. *
  19597. * map: new THREE.Texture( <Image> ),
  19598. *
  19599. * bumpMap: new THREE.Texture( <Image> ),
  19600. * bumpScale: <float>,
  19601. *
  19602. * normalMap: new THREE.Texture( <Image> ),
  19603. * normalMapType: THREE.TangentSpaceNormalMap,
  19604. * normalScale: <Vector2>,
  19605. *
  19606. * displacementMap: new THREE.Texture( <Image> ),
  19607. * displacementScale: <float>,
  19608. * displacementBias: <float>,
  19609. *
  19610. * alphaMap: new THREE.Texture( <Image> ),
  19611. *
  19612. * skinning: <bool>,
  19613. * morphTargets: <bool>,
  19614. * morphNormals: <bool>
  19615. * }
  19616. */
  19617. function MeshMatcapMaterial(parameters) {
  19618. Material.call(this);
  19619. this.defines = {
  19620. 'MATCAP': ''
  19621. };
  19622. this.type = 'MeshMatcapMaterial';
  19623. this.color = new Color(0xffffff); // diffuse
  19624. this.matcap = null;
  19625. this.map = null;
  19626. this.bumpMap = null;
  19627. this.bumpScale = 1;
  19628. this.normalMap = null;
  19629. this.normalMapType = TangentSpaceNormalMap;
  19630. this.normalScale = new Vector2(1, 1);
  19631. this.displacementMap = null;
  19632. this.displacementScale = 1;
  19633. this.displacementBias = 0;
  19634. this.alphaMap = null;
  19635. this.skinning = false;
  19636. this.morphTargets = false;
  19637. this.morphNormals = false;
  19638. this.setValues(parameters);
  19639. }
  19640. MeshMatcapMaterial.prototype = Object.create(Material.prototype);
  19641. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  19642. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  19643. MeshMatcapMaterial.prototype.copy = function (source) {
  19644. Material.prototype.copy.call(this, source);
  19645. this.defines = {
  19646. 'MATCAP': ''
  19647. };
  19648. this.color.copy(source.color);
  19649. this.matcap = source.matcap;
  19650. this.map = source.map;
  19651. this.bumpMap = source.bumpMap;
  19652. this.bumpScale = source.bumpScale;
  19653. this.normalMap = source.normalMap;
  19654. this.normalMapType = source.normalMapType;
  19655. this.normalScale.copy(source.normalScale);
  19656. this.displacementMap = source.displacementMap;
  19657. this.displacementScale = source.displacementScale;
  19658. this.displacementBias = source.displacementBias;
  19659. this.alphaMap = source.alphaMap;
  19660. this.skinning = source.skinning;
  19661. this.morphTargets = source.morphTargets;
  19662. this.morphNormals = source.morphNormals;
  19663. return this;
  19664. };
  19665. /**
  19666. * parameters = {
  19667. * color: <hex>,
  19668. * opacity: <float>,
  19669. *
  19670. * linewidth: <float>,
  19671. *
  19672. * scale: <float>,
  19673. * dashSize: <float>,
  19674. * gapSize: <float>
  19675. * }
  19676. */
  19677. function LineDashedMaterial(parameters) {
  19678. LineBasicMaterial.call(this);
  19679. this.type = 'LineDashedMaterial';
  19680. this.scale = 1;
  19681. this.dashSize = 3;
  19682. this.gapSize = 1;
  19683. this.setValues(parameters);
  19684. }
  19685. LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
  19686. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  19687. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  19688. LineDashedMaterial.prototype.copy = function (source) {
  19689. LineBasicMaterial.prototype.copy.call(this, source);
  19690. this.scale = source.scale;
  19691. this.dashSize = source.dashSize;
  19692. this.gapSize = source.gapSize;
  19693. return this;
  19694. };
  19695. var Materials = /*#__PURE__*/Object.freeze({
  19696. __proto__: null,
  19697. ShadowMaterial: ShadowMaterial,
  19698. SpriteMaterial: SpriteMaterial,
  19699. RawShaderMaterial: RawShaderMaterial,
  19700. ShaderMaterial: ShaderMaterial,
  19701. PointsMaterial: PointsMaterial,
  19702. MeshPhysicalMaterial: MeshPhysicalMaterial,
  19703. MeshStandardMaterial: MeshStandardMaterial,
  19704. MeshPhongMaterial: MeshPhongMaterial,
  19705. MeshToonMaterial: MeshToonMaterial,
  19706. MeshNormalMaterial: MeshNormalMaterial,
  19707. MeshLambertMaterial: MeshLambertMaterial,
  19708. MeshDepthMaterial: MeshDepthMaterial,
  19709. MeshDistanceMaterial: MeshDistanceMaterial,
  19710. MeshBasicMaterial: MeshBasicMaterial,
  19711. MeshMatcapMaterial: MeshMatcapMaterial,
  19712. LineDashedMaterial: LineDashedMaterial,
  19713. LineBasicMaterial: LineBasicMaterial,
  19714. Material: Material
  19715. });
  19716. var AnimationUtils = {
  19717. // same as Array.prototype.slice, but also works on typed arrays
  19718. arraySlice: function arraySlice(array, from, to) {
  19719. if (AnimationUtils.isTypedArray(array)) {
  19720. // in ios9 array.subarray(from, undefined) will return empty array
  19721. // but array.subarray(from) or array.subarray(from, len) is correct
  19722. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  19723. }
  19724. return array.slice(from, to);
  19725. },
  19726. // converts an array to a specific type
  19727. convertArray: function convertArray(array, type, forceClone) {
  19728. if (!array || // let 'undefined' and 'null' pass
  19729. !forceClone && array.constructor === type) return array;
  19730. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  19731. return new type(array); // create typed array
  19732. }
  19733. return Array.prototype.slice.call(array); // create Array
  19734. },
  19735. isTypedArray: function isTypedArray(object) {
  19736. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  19737. },
  19738. // returns an array by which times and values can be sorted
  19739. getKeyframeOrder: function getKeyframeOrder(times) {
  19740. function compareTime(i, j) {
  19741. return times[i] - times[j];
  19742. }
  19743. var n = times.length;
  19744. var result = new Array(n);
  19745. for (var i = 0; i !== n; ++i) {
  19746. result[i] = i;
  19747. }
  19748. result.sort(compareTime);
  19749. return result;
  19750. },
  19751. // uses the array previously returned by 'getKeyframeOrder' to sort data
  19752. sortedArray: function sortedArray(values, stride, order) {
  19753. var nValues = values.length;
  19754. var result = new values.constructor(nValues);
  19755. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  19756. var srcOffset = order[i] * stride;
  19757. for (var j = 0; j !== stride; ++j) {
  19758. result[dstOffset++] = values[srcOffset + j];
  19759. }
  19760. }
  19761. return result;
  19762. },
  19763. // function for parsing AOS keyframe formats
  19764. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  19765. var i = 1,
  19766. key = jsonKeys[0];
  19767. while (key !== undefined && key[valuePropertyName] === undefined) {
  19768. key = jsonKeys[i++];
  19769. }
  19770. if (key === undefined) return; // no data
  19771. var value = key[valuePropertyName];
  19772. if (value === undefined) return; // no data
  19773. if (Array.isArray(value)) {
  19774. do {
  19775. value = key[valuePropertyName];
  19776. if (value !== undefined) {
  19777. times.push(key.time);
  19778. values.push.apply(values, value); // push all elements
  19779. }
  19780. key = jsonKeys[i++];
  19781. } while (key !== undefined);
  19782. } else if (value.toArray !== undefined) {
  19783. // ...assume THREE.Math-ish
  19784. do {
  19785. value = key[valuePropertyName];
  19786. if (value !== undefined) {
  19787. times.push(key.time);
  19788. value.toArray(values, values.length);
  19789. }
  19790. key = jsonKeys[i++];
  19791. } while (key !== undefined);
  19792. } else {
  19793. // otherwise push as-is
  19794. do {
  19795. value = key[valuePropertyName];
  19796. if (value !== undefined) {
  19797. times.push(key.time);
  19798. values.push(value);
  19799. }
  19800. key = jsonKeys[i++];
  19801. } while (key !== undefined);
  19802. }
  19803. },
  19804. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  19805. if (fps === void 0) {
  19806. fps = 30;
  19807. }
  19808. var clip = sourceClip.clone();
  19809. clip.name = name;
  19810. var tracks = [];
  19811. for (var i = 0; i < clip.tracks.length; ++i) {
  19812. var track = clip.tracks[i];
  19813. var valueSize = track.getValueSize();
  19814. var times = [];
  19815. var values = [];
  19816. for (var j = 0; j < track.times.length; ++j) {
  19817. var frame = track.times[j] * fps;
  19818. if (frame < startFrame || frame >= endFrame) continue;
  19819. times.push(track.times[j]);
  19820. for (var k = 0; k < valueSize; ++k) {
  19821. values.push(track.values[j * valueSize + k]);
  19822. }
  19823. }
  19824. if (times.length === 0) continue;
  19825. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  19826. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  19827. tracks.push(track);
  19828. }
  19829. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  19830. var minStartTime = Infinity;
  19831. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  19832. if (minStartTime > clip.tracks[_i].times[0]) {
  19833. minStartTime = clip.tracks[_i].times[0];
  19834. }
  19835. } // shift all tracks such that clip begins at t=0
  19836. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  19837. clip.tracks[_i2].shift(-1 * minStartTime);
  19838. }
  19839. clip.resetDuration();
  19840. return clip;
  19841. },
  19842. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  19843. if (referenceFrame === void 0) {
  19844. referenceFrame = 0;
  19845. }
  19846. if (referenceClip === void 0) {
  19847. referenceClip = targetClip;
  19848. }
  19849. if (fps === void 0) {
  19850. fps = 30;
  19851. }
  19852. if (fps <= 0) fps = 30;
  19853. var numTracks = referenceClip.tracks.length;
  19854. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  19855. var _loop = function _loop(i) {
  19856. var referenceTrack = referenceClip.tracks[i];
  19857. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  19858. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  19859. var targetTrack = targetClip.tracks.find(function (track) {
  19860. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  19861. });
  19862. if (targetTrack === undefined) return "continue";
  19863. var referenceOffset = 0;
  19864. var referenceValueSize = referenceTrack.getValueSize();
  19865. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  19866. referenceOffset = referenceValueSize / 3;
  19867. }
  19868. var targetOffset = 0;
  19869. var targetValueSize = targetTrack.getValueSize();
  19870. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  19871. targetOffset = targetValueSize / 3;
  19872. }
  19873. var lastIndex = referenceTrack.times.length - 1;
  19874. var referenceValue = void 0; // Find the value to subtract out of the track
  19875. if (referenceTime <= referenceTrack.times[0]) {
  19876. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  19877. var startIndex = referenceOffset;
  19878. var endIndex = referenceValueSize - referenceOffset;
  19879. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  19880. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  19881. // Reference frame is after the last keyframe, so just use the last keyframe
  19882. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  19883. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  19884. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  19885. } else {
  19886. // Interpolate to the reference value
  19887. var interpolant = referenceTrack.createInterpolant();
  19888. var _startIndex2 = referenceOffset;
  19889. var _endIndex2 = referenceValueSize - referenceOffset;
  19890. interpolant.evaluate(referenceTime);
  19891. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  19892. } // Conjugate the quaternion
  19893. if (referenceTrackType === 'quaternion') {
  19894. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  19895. referenceQuat.toArray(referenceValue);
  19896. } // Subtract the reference value from all of the track values
  19897. var numTimes = targetTrack.times.length;
  19898. for (var j = 0; j < numTimes; ++j) {
  19899. var valueStart = j * targetValueSize + targetOffset;
  19900. if (referenceTrackType === 'quaternion') {
  19901. // Multiply the conjugate for quaternion track types
  19902. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  19903. } else {
  19904. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  19905. for (var k = 0; k < valueEnd; ++k) {
  19906. targetTrack.values[valueStart + k] -= referenceValue[k];
  19907. }
  19908. }
  19909. }
  19910. };
  19911. for (var i = 0; i < numTracks; ++i) {
  19912. var _ret = _loop(i);
  19913. if (_ret === "continue") continue;
  19914. }
  19915. targetClip.blendMode = AdditiveAnimationBlendMode;
  19916. return targetClip;
  19917. }
  19918. };
  19919. /**
  19920. * Abstract base class of interpolants over parametric samples.
  19921. *
  19922. * The parameter domain is one dimensional, typically the time or a path
  19923. * along a curve defined by the data.
  19924. *
  19925. * The sample values can have any dimensionality and derived classes may
  19926. * apply special interpretations to the data.
  19927. *
  19928. * This class provides the interval seek in a Template Method, deferring
  19929. * the actual interpolation to derived classes.
  19930. *
  19931. * Time complexity is O(1) for linear access crossing at most two points
  19932. * and O(log N) for random access, where N is the number of positions.
  19933. *
  19934. * References:
  19935. *
  19936. * http://www.oodesign.com/template-method-pattern.html
  19937. *
  19938. */
  19939. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  19940. this.parameterPositions = parameterPositions;
  19941. this._cachedIndex = 0;
  19942. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  19943. this.sampleValues = sampleValues;
  19944. this.valueSize = sampleSize;
  19945. }
  19946. Object.assign(Interpolant.prototype, {
  19947. evaluate: function evaluate(t) {
  19948. var pp = this.parameterPositions;
  19949. var i1 = this._cachedIndex,
  19950. t1 = pp[i1],
  19951. t0 = pp[i1 - 1];
  19952. validate_interval: {
  19953. seek: {
  19954. var right;
  19955. linear_scan: {
  19956. //- See http://jsperf.com/comparison-to-undefined/3
  19957. //- slower code:
  19958. //-
  19959. //- if ( t >= t1 || t1 === undefined ) {
  19960. forward_scan: if (!(t < t1)) {
  19961. for (var giveUpAt = i1 + 2;;) {
  19962. if (t1 === undefined) {
  19963. if (t < t0) break forward_scan; // after end
  19964. i1 = pp.length;
  19965. this._cachedIndex = i1;
  19966. return this.afterEnd_(i1 - 1, t, t0);
  19967. }
  19968. if (i1 === giveUpAt) break; // this loop
  19969. t0 = t1;
  19970. t1 = pp[++i1];
  19971. if (t < t1) {
  19972. // we have arrived at the sought interval
  19973. break seek;
  19974. }
  19975. } // prepare binary search on the right side of the index
  19976. right = pp.length;
  19977. break linear_scan;
  19978. } //- slower code:
  19979. //- if ( t < t0 || t0 === undefined ) {
  19980. if (!(t >= t0)) {
  19981. // looping?
  19982. var t1global = pp[1];
  19983. if (t < t1global) {
  19984. i1 = 2; // + 1, using the scan for the details
  19985. t0 = t1global;
  19986. } // linear reverse scan
  19987. for (var _giveUpAt = i1 - 2;;) {
  19988. if (t0 === undefined) {
  19989. // before start
  19990. this._cachedIndex = 0;
  19991. return this.beforeStart_(0, t, t1);
  19992. }
  19993. if (i1 === _giveUpAt) break; // this loop
  19994. t1 = t0;
  19995. t0 = pp[--i1 - 1];
  19996. if (t >= t0) {
  19997. // we have arrived at the sought interval
  19998. break seek;
  19999. }
  20000. } // prepare binary search on the left side of the index
  20001. right = i1;
  20002. i1 = 0;
  20003. break linear_scan;
  20004. } // the interval is valid
  20005. break validate_interval;
  20006. } // linear scan
  20007. // binary search
  20008. while (i1 < right) {
  20009. var mid = i1 + right >>> 1;
  20010. if (t < pp[mid]) {
  20011. right = mid;
  20012. } else {
  20013. i1 = mid + 1;
  20014. }
  20015. }
  20016. t1 = pp[i1];
  20017. t0 = pp[i1 - 1]; // check boundary cases, again
  20018. if (t0 === undefined) {
  20019. this._cachedIndex = 0;
  20020. return this.beforeStart_(0, t, t1);
  20021. }
  20022. if (t1 === undefined) {
  20023. i1 = pp.length;
  20024. this._cachedIndex = i1;
  20025. return this.afterEnd_(i1 - 1, t0, t);
  20026. }
  20027. } // seek
  20028. this._cachedIndex = i1;
  20029. this.intervalChanged_(i1, t0, t1);
  20030. } // validate_interval
  20031. return this.interpolate_(i1, t0, t, t1);
  20032. },
  20033. settings: null,
  20034. // optional, subclass-specific settings structure
  20035. // Note: The indirection allows central control of many interpolants.
  20036. // --- Protected interface
  20037. DefaultSettings_: {},
  20038. getSettings_: function getSettings_() {
  20039. return this.settings || this.DefaultSettings_;
  20040. },
  20041. copySampleValue_: function copySampleValue_(index) {
  20042. // copies a sample value to the result buffer
  20043. var result = this.resultBuffer,
  20044. values = this.sampleValues,
  20045. stride = this.valueSize,
  20046. offset = index * stride;
  20047. for (var i = 0; i !== stride; ++i) {
  20048. result[i] = values[offset + i];
  20049. }
  20050. return result;
  20051. },
  20052. // Template methods for derived classes:
  20053. interpolate_: function interpolate_()
  20054. /* i1, t0, t, t1 */
  20055. {
  20056. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  20057. },
  20058. intervalChanged_: function intervalChanged_()
  20059. /* i1, t0, t1 */
  20060. {// empty
  20061. }
  20062. }); // DECLARE ALIAS AFTER assign prototype
  20063. Object.assign(Interpolant.prototype, {
  20064. //( 0, t, t0 ), returns this.resultBuffer
  20065. beforeStart_: Interpolant.prototype.copySampleValue_,
  20066. //( N-1, tN-1, t ), returns this.resultBuffer
  20067. afterEnd_: Interpolant.prototype.copySampleValue_
  20068. });
  20069. /**
  20070. * Fast and simple cubic spline interpolant.
  20071. *
  20072. * It was derived from a Hermitian construction setting the first derivative
  20073. * at each sample position to the linear slope between neighboring positions
  20074. * over their parameter interval.
  20075. */
  20076. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20077. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20078. this._weightPrev = -0;
  20079. this._offsetPrev = -0;
  20080. this._weightNext = -0;
  20081. this._offsetNext = -0;
  20082. }
  20083. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20084. constructor: CubicInterpolant,
  20085. DefaultSettings_: {
  20086. endingStart: ZeroCurvatureEnding,
  20087. endingEnd: ZeroCurvatureEnding
  20088. },
  20089. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  20090. var pp = this.parameterPositions;
  20091. var iPrev = i1 - 2,
  20092. iNext = i1 + 1,
  20093. tPrev = pp[iPrev],
  20094. tNext = pp[iNext];
  20095. if (tPrev === undefined) {
  20096. switch (this.getSettings_().endingStart) {
  20097. case ZeroSlopeEnding:
  20098. // f'(t0) = 0
  20099. iPrev = i1;
  20100. tPrev = 2 * t0 - t1;
  20101. break;
  20102. case WrapAroundEnding:
  20103. // use the other end of the curve
  20104. iPrev = pp.length - 2;
  20105. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  20106. break;
  20107. default:
  20108. // ZeroCurvatureEnding
  20109. // f''(t0) = 0 a.k.a. Natural Spline
  20110. iPrev = i1;
  20111. tPrev = t1;
  20112. }
  20113. }
  20114. if (tNext === undefined) {
  20115. switch (this.getSettings_().endingEnd) {
  20116. case ZeroSlopeEnding:
  20117. // f'(tN) = 0
  20118. iNext = i1;
  20119. tNext = 2 * t1 - t0;
  20120. break;
  20121. case WrapAroundEnding:
  20122. // use the other end of the curve
  20123. iNext = 1;
  20124. tNext = t1 + pp[1] - pp[0];
  20125. break;
  20126. default:
  20127. // ZeroCurvatureEnding
  20128. // f''(tN) = 0, a.k.a. Natural Spline
  20129. iNext = i1 - 1;
  20130. tNext = t0;
  20131. }
  20132. }
  20133. var halfDt = (t1 - t0) * 0.5,
  20134. stride = this.valueSize;
  20135. this._weightPrev = halfDt / (t0 - tPrev);
  20136. this._weightNext = halfDt / (tNext - t1);
  20137. this._offsetPrev = iPrev * stride;
  20138. this._offsetNext = iNext * stride;
  20139. },
  20140. interpolate_: function interpolate_(i1, t0, t, t1) {
  20141. var result = this.resultBuffer,
  20142. values = this.sampleValues,
  20143. stride = this.valueSize,
  20144. o1 = i1 * stride,
  20145. o0 = o1 - stride,
  20146. oP = this._offsetPrev,
  20147. oN = this._offsetNext,
  20148. wP = this._weightPrev,
  20149. wN = this._weightNext,
  20150. p = (t - t0) / (t1 - t0),
  20151. pp = p * p,
  20152. ppp = pp * p; // evaluate polynomials
  20153. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  20154. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  20155. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  20156. var sN = wN * ppp - wN * pp; // combine data linearly
  20157. for (var i = 0; i !== stride; ++i) {
  20158. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  20159. }
  20160. return result;
  20161. }
  20162. });
  20163. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20164. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20165. }
  20166. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20167. constructor: LinearInterpolant,
  20168. interpolate_: function interpolate_(i1, t0, t, t1) {
  20169. var result = this.resultBuffer,
  20170. values = this.sampleValues,
  20171. stride = this.valueSize,
  20172. offset1 = i1 * stride,
  20173. offset0 = offset1 - stride,
  20174. weight1 = (t - t0) / (t1 - t0),
  20175. weight0 = 1 - weight1;
  20176. for (var i = 0; i !== stride; ++i) {
  20177. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  20178. }
  20179. return result;
  20180. }
  20181. });
  20182. /**
  20183. *
  20184. * Interpolant that evaluates to the sample value at the position preceeding
  20185. * the parameter.
  20186. */
  20187. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20188. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20189. }
  20190. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20191. constructor: DiscreteInterpolant,
  20192. interpolate_: function interpolate_(i1
  20193. /*, t0, t, t1 */
  20194. ) {
  20195. return this.copySampleValue_(i1 - 1);
  20196. }
  20197. });
  20198. function KeyframeTrack(name, times, values, interpolation) {
  20199. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  20200. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  20201. this.name = name;
  20202. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  20203. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  20204. this.setInterpolation(interpolation || this.DefaultInterpolation);
  20205. } // Static methods
  20206. Object.assign(KeyframeTrack, {
  20207. // Serialization (in static context, because of constructor invocation
  20208. // and automatic invocation of .toJSON):
  20209. toJSON: function toJSON(track) {
  20210. var trackType = track.constructor;
  20211. var json; // derived classes can define a static toJSON method
  20212. if (trackType.toJSON !== undefined) {
  20213. json = trackType.toJSON(track);
  20214. } else {
  20215. // by default, we assume the data can be serialized as-is
  20216. json = {
  20217. 'name': track.name,
  20218. 'times': AnimationUtils.convertArray(track.times, Array),
  20219. 'values': AnimationUtils.convertArray(track.values, Array)
  20220. };
  20221. var interpolation = track.getInterpolation();
  20222. if (interpolation !== track.DefaultInterpolation) {
  20223. json.interpolation = interpolation;
  20224. }
  20225. }
  20226. json.type = track.ValueTypeName; // mandatory
  20227. return json;
  20228. }
  20229. });
  20230. Object.assign(KeyframeTrack.prototype, {
  20231. constructor: KeyframeTrack,
  20232. TimeBufferType: Float32Array,
  20233. ValueBufferType: Float32Array,
  20234. DefaultInterpolation: InterpolateLinear,
  20235. InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
  20236. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  20237. },
  20238. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  20239. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  20240. },
  20241. InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
  20242. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  20243. },
  20244. setInterpolation: function setInterpolation(interpolation) {
  20245. var factoryMethod;
  20246. switch (interpolation) {
  20247. case InterpolateDiscrete:
  20248. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20249. break;
  20250. case InterpolateLinear:
  20251. factoryMethod = this.InterpolantFactoryMethodLinear;
  20252. break;
  20253. case InterpolateSmooth:
  20254. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20255. break;
  20256. }
  20257. if (factoryMethod === undefined) {
  20258. var message = 'unsupported interpolation for ' + this.ValueTypeName + ' keyframe track named ' + this.name;
  20259. if (this.createInterpolant === undefined) {
  20260. // fall back to default, unless the default itself is messed up
  20261. if (interpolation !== this.DefaultInterpolation) {
  20262. this.setInterpolation(this.DefaultInterpolation);
  20263. } else {
  20264. throw new Error(message); // fatal, in this case
  20265. }
  20266. }
  20267. console.warn('THREE.KeyframeTrack:', message);
  20268. return this;
  20269. }
  20270. this.createInterpolant = factoryMethod;
  20271. return this;
  20272. },
  20273. getInterpolation: function getInterpolation() {
  20274. switch (this.createInterpolant) {
  20275. case this.InterpolantFactoryMethodDiscrete:
  20276. return InterpolateDiscrete;
  20277. case this.InterpolantFactoryMethodLinear:
  20278. return InterpolateLinear;
  20279. case this.InterpolantFactoryMethodSmooth:
  20280. return InterpolateSmooth;
  20281. }
  20282. },
  20283. getValueSize: function getValueSize() {
  20284. return this.values.length / this.times.length;
  20285. },
  20286. // move all keyframes either forwards or backwards in time
  20287. shift: function shift(timeOffset) {
  20288. if (timeOffset !== 0.0) {
  20289. var times = this.times;
  20290. for (var i = 0, n = times.length; i !== n; ++i) {
  20291. times[i] += timeOffset;
  20292. }
  20293. }
  20294. return this;
  20295. },
  20296. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  20297. scale: function scale(timeScale) {
  20298. if (timeScale !== 1.0) {
  20299. var times = this.times;
  20300. for (var i = 0, n = times.length; i !== n; ++i) {
  20301. times[i] *= timeScale;
  20302. }
  20303. }
  20304. return this;
  20305. },
  20306. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  20307. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  20308. trim: function trim(startTime, endTime) {
  20309. var times = this.times,
  20310. nKeys = times.length;
  20311. var from = 0,
  20312. to = nKeys - 1;
  20313. while (from !== nKeys && times[from] < startTime) {
  20314. ++from;
  20315. }
  20316. while (to !== -1 && times[to] > endTime) {
  20317. --to;
  20318. }
  20319. ++to; // inclusive -> exclusive bound
  20320. if (from !== 0 || to !== nKeys) {
  20321. // empty tracks are forbidden, so keep at least one keyframe
  20322. if (from >= to) {
  20323. to = Math.max(to, 1);
  20324. from = to - 1;
  20325. }
  20326. var stride = this.getValueSize();
  20327. this.times = AnimationUtils.arraySlice(times, from, to);
  20328. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  20329. }
  20330. return this;
  20331. },
  20332. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  20333. validate: function validate() {
  20334. var valid = true;
  20335. var valueSize = this.getValueSize();
  20336. if (valueSize - Math.floor(valueSize) !== 0) {
  20337. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  20338. valid = false;
  20339. }
  20340. var times = this.times,
  20341. values = this.values,
  20342. nKeys = times.length;
  20343. if (nKeys === 0) {
  20344. console.error('THREE.KeyframeTrack: Track is empty.', this);
  20345. valid = false;
  20346. }
  20347. var prevTime = null;
  20348. for (var i = 0; i !== nKeys; i++) {
  20349. var currTime = times[i];
  20350. if (typeof currTime === 'number' && isNaN(currTime)) {
  20351. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  20352. valid = false;
  20353. break;
  20354. }
  20355. if (prevTime !== null && prevTime > currTime) {
  20356. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  20357. valid = false;
  20358. break;
  20359. }
  20360. prevTime = currTime;
  20361. }
  20362. if (values !== undefined) {
  20363. if (AnimationUtils.isTypedArray(values)) {
  20364. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  20365. var value = values[_i];
  20366. if (isNaN(value)) {
  20367. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  20368. valid = false;
  20369. break;
  20370. }
  20371. }
  20372. }
  20373. }
  20374. return valid;
  20375. },
  20376. // removes equivalent sequential keys as common in morph target sequences
  20377. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  20378. optimize: function optimize() {
  20379. // times or values may be shared with other tracks, so overwriting is unsafe
  20380. var times = AnimationUtils.arraySlice(this.times),
  20381. values = AnimationUtils.arraySlice(this.values),
  20382. stride = this.getValueSize(),
  20383. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  20384. lastIndex = times.length - 1;
  20385. var writeIndex = 1;
  20386. for (var i = 1; i < lastIndex; ++i) {
  20387. var keep = false;
  20388. var time = times[i];
  20389. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  20390. if (time !== timeNext && (i !== 1 || time !== time[0])) {
  20391. if (!smoothInterpolation) {
  20392. // remove unnecessary keyframes same as their neighbors
  20393. var offset = i * stride,
  20394. offsetP = offset - stride,
  20395. offsetN = offset + stride;
  20396. for (var j = 0; j !== stride; ++j) {
  20397. var value = values[offset + j];
  20398. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  20399. keep = true;
  20400. break;
  20401. }
  20402. }
  20403. } else {
  20404. keep = true;
  20405. }
  20406. } // in-place compaction
  20407. if (keep) {
  20408. if (i !== writeIndex) {
  20409. times[writeIndex] = times[i];
  20410. var readOffset = i * stride,
  20411. writeOffset = writeIndex * stride;
  20412. for (var _j = 0; _j !== stride; ++_j) {
  20413. values[writeOffset + _j] = values[readOffset + _j];
  20414. }
  20415. }
  20416. ++writeIndex;
  20417. }
  20418. } // flush last keyframe (compaction looks ahead)
  20419. if (lastIndex > 0) {
  20420. times[writeIndex] = times[lastIndex];
  20421. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  20422. values[_writeOffset + _j2] = values[_readOffset + _j2];
  20423. }
  20424. ++writeIndex;
  20425. }
  20426. if (writeIndex !== times.length) {
  20427. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  20428. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  20429. } else {
  20430. this.times = times;
  20431. this.values = values;
  20432. }
  20433. return this;
  20434. },
  20435. clone: function clone() {
  20436. var times = AnimationUtils.arraySlice(this.times, 0);
  20437. var values = AnimationUtils.arraySlice(this.values, 0);
  20438. var TypedKeyframeTrack = this.constructor;
  20439. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  20440. track.createInterpolant = this.createInterpolant;
  20441. return track;
  20442. }
  20443. });
  20444. /**
  20445. * A Track of Boolean keyframe values.
  20446. */
  20447. function BooleanKeyframeTrack(name, times, values) {
  20448. KeyframeTrack.call(this, name, times, values);
  20449. }
  20450. BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  20451. constructor: BooleanKeyframeTrack,
  20452. ValueTypeName: 'bool',
  20453. ValueBufferType: Array,
  20454. DefaultInterpolation: InterpolateDiscrete,
  20455. InterpolantFactoryMethodLinear: undefined,
  20456. InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
  20457. // representation of a single value and a custom interpolant that
  20458. // computes "firstValue ^ isOdd( index )".
  20459. });
  20460. /**
  20461. * A Track of keyframe values that represent color.
  20462. */
  20463. function ColorKeyframeTrack(name, times, values, interpolation) {
  20464. KeyframeTrack.call(this, name, times, values, interpolation);
  20465. }
  20466. ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  20467. constructor: ColorKeyframeTrack,
  20468. ValueTypeName: 'color' // ValueBufferType is inherited
  20469. // DefaultInterpolation is inherited
  20470. // Note: Very basic implementation and nothing special yet.
  20471. // However, this is the place for color space parameterization.
  20472. });
  20473. /**
  20474. * A Track of numeric keyframe values.
  20475. */
  20476. function NumberKeyframeTrack(name, times, values, interpolation) {
  20477. KeyframeTrack.call(this, name, times, values, interpolation);
  20478. }
  20479. NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  20480. constructor: NumberKeyframeTrack,
  20481. ValueTypeName: 'number' // ValueBufferType is inherited
  20482. // DefaultInterpolation is inherited
  20483. });
  20484. /**
  20485. * Spherical linear unit quaternion interpolant.
  20486. */
  20487. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20488. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20489. }
  20490. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20491. constructor: QuaternionLinearInterpolant,
  20492. interpolate_: function interpolate_(i1, t0, t, t1) {
  20493. var result = this.resultBuffer,
  20494. values = this.sampleValues,
  20495. stride = this.valueSize,
  20496. alpha = (t - t0) / (t1 - t0);
  20497. var offset = i1 * stride;
  20498. for (var end = offset + stride; offset !== end; offset += 4) {
  20499. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  20500. }
  20501. return result;
  20502. }
  20503. });
  20504. /**
  20505. * A Track of quaternion keyframe values.
  20506. */
  20507. function QuaternionKeyframeTrack(name, times, values, interpolation) {
  20508. KeyframeTrack.call(this, name, times, values, interpolation);
  20509. }
  20510. QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  20511. constructor: QuaternionKeyframeTrack,
  20512. ValueTypeName: 'quaternion',
  20513. // ValueBufferType is inherited
  20514. DefaultInterpolation: InterpolateLinear,
  20515. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  20516. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  20517. },
  20518. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20519. });
  20520. /**
  20521. * A Track that interpolates Strings
  20522. */
  20523. function StringKeyframeTrack(name, times, values, interpolation) {
  20524. KeyframeTrack.call(this, name, times, values, interpolation);
  20525. }
  20526. StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  20527. constructor: StringKeyframeTrack,
  20528. ValueTypeName: 'string',
  20529. ValueBufferType: Array,
  20530. DefaultInterpolation: InterpolateDiscrete,
  20531. InterpolantFactoryMethodLinear: undefined,
  20532. InterpolantFactoryMethodSmooth: undefined
  20533. });
  20534. /**
  20535. * A Track of vectored keyframe values.
  20536. */
  20537. function VectorKeyframeTrack(name, times, values, interpolation) {
  20538. KeyframeTrack.call(this, name, times, values, interpolation);
  20539. }
  20540. VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  20541. constructor: VectorKeyframeTrack,
  20542. ValueTypeName: 'vector' // ValueBufferType is inherited
  20543. // DefaultInterpolation is inherited
  20544. });
  20545. function AnimationClip(name, duration, tracks, blendMode) {
  20546. if (duration === void 0) {
  20547. duration = -1;
  20548. }
  20549. if (blendMode === void 0) {
  20550. blendMode = NormalAnimationBlendMode;
  20551. }
  20552. this.name = name;
  20553. this.tracks = tracks;
  20554. this.duration = duration;
  20555. this.blendMode = blendMode;
  20556. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  20557. if (this.duration < 0) {
  20558. this.resetDuration();
  20559. }
  20560. }
  20561. function getTrackTypeForValueTypeName(typeName) {
  20562. switch (typeName.toLowerCase()) {
  20563. case 'scalar':
  20564. case 'double':
  20565. case 'float':
  20566. case 'number':
  20567. case 'integer':
  20568. return NumberKeyframeTrack;
  20569. case 'vector':
  20570. case 'vector2':
  20571. case 'vector3':
  20572. case 'vector4':
  20573. return VectorKeyframeTrack;
  20574. case 'color':
  20575. return ColorKeyframeTrack;
  20576. case 'quaternion':
  20577. return QuaternionKeyframeTrack;
  20578. case 'bool':
  20579. case 'boolean':
  20580. return BooleanKeyframeTrack;
  20581. case 'string':
  20582. return StringKeyframeTrack;
  20583. }
  20584. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  20585. }
  20586. function parseKeyframeTrack(json) {
  20587. if (json.type === undefined) {
  20588. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  20589. }
  20590. var trackType = getTrackTypeForValueTypeName(json.type);
  20591. if (json.times === undefined) {
  20592. var times = [],
  20593. values = [];
  20594. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  20595. json.times = times;
  20596. json.values = values;
  20597. } // derived classes can define a static parse method
  20598. if (trackType.parse !== undefined) {
  20599. return trackType.parse(json);
  20600. } else {
  20601. // by default, we assume a constructor compatible with the base
  20602. return new trackType(json.name, json.times, json.values, json.interpolation);
  20603. }
  20604. }
  20605. Object.assign(AnimationClip, {
  20606. parse: function parse(json) {
  20607. var tracks = [],
  20608. jsonTracks = json.tracks,
  20609. frameTime = 1.0 / (json.fps || 1.0);
  20610. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  20611. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  20612. }
  20613. var clip = new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  20614. clip.uuid = json.uuid;
  20615. return clip;
  20616. },
  20617. toJSON: function toJSON(clip) {
  20618. var tracks = [],
  20619. clipTracks = clip.tracks;
  20620. var json = {
  20621. 'name': clip.name,
  20622. 'duration': clip.duration,
  20623. 'tracks': tracks,
  20624. 'uuid': clip.uuid,
  20625. 'blendMode': clip.blendMode
  20626. };
  20627. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  20628. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  20629. }
  20630. return json;
  20631. },
  20632. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  20633. var numMorphTargets = morphTargetSequence.length;
  20634. var tracks = [];
  20635. for (var i = 0; i < numMorphTargets; i++) {
  20636. var times = [];
  20637. var values = [];
  20638. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  20639. values.push(0, 1, 0);
  20640. var order = AnimationUtils.getKeyframeOrder(times);
  20641. times = AnimationUtils.sortedArray(times, 1, order);
  20642. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  20643. // last frame as well for perfect loop.
  20644. if (!noLoop && times[0] === 0) {
  20645. times.push(numMorphTargets);
  20646. values.push(values[0]);
  20647. }
  20648. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  20649. }
  20650. return new AnimationClip(name, -1, tracks);
  20651. },
  20652. findByName: function findByName(objectOrClipArray, name) {
  20653. var clipArray = objectOrClipArray;
  20654. if (!Array.isArray(objectOrClipArray)) {
  20655. var o = objectOrClipArray;
  20656. clipArray = o.geometry && o.geometry.animations || o.animations;
  20657. }
  20658. for (var i = 0; i < clipArray.length; i++) {
  20659. if (clipArray[i].name === name) {
  20660. return clipArray[i];
  20661. }
  20662. }
  20663. return null;
  20664. },
  20665. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  20666. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  20667. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  20668. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  20669. // patterns like Walk_001, Walk_002, Run_001, Run_002
  20670. for (var i = 0, il = morphTargets.length; i < il; i++) {
  20671. var morphTarget = morphTargets[i];
  20672. var parts = morphTarget.name.match(pattern);
  20673. if (parts && parts.length > 1) {
  20674. var name = parts[1];
  20675. var animationMorphTargets = animationToMorphTargets[name];
  20676. if (!animationMorphTargets) {
  20677. animationToMorphTargets[name] = animationMorphTargets = [];
  20678. }
  20679. animationMorphTargets.push(morphTarget);
  20680. }
  20681. }
  20682. var clips = [];
  20683. for (var _name in animationToMorphTargets) {
  20684. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  20685. }
  20686. return clips;
  20687. },
  20688. // parse the animation.hierarchy format
  20689. parseAnimation: function parseAnimation(animation, bones) {
  20690. if (!animation) {
  20691. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  20692. return null;
  20693. }
  20694. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  20695. // only return track if there are actually keys.
  20696. if (animationKeys.length !== 0) {
  20697. var times = [];
  20698. var values = [];
  20699. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  20700. if (times.length !== 0) {
  20701. destTracks.push(new trackType(trackName, times, values));
  20702. }
  20703. }
  20704. };
  20705. var tracks = [];
  20706. var clipName = animation.name || 'default';
  20707. var fps = animation.fps || 30;
  20708. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  20709. var duration = animation.length || -1;
  20710. var hierarchyTracks = animation.hierarchy || [];
  20711. for (var h = 0; h < hierarchyTracks.length; h++) {
  20712. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  20713. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  20714. if (animationKeys[0].morphTargets) {
  20715. // figure out all morph targets used in this track
  20716. var morphTargetNames = {};
  20717. var k = void 0;
  20718. for (k = 0; k < animationKeys.length; k++) {
  20719. if (animationKeys[k].morphTargets) {
  20720. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  20721. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  20722. }
  20723. }
  20724. } // create a track for each morph target with all zero
  20725. // morphTargetInfluences except for the keys in which
  20726. // the morphTarget is named.
  20727. for (var morphTargetName in morphTargetNames) {
  20728. var times = [];
  20729. var values = [];
  20730. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  20731. var animationKey = animationKeys[k];
  20732. times.push(animationKey.time);
  20733. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  20734. }
  20735. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  20736. }
  20737. duration = morphTargetNames.length * (fps || 1.0);
  20738. } else {
  20739. // ...assume skeletal animation
  20740. var boneName = '.bones[' + bones[h].name + ']';
  20741. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  20742. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  20743. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  20744. }
  20745. }
  20746. if (tracks.length === 0) {
  20747. return null;
  20748. }
  20749. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  20750. return clip;
  20751. }
  20752. });
  20753. Object.assign(AnimationClip.prototype, {
  20754. resetDuration: function resetDuration() {
  20755. var tracks = this.tracks;
  20756. var duration = 0;
  20757. for (var i = 0, n = tracks.length; i !== n; ++i) {
  20758. var track = this.tracks[i];
  20759. duration = Math.max(duration, track.times[track.times.length - 1]);
  20760. }
  20761. this.duration = duration;
  20762. return this;
  20763. },
  20764. trim: function trim() {
  20765. for (var i = 0; i < this.tracks.length; i++) {
  20766. this.tracks[i].trim(0, this.duration);
  20767. }
  20768. return this;
  20769. },
  20770. validate: function validate() {
  20771. var valid = true;
  20772. for (var i = 0; i < this.tracks.length; i++) {
  20773. valid = valid && this.tracks[i].validate();
  20774. }
  20775. return valid;
  20776. },
  20777. optimize: function optimize() {
  20778. for (var i = 0; i < this.tracks.length; i++) {
  20779. this.tracks[i].optimize();
  20780. }
  20781. return this;
  20782. },
  20783. clone: function clone() {
  20784. var tracks = [];
  20785. for (var i = 0; i < this.tracks.length; i++) {
  20786. tracks.push(this.tracks[i].clone());
  20787. }
  20788. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  20789. },
  20790. toJSON: function toJSON() {
  20791. return AnimationClip.toJSON(this);
  20792. }
  20793. });
  20794. var Cache = {
  20795. enabled: false,
  20796. files: {},
  20797. add: function add(key, file) {
  20798. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  20799. this.files[key] = file;
  20800. },
  20801. get: function get(key) {
  20802. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  20803. return this.files[key];
  20804. },
  20805. remove: function remove(key) {
  20806. delete this.files[key];
  20807. },
  20808. clear: function clear() {
  20809. this.files = {};
  20810. }
  20811. };
  20812. function LoadingManager(onLoad, onProgress, onError) {
  20813. var scope = this;
  20814. var isLoading = false;
  20815. var itemsLoaded = 0;
  20816. var itemsTotal = 0;
  20817. var urlModifier = undefined;
  20818. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  20819. // in the constructor
  20820. this.onStart = undefined;
  20821. this.onLoad = onLoad;
  20822. this.onProgress = onProgress;
  20823. this.onError = onError;
  20824. this.itemStart = function (url) {
  20825. itemsTotal++;
  20826. if (isLoading === false) {
  20827. if (scope.onStart !== undefined) {
  20828. scope.onStart(url, itemsLoaded, itemsTotal);
  20829. }
  20830. }
  20831. isLoading = true;
  20832. };
  20833. this.itemEnd = function (url) {
  20834. itemsLoaded++;
  20835. if (scope.onProgress !== undefined) {
  20836. scope.onProgress(url, itemsLoaded, itemsTotal);
  20837. }
  20838. if (itemsLoaded === itemsTotal) {
  20839. isLoading = false;
  20840. if (scope.onLoad !== undefined) {
  20841. scope.onLoad();
  20842. }
  20843. }
  20844. };
  20845. this.itemError = function (url) {
  20846. if (scope.onError !== undefined) {
  20847. scope.onError(url);
  20848. }
  20849. };
  20850. this.resolveURL = function (url) {
  20851. if (urlModifier) {
  20852. return urlModifier(url);
  20853. }
  20854. return url;
  20855. };
  20856. this.setURLModifier = function (transform) {
  20857. urlModifier = transform;
  20858. return this;
  20859. };
  20860. this.addHandler = function (regex, loader) {
  20861. handlers.push(regex, loader);
  20862. return this;
  20863. };
  20864. this.removeHandler = function (regex) {
  20865. var index = handlers.indexOf(regex);
  20866. if (index !== -1) {
  20867. handlers.splice(index, 2);
  20868. }
  20869. return this;
  20870. };
  20871. this.getHandler = function (file) {
  20872. for (var i = 0, l = handlers.length; i < l; i += 2) {
  20873. var regex = handlers[i];
  20874. var loader = handlers[i + 1];
  20875. if (regex.global) regex.lastIndex = 0; // see #17920
  20876. if (regex.test(file)) {
  20877. return loader;
  20878. }
  20879. }
  20880. return null;
  20881. };
  20882. }
  20883. var DefaultLoadingManager = new LoadingManager();
  20884. function Loader(manager) {
  20885. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  20886. this.crossOrigin = 'anonymous';
  20887. this.withCredentials = false;
  20888. this.path = '';
  20889. this.resourcePath = '';
  20890. this.requestHeader = {};
  20891. }
  20892. Object.assign(Loader.prototype, {
  20893. load: function load()
  20894. /* url, onLoad, onProgress, onError */
  20895. {},
  20896. loadAsync: function loadAsync(url, onProgress) {
  20897. var scope = this;
  20898. return new Promise(function (resolve, reject) {
  20899. scope.load(url, resolve, onProgress, reject);
  20900. });
  20901. },
  20902. parse: function parse()
  20903. /* data */
  20904. {},
  20905. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  20906. this.crossOrigin = crossOrigin;
  20907. return this;
  20908. },
  20909. setWithCredentials: function setWithCredentials(value) {
  20910. this.withCredentials = value;
  20911. return this;
  20912. },
  20913. setPath: function setPath(path) {
  20914. this.path = path;
  20915. return this;
  20916. },
  20917. setResourcePath: function setResourcePath(resourcePath) {
  20918. this.resourcePath = resourcePath;
  20919. return this;
  20920. },
  20921. setRequestHeader: function setRequestHeader(requestHeader) {
  20922. this.requestHeader = requestHeader;
  20923. return this;
  20924. }
  20925. });
  20926. var loading = {};
  20927. function FileLoader(manager) {
  20928. Loader.call(this, manager);
  20929. }
  20930. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  20931. constructor: FileLoader,
  20932. load: function load(url, onLoad, onProgress, onError) {
  20933. if (url === undefined) url = '';
  20934. if (this.path !== undefined) url = this.path + url;
  20935. url = this.manager.resolveURL(url);
  20936. var scope = this;
  20937. var cached = Cache.get(url);
  20938. if (cached !== undefined) {
  20939. scope.manager.itemStart(url);
  20940. setTimeout(function () {
  20941. if (onLoad) onLoad(cached);
  20942. scope.manager.itemEnd(url);
  20943. }, 0);
  20944. return cached;
  20945. } // Check if request is duplicate
  20946. if (loading[url] !== undefined) {
  20947. loading[url].push({
  20948. onLoad: onLoad,
  20949. onProgress: onProgress,
  20950. onError: onError
  20951. });
  20952. return;
  20953. } // Check for data: URI
  20954. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  20955. var dataUriRegexResult = url.match(dataUriRegex);
  20956. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  20957. if (dataUriRegexResult) {
  20958. var mimeType = dataUriRegexResult[1];
  20959. var isBase64 = !!dataUriRegexResult[2];
  20960. var data = dataUriRegexResult[3];
  20961. data = decodeURIComponent(data);
  20962. if (isBase64) data = atob(data);
  20963. try {
  20964. var response;
  20965. var responseType = (this.responseType || '').toLowerCase();
  20966. switch (responseType) {
  20967. case 'arraybuffer':
  20968. case 'blob':
  20969. var view = new Uint8Array(data.length);
  20970. for (var i = 0; i < data.length; i++) {
  20971. view[i] = data.charCodeAt(i);
  20972. }
  20973. if (responseType === 'blob') {
  20974. response = new Blob([view.buffer], {
  20975. type: mimeType
  20976. });
  20977. } else {
  20978. response = view.buffer;
  20979. }
  20980. break;
  20981. case 'document':
  20982. var parser = new DOMParser();
  20983. response = parser.parseFromString(data, mimeType);
  20984. break;
  20985. case 'json':
  20986. response = JSON.parse(data);
  20987. break;
  20988. default:
  20989. // 'text' or other
  20990. response = data;
  20991. break;
  20992. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20993. setTimeout(function () {
  20994. if (onLoad) onLoad(response);
  20995. scope.manager.itemEnd(url);
  20996. }, 0);
  20997. } catch (error) {
  20998. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20999. setTimeout(function () {
  21000. if (onError) onError(error);
  21001. scope.manager.itemError(url);
  21002. scope.manager.itemEnd(url);
  21003. }, 0);
  21004. }
  21005. } else {
  21006. // Initialise array for duplicate requests
  21007. loading[url] = [];
  21008. loading[url].push({
  21009. onLoad: onLoad,
  21010. onProgress: onProgress,
  21011. onError: onError
  21012. });
  21013. request = new XMLHttpRequest();
  21014. request.open('GET', url, true);
  21015. request.addEventListener('load', function (event) {
  21016. var response = this.response;
  21017. var callbacks = loading[url];
  21018. delete loading[url];
  21019. if (this.status === 200 || this.status === 0) {
  21020. // Some browsers return HTTP Status 0 when using non-http protocol
  21021. // e.g. 'file://' or 'data://'. Handle as success.
  21022. 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
  21023. // error response bodies as proper responses to requests.
  21024. Cache.add(url, response);
  21025. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  21026. var callback = callbacks[_i];
  21027. if (callback.onLoad) callback.onLoad(response);
  21028. }
  21029. scope.manager.itemEnd(url);
  21030. } else {
  21031. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  21032. var _callback = callbacks[_i2];
  21033. if (_callback.onError) _callback.onError(event);
  21034. }
  21035. scope.manager.itemError(url);
  21036. scope.manager.itemEnd(url);
  21037. }
  21038. }, false);
  21039. request.addEventListener('progress', function (event) {
  21040. var callbacks = loading[url];
  21041. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  21042. var callback = callbacks[_i3];
  21043. if (callback.onProgress) callback.onProgress(event);
  21044. }
  21045. }, false);
  21046. request.addEventListener('error', function (event) {
  21047. var callbacks = loading[url];
  21048. delete loading[url];
  21049. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  21050. var callback = callbacks[_i4];
  21051. if (callback.onError) callback.onError(event);
  21052. }
  21053. scope.manager.itemError(url);
  21054. scope.manager.itemEnd(url);
  21055. }, false);
  21056. request.addEventListener('abort', function (event) {
  21057. var callbacks = loading[url];
  21058. delete loading[url];
  21059. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  21060. var callback = callbacks[_i5];
  21061. if (callback.onError) callback.onError(event);
  21062. }
  21063. scope.manager.itemError(url);
  21064. scope.manager.itemEnd(url);
  21065. }, false);
  21066. if (this.responseType !== undefined) request.responseType = this.responseType;
  21067. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  21068. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  21069. for (var header in this.requestHeader) {
  21070. request.setRequestHeader(header, this.requestHeader[header]);
  21071. }
  21072. request.send(null);
  21073. }
  21074. scope.manager.itemStart(url);
  21075. return request;
  21076. },
  21077. setResponseType: function setResponseType(value) {
  21078. this.responseType = value;
  21079. return this;
  21080. },
  21081. setMimeType: function setMimeType(value) {
  21082. this.mimeType = value;
  21083. return this;
  21084. }
  21085. });
  21086. function AnimationLoader(manager) {
  21087. Loader.call(this, manager);
  21088. }
  21089. AnimationLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21090. constructor: AnimationLoader,
  21091. load: function load(url, onLoad, onProgress, onError) {
  21092. var scope = this;
  21093. var loader = new FileLoader(scope.manager);
  21094. loader.setPath(scope.path);
  21095. loader.setRequestHeader(scope.requestHeader);
  21096. loader.setWithCredentials(scope.withCredentials);
  21097. loader.load(url, function (text) {
  21098. try {
  21099. onLoad(scope.parse(JSON.parse(text)));
  21100. } catch (e) {
  21101. if (onError) {
  21102. onError(e);
  21103. } else {
  21104. console.error(e);
  21105. }
  21106. scope.manager.itemError(url);
  21107. }
  21108. }, onProgress, onError);
  21109. },
  21110. parse: function parse(json) {
  21111. var animations = [];
  21112. for (var i = 0; i < json.length; i++) {
  21113. var clip = AnimationClip.parse(json[i]);
  21114. animations.push(clip);
  21115. }
  21116. return animations;
  21117. }
  21118. });
  21119. /**
  21120. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21121. *
  21122. * Sub classes have to implement the parse() method which will be used in load().
  21123. */
  21124. function CompressedTextureLoader(manager) {
  21125. Loader.call(this, manager);
  21126. }
  21127. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21128. constructor: CompressedTextureLoader,
  21129. load: function load(url, onLoad, onProgress, onError) {
  21130. var scope = this;
  21131. var images = [];
  21132. var texture = new CompressedTexture();
  21133. var loader = new FileLoader(this.manager);
  21134. loader.setPath(this.path);
  21135. loader.setResponseType('arraybuffer');
  21136. loader.setRequestHeader(this.requestHeader);
  21137. loader.setWithCredentials(scope.withCredentials);
  21138. var loaded = 0;
  21139. function loadTexture(i) {
  21140. loader.load(url[i], function (buffer) {
  21141. var texDatas = scope.parse(buffer, true);
  21142. images[i] = {
  21143. width: texDatas.width,
  21144. height: texDatas.height,
  21145. format: texDatas.format,
  21146. mipmaps: texDatas.mipmaps
  21147. };
  21148. loaded += 1;
  21149. if (loaded === 6) {
  21150. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  21151. texture.image = images;
  21152. texture.format = texDatas.format;
  21153. texture.needsUpdate = true;
  21154. if (onLoad) onLoad(texture);
  21155. }
  21156. }, onProgress, onError);
  21157. }
  21158. if (Array.isArray(url)) {
  21159. for (var i = 0, il = url.length; i < il; ++i) {
  21160. loadTexture(i);
  21161. }
  21162. } else {
  21163. // compressed cubemap texture stored in a single DDS file
  21164. loader.load(url, function (buffer) {
  21165. var texDatas = scope.parse(buffer, true);
  21166. if (texDatas.isCubemap) {
  21167. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21168. for (var f = 0; f < faces; f++) {
  21169. images[f] = {
  21170. mipmaps: []
  21171. };
  21172. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  21173. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  21174. images[f].format = texDatas.format;
  21175. images[f].width = texDatas.width;
  21176. images[f].height = texDatas.height;
  21177. }
  21178. }
  21179. texture.image = images;
  21180. } else {
  21181. texture.image.width = texDatas.width;
  21182. texture.image.height = texDatas.height;
  21183. texture.mipmaps = texDatas.mipmaps;
  21184. }
  21185. if (texDatas.mipmapCount === 1) {
  21186. texture.minFilter = LinearFilter;
  21187. }
  21188. texture.format = texDatas.format;
  21189. texture.needsUpdate = true;
  21190. if (onLoad) onLoad(texture);
  21191. }, onProgress, onError);
  21192. }
  21193. return texture;
  21194. }
  21195. });
  21196. function ImageLoader(manager) {
  21197. Loader.call(this, manager);
  21198. }
  21199. ImageLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21200. constructor: ImageLoader,
  21201. load: function load(url, onLoad, onProgress, onError) {
  21202. if (this.path !== undefined) url = this.path + url;
  21203. url = this.manager.resolveURL(url);
  21204. var scope = this;
  21205. var cached = Cache.get(url);
  21206. if (cached !== undefined) {
  21207. scope.manager.itemStart(url);
  21208. setTimeout(function () {
  21209. if (onLoad) onLoad(cached);
  21210. scope.manager.itemEnd(url);
  21211. }, 0);
  21212. return cached;
  21213. }
  21214. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  21215. function onImageLoad() {
  21216. image.removeEventListener('load', onImageLoad, false);
  21217. image.removeEventListener('error', onImageError, false);
  21218. Cache.add(url, this);
  21219. if (onLoad) onLoad(this);
  21220. scope.manager.itemEnd(url);
  21221. }
  21222. function onImageError(event) {
  21223. image.removeEventListener('load', onImageLoad, false);
  21224. image.removeEventListener('error', onImageError, false);
  21225. if (onError) onError(event);
  21226. scope.manager.itemError(url);
  21227. scope.manager.itemEnd(url);
  21228. }
  21229. image.addEventListener('load', onImageLoad, false);
  21230. image.addEventListener('error', onImageError, false);
  21231. if (url.substr(0, 5) !== 'data:') {
  21232. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  21233. }
  21234. scope.manager.itemStart(url);
  21235. image.src = url;
  21236. return image;
  21237. }
  21238. });
  21239. function CubeTextureLoader(manager) {
  21240. Loader.call(this, manager);
  21241. }
  21242. CubeTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21243. constructor: CubeTextureLoader,
  21244. load: function load(urls, onLoad, onProgress, onError) {
  21245. var texture = new CubeTexture();
  21246. var loader = new ImageLoader(this.manager);
  21247. loader.setCrossOrigin(this.crossOrigin);
  21248. loader.setPath(this.path);
  21249. var loaded = 0;
  21250. function loadTexture(i) {
  21251. loader.load(urls[i], function (image) {
  21252. texture.images[i] = image;
  21253. loaded++;
  21254. if (loaded === 6) {
  21255. texture.needsUpdate = true;
  21256. if (onLoad) onLoad(texture);
  21257. }
  21258. }, undefined, onError);
  21259. }
  21260. for (var i = 0; i < urls.length; ++i) {
  21261. loadTexture(i);
  21262. }
  21263. return texture;
  21264. }
  21265. });
  21266. /**
  21267. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  21268. *
  21269. * Sub classes have to implement the parse() method which will be used in load().
  21270. */
  21271. function DataTextureLoader(manager) {
  21272. Loader.call(this, manager);
  21273. }
  21274. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21275. constructor: DataTextureLoader,
  21276. load: function load(url, onLoad, onProgress, onError) {
  21277. var scope = this;
  21278. var texture = new DataTexture();
  21279. var loader = new FileLoader(this.manager);
  21280. loader.setResponseType('arraybuffer');
  21281. loader.setRequestHeader(this.requestHeader);
  21282. loader.setPath(this.path);
  21283. loader.setWithCredentials(scope.withCredentials);
  21284. loader.load(url, function (buffer) {
  21285. var texData = scope.parse(buffer);
  21286. if (!texData) return;
  21287. if (texData.image !== undefined) {
  21288. texture.image = texData.image;
  21289. } else if (texData.data !== undefined) {
  21290. texture.image.width = texData.width;
  21291. texture.image.height = texData.height;
  21292. texture.image.data = texData.data;
  21293. }
  21294. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  21295. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  21296. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  21297. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  21298. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  21299. if (texData.format !== undefined) {
  21300. texture.format = texData.format;
  21301. }
  21302. if (texData.type !== undefined) {
  21303. texture.type = texData.type;
  21304. }
  21305. if (texData.mipmaps !== undefined) {
  21306. texture.mipmaps = texData.mipmaps;
  21307. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  21308. }
  21309. if (texData.mipmapCount === 1) {
  21310. texture.minFilter = LinearFilter;
  21311. }
  21312. texture.needsUpdate = true;
  21313. if (onLoad) onLoad(texture, texData);
  21314. }, onProgress, onError);
  21315. return texture;
  21316. }
  21317. });
  21318. function TextureLoader(manager) {
  21319. Loader.call(this, manager);
  21320. }
  21321. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21322. constructor: TextureLoader,
  21323. load: function load(url, onLoad, onProgress, onError) {
  21324. var texture = new Texture();
  21325. var loader = new ImageLoader(this.manager);
  21326. loader.setCrossOrigin(this.crossOrigin);
  21327. loader.setPath(this.path);
  21328. loader.load(url, function (image) {
  21329. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  21330. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  21331. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  21332. texture.needsUpdate = true;
  21333. if (onLoad !== undefined) {
  21334. onLoad(texture);
  21335. }
  21336. }, onProgress, onError);
  21337. return texture;
  21338. }
  21339. });
  21340. /**
  21341. * Extensible curve object.
  21342. *
  21343. * Some common of curve methods:
  21344. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  21345. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  21346. * .getPoints(), .getSpacedPoints()
  21347. * .getLength()
  21348. * .updateArcLengths()
  21349. *
  21350. * This following curves inherit from THREE.Curve:
  21351. *
  21352. * -- 2D curves --
  21353. * THREE.ArcCurve
  21354. * THREE.CubicBezierCurve
  21355. * THREE.EllipseCurve
  21356. * THREE.LineCurve
  21357. * THREE.QuadraticBezierCurve
  21358. * THREE.SplineCurve
  21359. *
  21360. * -- 3D curves --
  21361. * THREE.CatmullRomCurve3
  21362. * THREE.CubicBezierCurve3
  21363. * THREE.LineCurve3
  21364. * THREE.QuadraticBezierCurve3
  21365. *
  21366. * A series of curves can be represented as a THREE.CurvePath.
  21367. *
  21368. **/
  21369. function Curve() {
  21370. this.type = 'Curve';
  21371. this.arcLengthDivisions = 200;
  21372. }
  21373. Object.assign(Curve.prototype, {
  21374. // Virtual base class method to overwrite and implement in subclasses
  21375. // - t [0 .. 1]
  21376. getPoint: function getPoint()
  21377. /* t, optionalTarget */
  21378. {
  21379. console.warn('THREE.Curve: .getPoint() not implemented.');
  21380. return null;
  21381. },
  21382. // Get point at relative position in curve according to arc length
  21383. // - u [0 .. 1]
  21384. getPointAt: function getPointAt(u, optionalTarget) {
  21385. var t = this.getUtoTmapping(u);
  21386. return this.getPoint(t, optionalTarget);
  21387. },
  21388. // Get sequence of points using getPoint( t )
  21389. getPoints: function getPoints(divisions) {
  21390. if (divisions === void 0) {
  21391. divisions = 5;
  21392. }
  21393. var points = [];
  21394. for (var d = 0; d <= divisions; d++) {
  21395. points.push(this.getPoint(d / divisions));
  21396. }
  21397. return points;
  21398. },
  21399. // Get sequence of points using getPointAt( u )
  21400. getSpacedPoints: function getSpacedPoints(divisions) {
  21401. if (divisions === void 0) {
  21402. divisions = 5;
  21403. }
  21404. var points = [];
  21405. for (var d = 0; d <= divisions; d++) {
  21406. points.push(this.getPointAt(d / divisions));
  21407. }
  21408. return points;
  21409. },
  21410. // Get total curve arc length
  21411. getLength: function getLength() {
  21412. var lengths = this.getLengths();
  21413. return lengths[lengths.length - 1];
  21414. },
  21415. // Get list of cumulative segment lengths
  21416. getLengths: function getLengths(divisions) {
  21417. if (divisions === undefined) divisions = this.arcLengthDivisions;
  21418. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  21419. return this.cacheArcLengths;
  21420. }
  21421. this.needsUpdate = false;
  21422. var cache = [];
  21423. var current,
  21424. last = this.getPoint(0);
  21425. var sum = 0;
  21426. cache.push(0);
  21427. for (var p = 1; p <= divisions; p++) {
  21428. current = this.getPoint(p / divisions);
  21429. sum += current.distanceTo(last);
  21430. cache.push(sum);
  21431. last = current;
  21432. }
  21433. this.cacheArcLengths = cache;
  21434. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  21435. },
  21436. updateArcLengths: function updateArcLengths() {
  21437. this.needsUpdate = true;
  21438. this.getLengths();
  21439. },
  21440. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  21441. getUtoTmapping: function getUtoTmapping(u, distance) {
  21442. var arcLengths = this.getLengths();
  21443. var i = 0;
  21444. var il = arcLengths.length;
  21445. var targetArcLength; // The targeted u distance value to get
  21446. if (distance) {
  21447. targetArcLength = distance;
  21448. } else {
  21449. targetArcLength = u * arcLengths[il - 1];
  21450. } // binary search for the index with largest value smaller than target u distance
  21451. var low = 0,
  21452. high = il - 1,
  21453. comparison;
  21454. while (low <= high) {
  21455. 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
  21456. comparison = arcLengths[i] - targetArcLength;
  21457. if (comparison < 0) {
  21458. low = i + 1;
  21459. } else if (comparison > 0) {
  21460. high = i - 1;
  21461. } else {
  21462. high = i;
  21463. break; // DONE
  21464. }
  21465. }
  21466. i = high;
  21467. if (arcLengths[i] === targetArcLength) {
  21468. return i / (il - 1);
  21469. } // we could get finer grain at lengths, or use simple interpolation between two points
  21470. var lengthBefore = arcLengths[i];
  21471. var lengthAfter = arcLengths[i + 1];
  21472. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  21473. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  21474. var t = (i + segmentFraction) / (il - 1);
  21475. return t;
  21476. },
  21477. // Returns a unit vector tangent at t
  21478. // In case any sub curve does not implement its tangent derivation,
  21479. // 2 points a small delta apart will be used to find its gradient
  21480. // which seems to give a reasonable approximation
  21481. getTangent: function getTangent(t, optionalTarget) {
  21482. var delta = 0.0001;
  21483. var t1 = t - delta;
  21484. var t2 = t + delta; // Capping in case of danger
  21485. if (t1 < 0) t1 = 0;
  21486. if (t2 > 1) t2 = 1;
  21487. var pt1 = this.getPoint(t1);
  21488. var pt2 = this.getPoint(t2);
  21489. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  21490. tangent.copy(pt2).sub(pt1).normalize();
  21491. return tangent;
  21492. },
  21493. getTangentAt: function getTangentAt(u, optionalTarget) {
  21494. var t = this.getUtoTmapping(u);
  21495. return this.getTangent(t, optionalTarget);
  21496. },
  21497. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  21498. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  21499. var normal = new Vector3();
  21500. var tangents = [];
  21501. var normals = [];
  21502. var binormals = [];
  21503. var vec = new Vector3();
  21504. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  21505. for (var i = 0; i <= segments; i++) {
  21506. var u = i / segments;
  21507. tangents[i] = this.getTangentAt(u, new Vector3());
  21508. tangents[i].normalize();
  21509. } // select an initial normal vector perpendicular to the first tangent vector,
  21510. // and in the direction of the minimum tangent xyz component
  21511. normals[0] = new Vector3();
  21512. binormals[0] = new Vector3();
  21513. var min = Number.MAX_VALUE;
  21514. var tx = Math.abs(tangents[0].x);
  21515. var ty = Math.abs(tangents[0].y);
  21516. var tz = Math.abs(tangents[0].z);
  21517. if (tx <= min) {
  21518. min = tx;
  21519. normal.set(1, 0, 0);
  21520. }
  21521. if (ty <= min) {
  21522. min = ty;
  21523. normal.set(0, 1, 0);
  21524. }
  21525. if (tz <= min) {
  21526. normal.set(0, 0, 1);
  21527. }
  21528. vec.crossVectors(tangents[0], normal).normalize();
  21529. normals[0].crossVectors(tangents[0], vec);
  21530. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  21531. for (var _i = 1; _i <= segments; _i++) {
  21532. normals[_i] = normals[_i - 1].clone();
  21533. binormals[_i] = binormals[_i - 1].clone();
  21534. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  21535. if (vec.length() > Number.EPSILON) {
  21536. vec.normalize();
  21537. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  21538. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  21539. }
  21540. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  21541. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  21542. if (closed === true) {
  21543. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  21544. _theta /= segments;
  21545. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  21546. _theta = -_theta;
  21547. }
  21548. for (var _i2 = 1; _i2 <= segments; _i2++) {
  21549. // twist a little...
  21550. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  21551. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  21552. }
  21553. }
  21554. return {
  21555. tangents: tangents,
  21556. normals: normals,
  21557. binormals: binormals
  21558. };
  21559. },
  21560. clone: function clone() {
  21561. return new this.constructor().copy(this);
  21562. },
  21563. copy: function copy(source) {
  21564. this.arcLengthDivisions = source.arcLengthDivisions;
  21565. return this;
  21566. },
  21567. toJSON: function toJSON() {
  21568. var data = {
  21569. metadata: {
  21570. version: 4.5,
  21571. type: 'Curve',
  21572. generator: 'Curve.toJSON'
  21573. }
  21574. };
  21575. data.arcLengthDivisions = this.arcLengthDivisions;
  21576. data.type = this.type;
  21577. return data;
  21578. },
  21579. fromJSON: function fromJSON(json) {
  21580. this.arcLengthDivisions = json.arcLengthDivisions;
  21581. return this;
  21582. }
  21583. });
  21584. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  21585. Curve.call(this);
  21586. this.type = 'EllipseCurve';
  21587. this.aX = aX || 0;
  21588. this.aY = aY || 0;
  21589. this.xRadius = xRadius || 1;
  21590. this.yRadius = yRadius || 1;
  21591. this.aStartAngle = aStartAngle || 0;
  21592. this.aEndAngle = aEndAngle || 2 * Math.PI;
  21593. this.aClockwise = aClockwise || false;
  21594. this.aRotation = aRotation || 0;
  21595. }
  21596. EllipseCurve.prototype = Object.create(Curve.prototype);
  21597. EllipseCurve.prototype.constructor = EllipseCurve;
  21598. EllipseCurve.prototype.isEllipseCurve = true;
  21599. EllipseCurve.prototype.getPoint = function (t, optionalTarget) {
  21600. var point = optionalTarget || new Vector2();
  21601. var twoPi = Math.PI * 2;
  21602. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21603. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  21604. while (deltaAngle < 0) {
  21605. deltaAngle += twoPi;
  21606. }
  21607. while (deltaAngle > twoPi) {
  21608. deltaAngle -= twoPi;
  21609. }
  21610. if (deltaAngle < Number.EPSILON) {
  21611. if (samePoints) {
  21612. deltaAngle = 0;
  21613. } else {
  21614. deltaAngle = twoPi;
  21615. }
  21616. }
  21617. if (this.aClockwise === true && !samePoints) {
  21618. if (deltaAngle === twoPi) {
  21619. deltaAngle = -twoPi;
  21620. } else {
  21621. deltaAngle = deltaAngle - twoPi;
  21622. }
  21623. }
  21624. var angle = this.aStartAngle + t * deltaAngle;
  21625. var x = this.aX + this.xRadius * Math.cos(angle);
  21626. var y = this.aY + this.yRadius * Math.sin(angle);
  21627. if (this.aRotation !== 0) {
  21628. var cos = Math.cos(this.aRotation);
  21629. var sin = Math.sin(this.aRotation);
  21630. var tx = x - this.aX;
  21631. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  21632. x = tx * cos - ty * sin + this.aX;
  21633. y = tx * sin + ty * cos + this.aY;
  21634. }
  21635. return point.set(x, y);
  21636. };
  21637. EllipseCurve.prototype.copy = function (source) {
  21638. Curve.prototype.copy.call(this, source);
  21639. this.aX = source.aX;
  21640. this.aY = source.aY;
  21641. this.xRadius = source.xRadius;
  21642. this.yRadius = source.yRadius;
  21643. this.aStartAngle = source.aStartAngle;
  21644. this.aEndAngle = source.aEndAngle;
  21645. this.aClockwise = source.aClockwise;
  21646. this.aRotation = source.aRotation;
  21647. return this;
  21648. };
  21649. EllipseCurve.prototype.toJSON = function () {
  21650. var data = Curve.prototype.toJSON.call(this);
  21651. data.aX = this.aX;
  21652. data.aY = this.aY;
  21653. data.xRadius = this.xRadius;
  21654. data.yRadius = this.yRadius;
  21655. data.aStartAngle = this.aStartAngle;
  21656. data.aEndAngle = this.aEndAngle;
  21657. data.aClockwise = this.aClockwise;
  21658. data.aRotation = this.aRotation;
  21659. return data;
  21660. };
  21661. EllipseCurve.prototype.fromJSON = function (json) {
  21662. Curve.prototype.fromJSON.call(this, json);
  21663. this.aX = json.aX;
  21664. this.aY = json.aY;
  21665. this.xRadius = json.xRadius;
  21666. this.yRadius = json.yRadius;
  21667. this.aStartAngle = json.aStartAngle;
  21668. this.aEndAngle = json.aEndAngle;
  21669. this.aClockwise = json.aClockwise;
  21670. this.aRotation = json.aRotation;
  21671. return this;
  21672. };
  21673. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  21674. EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  21675. this.type = 'ArcCurve';
  21676. }
  21677. ArcCurve.prototype = Object.create(EllipseCurve.prototype);
  21678. ArcCurve.prototype.constructor = ArcCurve;
  21679. ArcCurve.prototype.isArcCurve = true;
  21680. /**
  21681. * Centripetal CatmullRom Curve - which is useful for avoiding
  21682. * cusps and self-intersections in non-uniform catmull rom curves.
  21683. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21684. *
  21685. * curve.type accepts centripetal(default), chordal and catmullrom
  21686. * curve.tension is used for catmullrom which defaults to 0.5
  21687. */
  21688. /*
  21689. Based on an optimized c++ solution in
  21690. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21691. - http://ideone.com/NoEbVM
  21692. This CubicPoly class could be used for reusing some variables and calculations,
  21693. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21694. which can be placed in CurveUtils.
  21695. */
  21696. function CubicPoly() {
  21697. var c0 = 0,
  21698. c1 = 0,
  21699. c2 = 0,
  21700. c3 = 0;
  21701. /*
  21702. * Compute coefficients for a cubic polynomial
  21703. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21704. * such that
  21705. * p(0) = x0, p(1) = x1
  21706. * and
  21707. * p'(0) = t0, p'(1) = t1.
  21708. */
  21709. function init(x0, x1, t0, t1) {
  21710. c0 = x0;
  21711. c1 = t0;
  21712. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  21713. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21714. }
  21715. return {
  21716. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  21717. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  21718. },
  21719. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  21720. // compute tangents when parameterized in [t1,t2]
  21721. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  21722. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  21723. t1 *= dt1;
  21724. t2 *= dt1;
  21725. init(x1, x2, t1, t2);
  21726. },
  21727. calc: function calc(t) {
  21728. var t2 = t * t;
  21729. var t3 = t2 * t;
  21730. return c0 + c1 * t + c2 * t2 + c3 * t3;
  21731. }
  21732. };
  21733. } //
  21734. var tmp = new Vector3();
  21735. var px = new CubicPoly(),
  21736. py = new CubicPoly(),
  21737. pz = new CubicPoly();
  21738. function CatmullRomCurve3(points, closed, curveType, tension) {
  21739. if (points === void 0) {
  21740. points = [];
  21741. }
  21742. if (closed === void 0) {
  21743. closed = false;
  21744. }
  21745. if (curveType === void 0) {
  21746. curveType = 'centripetal';
  21747. }
  21748. if (tension === void 0) {
  21749. tension = 0.5;
  21750. }
  21751. Curve.call(this);
  21752. this.type = 'CatmullRomCurve3';
  21753. this.points = points;
  21754. this.closed = closed;
  21755. this.curveType = curveType;
  21756. this.tension = tension;
  21757. }
  21758. CatmullRomCurve3.prototype = Object.create(Curve.prototype);
  21759. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  21760. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  21761. CatmullRomCurve3.prototype.getPoint = function (t, optionalTarget) {
  21762. if (optionalTarget === void 0) {
  21763. optionalTarget = new Vector3();
  21764. }
  21765. var point = optionalTarget;
  21766. var points = this.points;
  21767. var l = points.length;
  21768. var p = (l - (this.closed ? 0 : 1)) * t;
  21769. var intPoint = Math.floor(p);
  21770. var weight = p - intPoint;
  21771. if (this.closed) {
  21772. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  21773. } else if (weight === 0 && intPoint === l - 1) {
  21774. intPoint = l - 2;
  21775. weight = 1;
  21776. }
  21777. var p0, p3; // 4 points (p1 & p2 defined below)
  21778. if (this.closed || intPoint > 0) {
  21779. p0 = points[(intPoint - 1) % l];
  21780. } else {
  21781. // extrapolate first point
  21782. tmp.subVectors(points[0], points[1]).add(points[0]);
  21783. p0 = tmp;
  21784. }
  21785. var p1 = points[intPoint % l];
  21786. var p2 = points[(intPoint + 1) % l];
  21787. if (this.closed || intPoint + 2 < l) {
  21788. p3 = points[(intPoint + 2) % l];
  21789. } else {
  21790. // extrapolate last point
  21791. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  21792. p3 = tmp;
  21793. }
  21794. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  21795. // init Centripetal / Chordal Catmull-Rom
  21796. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  21797. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  21798. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  21799. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  21800. if (dt1 < 1e-4) dt1 = 1.0;
  21801. if (dt0 < 1e-4) dt0 = dt1;
  21802. if (dt2 < 1e-4) dt2 = dt1;
  21803. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  21804. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  21805. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  21806. } else if (this.curveType === 'catmullrom') {
  21807. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  21808. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  21809. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  21810. }
  21811. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  21812. return point;
  21813. };
  21814. CatmullRomCurve3.prototype.copy = function (source) {
  21815. Curve.prototype.copy.call(this, source);
  21816. this.points = [];
  21817. for (var i = 0, l = source.points.length; i < l; i++) {
  21818. var point = source.points[i];
  21819. this.points.push(point.clone());
  21820. }
  21821. this.closed = source.closed;
  21822. this.curveType = source.curveType;
  21823. this.tension = source.tension;
  21824. return this;
  21825. };
  21826. CatmullRomCurve3.prototype.toJSON = function () {
  21827. var data = Curve.prototype.toJSON.call(this);
  21828. data.points = [];
  21829. for (var i = 0, l = this.points.length; i < l; i++) {
  21830. var point = this.points[i];
  21831. data.points.push(point.toArray());
  21832. }
  21833. data.closed = this.closed;
  21834. data.curveType = this.curveType;
  21835. data.tension = this.tension;
  21836. return data;
  21837. };
  21838. CatmullRomCurve3.prototype.fromJSON = function (json) {
  21839. Curve.prototype.fromJSON.call(this, json);
  21840. this.points = [];
  21841. for (var i = 0, l = json.points.length; i < l; i++) {
  21842. var point = json.points[i];
  21843. this.points.push(new Vector3().fromArray(point));
  21844. }
  21845. this.closed = json.closed;
  21846. this.curveType = json.curveType;
  21847. this.tension = json.tension;
  21848. return this;
  21849. };
  21850. /**
  21851. * Bezier Curves formulas obtained from
  21852. * http://en.wikipedia.org/wiki/Bézier_curve
  21853. */
  21854. function CatmullRom(t, p0, p1, p2, p3) {
  21855. var v0 = (p2 - p0) * 0.5;
  21856. var v1 = (p3 - p1) * 0.5;
  21857. var t2 = t * t;
  21858. var t3 = t * t2;
  21859. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  21860. } //
  21861. function QuadraticBezierP0(t, p) {
  21862. var k = 1 - t;
  21863. return k * k * p;
  21864. }
  21865. function QuadraticBezierP1(t, p) {
  21866. return 2 * (1 - t) * t * p;
  21867. }
  21868. function QuadraticBezierP2(t, p) {
  21869. return t * t * p;
  21870. }
  21871. function QuadraticBezier(t, p0, p1, p2) {
  21872. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  21873. } //
  21874. function CubicBezierP0(t, p) {
  21875. var k = 1 - t;
  21876. return k * k * k * p;
  21877. }
  21878. function CubicBezierP1(t, p) {
  21879. var k = 1 - t;
  21880. return 3 * k * k * t * p;
  21881. }
  21882. function CubicBezierP2(t, p) {
  21883. return 3 * (1 - t) * t * t * p;
  21884. }
  21885. function CubicBezierP3(t, p) {
  21886. return t * t * t * p;
  21887. }
  21888. function CubicBezier(t, p0, p1, p2, p3) {
  21889. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  21890. }
  21891. function CubicBezierCurve(v0, v1, v2, v3) {
  21892. if (v0 === void 0) {
  21893. v0 = new Vector2();
  21894. }
  21895. if (v1 === void 0) {
  21896. v1 = new Vector2();
  21897. }
  21898. if (v2 === void 0) {
  21899. v2 = new Vector2();
  21900. }
  21901. if (v3 === void 0) {
  21902. v3 = new Vector2();
  21903. }
  21904. Curve.call(this);
  21905. this.type = 'CubicBezierCurve';
  21906. this.v0 = v0;
  21907. this.v1 = v1;
  21908. this.v2 = v2;
  21909. this.v3 = v3;
  21910. }
  21911. CubicBezierCurve.prototype = Object.create(Curve.prototype);
  21912. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  21913. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  21914. CubicBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  21915. if (optionalTarget === void 0) {
  21916. optionalTarget = new Vector2();
  21917. }
  21918. var point = optionalTarget;
  21919. var v0 = this.v0,
  21920. v1 = this.v1,
  21921. v2 = this.v2,
  21922. v3 = this.v3;
  21923. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  21924. return point;
  21925. };
  21926. CubicBezierCurve.prototype.copy = function (source) {
  21927. Curve.prototype.copy.call(this, source);
  21928. this.v0.copy(source.v0);
  21929. this.v1.copy(source.v1);
  21930. this.v2.copy(source.v2);
  21931. this.v3.copy(source.v3);
  21932. return this;
  21933. };
  21934. CubicBezierCurve.prototype.toJSON = function () {
  21935. var data = Curve.prototype.toJSON.call(this);
  21936. data.v0 = this.v0.toArray();
  21937. data.v1 = this.v1.toArray();
  21938. data.v2 = this.v2.toArray();
  21939. data.v3 = this.v3.toArray();
  21940. return data;
  21941. };
  21942. CubicBezierCurve.prototype.fromJSON = function (json) {
  21943. Curve.prototype.fromJSON.call(this, json);
  21944. this.v0.fromArray(json.v0);
  21945. this.v1.fromArray(json.v1);
  21946. this.v2.fromArray(json.v2);
  21947. this.v3.fromArray(json.v3);
  21948. return this;
  21949. };
  21950. function CubicBezierCurve3(v0, v1, v2, v3) {
  21951. if (v0 === void 0) {
  21952. v0 = new Vector3();
  21953. }
  21954. if (v1 === void 0) {
  21955. v1 = new Vector3();
  21956. }
  21957. if (v2 === void 0) {
  21958. v2 = new Vector3();
  21959. }
  21960. if (v3 === void 0) {
  21961. v3 = new Vector3();
  21962. }
  21963. Curve.call(this);
  21964. this.type = 'CubicBezierCurve3';
  21965. this.v0 = v0;
  21966. this.v1 = v1;
  21967. this.v2 = v2;
  21968. this.v3 = v3;
  21969. }
  21970. CubicBezierCurve3.prototype = Object.create(Curve.prototype);
  21971. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  21972. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  21973. CubicBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  21974. if (optionalTarget === void 0) {
  21975. optionalTarget = new Vector3();
  21976. }
  21977. var point = optionalTarget;
  21978. var v0 = this.v0,
  21979. v1 = this.v1,
  21980. v2 = this.v2,
  21981. v3 = this.v3;
  21982. 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));
  21983. return point;
  21984. };
  21985. CubicBezierCurve3.prototype.copy = function (source) {
  21986. Curve.prototype.copy.call(this, source);
  21987. this.v0.copy(source.v0);
  21988. this.v1.copy(source.v1);
  21989. this.v2.copy(source.v2);
  21990. this.v3.copy(source.v3);
  21991. return this;
  21992. };
  21993. CubicBezierCurve3.prototype.toJSON = function () {
  21994. var data = Curve.prototype.toJSON.call(this);
  21995. data.v0 = this.v0.toArray();
  21996. data.v1 = this.v1.toArray();
  21997. data.v2 = this.v2.toArray();
  21998. data.v3 = this.v3.toArray();
  21999. return data;
  22000. };
  22001. CubicBezierCurve3.prototype.fromJSON = function (json) {
  22002. Curve.prototype.fromJSON.call(this, json);
  22003. this.v0.fromArray(json.v0);
  22004. this.v1.fromArray(json.v1);
  22005. this.v2.fromArray(json.v2);
  22006. this.v3.fromArray(json.v3);
  22007. return this;
  22008. };
  22009. function LineCurve(v1, v2) {
  22010. if (v1 === void 0) {
  22011. v1 = new Vector2();
  22012. }
  22013. if (v2 === void 0) {
  22014. v2 = new Vector2();
  22015. }
  22016. Curve.call(this);
  22017. this.type = 'LineCurve';
  22018. this.v1 = v1;
  22019. this.v2 = v2;
  22020. }
  22021. LineCurve.prototype = Object.create(Curve.prototype);
  22022. LineCurve.prototype.constructor = LineCurve;
  22023. LineCurve.prototype.isLineCurve = true;
  22024. LineCurve.prototype.getPoint = function (t, optionalTarget) {
  22025. if (optionalTarget === void 0) {
  22026. optionalTarget = new Vector2();
  22027. }
  22028. var point = optionalTarget;
  22029. if (t === 1) {
  22030. point.copy(this.v2);
  22031. } else {
  22032. point.copy(this.v2).sub(this.v1);
  22033. point.multiplyScalar(t).add(this.v1);
  22034. }
  22035. return point;
  22036. }; // Line curve is linear, so we can overwrite default getPointAt
  22037. LineCurve.prototype.getPointAt = function (u, optionalTarget) {
  22038. return this.getPoint(u, optionalTarget);
  22039. };
  22040. LineCurve.prototype.getTangent = function (t, optionalTarget) {
  22041. var tangent = optionalTarget || new Vector2();
  22042. tangent.copy(this.v2).sub(this.v1).normalize();
  22043. return tangent;
  22044. };
  22045. LineCurve.prototype.copy = function (source) {
  22046. Curve.prototype.copy.call(this, source);
  22047. this.v1.copy(source.v1);
  22048. this.v2.copy(source.v2);
  22049. return this;
  22050. };
  22051. LineCurve.prototype.toJSON = function () {
  22052. var data = Curve.prototype.toJSON.call(this);
  22053. data.v1 = this.v1.toArray();
  22054. data.v2 = this.v2.toArray();
  22055. return data;
  22056. };
  22057. LineCurve.prototype.fromJSON = function (json) {
  22058. Curve.prototype.fromJSON.call(this, json);
  22059. this.v1.fromArray(json.v1);
  22060. this.v2.fromArray(json.v2);
  22061. return this;
  22062. };
  22063. function LineCurve3(v1, v2) {
  22064. if (v1 === void 0) {
  22065. v1 = new Vector3();
  22066. }
  22067. if (v2 === void 0) {
  22068. v2 = new Vector3();
  22069. }
  22070. Curve.call(this);
  22071. this.type = 'LineCurve3';
  22072. this.v1 = v1;
  22073. this.v2 = v2;
  22074. }
  22075. LineCurve3.prototype = Object.create(Curve.prototype);
  22076. LineCurve3.prototype.constructor = LineCurve3;
  22077. LineCurve3.prototype.isLineCurve3 = true;
  22078. LineCurve3.prototype.getPoint = function (t, optionalTarget) {
  22079. if (optionalTarget === void 0) {
  22080. optionalTarget = new Vector3();
  22081. }
  22082. var point = optionalTarget;
  22083. if (t === 1) {
  22084. point.copy(this.v2);
  22085. } else {
  22086. point.copy(this.v2).sub(this.v1);
  22087. point.multiplyScalar(t).add(this.v1);
  22088. }
  22089. return point;
  22090. }; // Line curve is linear, so we can overwrite default getPointAt
  22091. LineCurve3.prototype.getPointAt = function (u, optionalTarget) {
  22092. return this.getPoint(u, optionalTarget);
  22093. };
  22094. LineCurve3.prototype.copy = function (source) {
  22095. Curve.prototype.copy.call(this, source);
  22096. this.v1.copy(source.v1);
  22097. this.v2.copy(source.v2);
  22098. return this;
  22099. };
  22100. LineCurve3.prototype.toJSON = function () {
  22101. var data = Curve.prototype.toJSON.call(this);
  22102. data.v1 = this.v1.toArray();
  22103. data.v2 = this.v2.toArray();
  22104. return data;
  22105. };
  22106. LineCurve3.prototype.fromJSON = function (json) {
  22107. Curve.prototype.fromJSON.call(this, json);
  22108. this.v1.fromArray(json.v1);
  22109. this.v2.fromArray(json.v2);
  22110. return this;
  22111. };
  22112. function QuadraticBezierCurve(v0, v1, v2) {
  22113. if (v0 === void 0) {
  22114. v0 = new Vector2();
  22115. }
  22116. if (v1 === void 0) {
  22117. v1 = new Vector2();
  22118. }
  22119. if (v2 === void 0) {
  22120. v2 = new Vector2();
  22121. }
  22122. Curve.call(this);
  22123. this.type = 'QuadraticBezierCurve';
  22124. this.v0 = v0;
  22125. this.v1 = v1;
  22126. this.v2 = v2;
  22127. }
  22128. QuadraticBezierCurve.prototype = Object.create(Curve.prototype);
  22129. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  22130. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22131. QuadraticBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22132. if (optionalTarget === void 0) {
  22133. optionalTarget = new Vector2();
  22134. }
  22135. var point = optionalTarget;
  22136. var v0 = this.v0,
  22137. v1 = this.v1,
  22138. v2 = this.v2;
  22139. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  22140. return point;
  22141. };
  22142. QuadraticBezierCurve.prototype.copy = function (source) {
  22143. Curve.prototype.copy.call(this, source);
  22144. this.v0.copy(source.v0);
  22145. this.v1.copy(source.v1);
  22146. this.v2.copy(source.v2);
  22147. return this;
  22148. };
  22149. QuadraticBezierCurve.prototype.toJSON = function () {
  22150. var data = Curve.prototype.toJSON.call(this);
  22151. data.v0 = this.v0.toArray();
  22152. data.v1 = this.v1.toArray();
  22153. data.v2 = this.v2.toArray();
  22154. return data;
  22155. };
  22156. QuadraticBezierCurve.prototype.fromJSON = function (json) {
  22157. Curve.prototype.fromJSON.call(this, json);
  22158. this.v0.fromArray(json.v0);
  22159. this.v1.fromArray(json.v1);
  22160. this.v2.fromArray(json.v2);
  22161. return this;
  22162. };
  22163. function QuadraticBezierCurve3(v0, v1, v2) {
  22164. if (v0 === void 0) {
  22165. v0 = new Vector3();
  22166. }
  22167. if (v1 === void 0) {
  22168. v1 = new Vector3();
  22169. }
  22170. if (v2 === void 0) {
  22171. v2 = new Vector3();
  22172. }
  22173. Curve.call(this);
  22174. this.type = 'QuadraticBezierCurve3';
  22175. this.v0 = v0;
  22176. this.v1 = v1;
  22177. this.v2 = v2;
  22178. }
  22179. QuadraticBezierCurve3.prototype = Object.create(Curve.prototype);
  22180. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22181. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22182. QuadraticBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22183. if (optionalTarget === void 0) {
  22184. optionalTarget = new Vector3();
  22185. }
  22186. var point = optionalTarget;
  22187. var v0 = this.v0,
  22188. v1 = this.v1,
  22189. v2 = this.v2;
  22190. 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));
  22191. return point;
  22192. };
  22193. QuadraticBezierCurve3.prototype.copy = function (source) {
  22194. Curve.prototype.copy.call(this, source);
  22195. this.v0.copy(source.v0);
  22196. this.v1.copy(source.v1);
  22197. this.v2.copy(source.v2);
  22198. return this;
  22199. };
  22200. QuadraticBezierCurve3.prototype.toJSON = function () {
  22201. var data = Curve.prototype.toJSON.call(this);
  22202. data.v0 = this.v0.toArray();
  22203. data.v1 = this.v1.toArray();
  22204. data.v2 = this.v2.toArray();
  22205. return data;
  22206. };
  22207. QuadraticBezierCurve3.prototype.fromJSON = function (json) {
  22208. Curve.prototype.fromJSON.call(this, json);
  22209. this.v0.fromArray(json.v0);
  22210. this.v1.fromArray(json.v1);
  22211. this.v2.fromArray(json.v2);
  22212. return this;
  22213. };
  22214. function SplineCurve(points) {
  22215. if (points === void 0) {
  22216. points = [];
  22217. }
  22218. Curve.call(this);
  22219. this.type = 'SplineCurve';
  22220. this.points = points;
  22221. }
  22222. SplineCurve.prototype = Object.create(Curve.prototype);
  22223. SplineCurve.prototype.constructor = SplineCurve;
  22224. SplineCurve.prototype.isSplineCurve = true;
  22225. SplineCurve.prototype.getPoint = function (t, optionalTarget) {
  22226. if (optionalTarget === void 0) {
  22227. optionalTarget = new Vector2();
  22228. }
  22229. var point = optionalTarget;
  22230. var points = this.points;
  22231. var p = (points.length - 1) * t;
  22232. var intPoint = Math.floor(p);
  22233. var weight = p - intPoint;
  22234. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  22235. var p1 = points[intPoint];
  22236. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  22237. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  22238. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  22239. return point;
  22240. };
  22241. SplineCurve.prototype.copy = function (source) {
  22242. Curve.prototype.copy.call(this, source);
  22243. this.points = [];
  22244. for (var i = 0, l = source.points.length; i < l; i++) {
  22245. var point = source.points[i];
  22246. this.points.push(point.clone());
  22247. }
  22248. return this;
  22249. };
  22250. SplineCurve.prototype.toJSON = function () {
  22251. var data = Curve.prototype.toJSON.call(this);
  22252. data.points = [];
  22253. for (var i = 0, l = this.points.length; i < l; i++) {
  22254. var point = this.points[i];
  22255. data.points.push(point.toArray());
  22256. }
  22257. return data;
  22258. };
  22259. SplineCurve.prototype.fromJSON = function (json) {
  22260. Curve.prototype.fromJSON.call(this, json);
  22261. this.points = [];
  22262. for (var i = 0, l = json.points.length; i < l; i++) {
  22263. var point = json.points[i];
  22264. this.points.push(new Vector2().fromArray(point));
  22265. }
  22266. return this;
  22267. };
  22268. var Curves = /*#__PURE__*/Object.freeze({
  22269. __proto__: null,
  22270. ArcCurve: ArcCurve,
  22271. CatmullRomCurve3: CatmullRomCurve3,
  22272. CubicBezierCurve: CubicBezierCurve,
  22273. CubicBezierCurve3: CubicBezierCurve3,
  22274. EllipseCurve: EllipseCurve,
  22275. LineCurve: LineCurve,
  22276. LineCurve3: LineCurve3,
  22277. QuadraticBezierCurve: QuadraticBezierCurve,
  22278. QuadraticBezierCurve3: QuadraticBezierCurve3,
  22279. SplineCurve: SplineCurve
  22280. });
  22281. /**************************************************************
  22282. * Curved Path - a curve path is simply a array of connected
  22283. * curves, but retains the api of a curve
  22284. **************************************************************/
  22285. function CurvePath() {
  22286. Curve.call(this);
  22287. this.type = 'CurvePath';
  22288. this.curves = [];
  22289. this.autoClose = false; // Automatically closes the path
  22290. }
  22291. CurvePath.prototype = Object.assign(Object.create(Curve.prototype), {
  22292. constructor: CurvePath,
  22293. add: function add(curve) {
  22294. this.curves.push(curve);
  22295. },
  22296. closePath: function closePath() {
  22297. // Add a line curve if start and end of lines are not connected
  22298. var startPoint = this.curves[0].getPoint(0);
  22299. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  22300. if (!startPoint.equals(endPoint)) {
  22301. this.curves.push(new LineCurve(endPoint, startPoint));
  22302. }
  22303. },
  22304. // To get accurate point with reference to
  22305. // entire path distance at time t,
  22306. // following has to be done:
  22307. // 1. Length of each sub path have to be known
  22308. // 2. Locate and identify type of curve
  22309. // 3. Get t for the curve
  22310. // 4. Return curve.getPointAt(t')
  22311. getPoint: function getPoint(t) {
  22312. var d = t * this.getLength();
  22313. var curveLengths = this.getCurveLengths();
  22314. var i = 0; // To think about boundaries points.
  22315. while (i < curveLengths.length) {
  22316. if (curveLengths[i] >= d) {
  22317. var diff = curveLengths[i] - d;
  22318. var curve = this.curves[i];
  22319. var segmentLength = curve.getLength();
  22320. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  22321. return curve.getPointAt(u);
  22322. }
  22323. i++;
  22324. }
  22325. return null; // loop where sum != 0, sum > d , sum+1 <d
  22326. },
  22327. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  22328. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  22329. // getPoint() depends on getLength
  22330. getLength: function getLength() {
  22331. var lens = this.getCurveLengths();
  22332. return lens[lens.length - 1];
  22333. },
  22334. // cacheLengths must be recalculated.
  22335. updateArcLengths: function updateArcLengths() {
  22336. this.needsUpdate = true;
  22337. this.cacheLengths = null;
  22338. this.getCurveLengths();
  22339. },
  22340. // Compute lengths and cache them
  22341. // We cannot overwrite getLengths() because UtoT mapping uses it.
  22342. getCurveLengths: function getCurveLengths() {
  22343. // We use cache values if curves and cache array are same length
  22344. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  22345. return this.cacheLengths;
  22346. } // Get length of sub-curve
  22347. // Push sums into cached array
  22348. var lengths = [];
  22349. var sums = 0;
  22350. for (var i = 0, l = this.curves.length; i < l; i++) {
  22351. sums += this.curves[i].getLength();
  22352. lengths.push(sums);
  22353. }
  22354. this.cacheLengths = lengths;
  22355. return lengths;
  22356. },
  22357. getSpacedPoints: function getSpacedPoints(divisions) {
  22358. if (divisions === void 0) {
  22359. divisions = 40;
  22360. }
  22361. var points = [];
  22362. for (var i = 0; i <= divisions; i++) {
  22363. points.push(this.getPoint(i / divisions));
  22364. }
  22365. if (this.autoClose) {
  22366. points.push(points[0]);
  22367. }
  22368. return points;
  22369. },
  22370. getPoints: function getPoints(divisions) {
  22371. if (divisions === void 0) {
  22372. divisions = 12;
  22373. }
  22374. var points = [];
  22375. var last;
  22376. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  22377. var curve = curves[i];
  22378. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  22379. var pts = curve.getPoints(resolution);
  22380. for (var j = 0; j < pts.length; j++) {
  22381. var point = pts[j];
  22382. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  22383. points.push(point);
  22384. last = point;
  22385. }
  22386. }
  22387. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  22388. points.push(points[0]);
  22389. }
  22390. return points;
  22391. },
  22392. copy: function copy(source) {
  22393. Curve.prototype.copy.call(this, source);
  22394. this.curves = [];
  22395. for (var i = 0, l = source.curves.length; i < l; i++) {
  22396. var curve = source.curves[i];
  22397. this.curves.push(curve.clone());
  22398. }
  22399. this.autoClose = source.autoClose;
  22400. return this;
  22401. },
  22402. toJSON: function toJSON() {
  22403. var data = Curve.prototype.toJSON.call(this);
  22404. data.autoClose = this.autoClose;
  22405. data.curves = [];
  22406. for (var i = 0, l = this.curves.length; i < l; i++) {
  22407. var curve = this.curves[i];
  22408. data.curves.push(curve.toJSON());
  22409. }
  22410. return data;
  22411. },
  22412. fromJSON: function fromJSON(json) {
  22413. Curve.prototype.fromJSON.call(this, json);
  22414. this.autoClose = json.autoClose;
  22415. this.curves = [];
  22416. for (var i = 0, l = json.curves.length; i < l; i++) {
  22417. var curve = json.curves[i];
  22418. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  22419. }
  22420. return this;
  22421. }
  22422. });
  22423. function Path(points) {
  22424. CurvePath.call(this);
  22425. this.type = 'Path';
  22426. this.currentPoint = new Vector2();
  22427. if (points) {
  22428. this.setFromPoints(points);
  22429. }
  22430. }
  22431. Path.prototype = Object.assign(Object.create(CurvePath.prototype), {
  22432. constructor: Path,
  22433. setFromPoints: function setFromPoints(points) {
  22434. this.moveTo(points[0].x, points[0].y);
  22435. for (var i = 1, l = points.length; i < l; i++) {
  22436. this.lineTo(points[i].x, points[i].y);
  22437. }
  22438. return this;
  22439. },
  22440. moveTo: function moveTo(x, y) {
  22441. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  22442. return this;
  22443. },
  22444. lineTo: function lineTo(x, y) {
  22445. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  22446. this.curves.push(curve);
  22447. this.currentPoint.set(x, y);
  22448. return this;
  22449. },
  22450. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  22451. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  22452. this.curves.push(curve);
  22453. this.currentPoint.set(aX, aY);
  22454. return this;
  22455. },
  22456. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  22457. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  22458. this.curves.push(curve);
  22459. this.currentPoint.set(aX, aY);
  22460. return this;
  22461. },
  22462. splineThru: function splineThru(pts
  22463. /*Array of Vector*/
  22464. ) {
  22465. var npts = [this.currentPoint.clone()].concat(pts);
  22466. var curve = new SplineCurve(npts);
  22467. this.curves.push(curve);
  22468. this.currentPoint.copy(pts[pts.length - 1]);
  22469. return this;
  22470. },
  22471. arc: function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22472. var x0 = this.currentPoint.x;
  22473. var y0 = this.currentPoint.y;
  22474. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  22475. return this;
  22476. },
  22477. absarc: function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22478. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  22479. return this;
  22480. },
  22481. ellipse: function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22482. var x0 = this.currentPoint.x;
  22483. var y0 = this.currentPoint.y;
  22484. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  22485. return this;
  22486. },
  22487. absellipse: function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22488. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  22489. if (this.curves.length > 0) {
  22490. // if a previous curve is present, attempt to join
  22491. var firstPoint = curve.getPoint(0);
  22492. if (!firstPoint.equals(this.currentPoint)) {
  22493. this.lineTo(firstPoint.x, firstPoint.y);
  22494. }
  22495. }
  22496. this.curves.push(curve);
  22497. var lastPoint = curve.getPoint(1);
  22498. this.currentPoint.copy(lastPoint);
  22499. return this;
  22500. },
  22501. copy: function copy(source) {
  22502. CurvePath.prototype.copy.call(this, source);
  22503. this.currentPoint.copy(source.currentPoint);
  22504. return this;
  22505. },
  22506. toJSON: function toJSON() {
  22507. var data = CurvePath.prototype.toJSON.call(this);
  22508. data.currentPoint = this.currentPoint.toArray();
  22509. return data;
  22510. },
  22511. fromJSON: function fromJSON(json) {
  22512. CurvePath.prototype.fromJSON.call(this, json);
  22513. this.currentPoint.fromArray(json.currentPoint);
  22514. return this;
  22515. }
  22516. });
  22517. function Shape(points) {
  22518. Path.call(this, points);
  22519. this.uuid = MathUtils.generateUUID();
  22520. this.type = 'Shape';
  22521. this.holes = [];
  22522. }
  22523. Shape.prototype = Object.assign(Object.create(Path.prototype), {
  22524. constructor: Shape,
  22525. getPointsHoles: function getPointsHoles(divisions) {
  22526. var holesPts = [];
  22527. for (var i = 0, l = this.holes.length; i < l; i++) {
  22528. holesPts[i] = this.holes[i].getPoints(divisions);
  22529. }
  22530. return holesPts;
  22531. },
  22532. // get points of shape and holes (keypoints based on segments parameter)
  22533. extractPoints: function extractPoints(divisions) {
  22534. return {
  22535. shape: this.getPoints(divisions),
  22536. holes: this.getPointsHoles(divisions)
  22537. };
  22538. },
  22539. copy: function copy(source) {
  22540. Path.prototype.copy.call(this, source);
  22541. this.holes = [];
  22542. for (var i = 0, l = source.holes.length; i < l; i++) {
  22543. var hole = source.holes[i];
  22544. this.holes.push(hole.clone());
  22545. }
  22546. return this;
  22547. },
  22548. toJSON: function toJSON() {
  22549. var data = Path.prototype.toJSON.call(this);
  22550. data.uuid = this.uuid;
  22551. data.holes = [];
  22552. for (var i = 0, l = this.holes.length; i < l; i++) {
  22553. var hole = this.holes[i];
  22554. data.holes.push(hole.toJSON());
  22555. }
  22556. return data;
  22557. },
  22558. fromJSON: function fromJSON(json) {
  22559. Path.prototype.fromJSON.call(this, json);
  22560. this.uuid = json.uuid;
  22561. this.holes = [];
  22562. for (var i = 0, l = json.holes.length; i < l; i++) {
  22563. var hole = json.holes[i];
  22564. this.holes.push(new Path().fromJSON(hole));
  22565. }
  22566. return this;
  22567. }
  22568. });
  22569. function Light(color, intensity) {
  22570. if (intensity === void 0) {
  22571. intensity = 1;
  22572. }
  22573. Object3D.call(this);
  22574. this.type = 'Light';
  22575. this.color = new Color(color);
  22576. this.intensity = intensity;
  22577. }
  22578. Light.prototype = Object.assign(Object.create(Object3D.prototype), {
  22579. constructor: Light,
  22580. isLight: true,
  22581. copy: function copy(source) {
  22582. Object3D.prototype.copy.call(this, source);
  22583. this.color.copy(source.color);
  22584. this.intensity = source.intensity;
  22585. return this;
  22586. },
  22587. toJSON: function toJSON(meta) {
  22588. var data = Object3D.prototype.toJSON.call(this, meta);
  22589. data.object.color = this.color.getHex();
  22590. data.object.intensity = this.intensity;
  22591. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  22592. if (this.distance !== undefined) data.object.distance = this.distance;
  22593. if (this.angle !== undefined) data.object.angle = this.angle;
  22594. if (this.decay !== undefined) data.object.decay = this.decay;
  22595. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  22596. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  22597. return data;
  22598. }
  22599. });
  22600. function HemisphereLight(skyColor, groundColor, intensity) {
  22601. Light.call(this, skyColor, intensity);
  22602. this.type = 'HemisphereLight';
  22603. this.position.copy(Object3D.DefaultUp);
  22604. this.updateMatrix();
  22605. this.groundColor = new Color(groundColor);
  22606. }
  22607. HemisphereLight.prototype = Object.assign(Object.create(Light.prototype), {
  22608. constructor: HemisphereLight,
  22609. isHemisphereLight: true,
  22610. copy: function copy(source) {
  22611. Light.prototype.copy.call(this, source);
  22612. this.groundColor.copy(source.groundColor);
  22613. return this;
  22614. }
  22615. });
  22616. function LightShadow(camera) {
  22617. this.camera = camera;
  22618. this.bias = 0;
  22619. this.normalBias = 0;
  22620. this.radius = 1;
  22621. this.mapSize = new Vector2(512, 512);
  22622. this.map = null;
  22623. this.mapPass = null;
  22624. this.matrix = new Matrix4();
  22625. this.autoUpdate = true;
  22626. this.needsUpdate = false;
  22627. this._frustum = new Frustum();
  22628. this._frameExtents = new Vector2(1, 1);
  22629. this._viewportCount = 1;
  22630. this._viewports = [new Vector4(0, 0, 1, 1)];
  22631. }
  22632. Object.assign(LightShadow.prototype, {
  22633. _projScreenMatrix: new Matrix4(),
  22634. _lightPositionWorld: new Vector3(),
  22635. _lookTarget: new Vector3(),
  22636. getViewportCount: function getViewportCount() {
  22637. return this._viewportCount;
  22638. },
  22639. getFrustum: function getFrustum() {
  22640. return this._frustum;
  22641. },
  22642. updateMatrices: function updateMatrices(light) {
  22643. var shadowCamera = this.camera,
  22644. shadowMatrix = this.matrix,
  22645. projScreenMatrix = this._projScreenMatrix,
  22646. lookTarget = this._lookTarget,
  22647. lightPositionWorld = this._lightPositionWorld;
  22648. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  22649. shadowCamera.position.copy(lightPositionWorld);
  22650. lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  22651. shadowCamera.lookAt(lookTarget);
  22652. shadowCamera.updateMatrixWorld();
  22653. projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  22654. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  22655. 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);
  22656. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  22657. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  22658. },
  22659. getViewport: function getViewport(viewportIndex) {
  22660. return this._viewports[viewportIndex];
  22661. },
  22662. getFrameExtents: function getFrameExtents() {
  22663. return this._frameExtents;
  22664. },
  22665. copy: function copy(source) {
  22666. this.camera = source.camera.clone();
  22667. this.bias = source.bias;
  22668. this.radius = source.radius;
  22669. this.mapSize.copy(source.mapSize);
  22670. return this;
  22671. },
  22672. clone: function clone() {
  22673. return new this.constructor().copy(this);
  22674. },
  22675. toJSON: function toJSON() {
  22676. var object = {};
  22677. if (this.bias !== 0) object.bias = this.bias;
  22678. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  22679. if (this.radius !== 1) object.radius = this.radius;
  22680. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  22681. object.camera = this.camera.toJSON(false).object;
  22682. delete object.camera.matrix;
  22683. return object;
  22684. }
  22685. });
  22686. function SpotLightShadow() {
  22687. LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500));
  22688. this.focus = 1;
  22689. }
  22690. SpotLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  22691. constructor: SpotLightShadow,
  22692. isSpotLightShadow: true,
  22693. updateMatrices: function updateMatrices(light) {
  22694. var camera = this.camera;
  22695. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  22696. var aspect = this.mapSize.width / this.mapSize.height;
  22697. var far = light.distance || camera.far;
  22698. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  22699. camera.fov = fov;
  22700. camera.aspect = aspect;
  22701. camera.far = far;
  22702. camera.updateProjectionMatrix();
  22703. }
  22704. LightShadow.prototype.updateMatrices.call(this, light);
  22705. }
  22706. });
  22707. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  22708. Light.call(this, color, intensity);
  22709. this.type = 'SpotLight';
  22710. this.position.copy(Object3D.DefaultUp);
  22711. this.updateMatrix();
  22712. this.target = new Object3D();
  22713. Object.defineProperty(this, 'power', {
  22714. get: function get() {
  22715. // intensity = power per solid angle.
  22716. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22717. return this.intensity * Math.PI;
  22718. },
  22719. set: function set(power) {
  22720. // intensity = power per solid angle.
  22721. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22722. this.intensity = power / Math.PI;
  22723. }
  22724. });
  22725. this.distance = distance !== undefined ? distance : 0;
  22726. this.angle = angle !== undefined ? angle : Math.PI / 3;
  22727. this.penumbra = penumbra !== undefined ? penumbra : 0;
  22728. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  22729. this.shadow = new SpotLightShadow();
  22730. }
  22731. SpotLight.prototype = Object.assign(Object.create(Light.prototype), {
  22732. constructor: SpotLight,
  22733. isSpotLight: true,
  22734. copy: function copy(source) {
  22735. Light.prototype.copy.call(this, source);
  22736. this.distance = source.distance;
  22737. this.angle = source.angle;
  22738. this.penumbra = source.penumbra;
  22739. this.decay = source.decay;
  22740. this.target = source.target.clone();
  22741. this.shadow = source.shadow.clone();
  22742. return this;
  22743. }
  22744. });
  22745. function PointLightShadow() {
  22746. LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500));
  22747. this._frameExtents = new Vector2(4, 2);
  22748. this._viewportCount = 6;
  22749. this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  22750. // following orientation:
  22751. //
  22752. // xzXZ
  22753. // y Y
  22754. //
  22755. // X - Positive x direction
  22756. // x - Negative x direction
  22757. // Y - Positive y direction
  22758. // y - Negative y direction
  22759. // Z - Positive z direction
  22760. // z - Negative z direction
  22761. // positive X
  22762. new Vector4(2, 1, 1, 1), // negative X
  22763. new Vector4(0, 1, 1, 1), // positive Z
  22764. new Vector4(3, 1, 1, 1), // negative Z
  22765. new Vector4(1, 1, 1, 1), // positive Y
  22766. new Vector4(3, 0, 1, 1), // negative Y
  22767. new Vector4(1, 0, 1, 1)];
  22768. 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)];
  22769. 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)];
  22770. }
  22771. PointLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  22772. constructor: PointLightShadow,
  22773. isPointLightShadow: true,
  22774. updateMatrices: function updateMatrices(light, viewportIndex) {
  22775. if (viewportIndex === void 0) {
  22776. viewportIndex = 0;
  22777. }
  22778. var camera = this.camera,
  22779. shadowMatrix = this.matrix,
  22780. lightPositionWorld = this._lightPositionWorld,
  22781. lookTarget = this._lookTarget,
  22782. projScreenMatrix = this._projScreenMatrix;
  22783. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  22784. camera.position.copy(lightPositionWorld);
  22785. lookTarget.copy(camera.position);
  22786. lookTarget.add(this._cubeDirections[viewportIndex]);
  22787. camera.up.copy(this._cubeUps[viewportIndex]);
  22788. camera.lookAt(lookTarget);
  22789. camera.updateMatrixWorld();
  22790. shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
  22791. projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  22792. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  22793. }
  22794. });
  22795. function PointLight(color, intensity, distance, decay) {
  22796. Light.call(this, color, intensity);
  22797. this.type = 'PointLight';
  22798. Object.defineProperty(this, 'power', {
  22799. get: function get() {
  22800. // intensity = power per solid angle.
  22801. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22802. return this.intensity * 4 * Math.PI;
  22803. },
  22804. set: function set(power) {
  22805. // intensity = power per solid angle.
  22806. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22807. this.intensity = power / (4 * Math.PI);
  22808. }
  22809. });
  22810. this.distance = distance !== undefined ? distance : 0;
  22811. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  22812. this.shadow = new PointLightShadow();
  22813. }
  22814. PointLight.prototype = Object.assign(Object.create(Light.prototype), {
  22815. constructor: PointLight,
  22816. isPointLight: true,
  22817. copy: function copy(source) {
  22818. Light.prototype.copy.call(this, source);
  22819. this.distance = source.distance;
  22820. this.decay = source.decay;
  22821. this.shadow = source.shadow.clone();
  22822. return this;
  22823. }
  22824. });
  22825. function OrthographicCamera(left, right, top, bottom, near, far) {
  22826. if (left === void 0) {
  22827. left = -1;
  22828. }
  22829. if (right === void 0) {
  22830. right = 1;
  22831. }
  22832. if (top === void 0) {
  22833. top = 1;
  22834. }
  22835. if (bottom === void 0) {
  22836. bottom = -1;
  22837. }
  22838. if (near === void 0) {
  22839. near = 0.1;
  22840. }
  22841. if (far === void 0) {
  22842. far = 2000;
  22843. }
  22844. Camera.call(this);
  22845. this.type = 'OrthographicCamera';
  22846. this.zoom = 1;
  22847. this.view = null;
  22848. this.left = left;
  22849. this.right = right;
  22850. this.top = top;
  22851. this.bottom = bottom;
  22852. this.near = near;
  22853. this.far = far;
  22854. this.updateProjectionMatrix();
  22855. }
  22856. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  22857. constructor: OrthographicCamera,
  22858. isOrthographicCamera: true,
  22859. copy: function copy(source, recursive) {
  22860. Camera.prototype.copy.call(this, source, recursive);
  22861. this.left = source.left;
  22862. this.right = source.right;
  22863. this.top = source.top;
  22864. this.bottom = source.bottom;
  22865. this.near = source.near;
  22866. this.far = source.far;
  22867. this.zoom = source.zoom;
  22868. this.view = source.view === null ? null : Object.assign({}, source.view);
  22869. return this;
  22870. },
  22871. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  22872. if (this.view === null) {
  22873. this.view = {
  22874. enabled: true,
  22875. fullWidth: 1,
  22876. fullHeight: 1,
  22877. offsetX: 0,
  22878. offsetY: 0,
  22879. width: 1,
  22880. height: 1
  22881. };
  22882. }
  22883. this.view.enabled = true;
  22884. this.view.fullWidth = fullWidth;
  22885. this.view.fullHeight = fullHeight;
  22886. this.view.offsetX = x;
  22887. this.view.offsetY = y;
  22888. this.view.width = width;
  22889. this.view.height = height;
  22890. this.updateProjectionMatrix();
  22891. },
  22892. clearViewOffset: function clearViewOffset() {
  22893. if (this.view !== null) {
  22894. this.view.enabled = false;
  22895. }
  22896. this.updateProjectionMatrix();
  22897. },
  22898. updateProjectionMatrix: function updateProjectionMatrix() {
  22899. var dx = (this.right - this.left) / (2 * this.zoom);
  22900. var dy = (this.top - this.bottom) / (2 * this.zoom);
  22901. var cx = (this.right + this.left) / 2;
  22902. var cy = (this.top + this.bottom) / 2;
  22903. var left = cx - dx;
  22904. var right = cx + dx;
  22905. var top = cy + dy;
  22906. var bottom = cy - dy;
  22907. if (this.view !== null && this.view.enabled) {
  22908. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  22909. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  22910. left += scaleW * this.view.offsetX;
  22911. right = left + scaleW * this.view.width;
  22912. top -= scaleH * this.view.offsetY;
  22913. bottom = top - scaleH * this.view.height;
  22914. }
  22915. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  22916. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  22917. },
  22918. toJSON: function toJSON(meta) {
  22919. var data = Object3D.prototype.toJSON.call(this, meta);
  22920. data.object.zoom = this.zoom;
  22921. data.object.left = this.left;
  22922. data.object.right = this.right;
  22923. data.object.top = this.top;
  22924. data.object.bottom = this.bottom;
  22925. data.object.near = this.near;
  22926. data.object.far = this.far;
  22927. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  22928. return data;
  22929. }
  22930. });
  22931. function DirectionalLightShadow() {
  22932. LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
  22933. }
  22934. DirectionalLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  22935. constructor: DirectionalLightShadow,
  22936. isDirectionalLightShadow: true,
  22937. updateMatrices: function updateMatrices(light) {
  22938. LightShadow.prototype.updateMatrices.call(this, light);
  22939. }
  22940. });
  22941. function DirectionalLight(color, intensity) {
  22942. Light.call(this, color, intensity);
  22943. this.type = 'DirectionalLight';
  22944. this.position.copy(Object3D.DefaultUp);
  22945. this.updateMatrix();
  22946. this.target = new Object3D();
  22947. this.shadow = new DirectionalLightShadow();
  22948. }
  22949. DirectionalLight.prototype = Object.assign(Object.create(Light.prototype), {
  22950. constructor: DirectionalLight,
  22951. isDirectionalLight: true,
  22952. copy: function copy(source) {
  22953. Light.prototype.copy.call(this, source);
  22954. this.target = source.target.clone();
  22955. this.shadow = source.shadow.clone();
  22956. return this;
  22957. }
  22958. });
  22959. function AmbientLight(color, intensity) {
  22960. Light.call(this, color, intensity);
  22961. this.type = 'AmbientLight';
  22962. }
  22963. AmbientLight.prototype = Object.assign(Object.create(Light.prototype), {
  22964. constructor: AmbientLight,
  22965. isAmbientLight: true
  22966. });
  22967. function RectAreaLight(color, intensity, width, height) {
  22968. Light.call(this, color, intensity);
  22969. this.type = 'RectAreaLight';
  22970. this.width = width !== undefined ? width : 10;
  22971. this.height = height !== undefined ? height : 10;
  22972. }
  22973. RectAreaLight.prototype = Object.assign(Object.create(Light.prototype), {
  22974. constructor: RectAreaLight,
  22975. isRectAreaLight: true,
  22976. copy: function copy(source) {
  22977. Light.prototype.copy.call(this, source);
  22978. this.width = source.width;
  22979. this.height = source.height;
  22980. return this;
  22981. },
  22982. toJSON: function toJSON(meta) {
  22983. var data = Light.prototype.toJSON.call(this, meta);
  22984. data.object.width = this.width;
  22985. data.object.height = this.height;
  22986. return data;
  22987. }
  22988. });
  22989. /**
  22990. * Primary reference:
  22991. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  22992. *
  22993. * Secondary reference:
  22994. * https://www.ppsloan.org/publications/StupidSH36.pdf
  22995. */
  22996. // 3-band SH defined by 9 coefficients
  22997. var SphericalHarmonics3 = /*#__PURE__*/function () {
  22998. function SphericalHarmonics3() {
  22999. Object.defineProperty(this, 'isSphericalHarmonics3', {
  23000. value: true
  23001. });
  23002. this.coefficients = [];
  23003. for (var i = 0; i < 9; i++) {
  23004. this.coefficients.push(new Vector3());
  23005. }
  23006. }
  23007. var _proto = SphericalHarmonics3.prototype;
  23008. _proto.set = function set(coefficients) {
  23009. for (var i = 0; i < 9; i++) {
  23010. this.coefficients[i].copy(coefficients[i]);
  23011. }
  23012. return this;
  23013. };
  23014. _proto.zero = function zero() {
  23015. for (var i = 0; i < 9; i++) {
  23016. this.coefficients[i].set(0, 0, 0);
  23017. }
  23018. return this;
  23019. } // get the radiance in the direction of the normal
  23020. // target is a Vector3
  23021. ;
  23022. _proto.getAt = function getAt(normal, target) {
  23023. // normal is assumed to be unit length
  23024. var x = normal.x,
  23025. y = normal.y,
  23026. z = normal.z;
  23027. var coeff = this.coefficients; // band 0
  23028. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  23029. target.addScaledVector(coeff[1], 0.488603 * y);
  23030. target.addScaledVector(coeff[2], 0.488603 * z);
  23031. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  23032. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  23033. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  23034. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  23035. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  23036. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  23037. return target;
  23038. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23039. // target is a Vector3
  23040. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23041. ;
  23042. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  23043. // normal is assumed to be unit length
  23044. var x = normal.x,
  23045. y = normal.y,
  23046. z = normal.z;
  23047. var coeff = this.coefficients; // band 0
  23048. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  23049. // band 1
  23050. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  23051. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  23052. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  23053. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  23054. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  23055. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  23056. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  23057. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  23058. return target;
  23059. };
  23060. _proto.add = function add(sh) {
  23061. for (var i = 0; i < 9; i++) {
  23062. this.coefficients[i].add(sh.coefficients[i]);
  23063. }
  23064. return this;
  23065. };
  23066. _proto.addScaledSH = function addScaledSH(sh, s) {
  23067. for (var i = 0; i < 9; i++) {
  23068. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  23069. }
  23070. return this;
  23071. };
  23072. _proto.scale = function scale(s) {
  23073. for (var i = 0; i < 9; i++) {
  23074. this.coefficients[i].multiplyScalar(s);
  23075. }
  23076. return this;
  23077. };
  23078. _proto.lerp = function lerp(sh, alpha) {
  23079. for (var i = 0; i < 9; i++) {
  23080. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  23081. }
  23082. return this;
  23083. };
  23084. _proto.equals = function equals(sh) {
  23085. for (var i = 0; i < 9; i++) {
  23086. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  23087. return false;
  23088. }
  23089. }
  23090. return true;
  23091. };
  23092. _proto.copy = function copy(sh) {
  23093. return this.set(sh.coefficients);
  23094. };
  23095. _proto.clone = function clone() {
  23096. return new this.constructor().copy(this);
  23097. };
  23098. _proto.fromArray = function fromArray(array, offset) {
  23099. if (offset === void 0) {
  23100. offset = 0;
  23101. }
  23102. var coefficients = this.coefficients;
  23103. for (var i = 0; i < 9; i++) {
  23104. coefficients[i].fromArray(array, offset + i * 3);
  23105. }
  23106. return this;
  23107. };
  23108. _proto.toArray = function toArray(array, offset) {
  23109. if (array === void 0) {
  23110. array = [];
  23111. }
  23112. if (offset === void 0) {
  23113. offset = 0;
  23114. }
  23115. var coefficients = this.coefficients;
  23116. for (var i = 0; i < 9; i++) {
  23117. coefficients[i].toArray(array, offset + i * 3);
  23118. }
  23119. return array;
  23120. } // evaluate the basis functions
  23121. // shBasis is an Array[ 9 ]
  23122. ;
  23123. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  23124. // normal is assumed to be unit length
  23125. var x = normal.x,
  23126. y = normal.y,
  23127. z = normal.z; // band 0
  23128. shBasis[0] = 0.282095; // band 1
  23129. shBasis[1] = 0.488603 * y;
  23130. shBasis[2] = 0.488603 * z;
  23131. shBasis[3] = 0.488603 * x; // band 2
  23132. shBasis[4] = 1.092548 * x * y;
  23133. shBasis[5] = 1.092548 * y * z;
  23134. shBasis[6] = 0.315392 * (3 * z * z - 1);
  23135. shBasis[7] = 1.092548 * x * z;
  23136. shBasis[8] = 0.546274 * (x * x - y * y);
  23137. };
  23138. return SphericalHarmonics3;
  23139. }();
  23140. function LightProbe(sh, intensity) {
  23141. Light.call(this, undefined, intensity);
  23142. this.type = 'LightProbe';
  23143. this.sh = sh !== undefined ? sh : new SphericalHarmonics3();
  23144. }
  23145. LightProbe.prototype = Object.assign(Object.create(Light.prototype), {
  23146. constructor: LightProbe,
  23147. isLightProbe: true,
  23148. copy: function copy(source) {
  23149. Light.prototype.copy.call(this, source);
  23150. this.sh.copy(source.sh);
  23151. return this;
  23152. },
  23153. fromJSON: function fromJSON(json) {
  23154. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  23155. this.sh.fromArray(json.sh);
  23156. return this;
  23157. },
  23158. toJSON: function toJSON(meta) {
  23159. var data = Light.prototype.toJSON.call(this, meta);
  23160. data.object.sh = this.sh.toArray();
  23161. return data;
  23162. }
  23163. });
  23164. function MaterialLoader(manager) {
  23165. Loader.call(this, manager);
  23166. this.textures = {};
  23167. }
  23168. MaterialLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  23169. constructor: MaterialLoader,
  23170. load: function load(url, onLoad, onProgress, onError) {
  23171. var scope = this;
  23172. var loader = new FileLoader(scope.manager);
  23173. loader.setPath(scope.path);
  23174. loader.setRequestHeader(scope.requestHeader);
  23175. loader.setWithCredentials(scope.withCredentials);
  23176. loader.load(url, function (text) {
  23177. try {
  23178. onLoad(scope.parse(JSON.parse(text)));
  23179. } catch (e) {
  23180. if (onError) {
  23181. onError(e);
  23182. } else {
  23183. console.error(e);
  23184. }
  23185. scope.manager.itemError(url);
  23186. }
  23187. }, onProgress, onError);
  23188. },
  23189. parse: function parse(json) {
  23190. var textures = this.textures;
  23191. function getTexture(name) {
  23192. if (textures[name] === undefined) {
  23193. console.warn('THREE.MaterialLoader: Undefined texture', name);
  23194. }
  23195. return textures[name];
  23196. }
  23197. var material = new Materials[json.type]();
  23198. if (json.uuid !== undefined) material.uuid = json.uuid;
  23199. if (json.name !== undefined) material.name = json.name;
  23200. if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
  23201. if (json.roughness !== undefined) material.roughness = json.roughness;
  23202. if (json.metalness !== undefined) material.metalness = json.metalness;
  23203. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  23204. if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
  23205. if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
  23206. if (json.shininess !== undefined) material.shininess = json.shininess;
  23207. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  23208. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  23209. if (json.fog !== undefined) material.fog = json.fog;
  23210. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  23211. if (json.blending !== undefined) material.blending = json.blending;
  23212. if (json.combine !== undefined) material.combine = json.combine;
  23213. if (json.side !== undefined) material.side = json.side;
  23214. if (json.opacity !== undefined) material.opacity = json.opacity;
  23215. if (json.transparent !== undefined) material.transparent = json.transparent;
  23216. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  23217. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  23218. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  23219. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  23220. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  23221. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  23222. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  23223. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  23224. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  23225. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  23226. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  23227. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  23228. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  23229. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  23230. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  23231. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  23232. if (json.rotation !== undefined) material.rotation = json.rotation;
  23233. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  23234. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  23235. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  23236. if (json.scale !== undefined) material.scale = json.scale;
  23237. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  23238. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  23239. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  23240. if (json.skinning !== undefined) material.skinning = json.skinning;
  23241. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  23242. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  23243. if (json.dithering !== undefined) material.dithering = json.dithering;
  23244. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  23245. if (json.visible !== undefined) material.visible = json.visible;
  23246. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  23247. if (json.userData !== undefined) material.userData = json.userData;
  23248. if (json.vertexColors !== undefined) {
  23249. if (typeof json.vertexColors === 'number') {
  23250. material.vertexColors = json.vertexColors > 0 ? true : false;
  23251. } else {
  23252. material.vertexColors = json.vertexColors;
  23253. }
  23254. } // Shader Material
  23255. if (json.uniforms !== undefined) {
  23256. for (var name in json.uniforms) {
  23257. var uniform = json.uniforms[name];
  23258. material.uniforms[name] = {};
  23259. switch (uniform.type) {
  23260. case 't':
  23261. material.uniforms[name].value = getTexture(uniform.value);
  23262. break;
  23263. case 'c':
  23264. material.uniforms[name].value = new Color().setHex(uniform.value);
  23265. break;
  23266. case 'v2':
  23267. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  23268. break;
  23269. case 'v3':
  23270. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  23271. break;
  23272. case 'v4':
  23273. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  23274. break;
  23275. case 'm3':
  23276. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  23277. break;
  23278. case 'm4':
  23279. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  23280. break;
  23281. default:
  23282. material.uniforms[name].value = uniform.value;
  23283. }
  23284. }
  23285. }
  23286. if (json.defines !== undefined) material.defines = json.defines;
  23287. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  23288. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  23289. if (json.extensions !== undefined) {
  23290. for (var key in json.extensions) {
  23291. material.extensions[key] = json.extensions[key];
  23292. }
  23293. } // Deprecated
  23294. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  23295. // for PointsMaterial
  23296. if (json.size !== undefined) material.size = json.size;
  23297. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  23298. if (json.map !== undefined) material.map = getTexture(json.map);
  23299. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  23300. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  23301. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  23302. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  23303. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  23304. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  23305. if (json.normalScale !== undefined) {
  23306. var normalScale = json.normalScale;
  23307. if (Array.isArray(normalScale) === false) {
  23308. // Blender exporter used to export a scalar. See #7459
  23309. normalScale = [normalScale, normalScale];
  23310. }
  23311. material.normalScale = new Vector2().fromArray(normalScale);
  23312. }
  23313. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  23314. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  23315. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  23316. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  23317. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  23318. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  23319. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  23320. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  23321. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  23322. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  23323. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  23324. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  23325. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  23326. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  23327. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  23328. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  23329. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  23330. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  23331. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  23332. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  23333. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  23334. if (json.transmission !== undefined) material.transmission = json.transmission;
  23335. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  23336. return material;
  23337. },
  23338. setTextures: function setTextures(value) {
  23339. this.textures = value;
  23340. return this;
  23341. }
  23342. });
  23343. var LoaderUtils = {
  23344. decodeText: function decodeText(array) {
  23345. if (typeof TextDecoder !== 'undefined') {
  23346. return new TextDecoder().decode(array);
  23347. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  23348. // throws a "maximum call stack size exceeded" error for large arrays.
  23349. var s = '';
  23350. for (var i = 0, il = array.length; i < il; i++) {
  23351. // Implicitly assumes little-endian.
  23352. s += String.fromCharCode(array[i]);
  23353. }
  23354. try {
  23355. // merges multi-byte utf-8 characters.
  23356. return decodeURIComponent(escape(s));
  23357. } catch (e) {
  23358. // see #16358
  23359. return s;
  23360. }
  23361. },
  23362. extractUrlBase: function extractUrlBase(url) {
  23363. var index = url.lastIndexOf('/');
  23364. if (index === -1) return './';
  23365. return url.substr(0, index + 1);
  23366. }
  23367. };
  23368. function InstancedBufferGeometry() {
  23369. BufferGeometry.call(this);
  23370. this.type = 'InstancedBufferGeometry';
  23371. this.instanceCount = Infinity;
  23372. }
  23373. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  23374. constructor: InstancedBufferGeometry,
  23375. isInstancedBufferGeometry: true,
  23376. copy: function copy(source) {
  23377. BufferGeometry.prototype.copy.call(this, source);
  23378. this.instanceCount = source.instanceCount;
  23379. return this;
  23380. },
  23381. clone: function clone() {
  23382. return new this.constructor().copy(this);
  23383. },
  23384. toJSON: function toJSON() {
  23385. var data = BufferGeometry.prototype.toJSON.call(this);
  23386. data.instanceCount = this.instanceCount;
  23387. data.isInstancedBufferGeometry = true;
  23388. return data;
  23389. }
  23390. });
  23391. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  23392. if (typeof normalized === 'number') {
  23393. meshPerAttribute = normalized;
  23394. normalized = false;
  23395. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  23396. }
  23397. BufferAttribute.call(this, array, itemSize, normalized);
  23398. this.meshPerAttribute = meshPerAttribute || 1;
  23399. }
  23400. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  23401. constructor: InstancedBufferAttribute,
  23402. isInstancedBufferAttribute: true,
  23403. copy: function copy(source) {
  23404. BufferAttribute.prototype.copy.call(this, source);
  23405. this.meshPerAttribute = source.meshPerAttribute;
  23406. return this;
  23407. },
  23408. toJSON: function toJSON() {
  23409. var data = BufferAttribute.prototype.toJSON.call(this);
  23410. data.meshPerAttribute = this.meshPerAttribute;
  23411. data.isInstancedBufferAttribute = true;
  23412. return data;
  23413. }
  23414. });
  23415. function BufferGeometryLoader(manager) {
  23416. Loader.call(this, manager);
  23417. }
  23418. BufferGeometryLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  23419. constructor: BufferGeometryLoader,
  23420. load: function load(url, onLoad, onProgress, onError) {
  23421. var scope = this;
  23422. var loader = new FileLoader(scope.manager);
  23423. loader.setPath(scope.path);
  23424. loader.setRequestHeader(scope.requestHeader);
  23425. loader.setWithCredentials(scope.withCredentials);
  23426. loader.load(url, function (text) {
  23427. try {
  23428. onLoad(scope.parse(JSON.parse(text)));
  23429. } catch (e) {
  23430. if (onError) {
  23431. onError(e);
  23432. } else {
  23433. console.error(e);
  23434. }
  23435. scope.manager.itemError(url);
  23436. }
  23437. }, onProgress, onError);
  23438. },
  23439. parse: function parse(json) {
  23440. var interleavedBufferMap = {};
  23441. var arrayBufferMap = {};
  23442. function getInterleavedBuffer(json, uuid) {
  23443. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  23444. var interleavedBuffers = json.interleavedBuffers;
  23445. var interleavedBuffer = interleavedBuffers[uuid];
  23446. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  23447. var array = getTypedArray(interleavedBuffer.type, buffer);
  23448. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  23449. ib.uuid = interleavedBuffer.uuid;
  23450. interleavedBufferMap[uuid] = ib;
  23451. return ib;
  23452. }
  23453. function getArrayBuffer(json, uuid) {
  23454. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  23455. var arrayBuffers = json.arrayBuffers;
  23456. var arrayBuffer = arrayBuffers[uuid];
  23457. var ab = new Uint32Array(arrayBuffer).buffer;
  23458. arrayBufferMap[uuid] = ab;
  23459. return ab;
  23460. }
  23461. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  23462. var index = json.data.index;
  23463. if (index !== undefined) {
  23464. var typedArray = getTypedArray(index.type, index.array);
  23465. geometry.setIndex(new BufferAttribute(typedArray, 1));
  23466. }
  23467. var attributes = json.data.attributes;
  23468. for (var key in attributes) {
  23469. var attribute = attributes[key];
  23470. var bufferAttribute = void 0;
  23471. if (attribute.isInterleavedBufferAttribute) {
  23472. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  23473. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  23474. } else {
  23475. var _typedArray = getTypedArray(attribute.type, attribute.array);
  23476. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  23477. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  23478. }
  23479. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  23480. geometry.setAttribute(key, bufferAttribute);
  23481. }
  23482. var morphAttributes = json.data.morphAttributes;
  23483. if (morphAttributes) {
  23484. for (var _key in morphAttributes) {
  23485. var attributeArray = morphAttributes[_key];
  23486. var array = [];
  23487. for (var i = 0, il = attributeArray.length; i < il; i++) {
  23488. var _attribute = attributeArray[i];
  23489. var _bufferAttribute = void 0;
  23490. if (_attribute.isInterleavedBufferAttribute) {
  23491. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  23492. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  23493. } else {
  23494. var _typedArray2 = getTypedArray(_attribute.type, _attribute.array);
  23495. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  23496. }
  23497. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  23498. array.push(_bufferAttribute);
  23499. }
  23500. geometry.morphAttributes[_key] = array;
  23501. }
  23502. }
  23503. var morphTargetsRelative = json.data.morphTargetsRelative;
  23504. if (morphTargetsRelative) {
  23505. geometry.morphTargetsRelative = true;
  23506. }
  23507. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  23508. if (groups !== undefined) {
  23509. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  23510. var group = groups[_i];
  23511. geometry.addGroup(group.start, group.count, group.materialIndex);
  23512. }
  23513. }
  23514. var boundingSphere = json.data.boundingSphere;
  23515. if (boundingSphere !== undefined) {
  23516. var center = new Vector3();
  23517. if (boundingSphere.center !== undefined) {
  23518. center.fromArray(boundingSphere.center);
  23519. }
  23520. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  23521. }
  23522. if (json.name) geometry.name = json.name;
  23523. if (json.userData) geometry.userData = json.userData;
  23524. return geometry;
  23525. }
  23526. });
  23527. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  23528. _inheritsLoose(ObjectLoader, _Loader);
  23529. function ObjectLoader(manager) {
  23530. return _Loader.call(this, manager) || this;
  23531. }
  23532. var _proto = ObjectLoader.prototype;
  23533. _proto.load = function load(url, onLoad, onProgress, onError) {
  23534. var scope = this;
  23535. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  23536. this.resourcePath = this.resourcePath || path;
  23537. var loader = new FileLoader(this.manager);
  23538. loader.setPath(this.path);
  23539. loader.setRequestHeader(this.requestHeader);
  23540. loader.setWithCredentials(this.withCredentials);
  23541. loader.load(url, function (text) {
  23542. var json = null;
  23543. try {
  23544. json = JSON.parse(text);
  23545. } catch (error) {
  23546. if (onError !== undefined) onError(error);
  23547. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  23548. return;
  23549. }
  23550. var metadata = json.metadata;
  23551. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  23552. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  23553. return;
  23554. }
  23555. scope.parse(json, onLoad);
  23556. }, onProgress, onError);
  23557. };
  23558. _proto.parse = function parse(json, onLoad) {
  23559. var animations = this.parseAnimations(json.animations);
  23560. var shapes = this.parseShapes(json.shapes);
  23561. var geometries = this.parseGeometries(json.geometries, shapes);
  23562. var images = this.parseImages(json.images, function () {
  23563. if (onLoad !== undefined) onLoad(object);
  23564. });
  23565. var textures = this.parseTextures(json.textures, images);
  23566. var materials = this.parseMaterials(json.materials, textures);
  23567. var object = this.parseObject(json.object, geometries, materials, animations);
  23568. var skeletons = this.parseSkeletons(json.skeletons, object);
  23569. this.bindSkeletons(object, skeletons); //
  23570. if (onLoad !== undefined) {
  23571. var hasImages = false;
  23572. for (var uuid in images) {
  23573. if (images[uuid] instanceof HTMLImageElement) {
  23574. hasImages = true;
  23575. break;
  23576. }
  23577. }
  23578. if (hasImages === false) onLoad(object);
  23579. }
  23580. return object;
  23581. };
  23582. _proto.parseShapes = function parseShapes(json) {
  23583. var shapes = {};
  23584. if (json !== undefined) {
  23585. for (var i = 0, l = json.length; i < l; i++) {
  23586. var shape = new Shape().fromJSON(json[i]);
  23587. shapes[shape.uuid] = shape;
  23588. }
  23589. }
  23590. return shapes;
  23591. };
  23592. _proto.parseSkeletons = function parseSkeletons(json, object) {
  23593. var skeletons = {};
  23594. var bones = {}; // generate bone lookup table
  23595. object.traverse(function (child) {
  23596. if (child.isBone) bones[child.uuid] = child;
  23597. }); // create skeletons
  23598. if (json !== undefined) {
  23599. for (var i = 0, l = json.length; i < l; i++) {
  23600. var skeleton = new Skeleton().fromJSON(json[i], bones);
  23601. skeletons[skeleton.uuid] = skeleton;
  23602. }
  23603. }
  23604. return skeletons;
  23605. };
  23606. _proto.parseGeometries = function parseGeometries(json, shapes) {
  23607. var geometries = {};
  23608. var geometryShapes;
  23609. if (json !== undefined) {
  23610. var bufferGeometryLoader = new BufferGeometryLoader();
  23611. for (var i = 0, l = json.length; i < l; i++) {
  23612. var geometry = void 0;
  23613. var data = json[i];
  23614. switch (data.type) {
  23615. case 'PlaneGeometry':
  23616. case 'PlaneBufferGeometry':
  23617. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  23618. break;
  23619. case 'BoxGeometry':
  23620. case 'BoxBufferGeometry':
  23621. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  23622. break;
  23623. case 'CircleGeometry':
  23624. case 'CircleBufferGeometry':
  23625. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  23626. break;
  23627. case 'CylinderGeometry':
  23628. case 'CylinderBufferGeometry':
  23629. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  23630. break;
  23631. case 'ConeGeometry':
  23632. case 'ConeBufferGeometry':
  23633. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  23634. break;
  23635. case 'SphereGeometry':
  23636. case 'SphereBufferGeometry':
  23637. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  23638. break;
  23639. case 'DodecahedronGeometry':
  23640. case 'DodecahedronBufferGeometry':
  23641. case 'IcosahedronGeometry':
  23642. case 'IcosahedronBufferGeometry':
  23643. case 'OctahedronGeometry':
  23644. case 'OctahedronBufferGeometry':
  23645. case 'TetrahedronGeometry':
  23646. case 'TetrahedronBufferGeometry':
  23647. geometry = new Geometries[data.type](data.radius, data.detail);
  23648. break;
  23649. case 'RingGeometry':
  23650. case 'RingBufferGeometry':
  23651. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  23652. break;
  23653. case 'TorusGeometry':
  23654. case 'TorusBufferGeometry':
  23655. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  23656. break;
  23657. case 'TorusKnotGeometry':
  23658. case 'TorusKnotBufferGeometry':
  23659. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  23660. break;
  23661. case 'TubeGeometry':
  23662. case 'TubeBufferGeometry':
  23663. // This only works for built-in curves (e.g. CatmullRomCurve3).
  23664. // User defined curves or instances of CurvePath will not be deserialized.
  23665. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  23666. break;
  23667. case 'LatheGeometry':
  23668. case 'LatheBufferGeometry':
  23669. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  23670. break;
  23671. case 'PolyhedronGeometry':
  23672. case 'PolyhedronBufferGeometry':
  23673. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  23674. break;
  23675. case 'ShapeGeometry':
  23676. case 'ShapeBufferGeometry':
  23677. geometryShapes = [];
  23678. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  23679. var shape = shapes[data.shapes[j]];
  23680. geometryShapes.push(shape);
  23681. }
  23682. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  23683. break;
  23684. case 'ExtrudeGeometry':
  23685. case 'ExtrudeBufferGeometry':
  23686. geometryShapes = [];
  23687. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  23688. var _shape = shapes[data.shapes[_j]];
  23689. geometryShapes.push(_shape);
  23690. }
  23691. var extrudePath = data.options.extrudePath;
  23692. if (extrudePath !== undefined) {
  23693. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  23694. }
  23695. geometry = new Geometries[data.type](geometryShapes, data.options);
  23696. break;
  23697. case 'BufferGeometry':
  23698. case 'InstancedBufferGeometry':
  23699. geometry = bufferGeometryLoader.parse(data);
  23700. break;
  23701. case 'Geometry':
  23702. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  23703. break;
  23704. default:
  23705. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  23706. continue;
  23707. }
  23708. geometry.uuid = data.uuid;
  23709. if (data.name !== undefined) geometry.name = data.name;
  23710. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  23711. geometries[data.uuid] = geometry;
  23712. }
  23713. }
  23714. return geometries;
  23715. };
  23716. _proto.parseMaterials = function parseMaterials(json, textures) {
  23717. var cache = {}; // MultiMaterial
  23718. var materials = {};
  23719. if (json !== undefined) {
  23720. var loader = new MaterialLoader();
  23721. loader.setTextures(textures);
  23722. for (var i = 0, l = json.length; i < l; i++) {
  23723. var data = json[i];
  23724. if (data.type === 'MultiMaterial') {
  23725. // Deprecated
  23726. var array = [];
  23727. for (var j = 0; j < data.materials.length; j++) {
  23728. var material = data.materials[j];
  23729. if (cache[material.uuid] === undefined) {
  23730. cache[material.uuid] = loader.parse(material);
  23731. }
  23732. array.push(cache[material.uuid]);
  23733. }
  23734. materials[data.uuid] = array;
  23735. } else {
  23736. if (cache[data.uuid] === undefined) {
  23737. cache[data.uuid] = loader.parse(data);
  23738. }
  23739. materials[data.uuid] = cache[data.uuid];
  23740. }
  23741. }
  23742. }
  23743. return materials;
  23744. };
  23745. _proto.parseAnimations = function parseAnimations(json) {
  23746. var animations = {};
  23747. if (json !== undefined) {
  23748. for (var i = 0; i < json.length; i++) {
  23749. var data = json[i];
  23750. var clip = AnimationClip.parse(data);
  23751. animations[clip.uuid] = clip;
  23752. }
  23753. }
  23754. return animations;
  23755. };
  23756. _proto.parseImages = function parseImages(json, onLoad) {
  23757. var scope = this;
  23758. var images = {};
  23759. var loader;
  23760. function loadImage(url) {
  23761. scope.manager.itemStart(url);
  23762. return loader.load(url, function () {
  23763. scope.manager.itemEnd(url);
  23764. }, undefined, function () {
  23765. scope.manager.itemError(url);
  23766. scope.manager.itemEnd(url);
  23767. });
  23768. }
  23769. function deserializeImage(image) {
  23770. if (typeof image === 'string') {
  23771. var url = image;
  23772. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
  23773. return loadImage(path);
  23774. } else {
  23775. if (image.data) {
  23776. return {
  23777. data: getTypedArray(image.type, image.data),
  23778. width: image.width,
  23779. height: image.height
  23780. };
  23781. } else {
  23782. return null;
  23783. }
  23784. }
  23785. }
  23786. if (json !== undefined && json.length > 0) {
  23787. var manager = new LoadingManager(onLoad);
  23788. loader = new ImageLoader(manager);
  23789. loader.setCrossOrigin(this.crossOrigin);
  23790. for (var i = 0, il = json.length; i < il; i++) {
  23791. var image = json[i];
  23792. var url = image.url;
  23793. if (Array.isArray(url)) {
  23794. // load array of images e.g CubeTexture
  23795. images[image.uuid] = [];
  23796. for (var j = 0, jl = url.length; j < jl; j++) {
  23797. var currentUrl = url[j];
  23798. var deserializedImage = deserializeImage(currentUrl);
  23799. if (deserializedImage !== null) {
  23800. if (deserializedImage instanceof HTMLImageElement) {
  23801. images[image.uuid].push(deserializedImage);
  23802. } else {
  23803. // special case: handle array of data textures for cube textures
  23804. images[image.uuid].push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
  23805. }
  23806. }
  23807. }
  23808. } else {
  23809. // load single image
  23810. var _deserializedImage = deserializeImage(image.url);
  23811. if (_deserializedImage !== null) {
  23812. images[image.uuid] = _deserializedImage;
  23813. }
  23814. }
  23815. }
  23816. }
  23817. return images;
  23818. };
  23819. _proto.parseTextures = function parseTextures(json, images) {
  23820. function parseConstant(value, type) {
  23821. if (typeof value === 'number') return value;
  23822. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  23823. return type[value];
  23824. }
  23825. var textures = {};
  23826. if (json !== undefined) {
  23827. for (var i = 0, l = json.length; i < l; i++) {
  23828. var data = json[i];
  23829. if (data.image === undefined) {
  23830. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  23831. }
  23832. if (images[data.image] === undefined) {
  23833. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  23834. }
  23835. var texture = void 0;
  23836. var image = images[data.image];
  23837. if (Array.isArray(image)) {
  23838. texture = new CubeTexture(image);
  23839. if (image.length === 6) texture.needsUpdate = true;
  23840. } else {
  23841. if (image && image.data) {
  23842. texture = new DataTexture(image.data, image.width, image.height);
  23843. } else {
  23844. texture = new Texture(image);
  23845. }
  23846. if (image) texture.needsUpdate = true; // textures can have undefined image data
  23847. }
  23848. texture.uuid = data.uuid;
  23849. if (data.name !== undefined) texture.name = data.name;
  23850. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  23851. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  23852. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  23853. if (data.center !== undefined) texture.center.fromArray(data.center);
  23854. if (data.rotation !== undefined) texture.rotation = data.rotation;
  23855. if (data.wrap !== undefined) {
  23856. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  23857. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  23858. }
  23859. if (data.format !== undefined) texture.format = data.format;
  23860. if (data.type !== undefined) texture.type = data.type;
  23861. if (data.encoding !== undefined) texture.encoding = data.encoding;
  23862. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  23863. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  23864. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  23865. if (data.flipY !== undefined) texture.flipY = data.flipY;
  23866. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  23867. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  23868. textures[data.uuid] = texture;
  23869. }
  23870. }
  23871. return textures;
  23872. };
  23873. _proto.parseObject = function parseObject(data, geometries, materials, animations) {
  23874. var object;
  23875. function getGeometry(name) {
  23876. if (geometries[name] === undefined) {
  23877. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  23878. }
  23879. return geometries[name];
  23880. }
  23881. function getMaterial(name) {
  23882. if (name === undefined) return undefined;
  23883. if (Array.isArray(name)) {
  23884. var array = [];
  23885. for (var i = 0, l = name.length; i < l; i++) {
  23886. var uuid = name[i];
  23887. if (materials[uuid] === undefined) {
  23888. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  23889. }
  23890. array.push(materials[uuid]);
  23891. }
  23892. return array;
  23893. }
  23894. if (materials[name] === undefined) {
  23895. console.warn('THREE.ObjectLoader: Undefined material', name);
  23896. }
  23897. return materials[name];
  23898. }
  23899. var geometry, material;
  23900. switch (data.type) {
  23901. case 'Scene':
  23902. object = new Scene();
  23903. if (data.background !== undefined) {
  23904. if (Number.isInteger(data.background)) {
  23905. object.background = new Color(data.background);
  23906. }
  23907. }
  23908. if (data.fog !== undefined) {
  23909. if (data.fog.type === 'Fog') {
  23910. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  23911. } else if (data.fog.type === 'FogExp2') {
  23912. object.fog = new FogExp2(data.fog.color, data.fog.density);
  23913. }
  23914. }
  23915. break;
  23916. case 'PerspectiveCamera':
  23917. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  23918. if (data.focus !== undefined) object.focus = data.focus;
  23919. if (data.zoom !== undefined) object.zoom = data.zoom;
  23920. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  23921. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  23922. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  23923. break;
  23924. case 'OrthographicCamera':
  23925. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  23926. if (data.zoom !== undefined) object.zoom = data.zoom;
  23927. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  23928. break;
  23929. case 'AmbientLight':
  23930. object = new AmbientLight(data.color, data.intensity);
  23931. break;
  23932. case 'DirectionalLight':
  23933. object = new DirectionalLight(data.color, data.intensity);
  23934. break;
  23935. case 'PointLight':
  23936. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  23937. break;
  23938. case 'RectAreaLight':
  23939. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  23940. break;
  23941. case 'SpotLight':
  23942. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  23943. break;
  23944. case 'HemisphereLight':
  23945. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  23946. break;
  23947. case 'LightProbe':
  23948. object = new LightProbe().fromJSON(data);
  23949. break;
  23950. case 'SkinnedMesh':
  23951. geometry = getGeometry(data.geometry);
  23952. material = getMaterial(data.material);
  23953. object = new SkinnedMesh(geometry, material);
  23954. if (data.bindMode !== undefined) object.bindMode = data.bindMode;
  23955. if (data.bindMatrix !== undefined) object.bindMatrix.fromArray(data.bindMatrix);
  23956. if (data.skeleton !== undefined) object.skeleton = data.skeleton;
  23957. break;
  23958. case 'Mesh':
  23959. geometry = getGeometry(data.geometry);
  23960. material = getMaterial(data.material);
  23961. object = new Mesh(geometry, material);
  23962. break;
  23963. case 'InstancedMesh':
  23964. geometry = getGeometry(data.geometry);
  23965. material = getMaterial(data.material);
  23966. var count = data.count;
  23967. var instanceMatrix = data.instanceMatrix;
  23968. object = new InstancedMesh(geometry, material, count);
  23969. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  23970. break;
  23971. case 'LOD':
  23972. object = new LOD();
  23973. break;
  23974. case 'Line':
  23975. object = new Line(getGeometry(data.geometry), getMaterial(data.material));
  23976. break;
  23977. case 'LineLoop':
  23978. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  23979. break;
  23980. case 'LineSegments':
  23981. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  23982. break;
  23983. case 'PointCloud':
  23984. case 'Points':
  23985. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  23986. break;
  23987. case 'Sprite':
  23988. object = new Sprite(getMaterial(data.material));
  23989. break;
  23990. case 'Group':
  23991. object = new Group();
  23992. break;
  23993. case 'Bone':
  23994. object = new Bone();
  23995. break;
  23996. default:
  23997. object = new Object3D();
  23998. }
  23999. object.uuid = data.uuid;
  24000. if (data.name !== undefined) object.name = data.name;
  24001. if (data.matrix !== undefined) {
  24002. object.matrix.fromArray(data.matrix);
  24003. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24004. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  24005. } else {
  24006. if (data.position !== undefined) object.position.fromArray(data.position);
  24007. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  24008. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  24009. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  24010. }
  24011. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  24012. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  24013. if (data.shadow) {
  24014. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  24015. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  24016. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  24017. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  24018. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  24019. }
  24020. if (data.visible !== undefined) object.visible = data.visible;
  24021. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  24022. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  24023. if (data.userData !== undefined) object.userData = data.userData;
  24024. if (data.layers !== undefined) object.layers.mask = data.layers;
  24025. if (data.children !== undefined) {
  24026. var children = data.children;
  24027. for (var i = 0; i < children.length; i++) {
  24028. object.add(this.parseObject(children[i], geometries, materials, animations));
  24029. }
  24030. }
  24031. if (data.animations !== undefined) {
  24032. var objectAnimations = data.animations;
  24033. for (var _i = 0; _i < objectAnimations.length; _i++) {
  24034. var uuid = objectAnimations[_i];
  24035. object.animations.push(animations[uuid]);
  24036. }
  24037. }
  24038. if (data.type === 'LOD') {
  24039. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  24040. var levels = data.levels;
  24041. for (var l = 0; l < levels.length; l++) {
  24042. var level = levels[l];
  24043. var child = object.getObjectByProperty('uuid', level.object);
  24044. if (child !== undefined) {
  24045. object.addLevel(child, level.distance);
  24046. }
  24047. }
  24048. }
  24049. return object;
  24050. };
  24051. _proto.bindSkeletons = function bindSkeletons(object, skeletons) {
  24052. if (Object.keys(skeletons).length === 0) return;
  24053. object.traverse(function (child) {
  24054. if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
  24055. var skeleton = skeletons[child.skeleton];
  24056. if (skeleton === undefined) {
  24057. console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton);
  24058. } else {
  24059. child.bind(skeleton, child.bindMatrix);
  24060. }
  24061. }
  24062. });
  24063. }
  24064. /* DEPRECATED */
  24065. ;
  24066. _proto.setTexturePath = function setTexturePath(value) {
  24067. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  24068. return this.setResourcePath(value);
  24069. };
  24070. return ObjectLoader;
  24071. }(Loader);
  24072. var TEXTURE_MAPPING = {
  24073. UVMapping: UVMapping,
  24074. CubeReflectionMapping: CubeReflectionMapping,
  24075. CubeRefractionMapping: CubeRefractionMapping,
  24076. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24077. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24078. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24079. CubeUVRefractionMapping: CubeUVRefractionMapping
  24080. };
  24081. var TEXTURE_WRAPPING = {
  24082. RepeatWrapping: RepeatWrapping,
  24083. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24084. MirroredRepeatWrapping: MirroredRepeatWrapping
  24085. };
  24086. var TEXTURE_FILTER = {
  24087. NearestFilter: NearestFilter,
  24088. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24089. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24090. LinearFilter: LinearFilter,
  24091. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24092. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24093. };
  24094. function ImageBitmapLoader(manager) {
  24095. if (typeof createImageBitmap === 'undefined') {
  24096. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  24097. }
  24098. if (typeof fetch === 'undefined') {
  24099. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  24100. }
  24101. Loader.call(this, manager);
  24102. this.options = {
  24103. premultiplyAlpha: 'none'
  24104. };
  24105. }
  24106. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24107. constructor: ImageBitmapLoader,
  24108. isImageBitmapLoader: true,
  24109. setOptions: function setOptions(options) {
  24110. this.options = options;
  24111. return this;
  24112. },
  24113. load: function load(url, onLoad, onProgress, onError) {
  24114. if (url === undefined) url = '';
  24115. if (this.path !== undefined) url = this.path + url;
  24116. url = this.manager.resolveURL(url);
  24117. var scope = this;
  24118. var cached = Cache.get(url);
  24119. if (cached !== undefined) {
  24120. scope.manager.itemStart(url);
  24121. setTimeout(function () {
  24122. if (onLoad) onLoad(cached);
  24123. scope.manager.itemEnd(url);
  24124. }, 0);
  24125. return cached;
  24126. }
  24127. var fetchOptions = {};
  24128. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  24129. fetch(url, fetchOptions).then(function (res) {
  24130. return res.blob();
  24131. }).then(function (blob) {
  24132. return createImageBitmap(blob, scope.options);
  24133. }).then(function (imageBitmap) {
  24134. Cache.add(url, imageBitmap);
  24135. if (onLoad) onLoad(imageBitmap);
  24136. scope.manager.itemEnd(url);
  24137. }).catch(function (e) {
  24138. if (onError) onError(e);
  24139. scope.manager.itemError(url);
  24140. scope.manager.itemEnd(url);
  24141. });
  24142. scope.manager.itemStart(url);
  24143. }
  24144. });
  24145. function ShapePath() {
  24146. this.type = 'ShapePath';
  24147. this.color = new Color();
  24148. this.subPaths = [];
  24149. this.currentPath = null;
  24150. }
  24151. Object.assign(ShapePath.prototype, {
  24152. moveTo: function moveTo(x, y) {
  24153. this.currentPath = new Path();
  24154. this.subPaths.push(this.currentPath);
  24155. this.currentPath.moveTo(x, y);
  24156. return this;
  24157. },
  24158. lineTo: function lineTo(x, y) {
  24159. this.currentPath.lineTo(x, y);
  24160. return this;
  24161. },
  24162. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  24163. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  24164. return this;
  24165. },
  24166. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  24167. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  24168. return this;
  24169. },
  24170. splineThru: function splineThru(pts) {
  24171. this.currentPath.splineThru(pts);
  24172. return this;
  24173. },
  24174. toShapes: function toShapes(isCCW, noHoles) {
  24175. function toShapesNoHoles(inSubpaths) {
  24176. var shapes = [];
  24177. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  24178. var _tmpPath = inSubpaths[i];
  24179. var _tmpShape = new Shape();
  24180. _tmpShape.curves = _tmpPath.curves;
  24181. shapes.push(_tmpShape);
  24182. }
  24183. return shapes;
  24184. }
  24185. function isPointInsidePolygon(inPt, inPolygon) {
  24186. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  24187. // toggling of inside/outside at every single! intersection point of an edge
  24188. // with the horizontal line through inPt, left of inPt
  24189. // not counting lowerY endpoints of edges and whole edges on that line
  24190. var inside = false;
  24191. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  24192. var edgeLowPt = inPolygon[p];
  24193. var edgeHighPt = inPolygon[q];
  24194. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  24195. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  24196. if (Math.abs(edgeDy) > Number.EPSILON) {
  24197. // not parallel
  24198. if (edgeDy < 0) {
  24199. edgeLowPt = inPolygon[q];
  24200. edgeDx = -edgeDx;
  24201. edgeHighPt = inPolygon[p];
  24202. edgeDy = -edgeDy;
  24203. }
  24204. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  24205. if (inPt.y === edgeLowPt.y) {
  24206. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  24207. // continue; // no intersection or edgeLowPt => doesn't count !!!
  24208. } else {
  24209. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  24210. if (perpEdge === 0) return true; // inPt is on contour ?
  24211. if (perpEdge < 0) continue;
  24212. inside = !inside; // true intersection left of inPt
  24213. }
  24214. } else {
  24215. // parallel or collinear
  24216. if (inPt.y !== edgeLowPt.y) continue; // parallel
  24217. // edge lies on the same horizontal line as inPt
  24218. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  24219. // continue;
  24220. }
  24221. }
  24222. return inside;
  24223. }
  24224. var isClockWise = ShapeUtils.isClockWise;
  24225. var subPaths = this.subPaths;
  24226. if (subPaths.length === 0) return [];
  24227. if (noHoles === true) return toShapesNoHoles(subPaths);
  24228. var solid, tmpPath, tmpShape;
  24229. var shapes = [];
  24230. if (subPaths.length === 1) {
  24231. tmpPath = subPaths[0];
  24232. tmpShape = new Shape();
  24233. tmpShape.curves = tmpPath.curves;
  24234. shapes.push(tmpShape);
  24235. return shapes;
  24236. }
  24237. var holesFirst = !isClockWise(subPaths[0].getPoints());
  24238. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  24239. var betterShapeHoles = [];
  24240. var newShapes = [];
  24241. var newShapeHoles = [];
  24242. var mainIdx = 0;
  24243. var tmpPoints;
  24244. newShapes[mainIdx] = undefined;
  24245. newShapeHoles[mainIdx] = [];
  24246. for (var i = 0, l = subPaths.length; i < l; i++) {
  24247. tmpPath = subPaths[i];
  24248. tmpPoints = tmpPath.getPoints();
  24249. solid = isClockWise(tmpPoints);
  24250. solid = isCCW ? !solid : solid;
  24251. if (solid) {
  24252. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  24253. newShapes[mainIdx] = {
  24254. s: new Shape(),
  24255. p: tmpPoints
  24256. };
  24257. newShapes[mainIdx].s.curves = tmpPath.curves;
  24258. if (holesFirst) mainIdx++;
  24259. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  24260. } else {
  24261. newShapeHoles[mainIdx].push({
  24262. h: tmpPath,
  24263. p: tmpPoints[0]
  24264. }); //console.log('ccw', i);
  24265. }
  24266. } // only Holes? -> probably all Shapes with wrong orientation
  24267. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  24268. if (newShapes.length > 1) {
  24269. var ambiguous = false;
  24270. var toChange = [];
  24271. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  24272. betterShapeHoles[sIdx] = [];
  24273. }
  24274. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  24275. var sho = newShapeHoles[_sIdx];
  24276. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  24277. var ho = sho[hIdx];
  24278. var hole_unassigned = true;
  24279. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  24280. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  24281. if (_sIdx !== s2Idx) toChange.push({
  24282. froms: _sIdx,
  24283. tos: s2Idx,
  24284. hole: hIdx
  24285. });
  24286. if (hole_unassigned) {
  24287. hole_unassigned = false;
  24288. betterShapeHoles[s2Idx].push(ho);
  24289. } else {
  24290. ambiguous = true;
  24291. }
  24292. }
  24293. }
  24294. if (hole_unassigned) {
  24295. betterShapeHoles[_sIdx].push(ho);
  24296. }
  24297. }
  24298. } // console.log("ambiguous: ", ambiguous);
  24299. if (toChange.length > 0) {
  24300. // console.log("to change: ", toChange);
  24301. if (!ambiguous) newShapeHoles = betterShapeHoles;
  24302. }
  24303. }
  24304. var tmpHoles;
  24305. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  24306. tmpShape = newShapes[_i].s;
  24307. shapes.push(tmpShape);
  24308. tmpHoles = newShapeHoles[_i];
  24309. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  24310. tmpShape.holes.push(tmpHoles[j].h);
  24311. }
  24312. } //console.log("shape", shapes);
  24313. return shapes;
  24314. }
  24315. });
  24316. function Font(data) {
  24317. this.type = 'Font';
  24318. this.data = data;
  24319. }
  24320. Object.assign(Font.prototype, {
  24321. isFont: true,
  24322. generateShapes: function generateShapes(text, size) {
  24323. if (size === void 0) {
  24324. size = 100;
  24325. }
  24326. var shapes = [];
  24327. var paths = createPaths(text, size, this.data);
  24328. for (var p = 0, pl = paths.length; p < pl; p++) {
  24329. Array.prototype.push.apply(shapes, paths[p].toShapes());
  24330. }
  24331. return shapes;
  24332. }
  24333. });
  24334. function createPaths(text, size, data) {
  24335. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  24336. var scale = size / data.resolution;
  24337. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  24338. var paths = [];
  24339. var offsetX = 0,
  24340. offsetY = 0;
  24341. for (var i = 0; i < chars.length; i++) {
  24342. var char = chars[i];
  24343. if (char === '\n') {
  24344. offsetX = 0;
  24345. offsetY -= line_height;
  24346. } else {
  24347. var ret = createPath(char, scale, offsetX, offsetY, data);
  24348. offsetX += ret.offsetX;
  24349. paths.push(ret.path);
  24350. }
  24351. }
  24352. return paths;
  24353. }
  24354. function createPath(char, scale, offsetX, offsetY, data) {
  24355. var glyph = data.glyphs[char] || data.glyphs['?'];
  24356. if (!glyph) {
  24357. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  24358. return;
  24359. }
  24360. var path = new ShapePath();
  24361. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  24362. if (glyph.o) {
  24363. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  24364. for (var i = 0, l = outline.length; i < l;) {
  24365. var action = outline[i++];
  24366. switch (action) {
  24367. case 'm':
  24368. // moveTo
  24369. x = outline[i++] * scale + offsetX;
  24370. y = outline[i++] * scale + offsetY;
  24371. path.moveTo(x, y);
  24372. break;
  24373. case 'l':
  24374. // lineTo
  24375. x = outline[i++] * scale + offsetX;
  24376. y = outline[i++] * scale + offsetY;
  24377. path.lineTo(x, y);
  24378. break;
  24379. case 'q':
  24380. // quadraticCurveTo
  24381. cpx = outline[i++] * scale + offsetX;
  24382. cpy = outline[i++] * scale + offsetY;
  24383. cpx1 = outline[i++] * scale + offsetX;
  24384. cpy1 = outline[i++] * scale + offsetY;
  24385. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  24386. break;
  24387. case 'b':
  24388. // bezierCurveTo
  24389. cpx = outline[i++] * scale + offsetX;
  24390. cpy = outline[i++] * scale + offsetY;
  24391. cpx1 = outline[i++] * scale + offsetX;
  24392. cpy1 = outline[i++] * scale + offsetY;
  24393. cpx2 = outline[i++] * scale + offsetX;
  24394. cpy2 = outline[i++] * scale + offsetY;
  24395. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  24396. break;
  24397. }
  24398. }
  24399. }
  24400. return {
  24401. offsetX: glyph.ha * scale,
  24402. path: path
  24403. };
  24404. }
  24405. function FontLoader(manager) {
  24406. Loader.call(this, manager);
  24407. }
  24408. FontLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24409. constructor: FontLoader,
  24410. load: function load(url, onLoad, onProgress, onError) {
  24411. var scope = this;
  24412. var loader = new FileLoader(this.manager);
  24413. loader.setPath(this.path);
  24414. loader.setRequestHeader(this.requestHeader);
  24415. loader.setWithCredentials(scope.withCredentials);
  24416. loader.load(url, function (text) {
  24417. var json;
  24418. try {
  24419. json = JSON.parse(text);
  24420. } catch (e) {
  24421. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  24422. json = JSON.parse(text.substring(65, text.length - 2));
  24423. }
  24424. var font = scope.parse(json);
  24425. if (onLoad) onLoad(font);
  24426. }, onProgress, onError);
  24427. },
  24428. parse: function parse(json) {
  24429. return new Font(json);
  24430. }
  24431. });
  24432. var _context;
  24433. var AudioContext = {
  24434. getContext: function getContext() {
  24435. if (_context === undefined) {
  24436. _context = new (window.AudioContext || window.webkitAudioContext)();
  24437. }
  24438. return _context;
  24439. },
  24440. setContext: function setContext(value) {
  24441. _context = value;
  24442. }
  24443. };
  24444. function AudioLoader(manager) {
  24445. Loader.call(this, manager);
  24446. }
  24447. AudioLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24448. constructor: AudioLoader,
  24449. load: function load(url, onLoad, onProgress, onError) {
  24450. var scope = this;
  24451. var loader = new FileLoader(scope.manager);
  24452. loader.setResponseType('arraybuffer');
  24453. loader.setPath(scope.path);
  24454. loader.setRequestHeader(scope.requestHeader);
  24455. loader.setWithCredentials(scope.withCredentials);
  24456. loader.load(url, function (buffer) {
  24457. try {
  24458. // Create a copy of the buffer. The `decodeAudioData` method
  24459. // detaches the buffer when complete, preventing reuse.
  24460. var bufferCopy = buffer.slice(0);
  24461. var context = AudioContext.getContext();
  24462. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  24463. onLoad(audioBuffer);
  24464. });
  24465. } catch (e) {
  24466. if (onError) {
  24467. onError(e);
  24468. } else {
  24469. console.error(e);
  24470. }
  24471. scope.manager.itemError(url);
  24472. }
  24473. }, onProgress, onError);
  24474. }
  24475. });
  24476. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  24477. LightProbe.call(this, undefined, intensity);
  24478. var color1 = new Color().set(skyColor);
  24479. var color2 = new Color().set(groundColor);
  24480. var sky = new Vector3(color1.r, color1.g, color1.b);
  24481. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  24482. var c0 = Math.sqrt(Math.PI);
  24483. var c1 = c0 * Math.sqrt(0.75);
  24484. this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  24485. this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  24486. }
  24487. HemisphereLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  24488. constructor: HemisphereLightProbe,
  24489. isHemisphereLightProbe: true,
  24490. copy: function copy(source) {
  24491. // modifying colors not currently supported
  24492. LightProbe.prototype.copy.call(this, source);
  24493. return this;
  24494. },
  24495. toJSON: function toJSON(meta) {
  24496. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  24497. return data;
  24498. }
  24499. });
  24500. function AmbientLightProbe(color, intensity) {
  24501. LightProbe.call(this, undefined, intensity);
  24502. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  24503. this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  24504. }
  24505. AmbientLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  24506. constructor: AmbientLightProbe,
  24507. isAmbientLightProbe: true,
  24508. copy: function copy(source) {
  24509. // modifying color not currently supported
  24510. LightProbe.prototype.copy.call(this, source);
  24511. return this;
  24512. },
  24513. toJSON: function toJSON(meta) {
  24514. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  24515. return data;
  24516. }
  24517. });
  24518. var _eyeRight = new Matrix4();
  24519. var _eyeLeft = new Matrix4();
  24520. function StereoCamera() {
  24521. this.type = 'StereoCamera';
  24522. this.aspect = 1;
  24523. this.eyeSep = 0.064;
  24524. this.cameraL = new PerspectiveCamera();
  24525. this.cameraL.layers.enable(1);
  24526. this.cameraL.matrixAutoUpdate = false;
  24527. this.cameraR = new PerspectiveCamera();
  24528. this.cameraR.layers.enable(2);
  24529. this.cameraR.matrixAutoUpdate = false;
  24530. this._cache = {
  24531. focus: null,
  24532. fov: null,
  24533. aspect: null,
  24534. near: null,
  24535. far: null,
  24536. zoom: null,
  24537. eyeSep: null
  24538. };
  24539. }
  24540. Object.assign(StereoCamera.prototype, {
  24541. update: function update(camera) {
  24542. var cache = this._cache;
  24543. 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;
  24544. if (needsUpdate) {
  24545. cache.focus = camera.focus;
  24546. cache.fov = camera.fov;
  24547. cache.aspect = camera.aspect * this.aspect;
  24548. cache.near = camera.near;
  24549. cache.far = camera.far;
  24550. cache.zoom = camera.zoom;
  24551. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  24552. // http://paulbourke.net/stereographics/stereorender/
  24553. var projectionMatrix = camera.projectionMatrix.clone();
  24554. var eyeSepHalf = cache.eyeSep / 2;
  24555. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  24556. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  24557. var xmin, xmax; // translate xOffset
  24558. _eyeLeft.elements[12] = -eyeSepHalf;
  24559. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  24560. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  24561. xmax = ymax * cache.aspect + eyeSepOnProjection;
  24562. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  24563. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  24564. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  24565. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  24566. xmax = ymax * cache.aspect - eyeSepOnProjection;
  24567. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  24568. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  24569. this.cameraR.projectionMatrix.copy(projectionMatrix);
  24570. }
  24571. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  24572. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  24573. }
  24574. });
  24575. var Clock = /*#__PURE__*/function () {
  24576. function Clock(autoStart) {
  24577. this.autoStart = autoStart !== undefined ? autoStart : true;
  24578. this.startTime = 0;
  24579. this.oldTime = 0;
  24580. this.elapsedTime = 0;
  24581. this.running = false;
  24582. }
  24583. var _proto = Clock.prototype;
  24584. _proto.start = function start() {
  24585. this.startTime = now();
  24586. this.oldTime = this.startTime;
  24587. this.elapsedTime = 0;
  24588. this.running = true;
  24589. };
  24590. _proto.stop = function stop() {
  24591. this.getElapsedTime();
  24592. this.running = false;
  24593. this.autoStart = false;
  24594. };
  24595. _proto.getElapsedTime = function getElapsedTime() {
  24596. this.getDelta();
  24597. return this.elapsedTime;
  24598. };
  24599. _proto.getDelta = function getDelta() {
  24600. var diff = 0;
  24601. if (this.autoStart && !this.running) {
  24602. this.start();
  24603. return 0;
  24604. }
  24605. if (this.running) {
  24606. var newTime = now();
  24607. diff = (newTime - this.oldTime) / 1000;
  24608. this.oldTime = newTime;
  24609. this.elapsedTime += diff;
  24610. }
  24611. return diff;
  24612. };
  24613. return Clock;
  24614. }();
  24615. function now() {
  24616. return (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  24617. }
  24618. var _position$2 = /*@__PURE__*/new Vector3();
  24619. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  24620. var _scale$1 = /*@__PURE__*/new Vector3();
  24621. var _orientation = /*@__PURE__*/new Vector3();
  24622. var AudioListener = /*#__PURE__*/function (_Object3D) {
  24623. _inheritsLoose(AudioListener, _Object3D);
  24624. function AudioListener() {
  24625. var _this;
  24626. _this = _Object3D.call(this) || this;
  24627. _this.type = 'AudioListener';
  24628. _this.context = AudioContext.getContext();
  24629. _this.gain = _this.context.createGain();
  24630. _this.gain.connect(_this.context.destination);
  24631. _this.filter = null;
  24632. _this.timeDelta = 0; // private
  24633. _this._clock = new Clock();
  24634. return _this;
  24635. }
  24636. var _proto = AudioListener.prototype;
  24637. _proto.getInput = function getInput() {
  24638. return this.gain;
  24639. };
  24640. _proto.removeFilter = function removeFilter() {
  24641. if (this.filter !== null) {
  24642. this.gain.disconnect(this.filter);
  24643. this.filter.disconnect(this.context.destination);
  24644. this.gain.connect(this.context.destination);
  24645. this.filter = null;
  24646. }
  24647. return this;
  24648. };
  24649. _proto.getFilter = function getFilter() {
  24650. return this.filter;
  24651. };
  24652. _proto.setFilter = function setFilter(value) {
  24653. if (this.filter !== null) {
  24654. this.gain.disconnect(this.filter);
  24655. this.filter.disconnect(this.context.destination);
  24656. } else {
  24657. this.gain.disconnect(this.context.destination);
  24658. }
  24659. this.filter = value;
  24660. this.gain.connect(this.filter);
  24661. this.filter.connect(this.context.destination);
  24662. return this;
  24663. };
  24664. _proto.getMasterVolume = function getMasterVolume() {
  24665. return this.gain.gain.value;
  24666. };
  24667. _proto.setMasterVolume = function setMasterVolume(value) {
  24668. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  24669. return this;
  24670. };
  24671. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  24672. _Object3D.prototype.updateMatrixWorld.call(this, force);
  24673. var listener = this.context.listener;
  24674. var up = this.up;
  24675. this.timeDelta = this._clock.getDelta();
  24676. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  24677. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  24678. if (listener.positionX) {
  24679. // code path for Chrome (see #14393)
  24680. var endTime = this.context.currentTime + this.timeDelta;
  24681. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  24682. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  24683. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  24684. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  24685. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  24686. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  24687. listener.upX.linearRampToValueAtTime(up.x, endTime);
  24688. listener.upY.linearRampToValueAtTime(up.y, endTime);
  24689. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  24690. } else {
  24691. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  24692. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  24693. }
  24694. };
  24695. return AudioListener;
  24696. }(Object3D);
  24697. var Audio = /*#__PURE__*/function (_Object3D) {
  24698. _inheritsLoose(Audio, _Object3D);
  24699. function Audio(listener) {
  24700. var _this;
  24701. _this = _Object3D.call(this) || this;
  24702. _this.type = 'Audio';
  24703. _this.listener = listener;
  24704. _this.context = listener.context;
  24705. _this.gain = _this.context.createGain();
  24706. _this.gain.connect(listener.getInput());
  24707. _this.autoplay = false;
  24708. _this.buffer = null;
  24709. _this.detune = 0;
  24710. _this.loop = false;
  24711. _this.loopStart = 0;
  24712. _this.loopEnd = 0;
  24713. _this.offset = 0;
  24714. _this.duration = undefined;
  24715. _this.playbackRate = 1;
  24716. _this.isPlaying = false;
  24717. _this.hasPlaybackControl = true;
  24718. _this.source = null;
  24719. _this.sourceType = 'empty';
  24720. _this._startedAt = 0;
  24721. _this._progress = 0;
  24722. _this._connected = false;
  24723. _this.filters = [];
  24724. return _this;
  24725. }
  24726. var _proto = Audio.prototype;
  24727. _proto.getOutput = function getOutput() {
  24728. return this.gain;
  24729. };
  24730. _proto.setNodeSource = function setNodeSource(audioNode) {
  24731. this.hasPlaybackControl = false;
  24732. this.sourceType = 'audioNode';
  24733. this.source = audioNode;
  24734. this.connect();
  24735. return this;
  24736. };
  24737. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  24738. this.hasPlaybackControl = false;
  24739. this.sourceType = 'mediaNode';
  24740. this.source = this.context.createMediaElementSource(mediaElement);
  24741. this.connect();
  24742. return this;
  24743. };
  24744. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  24745. this.hasPlaybackControl = false;
  24746. this.sourceType = 'mediaStreamNode';
  24747. this.source = this.context.createMediaStreamSource(mediaStream);
  24748. this.connect();
  24749. return this;
  24750. };
  24751. _proto.setBuffer = function setBuffer(audioBuffer) {
  24752. this.buffer = audioBuffer;
  24753. this.sourceType = 'buffer';
  24754. if (this.autoplay) this.play();
  24755. return this;
  24756. };
  24757. _proto.play = function play(delay) {
  24758. if (delay === void 0) {
  24759. delay = 0;
  24760. }
  24761. if (this.isPlaying === true) {
  24762. console.warn('THREE.Audio: Audio is already playing.');
  24763. return;
  24764. }
  24765. if (this.hasPlaybackControl === false) {
  24766. console.warn('THREE.Audio: this Audio has no playback control.');
  24767. return;
  24768. }
  24769. this._startedAt = this.context.currentTime + delay;
  24770. var source = this.context.createBufferSource();
  24771. source.buffer = this.buffer;
  24772. source.loop = this.loop;
  24773. source.loopStart = this.loopStart;
  24774. source.loopEnd = this.loopEnd;
  24775. source.onended = this.onEnded.bind(this);
  24776. source.start(this._startedAt, this._progress + this.offset, this.duration);
  24777. this.isPlaying = true;
  24778. this.source = source;
  24779. this.setDetune(this.detune);
  24780. this.setPlaybackRate(this.playbackRate);
  24781. return this.connect();
  24782. };
  24783. _proto.pause = function pause() {
  24784. if (this.hasPlaybackControl === false) {
  24785. console.warn('THREE.Audio: this Audio has no playback control.');
  24786. return;
  24787. }
  24788. if (this.isPlaying === true) {
  24789. // update current progress
  24790. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  24791. if (this.loop === true) {
  24792. // ensure _progress does not exceed duration with looped audios
  24793. this._progress = this._progress % (this.duration || this.buffer.duration);
  24794. }
  24795. this.source.stop();
  24796. this.source.onended = null;
  24797. this.isPlaying = false;
  24798. }
  24799. return this;
  24800. };
  24801. _proto.stop = function stop() {
  24802. if (this.hasPlaybackControl === false) {
  24803. console.warn('THREE.Audio: this Audio has no playback control.');
  24804. return;
  24805. }
  24806. this._progress = 0;
  24807. this.source.stop();
  24808. this.source.onended = null;
  24809. this.isPlaying = false;
  24810. return this;
  24811. };
  24812. _proto.connect = function connect() {
  24813. if (this.filters.length > 0) {
  24814. this.source.connect(this.filters[0]);
  24815. for (var i = 1, l = this.filters.length; i < l; i++) {
  24816. this.filters[i - 1].connect(this.filters[i]);
  24817. }
  24818. this.filters[this.filters.length - 1].connect(this.getOutput());
  24819. } else {
  24820. this.source.connect(this.getOutput());
  24821. }
  24822. this._connected = true;
  24823. return this;
  24824. };
  24825. _proto.disconnect = function disconnect() {
  24826. if (this.filters.length > 0) {
  24827. this.source.disconnect(this.filters[0]);
  24828. for (var i = 1, l = this.filters.length; i < l; i++) {
  24829. this.filters[i - 1].disconnect(this.filters[i]);
  24830. }
  24831. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  24832. } else {
  24833. this.source.disconnect(this.getOutput());
  24834. }
  24835. this._connected = false;
  24836. return this;
  24837. };
  24838. _proto.getFilters = function getFilters() {
  24839. return this.filters;
  24840. };
  24841. _proto.setFilters = function setFilters(value) {
  24842. if (!value) value = [];
  24843. if (this._connected === true) {
  24844. this.disconnect();
  24845. this.filters = value.slice();
  24846. this.connect();
  24847. } else {
  24848. this.filters = value.slice();
  24849. }
  24850. return this;
  24851. };
  24852. _proto.setDetune = function setDetune(value) {
  24853. this.detune = value;
  24854. if (this.source.detune === undefined) return; // only set detune when available
  24855. if (this.isPlaying === true) {
  24856. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  24857. }
  24858. return this;
  24859. };
  24860. _proto.getDetune = function getDetune() {
  24861. return this.detune;
  24862. };
  24863. _proto.getFilter = function getFilter() {
  24864. return this.getFilters()[0];
  24865. };
  24866. _proto.setFilter = function setFilter(filter) {
  24867. return this.setFilters(filter ? [filter] : []);
  24868. };
  24869. _proto.setPlaybackRate = function setPlaybackRate(value) {
  24870. if (this.hasPlaybackControl === false) {
  24871. console.warn('THREE.Audio: this Audio has no playback control.');
  24872. return;
  24873. }
  24874. this.playbackRate = value;
  24875. if (this.isPlaying === true) {
  24876. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  24877. }
  24878. return this;
  24879. };
  24880. _proto.getPlaybackRate = function getPlaybackRate() {
  24881. return this.playbackRate;
  24882. };
  24883. _proto.onEnded = function onEnded() {
  24884. this.isPlaying = false;
  24885. };
  24886. _proto.getLoop = function getLoop() {
  24887. if (this.hasPlaybackControl === false) {
  24888. console.warn('THREE.Audio: this Audio has no playback control.');
  24889. return false;
  24890. }
  24891. return this.loop;
  24892. };
  24893. _proto.setLoop = function setLoop(value) {
  24894. if (this.hasPlaybackControl === false) {
  24895. console.warn('THREE.Audio: this Audio has no playback control.');
  24896. return;
  24897. }
  24898. this.loop = value;
  24899. if (this.isPlaying === true) {
  24900. this.source.loop = this.loop;
  24901. }
  24902. return this;
  24903. };
  24904. _proto.setLoopStart = function setLoopStart(value) {
  24905. this.loopStart = value;
  24906. return this;
  24907. };
  24908. _proto.setLoopEnd = function setLoopEnd(value) {
  24909. this.loopEnd = value;
  24910. return this;
  24911. };
  24912. _proto.getVolume = function getVolume() {
  24913. return this.gain.gain.value;
  24914. };
  24915. _proto.setVolume = function setVolume(value) {
  24916. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  24917. return this;
  24918. };
  24919. return Audio;
  24920. }(Object3D);
  24921. var _position$3 = /*@__PURE__*/new Vector3();
  24922. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  24923. var _scale$2 = /*@__PURE__*/new Vector3();
  24924. var _orientation$1 = /*@__PURE__*/new Vector3();
  24925. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  24926. _inheritsLoose(PositionalAudio, _Audio);
  24927. function PositionalAudio(listener) {
  24928. var _this;
  24929. _this = _Audio.call(this, listener) || this;
  24930. _this.panner = _this.context.createPanner();
  24931. _this.panner.panningModel = 'HRTF';
  24932. _this.panner.connect(_this.gain);
  24933. return _this;
  24934. }
  24935. var _proto = PositionalAudio.prototype;
  24936. _proto.getOutput = function getOutput() {
  24937. return this.panner;
  24938. };
  24939. _proto.getRefDistance = function getRefDistance() {
  24940. return this.panner.refDistance;
  24941. };
  24942. _proto.setRefDistance = function setRefDistance(value) {
  24943. this.panner.refDistance = value;
  24944. return this;
  24945. };
  24946. _proto.getRolloffFactor = function getRolloffFactor() {
  24947. return this.panner.rolloffFactor;
  24948. };
  24949. _proto.setRolloffFactor = function setRolloffFactor(value) {
  24950. this.panner.rolloffFactor = value;
  24951. return this;
  24952. };
  24953. _proto.getDistanceModel = function getDistanceModel() {
  24954. return this.panner.distanceModel;
  24955. };
  24956. _proto.setDistanceModel = function setDistanceModel(value) {
  24957. this.panner.distanceModel = value;
  24958. return this;
  24959. };
  24960. _proto.getMaxDistance = function getMaxDistance() {
  24961. return this.panner.maxDistance;
  24962. };
  24963. _proto.setMaxDistance = function setMaxDistance(value) {
  24964. this.panner.maxDistance = value;
  24965. return this;
  24966. };
  24967. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  24968. this.panner.coneInnerAngle = coneInnerAngle;
  24969. this.panner.coneOuterAngle = coneOuterAngle;
  24970. this.panner.coneOuterGain = coneOuterGain;
  24971. return this;
  24972. };
  24973. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  24974. _Audio.prototype.updateMatrixWorld.call(this, force);
  24975. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  24976. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  24977. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  24978. var panner = this.panner;
  24979. if (panner.positionX) {
  24980. // code path for Chrome and Firefox (see #14393)
  24981. var endTime = this.context.currentTime + this.listener.timeDelta;
  24982. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  24983. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  24984. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  24985. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  24986. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  24987. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  24988. } else {
  24989. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  24990. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  24991. }
  24992. };
  24993. return PositionalAudio;
  24994. }(Audio);
  24995. var AudioAnalyser = /*#__PURE__*/function () {
  24996. function AudioAnalyser(audio, fftSize) {
  24997. if (fftSize === void 0) {
  24998. fftSize = 2048;
  24999. }
  25000. this.analyser = audio.context.createAnalyser();
  25001. this.analyser.fftSize = fftSize;
  25002. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  25003. audio.getOutput().connect(this.analyser);
  25004. }
  25005. var _proto = AudioAnalyser.prototype;
  25006. _proto.getFrequencyData = function getFrequencyData() {
  25007. this.analyser.getByteFrequencyData(this.data);
  25008. return this.data;
  25009. };
  25010. _proto.getAverageFrequency = function getAverageFrequency() {
  25011. var value = 0;
  25012. var data = this.getFrequencyData();
  25013. for (var i = 0; i < data.length; i++) {
  25014. value += data[i];
  25015. }
  25016. return value / data.length;
  25017. };
  25018. return AudioAnalyser;
  25019. }();
  25020. function PropertyMixer(binding, typeName, valueSize) {
  25021. this.binding = binding;
  25022. this.valueSize = valueSize;
  25023. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25024. //
  25025. // interpolators can use .buffer as their .result
  25026. // the data then goes to 'incoming'
  25027. //
  25028. // 'accu0' and 'accu1' are used frame-interleaved for
  25029. // the cumulative result and are compared to detect
  25030. // changes
  25031. //
  25032. // 'orig' stores the original state of the property
  25033. //
  25034. // 'add' is used for additive cumulative results
  25035. //
  25036. // 'work' is optional and is only present for quaternion types. It is used
  25037. // to store intermediate quaternion multiplication results
  25038. switch (typeName) {
  25039. case 'quaternion':
  25040. mixFunction = this._slerp;
  25041. mixFunctionAdditive = this._slerpAdditive;
  25042. setIdentity = this._setAdditiveIdentityQuaternion;
  25043. this.buffer = new Float64Array(valueSize * 6);
  25044. this._workIndex = 5;
  25045. break;
  25046. case 'string':
  25047. case 'bool':
  25048. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  25049. // additive is not relevant for non-numeric types
  25050. mixFunctionAdditive = this._select;
  25051. setIdentity = this._setAdditiveIdentityOther;
  25052. this.buffer = new Array(valueSize * 5);
  25053. break;
  25054. default:
  25055. mixFunction = this._lerp;
  25056. mixFunctionAdditive = this._lerpAdditive;
  25057. setIdentity = this._setAdditiveIdentityNumeric;
  25058. this.buffer = new Float64Array(valueSize * 5);
  25059. }
  25060. this._mixBufferRegion = mixFunction;
  25061. this._mixBufferRegionAdditive = mixFunctionAdditive;
  25062. this._setIdentity = setIdentity;
  25063. this._origIndex = 3;
  25064. this._addIndex = 4;
  25065. this.cumulativeWeight = 0;
  25066. this.cumulativeWeightAdditive = 0;
  25067. this.useCount = 0;
  25068. this.referenceCount = 0;
  25069. }
  25070. Object.assign(PropertyMixer.prototype, {
  25071. // accumulate data in the 'incoming' region into 'accu<i>'
  25072. accumulate: function accumulate(accuIndex, weight) {
  25073. // note: happily accumulating nothing when weight = 0, the caller knows
  25074. // the weight and shouldn't have made the call in the first place
  25075. var buffer = this.buffer,
  25076. stride = this.valueSize,
  25077. offset = accuIndex * stride + stride;
  25078. var currentWeight = this.cumulativeWeight;
  25079. if (currentWeight === 0) {
  25080. // accuN := incoming * weight
  25081. for (var i = 0; i !== stride; ++i) {
  25082. buffer[offset + i] = buffer[i];
  25083. }
  25084. currentWeight = weight;
  25085. } else {
  25086. // accuN := accuN + incoming * weight
  25087. currentWeight += weight;
  25088. var mix = weight / currentWeight;
  25089. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  25090. }
  25091. this.cumulativeWeight = currentWeight;
  25092. },
  25093. // accumulate data in the 'incoming' region into 'add'
  25094. accumulateAdditive: function accumulateAdditive(weight) {
  25095. var buffer = this.buffer,
  25096. stride = this.valueSize,
  25097. offset = stride * this._addIndex;
  25098. if (this.cumulativeWeightAdditive === 0) {
  25099. // add = identity
  25100. this._setIdentity();
  25101. } // add := add + incoming * weight
  25102. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  25103. this.cumulativeWeightAdditive += weight;
  25104. },
  25105. // apply the state of 'accu<i>' to the binding when accus differ
  25106. apply: function apply(accuIndex) {
  25107. var stride = this.valueSize,
  25108. buffer = this.buffer,
  25109. offset = accuIndex * stride + stride,
  25110. weight = this.cumulativeWeight,
  25111. weightAdditive = this.cumulativeWeightAdditive,
  25112. binding = this.binding;
  25113. this.cumulativeWeight = 0;
  25114. this.cumulativeWeightAdditive = 0;
  25115. if (weight < 1) {
  25116. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25117. var originalValueOffset = stride * this._origIndex;
  25118. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  25119. }
  25120. if (weightAdditive > 0) {
  25121. // accuN := accuN + additive accuN
  25122. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  25123. }
  25124. for (var i = stride, e = stride + stride; i !== e; ++i) {
  25125. if (buffer[i] !== buffer[i + stride]) {
  25126. // value has changed -> update scene graph
  25127. binding.setValue(buffer, offset);
  25128. break;
  25129. }
  25130. }
  25131. },
  25132. // remember the state of the bound property and copy it to both accus
  25133. saveOriginalState: function saveOriginalState() {
  25134. var binding = this.binding;
  25135. var buffer = this.buffer,
  25136. stride = this.valueSize,
  25137. originalValueOffset = stride * this._origIndex;
  25138. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  25139. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  25140. buffer[i] = buffer[originalValueOffset + i % stride];
  25141. } // Add to identity for additive
  25142. this._setIdentity();
  25143. this.cumulativeWeight = 0;
  25144. this.cumulativeWeightAdditive = 0;
  25145. },
  25146. // apply the state previously taken via 'saveOriginalState' to the binding
  25147. restoreOriginalState: function restoreOriginalState() {
  25148. var originalValueOffset = this.valueSize * 3;
  25149. this.binding.setValue(this.buffer, originalValueOffset);
  25150. },
  25151. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  25152. var startIndex = this._addIndex * this.valueSize;
  25153. var endIndex = startIndex + this.valueSize;
  25154. for (var i = startIndex; i < endIndex; i++) {
  25155. this.buffer[i] = 0;
  25156. }
  25157. },
  25158. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  25159. this._setAdditiveIdentityNumeric();
  25160. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  25161. },
  25162. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  25163. var startIndex = this._origIndex * this.valueSize;
  25164. var targetIndex = this._addIndex * this.valueSize;
  25165. for (var i = 0; i < this.valueSize; i++) {
  25166. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  25167. }
  25168. },
  25169. // mix functions
  25170. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  25171. if (t >= 0.5) {
  25172. for (var i = 0; i !== stride; ++i) {
  25173. buffer[dstOffset + i] = buffer[srcOffset + i];
  25174. }
  25175. }
  25176. },
  25177. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  25178. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  25179. },
  25180. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25181. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  25182. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  25183. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  25184. },
  25185. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  25186. var s = 1 - t;
  25187. for (var i = 0; i !== stride; ++i) {
  25188. var j = dstOffset + i;
  25189. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  25190. }
  25191. },
  25192. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25193. for (var i = 0; i !== stride; ++i) {
  25194. var j = dstOffset + i;
  25195. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  25196. }
  25197. }
  25198. });
  25199. // Characters [].:/ are reserved for track binding syntax.
  25200. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25201. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25202. // only latin characters, and the unicode \p{L} is not yet supported. So
  25203. // instead, we exclude reserved characters and match everything else.
  25204. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  25205. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25206. // be matched to parse the rest of the track name.
  25207. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25208. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  25209. // characters. Accessor may contain any character except closing bracket.
  25210. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  25211. // contain any non-bracket characters.
  25212. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  25213. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  25214. var _supportedObjectNames = ['material', 'materials', 'bones'];
  25215. function Composite(targetGroup, path, optionalParsedPath) {
  25216. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  25217. this._targetGroup = targetGroup;
  25218. this._bindings = targetGroup.subscribe_(path, parsedPath);
  25219. }
  25220. Object.assign(Composite.prototype, {
  25221. getValue: function getValue(array, offset) {
  25222. this.bind(); // bind all binding
  25223. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25224. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  25225. if (binding !== undefined) binding.getValue(array, offset);
  25226. },
  25227. setValue: function setValue(array, offset) {
  25228. var bindings = this._bindings;
  25229. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25230. bindings[i].setValue(array, offset);
  25231. }
  25232. },
  25233. bind: function bind() {
  25234. var bindings = this._bindings;
  25235. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25236. bindings[i].bind();
  25237. }
  25238. },
  25239. unbind: function unbind() {
  25240. var bindings = this._bindings;
  25241. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25242. bindings[i].unbind();
  25243. }
  25244. }
  25245. });
  25246. function PropertyBinding(rootNode, path, parsedPath) {
  25247. this.path = path;
  25248. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  25249. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  25250. this.rootNode = rootNode;
  25251. }
  25252. Object.assign(PropertyBinding, {
  25253. Composite: Composite,
  25254. create: function create(root, path, parsedPath) {
  25255. if (!(root && root.isAnimationObjectGroup)) {
  25256. return new PropertyBinding(root, path, parsedPath);
  25257. } else {
  25258. return new PropertyBinding.Composite(root, path, parsedPath);
  25259. }
  25260. },
  25261. /**
  25262. * Replaces spaces with underscores and removes unsupported characters from
  25263. * node names, to ensure compatibility with parseTrackName().
  25264. *
  25265. * @param {string} name Node name to be sanitized.
  25266. * @return {string}
  25267. */
  25268. sanitizeNodeName: function sanitizeNodeName(name) {
  25269. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  25270. },
  25271. parseTrackName: function parseTrackName(trackName) {
  25272. var matches = _trackRe.exec(trackName);
  25273. if (!matches) {
  25274. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  25275. }
  25276. var results = {
  25277. // directoryName: matches[ 1 ], // (tschw) currently unused
  25278. nodeName: matches[2],
  25279. objectName: matches[3],
  25280. objectIndex: matches[4],
  25281. propertyName: matches[5],
  25282. // required
  25283. propertyIndex: matches[6]
  25284. };
  25285. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  25286. if (lastDot !== undefined && lastDot !== -1) {
  25287. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  25288. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  25289. // 'bar' could be the objectName, or part of a nodeName (which can
  25290. // include '.' characters).
  25291. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  25292. results.nodeName = results.nodeName.substring(0, lastDot);
  25293. results.objectName = objectName;
  25294. }
  25295. }
  25296. if (results.propertyName === null || results.propertyName.length === 0) {
  25297. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  25298. }
  25299. return results;
  25300. },
  25301. findNode: function findNode(root, nodeName) {
  25302. if (!nodeName || nodeName === '' || nodeName === '.' || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  25303. return root;
  25304. } // search into skeleton bones.
  25305. if (root.skeleton) {
  25306. var bone = root.skeleton.getBoneByName(nodeName);
  25307. if (bone !== undefined) {
  25308. return bone;
  25309. }
  25310. } // search into node subtree.
  25311. if (root.children) {
  25312. var searchNodeSubtree = function searchNodeSubtree(children) {
  25313. for (var i = 0; i < children.length; i++) {
  25314. var childNode = children[i];
  25315. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  25316. return childNode;
  25317. }
  25318. var result = searchNodeSubtree(childNode.children);
  25319. if (result) return result;
  25320. }
  25321. return null;
  25322. };
  25323. var subTreeNode = searchNodeSubtree(root.children);
  25324. if (subTreeNode) {
  25325. return subTreeNode;
  25326. }
  25327. }
  25328. return null;
  25329. }
  25330. });
  25331. Object.assign(PropertyBinding.prototype, {
  25332. // prototype, continued
  25333. // these are used to "bind" a nonexistent property
  25334. _getValue_unavailable: function _getValue_unavailable() {},
  25335. _setValue_unavailable: function _setValue_unavailable() {},
  25336. BindingType: {
  25337. Direct: 0,
  25338. EntireArray: 1,
  25339. ArrayElement: 2,
  25340. HasFromToArray: 3
  25341. },
  25342. Versioning: {
  25343. None: 0,
  25344. NeedsUpdate: 1,
  25345. MatrixWorldNeedsUpdate: 2
  25346. },
  25347. GetterByBindingType: [function getValue_direct(buffer, offset) {
  25348. buffer[offset] = this.node[this.propertyName];
  25349. }, function getValue_array(buffer, offset) {
  25350. var source = this.resolvedProperty;
  25351. for (var i = 0, n = source.length; i !== n; ++i) {
  25352. buffer[offset++] = source[i];
  25353. }
  25354. }, function getValue_arrayElement(buffer, offset) {
  25355. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  25356. }, function getValue_toArray(buffer, offset) {
  25357. this.resolvedProperty.toArray(buffer, offset);
  25358. }],
  25359. SetterByBindingTypeAndVersioning: [[// Direct
  25360. function setValue_direct(buffer, offset) {
  25361. this.targetObject[this.propertyName] = buffer[offset];
  25362. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  25363. this.targetObject[this.propertyName] = buffer[offset];
  25364. this.targetObject.needsUpdate = true;
  25365. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  25366. this.targetObject[this.propertyName] = buffer[offset];
  25367. this.targetObject.matrixWorldNeedsUpdate = true;
  25368. }], [// EntireArray
  25369. function setValue_array(buffer, offset) {
  25370. var dest = this.resolvedProperty;
  25371. for (var i = 0, n = dest.length; i !== n; ++i) {
  25372. dest[i] = buffer[offset++];
  25373. }
  25374. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  25375. var dest = this.resolvedProperty;
  25376. for (var i = 0, n = dest.length; i !== n; ++i) {
  25377. dest[i] = buffer[offset++];
  25378. }
  25379. this.targetObject.needsUpdate = true;
  25380. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  25381. var dest = this.resolvedProperty;
  25382. for (var i = 0, n = dest.length; i !== n; ++i) {
  25383. dest[i] = buffer[offset++];
  25384. }
  25385. this.targetObject.matrixWorldNeedsUpdate = true;
  25386. }], [// ArrayElement
  25387. function setValue_arrayElement(buffer, offset) {
  25388. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25389. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  25390. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25391. this.targetObject.needsUpdate = true;
  25392. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  25393. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25394. this.targetObject.matrixWorldNeedsUpdate = true;
  25395. }], [// HasToFromArray
  25396. function setValue_fromArray(buffer, offset) {
  25397. this.resolvedProperty.fromArray(buffer, offset);
  25398. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  25399. this.resolvedProperty.fromArray(buffer, offset);
  25400. this.targetObject.needsUpdate = true;
  25401. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  25402. this.resolvedProperty.fromArray(buffer, offset);
  25403. this.targetObject.matrixWorldNeedsUpdate = true;
  25404. }]],
  25405. getValue: function getValue_unbound(targetArray, offset) {
  25406. this.bind();
  25407. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  25408. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  25409. // prototype version of these methods with one that represents
  25410. // the bound state. When the property is not found, the methods
  25411. // become no-ops.
  25412. },
  25413. setValue: function getValue_unbound(sourceArray, offset) {
  25414. this.bind();
  25415. this.setValue(sourceArray, offset);
  25416. },
  25417. // create getter / setter pair for a property in the scene graph
  25418. bind: function bind() {
  25419. var targetObject = this.node;
  25420. var parsedPath = this.parsedPath;
  25421. var objectName = parsedPath.objectName;
  25422. var propertyName = parsedPath.propertyName;
  25423. var propertyIndex = parsedPath.propertyIndex;
  25424. if (!targetObject) {
  25425. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  25426. this.node = targetObject;
  25427. } // set fail state so we can just 'return' on error
  25428. this.getValue = this._getValue_unavailable;
  25429. this.setValue = this._setValue_unavailable; // ensure there is a value node
  25430. if (!targetObject) {
  25431. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  25432. return;
  25433. }
  25434. if (objectName) {
  25435. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  25436. switch (objectName) {
  25437. case 'materials':
  25438. if (!targetObject.material) {
  25439. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  25440. return;
  25441. }
  25442. if (!targetObject.material.materials) {
  25443. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  25444. return;
  25445. }
  25446. targetObject = targetObject.material.materials;
  25447. break;
  25448. case 'bones':
  25449. if (!targetObject.skeleton) {
  25450. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  25451. return;
  25452. } // potential future optimization: skip this if propertyIndex is already an integer
  25453. // and convert the integer string to a true integer.
  25454. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  25455. for (var i = 0; i < targetObject.length; i++) {
  25456. if (targetObject[i].name === objectIndex) {
  25457. objectIndex = i;
  25458. break;
  25459. }
  25460. }
  25461. break;
  25462. default:
  25463. if (targetObject[objectName] === undefined) {
  25464. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  25465. return;
  25466. }
  25467. targetObject = targetObject[objectName];
  25468. }
  25469. if (objectIndex !== undefined) {
  25470. if (targetObject[objectIndex] === undefined) {
  25471. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  25472. return;
  25473. }
  25474. targetObject = targetObject[objectIndex];
  25475. }
  25476. } // resolve property
  25477. var nodeProperty = targetObject[propertyName];
  25478. if (nodeProperty === undefined) {
  25479. var nodeName = parsedPath.nodeName;
  25480. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  25481. return;
  25482. } // determine versioning scheme
  25483. var versioning = this.Versioning.None;
  25484. this.targetObject = targetObject;
  25485. if (targetObject.needsUpdate !== undefined) {
  25486. // material
  25487. versioning = this.Versioning.NeedsUpdate;
  25488. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  25489. // node transform
  25490. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  25491. } // determine how the property gets bound
  25492. var bindingType = this.BindingType.Direct;
  25493. if (propertyIndex !== undefined) {
  25494. // access a sub element of the property array (only primitives are supported right now)
  25495. if (propertyName === 'morphTargetInfluences') {
  25496. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  25497. // support resolving morphTarget names into indices.
  25498. if (!targetObject.geometry) {
  25499. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  25500. return;
  25501. }
  25502. if (targetObject.geometry.isBufferGeometry) {
  25503. if (!targetObject.geometry.morphAttributes) {
  25504. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  25505. return;
  25506. }
  25507. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  25508. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  25509. }
  25510. } else {
  25511. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  25512. return;
  25513. }
  25514. }
  25515. bindingType = this.BindingType.ArrayElement;
  25516. this.resolvedProperty = nodeProperty;
  25517. this.propertyIndex = propertyIndex;
  25518. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  25519. // must use copy for Object3D.Euler/Quaternion
  25520. bindingType = this.BindingType.HasFromToArray;
  25521. this.resolvedProperty = nodeProperty;
  25522. } else if (Array.isArray(nodeProperty)) {
  25523. bindingType = this.BindingType.EntireArray;
  25524. this.resolvedProperty = nodeProperty;
  25525. } else {
  25526. this.propertyName = propertyName;
  25527. } // select getter / setter
  25528. this.getValue = this.GetterByBindingType[bindingType];
  25529. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  25530. },
  25531. unbind: function unbind() {
  25532. this.node = null; // back to the prototype version of getValue / setValue
  25533. // note: avoiding to mutate the shape of 'this' via 'delete'
  25534. this.getValue = this._getValue_unbound;
  25535. this.setValue = this._setValue_unbound;
  25536. }
  25537. }); // DECLARE ALIAS AFTER assign prototype
  25538. Object.assign(PropertyBinding.prototype, {
  25539. // initial state of these methods that calls 'bind'
  25540. _getValue_unbound: PropertyBinding.prototype.getValue,
  25541. _setValue_unbound: PropertyBinding.prototype.setValue
  25542. });
  25543. /**
  25544. *
  25545. * A group of objects that receives a shared animation state.
  25546. *
  25547. * Usage:
  25548. *
  25549. * - Add objects you would otherwise pass as 'root' to the
  25550. * constructor or the .clipAction method of AnimationMixer.
  25551. *
  25552. * - Instead pass this object as 'root'.
  25553. *
  25554. * - You can also add and remove objects later when the mixer
  25555. * is running.
  25556. *
  25557. * Note:
  25558. *
  25559. * Objects of this class appear as one object to the mixer,
  25560. * so cache control of the individual objects must be done
  25561. * on the group.
  25562. *
  25563. * Limitation:
  25564. *
  25565. * - The animated properties must be compatible among the
  25566. * all objects in the group.
  25567. *
  25568. * - A single property can either be controlled through a
  25569. * target group or directly, but not both.
  25570. */
  25571. function AnimationObjectGroup() {
  25572. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  25573. this._objects = Array.prototype.slice.call(arguments);
  25574. this.nCachedObjects_ = 0; // threshold
  25575. // note: read by PropertyBinding.Composite
  25576. var indices = {};
  25577. this._indicesByUUID = indices; // for bookkeeping
  25578. for (var i = 0, n = arguments.length; i !== n; ++i) {
  25579. indices[arguments[i].uuid] = i;
  25580. }
  25581. this._paths = []; // inside: string
  25582. this._parsedPaths = []; // inside: { we don't care, here }
  25583. this._bindings = []; // inside: Array< PropertyBinding >
  25584. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  25585. var scope = this;
  25586. this.stats = {
  25587. objects: {
  25588. get total() {
  25589. return scope._objects.length;
  25590. },
  25591. get inUse() {
  25592. return this.total - scope.nCachedObjects_;
  25593. }
  25594. },
  25595. get bindingsPerObject() {
  25596. return scope._bindings.length;
  25597. }
  25598. };
  25599. }
  25600. Object.assign(AnimationObjectGroup.prototype, {
  25601. isAnimationObjectGroup: true,
  25602. add: function add() {
  25603. var objects = this._objects,
  25604. indicesByUUID = this._indicesByUUID,
  25605. paths = this._paths,
  25606. parsedPaths = this._parsedPaths,
  25607. bindings = this._bindings,
  25608. nBindings = bindings.length;
  25609. var knownObject = undefined,
  25610. nObjects = objects.length,
  25611. nCachedObjects = this.nCachedObjects_;
  25612. for (var i = 0, n = arguments.length; i !== n; ++i) {
  25613. var object = arguments[i],
  25614. uuid = object.uuid;
  25615. var index = indicesByUUID[uuid];
  25616. if (index === undefined) {
  25617. // unknown object -> add it to the ACTIVE region
  25618. index = nObjects++;
  25619. indicesByUUID[uuid] = index;
  25620. objects.push(object); // accounting is done, now do the same for all bindings
  25621. for (var j = 0, m = nBindings; j !== m; ++j) {
  25622. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  25623. }
  25624. } else if (index < nCachedObjects) {
  25625. knownObject = objects[index]; // move existing object to the ACTIVE region
  25626. var firstActiveIndex = --nCachedObjects,
  25627. lastCachedObject = objects[firstActiveIndex];
  25628. indicesByUUID[lastCachedObject.uuid] = index;
  25629. objects[index] = lastCachedObject;
  25630. indicesByUUID[uuid] = firstActiveIndex;
  25631. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  25632. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  25633. var bindingsForPath = bindings[_j],
  25634. lastCached = bindingsForPath[firstActiveIndex];
  25635. var binding = bindingsForPath[index];
  25636. bindingsForPath[index] = lastCached;
  25637. if (binding === undefined) {
  25638. // since we do not bother to create new bindings
  25639. // for objects that are cached, the binding may
  25640. // or may not exist
  25641. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  25642. }
  25643. bindingsForPath[firstActiveIndex] = binding;
  25644. }
  25645. } else if (objects[index] !== knownObject) {
  25646. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  25647. } // else the object is already where we want it to be
  25648. } // for arguments
  25649. this.nCachedObjects_ = nCachedObjects;
  25650. },
  25651. remove: function remove() {
  25652. var objects = this._objects,
  25653. indicesByUUID = this._indicesByUUID,
  25654. bindings = this._bindings,
  25655. nBindings = bindings.length;
  25656. var nCachedObjects = this.nCachedObjects_;
  25657. for (var i = 0, n = arguments.length; i !== n; ++i) {
  25658. var object = arguments[i],
  25659. uuid = object.uuid,
  25660. index = indicesByUUID[uuid];
  25661. if (index !== undefined && index >= nCachedObjects) {
  25662. // move existing object into the CACHED region
  25663. var lastCachedIndex = nCachedObjects++,
  25664. firstActiveObject = objects[lastCachedIndex];
  25665. indicesByUUID[firstActiveObject.uuid] = index;
  25666. objects[index] = firstActiveObject;
  25667. indicesByUUID[uuid] = lastCachedIndex;
  25668. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  25669. for (var j = 0, m = nBindings; j !== m; ++j) {
  25670. var bindingsForPath = bindings[j],
  25671. firstActive = bindingsForPath[lastCachedIndex],
  25672. binding = bindingsForPath[index];
  25673. bindingsForPath[index] = firstActive;
  25674. bindingsForPath[lastCachedIndex] = binding;
  25675. }
  25676. }
  25677. } // for arguments
  25678. this.nCachedObjects_ = nCachedObjects;
  25679. },
  25680. // remove & forget
  25681. uncache: function uncache() {
  25682. var objects = this._objects,
  25683. indicesByUUID = this._indicesByUUID,
  25684. bindings = this._bindings,
  25685. nBindings = bindings.length;
  25686. var nCachedObjects = this.nCachedObjects_,
  25687. nObjects = objects.length;
  25688. for (var i = 0, n = arguments.length; i !== n; ++i) {
  25689. var object = arguments[i],
  25690. uuid = object.uuid,
  25691. index = indicesByUUID[uuid];
  25692. if (index !== undefined) {
  25693. delete indicesByUUID[uuid];
  25694. if (index < nCachedObjects) {
  25695. // object is cached, shrink the CACHED region
  25696. var firstActiveIndex = --nCachedObjects,
  25697. lastCachedObject = objects[firstActiveIndex],
  25698. lastIndex = --nObjects,
  25699. lastObject = objects[lastIndex]; // last cached object takes this object's place
  25700. indicesByUUID[lastCachedObject.uuid] = index;
  25701. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  25702. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  25703. objects[firstActiveIndex] = lastObject;
  25704. objects.pop(); // accounting is done, now do the same for all bindings
  25705. for (var j = 0, m = nBindings; j !== m; ++j) {
  25706. var bindingsForPath = bindings[j],
  25707. lastCached = bindingsForPath[firstActiveIndex],
  25708. last = bindingsForPath[lastIndex];
  25709. bindingsForPath[index] = lastCached;
  25710. bindingsForPath[firstActiveIndex] = last;
  25711. bindingsForPath.pop();
  25712. }
  25713. } else {
  25714. // object is active, just swap with the last and pop
  25715. var _lastIndex = --nObjects,
  25716. _lastObject = objects[_lastIndex];
  25717. if (_lastIndex > 0) {
  25718. indicesByUUID[_lastObject.uuid] = index;
  25719. }
  25720. objects[index] = _lastObject;
  25721. objects.pop(); // accounting is done, now do the same for all bindings
  25722. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  25723. var _bindingsForPath = bindings[_j2];
  25724. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  25725. _bindingsForPath.pop();
  25726. }
  25727. } // cached or active
  25728. } // if object is known
  25729. } // for arguments
  25730. this.nCachedObjects_ = nCachedObjects;
  25731. },
  25732. // Internal interface used by befriended PropertyBinding.Composite:
  25733. subscribe_: function subscribe_(path, parsedPath) {
  25734. // returns an array of bindings for the given path that is changed
  25735. // according to the contained objects in the group
  25736. var indicesByPath = this._bindingsIndicesByPath;
  25737. var index = indicesByPath[path];
  25738. var bindings = this._bindings;
  25739. if (index !== undefined) return bindings[index];
  25740. var paths = this._paths,
  25741. parsedPaths = this._parsedPaths,
  25742. objects = this._objects,
  25743. nObjects = objects.length,
  25744. nCachedObjects = this.nCachedObjects_,
  25745. bindingsForPath = new Array(nObjects);
  25746. index = bindings.length;
  25747. indicesByPath[path] = index;
  25748. paths.push(path);
  25749. parsedPaths.push(parsedPath);
  25750. bindings.push(bindingsForPath);
  25751. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  25752. var object = objects[i];
  25753. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  25754. }
  25755. return bindingsForPath;
  25756. },
  25757. unsubscribe_: function unsubscribe_(path) {
  25758. // tells the group to forget about a property path and no longer
  25759. // update the array previously obtained with 'subscribe_'
  25760. var indicesByPath = this._bindingsIndicesByPath,
  25761. index = indicesByPath[path];
  25762. if (index !== undefined) {
  25763. var paths = this._paths,
  25764. parsedPaths = this._parsedPaths,
  25765. bindings = this._bindings,
  25766. lastBindingsIndex = bindings.length - 1,
  25767. lastBindings = bindings[lastBindingsIndex],
  25768. lastBindingsPath = path[lastBindingsIndex];
  25769. indicesByPath[lastBindingsPath] = index;
  25770. bindings[index] = lastBindings;
  25771. bindings.pop();
  25772. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  25773. parsedPaths.pop();
  25774. paths[index] = paths[lastBindingsIndex];
  25775. paths.pop();
  25776. }
  25777. }
  25778. });
  25779. var AnimationAction = /*#__PURE__*/function () {
  25780. function AnimationAction(mixer, clip, localRoot, blendMode) {
  25781. if (localRoot === void 0) {
  25782. localRoot = null;
  25783. }
  25784. if (blendMode === void 0) {
  25785. blendMode = clip.blendMode;
  25786. }
  25787. this._mixer = mixer;
  25788. this._clip = clip;
  25789. this._localRoot = localRoot;
  25790. this.blendMode = blendMode;
  25791. var tracks = clip.tracks,
  25792. nTracks = tracks.length,
  25793. interpolants = new Array(nTracks);
  25794. var interpolantSettings = {
  25795. endingStart: ZeroCurvatureEnding,
  25796. endingEnd: ZeroCurvatureEnding
  25797. };
  25798. for (var i = 0; i !== nTracks; ++i) {
  25799. var interpolant = tracks[i].createInterpolant(null);
  25800. interpolants[i] = interpolant;
  25801. interpolant.settings = interpolantSettings;
  25802. }
  25803. this._interpolantSettings = interpolantSettings;
  25804. this._interpolants = interpolants; // bound by the mixer
  25805. // inside: PropertyMixer (managed by the mixer)
  25806. this._propertyBindings = new Array(nTracks);
  25807. this._cacheIndex = null; // for the memory manager
  25808. this._byClipCacheIndex = null; // for the memory manager
  25809. this._timeScaleInterpolant = null;
  25810. this._weightInterpolant = null;
  25811. this.loop = LoopRepeat;
  25812. this._loopCount = -1; // global mixer time when the action is to be started
  25813. // it's set back to 'null' upon start of the action
  25814. this._startTime = null; // scaled local time of the action
  25815. // gets clamped or wrapped to 0..clip.duration according to loop
  25816. this.time = 0;
  25817. this.timeScale = 1;
  25818. this._effectiveTimeScale = 1;
  25819. this.weight = 1;
  25820. this._effectiveWeight = 1;
  25821. this.repetitions = Infinity; // no. of repetitions when looping
  25822. this.paused = false; // true -> zero effective time scale
  25823. this.enabled = true; // false -> zero effective weight
  25824. this.clampWhenFinished = false; // keep feeding the last frame?
  25825. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  25826. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  25827. } // State & Scheduling
  25828. var _proto = AnimationAction.prototype;
  25829. _proto.play = function play() {
  25830. this._mixer._activateAction(this);
  25831. return this;
  25832. };
  25833. _proto.stop = function stop() {
  25834. this._mixer._deactivateAction(this);
  25835. return this.reset();
  25836. };
  25837. _proto.reset = function reset() {
  25838. this.paused = false;
  25839. this.enabled = true;
  25840. this.time = 0; // restart clip
  25841. this._loopCount = -1; // forget previous loops
  25842. this._startTime = null; // forget scheduling
  25843. return this.stopFading().stopWarping();
  25844. };
  25845. _proto.isRunning = function isRunning() {
  25846. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  25847. } // return true when play has been called
  25848. ;
  25849. _proto.isScheduled = function isScheduled() {
  25850. return this._mixer._isActiveAction(this);
  25851. };
  25852. _proto.startAt = function startAt(time) {
  25853. this._startTime = time;
  25854. return this;
  25855. };
  25856. _proto.setLoop = function setLoop(mode, repetitions) {
  25857. this.loop = mode;
  25858. this.repetitions = repetitions;
  25859. return this;
  25860. } // Weight
  25861. // set the weight stopping any scheduled fading
  25862. // although .enabled = false yields an effective weight of zero, this
  25863. // method does *not* change .enabled, because it would be confusing
  25864. ;
  25865. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  25866. this.weight = weight; // note: same logic as when updated at runtime
  25867. this._effectiveWeight = this.enabled ? weight : 0;
  25868. return this.stopFading();
  25869. } // return the weight considering fading and .enabled
  25870. ;
  25871. _proto.getEffectiveWeight = function getEffectiveWeight() {
  25872. return this._effectiveWeight;
  25873. };
  25874. _proto.fadeIn = function fadeIn(duration) {
  25875. return this._scheduleFading(duration, 0, 1);
  25876. };
  25877. _proto.fadeOut = function fadeOut(duration) {
  25878. return this._scheduleFading(duration, 1, 0);
  25879. };
  25880. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  25881. fadeOutAction.fadeOut(duration);
  25882. this.fadeIn(duration);
  25883. if (warp) {
  25884. var fadeInDuration = this._clip.duration,
  25885. fadeOutDuration = fadeOutAction._clip.duration,
  25886. startEndRatio = fadeOutDuration / fadeInDuration,
  25887. endStartRatio = fadeInDuration / fadeOutDuration;
  25888. fadeOutAction.warp(1.0, startEndRatio, duration);
  25889. this.warp(endStartRatio, 1.0, duration);
  25890. }
  25891. return this;
  25892. };
  25893. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  25894. return fadeInAction.crossFadeFrom(this, duration, warp);
  25895. };
  25896. _proto.stopFading = function stopFading() {
  25897. var weightInterpolant = this._weightInterpolant;
  25898. if (weightInterpolant !== null) {
  25899. this._weightInterpolant = null;
  25900. this._mixer._takeBackControlInterpolant(weightInterpolant);
  25901. }
  25902. return this;
  25903. } // Time Scale Control
  25904. // set the time scale stopping any scheduled warping
  25905. // although .paused = true yields an effective time scale of zero, this
  25906. // method does *not* change .paused, because it would be confusing
  25907. ;
  25908. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  25909. this.timeScale = timeScale;
  25910. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  25911. return this.stopWarping();
  25912. } // return the time scale considering warping and .paused
  25913. ;
  25914. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  25915. return this._effectiveTimeScale;
  25916. };
  25917. _proto.setDuration = function setDuration(duration) {
  25918. this.timeScale = this._clip.duration / duration;
  25919. return this.stopWarping();
  25920. };
  25921. _proto.syncWith = function syncWith(action) {
  25922. this.time = action.time;
  25923. this.timeScale = action.timeScale;
  25924. return this.stopWarping();
  25925. };
  25926. _proto.halt = function halt(duration) {
  25927. return this.warp(this._effectiveTimeScale, 0, duration);
  25928. };
  25929. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  25930. var mixer = this._mixer,
  25931. now = mixer.time,
  25932. timeScale = this.timeScale;
  25933. var interpolant = this._timeScaleInterpolant;
  25934. if (interpolant === null) {
  25935. interpolant = mixer._lendControlInterpolant();
  25936. this._timeScaleInterpolant = interpolant;
  25937. }
  25938. var times = interpolant.parameterPositions,
  25939. values = interpolant.sampleValues;
  25940. times[0] = now;
  25941. times[1] = now + duration;
  25942. values[0] = startTimeScale / timeScale;
  25943. values[1] = endTimeScale / timeScale;
  25944. return this;
  25945. };
  25946. _proto.stopWarping = function stopWarping() {
  25947. var timeScaleInterpolant = this._timeScaleInterpolant;
  25948. if (timeScaleInterpolant !== null) {
  25949. this._timeScaleInterpolant = null;
  25950. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  25951. }
  25952. return this;
  25953. } // Object Accessors
  25954. ;
  25955. _proto.getMixer = function getMixer() {
  25956. return this._mixer;
  25957. };
  25958. _proto.getClip = function getClip() {
  25959. return this._clip;
  25960. };
  25961. _proto.getRoot = function getRoot() {
  25962. return this._localRoot || this._mixer._root;
  25963. } // Interna
  25964. ;
  25965. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  25966. // called by the mixer
  25967. if (!this.enabled) {
  25968. // call ._updateWeight() to update ._effectiveWeight
  25969. this._updateWeight(time);
  25970. return;
  25971. }
  25972. var startTime = this._startTime;
  25973. if (startTime !== null) {
  25974. // check for scheduled start of action
  25975. var timeRunning = (time - startTime) * timeDirection;
  25976. if (timeRunning < 0 || timeDirection === 0) {
  25977. return; // yet to come / don't decide when delta = 0
  25978. } // start
  25979. this._startTime = null; // unschedule
  25980. deltaTime = timeDirection * timeRunning;
  25981. } // apply time scale and advance time
  25982. deltaTime *= this._updateTimeScale(time);
  25983. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  25984. // an effective weight of 0
  25985. var weight = this._updateWeight(time);
  25986. if (weight > 0) {
  25987. var _interpolants = this._interpolants;
  25988. var propertyMixers = this._propertyBindings;
  25989. switch (this.blendMode) {
  25990. case AdditiveAnimationBlendMode:
  25991. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  25992. _interpolants[j].evaluate(clipTime);
  25993. propertyMixers[j].accumulateAdditive(weight);
  25994. }
  25995. break;
  25996. case NormalAnimationBlendMode:
  25997. default:
  25998. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  25999. _interpolants[_j].evaluate(clipTime);
  26000. propertyMixers[_j].accumulate(accuIndex, weight);
  26001. }
  26002. }
  26003. }
  26004. };
  26005. _proto._updateWeight = function _updateWeight(time) {
  26006. var weight = 0;
  26007. if (this.enabled) {
  26008. weight = this.weight;
  26009. var interpolant = this._weightInterpolant;
  26010. if (interpolant !== null) {
  26011. var interpolantValue = interpolant.evaluate(time)[0];
  26012. weight *= interpolantValue;
  26013. if (time > interpolant.parameterPositions[1]) {
  26014. this.stopFading();
  26015. if (interpolantValue === 0) {
  26016. // faded out, disable
  26017. this.enabled = false;
  26018. }
  26019. }
  26020. }
  26021. }
  26022. this._effectiveWeight = weight;
  26023. return weight;
  26024. };
  26025. _proto._updateTimeScale = function _updateTimeScale(time) {
  26026. var timeScale = 0;
  26027. if (!this.paused) {
  26028. timeScale = this.timeScale;
  26029. var interpolant = this._timeScaleInterpolant;
  26030. if (interpolant !== null) {
  26031. var interpolantValue = interpolant.evaluate(time)[0];
  26032. timeScale *= interpolantValue;
  26033. if (time > interpolant.parameterPositions[1]) {
  26034. this.stopWarping();
  26035. if (timeScale === 0) {
  26036. // motion has halted, pause
  26037. this.paused = true;
  26038. } else {
  26039. // warp done - apply final time scale
  26040. this.timeScale = timeScale;
  26041. }
  26042. }
  26043. }
  26044. }
  26045. this._effectiveTimeScale = timeScale;
  26046. return timeScale;
  26047. };
  26048. _proto._updateTime = function _updateTime(deltaTime) {
  26049. var duration = this._clip.duration;
  26050. var loop = this.loop;
  26051. var time = this.time + deltaTime;
  26052. var loopCount = this._loopCount;
  26053. var pingPong = loop === LoopPingPong;
  26054. if (deltaTime === 0) {
  26055. if (loopCount === -1) return time;
  26056. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  26057. }
  26058. if (loop === LoopOnce) {
  26059. if (loopCount === -1) {
  26060. // just started
  26061. this._loopCount = 0;
  26062. this._setEndings(true, true, false);
  26063. }
  26064. handle_stop: {
  26065. if (time >= duration) {
  26066. time = duration;
  26067. } else if (time < 0) {
  26068. time = 0;
  26069. } else {
  26070. this.time = time;
  26071. break handle_stop;
  26072. }
  26073. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26074. this.time = time;
  26075. this._mixer.dispatchEvent({
  26076. type: 'finished',
  26077. action: this,
  26078. direction: deltaTime < 0 ? -1 : 1
  26079. });
  26080. }
  26081. } else {
  26082. // repetitive Repeat or PingPong
  26083. if (loopCount === -1) {
  26084. // just started
  26085. if (deltaTime >= 0) {
  26086. loopCount = 0;
  26087. this._setEndings(true, this.repetitions === 0, pingPong);
  26088. } else {
  26089. // when looping in reverse direction, the initial
  26090. // transition through zero counts as a repetition,
  26091. // so leave loopCount at -1
  26092. this._setEndings(this.repetitions === 0, true, pingPong);
  26093. }
  26094. }
  26095. if (time >= duration || time < 0) {
  26096. // wrap around
  26097. var loopDelta = Math.floor(time / duration); // signed
  26098. time -= duration * loopDelta;
  26099. loopCount += Math.abs(loopDelta);
  26100. var pending = this.repetitions - loopCount;
  26101. if (pending <= 0) {
  26102. // have to stop (switch state, clamp time, fire event)
  26103. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26104. time = deltaTime > 0 ? duration : 0;
  26105. this.time = time;
  26106. this._mixer.dispatchEvent({
  26107. type: 'finished',
  26108. action: this,
  26109. direction: deltaTime > 0 ? 1 : -1
  26110. });
  26111. } else {
  26112. // keep running
  26113. if (pending === 1) {
  26114. // entering the last round
  26115. var atStart = deltaTime < 0;
  26116. this._setEndings(atStart, !atStart, pingPong);
  26117. } else {
  26118. this._setEndings(false, false, pingPong);
  26119. }
  26120. this._loopCount = loopCount;
  26121. this.time = time;
  26122. this._mixer.dispatchEvent({
  26123. type: 'loop',
  26124. action: this,
  26125. loopDelta: loopDelta
  26126. });
  26127. }
  26128. } else {
  26129. this.time = time;
  26130. }
  26131. if (pingPong && (loopCount & 1) === 1) {
  26132. // invert time for the "pong round"
  26133. return duration - time;
  26134. }
  26135. }
  26136. return time;
  26137. };
  26138. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  26139. var settings = this._interpolantSettings;
  26140. if (pingPong) {
  26141. settings.endingStart = ZeroSlopeEnding;
  26142. settings.endingEnd = ZeroSlopeEnding;
  26143. } else {
  26144. // assuming for LoopOnce atStart == atEnd == true
  26145. if (atStart) {
  26146. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26147. } else {
  26148. settings.endingStart = WrapAroundEnding;
  26149. }
  26150. if (atEnd) {
  26151. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26152. } else {
  26153. settings.endingEnd = WrapAroundEnding;
  26154. }
  26155. }
  26156. };
  26157. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  26158. var mixer = this._mixer,
  26159. now = mixer.time;
  26160. var interpolant = this._weightInterpolant;
  26161. if (interpolant === null) {
  26162. interpolant = mixer._lendControlInterpolant();
  26163. this._weightInterpolant = interpolant;
  26164. }
  26165. var times = interpolant.parameterPositions,
  26166. values = interpolant.sampleValues;
  26167. times[0] = now;
  26168. values[0] = weightNow;
  26169. times[1] = now + duration;
  26170. values[1] = weightThen;
  26171. return this;
  26172. };
  26173. return AnimationAction;
  26174. }();
  26175. function AnimationMixer(root) {
  26176. this._root = root;
  26177. this._initMemoryManager();
  26178. this._accuIndex = 0;
  26179. this.time = 0;
  26180. this.timeScale = 1.0;
  26181. }
  26182. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  26183. constructor: AnimationMixer,
  26184. _bindAction: function _bindAction(action, prototypeAction) {
  26185. var root = action._localRoot || this._root,
  26186. tracks = action._clip.tracks,
  26187. nTracks = tracks.length,
  26188. bindings = action._propertyBindings,
  26189. interpolants = action._interpolants,
  26190. rootUuid = root.uuid,
  26191. bindingsByRoot = this._bindingsByRootAndName;
  26192. var bindingsByName = bindingsByRoot[rootUuid];
  26193. if (bindingsByName === undefined) {
  26194. bindingsByName = {};
  26195. bindingsByRoot[rootUuid] = bindingsByName;
  26196. }
  26197. for (var i = 0; i !== nTracks; ++i) {
  26198. var track = tracks[i],
  26199. trackName = track.name;
  26200. var binding = bindingsByName[trackName];
  26201. if (binding !== undefined) {
  26202. bindings[i] = binding;
  26203. } else {
  26204. binding = bindings[i];
  26205. if (binding !== undefined) {
  26206. // existing binding, make sure the cache knows
  26207. if (binding._cacheIndex === null) {
  26208. ++binding.referenceCount;
  26209. this._addInactiveBinding(binding, rootUuid, trackName);
  26210. }
  26211. continue;
  26212. }
  26213. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  26214. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  26215. ++binding.referenceCount;
  26216. this._addInactiveBinding(binding, rootUuid, trackName);
  26217. bindings[i] = binding;
  26218. }
  26219. interpolants[i].resultBuffer = binding.buffer;
  26220. }
  26221. },
  26222. _activateAction: function _activateAction(action) {
  26223. if (!this._isActiveAction(action)) {
  26224. if (action._cacheIndex === null) {
  26225. // this action has been forgotten by the cache, but the user
  26226. // appears to be still using it -> rebind
  26227. var rootUuid = (action._localRoot || this._root).uuid,
  26228. clipUuid = action._clip.uuid,
  26229. actionsForClip = this._actionsByClip[clipUuid];
  26230. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  26231. this._addInactiveAction(action, clipUuid, rootUuid);
  26232. }
  26233. var bindings = action._propertyBindings; // increment reference counts / sort out state
  26234. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26235. var binding = bindings[i];
  26236. if (binding.useCount++ === 0) {
  26237. this._lendBinding(binding);
  26238. binding.saveOriginalState();
  26239. }
  26240. }
  26241. this._lendAction(action);
  26242. }
  26243. },
  26244. _deactivateAction: function _deactivateAction(action) {
  26245. if (this._isActiveAction(action)) {
  26246. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  26247. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26248. var binding = bindings[i];
  26249. if (--binding.useCount === 0) {
  26250. binding.restoreOriginalState();
  26251. this._takeBackBinding(binding);
  26252. }
  26253. }
  26254. this._takeBackAction(action);
  26255. }
  26256. },
  26257. // Memory manager
  26258. _initMemoryManager: function _initMemoryManager() {
  26259. this._actions = []; // 'nActiveActions' followed by inactive ones
  26260. this._nActiveActions = 0;
  26261. this._actionsByClip = {}; // inside:
  26262. // {
  26263. // knownActions: Array< AnimationAction > - used as prototypes
  26264. // actionByRoot: AnimationAction - lookup
  26265. // }
  26266. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  26267. this._nActiveBindings = 0;
  26268. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  26269. this._controlInterpolants = []; // same game as above
  26270. this._nActiveControlInterpolants = 0;
  26271. var scope = this;
  26272. this.stats = {
  26273. actions: {
  26274. get total() {
  26275. return scope._actions.length;
  26276. },
  26277. get inUse() {
  26278. return scope._nActiveActions;
  26279. }
  26280. },
  26281. bindings: {
  26282. get total() {
  26283. return scope._bindings.length;
  26284. },
  26285. get inUse() {
  26286. return scope._nActiveBindings;
  26287. }
  26288. },
  26289. controlInterpolants: {
  26290. get total() {
  26291. return scope._controlInterpolants.length;
  26292. },
  26293. get inUse() {
  26294. return scope._nActiveControlInterpolants;
  26295. }
  26296. }
  26297. };
  26298. },
  26299. // Memory management for AnimationAction objects
  26300. _isActiveAction: function _isActiveAction(action) {
  26301. var index = action._cacheIndex;
  26302. return index !== null && index < this._nActiveActions;
  26303. },
  26304. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  26305. var actions = this._actions,
  26306. actionsByClip = this._actionsByClip;
  26307. var actionsForClip = actionsByClip[clipUuid];
  26308. if (actionsForClip === undefined) {
  26309. actionsForClip = {
  26310. knownActions: [action],
  26311. actionByRoot: {}
  26312. };
  26313. action._byClipCacheIndex = 0;
  26314. actionsByClip[clipUuid] = actionsForClip;
  26315. } else {
  26316. var knownActions = actionsForClip.knownActions;
  26317. action._byClipCacheIndex = knownActions.length;
  26318. knownActions.push(action);
  26319. }
  26320. action._cacheIndex = actions.length;
  26321. actions.push(action);
  26322. actionsForClip.actionByRoot[rootUuid] = action;
  26323. },
  26324. _removeInactiveAction: function _removeInactiveAction(action) {
  26325. var actions = this._actions,
  26326. lastInactiveAction = actions[actions.length - 1],
  26327. cacheIndex = action._cacheIndex;
  26328. lastInactiveAction._cacheIndex = cacheIndex;
  26329. actions[cacheIndex] = lastInactiveAction;
  26330. actions.pop();
  26331. action._cacheIndex = null;
  26332. var clipUuid = action._clip.uuid,
  26333. actionsByClip = this._actionsByClip,
  26334. actionsForClip = actionsByClip[clipUuid],
  26335. knownActionsForClip = actionsForClip.knownActions,
  26336. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  26337. byClipCacheIndex = action._byClipCacheIndex;
  26338. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26339. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  26340. knownActionsForClip.pop();
  26341. action._byClipCacheIndex = null;
  26342. var actionByRoot = actionsForClip.actionByRoot,
  26343. rootUuid = (action._localRoot || this._root).uuid;
  26344. delete actionByRoot[rootUuid];
  26345. if (knownActionsForClip.length === 0) {
  26346. delete actionsByClip[clipUuid];
  26347. }
  26348. this._removeInactiveBindingsForAction(action);
  26349. },
  26350. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  26351. var bindings = action._propertyBindings;
  26352. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26353. var binding = bindings[i];
  26354. if (--binding.referenceCount === 0) {
  26355. this._removeInactiveBinding(binding);
  26356. }
  26357. }
  26358. },
  26359. _lendAction: function _lendAction(action) {
  26360. // [ active actions | inactive actions ]
  26361. // [ active actions >| inactive actions ]
  26362. // s a
  26363. // <-swap->
  26364. // a s
  26365. var actions = this._actions,
  26366. prevIndex = action._cacheIndex,
  26367. lastActiveIndex = this._nActiveActions++,
  26368. firstInactiveAction = actions[lastActiveIndex];
  26369. action._cacheIndex = lastActiveIndex;
  26370. actions[lastActiveIndex] = action;
  26371. firstInactiveAction._cacheIndex = prevIndex;
  26372. actions[prevIndex] = firstInactiveAction;
  26373. },
  26374. _takeBackAction: function _takeBackAction(action) {
  26375. // [ active actions | inactive actions ]
  26376. // [ active actions |< inactive actions ]
  26377. // a s
  26378. // <-swap->
  26379. // s a
  26380. var actions = this._actions,
  26381. prevIndex = action._cacheIndex,
  26382. firstInactiveIndex = --this._nActiveActions,
  26383. lastActiveAction = actions[firstInactiveIndex];
  26384. action._cacheIndex = firstInactiveIndex;
  26385. actions[firstInactiveIndex] = action;
  26386. lastActiveAction._cacheIndex = prevIndex;
  26387. actions[prevIndex] = lastActiveAction;
  26388. },
  26389. // Memory management for PropertyMixer objects
  26390. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  26391. var bindingsByRoot = this._bindingsByRootAndName,
  26392. bindings = this._bindings;
  26393. var bindingByName = bindingsByRoot[rootUuid];
  26394. if (bindingByName === undefined) {
  26395. bindingByName = {};
  26396. bindingsByRoot[rootUuid] = bindingByName;
  26397. }
  26398. bindingByName[trackName] = binding;
  26399. binding._cacheIndex = bindings.length;
  26400. bindings.push(binding);
  26401. },
  26402. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  26403. var bindings = this._bindings,
  26404. propBinding = binding.binding,
  26405. rootUuid = propBinding.rootNode.uuid,
  26406. trackName = propBinding.path,
  26407. bindingsByRoot = this._bindingsByRootAndName,
  26408. bindingByName = bindingsByRoot[rootUuid],
  26409. lastInactiveBinding = bindings[bindings.length - 1],
  26410. cacheIndex = binding._cacheIndex;
  26411. lastInactiveBinding._cacheIndex = cacheIndex;
  26412. bindings[cacheIndex] = lastInactiveBinding;
  26413. bindings.pop();
  26414. delete bindingByName[trackName];
  26415. if (Object.keys(bindingByName).length === 0) {
  26416. delete bindingsByRoot[rootUuid];
  26417. }
  26418. },
  26419. _lendBinding: function _lendBinding(binding) {
  26420. var bindings = this._bindings,
  26421. prevIndex = binding._cacheIndex,
  26422. lastActiveIndex = this._nActiveBindings++,
  26423. firstInactiveBinding = bindings[lastActiveIndex];
  26424. binding._cacheIndex = lastActiveIndex;
  26425. bindings[lastActiveIndex] = binding;
  26426. firstInactiveBinding._cacheIndex = prevIndex;
  26427. bindings[prevIndex] = firstInactiveBinding;
  26428. },
  26429. _takeBackBinding: function _takeBackBinding(binding) {
  26430. var bindings = this._bindings,
  26431. prevIndex = binding._cacheIndex,
  26432. firstInactiveIndex = --this._nActiveBindings,
  26433. lastActiveBinding = bindings[firstInactiveIndex];
  26434. binding._cacheIndex = firstInactiveIndex;
  26435. bindings[firstInactiveIndex] = binding;
  26436. lastActiveBinding._cacheIndex = prevIndex;
  26437. bindings[prevIndex] = lastActiveBinding;
  26438. },
  26439. // Memory management of Interpolants for weight and time scale
  26440. _lendControlInterpolant: function _lendControlInterpolant() {
  26441. var interpolants = this._controlInterpolants,
  26442. lastActiveIndex = this._nActiveControlInterpolants++;
  26443. var interpolant = interpolants[lastActiveIndex];
  26444. if (interpolant === undefined) {
  26445. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  26446. interpolant.__cacheIndex = lastActiveIndex;
  26447. interpolants[lastActiveIndex] = interpolant;
  26448. }
  26449. return interpolant;
  26450. },
  26451. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  26452. var interpolants = this._controlInterpolants,
  26453. prevIndex = interpolant.__cacheIndex,
  26454. firstInactiveIndex = --this._nActiveControlInterpolants,
  26455. lastActiveInterpolant = interpolants[firstInactiveIndex];
  26456. interpolant.__cacheIndex = firstInactiveIndex;
  26457. interpolants[firstInactiveIndex] = interpolant;
  26458. lastActiveInterpolant.__cacheIndex = prevIndex;
  26459. interpolants[prevIndex] = lastActiveInterpolant;
  26460. },
  26461. _controlInterpolantsResultBuffer: new Float32Array(1),
  26462. // return an action for a clip optionally using a custom root target
  26463. // object (this method allocates a lot of dynamic memory in case a
  26464. // previously unknown clip/root combination is specified)
  26465. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  26466. var root = optionalRoot || this._root,
  26467. rootUuid = root.uuid;
  26468. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  26469. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  26470. var actionsForClip = this._actionsByClip[clipUuid];
  26471. var prototypeAction = null;
  26472. if (blendMode === undefined) {
  26473. if (clipObject !== null) {
  26474. blendMode = clipObject.blendMode;
  26475. } else {
  26476. blendMode = NormalAnimationBlendMode;
  26477. }
  26478. }
  26479. if (actionsForClip !== undefined) {
  26480. var existingAction = actionsForClip.actionByRoot[rootUuid];
  26481. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  26482. return existingAction;
  26483. } // we know the clip, so we don't have to parse all
  26484. // the bindings again but can just copy
  26485. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  26486. if (clipObject === null) clipObject = prototypeAction._clip;
  26487. } // clip must be known when specified via string
  26488. if (clipObject === null) return null; // allocate all resources required to run it
  26489. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  26490. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  26491. this._addInactiveAction(newAction, clipUuid, rootUuid);
  26492. return newAction;
  26493. },
  26494. // get an existing action
  26495. existingAction: function existingAction(clip, optionalRoot) {
  26496. var root = optionalRoot || this._root,
  26497. rootUuid = root.uuid,
  26498. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  26499. clipUuid = clipObject ? clipObject.uuid : clip,
  26500. actionsForClip = this._actionsByClip[clipUuid];
  26501. if (actionsForClip !== undefined) {
  26502. return actionsForClip.actionByRoot[rootUuid] || null;
  26503. }
  26504. return null;
  26505. },
  26506. // deactivates all previously scheduled actions
  26507. stopAllAction: function stopAllAction() {
  26508. var actions = this._actions,
  26509. nActions = this._nActiveActions;
  26510. for (var i = nActions - 1; i >= 0; --i) {
  26511. actions[i].stop();
  26512. }
  26513. return this;
  26514. },
  26515. // advance the time and update apply the animation
  26516. update: function update(deltaTime) {
  26517. deltaTime *= this.timeScale;
  26518. var actions = this._actions,
  26519. nActions = this._nActiveActions,
  26520. time = this.time += deltaTime,
  26521. timeDirection = Math.sign(deltaTime),
  26522. accuIndex = this._accuIndex ^= 1; // run active actions
  26523. for (var i = 0; i !== nActions; ++i) {
  26524. var action = actions[i];
  26525. action._update(time, deltaTime, timeDirection, accuIndex);
  26526. } // update scene graph
  26527. var bindings = this._bindings,
  26528. nBindings = this._nActiveBindings;
  26529. for (var _i = 0; _i !== nBindings; ++_i) {
  26530. bindings[_i].apply(accuIndex);
  26531. }
  26532. return this;
  26533. },
  26534. // Allows you to seek to a specific time in an animation.
  26535. setTime: function setTime(timeInSeconds) {
  26536. this.time = 0; // Zero out time attribute for AnimationMixer object;
  26537. for (var i = 0; i < this._actions.length; i++) {
  26538. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  26539. }
  26540. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  26541. },
  26542. // return this mixer's root target object
  26543. getRoot: function getRoot() {
  26544. return this._root;
  26545. },
  26546. // free all resources specific to a particular clip
  26547. uncacheClip: function uncacheClip(clip) {
  26548. var actions = this._actions,
  26549. clipUuid = clip.uuid,
  26550. actionsByClip = this._actionsByClip,
  26551. actionsForClip = actionsByClip[clipUuid];
  26552. if (actionsForClip !== undefined) {
  26553. // note: just calling _removeInactiveAction would mess up the
  26554. // iteration state and also require updating the state we can
  26555. // just throw away
  26556. var actionsToRemove = actionsForClip.knownActions;
  26557. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  26558. var action = actionsToRemove[i];
  26559. this._deactivateAction(action);
  26560. var cacheIndex = action._cacheIndex,
  26561. lastInactiveAction = actions[actions.length - 1];
  26562. action._cacheIndex = null;
  26563. action._byClipCacheIndex = null;
  26564. lastInactiveAction._cacheIndex = cacheIndex;
  26565. actions[cacheIndex] = lastInactiveAction;
  26566. actions.pop();
  26567. this._removeInactiveBindingsForAction(action);
  26568. }
  26569. delete actionsByClip[clipUuid];
  26570. }
  26571. },
  26572. // free all resources specific to a particular root target object
  26573. uncacheRoot: function uncacheRoot(root) {
  26574. var rootUuid = root.uuid,
  26575. actionsByClip = this._actionsByClip;
  26576. for (var clipUuid in actionsByClip) {
  26577. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  26578. action = actionByRoot[rootUuid];
  26579. if (action !== undefined) {
  26580. this._deactivateAction(action);
  26581. this._removeInactiveAction(action);
  26582. }
  26583. }
  26584. var bindingsByRoot = this._bindingsByRootAndName,
  26585. bindingByName = bindingsByRoot[rootUuid];
  26586. if (bindingByName !== undefined) {
  26587. for (var trackName in bindingByName) {
  26588. var binding = bindingByName[trackName];
  26589. binding.restoreOriginalState();
  26590. this._removeInactiveBinding(binding);
  26591. }
  26592. }
  26593. },
  26594. // remove a targeted clip from the cache
  26595. uncacheAction: function uncacheAction(clip, optionalRoot) {
  26596. var action = this.existingAction(clip, optionalRoot);
  26597. if (action !== null) {
  26598. this._deactivateAction(action);
  26599. this._removeInactiveAction(action);
  26600. }
  26601. }
  26602. });
  26603. var Uniform = /*#__PURE__*/function () {
  26604. function Uniform(value) {
  26605. if (typeof value === 'string') {
  26606. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  26607. value = arguments[1];
  26608. }
  26609. this.value = value;
  26610. }
  26611. var _proto = Uniform.prototype;
  26612. _proto.clone = function clone() {
  26613. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  26614. };
  26615. return Uniform;
  26616. }();
  26617. var _geometryId = 0; // Geometry uses even numbers as Id
  26618. var _m1$3 = new Matrix4();
  26619. var _obj$1 = new Object3D();
  26620. var _offset$1 = new Vector3();
  26621. function Geometry() {
  26622. Object.defineProperty(this, 'id', {
  26623. value: _geometryId += 2
  26624. });
  26625. this.uuid = MathUtils.generateUUID();
  26626. this.name = '';
  26627. this.type = 'Geometry';
  26628. this.vertices = [];
  26629. this.colors = [];
  26630. this.faces = [];
  26631. this.faceVertexUvs = [[]];
  26632. this.morphTargets = [];
  26633. this.morphNormals = [];
  26634. this.skinWeights = [];
  26635. this.skinIndices = [];
  26636. this.lineDistances = [];
  26637. this.boundingBox = null;
  26638. this.boundingSphere = null; // update flags
  26639. this.elementsNeedUpdate = false;
  26640. this.verticesNeedUpdate = false;
  26641. this.uvsNeedUpdate = false;
  26642. this.normalsNeedUpdate = false;
  26643. this.colorsNeedUpdate = false;
  26644. this.lineDistancesNeedUpdate = false;
  26645. this.groupsNeedUpdate = false;
  26646. }
  26647. Geometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  26648. constructor: Geometry,
  26649. isGeometry: true,
  26650. applyMatrix4: function applyMatrix4(matrix) {
  26651. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  26652. for (var i = 0, il = this.vertices.length; i < il; i++) {
  26653. var vertex = this.vertices[i];
  26654. vertex.applyMatrix4(matrix);
  26655. }
  26656. for (var _i = 0, _il = this.faces.length; _i < _il; _i++) {
  26657. var face = this.faces[_i];
  26658. face.normal.applyMatrix3(normalMatrix).normalize();
  26659. for (var j = 0, jl = face.vertexNormals.length; j < jl; j++) {
  26660. face.vertexNormals[j].applyMatrix3(normalMatrix).normalize();
  26661. }
  26662. }
  26663. if (this.boundingBox !== null) {
  26664. this.computeBoundingBox();
  26665. }
  26666. if (this.boundingSphere !== null) {
  26667. this.computeBoundingSphere();
  26668. }
  26669. this.verticesNeedUpdate = true;
  26670. this.normalsNeedUpdate = true;
  26671. return this;
  26672. },
  26673. rotateX: function rotateX(angle) {
  26674. // rotate geometry around world x-axis
  26675. _m1$3.makeRotationX(angle);
  26676. this.applyMatrix4(_m1$3);
  26677. return this;
  26678. },
  26679. rotateY: function rotateY(angle) {
  26680. // rotate geometry around world y-axis
  26681. _m1$3.makeRotationY(angle);
  26682. this.applyMatrix4(_m1$3);
  26683. return this;
  26684. },
  26685. rotateZ: function rotateZ(angle) {
  26686. // rotate geometry around world z-axis
  26687. _m1$3.makeRotationZ(angle);
  26688. this.applyMatrix4(_m1$3);
  26689. return this;
  26690. },
  26691. translate: function translate(x, y, z) {
  26692. // translate geometry
  26693. _m1$3.makeTranslation(x, y, z);
  26694. this.applyMatrix4(_m1$3);
  26695. return this;
  26696. },
  26697. scale: function scale(x, y, z) {
  26698. // scale geometry
  26699. _m1$3.makeScale(x, y, z);
  26700. this.applyMatrix4(_m1$3);
  26701. return this;
  26702. },
  26703. lookAt: function lookAt(vector) {
  26704. _obj$1.lookAt(vector);
  26705. _obj$1.updateMatrix();
  26706. this.applyMatrix4(_obj$1.matrix);
  26707. return this;
  26708. },
  26709. fromBufferGeometry: function fromBufferGeometry(geometry) {
  26710. var scope = this;
  26711. var index = geometry.index !== null ? geometry.index : undefined;
  26712. var attributes = geometry.attributes;
  26713. if (attributes.position === undefined) {
  26714. console.error('THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.');
  26715. return this;
  26716. }
  26717. var position = attributes.position;
  26718. var normal = attributes.normal;
  26719. var color = attributes.color;
  26720. var uv = attributes.uv;
  26721. var uv2 = attributes.uv2;
  26722. if (uv2 !== undefined) this.faceVertexUvs[1] = [];
  26723. for (var i = 0; i < position.count; i++) {
  26724. scope.vertices.push(new Vector3().fromBufferAttribute(position, i));
  26725. if (color !== undefined) {
  26726. scope.colors.push(new Color().fromBufferAttribute(color, i));
  26727. }
  26728. }
  26729. function addFace(a, b, c, materialIndex) {
  26730. var vertexColors = color === undefined ? [] : [scope.colors[a].clone(), scope.colors[b].clone(), scope.colors[c].clone()];
  26731. var vertexNormals = normal === undefined ? [] : [new Vector3().fromBufferAttribute(normal, a), new Vector3().fromBufferAttribute(normal, b), new Vector3().fromBufferAttribute(normal, c)];
  26732. var face = new Face3(a, b, c, vertexNormals, vertexColors, materialIndex);
  26733. scope.faces.push(face);
  26734. if (uv !== undefined) {
  26735. scope.faceVertexUvs[0].push([new Vector2().fromBufferAttribute(uv, a), new Vector2().fromBufferAttribute(uv, b), new Vector2().fromBufferAttribute(uv, c)]);
  26736. }
  26737. if (uv2 !== undefined) {
  26738. scope.faceVertexUvs[1].push([new Vector2().fromBufferAttribute(uv2, a), new Vector2().fromBufferAttribute(uv2, b), new Vector2().fromBufferAttribute(uv2, c)]);
  26739. }
  26740. }
  26741. var groups = geometry.groups;
  26742. if (groups.length > 0) {
  26743. for (var _i2 = 0; _i2 < groups.length; _i2++) {
  26744. var group = groups[_i2];
  26745. var start = group.start;
  26746. var count = group.count;
  26747. for (var j = start, jl = start + count; j < jl; j += 3) {
  26748. if (index !== undefined) {
  26749. addFace(index.getX(j), index.getX(j + 1), index.getX(j + 2), group.materialIndex);
  26750. } else {
  26751. addFace(j, j + 1, j + 2, group.materialIndex);
  26752. }
  26753. }
  26754. }
  26755. } else {
  26756. if (index !== undefined) {
  26757. for (var _i3 = 0; _i3 < index.count; _i3 += 3) {
  26758. addFace(index.getX(_i3), index.getX(_i3 + 1), index.getX(_i3 + 2));
  26759. }
  26760. } else {
  26761. for (var _i4 = 0; _i4 < position.count; _i4 += 3) {
  26762. addFace(_i4, _i4 + 1, _i4 + 2);
  26763. }
  26764. }
  26765. }
  26766. this.computeFaceNormals();
  26767. if (geometry.boundingBox !== null) {
  26768. this.boundingBox = geometry.boundingBox.clone();
  26769. }
  26770. if (geometry.boundingSphere !== null) {
  26771. this.boundingSphere = geometry.boundingSphere.clone();
  26772. }
  26773. return this;
  26774. },
  26775. center: function center() {
  26776. this.computeBoundingBox();
  26777. this.boundingBox.getCenter(_offset$1).negate();
  26778. this.translate(_offset$1.x, _offset$1.y, _offset$1.z);
  26779. return this;
  26780. },
  26781. normalize: function normalize() {
  26782. this.computeBoundingSphere();
  26783. var center = this.boundingSphere.center;
  26784. var radius = this.boundingSphere.radius;
  26785. var s = radius === 0 ? 1 : 1.0 / radius;
  26786. var matrix = new Matrix4();
  26787. matrix.set(s, 0, 0, -s * center.x, 0, s, 0, -s * center.y, 0, 0, s, -s * center.z, 0, 0, 0, 1);
  26788. this.applyMatrix4(matrix);
  26789. return this;
  26790. },
  26791. computeFaceNormals: function computeFaceNormals() {
  26792. var cb = new Vector3(),
  26793. ab = new Vector3();
  26794. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  26795. var face = this.faces[f];
  26796. var vA = this.vertices[face.a];
  26797. var vB = this.vertices[face.b];
  26798. var vC = this.vertices[face.c];
  26799. cb.subVectors(vC, vB);
  26800. ab.subVectors(vA, vB);
  26801. cb.cross(ab);
  26802. cb.normalize();
  26803. face.normal.copy(cb);
  26804. }
  26805. },
  26806. computeVertexNormals: function computeVertexNormals(areaWeighted) {
  26807. if (areaWeighted === void 0) {
  26808. areaWeighted = true;
  26809. }
  26810. var vertices = new Array(this.vertices.length);
  26811. for (var v = 0, vl = this.vertices.length; v < vl; v++) {
  26812. vertices[v] = new Vector3();
  26813. }
  26814. if (areaWeighted) {
  26815. // vertex normals weighted by triangle areas
  26816. // http://www.iquilezles.org/www/articles/normals/normals.htm
  26817. var cb = new Vector3(),
  26818. ab = new Vector3();
  26819. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  26820. var face = this.faces[f];
  26821. var vA = this.vertices[face.a];
  26822. var vB = this.vertices[face.b];
  26823. var vC = this.vertices[face.c];
  26824. cb.subVectors(vC, vB);
  26825. ab.subVectors(vA, vB);
  26826. cb.cross(ab);
  26827. vertices[face.a].add(cb);
  26828. vertices[face.b].add(cb);
  26829. vertices[face.c].add(cb);
  26830. }
  26831. } else {
  26832. this.computeFaceNormals();
  26833. for (var _f = 0, _fl = this.faces.length; _f < _fl; _f++) {
  26834. var _face = this.faces[_f];
  26835. vertices[_face.a].add(_face.normal);
  26836. vertices[_face.b].add(_face.normal);
  26837. vertices[_face.c].add(_face.normal);
  26838. }
  26839. }
  26840. for (var _v = 0, _vl = this.vertices.length; _v < _vl; _v++) {
  26841. vertices[_v].normalize();
  26842. }
  26843. for (var _f2 = 0, _fl2 = this.faces.length; _f2 < _fl2; _f2++) {
  26844. var _face2 = this.faces[_f2];
  26845. var vertexNormals = _face2.vertexNormals;
  26846. if (vertexNormals.length === 3) {
  26847. vertexNormals[0].copy(vertices[_face2.a]);
  26848. vertexNormals[1].copy(vertices[_face2.b]);
  26849. vertexNormals[2].copy(vertices[_face2.c]);
  26850. } else {
  26851. vertexNormals[0] = vertices[_face2.a].clone();
  26852. vertexNormals[1] = vertices[_face2.b].clone();
  26853. vertexNormals[2] = vertices[_face2.c].clone();
  26854. }
  26855. }
  26856. if (this.faces.length > 0) {
  26857. this.normalsNeedUpdate = true;
  26858. }
  26859. },
  26860. computeFlatVertexNormals: function computeFlatVertexNormals() {
  26861. this.computeFaceNormals();
  26862. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  26863. var face = this.faces[f];
  26864. var vertexNormals = face.vertexNormals;
  26865. if (vertexNormals.length === 3) {
  26866. vertexNormals[0].copy(face.normal);
  26867. vertexNormals[1].copy(face.normal);
  26868. vertexNormals[2].copy(face.normal);
  26869. } else {
  26870. vertexNormals[0] = face.normal.clone();
  26871. vertexNormals[1] = face.normal.clone();
  26872. vertexNormals[2] = face.normal.clone();
  26873. }
  26874. }
  26875. if (this.faces.length > 0) {
  26876. this.normalsNeedUpdate = true;
  26877. }
  26878. },
  26879. computeMorphNormals: function computeMorphNormals() {
  26880. // save original normals
  26881. // - create temp variables on first access
  26882. // otherwise just copy (for faster repeated calls)
  26883. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  26884. var face = this.faces[f];
  26885. if (!face.__originalFaceNormal) {
  26886. face.__originalFaceNormal = face.normal.clone();
  26887. } else {
  26888. face.__originalFaceNormal.copy(face.normal);
  26889. }
  26890. if (!face.__originalVertexNormals) face.__originalVertexNormals = [];
  26891. for (var i = 0, il = face.vertexNormals.length; i < il; i++) {
  26892. if (!face.__originalVertexNormals[i]) {
  26893. face.__originalVertexNormals[i] = face.vertexNormals[i].clone();
  26894. } else {
  26895. face.__originalVertexNormals[i].copy(face.vertexNormals[i]);
  26896. }
  26897. }
  26898. } // use temp geometry to compute face and vertex normals for each morph
  26899. var tmpGeo = new Geometry();
  26900. tmpGeo.faces = this.faces;
  26901. for (var _i5 = 0, _il2 = this.morphTargets.length; _i5 < _il2; _i5++) {
  26902. // create on first access
  26903. if (!this.morphNormals[_i5]) {
  26904. this.morphNormals[_i5] = {};
  26905. this.morphNormals[_i5].faceNormals = [];
  26906. this.morphNormals[_i5].vertexNormals = [];
  26907. var dstNormalsFace = this.morphNormals[_i5].faceNormals;
  26908. var dstNormalsVertex = this.morphNormals[_i5].vertexNormals;
  26909. for (var _f3 = 0, _fl3 = this.faces.length; _f3 < _fl3; _f3++) {
  26910. var faceNormal = new Vector3();
  26911. var vertexNormals = {
  26912. a: new Vector3(),
  26913. b: new Vector3(),
  26914. c: new Vector3()
  26915. };
  26916. dstNormalsFace.push(faceNormal);
  26917. dstNormalsVertex.push(vertexNormals);
  26918. }
  26919. }
  26920. var morphNormals = this.morphNormals[_i5]; // set vertices to morph target
  26921. tmpGeo.vertices = this.morphTargets[_i5].vertices; // compute morph normals
  26922. tmpGeo.computeFaceNormals();
  26923. tmpGeo.computeVertexNormals(); // store morph normals
  26924. for (var _f4 = 0, _fl4 = this.faces.length; _f4 < _fl4; _f4++) {
  26925. var _face3 = this.faces[_f4];
  26926. var _faceNormal = morphNormals.faceNormals[_f4];
  26927. var _vertexNormals = morphNormals.vertexNormals[_f4];
  26928. _faceNormal.copy(_face3.normal);
  26929. _vertexNormals.a.copy(_face3.vertexNormals[0]);
  26930. _vertexNormals.b.copy(_face3.vertexNormals[1]);
  26931. _vertexNormals.c.copy(_face3.vertexNormals[2]);
  26932. }
  26933. } // restore original normals
  26934. for (var _f5 = 0, _fl5 = this.faces.length; _f5 < _fl5; _f5++) {
  26935. var _face4 = this.faces[_f5];
  26936. _face4.normal = _face4.__originalFaceNormal;
  26937. _face4.vertexNormals = _face4.__originalVertexNormals;
  26938. }
  26939. },
  26940. computeBoundingBox: function computeBoundingBox() {
  26941. if (this.boundingBox === null) {
  26942. this.boundingBox = new Box3();
  26943. }
  26944. this.boundingBox.setFromPoints(this.vertices);
  26945. },
  26946. computeBoundingSphere: function computeBoundingSphere() {
  26947. if (this.boundingSphere === null) {
  26948. this.boundingSphere = new Sphere();
  26949. }
  26950. this.boundingSphere.setFromPoints(this.vertices);
  26951. },
  26952. merge: function merge(geometry, matrix, materialIndexOffset) {
  26953. if (materialIndexOffset === void 0) {
  26954. materialIndexOffset = 0;
  26955. }
  26956. if (!(geometry && geometry.isGeometry)) {
  26957. console.error('THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry);
  26958. return;
  26959. }
  26960. var normalMatrix;
  26961. var vertexOffset = this.vertices.length,
  26962. vertices1 = this.vertices,
  26963. vertices2 = geometry.vertices,
  26964. faces1 = this.faces,
  26965. faces2 = geometry.faces,
  26966. colors1 = this.colors,
  26967. colors2 = geometry.colors;
  26968. if (matrix !== undefined) {
  26969. normalMatrix = new Matrix3().getNormalMatrix(matrix);
  26970. } // vertices
  26971. for (var i = 0, il = vertices2.length; i < il; i++) {
  26972. var vertex = vertices2[i];
  26973. var vertexCopy = vertex.clone();
  26974. if (matrix !== undefined) vertexCopy.applyMatrix4(matrix);
  26975. vertices1.push(vertexCopy);
  26976. } // colors
  26977. for (var _i6 = 0, _il3 = colors2.length; _i6 < _il3; _i6++) {
  26978. colors1.push(colors2[_i6].clone());
  26979. } // faces
  26980. for (var _i7 = 0, _il4 = faces2.length; _i7 < _il4; _i7++) {
  26981. var face = faces2[_i7];
  26982. var normal = void 0,
  26983. color = void 0;
  26984. var faceVertexNormals = face.vertexNormals,
  26985. faceVertexColors = face.vertexColors;
  26986. var faceCopy = new Face3(face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset);
  26987. faceCopy.normal.copy(face.normal);
  26988. if (normalMatrix !== undefined) {
  26989. faceCopy.normal.applyMatrix3(normalMatrix).normalize();
  26990. }
  26991. for (var j = 0, jl = faceVertexNormals.length; j < jl; j++) {
  26992. normal = faceVertexNormals[j].clone();
  26993. if (normalMatrix !== undefined) {
  26994. normal.applyMatrix3(normalMatrix).normalize();
  26995. }
  26996. faceCopy.vertexNormals.push(normal);
  26997. }
  26998. faceCopy.color.copy(face.color);
  26999. for (var _j = 0, _jl = faceVertexColors.length; _j < _jl; _j++) {
  27000. color = faceVertexColors[_j];
  27001. faceCopy.vertexColors.push(color.clone());
  27002. }
  27003. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  27004. faces1.push(faceCopy);
  27005. } // uvs
  27006. for (var _i8 = 0, _il5 = geometry.faceVertexUvs.length; _i8 < _il5; _i8++) {
  27007. var faceVertexUvs2 = geometry.faceVertexUvs[_i8];
  27008. if (this.faceVertexUvs[_i8] === undefined) this.faceVertexUvs[_i8] = [];
  27009. for (var _j2 = 0, _jl2 = faceVertexUvs2.length; _j2 < _jl2; _j2++) {
  27010. var uvs2 = faceVertexUvs2[_j2],
  27011. uvsCopy = [];
  27012. for (var k = 0, kl = uvs2.length; k < kl; k++) {
  27013. uvsCopy.push(uvs2[k].clone());
  27014. }
  27015. this.faceVertexUvs[_i8].push(uvsCopy);
  27016. }
  27017. }
  27018. },
  27019. mergeMesh: function mergeMesh(mesh) {
  27020. if (!(mesh && mesh.isMesh)) {
  27021. console.error('THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh);
  27022. return;
  27023. }
  27024. if (mesh.matrixAutoUpdate) mesh.updateMatrix();
  27025. this.merge(mesh.geometry, mesh.matrix);
  27026. },
  27027. /*
  27028. * Checks for duplicate vertices with hashmap.
  27029. * Duplicated vertices are removed
  27030. * and faces' vertices are updated.
  27031. */
  27032. mergeVertices: function mergeVertices(precisionPoints) {
  27033. if (precisionPoints === void 0) {
  27034. precisionPoints = 4;
  27035. }
  27036. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  27037. var unique = [],
  27038. changes = [];
  27039. var precision = Math.pow(10, precisionPoints);
  27040. for (var i = 0, il = this.vertices.length; i < il; i++) {
  27041. var v = this.vertices[i];
  27042. var key = Math.round(v.x * precision) + '_' + Math.round(v.y * precision) + '_' + Math.round(v.z * precision);
  27043. if (verticesMap[key] === undefined) {
  27044. verticesMap[key] = i;
  27045. unique.push(this.vertices[i]);
  27046. changes[i] = unique.length - 1;
  27047. } else {
  27048. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  27049. changes[i] = changes[verticesMap[key]];
  27050. }
  27051. } // if faces are completely degenerate after merging vertices, we
  27052. // have to remove them from the geometry.
  27053. var faceIndicesToRemove = [];
  27054. for (var _i9 = 0, _il6 = this.faces.length; _i9 < _il6; _i9++) {
  27055. var face = this.faces[_i9];
  27056. face.a = changes[face.a];
  27057. face.b = changes[face.b];
  27058. face.c = changes[face.c];
  27059. var indices = [face.a, face.b, face.c]; // if any duplicate vertices are found in a Face3
  27060. // we have to remove the face as nothing can be saved
  27061. for (var n = 0; n < 3; n++) {
  27062. if (indices[n] === indices[(n + 1) % 3]) {
  27063. faceIndicesToRemove.push(_i9);
  27064. break;
  27065. }
  27066. }
  27067. }
  27068. for (var _i10 = faceIndicesToRemove.length - 1; _i10 >= 0; _i10--) {
  27069. var idx = faceIndicesToRemove[_i10];
  27070. this.faces.splice(idx, 1);
  27071. for (var j = 0, jl = this.faceVertexUvs.length; j < jl; j++) {
  27072. this.faceVertexUvs[j].splice(idx, 1);
  27073. }
  27074. } // Use unique set of vertices
  27075. var diff = this.vertices.length - unique.length;
  27076. this.vertices = unique;
  27077. return diff;
  27078. },
  27079. setFromPoints: function setFromPoints(points) {
  27080. this.vertices = [];
  27081. for (var i = 0, l = points.length; i < l; i++) {
  27082. var point = points[i];
  27083. this.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  27084. }
  27085. return this;
  27086. },
  27087. sortFacesByMaterialIndex: function sortFacesByMaterialIndex() {
  27088. var faces = this.faces;
  27089. var length = faces.length; // tag faces
  27090. for (var i = 0; i < length; i++) {
  27091. faces[i]._id = i;
  27092. } // sort faces
  27093. function materialIndexSort(a, b) {
  27094. return a.materialIndex - b.materialIndex;
  27095. }
  27096. faces.sort(materialIndexSort); // sort uvs
  27097. var uvs1 = this.faceVertexUvs[0];
  27098. var uvs2 = this.faceVertexUvs[1];
  27099. var newUvs1, newUvs2;
  27100. if (uvs1 && uvs1.length === length) newUvs1 = [];
  27101. if (uvs2 && uvs2.length === length) newUvs2 = [];
  27102. for (var _i11 = 0; _i11 < length; _i11++) {
  27103. var id = faces[_i11]._id;
  27104. if (newUvs1) newUvs1.push(uvs1[id]);
  27105. if (newUvs2) newUvs2.push(uvs2[id]);
  27106. }
  27107. if (newUvs1) this.faceVertexUvs[0] = newUvs1;
  27108. if (newUvs2) this.faceVertexUvs[1] = newUvs2;
  27109. },
  27110. toJSON: function toJSON() {
  27111. var data = {
  27112. metadata: {
  27113. version: 4.5,
  27114. type: 'Geometry',
  27115. generator: 'Geometry.toJSON'
  27116. }
  27117. }; // standard Geometry serialization
  27118. data.uuid = this.uuid;
  27119. data.type = this.type;
  27120. if (this.name !== '') data.name = this.name;
  27121. if (this.parameters !== undefined) {
  27122. var parameters = this.parameters;
  27123. for (var key in parameters) {
  27124. if (parameters[key] !== undefined) data[key] = parameters[key];
  27125. }
  27126. return data;
  27127. }
  27128. var vertices = [];
  27129. for (var i = 0; i < this.vertices.length; i++) {
  27130. var vertex = this.vertices[i];
  27131. vertices.push(vertex.x, vertex.y, vertex.z);
  27132. }
  27133. var faces = [];
  27134. var normals = [];
  27135. var normalsHash = {};
  27136. var colors = [];
  27137. var colorsHash = {};
  27138. var uvs = [];
  27139. var uvsHash = {};
  27140. for (var _i12 = 0; _i12 < this.faces.length; _i12++) {
  27141. var face = this.faces[_i12];
  27142. var hasMaterial = true;
  27143. var hasFaceUv = false; // deprecated
  27144. var hasFaceVertexUv = this.faceVertexUvs[0][_i12] !== undefined;
  27145. var hasFaceNormal = face.normal.length() > 0;
  27146. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  27147. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  27148. var hasFaceVertexColor = face.vertexColors.length > 0;
  27149. var faceType = 0;
  27150. faceType = setBit(faceType, 0, 0); // isQuad
  27151. faceType = setBit(faceType, 1, hasMaterial);
  27152. faceType = setBit(faceType, 2, hasFaceUv);
  27153. faceType = setBit(faceType, 3, hasFaceVertexUv);
  27154. faceType = setBit(faceType, 4, hasFaceNormal);
  27155. faceType = setBit(faceType, 5, hasFaceVertexNormal);
  27156. faceType = setBit(faceType, 6, hasFaceColor);
  27157. faceType = setBit(faceType, 7, hasFaceVertexColor);
  27158. faces.push(faceType);
  27159. faces.push(face.a, face.b, face.c);
  27160. faces.push(face.materialIndex);
  27161. if (hasFaceVertexUv) {
  27162. var faceVertexUvs = this.faceVertexUvs[0][_i12];
  27163. faces.push(getUvIndex(faceVertexUvs[0]), getUvIndex(faceVertexUvs[1]), getUvIndex(faceVertexUvs[2]));
  27164. }
  27165. if (hasFaceNormal) {
  27166. faces.push(getNormalIndex(face.normal));
  27167. }
  27168. if (hasFaceVertexNormal) {
  27169. var vertexNormals = face.vertexNormals;
  27170. faces.push(getNormalIndex(vertexNormals[0]), getNormalIndex(vertexNormals[1]), getNormalIndex(vertexNormals[2]));
  27171. }
  27172. if (hasFaceColor) {
  27173. faces.push(getColorIndex(face.color));
  27174. }
  27175. if (hasFaceVertexColor) {
  27176. var vertexColors = face.vertexColors;
  27177. faces.push(getColorIndex(vertexColors[0]), getColorIndex(vertexColors[1]), getColorIndex(vertexColors[2]));
  27178. }
  27179. }
  27180. function setBit(value, position, enabled) {
  27181. return enabled ? value | 1 << position : value & ~(1 << position);
  27182. }
  27183. function getNormalIndex(normal) {
  27184. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  27185. if (normalsHash[hash] !== undefined) {
  27186. return normalsHash[hash];
  27187. }
  27188. normalsHash[hash] = normals.length / 3;
  27189. normals.push(normal.x, normal.y, normal.z);
  27190. return normalsHash[hash];
  27191. }
  27192. function getColorIndex(color) {
  27193. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  27194. if (colorsHash[hash] !== undefined) {
  27195. return colorsHash[hash];
  27196. }
  27197. colorsHash[hash] = colors.length;
  27198. colors.push(color.getHex());
  27199. return colorsHash[hash];
  27200. }
  27201. function getUvIndex(uv) {
  27202. var hash = uv.x.toString() + uv.y.toString();
  27203. if (uvsHash[hash] !== undefined) {
  27204. return uvsHash[hash];
  27205. }
  27206. uvsHash[hash] = uvs.length / 2;
  27207. uvs.push(uv.x, uv.y);
  27208. return uvsHash[hash];
  27209. }
  27210. data.data = {};
  27211. data.data.vertices = vertices;
  27212. data.data.normals = normals;
  27213. if (colors.length > 0) data.data.colors = colors;
  27214. if (uvs.length > 0) data.data.uvs = [uvs]; // temporal backward compatibility
  27215. data.data.faces = faces;
  27216. return data;
  27217. },
  27218. clone: function clone() {
  27219. /*
  27220. // Handle primitives
  27221. const parameters = this.parameters;
  27222. if ( parameters !== undefined ) {
  27223. const values = [];
  27224. for ( const key in parameters ) {
  27225. values.push( parameters[ key ] );
  27226. }
  27227. const geometry = Object.create( this.constructor.prototype );
  27228. this.constructor.apply( geometry, values );
  27229. return geometry;
  27230. }
  27231. return new this.constructor().copy( this );
  27232. */
  27233. return new Geometry().copy(this);
  27234. },
  27235. copy: function copy(source) {
  27236. // reset
  27237. this.vertices = [];
  27238. this.colors = [];
  27239. this.faces = [];
  27240. this.faceVertexUvs = [[]];
  27241. this.morphTargets = [];
  27242. this.morphNormals = [];
  27243. this.skinWeights = [];
  27244. this.skinIndices = [];
  27245. this.lineDistances = [];
  27246. this.boundingBox = null;
  27247. this.boundingSphere = null; // name
  27248. this.name = source.name; // vertices
  27249. var vertices = source.vertices;
  27250. for (var i = 0, il = vertices.length; i < il; i++) {
  27251. this.vertices.push(vertices[i].clone());
  27252. } // colors
  27253. var colors = source.colors;
  27254. for (var _i13 = 0, _il7 = colors.length; _i13 < _il7; _i13++) {
  27255. this.colors.push(colors[_i13].clone());
  27256. } // faces
  27257. var faces = source.faces;
  27258. for (var _i14 = 0, _il8 = faces.length; _i14 < _il8; _i14++) {
  27259. this.faces.push(faces[_i14].clone());
  27260. } // face vertex uvs
  27261. for (var _i15 = 0, _il9 = source.faceVertexUvs.length; _i15 < _il9; _i15++) {
  27262. var faceVertexUvs = source.faceVertexUvs[_i15];
  27263. if (this.faceVertexUvs[_i15] === undefined) {
  27264. this.faceVertexUvs[_i15] = [];
  27265. }
  27266. for (var j = 0, jl = faceVertexUvs.length; j < jl; j++) {
  27267. var uvs = faceVertexUvs[j],
  27268. uvsCopy = [];
  27269. for (var k = 0, kl = uvs.length; k < kl; k++) {
  27270. var uv = uvs[k];
  27271. uvsCopy.push(uv.clone());
  27272. }
  27273. this.faceVertexUvs[_i15].push(uvsCopy);
  27274. }
  27275. } // morph targets
  27276. var morphTargets = source.morphTargets;
  27277. for (var _i16 = 0, _il10 = morphTargets.length; _i16 < _il10; _i16++) {
  27278. var morphTarget = {};
  27279. morphTarget.name = morphTargets[_i16].name; // vertices
  27280. if (morphTargets[_i16].vertices !== undefined) {
  27281. morphTarget.vertices = [];
  27282. for (var _j3 = 0, _jl3 = morphTargets[_i16].vertices.length; _j3 < _jl3; _j3++) {
  27283. morphTarget.vertices.push(morphTargets[_i16].vertices[_j3].clone());
  27284. }
  27285. } // normals
  27286. if (morphTargets[_i16].normals !== undefined) {
  27287. morphTarget.normals = [];
  27288. for (var _j4 = 0, _jl4 = morphTargets[_i16].normals.length; _j4 < _jl4; _j4++) {
  27289. morphTarget.normals.push(morphTargets[_i16].normals[_j4].clone());
  27290. }
  27291. }
  27292. this.morphTargets.push(morphTarget);
  27293. } // morph normals
  27294. var morphNormals = source.morphNormals;
  27295. for (var _i17 = 0, _il11 = morphNormals.length; _i17 < _il11; _i17++) {
  27296. var morphNormal = {}; // vertex normals
  27297. if (morphNormals[_i17].vertexNormals !== undefined) {
  27298. morphNormal.vertexNormals = [];
  27299. for (var _j5 = 0, _jl5 = morphNormals[_i17].vertexNormals.length; _j5 < _jl5; _j5++) {
  27300. var srcVertexNormal = morphNormals[_i17].vertexNormals[_j5];
  27301. var destVertexNormal = {};
  27302. destVertexNormal.a = srcVertexNormal.a.clone();
  27303. destVertexNormal.b = srcVertexNormal.b.clone();
  27304. destVertexNormal.c = srcVertexNormal.c.clone();
  27305. morphNormal.vertexNormals.push(destVertexNormal);
  27306. }
  27307. } // face normals
  27308. if (morphNormals[_i17].faceNormals !== undefined) {
  27309. morphNormal.faceNormals = [];
  27310. for (var _j6 = 0, _jl6 = morphNormals[_i17].faceNormals.length; _j6 < _jl6; _j6++) {
  27311. morphNormal.faceNormals.push(morphNormals[_i17].faceNormals[_j6].clone());
  27312. }
  27313. }
  27314. this.morphNormals.push(morphNormal);
  27315. } // skin weights
  27316. var skinWeights = source.skinWeights;
  27317. for (var _i18 = 0, _il12 = skinWeights.length; _i18 < _il12; _i18++) {
  27318. this.skinWeights.push(skinWeights[_i18].clone());
  27319. } // skin indices
  27320. var skinIndices = source.skinIndices;
  27321. for (var _i19 = 0, _il13 = skinIndices.length; _i19 < _il13; _i19++) {
  27322. this.skinIndices.push(skinIndices[_i19].clone());
  27323. } // line distances
  27324. var lineDistances = source.lineDistances;
  27325. for (var _i20 = 0, _il14 = lineDistances.length; _i20 < _il14; _i20++) {
  27326. this.lineDistances.push(lineDistances[_i20]);
  27327. } // bounding box
  27328. var boundingBox = source.boundingBox;
  27329. if (boundingBox !== null) {
  27330. this.boundingBox = boundingBox.clone();
  27331. } // bounding sphere
  27332. var boundingSphere = source.boundingSphere;
  27333. if (boundingSphere !== null) {
  27334. this.boundingSphere = boundingSphere.clone();
  27335. } // update flags
  27336. this.elementsNeedUpdate = source.elementsNeedUpdate;
  27337. this.verticesNeedUpdate = source.verticesNeedUpdate;
  27338. this.uvsNeedUpdate = source.uvsNeedUpdate;
  27339. this.normalsNeedUpdate = source.normalsNeedUpdate;
  27340. this.colorsNeedUpdate = source.colorsNeedUpdate;
  27341. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  27342. this.groupsNeedUpdate = source.groupsNeedUpdate;
  27343. return this;
  27344. },
  27345. dispose: function dispose() {
  27346. this.dispatchEvent({
  27347. type: 'dispose'
  27348. });
  27349. }
  27350. });
  27351. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27352. InterleavedBuffer.call(this, array, stride);
  27353. this.meshPerAttribute = meshPerAttribute || 1;
  27354. }
  27355. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27356. constructor: InstancedInterleavedBuffer,
  27357. isInstancedInterleavedBuffer: true,
  27358. copy: function copy(source) {
  27359. InterleavedBuffer.prototype.copy.call(this, source);
  27360. this.meshPerAttribute = source.meshPerAttribute;
  27361. return this;
  27362. },
  27363. clone: function clone(data) {
  27364. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27365. ib.meshPerAttribute = this.meshPerAttribute;
  27366. return ib;
  27367. },
  27368. toJSON: function toJSON(data) {
  27369. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27370. json.isInstancedInterleavedBuffer = true;
  27371. json.meshPerAttribute = this.meshPerAttribute;
  27372. return json;
  27373. }
  27374. });
  27375. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27376. this.buffer = buffer;
  27377. this.type = type;
  27378. this.itemSize = itemSize;
  27379. this.elementSize = elementSize;
  27380. this.count = count;
  27381. this.version = 0;
  27382. }
  27383. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27384. set: function set(value) {
  27385. if (value === true) this.version++;
  27386. }
  27387. });
  27388. Object.assign(GLBufferAttribute.prototype, {
  27389. isGLBufferAttribute: true,
  27390. setBuffer: function setBuffer(buffer) {
  27391. this.buffer = buffer;
  27392. return this;
  27393. },
  27394. setType: function setType(type, elementSize) {
  27395. this.type = type;
  27396. this.elementSize = elementSize;
  27397. return this;
  27398. },
  27399. setItemSize: function setItemSize(itemSize) {
  27400. this.itemSize = itemSize;
  27401. return this;
  27402. },
  27403. setCount: function setCount(count) {
  27404. this.count = count;
  27405. return this;
  27406. }
  27407. });
  27408. function Raycaster(origin, direction, near, far) {
  27409. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27410. this.near = near || 0;
  27411. this.far = far || Infinity;
  27412. this.camera = null;
  27413. this.layers = new Layers();
  27414. this.params = {
  27415. Mesh: {},
  27416. Line: {
  27417. threshold: 1
  27418. },
  27419. LOD: {},
  27420. Points: {
  27421. threshold: 1
  27422. },
  27423. Sprite: {}
  27424. };
  27425. Object.defineProperties(this.params, {
  27426. PointCloud: {
  27427. get: function get() {
  27428. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27429. return this.Points;
  27430. }
  27431. }
  27432. });
  27433. }
  27434. function ascSort(a, b) {
  27435. return a.distance - b.distance;
  27436. }
  27437. function _intersectObject(object, raycaster, intersects, recursive) {
  27438. if (object.layers.test(raycaster.layers)) {
  27439. object.raycast(raycaster, intersects);
  27440. }
  27441. if (recursive === true) {
  27442. var children = object.children;
  27443. for (var i = 0, l = children.length; i < l; i++) {
  27444. _intersectObject(children[i], raycaster, intersects, true);
  27445. }
  27446. }
  27447. }
  27448. Object.assign(Raycaster.prototype, {
  27449. set: function set(origin, direction) {
  27450. // direction is assumed to be normalized (for accurate distance calculations)
  27451. this.ray.set(origin, direction);
  27452. },
  27453. setFromCamera: function setFromCamera(coords, camera) {
  27454. if (camera && camera.isPerspectiveCamera) {
  27455. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27456. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27457. this.camera = camera;
  27458. } else if (camera && camera.isOrthographicCamera) {
  27459. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27460. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27461. this.camera = camera;
  27462. } else {
  27463. console.error('THREE.Raycaster: Unsupported camera type: ' + camera.type);
  27464. }
  27465. },
  27466. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27467. var intersects = optionalTarget || [];
  27468. _intersectObject(object, this, intersects, recursive);
  27469. intersects.sort(ascSort);
  27470. return intersects;
  27471. },
  27472. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27473. var intersects = optionalTarget || [];
  27474. if (Array.isArray(objects) === false) {
  27475. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27476. return intersects;
  27477. }
  27478. for (var i = 0, l = objects.length; i < l; i++) {
  27479. _intersectObject(objects[i], this, intersects, recursive);
  27480. }
  27481. intersects.sort(ascSort);
  27482. return intersects;
  27483. }
  27484. });
  27485. /**
  27486. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27487. *
  27488. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27489. * The azimuthal angle (theta) is measured from the positive z-axis.
  27490. */
  27491. var Spherical = /*#__PURE__*/function () {
  27492. function Spherical(radius, phi, theta) {
  27493. if (radius === void 0) {
  27494. radius = 1;
  27495. }
  27496. if (phi === void 0) {
  27497. phi = 0;
  27498. }
  27499. if (theta === void 0) {
  27500. theta = 0;
  27501. }
  27502. this.radius = radius;
  27503. this.phi = phi; // polar angle
  27504. this.theta = theta; // azimuthal angle
  27505. return this;
  27506. }
  27507. var _proto = Spherical.prototype;
  27508. _proto.set = function set(radius, phi, theta) {
  27509. this.radius = radius;
  27510. this.phi = phi;
  27511. this.theta = theta;
  27512. return this;
  27513. };
  27514. _proto.clone = function clone() {
  27515. return new this.constructor().copy(this);
  27516. };
  27517. _proto.copy = function copy(other) {
  27518. this.radius = other.radius;
  27519. this.phi = other.phi;
  27520. this.theta = other.theta;
  27521. return this;
  27522. } // restrict phi to be betwee EPS and PI-EPS
  27523. ;
  27524. _proto.makeSafe = function makeSafe() {
  27525. var EPS = 0.000001;
  27526. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27527. return this;
  27528. };
  27529. _proto.setFromVector3 = function setFromVector3(v) {
  27530. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27531. };
  27532. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27533. this.radius = Math.sqrt(x * x + y * y + z * z);
  27534. if (this.radius === 0) {
  27535. this.theta = 0;
  27536. this.phi = 0;
  27537. } else {
  27538. this.theta = Math.atan2(x, z);
  27539. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27540. }
  27541. return this;
  27542. };
  27543. return Spherical;
  27544. }();
  27545. /**
  27546. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27547. */
  27548. var Cylindrical = /*#__PURE__*/function () {
  27549. function Cylindrical(radius, theta, y) {
  27550. this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27551. this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27552. this.y = y !== undefined ? y : 0; // height above the x-z plane
  27553. return this;
  27554. }
  27555. var _proto = Cylindrical.prototype;
  27556. _proto.set = function set(radius, theta, y) {
  27557. this.radius = radius;
  27558. this.theta = theta;
  27559. this.y = y;
  27560. return this;
  27561. };
  27562. _proto.clone = function clone() {
  27563. return new this.constructor().copy(this);
  27564. };
  27565. _proto.copy = function copy(other) {
  27566. this.radius = other.radius;
  27567. this.theta = other.theta;
  27568. this.y = other.y;
  27569. return this;
  27570. };
  27571. _proto.setFromVector3 = function setFromVector3(v) {
  27572. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27573. };
  27574. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27575. this.radius = Math.sqrt(x * x + z * z);
  27576. this.theta = Math.atan2(x, z);
  27577. this.y = y;
  27578. return this;
  27579. };
  27580. return Cylindrical;
  27581. }();
  27582. var _vector$8 = /*@__PURE__*/new Vector2();
  27583. var Box2 = /*#__PURE__*/function () {
  27584. function Box2(min, max) {
  27585. Object.defineProperty(this, 'isBox2', {
  27586. value: true
  27587. });
  27588. this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
  27589. this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
  27590. }
  27591. var _proto = Box2.prototype;
  27592. _proto.set = function set(min, max) {
  27593. this.min.copy(min);
  27594. this.max.copy(max);
  27595. return this;
  27596. };
  27597. _proto.setFromPoints = function setFromPoints(points) {
  27598. this.makeEmpty();
  27599. for (var i = 0, il = points.length; i < il; i++) {
  27600. this.expandByPoint(points[i]);
  27601. }
  27602. return this;
  27603. };
  27604. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  27605. var halfSize = _vector$8.copy(size).multiplyScalar(0.5);
  27606. this.min.copy(center).sub(halfSize);
  27607. this.max.copy(center).add(halfSize);
  27608. return this;
  27609. };
  27610. _proto.clone = function clone() {
  27611. return new this.constructor().copy(this);
  27612. };
  27613. _proto.copy = function copy(box) {
  27614. this.min.copy(box.min);
  27615. this.max.copy(box.max);
  27616. return this;
  27617. };
  27618. _proto.makeEmpty = function makeEmpty() {
  27619. this.min.x = this.min.y = +Infinity;
  27620. this.max.x = this.max.y = -Infinity;
  27621. return this;
  27622. };
  27623. _proto.isEmpty = function isEmpty() {
  27624. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27625. return this.max.x < this.min.x || this.max.y < this.min.y;
  27626. };
  27627. _proto.getCenter = function getCenter(target) {
  27628. if (target === undefined) {
  27629. console.warn('THREE.Box2: .getCenter() target is now required');
  27630. target = new Vector2();
  27631. }
  27632. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  27633. };
  27634. _proto.getSize = function getSize(target) {
  27635. if (target === undefined) {
  27636. console.warn('THREE.Box2: .getSize() target is now required');
  27637. target = new Vector2();
  27638. }
  27639. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  27640. };
  27641. _proto.expandByPoint = function expandByPoint(point) {
  27642. this.min.min(point);
  27643. this.max.max(point);
  27644. return this;
  27645. };
  27646. _proto.expandByVector = function expandByVector(vector) {
  27647. this.min.sub(vector);
  27648. this.max.add(vector);
  27649. return this;
  27650. };
  27651. _proto.expandByScalar = function expandByScalar(scalar) {
  27652. this.min.addScalar(-scalar);
  27653. this.max.addScalar(scalar);
  27654. return this;
  27655. };
  27656. _proto.containsPoint = function containsPoint(point) {
  27657. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  27658. };
  27659. _proto.containsBox = function containsBox(box) {
  27660. 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;
  27661. };
  27662. _proto.getParameter = function getParameter(point, target) {
  27663. // This can potentially have a divide by zero if the box
  27664. // has a size dimension of 0.
  27665. if (target === undefined) {
  27666. console.warn('THREE.Box2: .getParameter() target is now required');
  27667. target = new Vector2();
  27668. }
  27669. 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));
  27670. };
  27671. _proto.intersectsBox = function intersectsBox(box) {
  27672. // using 4 splitting planes to rule out intersections
  27673. 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;
  27674. };
  27675. _proto.clampPoint = function clampPoint(point, target) {
  27676. if (target === undefined) {
  27677. console.warn('THREE.Box2: .clampPoint() target is now required');
  27678. target = new Vector2();
  27679. }
  27680. return target.copy(point).clamp(this.min, this.max);
  27681. };
  27682. _proto.distanceToPoint = function distanceToPoint(point) {
  27683. var clampedPoint = _vector$8.copy(point).clamp(this.min, this.max);
  27684. return clampedPoint.sub(point).length();
  27685. };
  27686. _proto.intersect = function intersect(box) {
  27687. this.min.max(box.min);
  27688. this.max.min(box.max);
  27689. return this;
  27690. };
  27691. _proto.union = function union(box) {
  27692. this.min.min(box.min);
  27693. this.max.max(box.max);
  27694. return this;
  27695. };
  27696. _proto.translate = function translate(offset) {
  27697. this.min.add(offset);
  27698. this.max.add(offset);
  27699. return this;
  27700. };
  27701. _proto.equals = function equals(box) {
  27702. return box.min.equals(this.min) && box.max.equals(this.max);
  27703. };
  27704. return Box2;
  27705. }();
  27706. var _startP = /*@__PURE__*/new Vector3();
  27707. var _startEnd = /*@__PURE__*/new Vector3();
  27708. var Line3 = /*#__PURE__*/function () {
  27709. function Line3(start, end) {
  27710. this.start = start !== undefined ? start : new Vector3();
  27711. this.end = end !== undefined ? end : new Vector3();
  27712. }
  27713. var _proto = Line3.prototype;
  27714. _proto.set = function set(start, end) {
  27715. this.start.copy(start);
  27716. this.end.copy(end);
  27717. return this;
  27718. };
  27719. _proto.clone = function clone() {
  27720. return new this.constructor().copy(this);
  27721. };
  27722. _proto.copy = function copy(line) {
  27723. this.start.copy(line.start);
  27724. this.end.copy(line.end);
  27725. return this;
  27726. };
  27727. _proto.getCenter = function getCenter(target) {
  27728. if (target === undefined) {
  27729. console.warn('THREE.Line3: .getCenter() target is now required');
  27730. target = new Vector3();
  27731. }
  27732. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  27733. };
  27734. _proto.delta = function delta(target) {
  27735. if (target === undefined) {
  27736. console.warn('THREE.Line3: .delta() target is now required');
  27737. target = new Vector3();
  27738. }
  27739. return target.subVectors(this.end, this.start);
  27740. };
  27741. _proto.distanceSq = function distanceSq() {
  27742. return this.start.distanceToSquared(this.end);
  27743. };
  27744. _proto.distance = function distance() {
  27745. return this.start.distanceTo(this.end);
  27746. };
  27747. _proto.at = function at(t, target) {
  27748. if (target === undefined) {
  27749. console.warn('THREE.Line3: .at() target is now required');
  27750. target = new Vector3();
  27751. }
  27752. return this.delta(target).multiplyScalar(t).add(this.start);
  27753. };
  27754. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  27755. _startP.subVectors(point, this.start);
  27756. _startEnd.subVectors(this.end, this.start);
  27757. var startEnd2 = _startEnd.dot(_startEnd);
  27758. var startEnd_startP = _startEnd.dot(_startP);
  27759. var t = startEnd_startP / startEnd2;
  27760. if (clampToLine) {
  27761. t = MathUtils.clamp(t, 0, 1);
  27762. }
  27763. return t;
  27764. };
  27765. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  27766. var t = this.closestPointToPointParameter(point, clampToLine);
  27767. if (target === undefined) {
  27768. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  27769. target = new Vector3();
  27770. }
  27771. return this.delta(target).multiplyScalar(t).add(this.start);
  27772. };
  27773. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  27774. this.start.applyMatrix4(matrix);
  27775. this.end.applyMatrix4(matrix);
  27776. return this;
  27777. };
  27778. _proto.equals = function equals(line) {
  27779. return line.start.equals(this.start) && line.end.equals(this.end);
  27780. };
  27781. return Line3;
  27782. }();
  27783. function ImmediateRenderObject(material) {
  27784. Object3D.call(this);
  27785. this.material = material;
  27786. this.render = function ()
  27787. /* renderCallback */
  27788. {};
  27789. this.hasPositions = false;
  27790. this.hasNormals = false;
  27791. this.hasColors = false;
  27792. this.hasUvs = false;
  27793. this.positionArray = null;
  27794. this.normalArray = null;
  27795. this.colorArray = null;
  27796. this.uvArray = null;
  27797. this.count = 0;
  27798. }
  27799. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  27800. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27801. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27802. var _vector$9 = /*@__PURE__*/new Vector3();
  27803. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  27804. _inheritsLoose(SpotLightHelper, _Object3D);
  27805. function SpotLightHelper(light, color) {
  27806. var _this;
  27807. _this = _Object3D.call(this) || this;
  27808. _this.light = light;
  27809. _this.light.updateMatrixWorld();
  27810. _this.matrix = light.matrixWorld;
  27811. _this.matrixAutoUpdate = false;
  27812. _this.color = color;
  27813. var geometry = new BufferGeometry();
  27814. 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];
  27815. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  27816. var p1 = i / l * Math.PI * 2;
  27817. var p2 = j / l * Math.PI * 2;
  27818. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  27819. }
  27820. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  27821. var material = new LineBasicMaterial({
  27822. fog: false,
  27823. toneMapped: false
  27824. });
  27825. _this.cone = new LineSegments(geometry, material);
  27826. _this.add(_this.cone);
  27827. _this.update();
  27828. return _this;
  27829. }
  27830. var _proto = SpotLightHelper.prototype;
  27831. _proto.dispose = function dispose() {
  27832. this.cone.geometry.dispose();
  27833. this.cone.material.dispose();
  27834. };
  27835. _proto.update = function update() {
  27836. this.light.updateMatrixWorld();
  27837. var coneLength = this.light.distance ? this.light.distance : 1000;
  27838. var coneWidth = coneLength * Math.tan(this.light.angle);
  27839. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  27840. _vector$9.setFromMatrixPosition(this.light.target.matrixWorld);
  27841. this.cone.lookAt(_vector$9);
  27842. if (this.color !== undefined) {
  27843. this.cone.material.color.set(this.color);
  27844. } else {
  27845. this.cone.material.color.copy(this.light.color);
  27846. }
  27847. };
  27848. return SpotLightHelper;
  27849. }(Object3D);
  27850. var _vector$a = /*@__PURE__*/new Vector3();
  27851. var _boneMatrix = /*@__PURE__*/new Matrix4();
  27852. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  27853. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  27854. _inheritsLoose(SkeletonHelper, _LineSegments);
  27855. function SkeletonHelper(object) {
  27856. var _this;
  27857. var bones = getBoneList(object);
  27858. var geometry = new BufferGeometry();
  27859. var vertices = [];
  27860. var colors = [];
  27861. var color1 = new Color(0, 0, 1);
  27862. var color2 = new Color(0, 1, 0);
  27863. for (var i = 0; i < bones.length; i++) {
  27864. var bone = bones[i];
  27865. if (bone.parent && bone.parent.isBone) {
  27866. vertices.push(0, 0, 0);
  27867. vertices.push(0, 0, 0);
  27868. colors.push(color1.r, color1.g, color1.b);
  27869. colors.push(color2.r, color2.g, color2.b);
  27870. }
  27871. }
  27872. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27873. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27874. var material = new LineBasicMaterial({
  27875. vertexColors: true,
  27876. depthTest: false,
  27877. depthWrite: false,
  27878. toneMapped: false,
  27879. transparent: true
  27880. });
  27881. _this = _LineSegments.call(this, geometry, material) || this;
  27882. _this.type = 'SkeletonHelper';
  27883. _this.isSkeletonHelper = true;
  27884. _this.root = object;
  27885. _this.bones = bones;
  27886. _this.matrix = object.matrixWorld;
  27887. _this.matrixAutoUpdate = false;
  27888. return _this;
  27889. }
  27890. var _proto = SkeletonHelper.prototype;
  27891. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  27892. var bones = this.bones;
  27893. var geometry = this.geometry;
  27894. var position = geometry.getAttribute('position');
  27895. _matrixWorldInv.copy(this.root.matrixWorld).invert();
  27896. for (var i = 0, j = 0; i < bones.length; i++) {
  27897. var bone = bones[i];
  27898. if (bone.parent && bone.parent.isBone) {
  27899. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  27900. _vector$a.setFromMatrixPosition(_boneMatrix);
  27901. position.setXYZ(j, _vector$a.x, _vector$a.y, _vector$a.z);
  27902. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  27903. _vector$a.setFromMatrixPosition(_boneMatrix);
  27904. position.setXYZ(j + 1, _vector$a.x, _vector$a.y, _vector$a.z);
  27905. j += 2;
  27906. }
  27907. }
  27908. geometry.getAttribute('position').needsUpdate = true;
  27909. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  27910. };
  27911. return SkeletonHelper;
  27912. }(LineSegments);
  27913. function getBoneList(object) {
  27914. var boneList = [];
  27915. if (object && object.isBone) {
  27916. boneList.push(object);
  27917. }
  27918. for (var i = 0; i < object.children.length; i++) {
  27919. boneList.push.apply(boneList, getBoneList(object.children[i]));
  27920. }
  27921. return boneList;
  27922. }
  27923. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  27924. _inheritsLoose(PointLightHelper, _Mesh);
  27925. function PointLightHelper(light, sphereSize, color) {
  27926. var _this;
  27927. var geometry = new SphereGeometry(sphereSize, 4, 2);
  27928. var material = new MeshBasicMaterial({
  27929. wireframe: true,
  27930. fog: false,
  27931. toneMapped: false
  27932. });
  27933. _this = _Mesh.call(this, geometry, material) || this;
  27934. _this.light = light;
  27935. _this.light.updateMatrixWorld();
  27936. _this.color = color;
  27937. _this.type = 'PointLightHelper';
  27938. _this.matrix = _this.light.matrixWorld;
  27939. _this.matrixAutoUpdate = false;
  27940. _this.update();
  27941. /*
  27942. // TODO: delete this comment?
  27943. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27944. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27945. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27946. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27947. const d = light.distance;
  27948. if ( d === 0.0 ) {
  27949. this.lightDistance.visible = false;
  27950. } else {
  27951. this.lightDistance.scale.set( d, d, d );
  27952. }
  27953. this.add( this.lightDistance );
  27954. */
  27955. return _this;
  27956. }
  27957. var _proto = PointLightHelper.prototype;
  27958. _proto.dispose = function dispose() {
  27959. this.geometry.dispose();
  27960. this.material.dispose();
  27961. };
  27962. _proto.update = function update() {
  27963. if (this.color !== undefined) {
  27964. this.material.color.set(this.color);
  27965. } else {
  27966. this.material.color.copy(this.light.color);
  27967. }
  27968. /*
  27969. const d = this.light.distance;
  27970. if ( d === 0.0 ) {
  27971. this.lightDistance.visible = false;
  27972. } else {
  27973. this.lightDistance.visible = true;
  27974. this.lightDistance.scale.set( d, d, d );
  27975. }
  27976. */
  27977. };
  27978. return PointLightHelper;
  27979. }(Mesh);
  27980. var _vector$b = /*@__PURE__*/new Vector3();
  27981. var _color1 = /*@__PURE__*/new Color();
  27982. var _color2 = /*@__PURE__*/new Color();
  27983. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  27984. _inheritsLoose(HemisphereLightHelper, _Object3D);
  27985. function HemisphereLightHelper(light, size, color) {
  27986. var _this;
  27987. _this = _Object3D.call(this) || this;
  27988. _this.light = light;
  27989. _this.light.updateMatrixWorld();
  27990. _this.matrix = light.matrixWorld;
  27991. _this.matrixAutoUpdate = false;
  27992. _this.color = color;
  27993. var geometry = new OctahedronGeometry(size);
  27994. geometry.rotateY(Math.PI * 0.5);
  27995. _this.material = new MeshBasicMaterial({
  27996. wireframe: true,
  27997. fog: false,
  27998. toneMapped: false
  27999. });
  28000. if (_this.color === undefined) _this.material.vertexColors = true;
  28001. var position = geometry.getAttribute('position');
  28002. var colors = new Float32Array(position.count * 3);
  28003. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  28004. _this.add(new Mesh(geometry, _this.material));
  28005. _this.update();
  28006. return _this;
  28007. }
  28008. var _proto = HemisphereLightHelper.prototype;
  28009. _proto.dispose = function dispose() {
  28010. this.children[0].geometry.dispose();
  28011. this.children[0].material.dispose();
  28012. };
  28013. _proto.update = function update() {
  28014. var mesh = this.children[0];
  28015. if (this.color !== undefined) {
  28016. this.material.color.set(this.color);
  28017. } else {
  28018. var colors = mesh.geometry.getAttribute('color');
  28019. _color1.copy(this.light.color);
  28020. _color2.copy(this.light.groundColor);
  28021. for (var i = 0, l = colors.count; i < l; i++) {
  28022. var color = i < l / 2 ? _color1 : _color2;
  28023. colors.setXYZ(i, color.r, color.g, color.b);
  28024. }
  28025. colors.needsUpdate = true;
  28026. }
  28027. mesh.lookAt(_vector$b.setFromMatrixPosition(this.light.matrixWorld).negate());
  28028. };
  28029. return HemisphereLightHelper;
  28030. }(Object3D);
  28031. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  28032. _inheritsLoose(GridHelper, _LineSegments);
  28033. function GridHelper(size, divisions, color1, color2) {
  28034. var _this;
  28035. if (size === void 0) {
  28036. size = 10;
  28037. }
  28038. if (divisions === void 0) {
  28039. divisions = 10;
  28040. }
  28041. if (color1 === void 0) {
  28042. color1 = 0x444444;
  28043. }
  28044. if (color2 === void 0) {
  28045. color2 = 0x888888;
  28046. }
  28047. color1 = new Color(color1);
  28048. color2 = new Color(color2);
  28049. var center = divisions / 2;
  28050. var step = size / divisions;
  28051. var halfSize = size / 2;
  28052. var vertices = [],
  28053. colors = [];
  28054. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  28055. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  28056. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  28057. var color = i === center ? color1 : color2;
  28058. color.toArray(colors, j);
  28059. j += 3;
  28060. color.toArray(colors, j);
  28061. j += 3;
  28062. color.toArray(colors, j);
  28063. j += 3;
  28064. color.toArray(colors, j);
  28065. j += 3;
  28066. }
  28067. var geometry = new BufferGeometry();
  28068. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28069. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28070. var material = new LineBasicMaterial({
  28071. vertexColors: true,
  28072. toneMapped: false
  28073. });
  28074. _this = _LineSegments.call(this, geometry, material) || this;
  28075. _this.type = 'GridHelper';
  28076. return _this;
  28077. }
  28078. return GridHelper;
  28079. }(LineSegments);
  28080. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  28081. _inheritsLoose(PolarGridHelper, _LineSegments);
  28082. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  28083. var _this;
  28084. if (radius === void 0) {
  28085. radius = 10;
  28086. }
  28087. if (radials === void 0) {
  28088. radials = 16;
  28089. }
  28090. if (circles === void 0) {
  28091. circles = 8;
  28092. }
  28093. if (divisions === void 0) {
  28094. divisions = 64;
  28095. }
  28096. if (color1 === void 0) {
  28097. color1 = 0x444444;
  28098. }
  28099. if (color2 === void 0) {
  28100. color2 = 0x888888;
  28101. }
  28102. color1 = new Color(color1);
  28103. color2 = new Color(color2);
  28104. var vertices = [];
  28105. var colors = []; // create the radials
  28106. for (var i = 0; i <= radials; i++) {
  28107. var v = i / radials * (Math.PI * 2);
  28108. var x = Math.sin(v) * radius;
  28109. var z = Math.cos(v) * radius;
  28110. vertices.push(0, 0, 0);
  28111. vertices.push(x, 0, z);
  28112. var color = i & 1 ? color1 : color2;
  28113. colors.push(color.r, color.g, color.b);
  28114. colors.push(color.r, color.g, color.b);
  28115. } // create the circles
  28116. for (var _i = 0; _i <= circles; _i++) {
  28117. var _color = _i & 1 ? color1 : color2;
  28118. var r = radius - radius / circles * _i;
  28119. for (var j = 0; j < divisions; j++) {
  28120. // first vertex
  28121. var _v = j / divisions * (Math.PI * 2);
  28122. var _x = Math.sin(_v) * r;
  28123. var _z = Math.cos(_v) * r;
  28124. vertices.push(_x, 0, _z);
  28125. colors.push(_color.r, _color.g, _color.b); // second vertex
  28126. _v = (j + 1) / divisions * (Math.PI * 2);
  28127. _x = Math.sin(_v) * r;
  28128. _z = Math.cos(_v) * r;
  28129. vertices.push(_x, 0, _z);
  28130. colors.push(_color.r, _color.g, _color.b);
  28131. }
  28132. }
  28133. var geometry = new BufferGeometry();
  28134. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28135. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28136. var material = new LineBasicMaterial({
  28137. vertexColors: true,
  28138. toneMapped: false
  28139. });
  28140. _this = _LineSegments.call(this, geometry, material) || this;
  28141. _this.type = 'PolarGridHelper';
  28142. return _this;
  28143. }
  28144. return PolarGridHelper;
  28145. }(LineSegments);
  28146. var _v1$6 = /*@__PURE__*/new Vector3();
  28147. var _v2$3 = /*@__PURE__*/new Vector3();
  28148. var _v3$1 = /*@__PURE__*/new Vector3();
  28149. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  28150. _inheritsLoose(DirectionalLightHelper, _Object3D);
  28151. function DirectionalLightHelper(light, size, color) {
  28152. var _this;
  28153. _this = _Object3D.call(this) || this;
  28154. _this.light = light;
  28155. _this.light.updateMatrixWorld();
  28156. _this.matrix = light.matrixWorld;
  28157. _this.matrixAutoUpdate = false;
  28158. _this.color = color;
  28159. if (size === undefined) size = 1;
  28160. var geometry = new BufferGeometry();
  28161. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  28162. var material = new LineBasicMaterial({
  28163. fog: false,
  28164. toneMapped: false
  28165. });
  28166. _this.lightPlane = new Line(geometry, material);
  28167. _this.add(_this.lightPlane);
  28168. geometry = new BufferGeometry();
  28169. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  28170. _this.targetLine = new Line(geometry, material);
  28171. _this.add(_this.targetLine);
  28172. _this.update();
  28173. return _this;
  28174. }
  28175. var _proto = DirectionalLightHelper.prototype;
  28176. _proto.dispose = function dispose() {
  28177. this.lightPlane.geometry.dispose();
  28178. this.lightPlane.material.dispose();
  28179. this.targetLine.geometry.dispose();
  28180. this.targetLine.material.dispose();
  28181. };
  28182. _proto.update = function update() {
  28183. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  28184. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  28185. _v3$1.subVectors(_v2$3, _v1$6);
  28186. this.lightPlane.lookAt(_v2$3);
  28187. if (this.color !== undefined) {
  28188. this.lightPlane.material.color.set(this.color);
  28189. this.targetLine.material.color.set(this.color);
  28190. } else {
  28191. this.lightPlane.material.color.copy(this.light.color);
  28192. this.targetLine.material.color.copy(this.light.color);
  28193. }
  28194. this.targetLine.lookAt(_v2$3);
  28195. this.targetLine.scale.z = _v3$1.length();
  28196. };
  28197. return DirectionalLightHelper;
  28198. }(Object3D);
  28199. var _vector$c = /*@__PURE__*/new Vector3();
  28200. var _camera = /*@__PURE__*/new Camera();
  28201. /**
  28202. * - shows frustum, line of sight and up of the camera
  28203. * - suitable for fast updates
  28204. * - based on frustum visualization in lightgl.js shadowmap example
  28205. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28206. */
  28207. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  28208. _inheritsLoose(CameraHelper, _LineSegments);
  28209. function CameraHelper(camera) {
  28210. var _this;
  28211. var geometry = new BufferGeometry();
  28212. var material = new LineBasicMaterial({
  28213. color: 0xffffff,
  28214. vertexColors: true,
  28215. toneMapped: false
  28216. });
  28217. var vertices = [];
  28218. var colors = [];
  28219. var pointMap = {}; // colors
  28220. var colorFrustum = new Color(0xffaa00);
  28221. var colorCone = new Color(0xff0000);
  28222. var colorUp = new Color(0x00aaff);
  28223. var colorTarget = new Color(0xffffff);
  28224. var colorCross = new Color(0x333333); // near
  28225. addLine('n1', 'n2', colorFrustum);
  28226. addLine('n2', 'n4', colorFrustum);
  28227. addLine('n4', 'n3', colorFrustum);
  28228. addLine('n3', 'n1', colorFrustum); // far
  28229. addLine('f1', 'f2', colorFrustum);
  28230. addLine('f2', 'f4', colorFrustum);
  28231. addLine('f4', 'f3', colorFrustum);
  28232. addLine('f3', 'f1', colorFrustum); // sides
  28233. addLine('n1', 'f1', colorFrustum);
  28234. addLine('n2', 'f2', colorFrustum);
  28235. addLine('n3', 'f3', colorFrustum);
  28236. addLine('n4', 'f4', colorFrustum); // cone
  28237. addLine('p', 'n1', colorCone);
  28238. addLine('p', 'n2', colorCone);
  28239. addLine('p', 'n3', colorCone);
  28240. addLine('p', 'n4', colorCone); // up
  28241. addLine('u1', 'u2', colorUp);
  28242. addLine('u2', 'u3', colorUp);
  28243. addLine('u3', 'u1', colorUp); // target
  28244. addLine('c', 't', colorTarget);
  28245. addLine('p', 'c', colorCross); // cross
  28246. addLine('cn1', 'cn2', colorCross);
  28247. addLine('cn3', 'cn4', colorCross);
  28248. addLine('cf1', 'cf2', colorCross);
  28249. addLine('cf3', 'cf4', colorCross);
  28250. function addLine(a, b, color) {
  28251. addPoint(a, color);
  28252. addPoint(b, color);
  28253. }
  28254. function addPoint(id, color) {
  28255. vertices.push(0, 0, 0);
  28256. colors.push(color.r, color.g, color.b);
  28257. if (pointMap[id] === undefined) {
  28258. pointMap[id] = [];
  28259. }
  28260. pointMap[id].push(vertices.length / 3 - 1);
  28261. }
  28262. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28263. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28264. _this = _LineSegments.call(this, geometry, material) || this;
  28265. _this.type = 'CameraHelper';
  28266. _this.camera = camera;
  28267. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28268. _this.matrix = camera.matrixWorld;
  28269. _this.matrixAutoUpdate = false;
  28270. _this.pointMap = pointMap;
  28271. _this.update();
  28272. return _this;
  28273. }
  28274. var _proto = CameraHelper.prototype;
  28275. _proto.update = function update() {
  28276. var geometry = this.geometry;
  28277. var pointMap = this.pointMap;
  28278. var w = 1,
  28279. h = 1; // we need just camera projection matrix inverse
  28280. // world matrix must be identity
  28281. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28282. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28283. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28284. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28285. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28286. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28287. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28288. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28289. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28290. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28291. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28292. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28293. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28294. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28295. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28296. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28297. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28298. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28299. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28300. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28301. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28302. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28303. geometry.getAttribute('position').needsUpdate = true;
  28304. };
  28305. return CameraHelper;
  28306. }(LineSegments);
  28307. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28308. _vector$c.set(x, y, z).unproject(camera);
  28309. var points = pointMap[point];
  28310. if (points !== undefined) {
  28311. var position = geometry.getAttribute('position');
  28312. for (var i = 0, l = points.length; i < l; i++) {
  28313. position.setXYZ(points[i], _vector$c.x, _vector$c.y, _vector$c.z);
  28314. }
  28315. }
  28316. }
  28317. var _box$3 = /*@__PURE__*/new Box3();
  28318. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28319. _inheritsLoose(BoxHelper, _LineSegments);
  28320. function BoxHelper(object, color) {
  28321. var _this;
  28322. if (color === void 0) {
  28323. color = 0xffff00;
  28324. }
  28325. 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]);
  28326. var positions = new Float32Array(8 * 3);
  28327. var geometry = new BufferGeometry();
  28328. geometry.setIndex(new BufferAttribute(indices, 1));
  28329. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28330. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28331. color: color,
  28332. toneMapped: false
  28333. })) || this;
  28334. _this.object = object;
  28335. _this.type = 'BoxHelper';
  28336. _this.matrixAutoUpdate = false;
  28337. _this.update();
  28338. return _this;
  28339. }
  28340. var _proto = BoxHelper.prototype;
  28341. _proto.update = function update(object) {
  28342. if (object !== undefined) {
  28343. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28344. }
  28345. if (this.object !== undefined) {
  28346. _box$3.setFromObject(this.object);
  28347. }
  28348. if (_box$3.isEmpty()) return;
  28349. var min = _box$3.min;
  28350. var max = _box$3.max;
  28351. /*
  28352. 5____4
  28353. 1/___0/|
  28354. | 6__|_7
  28355. 2/___3/
  28356. 0: max.x, max.y, max.z
  28357. 1: min.x, max.y, max.z
  28358. 2: min.x, min.y, max.z
  28359. 3: max.x, min.y, max.z
  28360. 4: max.x, max.y, min.z
  28361. 5: min.x, max.y, min.z
  28362. 6: min.x, min.y, min.z
  28363. 7: max.x, min.y, min.z
  28364. */
  28365. var position = this.geometry.attributes.position;
  28366. var array = position.array;
  28367. array[0] = max.x;
  28368. array[1] = max.y;
  28369. array[2] = max.z;
  28370. array[3] = min.x;
  28371. array[4] = max.y;
  28372. array[5] = max.z;
  28373. array[6] = min.x;
  28374. array[7] = min.y;
  28375. array[8] = max.z;
  28376. array[9] = max.x;
  28377. array[10] = min.y;
  28378. array[11] = max.z;
  28379. array[12] = max.x;
  28380. array[13] = max.y;
  28381. array[14] = min.z;
  28382. array[15] = min.x;
  28383. array[16] = max.y;
  28384. array[17] = min.z;
  28385. array[18] = min.x;
  28386. array[19] = min.y;
  28387. array[20] = min.z;
  28388. array[21] = max.x;
  28389. array[22] = min.y;
  28390. array[23] = min.z;
  28391. position.needsUpdate = true;
  28392. this.geometry.computeBoundingSphere();
  28393. };
  28394. _proto.setFromObject = function setFromObject(object) {
  28395. this.object = object;
  28396. this.update();
  28397. return this;
  28398. };
  28399. _proto.copy = function copy(source) {
  28400. LineSegments.prototype.copy.call(this, source);
  28401. this.object = source.object;
  28402. return this;
  28403. };
  28404. return BoxHelper;
  28405. }(LineSegments);
  28406. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28407. _inheritsLoose(Box3Helper, _LineSegments);
  28408. function Box3Helper(box, color) {
  28409. var _this;
  28410. if (color === void 0) {
  28411. color = 0xffff00;
  28412. }
  28413. 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]);
  28414. 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];
  28415. var geometry = new BufferGeometry();
  28416. geometry.setIndex(new BufferAttribute(indices, 1));
  28417. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28418. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28419. color: color,
  28420. toneMapped: false
  28421. })) || this;
  28422. _this.box = box;
  28423. _this.type = 'Box3Helper';
  28424. _this.geometry.computeBoundingSphere();
  28425. return _this;
  28426. }
  28427. var _proto = Box3Helper.prototype;
  28428. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28429. var box = this.box;
  28430. if (box.isEmpty()) return;
  28431. box.getCenter(this.position);
  28432. box.getSize(this.scale);
  28433. this.scale.multiplyScalar(0.5);
  28434. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28435. };
  28436. return Box3Helper;
  28437. }(LineSegments);
  28438. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28439. _inheritsLoose(PlaneHelper, _Line);
  28440. function PlaneHelper(plane, size, hex) {
  28441. var _this;
  28442. if (size === void 0) {
  28443. size = 1;
  28444. }
  28445. if (hex === void 0) {
  28446. hex = 0xffff00;
  28447. }
  28448. var color = hex;
  28449. 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];
  28450. var geometry = new BufferGeometry();
  28451. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28452. geometry.computeBoundingSphere();
  28453. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28454. color: color,
  28455. toneMapped: false
  28456. })) || this;
  28457. _this.type = 'PlaneHelper';
  28458. _this.plane = plane;
  28459. _this.size = size;
  28460. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28461. var geometry2 = new BufferGeometry();
  28462. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28463. geometry2.computeBoundingSphere();
  28464. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28465. color: color,
  28466. opacity: 0.2,
  28467. transparent: true,
  28468. depthWrite: false,
  28469. toneMapped: false
  28470. })));
  28471. return _this;
  28472. }
  28473. var _proto = PlaneHelper.prototype;
  28474. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28475. var scale = -this.plane.constant;
  28476. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28477. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28478. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28479. this.lookAt(this.plane.normal);
  28480. _Line.prototype.updateMatrixWorld.call(this, force);
  28481. };
  28482. return PlaneHelper;
  28483. }(Line);
  28484. var _axis = /*@__PURE__*/new Vector3();
  28485. var _lineGeometry, _coneGeometry;
  28486. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28487. _inheritsLoose(ArrowHelper, _Object3D);
  28488. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28489. var _this;
  28490. _this = _Object3D.call(this) || this; // dir is assumed to be normalized
  28491. _this.type = 'ArrowHelper';
  28492. if (dir === undefined) dir = new Vector3(0, 0, 1);
  28493. if (origin === undefined) origin = new Vector3(0, 0, 0);
  28494. if (length === undefined) length = 1;
  28495. if (color === undefined) color = 0xffff00;
  28496. if (headLength === undefined) headLength = 0.2 * length;
  28497. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28498. if (_lineGeometry === undefined) {
  28499. _lineGeometry = new BufferGeometry();
  28500. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28501. _coneGeometry = new CylinderGeometry(0, 0.5, 1, 5, 1);
  28502. _coneGeometry.translate(0, -0.5, 0);
  28503. }
  28504. _this.position.copy(origin);
  28505. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28506. color: color,
  28507. toneMapped: false
  28508. }));
  28509. _this.line.matrixAutoUpdate = false;
  28510. _this.add(_this.line);
  28511. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28512. color: color,
  28513. toneMapped: false
  28514. }));
  28515. _this.cone.matrixAutoUpdate = false;
  28516. _this.add(_this.cone);
  28517. _this.setDirection(dir);
  28518. _this.setLength(length, headLength, headWidth);
  28519. return _this;
  28520. }
  28521. var _proto = ArrowHelper.prototype;
  28522. _proto.setDirection = function setDirection(dir) {
  28523. // dir is assumed to be normalized
  28524. if (dir.y > 0.99999) {
  28525. this.quaternion.set(0, 0, 0, 1);
  28526. } else if (dir.y < -0.99999) {
  28527. this.quaternion.set(1, 0, 0, 0);
  28528. } else {
  28529. _axis.set(dir.z, 0, -dir.x).normalize();
  28530. var radians = Math.acos(dir.y);
  28531. this.quaternion.setFromAxisAngle(_axis, radians);
  28532. }
  28533. };
  28534. _proto.setLength = function setLength(length, headLength, headWidth) {
  28535. if (headLength === undefined) headLength = 0.2 * length;
  28536. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28537. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28538. this.line.updateMatrix();
  28539. this.cone.scale.set(headWidth, headLength, headWidth);
  28540. this.cone.position.y = length;
  28541. this.cone.updateMatrix();
  28542. };
  28543. _proto.setColor = function setColor(color) {
  28544. this.line.material.color.set(color);
  28545. this.cone.material.color.set(color);
  28546. };
  28547. _proto.copy = function copy(source) {
  28548. _Object3D.prototype.copy.call(this, source, false);
  28549. this.line.copy(source.line);
  28550. this.cone.copy(source.cone);
  28551. return this;
  28552. };
  28553. return ArrowHelper;
  28554. }(Object3D);
  28555. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  28556. _inheritsLoose(AxesHelper, _LineSegments);
  28557. function AxesHelper(size) {
  28558. var _this;
  28559. if (size === void 0) {
  28560. size = 1;
  28561. }
  28562. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  28563. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  28564. var geometry = new BufferGeometry();
  28565. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28566. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28567. var material = new LineBasicMaterial({
  28568. vertexColors: true,
  28569. toneMapped: false
  28570. });
  28571. _this = _LineSegments.call(this, geometry, material) || this;
  28572. _this.type = 'AxesHelper';
  28573. return _this;
  28574. }
  28575. return AxesHelper;
  28576. }(LineSegments);
  28577. var _floatView = new Float32Array(1);
  28578. var _int32View = new Int32Array(_floatView.buffer);
  28579. var DataUtils = {
  28580. // Converts float32 to float16 (stored as uint16 value).
  28581. toHalfFloat: function toHalfFloat(val) {
  28582. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  28583. /* This method is faster than the OpenEXR implementation (very often
  28584. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  28585. * by James Tursa?s half-precision code. */
  28586. _floatView[0] = val;
  28587. var x = _int32View[0];
  28588. var bits = x >> 16 & 0x8000;
  28589. /* Get the sign */
  28590. var m = x >> 12 & 0x07ff;
  28591. /* Keep one extra bit for rounding */
  28592. var e = x >> 23 & 0xff;
  28593. /* Using int is faster here */
  28594. /* If zero, or denormal, or exponent underflows too much for a denormal
  28595. * half, return signed zero. */
  28596. if (e < 103) return bits;
  28597. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  28598. if (e > 142) {
  28599. bits |= 0x7c00;
  28600. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  28601. * not Inf, so make sure we set one mantissa bit too. */
  28602. bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
  28603. return bits;
  28604. }
  28605. /* If exponent underflows but not too much, return a denormal */
  28606. if (e < 113) {
  28607. m |= 0x0800;
  28608. /* Extra rounding may overflow and set mantissa to 0 and exponent
  28609. * to 1, which is OK. */
  28610. bits |= (m >> 114 - e) + (m >> 113 - e & 1);
  28611. return bits;
  28612. }
  28613. bits |= e - 112 << 10 | m >> 1;
  28614. /* Extra rounding. An overflow will set mantissa to 0 and increment
  28615. * the exponent, which is OK. */
  28616. bits += m & 1;
  28617. return bits;
  28618. }
  28619. };
  28620. var _ENCODINGS;
  28621. var LOD_MIN = 4;
  28622. var LOD_MAX = 8;
  28623. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  28624. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28625. // geometric shadowing function. These sigma values squared must match the
  28626. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28627. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  28628. 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
  28629. // samples and exit early, but not recompile the shader.
  28630. var MAX_SAMPLES = 20;
  28631. 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);
  28632. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  28633. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  28634. _lodPlanes = _createPlanes2._lodPlanes,
  28635. _sizeLods = _createPlanes2._sizeLods,
  28636. _sigmas = _createPlanes2._sigmas;
  28637. var _clearColor = /*@__PURE__*/new Color();
  28638. var _backgroundColor = /*@__PURE__*/new Color();
  28639. var _oldTarget = null; // Golden Ratio
  28640. var PHI = (1 + Math.sqrt(5)) / 2;
  28641. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  28642. // same axis), used as axis directions evenly spread on a sphere.
  28643. 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)];
  28644. /**
  28645. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28646. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28647. * blur to be quickly accessed based on material roughness. It is packed into a
  28648. * special CubeUV format that allows us to perform custom interpolation so that
  28649. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28650. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28651. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28652. * higher roughness levels. In this way we maintain resolution to smoothly
  28653. * interpolate diffuse lighting while limiting sampling computation.
  28654. */
  28655. function convertLinearToRGBE(color) {
  28656. var maxComponent = Math.max(color.r, color.g, color.b);
  28657. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  28658. color.multiplyScalar(Math.pow(2.0, -fExp));
  28659. var alpha = (fExp + 128.0) / 255.0;
  28660. return alpha;
  28661. }
  28662. var PMREMGenerator = /*#__PURE__*/function () {
  28663. function PMREMGenerator(renderer) {
  28664. this._renderer = renderer;
  28665. this._pingPongRenderTarget = null;
  28666. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  28667. this._equirectShader = null;
  28668. this._cubemapShader = null;
  28669. this._compileMaterial(this._blurMaterial);
  28670. }
  28671. /**
  28672. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28673. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28674. * in radians to be applied to the scene before PMREM generation. Optional near
  28675. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28676. * is placed at the origin).
  28677. */
  28678. var _proto = PMREMGenerator.prototype;
  28679. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  28680. if (sigma === void 0) {
  28681. sigma = 0;
  28682. }
  28683. if (near === void 0) {
  28684. near = 0.1;
  28685. }
  28686. if (far === void 0) {
  28687. far = 100;
  28688. }
  28689. _oldTarget = this._renderer.getRenderTarget();
  28690. var cubeUVRenderTarget = this._allocateTargets();
  28691. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  28692. if (sigma > 0) {
  28693. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  28694. }
  28695. this._applyPMREM(cubeUVRenderTarget);
  28696. this._cleanup(cubeUVRenderTarget);
  28697. return cubeUVRenderTarget;
  28698. }
  28699. /**
  28700. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28701. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28702. * as this matches best with the 256 x 256 cubemap output.
  28703. */
  28704. ;
  28705. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  28706. return this._fromTexture(equirectangular);
  28707. }
  28708. /**
  28709. * Generates a PMREM from an cubemap texture, which can be either LDR
  28710. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28711. * as this matches best with the 256 x 256 cubemap output.
  28712. */
  28713. ;
  28714. _proto.fromCubemap = function fromCubemap(cubemap) {
  28715. return this._fromTexture(cubemap);
  28716. }
  28717. /**
  28718. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28719. * your texture's network fetch for increased concurrency.
  28720. */
  28721. ;
  28722. _proto.compileCubemapShader = function compileCubemapShader() {
  28723. if (this._cubemapShader === null) {
  28724. this._cubemapShader = _getCubemapShader();
  28725. this._compileMaterial(this._cubemapShader);
  28726. }
  28727. }
  28728. /**
  28729. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28730. * your texture's network fetch for increased concurrency.
  28731. */
  28732. ;
  28733. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  28734. if (this._equirectShader === null) {
  28735. this._equirectShader = _getEquirectShader();
  28736. this._compileMaterial(this._equirectShader);
  28737. }
  28738. }
  28739. /**
  28740. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  28741. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  28742. * one of them will cause any others to also become unusable.
  28743. */
  28744. ;
  28745. _proto.dispose = function dispose() {
  28746. this._blurMaterial.dispose();
  28747. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  28748. if (this._equirectShader !== null) this._equirectShader.dispose();
  28749. for (var i = 0; i < _lodPlanes.length; i++) {
  28750. _lodPlanes[i].dispose();
  28751. }
  28752. } // private interface
  28753. ;
  28754. _proto._cleanup = function _cleanup(outputTarget) {
  28755. this._pingPongRenderTarget.dispose();
  28756. this._renderer.setRenderTarget(_oldTarget);
  28757. outputTarget.scissorTest = false;
  28758. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  28759. };
  28760. _proto._fromTexture = function _fromTexture(texture) {
  28761. _oldTarget = this._renderer.getRenderTarget();
  28762. var cubeUVRenderTarget = this._allocateTargets(texture);
  28763. this._textureToCubeUV(texture, cubeUVRenderTarget);
  28764. this._applyPMREM(cubeUVRenderTarget);
  28765. this._cleanup(cubeUVRenderTarget);
  28766. return cubeUVRenderTarget;
  28767. };
  28768. _proto._allocateTargets = function _allocateTargets(texture) {
  28769. // warning: null texture is valid
  28770. var params = {
  28771. magFilter: NearestFilter,
  28772. minFilter: NearestFilter,
  28773. generateMipmaps: false,
  28774. type: UnsignedByteType,
  28775. format: RGBEFormat,
  28776. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  28777. depthBuffer: false
  28778. };
  28779. var cubeUVRenderTarget = _createRenderTarget(params);
  28780. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  28781. this._pingPongRenderTarget = _createRenderTarget(params);
  28782. return cubeUVRenderTarget;
  28783. };
  28784. _proto._compileMaterial = function _compileMaterial(material) {
  28785. var tmpMesh = new Mesh(_lodPlanes[0], material);
  28786. this._renderer.compile(tmpMesh, _flatCamera);
  28787. };
  28788. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  28789. var fov = 90;
  28790. var aspect = 1;
  28791. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  28792. var upSign = [1, -1, 1, 1, 1, 1];
  28793. var forwardSign = [1, 1, 1, -1, -1, -1];
  28794. var renderer = this._renderer;
  28795. var outputEncoding = renderer.outputEncoding;
  28796. var toneMapping = renderer.toneMapping;
  28797. renderer.getClearColor(_clearColor);
  28798. var clearAlpha = renderer.getClearAlpha();
  28799. var originalBackground = scene.background;
  28800. renderer.toneMapping = NoToneMapping;
  28801. renderer.outputEncoding = LinearEncoding;
  28802. var background = scene.background;
  28803. if (background) {
  28804. if (background.isColor) {
  28805. _backgroundColor.copy(background).convertSRGBToLinear();
  28806. scene.background = null;
  28807. var alpha = convertLinearToRGBE(_backgroundColor);
  28808. renderer.setClearColor(_backgroundColor);
  28809. renderer.setClearAlpha(alpha);
  28810. }
  28811. } else {
  28812. _backgroundColor.copy(_clearColor).convertSRGBToLinear();
  28813. var _alpha = convertLinearToRGBE(_backgroundColor);
  28814. renderer.setClearColor(_backgroundColor);
  28815. renderer.setClearAlpha(_alpha);
  28816. }
  28817. for (var i = 0; i < 6; i++) {
  28818. var col = i % 3;
  28819. if (col == 0) {
  28820. cubeCamera.up.set(0, upSign[i], 0);
  28821. cubeCamera.lookAt(forwardSign[i], 0, 0);
  28822. } else if (col == 1) {
  28823. cubeCamera.up.set(0, 0, upSign[i]);
  28824. cubeCamera.lookAt(0, forwardSign[i], 0);
  28825. } else {
  28826. cubeCamera.up.set(0, upSign[i], 0);
  28827. cubeCamera.lookAt(0, 0, forwardSign[i]);
  28828. }
  28829. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  28830. renderer.setRenderTarget(cubeUVRenderTarget);
  28831. renderer.render(scene, cubeCamera);
  28832. }
  28833. renderer.toneMapping = toneMapping;
  28834. renderer.outputEncoding = outputEncoding;
  28835. renderer.setClearColor(_clearColor, clearAlpha);
  28836. scene.background = originalBackground;
  28837. };
  28838. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  28839. var renderer = this._renderer;
  28840. if (texture.isCubeTexture) {
  28841. if (this._cubemapShader == null) {
  28842. this._cubemapShader = _getCubemapShader();
  28843. }
  28844. } else {
  28845. if (this._equirectShader == null) {
  28846. this._equirectShader = _getEquirectShader();
  28847. }
  28848. }
  28849. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  28850. var mesh = new Mesh(_lodPlanes[0], material);
  28851. var uniforms = material.uniforms;
  28852. uniforms['envMap'].value = texture;
  28853. if (!texture.isCubeTexture) {
  28854. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  28855. }
  28856. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  28857. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  28858. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  28859. renderer.setRenderTarget(cubeUVRenderTarget);
  28860. renderer.render(mesh, _flatCamera);
  28861. };
  28862. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  28863. var renderer = this._renderer;
  28864. var autoClear = renderer.autoClear;
  28865. renderer.autoClear = false;
  28866. for (var i = 1; i < TOTAL_LODS; i++) {
  28867. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  28868. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  28869. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  28870. }
  28871. renderer.autoClear = autoClear;
  28872. }
  28873. /**
  28874. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  28875. * vertically and horizontally, but this breaks down on a cube. Here we apply
  28876. * the blur latitudinally (around the poles), and then longitudinally (towards
  28877. * the poles) to approximate the orthogonally-separable blur. It is least
  28878. * accurate at the poles, but still does a decent job.
  28879. */
  28880. ;
  28881. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  28882. var pingPongRenderTarget = this._pingPongRenderTarget;
  28883. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  28884. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  28885. };
  28886. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  28887. var renderer = this._renderer;
  28888. var blurMaterial = this._blurMaterial;
  28889. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  28890. console.error('blur direction must be either latitudinal or longitudinal!');
  28891. } // Number of standard deviations at which to cut off the discrete approximation.
  28892. var STANDARD_DEVIATIONS = 3;
  28893. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  28894. var blurUniforms = blurMaterial.uniforms;
  28895. var pixels = _sizeLods[lodIn] - 1;
  28896. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  28897. var sigmaPixels = sigmaRadians / radiansPerPixel;
  28898. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  28899. if (samples > MAX_SAMPLES) {
  28900. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  28901. }
  28902. var weights = [];
  28903. var sum = 0;
  28904. for (var i = 0; i < MAX_SAMPLES; ++i) {
  28905. var _x = i / sigmaPixels;
  28906. var weight = Math.exp(-_x * _x / 2);
  28907. weights.push(weight);
  28908. if (i == 0) {
  28909. sum += weight;
  28910. } else if (i < samples) {
  28911. sum += 2 * weight;
  28912. }
  28913. }
  28914. for (var _i = 0; _i < weights.length; _i++) {
  28915. weights[_i] = weights[_i] / sum;
  28916. }
  28917. blurUniforms['envMap'].value = targetIn.texture;
  28918. blurUniforms['samples'].value = samples;
  28919. blurUniforms['weights'].value = weights;
  28920. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  28921. if (poleAxis) {
  28922. blurUniforms['poleAxis'].value = poleAxis;
  28923. }
  28924. blurUniforms['dTheta'].value = radiansPerPixel;
  28925. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  28926. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28927. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28928. var outputSize = _sizeLods[lodOut];
  28929. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  28930. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  28931. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  28932. renderer.setRenderTarget(targetOut);
  28933. renderer.render(blurMesh, _flatCamera);
  28934. };
  28935. return PMREMGenerator;
  28936. }();
  28937. function _isLDR(texture) {
  28938. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  28939. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  28940. }
  28941. function _createPlanes() {
  28942. var _lodPlanes = [];
  28943. var _sizeLods = [];
  28944. var _sigmas = [];
  28945. var lod = LOD_MAX;
  28946. for (var i = 0; i < TOTAL_LODS; i++) {
  28947. var sizeLod = Math.pow(2, lod);
  28948. _sizeLods.push(sizeLod);
  28949. var sigma = 1.0 / sizeLod;
  28950. if (i > LOD_MAX - LOD_MIN) {
  28951. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  28952. } else if (i == 0) {
  28953. sigma = 0;
  28954. }
  28955. _sigmas.push(sigma);
  28956. var texelSize = 1.0 / (sizeLod - 1);
  28957. var min = -texelSize / 2;
  28958. var max = 1 + texelSize / 2;
  28959. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  28960. var cubeFaces = 6;
  28961. var vertices = 6;
  28962. var positionSize = 3;
  28963. var uvSize = 2;
  28964. var faceIndexSize = 1;
  28965. var position = new Float32Array(positionSize * vertices * cubeFaces);
  28966. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  28967. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  28968. for (var face = 0; face < cubeFaces; face++) {
  28969. var x = face % 3 * 2 / 3 - 1;
  28970. var y = face > 2 ? 0 : -1;
  28971. 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];
  28972. position.set(coordinates, positionSize * vertices * face);
  28973. uv.set(uv1, uvSize * vertices * face);
  28974. var fill = [face, face, face, face, face, face];
  28975. faceIndex.set(fill, faceIndexSize * vertices * face);
  28976. }
  28977. var planes = new BufferGeometry();
  28978. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  28979. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  28980. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  28981. _lodPlanes.push(planes);
  28982. if (lod > LOD_MIN) {
  28983. lod--;
  28984. }
  28985. }
  28986. return {
  28987. _lodPlanes: _lodPlanes,
  28988. _sizeLods: _sizeLods,
  28989. _sigmas: _sigmas
  28990. };
  28991. }
  28992. function _createRenderTarget(params) {
  28993. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  28994. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  28995. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  28996. cubeUVRenderTarget.scissorTest = true;
  28997. return cubeUVRenderTarget;
  28998. }
  28999. function _setViewport(target, x, y, width, height) {
  29000. target.viewport.set(x, y, width, height);
  29001. target.scissor.set(x, y, width, height);
  29002. }
  29003. function _getBlurShader(maxSamples) {
  29004. var weights = new Float32Array(maxSamples);
  29005. var poleAxis = new Vector3(0, 1, 0);
  29006. var shaderMaterial = new RawShaderMaterial({
  29007. name: 'SphericalGaussianBlur',
  29008. defines: {
  29009. 'n': maxSamples
  29010. },
  29011. uniforms: {
  29012. 'envMap': {
  29013. value: null
  29014. },
  29015. 'samples': {
  29016. value: 1
  29017. },
  29018. 'weights': {
  29019. value: weights
  29020. },
  29021. 'latitudinal': {
  29022. value: false
  29023. },
  29024. 'dTheta': {
  29025. value: 0
  29026. },
  29027. 'mipInt': {
  29028. value: 0
  29029. },
  29030. 'poleAxis': {
  29031. value: poleAxis
  29032. },
  29033. 'inputEncoding': {
  29034. value: ENCODINGS[LinearEncoding]
  29035. },
  29036. 'outputEncoding': {
  29037. value: ENCODINGS[LinearEncoding]
  29038. }
  29039. },
  29040. vertexShader: _getCommonVertexShader(),
  29041. fragmentShader:
  29042. /* glsl */
  29043. "\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",
  29044. blending: NoBlending,
  29045. depthTest: false,
  29046. depthWrite: false
  29047. });
  29048. return shaderMaterial;
  29049. }
  29050. function _getEquirectShader() {
  29051. var texelSize = new Vector2(1, 1);
  29052. var shaderMaterial = new RawShaderMaterial({
  29053. name: 'EquirectangularToCubeUV',
  29054. uniforms: {
  29055. 'envMap': {
  29056. value: null
  29057. },
  29058. 'texelSize': {
  29059. value: texelSize
  29060. },
  29061. 'inputEncoding': {
  29062. value: ENCODINGS[LinearEncoding]
  29063. },
  29064. 'outputEncoding': {
  29065. value: ENCODINGS[LinearEncoding]
  29066. }
  29067. },
  29068. vertexShader: _getCommonVertexShader(),
  29069. fragmentShader:
  29070. /* glsl */
  29071. "\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",
  29072. blending: NoBlending,
  29073. depthTest: false,
  29074. depthWrite: false
  29075. });
  29076. return shaderMaterial;
  29077. }
  29078. function _getCubemapShader() {
  29079. var shaderMaterial = new RawShaderMaterial({
  29080. name: 'CubemapToCubeUV',
  29081. uniforms: {
  29082. 'envMap': {
  29083. value: null
  29084. },
  29085. 'inputEncoding': {
  29086. value: ENCODINGS[LinearEncoding]
  29087. },
  29088. 'outputEncoding': {
  29089. value: ENCODINGS[LinearEncoding]
  29090. }
  29091. },
  29092. vertexShader: _getCommonVertexShader(),
  29093. fragmentShader:
  29094. /* glsl */
  29095. "\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",
  29096. blending: NoBlending,
  29097. depthTest: false,
  29098. depthWrite: false
  29099. });
  29100. return shaderMaterial;
  29101. }
  29102. function _getCommonVertexShader() {
  29103. return (
  29104. /* glsl */
  29105. "\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"
  29106. );
  29107. }
  29108. function _getEncodings() {
  29109. return (
  29110. /* glsl */
  29111. "\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"
  29112. );
  29113. }
  29114. function Face4(a, b, c, d, normal, color, materialIndex) {
  29115. console.warn('THREE.Face4 has been removed. A THREE.Face3 will be created instead.');
  29116. return new Face3(a, b, c, normal, color, materialIndex);
  29117. }
  29118. var LineStrip = 0;
  29119. var LinePieces = 1;
  29120. var NoColors = 0;
  29121. var FaceColors = 1;
  29122. var VertexColors = 2;
  29123. function MeshFaceMaterial(materials) {
  29124. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  29125. return materials;
  29126. }
  29127. function MultiMaterial(materials) {
  29128. if (materials === void 0) {
  29129. materials = [];
  29130. }
  29131. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  29132. materials.isMultiMaterial = true;
  29133. materials.materials = materials;
  29134. materials.clone = function () {
  29135. return materials.slice();
  29136. };
  29137. return materials;
  29138. }
  29139. function PointCloud(geometry, material) {
  29140. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  29141. return new Points(geometry, material);
  29142. }
  29143. function Particle(material) {
  29144. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  29145. return new Sprite(material);
  29146. }
  29147. function ParticleSystem(geometry, material) {
  29148. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  29149. return new Points(geometry, material);
  29150. }
  29151. function PointCloudMaterial(parameters) {
  29152. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  29153. return new PointsMaterial(parameters);
  29154. }
  29155. function ParticleBasicMaterial(parameters) {
  29156. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  29157. return new PointsMaterial(parameters);
  29158. }
  29159. function ParticleSystemMaterial(parameters) {
  29160. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  29161. return new PointsMaterial(parameters);
  29162. }
  29163. function Vertex(x, y, z) {
  29164. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  29165. return new Vector3(x, y, z);
  29166. } //
  29167. function DynamicBufferAttribute(array, itemSize) {
  29168. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  29169. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  29170. }
  29171. function Int8Attribute(array, itemSize) {
  29172. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  29173. return new Int8BufferAttribute(array, itemSize);
  29174. }
  29175. function Uint8Attribute(array, itemSize) {
  29176. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  29177. return new Uint8BufferAttribute(array, itemSize);
  29178. }
  29179. function Uint8ClampedAttribute(array, itemSize) {
  29180. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  29181. return new Uint8ClampedBufferAttribute(array, itemSize);
  29182. }
  29183. function Int16Attribute(array, itemSize) {
  29184. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  29185. return new Int16BufferAttribute(array, itemSize);
  29186. }
  29187. function Uint16Attribute(array, itemSize) {
  29188. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  29189. return new Uint16BufferAttribute(array, itemSize);
  29190. }
  29191. function Int32Attribute(array, itemSize) {
  29192. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  29193. return new Int32BufferAttribute(array, itemSize);
  29194. }
  29195. function Uint32Attribute(array, itemSize) {
  29196. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  29197. return new Uint32BufferAttribute(array, itemSize);
  29198. }
  29199. function Float32Attribute(array, itemSize) {
  29200. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  29201. return new Float32BufferAttribute(array, itemSize);
  29202. }
  29203. function Float64Attribute(array, itemSize) {
  29204. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  29205. return new Float64BufferAttribute(array, itemSize);
  29206. } //
  29207. Curve.create = function (construct, getPoint) {
  29208. console.log('THREE.Curve.create() has been deprecated');
  29209. construct.prototype = Object.create(Curve.prototype);
  29210. construct.prototype.constructor = construct;
  29211. construct.prototype.getPoint = getPoint;
  29212. return construct;
  29213. }; //
  29214. Object.assign(CurvePath.prototype, {
  29215. createPointsGeometry: function createPointsGeometry(divisions) {
  29216. 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)
  29217. var pts = this.getPoints(divisions);
  29218. return this.createGeometry(pts);
  29219. },
  29220. createSpacedPointsGeometry: function createSpacedPointsGeometry(divisions) {
  29221. console.warn('THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.'); // generate geometry from equidistant sampling along the path
  29222. var pts = this.getSpacedPoints(divisions);
  29223. return this.createGeometry(pts);
  29224. },
  29225. createGeometry: function createGeometry(points) {
  29226. console.warn('THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');
  29227. var geometry = new Geometry();
  29228. for (var i = 0, l = points.length; i < l; i++) {
  29229. var point = points[i];
  29230. geometry.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  29231. }
  29232. return geometry;
  29233. }
  29234. }); //
  29235. Object.assign(Path.prototype, {
  29236. fromPoints: function fromPoints(points) {
  29237. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  29238. return this.setFromPoints(points);
  29239. }
  29240. }); //
  29241. function ClosedSplineCurve3(points) {
  29242. console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29243. CatmullRomCurve3.call(this, points);
  29244. this.type = 'catmullrom';
  29245. this.closed = true;
  29246. }
  29247. ClosedSplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29248. function SplineCurve3(points) {
  29249. console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29250. CatmullRomCurve3.call(this, points);
  29251. this.type = 'catmullrom';
  29252. }
  29253. SplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29254. function Spline(points) {
  29255. console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');
  29256. CatmullRomCurve3.call(this, points);
  29257. this.type = 'catmullrom';
  29258. }
  29259. Spline.prototype = Object.create(CatmullRomCurve3.prototype);
  29260. Object.assign(Spline.prototype, {
  29261. initFromArray: function initFromArray()
  29262. /* a */
  29263. {
  29264. console.error('THREE.Spline: .initFromArray() has been removed.');
  29265. },
  29266. getControlPointsArray: function getControlPointsArray()
  29267. /* optionalTarget */
  29268. {
  29269. console.error('THREE.Spline: .getControlPointsArray() has been removed.');
  29270. },
  29271. reparametrizeByArcLength: function reparametrizeByArcLength()
  29272. /* samplingCoef */
  29273. {
  29274. console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');
  29275. }
  29276. }); //
  29277. function AxisHelper(size) {
  29278. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  29279. return new AxesHelper(size);
  29280. }
  29281. function BoundingBoxHelper(object, color) {
  29282. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  29283. return new BoxHelper(object, color);
  29284. }
  29285. function EdgesHelper(object, hex) {
  29286. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  29287. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  29288. color: hex !== undefined ? hex : 0xffffff
  29289. }));
  29290. }
  29291. GridHelper.prototype.setColors = function () {
  29292. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  29293. };
  29294. SkeletonHelper.prototype.update = function () {
  29295. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  29296. };
  29297. function WireframeHelper(object, hex) {
  29298. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  29299. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  29300. color: hex !== undefined ? hex : 0xffffff
  29301. }));
  29302. } //
  29303. Object.assign(Loader.prototype, {
  29304. extractUrlBase: function extractUrlBase(url) {
  29305. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  29306. return LoaderUtils.extractUrlBase(url);
  29307. }
  29308. });
  29309. Loader.Handlers = {
  29310. add: function add()
  29311. /* regex, loader */
  29312. {
  29313. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  29314. },
  29315. get: function get()
  29316. /* file */
  29317. {
  29318. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  29319. }
  29320. };
  29321. function XHRLoader(manager) {
  29322. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  29323. return new FileLoader(manager);
  29324. }
  29325. function BinaryTextureLoader(manager) {
  29326. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29327. return new DataTextureLoader(manager);
  29328. } //
  29329. Object.assign(Box2.prototype, {
  29330. center: function center(optionalTarget) {
  29331. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29332. return this.getCenter(optionalTarget);
  29333. },
  29334. empty: function empty() {
  29335. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29336. return this.isEmpty();
  29337. },
  29338. isIntersectionBox: function isIntersectionBox(box) {
  29339. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29340. return this.intersectsBox(box);
  29341. },
  29342. size: function size(optionalTarget) {
  29343. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29344. return this.getSize(optionalTarget);
  29345. }
  29346. });
  29347. Object.assign(Box3.prototype, {
  29348. center: function center(optionalTarget) {
  29349. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29350. return this.getCenter(optionalTarget);
  29351. },
  29352. empty: function empty() {
  29353. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29354. return this.isEmpty();
  29355. },
  29356. isIntersectionBox: function isIntersectionBox(box) {
  29357. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29358. return this.intersectsBox(box);
  29359. },
  29360. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29361. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29362. return this.intersectsSphere(sphere);
  29363. },
  29364. size: function size(optionalTarget) {
  29365. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29366. return this.getSize(optionalTarget);
  29367. }
  29368. });
  29369. Object.assign(Sphere.prototype, {
  29370. empty: function empty() {
  29371. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29372. return this.isEmpty();
  29373. }
  29374. });
  29375. Frustum.prototype.setFromMatrix = function (m) {
  29376. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29377. return this.setFromProjectionMatrix(m);
  29378. };
  29379. Line3.prototype.center = function (optionalTarget) {
  29380. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29381. return this.getCenter(optionalTarget);
  29382. };
  29383. Object.assign(MathUtils, {
  29384. random16: function random16() {
  29385. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29386. return Math.random();
  29387. },
  29388. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29389. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29390. return MathUtils.floorPowerOfTwo(value);
  29391. },
  29392. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29393. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29394. return MathUtils.ceilPowerOfTwo(value);
  29395. }
  29396. });
  29397. Object.assign(Matrix3.prototype, {
  29398. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29399. console.warn('THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29400. return this.toArray(array, offset);
  29401. },
  29402. multiplyVector3: function multiplyVector3(vector) {
  29403. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29404. return vector.applyMatrix3(this);
  29405. },
  29406. multiplyVector3Array: function multiplyVector3Array()
  29407. /* a */
  29408. {
  29409. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29410. },
  29411. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29412. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29413. return attribute.applyMatrix3(this);
  29414. },
  29415. applyToVector3Array: function applyToVector3Array()
  29416. /* array, offset, length */
  29417. {
  29418. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29419. },
  29420. getInverse: function getInverse(matrix) {
  29421. console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29422. return this.copy(matrix).invert();
  29423. }
  29424. });
  29425. Object.assign(Matrix4.prototype, {
  29426. extractPosition: function extractPosition(m) {
  29427. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29428. return this.copyPosition(m);
  29429. },
  29430. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29431. console.warn('THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29432. return this.toArray(array, offset);
  29433. },
  29434. getPosition: function getPosition() {
  29435. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29436. return new Vector3().setFromMatrixColumn(this, 3);
  29437. },
  29438. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29439. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29440. return this.makeRotationFromQuaternion(q);
  29441. },
  29442. multiplyToArray: function multiplyToArray() {
  29443. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29444. },
  29445. multiplyVector3: function multiplyVector3(vector) {
  29446. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29447. return vector.applyMatrix4(this);
  29448. },
  29449. multiplyVector4: function multiplyVector4(vector) {
  29450. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29451. return vector.applyMatrix4(this);
  29452. },
  29453. multiplyVector3Array: function multiplyVector3Array()
  29454. /* a */
  29455. {
  29456. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29457. },
  29458. rotateAxis: function rotateAxis(v) {
  29459. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29460. v.transformDirection(this);
  29461. },
  29462. crossVector: function crossVector(vector) {
  29463. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29464. return vector.applyMatrix4(this);
  29465. },
  29466. translate: function translate() {
  29467. console.error('THREE.Matrix4: .translate() has been removed.');
  29468. },
  29469. rotateX: function rotateX() {
  29470. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29471. },
  29472. rotateY: function rotateY() {
  29473. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29474. },
  29475. rotateZ: function rotateZ() {
  29476. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29477. },
  29478. rotateByAxis: function rotateByAxis() {
  29479. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29480. },
  29481. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29482. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29483. return attribute.applyMatrix4(this);
  29484. },
  29485. applyToVector3Array: function applyToVector3Array()
  29486. /* array, offset, length */
  29487. {
  29488. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29489. },
  29490. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29491. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29492. return this.makePerspective(left, right, top, bottom, near, far);
  29493. },
  29494. getInverse: function getInverse(matrix) {
  29495. console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29496. return this.copy(matrix).invert();
  29497. }
  29498. });
  29499. Plane.prototype.isIntersectionLine = function (line) {
  29500. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29501. return this.intersectsLine(line);
  29502. };
  29503. Object.assign(Quaternion.prototype, {
  29504. multiplyVector3: function multiplyVector3(vector) {
  29505. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29506. return vector.applyQuaternion(this);
  29507. },
  29508. inverse: function inverse() {
  29509. console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');
  29510. return this.invert();
  29511. }
  29512. });
  29513. Object.assign(Ray.prototype, {
  29514. isIntersectionBox: function isIntersectionBox(box) {
  29515. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29516. return this.intersectsBox(box);
  29517. },
  29518. isIntersectionPlane: function isIntersectionPlane(plane) {
  29519. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29520. return this.intersectsPlane(plane);
  29521. },
  29522. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29523. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29524. return this.intersectsSphere(sphere);
  29525. }
  29526. });
  29527. Object.assign(Triangle.prototype, {
  29528. area: function area() {
  29529. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29530. return this.getArea();
  29531. },
  29532. barycoordFromPoint: function barycoordFromPoint(point, target) {
  29533. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29534. return this.getBarycoord(point, target);
  29535. },
  29536. midpoint: function midpoint(target) {
  29537. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29538. return this.getMidpoint(target);
  29539. },
  29540. normal: function normal(target) {
  29541. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29542. return this.getNormal(target);
  29543. },
  29544. plane: function plane(target) {
  29545. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29546. return this.getPlane(target);
  29547. }
  29548. });
  29549. Object.assign(Triangle, {
  29550. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  29551. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29552. return Triangle.getBarycoord(point, a, b, c, target);
  29553. },
  29554. normal: function normal(a, b, c, target) {
  29555. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29556. return Triangle.getNormal(a, b, c, target);
  29557. }
  29558. });
  29559. Object.assign(Shape.prototype, {
  29560. extractAllPoints: function extractAllPoints(divisions) {
  29561. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29562. return this.extractPoints(divisions);
  29563. },
  29564. extrude: function extrude(options) {
  29565. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  29566. return new ExtrudeGeometry(this, options);
  29567. },
  29568. makeGeometry: function makeGeometry(options) {
  29569. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  29570. return new ShapeGeometry(this, options);
  29571. }
  29572. });
  29573. Object.assign(Vector2.prototype, {
  29574. fromAttribute: function fromAttribute(attribute, index, offset) {
  29575. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29576. return this.fromBufferAttribute(attribute, index, offset);
  29577. },
  29578. distanceToManhattan: function distanceToManhattan(v) {
  29579. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29580. return this.manhattanDistanceTo(v);
  29581. },
  29582. lengthManhattan: function lengthManhattan() {
  29583. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  29584. return this.manhattanLength();
  29585. }
  29586. });
  29587. Object.assign(Vector3.prototype, {
  29588. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  29589. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  29590. },
  29591. setEulerFromQuaternion: function setEulerFromQuaternion() {
  29592. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  29593. },
  29594. getPositionFromMatrix: function getPositionFromMatrix(m) {
  29595. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  29596. return this.setFromMatrixPosition(m);
  29597. },
  29598. getScaleFromMatrix: function getScaleFromMatrix(m) {
  29599. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  29600. return this.setFromMatrixScale(m);
  29601. },
  29602. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  29603. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  29604. return this.setFromMatrixColumn(matrix, index);
  29605. },
  29606. applyProjection: function applyProjection(m) {
  29607. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  29608. return this.applyMatrix4(m);
  29609. },
  29610. fromAttribute: function fromAttribute(attribute, index, offset) {
  29611. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29612. return this.fromBufferAttribute(attribute, index, offset);
  29613. },
  29614. distanceToManhattan: function distanceToManhattan(v) {
  29615. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29616. return this.manhattanDistanceTo(v);
  29617. },
  29618. lengthManhattan: function lengthManhattan() {
  29619. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  29620. return this.manhattanLength();
  29621. }
  29622. });
  29623. Object.assign(Vector4.prototype, {
  29624. fromAttribute: function fromAttribute(attribute, index, offset) {
  29625. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29626. return this.fromBufferAttribute(attribute, index, offset);
  29627. },
  29628. lengthManhattan: function lengthManhattan() {
  29629. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  29630. return this.manhattanLength();
  29631. }
  29632. }); //
  29633. Object.assign(Geometry.prototype, {
  29634. computeTangents: function computeTangents() {
  29635. console.error('THREE.Geometry: .computeTangents() has been removed.');
  29636. },
  29637. computeLineDistances: function computeLineDistances() {
  29638. console.error('THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.');
  29639. },
  29640. applyMatrix: function applyMatrix(matrix) {
  29641. console.warn('THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29642. return this.applyMatrix4(matrix);
  29643. }
  29644. }); //
  29645. Object.assign(Object3D.prototype, {
  29646. getChildByName: function getChildByName(name) {
  29647. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  29648. return this.getObjectByName(name);
  29649. },
  29650. renderDepth: function renderDepth() {
  29651. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  29652. },
  29653. translate: function translate(distance, axis) {
  29654. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  29655. return this.translateOnAxis(axis, distance);
  29656. },
  29657. getWorldRotation: function getWorldRotation() {
  29658. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  29659. },
  29660. applyMatrix: function applyMatrix(matrix) {
  29661. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  29662. return this.applyMatrix4(matrix);
  29663. }
  29664. });
  29665. Object.defineProperties(Object3D.prototype, {
  29666. eulerOrder: {
  29667. get: function get() {
  29668. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29669. return this.rotation.order;
  29670. },
  29671. set: function set(value) {
  29672. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29673. this.rotation.order = value;
  29674. }
  29675. },
  29676. useQuaternion: {
  29677. get: function get() {
  29678. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29679. },
  29680. set: function set() {
  29681. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29682. }
  29683. }
  29684. });
  29685. Object.assign(Mesh.prototype, {
  29686. setDrawMode: function setDrawMode() {
  29687. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29688. }
  29689. });
  29690. Object.defineProperties(Mesh.prototype, {
  29691. drawMode: {
  29692. get: function get() {
  29693. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  29694. return TrianglesDrawMode;
  29695. },
  29696. set: function set() {
  29697. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29698. }
  29699. }
  29700. });
  29701. Object.defineProperties(LOD.prototype, {
  29702. objects: {
  29703. get: function get() {
  29704. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  29705. return this.levels;
  29706. }
  29707. }
  29708. });
  29709. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  29710. get: function get() {
  29711. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29712. },
  29713. set: function set() {
  29714. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29715. }
  29716. });
  29717. SkinnedMesh.prototype.initBones = function () {
  29718. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  29719. };
  29720. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  29721. get: function get() {
  29722. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29723. return this.arcLengthDivisions;
  29724. },
  29725. set: function set(value) {
  29726. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29727. this.arcLengthDivisions = value;
  29728. }
  29729. }); //
  29730. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  29731. console.warn('THREE.PerspectiveCamera.setLens is deprecated. ' + 'Use .setFocalLength and .filmGauge for a photographic setup.');
  29732. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  29733. this.setFocalLength(focalLength);
  29734. }; //
  29735. Object.defineProperties(Light.prototype, {
  29736. onlyShadow: {
  29737. set: function set() {
  29738. console.warn('THREE.Light: .onlyShadow has been removed.');
  29739. }
  29740. },
  29741. shadowCameraFov: {
  29742. set: function set(value) {
  29743. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  29744. this.shadow.camera.fov = value;
  29745. }
  29746. },
  29747. shadowCameraLeft: {
  29748. set: function set(value) {
  29749. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  29750. this.shadow.camera.left = value;
  29751. }
  29752. },
  29753. shadowCameraRight: {
  29754. set: function set(value) {
  29755. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  29756. this.shadow.camera.right = value;
  29757. }
  29758. },
  29759. shadowCameraTop: {
  29760. set: function set(value) {
  29761. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  29762. this.shadow.camera.top = value;
  29763. }
  29764. },
  29765. shadowCameraBottom: {
  29766. set: function set(value) {
  29767. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  29768. this.shadow.camera.bottom = value;
  29769. }
  29770. },
  29771. shadowCameraNear: {
  29772. set: function set(value) {
  29773. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  29774. this.shadow.camera.near = value;
  29775. }
  29776. },
  29777. shadowCameraFar: {
  29778. set: function set(value) {
  29779. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  29780. this.shadow.camera.far = value;
  29781. }
  29782. },
  29783. shadowCameraVisible: {
  29784. set: function set() {
  29785. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  29786. }
  29787. },
  29788. shadowBias: {
  29789. set: function set(value) {
  29790. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  29791. this.shadow.bias = value;
  29792. }
  29793. },
  29794. shadowDarkness: {
  29795. set: function set() {
  29796. console.warn('THREE.Light: .shadowDarkness has been removed.');
  29797. }
  29798. },
  29799. shadowMapWidth: {
  29800. set: function set(value) {
  29801. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  29802. this.shadow.mapSize.width = value;
  29803. }
  29804. },
  29805. shadowMapHeight: {
  29806. set: function set(value) {
  29807. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  29808. this.shadow.mapSize.height = value;
  29809. }
  29810. }
  29811. }); //
  29812. Object.defineProperties(BufferAttribute.prototype, {
  29813. length: {
  29814. get: function get() {
  29815. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  29816. return this.array.length;
  29817. }
  29818. },
  29819. dynamic: {
  29820. get: function get() {
  29821. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29822. return this.usage === DynamicDrawUsage;
  29823. },
  29824. set: function set()
  29825. /* value */
  29826. {
  29827. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29828. this.setUsage(DynamicDrawUsage);
  29829. }
  29830. }
  29831. });
  29832. Object.assign(BufferAttribute.prototype, {
  29833. setDynamic: function setDynamic(value) {
  29834. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29835. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29836. return this;
  29837. },
  29838. copyIndicesArray: function copyIndicesArray()
  29839. /* indices */
  29840. {
  29841. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  29842. },
  29843. setArray: function setArray()
  29844. /* array */
  29845. {
  29846. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29847. }
  29848. });
  29849. Object.assign(BufferGeometry.prototype, {
  29850. addIndex: function addIndex(index) {
  29851. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  29852. this.setIndex(index);
  29853. },
  29854. addAttribute: function addAttribute(name, attribute) {
  29855. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  29856. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  29857. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  29858. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  29859. }
  29860. if (name === 'index') {
  29861. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  29862. this.setIndex(attribute);
  29863. return this;
  29864. }
  29865. return this.setAttribute(name, attribute);
  29866. },
  29867. addDrawCall: function addDrawCall(start, count, indexOffset) {
  29868. if (indexOffset !== undefined) {
  29869. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  29870. }
  29871. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  29872. this.addGroup(start, count);
  29873. },
  29874. clearDrawCalls: function clearDrawCalls() {
  29875. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  29876. this.clearGroups();
  29877. },
  29878. computeTangents: function computeTangents() {
  29879. console.warn('THREE.BufferGeometry: .computeTangents() has been removed.');
  29880. },
  29881. computeOffsets: function computeOffsets() {
  29882. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  29883. },
  29884. removeAttribute: function removeAttribute(name) {
  29885. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  29886. return this.deleteAttribute(name);
  29887. },
  29888. applyMatrix: function applyMatrix(matrix) {
  29889. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29890. return this.applyMatrix4(matrix);
  29891. }
  29892. });
  29893. Object.defineProperties(BufferGeometry.prototype, {
  29894. drawcalls: {
  29895. get: function get() {
  29896. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  29897. return this.groups;
  29898. }
  29899. },
  29900. offsets: {
  29901. get: function get() {
  29902. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  29903. return this.groups;
  29904. }
  29905. }
  29906. });
  29907. Object.defineProperties(InstancedBufferGeometry.prototype, {
  29908. maxInstancedCount: {
  29909. get: function get() {
  29910. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29911. return this.instanceCount;
  29912. },
  29913. set: function set(value) {
  29914. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29915. this.instanceCount = value;
  29916. }
  29917. }
  29918. });
  29919. Object.defineProperties(Raycaster.prototype, {
  29920. linePrecision: {
  29921. get: function get() {
  29922. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29923. return this.params.Line.threshold;
  29924. },
  29925. set: function set(value) {
  29926. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29927. this.params.Line.threshold = value;
  29928. }
  29929. }
  29930. });
  29931. Object.defineProperties(InterleavedBuffer.prototype, {
  29932. dynamic: {
  29933. get: function get() {
  29934. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29935. return this.usage === DynamicDrawUsage;
  29936. },
  29937. set: function set(value) {
  29938. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29939. this.setUsage(value);
  29940. }
  29941. }
  29942. });
  29943. Object.assign(InterleavedBuffer.prototype, {
  29944. setDynamic: function setDynamic(value) {
  29945. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29946. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29947. return this;
  29948. },
  29949. setArray: function setArray()
  29950. /* array */
  29951. {
  29952. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29953. }
  29954. }); //
  29955. Object.assign(ExtrudeGeometry.prototype, {
  29956. getArrays: function getArrays() {
  29957. console.error('THREE.ExtrudeGeometry: .getArrays() has been removed.');
  29958. },
  29959. addShapeList: function addShapeList() {
  29960. console.error('THREE.ExtrudeGeometry: .addShapeList() has been removed.');
  29961. },
  29962. addShape: function addShape() {
  29963. console.error('THREE.ExtrudeGeometry: .addShape() has been removed.');
  29964. }
  29965. }); //
  29966. Object.assign(Scene.prototype, {
  29967. dispose: function dispose() {
  29968. console.error('THREE.Scene: .dispose() has been removed.');
  29969. }
  29970. }); //
  29971. Object.defineProperties(Uniform.prototype, {
  29972. dynamic: {
  29973. set: function set() {
  29974. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  29975. }
  29976. },
  29977. onUpdate: {
  29978. value: function value() {
  29979. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  29980. return this;
  29981. }
  29982. }
  29983. }); //
  29984. Object.defineProperties(Material.prototype, {
  29985. wrapAround: {
  29986. get: function get() {
  29987. console.warn('THREE.Material: .wrapAround has been removed.');
  29988. },
  29989. set: function set() {
  29990. console.warn('THREE.Material: .wrapAround has been removed.');
  29991. }
  29992. },
  29993. overdraw: {
  29994. get: function get() {
  29995. console.warn('THREE.Material: .overdraw has been removed.');
  29996. },
  29997. set: function set() {
  29998. console.warn('THREE.Material: .overdraw has been removed.');
  29999. }
  30000. },
  30001. wrapRGB: {
  30002. get: function get() {
  30003. console.warn('THREE.Material: .wrapRGB has been removed.');
  30004. return new Color();
  30005. }
  30006. },
  30007. shading: {
  30008. get: function get() {
  30009. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30010. },
  30011. set: function set(value) {
  30012. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30013. this.flatShading = value === FlatShading;
  30014. }
  30015. },
  30016. stencilMask: {
  30017. get: function get() {
  30018. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30019. return this.stencilFuncMask;
  30020. },
  30021. set: function set(value) {
  30022. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30023. this.stencilFuncMask = value;
  30024. }
  30025. }
  30026. });
  30027. Object.defineProperties(MeshPhongMaterial.prototype, {
  30028. metal: {
  30029. get: function get() {
  30030. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  30031. return false;
  30032. },
  30033. set: function set() {
  30034. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  30035. }
  30036. }
  30037. });
  30038. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  30039. transparency: {
  30040. get: function get() {
  30041. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30042. return this.transmission;
  30043. },
  30044. set: function set(value) {
  30045. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30046. this.transmission = value;
  30047. }
  30048. }
  30049. });
  30050. Object.defineProperties(ShaderMaterial.prototype, {
  30051. derivatives: {
  30052. get: function get() {
  30053. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30054. return this.extensions.derivatives;
  30055. },
  30056. set: function set(value) {
  30057. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30058. this.extensions.derivatives = value;
  30059. }
  30060. }
  30061. }); //
  30062. Object.assign(WebGLRenderer.prototype, {
  30063. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  30064. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  30065. this.setRenderTarget(renderTarget);
  30066. this.clear(color, depth, stencil);
  30067. },
  30068. animate: function animate(callback) {
  30069. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  30070. this.setAnimationLoop(callback);
  30071. },
  30072. getCurrentRenderTarget: function getCurrentRenderTarget() {
  30073. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  30074. return this.getRenderTarget();
  30075. },
  30076. getMaxAnisotropy: function getMaxAnisotropy() {
  30077. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  30078. return this.capabilities.getMaxAnisotropy();
  30079. },
  30080. getPrecision: function getPrecision() {
  30081. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  30082. return this.capabilities.precision;
  30083. },
  30084. resetGLState: function resetGLState() {
  30085. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  30086. return this.state.reset();
  30087. },
  30088. supportsFloatTextures: function supportsFloatTextures() {
  30089. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  30090. return this.extensions.get('OES_texture_float');
  30091. },
  30092. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  30093. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  30094. return this.extensions.get('OES_texture_half_float');
  30095. },
  30096. supportsStandardDerivatives: function supportsStandardDerivatives() {
  30097. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  30098. return this.extensions.get('OES_standard_derivatives');
  30099. },
  30100. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  30101. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  30102. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  30103. },
  30104. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  30105. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  30106. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  30107. },
  30108. supportsBlendMinMax: function supportsBlendMinMax() {
  30109. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  30110. return this.extensions.get('EXT_blend_minmax');
  30111. },
  30112. supportsVertexTextures: function supportsVertexTextures() {
  30113. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  30114. return this.capabilities.vertexTextures;
  30115. },
  30116. supportsInstancedArrays: function supportsInstancedArrays() {
  30117. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  30118. return this.extensions.get('ANGLE_instanced_arrays');
  30119. },
  30120. enableScissorTest: function enableScissorTest(boolean) {
  30121. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  30122. this.setScissorTest(boolean);
  30123. },
  30124. initMaterial: function initMaterial() {
  30125. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  30126. },
  30127. addPrePlugin: function addPrePlugin() {
  30128. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  30129. },
  30130. addPostPlugin: function addPostPlugin() {
  30131. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  30132. },
  30133. updateShadowMap: function updateShadowMap() {
  30134. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  30135. },
  30136. setFaceCulling: function setFaceCulling() {
  30137. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  30138. },
  30139. allocTextureUnit: function allocTextureUnit() {
  30140. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  30141. },
  30142. setTexture: function setTexture() {
  30143. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  30144. },
  30145. setTexture2D: function setTexture2D() {
  30146. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  30147. },
  30148. setTextureCube: function setTextureCube() {
  30149. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  30150. },
  30151. getActiveMipMapLevel: function getActiveMipMapLevel() {
  30152. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  30153. return this.getActiveMipmapLevel();
  30154. }
  30155. });
  30156. Object.defineProperties(WebGLRenderer.prototype, {
  30157. shadowMapEnabled: {
  30158. get: function get() {
  30159. return this.shadowMap.enabled;
  30160. },
  30161. set: function set(value) {
  30162. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  30163. this.shadowMap.enabled = value;
  30164. }
  30165. },
  30166. shadowMapType: {
  30167. get: function get() {
  30168. return this.shadowMap.type;
  30169. },
  30170. set: function set(value) {
  30171. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  30172. this.shadowMap.type = value;
  30173. }
  30174. },
  30175. shadowMapCullFace: {
  30176. get: function get() {
  30177. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30178. return undefined;
  30179. },
  30180. set: function set()
  30181. /* value */
  30182. {
  30183. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30184. }
  30185. },
  30186. context: {
  30187. get: function get() {
  30188. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  30189. return this.getContext();
  30190. }
  30191. },
  30192. vr: {
  30193. get: function get() {
  30194. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  30195. return this.xr;
  30196. }
  30197. },
  30198. gammaInput: {
  30199. get: function get() {
  30200. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30201. return false;
  30202. },
  30203. set: function set() {
  30204. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30205. }
  30206. },
  30207. gammaOutput: {
  30208. get: function get() {
  30209. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30210. return false;
  30211. },
  30212. set: function set(value) {
  30213. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30214. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  30215. }
  30216. },
  30217. toneMappingWhitePoint: {
  30218. get: function get() {
  30219. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30220. return 1.0;
  30221. },
  30222. set: function set() {
  30223. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30224. }
  30225. }
  30226. });
  30227. Object.defineProperties(WebGLShadowMap.prototype, {
  30228. cullFace: {
  30229. get: function get() {
  30230. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30231. return undefined;
  30232. },
  30233. set: function set()
  30234. /* cullFace */
  30235. {
  30236. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30237. }
  30238. },
  30239. renderReverseSided: {
  30240. get: function get() {
  30241. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30242. return undefined;
  30243. },
  30244. set: function set() {
  30245. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30246. }
  30247. },
  30248. renderSingleSided: {
  30249. get: function get() {
  30250. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30251. return undefined;
  30252. },
  30253. set: function set() {
  30254. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30255. }
  30256. }
  30257. });
  30258. function WebGLRenderTargetCube(width, height, options) {
  30259. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  30260. return new WebGLCubeRenderTarget(width, options);
  30261. } //
  30262. Object.defineProperties(WebGLRenderTarget.prototype, {
  30263. wrapS: {
  30264. get: function get() {
  30265. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30266. return this.texture.wrapS;
  30267. },
  30268. set: function set(value) {
  30269. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30270. this.texture.wrapS = value;
  30271. }
  30272. },
  30273. wrapT: {
  30274. get: function get() {
  30275. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30276. return this.texture.wrapT;
  30277. },
  30278. set: function set(value) {
  30279. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30280. this.texture.wrapT = value;
  30281. }
  30282. },
  30283. magFilter: {
  30284. get: function get() {
  30285. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30286. return this.texture.magFilter;
  30287. },
  30288. set: function set(value) {
  30289. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30290. this.texture.magFilter = value;
  30291. }
  30292. },
  30293. minFilter: {
  30294. get: function get() {
  30295. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30296. return this.texture.minFilter;
  30297. },
  30298. set: function set(value) {
  30299. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30300. this.texture.minFilter = value;
  30301. }
  30302. },
  30303. anisotropy: {
  30304. get: function get() {
  30305. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30306. return this.texture.anisotropy;
  30307. },
  30308. set: function set(value) {
  30309. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30310. this.texture.anisotropy = value;
  30311. }
  30312. },
  30313. offset: {
  30314. get: function get() {
  30315. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30316. return this.texture.offset;
  30317. },
  30318. set: function set(value) {
  30319. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30320. this.texture.offset = value;
  30321. }
  30322. },
  30323. repeat: {
  30324. get: function get() {
  30325. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30326. return this.texture.repeat;
  30327. },
  30328. set: function set(value) {
  30329. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30330. this.texture.repeat = value;
  30331. }
  30332. },
  30333. format: {
  30334. get: function get() {
  30335. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30336. return this.texture.format;
  30337. },
  30338. set: function set(value) {
  30339. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30340. this.texture.format = value;
  30341. }
  30342. },
  30343. type: {
  30344. get: function get() {
  30345. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30346. return this.texture.type;
  30347. },
  30348. set: function set(value) {
  30349. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30350. this.texture.type = value;
  30351. }
  30352. },
  30353. generateMipmaps: {
  30354. get: function get() {
  30355. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30356. return this.texture.generateMipmaps;
  30357. },
  30358. set: function set(value) {
  30359. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30360. this.texture.generateMipmaps = value;
  30361. }
  30362. }
  30363. }); //
  30364. Object.defineProperties(Audio.prototype, {
  30365. load: {
  30366. value: function value(file) {
  30367. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30368. var scope = this;
  30369. var audioLoader = new AudioLoader();
  30370. audioLoader.load(file, function (buffer) {
  30371. scope.setBuffer(buffer);
  30372. });
  30373. return this;
  30374. }
  30375. },
  30376. startTime: {
  30377. set: function set() {
  30378. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30379. }
  30380. }
  30381. });
  30382. AudioAnalyser.prototype.getData = function () {
  30383. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30384. return this.getFrequencyData();
  30385. }; //
  30386. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30387. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30388. return this.update(renderer, scene);
  30389. };
  30390. CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
  30391. console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
  30392. return this.renderTarget.clear(renderer, color, depth, stencil);
  30393. }; //
  30394. var GeometryUtils = {
  30395. merge: function merge(geometry1, geometry2, materialIndexOffset) {
  30396. console.warn('THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.');
  30397. var matrix;
  30398. if (geometry2.isMesh) {
  30399. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30400. matrix = geometry2.matrix;
  30401. geometry2 = geometry2.geometry;
  30402. }
  30403. geometry1.merge(geometry2, matrix, materialIndexOffset);
  30404. },
  30405. center: function center(geometry) {
  30406. console.warn('THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.');
  30407. return geometry.center();
  30408. }
  30409. };
  30410. ImageUtils.crossOrigin = undefined;
  30411. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30412. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30413. var loader = new TextureLoader();
  30414. loader.setCrossOrigin(this.crossOrigin);
  30415. var texture = loader.load(url, onLoad, undefined, onError);
  30416. if (mapping) texture.mapping = mapping;
  30417. return texture;
  30418. };
  30419. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30420. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30421. var loader = new CubeTextureLoader();
  30422. loader.setCrossOrigin(this.crossOrigin);
  30423. var texture = loader.load(urls, onLoad, undefined, onError);
  30424. if (mapping) texture.mapping = mapping;
  30425. return texture;
  30426. };
  30427. ImageUtils.loadCompressedTexture = function () {
  30428. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30429. };
  30430. ImageUtils.loadCompressedTextureCube = function () {
  30431. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30432. }; //
  30433. function CanvasRenderer() {
  30434. console.error('THREE.CanvasRenderer has been removed');
  30435. } //
  30436. function JSONLoader() {
  30437. console.error('THREE.JSONLoader has been removed.');
  30438. } //
  30439. var SceneUtils = {
  30440. createMultiMaterialObject: function createMultiMaterialObject()
  30441. /* geometry, materials */
  30442. {
  30443. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30444. },
  30445. detach: function detach()
  30446. /* child, parent, scene */
  30447. {
  30448. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30449. },
  30450. attach: function attach()
  30451. /* child, scene, parent */
  30452. {
  30453. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30454. }
  30455. }; //
  30456. function LensFlare() {
  30457. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30458. }
  30459. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30460. /* eslint-disable no-undef */
  30461. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30462. detail: {
  30463. revision: REVISION
  30464. }
  30465. }));
  30466. /* eslint-enable no-undef */
  30467. }
  30468. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30469. exports.AddEquation = AddEquation;
  30470. exports.AddOperation = AddOperation;
  30471. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30472. exports.AdditiveBlending = AdditiveBlending;
  30473. exports.AlphaFormat = AlphaFormat;
  30474. exports.AlwaysDepth = AlwaysDepth;
  30475. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30476. exports.AmbientLight = AmbientLight;
  30477. exports.AmbientLightProbe = AmbientLightProbe;
  30478. exports.AnimationClip = AnimationClip;
  30479. exports.AnimationLoader = AnimationLoader;
  30480. exports.AnimationMixer = AnimationMixer;
  30481. exports.AnimationObjectGroup = AnimationObjectGroup;
  30482. exports.AnimationUtils = AnimationUtils;
  30483. exports.ArcCurve = ArcCurve;
  30484. exports.ArrayCamera = ArrayCamera;
  30485. exports.ArrowHelper = ArrowHelper;
  30486. exports.Audio = Audio;
  30487. exports.AudioAnalyser = AudioAnalyser;
  30488. exports.AudioContext = AudioContext;
  30489. exports.AudioListener = AudioListener;
  30490. exports.AudioLoader = AudioLoader;
  30491. exports.AxesHelper = AxesHelper;
  30492. exports.AxisHelper = AxisHelper;
  30493. exports.BackSide = BackSide;
  30494. exports.BasicDepthPacking = BasicDepthPacking;
  30495. exports.BasicShadowMap = BasicShadowMap;
  30496. exports.BinaryTextureLoader = BinaryTextureLoader;
  30497. exports.Bone = Bone;
  30498. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30499. exports.BoundingBoxHelper = BoundingBoxHelper;
  30500. exports.Box2 = Box2;
  30501. exports.Box3 = Box3;
  30502. exports.Box3Helper = Box3Helper;
  30503. exports.BoxBufferGeometry = BoxGeometry;
  30504. exports.BoxGeometry = BoxGeometry;
  30505. exports.BoxHelper = BoxHelper;
  30506. exports.BufferAttribute = BufferAttribute;
  30507. exports.BufferGeometry = BufferGeometry;
  30508. exports.BufferGeometryLoader = BufferGeometryLoader;
  30509. exports.ByteType = ByteType;
  30510. exports.Cache = Cache;
  30511. exports.Camera = Camera;
  30512. exports.CameraHelper = CameraHelper;
  30513. exports.CanvasRenderer = CanvasRenderer;
  30514. exports.CanvasTexture = CanvasTexture;
  30515. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30516. exports.CineonToneMapping = CineonToneMapping;
  30517. exports.CircleBufferGeometry = CircleGeometry;
  30518. exports.CircleGeometry = CircleGeometry;
  30519. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30520. exports.Clock = Clock;
  30521. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  30522. exports.Color = Color;
  30523. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30524. exports.CompressedTexture = CompressedTexture;
  30525. exports.CompressedTextureLoader = CompressedTextureLoader;
  30526. exports.ConeBufferGeometry = ConeGeometry;
  30527. exports.ConeGeometry = ConeGeometry;
  30528. exports.CubeCamera = CubeCamera;
  30529. exports.CubeReflectionMapping = CubeReflectionMapping;
  30530. exports.CubeRefractionMapping = CubeRefractionMapping;
  30531. exports.CubeTexture = CubeTexture;
  30532. exports.CubeTextureLoader = CubeTextureLoader;
  30533. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30534. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30535. exports.CubicBezierCurve = CubicBezierCurve;
  30536. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30537. exports.CubicInterpolant = CubicInterpolant;
  30538. exports.CullFaceBack = CullFaceBack;
  30539. exports.CullFaceFront = CullFaceFront;
  30540. exports.CullFaceFrontBack = CullFaceFrontBack;
  30541. exports.CullFaceNone = CullFaceNone;
  30542. exports.Curve = Curve;
  30543. exports.CurvePath = CurvePath;
  30544. exports.CustomBlending = CustomBlending;
  30545. exports.CustomToneMapping = CustomToneMapping;
  30546. exports.CylinderBufferGeometry = CylinderGeometry;
  30547. exports.CylinderGeometry = CylinderGeometry;
  30548. exports.Cylindrical = Cylindrical;
  30549. exports.DataTexture = DataTexture;
  30550. exports.DataTexture2DArray = DataTexture2DArray;
  30551. exports.DataTexture3D = DataTexture3D;
  30552. exports.DataTextureLoader = DataTextureLoader;
  30553. exports.DataUtils = DataUtils;
  30554. exports.DecrementStencilOp = DecrementStencilOp;
  30555. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30556. exports.DefaultLoadingManager = DefaultLoadingManager;
  30557. exports.DepthFormat = DepthFormat;
  30558. exports.DepthStencilFormat = DepthStencilFormat;
  30559. exports.DepthTexture = DepthTexture;
  30560. exports.DirectionalLight = DirectionalLight;
  30561. exports.DirectionalLightHelper = DirectionalLightHelper;
  30562. exports.DiscreteInterpolant = DiscreteInterpolant;
  30563. exports.DodecahedronBufferGeometry = DodecahedronGeometry;
  30564. exports.DodecahedronGeometry = DodecahedronGeometry;
  30565. exports.DoubleSide = DoubleSide;
  30566. exports.DstAlphaFactor = DstAlphaFactor;
  30567. exports.DstColorFactor = DstColorFactor;
  30568. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30569. exports.DynamicCopyUsage = DynamicCopyUsage;
  30570. exports.DynamicDrawUsage = DynamicDrawUsage;
  30571. exports.DynamicReadUsage = DynamicReadUsage;
  30572. exports.EdgesGeometry = EdgesGeometry;
  30573. exports.EdgesHelper = EdgesHelper;
  30574. exports.EllipseCurve = EllipseCurve;
  30575. exports.EqualDepth = EqualDepth;
  30576. exports.EqualStencilFunc = EqualStencilFunc;
  30577. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30578. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30579. exports.Euler = Euler;
  30580. exports.EventDispatcher = EventDispatcher;
  30581. exports.ExtrudeBufferGeometry = ExtrudeGeometry;
  30582. exports.ExtrudeGeometry = ExtrudeGeometry;
  30583. exports.Face3 = Face3;
  30584. exports.Face4 = Face4;
  30585. exports.FaceColors = FaceColors;
  30586. exports.FileLoader = FileLoader;
  30587. exports.FlatShading = FlatShading;
  30588. exports.Float16BufferAttribute = Float16BufferAttribute;
  30589. exports.Float32Attribute = Float32Attribute;
  30590. exports.Float32BufferAttribute = Float32BufferAttribute;
  30591. exports.Float64Attribute = Float64Attribute;
  30592. exports.Float64BufferAttribute = Float64BufferAttribute;
  30593. exports.FloatType = FloatType;
  30594. exports.Fog = Fog;
  30595. exports.FogExp2 = FogExp2;
  30596. exports.Font = Font;
  30597. exports.FontLoader = FontLoader;
  30598. exports.FrontSide = FrontSide;
  30599. exports.Frustum = Frustum;
  30600. exports.GLBufferAttribute = GLBufferAttribute;
  30601. exports.GLSL1 = GLSL1;
  30602. exports.GLSL3 = GLSL3;
  30603. exports.GammaEncoding = GammaEncoding;
  30604. exports.Geometry = Geometry;
  30605. exports.GeometryUtils = GeometryUtils;
  30606. exports.GreaterDepth = GreaterDepth;
  30607. exports.GreaterEqualDepth = GreaterEqualDepth;
  30608. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30609. exports.GreaterStencilFunc = GreaterStencilFunc;
  30610. exports.GridHelper = GridHelper;
  30611. exports.Group = Group;
  30612. exports.HalfFloatType = HalfFloatType;
  30613. exports.HemisphereLight = HemisphereLight;
  30614. exports.HemisphereLightHelper = HemisphereLightHelper;
  30615. exports.HemisphereLightProbe = HemisphereLightProbe;
  30616. exports.IcosahedronBufferGeometry = IcosahedronGeometry;
  30617. exports.IcosahedronGeometry = IcosahedronGeometry;
  30618. exports.ImageBitmapLoader = ImageBitmapLoader;
  30619. exports.ImageLoader = ImageLoader;
  30620. exports.ImageUtils = ImageUtils;
  30621. exports.ImmediateRenderObject = ImmediateRenderObject;
  30622. exports.IncrementStencilOp = IncrementStencilOp;
  30623. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  30624. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  30625. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  30626. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  30627. exports.InstancedMesh = InstancedMesh;
  30628. exports.Int16Attribute = Int16Attribute;
  30629. exports.Int16BufferAttribute = Int16BufferAttribute;
  30630. exports.Int32Attribute = Int32Attribute;
  30631. exports.Int32BufferAttribute = Int32BufferAttribute;
  30632. exports.Int8Attribute = Int8Attribute;
  30633. exports.Int8BufferAttribute = Int8BufferAttribute;
  30634. exports.IntType = IntType;
  30635. exports.InterleavedBuffer = InterleavedBuffer;
  30636. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  30637. exports.Interpolant = Interpolant;
  30638. exports.InterpolateDiscrete = InterpolateDiscrete;
  30639. exports.InterpolateLinear = InterpolateLinear;
  30640. exports.InterpolateSmooth = InterpolateSmooth;
  30641. exports.InvertStencilOp = InvertStencilOp;
  30642. exports.JSONLoader = JSONLoader;
  30643. exports.KeepStencilOp = KeepStencilOp;
  30644. exports.KeyframeTrack = KeyframeTrack;
  30645. exports.LOD = LOD;
  30646. exports.LatheBufferGeometry = LatheGeometry;
  30647. exports.LatheGeometry = LatheGeometry;
  30648. exports.Layers = Layers;
  30649. exports.LensFlare = LensFlare;
  30650. exports.LessDepth = LessDepth;
  30651. exports.LessEqualDepth = LessEqualDepth;
  30652. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  30653. exports.LessStencilFunc = LessStencilFunc;
  30654. exports.Light = Light;
  30655. exports.LightProbe = LightProbe;
  30656. exports.Line = Line;
  30657. exports.Line3 = Line3;
  30658. exports.LineBasicMaterial = LineBasicMaterial;
  30659. exports.LineCurve = LineCurve;
  30660. exports.LineCurve3 = LineCurve3;
  30661. exports.LineDashedMaterial = LineDashedMaterial;
  30662. exports.LineLoop = LineLoop;
  30663. exports.LinePieces = LinePieces;
  30664. exports.LineSegments = LineSegments;
  30665. exports.LineStrip = LineStrip;
  30666. exports.LinearEncoding = LinearEncoding;
  30667. exports.LinearFilter = LinearFilter;
  30668. exports.LinearInterpolant = LinearInterpolant;
  30669. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  30670. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  30671. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  30672. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  30673. exports.LinearToneMapping = LinearToneMapping;
  30674. exports.Loader = Loader;
  30675. exports.LoaderUtils = LoaderUtils;
  30676. exports.LoadingManager = LoadingManager;
  30677. exports.LogLuvEncoding = LogLuvEncoding;
  30678. exports.LoopOnce = LoopOnce;
  30679. exports.LoopPingPong = LoopPingPong;
  30680. exports.LoopRepeat = LoopRepeat;
  30681. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  30682. exports.LuminanceFormat = LuminanceFormat;
  30683. exports.MOUSE = MOUSE;
  30684. exports.Material = Material;
  30685. exports.MaterialLoader = MaterialLoader;
  30686. exports.Math = MathUtils;
  30687. exports.MathUtils = MathUtils;
  30688. exports.Matrix3 = Matrix3;
  30689. exports.Matrix4 = Matrix4;
  30690. exports.MaxEquation = MaxEquation;
  30691. exports.Mesh = Mesh;
  30692. exports.MeshBasicMaterial = MeshBasicMaterial;
  30693. exports.MeshDepthMaterial = MeshDepthMaterial;
  30694. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  30695. exports.MeshFaceMaterial = MeshFaceMaterial;
  30696. exports.MeshLambertMaterial = MeshLambertMaterial;
  30697. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  30698. exports.MeshNormalMaterial = MeshNormalMaterial;
  30699. exports.MeshPhongMaterial = MeshPhongMaterial;
  30700. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  30701. exports.MeshStandardMaterial = MeshStandardMaterial;
  30702. exports.MeshToonMaterial = MeshToonMaterial;
  30703. exports.MinEquation = MinEquation;
  30704. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  30705. exports.MixOperation = MixOperation;
  30706. exports.MultiMaterial = MultiMaterial;
  30707. exports.MultiplyBlending = MultiplyBlending;
  30708. exports.MultiplyOperation = MultiplyOperation;
  30709. exports.NearestFilter = NearestFilter;
  30710. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  30711. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  30712. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  30713. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  30714. exports.NeverDepth = NeverDepth;
  30715. exports.NeverStencilFunc = NeverStencilFunc;
  30716. exports.NoBlending = NoBlending;
  30717. exports.NoColors = NoColors;
  30718. exports.NoToneMapping = NoToneMapping;
  30719. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  30720. exports.NormalBlending = NormalBlending;
  30721. exports.NotEqualDepth = NotEqualDepth;
  30722. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  30723. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  30724. exports.Object3D = Object3D;
  30725. exports.ObjectLoader = ObjectLoader;
  30726. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  30727. exports.OctahedronBufferGeometry = OctahedronGeometry;
  30728. exports.OctahedronGeometry = OctahedronGeometry;
  30729. exports.OneFactor = OneFactor;
  30730. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  30731. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  30732. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  30733. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  30734. exports.OrthographicCamera = OrthographicCamera;
  30735. exports.PCFShadowMap = PCFShadowMap;
  30736. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  30737. exports.PMREMGenerator = PMREMGenerator;
  30738. exports.ParametricBufferGeometry = ParametricGeometry;
  30739. exports.ParametricGeometry = ParametricGeometry;
  30740. exports.Particle = Particle;
  30741. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  30742. exports.ParticleSystem = ParticleSystem;
  30743. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  30744. exports.Path = Path;
  30745. exports.PerspectiveCamera = PerspectiveCamera;
  30746. exports.Plane = Plane;
  30747. exports.PlaneBufferGeometry = PlaneGeometry;
  30748. exports.PlaneGeometry = PlaneGeometry;
  30749. exports.PlaneHelper = PlaneHelper;
  30750. exports.PointCloud = PointCloud;
  30751. exports.PointCloudMaterial = PointCloudMaterial;
  30752. exports.PointLight = PointLight;
  30753. exports.PointLightHelper = PointLightHelper;
  30754. exports.Points = Points;
  30755. exports.PointsMaterial = PointsMaterial;
  30756. exports.PolarGridHelper = PolarGridHelper;
  30757. exports.PolyhedronBufferGeometry = PolyhedronGeometry;
  30758. exports.PolyhedronGeometry = PolyhedronGeometry;
  30759. exports.PositionalAudio = PositionalAudio;
  30760. exports.PropertyBinding = PropertyBinding;
  30761. exports.PropertyMixer = PropertyMixer;
  30762. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  30763. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  30764. exports.Quaternion = Quaternion;
  30765. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  30766. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  30767. exports.REVISION = REVISION;
  30768. exports.RGBADepthPacking = RGBADepthPacking;
  30769. exports.RGBAFormat = RGBAFormat;
  30770. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  30771. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  30772. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  30773. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  30774. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  30775. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  30776. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  30777. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  30778. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  30779. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  30780. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  30781. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  30782. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  30783. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  30784. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  30785. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  30786. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  30787. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  30788. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  30789. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  30790. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  30791. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  30792. exports.RGBDEncoding = RGBDEncoding;
  30793. exports.RGBEEncoding = RGBEEncoding;
  30794. exports.RGBEFormat = RGBEFormat;
  30795. exports.RGBFormat = RGBFormat;
  30796. exports.RGBIntegerFormat = RGBIntegerFormat;
  30797. exports.RGBM16Encoding = RGBM16Encoding;
  30798. exports.RGBM7Encoding = RGBM7Encoding;
  30799. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  30800. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  30801. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  30802. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  30803. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  30804. exports.RGFormat = RGFormat;
  30805. exports.RGIntegerFormat = RGIntegerFormat;
  30806. exports.RawShaderMaterial = RawShaderMaterial;
  30807. exports.Ray = Ray;
  30808. exports.Raycaster = Raycaster;
  30809. exports.RectAreaLight = RectAreaLight;
  30810. exports.RedFormat = RedFormat;
  30811. exports.RedIntegerFormat = RedIntegerFormat;
  30812. exports.ReinhardToneMapping = ReinhardToneMapping;
  30813. exports.RepeatWrapping = RepeatWrapping;
  30814. exports.ReplaceStencilOp = ReplaceStencilOp;
  30815. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  30816. exports.RingBufferGeometry = RingGeometry;
  30817. exports.RingGeometry = RingGeometry;
  30818. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  30819. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  30820. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  30821. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  30822. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  30823. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  30824. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  30825. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  30826. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  30827. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  30828. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  30829. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  30830. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  30831. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  30832. exports.Scene = Scene;
  30833. exports.SceneUtils = SceneUtils;
  30834. exports.ShaderChunk = ShaderChunk;
  30835. exports.ShaderLib = ShaderLib;
  30836. exports.ShaderMaterial = ShaderMaterial;
  30837. exports.ShadowMaterial = ShadowMaterial;
  30838. exports.Shape = Shape;
  30839. exports.ShapeBufferGeometry = ShapeGeometry;
  30840. exports.ShapeGeometry = ShapeGeometry;
  30841. exports.ShapePath = ShapePath;
  30842. exports.ShapeUtils = ShapeUtils;
  30843. exports.ShortType = ShortType;
  30844. exports.Skeleton = Skeleton;
  30845. exports.SkeletonHelper = SkeletonHelper;
  30846. exports.SkinnedMesh = SkinnedMesh;
  30847. exports.SmoothShading = SmoothShading;
  30848. exports.Sphere = Sphere;
  30849. exports.SphereBufferGeometry = SphereGeometry;
  30850. exports.SphereGeometry = SphereGeometry;
  30851. exports.Spherical = Spherical;
  30852. exports.SphericalHarmonics3 = SphericalHarmonics3;
  30853. exports.Spline = Spline;
  30854. exports.SplineCurve = SplineCurve;
  30855. exports.SplineCurve3 = SplineCurve3;
  30856. exports.SpotLight = SpotLight;
  30857. exports.SpotLightHelper = SpotLightHelper;
  30858. exports.Sprite = Sprite;
  30859. exports.SpriteMaterial = SpriteMaterial;
  30860. exports.SrcAlphaFactor = SrcAlphaFactor;
  30861. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  30862. exports.SrcColorFactor = SrcColorFactor;
  30863. exports.StaticCopyUsage = StaticCopyUsage;
  30864. exports.StaticDrawUsage = StaticDrawUsage;
  30865. exports.StaticReadUsage = StaticReadUsage;
  30866. exports.StereoCamera = StereoCamera;
  30867. exports.StreamCopyUsage = StreamCopyUsage;
  30868. exports.StreamDrawUsage = StreamDrawUsage;
  30869. exports.StreamReadUsage = StreamReadUsage;
  30870. exports.StringKeyframeTrack = StringKeyframeTrack;
  30871. exports.SubtractEquation = SubtractEquation;
  30872. exports.SubtractiveBlending = SubtractiveBlending;
  30873. exports.TOUCH = TOUCH;
  30874. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  30875. exports.TetrahedronBufferGeometry = TetrahedronGeometry;
  30876. exports.TetrahedronGeometry = TetrahedronGeometry;
  30877. exports.TextBufferGeometry = TextGeometry;
  30878. exports.TextGeometry = TextGeometry;
  30879. exports.Texture = Texture;
  30880. exports.TextureLoader = TextureLoader;
  30881. exports.TorusBufferGeometry = TorusGeometry;
  30882. exports.TorusGeometry = TorusGeometry;
  30883. exports.TorusKnotBufferGeometry = TorusKnotGeometry;
  30884. exports.TorusKnotGeometry = TorusKnotGeometry;
  30885. exports.Triangle = Triangle;
  30886. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  30887. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  30888. exports.TrianglesDrawMode = TrianglesDrawMode;
  30889. exports.TubeBufferGeometry = TubeGeometry;
  30890. exports.TubeGeometry = TubeGeometry;
  30891. exports.UVMapping = UVMapping;
  30892. exports.Uint16Attribute = Uint16Attribute;
  30893. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  30894. exports.Uint32Attribute = Uint32Attribute;
  30895. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  30896. exports.Uint8Attribute = Uint8Attribute;
  30897. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  30898. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  30899. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  30900. exports.Uniform = Uniform;
  30901. exports.UniformsLib = UniformsLib;
  30902. exports.UniformsUtils = UniformsUtils;
  30903. exports.UnsignedByteType = UnsignedByteType;
  30904. exports.UnsignedInt248Type = UnsignedInt248Type;
  30905. exports.UnsignedIntType = UnsignedIntType;
  30906. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  30907. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  30908. exports.UnsignedShort565Type = UnsignedShort565Type;
  30909. exports.UnsignedShortType = UnsignedShortType;
  30910. exports.VSMShadowMap = VSMShadowMap;
  30911. exports.Vector2 = Vector2;
  30912. exports.Vector3 = Vector3;
  30913. exports.Vector4 = Vector4;
  30914. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  30915. exports.Vertex = Vertex;
  30916. exports.VertexColors = VertexColors;
  30917. exports.VideoTexture = VideoTexture;
  30918. exports.WebGL1Renderer = WebGL1Renderer;
  30919. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  30920. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  30921. exports.WebGLRenderTarget = WebGLRenderTarget;
  30922. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  30923. exports.WebGLRenderer = WebGLRenderer;
  30924. exports.WebGLUtils = WebGLUtils;
  30925. exports.WireframeGeometry = WireframeGeometry;
  30926. exports.WireframeHelper = WireframeHelper;
  30927. exports.WrapAroundEnding = WrapAroundEnding;
  30928. exports.XHRLoader = XHRLoader;
  30929. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  30930. exports.ZeroFactor = ZeroFactor;
  30931. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  30932. exports.ZeroStencilOp = ZeroStencilOp;
  30933. exports.sRGBEncoding = sRGBEncoding;
  30934. Object.defineProperty(exports, '__esModule', { value: true });
  30935. })));
粤ICP备19079148号