three.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254
  1. // threejs.org/license
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.THREE = {}));
  6. }(this, (function (exports) { 'use strict';
  7. // Polyfills
  8. if (Number.EPSILON === undefined) {
  9. Number.EPSILON = Math.pow(2, -52);
  10. }
  11. if (Number.isInteger === undefined) {
  12. // Missing in IE
  13. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  14. Number.isInteger = function (value) {
  15. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  16. };
  17. } //
  18. if (Math.sign === undefined) {
  19. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  20. Math.sign = function (x) {
  21. return x < 0 ? -1 : x > 0 ? 1 : +x;
  22. };
  23. }
  24. if ('name' in Function.prototype === false) {
  25. // Missing in IE
  26. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  27. Object.defineProperty(Function.prototype, 'name', {
  28. get: function get() {
  29. return this.toString().match(/^\s*function\s*([^\(\s]*)/)[1];
  30. }
  31. });
  32. }
  33. if (Object.assign === undefined) {
  34. // Missing in IE
  35. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  36. Object.assign = function (target) {
  37. if (target === undefined || target === null) {
  38. throw new TypeError('Cannot convert undefined or null to object');
  39. }
  40. var output = Object(target);
  41. for (var index = 1; index < arguments.length; index++) {
  42. var source = arguments[index];
  43. if (source !== undefined && source !== null) {
  44. for (var nextKey in source) {
  45. if (Object.prototype.hasOwnProperty.call(source, nextKey)) {
  46. output[nextKey] = source[nextKey];
  47. }
  48. }
  49. }
  50. }
  51. return output;
  52. };
  53. }
  54. var REVISION = '122dev';
  55. var MOUSE = {
  56. LEFT: 0,
  57. MIDDLE: 1,
  58. RIGHT: 2,
  59. ROTATE: 0,
  60. DOLLY: 1,
  61. PAN: 2
  62. };
  63. var TOUCH = {
  64. ROTATE: 0,
  65. PAN: 1,
  66. DOLLY_PAN: 2,
  67. DOLLY_ROTATE: 3
  68. };
  69. var CullFaceNone = 0;
  70. var CullFaceBack = 1;
  71. var CullFaceFront = 2;
  72. var CullFaceFrontBack = 3;
  73. var BasicShadowMap = 0;
  74. var PCFShadowMap = 1;
  75. var PCFSoftShadowMap = 2;
  76. var VSMShadowMap = 3;
  77. var FrontSide = 0;
  78. var BackSide = 1;
  79. var DoubleSide = 2;
  80. var FlatShading = 1;
  81. var SmoothShading = 2;
  82. var NoBlending = 0;
  83. var NormalBlending = 1;
  84. var AdditiveBlending = 2;
  85. var SubtractiveBlending = 3;
  86. var MultiplyBlending = 4;
  87. var CustomBlending = 5;
  88. var AddEquation = 100;
  89. var SubtractEquation = 101;
  90. var ReverseSubtractEquation = 102;
  91. var MinEquation = 103;
  92. var MaxEquation = 104;
  93. var ZeroFactor = 200;
  94. var OneFactor = 201;
  95. var SrcColorFactor = 202;
  96. var OneMinusSrcColorFactor = 203;
  97. var SrcAlphaFactor = 204;
  98. var OneMinusSrcAlphaFactor = 205;
  99. var DstAlphaFactor = 206;
  100. var OneMinusDstAlphaFactor = 207;
  101. var DstColorFactor = 208;
  102. var OneMinusDstColorFactor = 209;
  103. var SrcAlphaSaturateFactor = 210;
  104. var NeverDepth = 0;
  105. var AlwaysDepth = 1;
  106. var LessDepth = 2;
  107. var LessEqualDepth = 3;
  108. var EqualDepth = 4;
  109. var GreaterEqualDepth = 5;
  110. var GreaterDepth = 6;
  111. var NotEqualDepth = 7;
  112. var MultiplyOperation = 0;
  113. var MixOperation = 1;
  114. var AddOperation = 2;
  115. var NoToneMapping = 0;
  116. var LinearToneMapping = 1;
  117. var ReinhardToneMapping = 2;
  118. var CineonToneMapping = 3;
  119. var ACESFilmicToneMapping = 4;
  120. var CustomToneMapping = 5;
  121. var UVMapping = 300;
  122. var CubeReflectionMapping = 301;
  123. var CubeRefractionMapping = 302;
  124. var EquirectangularReflectionMapping = 303;
  125. var EquirectangularRefractionMapping = 304;
  126. var CubeUVReflectionMapping = 306;
  127. var CubeUVRefractionMapping = 307;
  128. var RepeatWrapping = 1000;
  129. var ClampToEdgeWrapping = 1001;
  130. var MirroredRepeatWrapping = 1002;
  131. var NearestFilter = 1003;
  132. var NearestMipmapNearestFilter = 1004;
  133. var NearestMipMapNearestFilter = 1004;
  134. var NearestMipmapLinearFilter = 1005;
  135. var NearestMipMapLinearFilter = 1005;
  136. var LinearFilter = 1006;
  137. var LinearMipmapNearestFilter = 1007;
  138. var LinearMipMapNearestFilter = 1007;
  139. var LinearMipmapLinearFilter = 1008;
  140. var LinearMipMapLinearFilter = 1008;
  141. var UnsignedByteType = 1009;
  142. var ByteType = 1010;
  143. var ShortType = 1011;
  144. var UnsignedShortType = 1012;
  145. var IntType = 1013;
  146. var UnsignedIntType = 1014;
  147. var FloatType = 1015;
  148. var HalfFloatType = 1016;
  149. var UnsignedShort4444Type = 1017;
  150. var UnsignedShort5551Type = 1018;
  151. var UnsignedShort565Type = 1019;
  152. var UnsignedInt248Type = 1020;
  153. var AlphaFormat = 1021;
  154. var RGBFormat = 1022;
  155. var RGBAFormat = 1023;
  156. var LuminanceFormat = 1024;
  157. var LuminanceAlphaFormat = 1025;
  158. var RGBEFormat = RGBAFormat;
  159. var DepthFormat = 1026;
  160. var DepthStencilFormat = 1027;
  161. var RedFormat = 1028;
  162. var RedIntegerFormat = 1029;
  163. var RGFormat = 1030;
  164. var RGIntegerFormat = 1031;
  165. var RGBIntegerFormat = 1032;
  166. var RGBAIntegerFormat = 1033;
  167. var RGB_S3TC_DXT1_Format = 33776;
  168. var RGBA_S3TC_DXT1_Format = 33777;
  169. var RGBA_S3TC_DXT3_Format = 33778;
  170. var RGBA_S3TC_DXT5_Format = 33779;
  171. var RGB_PVRTC_4BPPV1_Format = 35840;
  172. var RGB_PVRTC_2BPPV1_Format = 35841;
  173. var RGBA_PVRTC_4BPPV1_Format = 35842;
  174. var RGBA_PVRTC_2BPPV1_Format = 35843;
  175. var RGB_ETC1_Format = 36196;
  176. var RGB_ETC2_Format = 37492;
  177. var RGBA_ETC2_EAC_Format = 37496;
  178. var RGBA_ASTC_4x4_Format = 37808;
  179. var RGBA_ASTC_5x4_Format = 37809;
  180. var RGBA_ASTC_5x5_Format = 37810;
  181. var RGBA_ASTC_6x5_Format = 37811;
  182. var RGBA_ASTC_6x6_Format = 37812;
  183. var RGBA_ASTC_8x5_Format = 37813;
  184. var RGBA_ASTC_8x6_Format = 37814;
  185. var RGBA_ASTC_8x8_Format = 37815;
  186. var RGBA_ASTC_10x5_Format = 37816;
  187. var RGBA_ASTC_10x6_Format = 37817;
  188. var RGBA_ASTC_10x8_Format = 37818;
  189. var RGBA_ASTC_10x10_Format = 37819;
  190. var RGBA_ASTC_12x10_Format = 37820;
  191. var RGBA_ASTC_12x12_Format = 37821;
  192. var RGBA_BPTC_Format = 36492;
  193. var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  194. var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  195. var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  196. var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  197. var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  198. var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  199. var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  200. var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  201. var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  202. var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  203. var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  204. var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  205. var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  206. var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  207. var LoopOnce = 2200;
  208. var LoopRepeat = 2201;
  209. var LoopPingPong = 2202;
  210. var InterpolateDiscrete = 2300;
  211. var InterpolateLinear = 2301;
  212. var InterpolateSmooth = 2302;
  213. var ZeroCurvatureEnding = 2400;
  214. var ZeroSlopeEnding = 2401;
  215. var WrapAroundEnding = 2402;
  216. var NormalAnimationBlendMode = 2500;
  217. var AdditiveAnimationBlendMode = 2501;
  218. var TrianglesDrawMode = 0;
  219. var TriangleStripDrawMode = 1;
  220. var TriangleFanDrawMode = 2;
  221. var LinearEncoding = 3000;
  222. var sRGBEncoding = 3001;
  223. var GammaEncoding = 3007;
  224. var RGBEEncoding = 3002;
  225. var LogLuvEncoding = 3003;
  226. var RGBM7Encoding = 3004;
  227. var RGBM16Encoding = 3005;
  228. var RGBDEncoding = 3006;
  229. var BasicDepthPacking = 3200;
  230. var RGBADepthPacking = 3201;
  231. var TangentSpaceNormalMap = 0;
  232. var ObjectSpaceNormalMap = 1;
  233. var ZeroStencilOp = 0;
  234. var KeepStencilOp = 7680;
  235. var ReplaceStencilOp = 7681;
  236. var IncrementStencilOp = 7682;
  237. var DecrementStencilOp = 7683;
  238. var IncrementWrapStencilOp = 34055;
  239. var DecrementWrapStencilOp = 34056;
  240. var InvertStencilOp = 5386;
  241. var NeverStencilFunc = 512;
  242. var LessStencilFunc = 513;
  243. var EqualStencilFunc = 514;
  244. var LessEqualStencilFunc = 515;
  245. var GreaterStencilFunc = 516;
  246. var NotEqualStencilFunc = 517;
  247. var GreaterEqualStencilFunc = 518;
  248. var AlwaysStencilFunc = 519;
  249. var StaticDrawUsage = 35044;
  250. var DynamicDrawUsage = 35048;
  251. var StreamDrawUsage = 35040;
  252. var StaticReadUsage = 35045;
  253. var DynamicReadUsage = 35049;
  254. var StreamReadUsage = 35041;
  255. var StaticCopyUsage = 35046;
  256. var DynamicCopyUsage = 35050;
  257. var StreamCopyUsage = 35042;
  258. var GLSL1 = "100";
  259. var GLSL3 = "300 es";
  260. /**
  261. * https://github.com/mrdoob/eventdispatcher.js/
  262. */
  263. function EventDispatcher() {}
  264. Object.assign(EventDispatcher.prototype, {
  265. addEventListener: function addEventListener(type, listener) {
  266. if (this._listeners === undefined) this._listeners = {};
  267. var listeners = this._listeners;
  268. if (listeners[type] === undefined) {
  269. listeners[type] = [];
  270. }
  271. if (listeners[type].indexOf(listener) === -1) {
  272. listeners[type].push(listener);
  273. }
  274. },
  275. hasEventListener: function hasEventListener(type, listener) {
  276. if (this._listeners === undefined) return false;
  277. var listeners = this._listeners;
  278. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
  279. },
  280. removeEventListener: function removeEventListener(type, listener) {
  281. if (this._listeners === undefined) return;
  282. var listeners = this._listeners;
  283. var listenerArray = listeners[type];
  284. if (listenerArray !== undefined) {
  285. var index = listenerArray.indexOf(listener);
  286. if (index !== -1) {
  287. listenerArray.splice(index, 1);
  288. }
  289. }
  290. },
  291. dispatchEvent: function dispatchEvent(event) {
  292. if (this._listeners === undefined) return;
  293. var listeners = this._listeners;
  294. var listenerArray = listeners[event.type];
  295. if (listenerArray !== undefined) {
  296. event.target = this; // Make a copy, in case listeners are removed while iterating.
  297. var array = listenerArray.slice(0);
  298. for (var i = 0, l = array.length; i < l; i++) {
  299. array[i].call(this, event);
  300. }
  301. }
  302. }
  303. });
  304. var _lut = [];
  305. for (var i = 0; i < 256; i++) {
  306. _lut[i] = (i < 16 ? '0' : '') + i.toString(16);
  307. }
  308. var _seed = 1234567;
  309. var MathUtils = {
  310. DEG2RAD: Math.PI / 180,
  311. RAD2DEG: 180 / Math.PI,
  312. generateUUID: function generateUUID() {
  313. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  314. var d0 = Math.random() * 0xffffffff | 0;
  315. var d1 = Math.random() * 0xffffffff | 0;
  316. var d2 = Math.random() * 0xffffffff | 0;
  317. var d3 = Math.random() * 0xffffffff | 0;
  318. var uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' + _lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' + _lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] + _lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff]; // .toUpperCase() here flattens concatenated strings to save heap memory space.
  319. return uuid.toUpperCase();
  320. },
  321. clamp: function clamp(value, min, max) {
  322. return Math.max(min, Math.min(max, value));
  323. },
  324. // compute euclidian modulo of m % n
  325. // https://en.wikipedia.org/wiki/Modulo_operation
  326. euclideanModulo: function euclideanModulo(n, m) {
  327. return (n % m + m) % m;
  328. },
  329. // Linear mapping from range <a1, a2> to range <b1, b2>
  330. mapLinear: function mapLinear(x, a1, a2, b1, b2) {
  331. return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
  332. },
  333. // https://en.wikipedia.org/wiki/Linear_interpolation
  334. lerp: function lerp(x, y, t) {
  335. return (1 - t) * x + t * y;
  336. },
  337. // http://en.wikipedia.org/wiki/Smoothstep
  338. smoothstep: function smoothstep(x, min, max) {
  339. if (x <= min) return 0;
  340. if (x >= max) return 1;
  341. x = (x - min) / (max - min);
  342. return x * x * (3 - 2 * x);
  343. },
  344. smootherstep: function smootherstep(x, min, max) {
  345. if (x <= min) return 0;
  346. if (x >= max) return 1;
  347. x = (x - min) / (max - min);
  348. return x * x * x * (x * (x * 6 - 15) + 10);
  349. },
  350. // Random integer from <low, high> interval
  351. randInt: function randInt(low, high) {
  352. return low + Math.floor(Math.random() * (high - low + 1));
  353. },
  354. // Random float from <low, high> interval
  355. randFloat: function randFloat(low, high) {
  356. return low + Math.random() * (high - low);
  357. },
  358. // Random float from <-range/2, range/2> interval
  359. randFloatSpread: function randFloatSpread(range) {
  360. return range * (0.5 - Math.random());
  361. },
  362. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  363. seededRandom: function seededRandom(s) {
  364. if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
  365. _seed = _seed * 16807 % 2147483647;
  366. return (_seed - 1) / 2147483646;
  367. },
  368. degToRad: function degToRad(degrees) {
  369. return degrees * MathUtils.DEG2RAD;
  370. },
  371. radToDeg: function radToDeg(radians) {
  372. return radians * MathUtils.RAD2DEG;
  373. },
  374. isPowerOfTwo: function isPowerOfTwo(value) {
  375. return (value & value - 1) === 0 && value !== 0;
  376. },
  377. ceilPowerOfTwo: function ceilPowerOfTwo(value) {
  378. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  379. },
  380. floorPowerOfTwo: function floorPowerOfTwo(value) {
  381. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  382. },
  383. setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
  384. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  385. // rotations are applied to the axes in the order specified by 'order'
  386. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  387. // angles are in radians
  388. var cos = Math.cos;
  389. var sin = Math.sin;
  390. var c2 = cos(b / 2);
  391. var s2 = sin(b / 2);
  392. var c13 = cos((a + c) / 2);
  393. var s13 = sin((a + c) / 2);
  394. var c1_3 = cos((a - c) / 2);
  395. var s1_3 = sin((a - c) / 2);
  396. var c3_1 = cos((c - a) / 2);
  397. var s3_1 = sin((c - a) / 2);
  398. switch (order) {
  399. case 'XYX':
  400. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  401. break;
  402. case 'YZY':
  403. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  404. break;
  405. case 'ZXZ':
  406. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  407. break;
  408. case 'XZX':
  409. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  410. break;
  411. case 'YXY':
  412. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  413. break;
  414. case 'ZYZ':
  415. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  416. break;
  417. default:
  418. console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
  419. }
  420. }
  421. };
  422. function _defineProperties(target, props) {
  423. for (var i = 0; i < props.length; i++) {
  424. var descriptor = props[i];
  425. descriptor.enumerable = descriptor.enumerable || false;
  426. descriptor.configurable = true;
  427. if ("value" in descriptor) descriptor.writable = true;
  428. Object.defineProperty(target, descriptor.key, descriptor);
  429. }
  430. }
  431. function _createClass(Constructor, protoProps, staticProps) {
  432. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  433. if (staticProps) _defineProperties(Constructor, staticProps);
  434. return Constructor;
  435. }
  436. function _inheritsLoose(subClass, superClass) {
  437. subClass.prototype = Object.create(superClass.prototype);
  438. subClass.prototype.constructor = subClass;
  439. subClass.__proto__ = superClass;
  440. }
  441. function _assertThisInitialized(self) {
  442. if (self === void 0) {
  443. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  444. }
  445. return self;
  446. }
  447. var Vector2 = /*#__PURE__*/function () {
  448. function Vector2(x, y) {
  449. if (x === void 0) {
  450. x = 0;
  451. }
  452. if (y === void 0) {
  453. y = 0;
  454. }
  455. Object.defineProperty(this, 'isVector2', {
  456. value: true
  457. });
  458. this.x = x;
  459. this.y = y;
  460. }
  461. var _proto = Vector2.prototype;
  462. _proto.set = function set(x, y) {
  463. this.x = x;
  464. this.y = y;
  465. return this;
  466. };
  467. _proto.setScalar = function setScalar(scalar) {
  468. this.x = scalar;
  469. this.y = scalar;
  470. return this;
  471. };
  472. _proto.setX = function setX(x) {
  473. this.x = x;
  474. return this;
  475. };
  476. _proto.setY = function setY(y) {
  477. this.y = y;
  478. return this;
  479. };
  480. _proto.setComponent = function setComponent(index, value) {
  481. switch (index) {
  482. case 0:
  483. this.x = value;
  484. break;
  485. case 1:
  486. this.y = value;
  487. break;
  488. default:
  489. throw new Error('index is out of range: ' + index);
  490. }
  491. return this;
  492. };
  493. _proto.getComponent = function getComponent(index) {
  494. switch (index) {
  495. case 0:
  496. return this.x;
  497. case 1:
  498. return this.y;
  499. default:
  500. throw new Error('index is out of range: ' + index);
  501. }
  502. };
  503. _proto.clone = function clone() {
  504. return new this.constructor(this.x, this.y);
  505. };
  506. _proto.copy = function copy(v) {
  507. this.x = v.x;
  508. this.y = v.y;
  509. return this;
  510. };
  511. _proto.add = function add(v, w) {
  512. if (w !== undefined) {
  513. console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  514. return this.addVectors(v, w);
  515. }
  516. this.x += v.x;
  517. this.y += v.y;
  518. return this;
  519. };
  520. _proto.addScalar = function addScalar(s) {
  521. this.x += s;
  522. this.y += s;
  523. return this;
  524. };
  525. _proto.addVectors = function addVectors(a, b) {
  526. this.x = a.x + b.x;
  527. this.y = a.y + b.y;
  528. return this;
  529. };
  530. _proto.addScaledVector = function addScaledVector(v, s) {
  531. this.x += v.x * s;
  532. this.y += v.y * s;
  533. return this;
  534. };
  535. _proto.sub = function sub(v, w) {
  536. if (w !== undefined) {
  537. console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  538. return this.subVectors(v, w);
  539. }
  540. this.x -= v.x;
  541. this.y -= v.y;
  542. return this;
  543. };
  544. _proto.subScalar = function subScalar(s) {
  545. this.x -= s;
  546. this.y -= s;
  547. return this;
  548. };
  549. _proto.subVectors = function subVectors(a, b) {
  550. this.x = a.x - b.x;
  551. this.y = a.y - b.y;
  552. return this;
  553. };
  554. _proto.multiply = function multiply(v) {
  555. this.x *= v.x;
  556. this.y *= v.y;
  557. return this;
  558. };
  559. _proto.multiplyScalar = function multiplyScalar(scalar) {
  560. this.x *= scalar;
  561. this.y *= scalar;
  562. return this;
  563. };
  564. _proto.divide = function divide(v) {
  565. this.x /= v.x;
  566. this.y /= v.y;
  567. return this;
  568. };
  569. _proto.divideScalar = function divideScalar(scalar) {
  570. return this.multiplyScalar(1 / scalar);
  571. };
  572. _proto.applyMatrix3 = function applyMatrix3(m) {
  573. var x = this.x,
  574. y = this.y;
  575. var e = m.elements;
  576. this.x = e[0] * x + e[3] * y + e[6];
  577. this.y = e[1] * x + e[4] * y + e[7];
  578. return this;
  579. };
  580. _proto.min = function min(v) {
  581. this.x = Math.min(this.x, v.x);
  582. this.y = Math.min(this.y, v.y);
  583. return this;
  584. };
  585. _proto.max = function max(v) {
  586. this.x = Math.max(this.x, v.x);
  587. this.y = Math.max(this.y, v.y);
  588. return this;
  589. };
  590. _proto.clamp = function clamp(min, max) {
  591. // assumes min < max, componentwise
  592. this.x = Math.max(min.x, Math.min(max.x, this.x));
  593. this.y = Math.max(min.y, Math.min(max.y, this.y));
  594. return this;
  595. };
  596. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  597. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  598. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  599. return this;
  600. };
  601. _proto.clampLength = function clampLength(min, max) {
  602. var length = this.length();
  603. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  604. };
  605. _proto.floor = function floor() {
  606. this.x = Math.floor(this.x);
  607. this.y = Math.floor(this.y);
  608. return this;
  609. };
  610. _proto.ceil = function ceil() {
  611. this.x = Math.ceil(this.x);
  612. this.y = Math.ceil(this.y);
  613. return this;
  614. };
  615. _proto.round = function round() {
  616. this.x = Math.round(this.x);
  617. this.y = Math.round(this.y);
  618. return this;
  619. };
  620. _proto.roundToZero = function roundToZero() {
  621. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  622. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  623. return this;
  624. };
  625. _proto.negate = function negate() {
  626. this.x = -this.x;
  627. this.y = -this.y;
  628. return this;
  629. };
  630. _proto.dot = function dot(v) {
  631. return this.x * v.x + this.y * v.y;
  632. };
  633. _proto.cross = function cross(v) {
  634. return this.x * v.y - this.y * v.x;
  635. };
  636. _proto.lengthSq = function lengthSq() {
  637. return this.x * this.x + this.y * this.y;
  638. };
  639. _proto.length = function length() {
  640. return Math.sqrt(this.x * this.x + this.y * this.y);
  641. };
  642. _proto.manhattanLength = function manhattanLength() {
  643. return Math.abs(this.x) + Math.abs(this.y);
  644. };
  645. _proto.normalize = function normalize() {
  646. return this.divideScalar(this.length() || 1);
  647. };
  648. _proto.angle = function angle() {
  649. // computes the angle in radians with respect to the positive x-axis
  650. var angle = Math.atan2(-this.y, -this.x) + Math.PI;
  651. return angle;
  652. };
  653. _proto.distanceTo = function distanceTo(v) {
  654. return Math.sqrt(this.distanceToSquared(v));
  655. };
  656. _proto.distanceToSquared = function distanceToSquared(v) {
  657. var dx = this.x - v.x,
  658. dy = this.y - v.y;
  659. return dx * dx + dy * dy;
  660. };
  661. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  662. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
  663. };
  664. _proto.setLength = function setLength(length) {
  665. return this.normalize().multiplyScalar(length);
  666. };
  667. _proto.lerp = function lerp(v, alpha) {
  668. this.x += (v.x - this.x) * alpha;
  669. this.y += (v.y - this.y) * alpha;
  670. return this;
  671. };
  672. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  673. this.x = v1.x + (v2.x - v1.x) * alpha;
  674. this.y = v1.y + (v2.y - v1.y) * alpha;
  675. return this;
  676. };
  677. _proto.equals = function equals(v) {
  678. return v.x === this.x && v.y === this.y;
  679. };
  680. _proto.fromArray = function fromArray(array, offset) {
  681. if (offset === 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.getInverse = function getInverse(matrix, throwOnDegenerate) {
  862. if (throwOnDegenerate !== undefined) {
  863. console.warn("THREE.Matrix3: .getInverse() can no longer be configured to throw on degenerate.");
  864. }
  865. var me = matrix.elements,
  866. te = this.elements,
  867. n11 = me[0],
  868. n21 = me[1],
  869. n31 = me[2],
  870. n12 = me[3],
  871. n22 = me[4],
  872. n32 = me[5],
  873. n13 = me[6],
  874. n23 = me[7],
  875. n33 = me[8],
  876. t11 = n33 * n22 - n32 * n23,
  877. t12 = n32 * n13 - n33 * n12,
  878. t13 = n23 * n12 - n22 * n13,
  879. det = n11 * t11 + n21 * t12 + n31 * t13;
  880. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  881. var detInv = 1 / det;
  882. te[0] = t11 * detInv;
  883. te[1] = (n31 * n23 - n33 * n21) * detInv;
  884. te[2] = (n32 * n21 - n31 * n22) * detInv;
  885. te[3] = t12 * detInv;
  886. te[4] = (n33 * n11 - n31 * n13) * detInv;
  887. te[5] = (n31 * n12 - n32 * n11) * detInv;
  888. te[6] = t13 * detInv;
  889. te[7] = (n21 * n13 - n23 * n11) * detInv;
  890. te[8] = (n22 * n11 - n21 * n12) * detInv;
  891. return this;
  892. };
  893. _proto.transpose = function transpose() {
  894. var tmp;
  895. var m = this.elements;
  896. tmp = m[1];
  897. m[1] = m[3];
  898. m[3] = tmp;
  899. tmp = m[2];
  900. m[2] = m[6];
  901. m[6] = tmp;
  902. tmp = m[5];
  903. m[5] = m[7];
  904. m[7] = tmp;
  905. return this;
  906. };
  907. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  908. return this.setFromMatrix4(matrix4).getInverse(this).transpose();
  909. };
  910. _proto.transposeIntoArray = function transposeIntoArray(r) {
  911. var m = this.elements;
  912. r[0] = m[0];
  913. r[1] = m[3];
  914. r[2] = m[6];
  915. r[3] = m[1];
  916. r[4] = m[4];
  917. r[5] = m[7];
  918. r[6] = m[2];
  919. r[7] = m[5];
  920. r[8] = m[8];
  921. return this;
  922. };
  923. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  924. var c = Math.cos(rotation);
  925. var s = Math.sin(rotation);
  926. 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);
  927. };
  928. _proto.scale = function scale(sx, sy) {
  929. var te = this.elements;
  930. te[0] *= sx;
  931. te[3] *= sx;
  932. te[6] *= sx;
  933. te[1] *= sy;
  934. te[4] *= sy;
  935. te[7] *= sy;
  936. return this;
  937. };
  938. _proto.rotate = function rotate(theta) {
  939. var c = Math.cos(theta);
  940. var s = Math.sin(theta);
  941. var te = this.elements;
  942. var a11 = te[0],
  943. a12 = te[3],
  944. a13 = te[6];
  945. var a21 = te[1],
  946. a22 = te[4],
  947. a23 = te[7];
  948. te[0] = c * a11 + s * a21;
  949. te[3] = c * a12 + s * a22;
  950. te[6] = c * a13 + s * a23;
  951. te[1] = -s * a11 + c * a21;
  952. te[4] = -s * a12 + c * a22;
  953. te[7] = -s * a13 + c * a23;
  954. return this;
  955. };
  956. _proto.translate = function translate(tx, ty) {
  957. var te = this.elements;
  958. te[0] += tx * te[2];
  959. te[3] += tx * te[5];
  960. te[6] += tx * te[8];
  961. te[1] += ty * te[2];
  962. te[4] += ty * te[5];
  963. te[7] += ty * te[8];
  964. return this;
  965. };
  966. _proto.equals = function equals(matrix) {
  967. var te = this.elements;
  968. var me = matrix.elements;
  969. for (var i = 0; i < 9; i++) {
  970. if (te[i] !== me[i]) return false;
  971. }
  972. return true;
  973. };
  974. _proto.fromArray = function fromArray(array, offset) {
  975. if (offset === void 0) {
  976. offset = 0;
  977. }
  978. for (var i = 0; i < 9; i++) {
  979. this.elements[i] = array[i + offset];
  980. }
  981. return this;
  982. };
  983. _proto.toArray = function toArray(array, offset) {
  984. if (array === void 0) {
  985. array = [];
  986. }
  987. if (offset === void 0) {
  988. offset = 0;
  989. }
  990. var te = this.elements;
  991. array[offset] = te[0];
  992. array[offset + 1] = te[1];
  993. array[offset + 2] = te[2];
  994. array[offset + 3] = te[3];
  995. array[offset + 4] = te[4];
  996. array[offset + 5] = te[5];
  997. array[offset + 6] = te[6];
  998. array[offset + 7] = te[7];
  999. array[offset + 8] = te[8];
  1000. return array;
  1001. };
  1002. return Matrix3;
  1003. }();
  1004. var _canvas;
  1005. var ImageUtils = {
  1006. getDataURL: function getDataURL(image) {
  1007. if (/^data:/i.test(image.src)) {
  1008. return image.src;
  1009. }
  1010. if (typeof HTMLCanvasElement == 'undefined') {
  1011. return image.src;
  1012. }
  1013. var canvas;
  1014. if (image instanceof HTMLCanvasElement) {
  1015. canvas = image;
  1016. } else {
  1017. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1018. _canvas.width = image.width;
  1019. _canvas.height = image.height;
  1020. var context = _canvas.getContext('2d');
  1021. if (image instanceof ImageData) {
  1022. context.putImageData(image, 0, 0);
  1023. } else {
  1024. context.drawImage(image, 0, 0, image.width, image.height);
  1025. }
  1026. canvas = _canvas;
  1027. }
  1028. if (canvas.width > 2048 || canvas.height > 2048) {
  1029. return canvas.toDataURL('image/jpeg', 0.6);
  1030. } else {
  1031. return canvas.toDataURL('image/png');
  1032. }
  1033. }
  1034. };
  1035. var textureId = 0;
  1036. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1037. Object.defineProperty(this, 'id', {
  1038. value: textureId++
  1039. });
  1040. this.uuid = MathUtils.generateUUID();
  1041. this.name = '';
  1042. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  1043. this.mipmaps = [];
  1044. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  1045. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  1046. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  1047. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  1048. this.minFilter = minFilter !== undefined ? minFilter : LinearMipmapLinearFilter;
  1049. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  1050. this.format = format !== undefined ? format : RGBAFormat;
  1051. this.internalFormat = null;
  1052. this.type = type !== undefined ? type : UnsignedByteType;
  1053. this.offset = new Vector2(0, 0);
  1054. this.repeat = new Vector2(1, 1);
  1055. this.center = new Vector2(0, 0);
  1056. this.rotation = 0;
  1057. this.matrixAutoUpdate = true;
  1058. this.matrix = new Matrix3();
  1059. this.generateMipmaps = true;
  1060. this.premultiplyAlpha = false;
  1061. this.flipY = true;
  1062. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1063. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1064. //
  1065. // Also changing the encoding after already used by a Material will not automatically make the Material
  1066. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1067. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  1068. this.version = 0;
  1069. this.onUpdate = null;
  1070. }
  1071. Texture.DEFAULT_IMAGE = undefined;
  1072. Texture.DEFAULT_MAPPING = UVMapping;
  1073. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1074. constructor: Texture,
  1075. isTexture: true,
  1076. updateMatrix: function updateMatrix() {
  1077. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1078. },
  1079. clone: function clone() {
  1080. return new this.constructor().copy(this);
  1081. },
  1082. copy: function copy(source) {
  1083. this.name = source.name;
  1084. this.image = source.image;
  1085. this.mipmaps = source.mipmaps.slice(0);
  1086. this.mapping = source.mapping;
  1087. this.wrapS = source.wrapS;
  1088. this.wrapT = source.wrapT;
  1089. this.magFilter = source.magFilter;
  1090. this.minFilter = source.minFilter;
  1091. this.anisotropy = source.anisotropy;
  1092. this.format = source.format;
  1093. this.internalFormat = source.internalFormat;
  1094. this.type = source.type;
  1095. this.offset.copy(source.offset);
  1096. this.repeat.copy(source.repeat);
  1097. this.center.copy(source.center);
  1098. this.rotation = source.rotation;
  1099. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1100. this.matrix.copy(source.matrix);
  1101. this.generateMipmaps = source.generateMipmaps;
  1102. this.premultiplyAlpha = source.premultiplyAlpha;
  1103. this.flipY = source.flipY;
  1104. this.unpackAlignment = source.unpackAlignment;
  1105. this.encoding = source.encoding;
  1106. return this;
  1107. },
  1108. toJSON: function toJSON(meta) {
  1109. var isRootObject = meta === undefined || typeof meta === 'string';
  1110. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1111. return meta.textures[this.uuid];
  1112. }
  1113. var output = {
  1114. metadata: {
  1115. version: 4.5,
  1116. type: 'Texture',
  1117. generator: 'Texture.toJSON'
  1118. },
  1119. uuid: this.uuid,
  1120. name: this.name,
  1121. mapping: this.mapping,
  1122. repeat: [this.repeat.x, this.repeat.y],
  1123. offset: [this.offset.x, this.offset.y],
  1124. center: [this.center.x, this.center.y],
  1125. rotation: this.rotation,
  1126. wrap: [this.wrapS, this.wrapT],
  1127. format: this.format,
  1128. type: this.type,
  1129. encoding: this.encoding,
  1130. minFilter: this.minFilter,
  1131. magFilter: this.magFilter,
  1132. anisotropy: this.anisotropy,
  1133. flipY: this.flipY,
  1134. premultiplyAlpha: this.premultiplyAlpha,
  1135. unpackAlignment: this.unpackAlignment
  1136. };
  1137. if (this.image !== undefined) {
  1138. // TODO: Move to THREE.Image
  1139. var image = this.image;
  1140. if (image.uuid === undefined) {
  1141. image.uuid = MathUtils.generateUUID(); // UGH
  1142. }
  1143. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1144. var url;
  1145. if (Array.isArray(image)) {
  1146. // process array of images e.g. CubeTexture
  1147. url = [];
  1148. for (var i = 0, l = image.length; i < l; i++) {
  1149. url.push(ImageUtils.getDataURL(image[i]));
  1150. }
  1151. } else {
  1152. // process single image
  1153. url = ImageUtils.getDataURL(image);
  1154. }
  1155. meta.images[image.uuid] = {
  1156. uuid: image.uuid,
  1157. url: url
  1158. };
  1159. }
  1160. output.image = image.uuid;
  1161. }
  1162. if (!isRootObject) {
  1163. meta.textures[this.uuid] = output;
  1164. }
  1165. return output;
  1166. },
  1167. dispose: function dispose() {
  1168. this.dispatchEvent({
  1169. type: 'dispose'
  1170. });
  1171. },
  1172. transformUv: function transformUv(uv) {
  1173. if (this.mapping !== UVMapping) return uv;
  1174. uv.applyMatrix3(this.matrix);
  1175. if (uv.x < 0 || uv.x > 1) {
  1176. switch (this.wrapS) {
  1177. case RepeatWrapping:
  1178. uv.x = uv.x - Math.floor(uv.x);
  1179. break;
  1180. case ClampToEdgeWrapping:
  1181. uv.x = uv.x < 0 ? 0 : 1;
  1182. break;
  1183. case MirroredRepeatWrapping:
  1184. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1185. uv.x = Math.ceil(uv.x) - uv.x;
  1186. } else {
  1187. uv.x = uv.x - Math.floor(uv.x);
  1188. }
  1189. break;
  1190. }
  1191. }
  1192. if (uv.y < 0 || uv.y > 1) {
  1193. switch (this.wrapT) {
  1194. case RepeatWrapping:
  1195. uv.y = uv.y - Math.floor(uv.y);
  1196. break;
  1197. case ClampToEdgeWrapping:
  1198. uv.y = uv.y < 0 ? 0 : 1;
  1199. break;
  1200. case MirroredRepeatWrapping:
  1201. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1202. uv.y = Math.ceil(uv.y) - uv.y;
  1203. } else {
  1204. uv.y = uv.y - Math.floor(uv.y);
  1205. }
  1206. break;
  1207. }
  1208. }
  1209. if (this.flipY) {
  1210. uv.y = 1 - uv.y;
  1211. }
  1212. return uv;
  1213. }
  1214. });
  1215. Object.defineProperty(Texture.prototype, "needsUpdate", {
  1216. set: function set(value) {
  1217. if (value === true) this.version++;
  1218. }
  1219. });
  1220. var Vector4 = /*#__PURE__*/function () {
  1221. function Vector4(x, y, z, w) {
  1222. if (x === void 0) {
  1223. x = 0;
  1224. }
  1225. if (y === void 0) {
  1226. y = 0;
  1227. }
  1228. if (z === void 0) {
  1229. z = 0;
  1230. }
  1231. if (w === void 0) {
  1232. w = 1;
  1233. }
  1234. Object.defineProperty(this, 'isVector4', {
  1235. value: true
  1236. });
  1237. this.x = x;
  1238. this.y = y;
  1239. this.z = z;
  1240. this.w = w;
  1241. }
  1242. var _proto = Vector4.prototype;
  1243. _proto.set = function set(x, y, z, w) {
  1244. this.x = x;
  1245. this.y = y;
  1246. this.z = z;
  1247. this.w = w;
  1248. return this;
  1249. };
  1250. _proto.setScalar = function setScalar(scalar) {
  1251. this.x = scalar;
  1252. this.y = scalar;
  1253. this.z = scalar;
  1254. this.w = scalar;
  1255. return this;
  1256. };
  1257. _proto.setX = function setX(x) {
  1258. this.x = x;
  1259. return this;
  1260. };
  1261. _proto.setY = function setY(y) {
  1262. this.y = y;
  1263. return this;
  1264. };
  1265. _proto.setZ = function setZ(z) {
  1266. this.z = z;
  1267. return this;
  1268. };
  1269. _proto.setW = function setW(w) {
  1270. this.w = w;
  1271. return this;
  1272. };
  1273. _proto.setComponent = function setComponent(index, value) {
  1274. switch (index) {
  1275. case 0:
  1276. this.x = value;
  1277. break;
  1278. case 1:
  1279. this.y = value;
  1280. break;
  1281. case 2:
  1282. this.z = value;
  1283. break;
  1284. case 3:
  1285. this.w = value;
  1286. break;
  1287. default:
  1288. throw new Error('index is out of range: ' + index);
  1289. }
  1290. return this;
  1291. };
  1292. _proto.getComponent = function getComponent(index) {
  1293. switch (index) {
  1294. case 0:
  1295. return this.x;
  1296. case 1:
  1297. return this.y;
  1298. case 2:
  1299. return this.z;
  1300. case 3:
  1301. return this.w;
  1302. default:
  1303. throw new Error('index is out of range: ' + index);
  1304. }
  1305. };
  1306. _proto.clone = function clone() {
  1307. return new this.constructor(this.x, this.y, this.z, this.w);
  1308. };
  1309. _proto.copy = function copy(v) {
  1310. this.x = v.x;
  1311. this.y = v.y;
  1312. this.z = v.z;
  1313. this.w = v.w !== undefined ? v.w : 1;
  1314. return this;
  1315. };
  1316. _proto.add = function add(v, w) {
  1317. if (w !== undefined) {
  1318. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1319. return this.addVectors(v, w);
  1320. }
  1321. this.x += v.x;
  1322. this.y += v.y;
  1323. this.z += v.z;
  1324. this.w += v.w;
  1325. return this;
  1326. };
  1327. _proto.addScalar = function addScalar(s) {
  1328. this.x += s;
  1329. this.y += s;
  1330. this.z += s;
  1331. this.w += s;
  1332. return this;
  1333. };
  1334. _proto.addVectors = function addVectors(a, b) {
  1335. this.x = a.x + b.x;
  1336. this.y = a.y + b.y;
  1337. this.z = a.z + b.z;
  1338. this.w = a.w + b.w;
  1339. return this;
  1340. };
  1341. _proto.addScaledVector = function addScaledVector(v, s) {
  1342. this.x += v.x * s;
  1343. this.y += v.y * s;
  1344. this.z += v.z * s;
  1345. this.w += v.w * s;
  1346. return this;
  1347. };
  1348. _proto.sub = function sub(v, w) {
  1349. if (w !== undefined) {
  1350. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1351. return this.subVectors(v, w);
  1352. }
  1353. this.x -= v.x;
  1354. this.y -= v.y;
  1355. this.z -= v.z;
  1356. this.w -= v.w;
  1357. return this;
  1358. };
  1359. _proto.subScalar = function subScalar(s) {
  1360. this.x -= s;
  1361. this.y -= s;
  1362. this.z -= s;
  1363. this.w -= s;
  1364. return this;
  1365. };
  1366. _proto.subVectors = function subVectors(a, b) {
  1367. this.x = a.x - b.x;
  1368. this.y = a.y - b.y;
  1369. this.z = a.z - b.z;
  1370. this.w = a.w - b.w;
  1371. return this;
  1372. };
  1373. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1374. this.x *= scalar;
  1375. this.y *= scalar;
  1376. this.z *= scalar;
  1377. this.w *= scalar;
  1378. return this;
  1379. };
  1380. _proto.applyMatrix4 = function applyMatrix4(m) {
  1381. var x = this.x,
  1382. y = this.y,
  1383. z = this.z,
  1384. w = this.w;
  1385. var e = m.elements;
  1386. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  1387. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  1388. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  1389. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  1390. return this;
  1391. };
  1392. _proto.divideScalar = function divideScalar(scalar) {
  1393. return this.multiplyScalar(1 / scalar);
  1394. };
  1395. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  1396. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1397. // q is assumed to be normalized
  1398. this.w = 2 * Math.acos(q.w);
  1399. var s = Math.sqrt(1 - q.w * q.w);
  1400. if (s < 0.0001) {
  1401. this.x = 1;
  1402. this.y = 0;
  1403. this.z = 0;
  1404. } else {
  1405. this.x = q.x / s;
  1406. this.y = q.y / s;
  1407. this.z = q.z / s;
  1408. }
  1409. return this;
  1410. };
  1411. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  1412. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1413. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1414. var angle, x, y, z; // variables for result
  1415. var epsilon = 0.01,
  1416. // margin to allow for rounding errors
  1417. epsilon2 = 0.1,
  1418. // margin to distinguish between 0 and 180 degrees
  1419. te = m.elements,
  1420. m11 = te[0],
  1421. m12 = te[4],
  1422. m13 = te[8],
  1423. m21 = te[1],
  1424. m22 = te[5],
  1425. m23 = te[9],
  1426. m31 = te[2],
  1427. m32 = te[6],
  1428. m33 = te[10];
  1429. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  1430. // singularity found
  1431. // first check for identity matrix which must have +1 for all terms
  1432. // in leading diagonal and zero in other terms
  1433. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  1434. // this singularity is identity matrix so angle = 0
  1435. this.set(1, 0, 0, 0);
  1436. return this; // zero angle, arbitrary axis
  1437. } // otherwise this singularity is angle = 180
  1438. angle = Math.PI;
  1439. var xx = (m11 + 1) / 2;
  1440. var yy = (m22 + 1) / 2;
  1441. var zz = (m33 + 1) / 2;
  1442. var xy = (m12 + m21) / 4;
  1443. var xz = (m13 + m31) / 4;
  1444. var yz = (m23 + m32) / 4;
  1445. if (xx > yy && xx > zz) {
  1446. // m11 is the largest diagonal term
  1447. if (xx < epsilon) {
  1448. x = 0;
  1449. y = 0.707106781;
  1450. z = 0.707106781;
  1451. } else {
  1452. x = Math.sqrt(xx);
  1453. y = xy / x;
  1454. z = xz / x;
  1455. }
  1456. } else if (yy > zz) {
  1457. // m22 is the largest diagonal term
  1458. if (yy < epsilon) {
  1459. x = 0.707106781;
  1460. y = 0;
  1461. z = 0.707106781;
  1462. } else {
  1463. y = Math.sqrt(yy);
  1464. x = xy / y;
  1465. z = yz / y;
  1466. }
  1467. } else {
  1468. // m33 is the largest diagonal term so base result on this
  1469. if (zz < epsilon) {
  1470. x = 0.707106781;
  1471. y = 0.707106781;
  1472. z = 0;
  1473. } else {
  1474. z = Math.sqrt(zz);
  1475. x = xz / z;
  1476. y = yz / z;
  1477. }
  1478. }
  1479. this.set(x, y, z, angle);
  1480. return this; // return 180 deg rotation
  1481. } // as we have reached here there are no singularities so we can handle normally
  1482. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  1483. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1484. // caught by singularity test above, but I've left it in just in case
  1485. this.x = (m32 - m23) / s;
  1486. this.y = (m13 - m31) / s;
  1487. this.z = (m21 - m12) / s;
  1488. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  1489. return this;
  1490. };
  1491. _proto.min = function min(v) {
  1492. this.x = Math.min(this.x, v.x);
  1493. this.y = Math.min(this.y, v.y);
  1494. this.z = Math.min(this.z, v.z);
  1495. this.w = Math.min(this.w, v.w);
  1496. return this;
  1497. };
  1498. _proto.max = function max(v) {
  1499. this.x = Math.max(this.x, v.x);
  1500. this.y = Math.max(this.y, v.y);
  1501. this.z = Math.max(this.z, v.z);
  1502. this.w = Math.max(this.w, v.w);
  1503. return this;
  1504. };
  1505. _proto.clamp = function clamp(min, max) {
  1506. // assumes min < max, componentwise
  1507. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1508. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1509. this.z = Math.max(min.z, Math.min(max.z, this.z));
  1510. this.w = Math.max(min.w, Math.min(max.w, this.w));
  1511. return this;
  1512. };
  1513. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1514. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1515. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1516. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  1517. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  1518. return this;
  1519. };
  1520. _proto.clampLength = function clampLength(min, max) {
  1521. var length = this.length();
  1522. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1523. };
  1524. _proto.floor = function floor() {
  1525. this.x = Math.floor(this.x);
  1526. this.y = Math.floor(this.y);
  1527. this.z = Math.floor(this.z);
  1528. this.w = Math.floor(this.w);
  1529. return this;
  1530. };
  1531. _proto.ceil = function ceil() {
  1532. this.x = Math.ceil(this.x);
  1533. this.y = Math.ceil(this.y);
  1534. this.z = Math.ceil(this.z);
  1535. this.w = Math.ceil(this.w);
  1536. return this;
  1537. };
  1538. _proto.round = function round() {
  1539. this.x = Math.round(this.x);
  1540. this.y = Math.round(this.y);
  1541. this.z = Math.round(this.z);
  1542. this.w = Math.round(this.w);
  1543. return this;
  1544. };
  1545. _proto.roundToZero = function roundToZero() {
  1546. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1547. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1548. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  1549. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  1550. return this;
  1551. };
  1552. _proto.negate = function negate() {
  1553. this.x = -this.x;
  1554. this.y = -this.y;
  1555. this.z = -this.z;
  1556. this.w = -this.w;
  1557. return this;
  1558. };
  1559. _proto.dot = function dot(v) {
  1560. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1561. };
  1562. _proto.lengthSq = function lengthSq() {
  1563. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1564. };
  1565. _proto.length = function length() {
  1566. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  1567. };
  1568. _proto.manhattanLength = function manhattanLength() {
  1569. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  1570. };
  1571. _proto.normalize = function normalize() {
  1572. return this.divideScalar(this.length() || 1);
  1573. };
  1574. _proto.setLength = function setLength(length) {
  1575. return this.normalize().multiplyScalar(length);
  1576. };
  1577. _proto.lerp = function lerp(v, alpha) {
  1578. this.x += (v.x - this.x) * alpha;
  1579. this.y += (v.y - this.y) * alpha;
  1580. this.z += (v.z - this.z) * alpha;
  1581. this.w += (v.w - this.w) * alpha;
  1582. return this;
  1583. };
  1584. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1585. this.x = v1.x + (v2.x - v1.x) * alpha;
  1586. this.y = v1.y + (v2.y - v1.y) * alpha;
  1587. this.z = v1.z + (v2.z - v1.z) * alpha;
  1588. this.w = v1.w + (v2.w - v1.w) * alpha;
  1589. return this;
  1590. };
  1591. _proto.equals = function equals(v) {
  1592. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  1593. };
  1594. _proto.fromArray = function fromArray(array, offset) {
  1595. if (offset === void 0) {
  1596. offset = 0;
  1597. }
  1598. this.x = array[offset];
  1599. this.y = array[offset + 1];
  1600. this.z = array[offset + 2];
  1601. this.w = array[offset + 3];
  1602. return this;
  1603. };
  1604. _proto.toArray = function toArray(array, offset) {
  1605. if (array === void 0) {
  1606. array = [];
  1607. }
  1608. if (offset === void 0) {
  1609. offset = 0;
  1610. }
  1611. array[offset] = this.x;
  1612. array[offset + 1] = this.y;
  1613. array[offset + 2] = this.z;
  1614. array[offset + 3] = this.w;
  1615. return array;
  1616. };
  1617. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1618. if (offset !== undefined) {
  1619. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  1620. }
  1621. this.x = attribute.getX(index);
  1622. this.y = attribute.getY(index);
  1623. this.z = attribute.getZ(index);
  1624. this.w = attribute.getW(index);
  1625. return this;
  1626. };
  1627. _proto.random = function random() {
  1628. this.x = Math.random();
  1629. this.y = Math.random();
  1630. this.z = Math.random();
  1631. this.w = Math.random();
  1632. return this;
  1633. };
  1634. _createClass(Vector4, [{
  1635. key: "width",
  1636. get: function get() {
  1637. return this.z;
  1638. },
  1639. set: function set(value) {
  1640. this.z = value;
  1641. }
  1642. }, {
  1643. key: "height",
  1644. get: function get() {
  1645. return this.w;
  1646. },
  1647. set: function set(value) {
  1648. this.w = value;
  1649. }
  1650. }]);
  1651. return Vector4;
  1652. }();
  1653. /*
  1654. In options, we can specify:
  1655. * Texture parameters for an auto-generated target texture
  1656. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1657. */
  1658. function WebGLRenderTarget(width, height, options) {
  1659. this.width = width;
  1660. this.height = height;
  1661. this.scissor = new Vector4(0, 0, width, height);
  1662. this.scissorTest = false;
  1663. this.viewport = new Vector4(0, 0, width, height);
  1664. options = options || {};
  1665. this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  1666. this.texture.image = {};
  1667. this.texture.image.width = width;
  1668. this.texture.image.height = height;
  1669. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  1670. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  1671. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1672. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  1673. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1674. }
  1675. WebGLRenderTarget.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1676. constructor: WebGLRenderTarget,
  1677. isWebGLRenderTarget: true,
  1678. setSize: function setSize(width, height) {
  1679. if (this.width !== width || this.height !== height) {
  1680. this.width = width;
  1681. this.height = height;
  1682. this.texture.image.width = width;
  1683. this.texture.image.height = height;
  1684. this.dispose();
  1685. }
  1686. this.viewport.set(0, 0, width, height);
  1687. this.scissor.set(0, 0, width, height);
  1688. },
  1689. clone: function clone() {
  1690. return new this.constructor().copy(this);
  1691. },
  1692. copy: function copy(source) {
  1693. this.width = source.width;
  1694. this.height = source.height;
  1695. this.viewport.copy(source.viewport);
  1696. this.texture = source.texture.clone();
  1697. this.depthBuffer = source.depthBuffer;
  1698. this.stencilBuffer = source.stencilBuffer;
  1699. this.depthTexture = source.depthTexture;
  1700. return this;
  1701. },
  1702. dispose: function dispose() {
  1703. this.dispatchEvent({
  1704. type: 'dispose'
  1705. });
  1706. }
  1707. });
  1708. function WebGLMultisampleRenderTarget(width, height, options) {
  1709. WebGLRenderTarget.call(this, width, height, options);
  1710. this.samples = 4;
  1711. }
  1712. WebGLMultisampleRenderTarget.prototype = Object.assign(Object.create(WebGLRenderTarget.prototype), {
  1713. constructor: WebGLMultisampleRenderTarget,
  1714. isWebGLMultisampleRenderTarget: true,
  1715. copy: function copy(source) {
  1716. WebGLRenderTarget.prototype.copy.call(this, source);
  1717. this.samples = source.samples;
  1718. return this;
  1719. }
  1720. });
  1721. var Quaternion = /*#__PURE__*/function () {
  1722. function Quaternion(x, y, z, w) {
  1723. if (x === void 0) {
  1724. x = 0;
  1725. }
  1726. if (y === void 0) {
  1727. y = 0;
  1728. }
  1729. if (z === void 0) {
  1730. z = 0;
  1731. }
  1732. if (w === void 0) {
  1733. w = 1;
  1734. }
  1735. Object.defineProperty(this, 'isQuaternion', {
  1736. value: true
  1737. });
  1738. this._x = x;
  1739. this._y = y;
  1740. this._z = z;
  1741. this._w = w;
  1742. }
  1743. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  1744. return qm.copy(qa).slerp(qb, t);
  1745. };
  1746. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  1747. // fuzz-free, array-based Quaternion SLERP operation
  1748. var x0 = src0[srcOffset0 + 0],
  1749. y0 = src0[srcOffset0 + 1],
  1750. z0 = src0[srcOffset0 + 2],
  1751. w0 = src0[srcOffset0 + 3];
  1752. var x1 = src1[srcOffset1 + 0],
  1753. y1 = src1[srcOffset1 + 1],
  1754. z1 = src1[srcOffset1 + 2],
  1755. w1 = src1[srcOffset1 + 3];
  1756. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  1757. var s = 1 - t;
  1758. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1759. dir = cos >= 0 ? 1 : -1,
  1760. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  1761. if (sqrSin > Number.EPSILON) {
  1762. var sin = Math.sqrt(sqrSin),
  1763. len = Math.atan2(sin, cos * dir);
  1764. s = Math.sin(s * len) / sin;
  1765. t = Math.sin(t * len) / sin;
  1766. }
  1767. var tDir = t * dir;
  1768. x0 = x0 * s + x1 * tDir;
  1769. y0 = y0 * s + y1 * tDir;
  1770. z0 = z0 * s + z1 * tDir;
  1771. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  1772. if (s === 1 - t) {
  1773. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  1774. x0 *= f;
  1775. y0 *= f;
  1776. z0 *= f;
  1777. w0 *= f;
  1778. }
  1779. }
  1780. dst[dstOffset] = x0;
  1781. dst[dstOffset + 1] = y0;
  1782. dst[dstOffset + 2] = z0;
  1783. dst[dstOffset + 3] = w0;
  1784. };
  1785. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  1786. var x0 = src0[srcOffset0];
  1787. var y0 = src0[srcOffset0 + 1];
  1788. var z0 = src0[srcOffset0 + 2];
  1789. var w0 = src0[srcOffset0 + 3];
  1790. var x1 = src1[srcOffset1];
  1791. var y1 = src1[srcOffset1 + 1];
  1792. var z1 = src1[srcOffset1 + 2];
  1793. var w1 = src1[srcOffset1 + 3];
  1794. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  1795. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  1796. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  1797. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  1798. return dst;
  1799. };
  1800. var _proto = Quaternion.prototype;
  1801. _proto.set = function set(x, y, z, w) {
  1802. this._x = x;
  1803. this._y = y;
  1804. this._z = z;
  1805. this._w = w;
  1806. this._onChangeCallback();
  1807. return this;
  1808. };
  1809. _proto.clone = function clone() {
  1810. return new this.constructor(this._x, this._y, this._z, this._w);
  1811. };
  1812. _proto.copy = function copy(quaternion) {
  1813. this._x = quaternion.x;
  1814. this._y = quaternion.y;
  1815. this._z = quaternion.z;
  1816. this._w = quaternion.w;
  1817. this._onChangeCallback();
  1818. return this;
  1819. };
  1820. _proto.setFromEuler = function setFromEuler(euler, update) {
  1821. if (!(euler && euler.isEuler)) {
  1822. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  1823. }
  1824. var x = euler._x,
  1825. y = euler._y,
  1826. z = euler._z,
  1827. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  1828. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1829. // content/SpinCalc.m
  1830. var cos = Math.cos;
  1831. var sin = Math.sin;
  1832. var c1 = cos(x / 2);
  1833. var c2 = cos(y / 2);
  1834. var c3 = cos(z / 2);
  1835. var s1 = sin(x / 2);
  1836. var s2 = sin(y / 2);
  1837. var s3 = sin(z / 2);
  1838. switch (order) {
  1839. case 'XYZ':
  1840. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1841. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1842. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1843. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1844. break;
  1845. case 'YXZ':
  1846. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1847. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1848. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1849. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1850. break;
  1851. case 'ZXY':
  1852. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1853. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1854. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1855. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1856. break;
  1857. case 'ZYX':
  1858. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1859. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1860. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1861. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1862. break;
  1863. case 'YZX':
  1864. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1865. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1866. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1867. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1868. break;
  1869. case 'XZY':
  1870. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1871. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1872. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1873. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1874. break;
  1875. default:
  1876. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  1877. }
  1878. if (update !== false) this._onChangeCallback();
  1879. return this;
  1880. };
  1881. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  1882. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1883. // assumes axis is normalized
  1884. var halfAngle = angle / 2,
  1885. s = Math.sin(halfAngle);
  1886. this._x = axis.x * s;
  1887. this._y = axis.y * s;
  1888. this._z = axis.z * s;
  1889. this._w = Math.cos(halfAngle);
  1890. this._onChangeCallback();
  1891. return this;
  1892. };
  1893. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  1894. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1895. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1896. var te = m.elements,
  1897. m11 = te[0],
  1898. m12 = te[4],
  1899. m13 = te[8],
  1900. m21 = te[1],
  1901. m22 = te[5],
  1902. m23 = te[9],
  1903. m31 = te[2],
  1904. m32 = te[6],
  1905. m33 = te[10],
  1906. trace = m11 + m22 + m33;
  1907. if (trace > 0) {
  1908. var s = 0.5 / Math.sqrt(trace + 1.0);
  1909. this._w = 0.25 / s;
  1910. this._x = (m32 - m23) * s;
  1911. this._y = (m13 - m31) * s;
  1912. this._z = (m21 - m12) * s;
  1913. } else if (m11 > m22 && m11 > m33) {
  1914. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  1915. this._w = (m32 - m23) / _s;
  1916. this._x = 0.25 * _s;
  1917. this._y = (m12 + m21) / _s;
  1918. this._z = (m13 + m31) / _s;
  1919. } else if (m22 > m33) {
  1920. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  1921. this._w = (m13 - m31) / _s2;
  1922. this._x = (m12 + m21) / _s2;
  1923. this._y = 0.25 * _s2;
  1924. this._z = (m23 + m32) / _s2;
  1925. } else {
  1926. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  1927. this._w = (m21 - m12) / _s3;
  1928. this._x = (m13 + m31) / _s3;
  1929. this._y = (m23 + m32) / _s3;
  1930. this._z = 0.25 * _s3;
  1931. }
  1932. this._onChangeCallback();
  1933. return this;
  1934. };
  1935. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  1936. // assumes direction vectors vFrom and vTo are normalized
  1937. var EPS = 0.000001;
  1938. var r = vFrom.dot(vTo) + 1;
  1939. if (r < EPS) {
  1940. r = 0;
  1941. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  1942. this._x = -vFrom.y;
  1943. this._y = vFrom.x;
  1944. this._z = 0;
  1945. this._w = r;
  1946. } else {
  1947. this._x = 0;
  1948. this._y = -vFrom.z;
  1949. this._z = vFrom.y;
  1950. this._w = r;
  1951. }
  1952. } else {
  1953. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  1954. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  1955. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  1956. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  1957. this._w = r;
  1958. }
  1959. return this.normalize();
  1960. };
  1961. _proto.angleTo = function angleTo(q) {
  1962. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  1963. };
  1964. _proto.rotateTowards = function rotateTowards(q, step) {
  1965. var angle = this.angleTo(q);
  1966. if (angle === 0) return this;
  1967. var t = Math.min(1, step / angle);
  1968. this.slerp(q, t);
  1969. return this;
  1970. };
  1971. _proto.identity = function identity() {
  1972. return this.set(0, 0, 0, 1);
  1973. };
  1974. _proto.inverse = function inverse() {
  1975. // quaternion is assumed to have unit length
  1976. return this.conjugate();
  1977. };
  1978. _proto.conjugate = function conjugate() {
  1979. this._x *= -1;
  1980. this._y *= -1;
  1981. this._z *= -1;
  1982. this._onChangeCallback();
  1983. return this;
  1984. };
  1985. _proto.dot = function dot(v) {
  1986. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1987. };
  1988. _proto.lengthSq = function lengthSq() {
  1989. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1990. };
  1991. _proto.length = function length() {
  1992. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  1993. };
  1994. _proto.normalize = function normalize() {
  1995. var l = this.length();
  1996. if (l === 0) {
  1997. this._x = 0;
  1998. this._y = 0;
  1999. this._z = 0;
  2000. this._w = 1;
  2001. } else {
  2002. l = 1 / l;
  2003. this._x = this._x * l;
  2004. this._y = this._y * l;
  2005. this._z = this._z * l;
  2006. this._w = this._w * l;
  2007. }
  2008. this._onChangeCallback();
  2009. return this;
  2010. };
  2011. _proto.multiply = function multiply(q, p) {
  2012. if (p !== undefined) {
  2013. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2014. return this.multiplyQuaternions(q, p);
  2015. }
  2016. return this.multiplyQuaternions(this, q);
  2017. };
  2018. _proto.premultiply = function premultiply(q) {
  2019. return this.multiplyQuaternions(q, this);
  2020. };
  2021. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2022. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2023. var qax = a._x,
  2024. qay = a._y,
  2025. qaz = a._z,
  2026. qaw = a._w;
  2027. var qbx = b._x,
  2028. qby = b._y,
  2029. qbz = b._z,
  2030. qbw = b._w;
  2031. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2032. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2033. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2034. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2035. this._onChangeCallback();
  2036. return this;
  2037. };
  2038. _proto.slerp = function slerp(qb, t) {
  2039. if (t === 0) return this;
  2040. if (t === 1) return this.copy(qb);
  2041. var x = this._x,
  2042. y = this._y,
  2043. z = this._z,
  2044. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2045. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2046. if (cosHalfTheta < 0) {
  2047. this._w = -qb._w;
  2048. this._x = -qb._x;
  2049. this._y = -qb._y;
  2050. this._z = -qb._z;
  2051. cosHalfTheta = -cosHalfTheta;
  2052. } else {
  2053. this.copy(qb);
  2054. }
  2055. if (cosHalfTheta >= 1.0) {
  2056. this._w = w;
  2057. this._x = x;
  2058. this._y = y;
  2059. this._z = z;
  2060. return this;
  2061. }
  2062. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2063. if (sqrSinHalfTheta <= Number.EPSILON) {
  2064. var s = 1 - t;
  2065. this._w = s * w + t * this._w;
  2066. this._x = s * x + t * this._x;
  2067. this._y = s * y + t * this._y;
  2068. this._z = s * z + t * this._z;
  2069. this.normalize();
  2070. this._onChangeCallback();
  2071. return this;
  2072. }
  2073. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2074. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2075. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2076. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2077. this._w = w * ratioA + this._w * ratioB;
  2078. this._x = x * ratioA + this._x * ratioB;
  2079. this._y = y * ratioA + this._y * ratioB;
  2080. this._z = z * ratioA + this._z * ratioB;
  2081. this._onChangeCallback();
  2082. return this;
  2083. };
  2084. _proto.equals = function equals(quaternion) {
  2085. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2086. };
  2087. _proto.fromArray = function fromArray(array, offset) {
  2088. if (offset === void 0) {
  2089. offset = 0;
  2090. }
  2091. this._x = array[offset];
  2092. this._y = array[offset + 1];
  2093. this._z = array[offset + 2];
  2094. this._w = array[offset + 3];
  2095. this._onChangeCallback();
  2096. return this;
  2097. };
  2098. _proto.toArray = function toArray(array, offset) {
  2099. if (array === void 0) {
  2100. array = [];
  2101. }
  2102. if (offset === void 0) {
  2103. offset = 0;
  2104. }
  2105. array[offset] = this._x;
  2106. array[offset + 1] = this._y;
  2107. array[offset + 2] = this._z;
  2108. array[offset + 3] = this._w;
  2109. return array;
  2110. };
  2111. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2112. this._x = attribute.getX(index);
  2113. this._y = attribute.getY(index);
  2114. this._z = attribute.getZ(index);
  2115. this._w = attribute.getW(index);
  2116. return this;
  2117. };
  2118. _proto._onChange = function _onChange(callback) {
  2119. this._onChangeCallback = callback;
  2120. return this;
  2121. };
  2122. _proto._onChangeCallback = function _onChangeCallback() {};
  2123. _createClass(Quaternion, [{
  2124. key: "x",
  2125. get: function get() {
  2126. return this._x;
  2127. },
  2128. set: function set(value) {
  2129. this._x = value;
  2130. this._onChangeCallback();
  2131. }
  2132. }, {
  2133. key: "y",
  2134. get: function get() {
  2135. return this._y;
  2136. },
  2137. set: function set(value) {
  2138. this._y = value;
  2139. this._onChangeCallback();
  2140. }
  2141. }, {
  2142. key: "z",
  2143. get: function get() {
  2144. return this._z;
  2145. },
  2146. set: function set(value) {
  2147. this._z = value;
  2148. this._onChangeCallback();
  2149. }
  2150. }, {
  2151. key: "w",
  2152. get: function get() {
  2153. return this._w;
  2154. },
  2155. set: function set(value) {
  2156. this._w = value;
  2157. this._onChangeCallback();
  2158. }
  2159. }]);
  2160. return Quaternion;
  2161. }();
  2162. var Vector3 = /*#__PURE__*/function () {
  2163. function Vector3(x, y, z) {
  2164. if (x === void 0) {
  2165. x = 0;
  2166. }
  2167. if (y === void 0) {
  2168. y = 0;
  2169. }
  2170. if (z === void 0) {
  2171. z = 0;
  2172. }
  2173. Object.defineProperty(this, 'isVector3', {
  2174. value: true
  2175. });
  2176. this.x = x;
  2177. this.y = y;
  2178. this.z = z;
  2179. }
  2180. var _proto = Vector3.prototype;
  2181. _proto.set = function set(x, y, z) {
  2182. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2183. this.x = x;
  2184. this.y = y;
  2185. this.z = z;
  2186. return this;
  2187. };
  2188. _proto.setScalar = function setScalar(scalar) {
  2189. this.x = scalar;
  2190. this.y = scalar;
  2191. this.z = scalar;
  2192. return this;
  2193. };
  2194. _proto.setX = function setX(x) {
  2195. this.x = x;
  2196. return this;
  2197. };
  2198. _proto.setY = function setY(y) {
  2199. this.y = y;
  2200. return this;
  2201. };
  2202. _proto.setZ = function setZ(z) {
  2203. this.z = z;
  2204. return this;
  2205. };
  2206. _proto.setComponent = function setComponent(index, value) {
  2207. switch (index) {
  2208. case 0:
  2209. this.x = value;
  2210. break;
  2211. case 1:
  2212. this.y = value;
  2213. break;
  2214. case 2:
  2215. this.z = value;
  2216. break;
  2217. default:
  2218. throw new Error('index is out of range: ' + index);
  2219. }
  2220. return this;
  2221. };
  2222. _proto.getComponent = function getComponent(index) {
  2223. switch (index) {
  2224. case 0:
  2225. return this.x;
  2226. case 1:
  2227. return this.y;
  2228. case 2:
  2229. return this.z;
  2230. default:
  2231. throw new Error('index is out of range: ' + index);
  2232. }
  2233. };
  2234. _proto.clone = function clone() {
  2235. return new this.constructor(this.x, this.y, this.z);
  2236. };
  2237. _proto.copy = function copy(v) {
  2238. this.x = v.x;
  2239. this.y = v.y;
  2240. this.z = v.z;
  2241. return this;
  2242. };
  2243. _proto.add = function add(v, w) {
  2244. if (w !== undefined) {
  2245. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2246. return this.addVectors(v, w);
  2247. }
  2248. this.x += v.x;
  2249. this.y += v.y;
  2250. this.z += v.z;
  2251. return this;
  2252. };
  2253. _proto.addScalar = function addScalar(s) {
  2254. this.x += s;
  2255. this.y += s;
  2256. this.z += s;
  2257. return this;
  2258. };
  2259. _proto.addVectors = function addVectors(a, b) {
  2260. this.x = a.x + b.x;
  2261. this.y = a.y + b.y;
  2262. this.z = a.z + b.z;
  2263. return this;
  2264. };
  2265. _proto.addScaledVector = function addScaledVector(v, s) {
  2266. this.x += v.x * s;
  2267. this.y += v.y * s;
  2268. this.z += v.z * s;
  2269. return this;
  2270. };
  2271. _proto.sub = function sub(v, w) {
  2272. if (w !== undefined) {
  2273. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2274. return this.subVectors(v, w);
  2275. }
  2276. this.x -= v.x;
  2277. this.y -= v.y;
  2278. this.z -= v.z;
  2279. return this;
  2280. };
  2281. _proto.subScalar = function subScalar(s) {
  2282. this.x -= s;
  2283. this.y -= s;
  2284. this.z -= s;
  2285. return this;
  2286. };
  2287. _proto.subVectors = function subVectors(a, b) {
  2288. this.x = a.x - b.x;
  2289. this.y = a.y - b.y;
  2290. this.z = a.z - b.z;
  2291. return this;
  2292. };
  2293. _proto.multiply = function multiply(v, w) {
  2294. if (w !== undefined) {
  2295. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  2296. return this.multiplyVectors(v, w);
  2297. }
  2298. this.x *= v.x;
  2299. this.y *= v.y;
  2300. this.z *= v.z;
  2301. return this;
  2302. };
  2303. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2304. this.x *= scalar;
  2305. this.y *= scalar;
  2306. this.z *= scalar;
  2307. return this;
  2308. };
  2309. _proto.multiplyVectors = function multiplyVectors(a, b) {
  2310. this.x = a.x * b.x;
  2311. this.y = a.y * b.y;
  2312. this.z = a.z * b.z;
  2313. return this;
  2314. };
  2315. _proto.applyEuler = function applyEuler(euler) {
  2316. if (!(euler && euler.isEuler)) {
  2317. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2318. }
  2319. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  2320. };
  2321. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  2322. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  2323. };
  2324. _proto.applyMatrix3 = function applyMatrix3(m) {
  2325. var x = this.x,
  2326. y = this.y,
  2327. z = this.z;
  2328. var e = m.elements;
  2329. this.x = e[0] * x + e[3] * y + e[6] * z;
  2330. this.y = e[1] * x + e[4] * y + e[7] * z;
  2331. this.z = e[2] * x + e[5] * y + e[8] * z;
  2332. return this;
  2333. };
  2334. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  2335. return this.applyMatrix3(m).normalize();
  2336. };
  2337. _proto.applyMatrix4 = function applyMatrix4(m) {
  2338. var x = this.x,
  2339. y = this.y,
  2340. z = this.z;
  2341. var e = m.elements;
  2342. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  2343. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  2344. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  2345. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  2346. return this;
  2347. };
  2348. _proto.applyQuaternion = function applyQuaternion(q) {
  2349. var x = this.x,
  2350. y = this.y,
  2351. z = this.z;
  2352. var qx = q.x,
  2353. qy = q.y,
  2354. qz = q.z,
  2355. qw = q.w; // calculate quat * vector
  2356. var ix = qw * x + qy * z - qz * y;
  2357. var iy = qw * y + qz * x - qx * z;
  2358. var iz = qw * z + qx * y - qy * x;
  2359. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  2360. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  2361. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  2362. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  2363. return this;
  2364. };
  2365. _proto.project = function project(camera) {
  2366. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  2367. };
  2368. _proto.unproject = function unproject(camera) {
  2369. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  2370. };
  2371. _proto.transformDirection = function transformDirection(m) {
  2372. // input: THREE.Matrix4 affine matrix
  2373. // vector interpreted as a direction
  2374. var x = this.x,
  2375. y = this.y,
  2376. z = this.z;
  2377. var e = m.elements;
  2378. this.x = e[0] * x + e[4] * y + e[8] * z;
  2379. this.y = e[1] * x + e[5] * y + e[9] * z;
  2380. this.z = e[2] * x + e[6] * y + e[10] * z;
  2381. return this.normalize();
  2382. };
  2383. _proto.divide = function divide(v) {
  2384. this.x /= v.x;
  2385. this.y /= v.y;
  2386. this.z /= v.z;
  2387. return this;
  2388. };
  2389. _proto.divideScalar = function divideScalar(scalar) {
  2390. return this.multiplyScalar(1 / scalar);
  2391. };
  2392. _proto.min = function min(v) {
  2393. this.x = Math.min(this.x, v.x);
  2394. this.y = Math.min(this.y, v.y);
  2395. this.z = Math.min(this.z, v.z);
  2396. return this;
  2397. };
  2398. _proto.max = function max(v) {
  2399. this.x = Math.max(this.x, v.x);
  2400. this.y = Math.max(this.y, v.y);
  2401. this.z = Math.max(this.z, v.z);
  2402. return this;
  2403. };
  2404. _proto.clamp = function clamp(min, max) {
  2405. // assumes min < max, componentwise
  2406. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2407. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2408. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2409. return this;
  2410. };
  2411. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2412. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2413. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2414. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2415. return this;
  2416. };
  2417. _proto.clampLength = function clampLength(min, max) {
  2418. var length = this.length();
  2419. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2420. };
  2421. _proto.floor = function floor() {
  2422. this.x = Math.floor(this.x);
  2423. this.y = Math.floor(this.y);
  2424. this.z = Math.floor(this.z);
  2425. return this;
  2426. };
  2427. _proto.ceil = function ceil() {
  2428. this.x = Math.ceil(this.x);
  2429. this.y = Math.ceil(this.y);
  2430. this.z = Math.ceil(this.z);
  2431. return this;
  2432. };
  2433. _proto.round = function round() {
  2434. this.x = Math.round(this.x);
  2435. this.y = Math.round(this.y);
  2436. this.z = Math.round(this.z);
  2437. return this;
  2438. };
  2439. _proto.roundToZero = function roundToZero() {
  2440. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2441. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2442. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2443. return this;
  2444. };
  2445. _proto.negate = function negate() {
  2446. this.x = -this.x;
  2447. this.y = -this.y;
  2448. this.z = -this.z;
  2449. return this;
  2450. };
  2451. _proto.dot = function dot(v) {
  2452. return this.x * v.x + this.y * v.y + this.z * v.z;
  2453. } // TODO lengthSquared?
  2454. ;
  2455. _proto.lengthSq = function lengthSq() {
  2456. return this.x * this.x + this.y * this.y + this.z * this.z;
  2457. };
  2458. _proto.length = function length() {
  2459. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  2460. };
  2461. _proto.manhattanLength = function manhattanLength() {
  2462. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  2463. };
  2464. _proto.normalize = function normalize() {
  2465. return this.divideScalar(this.length() || 1);
  2466. };
  2467. _proto.setLength = function setLength(length) {
  2468. return this.normalize().multiplyScalar(length);
  2469. };
  2470. _proto.lerp = function lerp(v, alpha) {
  2471. this.x += (v.x - this.x) * alpha;
  2472. this.y += (v.y - this.y) * alpha;
  2473. this.z += (v.z - this.z) * alpha;
  2474. return this;
  2475. };
  2476. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2477. this.x = v1.x + (v2.x - v1.x) * alpha;
  2478. this.y = v1.y + (v2.y - v1.y) * alpha;
  2479. this.z = v1.z + (v2.z - v1.z) * alpha;
  2480. return this;
  2481. };
  2482. _proto.cross = function cross(v, w) {
  2483. if (w !== undefined) {
  2484. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  2485. return this.crossVectors(v, w);
  2486. }
  2487. return this.crossVectors(this, v);
  2488. };
  2489. _proto.crossVectors = function crossVectors(a, b) {
  2490. var ax = a.x,
  2491. ay = a.y,
  2492. az = a.z;
  2493. var bx = b.x,
  2494. by = b.y,
  2495. bz = b.z;
  2496. this.x = ay * bz - az * by;
  2497. this.y = az * bx - ax * bz;
  2498. this.z = ax * by - ay * bx;
  2499. return this;
  2500. };
  2501. _proto.projectOnVector = function projectOnVector(v) {
  2502. var denominator = v.lengthSq();
  2503. if (denominator === 0) return this.set(0, 0, 0);
  2504. var scalar = v.dot(this) / denominator;
  2505. return this.copy(v).multiplyScalar(scalar);
  2506. };
  2507. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  2508. _vector.copy(this).projectOnVector(planeNormal);
  2509. return this.sub(_vector);
  2510. };
  2511. _proto.reflect = function reflect(normal) {
  2512. // reflect incident vector off plane orthogonal to normal
  2513. // normal is assumed to have unit length
  2514. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  2515. };
  2516. _proto.angleTo = function angleTo(v) {
  2517. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  2518. if (denominator === 0) return Math.PI / 2;
  2519. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  2520. return Math.acos(MathUtils.clamp(theta, -1, 1));
  2521. };
  2522. _proto.distanceTo = function distanceTo(v) {
  2523. return Math.sqrt(this.distanceToSquared(v));
  2524. };
  2525. _proto.distanceToSquared = function distanceToSquared(v) {
  2526. var dx = this.x - v.x,
  2527. dy = this.y - v.y,
  2528. dz = this.z - v.z;
  2529. return dx * dx + dy * dy + dz * dz;
  2530. };
  2531. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  2532. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  2533. };
  2534. _proto.setFromSpherical = function setFromSpherical(s) {
  2535. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  2536. };
  2537. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  2538. var sinPhiRadius = Math.sin(phi) * radius;
  2539. this.x = sinPhiRadius * Math.sin(theta);
  2540. this.y = Math.cos(phi) * radius;
  2541. this.z = sinPhiRadius * Math.cos(theta);
  2542. return this;
  2543. };
  2544. _proto.setFromCylindrical = function setFromCylindrical(c) {
  2545. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  2546. };
  2547. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  2548. this.x = radius * Math.sin(theta);
  2549. this.y = y;
  2550. this.z = radius * Math.cos(theta);
  2551. return this;
  2552. };
  2553. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  2554. var e = m.elements;
  2555. this.x = e[12];
  2556. this.y = e[13];
  2557. this.z = e[14];
  2558. return this;
  2559. };
  2560. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  2561. var sx = this.setFromMatrixColumn(m, 0).length();
  2562. var sy = this.setFromMatrixColumn(m, 1).length();
  2563. var sz = this.setFromMatrixColumn(m, 2).length();
  2564. this.x = sx;
  2565. this.y = sy;
  2566. this.z = sz;
  2567. return this;
  2568. };
  2569. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  2570. return this.fromArray(m.elements, index * 4);
  2571. };
  2572. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  2573. return this.fromArray(m.elements, index * 3);
  2574. };
  2575. _proto.equals = function equals(v) {
  2576. return v.x === this.x && v.y === this.y && v.z === this.z;
  2577. };
  2578. _proto.fromArray = function fromArray(array, offset) {
  2579. if (offset === void 0) {
  2580. offset = 0;
  2581. }
  2582. this.x = array[offset];
  2583. this.y = array[offset + 1];
  2584. this.z = array[offset + 2];
  2585. return this;
  2586. };
  2587. _proto.toArray = function toArray(array, offset) {
  2588. if (array === void 0) {
  2589. array = [];
  2590. }
  2591. if (offset === void 0) {
  2592. offset = 0;
  2593. }
  2594. array[offset] = this.x;
  2595. array[offset + 1] = this.y;
  2596. array[offset + 2] = this.z;
  2597. return array;
  2598. };
  2599. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2600. if (offset !== undefined) {
  2601. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  2602. }
  2603. this.x = attribute.getX(index);
  2604. this.y = attribute.getY(index);
  2605. this.z = attribute.getZ(index);
  2606. return this;
  2607. };
  2608. _proto.random = function random() {
  2609. this.x = Math.random();
  2610. this.y = Math.random();
  2611. this.z = Math.random();
  2612. return this;
  2613. };
  2614. return Vector3;
  2615. }();
  2616. var _vector = /*@__PURE__*/new Vector3();
  2617. var _quaternion = /*@__PURE__*/new Quaternion();
  2618. var Box3 = /*#__PURE__*/function () {
  2619. function Box3(min, max) {
  2620. Object.defineProperty(this, 'isBox3', {
  2621. value: true
  2622. });
  2623. this.min = min !== undefined ? min : new Vector3(+Infinity, +Infinity, +Infinity);
  2624. this.max = max !== undefined ? max : new Vector3(-Infinity, -Infinity, -Infinity);
  2625. }
  2626. var _proto = Box3.prototype;
  2627. _proto.set = function set(min, max) {
  2628. this.min.copy(min);
  2629. this.max.copy(max);
  2630. return this;
  2631. };
  2632. _proto.setFromArray = function setFromArray(array) {
  2633. var minX = +Infinity;
  2634. var minY = +Infinity;
  2635. var minZ = +Infinity;
  2636. var maxX = -Infinity;
  2637. var maxY = -Infinity;
  2638. var maxZ = -Infinity;
  2639. for (var i = 0, l = array.length; i < l; i += 3) {
  2640. var x = array[i];
  2641. var y = array[i + 1];
  2642. var z = array[i + 2];
  2643. if (x < minX) minX = x;
  2644. if (y < minY) minY = y;
  2645. if (z < minZ) minZ = z;
  2646. if (x > maxX) maxX = x;
  2647. if (y > maxY) maxY = y;
  2648. if (z > maxZ) maxZ = z;
  2649. }
  2650. this.min.set(minX, minY, minZ);
  2651. this.max.set(maxX, maxY, maxZ);
  2652. return this;
  2653. };
  2654. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  2655. var minX = +Infinity;
  2656. var minY = +Infinity;
  2657. var minZ = +Infinity;
  2658. var maxX = -Infinity;
  2659. var maxY = -Infinity;
  2660. var maxZ = -Infinity;
  2661. for (var i = 0, l = attribute.count; i < l; i++) {
  2662. var x = attribute.getX(i);
  2663. var y = attribute.getY(i);
  2664. var z = attribute.getZ(i);
  2665. if (x < minX) minX = x;
  2666. if (y < minY) minY = y;
  2667. if (z < minZ) minZ = z;
  2668. if (x > maxX) maxX = x;
  2669. if (y > maxY) maxY = y;
  2670. if (z > maxZ) maxZ = z;
  2671. }
  2672. this.min.set(minX, minY, minZ);
  2673. this.max.set(maxX, maxY, maxZ);
  2674. return this;
  2675. };
  2676. _proto.setFromPoints = function setFromPoints(points) {
  2677. this.makeEmpty();
  2678. for (var i = 0, il = points.length; i < il; i++) {
  2679. this.expandByPoint(points[i]);
  2680. }
  2681. return this;
  2682. };
  2683. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  2684. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  2685. this.min.copy(center).sub(halfSize);
  2686. this.max.copy(center).add(halfSize);
  2687. return this;
  2688. };
  2689. _proto.setFromObject = function setFromObject(object) {
  2690. this.makeEmpty();
  2691. return this.expandByObject(object);
  2692. };
  2693. _proto.clone = function clone() {
  2694. return new this.constructor().copy(this);
  2695. };
  2696. _proto.copy = function copy(box) {
  2697. this.min.copy(box.min);
  2698. this.max.copy(box.max);
  2699. return this;
  2700. };
  2701. _proto.makeEmpty = function makeEmpty() {
  2702. this.min.x = this.min.y = this.min.z = +Infinity;
  2703. this.max.x = this.max.y = this.max.z = -Infinity;
  2704. return this;
  2705. };
  2706. _proto.isEmpty = function isEmpty() {
  2707. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2708. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  2709. };
  2710. _proto.getCenter = function getCenter(target) {
  2711. if (target === undefined) {
  2712. console.warn('THREE.Box3: .getCenter() target is now required');
  2713. target = new Vector3();
  2714. }
  2715. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  2716. };
  2717. _proto.getSize = function getSize(target) {
  2718. if (target === undefined) {
  2719. console.warn('THREE.Box3: .getSize() target is now required');
  2720. target = new Vector3();
  2721. }
  2722. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  2723. };
  2724. _proto.expandByPoint = function expandByPoint(point) {
  2725. this.min.min(point);
  2726. this.max.max(point);
  2727. return this;
  2728. };
  2729. _proto.expandByVector = function expandByVector(vector) {
  2730. this.min.sub(vector);
  2731. this.max.add(vector);
  2732. return this;
  2733. };
  2734. _proto.expandByScalar = function expandByScalar(scalar) {
  2735. this.min.addScalar(-scalar);
  2736. this.max.addScalar(scalar);
  2737. return this;
  2738. };
  2739. _proto.expandByObject = function expandByObject(object) {
  2740. // Computes the world-axis-aligned bounding box of an object (including its children),
  2741. // accounting for both the object's, and children's, world transforms
  2742. object.updateWorldMatrix(false, false);
  2743. var geometry = object.geometry;
  2744. if (geometry !== undefined) {
  2745. if (geometry.boundingBox === null) {
  2746. geometry.computeBoundingBox();
  2747. }
  2748. _box.copy(geometry.boundingBox);
  2749. _box.applyMatrix4(object.matrixWorld);
  2750. this.union(_box);
  2751. }
  2752. var children = object.children;
  2753. for (var i = 0, l = children.length; i < l; i++) {
  2754. this.expandByObject(children[i]);
  2755. }
  2756. return this;
  2757. };
  2758. _proto.containsPoint = function containsPoint(point) {
  2759. 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;
  2760. };
  2761. _proto.containsBox = function containsBox(box) {
  2762. 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;
  2763. };
  2764. _proto.getParameter = function getParameter(point, target) {
  2765. // This can potentially have a divide by zero if the box
  2766. // has a size dimension of 0.
  2767. if (target === undefined) {
  2768. console.warn('THREE.Box3: .getParameter() target is now required');
  2769. target = new Vector3();
  2770. }
  2771. 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));
  2772. };
  2773. _proto.intersectsBox = function intersectsBox(box) {
  2774. // using 6 splitting planes to rule out intersections.
  2775. 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;
  2776. };
  2777. _proto.intersectsSphere = function intersectsSphere(sphere) {
  2778. // Find the point on the AABB closest to the sphere center.
  2779. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  2780. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  2781. };
  2782. _proto.intersectsPlane = function intersectsPlane(plane) {
  2783. // We compute the minimum and maximum dot product values. If those values
  2784. // are on the same side (back or front) of the plane, then there is no intersection.
  2785. var min, max;
  2786. if (plane.normal.x > 0) {
  2787. min = plane.normal.x * this.min.x;
  2788. max = plane.normal.x * this.max.x;
  2789. } else {
  2790. min = plane.normal.x * this.max.x;
  2791. max = plane.normal.x * this.min.x;
  2792. }
  2793. if (plane.normal.y > 0) {
  2794. min += plane.normal.y * this.min.y;
  2795. max += plane.normal.y * this.max.y;
  2796. } else {
  2797. min += plane.normal.y * this.max.y;
  2798. max += plane.normal.y * this.min.y;
  2799. }
  2800. if (plane.normal.z > 0) {
  2801. min += plane.normal.z * this.min.z;
  2802. max += plane.normal.z * this.max.z;
  2803. } else {
  2804. min += plane.normal.z * this.max.z;
  2805. max += plane.normal.z * this.min.z;
  2806. }
  2807. return min <= -plane.constant && max >= -plane.constant;
  2808. };
  2809. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  2810. if (this.isEmpty()) {
  2811. return false;
  2812. } // compute box center and extents
  2813. this.getCenter(_center);
  2814. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  2815. _v0.subVectors(triangle.a, _center);
  2816. _v1.subVectors(triangle.b, _center);
  2817. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  2818. _f0.subVectors(_v1, _v0);
  2819. _f1.subVectors(_v2, _v1);
  2820. _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
  2821. // 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
  2822. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  2823. 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];
  2824. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2825. return false;
  2826. } // test 3 face normals from the aabb
  2827. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  2828. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2829. return false;
  2830. } // finally testing the face normal of the triangle
  2831. // use already existing triangle edge vectors here
  2832. _triangleNormal.crossVectors(_f0, _f1);
  2833. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  2834. return satForAxes(axes, _v0, _v1, _v2, _extents);
  2835. };
  2836. _proto.clampPoint = function clampPoint(point, target) {
  2837. if (target === undefined) {
  2838. console.warn('THREE.Box3: .clampPoint() target is now required');
  2839. target = new Vector3();
  2840. }
  2841. return target.copy(point).clamp(this.min, this.max);
  2842. };
  2843. _proto.distanceToPoint = function distanceToPoint(point) {
  2844. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  2845. return clampedPoint.sub(point).length();
  2846. };
  2847. _proto.getBoundingSphere = function getBoundingSphere(target) {
  2848. if (target === undefined) {
  2849. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  2850. }
  2851. this.getCenter(target.center);
  2852. target.radius = this.getSize(_vector$1).length() * 0.5;
  2853. return target;
  2854. };
  2855. _proto.intersect = function intersect(box) {
  2856. this.min.max(box.min);
  2857. 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.
  2858. if (this.isEmpty()) this.makeEmpty();
  2859. return this;
  2860. };
  2861. _proto.union = function union(box) {
  2862. this.min.min(box.min);
  2863. this.max.max(box.max);
  2864. return this;
  2865. };
  2866. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  2867. // transform of empty box is an empty box.
  2868. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2869. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  2870. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  2871. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  2872. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  2873. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  2874. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  2875. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  2876. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  2877. this.setFromPoints(_points);
  2878. return this;
  2879. };
  2880. _proto.translate = function translate(offset) {
  2881. this.min.add(offset);
  2882. this.max.add(offset);
  2883. return this;
  2884. };
  2885. _proto.equals = function equals(box) {
  2886. return box.min.equals(this.min) && box.max.equals(this.max);
  2887. };
  2888. return Box3;
  2889. }();
  2890. function satForAxes(axes, v0, v1, v2, extents) {
  2891. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  2892. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  2893. 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
  2894. var p0 = v0.dot(_testAxis);
  2895. var p1 = v1.dot(_testAxis);
  2896. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  2897. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  2898. // points of the projected triangle are outside the projected half-length of the aabb
  2899. // the axis is seperating and we can exit
  2900. return false;
  2901. }
  2902. }
  2903. return true;
  2904. }
  2905. 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()];
  2906. var _vector$1 = /*@__PURE__*/new Vector3();
  2907. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  2908. var _v0 = /*@__PURE__*/new Vector3();
  2909. var _v1 = /*@__PURE__*/new Vector3();
  2910. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  2911. var _f0 = /*@__PURE__*/new Vector3();
  2912. var _f1 = /*@__PURE__*/new Vector3();
  2913. var _f2 = /*@__PURE__*/new Vector3();
  2914. var _center = /*@__PURE__*/new Vector3();
  2915. var _extents = /*@__PURE__*/new Vector3();
  2916. var _triangleNormal = /*@__PURE__*/new Vector3();
  2917. var _testAxis = /*@__PURE__*/new Vector3();
  2918. var _box$1 = /*@__PURE__*/new Box3();
  2919. var Sphere = /*#__PURE__*/function () {
  2920. function Sphere(center, radius) {
  2921. this.center = center !== undefined ? center : new Vector3();
  2922. this.radius = radius !== undefined ? radius : -1;
  2923. }
  2924. var _proto = Sphere.prototype;
  2925. _proto.set = function set(center, radius) {
  2926. this.center.copy(center);
  2927. this.radius = radius;
  2928. return this;
  2929. };
  2930. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  2931. var center = this.center;
  2932. if (optionalCenter !== undefined) {
  2933. center.copy(optionalCenter);
  2934. } else {
  2935. _box$1.setFromPoints(points).getCenter(center);
  2936. }
  2937. var maxRadiusSq = 0;
  2938. for (var i = 0, il = points.length; i < il; i++) {
  2939. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  2940. }
  2941. this.radius = Math.sqrt(maxRadiusSq);
  2942. return this;
  2943. };
  2944. _proto.clone = function clone() {
  2945. return new this.constructor().copy(this);
  2946. };
  2947. _proto.copy = function copy(sphere) {
  2948. this.center.copy(sphere.center);
  2949. this.radius = sphere.radius;
  2950. return this;
  2951. };
  2952. _proto.isEmpty = function isEmpty() {
  2953. return this.radius < 0;
  2954. };
  2955. _proto.makeEmpty = function makeEmpty() {
  2956. this.center.set(0, 0, 0);
  2957. this.radius = -1;
  2958. return this;
  2959. };
  2960. _proto.containsPoint = function containsPoint(point) {
  2961. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  2962. };
  2963. _proto.distanceToPoint = function distanceToPoint(point) {
  2964. return point.distanceTo(this.center) - this.radius;
  2965. };
  2966. _proto.intersectsSphere = function intersectsSphere(sphere) {
  2967. var radiusSum = this.radius + sphere.radius;
  2968. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  2969. };
  2970. _proto.intersectsBox = function intersectsBox(box) {
  2971. return box.intersectsSphere(this);
  2972. };
  2973. _proto.intersectsPlane = function intersectsPlane(plane) {
  2974. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  2975. };
  2976. _proto.clampPoint = function clampPoint(point, target) {
  2977. var deltaLengthSq = this.center.distanceToSquared(point);
  2978. if (target === undefined) {
  2979. console.warn('THREE.Sphere: .clampPoint() target is now required');
  2980. target = new Vector3();
  2981. }
  2982. target.copy(point);
  2983. if (deltaLengthSq > this.radius * this.radius) {
  2984. target.sub(this.center).normalize();
  2985. target.multiplyScalar(this.radius).add(this.center);
  2986. }
  2987. return target;
  2988. };
  2989. _proto.getBoundingBox = function getBoundingBox(target) {
  2990. if (target === undefined) {
  2991. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  2992. target = new Box3();
  2993. }
  2994. if (this.isEmpty()) {
  2995. // Empty sphere produces empty bounding box
  2996. target.makeEmpty();
  2997. return target;
  2998. }
  2999. target.set(this.center, this.center);
  3000. target.expandByScalar(this.radius);
  3001. return target;
  3002. };
  3003. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3004. this.center.applyMatrix4(matrix);
  3005. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3006. return this;
  3007. };
  3008. _proto.translate = function translate(offset) {
  3009. this.center.add(offset);
  3010. return this;
  3011. };
  3012. _proto.equals = function equals(sphere) {
  3013. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3014. };
  3015. return Sphere;
  3016. }();
  3017. var _vector$2 = /*@__PURE__*/new Vector3();
  3018. var _segCenter = /*@__PURE__*/new Vector3();
  3019. var _segDir = /*@__PURE__*/new Vector3();
  3020. var _diff = /*@__PURE__*/new Vector3();
  3021. var _edge1 = /*@__PURE__*/new Vector3();
  3022. var _edge2 = /*@__PURE__*/new Vector3();
  3023. var _normal = /*@__PURE__*/new Vector3();
  3024. var Ray = /*#__PURE__*/function () {
  3025. function Ray(origin, direction) {
  3026. this.origin = origin !== undefined ? origin : new Vector3();
  3027. this.direction = direction !== undefined ? direction : new Vector3(0, 0, -1);
  3028. }
  3029. var _proto = Ray.prototype;
  3030. _proto.set = function set(origin, direction) {
  3031. this.origin.copy(origin);
  3032. this.direction.copy(direction);
  3033. return this;
  3034. };
  3035. _proto.clone = function clone() {
  3036. return new this.constructor().copy(this);
  3037. };
  3038. _proto.copy = function copy(ray) {
  3039. this.origin.copy(ray.origin);
  3040. this.direction.copy(ray.direction);
  3041. return this;
  3042. };
  3043. _proto.at = function at(t, target) {
  3044. if (target === undefined) {
  3045. console.warn('THREE.Ray: .at() target is now required');
  3046. target = new Vector3();
  3047. }
  3048. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3049. };
  3050. _proto.lookAt = function lookAt(v) {
  3051. this.direction.copy(v).sub(this.origin).normalize();
  3052. return this;
  3053. };
  3054. _proto.recast = function recast(t) {
  3055. this.origin.copy(this.at(t, _vector$2));
  3056. return this;
  3057. };
  3058. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3059. if (target === undefined) {
  3060. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3061. target = new Vector3();
  3062. }
  3063. target.subVectors(point, this.origin);
  3064. var directionDistance = target.dot(this.direction);
  3065. if (directionDistance < 0) {
  3066. return target.copy(this.origin);
  3067. }
  3068. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3069. };
  3070. _proto.distanceToPoint = function distanceToPoint(point) {
  3071. return Math.sqrt(this.distanceSqToPoint(point));
  3072. };
  3073. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3074. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3075. if (directionDistance < 0) {
  3076. return this.origin.distanceToSquared(point);
  3077. }
  3078. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3079. return _vector$2.distanceToSquared(point);
  3080. };
  3081. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3082. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3083. // It returns the min distance between the ray and the segment
  3084. // defined by v0 and v1
  3085. // It can also set two optional targets :
  3086. // - The closest point on the ray
  3087. // - The closest point on the segment
  3088. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3089. _segDir.copy(v1).sub(v0).normalize();
  3090. _diff.copy(this.origin).sub(_segCenter);
  3091. var segExtent = v0.distanceTo(v1) * 0.5;
  3092. var a01 = -this.direction.dot(_segDir);
  3093. var b0 = _diff.dot(this.direction);
  3094. var b1 = -_diff.dot(_segDir);
  3095. var c = _diff.lengthSq();
  3096. var det = Math.abs(1 - a01 * a01);
  3097. var s0, s1, sqrDist, extDet;
  3098. if (det > 0) {
  3099. // The ray and segment are not parallel.
  3100. s0 = a01 * b1 - b0;
  3101. s1 = a01 * b0 - b1;
  3102. extDet = segExtent * det;
  3103. if (s0 >= 0) {
  3104. if (s1 >= -extDet) {
  3105. if (s1 <= extDet) {
  3106. // region 0
  3107. // Minimum at interior points of ray and segment.
  3108. var invDet = 1 / det;
  3109. s0 *= invDet;
  3110. s1 *= invDet;
  3111. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3112. } else {
  3113. // region 1
  3114. s1 = segExtent;
  3115. s0 = Math.max(0, -(a01 * s1 + b0));
  3116. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3117. }
  3118. } else {
  3119. // region 5
  3120. s1 = -segExtent;
  3121. s0 = Math.max(0, -(a01 * s1 + b0));
  3122. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3123. }
  3124. } else {
  3125. if (s1 <= -extDet) {
  3126. // region 4
  3127. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3128. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3129. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3130. } else if (s1 <= extDet) {
  3131. // region 3
  3132. s0 = 0;
  3133. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3134. sqrDist = s1 * (s1 + 2 * b1) + c;
  3135. } else {
  3136. // region 2
  3137. s0 = Math.max(0, -(a01 * segExtent + b0));
  3138. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3139. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3140. }
  3141. }
  3142. } else {
  3143. // Ray and segment are parallel.
  3144. s1 = a01 > 0 ? -segExtent : segExtent;
  3145. s0 = Math.max(0, -(a01 * s1 + b0));
  3146. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3147. }
  3148. if (optionalPointOnRay) {
  3149. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3150. }
  3151. if (optionalPointOnSegment) {
  3152. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3153. }
  3154. return sqrDist;
  3155. };
  3156. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3157. _vector$2.subVectors(sphere.center, this.origin);
  3158. var tca = _vector$2.dot(this.direction);
  3159. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3160. var radius2 = sphere.radius * sphere.radius;
  3161. if (d2 > radius2) return null;
  3162. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3163. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3164. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3165. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3166. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3167. // in order to always return an intersect point that is in front of the ray.
  3168. 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
  3169. return this.at(t0, target);
  3170. };
  3171. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3172. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3173. };
  3174. _proto.distanceToPlane = function distanceToPlane(plane) {
  3175. var denominator = plane.normal.dot(this.direction);
  3176. if (denominator === 0) {
  3177. // line is coplanar, return origin
  3178. if (plane.distanceToPoint(this.origin) === 0) {
  3179. return 0;
  3180. } // Null is preferable to undefined since undefined means.... it is undefined
  3181. return null;
  3182. }
  3183. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3184. return t >= 0 ? t : null;
  3185. };
  3186. _proto.intersectPlane = function intersectPlane(plane, target) {
  3187. var t = this.distanceToPlane(plane);
  3188. if (t === null) {
  3189. return null;
  3190. }
  3191. return this.at(t, target);
  3192. };
  3193. _proto.intersectsPlane = function intersectsPlane(plane) {
  3194. // check if the ray lies on the plane first
  3195. var distToPoint = plane.distanceToPoint(this.origin);
  3196. if (distToPoint === 0) {
  3197. return true;
  3198. }
  3199. var denominator = plane.normal.dot(this.direction);
  3200. if (denominator * distToPoint < 0) {
  3201. return true;
  3202. } // ray origin is behind the plane (and is pointing behind it)
  3203. return false;
  3204. };
  3205. _proto.intersectBox = function intersectBox(box, target) {
  3206. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3207. var invdirx = 1 / this.direction.x,
  3208. invdiry = 1 / this.direction.y,
  3209. invdirz = 1 / this.direction.z;
  3210. var origin = this.origin;
  3211. if (invdirx >= 0) {
  3212. tmin = (box.min.x - origin.x) * invdirx;
  3213. tmax = (box.max.x - origin.x) * invdirx;
  3214. } else {
  3215. tmin = (box.max.x - origin.x) * invdirx;
  3216. tmax = (box.min.x - origin.x) * invdirx;
  3217. }
  3218. if (invdiry >= 0) {
  3219. tymin = (box.min.y - origin.y) * invdiry;
  3220. tymax = (box.max.y - origin.y) * invdiry;
  3221. } else {
  3222. tymin = (box.max.y - origin.y) * invdiry;
  3223. tymax = (box.min.y - origin.y) * invdiry;
  3224. }
  3225. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  3226. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3227. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  3228. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  3229. if (invdirz >= 0) {
  3230. tzmin = (box.min.z - origin.z) * invdirz;
  3231. tzmax = (box.max.z - origin.z) * invdirz;
  3232. } else {
  3233. tzmin = (box.max.z - origin.z) * invdirz;
  3234. tzmax = (box.min.z - origin.z) * invdirz;
  3235. }
  3236. if (tmin > tzmax || tzmin > tmax) return null;
  3237. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  3238. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  3239. if (tmax < 0) return null;
  3240. return this.at(tmin >= 0 ? tmin : tmax, target);
  3241. };
  3242. _proto.intersectsBox = function intersectsBox(box) {
  3243. return this.intersectBox(box, _vector$2) !== null;
  3244. };
  3245. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  3246. // Compute the offset origin, edges, and normal.
  3247. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3248. _edge1.subVectors(b, a);
  3249. _edge2.subVectors(c, a);
  3250. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3251. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3252. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3253. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3254. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3255. var DdN = this.direction.dot(_normal);
  3256. var sign;
  3257. if (DdN > 0) {
  3258. if (backfaceCulling) return null;
  3259. sign = 1;
  3260. } else if (DdN < 0) {
  3261. sign = -1;
  3262. DdN = -DdN;
  3263. } else {
  3264. return null;
  3265. }
  3266. _diff.subVectors(this.origin, a);
  3267. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  3268. if (DdQxE2 < 0) {
  3269. return null;
  3270. }
  3271. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  3272. if (DdE1xQ < 0) {
  3273. return null;
  3274. } // b1+b2 > 1, no intersection
  3275. if (DdQxE2 + DdE1xQ > DdN) {
  3276. return null;
  3277. } // Line intersects triangle, check if ray does.
  3278. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  3279. if (QdN < 0) {
  3280. return null;
  3281. } // Ray intersects triangle.
  3282. return this.at(QdN / DdN, target);
  3283. };
  3284. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  3285. this.origin.applyMatrix4(matrix4);
  3286. this.direction.transformDirection(matrix4);
  3287. return this;
  3288. };
  3289. _proto.equals = function equals(ray) {
  3290. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  3291. };
  3292. return Ray;
  3293. }();
  3294. var Matrix4 = /*#__PURE__*/function () {
  3295. function Matrix4() {
  3296. Object.defineProperty(this, 'isMatrix4', {
  3297. value: true
  3298. });
  3299. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  3300. if (arguments.length > 0) {
  3301. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  3302. }
  3303. }
  3304. var _proto = Matrix4.prototype;
  3305. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  3306. var te = this.elements;
  3307. te[0] = n11;
  3308. te[4] = n12;
  3309. te[8] = n13;
  3310. te[12] = n14;
  3311. te[1] = n21;
  3312. te[5] = n22;
  3313. te[9] = n23;
  3314. te[13] = n24;
  3315. te[2] = n31;
  3316. te[6] = n32;
  3317. te[10] = n33;
  3318. te[14] = n34;
  3319. te[3] = n41;
  3320. te[7] = n42;
  3321. te[11] = n43;
  3322. te[15] = n44;
  3323. return this;
  3324. };
  3325. _proto.identity = function identity() {
  3326. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3327. return this;
  3328. };
  3329. _proto.clone = function clone() {
  3330. return new Matrix4().fromArray(this.elements);
  3331. };
  3332. _proto.copy = function copy(m) {
  3333. var te = this.elements;
  3334. var me = m.elements;
  3335. te[0] = me[0];
  3336. te[1] = me[1];
  3337. te[2] = me[2];
  3338. te[3] = me[3];
  3339. te[4] = me[4];
  3340. te[5] = me[5];
  3341. te[6] = me[6];
  3342. te[7] = me[7];
  3343. te[8] = me[8];
  3344. te[9] = me[9];
  3345. te[10] = me[10];
  3346. te[11] = me[11];
  3347. te[12] = me[12];
  3348. te[13] = me[13];
  3349. te[14] = me[14];
  3350. te[15] = me[15];
  3351. return this;
  3352. };
  3353. _proto.copyPosition = function copyPosition(m) {
  3354. var te = this.elements,
  3355. me = m.elements;
  3356. te[12] = me[12];
  3357. te[13] = me[13];
  3358. te[14] = me[14];
  3359. return this;
  3360. };
  3361. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  3362. xAxis.setFromMatrixColumn(this, 0);
  3363. yAxis.setFromMatrixColumn(this, 1);
  3364. zAxis.setFromMatrixColumn(this, 2);
  3365. return this;
  3366. };
  3367. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  3368. 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);
  3369. return this;
  3370. };
  3371. _proto.extractRotation = function extractRotation(m) {
  3372. // this method does not support reflection matrices
  3373. var te = this.elements;
  3374. var me = m.elements;
  3375. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  3376. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  3377. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  3378. te[0] = me[0] * scaleX;
  3379. te[1] = me[1] * scaleX;
  3380. te[2] = me[2] * scaleX;
  3381. te[3] = 0;
  3382. te[4] = me[4] * scaleY;
  3383. te[5] = me[5] * scaleY;
  3384. te[6] = me[6] * scaleY;
  3385. te[7] = 0;
  3386. te[8] = me[8] * scaleZ;
  3387. te[9] = me[9] * scaleZ;
  3388. te[10] = me[10] * scaleZ;
  3389. te[11] = 0;
  3390. te[12] = 0;
  3391. te[13] = 0;
  3392. te[14] = 0;
  3393. te[15] = 1;
  3394. return this;
  3395. };
  3396. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  3397. if (!(euler && euler.isEuler)) {
  3398. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  3399. }
  3400. var te = this.elements;
  3401. var x = euler.x,
  3402. y = euler.y,
  3403. z = euler.z;
  3404. var a = Math.cos(x),
  3405. b = Math.sin(x);
  3406. var c = Math.cos(y),
  3407. d = Math.sin(y);
  3408. var e = Math.cos(z),
  3409. f = Math.sin(z);
  3410. if (euler.order === 'XYZ') {
  3411. var ae = a * e,
  3412. af = a * f,
  3413. be = b * e,
  3414. bf = b * f;
  3415. te[0] = c * e;
  3416. te[4] = -c * f;
  3417. te[8] = d;
  3418. te[1] = af + be * d;
  3419. te[5] = ae - bf * d;
  3420. te[9] = -b * c;
  3421. te[2] = bf - ae * d;
  3422. te[6] = be + af * d;
  3423. te[10] = a * c;
  3424. } else if (euler.order === 'YXZ') {
  3425. var ce = c * e,
  3426. cf = c * f,
  3427. de = d * e,
  3428. df = d * f;
  3429. te[0] = ce + df * b;
  3430. te[4] = de * b - cf;
  3431. te[8] = a * d;
  3432. te[1] = a * f;
  3433. te[5] = a * e;
  3434. te[9] = -b;
  3435. te[2] = cf * b - de;
  3436. te[6] = df + ce * b;
  3437. te[10] = a * c;
  3438. } else if (euler.order === 'ZXY') {
  3439. var _ce = c * e,
  3440. _cf = c * f,
  3441. _de = d * e,
  3442. _df = d * f;
  3443. te[0] = _ce - _df * b;
  3444. te[4] = -a * f;
  3445. te[8] = _de + _cf * b;
  3446. te[1] = _cf + _de * b;
  3447. te[5] = a * e;
  3448. te[9] = _df - _ce * b;
  3449. te[2] = -a * d;
  3450. te[6] = b;
  3451. te[10] = a * c;
  3452. } else if (euler.order === 'ZYX') {
  3453. var _ae = a * e,
  3454. _af = a * f,
  3455. _be = b * e,
  3456. _bf = b * f;
  3457. te[0] = c * e;
  3458. te[4] = _be * d - _af;
  3459. te[8] = _ae * d + _bf;
  3460. te[1] = c * f;
  3461. te[5] = _bf * d + _ae;
  3462. te[9] = _af * d - _be;
  3463. te[2] = -d;
  3464. te[6] = b * c;
  3465. te[10] = a * c;
  3466. } else if (euler.order === 'YZX') {
  3467. var ac = a * c,
  3468. ad = a * d,
  3469. bc = b * c,
  3470. bd = b * d;
  3471. te[0] = c * e;
  3472. te[4] = bd - ac * f;
  3473. te[8] = bc * f + ad;
  3474. te[1] = f;
  3475. te[5] = a * e;
  3476. te[9] = -b * e;
  3477. te[2] = -d * e;
  3478. te[6] = ad * f + bc;
  3479. te[10] = ac - bd * f;
  3480. } else if (euler.order === 'XZY') {
  3481. var _ac = a * c,
  3482. _ad = a * d,
  3483. _bc = b * c,
  3484. _bd = b * d;
  3485. te[0] = c * e;
  3486. te[4] = -f;
  3487. te[8] = d * e;
  3488. te[1] = _ac * f + _bd;
  3489. te[5] = a * e;
  3490. te[9] = _ad * f - _bc;
  3491. te[2] = _bc * f - _ad;
  3492. te[6] = b * e;
  3493. te[10] = _bd * f + _ac;
  3494. } // bottom row
  3495. te[3] = 0;
  3496. te[7] = 0;
  3497. te[11] = 0; // last column
  3498. te[12] = 0;
  3499. te[13] = 0;
  3500. te[14] = 0;
  3501. te[15] = 1;
  3502. return this;
  3503. };
  3504. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  3505. return this.compose(_zero, q, _one);
  3506. };
  3507. _proto.lookAt = function lookAt(eye, target, up) {
  3508. var te = this.elements;
  3509. _z.subVectors(eye, target);
  3510. if (_z.lengthSq() === 0) {
  3511. // eye and target are in the same position
  3512. _z.z = 1;
  3513. }
  3514. _z.normalize();
  3515. _x.crossVectors(up, _z);
  3516. if (_x.lengthSq() === 0) {
  3517. // up and z are parallel
  3518. if (Math.abs(up.z) === 1) {
  3519. _z.x += 0.0001;
  3520. } else {
  3521. _z.z += 0.0001;
  3522. }
  3523. _z.normalize();
  3524. _x.crossVectors(up, _z);
  3525. }
  3526. _x.normalize();
  3527. _y.crossVectors(_z, _x);
  3528. te[0] = _x.x;
  3529. te[4] = _y.x;
  3530. te[8] = _z.x;
  3531. te[1] = _x.y;
  3532. te[5] = _y.y;
  3533. te[9] = _z.y;
  3534. te[2] = _x.z;
  3535. te[6] = _y.z;
  3536. te[10] = _z.z;
  3537. return this;
  3538. };
  3539. _proto.multiply = function multiply(m, n) {
  3540. if (n !== undefined) {
  3541. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  3542. return this.multiplyMatrices(m, n);
  3543. }
  3544. return this.multiplyMatrices(this, m);
  3545. };
  3546. _proto.premultiply = function premultiply(m) {
  3547. return this.multiplyMatrices(m, this);
  3548. };
  3549. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  3550. var ae = a.elements;
  3551. var be = b.elements;
  3552. var te = this.elements;
  3553. var a11 = ae[0],
  3554. a12 = ae[4],
  3555. a13 = ae[8],
  3556. a14 = ae[12];
  3557. var a21 = ae[1],
  3558. a22 = ae[5],
  3559. a23 = ae[9],
  3560. a24 = ae[13];
  3561. var a31 = ae[2],
  3562. a32 = ae[6],
  3563. a33 = ae[10],
  3564. a34 = ae[14];
  3565. var a41 = ae[3],
  3566. a42 = ae[7],
  3567. a43 = ae[11],
  3568. a44 = ae[15];
  3569. var b11 = be[0],
  3570. b12 = be[4],
  3571. b13 = be[8],
  3572. b14 = be[12];
  3573. var b21 = be[1],
  3574. b22 = be[5],
  3575. b23 = be[9],
  3576. b24 = be[13];
  3577. var b31 = be[2],
  3578. b32 = be[6],
  3579. b33 = be[10],
  3580. b34 = be[14];
  3581. var b41 = be[3],
  3582. b42 = be[7],
  3583. b43 = be[11],
  3584. b44 = be[15];
  3585. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3586. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3587. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3588. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3589. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3590. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3591. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3592. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3593. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3594. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3595. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3596. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3597. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3598. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3599. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3600. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3601. return this;
  3602. };
  3603. _proto.multiplyScalar = function multiplyScalar(s) {
  3604. var te = this.elements;
  3605. te[0] *= s;
  3606. te[4] *= s;
  3607. te[8] *= s;
  3608. te[12] *= s;
  3609. te[1] *= s;
  3610. te[5] *= s;
  3611. te[9] *= s;
  3612. te[13] *= s;
  3613. te[2] *= s;
  3614. te[6] *= s;
  3615. te[10] *= s;
  3616. te[14] *= s;
  3617. te[3] *= s;
  3618. te[7] *= s;
  3619. te[11] *= s;
  3620. te[15] *= s;
  3621. return this;
  3622. };
  3623. _proto.determinant = function determinant() {
  3624. var te = this.elements;
  3625. var n11 = te[0],
  3626. n12 = te[4],
  3627. n13 = te[8],
  3628. n14 = te[12];
  3629. var n21 = te[1],
  3630. n22 = te[5],
  3631. n23 = te[9],
  3632. n24 = te[13];
  3633. var n31 = te[2],
  3634. n32 = te[6],
  3635. n33 = te[10],
  3636. n34 = te[14];
  3637. var n41 = te[3],
  3638. n42 = te[7],
  3639. n43 = te[11],
  3640. n44 = te[15]; //TODO: make this more efficient
  3641. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3642. 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);
  3643. };
  3644. _proto.transpose = function transpose() {
  3645. var te = this.elements;
  3646. var tmp;
  3647. tmp = te[1];
  3648. te[1] = te[4];
  3649. te[4] = tmp;
  3650. tmp = te[2];
  3651. te[2] = te[8];
  3652. te[8] = tmp;
  3653. tmp = te[6];
  3654. te[6] = te[9];
  3655. te[9] = tmp;
  3656. tmp = te[3];
  3657. te[3] = te[12];
  3658. te[12] = tmp;
  3659. tmp = te[7];
  3660. te[7] = te[13];
  3661. te[13] = tmp;
  3662. tmp = te[11];
  3663. te[11] = te[14];
  3664. te[14] = tmp;
  3665. return this;
  3666. };
  3667. _proto.setPosition = function setPosition(x, y, z) {
  3668. var te = this.elements;
  3669. if (x.isVector3) {
  3670. te[12] = x.x;
  3671. te[13] = x.y;
  3672. te[14] = x.z;
  3673. } else {
  3674. te[12] = x;
  3675. te[13] = y;
  3676. te[14] = z;
  3677. }
  3678. return this;
  3679. };
  3680. _proto.getInverse = function getInverse(m, throwOnDegenerate) {
  3681. if (throwOnDegenerate !== undefined) {
  3682. console.warn("THREE.Matrix4: .getInverse() can no longer be configured to throw on degenerate.");
  3683. } // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3684. var te = this.elements,
  3685. me = m.elements,
  3686. n11 = me[0],
  3687. n21 = me[1],
  3688. n31 = me[2],
  3689. n41 = me[3],
  3690. n12 = me[4],
  3691. n22 = me[5],
  3692. n32 = me[6],
  3693. n42 = me[7],
  3694. n13 = me[8],
  3695. n23 = me[9],
  3696. n33 = me[10],
  3697. n43 = me[11],
  3698. n14 = me[12],
  3699. n24 = me[13],
  3700. n34 = me[14],
  3701. n44 = me[15],
  3702. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3703. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3704. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3705. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3706. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3707. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  3708. var detInv = 1 / det;
  3709. te[0] = t11 * detInv;
  3710. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  3711. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  3712. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  3713. te[4] = t12 * detInv;
  3714. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  3715. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  3716. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  3717. te[8] = t13 * detInv;
  3718. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  3719. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  3720. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  3721. te[12] = t14 * detInv;
  3722. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  3723. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  3724. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  3725. return this;
  3726. };
  3727. _proto.scale = function scale(v) {
  3728. var te = this.elements;
  3729. var x = v.x,
  3730. y = v.y,
  3731. z = v.z;
  3732. te[0] *= x;
  3733. te[4] *= y;
  3734. te[8] *= z;
  3735. te[1] *= x;
  3736. te[5] *= y;
  3737. te[9] *= z;
  3738. te[2] *= x;
  3739. te[6] *= y;
  3740. te[10] *= z;
  3741. te[3] *= x;
  3742. te[7] *= y;
  3743. te[11] *= z;
  3744. return this;
  3745. };
  3746. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  3747. var te = this.elements;
  3748. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  3749. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  3750. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  3751. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  3752. };
  3753. _proto.makeTranslation = function makeTranslation(x, y, z) {
  3754. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  3755. return this;
  3756. };
  3757. _proto.makeRotationX = function makeRotationX(theta) {
  3758. var c = Math.cos(theta),
  3759. s = Math.sin(theta);
  3760. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  3761. return this;
  3762. };
  3763. _proto.makeRotationY = function makeRotationY(theta) {
  3764. var c = Math.cos(theta),
  3765. s = Math.sin(theta);
  3766. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  3767. return this;
  3768. };
  3769. _proto.makeRotationZ = function makeRotationZ(theta) {
  3770. var c = Math.cos(theta),
  3771. s = Math.sin(theta);
  3772. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3773. return this;
  3774. };
  3775. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  3776. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3777. var c = Math.cos(angle);
  3778. var s = Math.sin(angle);
  3779. var t = 1 - c;
  3780. var x = axis.x,
  3781. y = axis.y,
  3782. z = axis.z;
  3783. var tx = t * x,
  3784. ty = t * y;
  3785. 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);
  3786. return this;
  3787. };
  3788. _proto.makeScale = function makeScale(x, y, z) {
  3789. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  3790. return this;
  3791. };
  3792. _proto.makeShear = function makeShear(x, y, z) {
  3793. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  3794. return this;
  3795. };
  3796. _proto.compose = function compose(position, quaternion, scale) {
  3797. var te = this.elements;
  3798. var x = quaternion._x,
  3799. y = quaternion._y,
  3800. z = quaternion._z,
  3801. w = quaternion._w;
  3802. var x2 = x + x,
  3803. y2 = y + y,
  3804. z2 = z + z;
  3805. var xx = x * x2,
  3806. xy = x * y2,
  3807. xz = x * z2;
  3808. var yy = y * y2,
  3809. yz = y * z2,
  3810. zz = z * z2;
  3811. var wx = w * x2,
  3812. wy = w * y2,
  3813. wz = w * z2;
  3814. var sx = scale.x,
  3815. sy = scale.y,
  3816. sz = scale.z;
  3817. te[0] = (1 - (yy + zz)) * sx;
  3818. te[1] = (xy + wz) * sx;
  3819. te[2] = (xz - wy) * sx;
  3820. te[3] = 0;
  3821. te[4] = (xy - wz) * sy;
  3822. te[5] = (1 - (xx + zz)) * sy;
  3823. te[6] = (yz + wx) * sy;
  3824. te[7] = 0;
  3825. te[8] = (xz + wy) * sz;
  3826. te[9] = (yz - wx) * sz;
  3827. te[10] = (1 - (xx + yy)) * sz;
  3828. te[11] = 0;
  3829. te[12] = position.x;
  3830. te[13] = position.y;
  3831. te[14] = position.z;
  3832. te[15] = 1;
  3833. return this;
  3834. };
  3835. _proto.decompose = function decompose(position, quaternion, scale) {
  3836. var te = this.elements;
  3837. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  3838. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  3839. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  3840. var det = this.determinant();
  3841. if (det < 0) sx = -sx;
  3842. position.x = te[12];
  3843. position.y = te[13];
  3844. position.z = te[14]; // scale the rotation part
  3845. _m1.copy(this);
  3846. var invSX = 1 / sx;
  3847. var invSY = 1 / sy;
  3848. var invSZ = 1 / sz;
  3849. _m1.elements[0] *= invSX;
  3850. _m1.elements[1] *= invSX;
  3851. _m1.elements[2] *= invSX;
  3852. _m1.elements[4] *= invSY;
  3853. _m1.elements[5] *= invSY;
  3854. _m1.elements[6] *= invSY;
  3855. _m1.elements[8] *= invSZ;
  3856. _m1.elements[9] *= invSZ;
  3857. _m1.elements[10] *= invSZ;
  3858. quaternion.setFromRotationMatrix(_m1);
  3859. scale.x = sx;
  3860. scale.y = sy;
  3861. scale.z = sz;
  3862. return this;
  3863. };
  3864. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  3865. if (far === undefined) {
  3866. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  3867. }
  3868. var te = this.elements;
  3869. var x = 2 * near / (right - left);
  3870. var y = 2 * near / (top - bottom);
  3871. var a = (right + left) / (right - left);
  3872. var b = (top + bottom) / (top - bottom);
  3873. var c = -(far + near) / (far - near);
  3874. var d = -2 * far * near / (far - near);
  3875. te[0] = x;
  3876. te[4] = 0;
  3877. te[8] = a;
  3878. te[12] = 0;
  3879. te[1] = 0;
  3880. te[5] = y;
  3881. te[9] = b;
  3882. te[13] = 0;
  3883. te[2] = 0;
  3884. te[6] = 0;
  3885. te[10] = c;
  3886. te[14] = d;
  3887. te[3] = 0;
  3888. te[7] = 0;
  3889. te[11] = -1;
  3890. te[15] = 0;
  3891. return this;
  3892. };
  3893. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  3894. var te = this.elements;
  3895. var w = 1.0 / (right - left);
  3896. var h = 1.0 / (top - bottom);
  3897. var p = 1.0 / (far - near);
  3898. var x = (right + left) * w;
  3899. var y = (top + bottom) * h;
  3900. var z = (far + near) * p;
  3901. te[0] = 2 * w;
  3902. te[4] = 0;
  3903. te[8] = 0;
  3904. te[12] = -x;
  3905. te[1] = 0;
  3906. te[5] = 2 * h;
  3907. te[9] = 0;
  3908. te[13] = -y;
  3909. te[2] = 0;
  3910. te[6] = 0;
  3911. te[10] = -2 * p;
  3912. te[14] = -z;
  3913. te[3] = 0;
  3914. te[7] = 0;
  3915. te[11] = 0;
  3916. te[15] = 1;
  3917. return this;
  3918. };
  3919. _proto.equals = function equals(matrix) {
  3920. var te = this.elements;
  3921. var me = matrix.elements;
  3922. for (var i = 0; i < 16; i++) {
  3923. if (te[i] !== me[i]) return false;
  3924. }
  3925. return true;
  3926. };
  3927. _proto.fromArray = function fromArray(array, offset) {
  3928. if (offset === void 0) {
  3929. offset = 0;
  3930. }
  3931. for (var i = 0; i < 16; i++) {
  3932. this.elements[i] = array[i + offset];
  3933. }
  3934. return this;
  3935. };
  3936. _proto.toArray = function toArray(array, offset) {
  3937. if (array === void 0) {
  3938. array = [];
  3939. }
  3940. if (offset === void 0) {
  3941. offset = 0;
  3942. }
  3943. var te = this.elements;
  3944. array[offset] = te[0];
  3945. array[offset + 1] = te[1];
  3946. array[offset + 2] = te[2];
  3947. array[offset + 3] = te[3];
  3948. array[offset + 4] = te[4];
  3949. array[offset + 5] = te[5];
  3950. array[offset + 6] = te[6];
  3951. array[offset + 7] = te[7];
  3952. array[offset + 8] = te[8];
  3953. array[offset + 9] = te[9];
  3954. array[offset + 10] = te[10];
  3955. array[offset + 11] = te[11];
  3956. array[offset + 12] = te[12];
  3957. array[offset + 13] = te[13];
  3958. array[offset + 14] = te[14];
  3959. array[offset + 15] = te[15];
  3960. return array;
  3961. };
  3962. return Matrix4;
  3963. }();
  3964. var _v1$1 = /*@__PURE__*/new Vector3();
  3965. var _m1 = /*@__PURE__*/new Matrix4();
  3966. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  3967. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  3968. var _x = /*@__PURE__*/new Vector3();
  3969. var _y = /*@__PURE__*/new Vector3();
  3970. var _z = /*@__PURE__*/new Vector3();
  3971. var Euler = /*#__PURE__*/function () {
  3972. function Euler(x, y, z, order) {
  3973. if (x === void 0) {
  3974. x = 0;
  3975. }
  3976. if (y === void 0) {
  3977. y = 0;
  3978. }
  3979. if (z === void 0) {
  3980. z = 0;
  3981. }
  3982. if (order === void 0) {
  3983. order = Euler.DefaultOrder;
  3984. }
  3985. Object.defineProperty(this, 'isEuler', {
  3986. value: true
  3987. });
  3988. this._x = x;
  3989. this._y = y;
  3990. this._z = z;
  3991. this._order = order;
  3992. }
  3993. var _proto = Euler.prototype;
  3994. _proto.set = function set(x, y, z, order) {
  3995. this._x = x;
  3996. this._y = y;
  3997. this._z = z;
  3998. this._order = order || this._order;
  3999. this._onChangeCallback();
  4000. return this;
  4001. };
  4002. _proto.clone = function clone() {
  4003. return new this.constructor(this._x, this._y, this._z, this._order);
  4004. };
  4005. _proto.copy = function copy(euler) {
  4006. this._x = euler._x;
  4007. this._y = euler._y;
  4008. this._z = euler._z;
  4009. this._order = euler._order;
  4010. this._onChangeCallback();
  4011. return this;
  4012. };
  4013. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4014. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4015. var te = m.elements;
  4016. var m11 = te[0],
  4017. m12 = te[4],
  4018. m13 = te[8];
  4019. var m21 = te[1],
  4020. m22 = te[5],
  4021. m23 = te[9];
  4022. var m31 = te[2],
  4023. m32 = te[6],
  4024. m33 = te[10];
  4025. order = order || this._order;
  4026. switch (order) {
  4027. case 'XYZ':
  4028. this._y = Math.asin(clamp(m13, -1, 1));
  4029. if (Math.abs(m13) < 0.9999999) {
  4030. this._x = Math.atan2(-m23, m33);
  4031. this._z = Math.atan2(-m12, m11);
  4032. } else {
  4033. this._x = Math.atan2(m32, m22);
  4034. this._z = 0;
  4035. }
  4036. break;
  4037. case 'YXZ':
  4038. this._x = Math.asin(-clamp(m23, -1, 1));
  4039. if (Math.abs(m23) < 0.9999999) {
  4040. this._y = Math.atan2(m13, m33);
  4041. this._z = Math.atan2(m21, m22);
  4042. } else {
  4043. this._y = Math.atan2(-m31, m11);
  4044. this._z = 0;
  4045. }
  4046. break;
  4047. case 'ZXY':
  4048. this._x = Math.asin(clamp(m32, -1, 1));
  4049. if (Math.abs(m32) < 0.9999999) {
  4050. this._y = Math.atan2(-m31, m33);
  4051. this._z = Math.atan2(-m12, m22);
  4052. } else {
  4053. this._y = 0;
  4054. this._z = Math.atan2(m21, m11);
  4055. }
  4056. break;
  4057. case 'ZYX':
  4058. this._y = Math.asin(-clamp(m31, -1, 1));
  4059. if (Math.abs(m31) < 0.9999999) {
  4060. this._x = Math.atan2(m32, m33);
  4061. this._z = Math.atan2(m21, m11);
  4062. } else {
  4063. this._x = 0;
  4064. this._z = Math.atan2(-m12, m22);
  4065. }
  4066. break;
  4067. case 'YZX':
  4068. this._z = Math.asin(clamp(m21, -1, 1));
  4069. if (Math.abs(m21) < 0.9999999) {
  4070. this._x = Math.atan2(-m23, m22);
  4071. this._y = Math.atan2(-m31, m11);
  4072. } else {
  4073. this._x = 0;
  4074. this._y = Math.atan2(m13, m33);
  4075. }
  4076. break;
  4077. case 'XZY':
  4078. this._z = Math.asin(-clamp(m12, -1, 1));
  4079. if (Math.abs(m12) < 0.9999999) {
  4080. this._x = Math.atan2(m32, m22);
  4081. this._y = Math.atan2(m13, m11);
  4082. } else {
  4083. this._x = Math.atan2(-m23, m33);
  4084. this._y = 0;
  4085. }
  4086. break;
  4087. default:
  4088. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4089. }
  4090. this._order = order;
  4091. if (update !== false) this._onChangeCallback();
  4092. return this;
  4093. };
  4094. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4095. _matrix.makeRotationFromQuaternion(q);
  4096. return this.setFromRotationMatrix(_matrix, order, update);
  4097. };
  4098. _proto.setFromVector3 = function setFromVector3(v, order) {
  4099. return this.set(v.x, v.y, v.z, order || this._order);
  4100. };
  4101. _proto.reorder = function reorder(newOrder) {
  4102. // WARNING: this discards revolution information -bhouston
  4103. _quaternion$1.setFromEuler(this);
  4104. return this.setFromQuaternion(_quaternion$1, newOrder);
  4105. };
  4106. _proto.equals = function equals(euler) {
  4107. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4108. };
  4109. _proto.fromArray = function fromArray(array) {
  4110. this._x = array[0];
  4111. this._y = array[1];
  4112. this._z = array[2];
  4113. if (array[3] !== undefined) this._order = array[3];
  4114. this._onChangeCallback();
  4115. return this;
  4116. };
  4117. _proto.toArray = function toArray(array, offset) {
  4118. if (array === void 0) {
  4119. array = [];
  4120. }
  4121. if (offset === void 0) {
  4122. offset = 0;
  4123. }
  4124. array[offset] = this._x;
  4125. array[offset + 1] = this._y;
  4126. array[offset + 2] = this._z;
  4127. array[offset + 3] = this._order;
  4128. return array;
  4129. };
  4130. _proto.toVector3 = function toVector3(optionalResult) {
  4131. if (optionalResult) {
  4132. return optionalResult.set(this._x, this._y, this._z);
  4133. } else {
  4134. return new Vector3(this._x, this._y, this._z);
  4135. }
  4136. };
  4137. _proto._onChange = function _onChange(callback) {
  4138. this._onChangeCallback = callback;
  4139. return this;
  4140. };
  4141. _proto._onChangeCallback = function _onChangeCallback() {};
  4142. _createClass(Euler, [{
  4143. key: "x",
  4144. get: function get() {
  4145. return this._x;
  4146. },
  4147. set: function set(value) {
  4148. this._x = value;
  4149. this._onChangeCallback();
  4150. }
  4151. }, {
  4152. key: "y",
  4153. get: function get() {
  4154. return this._y;
  4155. },
  4156. set: function set(value) {
  4157. this._y = value;
  4158. this._onChangeCallback();
  4159. }
  4160. }, {
  4161. key: "z",
  4162. get: function get() {
  4163. return this._z;
  4164. },
  4165. set: function set(value) {
  4166. this._z = value;
  4167. this._onChangeCallback();
  4168. }
  4169. }, {
  4170. key: "order",
  4171. get: function get() {
  4172. return this._order;
  4173. },
  4174. set: function set(value) {
  4175. this._order = value;
  4176. this._onChangeCallback();
  4177. }
  4178. }]);
  4179. return Euler;
  4180. }();
  4181. Euler.DefaultOrder = 'XYZ';
  4182. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4183. var _matrix = /*@__PURE__*/new Matrix4();
  4184. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4185. var Layers = /*#__PURE__*/function () {
  4186. function Layers() {
  4187. this.mask = 1 | 0;
  4188. }
  4189. var _proto = Layers.prototype;
  4190. _proto.set = function set(channel) {
  4191. this.mask = 1 << channel | 0;
  4192. };
  4193. _proto.enable = function enable(channel) {
  4194. this.mask |= 1 << channel | 0;
  4195. };
  4196. _proto.enableAll = function enableAll() {
  4197. this.mask = 0xffffffff | 0;
  4198. };
  4199. _proto.toggle = function toggle(channel) {
  4200. this.mask ^= 1 << channel | 0;
  4201. };
  4202. _proto.disable = function disable(channel) {
  4203. this.mask &= ~(1 << channel | 0);
  4204. };
  4205. _proto.disableAll = function disableAll() {
  4206. this.mask = 0;
  4207. };
  4208. _proto.test = function test(layers) {
  4209. return (this.mask & layers.mask) !== 0;
  4210. };
  4211. return Layers;
  4212. }();
  4213. var _object3DId = 0;
  4214. var _v1$2 = new Vector3();
  4215. var _q1 = new Quaternion();
  4216. var _m1$1 = new Matrix4();
  4217. var _target = new Vector3();
  4218. var _position = new Vector3();
  4219. var _scale = new Vector3();
  4220. var _quaternion$2 = new Quaternion();
  4221. var _xAxis = new Vector3(1, 0, 0);
  4222. var _yAxis = new Vector3(0, 1, 0);
  4223. var _zAxis = new Vector3(0, 0, 1);
  4224. var _addedEvent = {
  4225. type: 'added'
  4226. };
  4227. var _removedEvent = {
  4228. type: 'removed'
  4229. };
  4230. function Object3D() {
  4231. Object.defineProperty(this, 'id', {
  4232. value: _object3DId++
  4233. });
  4234. this.uuid = MathUtils.generateUUID();
  4235. this.name = '';
  4236. this.type = 'Object3D';
  4237. this.parent = null;
  4238. this.children = [];
  4239. this.up = Object3D.DefaultUp.clone();
  4240. var position = new Vector3();
  4241. var rotation = new Euler();
  4242. var quaternion = new Quaternion();
  4243. var scale = new Vector3(1, 1, 1);
  4244. function onRotationChange() {
  4245. quaternion.setFromEuler(rotation, false);
  4246. }
  4247. function onQuaternionChange() {
  4248. rotation.setFromQuaternion(quaternion, undefined, false);
  4249. }
  4250. rotation._onChange(onRotationChange);
  4251. quaternion._onChange(onQuaternionChange);
  4252. Object.defineProperties(this, {
  4253. position: {
  4254. configurable: true,
  4255. enumerable: true,
  4256. value: position
  4257. },
  4258. rotation: {
  4259. configurable: true,
  4260. enumerable: true,
  4261. value: rotation
  4262. },
  4263. quaternion: {
  4264. configurable: true,
  4265. enumerable: true,
  4266. value: quaternion
  4267. },
  4268. scale: {
  4269. configurable: true,
  4270. enumerable: true,
  4271. value: scale
  4272. },
  4273. modelViewMatrix: {
  4274. value: new Matrix4()
  4275. },
  4276. normalMatrix: {
  4277. value: new Matrix3()
  4278. }
  4279. });
  4280. this.matrix = new Matrix4();
  4281. this.matrixWorld = new Matrix4();
  4282. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  4283. this.matrixWorldNeedsUpdate = false;
  4284. this.layers = new Layers();
  4285. this.visible = true;
  4286. this.castShadow = false;
  4287. this.receiveShadow = false;
  4288. this.frustumCulled = true;
  4289. this.renderOrder = 0;
  4290. this.userData = {};
  4291. }
  4292. Object3D.DefaultUp = new Vector3(0, 1, 0);
  4293. Object3D.DefaultMatrixAutoUpdate = true;
  4294. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  4295. constructor: Object3D,
  4296. isObject3D: true,
  4297. onBeforeRender: function onBeforeRender() {},
  4298. onAfterRender: function onAfterRender() {},
  4299. applyMatrix4: function applyMatrix4(matrix) {
  4300. if (this.matrixAutoUpdate) this.updateMatrix();
  4301. this.matrix.premultiply(matrix);
  4302. this.matrix.decompose(this.position, this.quaternion, this.scale);
  4303. },
  4304. applyQuaternion: function applyQuaternion(q) {
  4305. this.quaternion.premultiply(q);
  4306. return this;
  4307. },
  4308. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  4309. // assumes axis is normalized
  4310. this.quaternion.setFromAxisAngle(axis, angle);
  4311. },
  4312. setRotationFromEuler: function setRotationFromEuler(euler) {
  4313. this.quaternion.setFromEuler(euler, true);
  4314. },
  4315. setRotationFromMatrix: function setRotationFromMatrix(m) {
  4316. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4317. this.quaternion.setFromRotationMatrix(m);
  4318. },
  4319. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  4320. // assumes q is normalized
  4321. this.quaternion.copy(q);
  4322. },
  4323. rotateOnAxis: function rotateOnAxis(axis, angle) {
  4324. // rotate object on axis in object space
  4325. // axis is assumed to be normalized
  4326. _q1.setFromAxisAngle(axis, angle);
  4327. this.quaternion.multiply(_q1);
  4328. return this;
  4329. },
  4330. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  4331. // rotate object on axis in world space
  4332. // axis is assumed to be normalized
  4333. // method assumes no rotated parent
  4334. _q1.setFromAxisAngle(axis, angle);
  4335. this.quaternion.premultiply(_q1);
  4336. return this;
  4337. },
  4338. rotateX: function rotateX(angle) {
  4339. return this.rotateOnAxis(_xAxis, angle);
  4340. },
  4341. rotateY: function rotateY(angle) {
  4342. return this.rotateOnAxis(_yAxis, angle);
  4343. },
  4344. rotateZ: function rotateZ(angle) {
  4345. return this.rotateOnAxis(_zAxis, angle);
  4346. },
  4347. translateOnAxis: function translateOnAxis(axis, distance) {
  4348. // translate object by distance along axis in object space
  4349. // axis is assumed to be normalized
  4350. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  4351. this.position.add(_v1$2.multiplyScalar(distance));
  4352. return this;
  4353. },
  4354. translateX: function translateX(distance) {
  4355. return this.translateOnAxis(_xAxis, distance);
  4356. },
  4357. translateY: function translateY(distance) {
  4358. return this.translateOnAxis(_yAxis, distance);
  4359. },
  4360. translateZ: function translateZ(distance) {
  4361. return this.translateOnAxis(_zAxis, distance);
  4362. },
  4363. localToWorld: function localToWorld(vector) {
  4364. return vector.applyMatrix4(this.matrixWorld);
  4365. },
  4366. worldToLocal: function worldToLocal(vector) {
  4367. return vector.applyMatrix4(_m1$1.getInverse(this.matrixWorld));
  4368. },
  4369. lookAt: function lookAt(x, y, z) {
  4370. // This method does not support objects having non-uniformly-scaled parent(s)
  4371. if (x.isVector3) {
  4372. _target.copy(x);
  4373. } else {
  4374. _target.set(x, y, z);
  4375. }
  4376. var parent = this.parent;
  4377. this.updateWorldMatrix(true, false);
  4378. _position.setFromMatrixPosition(this.matrixWorld);
  4379. if (this.isCamera || this.isLight) {
  4380. _m1$1.lookAt(_position, _target, this.up);
  4381. } else {
  4382. _m1$1.lookAt(_target, _position, this.up);
  4383. }
  4384. this.quaternion.setFromRotationMatrix(_m1$1);
  4385. if (parent) {
  4386. _m1$1.extractRotation(parent.matrixWorld);
  4387. _q1.setFromRotationMatrix(_m1$1);
  4388. this.quaternion.premultiply(_q1.inverse());
  4389. }
  4390. },
  4391. add: function add(object) {
  4392. if (arguments.length > 1) {
  4393. for (var i = 0; i < arguments.length; i++) {
  4394. this.add(arguments[i]);
  4395. }
  4396. return this;
  4397. }
  4398. if (object === this) {
  4399. console.error("THREE.Object3D.add: object can't be added as a child of itself.", object);
  4400. return this;
  4401. }
  4402. if (object && object.isObject3D) {
  4403. if (object.parent !== null) {
  4404. object.parent.remove(object);
  4405. }
  4406. object.parent = this;
  4407. this.children.push(object);
  4408. object.dispatchEvent(_addedEvent);
  4409. } else {
  4410. console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.", object);
  4411. }
  4412. return this;
  4413. },
  4414. remove: function remove(object) {
  4415. if (arguments.length > 1) {
  4416. for (var i = 0; i < arguments.length; i++) {
  4417. this.remove(arguments[i]);
  4418. }
  4419. return this;
  4420. }
  4421. var index = this.children.indexOf(object);
  4422. if (index !== -1) {
  4423. object.parent = null;
  4424. this.children.splice(index, 1);
  4425. object.dispatchEvent(_removedEvent);
  4426. }
  4427. return this;
  4428. },
  4429. removeAll: function removeAll() {
  4430. for (var i = 0; i < this.children.length; i++) {
  4431. var object = this.children[i];
  4432. object.parent = null;
  4433. object.dispatchEvent(_removedEvent);
  4434. }
  4435. this.children.length = 0;
  4436. return this;
  4437. },
  4438. attach: function attach(object) {
  4439. // adds object as a child of this, while maintaining the object's world transform
  4440. this.updateWorldMatrix(true, false);
  4441. _m1$1.getInverse(this.matrixWorld);
  4442. if (object.parent !== null) {
  4443. object.parent.updateWorldMatrix(true, false);
  4444. _m1$1.multiply(object.parent.matrixWorld);
  4445. }
  4446. object.applyMatrix4(_m1$1);
  4447. object.updateWorldMatrix(false, false);
  4448. this.add(object);
  4449. return this;
  4450. },
  4451. getObjectById: function getObjectById(id) {
  4452. return this.getObjectByProperty('id', id);
  4453. },
  4454. getObjectByName: function getObjectByName(name) {
  4455. return this.getObjectByProperty('name', name);
  4456. },
  4457. getObjectByProperty: function getObjectByProperty(name, value) {
  4458. if (this[name] === value) return this;
  4459. for (var i = 0, l = this.children.length; i < l; i++) {
  4460. var child = this.children[i];
  4461. var object = child.getObjectByProperty(name, value);
  4462. if (object !== undefined) {
  4463. return object;
  4464. }
  4465. }
  4466. return undefined;
  4467. },
  4468. getWorldPosition: function getWorldPosition(target) {
  4469. if (target === undefined) {
  4470. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  4471. target = new Vector3();
  4472. }
  4473. this.updateWorldMatrix(true, false);
  4474. return target.setFromMatrixPosition(this.matrixWorld);
  4475. },
  4476. getWorldQuaternion: function getWorldQuaternion(target) {
  4477. if (target === undefined) {
  4478. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  4479. target = new Quaternion();
  4480. }
  4481. this.updateWorldMatrix(true, false);
  4482. this.matrixWorld.decompose(_position, target, _scale);
  4483. return target;
  4484. },
  4485. getWorldScale: function getWorldScale(target) {
  4486. if (target === undefined) {
  4487. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  4488. target = new Vector3();
  4489. }
  4490. this.updateWorldMatrix(true, false);
  4491. this.matrixWorld.decompose(_position, _quaternion$2, target);
  4492. return target;
  4493. },
  4494. getWorldDirection: function getWorldDirection(target) {
  4495. if (target === undefined) {
  4496. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  4497. target = new Vector3();
  4498. }
  4499. this.updateWorldMatrix(true, false);
  4500. var e = this.matrixWorld.elements;
  4501. return target.set(e[8], e[9], e[10]).normalize();
  4502. },
  4503. raycast: function raycast() {},
  4504. traverse: function traverse(callback) {
  4505. callback(this);
  4506. var children = this.children;
  4507. for (var i = 0, l = children.length; i < l; i++) {
  4508. children[i].traverse(callback);
  4509. }
  4510. },
  4511. traverseVisible: function traverseVisible(callback) {
  4512. if (this.visible === false) return;
  4513. callback(this);
  4514. var children = this.children;
  4515. for (var i = 0, l = children.length; i < l; i++) {
  4516. children[i].traverseVisible(callback);
  4517. }
  4518. },
  4519. traverseAncestors: function traverseAncestors(callback) {
  4520. var parent = this.parent;
  4521. if (parent !== null) {
  4522. callback(parent);
  4523. parent.traverseAncestors(callback);
  4524. }
  4525. },
  4526. updateMatrix: function updateMatrix() {
  4527. this.matrix.compose(this.position, this.quaternion, this.scale);
  4528. this.matrixWorldNeedsUpdate = true;
  4529. },
  4530. updateMatrixWorld: function updateMatrixWorld(force) {
  4531. if (this.matrixAutoUpdate) this.updateMatrix();
  4532. if (this.matrixWorldNeedsUpdate || force) {
  4533. if (this.parent === null) {
  4534. this.matrixWorld.copy(this.matrix);
  4535. } else {
  4536. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4537. }
  4538. this.matrixWorldNeedsUpdate = false;
  4539. force = true;
  4540. } // update children
  4541. var children = this.children;
  4542. for (var i = 0, l = children.length; i < l; i++) {
  4543. children[i].updateMatrixWorld(force);
  4544. }
  4545. },
  4546. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  4547. var parent = this.parent;
  4548. if (updateParents === true && parent !== null) {
  4549. parent.updateWorldMatrix(true, false);
  4550. }
  4551. if (this.matrixAutoUpdate) this.updateMatrix();
  4552. if (this.parent === null) {
  4553. this.matrixWorld.copy(this.matrix);
  4554. } else {
  4555. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4556. } // update children
  4557. if (updateChildren === true) {
  4558. var children = this.children;
  4559. for (var i = 0, l = children.length; i < l; i++) {
  4560. children[i].updateWorldMatrix(false, true);
  4561. }
  4562. }
  4563. },
  4564. toJSON: function toJSON(meta) {
  4565. // meta is a string when called from JSON.stringify
  4566. var isRootObject = meta === undefined || typeof meta === 'string';
  4567. var output = {}; // meta is a hash used to collect geometries, materials.
  4568. // not providing it implies that this is the root object
  4569. // being serialized.
  4570. if (isRootObject) {
  4571. // initialize meta obj
  4572. meta = {
  4573. geometries: {},
  4574. materials: {},
  4575. textures: {},
  4576. images: {},
  4577. shapes: {}
  4578. };
  4579. output.metadata = {
  4580. version: 4.5,
  4581. type: 'Object',
  4582. generator: 'Object3D.toJSON'
  4583. };
  4584. } // standard Object3D serialization
  4585. var object = {};
  4586. object.uuid = this.uuid;
  4587. object.type = this.type;
  4588. if (this.name !== '') object.name = this.name;
  4589. if (this.castShadow === true) object.castShadow = true;
  4590. if (this.receiveShadow === true) object.receiveShadow = true;
  4591. if (this.visible === false) object.visible = false;
  4592. if (this.frustumCulled === false) object.frustumCulled = false;
  4593. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  4594. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  4595. object.layers = this.layers.mask;
  4596. object.matrix = this.matrix.toArray();
  4597. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  4598. if (this.isInstancedMesh) {
  4599. object.type = 'InstancedMesh';
  4600. object.count = this.count;
  4601. object.instanceMatrix = this.instanceMatrix.toJSON();
  4602. } //
  4603. function serialize(library, element) {
  4604. if (library[element.uuid] === undefined) {
  4605. library[element.uuid] = element.toJSON(meta);
  4606. }
  4607. return element.uuid;
  4608. }
  4609. if (this.isMesh || this.isLine || this.isPoints) {
  4610. object.geometry = serialize(meta.geometries, this.geometry);
  4611. var parameters = this.geometry.parameters;
  4612. if (parameters !== undefined && parameters.shapes !== undefined) {
  4613. var shapes = parameters.shapes;
  4614. if (Array.isArray(shapes)) {
  4615. for (var i = 0, l = shapes.length; i < l; i++) {
  4616. var shape = shapes[i];
  4617. serialize(meta.shapes, shape);
  4618. }
  4619. } else {
  4620. serialize(meta.shapes, shapes);
  4621. }
  4622. }
  4623. }
  4624. if (this.material !== undefined) {
  4625. if (Array.isArray(this.material)) {
  4626. var uuids = [];
  4627. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  4628. uuids.push(serialize(meta.materials, this.material[_i]));
  4629. }
  4630. object.material = uuids;
  4631. } else {
  4632. object.material = serialize(meta.materials, this.material);
  4633. }
  4634. } //
  4635. if (this.children.length > 0) {
  4636. object.children = [];
  4637. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  4638. object.children.push(this.children[_i2].toJSON(meta).object);
  4639. }
  4640. }
  4641. if (isRootObject) {
  4642. var geometries = extractFromCache(meta.geometries);
  4643. var materials = extractFromCache(meta.materials);
  4644. var textures = extractFromCache(meta.textures);
  4645. var images = extractFromCache(meta.images);
  4646. var _shapes = extractFromCache(meta.shapes);
  4647. if (geometries.length > 0) output.geometries = geometries;
  4648. if (materials.length > 0) output.materials = materials;
  4649. if (textures.length > 0) output.textures = textures;
  4650. if (images.length > 0) output.images = images;
  4651. if (_shapes.length > 0) output.shapes = _shapes;
  4652. }
  4653. output.object = object;
  4654. return output; // extract data from the cache hash
  4655. // remove metadata on each item
  4656. // and return as array
  4657. function extractFromCache(cache) {
  4658. var values = [];
  4659. for (var key in cache) {
  4660. var data = cache[key];
  4661. delete data.metadata;
  4662. values.push(data);
  4663. }
  4664. return values;
  4665. }
  4666. },
  4667. clone: function clone(recursive) {
  4668. return new this.constructor().copy(this, recursive);
  4669. },
  4670. copy: function copy(source, recursive) {
  4671. if (recursive === undefined) recursive = true;
  4672. this.name = source.name;
  4673. this.up.copy(source.up);
  4674. this.position.copy(source.position);
  4675. this.rotation.order = source.rotation.order;
  4676. this.quaternion.copy(source.quaternion);
  4677. this.scale.copy(source.scale);
  4678. this.matrix.copy(source.matrix);
  4679. this.matrixWorld.copy(source.matrixWorld);
  4680. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4681. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4682. this.layers.mask = source.layers.mask;
  4683. this.visible = source.visible;
  4684. this.castShadow = source.castShadow;
  4685. this.receiveShadow = source.receiveShadow;
  4686. this.frustumCulled = source.frustumCulled;
  4687. this.renderOrder = source.renderOrder;
  4688. this.userData = JSON.parse(JSON.stringify(source.userData));
  4689. if (recursive === true) {
  4690. for (var i = 0; i < source.children.length; i++) {
  4691. var child = source.children[i];
  4692. this.add(child.clone());
  4693. }
  4694. }
  4695. return this;
  4696. }
  4697. });
  4698. var _vector1 = /*@__PURE__*/new Vector3();
  4699. var _vector2 = /*@__PURE__*/new Vector3();
  4700. var _normalMatrix = /*@__PURE__*/new Matrix3();
  4701. var Plane = /*#__PURE__*/function () {
  4702. function Plane(normal, constant) {
  4703. Object.defineProperty(this, 'isPlane', {
  4704. value: true
  4705. }); // normal is assumed to be normalized
  4706. this.normal = normal !== undefined ? normal : new Vector3(1, 0, 0);
  4707. this.constant = constant !== undefined ? constant : 0;
  4708. }
  4709. var _proto = Plane.prototype;
  4710. _proto.set = function set(normal, constant) {
  4711. this.normal.copy(normal);
  4712. this.constant = constant;
  4713. return this;
  4714. };
  4715. _proto.setComponents = function setComponents(x, y, z, w) {
  4716. this.normal.set(x, y, z);
  4717. this.constant = w;
  4718. return this;
  4719. };
  4720. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  4721. this.normal.copy(normal);
  4722. this.constant = -point.dot(this.normal);
  4723. return this;
  4724. };
  4725. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  4726. 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)?
  4727. this.setFromNormalAndCoplanarPoint(normal, a);
  4728. return this;
  4729. };
  4730. _proto.clone = function clone() {
  4731. return new this.constructor().copy(this);
  4732. };
  4733. _proto.copy = function copy(plane) {
  4734. this.normal.copy(plane.normal);
  4735. this.constant = plane.constant;
  4736. return this;
  4737. };
  4738. _proto.normalize = function normalize() {
  4739. // Note: will lead to a divide by zero if the plane is invalid.
  4740. var inverseNormalLength = 1.0 / this.normal.length();
  4741. this.normal.multiplyScalar(inverseNormalLength);
  4742. this.constant *= inverseNormalLength;
  4743. return this;
  4744. };
  4745. _proto.negate = function negate() {
  4746. this.constant *= -1;
  4747. this.normal.negate();
  4748. return this;
  4749. };
  4750. _proto.distanceToPoint = function distanceToPoint(point) {
  4751. return this.normal.dot(point) + this.constant;
  4752. };
  4753. _proto.distanceToSphere = function distanceToSphere(sphere) {
  4754. return this.distanceToPoint(sphere.center) - sphere.radius;
  4755. };
  4756. _proto.projectPoint = function projectPoint(point, target) {
  4757. if (target === undefined) {
  4758. console.warn('THREE.Plane: .projectPoint() target is now required');
  4759. target = new Vector3();
  4760. }
  4761. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  4762. };
  4763. _proto.intersectLine = function intersectLine(line, target) {
  4764. if (target === undefined) {
  4765. console.warn('THREE.Plane: .intersectLine() target is now required');
  4766. target = new Vector3();
  4767. }
  4768. var direction = line.delta(_vector1);
  4769. var denominator = this.normal.dot(direction);
  4770. if (denominator === 0) {
  4771. // line is coplanar, return origin
  4772. if (this.distanceToPoint(line.start) === 0) {
  4773. return target.copy(line.start);
  4774. } // Unsure if this is the correct method to handle this case.
  4775. return undefined;
  4776. }
  4777. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  4778. if (t < 0 || t > 1) {
  4779. return undefined;
  4780. }
  4781. return target.copy(direction).multiplyScalar(t).add(line.start);
  4782. };
  4783. _proto.intersectsLine = function intersectsLine(line) {
  4784. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4785. var startSign = this.distanceToPoint(line.start);
  4786. var endSign = this.distanceToPoint(line.end);
  4787. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  4788. };
  4789. _proto.intersectsBox = function intersectsBox(box) {
  4790. return box.intersectsPlane(this);
  4791. };
  4792. _proto.intersectsSphere = function intersectsSphere(sphere) {
  4793. return sphere.intersectsPlane(this);
  4794. };
  4795. _proto.coplanarPoint = function coplanarPoint(target) {
  4796. if (target === undefined) {
  4797. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  4798. target = new Vector3();
  4799. }
  4800. return target.copy(this.normal).multiplyScalar(-this.constant);
  4801. };
  4802. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  4803. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  4804. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  4805. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  4806. this.constant = -referencePoint.dot(normal);
  4807. return this;
  4808. };
  4809. _proto.translate = function translate(offset) {
  4810. this.constant -= offset.dot(this.normal);
  4811. return this;
  4812. };
  4813. _proto.equals = function equals(plane) {
  4814. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  4815. };
  4816. return Plane;
  4817. }();
  4818. var _v0$1 = /*@__PURE__*/new Vector3();
  4819. var _v1$3 = /*@__PURE__*/new Vector3();
  4820. var _v2$1 = /*@__PURE__*/new Vector3();
  4821. var _v3 = /*@__PURE__*/new Vector3();
  4822. var _vab = /*@__PURE__*/new Vector3();
  4823. var _vac = /*@__PURE__*/new Vector3();
  4824. var _vbc = /*@__PURE__*/new Vector3();
  4825. var _vap = /*@__PURE__*/new Vector3();
  4826. var _vbp = /*@__PURE__*/new Vector3();
  4827. var _vcp = /*@__PURE__*/new Vector3();
  4828. var Triangle = /*#__PURE__*/function () {
  4829. function Triangle(a, b, c) {
  4830. this.a = a !== undefined ? a : new Vector3();
  4831. this.b = b !== undefined ? b : new Vector3();
  4832. this.c = c !== undefined ? c : new Vector3();
  4833. }
  4834. Triangle.getNormal = function getNormal(a, b, c, target) {
  4835. if (target === undefined) {
  4836. console.warn('THREE.Triangle: .getNormal() target is now required');
  4837. target = new Vector3();
  4838. }
  4839. target.subVectors(c, b);
  4840. _v0$1.subVectors(a, b);
  4841. target.cross(_v0$1);
  4842. var targetLengthSq = target.lengthSq();
  4843. if (targetLengthSq > 0) {
  4844. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  4845. }
  4846. return target.set(0, 0, 0);
  4847. } // static/instance method to calculate barycentric coordinates
  4848. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4849. ;
  4850. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  4851. _v0$1.subVectors(c, a);
  4852. _v1$3.subVectors(b, a);
  4853. _v2$1.subVectors(point, a);
  4854. var dot00 = _v0$1.dot(_v0$1);
  4855. var dot01 = _v0$1.dot(_v1$3);
  4856. var dot02 = _v0$1.dot(_v2$1);
  4857. var dot11 = _v1$3.dot(_v1$3);
  4858. var dot12 = _v1$3.dot(_v2$1);
  4859. var denom = dot00 * dot11 - dot01 * dot01;
  4860. if (target === undefined) {
  4861. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  4862. target = new Vector3();
  4863. } // collinear or singular triangle
  4864. if (denom === 0) {
  4865. // arbitrary location outside of triangle?
  4866. // not sure if this is the best idea, maybe should be returning undefined
  4867. return target.set(-2, -1, -1);
  4868. }
  4869. var invDenom = 1 / denom;
  4870. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  4871. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  4872. return target.set(1 - u - v, v, u);
  4873. };
  4874. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  4875. this.getBarycoord(point, a, b, c, _v3);
  4876. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  4877. };
  4878. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  4879. this.getBarycoord(point, p1, p2, p3, _v3);
  4880. target.set(0, 0);
  4881. target.addScaledVector(uv1, _v3.x);
  4882. target.addScaledVector(uv2, _v3.y);
  4883. target.addScaledVector(uv3, _v3.z);
  4884. return target;
  4885. };
  4886. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  4887. _v0$1.subVectors(c, b);
  4888. _v1$3.subVectors(a, b); // strictly front facing
  4889. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  4890. };
  4891. var _proto = Triangle.prototype;
  4892. _proto.set = function set(a, b, c) {
  4893. this.a.copy(a);
  4894. this.b.copy(b);
  4895. this.c.copy(c);
  4896. return this;
  4897. };
  4898. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  4899. this.a.copy(points[i0]);
  4900. this.b.copy(points[i1]);
  4901. this.c.copy(points[i2]);
  4902. return this;
  4903. };
  4904. _proto.clone = function clone() {
  4905. return new this.constructor().copy(this);
  4906. };
  4907. _proto.copy = function copy(triangle) {
  4908. this.a.copy(triangle.a);
  4909. this.b.copy(triangle.b);
  4910. this.c.copy(triangle.c);
  4911. return this;
  4912. };
  4913. _proto.getArea = function getArea() {
  4914. _v0$1.subVectors(this.c, this.b);
  4915. _v1$3.subVectors(this.a, this.b);
  4916. return _v0$1.cross(_v1$3).length() * 0.5;
  4917. };
  4918. _proto.getMidpoint = function getMidpoint(target) {
  4919. if (target === undefined) {
  4920. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  4921. target = new Vector3();
  4922. }
  4923. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  4924. };
  4925. _proto.getNormal = function getNormal(target) {
  4926. return Triangle.getNormal(this.a, this.b, this.c, target);
  4927. };
  4928. _proto.getPlane = function getPlane(target) {
  4929. if (target === undefined) {
  4930. console.warn('THREE.Triangle: .getPlane() target is now required');
  4931. target = new Plane();
  4932. }
  4933. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  4934. };
  4935. _proto.getBarycoord = function getBarycoord(point, target) {
  4936. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  4937. };
  4938. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  4939. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  4940. };
  4941. _proto.containsPoint = function containsPoint(point) {
  4942. return Triangle.containsPoint(point, this.a, this.b, this.c);
  4943. };
  4944. _proto.isFrontFacing = function isFrontFacing(direction) {
  4945. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  4946. };
  4947. _proto.intersectsBox = function intersectsBox(box) {
  4948. return box.intersectsTriangle(this);
  4949. };
  4950. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  4951. if (target === undefined) {
  4952. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  4953. target = new Vector3();
  4954. }
  4955. var a = this.a,
  4956. b = this.b,
  4957. c = this.c;
  4958. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4959. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4960. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4961. // basically, we're distinguishing which of the voronoi regions of the triangle
  4962. // the point lies in with the minimum amount of redundant computation.
  4963. _vab.subVectors(b, a);
  4964. _vac.subVectors(c, a);
  4965. _vap.subVectors(p, a);
  4966. var d1 = _vab.dot(_vap);
  4967. var d2 = _vac.dot(_vap);
  4968. if (d1 <= 0 && d2 <= 0) {
  4969. // vertex region of A; barycentric coords (1, 0, 0)
  4970. return target.copy(a);
  4971. }
  4972. _vbp.subVectors(p, b);
  4973. var d3 = _vab.dot(_vbp);
  4974. var d4 = _vac.dot(_vbp);
  4975. if (d3 >= 0 && d4 <= d3) {
  4976. // vertex region of B; barycentric coords (0, 1, 0)
  4977. return target.copy(b);
  4978. }
  4979. var vc = d1 * d4 - d3 * d2;
  4980. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  4981. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  4982. return target.copy(a).addScaledVector(_vab, v);
  4983. }
  4984. _vcp.subVectors(p, c);
  4985. var d5 = _vab.dot(_vcp);
  4986. var d6 = _vac.dot(_vcp);
  4987. if (d6 >= 0 && d5 <= d6) {
  4988. // vertex region of C; barycentric coords (0, 0, 1)
  4989. return target.copy(c);
  4990. }
  4991. var vb = d5 * d2 - d1 * d6;
  4992. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  4993. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  4994. return target.copy(a).addScaledVector(_vac, w);
  4995. }
  4996. var va = d3 * d6 - d5 * d4;
  4997. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  4998. _vbc.subVectors(c, b);
  4999. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5000. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5001. } // face region
  5002. var denom = 1 / (va + vb + vc); // u = va * denom
  5003. v = vb * denom;
  5004. w = vc * denom;
  5005. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5006. };
  5007. _proto.equals = function equals(triangle) {
  5008. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5009. };
  5010. return Triangle;
  5011. }();
  5012. var _colorKeywords = {
  5013. 'aliceblue': 0xF0F8FF,
  5014. 'antiquewhite': 0xFAEBD7,
  5015. 'aqua': 0x00FFFF,
  5016. 'aquamarine': 0x7FFFD4,
  5017. 'azure': 0xF0FFFF,
  5018. 'beige': 0xF5F5DC,
  5019. 'bisque': 0xFFE4C4,
  5020. 'black': 0x000000,
  5021. 'blanchedalmond': 0xFFEBCD,
  5022. 'blue': 0x0000FF,
  5023. 'blueviolet': 0x8A2BE2,
  5024. 'brown': 0xA52A2A,
  5025. 'burlywood': 0xDEB887,
  5026. 'cadetblue': 0x5F9EA0,
  5027. 'chartreuse': 0x7FFF00,
  5028. 'chocolate': 0xD2691E,
  5029. 'coral': 0xFF7F50,
  5030. 'cornflowerblue': 0x6495ED,
  5031. 'cornsilk': 0xFFF8DC,
  5032. 'crimson': 0xDC143C,
  5033. 'cyan': 0x00FFFF,
  5034. 'darkblue': 0x00008B,
  5035. 'darkcyan': 0x008B8B,
  5036. 'darkgoldenrod': 0xB8860B,
  5037. 'darkgray': 0xA9A9A9,
  5038. 'darkgreen': 0x006400,
  5039. 'darkgrey': 0xA9A9A9,
  5040. 'darkkhaki': 0xBDB76B,
  5041. 'darkmagenta': 0x8B008B,
  5042. 'darkolivegreen': 0x556B2F,
  5043. 'darkorange': 0xFF8C00,
  5044. 'darkorchid': 0x9932CC,
  5045. 'darkred': 0x8B0000,
  5046. 'darksalmon': 0xE9967A,
  5047. 'darkseagreen': 0x8FBC8F,
  5048. 'darkslateblue': 0x483D8B,
  5049. 'darkslategray': 0x2F4F4F,
  5050. 'darkslategrey': 0x2F4F4F,
  5051. 'darkturquoise': 0x00CED1,
  5052. 'darkviolet': 0x9400D3,
  5053. 'deeppink': 0xFF1493,
  5054. 'deepskyblue': 0x00BFFF,
  5055. 'dimgray': 0x696969,
  5056. 'dimgrey': 0x696969,
  5057. 'dodgerblue': 0x1E90FF,
  5058. 'firebrick': 0xB22222,
  5059. 'floralwhite': 0xFFFAF0,
  5060. 'forestgreen': 0x228B22,
  5061. 'fuchsia': 0xFF00FF,
  5062. 'gainsboro': 0xDCDCDC,
  5063. 'ghostwhite': 0xF8F8FF,
  5064. 'gold': 0xFFD700,
  5065. 'goldenrod': 0xDAA520,
  5066. 'gray': 0x808080,
  5067. 'green': 0x008000,
  5068. 'greenyellow': 0xADFF2F,
  5069. 'grey': 0x808080,
  5070. 'honeydew': 0xF0FFF0,
  5071. 'hotpink': 0xFF69B4,
  5072. 'indianred': 0xCD5C5C,
  5073. 'indigo': 0x4B0082,
  5074. 'ivory': 0xFFFFF0,
  5075. 'khaki': 0xF0E68C,
  5076. 'lavender': 0xE6E6FA,
  5077. 'lavenderblush': 0xFFF0F5,
  5078. 'lawngreen': 0x7CFC00,
  5079. 'lemonchiffon': 0xFFFACD,
  5080. 'lightblue': 0xADD8E6,
  5081. 'lightcoral': 0xF08080,
  5082. 'lightcyan': 0xE0FFFF,
  5083. 'lightgoldenrodyellow': 0xFAFAD2,
  5084. 'lightgray': 0xD3D3D3,
  5085. 'lightgreen': 0x90EE90,
  5086. 'lightgrey': 0xD3D3D3,
  5087. 'lightpink': 0xFFB6C1,
  5088. 'lightsalmon': 0xFFA07A,
  5089. 'lightseagreen': 0x20B2AA,
  5090. 'lightskyblue': 0x87CEFA,
  5091. 'lightslategray': 0x778899,
  5092. 'lightslategrey': 0x778899,
  5093. 'lightsteelblue': 0xB0C4DE,
  5094. 'lightyellow': 0xFFFFE0,
  5095. 'lime': 0x00FF00,
  5096. 'limegreen': 0x32CD32,
  5097. 'linen': 0xFAF0E6,
  5098. 'magenta': 0xFF00FF,
  5099. 'maroon': 0x800000,
  5100. 'mediumaquamarine': 0x66CDAA,
  5101. 'mediumblue': 0x0000CD,
  5102. 'mediumorchid': 0xBA55D3,
  5103. 'mediumpurple': 0x9370DB,
  5104. 'mediumseagreen': 0x3CB371,
  5105. 'mediumslateblue': 0x7B68EE,
  5106. 'mediumspringgreen': 0x00FA9A,
  5107. 'mediumturquoise': 0x48D1CC,
  5108. 'mediumvioletred': 0xC71585,
  5109. 'midnightblue': 0x191970,
  5110. 'mintcream': 0xF5FFFA,
  5111. 'mistyrose': 0xFFE4E1,
  5112. 'moccasin': 0xFFE4B5,
  5113. 'navajowhite': 0xFFDEAD,
  5114. 'navy': 0x000080,
  5115. 'oldlace': 0xFDF5E6,
  5116. 'olive': 0x808000,
  5117. 'olivedrab': 0x6B8E23,
  5118. 'orange': 0xFFA500,
  5119. 'orangered': 0xFF4500,
  5120. 'orchid': 0xDA70D6,
  5121. 'palegoldenrod': 0xEEE8AA,
  5122. 'palegreen': 0x98FB98,
  5123. 'paleturquoise': 0xAFEEEE,
  5124. 'palevioletred': 0xDB7093,
  5125. 'papayawhip': 0xFFEFD5,
  5126. 'peachpuff': 0xFFDAB9,
  5127. 'peru': 0xCD853F,
  5128. 'pink': 0xFFC0CB,
  5129. 'plum': 0xDDA0DD,
  5130. 'powderblue': 0xB0E0E6,
  5131. 'purple': 0x800080,
  5132. 'rebeccapurple': 0x663399,
  5133. 'red': 0xFF0000,
  5134. 'rosybrown': 0xBC8F8F,
  5135. 'royalblue': 0x4169E1,
  5136. 'saddlebrown': 0x8B4513,
  5137. 'salmon': 0xFA8072,
  5138. 'sandybrown': 0xF4A460,
  5139. 'seagreen': 0x2E8B57,
  5140. 'seashell': 0xFFF5EE,
  5141. 'sienna': 0xA0522D,
  5142. 'silver': 0xC0C0C0,
  5143. 'skyblue': 0x87CEEB,
  5144. 'slateblue': 0x6A5ACD,
  5145. 'slategray': 0x708090,
  5146. 'slategrey': 0x708090,
  5147. 'snow': 0xFFFAFA,
  5148. 'springgreen': 0x00FF7F,
  5149. 'steelblue': 0x4682B4,
  5150. 'tan': 0xD2B48C,
  5151. 'teal': 0x008080,
  5152. 'thistle': 0xD8BFD8,
  5153. 'tomato': 0xFF6347,
  5154. 'turquoise': 0x40E0D0,
  5155. 'violet': 0xEE82EE,
  5156. 'wheat': 0xF5DEB3,
  5157. 'white': 0xFFFFFF,
  5158. 'whitesmoke': 0xF5F5F5,
  5159. 'yellow': 0xFFFF00,
  5160. 'yellowgreen': 0x9ACD32
  5161. };
  5162. var _hslA = {
  5163. h: 0,
  5164. s: 0,
  5165. l: 0
  5166. };
  5167. var _hslB = {
  5168. h: 0,
  5169. s: 0,
  5170. l: 0
  5171. };
  5172. function hue2rgb(p, q, t) {
  5173. if (t < 0) t += 1;
  5174. if (t > 1) t -= 1;
  5175. if (t < 1 / 6) return p + (q - p) * 6 * t;
  5176. if (t < 1 / 2) return q;
  5177. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  5178. return p;
  5179. }
  5180. function SRGBToLinear(c) {
  5181. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  5182. }
  5183. function LinearToSRGB(c) {
  5184. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  5185. }
  5186. var Color = /*#__PURE__*/function () {
  5187. function Color(r, g, b) {
  5188. Object.defineProperty(this, 'isColor', {
  5189. value: true
  5190. });
  5191. if (g === undefined && b === undefined) {
  5192. // r is THREE.Color, hex or string
  5193. return this.set(r);
  5194. }
  5195. return this.setRGB(r, g, b);
  5196. }
  5197. var _proto = Color.prototype;
  5198. _proto.set = function set(value) {
  5199. if (value && value.isColor) {
  5200. this.copy(value);
  5201. } else if (typeof value === 'number') {
  5202. this.setHex(value);
  5203. } else if (typeof value === 'string') {
  5204. this.setStyle(value);
  5205. }
  5206. return this;
  5207. };
  5208. _proto.setScalar = function setScalar(scalar) {
  5209. this.r = scalar;
  5210. this.g = scalar;
  5211. this.b = scalar;
  5212. return this;
  5213. };
  5214. _proto.setHex = function setHex(hex) {
  5215. hex = Math.floor(hex);
  5216. this.r = (hex >> 16 & 255) / 255;
  5217. this.g = (hex >> 8 & 255) / 255;
  5218. this.b = (hex & 255) / 255;
  5219. return this;
  5220. };
  5221. _proto.setRGB = function setRGB(r, g, b) {
  5222. this.r = r;
  5223. this.g = g;
  5224. this.b = b;
  5225. return this;
  5226. };
  5227. _proto.setHSL = function setHSL(h, s, l) {
  5228. // h,s,l ranges are in 0.0 - 1.0
  5229. h = MathUtils.euclideanModulo(h, 1);
  5230. s = MathUtils.clamp(s, 0, 1);
  5231. l = MathUtils.clamp(l, 0, 1);
  5232. if (s === 0) {
  5233. this.r = this.g = this.b = l;
  5234. } else {
  5235. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  5236. var q = 2 * l - p;
  5237. this.r = hue2rgb(q, p, h + 1 / 3);
  5238. this.g = hue2rgb(q, p, h);
  5239. this.b = hue2rgb(q, p, h - 1 / 3);
  5240. }
  5241. return this;
  5242. };
  5243. _proto.setStyle = function setStyle(style) {
  5244. function handleAlpha(string) {
  5245. if (string === undefined) return;
  5246. if (parseFloat(string) < 1) {
  5247. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  5248. }
  5249. }
  5250. var m;
  5251. if (m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(style)) {
  5252. // rgb / hsl
  5253. var color;
  5254. var name = m[1];
  5255. var components = m[2];
  5256. switch (name) {
  5257. case 'rgb':
  5258. case 'rgba':
  5259. if (color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5260. // rgb(255,0,0) rgba(255,0,0,0.5)
  5261. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  5262. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  5263. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  5264. handleAlpha(color[5]);
  5265. return this;
  5266. }
  5267. if (color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5268. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5269. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  5270. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  5271. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  5272. handleAlpha(color[5]);
  5273. return this;
  5274. }
  5275. break;
  5276. case 'hsl':
  5277. case 'hsla':
  5278. if (color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5279. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  5280. var h = parseFloat(color[1]) / 360;
  5281. var s = parseInt(color[2], 10) / 100;
  5282. var l = parseInt(color[3], 10) / 100;
  5283. handleAlpha(color[5]);
  5284. return this.setHSL(h, s, l);
  5285. }
  5286. break;
  5287. }
  5288. } else if (m = /^\#([A-Fa-f0-9]+)$/.exec(style)) {
  5289. // hex color
  5290. var hex = m[1];
  5291. var size = hex.length;
  5292. if (size === 3) {
  5293. // #ff0
  5294. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  5295. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  5296. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  5297. return this;
  5298. } else if (size === 6) {
  5299. // #ff0000
  5300. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  5301. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  5302. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  5303. return this;
  5304. }
  5305. }
  5306. if (style && style.length > 0) {
  5307. return this.setColorName(style);
  5308. }
  5309. return this;
  5310. };
  5311. _proto.setColorName = function setColorName(style) {
  5312. // color keywords
  5313. var hex = _colorKeywords[style];
  5314. if (hex !== undefined) {
  5315. // red
  5316. this.setHex(hex);
  5317. } else {
  5318. // unknown color
  5319. console.warn('THREE.Color: Unknown color ' + style);
  5320. }
  5321. return this;
  5322. };
  5323. _proto.clone = function clone() {
  5324. return new this.constructor(this.r, this.g, this.b);
  5325. };
  5326. _proto.copy = function copy(color) {
  5327. this.r = color.r;
  5328. this.g = color.g;
  5329. this.b = color.b;
  5330. return this;
  5331. };
  5332. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  5333. if (gammaFactor === undefined) gammaFactor = 2.0;
  5334. this.r = Math.pow(color.r, gammaFactor);
  5335. this.g = Math.pow(color.g, gammaFactor);
  5336. this.b = Math.pow(color.b, gammaFactor);
  5337. return this;
  5338. };
  5339. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  5340. if (gammaFactor === undefined) gammaFactor = 2.0;
  5341. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  5342. this.r = Math.pow(color.r, safeInverse);
  5343. this.g = Math.pow(color.g, safeInverse);
  5344. this.b = Math.pow(color.b, safeInverse);
  5345. return this;
  5346. };
  5347. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  5348. this.copyGammaToLinear(this, gammaFactor);
  5349. return this;
  5350. };
  5351. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  5352. this.copyLinearToGamma(this, gammaFactor);
  5353. return this;
  5354. };
  5355. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  5356. this.r = SRGBToLinear(color.r);
  5357. this.g = SRGBToLinear(color.g);
  5358. this.b = SRGBToLinear(color.b);
  5359. return this;
  5360. };
  5361. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  5362. this.r = LinearToSRGB(color.r);
  5363. this.g = LinearToSRGB(color.g);
  5364. this.b = LinearToSRGB(color.b);
  5365. return this;
  5366. };
  5367. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  5368. this.copySRGBToLinear(this);
  5369. return this;
  5370. };
  5371. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  5372. this.copyLinearToSRGB(this);
  5373. return this;
  5374. };
  5375. _proto.getHex = function getHex() {
  5376. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  5377. };
  5378. _proto.getHexString = function getHexString() {
  5379. return ('000000' + this.getHex().toString(16)).slice(-6);
  5380. };
  5381. _proto.getHSL = function getHSL(target) {
  5382. // h,s,l ranges are in 0.0 - 1.0
  5383. if (target === undefined) {
  5384. console.warn('THREE.Color: .getHSL() target is now required');
  5385. target = {
  5386. h: 0,
  5387. s: 0,
  5388. l: 0
  5389. };
  5390. }
  5391. var r = this.r,
  5392. g = this.g,
  5393. b = this.b;
  5394. var max = Math.max(r, g, b);
  5395. var min = Math.min(r, g, b);
  5396. var hue, saturation;
  5397. var lightness = (min + max) / 2.0;
  5398. if (min === max) {
  5399. hue = 0;
  5400. saturation = 0;
  5401. } else {
  5402. var delta = max - min;
  5403. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  5404. switch (max) {
  5405. case r:
  5406. hue = (g - b) / delta + (g < b ? 6 : 0);
  5407. break;
  5408. case g:
  5409. hue = (b - r) / delta + 2;
  5410. break;
  5411. case b:
  5412. hue = (r - g) / delta + 4;
  5413. break;
  5414. }
  5415. hue /= 6;
  5416. }
  5417. target.h = hue;
  5418. target.s = saturation;
  5419. target.l = lightness;
  5420. return target;
  5421. };
  5422. _proto.getStyle = function getStyle() {
  5423. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  5424. };
  5425. _proto.offsetHSL = function offsetHSL(h, s, l) {
  5426. this.getHSL(_hslA);
  5427. _hslA.h += h;
  5428. _hslA.s += s;
  5429. _hslA.l += l;
  5430. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  5431. return this;
  5432. };
  5433. _proto.add = function add(color) {
  5434. this.r += color.r;
  5435. this.g += color.g;
  5436. this.b += color.b;
  5437. return this;
  5438. };
  5439. _proto.addColors = function addColors(color1, color2) {
  5440. this.r = color1.r + color2.r;
  5441. this.g = color1.g + color2.g;
  5442. this.b = color1.b + color2.b;
  5443. return this;
  5444. };
  5445. _proto.addScalar = function addScalar(s) {
  5446. this.r += s;
  5447. this.g += s;
  5448. this.b += s;
  5449. return this;
  5450. };
  5451. _proto.sub = function sub(color) {
  5452. this.r = Math.max(0, this.r - color.r);
  5453. this.g = Math.max(0, this.g - color.g);
  5454. this.b = Math.max(0, this.b - color.b);
  5455. return this;
  5456. };
  5457. _proto.multiply = function multiply(color) {
  5458. this.r *= color.r;
  5459. this.g *= color.g;
  5460. this.b *= color.b;
  5461. return this;
  5462. };
  5463. _proto.multiplyScalar = function multiplyScalar(s) {
  5464. this.r *= s;
  5465. this.g *= s;
  5466. this.b *= s;
  5467. return this;
  5468. };
  5469. _proto.lerp = function lerp(color, alpha) {
  5470. this.r += (color.r - this.r) * alpha;
  5471. this.g += (color.g - this.g) * alpha;
  5472. this.b += (color.b - this.b) * alpha;
  5473. return this;
  5474. };
  5475. _proto.lerpHSL = function lerpHSL(color, alpha) {
  5476. this.getHSL(_hslA);
  5477. color.getHSL(_hslB);
  5478. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  5479. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  5480. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  5481. this.setHSL(h, s, l);
  5482. return this;
  5483. };
  5484. _proto.equals = function equals(c) {
  5485. return c.r === this.r && c.g === this.g && c.b === this.b;
  5486. };
  5487. _proto.fromArray = function fromArray(array, offset) {
  5488. if (offset === void 0) {
  5489. offset = 0;
  5490. }
  5491. this.r = array[offset];
  5492. this.g = array[offset + 1];
  5493. this.b = array[offset + 2];
  5494. return this;
  5495. };
  5496. _proto.toArray = function toArray(array, offset) {
  5497. if (array === void 0) {
  5498. array = [];
  5499. }
  5500. if (offset === void 0) {
  5501. offset = 0;
  5502. }
  5503. array[offset] = this.r;
  5504. array[offset + 1] = this.g;
  5505. array[offset + 2] = this.b;
  5506. return array;
  5507. };
  5508. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  5509. this.r = attribute.getX(index);
  5510. this.g = attribute.getY(index);
  5511. this.b = attribute.getZ(index);
  5512. if (attribute.normalized === true) {
  5513. // assuming Uint8Array
  5514. this.r /= 255;
  5515. this.g /= 255;
  5516. this.b /= 255;
  5517. }
  5518. return this;
  5519. };
  5520. _proto.toJSON = function toJSON() {
  5521. return this.getHex();
  5522. };
  5523. return Color;
  5524. }();
  5525. Color.NAMES = _colorKeywords;
  5526. Color.prototype.r = 1;
  5527. Color.prototype.g = 1;
  5528. Color.prototype.b = 1;
  5529. var Face3 = /*#__PURE__*/function () {
  5530. function Face3(a, b, c, normal, color, materialIndex) {
  5531. this.a = a;
  5532. this.b = b;
  5533. this.c = c;
  5534. this.normal = normal && normal.isVector3 ? normal : new Vector3();
  5535. this.vertexNormals = Array.isArray(normal) ? normal : [];
  5536. this.color = color && color.isColor ? color : new Color();
  5537. this.vertexColors = Array.isArray(color) ? color : [];
  5538. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5539. }
  5540. var _proto = Face3.prototype;
  5541. _proto.clone = function clone() {
  5542. return new this.constructor().copy(this);
  5543. };
  5544. _proto.copy = function copy(source) {
  5545. this.a = source.a;
  5546. this.b = source.b;
  5547. this.c = source.c;
  5548. this.normal.copy(source.normal);
  5549. this.color.copy(source.color);
  5550. this.materialIndex = source.materialIndex;
  5551. for (var i = 0, il = source.vertexNormals.length; i < il; i++) {
  5552. this.vertexNormals[i] = source.vertexNormals[i].clone();
  5553. }
  5554. for (var _i = 0, _il = source.vertexColors.length; _i < _il; _i++) {
  5555. this.vertexColors[_i] = source.vertexColors[_i].clone();
  5556. }
  5557. return this;
  5558. };
  5559. return Face3;
  5560. }();
  5561. var materialId = 0;
  5562. function Material() {
  5563. Object.defineProperty(this, 'id', {
  5564. value: materialId++
  5565. });
  5566. this.uuid = MathUtils.generateUUID();
  5567. this.name = '';
  5568. this.type = 'Material';
  5569. this.fog = true;
  5570. this.blending = NormalBlending;
  5571. this.side = FrontSide;
  5572. this.flatShading = false;
  5573. this.vertexColors = false;
  5574. this.opacity = 1;
  5575. this.transparent = false;
  5576. this.blendSrc = SrcAlphaFactor;
  5577. this.blendDst = OneMinusSrcAlphaFactor;
  5578. this.blendEquation = AddEquation;
  5579. this.blendSrcAlpha = null;
  5580. this.blendDstAlpha = null;
  5581. this.blendEquationAlpha = null;
  5582. this.depthFunc = LessEqualDepth;
  5583. this.depthTest = true;
  5584. this.depthWrite = true;
  5585. this.stencilWriteMask = 0xff;
  5586. this.stencilFunc = AlwaysStencilFunc;
  5587. this.stencilRef = 0;
  5588. this.stencilFuncMask = 0xff;
  5589. this.stencilFail = KeepStencilOp;
  5590. this.stencilZFail = KeepStencilOp;
  5591. this.stencilZPass = KeepStencilOp;
  5592. this.stencilWrite = false;
  5593. this.clippingPlanes = null;
  5594. this.clipIntersection = false;
  5595. this.clipShadows = false;
  5596. this.shadowSide = null;
  5597. this.colorWrite = true;
  5598. this.precision = null; // override the renderer's default precision for this material
  5599. this.polygonOffset = false;
  5600. this.polygonOffsetFactor = 0;
  5601. this.polygonOffsetUnits = 0;
  5602. this.dithering = false;
  5603. this.alphaTest = 0;
  5604. this.premultipliedAlpha = false;
  5605. this.visible = true;
  5606. this.toneMapped = true;
  5607. this.userData = {};
  5608. this.version = 0;
  5609. }
  5610. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5611. constructor: Material,
  5612. isMaterial: true,
  5613. onBeforeCompile: function onBeforeCompile()
  5614. /* shaderobject, renderer */
  5615. {},
  5616. customProgramCacheKey: function customProgramCacheKey() {
  5617. return this.onBeforeCompile.toString();
  5618. },
  5619. setValues: function setValues(values) {
  5620. if (values === undefined) return;
  5621. for (var key in values) {
  5622. var newValue = values[key];
  5623. if (newValue === undefined) {
  5624. console.warn("THREE.Material: '" + key + "' parameter is undefined.");
  5625. continue;
  5626. } // for backward compatability if shading is set in the constructor
  5627. if (key === 'shading') {
  5628. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  5629. this.flatShading = newValue === FlatShading ? true : false;
  5630. continue;
  5631. }
  5632. var currentValue = this[key];
  5633. if (currentValue === undefined) {
  5634. console.warn("THREE." + this.type + ": '" + key + "' is not a property of this material.");
  5635. continue;
  5636. }
  5637. if (currentValue && currentValue.isColor) {
  5638. currentValue.set(newValue);
  5639. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  5640. currentValue.copy(newValue);
  5641. } else {
  5642. this[key] = newValue;
  5643. }
  5644. }
  5645. },
  5646. toJSON: function toJSON(meta) {
  5647. var isRoot = meta === undefined || typeof meta === 'string';
  5648. if (isRoot) {
  5649. meta = {
  5650. textures: {},
  5651. images: {}
  5652. };
  5653. }
  5654. var data = {
  5655. metadata: {
  5656. version: 4.5,
  5657. type: 'Material',
  5658. generator: 'Material.toJSON'
  5659. }
  5660. }; // standard Material serialization
  5661. data.uuid = this.uuid;
  5662. data.type = this.type;
  5663. if (this.name !== '') data.name = this.name;
  5664. if (this.color && this.color.isColor) data.color = this.color.getHex();
  5665. if (this.roughness !== undefined) data.roughness = this.roughness;
  5666. if (this.metalness !== undefined) data.metalness = this.metalness;
  5667. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  5668. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  5669. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  5670. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  5671. if (this.shininess !== undefined) data.shininess = this.shininess;
  5672. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  5673. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  5674. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  5675. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  5676. }
  5677. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  5678. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  5679. }
  5680. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  5681. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  5682. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5683. }
  5684. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  5685. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  5686. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  5687. if (this.lightMap && this.lightMap.isTexture) data.lightMap = this.lightMap.toJSON(meta).uuid;
  5688. if (this.aoMap && this.aoMap.isTexture) {
  5689. data.aoMap = this.aoMap.toJSON(meta).uuid;
  5690. data.aoMapIntensity = this.aoMapIntensity;
  5691. }
  5692. if (this.bumpMap && this.bumpMap.isTexture) {
  5693. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  5694. data.bumpScale = this.bumpScale;
  5695. }
  5696. if (this.normalMap && this.normalMap.isTexture) {
  5697. data.normalMap = this.normalMap.toJSON(meta).uuid;
  5698. data.normalMapType = this.normalMapType;
  5699. data.normalScale = this.normalScale.toArray();
  5700. }
  5701. if (this.displacementMap && this.displacementMap.isTexture) {
  5702. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  5703. data.displacementScale = this.displacementScale;
  5704. data.displacementBias = this.displacementBias;
  5705. }
  5706. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  5707. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  5708. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  5709. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  5710. if (this.envMap && this.envMap.isTexture) {
  5711. data.envMap = this.envMap.toJSON(meta).uuid;
  5712. data.reflectivity = this.reflectivity; // Scale behind envMap
  5713. data.refractionRatio = this.refractionRatio;
  5714. if (this.combine !== undefined) data.combine = this.combine;
  5715. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  5716. }
  5717. if (this.gradientMap && this.gradientMap.isTexture) {
  5718. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  5719. }
  5720. if (this.size !== undefined) data.size = this.size;
  5721. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  5722. if (this.blending !== NormalBlending) data.blending = this.blending;
  5723. if (this.flatShading === true) data.flatShading = this.flatShading;
  5724. if (this.side !== FrontSide) data.side = this.side;
  5725. if (this.vertexColors) data.vertexColors = true;
  5726. if (this.opacity < 1) data.opacity = this.opacity;
  5727. if (this.transparent === true) data.transparent = this.transparent;
  5728. data.depthFunc = this.depthFunc;
  5729. data.depthTest = this.depthTest;
  5730. data.depthWrite = this.depthWrite;
  5731. data.stencilWrite = this.stencilWrite;
  5732. data.stencilWriteMask = this.stencilWriteMask;
  5733. data.stencilFunc = this.stencilFunc;
  5734. data.stencilRef = this.stencilRef;
  5735. data.stencilFuncMask = this.stencilFuncMask;
  5736. data.stencilFail = this.stencilFail;
  5737. data.stencilZFail = this.stencilZFail;
  5738. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  5739. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  5740. if (this.polygonOffset === true) data.polygonOffset = true;
  5741. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5742. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5743. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  5744. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  5745. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  5746. if (this.scale !== undefined) data.scale = this.scale;
  5747. if (this.dithering === true) data.dithering = true;
  5748. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  5749. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  5750. if (this.wireframe === true) data.wireframe = this.wireframe;
  5751. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  5752. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  5753. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  5754. if (this.morphTargets === true) data.morphTargets = true;
  5755. if (this.morphNormals === true) data.morphNormals = true;
  5756. if (this.skinning === true) data.skinning = true;
  5757. if (this.visible === false) data.visible = false;
  5758. if (this.toneMapped === false) data.toneMapped = false;
  5759. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  5760. function extractFromCache(cache) {
  5761. var values = [];
  5762. for (var key in cache) {
  5763. var _data = cache[key];
  5764. delete _data.metadata;
  5765. values.push(_data);
  5766. }
  5767. return values;
  5768. }
  5769. if (isRoot) {
  5770. var textures = extractFromCache(meta.textures);
  5771. var images = extractFromCache(meta.images);
  5772. if (textures.length > 0) data.textures = textures;
  5773. if (images.length > 0) data.images = images;
  5774. }
  5775. return data;
  5776. },
  5777. clone: function clone() {
  5778. return new this.constructor().copy(this);
  5779. },
  5780. copy: function copy(source) {
  5781. this.name = source.name;
  5782. this.fog = source.fog;
  5783. this.blending = source.blending;
  5784. this.side = source.side;
  5785. this.flatShading = source.flatShading;
  5786. this.vertexColors = source.vertexColors;
  5787. this.opacity = source.opacity;
  5788. this.transparent = source.transparent;
  5789. this.blendSrc = source.blendSrc;
  5790. this.blendDst = source.blendDst;
  5791. this.blendEquation = source.blendEquation;
  5792. this.blendSrcAlpha = source.blendSrcAlpha;
  5793. this.blendDstAlpha = source.blendDstAlpha;
  5794. this.blendEquationAlpha = source.blendEquationAlpha;
  5795. this.depthFunc = source.depthFunc;
  5796. this.depthTest = source.depthTest;
  5797. this.depthWrite = source.depthWrite;
  5798. this.stencilWriteMask = source.stencilWriteMask;
  5799. this.stencilFunc = source.stencilFunc;
  5800. this.stencilRef = source.stencilRef;
  5801. this.stencilFuncMask = source.stencilFuncMask;
  5802. this.stencilFail = source.stencilFail;
  5803. this.stencilZFail = source.stencilZFail;
  5804. this.stencilZPass = source.stencilZPass;
  5805. this.stencilWrite = source.stencilWrite;
  5806. var srcPlanes = source.clippingPlanes;
  5807. var dstPlanes = null;
  5808. if (srcPlanes !== null) {
  5809. var n = srcPlanes.length;
  5810. dstPlanes = new Array(n);
  5811. for (var i = 0; i !== n; ++i) {
  5812. dstPlanes[i] = srcPlanes[i].clone();
  5813. }
  5814. }
  5815. this.clippingPlanes = dstPlanes;
  5816. this.clipIntersection = source.clipIntersection;
  5817. this.clipShadows = source.clipShadows;
  5818. this.shadowSide = source.shadowSide;
  5819. this.colorWrite = source.colorWrite;
  5820. this.precision = source.precision;
  5821. this.polygonOffset = source.polygonOffset;
  5822. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5823. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5824. this.dithering = source.dithering;
  5825. this.alphaTest = source.alphaTest;
  5826. this.premultipliedAlpha = source.premultipliedAlpha;
  5827. this.visible = source.visible;
  5828. this.toneMapped = source.toneMapped;
  5829. this.userData = JSON.parse(JSON.stringify(source.userData));
  5830. return this;
  5831. },
  5832. dispose: function dispose() {
  5833. this.dispatchEvent({
  5834. type: 'dispose'
  5835. });
  5836. }
  5837. });
  5838. Object.defineProperty(Material.prototype, 'needsUpdate', {
  5839. set: function set(value) {
  5840. if (value === true) this.version++;
  5841. }
  5842. });
  5843. /**
  5844. * parameters = {
  5845. * color: <hex>,
  5846. * opacity: <float>,
  5847. * map: new THREE.Texture( <Image> ),
  5848. *
  5849. * lightMap: new THREE.Texture( <Image> ),
  5850. * lightMapIntensity: <float>
  5851. *
  5852. * aoMap: new THREE.Texture( <Image> ),
  5853. * aoMapIntensity: <float>
  5854. *
  5855. * specularMap: new THREE.Texture( <Image> ),
  5856. *
  5857. * alphaMap: new THREE.Texture( <Image> ),
  5858. *
  5859. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5860. * combine: THREE.Multiply,
  5861. * reflectivity: <float>,
  5862. * refractionRatio: <float>,
  5863. *
  5864. * depthTest: <bool>,
  5865. * depthWrite: <bool>,
  5866. *
  5867. * wireframe: <boolean>,
  5868. * wireframeLinewidth: <float>,
  5869. *
  5870. * skinning: <bool>,
  5871. * morphTargets: <bool>
  5872. * }
  5873. */
  5874. function MeshBasicMaterial(parameters) {
  5875. Material.call(this);
  5876. this.type = 'MeshBasicMaterial';
  5877. this.color = new Color(0xffffff); // emissive
  5878. this.map = null;
  5879. this.lightMap = null;
  5880. this.lightMapIntensity = 1.0;
  5881. this.aoMap = null;
  5882. this.aoMapIntensity = 1.0;
  5883. this.specularMap = null;
  5884. this.alphaMap = null;
  5885. this.envMap = null;
  5886. this.combine = MultiplyOperation;
  5887. this.reflectivity = 1;
  5888. this.refractionRatio = 0.98;
  5889. this.wireframe = false;
  5890. this.wireframeLinewidth = 1;
  5891. this.wireframeLinecap = 'round';
  5892. this.wireframeLinejoin = 'round';
  5893. this.skinning = false;
  5894. this.morphTargets = false;
  5895. this.setValues(parameters);
  5896. }
  5897. MeshBasicMaterial.prototype = Object.create(Material.prototype);
  5898. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5899. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5900. MeshBasicMaterial.prototype.copy = function (source) {
  5901. Material.prototype.copy.call(this, source);
  5902. this.color.copy(source.color);
  5903. this.map = source.map;
  5904. this.lightMap = source.lightMap;
  5905. this.lightMapIntensity = source.lightMapIntensity;
  5906. this.aoMap = source.aoMap;
  5907. this.aoMapIntensity = source.aoMapIntensity;
  5908. this.specularMap = source.specularMap;
  5909. this.alphaMap = source.alphaMap;
  5910. this.envMap = source.envMap;
  5911. this.combine = source.combine;
  5912. this.reflectivity = source.reflectivity;
  5913. this.refractionRatio = source.refractionRatio;
  5914. this.wireframe = source.wireframe;
  5915. this.wireframeLinewidth = source.wireframeLinewidth;
  5916. this.wireframeLinecap = source.wireframeLinecap;
  5917. this.wireframeLinejoin = source.wireframeLinejoin;
  5918. this.skinning = source.skinning;
  5919. this.morphTargets = source.morphTargets;
  5920. return this;
  5921. };
  5922. var _vector$3 = new Vector3();
  5923. var _vector2$1 = new Vector2();
  5924. function BufferAttribute(array, itemSize, normalized) {
  5925. if (Array.isArray(array)) {
  5926. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  5927. }
  5928. this.name = '';
  5929. this.array = array;
  5930. this.itemSize = itemSize;
  5931. this.count = array !== undefined ? array.length / itemSize : 0;
  5932. this.normalized = normalized === true;
  5933. this.usage = StaticDrawUsage;
  5934. this.updateRange = {
  5935. offset: 0,
  5936. count: -1
  5937. };
  5938. this.version = 0;
  5939. }
  5940. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  5941. set: function set(value) {
  5942. if (value === true) this.version++;
  5943. }
  5944. });
  5945. Object.assign(BufferAttribute.prototype, {
  5946. isBufferAttribute: true,
  5947. onUploadCallback: function onUploadCallback() {},
  5948. setUsage: function setUsage(value) {
  5949. this.usage = value;
  5950. return this;
  5951. },
  5952. copy: function copy(source) {
  5953. this.name = source.name;
  5954. this.array = new source.array.constructor(source.array);
  5955. this.itemSize = source.itemSize;
  5956. this.count = source.count;
  5957. this.normalized = source.normalized;
  5958. this.usage = source.usage;
  5959. return this;
  5960. },
  5961. copyAt: function copyAt(index1, attribute, index2) {
  5962. index1 *= this.itemSize;
  5963. index2 *= attribute.itemSize;
  5964. for (var i = 0, l = this.itemSize; i < l; i++) {
  5965. this.array[index1 + i] = attribute.array[index2 + i];
  5966. }
  5967. return this;
  5968. },
  5969. copyArray: function copyArray(array) {
  5970. this.array.set(array);
  5971. return this;
  5972. },
  5973. copyColorsArray: function copyColorsArray(colors) {
  5974. var array = this.array;
  5975. var offset = 0;
  5976. for (var i = 0, l = colors.length; i < l; i++) {
  5977. var color = colors[i];
  5978. if (color === undefined) {
  5979. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  5980. color = new Color();
  5981. }
  5982. array[offset++] = color.r;
  5983. array[offset++] = color.g;
  5984. array[offset++] = color.b;
  5985. }
  5986. return this;
  5987. },
  5988. copyVector2sArray: function copyVector2sArray(vectors) {
  5989. var array = this.array;
  5990. var offset = 0;
  5991. for (var i = 0, l = vectors.length; i < l; i++) {
  5992. var vector = vectors[i];
  5993. if (vector === undefined) {
  5994. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  5995. vector = new Vector2();
  5996. }
  5997. array[offset++] = vector.x;
  5998. array[offset++] = vector.y;
  5999. }
  6000. return this;
  6001. },
  6002. copyVector3sArray: function copyVector3sArray(vectors) {
  6003. var array = this.array;
  6004. var offset = 0;
  6005. for (var i = 0, l = vectors.length; i < l; i++) {
  6006. var vector = vectors[i];
  6007. if (vector === undefined) {
  6008. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  6009. vector = new Vector3();
  6010. }
  6011. array[offset++] = vector.x;
  6012. array[offset++] = vector.y;
  6013. array[offset++] = vector.z;
  6014. }
  6015. return this;
  6016. },
  6017. copyVector4sArray: function copyVector4sArray(vectors) {
  6018. var array = this.array;
  6019. var offset = 0;
  6020. for (var i = 0, l = vectors.length; i < l; i++) {
  6021. var vector = vectors[i];
  6022. if (vector === undefined) {
  6023. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  6024. vector = new Vector4();
  6025. }
  6026. array[offset++] = vector.x;
  6027. array[offset++] = vector.y;
  6028. array[offset++] = vector.z;
  6029. array[offset++] = vector.w;
  6030. }
  6031. return this;
  6032. },
  6033. applyMatrix3: function applyMatrix3(m) {
  6034. if (this.itemSize === 2) {
  6035. for (var i = 0, l = this.count; i < l; i++) {
  6036. _vector2$1.fromBufferAttribute(this, i);
  6037. _vector2$1.applyMatrix3(m);
  6038. this.setXY(i, _vector2$1.x, _vector2$1.y);
  6039. }
  6040. } else if (this.itemSize === 3) {
  6041. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  6042. _vector$3.fromBufferAttribute(this, _i);
  6043. _vector$3.applyMatrix3(m);
  6044. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  6045. }
  6046. }
  6047. return this;
  6048. },
  6049. applyMatrix4: function applyMatrix4(m) {
  6050. for (var i = 0, l = this.count; i < l; i++) {
  6051. _vector$3.x = this.getX(i);
  6052. _vector$3.y = this.getY(i);
  6053. _vector$3.z = this.getZ(i);
  6054. _vector$3.applyMatrix4(m);
  6055. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6056. }
  6057. return this;
  6058. },
  6059. applyNormalMatrix: function applyNormalMatrix(m) {
  6060. for (var i = 0, l = this.count; i < l; i++) {
  6061. _vector$3.x = this.getX(i);
  6062. _vector$3.y = this.getY(i);
  6063. _vector$3.z = this.getZ(i);
  6064. _vector$3.applyNormalMatrix(m);
  6065. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6066. }
  6067. return this;
  6068. },
  6069. transformDirection: function transformDirection(m) {
  6070. for (var i = 0, l = this.count; i < l; i++) {
  6071. _vector$3.x = this.getX(i);
  6072. _vector$3.y = this.getY(i);
  6073. _vector$3.z = this.getZ(i);
  6074. _vector$3.transformDirection(m);
  6075. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6076. }
  6077. return this;
  6078. },
  6079. set: function set(value, offset) {
  6080. if (offset === undefined) offset = 0;
  6081. this.array.set(value, offset);
  6082. return this;
  6083. },
  6084. getX: function getX(index) {
  6085. return this.array[index * this.itemSize];
  6086. },
  6087. setX: function setX(index, x) {
  6088. this.array[index * this.itemSize] = x;
  6089. return this;
  6090. },
  6091. getY: function getY(index) {
  6092. return this.array[index * this.itemSize + 1];
  6093. },
  6094. setY: function setY(index, y) {
  6095. this.array[index * this.itemSize + 1] = y;
  6096. return this;
  6097. },
  6098. getZ: function getZ(index) {
  6099. return this.array[index * this.itemSize + 2];
  6100. },
  6101. setZ: function setZ(index, z) {
  6102. this.array[index * this.itemSize + 2] = z;
  6103. return this;
  6104. },
  6105. getW: function getW(index) {
  6106. return this.array[index * this.itemSize + 3];
  6107. },
  6108. setW: function setW(index, w) {
  6109. this.array[index * this.itemSize + 3] = w;
  6110. return this;
  6111. },
  6112. setXY: function setXY(index, x, y) {
  6113. index *= this.itemSize;
  6114. this.array[index + 0] = x;
  6115. this.array[index + 1] = y;
  6116. return this;
  6117. },
  6118. setXYZ: function setXYZ(index, x, y, z) {
  6119. index *= this.itemSize;
  6120. this.array[index + 0] = x;
  6121. this.array[index + 1] = y;
  6122. this.array[index + 2] = z;
  6123. return this;
  6124. },
  6125. setXYZW: function setXYZW(index, x, y, z, w) {
  6126. index *= this.itemSize;
  6127. this.array[index + 0] = x;
  6128. this.array[index + 1] = y;
  6129. this.array[index + 2] = z;
  6130. this.array[index + 3] = w;
  6131. return this;
  6132. },
  6133. onUpload: function onUpload(callback) {
  6134. this.onUploadCallback = callback;
  6135. return this;
  6136. },
  6137. clone: function clone() {
  6138. return new this.constructor(this.array, this.itemSize).copy(this);
  6139. },
  6140. toJSON: function toJSON() {
  6141. return {
  6142. itemSize: this.itemSize,
  6143. type: this.array.constructor.name,
  6144. array: Array.prototype.slice.call(this.array),
  6145. normalized: this.normalized
  6146. };
  6147. }
  6148. }); //
  6149. function Int8BufferAttribute(array, itemSize, normalized) {
  6150. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6151. }
  6152. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6153. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6154. function Uint8BufferAttribute(array, itemSize, normalized) {
  6155. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6156. }
  6157. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6158. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6159. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6160. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6161. }
  6162. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6163. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6164. function Int16BufferAttribute(array, itemSize, normalized) {
  6165. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6166. }
  6167. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6168. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6169. function Uint16BufferAttribute(array, itemSize, normalized) {
  6170. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6171. }
  6172. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6173. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6174. function Int32BufferAttribute(array, itemSize, normalized) {
  6175. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6176. }
  6177. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6178. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6179. function Uint32BufferAttribute(array, itemSize, normalized) {
  6180. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6181. }
  6182. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6183. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6184. function Float32BufferAttribute(array, itemSize, normalized) {
  6185. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6186. }
  6187. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6188. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6189. function Float64BufferAttribute(array, itemSize, normalized) {
  6190. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6191. }
  6192. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6193. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  6194. var DirectGeometry = /*#__PURE__*/function () {
  6195. function DirectGeometry() {
  6196. this.vertices = [];
  6197. this.normals = [];
  6198. this.colors = [];
  6199. this.uvs = [];
  6200. this.uvs2 = [];
  6201. this.groups = [];
  6202. this.morphTargets = {};
  6203. this.skinWeights = [];
  6204. this.skinIndices = []; // this.lineDistances = [];
  6205. this.boundingBox = null;
  6206. this.boundingSphere = null; // update flags
  6207. this.verticesNeedUpdate = false;
  6208. this.normalsNeedUpdate = false;
  6209. this.colorsNeedUpdate = false;
  6210. this.uvsNeedUpdate = false;
  6211. this.groupsNeedUpdate = false;
  6212. }
  6213. var _proto = DirectGeometry.prototype;
  6214. _proto.computeGroups = function computeGroups(geometry) {
  6215. var groups = [];
  6216. var group, i;
  6217. var materialIndex = undefined;
  6218. var faces = geometry.faces;
  6219. for (i = 0; i < faces.length; i++) {
  6220. var face = faces[i]; // materials
  6221. if (face.materialIndex !== materialIndex) {
  6222. materialIndex = face.materialIndex;
  6223. if (group !== undefined) {
  6224. group.count = i * 3 - group.start;
  6225. groups.push(group);
  6226. }
  6227. group = {
  6228. start: i * 3,
  6229. materialIndex: materialIndex
  6230. };
  6231. }
  6232. }
  6233. if (group !== undefined) {
  6234. group.count = i * 3 - group.start;
  6235. groups.push(group);
  6236. }
  6237. this.groups = groups;
  6238. };
  6239. _proto.fromGeometry = function fromGeometry(geometry) {
  6240. var faces = geometry.faces;
  6241. var vertices = geometry.vertices;
  6242. var faceVertexUvs = geometry.faceVertexUvs;
  6243. var hasFaceVertexUv = faceVertexUvs[0] && faceVertexUvs[0].length > 0;
  6244. var hasFaceVertexUv2 = faceVertexUvs[1] && faceVertexUvs[1].length > 0; // morphs
  6245. var morphTargets = geometry.morphTargets;
  6246. var morphTargetsLength = morphTargets.length;
  6247. var morphTargetsPosition;
  6248. if (morphTargetsLength > 0) {
  6249. morphTargetsPosition = [];
  6250. for (var i = 0; i < morphTargetsLength; i++) {
  6251. morphTargetsPosition[i] = {
  6252. name: morphTargets[i].name,
  6253. data: []
  6254. };
  6255. }
  6256. this.morphTargets.position = morphTargetsPosition;
  6257. }
  6258. var morphNormals = geometry.morphNormals;
  6259. var morphNormalsLength = morphNormals.length;
  6260. var morphTargetsNormal;
  6261. if (morphNormalsLength > 0) {
  6262. morphTargetsNormal = [];
  6263. for (var _i = 0; _i < morphNormalsLength; _i++) {
  6264. morphTargetsNormal[_i] = {
  6265. name: morphNormals[_i].name,
  6266. data: []
  6267. };
  6268. }
  6269. this.morphTargets.normal = morphTargetsNormal;
  6270. } // skins
  6271. var skinIndices = geometry.skinIndices;
  6272. var skinWeights = geometry.skinWeights;
  6273. var hasSkinIndices = skinIndices.length === vertices.length;
  6274. var hasSkinWeights = skinWeights.length === vertices.length; //
  6275. if (vertices.length > 0 && faces.length === 0) {
  6276. console.error('THREE.DirectGeometry: Faceless geometries are not supported.');
  6277. }
  6278. for (var _i2 = 0; _i2 < faces.length; _i2++) {
  6279. var face = faces[_i2];
  6280. this.vertices.push(vertices[face.a], vertices[face.b], vertices[face.c]);
  6281. var vertexNormals = face.vertexNormals;
  6282. if (vertexNormals.length === 3) {
  6283. this.normals.push(vertexNormals[0], vertexNormals[1], vertexNormals[2]);
  6284. } else {
  6285. var normal = face.normal;
  6286. this.normals.push(normal, normal, normal);
  6287. }
  6288. var vertexColors = face.vertexColors;
  6289. if (vertexColors.length === 3) {
  6290. this.colors.push(vertexColors[0], vertexColors[1], vertexColors[2]);
  6291. } else {
  6292. var color = face.color;
  6293. this.colors.push(color, color, color);
  6294. }
  6295. if (hasFaceVertexUv === true) {
  6296. var vertexUvs = faceVertexUvs[0][_i2];
  6297. if (vertexUvs !== undefined) {
  6298. this.uvs.push(vertexUvs[0], vertexUvs[1], vertexUvs[2]);
  6299. } else {
  6300. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', _i2);
  6301. this.uvs.push(new Vector2(), new Vector2(), new Vector2());
  6302. }
  6303. }
  6304. if (hasFaceVertexUv2 === true) {
  6305. var _vertexUvs = faceVertexUvs[1][_i2];
  6306. if (_vertexUvs !== undefined) {
  6307. this.uvs2.push(_vertexUvs[0], _vertexUvs[1], _vertexUvs[2]);
  6308. } else {
  6309. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', _i2);
  6310. this.uvs2.push(new Vector2(), new Vector2(), new Vector2());
  6311. }
  6312. } // morphs
  6313. for (var j = 0; j < morphTargetsLength; j++) {
  6314. var morphTarget = morphTargets[j].vertices;
  6315. morphTargetsPosition[j].data.push(morphTarget[face.a], morphTarget[face.b], morphTarget[face.c]);
  6316. }
  6317. for (var _j = 0; _j < morphNormalsLength; _j++) {
  6318. var morphNormal = morphNormals[_j].vertexNormals[_i2];
  6319. morphTargetsNormal[_j].data.push(morphNormal.a, morphNormal.b, morphNormal.c);
  6320. } // skins
  6321. if (hasSkinIndices) {
  6322. this.skinIndices.push(skinIndices[face.a], skinIndices[face.b], skinIndices[face.c]);
  6323. }
  6324. if (hasSkinWeights) {
  6325. this.skinWeights.push(skinWeights[face.a], skinWeights[face.b], skinWeights[face.c]);
  6326. }
  6327. }
  6328. this.computeGroups(geometry);
  6329. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6330. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6331. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6332. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6333. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6334. if (geometry.boundingSphere !== null) {
  6335. this.boundingSphere = geometry.boundingSphere.clone();
  6336. }
  6337. if (geometry.boundingBox !== null) {
  6338. this.boundingBox = geometry.boundingBox.clone();
  6339. }
  6340. return this;
  6341. };
  6342. return DirectGeometry;
  6343. }();
  6344. function arrayMax(array) {
  6345. if (array.length === 0) return -Infinity;
  6346. var max = array[0];
  6347. for (var i = 1, l = array.length; i < l; ++i) {
  6348. if (array[i] > max) max = array[i];
  6349. }
  6350. return max;
  6351. }
  6352. var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6353. var _m1$2 = new Matrix4();
  6354. var _obj = new Object3D();
  6355. var _offset = new Vector3();
  6356. var _box$2 = new Box3();
  6357. var _boxMorphTargets = new Box3();
  6358. var _vector$4 = new Vector3();
  6359. function BufferGeometry() {
  6360. Object.defineProperty(this, 'id', {
  6361. value: _bufferGeometryId += 2
  6362. });
  6363. this.uuid = MathUtils.generateUUID();
  6364. this.name = '';
  6365. this.type = 'BufferGeometry';
  6366. this.index = null;
  6367. this.attributes = {};
  6368. this.morphAttributes = {};
  6369. this.morphTargetsRelative = false;
  6370. this.groups = [];
  6371. this.boundingBox = null;
  6372. this.boundingSphere = null;
  6373. this.drawRange = {
  6374. start: 0,
  6375. count: Infinity
  6376. };
  6377. this.userData = {};
  6378. }
  6379. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  6380. constructor: BufferGeometry,
  6381. isBufferGeometry: true,
  6382. getIndex: function getIndex() {
  6383. return this.index;
  6384. },
  6385. setIndex: function setIndex(index) {
  6386. if (Array.isArray(index)) {
  6387. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  6388. } else {
  6389. this.index = index;
  6390. }
  6391. return this;
  6392. },
  6393. getAttribute: function getAttribute(name) {
  6394. return this.attributes[name];
  6395. },
  6396. setAttribute: function setAttribute(name, attribute) {
  6397. this.attributes[name] = attribute;
  6398. return this;
  6399. },
  6400. deleteAttribute: function deleteAttribute(name) {
  6401. delete this.attributes[name];
  6402. return this;
  6403. },
  6404. addGroup: function addGroup(start, count, materialIndex) {
  6405. this.groups.push({
  6406. start: start,
  6407. count: count,
  6408. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6409. });
  6410. },
  6411. clearGroups: function clearGroups() {
  6412. this.groups = [];
  6413. },
  6414. setDrawRange: function setDrawRange(start, count) {
  6415. this.drawRange.start = start;
  6416. this.drawRange.count = count;
  6417. },
  6418. applyMatrix4: function applyMatrix4(matrix) {
  6419. var position = this.attributes.position;
  6420. if (position !== undefined) {
  6421. position.applyMatrix4(matrix);
  6422. position.needsUpdate = true;
  6423. }
  6424. var normal = this.attributes.normal;
  6425. if (normal !== undefined) {
  6426. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  6427. normal.applyNormalMatrix(normalMatrix);
  6428. normal.needsUpdate = true;
  6429. }
  6430. var tangent = this.attributes.tangent;
  6431. if (tangent !== undefined) {
  6432. tangent.transformDirection(matrix);
  6433. tangent.needsUpdate = true;
  6434. }
  6435. if (this.boundingBox !== null) {
  6436. this.computeBoundingBox();
  6437. }
  6438. if (this.boundingSphere !== null) {
  6439. this.computeBoundingSphere();
  6440. }
  6441. return this;
  6442. },
  6443. rotateX: function rotateX(angle) {
  6444. // rotate geometry around world x-axis
  6445. _m1$2.makeRotationX(angle);
  6446. this.applyMatrix4(_m1$2);
  6447. return this;
  6448. },
  6449. rotateY: function rotateY(angle) {
  6450. // rotate geometry around world y-axis
  6451. _m1$2.makeRotationY(angle);
  6452. this.applyMatrix4(_m1$2);
  6453. return this;
  6454. },
  6455. rotateZ: function rotateZ(angle) {
  6456. // rotate geometry around world z-axis
  6457. _m1$2.makeRotationZ(angle);
  6458. this.applyMatrix4(_m1$2);
  6459. return this;
  6460. },
  6461. translate: function translate(x, y, z) {
  6462. // translate geometry
  6463. _m1$2.makeTranslation(x, y, z);
  6464. this.applyMatrix4(_m1$2);
  6465. return this;
  6466. },
  6467. scale: function scale(x, y, z) {
  6468. // scale geometry
  6469. _m1$2.makeScale(x, y, z);
  6470. this.applyMatrix4(_m1$2);
  6471. return this;
  6472. },
  6473. lookAt: function lookAt(vector) {
  6474. _obj.lookAt(vector);
  6475. _obj.updateMatrix();
  6476. this.applyMatrix4(_obj.matrix);
  6477. return this;
  6478. },
  6479. center: function center() {
  6480. this.computeBoundingBox();
  6481. this.boundingBox.getCenter(_offset).negate();
  6482. this.translate(_offset.x, _offset.y, _offset.z);
  6483. return this;
  6484. },
  6485. setFromObject: function setFromObject(object) {
  6486. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6487. var geometry = object.geometry;
  6488. if (object.isPoints || object.isLine) {
  6489. var positions = new Float32BufferAttribute(geometry.vertices.length * 3, 3);
  6490. var colors = new Float32BufferAttribute(geometry.colors.length * 3, 3);
  6491. this.setAttribute('position', positions.copyVector3sArray(geometry.vertices));
  6492. this.setAttribute('color', colors.copyColorsArray(geometry.colors));
  6493. if (geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length) {
  6494. var lineDistances = new Float32BufferAttribute(geometry.lineDistances.length, 1);
  6495. this.setAttribute('lineDistance', lineDistances.copyArray(geometry.lineDistances));
  6496. }
  6497. if (geometry.boundingSphere !== null) {
  6498. this.boundingSphere = geometry.boundingSphere.clone();
  6499. }
  6500. if (geometry.boundingBox !== null) {
  6501. this.boundingBox = geometry.boundingBox.clone();
  6502. }
  6503. } else if (object.isMesh) {
  6504. if (geometry && geometry.isGeometry) {
  6505. this.fromGeometry(geometry);
  6506. }
  6507. }
  6508. return this;
  6509. },
  6510. setFromPoints: function setFromPoints(points) {
  6511. var position = [];
  6512. for (var i = 0, l = points.length; i < l; i++) {
  6513. var point = points[i];
  6514. position.push(point.x, point.y, point.z || 0);
  6515. }
  6516. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  6517. return this;
  6518. },
  6519. updateFromObject: function updateFromObject(object) {
  6520. var geometry = object.geometry;
  6521. if (object.isMesh) {
  6522. var direct = geometry.__directGeometry;
  6523. if (geometry.elementsNeedUpdate === true) {
  6524. direct = undefined;
  6525. geometry.elementsNeedUpdate = false;
  6526. }
  6527. if (direct === undefined) {
  6528. return this.fromGeometry(geometry);
  6529. }
  6530. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6531. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6532. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6533. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6534. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6535. geometry.verticesNeedUpdate = false;
  6536. geometry.normalsNeedUpdate = false;
  6537. geometry.colorsNeedUpdate = false;
  6538. geometry.uvsNeedUpdate = false;
  6539. geometry.groupsNeedUpdate = false;
  6540. geometry = direct;
  6541. }
  6542. if (geometry.verticesNeedUpdate === true) {
  6543. var attribute = this.attributes.position;
  6544. if (attribute !== undefined) {
  6545. attribute.copyVector3sArray(geometry.vertices);
  6546. attribute.needsUpdate = true;
  6547. }
  6548. geometry.verticesNeedUpdate = false;
  6549. }
  6550. if (geometry.normalsNeedUpdate === true) {
  6551. var _attribute = this.attributes.normal;
  6552. if (_attribute !== undefined) {
  6553. _attribute.copyVector3sArray(geometry.normals);
  6554. _attribute.needsUpdate = true;
  6555. }
  6556. geometry.normalsNeedUpdate = false;
  6557. }
  6558. if (geometry.colorsNeedUpdate === true) {
  6559. var _attribute2 = this.attributes.color;
  6560. if (_attribute2 !== undefined) {
  6561. _attribute2.copyColorsArray(geometry.colors);
  6562. _attribute2.needsUpdate = true;
  6563. }
  6564. geometry.colorsNeedUpdate = false;
  6565. }
  6566. if (geometry.uvsNeedUpdate) {
  6567. var _attribute3 = this.attributes.uv;
  6568. if (_attribute3 !== undefined) {
  6569. _attribute3.copyVector2sArray(geometry.uvs);
  6570. _attribute3.needsUpdate = true;
  6571. }
  6572. geometry.uvsNeedUpdate = false;
  6573. }
  6574. if (geometry.lineDistancesNeedUpdate) {
  6575. var _attribute4 = this.attributes.lineDistance;
  6576. if (_attribute4 !== undefined) {
  6577. _attribute4.copyArray(geometry.lineDistances);
  6578. _attribute4.needsUpdate = true;
  6579. }
  6580. geometry.lineDistancesNeedUpdate = false;
  6581. }
  6582. if (geometry.groupsNeedUpdate) {
  6583. geometry.computeGroups(object.geometry);
  6584. this.groups = geometry.groups;
  6585. geometry.groupsNeedUpdate = false;
  6586. }
  6587. return this;
  6588. },
  6589. fromGeometry: function fromGeometry(geometry) {
  6590. geometry.__directGeometry = new DirectGeometry().fromGeometry(geometry);
  6591. return this.fromDirectGeometry(geometry.__directGeometry);
  6592. },
  6593. fromDirectGeometry: function fromDirectGeometry(geometry) {
  6594. var positions = new Float32Array(geometry.vertices.length * 3);
  6595. this.setAttribute('position', new BufferAttribute(positions, 3).copyVector3sArray(geometry.vertices));
  6596. if (geometry.normals.length > 0) {
  6597. var normals = new Float32Array(geometry.normals.length * 3);
  6598. this.setAttribute('normal', new BufferAttribute(normals, 3).copyVector3sArray(geometry.normals));
  6599. }
  6600. if (geometry.colors.length > 0) {
  6601. var colors = new Float32Array(geometry.colors.length * 3);
  6602. this.setAttribute('color', new BufferAttribute(colors, 3).copyColorsArray(geometry.colors));
  6603. }
  6604. if (geometry.uvs.length > 0) {
  6605. var uvs = new Float32Array(geometry.uvs.length * 2);
  6606. this.setAttribute('uv', new BufferAttribute(uvs, 2).copyVector2sArray(geometry.uvs));
  6607. }
  6608. if (geometry.uvs2.length > 0) {
  6609. var uvs2 = new Float32Array(geometry.uvs2.length * 2);
  6610. this.setAttribute('uv2', new BufferAttribute(uvs2, 2).copyVector2sArray(geometry.uvs2));
  6611. } // groups
  6612. this.groups = geometry.groups; // morphs
  6613. for (var name in geometry.morphTargets) {
  6614. var array = [];
  6615. var morphTargets = geometry.morphTargets[name];
  6616. for (var i = 0, l = morphTargets.length; i < l; i++) {
  6617. var morphTarget = morphTargets[i];
  6618. var attribute = new Float32BufferAttribute(morphTarget.data.length * 3, 3);
  6619. attribute.name = morphTarget.name;
  6620. array.push(attribute.copyVector3sArray(morphTarget.data));
  6621. }
  6622. this.morphAttributes[name] = array;
  6623. } // skinning
  6624. if (geometry.skinIndices.length > 0) {
  6625. var skinIndices = new Float32BufferAttribute(geometry.skinIndices.length * 4, 4);
  6626. this.setAttribute('skinIndex', skinIndices.copyVector4sArray(geometry.skinIndices));
  6627. }
  6628. if (geometry.skinWeights.length > 0) {
  6629. var skinWeights = new Float32BufferAttribute(geometry.skinWeights.length * 4, 4);
  6630. this.setAttribute('skinWeight', skinWeights.copyVector4sArray(geometry.skinWeights));
  6631. } //
  6632. if (geometry.boundingSphere !== null) {
  6633. this.boundingSphere = geometry.boundingSphere.clone();
  6634. }
  6635. if (geometry.boundingBox !== null) {
  6636. this.boundingBox = geometry.boundingBox.clone();
  6637. }
  6638. return this;
  6639. },
  6640. computeBoundingBox: function computeBoundingBox() {
  6641. if (this.boundingBox === null) {
  6642. this.boundingBox = new Box3();
  6643. }
  6644. var position = this.attributes.position;
  6645. var morphAttributesPosition = this.morphAttributes.position;
  6646. if (position && position.isGLBufferAttribute) {
  6647. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  6648. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  6649. return;
  6650. }
  6651. if (position !== undefined) {
  6652. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  6653. if (morphAttributesPosition) {
  6654. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6655. var morphAttribute = morphAttributesPosition[i];
  6656. _box$2.setFromBufferAttribute(morphAttribute);
  6657. if (this.morphTargetsRelative) {
  6658. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  6659. this.boundingBox.expandByPoint(_vector$4);
  6660. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  6661. this.boundingBox.expandByPoint(_vector$4);
  6662. } else {
  6663. this.boundingBox.expandByPoint(_box$2.min);
  6664. this.boundingBox.expandByPoint(_box$2.max);
  6665. }
  6666. }
  6667. }
  6668. } else {
  6669. this.boundingBox.makeEmpty();
  6670. }
  6671. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  6672. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  6673. }
  6674. },
  6675. computeBoundingSphere: function computeBoundingSphere() {
  6676. if (this.boundingSphere === null) {
  6677. this.boundingSphere = new Sphere();
  6678. }
  6679. var position = this.attributes.position;
  6680. var morphAttributesPosition = this.morphAttributes.position;
  6681. if (position && position.isGLBufferAttribute) {
  6682. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  6683. this.boundingSphere.set(new Vector3(), Infinity);
  6684. return;
  6685. }
  6686. if (position) {
  6687. // first, find the center of the bounding sphere
  6688. var center = this.boundingSphere.center;
  6689. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  6690. if (morphAttributesPosition) {
  6691. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6692. var morphAttribute = morphAttributesPosition[i];
  6693. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  6694. if (this.morphTargetsRelative) {
  6695. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  6696. _box$2.expandByPoint(_vector$4);
  6697. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  6698. _box$2.expandByPoint(_vector$4);
  6699. } else {
  6700. _box$2.expandByPoint(_boxMorphTargets.min);
  6701. _box$2.expandByPoint(_boxMorphTargets.max);
  6702. }
  6703. }
  6704. }
  6705. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  6706. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6707. var maxRadiusSq = 0;
  6708. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  6709. _vector$4.fromBufferAttribute(position, _i);
  6710. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6711. } // process morph attributes if present
  6712. if (morphAttributesPosition) {
  6713. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  6714. var _morphAttribute = morphAttributesPosition[_i2];
  6715. var morphTargetsRelative = this.morphTargetsRelative;
  6716. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  6717. _vector$4.fromBufferAttribute(_morphAttribute, j);
  6718. if (morphTargetsRelative) {
  6719. _offset.fromBufferAttribute(position, j);
  6720. _vector$4.add(_offset);
  6721. }
  6722. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6723. }
  6724. }
  6725. }
  6726. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  6727. if (isNaN(this.boundingSphere.radius)) {
  6728. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  6729. }
  6730. }
  6731. },
  6732. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  6733. },
  6734. computeVertexNormals: function computeVertexNormals() {
  6735. var index = this.index;
  6736. var positionAttribute = this.getAttribute('position');
  6737. if (positionAttribute !== undefined) {
  6738. var normalAttribute = this.getAttribute('normal');
  6739. if (normalAttribute === undefined) {
  6740. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  6741. this.setAttribute('normal', normalAttribute);
  6742. } else {
  6743. // reset existing normals to zero
  6744. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  6745. normalAttribute.setXYZ(i, 0, 0, 0);
  6746. }
  6747. }
  6748. var pA = new Vector3(),
  6749. pB = new Vector3(),
  6750. pC = new Vector3();
  6751. var nA = new Vector3(),
  6752. nB = new Vector3(),
  6753. nC = new Vector3();
  6754. var cb = new Vector3(),
  6755. ab = new Vector3(); // indexed elements
  6756. if (index) {
  6757. for (var _i3 = 0, _il3 = index.count; _i3 < _il3; _i3 += 3) {
  6758. var vA = index.getX(_i3 + 0);
  6759. var vB = index.getX(_i3 + 1);
  6760. var vC = index.getX(_i3 + 2);
  6761. pA.fromBufferAttribute(positionAttribute, vA);
  6762. pB.fromBufferAttribute(positionAttribute, vB);
  6763. pC.fromBufferAttribute(positionAttribute, vC);
  6764. cb.subVectors(pC, pB);
  6765. ab.subVectors(pA, pB);
  6766. cb.cross(ab);
  6767. nA.fromBufferAttribute(normalAttribute, vA);
  6768. nB.fromBufferAttribute(normalAttribute, vB);
  6769. nC.fromBufferAttribute(normalAttribute, vC);
  6770. nA.add(cb);
  6771. nB.add(cb);
  6772. nC.add(cb);
  6773. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  6774. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  6775. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  6776. }
  6777. } else {
  6778. // non-indexed elements (unconnected triangle soup)
  6779. for (var _i4 = 0, _il4 = positionAttribute.count; _i4 < _il4; _i4 += 3) {
  6780. pA.fromBufferAttribute(positionAttribute, _i4 + 0);
  6781. pB.fromBufferAttribute(positionAttribute, _i4 + 1);
  6782. pC.fromBufferAttribute(positionAttribute, _i4 + 2);
  6783. cb.subVectors(pC, pB);
  6784. ab.subVectors(pA, pB);
  6785. cb.cross(ab);
  6786. normalAttribute.setXYZ(_i4 + 0, cb.x, cb.y, cb.z);
  6787. normalAttribute.setXYZ(_i4 + 1, cb.x, cb.y, cb.z);
  6788. normalAttribute.setXYZ(_i4 + 2, cb.x, cb.y, cb.z);
  6789. }
  6790. }
  6791. this.normalizeNormals();
  6792. normalAttribute.needsUpdate = true;
  6793. }
  6794. },
  6795. merge: function merge(geometry, offset) {
  6796. if (!(geometry && geometry.isBufferGeometry)) {
  6797. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  6798. return;
  6799. }
  6800. if (offset === undefined) {
  6801. offset = 0;
  6802. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  6803. }
  6804. var attributes = this.attributes;
  6805. for (var key in attributes) {
  6806. if (geometry.attributes[key] === undefined) continue;
  6807. var attribute1 = attributes[key];
  6808. var attributeArray1 = attribute1.array;
  6809. var attribute2 = geometry.attributes[key];
  6810. var attributeArray2 = attribute2.array;
  6811. var attributeOffset = attribute2.itemSize * offset;
  6812. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  6813. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  6814. attributeArray1[j] = attributeArray2[i];
  6815. }
  6816. }
  6817. return this;
  6818. },
  6819. normalizeNormals: function normalizeNormals() {
  6820. var normals = this.attributes.normal;
  6821. for (var i = 0, il = normals.count; i < il; i++) {
  6822. _vector$4.fromBufferAttribute(normals, i);
  6823. _vector$4.normalize();
  6824. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  6825. }
  6826. },
  6827. toNonIndexed: function toNonIndexed() {
  6828. function convertBufferAttribute(attribute, indices) {
  6829. var array = attribute.array;
  6830. var itemSize = attribute.itemSize;
  6831. var normalized = attribute.normalized;
  6832. var array2 = new array.constructor(indices.length * itemSize);
  6833. var index = 0,
  6834. index2 = 0;
  6835. for (var i = 0, l = indices.length; i < l; i++) {
  6836. index = indices[i] * itemSize;
  6837. for (var j = 0; j < itemSize; j++) {
  6838. array2[index2++] = array[index++];
  6839. }
  6840. }
  6841. return new BufferAttribute(array2, itemSize, normalized);
  6842. } //
  6843. if (this.index === null) {
  6844. console.warn('THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.');
  6845. return this;
  6846. }
  6847. var geometry2 = new BufferGeometry();
  6848. var indices = this.index.array;
  6849. var attributes = this.attributes; // attributes
  6850. for (var name in attributes) {
  6851. var attribute = attributes[name];
  6852. var newAttribute = convertBufferAttribute(attribute, indices);
  6853. geometry2.setAttribute(name, newAttribute);
  6854. } // morph attributes
  6855. var morphAttributes = this.morphAttributes;
  6856. for (var _name in morphAttributes) {
  6857. var morphArray = [];
  6858. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  6859. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  6860. var _attribute5 = morphAttribute[i];
  6861. var _newAttribute = convertBufferAttribute(_attribute5, indices);
  6862. morphArray.push(_newAttribute);
  6863. }
  6864. geometry2.morphAttributes[_name] = morphArray;
  6865. }
  6866. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  6867. var groups = this.groups;
  6868. for (var _i5 = 0, l = groups.length; _i5 < l; _i5++) {
  6869. var group = groups[_i5];
  6870. geometry2.addGroup(group.start, group.count, group.materialIndex);
  6871. }
  6872. return geometry2;
  6873. },
  6874. toJSON: function toJSON() {
  6875. var data = {
  6876. metadata: {
  6877. version: 4.5,
  6878. type: 'BufferGeometry',
  6879. generator: 'BufferGeometry.toJSON'
  6880. }
  6881. }; // standard BufferGeometry serialization
  6882. data.uuid = this.uuid;
  6883. data.type = this.type;
  6884. if (this.name !== '') data.name = this.name;
  6885. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  6886. if (this.parameters !== undefined) {
  6887. var parameters = this.parameters;
  6888. for (var key in parameters) {
  6889. if (parameters[key] !== undefined) data[key] = parameters[key];
  6890. }
  6891. return data;
  6892. }
  6893. data.data = {
  6894. attributes: {}
  6895. };
  6896. var index = this.index;
  6897. if (index !== null) {
  6898. data.data.index = {
  6899. type: index.array.constructor.name,
  6900. array: Array.prototype.slice.call(index.array)
  6901. };
  6902. }
  6903. var attributes = this.attributes;
  6904. for (var _key in attributes) {
  6905. var attribute = attributes[_key];
  6906. var attributeData = attribute.toJSON(data.data);
  6907. if (attribute.name !== '') attributeData.name = attribute.name;
  6908. data.data.attributes[_key] = attributeData;
  6909. }
  6910. var morphAttributes = {};
  6911. var hasMorphAttributes = false;
  6912. for (var _key2 in this.morphAttributes) {
  6913. var attributeArray = this.morphAttributes[_key2];
  6914. var array = [];
  6915. for (var i = 0, il = attributeArray.length; i < il; i++) {
  6916. var _attribute6 = attributeArray[i];
  6917. var _attributeData = _attribute6.toJSON(data.data);
  6918. if (_attribute6.name !== '') _attributeData.name = _attribute6.name;
  6919. array.push(_attributeData);
  6920. }
  6921. if (array.length > 0) {
  6922. morphAttributes[_key2] = array;
  6923. hasMorphAttributes = true;
  6924. }
  6925. }
  6926. if (hasMorphAttributes) {
  6927. data.data.morphAttributes = morphAttributes;
  6928. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6929. }
  6930. var groups = this.groups;
  6931. if (groups.length > 0) {
  6932. data.data.groups = JSON.parse(JSON.stringify(groups));
  6933. }
  6934. var boundingSphere = this.boundingSphere;
  6935. if (boundingSphere !== null) {
  6936. data.data.boundingSphere = {
  6937. center: boundingSphere.center.toArray(),
  6938. radius: boundingSphere.radius
  6939. };
  6940. }
  6941. return data;
  6942. },
  6943. clone: function clone() {
  6944. /*
  6945. // Handle primitives
  6946. const parameters = this.parameters;
  6947. if ( parameters !== undefined ) {
  6948. const values = [];
  6949. for ( const key in parameters ) {
  6950. values.push( parameters[ key ] );
  6951. }
  6952. const geometry = Object.create( this.constructor.prototype );
  6953. this.constructor.apply( geometry, values );
  6954. return geometry;
  6955. }
  6956. return new this.constructor().copy( this );
  6957. */
  6958. return new BufferGeometry().copy(this);
  6959. },
  6960. copy: function copy(source) {
  6961. // reset
  6962. this.index = null;
  6963. this.attributes = {};
  6964. this.morphAttributes = {};
  6965. this.groups = [];
  6966. this.boundingBox = null;
  6967. this.boundingSphere = null; // used for storing cloned, shared data
  6968. var data = {}; // name
  6969. this.name = source.name; // index
  6970. var index = source.index;
  6971. if (index !== null) {
  6972. this.setIndex(index.clone(data));
  6973. } // attributes
  6974. var attributes = source.attributes;
  6975. for (var name in attributes) {
  6976. var attribute = attributes[name];
  6977. this.setAttribute(name, attribute.clone(data));
  6978. } // morph attributes
  6979. var morphAttributes = source.morphAttributes;
  6980. for (var _name2 in morphAttributes) {
  6981. var array = [];
  6982. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  6983. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  6984. array.push(morphAttribute[i].clone(data));
  6985. }
  6986. this.morphAttributes[_name2] = array;
  6987. }
  6988. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  6989. var groups = source.groups;
  6990. for (var _i6 = 0, _l = groups.length; _i6 < _l; _i6++) {
  6991. var group = groups[_i6];
  6992. this.addGroup(group.start, group.count, group.materialIndex);
  6993. } // bounding box
  6994. var boundingBox = source.boundingBox;
  6995. if (boundingBox !== null) {
  6996. this.boundingBox = boundingBox.clone();
  6997. } // bounding sphere
  6998. var boundingSphere = source.boundingSphere;
  6999. if (boundingSphere !== null) {
  7000. this.boundingSphere = boundingSphere.clone();
  7001. } // draw range
  7002. this.drawRange.start = source.drawRange.start;
  7003. this.drawRange.count = source.drawRange.count; // user data
  7004. this.userData = source.userData;
  7005. return this;
  7006. },
  7007. dispose: function dispose() {
  7008. this.dispatchEvent({
  7009. type: 'dispose'
  7010. });
  7011. }
  7012. });
  7013. var _inverseMatrix = new Matrix4();
  7014. var _ray = new Ray();
  7015. var _sphere = new Sphere();
  7016. var _vA = new Vector3();
  7017. var _vB = new Vector3();
  7018. var _vC = new Vector3();
  7019. var _tempA = new Vector3();
  7020. var _tempB = new Vector3();
  7021. var _tempC = new Vector3();
  7022. var _morphA = new Vector3();
  7023. var _morphB = new Vector3();
  7024. var _morphC = new Vector3();
  7025. var _uvA = new Vector2();
  7026. var _uvB = new Vector2();
  7027. var _uvC = new Vector2();
  7028. var _intersectionPoint = new Vector3();
  7029. var _intersectionPointWorld = new Vector3();
  7030. function Mesh(geometry, material) {
  7031. Object3D.call(this);
  7032. this.type = 'Mesh';
  7033. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  7034. this.material = material !== undefined ? material : new MeshBasicMaterial();
  7035. this.updateMorphTargets();
  7036. }
  7037. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7038. constructor: Mesh,
  7039. isMesh: true,
  7040. copy: function copy(source) {
  7041. Object3D.prototype.copy.call(this, source);
  7042. if (source.morphTargetInfluences !== undefined) {
  7043. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7044. }
  7045. if (source.morphTargetDictionary !== undefined) {
  7046. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7047. }
  7048. this.material = source.material;
  7049. this.geometry = source.geometry;
  7050. return this;
  7051. },
  7052. updateMorphTargets: function updateMorphTargets() {
  7053. var geometry = this.geometry;
  7054. if (geometry.isBufferGeometry) {
  7055. var morphAttributes = geometry.morphAttributes;
  7056. var keys = Object.keys(morphAttributes);
  7057. if (keys.length > 0) {
  7058. var morphAttribute = morphAttributes[keys[0]];
  7059. if (morphAttribute !== undefined) {
  7060. this.morphTargetInfluences = [];
  7061. this.morphTargetDictionary = {};
  7062. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7063. var name = morphAttribute[m].name || String(m);
  7064. this.morphTargetInfluences.push(0);
  7065. this.morphTargetDictionary[name] = m;
  7066. }
  7067. }
  7068. }
  7069. } else {
  7070. var morphTargets = geometry.morphTargets;
  7071. if (morphTargets !== undefined && morphTargets.length > 0) {
  7072. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7073. }
  7074. }
  7075. },
  7076. raycast: function raycast(raycaster, intersects) {
  7077. var geometry = this.geometry;
  7078. var material = this.material;
  7079. var matrixWorld = this.matrixWorld;
  7080. if (material === undefined) return; // Checking boundingSphere distance to ray
  7081. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7082. _sphere.copy(geometry.boundingSphere);
  7083. _sphere.applyMatrix4(matrixWorld);
  7084. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7085. _inverseMatrix.getInverse(matrixWorld);
  7086. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7087. if (geometry.boundingBox !== null) {
  7088. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7089. }
  7090. var intersection;
  7091. if (geometry.isBufferGeometry) {
  7092. var index = geometry.index;
  7093. var position = geometry.attributes.position;
  7094. var morphPosition = geometry.morphAttributes.position;
  7095. var morphTargetsRelative = geometry.morphTargetsRelative;
  7096. var uv = geometry.attributes.uv;
  7097. var uv2 = geometry.attributes.uv2;
  7098. var groups = geometry.groups;
  7099. var drawRange = geometry.drawRange;
  7100. if (index !== null) {
  7101. // indexed buffer geometry
  7102. if (Array.isArray(material)) {
  7103. for (var i = 0, il = groups.length; i < il; i++) {
  7104. var group = groups[i];
  7105. var groupMaterial = material[group.materialIndex];
  7106. var start = Math.max(group.start, drawRange.start);
  7107. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7108. for (var j = start, jl = end; j < jl; j += 3) {
  7109. var a = index.getX(j);
  7110. var b = index.getX(j + 1);
  7111. var c = index.getX(j + 2);
  7112. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7113. if (intersection) {
  7114. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7115. intersection.face.materialIndex = group.materialIndex;
  7116. intersects.push(intersection);
  7117. }
  7118. }
  7119. }
  7120. } else {
  7121. var _start = Math.max(0, drawRange.start);
  7122. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7123. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7124. var _a = index.getX(_i);
  7125. var _b = index.getX(_i + 1);
  7126. var _c = index.getX(_i + 2);
  7127. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7128. if (intersection) {
  7129. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7130. intersects.push(intersection);
  7131. }
  7132. }
  7133. }
  7134. } else if (position !== undefined) {
  7135. // non-indexed buffer geometry
  7136. if (Array.isArray(material)) {
  7137. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7138. var _group = groups[_i2];
  7139. var _groupMaterial = material[_group.materialIndex];
  7140. var _start2 = Math.max(_group.start, drawRange.start);
  7141. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7142. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7143. var _a2 = _j;
  7144. var _b2 = _j + 1;
  7145. var _c2 = _j + 2;
  7146. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7147. if (intersection) {
  7148. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7149. intersection.face.materialIndex = _group.materialIndex;
  7150. intersects.push(intersection);
  7151. }
  7152. }
  7153. }
  7154. } else {
  7155. var _start3 = Math.max(0, drawRange.start);
  7156. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7157. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7158. var _a3 = _i3;
  7159. var _b3 = _i3 + 1;
  7160. var _c3 = _i3 + 2;
  7161. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7162. if (intersection) {
  7163. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7164. intersects.push(intersection);
  7165. }
  7166. }
  7167. }
  7168. }
  7169. } else if (geometry.isGeometry) {
  7170. var isMultiMaterial = Array.isArray(material);
  7171. var vertices = geometry.vertices;
  7172. var faces = geometry.faces;
  7173. var uvs;
  7174. var faceVertexUvs = geometry.faceVertexUvs[0];
  7175. if (faceVertexUvs.length > 0) uvs = faceVertexUvs;
  7176. for (var f = 0, fl = faces.length; f < fl; f++) {
  7177. var face = faces[f];
  7178. var faceMaterial = isMultiMaterial ? material[face.materialIndex] : material;
  7179. if (faceMaterial === undefined) continue;
  7180. var fvA = vertices[face.a];
  7181. var fvB = vertices[face.b];
  7182. var fvC = vertices[face.c];
  7183. intersection = checkIntersection(this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint);
  7184. if (intersection) {
  7185. if (uvs && uvs[f]) {
  7186. var uvs_f = uvs[f];
  7187. _uvA.copy(uvs_f[0]);
  7188. _uvB.copy(uvs_f[1]);
  7189. _uvC.copy(uvs_f[2]);
  7190. intersection.uv = Triangle.getUV(_intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2());
  7191. }
  7192. intersection.face = face;
  7193. intersection.faceIndex = f;
  7194. intersects.push(intersection);
  7195. }
  7196. }
  7197. }
  7198. }
  7199. });
  7200. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7201. var intersect;
  7202. if (material.side === BackSide) {
  7203. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7204. } else {
  7205. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7206. }
  7207. if (intersect === null) return null;
  7208. _intersectionPointWorld.copy(point);
  7209. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7210. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7211. if (distance < raycaster.near || distance > raycaster.far) return null;
  7212. return {
  7213. distance: distance,
  7214. point: _intersectionPointWorld.clone(),
  7215. object: object
  7216. };
  7217. }
  7218. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7219. _vA.fromBufferAttribute(position, a);
  7220. _vB.fromBufferAttribute(position, b);
  7221. _vC.fromBufferAttribute(position, c);
  7222. var morphInfluences = object.morphTargetInfluences;
  7223. if (material.morphTargets && morphPosition && morphInfluences) {
  7224. _morphA.set(0, 0, 0);
  7225. _morphB.set(0, 0, 0);
  7226. _morphC.set(0, 0, 0);
  7227. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7228. var influence = morphInfluences[i];
  7229. var morphAttribute = morphPosition[i];
  7230. if (influence === 0) continue;
  7231. _tempA.fromBufferAttribute(morphAttribute, a);
  7232. _tempB.fromBufferAttribute(morphAttribute, b);
  7233. _tempC.fromBufferAttribute(morphAttribute, c);
  7234. if (morphTargetsRelative) {
  7235. _morphA.addScaledVector(_tempA, influence);
  7236. _morphB.addScaledVector(_tempB, influence);
  7237. _morphC.addScaledVector(_tempC, influence);
  7238. } else {
  7239. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7240. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7241. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7242. }
  7243. }
  7244. _vA.add(_morphA);
  7245. _vB.add(_morphB);
  7246. _vC.add(_morphC);
  7247. }
  7248. if (object.isSkinnedMesh) {
  7249. object.boneTransform(a, _vA);
  7250. object.boneTransform(b, _vB);
  7251. object.boneTransform(c, _vC);
  7252. }
  7253. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7254. if (intersection) {
  7255. if (uv) {
  7256. _uvA.fromBufferAttribute(uv, a);
  7257. _uvB.fromBufferAttribute(uv, b);
  7258. _uvC.fromBufferAttribute(uv, c);
  7259. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7260. }
  7261. if (uv2) {
  7262. _uvA.fromBufferAttribute(uv2, a);
  7263. _uvB.fromBufferAttribute(uv2, b);
  7264. _uvC.fromBufferAttribute(uv2, c);
  7265. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7266. }
  7267. var face = new Face3(a, b, c);
  7268. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7269. intersection.face = face;
  7270. }
  7271. return intersection;
  7272. }
  7273. var BoxBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7274. _inheritsLoose(BoxBufferGeometry, _BufferGeometry);
  7275. function BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7276. var _this;
  7277. if (width === void 0) {
  7278. width = 1;
  7279. }
  7280. if (height === void 0) {
  7281. height = 1;
  7282. }
  7283. if (depth === void 0) {
  7284. depth = 1;
  7285. }
  7286. if (widthSegments === void 0) {
  7287. widthSegments = 1;
  7288. }
  7289. if (heightSegments === void 0) {
  7290. heightSegments = 1;
  7291. }
  7292. if (depthSegments === void 0) {
  7293. depthSegments = 1;
  7294. }
  7295. _this = _BufferGeometry.call(this) || this;
  7296. _this.type = 'BoxBufferGeometry';
  7297. _this.parameters = {
  7298. width: width,
  7299. height: height,
  7300. depth: depth,
  7301. widthSegments: widthSegments,
  7302. heightSegments: heightSegments,
  7303. depthSegments: depthSegments
  7304. };
  7305. var scope = _assertThisInitialized(_this); // segments
  7306. widthSegments = Math.floor(widthSegments);
  7307. heightSegments = Math.floor(heightSegments);
  7308. depthSegments = Math.floor(depthSegments); // buffers
  7309. var indices = [];
  7310. var vertices = [];
  7311. var normals = [];
  7312. var uvs = []; // helper variables
  7313. var numberOfVertices = 0;
  7314. var groupStart = 0; // build each side of the box geometry
  7315. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7316. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7317. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7318. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7319. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7320. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7321. // build geometry
  7322. _this.setIndex(indices);
  7323. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7324. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7325. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7326. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7327. var segmentWidth = width / gridX;
  7328. var segmentHeight = height / gridY;
  7329. var widthHalf = width / 2;
  7330. var heightHalf = height / 2;
  7331. var depthHalf = depth / 2;
  7332. var gridX1 = gridX + 1;
  7333. var gridY1 = gridY + 1;
  7334. var vertexCounter = 0;
  7335. var groupCount = 0;
  7336. var vector = new Vector3(); // generate vertices, normals and uvs
  7337. for (var iy = 0; iy < gridY1; iy++) {
  7338. var y = iy * segmentHeight - heightHalf;
  7339. for (var ix = 0; ix < gridX1; ix++) {
  7340. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7341. vector[u] = x * udir;
  7342. vector[v] = y * vdir;
  7343. vector[w] = depthHalf; // now apply vector to vertex buffer
  7344. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7345. vector[u] = 0;
  7346. vector[v] = 0;
  7347. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7348. normals.push(vector.x, vector.y, vector.z); // uvs
  7349. uvs.push(ix / gridX);
  7350. uvs.push(1 - iy / gridY); // counters
  7351. vertexCounter += 1;
  7352. }
  7353. } // indices
  7354. // 1. you need three indices to draw a single face
  7355. // 2. a single segment consists of two faces
  7356. // 3. so we need to generate six (2*3) indices per segment
  7357. for (var _iy = 0; _iy < gridY; _iy++) {
  7358. for (var _ix = 0; _ix < gridX; _ix++) {
  7359. var a = numberOfVertices + _ix + gridX1 * _iy;
  7360. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7361. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7362. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7363. indices.push(a, b, d);
  7364. indices.push(b, c, d); // increase counter
  7365. groupCount += 6;
  7366. }
  7367. } // add a group to the geometry. this will ensure multi material support
  7368. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7369. groupStart += groupCount; // update total number of vertices
  7370. numberOfVertices += vertexCounter;
  7371. }
  7372. return _this;
  7373. }
  7374. return BoxBufferGeometry;
  7375. }(BufferGeometry);
  7376. /**
  7377. * Uniform Utilities
  7378. */
  7379. function cloneUniforms(src) {
  7380. var dst = {};
  7381. for (var u in src) {
  7382. dst[u] = {};
  7383. for (var p in src[u]) {
  7384. var property = src[u][p];
  7385. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture)) {
  7386. dst[u][p] = property.clone();
  7387. } else if (Array.isArray(property)) {
  7388. dst[u][p] = property.slice();
  7389. } else {
  7390. dst[u][p] = property;
  7391. }
  7392. }
  7393. }
  7394. return dst;
  7395. }
  7396. function mergeUniforms(uniforms) {
  7397. var merged = {};
  7398. for (var u = 0; u < uniforms.length; u++) {
  7399. var tmp = cloneUniforms(uniforms[u]);
  7400. for (var p in tmp) {
  7401. merged[p] = tmp[p];
  7402. }
  7403. }
  7404. return merged;
  7405. } // Legacy
  7406. var UniformsUtils = {
  7407. clone: cloneUniforms,
  7408. merge: mergeUniforms
  7409. };
  7410. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7411. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7412. /**
  7413. * parameters = {
  7414. * defines: { "label" : "value" },
  7415. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7416. *
  7417. * fragmentShader: <string>,
  7418. * vertexShader: <string>,
  7419. *
  7420. * wireframe: <boolean>,
  7421. * wireframeLinewidth: <float>,
  7422. *
  7423. * lights: <bool>,
  7424. *
  7425. * skinning: <bool>,
  7426. * morphTargets: <bool>,
  7427. * morphNormals: <bool>
  7428. * }
  7429. */
  7430. function ShaderMaterial(parameters) {
  7431. Material.call(this);
  7432. this.type = 'ShaderMaterial';
  7433. this.defines = {};
  7434. this.uniforms = {};
  7435. this.vertexShader = default_vertex;
  7436. this.fragmentShader = default_fragment;
  7437. this.linewidth = 1;
  7438. this.wireframe = false;
  7439. this.wireframeLinewidth = 1;
  7440. this.fog = false; // set to use scene fog
  7441. this.lights = false; // set to use scene lights
  7442. this.clipping = false; // set to use user-defined clipping planes
  7443. this.skinning = false; // set to use skinning attribute streams
  7444. this.morphTargets = false; // set to use morph targets
  7445. this.morphNormals = false; // set to use morph normals
  7446. this.extensions = {
  7447. derivatives: false,
  7448. // set to use derivatives
  7449. fragDepth: false,
  7450. // set to use fragment depth values
  7451. drawBuffers: false,
  7452. // set to use draw buffers
  7453. shaderTextureLOD: false // set to use shader texture LOD
  7454. }; // When rendered geometry doesn't include these attributes but the material does,
  7455. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7456. this.defaultAttributeValues = {
  7457. 'color': [1, 1, 1],
  7458. 'uv': [0, 0],
  7459. 'uv2': [0, 0]
  7460. };
  7461. this.index0AttributeName = undefined;
  7462. this.uniformsNeedUpdate = false;
  7463. this.glslVersion = null;
  7464. if (parameters !== undefined) {
  7465. if (parameters.attributes !== undefined) {
  7466. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  7467. }
  7468. this.setValues(parameters);
  7469. }
  7470. }
  7471. ShaderMaterial.prototype = Object.create(Material.prototype);
  7472. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7473. ShaderMaterial.prototype.isShaderMaterial = true;
  7474. ShaderMaterial.prototype.copy = function (source) {
  7475. Material.prototype.copy.call(this, source);
  7476. this.fragmentShader = source.fragmentShader;
  7477. this.vertexShader = source.vertexShader;
  7478. this.uniforms = cloneUniforms(source.uniforms);
  7479. this.defines = Object.assign({}, source.defines);
  7480. this.wireframe = source.wireframe;
  7481. this.wireframeLinewidth = source.wireframeLinewidth;
  7482. this.lights = source.lights;
  7483. this.clipping = source.clipping;
  7484. this.skinning = source.skinning;
  7485. this.morphTargets = source.morphTargets;
  7486. this.morphNormals = source.morphNormals;
  7487. this.extensions = Object.assign({}, source.extensions);
  7488. this.glslVersion = source.glslVersion;
  7489. return this;
  7490. };
  7491. ShaderMaterial.prototype.toJSON = function (meta) {
  7492. var data = Material.prototype.toJSON.call(this, meta);
  7493. data.glslVersion = this.glslVersion;
  7494. data.uniforms = {};
  7495. for (var name in this.uniforms) {
  7496. var uniform = this.uniforms[name];
  7497. var value = uniform.value;
  7498. if (value && value.isTexture) {
  7499. data.uniforms[name] = {
  7500. type: 't',
  7501. value: value.toJSON(meta).uuid
  7502. };
  7503. } else if (value && value.isColor) {
  7504. data.uniforms[name] = {
  7505. type: 'c',
  7506. value: value.getHex()
  7507. };
  7508. } else if (value && value.isVector2) {
  7509. data.uniforms[name] = {
  7510. type: 'v2',
  7511. value: value.toArray()
  7512. };
  7513. } else if (value && value.isVector3) {
  7514. data.uniforms[name] = {
  7515. type: 'v3',
  7516. value: value.toArray()
  7517. };
  7518. } else if (value && value.isVector4) {
  7519. data.uniforms[name] = {
  7520. type: 'v4',
  7521. value: value.toArray()
  7522. };
  7523. } else if (value && value.isMatrix3) {
  7524. data.uniforms[name] = {
  7525. type: 'm3',
  7526. value: value.toArray()
  7527. };
  7528. } else if (value && value.isMatrix4) {
  7529. data.uniforms[name] = {
  7530. type: 'm4',
  7531. value: value.toArray()
  7532. };
  7533. } else {
  7534. data.uniforms[name] = {
  7535. value: value
  7536. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7537. }
  7538. }
  7539. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  7540. data.vertexShader = this.vertexShader;
  7541. data.fragmentShader = this.fragmentShader;
  7542. var extensions = {};
  7543. for (var key in this.extensions) {
  7544. if (this.extensions[key] === true) extensions[key] = true;
  7545. }
  7546. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  7547. return data;
  7548. };
  7549. function Camera() {
  7550. Object3D.call(this);
  7551. this.type = 'Camera';
  7552. this.matrixWorldInverse = new Matrix4();
  7553. this.projectionMatrix = new Matrix4();
  7554. this.projectionMatrixInverse = new Matrix4();
  7555. }
  7556. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  7557. constructor: Camera,
  7558. isCamera: true,
  7559. copy: function copy(source, recursive) {
  7560. Object3D.prototype.copy.call(this, source, recursive);
  7561. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  7562. this.projectionMatrix.copy(source.projectionMatrix);
  7563. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  7564. return this;
  7565. },
  7566. getWorldDirection: function getWorldDirection(target) {
  7567. if (target === undefined) {
  7568. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  7569. target = new Vector3();
  7570. }
  7571. this.updateMatrixWorld(true);
  7572. var e = this.matrixWorld.elements;
  7573. return target.set(-e[8], -e[9], -e[10]).normalize();
  7574. },
  7575. updateMatrixWorld: function updateMatrixWorld(force) {
  7576. Object3D.prototype.updateMatrixWorld.call(this, force);
  7577. this.matrixWorldInverse.getInverse(this.matrixWorld);
  7578. },
  7579. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  7580. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  7581. this.matrixWorldInverse.getInverse(this.matrixWorld);
  7582. },
  7583. clone: function clone() {
  7584. return new this.constructor().copy(this);
  7585. }
  7586. });
  7587. function PerspectiveCamera(fov, aspect, near, far) {
  7588. Camera.call(this);
  7589. this.type = 'PerspectiveCamera';
  7590. this.fov = fov !== undefined ? fov : 50;
  7591. this.zoom = 1;
  7592. this.near = near !== undefined ? near : 0.1;
  7593. this.far = far !== undefined ? far : 2000;
  7594. this.focus = 10;
  7595. this.aspect = aspect !== undefined ? aspect : 1;
  7596. this.view = null;
  7597. this.filmGauge = 35; // width of the film (default in millimeters)
  7598. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7599. this.updateProjectionMatrix();
  7600. }
  7601. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  7602. constructor: PerspectiveCamera,
  7603. isPerspectiveCamera: true,
  7604. copy: function copy(source, recursive) {
  7605. Camera.prototype.copy.call(this, source, recursive);
  7606. this.fov = source.fov;
  7607. this.zoom = source.zoom;
  7608. this.near = source.near;
  7609. this.far = source.far;
  7610. this.focus = source.focus;
  7611. this.aspect = source.aspect;
  7612. this.view = source.view === null ? null : Object.assign({}, source.view);
  7613. this.filmGauge = source.filmGauge;
  7614. this.filmOffset = source.filmOffset;
  7615. return this;
  7616. },
  7617. /**
  7618. * Sets the FOV by focal length in respect to the current .filmGauge.
  7619. *
  7620. * The default film gauge is 35, so that the focal length can be specified for
  7621. * a 35mm (full frame) camera.
  7622. *
  7623. * Values for focal length and film gauge must have the same unit.
  7624. */
  7625. setFocalLength: function setFocalLength(focalLength) {
  7626. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7627. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7628. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  7629. this.updateProjectionMatrix();
  7630. },
  7631. /**
  7632. * Calculates the focal length from the current .fov and .filmGauge.
  7633. */
  7634. getFocalLength: function getFocalLength() {
  7635. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  7636. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7637. },
  7638. getEffectiveFOV: function getEffectiveFOV() {
  7639. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  7640. },
  7641. getFilmWidth: function getFilmWidth() {
  7642. // film not completely covered in portrait format (aspect < 1)
  7643. return this.filmGauge * Math.min(this.aspect, 1);
  7644. },
  7645. getFilmHeight: function getFilmHeight() {
  7646. // film not completely covered in landscape format (aspect > 1)
  7647. return this.filmGauge / Math.max(this.aspect, 1);
  7648. },
  7649. /**
  7650. * Sets an offset in a larger frustum. This is useful for multi-window or
  7651. * multi-monitor/multi-machine setups.
  7652. *
  7653. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7654. * the monitors are in grid like this
  7655. *
  7656. * +---+---+---+
  7657. * | A | B | C |
  7658. * +---+---+---+
  7659. * | D | E | F |
  7660. * +---+---+---+
  7661. *
  7662. * then for each monitor you would call it like this
  7663. *
  7664. * const w = 1920;
  7665. * const h = 1080;
  7666. * const fullWidth = w * 3;
  7667. * const fullHeight = h * 2;
  7668. *
  7669. * --A--
  7670. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7671. * --B--
  7672. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7673. * --C--
  7674. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7675. * --D--
  7676. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7677. * --E--
  7678. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7679. * --F--
  7680. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7681. *
  7682. * Note there is no reason monitors have to be the same size or in a grid.
  7683. */
  7684. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  7685. this.aspect = fullWidth / fullHeight;
  7686. if (this.view === null) {
  7687. this.view = {
  7688. enabled: true,
  7689. fullWidth: 1,
  7690. fullHeight: 1,
  7691. offsetX: 0,
  7692. offsetY: 0,
  7693. width: 1,
  7694. height: 1
  7695. };
  7696. }
  7697. this.view.enabled = true;
  7698. this.view.fullWidth = fullWidth;
  7699. this.view.fullHeight = fullHeight;
  7700. this.view.offsetX = x;
  7701. this.view.offsetY = y;
  7702. this.view.width = width;
  7703. this.view.height = height;
  7704. this.updateProjectionMatrix();
  7705. },
  7706. clearViewOffset: function clearViewOffset() {
  7707. if (this.view !== null) {
  7708. this.view.enabled = false;
  7709. }
  7710. this.updateProjectionMatrix();
  7711. },
  7712. updateProjectionMatrix: function updateProjectionMatrix() {
  7713. var near = this.near;
  7714. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  7715. var height = 2 * top;
  7716. var width = this.aspect * height;
  7717. var left = -0.5 * width;
  7718. var view = this.view;
  7719. if (this.view !== null && this.view.enabled) {
  7720. var fullWidth = view.fullWidth,
  7721. fullHeight = view.fullHeight;
  7722. left += view.offsetX * width / fullWidth;
  7723. top -= view.offsetY * height / fullHeight;
  7724. width *= view.width / fullWidth;
  7725. height *= view.height / fullHeight;
  7726. }
  7727. var skew = this.filmOffset;
  7728. if (skew !== 0) left += near * skew / this.getFilmWidth();
  7729. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  7730. this.projectionMatrixInverse.getInverse(this.projectionMatrix);
  7731. },
  7732. toJSON: function toJSON(meta) {
  7733. var data = Object3D.prototype.toJSON.call(this, meta);
  7734. data.object.fov = this.fov;
  7735. data.object.zoom = this.zoom;
  7736. data.object.near = this.near;
  7737. data.object.far = this.far;
  7738. data.object.focus = this.focus;
  7739. data.object.aspect = this.aspect;
  7740. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  7741. data.object.filmGauge = this.filmGauge;
  7742. data.object.filmOffset = this.filmOffset;
  7743. return data;
  7744. }
  7745. });
  7746. var fov = 90,
  7747. aspect = 1;
  7748. function CubeCamera(near, far, renderTarget) {
  7749. Object3D.call(this);
  7750. this.type = 'CubeCamera';
  7751. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  7752. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  7753. return;
  7754. }
  7755. this.renderTarget = renderTarget;
  7756. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  7757. cameraPX.layers = this.layers;
  7758. cameraPX.up.set(0, -1, 0);
  7759. cameraPX.lookAt(new Vector3(1, 0, 0));
  7760. this.add(cameraPX);
  7761. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  7762. cameraNX.layers = this.layers;
  7763. cameraNX.up.set(0, -1, 0);
  7764. cameraNX.lookAt(new Vector3(-1, 0, 0));
  7765. this.add(cameraNX);
  7766. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  7767. cameraPY.layers = this.layers;
  7768. cameraPY.up.set(0, 0, 1);
  7769. cameraPY.lookAt(new Vector3(0, 1, 0));
  7770. this.add(cameraPY);
  7771. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  7772. cameraNY.layers = this.layers;
  7773. cameraNY.up.set(0, 0, -1);
  7774. cameraNY.lookAt(new Vector3(0, -1, 0));
  7775. this.add(cameraNY);
  7776. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  7777. cameraPZ.layers = this.layers;
  7778. cameraPZ.up.set(0, -1, 0);
  7779. cameraPZ.lookAt(new Vector3(0, 0, 1));
  7780. this.add(cameraPZ);
  7781. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  7782. cameraNZ.layers = this.layers;
  7783. cameraNZ.up.set(0, -1, 0);
  7784. cameraNZ.lookAt(new Vector3(0, 0, -1));
  7785. this.add(cameraNZ);
  7786. this.update = function (renderer, scene) {
  7787. if (this.parent === null) this.updateMatrixWorld();
  7788. var currentXrEnabled = renderer.xr.enabled;
  7789. var currentRenderTarget = renderer.getRenderTarget();
  7790. renderer.xr.enabled = false;
  7791. var generateMipmaps = renderTarget.texture.generateMipmaps;
  7792. renderTarget.texture.generateMipmaps = false;
  7793. renderer.setRenderTarget(renderTarget, 0);
  7794. renderer.render(scene, cameraPX);
  7795. renderer.setRenderTarget(renderTarget, 1);
  7796. renderer.render(scene, cameraNX);
  7797. renderer.setRenderTarget(renderTarget, 2);
  7798. renderer.render(scene, cameraPY);
  7799. renderer.setRenderTarget(renderTarget, 3);
  7800. renderer.render(scene, cameraNY);
  7801. renderer.setRenderTarget(renderTarget, 4);
  7802. renderer.render(scene, cameraPZ);
  7803. renderTarget.texture.generateMipmaps = generateMipmaps;
  7804. renderer.setRenderTarget(renderTarget, 5);
  7805. renderer.render(scene, cameraNZ);
  7806. renderer.setRenderTarget(currentRenderTarget);
  7807. renderer.xr.enabled = currentXrEnabled;
  7808. };
  7809. this.clear = function (renderer, color, depth, stencil) {
  7810. var currentRenderTarget = renderer.getRenderTarget();
  7811. for (var i = 0; i < 6; i++) {
  7812. renderer.setRenderTarget(renderTarget, i);
  7813. renderer.clear(color, depth, stencil);
  7814. }
  7815. renderer.setRenderTarget(currentRenderTarget);
  7816. };
  7817. }
  7818. CubeCamera.prototype = Object.create(Object3D.prototype);
  7819. CubeCamera.prototype.constructor = CubeCamera;
  7820. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  7821. images = images !== undefined ? images : [];
  7822. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7823. format = format !== undefined ? format : RGBFormat;
  7824. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  7825. this.flipY = false;
  7826. this._needsFlipEnvMap = true;
  7827. }
  7828. CubeTexture.prototype = Object.create(Texture.prototype);
  7829. CubeTexture.prototype.constructor = CubeTexture;
  7830. CubeTexture.prototype.isCubeTexture = true;
  7831. Object.defineProperty(CubeTexture.prototype, 'images', {
  7832. get: function get() {
  7833. return this.image;
  7834. },
  7835. set: function set(value) {
  7836. this.image = value;
  7837. }
  7838. });
  7839. function WebGLCubeRenderTarget(size, options, dummy) {
  7840. if (Number.isInteger(options)) {
  7841. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  7842. options = dummy;
  7843. }
  7844. WebGLRenderTarget.call(this, size, size, options);
  7845. options = options || {};
  7846. this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  7847. this.texture._needsFlipEnvMap = false;
  7848. }
  7849. WebGLCubeRenderTarget.prototype = Object.create(WebGLRenderTarget.prototype);
  7850. WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
  7851. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  7852. WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function (renderer, texture) {
  7853. this.texture.type = texture.type;
  7854. this.texture.format = RGBAFormat; // see #18859
  7855. this.texture.encoding = texture.encoding;
  7856. this.texture.generateMipmaps = texture.generateMipmaps;
  7857. this.texture.minFilter = texture.minFilter;
  7858. this.texture.magFilter = texture.magFilter;
  7859. var shader = {
  7860. uniforms: {
  7861. tEquirect: {
  7862. value: null
  7863. }
  7864. },
  7865. vertexShader:
  7866. /* glsl */
  7867. "\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",
  7868. fragmentShader:
  7869. /* glsl */
  7870. "\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"
  7871. };
  7872. var geometry = new BoxBufferGeometry(5, 5, 5);
  7873. var material = new ShaderMaterial({
  7874. name: 'CubemapFromEquirect',
  7875. uniforms: cloneUniforms(shader.uniforms),
  7876. vertexShader: shader.vertexShader,
  7877. fragmentShader: shader.fragmentShader,
  7878. side: BackSide,
  7879. blending: NoBlending
  7880. });
  7881. material.uniforms.tEquirect.value = texture;
  7882. var mesh = new Mesh(geometry, material);
  7883. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  7884. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  7885. var camera = new CubeCamera(1, 10, this);
  7886. camera.update(renderer, mesh);
  7887. texture.minFilter = currentMinFilter;
  7888. mesh.geometry.dispose();
  7889. mesh.material.dispose();
  7890. return this;
  7891. };
  7892. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  7893. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  7894. this.image = {
  7895. data: data || null,
  7896. width: width || 1,
  7897. height: height || 1
  7898. };
  7899. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  7900. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  7901. this.generateMipmaps = false;
  7902. this.flipY = false;
  7903. this.unpackAlignment = 1;
  7904. this.needsUpdate = true;
  7905. }
  7906. DataTexture.prototype = Object.create(Texture.prototype);
  7907. DataTexture.prototype.constructor = DataTexture;
  7908. DataTexture.prototype.isDataTexture = true;
  7909. var _sphere$1 = /*@__PURE__*/new Sphere();
  7910. var _vector$5 = /*@__PURE__*/new Vector3();
  7911. var Frustum = /*#__PURE__*/function () {
  7912. function Frustum(p0, p1, p2, p3, p4, p5) {
  7913. 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()];
  7914. }
  7915. var _proto = Frustum.prototype;
  7916. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  7917. var planes = this.planes;
  7918. planes[0].copy(p0);
  7919. planes[1].copy(p1);
  7920. planes[2].copy(p2);
  7921. planes[3].copy(p3);
  7922. planes[4].copy(p4);
  7923. planes[5].copy(p5);
  7924. return this;
  7925. };
  7926. _proto.clone = function clone() {
  7927. return new this.constructor().copy(this);
  7928. };
  7929. _proto.copy = function copy(frustum) {
  7930. var planes = this.planes;
  7931. for (var i = 0; i < 6; i++) {
  7932. planes[i].copy(frustum.planes[i]);
  7933. }
  7934. return this;
  7935. };
  7936. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  7937. var planes = this.planes;
  7938. var me = m.elements;
  7939. var me0 = me[0],
  7940. me1 = me[1],
  7941. me2 = me[2],
  7942. me3 = me[3];
  7943. var me4 = me[4],
  7944. me5 = me[5],
  7945. me6 = me[6],
  7946. me7 = me[7];
  7947. var me8 = me[8],
  7948. me9 = me[9],
  7949. me10 = me[10],
  7950. me11 = me[11];
  7951. var me12 = me[12],
  7952. me13 = me[13],
  7953. me14 = me[14],
  7954. me15 = me[15];
  7955. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  7956. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  7957. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  7958. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  7959. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  7960. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  7961. return this;
  7962. };
  7963. _proto.intersectsObject = function intersectsObject(object) {
  7964. var geometry = object.geometry;
  7965. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7966. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  7967. return this.intersectsSphere(_sphere$1);
  7968. };
  7969. _proto.intersectsSprite = function intersectsSprite(sprite) {
  7970. _sphere$1.center.set(0, 0, 0);
  7971. _sphere$1.radius = 0.7071067811865476;
  7972. _sphere$1.applyMatrix4(sprite.matrixWorld);
  7973. return this.intersectsSphere(_sphere$1);
  7974. };
  7975. _proto.intersectsSphere = function intersectsSphere(sphere) {
  7976. var planes = this.planes;
  7977. var center = sphere.center;
  7978. var negRadius = -sphere.radius;
  7979. for (var i = 0; i < 6; i++) {
  7980. var distance = planes[i].distanceToPoint(center);
  7981. if (distance < negRadius) {
  7982. return false;
  7983. }
  7984. }
  7985. return true;
  7986. };
  7987. _proto.intersectsBox = function intersectsBox(box) {
  7988. var planes = this.planes;
  7989. for (var i = 0; i < 6; i++) {
  7990. var plane = planes[i]; // corner at max distance
  7991. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  7992. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  7993. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  7994. if (plane.distanceToPoint(_vector$5) < 0) {
  7995. return false;
  7996. }
  7997. }
  7998. return true;
  7999. };
  8000. _proto.containsPoint = function containsPoint(point) {
  8001. var planes = this.planes;
  8002. for (var i = 0; i < 6; i++) {
  8003. if (planes[i].distanceToPoint(point) < 0) {
  8004. return false;
  8005. }
  8006. }
  8007. return true;
  8008. };
  8009. return Frustum;
  8010. }();
  8011. function WebGLAnimation() {
  8012. var context = null;
  8013. var isAnimating = false;
  8014. var animationLoop = null;
  8015. var requestId = null;
  8016. function onAnimationFrame(time, frame) {
  8017. animationLoop(time, frame);
  8018. requestId = context.requestAnimationFrame(onAnimationFrame);
  8019. }
  8020. return {
  8021. start: function start() {
  8022. if (isAnimating === true) return;
  8023. if (animationLoop === null) return;
  8024. requestId = context.requestAnimationFrame(onAnimationFrame);
  8025. isAnimating = true;
  8026. },
  8027. stop: function stop() {
  8028. context.cancelAnimationFrame(requestId);
  8029. isAnimating = false;
  8030. },
  8031. setAnimationLoop: function setAnimationLoop(callback) {
  8032. animationLoop = callback;
  8033. },
  8034. setContext: function setContext(value) {
  8035. context = value;
  8036. }
  8037. };
  8038. }
  8039. function WebGLAttributes(gl, capabilities) {
  8040. var isWebGL2 = capabilities.isWebGL2;
  8041. var buffers = new WeakMap();
  8042. function createBuffer(attribute, bufferType) {
  8043. var array = attribute.array;
  8044. var usage = attribute.usage;
  8045. var buffer = gl.createBuffer();
  8046. gl.bindBuffer(bufferType, buffer);
  8047. gl.bufferData(bufferType, array, usage);
  8048. attribute.onUploadCallback();
  8049. var type = 5126;
  8050. if (array instanceof Float32Array) {
  8051. type = 5126;
  8052. } else if (array instanceof Float64Array) {
  8053. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8054. } else if (array instanceof Uint16Array) {
  8055. type = 5123;
  8056. } else if (array instanceof Int16Array) {
  8057. type = 5122;
  8058. } else if (array instanceof Uint32Array) {
  8059. type = 5125;
  8060. } else if (array instanceof Int32Array) {
  8061. type = 5124;
  8062. } else if (array instanceof Int8Array) {
  8063. type = 5120;
  8064. } else if (array instanceof Uint8Array) {
  8065. type = 5121;
  8066. }
  8067. return {
  8068. buffer: buffer,
  8069. type: type,
  8070. bytesPerElement: array.BYTES_PER_ELEMENT,
  8071. version: attribute.version
  8072. };
  8073. }
  8074. function updateBuffer(buffer, attribute, bufferType) {
  8075. var array = attribute.array;
  8076. var updateRange = attribute.updateRange;
  8077. gl.bindBuffer(bufferType, buffer);
  8078. if (updateRange.count === -1) {
  8079. // Not using update ranges
  8080. gl.bufferSubData(bufferType, 0, array);
  8081. } else {
  8082. if (isWebGL2) {
  8083. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8084. } else {
  8085. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8086. }
  8087. updateRange.count = -1; // reset range
  8088. }
  8089. } //
  8090. function get(attribute) {
  8091. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8092. return buffers.get(attribute);
  8093. }
  8094. function remove(attribute) {
  8095. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8096. var data = buffers.get(attribute);
  8097. if (data) {
  8098. gl.deleteBuffer(data.buffer);
  8099. buffers.delete(attribute);
  8100. }
  8101. }
  8102. function update(attribute, bufferType) {
  8103. if (attribute.isGLBufferAttribute) {
  8104. var cached = buffers.get(attribute);
  8105. if (!cached || cached.version < attribute.version) {
  8106. buffers.set(attribute, {
  8107. buffer: attribute.buffer,
  8108. type: attribute.type,
  8109. bytesPerElement: attribute.elementSize,
  8110. version: attribute.version
  8111. });
  8112. }
  8113. return;
  8114. }
  8115. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8116. var data = buffers.get(attribute);
  8117. if (data === undefined) {
  8118. buffers.set(attribute, createBuffer(attribute, bufferType));
  8119. } else if (data.version < attribute.version) {
  8120. updateBuffer(data.buffer, attribute, bufferType);
  8121. data.version = attribute.version;
  8122. }
  8123. }
  8124. return {
  8125. get: get,
  8126. remove: remove,
  8127. update: update
  8128. };
  8129. }
  8130. var PlaneBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8131. _inheritsLoose(PlaneBufferGeometry, _BufferGeometry);
  8132. function PlaneBufferGeometry(width, height, widthSegments, heightSegments) {
  8133. var _this;
  8134. _this = _BufferGeometry.call(this) || this;
  8135. _this.type = 'PlaneBufferGeometry';
  8136. _this.parameters = {
  8137. width: width,
  8138. height: height,
  8139. widthSegments: widthSegments,
  8140. heightSegments: heightSegments
  8141. };
  8142. width = width || 1;
  8143. height = height || 1;
  8144. var width_half = width / 2;
  8145. var height_half = height / 2;
  8146. var gridX = Math.floor(widthSegments) || 1;
  8147. var gridY = Math.floor(heightSegments) || 1;
  8148. var gridX1 = gridX + 1;
  8149. var gridY1 = gridY + 1;
  8150. var segment_width = width / gridX;
  8151. var segment_height = height / gridY; // buffers
  8152. var indices = [];
  8153. var vertices = [];
  8154. var normals = [];
  8155. var uvs = []; // generate vertices, normals and uvs
  8156. for (var iy = 0; iy < gridY1; iy++) {
  8157. var y = iy * segment_height - height_half;
  8158. for (var ix = 0; ix < gridX1; ix++) {
  8159. var x = ix * segment_width - width_half;
  8160. vertices.push(x, -y, 0);
  8161. normals.push(0, 0, 1);
  8162. uvs.push(ix / gridX);
  8163. uvs.push(1 - iy / gridY);
  8164. }
  8165. } // indices
  8166. for (var _iy = 0; _iy < gridY; _iy++) {
  8167. for (var _ix = 0; _ix < gridX; _ix++) {
  8168. var a = _ix + gridX1 * _iy;
  8169. var b = _ix + gridX1 * (_iy + 1);
  8170. var c = _ix + 1 + gridX1 * (_iy + 1);
  8171. var d = _ix + 1 + gridX1 * _iy; // faces
  8172. indices.push(a, b, d);
  8173. indices.push(b, c, d);
  8174. }
  8175. } // build geometry
  8176. _this.setIndex(indices);
  8177. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8178. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8179. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8180. return _this;
  8181. }
  8182. return PlaneBufferGeometry;
  8183. }(BufferGeometry);
  8184. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8185. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8186. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8187. 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";
  8188. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8189. var begin_vertex = "vec3 transformed = vec3( position );";
  8190. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8191. 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";
  8192. 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";
  8193. 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";
  8194. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8195. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8196. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8197. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8198. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8199. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8200. 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";
  8201. 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}";
  8202. 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";
  8203. 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";
  8204. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8205. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8206. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8207. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8208. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8209. 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}";
  8210. 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";
  8211. 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";
  8212. 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";
  8213. 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";
  8214. 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";
  8215. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8216. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8217. 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";
  8218. 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";
  8219. 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}";
  8220. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8221. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8222. 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";
  8223. 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";
  8224. 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";
  8225. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8226. 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)";
  8227. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8228. 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)";
  8229. 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";
  8230. 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}";
  8231. 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";
  8232. 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";
  8233. 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";
  8234. 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";
  8235. 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";
  8236. 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";
  8237. 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";
  8238. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8239. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8240. 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";
  8241. 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";
  8242. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8243. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8244. 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";
  8245. 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";
  8246. 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";
  8247. 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;";
  8248. 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";
  8249. 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";
  8250. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8251. 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";
  8252. 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";
  8253. 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}";
  8254. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8255. 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;";
  8256. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8257. 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";
  8258. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8259. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8260. 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";
  8261. 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";
  8262. 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";
  8263. 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}";
  8264. 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";
  8265. 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";
  8266. 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";
  8267. 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";
  8268. 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";
  8269. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8270. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8271. 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; }";
  8272. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8273. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8274. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8275. 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";
  8276. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8277. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8278. 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";
  8279. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8280. 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";
  8281. 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}";
  8282. 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}";
  8283. 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}";
  8284. 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}";
  8285. 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}";
  8286. 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}";
  8287. 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}";
  8288. 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}";
  8289. 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}";
  8290. 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}";
  8291. 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}";
  8292. 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}";
  8293. 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}";
  8294. 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}";
  8295. 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}";
  8296. 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}";
  8297. 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}";
  8298. 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}";
  8299. 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}";
  8300. 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}";
  8301. 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}";
  8302. 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}";
  8303. 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}";
  8304. 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}";
  8305. 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}";
  8306. 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}";
  8307. 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}";
  8308. 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}";
  8309. 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}";
  8310. 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}";
  8311. 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}";
  8312. 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}";
  8313. var ShaderChunk = {
  8314. alphamap_fragment: alphamap_fragment,
  8315. alphamap_pars_fragment: alphamap_pars_fragment,
  8316. alphatest_fragment: alphatest_fragment,
  8317. aomap_fragment: aomap_fragment,
  8318. aomap_pars_fragment: aomap_pars_fragment,
  8319. begin_vertex: begin_vertex,
  8320. beginnormal_vertex: beginnormal_vertex,
  8321. bsdfs: bsdfs,
  8322. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8323. clipping_planes_fragment: clipping_planes_fragment,
  8324. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8325. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8326. clipping_planes_vertex: clipping_planes_vertex,
  8327. color_fragment: color_fragment,
  8328. color_pars_fragment: color_pars_fragment,
  8329. color_pars_vertex: color_pars_vertex,
  8330. color_vertex: color_vertex,
  8331. common: common,
  8332. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8333. defaultnormal_vertex: defaultnormal_vertex,
  8334. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8335. displacementmap_vertex: displacementmap_vertex,
  8336. emissivemap_fragment: emissivemap_fragment,
  8337. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8338. encodings_fragment: encodings_fragment,
  8339. encodings_pars_fragment: encodings_pars_fragment,
  8340. envmap_fragment: envmap_fragment,
  8341. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8342. envmap_pars_fragment: envmap_pars_fragment,
  8343. envmap_pars_vertex: envmap_pars_vertex,
  8344. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8345. envmap_vertex: envmap_vertex,
  8346. fog_vertex: fog_vertex,
  8347. fog_pars_vertex: fog_pars_vertex,
  8348. fog_fragment: fog_fragment,
  8349. fog_pars_fragment: fog_pars_fragment,
  8350. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8351. lightmap_fragment: lightmap_fragment,
  8352. lightmap_pars_fragment: lightmap_pars_fragment,
  8353. lights_lambert_vertex: lights_lambert_vertex,
  8354. lights_pars_begin: lights_pars_begin,
  8355. lights_toon_fragment: lights_toon_fragment,
  8356. lights_toon_pars_fragment: lights_toon_pars_fragment,
  8357. lights_phong_fragment: lights_phong_fragment,
  8358. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8359. lights_physical_fragment: lights_physical_fragment,
  8360. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8361. lights_fragment_begin: lights_fragment_begin,
  8362. lights_fragment_maps: lights_fragment_maps,
  8363. lights_fragment_end: lights_fragment_end,
  8364. logdepthbuf_fragment: logdepthbuf_fragment,
  8365. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8366. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8367. logdepthbuf_vertex: logdepthbuf_vertex,
  8368. map_fragment: map_fragment,
  8369. map_pars_fragment: map_pars_fragment,
  8370. map_particle_fragment: map_particle_fragment,
  8371. map_particle_pars_fragment: map_particle_pars_fragment,
  8372. metalnessmap_fragment: metalnessmap_fragment,
  8373. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  8374. morphnormal_vertex: morphnormal_vertex,
  8375. morphtarget_pars_vertex: morphtarget_pars_vertex,
  8376. morphtarget_vertex: morphtarget_vertex,
  8377. normal_fragment_begin: normal_fragment_begin,
  8378. normal_fragment_maps: normal_fragment_maps,
  8379. normalmap_pars_fragment: normalmap_pars_fragment,
  8380. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  8381. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  8382. clearcoat_pars_fragment: clearcoat_pars_fragment,
  8383. packing: packing,
  8384. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  8385. project_vertex: project_vertex,
  8386. dithering_fragment: dithering_fragment,
  8387. dithering_pars_fragment: dithering_pars_fragment,
  8388. roughnessmap_fragment: roughnessmap_fragment,
  8389. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  8390. shadowmap_pars_fragment: shadowmap_pars_fragment,
  8391. shadowmap_pars_vertex: shadowmap_pars_vertex,
  8392. shadowmap_vertex: shadowmap_vertex,
  8393. shadowmask_pars_fragment: shadowmask_pars_fragment,
  8394. skinbase_vertex: skinbase_vertex,
  8395. skinning_pars_vertex: skinning_pars_vertex,
  8396. skinning_vertex: skinning_vertex,
  8397. skinnormal_vertex: skinnormal_vertex,
  8398. specularmap_fragment: specularmap_fragment,
  8399. specularmap_pars_fragment: specularmap_pars_fragment,
  8400. tonemapping_fragment: tonemapping_fragment,
  8401. tonemapping_pars_fragment: tonemapping_pars_fragment,
  8402. transmissionmap_fragment: transmissionmap_fragment,
  8403. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  8404. uv_pars_fragment: uv_pars_fragment,
  8405. uv_pars_vertex: uv_pars_vertex,
  8406. uv_vertex: uv_vertex,
  8407. uv2_pars_fragment: uv2_pars_fragment,
  8408. uv2_pars_vertex: uv2_pars_vertex,
  8409. uv2_vertex: uv2_vertex,
  8410. worldpos_vertex: worldpos_vertex,
  8411. background_frag: background_frag,
  8412. background_vert: background_vert,
  8413. cube_frag: cube_frag,
  8414. cube_vert: cube_vert,
  8415. depth_frag: depth_frag,
  8416. depth_vert: depth_vert,
  8417. distanceRGBA_frag: distanceRGBA_frag,
  8418. distanceRGBA_vert: distanceRGBA_vert,
  8419. equirect_frag: equirect_frag,
  8420. equirect_vert: equirect_vert,
  8421. linedashed_frag: linedashed_frag,
  8422. linedashed_vert: linedashed_vert,
  8423. meshbasic_frag: meshbasic_frag,
  8424. meshbasic_vert: meshbasic_vert,
  8425. meshlambert_frag: meshlambert_frag,
  8426. meshlambert_vert: meshlambert_vert,
  8427. meshmatcap_frag: meshmatcap_frag,
  8428. meshmatcap_vert: meshmatcap_vert,
  8429. meshtoon_frag: meshtoon_frag,
  8430. meshtoon_vert: meshtoon_vert,
  8431. meshphong_frag: meshphong_frag,
  8432. meshphong_vert: meshphong_vert,
  8433. meshphysical_frag: meshphysical_frag,
  8434. meshphysical_vert: meshphysical_vert,
  8435. normal_frag: normal_frag,
  8436. normal_vert: normal_vert,
  8437. points_frag: points_frag,
  8438. points_vert: points_vert,
  8439. shadow_frag: shadow_frag,
  8440. shadow_vert: shadow_vert,
  8441. sprite_frag: sprite_frag,
  8442. sprite_vert: sprite_vert
  8443. };
  8444. /**
  8445. * Uniforms library for shared webgl shaders
  8446. */
  8447. var UniformsLib = {
  8448. common: {
  8449. diffuse: {
  8450. value: new Color(0xeeeeee)
  8451. },
  8452. opacity: {
  8453. value: 1.0
  8454. },
  8455. map: {
  8456. value: null
  8457. },
  8458. uvTransform: {
  8459. value: new Matrix3()
  8460. },
  8461. uv2Transform: {
  8462. value: new Matrix3()
  8463. },
  8464. alphaMap: {
  8465. value: null
  8466. }
  8467. },
  8468. specularmap: {
  8469. specularMap: {
  8470. value: null
  8471. }
  8472. },
  8473. envmap: {
  8474. envMap: {
  8475. value: null
  8476. },
  8477. flipEnvMap: {
  8478. value: -1
  8479. },
  8480. reflectivity: {
  8481. value: 1.0
  8482. },
  8483. refractionRatio: {
  8484. value: 0.98
  8485. },
  8486. maxMipLevel: {
  8487. value: 0
  8488. }
  8489. },
  8490. aomap: {
  8491. aoMap: {
  8492. value: null
  8493. },
  8494. aoMapIntensity: {
  8495. value: 1
  8496. }
  8497. },
  8498. lightmap: {
  8499. lightMap: {
  8500. value: null
  8501. },
  8502. lightMapIntensity: {
  8503. value: 1
  8504. }
  8505. },
  8506. emissivemap: {
  8507. emissiveMap: {
  8508. value: null
  8509. }
  8510. },
  8511. bumpmap: {
  8512. bumpMap: {
  8513. value: null
  8514. },
  8515. bumpScale: {
  8516. value: 1
  8517. }
  8518. },
  8519. normalmap: {
  8520. normalMap: {
  8521. value: null
  8522. },
  8523. normalScale: {
  8524. value: new Vector2(1, 1)
  8525. }
  8526. },
  8527. displacementmap: {
  8528. displacementMap: {
  8529. value: null
  8530. },
  8531. displacementScale: {
  8532. value: 1
  8533. },
  8534. displacementBias: {
  8535. value: 0
  8536. }
  8537. },
  8538. roughnessmap: {
  8539. roughnessMap: {
  8540. value: null
  8541. }
  8542. },
  8543. metalnessmap: {
  8544. metalnessMap: {
  8545. value: null
  8546. }
  8547. },
  8548. gradientmap: {
  8549. gradientMap: {
  8550. value: null
  8551. }
  8552. },
  8553. fog: {
  8554. fogDensity: {
  8555. value: 0.00025
  8556. },
  8557. fogNear: {
  8558. value: 1
  8559. },
  8560. fogFar: {
  8561. value: 2000
  8562. },
  8563. fogColor: {
  8564. value: new Color(0xffffff)
  8565. }
  8566. },
  8567. lights: {
  8568. ambientLightColor: {
  8569. value: []
  8570. },
  8571. lightProbe: {
  8572. value: []
  8573. },
  8574. directionalLights: {
  8575. value: [],
  8576. properties: {
  8577. direction: {},
  8578. color: {}
  8579. }
  8580. },
  8581. directionalLightShadows: {
  8582. value: [],
  8583. properties: {
  8584. shadowBias: {},
  8585. shadowNormalBias: {},
  8586. shadowRadius: {},
  8587. shadowMapSize: {}
  8588. }
  8589. },
  8590. directionalShadowMap: {
  8591. value: []
  8592. },
  8593. directionalShadowMatrix: {
  8594. value: []
  8595. },
  8596. spotLights: {
  8597. value: [],
  8598. properties: {
  8599. color: {},
  8600. position: {},
  8601. direction: {},
  8602. distance: {},
  8603. coneCos: {},
  8604. penumbraCos: {},
  8605. decay: {}
  8606. }
  8607. },
  8608. spotLightShadows: {
  8609. value: [],
  8610. properties: {
  8611. shadowBias: {},
  8612. shadowNormalBias: {},
  8613. shadowRadius: {},
  8614. shadowMapSize: {}
  8615. }
  8616. },
  8617. spotShadowMap: {
  8618. value: []
  8619. },
  8620. spotShadowMatrix: {
  8621. value: []
  8622. },
  8623. pointLights: {
  8624. value: [],
  8625. properties: {
  8626. color: {},
  8627. position: {},
  8628. decay: {},
  8629. distance: {}
  8630. }
  8631. },
  8632. pointLightShadows: {
  8633. value: [],
  8634. properties: {
  8635. shadowBias: {},
  8636. shadowNormalBias: {},
  8637. shadowRadius: {},
  8638. shadowMapSize: {},
  8639. shadowCameraNear: {},
  8640. shadowCameraFar: {}
  8641. }
  8642. },
  8643. pointShadowMap: {
  8644. value: []
  8645. },
  8646. pointShadowMatrix: {
  8647. value: []
  8648. },
  8649. hemisphereLights: {
  8650. value: [],
  8651. properties: {
  8652. direction: {},
  8653. skyColor: {},
  8654. groundColor: {}
  8655. }
  8656. },
  8657. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8658. rectAreaLights: {
  8659. value: [],
  8660. properties: {
  8661. color: {},
  8662. position: {},
  8663. width: {},
  8664. height: {}
  8665. }
  8666. },
  8667. ltc_1: {
  8668. value: null
  8669. },
  8670. ltc_2: {
  8671. value: null
  8672. }
  8673. },
  8674. points: {
  8675. diffuse: {
  8676. value: new Color(0xeeeeee)
  8677. },
  8678. opacity: {
  8679. value: 1.0
  8680. },
  8681. size: {
  8682. value: 1.0
  8683. },
  8684. scale: {
  8685. value: 1.0
  8686. },
  8687. map: {
  8688. value: null
  8689. },
  8690. alphaMap: {
  8691. value: null
  8692. },
  8693. uvTransform: {
  8694. value: new Matrix3()
  8695. }
  8696. },
  8697. sprite: {
  8698. diffuse: {
  8699. value: new Color(0xeeeeee)
  8700. },
  8701. opacity: {
  8702. value: 1.0
  8703. },
  8704. center: {
  8705. value: new Vector2(0.5, 0.5)
  8706. },
  8707. rotation: {
  8708. value: 0.0
  8709. },
  8710. map: {
  8711. value: null
  8712. },
  8713. alphaMap: {
  8714. value: null
  8715. },
  8716. uvTransform: {
  8717. value: new Matrix3()
  8718. }
  8719. }
  8720. };
  8721. var ShaderLib = {
  8722. basic: {
  8723. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  8724. vertexShader: ShaderChunk.meshbasic_vert,
  8725. fragmentShader: ShaderChunk.meshbasic_frag
  8726. },
  8727. lambert: {
  8728. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  8729. emissive: {
  8730. value: new Color(0x000000)
  8731. }
  8732. }]),
  8733. vertexShader: ShaderChunk.meshlambert_vert,
  8734. fragmentShader: ShaderChunk.meshlambert_frag
  8735. },
  8736. phong: {
  8737. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  8738. emissive: {
  8739. value: new Color(0x000000)
  8740. },
  8741. specular: {
  8742. value: new Color(0x111111)
  8743. },
  8744. shininess: {
  8745. value: 30
  8746. }
  8747. }]),
  8748. vertexShader: ShaderChunk.meshphong_vert,
  8749. fragmentShader: ShaderChunk.meshphong_frag
  8750. },
  8751. standard: {
  8752. 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, {
  8753. emissive: {
  8754. value: new Color(0x000000)
  8755. },
  8756. roughness: {
  8757. value: 1.0
  8758. },
  8759. metalness: {
  8760. value: 0.0
  8761. },
  8762. envMapIntensity: {
  8763. value: 1
  8764. } // temporary
  8765. }]),
  8766. vertexShader: ShaderChunk.meshphysical_vert,
  8767. fragmentShader: ShaderChunk.meshphysical_frag
  8768. },
  8769. toon: {
  8770. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  8771. emissive: {
  8772. value: new Color(0x000000)
  8773. }
  8774. }]),
  8775. vertexShader: ShaderChunk.meshtoon_vert,
  8776. fragmentShader: ShaderChunk.meshtoon_frag
  8777. },
  8778. matcap: {
  8779. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  8780. matcap: {
  8781. value: null
  8782. }
  8783. }]),
  8784. vertexShader: ShaderChunk.meshmatcap_vert,
  8785. fragmentShader: ShaderChunk.meshmatcap_frag
  8786. },
  8787. points: {
  8788. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  8789. vertexShader: ShaderChunk.points_vert,
  8790. fragmentShader: ShaderChunk.points_frag
  8791. },
  8792. dashed: {
  8793. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  8794. scale: {
  8795. value: 1
  8796. },
  8797. dashSize: {
  8798. value: 1
  8799. },
  8800. totalSize: {
  8801. value: 2
  8802. }
  8803. }]),
  8804. vertexShader: ShaderChunk.linedashed_vert,
  8805. fragmentShader: ShaderChunk.linedashed_frag
  8806. },
  8807. depth: {
  8808. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  8809. vertexShader: ShaderChunk.depth_vert,
  8810. fragmentShader: ShaderChunk.depth_frag
  8811. },
  8812. normal: {
  8813. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  8814. opacity: {
  8815. value: 1.0
  8816. }
  8817. }]),
  8818. vertexShader: ShaderChunk.normal_vert,
  8819. fragmentShader: ShaderChunk.normal_frag
  8820. },
  8821. sprite: {
  8822. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  8823. vertexShader: ShaderChunk.sprite_vert,
  8824. fragmentShader: ShaderChunk.sprite_frag
  8825. },
  8826. background: {
  8827. uniforms: {
  8828. uvTransform: {
  8829. value: new Matrix3()
  8830. },
  8831. t2D: {
  8832. value: null
  8833. }
  8834. },
  8835. vertexShader: ShaderChunk.background_vert,
  8836. fragmentShader: ShaderChunk.background_frag
  8837. },
  8838. /* -------------------------------------------------------------------------
  8839. // Cube map shader
  8840. ------------------------------------------------------------------------- */
  8841. cube: {
  8842. uniforms: mergeUniforms([UniformsLib.envmap, {
  8843. opacity: {
  8844. value: 1.0
  8845. }
  8846. }]),
  8847. vertexShader: ShaderChunk.cube_vert,
  8848. fragmentShader: ShaderChunk.cube_frag
  8849. },
  8850. equirect: {
  8851. uniforms: {
  8852. tEquirect: {
  8853. value: null
  8854. }
  8855. },
  8856. vertexShader: ShaderChunk.equirect_vert,
  8857. fragmentShader: ShaderChunk.equirect_frag
  8858. },
  8859. distanceRGBA: {
  8860. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  8861. referencePosition: {
  8862. value: new Vector3()
  8863. },
  8864. nearDistance: {
  8865. value: 1
  8866. },
  8867. farDistance: {
  8868. value: 1000
  8869. }
  8870. }]),
  8871. vertexShader: ShaderChunk.distanceRGBA_vert,
  8872. fragmentShader: ShaderChunk.distanceRGBA_frag
  8873. },
  8874. shadow: {
  8875. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  8876. color: {
  8877. value: new Color(0x00000)
  8878. },
  8879. opacity: {
  8880. value: 1.0
  8881. }
  8882. }]),
  8883. vertexShader: ShaderChunk.shadow_vert,
  8884. fragmentShader: ShaderChunk.shadow_frag
  8885. }
  8886. };
  8887. ShaderLib.physical = {
  8888. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  8889. clearcoat: {
  8890. value: 0
  8891. },
  8892. clearcoatMap: {
  8893. value: null
  8894. },
  8895. clearcoatRoughness: {
  8896. value: 0
  8897. },
  8898. clearcoatRoughnessMap: {
  8899. value: null
  8900. },
  8901. clearcoatNormalScale: {
  8902. value: new Vector2(1, 1)
  8903. },
  8904. clearcoatNormalMap: {
  8905. value: null
  8906. },
  8907. sheen: {
  8908. value: new Color(0x000000)
  8909. },
  8910. transmission: {
  8911. value: 0
  8912. },
  8913. transmissionMap: {
  8914. value: null
  8915. }
  8916. }]),
  8917. vertexShader: ShaderChunk.meshphysical_vert,
  8918. fragmentShader: ShaderChunk.meshphysical_frag
  8919. };
  8920. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  8921. var clearColor = new Color(0x000000);
  8922. var clearAlpha = 0;
  8923. var planeMesh;
  8924. var boxMesh;
  8925. var currentBackground = null;
  8926. var currentBackgroundVersion = 0;
  8927. var currentTonemapping = null;
  8928. function render(renderList, scene, camera, forceClear) {
  8929. var background = scene.isScene === true ? scene.background : null;
  8930. if (background && background.isTexture) {
  8931. background = cubemaps.get(background);
  8932. } // Ignore background in AR
  8933. // TODO: Reconsider this.
  8934. var xr = renderer.xr;
  8935. var session = xr.getSession && xr.getSession();
  8936. if (session && session.environmentBlendMode === 'additive') {
  8937. background = null;
  8938. }
  8939. if (background === null) {
  8940. setClear(clearColor, clearAlpha);
  8941. } else if (background && background.isColor) {
  8942. setClear(background, 1);
  8943. forceClear = true;
  8944. }
  8945. if (renderer.autoClear || forceClear) {
  8946. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  8947. }
  8948. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  8949. if (boxMesh === undefined) {
  8950. boxMesh = new Mesh(new BoxBufferGeometry(1, 1, 1), new ShaderMaterial({
  8951. name: 'BackgroundCubeMaterial',
  8952. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  8953. vertexShader: ShaderLib.cube.vertexShader,
  8954. fragmentShader: ShaderLib.cube.fragmentShader,
  8955. side: BackSide,
  8956. depthTest: false,
  8957. depthWrite: false,
  8958. fog: false
  8959. }));
  8960. boxMesh.geometry.deleteAttribute('normal');
  8961. boxMesh.geometry.deleteAttribute('uv');
  8962. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  8963. this.matrixWorld.copyPosition(camera.matrixWorld);
  8964. }; // enable code injection for non-built-in material
  8965. Object.defineProperty(boxMesh.material, 'envMap', {
  8966. get: function get() {
  8967. return this.uniforms.envMap.value;
  8968. }
  8969. });
  8970. objects.update(boxMesh);
  8971. }
  8972. if (background.isWebGLCubeRenderTarget) {
  8973. // TODO Deprecate
  8974. background = background.texture;
  8975. }
  8976. boxMesh.material.uniforms.envMap.value = background;
  8977. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  8978. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  8979. boxMesh.material.needsUpdate = true;
  8980. currentBackground = background;
  8981. currentBackgroundVersion = background.version;
  8982. currentTonemapping = renderer.toneMapping;
  8983. } // push to the pre-sorted opaque render list
  8984. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  8985. } else if (background && background.isTexture) {
  8986. if (planeMesh === undefined) {
  8987. planeMesh = new Mesh(new PlaneBufferGeometry(2, 2), new ShaderMaterial({
  8988. name: 'BackgroundMaterial',
  8989. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  8990. vertexShader: ShaderLib.background.vertexShader,
  8991. fragmentShader: ShaderLib.background.fragmentShader,
  8992. side: FrontSide,
  8993. depthTest: false,
  8994. depthWrite: false,
  8995. fog: false
  8996. }));
  8997. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  8998. Object.defineProperty(planeMesh.material, 'map', {
  8999. get: function get() {
  9000. return this.uniforms.t2D.value;
  9001. }
  9002. });
  9003. objects.update(planeMesh);
  9004. }
  9005. planeMesh.material.uniforms.t2D.value = background;
  9006. if (background.matrixAutoUpdate === true) {
  9007. background.updateMatrix();
  9008. }
  9009. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9010. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9011. planeMesh.material.needsUpdate = true;
  9012. currentBackground = background;
  9013. currentBackgroundVersion = background.version;
  9014. currentTonemapping = renderer.toneMapping;
  9015. } // push to the pre-sorted opaque render list
  9016. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9017. }
  9018. }
  9019. function setClear(color, alpha) {
  9020. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9021. }
  9022. return {
  9023. getClearColor: function getClearColor() {
  9024. return clearColor;
  9025. },
  9026. setClearColor: function setClearColor(color, alpha) {
  9027. clearColor.set(color);
  9028. clearAlpha = alpha !== undefined ? alpha : 1;
  9029. setClear(clearColor, clearAlpha);
  9030. },
  9031. getClearAlpha: function getClearAlpha() {
  9032. return clearAlpha;
  9033. },
  9034. setClearAlpha: function setClearAlpha(alpha) {
  9035. clearAlpha = alpha;
  9036. setClear(clearColor, clearAlpha);
  9037. },
  9038. render: render
  9039. };
  9040. }
  9041. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9042. var maxVertexAttributes = gl.getParameter(34921);
  9043. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9044. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9045. var bindingStates = {};
  9046. var defaultState = createBindingState(null);
  9047. var currentState = defaultState;
  9048. function setup(object, material, program, geometry, index) {
  9049. var updateBuffers = false;
  9050. if (vaoAvailable) {
  9051. var state = getBindingState(geometry, program, material);
  9052. if (currentState !== state) {
  9053. currentState = state;
  9054. bindVertexArrayObject(currentState.object);
  9055. }
  9056. updateBuffers = needsUpdate(geometry, index);
  9057. if (updateBuffers) saveCache(geometry, index);
  9058. } else {
  9059. var wireframe = material.wireframe === true;
  9060. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9061. currentState.geometry = geometry.id;
  9062. currentState.program = program.id;
  9063. currentState.wireframe = wireframe;
  9064. updateBuffers = true;
  9065. }
  9066. }
  9067. if (object.isInstancedMesh === true) {
  9068. updateBuffers = true;
  9069. }
  9070. if (index !== null) {
  9071. attributes.update(index, 34963);
  9072. }
  9073. if (updateBuffers) {
  9074. setupVertexAttributes(object, material, program, geometry);
  9075. if (index !== null) {
  9076. gl.bindBuffer(34963, attributes.get(index).buffer);
  9077. }
  9078. }
  9079. }
  9080. function createVertexArrayObject() {
  9081. if (capabilities.isWebGL2) return gl.createVertexArray();
  9082. return extension.createVertexArrayOES();
  9083. }
  9084. function bindVertexArrayObject(vao) {
  9085. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9086. return extension.bindVertexArrayOES(vao);
  9087. }
  9088. function deleteVertexArrayObject(vao) {
  9089. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9090. return extension.deleteVertexArrayOES(vao);
  9091. }
  9092. function getBindingState(geometry, program, material) {
  9093. var wireframe = material.wireframe === true;
  9094. var programMap = bindingStates[geometry.id];
  9095. if (programMap === undefined) {
  9096. programMap = {};
  9097. bindingStates[geometry.id] = programMap;
  9098. }
  9099. var stateMap = programMap[program.id];
  9100. if (stateMap === undefined) {
  9101. stateMap = {};
  9102. programMap[program.id] = stateMap;
  9103. }
  9104. var state = stateMap[wireframe];
  9105. if (state === undefined) {
  9106. state = createBindingState(createVertexArrayObject());
  9107. stateMap[wireframe] = state;
  9108. }
  9109. return state;
  9110. }
  9111. function createBindingState(vao) {
  9112. var newAttributes = [];
  9113. var enabledAttributes = [];
  9114. var attributeDivisors = [];
  9115. for (var i = 0; i < maxVertexAttributes; i++) {
  9116. newAttributes[i] = 0;
  9117. enabledAttributes[i] = 0;
  9118. attributeDivisors[i] = 0;
  9119. }
  9120. return {
  9121. // for backward compatibility on non-VAO support browser
  9122. geometry: null,
  9123. program: null,
  9124. wireframe: false,
  9125. newAttributes: newAttributes,
  9126. enabledAttributes: enabledAttributes,
  9127. attributeDivisors: attributeDivisors,
  9128. object: vao,
  9129. attributes: {},
  9130. index: null
  9131. };
  9132. }
  9133. function needsUpdate(geometry, index) {
  9134. var cachedAttributes = currentState.attributes;
  9135. var geometryAttributes = geometry.attributes;
  9136. if (Object.keys(cachedAttributes).length !== Object.keys(geometryAttributes).length) return true;
  9137. for (var key in geometryAttributes) {
  9138. var cachedAttribute = cachedAttributes[key];
  9139. var geometryAttribute = geometryAttributes[key];
  9140. if (cachedAttribute === undefined) return true;
  9141. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9142. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9143. }
  9144. if (currentState.index !== index) return true;
  9145. return false;
  9146. }
  9147. function saveCache(geometry, index) {
  9148. var cache = {};
  9149. var attributes = geometry.attributes;
  9150. for (var key in attributes) {
  9151. var attribute = attributes[key];
  9152. var data = {};
  9153. data.attribute = attribute;
  9154. if (attribute.data) {
  9155. data.data = attribute.data;
  9156. }
  9157. cache[key] = data;
  9158. }
  9159. currentState.attributes = cache;
  9160. currentState.index = index;
  9161. }
  9162. function initAttributes() {
  9163. var newAttributes = currentState.newAttributes;
  9164. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9165. newAttributes[i] = 0;
  9166. }
  9167. }
  9168. function enableAttribute(attribute) {
  9169. enableAttributeAndDivisor(attribute, 0);
  9170. }
  9171. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9172. var newAttributes = currentState.newAttributes;
  9173. var enabledAttributes = currentState.enabledAttributes;
  9174. var attributeDivisors = currentState.attributeDivisors;
  9175. newAttributes[attribute] = 1;
  9176. if (enabledAttributes[attribute] === 0) {
  9177. gl.enableVertexAttribArray(attribute);
  9178. enabledAttributes[attribute] = 1;
  9179. }
  9180. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9181. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9182. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9183. attributeDivisors[attribute] = meshPerAttribute;
  9184. }
  9185. }
  9186. function disableUnusedAttributes() {
  9187. var newAttributes = currentState.newAttributes;
  9188. var enabledAttributes = currentState.enabledAttributes;
  9189. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9190. if (enabledAttributes[i] !== newAttributes[i]) {
  9191. gl.disableVertexAttribArray(i);
  9192. enabledAttributes[i] = 0;
  9193. }
  9194. }
  9195. }
  9196. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9197. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9198. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9199. } else {
  9200. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9201. }
  9202. }
  9203. function setupVertexAttributes(object, material, program, geometry) {
  9204. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9205. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9206. }
  9207. initAttributes();
  9208. var geometryAttributes = geometry.attributes;
  9209. var programAttributes = program.getAttributes();
  9210. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9211. for (var name in programAttributes) {
  9212. var programAttribute = programAttributes[name];
  9213. if (programAttribute >= 0) {
  9214. var geometryAttribute = geometryAttributes[name];
  9215. if (geometryAttribute !== undefined) {
  9216. var normalized = geometryAttribute.normalized;
  9217. var size = geometryAttribute.itemSize;
  9218. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9219. if (attribute === undefined) continue;
  9220. var buffer = attribute.buffer;
  9221. var type = attribute.type;
  9222. var bytesPerElement = attribute.bytesPerElement;
  9223. if (geometryAttribute.isInterleavedBufferAttribute) {
  9224. var data = geometryAttribute.data;
  9225. var stride = data.stride;
  9226. var offset = geometryAttribute.offset;
  9227. if (data && data.isInstancedInterleavedBuffer) {
  9228. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9229. if (geometry._maxInstanceCount === undefined) {
  9230. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9231. }
  9232. } else {
  9233. enableAttribute(programAttribute);
  9234. }
  9235. gl.bindBuffer(34962, buffer);
  9236. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9237. } else {
  9238. if (geometryAttribute.isInstancedBufferAttribute) {
  9239. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9240. if (geometry._maxInstanceCount === undefined) {
  9241. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9242. }
  9243. } else {
  9244. enableAttribute(programAttribute);
  9245. }
  9246. gl.bindBuffer(34962, buffer);
  9247. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9248. }
  9249. } else if (name === 'instanceMatrix') {
  9250. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9251. if (_attribute === undefined) continue;
  9252. var _buffer = _attribute.buffer;
  9253. var _type = _attribute.type;
  9254. enableAttributeAndDivisor(programAttribute + 0, 1);
  9255. enableAttributeAndDivisor(programAttribute + 1, 1);
  9256. enableAttributeAndDivisor(programAttribute + 2, 1);
  9257. enableAttributeAndDivisor(programAttribute + 3, 1);
  9258. gl.bindBuffer(34962, _buffer);
  9259. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9260. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9261. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9262. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9263. } else if (name === 'instanceColor') {
  9264. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9265. if (_attribute2 === undefined) continue;
  9266. var _buffer2 = _attribute2.buffer;
  9267. var _type2 = _attribute2.type;
  9268. enableAttributeAndDivisor(programAttribute, 1);
  9269. gl.bindBuffer(34962, _buffer2);
  9270. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9271. } else if (materialDefaultAttributeValues !== undefined) {
  9272. var value = materialDefaultAttributeValues[name];
  9273. if (value !== undefined) {
  9274. switch (value.length) {
  9275. case 2:
  9276. gl.vertexAttrib2fv(programAttribute, value);
  9277. break;
  9278. case 3:
  9279. gl.vertexAttrib3fv(programAttribute, value);
  9280. break;
  9281. case 4:
  9282. gl.vertexAttrib4fv(programAttribute, value);
  9283. break;
  9284. default:
  9285. gl.vertexAttrib1fv(programAttribute, value);
  9286. }
  9287. }
  9288. }
  9289. }
  9290. }
  9291. disableUnusedAttributes();
  9292. }
  9293. function dispose() {
  9294. reset();
  9295. for (var geometryId in bindingStates) {
  9296. var programMap = bindingStates[geometryId];
  9297. for (var programId in programMap) {
  9298. var stateMap = programMap[programId];
  9299. for (var wireframe in stateMap) {
  9300. deleteVertexArrayObject(stateMap[wireframe].object);
  9301. delete stateMap[wireframe];
  9302. }
  9303. delete programMap[programId];
  9304. }
  9305. delete bindingStates[geometryId];
  9306. }
  9307. }
  9308. function releaseStatesOfGeometry(geometry) {
  9309. if (bindingStates[geometry.id] === undefined) return;
  9310. var programMap = bindingStates[geometry.id];
  9311. for (var programId in programMap) {
  9312. var stateMap = programMap[programId];
  9313. for (var wireframe in stateMap) {
  9314. deleteVertexArrayObject(stateMap[wireframe].object);
  9315. delete stateMap[wireframe];
  9316. }
  9317. delete programMap[programId];
  9318. }
  9319. delete bindingStates[geometry.id];
  9320. }
  9321. function releaseStatesOfProgram(program) {
  9322. for (var geometryId in bindingStates) {
  9323. var programMap = bindingStates[geometryId];
  9324. if (programMap[program.id] === undefined) continue;
  9325. var stateMap = programMap[program.id];
  9326. for (var wireframe in stateMap) {
  9327. deleteVertexArrayObject(stateMap[wireframe].object);
  9328. delete stateMap[wireframe];
  9329. }
  9330. delete programMap[program.id];
  9331. }
  9332. }
  9333. function reset() {
  9334. resetDefaultState();
  9335. if (currentState === defaultState) return;
  9336. currentState = defaultState;
  9337. bindVertexArrayObject(currentState.object);
  9338. } // for backward-compatilibity
  9339. function resetDefaultState() {
  9340. defaultState.geometry = null;
  9341. defaultState.program = null;
  9342. defaultState.wireframe = false;
  9343. }
  9344. return {
  9345. setup: setup,
  9346. reset: reset,
  9347. resetDefaultState: resetDefaultState,
  9348. dispose: dispose,
  9349. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9350. releaseStatesOfProgram: releaseStatesOfProgram,
  9351. initAttributes: initAttributes,
  9352. enableAttribute: enableAttribute,
  9353. disableUnusedAttributes: disableUnusedAttributes
  9354. };
  9355. }
  9356. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  9357. var isWebGL2 = capabilities.isWebGL2;
  9358. var mode;
  9359. function setMode(value) {
  9360. mode = value;
  9361. }
  9362. function render(start, count) {
  9363. gl.drawArrays(mode, start, count);
  9364. info.update(count, mode, 1);
  9365. }
  9366. function renderInstances(start, count, primcount) {
  9367. if (primcount === 0) return;
  9368. var extension, methodName;
  9369. if (isWebGL2) {
  9370. extension = gl;
  9371. methodName = 'drawArraysInstanced';
  9372. } else {
  9373. extension = extensions.get('ANGLE_instanced_arrays');
  9374. methodName = 'drawArraysInstancedANGLE';
  9375. if (extension === null) {
  9376. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9377. return;
  9378. }
  9379. }
  9380. extension[methodName](mode, start, count, primcount);
  9381. info.update(count, mode, primcount);
  9382. } //
  9383. this.setMode = setMode;
  9384. this.render = render;
  9385. this.renderInstances = renderInstances;
  9386. }
  9387. function WebGLCapabilities(gl, extensions, parameters) {
  9388. var maxAnisotropy;
  9389. function getMaxAnisotropy() {
  9390. if (maxAnisotropy !== undefined) return maxAnisotropy;
  9391. var extension = extensions.get('EXT_texture_filter_anisotropic');
  9392. if (extension !== null) {
  9393. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  9394. } else {
  9395. maxAnisotropy = 0;
  9396. }
  9397. return maxAnisotropy;
  9398. }
  9399. function getMaxPrecision(precision) {
  9400. if (precision === 'highp') {
  9401. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  9402. return 'highp';
  9403. }
  9404. precision = 'mediump';
  9405. }
  9406. if (precision === 'mediump') {
  9407. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  9408. return 'mediump';
  9409. }
  9410. }
  9411. return 'lowp';
  9412. }
  9413. /* eslint-disable no-undef */
  9414. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  9415. /* eslint-enable no-undef */
  9416. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9417. var maxPrecision = getMaxPrecision(precision);
  9418. if (maxPrecision !== precision) {
  9419. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  9420. precision = maxPrecision;
  9421. }
  9422. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9423. var maxTextures = gl.getParameter(34930);
  9424. var maxVertexTextures = gl.getParameter(35660);
  9425. var maxTextureSize = gl.getParameter(3379);
  9426. var maxCubemapSize = gl.getParameter(34076);
  9427. var maxAttributes = gl.getParameter(34921);
  9428. var maxVertexUniforms = gl.getParameter(36347);
  9429. var maxVaryings = gl.getParameter(36348);
  9430. var maxFragmentUniforms = gl.getParameter(36349);
  9431. var vertexTextures = maxVertexTextures > 0;
  9432. var floatFragmentTextures = isWebGL2 || !!extensions.get('OES_texture_float');
  9433. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9434. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  9435. return {
  9436. isWebGL2: isWebGL2,
  9437. getMaxAnisotropy: getMaxAnisotropy,
  9438. getMaxPrecision: getMaxPrecision,
  9439. precision: precision,
  9440. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9441. maxTextures: maxTextures,
  9442. maxVertexTextures: maxVertexTextures,
  9443. maxTextureSize: maxTextureSize,
  9444. maxCubemapSize: maxCubemapSize,
  9445. maxAttributes: maxAttributes,
  9446. maxVertexUniforms: maxVertexUniforms,
  9447. maxVaryings: maxVaryings,
  9448. maxFragmentUniforms: maxFragmentUniforms,
  9449. vertexTextures: vertexTextures,
  9450. floatFragmentTextures: floatFragmentTextures,
  9451. floatVertexTextures: floatVertexTextures,
  9452. maxSamples: maxSamples
  9453. };
  9454. }
  9455. function WebGLClipping(properties) {
  9456. var scope = this;
  9457. var globalState = null,
  9458. numGlobalPlanes = 0,
  9459. localClippingEnabled = false,
  9460. renderingShadows = false;
  9461. var plane = new Plane(),
  9462. viewNormalMatrix = new Matrix3(),
  9463. uniform = {
  9464. value: null,
  9465. needsUpdate: false
  9466. };
  9467. this.uniform = uniform;
  9468. this.numPlanes = 0;
  9469. this.numIntersection = 0;
  9470. this.init = function (planes, enableLocalClipping, camera) {
  9471. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  9472. // run another frame in order to reset the state:
  9473. numGlobalPlanes !== 0 || localClippingEnabled;
  9474. localClippingEnabled = enableLocalClipping;
  9475. globalState = projectPlanes(planes, camera, 0);
  9476. numGlobalPlanes = planes.length;
  9477. return enabled;
  9478. };
  9479. this.beginShadows = function () {
  9480. renderingShadows = true;
  9481. projectPlanes(null);
  9482. };
  9483. this.endShadows = function () {
  9484. renderingShadows = false;
  9485. resetGlobalState();
  9486. };
  9487. this.setState = function (material, camera, useCache) {
  9488. var planes = material.clippingPlanes,
  9489. clipIntersection = material.clipIntersection,
  9490. clipShadows = material.clipShadows;
  9491. var materialProperties = properties.get(material);
  9492. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  9493. // there's no local clipping
  9494. if (renderingShadows) {
  9495. // there's no global clipping
  9496. projectPlanes(null);
  9497. } else {
  9498. resetGlobalState();
  9499. }
  9500. } else {
  9501. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9502. lGlobal = nGlobal * 4;
  9503. var dstArray = materialProperties.clippingState || null;
  9504. uniform.value = dstArray; // ensure unique state
  9505. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  9506. for (var i = 0; i !== lGlobal; ++i) {
  9507. dstArray[i] = globalState[i];
  9508. }
  9509. materialProperties.clippingState = dstArray;
  9510. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9511. this.numPlanes += nGlobal;
  9512. }
  9513. };
  9514. function resetGlobalState() {
  9515. if (uniform.value !== globalState) {
  9516. uniform.value = globalState;
  9517. uniform.needsUpdate = numGlobalPlanes > 0;
  9518. }
  9519. scope.numPlanes = numGlobalPlanes;
  9520. scope.numIntersection = 0;
  9521. }
  9522. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  9523. var nPlanes = planes !== null ? planes.length : 0;
  9524. var dstArray = null;
  9525. if (nPlanes !== 0) {
  9526. dstArray = uniform.value;
  9527. if (skipTransform !== true || dstArray === null) {
  9528. var flatSize = dstOffset + nPlanes * 4,
  9529. viewMatrix = camera.matrixWorldInverse;
  9530. viewNormalMatrix.getNormalMatrix(viewMatrix);
  9531. if (dstArray === null || dstArray.length < flatSize) {
  9532. dstArray = new Float32Array(flatSize);
  9533. }
  9534. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  9535. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  9536. plane.normal.toArray(dstArray, i4);
  9537. dstArray[i4 + 3] = plane.constant;
  9538. }
  9539. }
  9540. uniform.value = dstArray;
  9541. uniform.needsUpdate = true;
  9542. }
  9543. scope.numPlanes = nPlanes;
  9544. scope.numIntersection = 0;
  9545. return dstArray;
  9546. }
  9547. }
  9548. function WebGLCubeMaps(renderer) {
  9549. var cubemaps = new WeakMap();
  9550. function mapTextureMapping(texture, mapping) {
  9551. if (mapping === EquirectangularReflectionMapping) {
  9552. texture.mapping = CubeReflectionMapping;
  9553. } else if (mapping === EquirectangularRefractionMapping) {
  9554. texture.mapping = CubeRefractionMapping;
  9555. }
  9556. return texture;
  9557. }
  9558. function get(texture) {
  9559. if (texture && texture.isTexture) {
  9560. var mapping = texture.mapping;
  9561. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  9562. if (cubemaps.has(texture)) {
  9563. var cubemap = cubemaps.get(texture).texture;
  9564. return mapTextureMapping(cubemap, texture.mapping);
  9565. } else {
  9566. var image = texture.image;
  9567. if (image && image.height > 0) {
  9568. var currentRenderList = renderer.getRenderList();
  9569. var currentRenderTarget = renderer.getRenderTarget();
  9570. var currentRenderState = renderer.getRenderState();
  9571. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  9572. renderTarget.fromEquirectangularTexture(renderer, texture);
  9573. cubemaps.set(texture, renderTarget);
  9574. renderer.setRenderTarget(currentRenderTarget);
  9575. renderer.setRenderList(currentRenderList);
  9576. renderer.setRenderState(currentRenderState);
  9577. texture.addEventListener('dispose', onTextureDispose);
  9578. return mapTextureMapping(renderTarget.texture, texture.mapping);
  9579. } else {
  9580. // image not yet ready. try the conversion next frame
  9581. return null;
  9582. }
  9583. }
  9584. }
  9585. }
  9586. return texture;
  9587. }
  9588. function onTextureDispose(event) {
  9589. var texture = event.target;
  9590. texture.removeEventListener('dispose', onTextureDispose);
  9591. var cubemap = cubemaps.get(texture);
  9592. if (cubemap !== undefined) {
  9593. cubemaps.delete(texture);
  9594. cubemap.dispose();
  9595. }
  9596. }
  9597. function dispose() {
  9598. cubemaps = new WeakMap();
  9599. }
  9600. return {
  9601. get: get,
  9602. dispose: dispose
  9603. };
  9604. }
  9605. function WebGLExtensions(gl) {
  9606. var extensions = {};
  9607. return {
  9608. has: function has(name) {
  9609. if (extensions[name] !== undefined) {
  9610. return extensions[name] !== null;
  9611. }
  9612. var extension;
  9613. switch (name) {
  9614. case 'WEBGL_depth_texture':
  9615. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  9616. break;
  9617. case 'EXT_texture_filter_anisotropic':
  9618. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  9619. break;
  9620. case 'WEBGL_compressed_texture_s3tc':
  9621. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  9622. break;
  9623. case 'WEBGL_compressed_texture_pvrtc':
  9624. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  9625. break;
  9626. default:
  9627. extension = gl.getExtension(name);
  9628. }
  9629. extensions[name] = extension;
  9630. return extension !== null;
  9631. },
  9632. get: function get(name) {
  9633. if (!this.has(name)) {
  9634. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  9635. }
  9636. return extensions[name];
  9637. }
  9638. };
  9639. }
  9640. function WebGLGeometries(gl, attributes, info, bindingStates) {
  9641. var geometries = new WeakMap();
  9642. var wireframeAttributes = new WeakMap();
  9643. function onGeometryDispose(event) {
  9644. var geometry = event.target;
  9645. var buffergeometry = geometries.get(geometry);
  9646. if (buffergeometry.index !== null) {
  9647. attributes.remove(buffergeometry.index);
  9648. }
  9649. for (var name in buffergeometry.attributes) {
  9650. attributes.remove(buffergeometry.attributes[name]);
  9651. }
  9652. geometry.removeEventListener('dispose', onGeometryDispose);
  9653. geometries.delete(geometry);
  9654. var attribute = wireframeAttributes.get(buffergeometry);
  9655. if (attribute) {
  9656. attributes.remove(attribute);
  9657. wireframeAttributes.delete(buffergeometry);
  9658. }
  9659. bindingStates.releaseStatesOfGeometry(geometry);
  9660. if (geometry.isInstancedBufferGeometry === true) {
  9661. delete geometry._maxInstanceCount;
  9662. } //
  9663. info.memory.geometries--;
  9664. }
  9665. function get(object, geometry) {
  9666. var buffergeometry = geometries.get(geometry);
  9667. if (buffergeometry) return buffergeometry;
  9668. geometry.addEventListener('dispose', onGeometryDispose);
  9669. if (geometry.isBufferGeometry) {
  9670. buffergeometry = geometry;
  9671. } else if (geometry.isGeometry) {
  9672. if (geometry._bufferGeometry === undefined) {
  9673. geometry._bufferGeometry = new BufferGeometry().setFromObject(object);
  9674. }
  9675. buffergeometry = geometry._bufferGeometry;
  9676. }
  9677. geometries.set(geometry, buffergeometry);
  9678. info.memory.geometries++;
  9679. return buffergeometry;
  9680. }
  9681. function update(geometry) {
  9682. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  9683. for (var name in geometryAttributes) {
  9684. attributes.update(geometryAttributes[name], 34962);
  9685. } // morph targets
  9686. var morphAttributes = geometry.morphAttributes;
  9687. for (var _name in morphAttributes) {
  9688. var array = morphAttributes[_name];
  9689. for (var i = 0, l = array.length; i < l; i++) {
  9690. attributes.update(array[i], 34962);
  9691. }
  9692. }
  9693. }
  9694. function updateWireframeAttribute(geometry) {
  9695. var indices = [];
  9696. var geometryIndex = geometry.index;
  9697. var geometryPosition = geometry.attributes.position;
  9698. var version = 0;
  9699. if (geometryIndex !== null) {
  9700. var array = geometryIndex.array;
  9701. version = geometryIndex.version;
  9702. for (var i = 0, l = array.length; i < l; i += 3) {
  9703. var a = array[i + 0];
  9704. var b = array[i + 1];
  9705. var c = array[i + 2];
  9706. indices.push(a, b, b, c, c, a);
  9707. }
  9708. } else {
  9709. var _array = geometryPosition.array;
  9710. version = geometryPosition.version;
  9711. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  9712. var _a = _i + 0;
  9713. var _b = _i + 1;
  9714. var _c = _i + 2;
  9715. indices.push(_a, _b, _b, _c, _c, _a);
  9716. }
  9717. }
  9718. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  9719. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  9720. //
  9721. var previousAttribute = wireframeAttributes.get(geometry);
  9722. if (previousAttribute) attributes.remove(previousAttribute); //
  9723. wireframeAttributes.set(geometry, attribute);
  9724. }
  9725. function getWireframeAttribute(geometry) {
  9726. var currentAttribute = wireframeAttributes.get(geometry);
  9727. if (currentAttribute) {
  9728. var geometryIndex = geometry.index;
  9729. if (geometryIndex !== null) {
  9730. // if the attribute is obsolete, create a new one
  9731. if (currentAttribute.version < geometryIndex.version) {
  9732. updateWireframeAttribute(geometry);
  9733. }
  9734. }
  9735. } else {
  9736. updateWireframeAttribute(geometry);
  9737. }
  9738. return wireframeAttributes.get(geometry);
  9739. }
  9740. return {
  9741. get: get,
  9742. update: update,
  9743. getWireframeAttribute: getWireframeAttribute
  9744. };
  9745. }
  9746. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  9747. var isWebGL2 = capabilities.isWebGL2;
  9748. var mode;
  9749. function setMode(value) {
  9750. mode = value;
  9751. }
  9752. var type, bytesPerElement;
  9753. function setIndex(value) {
  9754. type = value.type;
  9755. bytesPerElement = value.bytesPerElement;
  9756. }
  9757. function render(start, count) {
  9758. gl.drawElements(mode, count, type, start * bytesPerElement);
  9759. info.update(count, mode, 1);
  9760. }
  9761. function renderInstances(start, count, primcount) {
  9762. if (primcount === 0) return;
  9763. var extension, methodName;
  9764. if (isWebGL2) {
  9765. extension = gl;
  9766. methodName = 'drawElementsInstanced';
  9767. } else {
  9768. extension = extensions.get('ANGLE_instanced_arrays');
  9769. methodName = 'drawElementsInstancedANGLE';
  9770. if (extension === null) {
  9771. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9772. return;
  9773. }
  9774. }
  9775. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  9776. info.update(count, mode, primcount);
  9777. } //
  9778. this.setMode = setMode;
  9779. this.setIndex = setIndex;
  9780. this.render = render;
  9781. this.renderInstances = renderInstances;
  9782. }
  9783. function WebGLInfo(gl) {
  9784. var memory = {
  9785. geometries: 0,
  9786. textures: 0
  9787. };
  9788. var render = {
  9789. frame: 0,
  9790. calls: 0,
  9791. triangles: 0,
  9792. points: 0,
  9793. lines: 0
  9794. };
  9795. function update(count, mode, instanceCount) {
  9796. render.calls++;
  9797. switch (mode) {
  9798. case 4:
  9799. render.triangles += instanceCount * (count / 3);
  9800. break;
  9801. case 1:
  9802. render.lines += instanceCount * (count / 2);
  9803. break;
  9804. case 3:
  9805. render.lines += instanceCount * (count - 1);
  9806. break;
  9807. case 2:
  9808. render.lines += instanceCount * count;
  9809. break;
  9810. case 0:
  9811. render.points += instanceCount * count;
  9812. break;
  9813. default:
  9814. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  9815. break;
  9816. }
  9817. }
  9818. function reset() {
  9819. render.frame++;
  9820. render.calls = 0;
  9821. render.triangles = 0;
  9822. render.points = 0;
  9823. render.lines = 0;
  9824. }
  9825. return {
  9826. memory: memory,
  9827. render: render,
  9828. programs: null,
  9829. autoReset: true,
  9830. reset: reset,
  9831. update: update
  9832. };
  9833. }
  9834. function numericalSort(a, b) {
  9835. return a[0] - b[0];
  9836. }
  9837. function absNumericalSort(a, b) {
  9838. return Math.abs(b[1]) - Math.abs(a[1]);
  9839. }
  9840. function WebGLMorphtargets(gl) {
  9841. var influencesList = {};
  9842. var morphInfluences = new Float32Array(8);
  9843. var workInfluences = [];
  9844. for (var i = 0; i < 8; i++) {
  9845. workInfluences[i] = [i, 0];
  9846. }
  9847. function update(object, geometry, material, program) {
  9848. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  9849. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  9850. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  9851. var influences = influencesList[geometry.id];
  9852. if (influences === undefined) {
  9853. // initialise list
  9854. influences = [];
  9855. for (var _i = 0; _i < length; _i++) {
  9856. influences[_i] = [_i, 0];
  9857. }
  9858. influencesList[geometry.id] = influences;
  9859. } // Collect influences
  9860. for (var _i2 = 0; _i2 < length; _i2++) {
  9861. var influence = influences[_i2];
  9862. influence[0] = _i2;
  9863. influence[1] = objectInfluences[_i2];
  9864. }
  9865. influences.sort(absNumericalSort);
  9866. for (var _i3 = 0; _i3 < 8; _i3++) {
  9867. if (_i3 < length && influences[_i3][1]) {
  9868. workInfluences[_i3][0] = influences[_i3][0];
  9869. workInfluences[_i3][1] = influences[_i3][1];
  9870. } else {
  9871. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  9872. workInfluences[_i3][1] = 0;
  9873. }
  9874. }
  9875. workInfluences.sort(numericalSort);
  9876. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9877. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9878. var morphInfluencesSum = 0;
  9879. for (var _i4 = 0; _i4 < 8; _i4++) {
  9880. var _influence = workInfluences[_i4];
  9881. var index = _influence[0];
  9882. var value = _influence[1];
  9883. if (index !== Number.MAX_SAFE_INTEGER && value) {
  9884. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  9885. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  9886. }
  9887. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  9888. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  9889. }
  9890. morphInfluences[_i4] = value;
  9891. morphInfluencesSum += value;
  9892. } else {
  9893. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== undefined) {
  9894. geometry.deleteAttribute('morphTarget' + _i4);
  9895. }
  9896. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== undefined) {
  9897. geometry.deleteAttribute('morphNormal' + _i4);
  9898. }
  9899. morphInfluences[_i4] = 0;
  9900. }
  9901. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  9902. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  9903. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  9904. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  9905. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  9906. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  9907. }
  9908. return {
  9909. update: update
  9910. };
  9911. }
  9912. function WebGLObjects(gl, geometries, attributes, info) {
  9913. var updateMap = new WeakMap();
  9914. function update(object) {
  9915. var frame = info.render.frame;
  9916. var geometry = object.geometry;
  9917. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  9918. if (updateMap.get(buffergeometry) !== frame) {
  9919. if (geometry.isGeometry) {
  9920. buffergeometry.updateFromObject(object);
  9921. }
  9922. geometries.update(buffergeometry);
  9923. updateMap.set(buffergeometry, frame);
  9924. }
  9925. if (object.isInstancedMesh) {
  9926. attributes.update(object.instanceMatrix, 34962);
  9927. if (object.instanceColor !== null) {
  9928. attributes.update(object.instanceColor, 34962);
  9929. }
  9930. }
  9931. return buffergeometry;
  9932. }
  9933. function dispose() {
  9934. updateMap = new WeakMap();
  9935. }
  9936. return {
  9937. update: update,
  9938. dispose: dispose
  9939. };
  9940. }
  9941. function DataTexture2DArray(data, width, height, depth) {
  9942. Texture.call(this, null);
  9943. this.image = {
  9944. data: data || null,
  9945. width: width || 1,
  9946. height: height || 1,
  9947. depth: depth || 1
  9948. };
  9949. this.magFilter = NearestFilter;
  9950. this.minFilter = NearestFilter;
  9951. this.wrapR = ClampToEdgeWrapping;
  9952. this.generateMipmaps = false;
  9953. this.flipY = false;
  9954. this.needsUpdate = true;
  9955. }
  9956. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  9957. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  9958. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9959. function DataTexture3D(data, width, height, depth) {
  9960. // We're going to add .setXXX() methods for setting properties later.
  9961. // Users can still set in DataTexture3D directly.
  9962. //
  9963. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  9964. // texture.anisotropy = 16;
  9965. //
  9966. // See #14839
  9967. Texture.call(this, null);
  9968. this.image = {
  9969. data: data || null,
  9970. width: width || 1,
  9971. height: height || 1,
  9972. depth: depth || 1
  9973. };
  9974. this.magFilter = NearestFilter;
  9975. this.minFilter = NearestFilter;
  9976. this.wrapR = ClampToEdgeWrapping;
  9977. this.generateMipmaps = false;
  9978. this.flipY = false;
  9979. this.needsUpdate = true;
  9980. }
  9981. DataTexture3D.prototype = Object.create(Texture.prototype);
  9982. DataTexture3D.prototype.constructor = DataTexture3D;
  9983. DataTexture3D.prototype.isDataTexture3D = true;
  9984. /**
  9985. * Uniforms of a program.
  9986. * Those form a tree structure with a special top-level container for the root,
  9987. * which you get by calling 'new WebGLUniforms( gl, program )'.
  9988. *
  9989. *
  9990. * Properties of inner nodes including the top-level container:
  9991. *
  9992. * .seq - array of nested uniforms
  9993. * .map - nested uniforms by name
  9994. *
  9995. *
  9996. * Methods of all nodes except the top-level container:
  9997. *
  9998. * .setValue( gl, value, [textures] )
  9999. *
  10000. * uploads a uniform value(s)
  10001. * the 'textures' parameter is needed for sampler uniforms
  10002. *
  10003. *
  10004. * Static methods of the top-level container (textures factorizations):
  10005. *
  10006. * .upload( gl, seq, values, textures )
  10007. *
  10008. * sets uniforms in 'seq' to 'values[id].value'
  10009. *
  10010. * .seqWithValue( seq, values ) : filteredSeq
  10011. *
  10012. * filters 'seq' entries with corresponding entry in values
  10013. *
  10014. *
  10015. * Methods of the top-level container (textures factorizations):
  10016. *
  10017. * .setValue( gl, name, value, textures )
  10018. *
  10019. * sets uniform with name 'name' to 'value'
  10020. *
  10021. * .setOptional( gl, obj, prop )
  10022. *
  10023. * like .set for an optional property of the object
  10024. *
  10025. */
  10026. var emptyTexture = new Texture();
  10027. var emptyTexture2dArray = new DataTexture2DArray();
  10028. var emptyTexture3d = new DataTexture3D();
  10029. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10030. // Array Caches (provide typed arrays for temporary by size)
  10031. var arrayCacheF32 = [];
  10032. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10033. var mat4array = new Float32Array(16);
  10034. var mat3array = new Float32Array(9);
  10035. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10036. function flatten(array, nBlocks, blockSize) {
  10037. var firstElem = array[0];
  10038. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10039. // see http://jacksondunstan.com/articles/983
  10040. var n = nBlocks * blockSize;
  10041. var r = arrayCacheF32[n];
  10042. if (r === undefined) {
  10043. r = new Float32Array(n);
  10044. arrayCacheF32[n] = r;
  10045. }
  10046. if (nBlocks !== 0) {
  10047. firstElem.toArray(r, 0);
  10048. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10049. offset += blockSize;
  10050. array[i].toArray(r, offset);
  10051. }
  10052. }
  10053. return r;
  10054. }
  10055. function arraysEqual(a, b) {
  10056. if (a.length !== b.length) return false;
  10057. for (var i = 0, l = a.length; i < l; i++) {
  10058. if (a[i] !== b[i]) return false;
  10059. }
  10060. return true;
  10061. }
  10062. function copyArray(a, b) {
  10063. for (var i = 0, l = b.length; i < l; i++) {
  10064. a[i] = b[i];
  10065. }
  10066. } // Texture unit allocation
  10067. function allocTexUnits(textures, n) {
  10068. var r = arrayCacheI32[n];
  10069. if (r === undefined) {
  10070. r = new Int32Array(n);
  10071. arrayCacheI32[n] = r;
  10072. }
  10073. for (var i = 0; i !== n; ++i) {
  10074. r[i] = textures.allocateTextureUnit();
  10075. }
  10076. return r;
  10077. } // --- Setters ---
  10078. // Note: Defining these methods externally, because they come in a bunch
  10079. // and this way their names minify.
  10080. // Single scalar
  10081. function setValueV1f(gl, v) {
  10082. var cache = this.cache;
  10083. if (cache[0] === v) return;
  10084. gl.uniform1f(this.addr, v);
  10085. cache[0] = v;
  10086. } // Single float vector (from flat array or THREE.VectorN)
  10087. function setValueV2f(gl, v) {
  10088. var cache = this.cache;
  10089. if (v.x !== undefined) {
  10090. if (cache[0] !== v.x || cache[1] !== v.y) {
  10091. gl.uniform2f(this.addr, v.x, v.y);
  10092. cache[0] = v.x;
  10093. cache[1] = v.y;
  10094. }
  10095. } else {
  10096. if (arraysEqual(cache, v)) return;
  10097. gl.uniform2fv(this.addr, v);
  10098. copyArray(cache, v);
  10099. }
  10100. }
  10101. function setValueV3f(gl, v) {
  10102. var cache = this.cache;
  10103. if (v.x !== undefined) {
  10104. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10105. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10106. cache[0] = v.x;
  10107. cache[1] = v.y;
  10108. cache[2] = v.z;
  10109. }
  10110. } else if (v.r !== undefined) {
  10111. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10112. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10113. cache[0] = v.r;
  10114. cache[1] = v.g;
  10115. cache[2] = v.b;
  10116. }
  10117. } else {
  10118. if (arraysEqual(cache, v)) return;
  10119. gl.uniform3fv(this.addr, v);
  10120. copyArray(cache, v);
  10121. }
  10122. }
  10123. function setValueV4f(gl, v) {
  10124. var cache = this.cache;
  10125. if (v.x !== undefined) {
  10126. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10127. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10128. cache[0] = v.x;
  10129. cache[1] = v.y;
  10130. cache[2] = v.z;
  10131. cache[3] = v.w;
  10132. }
  10133. } else {
  10134. if (arraysEqual(cache, v)) return;
  10135. gl.uniform4fv(this.addr, v);
  10136. copyArray(cache, v);
  10137. }
  10138. } // Single matrix (from flat array or MatrixN)
  10139. function setValueM2(gl, v) {
  10140. var cache = this.cache;
  10141. var elements = v.elements;
  10142. if (elements === undefined) {
  10143. if (arraysEqual(cache, v)) return;
  10144. gl.uniformMatrix2fv(this.addr, false, v);
  10145. copyArray(cache, v);
  10146. } else {
  10147. if (arraysEqual(cache, elements)) return;
  10148. mat2array.set(elements);
  10149. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10150. copyArray(cache, elements);
  10151. }
  10152. }
  10153. function setValueM3(gl, v) {
  10154. var cache = this.cache;
  10155. var elements = v.elements;
  10156. if (elements === undefined) {
  10157. if (arraysEqual(cache, v)) return;
  10158. gl.uniformMatrix3fv(this.addr, false, v);
  10159. copyArray(cache, v);
  10160. } else {
  10161. if (arraysEqual(cache, elements)) return;
  10162. mat3array.set(elements);
  10163. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10164. copyArray(cache, elements);
  10165. }
  10166. }
  10167. function setValueM4(gl, v) {
  10168. var cache = this.cache;
  10169. var elements = v.elements;
  10170. if (elements === undefined) {
  10171. if (arraysEqual(cache, v)) return;
  10172. gl.uniformMatrix4fv(this.addr, false, v);
  10173. copyArray(cache, v);
  10174. } else {
  10175. if (arraysEqual(cache, elements)) return;
  10176. mat4array.set(elements);
  10177. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10178. copyArray(cache, elements);
  10179. }
  10180. } // Single texture (2D / Cube)
  10181. function setValueT1(gl, v, textures) {
  10182. var cache = this.cache;
  10183. var unit = textures.allocateTextureUnit();
  10184. if (cache[0] !== unit) {
  10185. gl.uniform1i(this.addr, unit);
  10186. cache[0] = unit;
  10187. }
  10188. textures.safeSetTexture2D(v || emptyTexture, unit);
  10189. }
  10190. function setValueT2DArray1(gl, v, textures) {
  10191. var cache = this.cache;
  10192. var unit = textures.allocateTextureUnit();
  10193. if (cache[0] !== unit) {
  10194. gl.uniform1i(this.addr, unit);
  10195. cache[0] = unit;
  10196. }
  10197. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10198. }
  10199. function setValueT3D1(gl, v, textures) {
  10200. var cache = this.cache;
  10201. var unit = textures.allocateTextureUnit();
  10202. if (cache[0] !== unit) {
  10203. gl.uniform1i(this.addr, unit);
  10204. cache[0] = unit;
  10205. }
  10206. textures.setTexture3D(v || emptyTexture3d, unit);
  10207. }
  10208. function setValueT6(gl, v, textures) {
  10209. var cache = this.cache;
  10210. var unit = textures.allocateTextureUnit();
  10211. if (cache[0] !== unit) {
  10212. gl.uniform1i(this.addr, unit);
  10213. cache[0] = unit;
  10214. }
  10215. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10216. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10217. function setValueV1i(gl, v) {
  10218. var cache = this.cache;
  10219. if (cache[0] === v) return;
  10220. gl.uniform1i(this.addr, v);
  10221. cache[0] = v;
  10222. }
  10223. function setValueV2i(gl, v) {
  10224. var cache = this.cache;
  10225. if (arraysEqual(cache, v)) return;
  10226. gl.uniform2iv(this.addr, v);
  10227. copyArray(cache, v);
  10228. }
  10229. function setValueV3i(gl, v) {
  10230. var cache = this.cache;
  10231. if (arraysEqual(cache, v)) return;
  10232. gl.uniform3iv(this.addr, v);
  10233. copyArray(cache, v);
  10234. }
  10235. function setValueV4i(gl, v) {
  10236. var cache = this.cache;
  10237. if (arraysEqual(cache, v)) return;
  10238. gl.uniform4iv(this.addr, v);
  10239. copyArray(cache, v);
  10240. } // uint
  10241. function setValueV1ui(gl, v) {
  10242. var cache = this.cache;
  10243. if (cache[0] === v) return;
  10244. gl.uniform1ui(this.addr, v);
  10245. cache[0] = v;
  10246. } // Helper to pick the right setter for the singular case
  10247. function getSingularSetter(type) {
  10248. switch (type) {
  10249. case 0x1406:
  10250. return setValueV1f;
  10251. // FLOAT
  10252. case 0x8b50:
  10253. return setValueV2f;
  10254. // _VEC2
  10255. case 0x8b51:
  10256. return setValueV3f;
  10257. // _VEC3
  10258. case 0x8b52:
  10259. return setValueV4f;
  10260. // _VEC4
  10261. case 0x8b5a:
  10262. return setValueM2;
  10263. // _MAT2
  10264. case 0x8b5b:
  10265. return setValueM3;
  10266. // _MAT3
  10267. case 0x8b5c:
  10268. return setValueM4;
  10269. // _MAT4
  10270. case 0x1404:
  10271. case 0x8b56:
  10272. return setValueV1i;
  10273. // INT, BOOL
  10274. case 0x8b53:
  10275. case 0x8b57:
  10276. return setValueV2i;
  10277. // _VEC2
  10278. case 0x8b54:
  10279. case 0x8b58:
  10280. return setValueV3i;
  10281. // _VEC3
  10282. case 0x8b55:
  10283. case 0x8b59:
  10284. return setValueV4i;
  10285. // _VEC4
  10286. case 0x1405:
  10287. return setValueV1ui;
  10288. // UINT
  10289. case 0x8b5e: // SAMPLER_2D
  10290. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10291. case 0x8dca: // INT_SAMPLER_2D
  10292. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10293. case 0x8b62:
  10294. // SAMPLER_2D_SHADOW
  10295. return setValueT1;
  10296. case 0x8b5f: // SAMPLER_3D
  10297. case 0x8dcb: // INT_SAMPLER_3D
  10298. case 0x8dd3:
  10299. // UNSIGNED_INT_SAMPLER_3D
  10300. return setValueT3D1;
  10301. case 0x8b60: // SAMPLER_CUBE
  10302. case 0x8dcc: // INT_SAMPLER_CUBE
  10303. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10304. case 0x8dc5:
  10305. // SAMPLER_CUBE_SHADOW
  10306. return setValueT6;
  10307. case 0x8dc1: // SAMPLER_2D_ARRAY
  10308. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10309. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10310. case 0x8dc4:
  10311. // SAMPLER_2D_ARRAY_SHADOW
  10312. return setValueT2DArray1;
  10313. }
  10314. } // Array of scalars
  10315. function setValueV1fArray(gl, v) {
  10316. gl.uniform1fv(this.addr, v);
  10317. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10318. function setValueV1iArray(gl, v) {
  10319. gl.uniform1iv(this.addr, v);
  10320. }
  10321. function setValueV2iArray(gl, v) {
  10322. gl.uniform2iv(this.addr, v);
  10323. }
  10324. function setValueV3iArray(gl, v) {
  10325. gl.uniform3iv(this.addr, v);
  10326. }
  10327. function setValueV4iArray(gl, v) {
  10328. gl.uniform4iv(this.addr, v);
  10329. } // Array of vectors (flat or from THREE classes)
  10330. function setValueV2fArray(gl, v) {
  10331. var data = flatten(v, this.size, 2);
  10332. gl.uniform2fv(this.addr, data);
  10333. }
  10334. function setValueV3fArray(gl, v) {
  10335. var data = flatten(v, this.size, 3);
  10336. gl.uniform3fv(this.addr, data);
  10337. }
  10338. function setValueV4fArray(gl, v) {
  10339. var data = flatten(v, this.size, 4);
  10340. gl.uniform4fv(this.addr, data);
  10341. } // Array of matrices (flat or from THREE clases)
  10342. function setValueM2Array(gl, v) {
  10343. var data = flatten(v, this.size, 4);
  10344. gl.uniformMatrix2fv(this.addr, false, data);
  10345. }
  10346. function setValueM3Array(gl, v) {
  10347. var data = flatten(v, this.size, 9);
  10348. gl.uniformMatrix3fv(this.addr, false, data);
  10349. }
  10350. function setValueM4Array(gl, v) {
  10351. var data = flatten(v, this.size, 16);
  10352. gl.uniformMatrix4fv(this.addr, false, data);
  10353. } // Array of textures (2D / Cube)
  10354. function setValueT1Array(gl, v, textures) {
  10355. var n = v.length;
  10356. var units = allocTexUnits(textures, n);
  10357. gl.uniform1iv(this.addr, units);
  10358. for (var i = 0; i !== n; ++i) {
  10359. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  10360. }
  10361. }
  10362. function setValueT6Array(gl, v, textures) {
  10363. var n = v.length;
  10364. var units = allocTexUnits(textures, n);
  10365. gl.uniform1iv(this.addr, units);
  10366. for (var i = 0; i !== n; ++i) {
  10367. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  10368. }
  10369. } // Helper to pick the right setter for a pure (bottom-level) array
  10370. function getPureArraySetter(type) {
  10371. switch (type) {
  10372. case 0x1406:
  10373. return setValueV1fArray;
  10374. // FLOAT
  10375. case 0x8b50:
  10376. return setValueV2fArray;
  10377. // _VEC2
  10378. case 0x8b51:
  10379. return setValueV3fArray;
  10380. // _VEC3
  10381. case 0x8b52:
  10382. return setValueV4fArray;
  10383. // _VEC4
  10384. case 0x8b5a:
  10385. return setValueM2Array;
  10386. // _MAT2
  10387. case 0x8b5b:
  10388. return setValueM3Array;
  10389. // _MAT3
  10390. case 0x8b5c:
  10391. return setValueM4Array;
  10392. // _MAT4
  10393. case 0x1404:
  10394. case 0x8b56:
  10395. return setValueV1iArray;
  10396. // INT, BOOL
  10397. case 0x8b53:
  10398. case 0x8b57:
  10399. return setValueV2iArray;
  10400. // _VEC2
  10401. case 0x8b54:
  10402. case 0x8b58:
  10403. return setValueV3iArray;
  10404. // _VEC3
  10405. case 0x8b55:
  10406. case 0x8b59:
  10407. return setValueV4iArray;
  10408. // _VEC4
  10409. case 0x8b5e: // SAMPLER_2D
  10410. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10411. case 0x8dca: // INT_SAMPLER_2D
  10412. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10413. case 0x8b62:
  10414. // SAMPLER_2D_SHADOW
  10415. return setValueT1Array;
  10416. case 0x8b60: // SAMPLER_CUBE
  10417. case 0x8dcc: // INT_SAMPLER_CUBE
  10418. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10419. case 0x8dc5:
  10420. // SAMPLER_CUBE_SHADOW
  10421. return setValueT6Array;
  10422. }
  10423. } // --- Uniform Classes ---
  10424. function SingleUniform(id, activeInfo, addr) {
  10425. this.id = id;
  10426. this.addr = addr;
  10427. this.cache = [];
  10428. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10429. }
  10430. function PureArrayUniform(id, activeInfo, addr) {
  10431. this.id = id;
  10432. this.addr = addr;
  10433. this.cache = [];
  10434. this.size = activeInfo.size;
  10435. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10436. }
  10437. PureArrayUniform.prototype.updateCache = function (data) {
  10438. var cache = this.cache;
  10439. if (data instanceof Float32Array && cache.length !== data.length) {
  10440. this.cache = new Float32Array(data.length);
  10441. }
  10442. copyArray(cache, data);
  10443. };
  10444. function StructuredUniform(id) {
  10445. this.id = id;
  10446. this.seq = [];
  10447. this.map = {};
  10448. }
  10449. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  10450. var seq = this.seq;
  10451. for (var i = 0, n = seq.length; i !== n; ++i) {
  10452. var u = seq[i];
  10453. u.setValue(gl, value[u.id], textures);
  10454. }
  10455. }; // --- Top-level ---
  10456. // Parser - builds up the property tree from the path strings
  10457. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g; // extracts
  10458. // - the identifier (member name or array index)
  10459. // - followed by an optional right bracket (found when array index)
  10460. // - followed by an optional left bracket or dot (type of subscript)
  10461. //
  10462. // Note: These portions can be read in a non-overlapping fashion and
  10463. // allow straightforward parsing of the hierarchy that WebGL encodes
  10464. // in the uniform names.
  10465. function addUniform(container, uniformObject) {
  10466. container.seq.push(uniformObject);
  10467. container.map[uniformObject.id] = uniformObject;
  10468. }
  10469. function parseUniform(activeInfo, addr, container) {
  10470. var path = activeInfo.name,
  10471. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  10472. RePathPart.lastIndex = 0;
  10473. while (true) {
  10474. var match = RePathPart.exec(path),
  10475. matchEnd = RePathPart.lastIndex;
  10476. var id = match[1];
  10477. var idIsIndex = match[2] === ']',
  10478. subscript = match[3];
  10479. if (idIsIndex) id = id | 0; // convert to integer
  10480. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  10481. // bare name or "pure" bottom-level array "[0]" suffix
  10482. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  10483. break;
  10484. } else {
  10485. // step into inner node / create it in case it doesn't exist
  10486. var map = container.map;
  10487. var next = map[id];
  10488. if (next === undefined) {
  10489. next = new StructuredUniform(id);
  10490. addUniform(container, next);
  10491. }
  10492. container = next;
  10493. }
  10494. }
  10495. } // Root Container
  10496. function WebGLUniforms(gl, program) {
  10497. this.seq = [];
  10498. this.map = {};
  10499. var n = gl.getProgramParameter(program, 35718);
  10500. for (var i = 0; i < n; ++i) {
  10501. var info = gl.getActiveUniform(program, i),
  10502. addr = gl.getUniformLocation(program, info.name);
  10503. parseUniform(info, addr, this);
  10504. }
  10505. }
  10506. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  10507. var u = this.map[name];
  10508. if (u !== undefined) u.setValue(gl, value, textures);
  10509. };
  10510. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  10511. var v = object[name];
  10512. if (v !== undefined) this.setValue(gl, name, v);
  10513. }; // Static interface
  10514. WebGLUniforms.upload = function (gl, seq, values, textures) {
  10515. for (var i = 0, n = seq.length; i !== n; ++i) {
  10516. var u = seq[i],
  10517. v = values[u.id];
  10518. if (v.needsUpdate !== false) {
  10519. // note: always updating when .needsUpdate is undefined
  10520. u.setValue(gl, v.value, textures);
  10521. }
  10522. }
  10523. };
  10524. WebGLUniforms.seqWithValue = function (seq, values) {
  10525. var r = [];
  10526. for (var i = 0, n = seq.length; i !== n; ++i) {
  10527. var u = seq[i];
  10528. if (u.id in values) r.push(u);
  10529. }
  10530. return r;
  10531. };
  10532. function WebGLShader(gl, type, string) {
  10533. var shader = gl.createShader(type);
  10534. gl.shaderSource(shader, string);
  10535. gl.compileShader(shader);
  10536. return shader;
  10537. }
  10538. var programIdCount = 0;
  10539. function addLineNumbers(string) {
  10540. var lines = string.split('\n');
  10541. for (var i = 0; i < lines.length; i++) {
  10542. lines[i] = i + 1 + ': ' + lines[i];
  10543. }
  10544. return lines.join('\n');
  10545. }
  10546. function getEncodingComponents(encoding) {
  10547. switch (encoding) {
  10548. case LinearEncoding:
  10549. return ['Linear', '( value )'];
  10550. case sRGBEncoding:
  10551. return ['sRGB', '( value )'];
  10552. case RGBEEncoding:
  10553. return ['RGBE', '( value )'];
  10554. case RGBM7Encoding:
  10555. return ['RGBM', '( value, 7.0 )'];
  10556. case RGBM16Encoding:
  10557. return ['RGBM', '( value, 16.0 )'];
  10558. case RGBDEncoding:
  10559. return ['RGBD', '( value, 256.0 )'];
  10560. case GammaEncoding:
  10561. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  10562. case LogLuvEncoding:
  10563. return ['LogLuv', '( value )'];
  10564. default:
  10565. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  10566. return ['Linear', '( value )'];
  10567. }
  10568. }
  10569. function getShaderErrors(gl, shader, type) {
  10570. var status = gl.getShaderParameter(shader, 35713);
  10571. var log = gl.getShaderInfoLog(shader).trim();
  10572. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  10573. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10574. var source = gl.getShaderSource(shader);
  10575. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  10576. }
  10577. function getTexelDecodingFunction(functionName, encoding) {
  10578. var components = getEncodingComponents(encoding);
  10579. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  10580. }
  10581. function getTexelEncodingFunction(functionName, encoding) {
  10582. var components = getEncodingComponents(encoding);
  10583. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  10584. }
  10585. function getToneMappingFunction(functionName, toneMapping) {
  10586. var toneMappingName;
  10587. switch (toneMapping) {
  10588. case LinearToneMapping:
  10589. toneMappingName = 'Linear';
  10590. break;
  10591. case ReinhardToneMapping:
  10592. toneMappingName = 'Reinhard';
  10593. break;
  10594. case CineonToneMapping:
  10595. toneMappingName = 'OptimizedCineon';
  10596. break;
  10597. case ACESFilmicToneMapping:
  10598. toneMappingName = 'ACESFilmic';
  10599. break;
  10600. case CustomToneMapping:
  10601. toneMappingName = 'Custom';
  10602. break;
  10603. default:
  10604. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  10605. toneMappingName = 'Linear';
  10606. }
  10607. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10608. }
  10609. function generateExtensions(parameters) {
  10610. 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' : ''];
  10611. return chunks.filter(filterEmptyLine).join('\n');
  10612. }
  10613. function generateDefines(defines) {
  10614. var chunks = [];
  10615. for (var name in defines) {
  10616. var value = defines[name];
  10617. if (value === false) continue;
  10618. chunks.push('#define ' + name + ' ' + value);
  10619. }
  10620. return chunks.join('\n');
  10621. }
  10622. function fetchAttributeLocations(gl, program) {
  10623. var attributes = {};
  10624. var n = gl.getProgramParameter(program, 35721);
  10625. for (var i = 0; i < n; i++) {
  10626. var info = gl.getActiveAttrib(program, i);
  10627. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10628. attributes[name] = gl.getAttribLocation(program, name);
  10629. }
  10630. return attributes;
  10631. }
  10632. function filterEmptyLine(string) {
  10633. return string !== '';
  10634. }
  10635. function replaceLightNums(string, parameters) {
  10636. 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);
  10637. }
  10638. function replaceClippingPlaneNums(string, parameters) {
  10639. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  10640. } // Resolve Includes
  10641. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10642. function resolveIncludes(string) {
  10643. return string.replace(includePattern, includeReplacer);
  10644. }
  10645. function includeReplacer(match, include) {
  10646. var string = ShaderChunk[include];
  10647. if (string === undefined) {
  10648. throw new Error('Can not resolve #include <' + include + '>');
  10649. }
  10650. return resolveIncludes(string);
  10651. } // Unroll Loops
  10652. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10653. 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;
  10654. function unrollLoops(string) {
  10655. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  10656. }
  10657. function deprecatedLoopReplacer(match, start, end, snippet) {
  10658. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  10659. return loopReplacer(match, start, end, snippet);
  10660. }
  10661. function loopReplacer(match, start, end, snippet) {
  10662. var string = '';
  10663. for (var i = parseInt(start); i < parseInt(end); i++) {
  10664. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  10665. }
  10666. return string;
  10667. } //
  10668. function generatePrecision(parameters) {
  10669. var precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;";
  10670. if (parameters.precision === "highp") {
  10671. precisionstring += "\n#define HIGH_PRECISION";
  10672. } else if (parameters.precision === "mediump") {
  10673. precisionstring += "\n#define MEDIUM_PRECISION";
  10674. } else if (parameters.precision === "lowp") {
  10675. precisionstring += "\n#define LOW_PRECISION";
  10676. }
  10677. return precisionstring;
  10678. }
  10679. function generateShadowMapTypeDefine(parameters) {
  10680. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10681. if (parameters.shadowMapType === PCFShadowMap) {
  10682. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10683. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  10684. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10685. } else if (parameters.shadowMapType === VSMShadowMap) {
  10686. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  10687. }
  10688. return shadowMapTypeDefine;
  10689. }
  10690. function generateEnvMapTypeDefine(parameters) {
  10691. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10692. if (parameters.envMap) {
  10693. switch (parameters.envMapMode) {
  10694. case CubeReflectionMapping:
  10695. case CubeRefractionMapping:
  10696. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10697. break;
  10698. case CubeUVReflectionMapping:
  10699. case CubeUVRefractionMapping:
  10700. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10701. break;
  10702. }
  10703. }
  10704. return envMapTypeDefine;
  10705. }
  10706. function generateEnvMapModeDefine(parameters) {
  10707. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10708. if (parameters.envMap) {
  10709. switch (parameters.envMapMode) {
  10710. case CubeRefractionMapping:
  10711. case CubeUVRefractionMapping:
  10712. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10713. break;
  10714. }
  10715. }
  10716. return envMapModeDefine;
  10717. }
  10718. function generateEnvMapBlendingDefine(parameters) {
  10719. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  10720. if (parameters.envMap) {
  10721. switch (parameters.combine) {
  10722. case MultiplyOperation:
  10723. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10724. break;
  10725. case MixOperation:
  10726. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10727. break;
  10728. case AddOperation:
  10729. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10730. break;
  10731. }
  10732. }
  10733. return envMapBlendingDefine;
  10734. }
  10735. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  10736. var gl = renderer.getContext();
  10737. var defines = parameters.defines;
  10738. var vertexShader = parameters.vertexShader;
  10739. var fragmentShader = parameters.fragmentShader;
  10740. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  10741. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  10742. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  10743. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  10744. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  10745. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  10746. var customDefines = generateDefines(defines);
  10747. var program = gl.createProgram();
  10748. var prefixVertex, prefixFragment;
  10749. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + "\n" : '';
  10750. if (parameters.isRawShaderMaterial) {
  10751. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  10752. if (prefixVertex.length > 0) {
  10753. prefixVertex += '\n';
  10754. }
  10755. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  10756. if (prefixFragment.length > 0) {
  10757. prefixFragment += '\n';
  10758. }
  10759. } else {
  10760. 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');
  10761. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  10762. '#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
  10763. 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
  10764. 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');
  10765. }
  10766. vertexShader = resolveIncludes(vertexShader);
  10767. vertexShader = replaceLightNums(vertexShader, parameters);
  10768. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  10769. fragmentShader = resolveIncludes(fragmentShader);
  10770. fragmentShader = replaceLightNums(fragmentShader, parameters);
  10771. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  10772. vertexShader = unrollLoops(vertexShader);
  10773. fragmentShader = unrollLoops(fragmentShader);
  10774. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  10775. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  10776. versionString = '#version 300 es\n';
  10777. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  10778. 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;
  10779. }
  10780. var vertexGlsl = versionString + prefixVertex + vertexShader;
  10781. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  10782. // console.log( '*FRAGMENT*', fragmentGlsl );
  10783. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  10784. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  10785. gl.attachShader(program, glVertexShader);
  10786. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  10787. if (parameters.index0AttributeName !== undefined) {
  10788. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  10789. } else if (parameters.morphTargets === true) {
  10790. // programs with morphTargets displace position out of attribute 0
  10791. gl.bindAttribLocation(program, 0, 'position');
  10792. }
  10793. gl.linkProgram(program); // check for link errors
  10794. if (renderer.debug.checkShaderErrors) {
  10795. var programLog = gl.getProgramInfoLog(program).trim();
  10796. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  10797. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  10798. var runnable = true;
  10799. var haveDiagnostics = true;
  10800. if (gl.getProgramParameter(program, 35714) === false) {
  10801. runnable = false;
  10802. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  10803. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  10804. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  10805. } else if (programLog !== '') {
  10806. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  10807. } else if (vertexLog === '' || fragmentLog === '') {
  10808. haveDiagnostics = false;
  10809. }
  10810. if (haveDiagnostics) {
  10811. this.diagnostics = {
  10812. runnable: runnable,
  10813. programLog: programLog,
  10814. vertexShader: {
  10815. log: vertexLog,
  10816. prefix: prefixVertex
  10817. },
  10818. fragmentShader: {
  10819. log: fragmentLog,
  10820. prefix: prefixFragment
  10821. }
  10822. };
  10823. }
  10824. } // Clean up
  10825. // Crashes in iOS9 and iOS10. #18402
  10826. // gl.detachShader( program, glVertexShader );
  10827. // gl.detachShader( program, glFragmentShader );
  10828. gl.deleteShader(glVertexShader);
  10829. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  10830. var cachedUniforms;
  10831. this.getUniforms = function () {
  10832. if (cachedUniforms === undefined) {
  10833. cachedUniforms = new WebGLUniforms(gl, program);
  10834. }
  10835. return cachedUniforms;
  10836. }; // set up caching for attribute locations
  10837. var cachedAttributes;
  10838. this.getAttributes = function () {
  10839. if (cachedAttributes === undefined) {
  10840. cachedAttributes = fetchAttributeLocations(gl, program);
  10841. }
  10842. return cachedAttributes;
  10843. }; // free resource
  10844. this.destroy = function () {
  10845. bindingStates.releaseStatesOfProgram(this);
  10846. gl.deleteProgram(program);
  10847. this.program = undefined;
  10848. }; //
  10849. this.name = parameters.shaderName;
  10850. this.id = programIdCount++;
  10851. this.cacheKey = cacheKey;
  10852. this.usedTimes = 1;
  10853. this.program = program;
  10854. this.vertexShader = glVertexShader;
  10855. this.fragmentShader = glFragmentShader;
  10856. return this;
  10857. }
  10858. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  10859. var programs = [];
  10860. var isWebGL2 = capabilities.isWebGL2;
  10861. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  10862. var floatVertexTextures = capabilities.floatVertexTextures;
  10863. var maxVertexUniforms = capabilities.maxVertexUniforms;
  10864. var vertexTextures = capabilities.vertexTextures;
  10865. var precision = capabilities.precision;
  10866. var shaderIDs = {
  10867. MeshDepthMaterial: 'depth',
  10868. MeshDistanceMaterial: 'distanceRGBA',
  10869. MeshNormalMaterial: 'normal',
  10870. MeshBasicMaterial: 'basic',
  10871. MeshLambertMaterial: 'lambert',
  10872. MeshPhongMaterial: 'phong',
  10873. MeshToonMaterial: 'toon',
  10874. MeshStandardMaterial: 'physical',
  10875. MeshPhysicalMaterial: 'physical',
  10876. MeshMatcapMaterial: 'matcap',
  10877. LineBasicMaterial: 'basic',
  10878. LineDashedMaterial: 'dashed',
  10879. PointsMaterial: 'points',
  10880. ShadowMaterial: 'shadow',
  10881. SpriteMaterial: 'sprite'
  10882. };
  10883. 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"];
  10884. function getMaxBones(object) {
  10885. var skeleton = object.skeleton;
  10886. var bones = skeleton.bones;
  10887. if (floatVertexTextures) {
  10888. return 1024;
  10889. } else {
  10890. // default for when object is not specified
  10891. // ( for example when prebuilding shader to be used with multiple objects )
  10892. //
  10893. // - leave some extra space for other uniforms
  10894. // - limit here is ANGLE's 254 max uniform vectors
  10895. // (up to 54 should be safe)
  10896. var nVertexUniforms = maxVertexUniforms;
  10897. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  10898. var maxBones = Math.min(nVertexMatrices, bones.length);
  10899. if (maxBones < bones.length) {
  10900. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  10901. return 0;
  10902. }
  10903. return maxBones;
  10904. }
  10905. }
  10906. function getTextureEncodingFromMap(map) {
  10907. var encoding;
  10908. if (!map) {
  10909. encoding = LinearEncoding;
  10910. } else if (map.isTexture) {
  10911. encoding = map.encoding;
  10912. } else if (map.isWebGLRenderTarget) {
  10913. console.warn("THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead.");
  10914. encoding = map.texture.encoding;
  10915. }
  10916. return encoding;
  10917. }
  10918. function getParameters(material, lights, shadows, scene, object) {
  10919. var fog = scene.fog;
  10920. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  10921. var envMap = cubemaps.get(material.envMap || environment);
  10922. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  10923. // (not to blow over maxLights budget)
  10924. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  10925. if (material.precision !== null) {
  10926. precision = capabilities.getMaxPrecision(material.precision);
  10927. if (precision !== material.precision) {
  10928. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  10929. }
  10930. }
  10931. var vertexShader, fragmentShader;
  10932. if (shaderID) {
  10933. var shader = ShaderLib[shaderID];
  10934. vertexShader = shader.vertexShader;
  10935. fragmentShader = shader.fragmentShader;
  10936. } else {
  10937. vertexShader = material.vertexShader;
  10938. fragmentShader = material.fragmentShader;
  10939. }
  10940. var currentRenderTarget = renderer.getRenderTarget();
  10941. var parameters = {
  10942. isWebGL2: isWebGL2,
  10943. shaderID: shaderID,
  10944. shaderName: material.type,
  10945. vertexShader: vertexShader,
  10946. fragmentShader: fragmentShader,
  10947. defines: material.defines,
  10948. isRawShaderMaterial: material.isRawShaderMaterial === true,
  10949. glslVersion: material.glslVersion,
  10950. precision: precision,
  10951. instancing: object.isInstancedMesh === true,
  10952. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  10953. supportsVertexTextures: vertexTextures,
  10954. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  10955. map: !!material.map,
  10956. mapEncoding: getTextureEncodingFromMap(material.map),
  10957. matcap: !!material.matcap,
  10958. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  10959. envMap: !!envMap,
  10960. envMapMode: envMap && envMap.mapping,
  10961. envMapEncoding: getTextureEncodingFromMap(envMap),
  10962. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  10963. lightMap: !!material.lightMap,
  10964. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  10965. aoMap: !!material.aoMap,
  10966. emissiveMap: !!material.emissiveMap,
  10967. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  10968. bumpMap: !!material.bumpMap,
  10969. normalMap: !!material.normalMap,
  10970. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  10971. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  10972. clearcoatMap: !!material.clearcoatMap,
  10973. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  10974. clearcoatNormalMap: !!material.clearcoatNormalMap,
  10975. displacementMap: !!material.displacementMap,
  10976. roughnessMap: !!material.roughnessMap,
  10977. metalnessMap: !!material.metalnessMap,
  10978. specularMap: !!material.specularMap,
  10979. alphaMap: !!material.alphaMap,
  10980. gradientMap: !!material.gradientMap,
  10981. sheen: !!material.sheen,
  10982. transmissionMap: !!material.transmissionMap,
  10983. combine: material.combine,
  10984. vertexTangents: material.normalMap && material.vertexTangents,
  10985. vertexColors: material.vertexColors,
  10986. 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,
  10987. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  10988. fog: !!fog,
  10989. useFog: material.fog,
  10990. fogExp2: fog && fog.isFogExp2,
  10991. flatShading: material.flatShading,
  10992. sizeAttenuation: material.sizeAttenuation,
  10993. logarithmicDepthBuffer: logarithmicDepthBuffer,
  10994. skinning: material.skinning && maxBones > 0,
  10995. maxBones: maxBones,
  10996. useVertexTexture: floatVertexTextures,
  10997. morphTargets: material.morphTargets,
  10998. morphNormals: material.morphNormals,
  10999. maxMorphTargets: renderer.maxMorphTargets,
  11000. maxMorphNormals: renderer.maxMorphNormals,
  11001. numDirLights: lights.directional.length,
  11002. numPointLights: lights.point.length,
  11003. numSpotLights: lights.spot.length,
  11004. numRectAreaLights: lights.rectArea.length,
  11005. numHemiLights: lights.hemi.length,
  11006. numDirLightShadows: lights.directionalShadowMap.length,
  11007. numPointLightShadows: lights.pointShadowMap.length,
  11008. numSpotLightShadows: lights.spotShadowMap.length,
  11009. numClippingPlanes: clipping.numPlanes,
  11010. numClipIntersection: clipping.numIntersection,
  11011. dithering: material.dithering,
  11012. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11013. shadowMapType: renderer.shadowMap.type,
  11014. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11015. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11016. premultipliedAlpha: material.premultipliedAlpha,
  11017. alphaTest: material.alphaTest,
  11018. doubleSided: material.side === DoubleSide,
  11019. flipSided: material.side === BackSide,
  11020. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11021. index0AttributeName: material.index0AttributeName,
  11022. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11023. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11024. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11025. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11026. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11027. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11028. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11029. customProgramCacheKey: material.customProgramCacheKey()
  11030. };
  11031. return parameters;
  11032. }
  11033. function getProgramCacheKey(parameters) {
  11034. var array = [];
  11035. if (parameters.shaderID) {
  11036. array.push(parameters.shaderID);
  11037. } else {
  11038. array.push(parameters.fragmentShader);
  11039. array.push(parameters.vertexShader);
  11040. }
  11041. if (parameters.defines !== undefined) {
  11042. for (var name in parameters.defines) {
  11043. array.push(name);
  11044. array.push(parameters.defines[name]);
  11045. }
  11046. }
  11047. if (parameters.isRawShaderMaterial === false) {
  11048. for (var i = 0; i < parameterNames.length; i++) {
  11049. array.push(parameters[parameterNames[i]]);
  11050. }
  11051. array.push(renderer.outputEncoding);
  11052. array.push(renderer.gammaFactor);
  11053. }
  11054. array.push(parameters.customProgramCacheKey);
  11055. return array.join();
  11056. }
  11057. function getUniforms(material) {
  11058. var shaderID = shaderIDs[material.type];
  11059. var uniforms;
  11060. if (shaderID) {
  11061. var shader = ShaderLib[shaderID];
  11062. uniforms = UniformsUtils.clone(shader.uniforms);
  11063. } else {
  11064. uniforms = material.uniforms;
  11065. }
  11066. return uniforms;
  11067. }
  11068. function acquireProgram(parameters, cacheKey) {
  11069. var program; // Check if code has been already compiled
  11070. for (var p = 0, pl = programs.length; p < pl; p++) {
  11071. var preexistingProgram = programs[p];
  11072. if (preexistingProgram.cacheKey === cacheKey) {
  11073. program = preexistingProgram;
  11074. ++program.usedTimes;
  11075. break;
  11076. }
  11077. }
  11078. if (program === undefined) {
  11079. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11080. programs.push(program);
  11081. }
  11082. return program;
  11083. }
  11084. function releaseProgram(program) {
  11085. if (--program.usedTimes === 0) {
  11086. // Remove from unordered set
  11087. var i = programs.indexOf(program);
  11088. programs[i] = programs[programs.length - 1];
  11089. programs.pop(); // Free WebGL resources
  11090. program.destroy();
  11091. }
  11092. }
  11093. return {
  11094. getParameters: getParameters,
  11095. getProgramCacheKey: getProgramCacheKey,
  11096. getUniforms: getUniforms,
  11097. acquireProgram: acquireProgram,
  11098. releaseProgram: releaseProgram,
  11099. // Exposed for resource monitoring & error feedback via renderer.info:
  11100. programs: programs
  11101. };
  11102. }
  11103. function WebGLProperties() {
  11104. var properties = new WeakMap();
  11105. function get(object) {
  11106. var map = properties.get(object);
  11107. if (map === undefined) {
  11108. map = {};
  11109. properties.set(object, map);
  11110. }
  11111. return map;
  11112. }
  11113. function remove(object) {
  11114. properties.delete(object);
  11115. }
  11116. function update(object, key, value) {
  11117. properties.get(object)[key] = value;
  11118. }
  11119. function dispose() {
  11120. properties = new WeakMap();
  11121. }
  11122. return {
  11123. get: get,
  11124. remove: remove,
  11125. update: update,
  11126. dispose: dispose
  11127. };
  11128. }
  11129. function painterSortStable(a, b) {
  11130. if (a.groupOrder !== b.groupOrder) {
  11131. return a.groupOrder - b.groupOrder;
  11132. } else if (a.renderOrder !== b.renderOrder) {
  11133. return a.renderOrder - b.renderOrder;
  11134. } else if (a.program !== b.program) {
  11135. return a.program.id - b.program.id;
  11136. } else if (a.material.id !== b.material.id) {
  11137. return a.material.id - b.material.id;
  11138. } else if (a.z !== b.z) {
  11139. return a.z - b.z;
  11140. } else {
  11141. return a.id - b.id;
  11142. }
  11143. }
  11144. function reversePainterSortStable(a, b) {
  11145. if (a.groupOrder !== b.groupOrder) {
  11146. return a.groupOrder - b.groupOrder;
  11147. } else if (a.renderOrder !== b.renderOrder) {
  11148. return a.renderOrder - b.renderOrder;
  11149. } else if (a.z !== b.z) {
  11150. return b.z - a.z;
  11151. } else {
  11152. return a.id - b.id;
  11153. }
  11154. }
  11155. function WebGLRenderList(properties) {
  11156. var renderItems = [];
  11157. var renderItemsIndex = 0;
  11158. var opaque = [];
  11159. var transparent = [];
  11160. var defaultProgram = {
  11161. id: -1
  11162. };
  11163. function init() {
  11164. renderItemsIndex = 0;
  11165. opaque.length = 0;
  11166. transparent.length = 0;
  11167. }
  11168. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11169. var renderItem = renderItems[renderItemsIndex];
  11170. var materialProperties = properties.get(material);
  11171. if (renderItem === undefined) {
  11172. renderItem = {
  11173. id: object.id,
  11174. object: object,
  11175. geometry: geometry,
  11176. material: material,
  11177. program: materialProperties.program || defaultProgram,
  11178. groupOrder: groupOrder,
  11179. renderOrder: object.renderOrder,
  11180. z: z,
  11181. group: group
  11182. };
  11183. renderItems[renderItemsIndex] = renderItem;
  11184. } else {
  11185. renderItem.id = object.id;
  11186. renderItem.object = object;
  11187. renderItem.geometry = geometry;
  11188. renderItem.material = material;
  11189. renderItem.program = materialProperties.program || defaultProgram;
  11190. renderItem.groupOrder = groupOrder;
  11191. renderItem.renderOrder = object.renderOrder;
  11192. renderItem.z = z;
  11193. renderItem.group = group;
  11194. }
  11195. renderItemsIndex++;
  11196. return renderItem;
  11197. }
  11198. function push(object, geometry, material, groupOrder, z, group) {
  11199. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11200. (material.transparent === true ? transparent : opaque).push(renderItem);
  11201. }
  11202. function unshift(object, geometry, material, groupOrder, z, group) {
  11203. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11204. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11205. }
  11206. function sort(customOpaqueSort, customTransparentSort) {
  11207. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11208. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11209. }
  11210. function finish() {
  11211. // Clear references from inactive renderItems in the list
  11212. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11213. var renderItem = renderItems[i];
  11214. if (renderItem.id === null) break;
  11215. renderItem.id = null;
  11216. renderItem.object = null;
  11217. renderItem.geometry = null;
  11218. renderItem.material = null;
  11219. renderItem.program = null;
  11220. renderItem.group = null;
  11221. }
  11222. }
  11223. return {
  11224. opaque: opaque,
  11225. transparent: transparent,
  11226. init: init,
  11227. push: push,
  11228. unshift: unshift,
  11229. finish: finish,
  11230. sort: sort
  11231. };
  11232. }
  11233. function WebGLRenderLists(properties) {
  11234. var lists = new WeakMap();
  11235. function get(scene, camera) {
  11236. var cameras = lists.get(scene);
  11237. var list;
  11238. if (cameras === undefined) {
  11239. list = new WebGLRenderList(properties);
  11240. lists.set(scene, new WeakMap());
  11241. lists.get(scene).set(camera, list);
  11242. } else {
  11243. list = cameras.get(camera);
  11244. if (list === undefined) {
  11245. list = new WebGLRenderList(properties);
  11246. cameras.set(camera, list);
  11247. }
  11248. }
  11249. return list;
  11250. }
  11251. function dispose() {
  11252. lists = new WeakMap();
  11253. }
  11254. return {
  11255. get: get,
  11256. dispose: dispose
  11257. };
  11258. }
  11259. function UniformsCache() {
  11260. var lights = {};
  11261. return {
  11262. get: function get(light) {
  11263. if (lights[light.id] !== undefined) {
  11264. return lights[light.id];
  11265. }
  11266. var uniforms;
  11267. switch (light.type) {
  11268. case 'DirectionalLight':
  11269. uniforms = {
  11270. direction: new Vector3(),
  11271. color: new Color()
  11272. };
  11273. break;
  11274. case 'SpotLight':
  11275. uniforms = {
  11276. position: new Vector3(),
  11277. direction: new Vector3(),
  11278. color: new Color(),
  11279. distance: 0,
  11280. coneCos: 0,
  11281. penumbraCos: 0,
  11282. decay: 0
  11283. };
  11284. break;
  11285. case 'PointLight':
  11286. uniforms = {
  11287. position: new Vector3(),
  11288. color: new Color(),
  11289. distance: 0,
  11290. decay: 0
  11291. };
  11292. break;
  11293. case 'HemisphereLight':
  11294. uniforms = {
  11295. direction: new Vector3(),
  11296. skyColor: new Color(),
  11297. groundColor: new Color()
  11298. };
  11299. break;
  11300. case 'RectAreaLight':
  11301. uniforms = {
  11302. color: new Color(),
  11303. position: new Vector3(),
  11304. halfWidth: new Vector3(),
  11305. halfHeight: new Vector3()
  11306. };
  11307. break;
  11308. }
  11309. lights[light.id] = uniforms;
  11310. return uniforms;
  11311. }
  11312. };
  11313. }
  11314. function ShadowUniformsCache() {
  11315. var lights = {};
  11316. return {
  11317. get: function get(light) {
  11318. if (lights[light.id] !== undefined) {
  11319. return lights[light.id];
  11320. }
  11321. var uniforms;
  11322. switch (light.type) {
  11323. case 'DirectionalLight':
  11324. uniforms = {
  11325. shadowBias: 0,
  11326. shadowNormalBias: 0,
  11327. shadowRadius: 1,
  11328. shadowMapSize: new Vector2()
  11329. };
  11330. break;
  11331. case 'SpotLight':
  11332. uniforms = {
  11333. shadowBias: 0,
  11334. shadowNormalBias: 0,
  11335. shadowRadius: 1,
  11336. shadowMapSize: new Vector2()
  11337. };
  11338. break;
  11339. case 'PointLight':
  11340. uniforms = {
  11341. shadowBias: 0,
  11342. shadowNormalBias: 0,
  11343. shadowRadius: 1,
  11344. shadowMapSize: new Vector2(),
  11345. shadowCameraNear: 1,
  11346. shadowCameraFar: 1000
  11347. };
  11348. break;
  11349. // TODO (abelnation): set RectAreaLight shadow uniforms
  11350. }
  11351. lights[light.id] = uniforms;
  11352. return uniforms;
  11353. }
  11354. };
  11355. }
  11356. var nextVersion = 0;
  11357. function shadowCastingLightsFirst(lightA, lightB) {
  11358. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  11359. }
  11360. function WebGLLights() {
  11361. var cache = new UniformsCache();
  11362. var shadowCache = ShadowUniformsCache();
  11363. var state = {
  11364. version: 0,
  11365. hash: {
  11366. directionalLength: -1,
  11367. pointLength: -1,
  11368. spotLength: -1,
  11369. rectAreaLength: -1,
  11370. hemiLength: -1,
  11371. numDirectionalShadows: -1,
  11372. numPointShadows: -1,
  11373. numSpotShadows: -1
  11374. },
  11375. ambient: [0, 0, 0],
  11376. probe: [],
  11377. directional: [],
  11378. directionalShadow: [],
  11379. directionalShadowMap: [],
  11380. directionalShadowMatrix: [],
  11381. spot: [],
  11382. spotShadow: [],
  11383. spotShadowMap: [],
  11384. spotShadowMatrix: [],
  11385. rectArea: [],
  11386. rectAreaLTC1: null,
  11387. rectAreaLTC2: null,
  11388. point: [],
  11389. pointShadow: [],
  11390. pointShadowMap: [],
  11391. pointShadowMatrix: [],
  11392. hemi: []
  11393. };
  11394. for (var i = 0; i < 9; i++) {
  11395. state.probe.push(new Vector3());
  11396. }
  11397. var vector3 = new Vector3();
  11398. var matrix4 = new Matrix4();
  11399. var matrix42 = new Matrix4();
  11400. function setup(lights, shadows, camera) {
  11401. var r = 0,
  11402. g = 0,
  11403. b = 0;
  11404. for (var _i = 0; _i < 9; _i++) {
  11405. state.probe[_i].set(0, 0, 0);
  11406. }
  11407. var directionalLength = 0;
  11408. var pointLength = 0;
  11409. var spotLength = 0;
  11410. var rectAreaLength = 0;
  11411. var hemiLength = 0;
  11412. var numDirectionalShadows = 0;
  11413. var numPointShadows = 0;
  11414. var numSpotShadows = 0;
  11415. var viewMatrix = camera.matrixWorldInverse;
  11416. lights.sort(shadowCastingLightsFirst);
  11417. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  11418. var light = lights[_i2];
  11419. var color = light.color;
  11420. var intensity = light.intensity;
  11421. var distance = light.distance;
  11422. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  11423. if (light.isAmbientLight) {
  11424. r += color.r * intensity;
  11425. g += color.g * intensity;
  11426. b += color.b * intensity;
  11427. } else if (light.isLightProbe) {
  11428. for (var j = 0; j < 9; j++) {
  11429. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  11430. }
  11431. } else if (light.isDirectionalLight) {
  11432. var uniforms = cache.get(light);
  11433. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  11434. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11435. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11436. uniforms.direction.sub(vector3);
  11437. uniforms.direction.transformDirection(viewMatrix);
  11438. if (light.castShadow) {
  11439. var shadow = light.shadow;
  11440. var shadowUniforms = shadowCache.get(light);
  11441. shadowUniforms.shadowBias = shadow.bias;
  11442. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11443. shadowUniforms.shadowRadius = shadow.radius;
  11444. shadowUniforms.shadowMapSize = shadow.mapSize;
  11445. state.directionalShadow[directionalLength] = shadowUniforms;
  11446. state.directionalShadowMap[directionalLength] = shadowMap;
  11447. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  11448. numDirectionalShadows++;
  11449. }
  11450. state.directional[directionalLength] = uniforms;
  11451. directionalLength++;
  11452. } else if (light.isSpotLight) {
  11453. var _uniforms = cache.get(light);
  11454. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  11455. _uniforms.position.applyMatrix4(viewMatrix);
  11456. _uniforms.color.copy(color).multiplyScalar(intensity);
  11457. _uniforms.distance = distance;
  11458. _uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11459. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11460. _uniforms.direction.sub(vector3);
  11461. _uniforms.direction.transformDirection(viewMatrix);
  11462. _uniforms.coneCos = Math.cos(light.angle);
  11463. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  11464. _uniforms.decay = light.decay;
  11465. if (light.castShadow) {
  11466. var _shadow = light.shadow;
  11467. var _shadowUniforms = shadowCache.get(light);
  11468. _shadowUniforms.shadowBias = _shadow.bias;
  11469. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  11470. _shadowUniforms.shadowRadius = _shadow.radius;
  11471. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  11472. state.spotShadow[spotLength] = _shadowUniforms;
  11473. state.spotShadowMap[spotLength] = shadowMap;
  11474. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  11475. numSpotShadows++;
  11476. }
  11477. state.spot[spotLength] = _uniforms;
  11478. spotLength++;
  11479. } else if (light.isRectAreaLight) {
  11480. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  11481. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11482. // (b) intensity is the brightness of the light
  11483. _uniforms2.color.copy(color).multiplyScalar(intensity);
  11484. _uniforms2.position.setFromMatrixPosition(light.matrixWorld);
  11485. _uniforms2.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  11486. matrix42.identity();
  11487. matrix4.copy(light.matrixWorld);
  11488. matrix4.premultiply(viewMatrix);
  11489. matrix42.extractRotation(matrix4);
  11490. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  11491. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  11492. _uniforms2.halfWidth.applyMatrix4(matrix42);
  11493. _uniforms2.halfHeight.applyMatrix4(matrix42); // TODO (abelnation): RectAreaLight distance?
  11494. // uniforms.distance = distance;
  11495. state.rectArea[rectAreaLength] = _uniforms2;
  11496. rectAreaLength++;
  11497. } else if (light.isPointLight) {
  11498. var _uniforms3 = cache.get(light);
  11499. _uniforms3.position.setFromMatrixPosition(light.matrixWorld);
  11500. _uniforms3.position.applyMatrix4(viewMatrix);
  11501. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  11502. _uniforms3.distance = light.distance;
  11503. _uniforms3.decay = light.decay;
  11504. if (light.castShadow) {
  11505. var _shadow2 = light.shadow;
  11506. var _shadowUniforms2 = shadowCache.get(light);
  11507. _shadowUniforms2.shadowBias = _shadow2.bias;
  11508. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  11509. _shadowUniforms2.shadowRadius = _shadow2.radius;
  11510. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  11511. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  11512. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  11513. state.pointShadow[pointLength] = _shadowUniforms2;
  11514. state.pointShadowMap[pointLength] = shadowMap;
  11515. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  11516. numPointShadows++;
  11517. }
  11518. state.point[pointLength] = _uniforms3;
  11519. pointLength++;
  11520. } else if (light.isHemisphereLight) {
  11521. var _uniforms4 = cache.get(light);
  11522. _uniforms4.direction.setFromMatrixPosition(light.matrixWorld);
  11523. _uniforms4.direction.transformDirection(viewMatrix);
  11524. _uniforms4.direction.normalize();
  11525. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  11526. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  11527. state.hemi[hemiLength] = _uniforms4;
  11528. hemiLength++;
  11529. }
  11530. }
  11531. if (rectAreaLength > 0) {
  11532. state.rectAreaLTC1 = UniformsLib.LTC_1;
  11533. state.rectAreaLTC2 = UniformsLib.LTC_2;
  11534. }
  11535. state.ambient[0] = r;
  11536. state.ambient[1] = g;
  11537. state.ambient[2] = b;
  11538. var hash = state.hash;
  11539. 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) {
  11540. state.directional.length = directionalLength;
  11541. state.spot.length = spotLength;
  11542. state.rectArea.length = rectAreaLength;
  11543. state.point.length = pointLength;
  11544. state.hemi.length = hemiLength;
  11545. state.directionalShadow.length = numDirectionalShadows;
  11546. state.directionalShadowMap.length = numDirectionalShadows;
  11547. state.pointShadow.length = numPointShadows;
  11548. state.pointShadowMap.length = numPointShadows;
  11549. state.spotShadow.length = numSpotShadows;
  11550. state.spotShadowMap.length = numSpotShadows;
  11551. state.directionalShadowMatrix.length = numDirectionalShadows;
  11552. state.pointShadowMatrix.length = numPointShadows;
  11553. state.spotShadowMatrix.length = numSpotShadows;
  11554. hash.directionalLength = directionalLength;
  11555. hash.pointLength = pointLength;
  11556. hash.spotLength = spotLength;
  11557. hash.rectAreaLength = rectAreaLength;
  11558. hash.hemiLength = hemiLength;
  11559. hash.numDirectionalShadows = numDirectionalShadows;
  11560. hash.numPointShadows = numPointShadows;
  11561. hash.numSpotShadows = numSpotShadows;
  11562. state.version = nextVersion++;
  11563. }
  11564. }
  11565. return {
  11566. setup: setup,
  11567. state: state
  11568. };
  11569. }
  11570. function WebGLRenderState() {
  11571. var lights = new WebGLLights();
  11572. var lightsArray = [];
  11573. var shadowsArray = [];
  11574. function init() {
  11575. lightsArray.length = 0;
  11576. shadowsArray.length = 0;
  11577. }
  11578. function pushLight(light) {
  11579. lightsArray.push(light);
  11580. }
  11581. function pushShadow(shadowLight) {
  11582. shadowsArray.push(shadowLight);
  11583. }
  11584. function setupLights(camera) {
  11585. lights.setup(lightsArray, shadowsArray, camera);
  11586. }
  11587. var state = {
  11588. lightsArray: lightsArray,
  11589. shadowsArray: shadowsArray,
  11590. lights: lights
  11591. };
  11592. return {
  11593. init: init,
  11594. state: state,
  11595. setupLights: setupLights,
  11596. pushLight: pushLight,
  11597. pushShadow: pushShadow
  11598. };
  11599. }
  11600. function WebGLRenderStates() {
  11601. var renderStates = new WeakMap();
  11602. function get(scene, camera) {
  11603. var renderState;
  11604. if (renderStates.has(scene) === false) {
  11605. renderState = new WebGLRenderState();
  11606. renderStates.set(scene, new WeakMap());
  11607. renderStates.get(scene).set(camera, renderState);
  11608. } else {
  11609. if (renderStates.get(scene).has(camera) === false) {
  11610. renderState = new WebGLRenderState();
  11611. renderStates.get(scene).set(camera, renderState);
  11612. } else {
  11613. renderState = renderStates.get(scene).get(camera);
  11614. }
  11615. }
  11616. return renderState;
  11617. }
  11618. function dispose() {
  11619. renderStates = new WeakMap();
  11620. }
  11621. return {
  11622. get: get,
  11623. dispose: dispose
  11624. };
  11625. }
  11626. /**
  11627. * parameters = {
  11628. *
  11629. * opacity: <float>,
  11630. *
  11631. * map: new THREE.Texture( <Image> ),
  11632. *
  11633. * alphaMap: new THREE.Texture( <Image> ),
  11634. *
  11635. * displacementMap: new THREE.Texture( <Image> ),
  11636. * displacementScale: <float>,
  11637. * displacementBias: <float>,
  11638. *
  11639. * wireframe: <boolean>,
  11640. * wireframeLinewidth: <float>
  11641. * }
  11642. */
  11643. function MeshDepthMaterial(parameters) {
  11644. Material.call(this);
  11645. this.type = 'MeshDepthMaterial';
  11646. this.depthPacking = BasicDepthPacking;
  11647. this.skinning = false;
  11648. this.morphTargets = false;
  11649. this.map = null;
  11650. this.alphaMap = null;
  11651. this.displacementMap = null;
  11652. this.displacementScale = 1;
  11653. this.displacementBias = 0;
  11654. this.wireframe = false;
  11655. this.wireframeLinewidth = 1;
  11656. this.fog = false;
  11657. this.setValues(parameters);
  11658. }
  11659. MeshDepthMaterial.prototype = Object.create(Material.prototype);
  11660. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11661. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11662. MeshDepthMaterial.prototype.copy = function (source) {
  11663. Material.prototype.copy.call(this, source);
  11664. this.depthPacking = source.depthPacking;
  11665. this.skinning = source.skinning;
  11666. this.morphTargets = source.morphTargets;
  11667. this.map = source.map;
  11668. this.alphaMap = source.alphaMap;
  11669. this.displacementMap = source.displacementMap;
  11670. this.displacementScale = source.displacementScale;
  11671. this.displacementBias = source.displacementBias;
  11672. this.wireframe = source.wireframe;
  11673. this.wireframeLinewidth = source.wireframeLinewidth;
  11674. return this;
  11675. };
  11676. /**
  11677. * parameters = {
  11678. *
  11679. * referencePosition: <float>,
  11680. * nearDistance: <float>,
  11681. * farDistance: <float>,
  11682. *
  11683. * skinning: <bool>,
  11684. * morphTargets: <bool>,
  11685. *
  11686. * map: new THREE.Texture( <Image> ),
  11687. *
  11688. * alphaMap: new THREE.Texture( <Image> ),
  11689. *
  11690. * displacementMap: new THREE.Texture( <Image> ),
  11691. * displacementScale: <float>,
  11692. * displacementBias: <float>
  11693. *
  11694. * }
  11695. */
  11696. function MeshDistanceMaterial(parameters) {
  11697. Material.call(this);
  11698. this.type = 'MeshDistanceMaterial';
  11699. this.referencePosition = new Vector3();
  11700. this.nearDistance = 1;
  11701. this.farDistance = 1000;
  11702. this.skinning = false;
  11703. this.morphTargets = false;
  11704. this.map = null;
  11705. this.alphaMap = null;
  11706. this.displacementMap = null;
  11707. this.displacementScale = 1;
  11708. this.displacementBias = 0;
  11709. this.fog = false;
  11710. this.setValues(parameters);
  11711. }
  11712. MeshDistanceMaterial.prototype = Object.create(Material.prototype);
  11713. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11714. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11715. MeshDistanceMaterial.prototype.copy = function (source) {
  11716. Material.prototype.copy.call(this, source);
  11717. this.referencePosition.copy(source.referencePosition);
  11718. this.nearDistance = source.nearDistance;
  11719. this.farDistance = source.farDistance;
  11720. this.skinning = source.skinning;
  11721. this.morphTargets = source.morphTargets;
  11722. this.map = source.map;
  11723. this.alphaMap = source.alphaMap;
  11724. this.displacementMap = source.displacementMap;
  11725. this.displacementScale = source.displacementScale;
  11726. this.displacementBias = source.displacementBias;
  11727. return this;
  11728. };
  11729. var vsm_frag = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n\tfor ( float i = -1.0; i < 1.0 ; i += SAMPLE_RATE) {\n\t\t#ifdef HORIZONAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, i ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean * HALF_SAMPLE_RATE;\n\tsquared_mean = squared_mean * HALF_SAMPLE_RATE;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";
  11730. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  11731. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  11732. var _frustum = new Frustum();
  11733. var _shadowMapSize = new Vector2(),
  11734. _viewportSize = new Vector2(),
  11735. _viewport = new Vector4(),
  11736. _depthMaterials = [],
  11737. _distanceMaterials = [],
  11738. _materialCache = {};
  11739. var shadowSide = {
  11740. 0: BackSide,
  11741. 1: FrontSide,
  11742. 2: DoubleSide
  11743. };
  11744. var shadowMaterialVertical = new ShaderMaterial({
  11745. defines: {
  11746. SAMPLE_RATE: 2.0 / 8.0,
  11747. HALF_SAMPLE_RATE: 1.0 / 8.0
  11748. },
  11749. uniforms: {
  11750. shadow_pass: {
  11751. value: null
  11752. },
  11753. resolution: {
  11754. value: new Vector2()
  11755. },
  11756. radius: {
  11757. value: 4.0
  11758. }
  11759. },
  11760. vertexShader: vsm_vert,
  11761. fragmentShader: vsm_frag
  11762. });
  11763. var shadowMaterialHorizonal = shadowMaterialVertical.clone();
  11764. shadowMaterialHorizonal.defines.HORIZONAL_PASS = 1;
  11765. var fullScreenTri = new BufferGeometry();
  11766. fullScreenTri.setAttribute("position", new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  11767. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  11768. var scope = this;
  11769. this.enabled = false;
  11770. this.autoUpdate = true;
  11771. this.needsUpdate = false;
  11772. this.type = PCFShadowMap;
  11773. this.render = function (lights, scene, camera) {
  11774. if (scope.enabled === false) return;
  11775. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  11776. if (lights.length === 0) return;
  11777. var currentRenderTarget = _renderer.getRenderTarget();
  11778. var activeCubeFace = _renderer.getActiveCubeFace();
  11779. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  11780. var _state = _renderer.state; // Set GL state for depth map.
  11781. _state.setBlending(NoBlending);
  11782. _state.buffers.color.setClear(1, 1, 1, 1);
  11783. _state.buffers.depth.setTest(true);
  11784. _state.setScissorTest(false); // render depth map
  11785. for (var i = 0, il = lights.length; i < il; i++) {
  11786. var light = lights[i];
  11787. var shadow = light.shadow;
  11788. if (shadow === undefined) {
  11789. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  11790. continue;
  11791. }
  11792. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  11793. _shadowMapSize.copy(shadow.mapSize);
  11794. var shadowFrameExtents = shadow.getFrameExtents();
  11795. _shadowMapSize.multiply(shadowFrameExtents);
  11796. _viewportSize.copy(shadow.mapSize);
  11797. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  11798. if (_shadowMapSize.x > maxTextureSize) {
  11799. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  11800. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  11801. shadow.mapSize.x = _viewportSize.x;
  11802. }
  11803. if (_shadowMapSize.y > maxTextureSize) {
  11804. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  11805. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  11806. shadow.mapSize.y = _viewportSize.y;
  11807. }
  11808. }
  11809. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  11810. var pars = {
  11811. minFilter: LinearFilter,
  11812. magFilter: LinearFilter,
  11813. format: RGBAFormat
  11814. };
  11815. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  11816. shadow.map.texture.name = light.name + ".shadowMap";
  11817. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  11818. shadow.camera.updateProjectionMatrix();
  11819. }
  11820. if (shadow.map === null) {
  11821. var _pars = {
  11822. minFilter: NearestFilter,
  11823. magFilter: NearestFilter,
  11824. format: RGBAFormat
  11825. };
  11826. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  11827. shadow.map.texture.name = light.name + ".shadowMap";
  11828. shadow.camera.updateProjectionMatrix();
  11829. }
  11830. _renderer.setRenderTarget(shadow.map);
  11831. _renderer.clear();
  11832. var viewportCount = shadow.getViewportCount();
  11833. for (var vp = 0; vp < viewportCount; vp++) {
  11834. var viewport = shadow.getViewport(vp);
  11835. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  11836. _state.viewport(_viewport);
  11837. shadow.updateMatrices(light, vp);
  11838. _frustum = shadow.getFrustum();
  11839. renderObject(scene, camera, shadow.camera, light, this.type);
  11840. } // do blur pass for VSM
  11841. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  11842. VSMPass(shadow, camera);
  11843. }
  11844. shadow.needsUpdate = false;
  11845. }
  11846. scope.needsUpdate = false;
  11847. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  11848. };
  11849. function VSMPass(shadow, camera) {
  11850. var geometry = _objects.update(fullScreenMesh); // vertical pass
  11851. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  11852. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  11853. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  11854. _renderer.setRenderTarget(shadow.mapPass);
  11855. _renderer.clear();
  11856. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizonal pass
  11857. shadowMaterialHorizonal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  11858. shadowMaterialHorizonal.uniforms.resolution.value = shadow.mapSize;
  11859. shadowMaterialHorizonal.uniforms.radius.value = shadow.radius;
  11860. _renderer.setRenderTarget(shadow.map);
  11861. _renderer.clear();
  11862. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizonal, fullScreenMesh, null);
  11863. }
  11864. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  11865. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11866. var material = _depthMaterials[index];
  11867. if (material === undefined) {
  11868. material = new MeshDepthMaterial({
  11869. depthPacking: RGBADepthPacking,
  11870. morphTargets: useMorphing,
  11871. skinning: useSkinning
  11872. });
  11873. _depthMaterials[index] = material;
  11874. }
  11875. return material;
  11876. }
  11877. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  11878. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11879. var material = _distanceMaterials[index];
  11880. if (material === undefined) {
  11881. material = new MeshDistanceMaterial({
  11882. morphTargets: useMorphing,
  11883. skinning: useSkinning
  11884. });
  11885. _distanceMaterials[index] = material;
  11886. }
  11887. return material;
  11888. }
  11889. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  11890. var result = null;
  11891. var getMaterialVariant = getDepthMaterialVariant;
  11892. var customMaterial = object.customDepthMaterial;
  11893. if (light.isPointLight === true) {
  11894. getMaterialVariant = getDistanceMaterialVariant;
  11895. customMaterial = object.customDistanceMaterial;
  11896. }
  11897. if (customMaterial === undefined) {
  11898. var useMorphing = false;
  11899. if (material.morphTargets === true) {
  11900. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11901. }
  11902. var useSkinning = false;
  11903. if (object.isSkinnedMesh === true) {
  11904. if (material.skinning === true) {
  11905. useSkinning = true;
  11906. } else {
  11907. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  11908. }
  11909. }
  11910. var useInstancing = object.isInstancedMesh === true;
  11911. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  11912. } else {
  11913. result = customMaterial;
  11914. }
  11915. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  11916. // in this case we need a unique material instance reflecting the
  11917. // appropriate state
  11918. var keyA = result.uuid,
  11919. keyB = material.uuid;
  11920. var materialsForVariant = _materialCache[keyA];
  11921. if (materialsForVariant === undefined) {
  11922. materialsForVariant = {};
  11923. _materialCache[keyA] = materialsForVariant;
  11924. }
  11925. var cachedMaterial = materialsForVariant[keyB];
  11926. if (cachedMaterial === undefined) {
  11927. cachedMaterial = result.clone();
  11928. materialsForVariant[keyB] = cachedMaterial;
  11929. }
  11930. result = cachedMaterial;
  11931. }
  11932. result.visible = material.visible;
  11933. result.wireframe = material.wireframe;
  11934. if (type === VSMShadowMap) {
  11935. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  11936. } else {
  11937. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  11938. }
  11939. result.clipShadows = material.clipShadows;
  11940. result.clippingPlanes = material.clippingPlanes;
  11941. result.clipIntersection = material.clipIntersection;
  11942. result.wireframeLinewidth = material.wireframeLinewidth;
  11943. result.linewidth = material.linewidth;
  11944. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  11945. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  11946. result.nearDistance = shadowCameraNear;
  11947. result.farDistance = shadowCameraFar;
  11948. }
  11949. return result;
  11950. }
  11951. function renderObject(object, camera, shadowCamera, light, type) {
  11952. if (object.visible === false) return;
  11953. var visible = object.layers.test(camera.layers);
  11954. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  11955. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  11956. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  11957. var geometry = _objects.update(object);
  11958. var material = object.material;
  11959. if (Array.isArray(material)) {
  11960. var groups = geometry.groups;
  11961. for (var k = 0, kl = groups.length; k < kl; k++) {
  11962. var group = groups[k];
  11963. var groupMaterial = material[group.materialIndex];
  11964. if (groupMaterial && groupMaterial.visible) {
  11965. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  11966. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  11967. }
  11968. }
  11969. } else if (material.visible) {
  11970. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  11971. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  11972. }
  11973. }
  11974. }
  11975. var children = object.children;
  11976. for (var i = 0, l = children.length; i < l; i++) {
  11977. renderObject(children[i], camera, shadowCamera, light, type);
  11978. }
  11979. }
  11980. }
  11981. function WebGLState(gl, extensions, capabilities) {
  11982. var _equationToGL, _factorToGL;
  11983. var isWebGL2 = capabilities.isWebGL2;
  11984. function ColorBuffer() {
  11985. var locked = false;
  11986. var color = new Vector4();
  11987. var currentColorMask = null;
  11988. var currentColorClear = new Vector4(0, 0, 0, 0);
  11989. return {
  11990. setMask: function setMask(colorMask) {
  11991. if (currentColorMask !== colorMask && !locked) {
  11992. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  11993. currentColorMask = colorMask;
  11994. }
  11995. },
  11996. setLocked: function setLocked(lock) {
  11997. locked = lock;
  11998. },
  11999. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12000. if (premultipliedAlpha === true) {
  12001. r *= a;
  12002. g *= a;
  12003. b *= a;
  12004. }
  12005. color.set(r, g, b, a);
  12006. if (currentColorClear.equals(color) === false) {
  12007. gl.clearColor(r, g, b, a);
  12008. currentColorClear.copy(color);
  12009. }
  12010. },
  12011. reset: function reset() {
  12012. locked = false;
  12013. currentColorMask = null;
  12014. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12015. }
  12016. };
  12017. }
  12018. function DepthBuffer() {
  12019. var locked = false;
  12020. var currentDepthMask = null;
  12021. var currentDepthFunc = null;
  12022. var currentDepthClear = null;
  12023. return {
  12024. setTest: function setTest(depthTest) {
  12025. if (depthTest) {
  12026. enable(2929);
  12027. } else {
  12028. disable(2929);
  12029. }
  12030. },
  12031. setMask: function setMask(depthMask) {
  12032. if (currentDepthMask !== depthMask && !locked) {
  12033. gl.depthMask(depthMask);
  12034. currentDepthMask = depthMask;
  12035. }
  12036. },
  12037. setFunc: function setFunc(depthFunc) {
  12038. if (currentDepthFunc !== depthFunc) {
  12039. if (depthFunc) {
  12040. switch (depthFunc) {
  12041. case NeverDepth:
  12042. gl.depthFunc(512);
  12043. break;
  12044. case AlwaysDepth:
  12045. gl.depthFunc(519);
  12046. break;
  12047. case LessDepth:
  12048. gl.depthFunc(513);
  12049. break;
  12050. case LessEqualDepth:
  12051. gl.depthFunc(515);
  12052. break;
  12053. case EqualDepth:
  12054. gl.depthFunc(514);
  12055. break;
  12056. case GreaterEqualDepth:
  12057. gl.depthFunc(518);
  12058. break;
  12059. case GreaterDepth:
  12060. gl.depthFunc(516);
  12061. break;
  12062. case NotEqualDepth:
  12063. gl.depthFunc(517);
  12064. break;
  12065. default:
  12066. gl.depthFunc(515);
  12067. }
  12068. } else {
  12069. gl.depthFunc(515);
  12070. }
  12071. currentDepthFunc = depthFunc;
  12072. }
  12073. },
  12074. setLocked: function setLocked(lock) {
  12075. locked = lock;
  12076. },
  12077. setClear: function setClear(depth) {
  12078. if (currentDepthClear !== depth) {
  12079. gl.clearDepth(depth);
  12080. currentDepthClear = depth;
  12081. }
  12082. },
  12083. reset: function reset() {
  12084. locked = false;
  12085. currentDepthMask = null;
  12086. currentDepthFunc = null;
  12087. currentDepthClear = null;
  12088. }
  12089. };
  12090. }
  12091. function StencilBuffer() {
  12092. var locked = false;
  12093. var currentStencilMask = null;
  12094. var currentStencilFunc = null;
  12095. var currentStencilRef = null;
  12096. var currentStencilFuncMask = null;
  12097. var currentStencilFail = null;
  12098. var currentStencilZFail = null;
  12099. var currentStencilZPass = null;
  12100. var currentStencilClear = null;
  12101. return {
  12102. setTest: function setTest(stencilTest) {
  12103. if (!locked) {
  12104. if (stencilTest) {
  12105. enable(2960);
  12106. } else {
  12107. disable(2960);
  12108. }
  12109. }
  12110. },
  12111. setMask: function setMask(stencilMask) {
  12112. if (currentStencilMask !== stencilMask && !locked) {
  12113. gl.stencilMask(stencilMask);
  12114. currentStencilMask = stencilMask;
  12115. }
  12116. },
  12117. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12118. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12119. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12120. currentStencilFunc = stencilFunc;
  12121. currentStencilRef = stencilRef;
  12122. currentStencilFuncMask = stencilMask;
  12123. }
  12124. },
  12125. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12126. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12127. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12128. currentStencilFail = stencilFail;
  12129. currentStencilZFail = stencilZFail;
  12130. currentStencilZPass = stencilZPass;
  12131. }
  12132. },
  12133. setLocked: function setLocked(lock) {
  12134. locked = lock;
  12135. },
  12136. setClear: function setClear(stencil) {
  12137. if (currentStencilClear !== stencil) {
  12138. gl.clearStencil(stencil);
  12139. currentStencilClear = stencil;
  12140. }
  12141. },
  12142. reset: function reset() {
  12143. locked = false;
  12144. currentStencilMask = null;
  12145. currentStencilFunc = null;
  12146. currentStencilRef = null;
  12147. currentStencilFuncMask = null;
  12148. currentStencilFail = null;
  12149. currentStencilZFail = null;
  12150. currentStencilZPass = null;
  12151. currentStencilClear = null;
  12152. }
  12153. };
  12154. } //
  12155. var colorBuffer = new ColorBuffer();
  12156. var depthBuffer = new DepthBuffer();
  12157. var stencilBuffer = new StencilBuffer();
  12158. var enabledCapabilities = {};
  12159. var currentProgram = null;
  12160. var currentBlendingEnabled = null;
  12161. var currentBlending = null;
  12162. var currentBlendEquation = null;
  12163. var currentBlendSrc = null;
  12164. var currentBlendDst = null;
  12165. var currentBlendEquationAlpha = null;
  12166. var currentBlendSrcAlpha = null;
  12167. var currentBlendDstAlpha = null;
  12168. var currentPremultipledAlpha = false;
  12169. var currentFlipSided = null;
  12170. var currentCullFace = null;
  12171. var currentLineWidth = null;
  12172. var currentPolygonOffsetFactor = null;
  12173. var currentPolygonOffsetUnits = null;
  12174. var maxTextures = gl.getParameter(35661);
  12175. var lineWidthAvailable = false;
  12176. var version = 0;
  12177. var glVersion = gl.getParameter(7938);
  12178. if (glVersion.indexOf('WebGL') !== -1) {
  12179. version = parseFloat(/^WebGL\ ([0-9])/.exec(glVersion)[1]);
  12180. lineWidthAvailable = version >= 1.0;
  12181. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12182. version = parseFloat(/^OpenGL\ ES\ ([0-9])/.exec(glVersion)[1]);
  12183. lineWidthAvailable = version >= 2.0;
  12184. }
  12185. var currentTextureSlot = null;
  12186. var currentBoundTextures = {};
  12187. var currentScissor = new Vector4();
  12188. var currentViewport = new Vector4();
  12189. function createTexture(type, target, count) {
  12190. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12191. var texture = gl.createTexture();
  12192. gl.bindTexture(type, texture);
  12193. gl.texParameteri(type, 10241, 9728);
  12194. gl.texParameteri(type, 10240, 9728);
  12195. for (var i = 0; i < count; i++) {
  12196. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12197. }
  12198. return texture;
  12199. }
  12200. var emptyTextures = {};
  12201. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12202. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12203. colorBuffer.setClear(0, 0, 0, 1);
  12204. depthBuffer.setClear(1);
  12205. stencilBuffer.setClear(0);
  12206. enable(2929);
  12207. depthBuffer.setFunc(LessEqualDepth);
  12208. setFlipSided(false);
  12209. setCullFace(CullFaceBack);
  12210. enable(2884);
  12211. setBlending(NoBlending); //
  12212. function enable(id) {
  12213. if (enabledCapabilities[id] !== true) {
  12214. gl.enable(id);
  12215. enabledCapabilities[id] = true;
  12216. }
  12217. }
  12218. function disable(id) {
  12219. if (enabledCapabilities[id] !== false) {
  12220. gl.disable(id);
  12221. enabledCapabilities[id] = false;
  12222. }
  12223. }
  12224. function useProgram(program) {
  12225. if (currentProgram !== program) {
  12226. gl.useProgram(program);
  12227. currentProgram = program;
  12228. return true;
  12229. }
  12230. return false;
  12231. }
  12232. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12233. if (isWebGL2) {
  12234. equationToGL[MinEquation] = 32775;
  12235. equationToGL[MaxEquation] = 32776;
  12236. } else {
  12237. var extension = extensions.get('EXT_blend_minmax');
  12238. if (extension !== null) {
  12239. equationToGL[MinEquation] = extension.MIN_EXT;
  12240. equationToGL[MaxEquation] = extension.MAX_EXT;
  12241. }
  12242. }
  12243. 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);
  12244. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  12245. if (blending === NoBlending) {
  12246. if (currentBlendingEnabled) {
  12247. disable(3042);
  12248. currentBlendingEnabled = false;
  12249. }
  12250. return;
  12251. }
  12252. if (!currentBlendingEnabled) {
  12253. enable(3042);
  12254. currentBlendingEnabled = true;
  12255. }
  12256. if (blending !== CustomBlending) {
  12257. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  12258. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  12259. gl.blendEquation(32774);
  12260. currentBlendEquation = AddEquation;
  12261. currentBlendEquationAlpha = AddEquation;
  12262. }
  12263. if (premultipliedAlpha) {
  12264. switch (blending) {
  12265. case NormalBlending:
  12266. gl.blendFuncSeparate(1, 771, 1, 771);
  12267. break;
  12268. case AdditiveBlending:
  12269. gl.blendFunc(1, 1);
  12270. break;
  12271. case SubtractiveBlending:
  12272. gl.blendFuncSeparate(0, 0, 769, 771);
  12273. break;
  12274. case MultiplyBlending:
  12275. gl.blendFuncSeparate(0, 768, 0, 770);
  12276. break;
  12277. default:
  12278. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12279. break;
  12280. }
  12281. } else {
  12282. switch (blending) {
  12283. case NormalBlending:
  12284. gl.blendFuncSeparate(770, 771, 1, 771);
  12285. break;
  12286. case AdditiveBlending:
  12287. gl.blendFunc(770, 1);
  12288. break;
  12289. case SubtractiveBlending:
  12290. gl.blendFunc(0, 769);
  12291. break;
  12292. case MultiplyBlending:
  12293. gl.blendFunc(0, 768);
  12294. break;
  12295. default:
  12296. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12297. break;
  12298. }
  12299. }
  12300. currentBlendSrc = null;
  12301. currentBlendDst = null;
  12302. currentBlendSrcAlpha = null;
  12303. currentBlendDstAlpha = null;
  12304. currentBlending = blending;
  12305. currentPremultipledAlpha = premultipliedAlpha;
  12306. }
  12307. return;
  12308. } // custom blending
  12309. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12310. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12311. blendDstAlpha = blendDstAlpha || blendDst;
  12312. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  12313. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  12314. currentBlendEquation = blendEquation;
  12315. currentBlendEquationAlpha = blendEquationAlpha;
  12316. }
  12317. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  12318. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  12319. currentBlendSrc = blendSrc;
  12320. currentBlendDst = blendDst;
  12321. currentBlendSrcAlpha = blendSrcAlpha;
  12322. currentBlendDstAlpha = blendDstAlpha;
  12323. }
  12324. currentBlending = blending;
  12325. currentPremultipledAlpha = null;
  12326. }
  12327. function setMaterial(material, frontFaceCW) {
  12328. material.side === DoubleSide ? disable(2884) : enable(2884);
  12329. var flipSided = material.side === BackSide;
  12330. if (frontFaceCW) flipSided = !flipSided;
  12331. setFlipSided(flipSided);
  12332. 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);
  12333. depthBuffer.setFunc(material.depthFunc);
  12334. depthBuffer.setTest(material.depthTest);
  12335. depthBuffer.setMask(material.depthWrite);
  12336. colorBuffer.setMask(material.colorWrite);
  12337. var stencilWrite = material.stencilWrite;
  12338. stencilBuffer.setTest(stencilWrite);
  12339. if (stencilWrite) {
  12340. stencilBuffer.setMask(material.stencilWriteMask);
  12341. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  12342. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  12343. }
  12344. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  12345. } //
  12346. function setFlipSided(flipSided) {
  12347. if (currentFlipSided !== flipSided) {
  12348. if (flipSided) {
  12349. gl.frontFace(2304);
  12350. } else {
  12351. gl.frontFace(2305);
  12352. }
  12353. currentFlipSided = flipSided;
  12354. }
  12355. }
  12356. function setCullFace(cullFace) {
  12357. if (cullFace !== CullFaceNone) {
  12358. enable(2884);
  12359. if (cullFace !== currentCullFace) {
  12360. if (cullFace === CullFaceBack) {
  12361. gl.cullFace(1029);
  12362. } else if (cullFace === CullFaceFront) {
  12363. gl.cullFace(1028);
  12364. } else {
  12365. gl.cullFace(1032);
  12366. }
  12367. }
  12368. } else {
  12369. disable(2884);
  12370. }
  12371. currentCullFace = cullFace;
  12372. }
  12373. function setLineWidth(width) {
  12374. if (width !== currentLineWidth) {
  12375. if (lineWidthAvailable) gl.lineWidth(width);
  12376. currentLineWidth = width;
  12377. }
  12378. }
  12379. function setPolygonOffset(polygonOffset, factor, units) {
  12380. if (polygonOffset) {
  12381. enable(32823);
  12382. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  12383. gl.polygonOffset(factor, units);
  12384. currentPolygonOffsetFactor = factor;
  12385. currentPolygonOffsetUnits = units;
  12386. }
  12387. } else {
  12388. disable(32823);
  12389. }
  12390. }
  12391. function setScissorTest(scissorTest) {
  12392. if (scissorTest) {
  12393. enable(3089);
  12394. } else {
  12395. disable(3089);
  12396. }
  12397. } // texture
  12398. function activeTexture(webglSlot) {
  12399. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  12400. if (currentTextureSlot !== webglSlot) {
  12401. gl.activeTexture(webglSlot);
  12402. currentTextureSlot = webglSlot;
  12403. }
  12404. }
  12405. function bindTexture(webglType, webglTexture) {
  12406. if (currentTextureSlot === null) {
  12407. activeTexture();
  12408. }
  12409. var boundTexture = currentBoundTextures[currentTextureSlot];
  12410. if (boundTexture === undefined) {
  12411. boundTexture = {
  12412. type: undefined,
  12413. texture: undefined
  12414. };
  12415. currentBoundTextures[currentTextureSlot] = boundTexture;
  12416. }
  12417. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  12418. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  12419. boundTexture.type = webglType;
  12420. boundTexture.texture = webglTexture;
  12421. }
  12422. }
  12423. function unbindTexture() {
  12424. var boundTexture = currentBoundTextures[currentTextureSlot];
  12425. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  12426. gl.bindTexture(boundTexture.type, null);
  12427. boundTexture.type = undefined;
  12428. boundTexture.texture = undefined;
  12429. }
  12430. }
  12431. function compressedTexImage2D() {
  12432. try {
  12433. gl.compressedTexImage2D.apply(gl, arguments);
  12434. } catch (error) {
  12435. console.error('THREE.WebGLState:', error);
  12436. }
  12437. }
  12438. function texImage2D() {
  12439. try {
  12440. gl.texImage2D.apply(gl, arguments);
  12441. } catch (error) {
  12442. console.error('THREE.WebGLState:', error);
  12443. }
  12444. }
  12445. function texImage3D() {
  12446. try {
  12447. gl.texImage3D.apply(gl, arguments);
  12448. } catch (error) {
  12449. console.error('THREE.WebGLState:', error);
  12450. }
  12451. } //
  12452. function scissor(scissor) {
  12453. if (currentScissor.equals(scissor) === false) {
  12454. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  12455. currentScissor.copy(scissor);
  12456. }
  12457. }
  12458. function viewport(viewport) {
  12459. if (currentViewport.equals(viewport) === false) {
  12460. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  12461. currentViewport.copy(viewport);
  12462. }
  12463. } //
  12464. function reset() {
  12465. enabledCapabilities = {};
  12466. currentTextureSlot = null;
  12467. currentBoundTextures = {};
  12468. currentProgram = null;
  12469. currentBlending = null;
  12470. currentFlipSided = null;
  12471. currentCullFace = null;
  12472. colorBuffer.reset();
  12473. depthBuffer.reset();
  12474. stencilBuffer.reset();
  12475. }
  12476. return {
  12477. buffers: {
  12478. color: colorBuffer,
  12479. depth: depthBuffer,
  12480. stencil: stencilBuffer
  12481. },
  12482. enable: enable,
  12483. disable: disable,
  12484. useProgram: useProgram,
  12485. setBlending: setBlending,
  12486. setMaterial: setMaterial,
  12487. setFlipSided: setFlipSided,
  12488. setCullFace: setCullFace,
  12489. setLineWidth: setLineWidth,
  12490. setPolygonOffset: setPolygonOffset,
  12491. setScissorTest: setScissorTest,
  12492. activeTexture: activeTexture,
  12493. bindTexture: bindTexture,
  12494. unbindTexture: unbindTexture,
  12495. compressedTexImage2D: compressedTexImage2D,
  12496. texImage2D: texImage2D,
  12497. texImage3D: texImage3D,
  12498. scissor: scissor,
  12499. viewport: viewport,
  12500. reset: reset
  12501. };
  12502. }
  12503. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  12504. var _wrappingToGL, _filterToGL;
  12505. var isWebGL2 = capabilities.isWebGL2;
  12506. var maxTextures = capabilities.maxTextures;
  12507. var maxCubemapSize = capabilities.maxCubemapSize;
  12508. var maxTextureSize = capabilities.maxTextureSize;
  12509. var maxSamples = capabilities.maxSamples;
  12510. var _videoTextures = new WeakMap();
  12511. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  12512. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  12513. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  12514. var useOffscreenCanvas = false;
  12515. try {
  12516. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext("2d") !== null;
  12517. } catch (err) {// Ignore any errors
  12518. }
  12519. function createCanvas(width, height) {
  12520. // Use OffscreenCanvas when available. Specially needed in web workers
  12521. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  12522. }
  12523. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  12524. var scale = 1; // handle case if texture exceeds max size
  12525. if (image.width > maxSize || image.height > maxSize) {
  12526. scale = maxSize / Math.max(image.width, image.height);
  12527. } // only perform resize if necessary
  12528. if (scale < 1 || needsPowerOfTwo === true) {
  12529. // only perform resize for certain image types
  12530. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  12531. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  12532. var width = floor(scale * image.width);
  12533. var height = floor(scale * image.height);
  12534. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  12535. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  12536. canvas.width = width;
  12537. canvas.height = height;
  12538. var context = canvas.getContext('2d');
  12539. context.drawImage(image, 0, 0, width, height);
  12540. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  12541. return canvas;
  12542. } else {
  12543. if ('data' in image) {
  12544. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  12545. }
  12546. return image;
  12547. }
  12548. }
  12549. return image;
  12550. }
  12551. function isPowerOfTwo(image) {
  12552. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  12553. }
  12554. function textureNeedsPowerOfTwo(texture) {
  12555. if (isWebGL2) return false;
  12556. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12557. }
  12558. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  12559. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12560. }
  12561. function generateMipmap(target, texture, width, height) {
  12562. _gl.generateMipmap(target);
  12563. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12564. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  12565. }
  12566. function getInternalFormat(internalFormatName, glFormat, glType) {
  12567. if (isWebGL2 === false) return glFormat;
  12568. if (internalFormatName !== null) {
  12569. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  12570. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  12571. }
  12572. var internalFormat = glFormat;
  12573. if (glFormat === 6403) {
  12574. if (glType === 5126) internalFormat = 33326;
  12575. if (glType === 5131) internalFormat = 33325;
  12576. if (glType === 5121) internalFormat = 33321;
  12577. }
  12578. if (glFormat === 6407) {
  12579. if (glType === 5126) internalFormat = 34837;
  12580. if (glType === 5131) internalFormat = 34843;
  12581. if (glType === 5121) internalFormat = 32849;
  12582. }
  12583. if (glFormat === 6408) {
  12584. if (glType === 5126) internalFormat = 34836;
  12585. if (glType === 5131) internalFormat = 34842;
  12586. if (glType === 5121) internalFormat = 32856;
  12587. }
  12588. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  12589. extensions.get('EXT_color_buffer_float');
  12590. }
  12591. return internalFormat;
  12592. } // Fallback filters for non-power-of-2 textures
  12593. function filterFallback(f) {
  12594. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  12595. return 9728;
  12596. }
  12597. return 9729;
  12598. } //
  12599. function onTextureDispose(event) {
  12600. var texture = event.target;
  12601. texture.removeEventListener('dispose', onTextureDispose);
  12602. deallocateTexture(texture);
  12603. if (texture.isVideoTexture) {
  12604. _videoTextures.delete(texture);
  12605. }
  12606. info.memory.textures--;
  12607. }
  12608. function onRenderTargetDispose(event) {
  12609. var renderTarget = event.target;
  12610. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  12611. deallocateRenderTarget(renderTarget);
  12612. info.memory.textures--;
  12613. } //
  12614. function deallocateTexture(texture) {
  12615. var textureProperties = properties.get(texture);
  12616. if (textureProperties.__webglInit === undefined) return;
  12617. _gl.deleteTexture(textureProperties.__webglTexture);
  12618. properties.remove(texture);
  12619. }
  12620. function deallocateRenderTarget(renderTarget) {
  12621. var renderTargetProperties = properties.get(renderTarget);
  12622. var textureProperties = properties.get(renderTarget.texture);
  12623. if (!renderTarget) return;
  12624. if (textureProperties.__webglTexture !== undefined) {
  12625. _gl.deleteTexture(textureProperties.__webglTexture);
  12626. }
  12627. if (renderTarget.depthTexture) {
  12628. renderTarget.depthTexture.dispose();
  12629. }
  12630. if (renderTarget.isWebGLCubeRenderTarget) {
  12631. for (var i = 0; i < 6; i++) {
  12632. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  12633. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  12634. }
  12635. } else {
  12636. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  12637. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  12638. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  12639. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  12640. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  12641. }
  12642. properties.remove(renderTarget.texture);
  12643. properties.remove(renderTarget);
  12644. } //
  12645. var textureUnits = 0;
  12646. function resetTextureUnits() {
  12647. textureUnits = 0;
  12648. }
  12649. function allocateTextureUnit() {
  12650. var textureUnit = textureUnits;
  12651. if (textureUnit >= maxTextures) {
  12652. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  12653. }
  12654. textureUnits += 1;
  12655. return textureUnit;
  12656. } //
  12657. function setTexture2D(texture, slot) {
  12658. var textureProperties = properties.get(texture);
  12659. if (texture.isVideoTexture) updateVideoTexture(texture);
  12660. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12661. var image = texture.image;
  12662. if (image === undefined) {
  12663. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  12664. } else if (image.complete === false) {
  12665. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  12666. } else {
  12667. uploadTexture(textureProperties, texture, slot);
  12668. return;
  12669. }
  12670. }
  12671. state.activeTexture(33984 + slot);
  12672. state.bindTexture(3553, textureProperties.__webglTexture);
  12673. }
  12674. function setTexture2DArray(texture, slot) {
  12675. var textureProperties = properties.get(texture);
  12676. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12677. uploadTexture(textureProperties, texture, slot);
  12678. return;
  12679. }
  12680. state.activeTexture(33984 + slot);
  12681. state.bindTexture(35866, textureProperties.__webglTexture);
  12682. }
  12683. function setTexture3D(texture, slot) {
  12684. var textureProperties = properties.get(texture);
  12685. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12686. uploadTexture(textureProperties, texture, slot);
  12687. return;
  12688. }
  12689. state.activeTexture(33984 + slot);
  12690. state.bindTexture(32879, textureProperties.__webglTexture);
  12691. }
  12692. function setTextureCube(texture, slot) {
  12693. var textureProperties = properties.get(texture);
  12694. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12695. uploadCubeTexture(textureProperties, texture, slot);
  12696. return;
  12697. }
  12698. state.activeTexture(33984 + slot);
  12699. state.bindTexture(34067, textureProperties.__webglTexture);
  12700. }
  12701. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  12702. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  12703. function setTextureParameters(textureType, texture, supportsMips) {
  12704. if (supportsMips) {
  12705. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  12706. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  12707. if (textureType === 32879 || textureType === 35866) {
  12708. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  12709. }
  12710. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  12711. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  12712. } else {
  12713. _gl.texParameteri(textureType, 10242, 33071);
  12714. _gl.texParameteri(textureType, 10243, 33071);
  12715. if (textureType === 32879 || textureType === 35866) {
  12716. _gl.texParameteri(textureType, 32882, 33071);
  12717. }
  12718. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  12719. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  12720. }
  12721. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  12722. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  12723. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  12724. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  12725. }
  12726. }
  12727. var extension = extensions.get('EXT_texture_filter_anisotropic');
  12728. if (extension) {
  12729. if (texture.type === FloatType && extensions.get('OES_texture_float_linear') === null) return;
  12730. if (texture.type === HalfFloatType && (isWebGL2 || extensions.get('OES_texture_half_float_linear')) === null) return;
  12731. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  12732. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  12733. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  12734. }
  12735. }
  12736. }
  12737. function initTexture(textureProperties, texture) {
  12738. if (textureProperties.__webglInit === undefined) {
  12739. textureProperties.__webglInit = true;
  12740. texture.addEventListener('dispose', onTextureDispose);
  12741. textureProperties.__webglTexture = _gl.createTexture();
  12742. info.memory.textures++;
  12743. }
  12744. }
  12745. function uploadTexture(textureProperties, texture, slot) {
  12746. var textureType = 3553;
  12747. if (texture.isDataTexture2DArray) textureType = 35866;
  12748. if (texture.isDataTexture3D) textureType = 32879;
  12749. initTexture(textureProperties, texture);
  12750. state.activeTexture(33984 + slot);
  12751. state.bindTexture(textureType, textureProperties.__webglTexture);
  12752. _gl.pixelStorei(37440, texture.flipY);
  12753. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  12754. _gl.pixelStorei(3317, texture.unpackAlignment);
  12755. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  12756. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  12757. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  12758. glFormat = utils.convert(texture.format);
  12759. var glType = utils.convert(texture.type),
  12760. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  12761. setTextureParameters(textureType, texture, supportsMips);
  12762. var mipmap;
  12763. var mipmaps = texture.mipmaps;
  12764. if (texture.isDepthTexture) {
  12765. // populate depth texture with dummy data
  12766. glInternalFormat = 6402;
  12767. if (isWebGL2) {
  12768. if (texture.type === FloatType) {
  12769. glInternalFormat = 36012;
  12770. } else if (texture.type === UnsignedIntType) {
  12771. glInternalFormat = 33190;
  12772. } else if (texture.type === UnsignedInt248Type) {
  12773. glInternalFormat = 35056;
  12774. } else {
  12775. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  12776. }
  12777. } else {
  12778. if (texture.type === FloatType) {
  12779. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  12780. }
  12781. } // validation checks for WebGL 1
  12782. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  12783. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12784. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12785. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12786. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  12787. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  12788. texture.type = UnsignedShortType;
  12789. glType = utils.convert(texture.type);
  12790. }
  12791. }
  12792. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  12793. // Depth stencil textures need the DEPTH_STENCIL internal format
  12794. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12795. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12796. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12797. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12798. if (texture.type !== UnsignedInt248Type) {
  12799. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  12800. texture.type = UnsignedInt248Type;
  12801. glType = utils.convert(texture.type);
  12802. }
  12803. } //
  12804. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  12805. } else if (texture.isDataTexture) {
  12806. // use manually created mipmaps if available
  12807. // if there are no manual mipmaps
  12808. // set 0 level mipmap and then use GL to generate other mipmap levels
  12809. if (mipmaps.length > 0 && supportsMips) {
  12810. for (var i = 0, il = mipmaps.length; i < il; i++) {
  12811. mipmap = mipmaps[i];
  12812. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  12813. }
  12814. texture.generateMipmaps = false;
  12815. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12816. } else {
  12817. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  12818. textureProperties.__maxMipLevel = 0;
  12819. }
  12820. } else if (texture.isCompressedTexture) {
  12821. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  12822. mipmap = mipmaps[_i];
  12823. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  12824. if (glFormat !== null) {
  12825. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  12826. } else {
  12827. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  12828. }
  12829. } else {
  12830. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  12831. }
  12832. }
  12833. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12834. } else if (texture.isDataTexture2DArray) {
  12835. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  12836. textureProperties.__maxMipLevel = 0;
  12837. } else if (texture.isDataTexture3D) {
  12838. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  12839. textureProperties.__maxMipLevel = 0;
  12840. } else {
  12841. // regular Texture (image, video, canvas)
  12842. // use manually created mipmaps if available
  12843. // if there are no manual mipmaps
  12844. // set 0 level mipmap and then use GL to generate other mipmap levels
  12845. if (mipmaps.length > 0 && supportsMips) {
  12846. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  12847. mipmap = mipmaps[_i2];
  12848. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  12849. }
  12850. texture.generateMipmaps = false;
  12851. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12852. } else {
  12853. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  12854. textureProperties.__maxMipLevel = 0;
  12855. }
  12856. }
  12857. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  12858. generateMipmap(textureType, texture, image.width, image.height);
  12859. }
  12860. textureProperties.__version = texture.version;
  12861. if (texture.onUpdate) texture.onUpdate(texture);
  12862. }
  12863. function uploadCubeTexture(textureProperties, texture, slot) {
  12864. if (texture.image.length !== 6) return;
  12865. initTexture(textureProperties, texture);
  12866. state.activeTexture(33984 + slot);
  12867. state.bindTexture(34067, textureProperties.__webglTexture);
  12868. _gl.pixelStorei(37440, texture.flipY);
  12869. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  12870. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  12871. var cubeImage = [];
  12872. for (var i = 0; i < 6; i++) {
  12873. if (!isCompressed && !isDataTexture) {
  12874. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  12875. } else {
  12876. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  12877. }
  12878. }
  12879. var image = cubeImage[0],
  12880. supportsMips = isPowerOfTwo(image) || isWebGL2,
  12881. glFormat = utils.convert(texture.format),
  12882. glType = utils.convert(texture.type),
  12883. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  12884. setTextureParameters(34067, texture, supportsMips);
  12885. var mipmaps;
  12886. if (isCompressed) {
  12887. for (var _i3 = 0; _i3 < 6; _i3++) {
  12888. mipmaps = cubeImage[_i3].mipmaps;
  12889. for (var j = 0; j < mipmaps.length; j++) {
  12890. var mipmap = mipmaps[j];
  12891. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  12892. if (glFormat !== null) {
  12893. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  12894. } else {
  12895. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  12896. }
  12897. } else {
  12898. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  12899. }
  12900. }
  12901. }
  12902. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12903. } else {
  12904. mipmaps = texture.mipmaps;
  12905. for (var _i4 = 0; _i4 < 6; _i4++) {
  12906. if (isDataTexture) {
  12907. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  12908. for (var _j = 0; _j < mipmaps.length; _j++) {
  12909. var _mipmap = mipmaps[_j];
  12910. var mipmapImage = _mipmap.image[_i4].image;
  12911. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  12912. }
  12913. } else {
  12914. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  12915. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  12916. var _mipmap2 = mipmaps[_j2];
  12917. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  12918. }
  12919. }
  12920. }
  12921. textureProperties.__maxMipLevel = mipmaps.length;
  12922. }
  12923. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  12924. // We assume images for cube map have the same size.
  12925. generateMipmap(34067, texture, image.width, image.height);
  12926. }
  12927. textureProperties.__version = texture.version;
  12928. if (texture.onUpdate) texture.onUpdate(texture);
  12929. } // Render targets
  12930. // Setup storage for target texture and bind it to correct framebuffer
  12931. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  12932. var glFormat = utils.convert(renderTarget.texture.format);
  12933. var glType = utils.convert(renderTarget.texture.type);
  12934. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  12935. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  12936. _gl.bindFramebuffer(36160, framebuffer);
  12937. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(renderTarget.texture).__webglTexture, 0);
  12938. _gl.bindFramebuffer(36160, null);
  12939. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12940. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  12941. _gl.bindRenderbuffer(36161, renderbuffer);
  12942. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  12943. var glInternalFormat = 33189;
  12944. if (isMultisample) {
  12945. var depthTexture = renderTarget.depthTexture;
  12946. if (depthTexture && depthTexture.isDepthTexture) {
  12947. if (depthTexture.type === FloatType) {
  12948. glInternalFormat = 36012;
  12949. } else if (depthTexture.type === UnsignedIntType) {
  12950. glInternalFormat = 33190;
  12951. }
  12952. }
  12953. var samples = getRenderTargetSamples(renderTarget);
  12954. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  12955. } else {
  12956. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  12957. }
  12958. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  12959. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  12960. if (isMultisample) {
  12961. var _samples = getRenderTargetSamples(renderTarget);
  12962. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  12963. } else {
  12964. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  12965. }
  12966. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  12967. } else {
  12968. var glFormat = utils.convert(renderTarget.texture.format);
  12969. var glType = utils.convert(renderTarget.texture.type);
  12970. var _glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  12971. if (isMultisample) {
  12972. var _samples2 = getRenderTargetSamples(renderTarget);
  12973. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  12974. } else {
  12975. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  12976. }
  12977. }
  12978. _gl.bindRenderbuffer(36161, null);
  12979. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  12980. function setupDepthTexture(framebuffer, renderTarget) {
  12981. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  12982. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  12983. _gl.bindFramebuffer(36160, framebuffer);
  12984. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  12985. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  12986. } // upload an empty depth texture with framebuffer size
  12987. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  12988. renderTarget.depthTexture.image.width = renderTarget.width;
  12989. renderTarget.depthTexture.image.height = renderTarget.height;
  12990. renderTarget.depthTexture.needsUpdate = true;
  12991. }
  12992. setTexture2D(renderTarget.depthTexture, 0);
  12993. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  12994. if (renderTarget.depthTexture.format === DepthFormat) {
  12995. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  12996. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  12997. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  12998. } else {
  12999. throw new Error('Unknown depthTexture format');
  13000. }
  13001. } // Setup GL resources for a non-texture depth buffer
  13002. function setupDepthRenderbuffer(renderTarget) {
  13003. var renderTargetProperties = properties.get(renderTarget);
  13004. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13005. if (renderTarget.depthTexture) {
  13006. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13007. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13008. } else {
  13009. if (isCube) {
  13010. renderTargetProperties.__webglDepthbuffer = [];
  13011. for (var i = 0; i < 6; i++) {
  13012. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13013. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13014. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13015. }
  13016. } else {
  13017. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13018. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13019. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13020. }
  13021. }
  13022. _gl.bindFramebuffer(36160, null);
  13023. } // Set up GL resources for the render target
  13024. function setupRenderTarget(renderTarget) {
  13025. var renderTargetProperties = properties.get(renderTarget);
  13026. var textureProperties = properties.get(renderTarget.texture);
  13027. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13028. textureProperties.__webglTexture = _gl.createTexture();
  13029. info.memory.textures++;
  13030. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13031. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13032. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13033. if (isWebGL2 && renderTarget.texture.format === RGBFormat && (renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType)) {
  13034. renderTarget.texture.format = RGBAFormat;
  13035. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13036. } // Setup framebuffer
  13037. if (isCube) {
  13038. renderTargetProperties.__webglFramebuffer = [];
  13039. for (var i = 0; i < 6; i++) {
  13040. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13041. }
  13042. } else {
  13043. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13044. if (isMultisample) {
  13045. if (isWebGL2) {
  13046. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13047. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13048. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13049. var glFormat = utils.convert(renderTarget.texture.format);
  13050. var glType = utils.convert(renderTarget.texture.type);
  13051. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13052. var samples = getRenderTargetSamples(renderTarget);
  13053. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13054. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13055. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13056. _gl.bindRenderbuffer(36161, null);
  13057. if (renderTarget.depthBuffer) {
  13058. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13059. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13060. }
  13061. _gl.bindFramebuffer(36160, null);
  13062. } else {
  13063. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13064. }
  13065. }
  13066. } // Setup color buffer
  13067. if (isCube) {
  13068. state.bindTexture(34067, textureProperties.__webglTexture);
  13069. setTextureParameters(34067, renderTarget.texture, supportsMips);
  13070. for (var _i5 = 0; _i5 < 6; _i5++) {
  13071. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13072. }
  13073. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13074. generateMipmap(34067, renderTarget.texture, renderTarget.width, renderTarget.height);
  13075. }
  13076. state.bindTexture(34067, null);
  13077. } else {
  13078. state.bindTexture(3553, textureProperties.__webglTexture);
  13079. setTextureParameters(3553, renderTarget.texture, supportsMips);
  13080. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553);
  13081. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13082. generateMipmap(3553, renderTarget.texture, renderTarget.width, renderTarget.height);
  13083. }
  13084. state.bindTexture(3553, null);
  13085. } // Setup depth and stencil buffers
  13086. if (renderTarget.depthBuffer) {
  13087. setupDepthRenderbuffer(renderTarget);
  13088. }
  13089. }
  13090. function updateRenderTargetMipmap(renderTarget) {
  13091. var texture = renderTarget.texture;
  13092. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13093. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13094. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13095. var webglTexture = properties.get(texture).__webglTexture;
  13096. state.bindTexture(target, webglTexture);
  13097. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13098. state.bindTexture(target, null);
  13099. }
  13100. }
  13101. function updateMultisampleRenderTarget(renderTarget) {
  13102. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13103. if (isWebGL2) {
  13104. var renderTargetProperties = properties.get(renderTarget);
  13105. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13106. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13107. var width = renderTarget.width;
  13108. var height = renderTarget.height;
  13109. var mask = 16384;
  13110. if (renderTarget.depthBuffer) mask |= 256;
  13111. if (renderTarget.stencilBuffer) mask |= 1024;
  13112. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13113. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13114. } else {
  13115. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13116. }
  13117. }
  13118. }
  13119. function getRenderTargetSamples(renderTarget) {
  13120. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13121. }
  13122. function updateVideoTexture(texture) {
  13123. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13124. if (_videoTextures.get(texture) !== frame) {
  13125. _videoTextures.set(texture, frame);
  13126. texture.update();
  13127. }
  13128. } // backwards compatibility
  13129. var warnedTexture2D = false;
  13130. var warnedTextureCube = false;
  13131. function safeSetTexture2D(texture, slot) {
  13132. if (texture && texture.isWebGLRenderTarget) {
  13133. if (warnedTexture2D === false) {
  13134. console.warn("THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead.");
  13135. warnedTexture2D = true;
  13136. }
  13137. texture = texture.texture;
  13138. }
  13139. setTexture2D(texture, slot);
  13140. }
  13141. function safeSetTextureCube(texture, slot) {
  13142. if (texture && texture.isWebGLCubeRenderTarget) {
  13143. if (warnedTextureCube === false) {
  13144. console.warn("THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead.");
  13145. warnedTextureCube = true;
  13146. }
  13147. texture = texture.texture;
  13148. }
  13149. setTextureCube(texture, slot);
  13150. } //
  13151. this.allocateTextureUnit = allocateTextureUnit;
  13152. this.resetTextureUnits = resetTextureUnits;
  13153. this.setTexture2D = setTexture2D;
  13154. this.setTexture2DArray = setTexture2DArray;
  13155. this.setTexture3D = setTexture3D;
  13156. this.setTextureCube = setTextureCube;
  13157. this.setupRenderTarget = setupRenderTarget;
  13158. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13159. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13160. this.safeSetTexture2D = safeSetTexture2D;
  13161. this.safeSetTextureCube = safeSetTextureCube;
  13162. }
  13163. function WebGLUtils(gl, extensions, capabilities) {
  13164. var isWebGL2 = capabilities.isWebGL2;
  13165. function convert(p) {
  13166. var extension;
  13167. if (p === UnsignedByteType) return 5121;
  13168. if (p === UnsignedShort4444Type) return 32819;
  13169. if (p === UnsignedShort5551Type) return 32820;
  13170. if (p === UnsignedShort565Type) return 33635;
  13171. if (p === ByteType) return 5120;
  13172. if (p === ShortType) return 5122;
  13173. if (p === UnsignedShortType) return 5123;
  13174. if (p === IntType) return 5124;
  13175. if (p === UnsignedIntType) return 5125;
  13176. if (p === FloatType) return 5126;
  13177. if (p === HalfFloatType) {
  13178. if (isWebGL2) return 5131;
  13179. extension = extensions.get('OES_texture_half_float');
  13180. if (extension !== null) {
  13181. return extension.HALF_FLOAT_OES;
  13182. } else {
  13183. return null;
  13184. }
  13185. }
  13186. if (p === AlphaFormat) return 6406;
  13187. if (p === RGBFormat) return 6407;
  13188. if (p === RGBAFormat) return 6408;
  13189. if (p === LuminanceFormat) return 6409;
  13190. if (p === LuminanceAlphaFormat) return 6410;
  13191. if (p === DepthFormat) return 6402;
  13192. if (p === DepthStencilFormat) return 34041;
  13193. if (p === RedFormat) return 6403; // WebGL2 formats.
  13194. if (p === RedIntegerFormat) return 36244;
  13195. if (p === RGFormat) return 33319;
  13196. if (p === RGIntegerFormat) return 33320;
  13197. if (p === RGBIntegerFormat) return 36248;
  13198. if (p === RGBAIntegerFormat) return 36249;
  13199. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13200. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13201. if (extension !== null) {
  13202. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13203. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13204. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13205. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13206. } else {
  13207. return null;
  13208. }
  13209. }
  13210. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13211. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13212. if (extension !== null) {
  13213. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13214. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13215. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13216. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13217. } else {
  13218. return null;
  13219. }
  13220. }
  13221. if (p === RGB_ETC1_Format) {
  13222. extension = extensions.get('WEBGL_compressed_texture_etc1');
  13223. if (extension !== null) {
  13224. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13225. } else {
  13226. return null;
  13227. }
  13228. }
  13229. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  13230. extension = extensions.get('WEBGL_compressed_texture_etc');
  13231. if (extension !== null) {
  13232. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  13233. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13234. }
  13235. }
  13236. 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) {
  13237. extension = extensions.get('WEBGL_compressed_texture_astc');
  13238. if (extension !== null) {
  13239. // TODO Complete?
  13240. return p;
  13241. } else {
  13242. return null;
  13243. }
  13244. }
  13245. if (p === RGBA_BPTC_Format) {
  13246. extension = extensions.get('EXT_texture_compression_bptc');
  13247. if (extension !== null) {
  13248. // TODO Complete?
  13249. return p;
  13250. } else {
  13251. return null;
  13252. }
  13253. }
  13254. if (p === UnsignedInt248Type) {
  13255. if (isWebGL2) return 34042;
  13256. extension = extensions.get('WEBGL_depth_texture');
  13257. if (extension !== null) {
  13258. return extension.UNSIGNED_INT_24_8_WEBGL;
  13259. } else {
  13260. return null;
  13261. }
  13262. }
  13263. }
  13264. return {
  13265. convert: convert
  13266. };
  13267. }
  13268. function ArrayCamera(array) {
  13269. PerspectiveCamera.call(this);
  13270. this.cameras = array || [];
  13271. }
  13272. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  13273. constructor: ArrayCamera,
  13274. isArrayCamera: true
  13275. });
  13276. function Group() {
  13277. Object3D.call(this);
  13278. this.type = 'Group';
  13279. }
  13280. Group.prototype = Object.assign(Object.create(Object3D.prototype), {
  13281. constructor: Group,
  13282. isGroup: true
  13283. });
  13284. function WebXRController() {
  13285. this._targetRay = null;
  13286. this._grip = null;
  13287. this._hand = null;
  13288. }
  13289. Object.assign(WebXRController.prototype, {
  13290. constructor: WebXRController,
  13291. getHandSpace: function getHandSpace() {
  13292. if (this._hand === null) {
  13293. this._hand = new Group();
  13294. this._hand.matrixAutoUpdate = false;
  13295. this._hand.visible = false;
  13296. this._hand.joints = [];
  13297. this._hand.inputState = {
  13298. pinching: false
  13299. };
  13300. if (window.XRHand) {
  13301. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13302. // The transform of this joint will be updated with the joint pose on each frame
  13303. var joint = new Group();
  13304. joint.matrixAutoUpdate = false;
  13305. joint.visible = false;
  13306. this._hand.joints.push(joint); // ??
  13307. this._hand.add(joint);
  13308. }
  13309. }
  13310. }
  13311. return this._hand;
  13312. },
  13313. getTargetRaySpace: function getTargetRaySpace() {
  13314. if (this._targetRay === null) {
  13315. this._targetRay = new Group();
  13316. this._targetRay.matrixAutoUpdate = false;
  13317. this._targetRay.visible = false;
  13318. }
  13319. return this._targetRay;
  13320. },
  13321. getGripSpace: function getGripSpace() {
  13322. if (this._grip === null) {
  13323. this._grip = new Group();
  13324. this._grip.matrixAutoUpdate = false;
  13325. this._grip.visible = false;
  13326. }
  13327. return this._grip;
  13328. },
  13329. dispatchEvent: function dispatchEvent(event) {
  13330. if (this._targetRay !== null) {
  13331. this._targetRay.dispatchEvent(event);
  13332. }
  13333. if (this._grip !== null) {
  13334. this._grip.dispatchEvent(event);
  13335. }
  13336. if (this._hand !== null) {
  13337. this._hand.dispatchEvent(event);
  13338. }
  13339. return this;
  13340. },
  13341. disconnect: function disconnect(inputSource) {
  13342. this.dispatchEvent({
  13343. type: 'disconnected',
  13344. data: inputSource
  13345. });
  13346. if (this._targetRay !== null) {
  13347. this._targetRay.visible = false;
  13348. }
  13349. if (this._grip !== null) {
  13350. this._grip.visible = false;
  13351. }
  13352. if (this._hand !== null) {
  13353. this._hand.visible = false;
  13354. }
  13355. return this;
  13356. },
  13357. update: function update(inputSource, frame, referenceSpace) {
  13358. var inputPose = null;
  13359. var gripPose = null;
  13360. var handPose = null;
  13361. var targetRay = this._targetRay;
  13362. var grip = this._grip;
  13363. var hand = this._hand;
  13364. if (inputSource) {
  13365. if (hand && inputSource.hand) {
  13366. handPose = true;
  13367. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13368. if (inputSource.hand[i]) {
  13369. // Update the joints groups with the XRJoint poses
  13370. var jointPose = frame.getJointPose(inputSource.hand[i], referenceSpace);
  13371. var joint = hand.joints[i];
  13372. if (jointPose !== null) {
  13373. joint.matrix.fromArray(jointPose.transform.matrix);
  13374. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  13375. joint.jointRadius = jointPose.radius;
  13376. }
  13377. joint.visible = jointPose !== null; // Custom events
  13378. // Check pinch
  13379. var indexTip = hand.joints[window.XRHand.INDEX_PHALANX_TIP];
  13380. var thumbTip = hand.joints[window.XRHand.THUMB_PHALANX_TIP];
  13381. var distance = indexTip.position.distanceTo(thumbTip.position);
  13382. var distanceToPinch = 0.02;
  13383. var threshold = 0.005;
  13384. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  13385. hand.inputState.pinching = false;
  13386. this.dispatchEvent({
  13387. type: "pinchend",
  13388. handedness: inputSource.handedness,
  13389. target: this
  13390. });
  13391. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  13392. hand.inputState.pinching = true;
  13393. this.dispatchEvent({
  13394. type: "pinchstart",
  13395. handedness: inputSource.handedness,
  13396. target: this
  13397. });
  13398. }
  13399. }
  13400. }
  13401. } else {
  13402. if (targetRay !== null) {
  13403. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  13404. if (inputPose !== null) {
  13405. targetRay.matrix.fromArray(inputPose.transform.matrix);
  13406. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  13407. }
  13408. }
  13409. if (grip !== null && inputSource.gripSpace) {
  13410. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  13411. if (gripPose !== null) {
  13412. grip.matrix.fromArray(gripPose.transform.matrix);
  13413. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  13414. }
  13415. }
  13416. }
  13417. }
  13418. if (targetRay !== null) {
  13419. targetRay.visible = inputPose !== null;
  13420. }
  13421. if (grip !== null) {
  13422. grip.visible = gripPose !== null;
  13423. }
  13424. if (hand !== null) {
  13425. hand.visible = handPose !== null;
  13426. }
  13427. return this;
  13428. }
  13429. });
  13430. function WebXRManager(renderer, gl) {
  13431. var scope = this;
  13432. var session = null;
  13433. var framebufferScaleFactor = 1.0;
  13434. var referenceSpace = null;
  13435. var referenceSpaceType = 'local-floor';
  13436. var pose = null;
  13437. var controllers = [];
  13438. var inputSourcesMap = new Map(); //
  13439. var cameraL = new PerspectiveCamera();
  13440. cameraL.layers.enable(1);
  13441. cameraL.viewport = new Vector4();
  13442. var cameraR = new PerspectiveCamera();
  13443. cameraR.layers.enable(2);
  13444. cameraR.viewport = new Vector4();
  13445. var cameras = [cameraL, cameraR];
  13446. var cameraVR = new ArrayCamera();
  13447. cameraVR.layers.enable(1);
  13448. cameraVR.layers.enable(2);
  13449. var _currentDepthNear = null;
  13450. var _currentDepthFar = null; //
  13451. this.enabled = false;
  13452. this.isPresenting = false;
  13453. this.getController = function (index) {
  13454. var controller = controllers[index];
  13455. if (controller === undefined) {
  13456. controller = new WebXRController();
  13457. controllers[index] = controller;
  13458. }
  13459. return controller.getTargetRaySpace();
  13460. };
  13461. this.getControllerGrip = function (index) {
  13462. var controller = controllers[index];
  13463. if (controller === undefined) {
  13464. controller = new WebXRController();
  13465. controllers[index] = controller;
  13466. }
  13467. return controller.getGripSpace();
  13468. };
  13469. this.getHand = function (index) {
  13470. var controller = controllers[index];
  13471. if (controller === undefined) {
  13472. controller = new WebXRController();
  13473. controllers[index] = controller;
  13474. }
  13475. return controller.getHandSpace();
  13476. }; //
  13477. function onSessionEvent(event) {
  13478. var controller = inputSourcesMap.get(event.inputSource);
  13479. if (controller) {
  13480. controller.dispatchEvent({
  13481. type: event.type,
  13482. data: event.inputSource
  13483. });
  13484. }
  13485. }
  13486. function onSessionEnd() {
  13487. inputSourcesMap.forEach(function (controller, inputSource) {
  13488. controller.disconnect(inputSource);
  13489. });
  13490. inputSourcesMap.clear(); //
  13491. renderer.setFramebuffer(null);
  13492. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  13493. animation.stop();
  13494. scope.isPresenting = false;
  13495. scope.dispatchEvent({
  13496. type: 'sessionend'
  13497. });
  13498. }
  13499. function onRequestReferenceSpace(value) {
  13500. referenceSpace = value;
  13501. animation.setContext(session);
  13502. animation.start();
  13503. scope.isPresenting = true;
  13504. scope.dispatchEvent({
  13505. type: 'sessionstart'
  13506. });
  13507. }
  13508. this.setFramebufferScaleFactor = function (value) {
  13509. framebufferScaleFactor = value;
  13510. if (scope.isPresenting === true) {
  13511. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  13512. }
  13513. };
  13514. this.setReferenceSpaceType = function (value) {
  13515. referenceSpaceType = value;
  13516. if (scope.isPresenting === true) {
  13517. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  13518. }
  13519. };
  13520. this.getReferenceSpace = function () {
  13521. return referenceSpace;
  13522. };
  13523. this.getSession = function () {
  13524. return session;
  13525. };
  13526. this.setSession = function (value) {
  13527. session = value;
  13528. if (session !== null) {
  13529. session.addEventListener('select', onSessionEvent);
  13530. session.addEventListener('selectstart', onSessionEvent);
  13531. session.addEventListener('selectend', onSessionEvent);
  13532. session.addEventListener('squeeze', onSessionEvent);
  13533. session.addEventListener('squeezestart', onSessionEvent);
  13534. session.addEventListener('squeezeend', onSessionEvent);
  13535. session.addEventListener('end', onSessionEnd);
  13536. var attributes = gl.getContextAttributes();
  13537. if (attributes.xrCompatible !== true) {
  13538. gl.makeXRCompatible();
  13539. }
  13540. var layerInit = {
  13541. antialias: attributes.antialias,
  13542. alpha: attributes.alpha,
  13543. depth: attributes.depth,
  13544. stencil: attributes.stencil,
  13545. framebufferScaleFactor: framebufferScaleFactor
  13546. }; // eslint-disable-next-line no-undef
  13547. var baseLayer = new XRWebGLLayer(session, gl, layerInit);
  13548. session.updateRenderState({
  13549. baseLayer: baseLayer
  13550. });
  13551. session.requestReferenceSpace(referenceSpaceType).then(onRequestReferenceSpace); //
  13552. session.addEventListener('inputsourceschange', updateInputSources);
  13553. }
  13554. };
  13555. function updateInputSources(event) {
  13556. var inputSources = session.inputSources; // Assign inputSources to available controllers
  13557. for (var i = 0; i < controllers.length; i++) {
  13558. inputSourcesMap.set(inputSources[i], controllers[i]);
  13559. } // Notify disconnected
  13560. for (var _i = 0; _i < event.removed.length; _i++) {
  13561. var inputSource = event.removed[_i];
  13562. var controller = inputSourcesMap.get(inputSource);
  13563. if (controller) {
  13564. controller.dispatchEvent({
  13565. type: 'disconnected',
  13566. data: inputSource
  13567. });
  13568. inputSourcesMap.delete(inputSource);
  13569. }
  13570. } // Notify connected
  13571. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  13572. var _inputSource = event.added[_i2];
  13573. var _controller = inputSourcesMap.get(_inputSource);
  13574. if (_controller) {
  13575. _controller.dispatchEvent({
  13576. type: 'connected',
  13577. data: _inputSource
  13578. });
  13579. }
  13580. }
  13581. } //
  13582. var cameraLPos = new Vector3();
  13583. var cameraRPos = new Vector3();
  13584. /**
  13585. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13586. * the cameras' projection and world matrices have already been set.
  13587. * And that near and far planes are identical for both cameras.
  13588. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13589. */
  13590. function setProjectionFromUnion(camera, cameraL, cameraR) {
  13591. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  13592. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  13593. var ipd = cameraLPos.distanceTo(cameraRPos);
  13594. var projL = cameraL.projectionMatrix.elements;
  13595. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  13596. // most likely identical top and bottom frustum extents.
  13597. // Use the left camera for these values.
  13598. var near = projL[14] / (projL[10] - 1);
  13599. var far = projL[14] / (projL[10] + 1);
  13600. var topFov = (projL[9] + 1) / projL[5];
  13601. var bottomFov = (projL[9] - 1) / projL[5];
  13602. var leftFov = (projL[8] - 1) / projL[0];
  13603. var rightFov = (projR[8] + 1) / projR[0];
  13604. var left = near * leftFov;
  13605. var right = near * rightFov; // Calculate the new camera's position offset from the
  13606. // left camera. xOffset should be roughly half `ipd`.
  13607. var zOffset = ipd / (-leftFov + rightFov);
  13608. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  13609. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  13610. camera.translateX(xOffset);
  13611. camera.translateZ(zOffset);
  13612. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  13613. camera.matrixWorldInverse.getInverse(camera.matrixWorld); // Find the union of the frustum values of the cameras and scale
  13614. // the values so that the near plane's position does not change in world space,
  13615. // although must now be relative to the new union camera.
  13616. var near2 = near + zOffset;
  13617. var far2 = far + zOffset;
  13618. var left2 = left - xOffset;
  13619. var right2 = right + (ipd - xOffset);
  13620. var top2 = topFov * far / far2 * near2;
  13621. var bottom2 = bottomFov * far / far2 * near2;
  13622. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  13623. }
  13624. function updateCamera(camera, parent) {
  13625. if (parent === null) {
  13626. camera.matrixWorld.copy(camera.matrix);
  13627. } else {
  13628. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  13629. }
  13630. camera.matrixWorldInverse.getInverse(camera.matrixWorld);
  13631. }
  13632. this.getCamera = function (camera) {
  13633. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  13634. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  13635. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  13636. // Note that the new renderState won't apply until the next frame. See #18320
  13637. session.updateRenderState({
  13638. depthNear: cameraVR.near,
  13639. depthFar: cameraVR.far
  13640. });
  13641. _currentDepthNear = cameraVR.near;
  13642. _currentDepthFar = cameraVR.far;
  13643. }
  13644. var parent = camera.parent;
  13645. var cameras = cameraVR.cameras;
  13646. updateCamera(cameraVR, parent);
  13647. for (var i = 0; i < cameras.length; i++) {
  13648. updateCamera(cameras[i], parent);
  13649. } // update camera and its children
  13650. camera.matrixWorld.copy(cameraVR.matrixWorld);
  13651. var children = camera.children;
  13652. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  13653. children[_i3].updateMatrixWorld(true);
  13654. } // update projection matrix for proper view frustum culling
  13655. if (cameras.length === 2) {
  13656. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  13657. } else {
  13658. // assume single camera setup (AR)
  13659. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  13660. }
  13661. return cameraVR;
  13662. }; // Animation Loop
  13663. var onAnimationFrameCallback = null;
  13664. function onAnimationFrame(time, frame) {
  13665. pose = frame.getViewerPose(referenceSpace);
  13666. if (pose !== null) {
  13667. var views = pose.views;
  13668. var baseLayer = session.renderState.baseLayer;
  13669. renderer.setFramebuffer(baseLayer.framebuffer);
  13670. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  13671. if (views.length !== cameraVR.cameras.length) {
  13672. cameraVR.cameras.length = 0;
  13673. cameraVRNeedsUpdate = true;
  13674. }
  13675. for (var i = 0; i < views.length; i++) {
  13676. var view = views[i];
  13677. var viewport = baseLayer.getViewport(view);
  13678. var camera = cameras[i];
  13679. camera.matrix.fromArray(view.transform.matrix);
  13680. camera.projectionMatrix.fromArray(view.projectionMatrix);
  13681. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  13682. if (i === 0) {
  13683. cameraVR.matrix.copy(camera.matrix);
  13684. }
  13685. if (cameraVRNeedsUpdate === true) {
  13686. cameraVR.cameras.push(camera);
  13687. }
  13688. }
  13689. } //
  13690. var inputSources = session.inputSources;
  13691. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  13692. var controller = controllers[_i4];
  13693. var inputSource = inputSources[_i4];
  13694. controller.update(inputSource, frame, referenceSpace);
  13695. }
  13696. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  13697. }
  13698. var animation = new WebGLAnimation();
  13699. animation.setAnimationLoop(onAnimationFrame);
  13700. this.setAnimationLoop = function (callback) {
  13701. onAnimationFrameCallback = callback;
  13702. };
  13703. this.dispose = function () {};
  13704. }
  13705. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  13706. function WebGLMaterials(properties) {
  13707. function refreshFogUniforms(uniforms, fog) {
  13708. uniforms.fogColor.value.copy(fog.color);
  13709. if (fog.isFog) {
  13710. uniforms.fogNear.value = fog.near;
  13711. uniforms.fogFar.value = fog.far;
  13712. } else if (fog.isFogExp2) {
  13713. uniforms.fogDensity.value = fog.density;
  13714. }
  13715. }
  13716. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  13717. if (material.isMeshBasicMaterial) {
  13718. refreshUniformsCommon(uniforms, material);
  13719. } else if (material.isMeshLambertMaterial) {
  13720. refreshUniformsCommon(uniforms, material);
  13721. refreshUniformsLambert(uniforms, material);
  13722. } else if (material.isMeshToonMaterial) {
  13723. refreshUniformsCommon(uniforms, material);
  13724. refreshUniformsToon(uniforms, material);
  13725. } else if (material.isMeshPhongMaterial) {
  13726. refreshUniformsCommon(uniforms, material);
  13727. refreshUniformsPhong(uniforms, material);
  13728. } else if (material.isMeshStandardMaterial) {
  13729. refreshUniformsCommon(uniforms, material);
  13730. if (material.isMeshPhysicalMaterial) {
  13731. refreshUniformsPhysical(uniforms, material);
  13732. } else {
  13733. refreshUniformsStandard(uniforms, material);
  13734. }
  13735. } else if (material.isMeshMatcapMaterial) {
  13736. refreshUniformsCommon(uniforms, material);
  13737. refreshUniformsMatcap(uniforms, material);
  13738. } else if (material.isMeshDepthMaterial) {
  13739. refreshUniformsCommon(uniforms, material);
  13740. refreshUniformsDepth(uniforms, material);
  13741. } else if (material.isMeshDistanceMaterial) {
  13742. refreshUniformsCommon(uniforms, material);
  13743. refreshUniformsDistance(uniforms, material);
  13744. } else if (material.isMeshNormalMaterial) {
  13745. refreshUniformsCommon(uniforms, material);
  13746. refreshUniformsNormal(uniforms, material);
  13747. } else if (material.isLineBasicMaterial) {
  13748. refreshUniformsLine(uniforms, material);
  13749. if (material.isLineDashedMaterial) {
  13750. refreshUniformsDash(uniforms, material);
  13751. }
  13752. } else if (material.isPointsMaterial) {
  13753. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  13754. } else if (material.isSpriteMaterial) {
  13755. refreshUniformsSprites(uniforms, material);
  13756. } else if (material.isShadowMaterial) {
  13757. uniforms.color.value.copy(material.color);
  13758. uniforms.opacity.value = material.opacity;
  13759. } else if (material.isShaderMaterial) {
  13760. material.uniformsNeedUpdate = false; // #15581
  13761. }
  13762. }
  13763. function refreshUniformsCommon(uniforms, material) {
  13764. uniforms.opacity.value = material.opacity;
  13765. if (material.color) {
  13766. uniforms.diffuse.value.copy(material.color);
  13767. }
  13768. if (material.emissive) {
  13769. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  13770. }
  13771. if (material.map) {
  13772. uniforms.map.value = material.map;
  13773. }
  13774. if (material.alphaMap) {
  13775. uniforms.alphaMap.value = material.alphaMap;
  13776. }
  13777. if (material.specularMap) {
  13778. uniforms.specularMap.value = material.specularMap;
  13779. }
  13780. var envMap = properties.get(material).envMap;
  13781. if (envMap) {
  13782. uniforms.envMap.value = envMap;
  13783. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  13784. uniforms.reflectivity.value = material.reflectivity;
  13785. uniforms.refractionRatio.value = material.refractionRatio;
  13786. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  13787. if (maxMipLevel !== undefined) {
  13788. uniforms.maxMipLevel.value = maxMipLevel;
  13789. }
  13790. }
  13791. if (material.lightMap) {
  13792. uniforms.lightMap.value = material.lightMap;
  13793. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13794. }
  13795. if (material.aoMap) {
  13796. uniforms.aoMap.value = material.aoMap;
  13797. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13798. } // uv repeat and offset setting priorities
  13799. // 1. color map
  13800. // 2. specular map
  13801. // 3. displacementMap map
  13802. // 4. normal map
  13803. // 5. bump map
  13804. // 6. roughnessMap map
  13805. // 7. metalnessMap map
  13806. // 8. alphaMap map
  13807. // 9. emissiveMap map
  13808. // 10. clearcoat map
  13809. // 11. clearcoat normal map
  13810. // 12. clearcoat roughnessMap map
  13811. var uvScaleMap;
  13812. if (material.map) {
  13813. uvScaleMap = material.map;
  13814. } else if (material.specularMap) {
  13815. uvScaleMap = material.specularMap;
  13816. } else if (material.displacementMap) {
  13817. uvScaleMap = material.displacementMap;
  13818. } else if (material.normalMap) {
  13819. uvScaleMap = material.normalMap;
  13820. } else if (material.bumpMap) {
  13821. uvScaleMap = material.bumpMap;
  13822. } else if (material.roughnessMap) {
  13823. uvScaleMap = material.roughnessMap;
  13824. } else if (material.metalnessMap) {
  13825. uvScaleMap = material.metalnessMap;
  13826. } else if (material.alphaMap) {
  13827. uvScaleMap = material.alphaMap;
  13828. } else if (material.emissiveMap) {
  13829. uvScaleMap = material.emissiveMap;
  13830. } else if (material.clearcoatMap) {
  13831. uvScaleMap = material.clearcoatMap;
  13832. } else if (material.clearcoatNormalMap) {
  13833. uvScaleMap = material.clearcoatNormalMap;
  13834. } else if (material.clearcoatRoughnessMap) {
  13835. uvScaleMap = material.clearcoatRoughnessMap;
  13836. }
  13837. if (uvScaleMap !== undefined) {
  13838. // backwards compatibility
  13839. if (uvScaleMap.isWebGLRenderTarget) {
  13840. uvScaleMap = uvScaleMap.texture;
  13841. }
  13842. if (uvScaleMap.matrixAutoUpdate === true) {
  13843. uvScaleMap.updateMatrix();
  13844. }
  13845. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  13846. } // uv repeat and offset setting priorities for uv2
  13847. // 1. ao map
  13848. // 2. light map
  13849. var uv2ScaleMap;
  13850. if (material.aoMap) {
  13851. uv2ScaleMap = material.aoMap;
  13852. } else if (material.lightMap) {
  13853. uv2ScaleMap = material.lightMap;
  13854. }
  13855. if (uv2ScaleMap !== undefined) {
  13856. // backwards compatibility
  13857. if (uv2ScaleMap.isWebGLRenderTarget) {
  13858. uv2ScaleMap = uv2ScaleMap.texture;
  13859. }
  13860. if (uv2ScaleMap.matrixAutoUpdate === true) {
  13861. uv2ScaleMap.updateMatrix();
  13862. }
  13863. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  13864. }
  13865. }
  13866. function refreshUniformsLine(uniforms, material) {
  13867. uniforms.diffuse.value.copy(material.color);
  13868. uniforms.opacity.value = material.opacity;
  13869. }
  13870. function refreshUniformsDash(uniforms, material) {
  13871. uniforms.dashSize.value = material.dashSize;
  13872. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13873. uniforms.scale.value = material.scale;
  13874. }
  13875. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  13876. uniforms.diffuse.value.copy(material.color);
  13877. uniforms.opacity.value = material.opacity;
  13878. uniforms.size.value = material.size * pixelRatio;
  13879. uniforms.scale.value = height * 0.5;
  13880. if (material.map) {
  13881. uniforms.map.value = material.map;
  13882. }
  13883. if (material.alphaMap) {
  13884. uniforms.alphaMap.value = material.alphaMap;
  13885. } // uv repeat and offset setting priorities
  13886. // 1. color map
  13887. // 2. alpha map
  13888. var uvScaleMap;
  13889. if (material.map) {
  13890. uvScaleMap = material.map;
  13891. } else if (material.alphaMap) {
  13892. uvScaleMap = material.alphaMap;
  13893. }
  13894. if (uvScaleMap !== undefined) {
  13895. if (uvScaleMap.matrixAutoUpdate === true) {
  13896. uvScaleMap.updateMatrix();
  13897. }
  13898. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  13899. }
  13900. }
  13901. function refreshUniformsSprites(uniforms, material) {
  13902. uniforms.diffuse.value.copy(material.color);
  13903. uniforms.opacity.value = material.opacity;
  13904. uniforms.rotation.value = material.rotation;
  13905. if (material.map) {
  13906. uniforms.map.value = material.map;
  13907. }
  13908. if (material.alphaMap) {
  13909. uniforms.alphaMap.value = material.alphaMap;
  13910. } // uv repeat and offset setting priorities
  13911. // 1. color map
  13912. // 2. alpha map
  13913. var uvScaleMap;
  13914. if (material.map) {
  13915. uvScaleMap = material.map;
  13916. } else if (material.alphaMap) {
  13917. uvScaleMap = material.alphaMap;
  13918. }
  13919. if (uvScaleMap !== undefined) {
  13920. if (uvScaleMap.matrixAutoUpdate === true) {
  13921. uvScaleMap.updateMatrix();
  13922. }
  13923. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  13924. }
  13925. }
  13926. function refreshUniformsLambert(uniforms, material) {
  13927. if (material.emissiveMap) {
  13928. uniforms.emissiveMap.value = material.emissiveMap;
  13929. }
  13930. }
  13931. function refreshUniformsPhong(uniforms, material) {
  13932. uniforms.specular.value.copy(material.specular);
  13933. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  13934. if (material.emissiveMap) {
  13935. uniforms.emissiveMap.value = material.emissiveMap;
  13936. }
  13937. if (material.bumpMap) {
  13938. uniforms.bumpMap.value = material.bumpMap;
  13939. uniforms.bumpScale.value = material.bumpScale;
  13940. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  13941. }
  13942. if (material.normalMap) {
  13943. uniforms.normalMap.value = material.normalMap;
  13944. uniforms.normalScale.value.copy(material.normalScale);
  13945. if (material.side === BackSide) uniforms.normalScale.value.negate();
  13946. }
  13947. if (material.displacementMap) {
  13948. uniforms.displacementMap.value = material.displacementMap;
  13949. uniforms.displacementScale.value = material.displacementScale;
  13950. uniforms.displacementBias.value = material.displacementBias;
  13951. }
  13952. }
  13953. function refreshUniformsToon(uniforms, material) {
  13954. if (material.gradientMap) {
  13955. uniforms.gradientMap.value = material.gradientMap;
  13956. }
  13957. if (material.emissiveMap) {
  13958. uniforms.emissiveMap.value = material.emissiveMap;
  13959. }
  13960. if (material.bumpMap) {
  13961. uniforms.bumpMap.value = material.bumpMap;
  13962. uniforms.bumpScale.value = material.bumpScale;
  13963. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  13964. }
  13965. if (material.normalMap) {
  13966. uniforms.normalMap.value = material.normalMap;
  13967. uniforms.normalScale.value.copy(material.normalScale);
  13968. if (material.side === BackSide) uniforms.normalScale.value.negate();
  13969. }
  13970. if (material.displacementMap) {
  13971. uniforms.displacementMap.value = material.displacementMap;
  13972. uniforms.displacementScale.value = material.displacementScale;
  13973. uniforms.displacementBias.value = material.displacementBias;
  13974. }
  13975. }
  13976. function refreshUniformsStandard(uniforms, material) {
  13977. uniforms.roughness.value = material.roughness;
  13978. uniforms.metalness.value = material.metalness;
  13979. if (material.roughnessMap) {
  13980. uniforms.roughnessMap.value = material.roughnessMap;
  13981. }
  13982. if (material.metalnessMap) {
  13983. uniforms.metalnessMap.value = material.metalnessMap;
  13984. }
  13985. if (material.emissiveMap) {
  13986. uniforms.emissiveMap.value = material.emissiveMap;
  13987. }
  13988. if (material.bumpMap) {
  13989. uniforms.bumpMap.value = material.bumpMap;
  13990. uniforms.bumpScale.value = material.bumpScale;
  13991. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  13992. }
  13993. if (material.normalMap) {
  13994. uniforms.normalMap.value = material.normalMap;
  13995. uniforms.normalScale.value.copy(material.normalScale);
  13996. if (material.side === BackSide) uniforms.normalScale.value.negate();
  13997. }
  13998. if (material.displacementMap) {
  13999. uniforms.displacementMap.value = material.displacementMap;
  14000. uniforms.displacementScale.value = material.displacementScale;
  14001. uniforms.displacementBias.value = material.displacementBias;
  14002. }
  14003. var envMap = properties.get(material).envMap;
  14004. if (envMap) {
  14005. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14006. uniforms.envMapIntensity.value = material.envMapIntensity;
  14007. }
  14008. }
  14009. function refreshUniformsPhysical(uniforms, material) {
  14010. refreshUniformsStandard(uniforms, material);
  14011. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14012. uniforms.clearcoat.value = material.clearcoat;
  14013. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14014. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14015. if (material.clearcoatMap) {
  14016. uniforms.clearcoatMap.value = material.clearcoatMap;
  14017. }
  14018. if (material.clearcoatRoughnessMap) {
  14019. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14020. }
  14021. if (material.clearcoatNormalMap) {
  14022. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14023. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14024. if (material.side === BackSide) {
  14025. uniforms.clearcoatNormalScale.value.negate();
  14026. }
  14027. }
  14028. uniforms.transmission.value = material.transmission;
  14029. if (material.transmissionMap) {
  14030. uniforms.transmissionMap.value = material.transmissionMap;
  14031. }
  14032. }
  14033. function refreshUniformsMatcap(uniforms, material) {
  14034. if (material.matcap) {
  14035. uniforms.matcap.value = material.matcap;
  14036. }
  14037. if (material.bumpMap) {
  14038. uniforms.bumpMap.value = material.bumpMap;
  14039. uniforms.bumpScale.value = material.bumpScale;
  14040. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14041. }
  14042. if (material.normalMap) {
  14043. uniforms.normalMap.value = material.normalMap;
  14044. uniforms.normalScale.value.copy(material.normalScale);
  14045. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14046. }
  14047. if (material.displacementMap) {
  14048. uniforms.displacementMap.value = material.displacementMap;
  14049. uniforms.displacementScale.value = material.displacementScale;
  14050. uniforms.displacementBias.value = material.displacementBias;
  14051. }
  14052. }
  14053. function refreshUniformsDepth(uniforms, material) {
  14054. if (material.displacementMap) {
  14055. uniforms.displacementMap.value = material.displacementMap;
  14056. uniforms.displacementScale.value = material.displacementScale;
  14057. uniforms.displacementBias.value = material.displacementBias;
  14058. }
  14059. }
  14060. function refreshUniformsDistance(uniforms, material) {
  14061. if (material.displacementMap) {
  14062. uniforms.displacementMap.value = material.displacementMap;
  14063. uniforms.displacementScale.value = material.displacementScale;
  14064. uniforms.displacementBias.value = material.displacementBias;
  14065. }
  14066. uniforms.referencePosition.value.copy(material.referencePosition);
  14067. uniforms.nearDistance.value = material.nearDistance;
  14068. uniforms.farDistance.value = material.farDistance;
  14069. }
  14070. function refreshUniformsNormal(uniforms, material) {
  14071. if (material.bumpMap) {
  14072. uniforms.bumpMap.value = material.bumpMap;
  14073. uniforms.bumpScale.value = material.bumpScale;
  14074. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14075. }
  14076. if (material.normalMap) {
  14077. uniforms.normalMap.value = material.normalMap;
  14078. uniforms.normalScale.value.copy(material.normalScale);
  14079. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14080. }
  14081. if (material.displacementMap) {
  14082. uniforms.displacementMap.value = material.displacementMap;
  14083. uniforms.displacementScale.value = material.displacementScale;
  14084. uniforms.displacementBias.value = material.displacementBias;
  14085. }
  14086. }
  14087. return {
  14088. refreshFogUniforms: refreshFogUniforms,
  14089. refreshMaterialUniforms: refreshMaterialUniforms
  14090. };
  14091. }
  14092. function WebGLRenderer(parameters) {
  14093. parameters = parameters || {};
  14094. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas'),
  14095. _context = parameters.context !== undefined ? parameters.context : null,
  14096. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14097. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14098. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14099. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14100. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14101. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14102. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14103. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14104. var currentRenderList = null;
  14105. var currentRenderState = null; // public properties
  14106. this.domElement = _canvas; // Debug configuration container
  14107. this.debug = {
  14108. /**
  14109. * Enables error checking and reporting when shader programs are being compiled
  14110. * @type {boolean}
  14111. */
  14112. checkShaderErrors: true
  14113. }; // clearing
  14114. this.autoClear = true;
  14115. this.autoClearColor = true;
  14116. this.autoClearDepth = true;
  14117. this.autoClearStencil = true; // scene graph
  14118. this.sortObjects = true; // user-defined clipping
  14119. this.clippingPlanes = [];
  14120. this.localClippingEnabled = false; // physically based shading
  14121. this.gammaFactor = 2.0; // for backwards compatibility
  14122. this.outputEncoding = LinearEncoding; // physical lights
  14123. this.physicallyCorrectLights = false; // tone mapping
  14124. this.toneMapping = NoToneMapping;
  14125. this.toneMappingExposure = 1.0; // morphs
  14126. this.maxMorphTargets = 8;
  14127. this.maxMorphNormals = 4; // internal properties
  14128. var _this = this;
  14129. var _isContextLost = false; // internal state cache
  14130. var _framebuffer = null;
  14131. var _currentActiveCubeFace = 0;
  14132. var _currentActiveMipmapLevel = 0;
  14133. var _currentRenderTarget = null;
  14134. var _currentFramebuffer = null;
  14135. var _currentMaterialId = -1;
  14136. var _currentCamera = null;
  14137. var _currentArrayCamera = null;
  14138. var _currentViewport = new Vector4();
  14139. var _currentScissor = new Vector4();
  14140. var _currentScissorTest = null; //
  14141. var _width = _canvas.width;
  14142. var _height = _canvas.height;
  14143. var _pixelRatio = 1;
  14144. var _opaqueSort = null;
  14145. var _transparentSort = null;
  14146. var _viewport = new Vector4(0, 0, _width, _height);
  14147. var _scissor = new Vector4(0, 0, _width, _height);
  14148. var _scissorTest = false; // frustum
  14149. var _frustum = new Frustum(); // clipping
  14150. var _clippingEnabled = false;
  14151. var _localClippingEnabled = false; // camera matrices cache
  14152. var _projScreenMatrix = new Matrix4();
  14153. var _vector3 = new Vector3();
  14154. var _emptyScene = {
  14155. background: null,
  14156. fog: null,
  14157. environment: null,
  14158. overrideMaterial: null,
  14159. isScene: true
  14160. };
  14161. function getTargetPixelRatio() {
  14162. return _currentRenderTarget === null ? _pixelRatio : 1;
  14163. } // initialize
  14164. var _gl = _context;
  14165. function getContext(contextNames, contextAttributes) {
  14166. for (var i = 0; i < contextNames.length; i++) {
  14167. var contextName = contextNames[i];
  14168. var context = _canvas.getContext(contextName, contextAttributes);
  14169. if (context !== null) return context;
  14170. }
  14171. return null;
  14172. }
  14173. try {
  14174. var contextAttributes = {
  14175. alpha: _alpha,
  14176. depth: _depth,
  14177. stencil: _stencil,
  14178. antialias: _antialias,
  14179. premultipliedAlpha: _premultipliedAlpha,
  14180. preserveDrawingBuffer: _preserveDrawingBuffer,
  14181. powerPreference: _powerPreference,
  14182. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14183. }; // event listeners must be registered before WebGL context is created, see #12753
  14184. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  14185. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  14186. if (_gl === null) {
  14187. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  14188. if (_this.isWebGL1Renderer === true) {
  14189. contextNames.shift();
  14190. }
  14191. _gl = getContext(contextNames, contextAttributes);
  14192. if (_gl === null) {
  14193. if (getContext(contextNames)) {
  14194. throw new Error('Error creating WebGL context with your selected attributes.');
  14195. } else {
  14196. throw new Error('Error creating WebGL context.');
  14197. }
  14198. }
  14199. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14200. if (_gl.getShaderPrecisionFormat === undefined) {
  14201. _gl.getShaderPrecisionFormat = function () {
  14202. return {
  14203. 'rangeMin': 1,
  14204. 'rangeMax': 1,
  14205. 'precision': 1
  14206. };
  14207. };
  14208. }
  14209. } catch (error) {
  14210. console.error('THREE.WebGLRenderer: ' + error.message);
  14211. throw error;
  14212. }
  14213. var extensions, capabilities, state, info;
  14214. var properties, textures, cubemaps, attributes, geometries, objects;
  14215. var programCache, materials, renderLists, renderStates, clipping;
  14216. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14217. var utils, bindingStates;
  14218. function initGLContext() {
  14219. extensions = new WebGLExtensions(_gl);
  14220. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  14221. if (capabilities.isWebGL2 === false) {
  14222. extensions.get('WEBGL_depth_texture');
  14223. extensions.get('OES_texture_float');
  14224. extensions.get('OES_texture_half_float');
  14225. extensions.get('OES_texture_half_float_linear');
  14226. extensions.get('OES_standard_derivatives');
  14227. extensions.get('OES_element_index_uint');
  14228. extensions.get('OES_vertex_array_object');
  14229. extensions.get('ANGLE_instanced_arrays');
  14230. }
  14231. extensions.get('OES_texture_float_linear');
  14232. utils = new WebGLUtils(_gl, extensions, capabilities);
  14233. state = new WebGLState(_gl, extensions, capabilities);
  14234. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14235. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14236. info = new WebGLInfo(_gl);
  14237. properties = new WebGLProperties();
  14238. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  14239. cubemaps = new WebGLCubeMaps(_this);
  14240. attributes = new WebGLAttributes(_gl, capabilities);
  14241. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  14242. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  14243. objects = new WebGLObjects(_gl, geometries, attributes, info);
  14244. morphtargets = new WebGLMorphtargets(_gl);
  14245. clipping = new WebGLClipping(properties);
  14246. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  14247. materials = new WebGLMaterials(properties);
  14248. renderLists = new WebGLRenderLists(properties);
  14249. renderStates = new WebGLRenderStates();
  14250. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  14251. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  14252. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  14253. info.programs = programCache.programs;
  14254. _this.capabilities = capabilities;
  14255. _this.extensions = extensions;
  14256. _this.properties = properties;
  14257. _this.renderLists = renderLists;
  14258. _this.state = state;
  14259. _this.info = info;
  14260. }
  14261. initGLContext(); // xr
  14262. var xr = new WebXRManager(_this, _gl);
  14263. this.xr = xr; // shadow map
  14264. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  14265. this.shadowMap = shadowMap; // API
  14266. this.getContext = function () {
  14267. return _gl;
  14268. };
  14269. this.getContextAttributes = function () {
  14270. return _gl.getContextAttributes();
  14271. };
  14272. this.forceContextLoss = function () {
  14273. var extension = extensions.get('WEBGL_lose_context');
  14274. if (extension) extension.loseContext();
  14275. };
  14276. this.forceContextRestore = function () {
  14277. var extension = extensions.get('WEBGL_lose_context');
  14278. if (extension) extension.restoreContext();
  14279. };
  14280. this.getPixelRatio = function () {
  14281. return _pixelRatio;
  14282. };
  14283. this.setPixelRatio = function (value) {
  14284. if (value === undefined) return;
  14285. _pixelRatio = value;
  14286. this.setSize(_width, _height, false);
  14287. };
  14288. this.getSize = function (target) {
  14289. if (target === undefined) {
  14290. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  14291. target = new Vector2();
  14292. }
  14293. return target.set(_width, _height);
  14294. };
  14295. this.setSize = function (width, height, updateStyle) {
  14296. if (xr.isPresenting) {
  14297. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  14298. return;
  14299. }
  14300. _width = width;
  14301. _height = height;
  14302. _canvas.width = Math.floor(width * _pixelRatio);
  14303. _canvas.height = Math.floor(height * _pixelRatio);
  14304. if (updateStyle !== false) {
  14305. _canvas.style.width = width + 'px';
  14306. _canvas.style.height = height + 'px';
  14307. }
  14308. this.setViewport(0, 0, width, height);
  14309. };
  14310. this.getDrawingBufferSize = function (target) {
  14311. if (target === undefined) {
  14312. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  14313. target = new Vector2();
  14314. }
  14315. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  14316. };
  14317. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  14318. _width = width;
  14319. _height = height;
  14320. _pixelRatio = pixelRatio;
  14321. _canvas.width = Math.floor(width * pixelRatio);
  14322. _canvas.height = Math.floor(height * pixelRatio);
  14323. this.setViewport(0, 0, width, height);
  14324. };
  14325. this.getCurrentViewport = function (target) {
  14326. if (target === undefined) {
  14327. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  14328. target = new Vector4();
  14329. }
  14330. return target.copy(_currentViewport);
  14331. };
  14332. this.getViewport = function (target) {
  14333. return target.copy(_viewport);
  14334. };
  14335. this.setViewport = function (x, y, width, height) {
  14336. if (x.isVector4) {
  14337. _viewport.set(x.x, x.y, x.z, x.w);
  14338. } else {
  14339. _viewport.set(x, y, width, height);
  14340. }
  14341. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14342. };
  14343. this.getScissor = function (target) {
  14344. return target.copy(_scissor);
  14345. };
  14346. this.setScissor = function (x, y, width, height) {
  14347. if (x.isVector4) {
  14348. _scissor.set(x.x, x.y, x.z, x.w);
  14349. } else {
  14350. _scissor.set(x, y, width, height);
  14351. }
  14352. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14353. };
  14354. this.getScissorTest = function () {
  14355. return _scissorTest;
  14356. };
  14357. this.setScissorTest = function (boolean) {
  14358. state.setScissorTest(_scissorTest = boolean);
  14359. };
  14360. this.setOpaqueSort = function (method) {
  14361. _opaqueSort = method;
  14362. };
  14363. this.setTransparentSort = function (method) {
  14364. _transparentSort = method;
  14365. }; // Clearing
  14366. this.getClearColor = function () {
  14367. return background.getClearColor();
  14368. };
  14369. this.setClearColor = function () {
  14370. background.setClearColor.apply(background, arguments);
  14371. };
  14372. this.getClearAlpha = function () {
  14373. return background.getClearAlpha();
  14374. };
  14375. this.setClearAlpha = function () {
  14376. background.setClearAlpha.apply(background, arguments);
  14377. };
  14378. this.clear = function (color, depth, stencil) {
  14379. var bits = 0;
  14380. if (color === undefined || color) bits |= 16384;
  14381. if (depth === undefined || depth) bits |= 256;
  14382. if (stencil === undefined || stencil) bits |= 1024;
  14383. _gl.clear(bits);
  14384. };
  14385. this.clearColor = function () {
  14386. this.clear(true, false, false);
  14387. };
  14388. this.clearDepth = function () {
  14389. this.clear(false, true, false);
  14390. };
  14391. this.clearStencil = function () {
  14392. this.clear(false, false, true);
  14393. }; //
  14394. this.dispose = function () {
  14395. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  14396. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  14397. renderLists.dispose();
  14398. renderStates.dispose();
  14399. properties.dispose();
  14400. cubemaps.dispose();
  14401. objects.dispose();
  14402. bindingStates.dispose();
  14403. xr.dispose();
  14404. animation.stop();
  14405. }; // Events
  14406. function onContextLost(event) {
  14407. event.preventDefault();
  14408. console.log('THREE.WebGLRenderer: Context Lost.');
  14409. _isContextLost = true;
  14410. }
  14411. function onContextRestore()
  14412. /* event */
  14413. {
  14414. console.log('THREE.WebGLRenderer: Context Restored.');
  14415. _isContextLost = false;
  14416. initGLContext();
  14417. }
  14418. function onMaterialDispose(event) {
  14419. var material = event.target;
  14420. material.removeEventListener('dispose', onMaterialDispose);
  14421. deallocateMaterial(material);
  14422. } // Buffer deallocation
  14423. function deallocateMaterial(material) {
  14424. releaseMaterialProgramReference(material);
  14425. properties.remove(material);
  14426. }
  14427. function releaseMaterialProgramReference(material) {
  14428. var programInfo = properties.get(material).program;
  14429. if (programInfo !== undefined) {
  14430. programCache.releaseProgram(programInfo);
  14431. }
  14432. } // Buffer rendering
  14433. function renderObjectImmediate(object, program) {
  14434. object.render(function (object) {
  14435. _this.renderBufferImmediate(object, program);
  14436. });
  14437. }
  14438. this.renderBufferImmediate = function (object, program) {
  14439. bindingStates.initAttributes();
  14440. var buffers = properties.get(object);
  14441. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  14442. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  14443. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  14444. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  14445. var programAttributes = program.getAttributes();
  14446. if (object.hasPositions) {
  14447. _gl.bindBuffer(34962, buffers.position);
  14448. _gl.bufferData(34962, object.positionArray, 35048);
  14449. bindingStates.enableAttribute(programAttributes.position);
  14450. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  14451. }
  14452. if (object.hasNormals) {
  14453. _gl.bindBuffer(34962, buffers.normal);
  14454. _gl.bufferData(34962, object.normalArray, 35048);
  14455. bindingStates.enableAttribute(programAttributes.normal);
  14456. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  14457. }
  14458. if (object.hasUvs) {
  14459. _gl.bindBuffer(34962, buffers.uv);
  14460. _gl.bufferData(34962, object.uvArray, 35048);
  14461. bindingStates.enableAttribute(programAttributes.uv);
  14462. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  14463. }
  14464. if (object.hasColors) {
  14465. _gl.bindBuffer(34962, buffers.color);
  14466. _gl.bufferData(34962, object.colorArray, 35048);
  14467. bindingStates.enableAttribute(programAttributes.color);
  14468. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  14469. }
  14470. bindingStates.disableUnusedAttributes();
  14471. _gl.drawArrays(4, 0, object.count);
  14472. object.count = 0;
  14473. };
  14474. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  14475. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  14476. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  14477. var program = setProgram(camera, scene, material, object);
  14478. state.setMaterial(material, frontFaceCW); //
  14479. var index = geometry.index;
  14480. var position = geometry.attributes.position; //
  14481. if (index === null) {
  14482. if (position === undefined || position.count === 0) return;
  14483. } else if (index.count === 0) {
  14484. return;
  14485. } //
  14486. var rangeFactor = 1;
  14487. if (material.wireframe === true) {
  14488. index = geometries.getWireframeAttribute(geometry);
  14489. rangeFactor = 2;
  14490. }
  14491. if (material.morphTargets || material.morphNormals) {
  14492. morphtargets.update(object, geometry, material, program);
  14493. }
  14494. bindingStates.setup(object, material, program, geometry, index);
  14495. var attribute;
  14496. var renderer = bufferRenderer;
  14497. if (index !== null) {
  14498. attribute = attributes.get(index);
  14499. renderer = indexedBufferRenderer;
  14500. renderer.setIndex(attribute);
  14501. } //
  14502. var dataCount = index !== null ? index.count : position.count;
  14503. var rangeStart = geometry.drawRange.start * rangeFactor;
  14504. var rangeCount = geometry.drawRange.count * rangeFactor;
  14505. var groupStart = group !== null ? group.start * rangeFactor : 0;
  14506. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14507. var drawStart = Math.max(rangeStart, groupStart);
  14508. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  14509. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  14510. if (drawCount === 0) return; //
  14511. if (object.isMesh) {
  14512. if (material.wireframe === true) {
  14513. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  14514. renderer.setMode(1);
  14515. } else {
  14516. renderer.setMode(4);
  14517. }
  14518. } else if (object.isLine) {
  14519. var lineWidth = material.linewidth;
  14520. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  14521. state.setLineWidth(lineWidth * getTargetPixelRatio());
  14522. if (object.isLineSegments) {
  14523. renderer.setMode(1);
  14524. } else if (object.isLineLoop) {
  14525. renderer.setMode(2);
  14526. } else {
  14527. renderer.setMode(3);
  14528. }
  14529. } else if (object.isPoints) {
  14530. renderer.setMode(0);
  14531. } else if (object.isSprite) {
  14532. renderer.setMode(4);
  14533. }
  14534. if (object.isInstancedMesh) {
  14535. renderer.renderInstances(drawStart, drawCount, object.count);
  14536. } else if (geometry.isInstancedBufferGeometry) {
  14537. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  14538. renderer.renderInstances(drawStart, drawCount, instanceCount);
  14539. } else {
  14540. renderer.render(drawStart, drawCount);
  14541. }
  14542. }; // Compile
  14543. this.compile = function (scene, camera) {
  14544. currentRenderState = renderStates.get(scene, camera);
  14545. currentRenderState.init();
  14546. scene.traverseVisible(function (object) {
  14547. if (object.isLight && object.layers.test(camera.layers)) {
  14548. currentRenderState.pushLight(object);
  14549. if (object.castShadow) {
  14550. currentRenderState.pushShadow(object);
  14551. }
  14552. }
  14553. });
  14554. currentRenderState.setupLights(camera);
  14555. var compiled = new WeakMap();
  14556. scene.traverse(function (object) {
  14557. var material = object.material;
  14558. if (material) {
  14559. if (Array.isArray(material)) {
  14560. for (var i = 0; i < material.length; i++) {
  14561. var material2 = material[i];
  14562. if (compiled.has(material2) === false) {
  14563. initMaterial(material2, scene, object);
  14564. compiled.set(material2);
  14565. }
  14566. }
  14567. } else if (compiled.has(material) === false) {
  14568. initMaterial(material, scene, object);
  14569. compiled.set(material);
  14570. }
  14571. }
  14572. });
  14573. }; // Animation Loop
  14574. var onAnimationFrameCallback = null;
  14575. function onAnimationFrame(time) {
  14576. if (xr.isPresenting) return;
  14577. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  14578. }
  14579. var animation = new WebGLAnimation();
  14580. animation.setAnimationLoop(onAnimationFrame);
  14581. if (typeof window !== 'undefined') animation.setContext(window);
  14582. this.setAnimationLoop = function (callback) {
  14583. onAnimationFrameCallback = callback;
  14584. xr.setAnimationLoop(callback);
  14585. callback === null ? animation.stop() : animation.start();
  14586. }; // Rendering
  14587. this.render = function (scene, camera) {
  14588. var renderTarget, forceClear;
  14589. if (arguments[2] !== undefined) {
  14590. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  14591. renderTarget = arguments[2];
  14592. }
  14593. if (arguments[3] !== undefined) {
  14594. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  14595. forceClear = arguments[3];
  14596. }
  14597. if (camera !== undefined && camera.isCamera !== true) {
  14598. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  14599. return;
  14600. }
  14601. if (_isContextLost === true) return; // reset caching for this frame
  14602. bindingStates.resetDefaultState();
  14603. _currentMaterialId = -1;
  14604. _currentCamera = null; // update scene graph
  14605. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  14606. if (camera.parent === null) camera.updateMatrixWorld();
  14607. if (xr.enabled === true && xr.isPresenting === true) {
  14608. camera = xr.getCamera(camera);
  14609. } //
  14610. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  14611. currentRenderState = renderStates.get(scene, camera);
  14612. currentRenderState.init();
  14613. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  14614. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  14615. _localClippingEnabled = this.localClippingEnabled;
  14616. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  14617. currentRenderList = renderLists.get(scene, camera);
  14618. currentRenderList.init();
  14619. projectObject(scene, camera, 0, _this.sortObjects);
  14620. currentRenderList.finish();
  14621. if (_this.sortObjects === true) {
  14622. currentRenderList.sort(_opaqueSort, _transparentSort);
  14623. } //
  14624. if (_clippingEnabled === true) clipping.beginShadows();
  14625. var shadowsArray = currentRenderState.state.shadowsArray;
  14626. shadowMap.render(shadowsArray, scene, camera);
  14627. currentRenderState.setupLights(camera);
  14628. if (_clippingEnabled === true) clipping.endShadows(); //
  14629. if (this.info.autoReset === true) this.info.reset();
  14630. if (renderTarget !== undefined) {
  14631. this.setRenderTarget(renderTarget);
  14632. } //
  14633. background.render(currentRenderList, scene, camera, forceClear); // render scene
  14634. var opaqueObjects = currentRenderList.opaque;
  14635. var transparentObjects = currentRenderList.transparent;
  14636. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  14637. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  14638. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  14639. if (_currentRenderTarget !== null) {
  14640. // Generate mipmap if we're using any kind of mipmap filtering
  14641. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  14642. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  14643. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  14644. state.buffers.depth.setTest(true);
  14645. state.buffers.depth.setMask(true);
  14646. state.buffers.color.setMask(true);
  14647. state.setPolygonOffset(false); // _gl.finish();
  14648. currentRenderList = null;
  14649. currentRenderState = null;
  14650. };
  14651. function projectObject(object, camera, groupOrder, sortObjects) {
  14652. if (object.visible === false) return;
  14653. var visible = object.layers.test(camera.layers);
  14654. if (visible) {
  14655. if (object.isGroup) {
  14656. groupOrder = object.renderOrder;
  14657. } else if (object.isLOD) {
  14658. if (object.autoUpdate === true) object.update(camera);
  14659. } else if (object.isLight) {
  14660. currentRenderState.pushLight(object);
  14661. if (object.castShadow) {
  14662. currentRenderState.pushShadow(object);
  14663. }
  14664. } else if (object.isSprite) {
  14665. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  14666. if (sortObjects) {
  14667. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14668. }
  14669. var geometry = objects.update(object);
  14670. var material = object.material;
  14671. if (material.visible) {
  14672. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  14673. }
  14674. }
  14675. } else if (object.isImmediateRenderObject) {
  14676. if (sortObjects) {
  14677. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14678. }
  14679. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  14680. } else if (object.isMesh || object.isLine || object.isPoints) {
  14681. if (object.isSkinnedMesh) {
  14682. // update skeleton only once in a frame
  14683. if (object.skeleton.frame !== info.render.frame) {
  14684. object.skeleton.update();
  14685. object.skeleton.frame = info.render.frame;
  14686. }
  14687. }
  14688. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  14689. if (sortObjects) {
  14690. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14691. }
  14692. var _geometry = objects.update(object);
  14693. var _material = object.material;
  14694. if (Array.isArray(_material)) {
  14695. var groups = _geometry.groups;
  14696. for (var i = 0, l = groups.length; i < l; i++) {
  14697. var group = groups[i];
  14698. var groupMaterial = _material[group.materialIndex];
  14699. if (groupMaterial && groupMaterial.visible) {
  14700. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  14701. }
  14702. }
  14703. } else if (_material.visible) {
  14704. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  14705. }
  14706. }
  14707. }
  14708. }
  14709. var children = object.children;
  14710. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  14711. projectObject(children[_i], camera, groupOrder, sortObjects);
  14712. }
  14713. }
  14714. function renderObjects(renderList, scene, camera) {
  14715. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  14716. for (var i = 0, l = renderList.length; i < l; i++) {
  14717. var renderItem = renderList[i];
  14718. var object = renderItem.object;
  14719. var geometry = renderItem.geometry;
  14720. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  14721. var group = renderItem.group;
  14722. if (camera.isArrayCamera) {
  14723. _currentArrayCamera = camera;
  14724. var cameras = camera.cameras;
  14725. for (var j = 0, jl = cameras.length; j < jl; j++) {
  14726. var camera2 = cameras[j];
  14727. if (object.layers.test(camera2.layers)) {
  14728. state.viewport(_currentViewport.copy(camera2.viewport));
  14729. currentRenderState.setupLights(camera2);
  14730. renderObject(object, scene, camera2, geometry, material, group);
  14731. }
  14732. }
  14733. } else {
  14734. _currentArrayCamera = null;
  14735. renderObject(object, scene, camera, geometry, material, group);
  14736. }
  14737. }
  14738. }
  14739. function renderObject(object, scene, camera, geometry, material, group) {
  14740. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  14741. currentRenderState = renderStates.get(scene, _currentArrayCamera || camera);
  14742. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  14743. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  14744. if (object.isImmediateRenderObject) {
  14745. var program = setProgram(camera, scene, material, object);
  14746. state.setMaterial(material);
  14747. bindingStates.reset();
  14748. renderObjectImmediate(object, program);
  14749. } else {
  14750. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  14751. }
  14752. object.onAfterRender(_this, scene, camera, geometry, material, group);
  14753. currentRenderState = renderStates.get(scene, _currentArrayCamera || camera);
  14754. }
  14755. function initMaterial(material, scene, object) {
  14756. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14757. var materialProperties = properties.get(material);
  14758. var lights = currentRenderState.state.lights;
  14759. var shadowsArray = currentRenderState.state.shadowsArray;
  14760. var lightsStateVersion = lights.state.version;
  14761. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  14762. var programCacheKey = programCache.getProgramCacheKey(parameters);
  14763. var program = materialProperties.program;
  14764. var programChange = true;
  14765. if (program === undefined) {
  14766. // new material
  14767. material.addEventListener('dispose', onMaterialDispose);
  14768. } else if (program.cacheKey !== programCacheKey) {
  14769. // changed glsl or parameters
  14770. releaseMaterialProgramReference(material);
  14771. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  14772. programChange = false;
  14773. } else if (parameters.shaderID !== undefined) {
  14774. // same glsl and uniform list, envMap still needs the update here to avoid a frame-late effect
  14775. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  14776. materialProperties.envMap = cubemaps.get(material.envMap || environment);
  14777. return;
  14778. } else {
  14779. // only rebuild uniform list
  14780. programChange = false;
  14781. }
  14782. if (programChange) {
  14783. parameters.uniforms = programCache.getUniforms(material);
  14784. material.onBeforeCompile(parameters, _this);
  14785. program = programCache.acquireProgram(parameters, programCacheKey);
  14786. materialProperties.program = program;
  14787. materialProperties.uniforms = parameters.uniforms;
  14788. materialProperties.outputEncoding = parameters.outputEncoding;
  14789. }
  14790. var uniforms = materialProperties.uniforms;
  14791. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  14792. materialProperties.numClippingPlanes = clipping.numPlanes;
  14793. materialProperties.numIntersection = clipping.numIntersection;
  14794. uniforms.clippingPlanes = clipping.uniform;
  14795. }
  14796. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  14797. materialProperties.fog = scene.fog;
  14798. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment); // store the light setup it was created for
  14799. materialProperties.needsLights = materialNeedsLights(material);
  14800. materialProperties.lightsStateVersion = lightsStateVersion;
  14801. if (materialProperties.needsLights) {
  14802. // wire up the material to this renderer's lighting state
  14803. uniforms.ambientLightColor.value = lights.state.ambient;
  14804. uniforms.lightProbe.value = lights.state.probe;
  14805. uniforms.directionalLights.value = lights.state.directional;
  14806. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  14807. uniforms.spotLights.value = lights.state.spot;
  14808. uniforms.spotLightShadows.value = lights.state.spotShadow;
  14809. uniforms.rectAreaLights.value = lights.state.rectArea;
  14810. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  14811. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  14812. uniforms.pointLights.value = lights.state.point;
  14813. uniforms.pointLightShadows.value = lights.state.pointShadow;
  14814. uniforms.hemisphereLights.value = lights.state.hemi;
  14815. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14816. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14817. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14818. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14819. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14820. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  14821. }
  14822. var progUniforms = materialProperties.program.getUniforms();
  14823. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  14824. materialProperties.uniformsList = uniformsList;
  14825. }
  14826. function setProgram(camera, scene, material, object) {
  14827. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14828. textures.resetTextureUnits();
  14829. var fog = scene.fog;
  14830. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  14831. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  14832. var envMap = cubemaps.get(material.envMap || environment);
  14833. var materialProperties = properties.get(material);
  14834. var lights = currentRenderState.state.lights;
  14835. if (_clippingEnabled === true) {
  14836. if (_localClippingEnabled === true || camera !== _currentCamera) {
  14837. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  14838. // object instead of the material, once it becomes feasible
  14839. // (#8465, #8379)
  14840. clipping.setState(material, camera, useCache);
  14841. }
  14842. }
  14843. if (material.version === materialProperties.__version) {
  14844. if (material.fog && materialProperties.fog !== fog) {
  14845. initMaterial(material, scene, object);
  14846. } else if (materialProperties.environment !== environment) {
  14847. initMaterial(material, scene, object);
  14848. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  14849. initMaterial(material, scene, object);
  14850. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  14851. initMaterial(material, scene, object);
  14852. } else if (materialProperties.outputEncoding !== encoding) {
  14853. initMaterial(material, scene, object);
  14854. } else if (materialProperties.envMap !== envMap) {
  14855. initMaterial(material, scene, object);
  14856. }
  14857. } else {
  14858. initMaterial(material, scene, object);
  14859. materialProperties.__version = material.version;
  14860. }
  14861. var refreshProgram = false;
  14862. var refreshMaterial = false;
  14863. var refreshLights = false;
  14864. var program = materialProperties.program,
  14865. p_uniforms = program.getUniforms(),
  14866. m_uniforms = materialProperties.uniforms;
  14867. if (state.useProgram(program.program)) {
  14868. refreshProgram = true;
  14869. refreshMaterial = true;
  14870. refreshLights = true;
  14871. }
  14872. if (material.id !== _currentMaterialId) {
  14873. _currentMaterialId = material.id;
  14874. refreshMaterial = true;
  14875. }
  14876. if (refreshProgram || _currentCamera !== camera) {
  14877. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  14878. if (capabilities.logarithmicDepthBuffer) {
  14879. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  14880. }
  14881. if (_currentCamera !== camera) {
  14882. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  14883. // now, in case this material supports lights - or later, when
  14884. // the next material that does gets activated:
  14885. refreshMaterial = true; // set to true on material change
  14886. refreshLights = true; // remains set until update done
  14887. } // load material specific uniforms
  14888. // (shader material also gets them for the sake of genericity)
  14889. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  14890. var uCamPos = p_uniforms.map.cameraPosition;
  14891. if (uCamPos !== undefined) {
  14892. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  14893. }
  14894. }
  14895. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  14896. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  14897. }
  14898. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  14899. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  14900. }
  14901. } // skinning uniforms must be set even if material didn't change
  14902. // auto-setting of texture unit for bone texture must go before other textures
  14903. // otherwise textures used for skinning can take over texture units reserved for other material textures
  14904. if (material.skinning) {
  14905. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  14906. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  14907. var skeleton = object.skeleton;
  14908. if (skeleton) {
  14909. var bones = skeleton.bones;
  14910. if (capabilities.floatVertexTextures) {
  14911. if (skeleton.boneTexture === undefined) {
  14912. // layout (1 matrix = 4 pixels)
  14913. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14914. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14915. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14916. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14917. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14918. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  14919. size = MathUtils.ceilPowerOfTwo(size);
  14920. size = Math.max(size, 4);
  14921. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  14922. boneMatrices.set(skeleton.boneMatrices); // copy current values
  14923. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  14924. skeleton.boneMatrices = boneMatrices;
  14925. skeleton.boneTexture = boneTexture;
  14926. skeleton.boneTextureSize = size;
  14927. }
  14928. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  14929. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  14930. } else {
  14931. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  14932. }
  14933. }
  14934. }
  14935. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  14936. materialProperties.receiveShadow = object.receiveShadow;
  14937. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  14938. }
  14939. if (refreshMaterial) {
  14940. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  14941. if (materialProperties.needsLights) {
  14942. // the current material requires lighting info
  14943. // note: all lighting uniforms are always set correctly
  14944. // they simply reference the renderer's state for their
  14945. // values
  14946. //
  14947. // use the current material's .needsUpdate flags to set
  14948. // the GL state when required
  14949. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  14950. } // refresh uniforms common to several materials
  14951. if (fog && material.fog) {
  14952. materials.refreshFogUniforms(m_uniforms, fog);
  14953. }
  14954. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  14955. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  14956. }
  14957. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  14958. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  14959. material.uniformsNeedUpdate = false;
  14960. }
  14961. if (material.isSpriteMaterial) {
  14962. p_uniforms.setValue(_gl, 'center', object.center);
  14963. } // common matrices
  14964. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  14965. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  14966. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  14967. return program;
  14968. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  14969. function markUniformsLightsNeedsUpdate(uniforms, value) {
  14970. uniforms.ambientLightColor.needsUpdate = value;
  14971. uniforms.lightProbe.needsUpdate = value;
  14972. uniforms.directionalLights.needsUpdate = value;
  14973. uniforms.directionalLightShadows.needsUpdate = value;
  14974. uniforms.pointLights.needsUpdate = value;
  14975. uniforms.pointLightShadows.needsUpdate = value;
  14976. uniforms.spotLights.needsUpdate = value;
  14977. uniforms.spotLightShadows.needsUpdate = value;
  14978. uniforms.rectAreaLights.needsUpdate = value;
  14979. uniforms.hemisphereLights.needsUpdate = value;
  14980. }
  14981. function materialNeedsLights(material) {
  14982. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  14983. } //
  14984. this.setFramebuffer = function (value) {
  14985. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  14986. _framebuffer = value;
  14987. };
  14988. this.getActiveCubeFace = function () {
  14989. return _currentActiveCubeFace;
  14990. };
  14991. this.getActiveMipmapLevel = function () {
  14992. return _currentActiveMipmapLevel;
  14993. };
  14994. this.getRenderList = function () {
  14995. return currentRenderList;
  14996. };
  14997. this.setRenderList = function (renderList) {
  14998. currentRenderList = renderList;
  14999. };
  15000. this.getRenderState = function () {
  15001. return currentRenderState;
  15002. };
  15003. this.setRenderState = function (renderState) {
  15004. currentRenderState = renderState;
  15005. };
  15006. this.getRenderTarget = function () {
  15007. return _currentRenderTarget;
  15008. };
  15009. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15010. if (activeCubeFace === void 0) {
  15011. activeCubeFace = 0;
  15012. }
  15013. if (activeMipmapLevel === void 0) {
  15014. activeMipmapLevel = 0;
  15015. }
  15016. _currentRenderTarget = renderTarget;
  15017. _currentActiveCubeFace = activeCubeFace;
  15018. _currentActiveMipmapLevel = activeMipmapLevel;
  15019. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15020. textures.setupRenderTarget(renderTarget);
  15021. }
  15022. var framebuffer = _framebuffer;
  15023. var isCube = false;
  15024. if (renderTarget) {
  15025. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15026. if (renderTarget.isWebGLCubeRenderTarget) {
  15027. framebuffer = __webglFramebuffer[activeCubeFace];
  15028. isCube = true;
  15029. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15030. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15031. } else {
  15032. framebuffer = __webglFramebuffer;
  15033. }
  15034. _currentViewport.copy(renderTarget.viewport);
  15035. _currentScissor.copy(renderTarget.scissor);
  15036. _currentScissorTest = renderTarget.scissorTest;
  15037. } else {
  15038. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15039. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15040. _currentScissorTest = _scissorTest;
  15041. }
  15042. if (_currentFramebuffer !== framebuffer) {
  15043. _gl.bindFramebuffer(36160, framebuffer);
  15044. _currentFramebuffer = framebuffer;
  15045. }
  15046. state.viewport(_currentViewport);
  15047. state.scissor(_currentScissor);
  15048. state.setScissorTest(_currentScissorTest);
  15049. if (isCube) {
  15050. var textureProperties = properties.get(renderTarget.texture);
  15051. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15052. }
  15053. };
  15054. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15055. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15056. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15057. return;
  15058. }
  15059. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15060. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15061. framebuffer = framebuffer[activeCubeFaceIndex];
  15062. }
  15063. if (framebuffer) {
  15064. var restore = false;
  15065. if (framebuffer !== _currentFramebuffer) {
  15066. _gl.bindFramebuffer(36160, framebuffer);
  15067. restore = true;
  15068. }
  15069. try {
  15070. var texture = renderTarget.texture;
  15071. var textureFormat = texture.format;
  15072. var textureType = texture.type;
  15073. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15074. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15075. return;
  15076. }
  15077. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15078. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.get('OES_texture_float') || extensions.get('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15079. !(textureType === HalfFloatType && (capabilities.isWebGL2 ? extensions.get('EXT_color_buffer_float') : extensions.get('EXT_color_buffer_half_float')))) {
  15080. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15081. return;
  15082. }
  15083. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15084. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15085. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15086. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15087. }
  15088. } else {
  15089. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15090. }
  15091. } finally {
  15092. if (restore) {
  15093. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15094. }
  15095. }
  15096. }
  15097. };
  15098. this.copyFramebufferToTexture = function (position, texture, level) {
  15099. if (level === undefined) level = 0;
  15100. var levelScale = Math.pow(2, -level);
  15101. var width = Math.floor(texture.image.width * levelScale);
  15102. var height = Math.floor(texture.image.height * levelScale);
  15103. var glFormat = utils.convert(texture.format);
  15104. textures.setTexture2D(texture, 0);
  15105. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15106. state.unbindTexture();
  15107. };
  15108. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15109. if (level === undefined) level = 0;
  15110. var width = srcTexture.image.width;
  15111. var height = srcTexture.image.height;
  15112. var glFormat = utils.convert(dstTexture.format);
  15113. var glType = utils.convert(dstTexture.type);
  15114. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15115. // parameters, make sure they are correct for the dstTexture
  15116. _gl.pixelStorei(37440, dstTexture.flipY);
  15117. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15118. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15119. if (srcTexture.isDataTexture) {
  15120. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15121. } else {
  15122. if (srcTexture.isCompressedTexture) {
  15123. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15124. } else {
  15125. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15126. }
  15127. } // Generate mipmaps only when copying level 0
  15128. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15129. state.unbindTexture();
  15130. };
  15131. this.initTexture = function (texture) {
  15132. textures.setTexture2D(texture, 0);
  15133. state.unbindTexture();
  15134. };
  15135. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15136. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15137. detail: this
  15138. })); // eslint-disable-line no-undef
  15139. }
  15140. }
  15141. function WebGL1Renderer(parameters) {
  15142. WebGLRenderer.call(this, parameters);
  15143. }
  15144. WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
  15145. constructor: WebGL1Renderer,
  15146. isWebGL1Renderer: true
  15147. });
  15148. var FogExp2 = /*#__PURE__*/function () {
  15149. function FogExp2(color, density) {
  15150. Object.defineProperty(this, 'isFogExp2', {
  15151. value: true
  15152. });
  15153. this.name = '';
  15154. this.color = new Color(color);
  15155. this.density = density !== undefined ? density : 0.00025;
  15156. }
  15157. var _proto = FogExp2.prototype;
  15158. _proto.clone = function clone() {
  15159. return new FogExp2(this.color, this.density);
  15160. };
  15161. _proto.toJSON = function toJSON()
  15162. /* meta */
  15163. {
  15164. return {
  15165. type: 'FogExp2',
  15166. color: this.color.getHex(),
  15167. density: this.density
  15168. };
  15169. };
  15170. return FogExp2;
  15171. }();
  15172. var Fog = /*#__PURE__*/function () {
  15173. function Fog(color, near, far) {
  15174. Object.defineProperty(this, 'isFog', {
  15175. value: true
  15176. });
  15177. this.name = '';
  15178. this.color = new Color(color);
  15179. this.near = near !== undefined ? near : 1;
  15180. this.far = far !== undefined ? far : 1000;
  15181. }
  15182. var _proto = Fog.prototype;
  15183. _proto.clone = function clone() {
  15184. return new Fog(this.color, this.near, this.far);
  15185. };
  15186. _proto.toJSON = function toJSON()
  15187. /* meta */
  15188. {
  15189. return {
  15190. type: 'Fog',
  15191. color: this.color.getHex(),
  15192. near: this.near,
  15193. far: this.far
  15194. };
  15195. };
  15196. return Fog;
  15197. }();
  15198. var Scene = /*#__PURE__*/function (_Object3D) {
  15199. _inheritsLoose(Scene, _Object3D);
  15200. function Scene() {
  15201. var _this;
  15202. _this = _Object3D.call(this) || this;
  15203. Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
  15204. value: true
  15205. });
  15206. _this.type = 'Scene';
  15207. _this.background = null;
  15208. _this.environment = null;
  15209. _this.fog = null;
  15210. _this.overrideMaterial = null;
  15211. _this.autoUpdate = true; // checked by the renderer
  15212. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15213. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15214. detail: _assertThisInitialized(_this)
  15215. })); // eslint-disable-line no-undef
  15216. }
  15217. return _this;
  15218. }
  15219. var _proto = Scene.prototype;
  15220. _proto.copy = function copy(source, recursive) {
  15221. _Object3D.prototype.copy.call(this, source, recursive);
  15222. if (source.background !== null) this.background = source.background.clone();
  15223. if (source.environment !== null) this.environment = source.environment.clone();
  15224. if (source.fog !== null) this.fog = source.fog.clone();
  15225. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  15226. this.autoUpdate = source.autoUpdate;
  15227. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15228. return this;
  15229. };
  15230. _proto.toJSON = function toJSON(meta) {
  15231. var data = _Object3D.prototype.toJSON.call(this, meta);
  15232. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  15233. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  15234. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  15235. return data;
  15236. };
  15237. return Scene;
  15238. }(Object3D);
  15239. function InterleavedBuffer(array, stride) {
  15240. this.array = array;
  15241. this.stride = stride;
  15242. this.count = array !== undefined ? array.length / stride : 0;
  15243. this.usage = StaticDrawUsage;
  15244. this.updateRange = {
  15245. offset: 0,
  15246. count: -1
  15247. };
  15248. this.version = 0;
  15249. this.uuid = MathUtils.generateUUID();
  15250. }
  15251. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  15252. set: function set(value) {
  15253. if (value === true) this.version++;
  15254. }
  15255. });
  15256. Object.assign(InterleavedBuffer.prototype, {
  15257. isInterleavedBuffer: true,
  15258. onUploadCallback: function onUploadCallback() {},
  15259. setUsage: function setUsage(value) {
  15260. this.usage = value;
  15261. return this;
  15262. },
  15263. copy: function copy(source) {
  15264. this.array = new source.array.constructor(source.array);
  15265. this.count = source.count;
  15266. this.stride = source.stride;
  15267. this.usage = source.usage;
  15268. return this;
  15269. },
  15270. copyAt: function copyAt(index1, attribute, index2) {
  15271. index1 *= this.stride;
  15272. index2 *= attribute.stride;
  15273. for (var i = 0, l = this.stride; i < l; i++) {
  15274. this.array[index1 + i] = attribute.array[index2 + i];
  15275. }
  15276. return this;
  15277. },
  15278. set: function set(value, offset) {
  15279. if (offset === undefined) offset = 0;
  15280. this.array.set(value, offset);
  15281. return this;
  15282. },
  15283. clone: function clone(data) {
  15284. if (data.arrayBuffers === undefined) {
  15285. data.arrayBuffers = {};
  15286. }
  15287. if (this.array.buffer._uuid === undefined) {
  15288. this.array.buffer._uuid = MathUtils.generateUUID();
  15289. }
  15290. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15291. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  15292. }
  15293. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  15294. var ib = new InterleavedBuffer(array, this.stride);
  15295. ib.setUsage(this.usage);
  15296. return ib;
  15297. },
  15298. onUpload: function onUpload(callback) {
  15299. this.onUploadCallback = callback;
  15300. return this;
  15301. },
  15302. toJSON: function toJSON(data) {
  15303. if (data.arrayBuffers === undefined) {
  15304. data.arrayBuffers = {};
  15305. } // generate UUID for array buffer if necessary
  15306. if (this.array.buffer._uuid === undefined) {
  15307. this.array.buffer._uuid = MathUtils.generateUUID();
  15308. }
  15309. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15310. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  15311. } //
  15312. return {
  15313. uuid: this.uuid,
  15314. buffer: this.array.buffer._uuid,
  15315. type: this.array.constructor.name,
  15316. stride: this.stride
  15317. };
  15318. }
  15319. });
  15320. var _vector$6 = new Vector3();
  15321. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  15322. this.name = '';
  15323. this.data = interleavedBuffer;
  15324. this.itemSize = itemSize;
  15325. this.offset = offset;
  15326. this.normalized = normalized === true;
  15327. }
  15328. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  15329. count: {
  15330. get: function get() {
  15331. return this.data.count;
  15332. }
  15333. },
  15334. array: {
  15335. get: function get() {
  15336. return this.data.array;
  15337. }
  15338. },
  15339. needsUpdate: {
  15340. set: function set(value) {
  15341. this.data.needsUpdate = value;
  15342. }
  15343. }
  15344. });
  15345. Object.assign(InterleavedBufferAttribute.prototype, {
  15346. isInterleavedBufferAttribute: true,
  15347. applyMatrix4: function applyMatrix4(m) {
  15348. for (var i = 0, l = this.data.count; i < l; i++) {
  15349. _vector$6.x = this.getX(i);
  15350. _vector$6.y = this.getY(i);
  15351. _vector$6.z = this.getZ(i);
  15352. _vector$6.applyMatrix4(m);
  15353. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  15354. }
  15355. return this;
  15356. },
  15357. setX: function setX(index, x) {
  15358. this.data.array[index * this.data.stride + this.offset] = x;
  15359. return this;
  15360. },
  15361. setY: function setY(index, y) {
  15362. this.data.array[index * this.data.stride + this.offset + 1] = y;
  15363. return this;
  15364. },
  15365. setZ: function setZ(index, z) {
  15366. this.data.array[index * this.data.stride + this.offset + 2] = z;
  15367. return this;
  15368. },
  15369. setW: function setW(index, w) {
  15370. this.data.array[index * this.data.stride + this.offset + 3] = w;
  15371. return this;
  15372. },
  15373. getX: function getX(index) {
  15374. return this.data.array[index * this.data.stride + this.offset];
  15375. },
  15376. getY: function getY(index) {
  15377. return this.data.array[index * this.data.stride + this.offset + 1];
  15378. },
  15379. getZ: function getZ(index) {
  15380. return this.data.array[index * this.data.stride + this.offset + 2];
  15381. },
  15382. getW: function getW(index) {
  15383. return this.data.array[index * this.data.stride + this.offset + 3];
  15384. },
  15385. setXY: function setXY(index, x, y) {
  15386. index = index * this.data.stride + this.offset;
  15387. this.data.array[index + 0] = x;
  15388. this.data.array[index + 1] = y;
  15389. return this;
  15390. },
  15391. setXYZ: function setXYZ(index, x, y, z) {
  15392. index = index * this.data.stride + this.offset;
  15393. this.data.array[index + 0] = x;
  15394. this.data.array[index + 1] = y;
  15395. this.data.array[index + 2] = z;
  15396. return this;
  15397. },
  15398. setXYZW: function setXYZW(index, x, y, z, w) {
  15399. index = index * this.data.stride + this.offset;
  15400. this.data.array[index + 0] = x;
  15401. this.data.array[index + 1] = y;
  15402. this.data.array[index + 2] = z;
  15403. this.data.array[index + 3] = w;
  15404. return this;
  15405. },
  15406. clone: function clone(data) {
  15407. if (data === undefined) {
  15408. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  15409. var array = [];
  15410. for (var i = 0; i < this.count; i++) {
  15411. var index = i * this.data.stride + this.offset;
  15412. for (var j = 0; j < this.itemSize; j++) {
  15413. array.push(this.data.array[index + j]);
  15414. }
  15415. }
  15416. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  15417. } else {
  15418. if (data.interleavedBuffers === undefined) {
  15419. data.interleavedBuffers = {};
  15420. }
  15421. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15422. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  15423. }
  15424. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  15425. }
  15426. },
  15427. toJSON: function toJSON(data) {
  15428. if (data === undefined) {
  15429. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  15430. var array = [];
  15431. for (var i = 0; i < this.count; i++) {
  15432. var index = i * this.data.stride + this.offset;
  15433. for (var j = 0; j < this.itemSize; j++) {
  15434. array.push(this.data.array[index + j]);
  15435. }
  15436. } // deinterleave data and save it as an ordinary buffer attribute for now
  15437. return {
  15438. itemSize: this.itemSize,
  15439. type: this.array.constructor.name,
  15440. array: array,
  15441. normalized: this.normalized
  15442. };
  15443. } else {
  15444. // save as true interlaved attribtue
  15445. if (data.interleavedBuffers === undefined) {
  15446. data.interleavedBuffers = {};
  15447. }
  15448. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15449. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  15450. }
  15451. return {
  15452. isInterleavedBufferAttribute: true,
  15453. itemSize: this.itemSize,
  15454. data: this.data.uuid,
  15455. offset: this.offset,
  15456. normalized: this.normalized
  15457. };
  15458. }
  15459. }
  15460. });
  15461. /**
  15462. * parameters = {
  15463. * color: <hex>,
  15464. * map: new THREE.Texture( <Image> ),
  15465. * alphaMap: new THREE.Texture( <Image> ),
  15466. * rotation: <float>,
  15467. * sizeAttenuation: <bool>
  15468. * }
  15469. */
  15470. function SpriteMaterial(parameters) {
  15471. Material.call(this);
  15472. this.type = 'SpriteMaterial';
  15473. this.color = new Color(0xffffff);
  15474. this.map = null;
  15475. this.alphaMap = null;
  15476. this.rotation = 0;
  15477. this.sizeAttenuation = true;
  15478. this.transparent = true;
  15479. this.setValues(parameters);
  15480. }
  15481. SpriteMaterial.prototype = Object.create(Material.prototype);
  15482. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15483. SpriteMaterial.prototype.isSpriteMaterial = true;
  15484. SpriteMaterial.prototype.copy = function (source) {
  15485. Material.prototype.copy.call(this, source);
  15486. this.color.copy(source.color);
  15487. this.map = source.map;
  15488. this.alphaMap = source.alphaMap;
  15489. this.rotation = source.rotation;
  15490. this.sizeAttenuation = source.sizeAttenuation;
  15491. return this;
  15492. };
  15493. var _geometry;
  15494. var _intersectPoint = new Vector3();
  15495. var _worldScale = new Vector3();
  15496. var _mvPosition = new Vector3();
  15497. var _alignedPosition = new Vector2();
  15498. var _rotatedPosition = new Vector2();
  15499. var _viewWorldMatrix = new Matrix4();
  15500. var _vA$1 = new Vector3();
  15501. var _vB$1 = new Vector3();
  15502. var _vC$1 = new Vector3();
  15503. var _uvA$1 = new Vector2();
  15504. var _uvB$1 = new Vector2();
  15505. var _uvC$1 = new Vector2();
  15506. function Sprite(material) {
  15507. Object3D.call(this);
  15508. this.type = 'Sprite';
  15509. if (_geometry === undefined) {
  15510. _geometry = new BufferGeometry();
  15511. 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]);
  15512. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  15513. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  15514. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  15515. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  15516. }
  15517. this.geometry = _geometry;
  15518. this.material = material !== undefined ? material : new SpriteMaterial();
  15519. this.center = new Vector2(0.5, 0.5);
  15520. }
  15521. Sprite.prototype = Object.assign(Object.create(Object3D.prototype), {
  15522. constructor: Sprite,
  15523. isSprite: true,
  15524. raycast: function raycast(raycaster, intersects) {
  15525. if (raycaster.camera === null) {
  15526. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  15527. }
  15528. _worldScale.setFromMatrixScale(this.matrixWorld);
  15529. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  15530. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  15531. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  15532. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  15533. _worldScale.multiplyScalar(-_mvPosition.z);
  15534. }
  15535. var rotation = this.material.rotation;
  15536. var sin, cos;
  15537. if (rotation !== 0) {
  15538. cos = Math.cos(rotation);
  15539. sin = Math.sin(rotation);
  15540. }
  15541. var center = this.center;
  15542. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15543. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15544. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15545. _uvA$1.set(0, 0);
  15546. _uvB$1.set(1, 0);
  15547. _uvC$1.set(1, 1); // check first triangle
  15548. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  15549. if (intersect === null) {
  15550. // check second triangle
  15551. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15552. _uvB$1.set(0, 1);
  15553. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  15554. if (intersect === null) {
  15555. return;
  15556. }
  15557. }
  15558. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  15559. if (distance < raycaster.near || distance > raycaster.far) return;
  15560. intersects.push({
  15561. distance: distance,
  15562. point: _intersectPoint.clone(),
  15563. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  15564. face: null,
  15565. object: this
  15566. });
  15567. },
  15568. copy: function copy(source) {
  15569. Object3D.prototype.copy.call(this, source);
  15570. if (source.center !== undefined) this.center.copy(source.center);
  15571. this.material = source.material;
  15572. return this;
  15573. }
  15574. });
  15575. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  15576. // compute position in camera space
  15577. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  15578. if (sin !== undefined) {
  15579. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  15580. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  15581. } else {
  15582. _rotatedPosition.copy(_alignedPosition);
  15583. }
  15584. vertexPosition.copy(mvPosition);
  15585. vertexPosition.x += _rotatedPosition.x;
  15586. vertexPosition.y += _rotatedPosition.y; // transform to world space
  15587. vertexPosition.applyMatrix4(_viewWorldMatrix);
  15588. }
  15589. var _v1$4 = new Vector3();
  15590. var _v2$2 = new Vector3();
  15591. function LOD() {
  15592. Object3D.call(this);
  15593. this._currentLevel = 0;
  15594. this.type = 'LOD';
  15595. Object.defineProperties(this, {
  15596. levels: {
  15597. enumerable: true,
  15598. value: []
  15599. }
  15600. });
  15601. this.autoUpdate = true;
  15602. }
  15603. LOD.prototype = Object.assign(Object.create(Object3D.prototype), {
  15604. constructor: LOD,
  15605. isLOD: true,
  15606. copy: function copy(source) {
  15607. Object3D.prototype.copy.call(this, source, false);
  15608. var levels = source.levels;
  15609. for (var i = 0, l = levels.length; i < l; i++) {
  15610. var level = levels[i];
  15611. this.addLevel(level.object.clone(), level.distance);
  15612. }
  15613. this.autoUpdate = source.autoUpdate;
  15614. return this;
  15615. },
  15616. addLevel: function addLevel(object, distance) {
  15617. if (distance === undefined) distance = 0;
  15618. distance = Math.abs(distance);
  15619. var levels = this.levels;
  15620. var l;
  15621. for (l = 0; l < levels.length; l++) {
  15622. if (distance < levels[l].distance) {
  15623. break;
  15624. }
  15625. }
  15626. levels.splice(l, 0, {
  15627. distance: distance,
  15628. object: object
  15629. });
  15630. this.add(object);
  15631. return this;
  15632. },
  15633. getCurrentLevel: function getCurrentLevel() {
  15634. return this._currentLevel;
  15635. },
  15636. getObjectForDistance: function getObjectForDistance(distance) {
  15637. var levels = this.levels;
  15638. if (levels.length > 0) {
  15639. var i, l;
  15640. for (i = 1, l = levels.length; i < l; i++) {
  15641. if (distance < levels[i].distance) {
  15642. break;
  15643. }
  15644. }
  15645. return levels[i - 1].object;
  15646. }
  15647. return null;
  15648. },
  15649. raycast: function raycast(raycaster, intersects) {
  15650. var levels = this.levels;
  15651. if (levels.length > 0) {
  15652. _v1$4.setFromMatrixPosition(this.matrixWorld);
  15653. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  15654. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  15655. }
  15656. },
  15657. update: function update(camera) {
  15658. var levels = this.levels;
  15659. if (levels.length > 1) {
  15660. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  15661. _v2$2.setFromMatrixPosition(this.matrixWorld);
  15662. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  15663. levels[0].object.visible = true;
  15664. var i, l;
  15665. for (i = 1, l = levels.length; i < l; i++) {
  15666. if (distance >= levels[i].distance) {
  15667. levels[i - 1].object.visible = false;
  15668. levels[i].object.visible = true;
  15669. } else {
  15670. break;
  15671. }
  15672. }
  15673. this._currentLevel = i - 1;
  15674. for (; i < l; i++) {
  15675. levels[i].object.visible = false;
  15676. }
  15677. }
  15678. },
  15679. toJSON: function toJSON(meta) {
  15680. var data = Object3D.prototype.toJSON.call(this, meta);
  15681. if (this.autoUpdate === false) data.object.autoUpdate = false;
  15682. data.object.levels = [];
  15683. var levels = this.levels;
  15684. for (var i = 0, l = levels.length; i < l; i++) {
  15685. var level = levels[i];
  15686. data.object.levels.push({
  15687. object: level.object.uuid,
  15688. distance: level.distance
  15689. });
  15690. }
  15691. return data;
  15692. }
  15693. });
  15694. function SkinnedMesh(geometry, material) {
  15695. if (geometry && geometry.isGeometry) {
  15696. console.error('THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  15697. }
  15698. Mesh.call(this, geometry, material);
  15699. this.type = 'SkinnedMesh';
  15700. this.bindMode = 'attached';
  15701. this.bindMatrix = new Matrix4();
  15702. this.bindMatrixInverse = new Matrix4();
  15703. }
  15704. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  15705. constructor: SkinnedMesh,
  15706. isSkinnedMesh: true,
  15707. copy: function copy(source) {
  15708. Mesh.prototype.copy.call(this, source);
  15709. this.bindMode = source.bindMode;
  15710. this.bindMatrix.copy(source.bindMatrix);
  15711. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  15712. this.skeleton = source.skeleton;
  15713. return this;
  15714. },
  15715. bind: function bind(skeleton, bindMatrix) {
  15716. this.skeleton = skeleton;
  15717. if (bindMatrix === undefined) {
  15718. this.updateMatrixWorld(true);
  15719. this.skeleton.calculateInverses();
  15720. bindMatrix = this.matrixWorld;
  15721. }
  15722. this.bindMatrix.copy(bindMatrix);
  15723. this.bindMatrixInverse.getInverse(bindMatrix);
  15724. },
  15725. pose: function pose() {
  15726. this.skeleton.pose();
  15727. },
  15728. normalizeSkinWeights: function normalizeSkinWeights() {
  15729. var vector = new Vector4();
  15730. var skinWeight = this.geometry.attributes.skinWeight;
  15731. for (var i = 0, l = skinWeight.count; i < l; i++) {
  15732. vector.x = skinWeight.getX(i);
  15733. vector.y = skinWeight.getY(i);
  15734. vector.z = skinWeight.getZ(i);
  15735. vector.w = skinWeight.getW(i);
  15736. var scale = 1.0 / vector.manhattanLength();
  15737. if (scale !== Infinity) {
  15738. vector.multiplyScalar(scale);
  15739. } else {
  15740. vector.set(1, 0, 0, 0); // do something reasonable
  15741. }
  15742. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  15743. }
  15744. },
  15745. updateMatrixWorld: function updateMatrixWorld(force) {
  15746. Mesh.prototype.updateMatrixWorld.call(this, force);
  15747. if (this.bindMode === 'attached') {
  15748. this.bindMatrixInverse.getInverse(this.matrixWorld);
  15749. } else if (this.bindMode === 'detached') {
  15750. this.bindMatrixInverse.getInverse(this.bindMatrix);
  15751. } else {
  15752. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  15753. }
  15754. },
  15755. boneTransform: function () {
  15756. var basePosition = new Vector3();
  15757. var skinIndex = new Vector4();
  15758. var skinWeight = new Vector4();
  15759. var vector = new Vector3();
  15760. var matrix = new Matrix4();
  15761. return function (index, target) {
  15762. var skeleton = this.skeleton;
  15763. var geometry = this.geometry;
  15764. skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  15765. skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  15766. basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  15767. target.set(0, 0, 0);
  15768. for (var i = 0; i < 4; i++) {
  15769. var weight = skinWeight.getComponent(i);
  15770. if (weight !== 0) {
  15771. var boneIndex = skinIndex.getComponent(i);
  15772. matrix.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  15773. target.addScaledVector(vector.copy(basePosition).applyMatrix4(matrix), weight);
  15774. }
  15775. }
  15776. return target.applyMatrix4(this.bindMatrixInverse);
  15777. };
  15778. }()
  15779. });
  15780. var _offsetMatrix = new Matrix4();
  15781. var _identityMatrix = new Matrix4();
  15782. function Skeleton(bones, boneInverses) {
  15783. // copy the bone array
  15784. bones = bones || [];
  15785. this.bones = bones.slice(0);
  15786. this.boneMatrices = new Float32Array(this.bones.length * 16);
  15787. this.frame = -1; // use the supplied bone inverses or calculate the inverses
  15788. if (boneInverses === undefined) {
  15789. this.calculateInverses();
  15790. } else {
  15791. if (this.bones.length === boneInverses.length) {
  15792. this.boneInverses = boneInverses.slice(0);
  15793. } else {
  15794. console.warn('THREE.Skeleton boneInverses is the wrong length.');
  15795. this.boneInverses = [];
  15796. for (var i = 0, il = this.bones.length; i < il; i++) {
  15797. this.boneInverses.push(new Matrix4());
  15798. }
  15799. }
  15800. }
  15801. }
  15802. Object.assign(Skeleton.prototype, {
  15803. calculateInverses: function calculateInverses() {
  15804. this.boneInverses = [];
  15805. for (var i = 0, il = this.bones.length; i < il; i++) {
  15806. var inverse = new Matrix4();
  15807. if (this.bones[i]) {
  15808. inverse.getInverse(this.bones[i].matrixWorld);
  15809. }
  15810. this.boneInverses.push(inverse);
  15811. }
  15812. },
  15813. pose: function pose() {
  15814. // recover the bind-time world matrices
  15815. for (var i = 0, il = this.bones.length; i < il; i++) {
  15816. var bone = this.bones[i];
  15817. if (bone) {
  15818. bone.matrixWorld.getInverse(this.boneInverses[i]);
  15819. }
  15820. } // compute the local matrices, positions, rotations and scales
  15821. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  15822. var _bone = this.bones[_i];
  15823. if (_bone) {
  15824. if (_bone.parent && _bone.parent.isBone) {
  15825. _bone.matrix.getInverse(_bone.parent.matrixWorld);
  15826. _bone.matrix.multiply(_bone.matrixWorld);
  15827. } else {
  15828. _bone.matrix.copy(_bone.matrixWorld);
  15829. }
  15830. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  15831. }
  15832. }
  15833. },
  15834. update: function update() {
  15835. var bones = this.bones;
  15836. var boneInverses = this.boneInverses;
  15837. var boneMatrices = this.boneMatrices;
  15838. var boneTexture = this.boneTexture; // flatten bone matrices to array
  15839. for (var i = 0, il = bones.length; i < il; i++) {
  15840. // compute the offset between the current and the original transform
  15841. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  15842. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  15843. _offsetMatrix.toArray(boneMatrices, i * 16);
  15844. }
  15845. if (boneTexture !== undefined) {
  15846. boneTexture.needsUpdate = true;
  15847. }
  15848. },
  15849. clone: function clone() {
  15850. return new Skeleton(this.bones, this.boneInverses);
  15851. },
  15852. getBoneByName: function getBoneByName(name) {
  15853. for (var i = 0, il = this.bones.length; i < il; i++) {
  15854. var bone = this.bones[i];
  15855. if (bone.name === name) {
  15856. return bone;
  15857. }
  15858. }
  15859. return undefined;
  15860. },
  15861. dispose: function dispose() {
  15862. if (this.boneTexture) {
  15863. this.boneTexture.dispose();
  15864. this.boneTexture = undefined;
  15865. }
  15866. }
  15867. });
  15868. function Bone() {
  15869. Object3D.call(this);
  15870. this.type = 'Bone';
  15871. }
  15872. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  15873. constructor: Bone,
  15874. isBone: true
  15875. });
  15876. var _instanceLocalMatrix = new Matrix4();
  15877. var _instanceWorldMatrix = new Matrix4();
  15878. var _instanceIntersects = [];
  15879. var _mesh = new Mesh();
  15880. function InstancedMesh(geometry, material, count) {
  15881. Mesh.call(this, geometry, material);
  15882. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  15883. this.instanceColor = null;
  15884. this.count = count;
  15885. this.frustumCulled = false;
  15886. }
  15887. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  15888. constructor: InstancedMesh,
  15889. isInstancedMesh: true,
  15890. copy: function copy(source) {
  15891. Mesh.prototype.copy.call(this, source);
  15892. this.instanceMatrix.copy(source.instanceMatrix);
  15893. this.count = source.count;
  15894. return this;
  15895. },
  15896. setColorAt: function setColorAt(index, color) {
  15897. if (this.instanceColor === null) {
  15898. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  15899. }
  15900. color.toArray(this.instanceColor.array, index * 3);
  15901. },
  15902. getMatrixAt: function getMatrixAt(index, matrix) {
  15903. matrix.fromArray(this.instanceMatrix.array, index * 16);
  15904. },
  15905. raycast: function raycast(raycaster, intersects) {
  15906. var matrixWorld = this.matrixWorld;
  15907. var raycastTimes = this.count;
  15908. _mesh.geometry = this.geometry;
  15909. _mesh.material = this.material;
  15910. if (_mesh.material === undefined) return;
  15911. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  15912. // calculate the world matrix for each instance
  15913. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  15914. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  15915. _mesh.matrixWorld = _instanceWorldMatrix;
  15916. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  15917. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  15918. var intersect = _instanceIntersects[i];
  15919. intersect.instanceId = instanceId;
  15920. intersect.object = this;
  15921. intersects.push(intersect);
  15922. }
  15923. _instanceIntersects.length = 0;
  15924. }
  15925. },
  15926. setMatrixAt: function setMatrixAt(index, matrix) {
  15927. matrix.toArray(this.instanceMatrix.array, index * 16);
  15928. },
  15929. updateMorphTargets: function updateMorphTargets() {}
  15930. });
  15931. /**
  15932. * parameters = {
  15933. * color: <hex>,
  15934. * opacity: <float>,
  15935. *
  15936. * linewidth: <float>,
  15937. * linecap: "round",
  15938. * linejoin: "round"
  15939. * }
  15940. */
  15941. function LineBasicMaterial(parameters) {
  15942. Material.call(this);
  15943. this.type = 'LineBasicMaterial';
  15944. this.color = new Color(0xffffff);
  15945. this.linewidth = 1;
  15946. this.linecap = 'round';
  15947. this.linejoin = 'round';
  15948. this.morphTargets = false;
  15949. this.setValues(parameters);
  15950. }
  15951. LineBasicMaterial.prototype = Object.create(Material.prototype);
  15952. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  15953. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15954. LineBasicMaterial.prototype.copy = function (source) {
  15955. Material.prototype.copy.call(this, source);
  15956. this.color.copy(source.color);
  15957. this.linewidth = source.linewidth;
  15958. this.linecap = source.linecap;
  15959. this.linejoin = source.linejoin;
  15960. this.morphTargets = source.morphTargets;
  15961. return this;
  15962. };
  15963. var _start = new Vector3();
  15964. var _end = new Vector3();
  15965. var _inverseMatrix$1 = new Matrix4();
  15966. var _ray$1 = new Ray();
  15967. var _sphere$2 = new Sphere();
  15968. function Line(geometry, material, mode) {
  15969. if (mode === 1) {
  15970. console.error('THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.');
  15971. }
  15972. Object3D.call(this);
  15973. this.type = 'Line';
  15974. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15975. this.material = material !== undefined ? material : new LineBasicMaterial();
  15976. this.updateMorphTargets();
  15977. }
  15978. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  15979. constructor: Line,
  15980. isLine: true,
  15981. copy: function copy(source) {
  15982. Object3D.prototype.copy.call(this, source);
  15983. this.material = source.material;
  15984. this.geometry = source.geometry;
  15985. return this;
  15986. },
  15987. computeLineDistances: function computeLineDistances() {
  15988. var geometry = this.geometry;
  15989. if (geometry.isBufferGeometry) {
  15990. // we assume non-indexed geometry
  15991. if (geometry.index === null) {
  15992. var positionAttribute = geometry.attributes.position;
  15993. var lineDistances = [0];
  15994. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  15995. _start.fromBufferAttribute(positionAttribute, i - 1);
  15996. _end.fromBufferAttribute(positionAttribute, i);
  15997. lineDistances[i] = lineDistances[i - 1];
  15998. lineDistances[i] += _start.distanceTo(_end);
  15999. }
  16000. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16001. } else {
  16002. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16003. }
  16004. } else if (geometry.isGeometry) {
  16005. var vertices = geometry.vertices;
  16006. var _lineDistances = geometry.lineDistances;
  16007. _lineDistances[0] = 0;
  16008. for (var _i = 1, _l = vertices.length; _i < _l; _i++) {
  16009. _lineDistances[_i] = _lineDistances[_i - 1];
  16010. _lineDistances[_i] += vertices[_i - 1].distanceTo(vertices[_i]);
  16011. }
  16012. }
  16013. return this;
  16014. },
  16015. raycast: function raycast(raycaster, intersects) {
  16016. var geometry = this.geometry;
  16017. var matrixWorld = this.matrixWorld;
  16018. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  16019. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16020. _sphere$2.copy(geometry.boundingSphere);
  16021. _sphere$2.applyMatrix4(matrixWorld);
  16022. _sphere$2.radius += threshold;
  16023. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  16024. _inverseMatrix$1.getInverse(matrixWorld);
  16025. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  16026. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16027. var localThresholdSq = localThreshold * localThreshold;
  16028. var vStart = new Vector3();
  16029. var vEnd = new Vector3();
  16030. var interSegment = new Vector3();
  16031. var interRay = new Vector3();
  16032. var step = this.isLineSegments ? 2 : 1;
  16033. if (geometry.isBufferGeometry) {
  16034. var index = geometry.index;
  16035. var attributes = geometry.attributes;
  16036. var positionAttribute = attributes.position;
  16037. if (index !== null) {
  16038. var indices = index.array;
  16039. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  16040. var a = indices[i];
  16041. var b = indices[i + 1];
  16042. vStart.fromBufferAttribute(positionAttribute, a);
  16043. vEnd.fromBufferAttribute(positionAttribute, b);
  16044. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16045. if (distSq > localThresholdSq) continue;
  16046. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16047. var distance = raycaster.ray.origin.distanceTo(interRay);
  16048. if (distance < raycaster.near || distance > raycaster.far) continue;
  16049. intersects.push({
  16050. distance: distance,
  16051. // What do we want? intersection point on the ray or on the segment??
  16052. // point: raycaster.ray.at( distance ),
  16053. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16054. index: i,
  16055. face: null,
  16056. faceIndex: null,
  16057. object: this
  16058. });
  16059. }
  16060. } else {
  16061. for (var _i2 = 0, _l2 = positionAttribute.count - 1; _i2 < _l2; _i2 += step) {
  16062. vStart.fromBufferAttribute(positionAttribute, _i2);
  16063. vEnd.fromBufferAttribute(positionAttribute, _i2 + 1);
  16064. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16065. if (_distSq > localThresholdSq) continue;
  16066. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16067. var _distance = raycaster.ray.origin.distanceTo(interRay);
  16068. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  16069. intersects.push({
  16070. distance: _distance,
  16071. // What do we want? intersection point on the ray or on the segment??
  16072. // point: raycaster.ray.at( distance ),
  16073. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16074. index: _i2,
  16075. face: null,
  16076. faceIndex: null,
  16077. object: this
  16078. });
  16079. }
  16080. }
  16081. } else if (geometry.isGeometry) {
  16082. var vertices = geometry.vertices;
  16083. var nbVertices = vertices.length;
  16084. for (var _i3 = 0; _i3 < nbVertices - 1; _i3 += step) {
  16085. var _distSq2 = _ray$1.distanceSqToSegment(vertices[_i3], vertices[_i3 + 1], interRay, interSegment);
  16086. if (_distSq2 > localThresholdSq) continue;
  16087. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16088. var _distance2 = raycaster.ray.origin.distanceTo(interRay);
  16089. if (_distance2 < raycaster.near || _distance2 > raycaster.far) continue;
  16090. intersects.push({
  16091. distance: _distance2,
  16092. // What do we want? intersection point on the ray or on the segment??
  16093. // point: raycaster.ray.at( distance ),
  16094. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16095. index: _i3,
  16096. face: null,
  16097. faceIndex: null,
  16098. object: this
  16099. });
  16100. }
  16101. }
  16102. },
  16103. updateMorphTargets: function updateMorphTargets() {
  16104. var geometry = this.geometry;
  16105. if (geometry.isBufferGeometry) {
  16106. var morphAttributes = geometry.morphAttributes;
  16107. var keys = Object.keys(morphAttributes);
  16108. if (keys.length > 0) {
  16109. var morphAttribute = morphAttributes[keys[0]];
  16110. if (morphAttribute !== undefined) {
  16111. this.morphTargetInfluences = [];
  16112. this.morphTargetDictionary = {};
  16113. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16114. var name = morphAttribute[m].name || String(m);
  16115. this.morphTargetInfluences.push(0);
  16116. this.morphTargetDictionary[name] = m;
  16117. }
  16118. }
  16119. }
  16120. } else {
  16121. var morphTargets = geometry.morphTargets;
  16122. if (morphTargets !== undefined && morphTargets.length > 0) {
  16123. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16124. }
  16125. }
  16126. }
  16127. });
  16128. var _start$1 = new Vector3();
  16129. var _end$1 = new Vector3();
  16130. function LineSegments(geometry, material) {
  16131. Line.call(this, geometry, material);
  16132. this.type = 'LineSegments';
  16133. }
  16134. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  16135. constructor: LineSegments,
  16136. isLineSegments: true,
  16137. computeLineDistances: function computeLineDistances() {
  16138. var geometry = this.geometry;
  16139. if (geometry.isBufferGeometry) {
  16140. // we assume non-indexed geometry
  16141. if (geometry.index === null) {
  16142. var positionAttribute = geometry.attributes.position;
  16143. var lineDistances = [];
  16144. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  16145. _start$1.fromBufferAttribute(positionAttribute, i);
  16146. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  16147. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  16148. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  16149. }
  16150. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16151. } else {
  16152. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16153. }
  16154. } else if (geometry.isGeometry) {
  16155. var vertices = geometry.vertices;
  16156. var _lineDistances = geometry.lineDistances;
  16157. for (var _i = 0, _l = vertices.length; _i < _l; _i += 2) {
  16158. _start$1.copy(vertices[_i]);
  16159. _end$1.copy(vertices[_i + 1]);
  16160. _lineDistances[_i] = _i === 0 ? 0 : _lineDistances[_i - 1];
  16161. _lineDistances[_i + 1] = _lineDistances[_i] + _start$1.distanceTo(_end$1);
  16162. }
  16163. }
  16164. return this;
  16165. }
  16166. });
  16167. function LineLoop(geometry, material) {
  16168. Line.call(this, geometry, material);
  16169. this.type = 'LineLoop';
  16170. }
  16171. LineLoop.prototype = Object.assign(Object.create(Line.prototype), {
  16172. constructor: LineLoop,
  16173. isLineLoop: true
  16174. });
  16175. /**
  16176. * parameters = {
  16177. * color: <hex>,
  16178. * opacity: <float>,
  16179. * map: new THREE.Texture( <Image> ),
  16180. * alphaMap: new THREE.Texture( <Image> ),
  16181. *
  16182. * size: <float>,
  16183. * sizeAttenuation: <bool>
  16184. *
  16185. * morphTargets: <bool>
  16186. * }
  16187. */
  16188. function PointsMaterial(parameters) {
  16189. Material.call(this);
  16190. this.type = 'PointsMaterial';
  16191. this.color = new Color(0xffffff);
  16192. this.map = null;
  16193. this.alphaMap = null;
  16194. this.size = 1;
  16195. this.sizeAttenuation = true;
  16196. this.morphTargets = false;
  16197. this.setValues(parameters);
  16198. }
  16199. PointsMaterial.prototype = Object.create(Material.prototype);
  16200. PointsMaterial.prototype.constructor = PointsMaterial;
  16201. PointsMaterial.prototype.isPointsMaterial = true;
  16202. PointsMaterial.prototype.copy = function (source) {
  16203. Material.prototype.copy.call(this, source);
  16204. this.color.copy(source.color);
  16205. this.map = source.map;
  16206. this.alphaMap = source.alphaMap;
  16207. this.size = source.size;
  16208. this.sizeAttenuation = source.sizeAttenuation;
  16209. this.morphTargets = source.morphTargets;
  16210. return this;
  16211. };
  16212. var _inverseMatrix$2 = new Matrix4();
  16213. var _ray$2 = new Ray();
  16214. var _sphere$3 = new Sphere();
  16215. var _position$1 = new Vector3();
  16216. function Points(geometry, material) {
  16217. Object3D.call(this);
  16218. this.type = 'Points';
  16219. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16220. this.material = material !== undefined ? material : new PointsMaterial();
  16221. this.updateMorphTargets();
  16222. }
  16223. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  16224. constructor: Points,
  16225. isPoints: true,
  16226. copy: function copy(source) {
  16227. Object3D.prototype.copy.call(this, source);
  16228. this.material = source.material;
  16229. this.geometry = source.geometry;
  16230. return this;
  16231. },
  16232. raycast: function raycast(raycaster, intersects) {
  16233. var geometry = this.geometry;
  16234. var matrixWorld = this.matrixWorld;
  16235. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  16236. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16237. _sphere$3.copy(geometry.boundingSphere);
  16238. _sphere$3.applyMatrix4(matrixWorld);
  16239. _sphere$3.radius += threshold;
  16240. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  16241. _inverseMatrix$2.getInverse(matrixWorld);
  16242. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  16243. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16244. var localThresholdSq = localThreshold * localThreshold;
  16245. if (geometry.isBufferGeometry) {
  16246. var index = geometry.index;
  16247. var attributes = geometry.attributes;
  16248. var positionAttribute = attributes.position;
  16249. if (index !== null) {
  16250. var indices = index.array;
  16251. for (var i = 0, il = indices.length; i < il; i++) {
  16252. var a = indices[i];
  16253. _position$1.fromBufferAttribute(positionAttribute, a);
  16254. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16255. }
  16256. } else {
  16257. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  16258. _position$1.fromBufferAttribute(positionAttribute, _i);
  16259. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16260. }
  16261. }
  16262. } else {
  16263. var vertices = geometry.vertices;
  16264. for (var _i2 = 0, _l = vertices.length; _i2 < _l; _i2++) {
  16265. testPoint(vertices[_i2], _i2, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16266. }
  16267. }
  16268. },
  16269. updateMorphTargets: function updateMorphTargets() {
  16270. var geometry = this.geometry;
  16271. if (geometry.isBufferGeometry) {
  16272. var morphAttributes = geometry.morphAttributes;
  16273. var keys = Object.keys(morphAttributes);
  16274. if (keys.length > 0) {
  16275. var morphAttribute = morphAttributes[keys[0]];
  16276. if (morphAttribute !== undefined) {
  16277. this.morphTargetInfluences = [];
  16278. this.morphTargetDictionary = {};
  16279. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16280. var name = morphAttribute[m].name || String(m);
  16281. this.morphTargetInfluences.push(0);
  16282. this.morphTargetDictionary[name] = m;
  16283. }
  16284. }
  16285. }
  16286. } else {
  16287. var morphTargets = geometry.morphTargets;
  16288. if (morphTargets !== undefined && morphTargets.length > 0) {
  16289. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16290. }
  16291. }
  16292. }
  16293. });
  16294. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  16295. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  16296. if (rayPointDistanceSq < localThresholdSq) {
  16297. var intersectPoint = new Vector3();
  16298. _ray$2.closestPointToPoint(point, intersectPoint);
  16299. intersectPoint.applyMatrix4(matrixWorld);
  16300. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  16301. if (distance < raycaster.near || distance > raycaster.far) return;
  16302. intersects.push({
  16303. distance: distance,
  16304. distanceToRay: Math.sqrt(rayPointDistanceSq),
  16305. point: intersectPoint,
  16306. index: index,
  16307. face: null,
  16308. object: object
  16309. });
  16310. }
  16311. }
  16312. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16313. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16314. this.format = format !== undefined ? format : RGBFormat;
  16315. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16316. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16317. this.generateMipmaps = false;
  16318. var scope = this;
  16319. function updateVideo() {
  16320. scope.needsUpdate = true;
  16321. video.requestVideoFrameCallback(updateVideo);
  16322. }
  16323. if ('requestVideoFrameCallback' in video) {
  16324. video.requestVideoFrameCallback(updateVideo);
  16325. }
  16326. }
  16327. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  16328. constructor: VideoTexture,
  16329. isVideoTexture: true,
  16330. update: function update() {
  16331. var video = this.image;
  16332. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  16333. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  16334. this.needsUpdate = true;
  16335. }
  16336. }
  16337. });
  16338. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  16339. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  16340. this.image = {
  16341. width: width,
  16342. height: height
  16343. };
  16344. this.mipmaps = mipmaps; // no flipping for cube textures
  16345. // (also flipping doesn't work for compressed textures )
  16346. this.flipY = false; // can't generate mipmaps for compressed textures
  16347. // mips must be embedded in DDS files
  16348. this.generateMipmaps = false;
  16349. }
  16350. CompressedTexture.prototype = Object.create(Texture.prototype);
  16351. CompressedTexture.prototype.constructor = CompressedTexture;
  16352. CompressedTexture.prototype.isCompressedTexture = true;
  16353. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16354. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16355. this.needsUpdate = true;
  16356. }
  16357. CanvasTexture.prototype = Object.create(Texture.prototype);
  16358. CanvasTexture.prototype.constructor = CanvasTexture;
  16359. CanvasTexture.prototype.isCanvasTexture = true;
  16360. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  16361. format = format !== undefined ? format : DepthFormat;
  16362. if (format !== DepthFormat && format !== DepthStencilFormat) {
  16363. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  16364. }
  16365. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  16366. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  16367. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16368. this.image = {
  16369. width: width,
  16370. height: height
  16371. };
  16372. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16373. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16374. this.flipY = false;
  16375. this.generateMipmaps = false;
  16376. }
  16377. DepthTexture.prototype = Object.create(Texture.prototype);
  16378. DepthTexture.prototype.constructor = DepthTexture;
  16379. DepthTexture.prototype.isDepthTexture = true;
  16380. var _geometryId = 0; // Geometry uses even numbers as Id
  16381. var _m1$3 = new Matrix4();
  16382. var _obj$1 = new Object3D();
  16383. var _offset$1 = new Vector3();
  16384. function Geometry() {
  16385. Object.defineProperty(this, 'id', {
  16386. value: _geometryId += 2
  16387. });
  16388. this.uuid = MathUtils.generateUUID();
  16389. this.name = '';
  16390. this.type = 'Geometry';
  16391. this.vertices = [];
  16392. this.colors = [];
  16393. this.faces = [];
  16394. this.faceVertexUvs = [[]];
  16395. this.morphTargets = [];
  16396. this.morphNormals = [];
  16397. this.skinWeights = [];
  16398. this.skinIndices = [];
  16399. this.lineDistances = [];
  16400. this.boundingBox = null;
  16401. this.boundingSphere = null; // update flags
  16402. this.elementsNeedUpdate = false;
  16403. this.verticesNeedUpdate = false;
  16404. this.uvsNeedUpdate = false;
  16405. this.normalsNeedUpdate = false;
  16406. this.colorsNeedUpdate = false;
  16407. this.lineDistancesNeedUpdate = false;
  16408. this.groupsNeedUpdate = false;
  16409. }
  16410. Geometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  16411. constructor: Geometry,
  16412. isGeometry: true,
  16413. applyMatrix4: function applyMatrix4(matrix) {
  16414. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  16415. for (var i = 0, il = this.vertices.length; i < il; i++) {
  16416. var vertex = this.vertices[i];
  16417. vertex.applyMatrix4(matrix);
  16418. }
  16419. for (var _i = 0, _il = this.faces.length; _i < _il; _i++) {
  16420. var face = this.faces[_i];
  16421. face.normal.applyMatrix3(normalMatrix).normalize();
  16422. for (var j = 0, jl = face.vertexNormals.length; j < jl; j++) {
  16423. face.vertexNormals[j].applyMatrix3(normalMatrix).normalize();
  16424. }
  16425. }
  16426. if (this.boundingBox !== null) {
  16427. this.computeBoundingBox();
  16428. }
  16429. if (this.boundingSphere !== null) {
  16430. this.computeBoundingSphere();
  16431. }
  16432. this.verticesNeedUpdate = true;
  16433. this.normalsNeedUpdate = true;
  16434. return this;
  16435. },
  16436. rotateX: function rotateX(angle) {
  16437. // rotate geometry around world x-axis
  16438. _m1$3.makeRotationX(angle);
  16439. this.applyMatrix4(_m1$3);
  16440. return this;
  16441. },
  16442. rotateY: function rotateY(angle) {
  16443. // rotate geometry around world y-axis
  16444. _m1$3.makeRotationY(angle);
  16445. this.applyMatrix4(_m1$3);
  16446. return this;
  16447. },
  16448. rotateZ: function rotateZ(angle) {
  16449. // rotate geometry around world z-axis
  16450. _m1$3.makeRotationZ(angle);
  16451. this.applyMatrix4(_m1$3);
  16452. return this;
  16453. },
  16454. translate: function translate(x, y, z) {
  16455. // translate geometry
  16456. _m1$3.makeTranslation(x, y, z);
  16457. this.applyMatrix4(_m1$3);
  16458. return this;
  16459. },
  16460. scale: function scale(x, y, z) {
  16461. // scale geometry
  16462. _m1$3.makeScale(x, y, z);
  16463. this.applyMatrix4(_m1$3);
  16464. return this;
  16465. },
  16466. lookAt: function lookAt(vector) {
  16467. _obj$1.lookAt(vector);
  16468. _obj$1.updateMatrix();
  16469. this.applyMatrix4(_obj$1.matrix);
  16470. return this;
  16471. },
  16472. fromBufferGeometry: function fromBufferGeometry(geometry) {
  16473. var scope = this;
  16474. var index = geometry.index !== null ? geometry.index : undefined;
  16475. var attributes = geometry.attributes;
  16476. if (attributes.position === undefined) {
  16477. console.error('THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.');
  16478. return this;
  16479. }
  16480. var position = attributes.position;
  16481. var normal = attributes.normal;
  16482. var color = attributes.color;
  16483. var uv = attributes.uv;
  16484. var uv2 = attributes.uv2;
  16485. if (uv2 !== undefined) this.faceVertexUvs[1] = [];
  16486. for (var i = 0; i < position.count; i++) {
  16487. scope.vertices.push(new Vector3().fromBufferAttribute(position, i));
  16488. if (color !== undefined) {
  16489. scope.colors.push(new Color().fromBufferAttribute(color, i));
  16490. }
  16491. }
  16492. function addFace(a, b, c, materialIndex) {
  16493. var vertexColors = color === undefined ? [] : [scope.colors[a].clone(), scope.colors[b].clone(), scope.colors[c].clone()];
  16494. var vertexNormals = normal === undefined ? [] : [new Vector3().fromBufferAttribute(normal, a), new Vector3().fromBufferAttribute(normal, b), new Vector3().fromBufferAttribute(normal, c)];
  16495. var face = new Face3(a, b, c, vertexNormals, vertexColors, materialIndex);
  16496. scope.faces.push(face);
  16497. if (uv !== undefined) {
  16498. scope.faceVertexUvs[0].push([new Vector2().fromBufferAttribute(uv, a), new Vector2().fromBufferAttribute(uv, b), new Vector2().fromBufferAttribute(uv, c)]);
  16499. }
  16500. if (uv2 !== undefined) {
  16501. scope.faceVertexUvs[1].push([new Vector2().fromBufferAttribute(uv2, a), new Vector2().fromBufferAttribute(uv2, b), new Vector2().fromBufferAttribute(uv2, c)]);
  16502. }
  16503. }
  16504. var groups = geometry.groups;
  16505. if (groups.length > 0) {
  16506. for (var _i2 = 0; _i2 < groups.length; _i2++) {
  16507. var group = groups[_i2];
  16508. var start = group.start;
  16509. var count = group.count;
  16510. for (var j = start, jl = start + count; j < jl; j += 3) {
  16511. if (index !== undefined) {
  16512. addFace(index.getX(j), index.getX(j + 1), index.getX(j + 2), group.materialIndex);
  16513. } else {
  16514. addFace(j, j + 1, j + 2, group.materialIndex);
  16515. }
  16516. }
  16517. }
  16518. } else {
  16519. if (index !== undefined) {
  16520. for (var _i3 = 0; _i3 < index.count; _i3 += 3) {
  16521. addFace(index.getX(_i3), index.getX(_i3 + 1), index.getX(_i3 + 2));
  16522. }
  16523. } else {
  16524. for (var _i4 = 0; _i4 < position.count; _i4 += 3) {
  16525. addFace(_i4, _i4 + 1, _i4 + 2);
  16526. }
  16527. }
  16528. }
  16529. this.computeFaceNormals();
  16530. if (geometry.boundingBox !== null) {
  16531. this.boundingBox = geometry.boundingBox.clone();
  16532. }
  16533. if (geometry.boundingSphere !== null) {
  16534. this.boundingSphere = geometry.boundingSphere.clone();
  16535. }
  16536. return this;
  16537. },
  16538. center: function center() {
  16539. this.computeBoundingBox();
  16540. this.boundingBox.getCenter(_offset$1).negate();
  16541. this.translate(_offset$1.x, _offset$1.y, _offset$1.z);
  16542. return this;
  16543. },
  16544. normalize: function normalize() {
  16545. this.computeBoundingSphere();
  16546. var center = this.boundingSphere.center;
  16547. var radius = this.boundingSphere.radius;
  16548. var s = radius === 0 ? 1 : 1.0 / radius;
  16549. var matrix = new Matrix4();
  16550. matrix.set(s, 0, 0, -s * center.x, 0, s, 0, -s * center.y, 0, 0, s, -s * center.z, 0, 0, 0, 1);
  16551. this.applyMatrix4(matrix);
  16552. return this;
  16553. },
  16554. computeFaceNormals: function computeFaceNormals() {
  16555. var cb = new Vector3(),
  16556. ab = new Vector3();
  16557. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16558. var face = this.faces[f];
  16559. var vA = this.vertices[face.a];
  16560. var vB = this.vertices[face.b];
  16561. var vC = this.vertices[face.c];
  16562. cb.subVectors(vC, vB);
  16563. ab.subVectors(vA, vB);
  16564. cb.cross(ab);
  16565. cb.normalize();
  16566. face.normal.copy(cb);
  16567. }
  16568. },
  16569. computeVertexNormals: function computeVertexNormals(areaWeighted) {
  16570. if (areaWeighted === undefined) areaWeighted = true;
  16571. var vertices = new Array(this.vertices.length);
  16572. for (var v = 0, vl = this.vertices.length; v < vl; v++) {
  16573. vertices[v] = new Vector3();
  16574. }
  16575. if (areaWeighted) {
  16576. // vertex normals weighted by triangle areas
  16577. // http://www.iquilezles.org/www/articles/normals/normals.htm
  16578. var cb = new Vector3(),
  16579. ab = new Vector3();
  16580. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16581. var face = this.faces[f];
  16582. var vA = this.vertices[face.a];
  16583. var vB = this.vertices[face.b];
  16584. var vC = this.vertices[face.c];
  16585. cb.subVectors(vC, vB);
  16586. ab.subVectors(vA, vB);
  16587. cb.cross(ab);
  16588. vertices[face.a].add(cb);
  16589. vertices[face.b].add(cb);
  16590. vertices[face.c].add(cb);
  16591. }
  16592. } else {
  16593. this.computeFaceNormals();
  16594. for (var _f = 0, _fl = this.faces.length; _f < _fl; _f++) {
  16595. var _face = this.faces[_f];
  16596. vertices[_face.a].add(_face.normal);
  16597. vertices[_face.b].add(_face.normal);
  16598. vertices[_face.c].add(_face.normal);
  16599. }
  16600. }
  16601. for (var _v = 0, _vl = this.vertices.length; _v < _vl; _v++) {
  16602. vertices[_v].normalize();
  16603. }
  16604. for (var _f2 = 0, _fl2 = this.faces.length; _f2 < _fl2; _f2++) {
  16605. var _face2 = this.faces[_f2];
  16606. var vertexNormals = _face2.vertexNormals;
  16607. if (vertexNormals.length === 3) {
  16608. vertexNormals[0].copy(vertices[_face2.a]);
  16609. vertexNormals[1].copy(vertices[_face2.b]);
  16610. vertexNormals[2].copy(vertices[_face2.c]);
  16611. } else {
  16612. vertexNormals[0] = vertices[_face2.a].clone();
  16613. vertexNormals[1] = vertices[_face2.b].clone();
  16614. vertexNormals[2] = vertices[_face2.c].clone();
  16615. }
  16616. }
  16617. if (this.faces.length > 0) {
  16618. this.normalsNeedUpdate = true;
  16619. }
  16620. },
  16621. computeFlatVertexNormals: function computeFlatVertexNormals() {
  16622. this.computeFaceNormals();
  16623. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16624. var face = this.faces[f];
  16625. var vertexNormals = face.vertexNormals;
  16626. if (vertexNormals.length === 3) {
  16627. vertexNormals[0].copy(face.normal);
  16628. vertexNormals[1].copy(face.normal);
  16629. vertexNormals[2].copy(face.normal);
  16630. } else {
  16631. vertexNormals[0] = face.normal.clone();
  16632. vertexNormals[1] = face.normal.clone();
  16633. vertexNormals[2] = face.normal.clone();
  16634. }
  16635. }
  16636. if (this.faces.length > 0) {
  16637. this.normalsNeedUpdate = true;
  16638. }
  16639. },
  16640. computeMorphNormals: function computeMorphNormals() {
  16641. // save original normals
  16642. // - create temp variables on first access
  16643. // otherwise just copy (for faster repeated calls)
  16644. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16645. var face = this.faces[f];
  16646. if (!face.__originalFaceNormal) {
  16647. face.__originalFaceNormal = face.normal.clone();
  16648. } else {
  16649. face.__originalFaceNormal.copy(face.normal);
  16650. }
  16651. if (!face.__originalVertexNormals) face.__originalVertexNormals = [];
  16652. for (var i = 0, il = face.vertexNormals.length; i < il; i++) {
  16653. if (!face.__originalVertexNormals[i]) {
  16654. face.__originalVertexNormals[i] = face.vertexNormals[i].clone();
  16655. } else {
  16656. face.__originalVertexNormals[i].copy(face.vertexNormals[i]);
  16657. }
  16658. }
  16659. } // use temp geometry to compute face and vertex normals for each morph
  16660. var tmpGeo = new Geometry();
  16661. tmpGeo.faces = this.faces;
  16662. for (var _i5 = 0, _il2 = this.morphTargets.length; _i5 < _il2; _i5++) {
  16663. // create on first access
  16664. if (!this.morphNormals[_i5]) {
  16665. this.morphNormals[_i5] = {};
  16666. this.morphNormals[_i5].faceNormals = [];
  16667. this.morphNormals[_i5].vertexNormals = [];
  16668. var dstNormalsFace = this.morphNormals[_i5].faceNormals;
  16669. var dstNormalsVertex = this.morphNormals[_i5].vertexNormals;
  16670. for (var _f3 = 0, _fl3 = this.faces.length; _f3 < _fl3; _f3++) {
  16671. var faceNormal = new Vector3();
  16672. var vertexNormals = {
  16673. a: new Vector3(),
  16674. b: new Vector3(),
  16675. c: new Vector3()
  16676. };
  16677. dstNormalsFace.push(faceNormal);
  16678. dstNormalsVertex.push(vertexNormals);
  16679. }
  16680. }
  16681. var morphNormals = this.morphNormals[_i5]; // set vertices to morph target
  16682. tmpGeo.vertices = this.morphTargets[_i5].vertices; // compute morph normals
  16683. tmpGeo.computeFaceNormals();
  16684. tmpGeo.computeVertexNormals(); // store morph normals
  16685. for (var _f4 = 0, _fl4 = this.faces.length; _f4 < _fl4; _f4++) {
  16686. var _face3 = this.faces[_f4];
  16687. var _faceNormal = morphNormals.faceNormals[_f4];
  16688. var _vertexNormals = morphNormals.vertexNormals[_f4];
  16689. _faceNormal.copy(_face3.normal);
  16690. _vertexNormals.a.copy(_face3.vertexNormals[0]);
  16691. _vertexNormals.b.copy(_face3.vertexNormals[1]);
  16692. _vertexNormals.c.copy(_face3.vertexNormals[2]);
  16693. }
  16694. } // restore original normals
  16695. for (var _f5 = 0, _fl5 = this.faces.length; _f5 < _fl5; _f5++) {
  16696. var _face4 = this.faces[_f5];
  16697. _face4.normal = _face4.__originalFaceNormal;
  16698. _face4.vertexNormals = _face4.__originalVertexNormals;
  16699. }
  16700. },
  16701. computeBoundingBox: function computeBoundingBox() {
  16702. if (this.boundingBox === null) {
  16703. this.boundingBox = new Box3();
  16704. }
  16705. this.boundingBox.setFromPoints(this.vertices);
  16706. },
  16707. computeBoundingSphere: function computeBoundingSphere() {
  16708. if (this.boundingSphere === null) {
  16709. this.boundingSphere = new Sphere();
  16710. }
  16711. this.boundingSphere.setFromPoints(this.vertices);
  16712. },
  16713. merge: function merge(geometry, matrix, materialIndexOffset) {
  16714. if (!(geometry && geometry.isGeometry)) {
  16715. console.error('THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry);
  16716. return;
  16717. }
  16718. var normalMatrix;
  16719. var vertexOffset = this.vertices.length,
  16720. vertices1 = this.vertices,
  16721. vertices2 = geometry.vertices,
  16722. faces1 = this.faces,
  16723. faces2 = geometry.faces,
  16724. colors1 = this.colors,
  16725. colors2 = geometry.colors;
  16726. if (materialIndexOffset === undefined) materialIndexOffset = 0;
  16727. if (matrix !== undefined) {
  16728. normalMatrix = new Matrix3().getNormalMatrix(matrix);
  16729. } // vertices
  16730. for (var i = 0, il = vertices2.length; i < il; i++) {
  16731. var vertex = vertices2[i];
  16732. var vertexCopy = vertex.clone();
  16733. if (matrix !== undefined) vertexCopy.applyMatrix4(matrix);
  16734. vertices1.push(vertexCopy);
  16735. } // colors
  16736. for (var _i6 = 0, _il3 = colors2.length; _i6 < _il3; _i6++) {
  16737. colors1.push(colors2[_i6].clone());
  16738. } // faces
  16739. for (var _i7 = 0, _il4 = faces2.length; _i7 < _il4; _i7++) {
  16740. var face = faces2[_i7];
  16741. var normal = void 0,
  16742. color = void 0;
  16743. var faceVertexNormals = face.vertexNormals,
  16744. faceVertexColors = face.vertexColors;
  16745. var faceCopy = new Face3(face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset);
  16746. faceCopy.normal.copy(face.normal);
  16747. if (normalMatrix !== undefined) {
  16748. faceCopy.normal.applyMatrix3(normalMatrix).normalize();
  16749. }
  16750. for (var j = 0, jl = faceVertexNormals.length; j < jl; j++) {
  16751. normal = faceVertexNormals[j].clone();
  16752. if (normalMatrix !== undefined) {
  16753. normal.applyMatrix3(normalMatrix).normalize();
  16754. }
  16755. faceCopy.vertexNormals.push(normal);
  16756. }
  16757. faceCopy.color.copy(face.color);
  16758. for (var _j = 0, _jl = faceVertexColors.length; _j < _jl; _j++) {
  16759. color = faceVertexColors[_j];
  16760. faceCopy.vertexColors.push(color.clone());
  16761. }
  16762. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  16763. faces1.push(faceCopy);
  16764. } // uvs
  16765. for (var _i8 = 0, _il5 = geometry.faceVertexUvs.length; _i8 < _il5; _i8++) {
  16766. var faceVertexUvs2 = geometry.faceVertexUvs[_i8];
  16767. if (this.faceVertexUvs[_i8] === undefined) this.faceVertexUvs[_i8] = [];
  16768. for (var _j2 = 0, _jl2 = faceVertexUvs2.length; _j2 < _jl2; _j2++) {
  16769. var uvs2 = faceVertexUvs2[_j2],
  16770. uvsCopy = [];
  16771. for (var k = 0, kl = uvs2.length; k < kl; k++) {
  16772. uvsCopy.push(uvs2[k].clone());
  16773. }
  16774. this.faceVertexUvs[_i8].push(uvsCopy);
  16775. }
  16776. }
  16777. },
  16778. mergeMesh: function mergeMesh(mesh) {
  16779. if (!(mesh && mesh.isMesh)) {
  16780. console.error('THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh);
  16781. return;
  16782. }
  16783. if (mesh.matrixAutoUpdate) mesh.updateMatrix();
  16784. this.merge(mesh.geometry, mesh.matrix);
  16785. },
  16786. /*
  16787. * Checks for duplicate vertices with hashmap.
  16788. * Duplicated vertices are removed
  16789. * and faces' vertices are updated.
  16790. */
  16791. mergeVertices: function mergeVertices() {
  16792. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  16793. var unique = [],
  16794. changes = [];
  16795. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  16796. var precision = Math.pow(10, precisionPoints);
  16797. for (var i = 0, il = this.vertices.length; i < il; i++) {
  16798. var v = this.vertices[i];
  16799. var key = Math.round(v.x * precision) + '_' + Math.round(v.y * precision) + '_' + Math.round(v.z * precision);
  16800. if (verticesMap[key] === undefined) {
  16801. verticesMap[key] = i;
  16802. unique.push(this.vertices[i]);
  16803. changes[i] = unique.length - 1;
  16804. } else {
  16805. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  16806. changes[i] = changes[verticesMap[key]];
  16807. }
  16808. } // if faces are completely degenerate after merging vertices, we
  16809. // have to remove them from the geometry.
  16810. var faceIndicesToRemove = [];
  16811. for (var _i9 = 0, _il6 = this.faces.length; _i9 < _il6; _i9++) {
  16812. var face = this.faces[_i9];
  16813. face.a = changes[face.a];
  16814. face.b = changes[face.b];
  16815. face.c = changes[face.c];
  16816. var indices = [face.a, face.b, face.c]; // if any duplicate vertices are found in a Face3
  16817. // we have to remove the face as nothing can be saved
  16818. for (var n = 0; n < 3; n++) {
  16819. if (indices[n] === indices[(n + 1) % 3]) {
  16820. faceIndicesToRemove.push(_i9);
  16821. break;
  16822. }
  16823. }
  16824. }
  16825. for (var _i10 = faceIndicesToRemove.length - 1; _i10 >= 0; _i10--) {
  16826. var idx = faceIndicesToRemove[_i10];
  16827. this.faces.splice(idx, 1);
  16828. for (var j = 0, jl = this.faceVertexUvs.length; j < jl; j++) {
  16829. this.faceVertexUvs[j].splice(idx, 1);
  16830. }
  16831. } // Use unique set of vertices
  16832. var diff = this.vertices.length - unique.length;
  16833. this.vertices = unique;
  16834. return diff;
  16835. },
  16836. setFromPoints: function setFromPoints(points) {
  16837. this.vertices = [];
  16838. for (var i = 0, l = points.length; i < l; i++) {
  16839. var point = points[i];
  16840. this.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  16841. }
  16842. return this;
  16843. },
  16844. sortFacesByMaterialIndex: function sortFacesByMaterialIndex() {
  16845. var faces = this.faces;
  16846. var length = faces.length; // tag faces
  16847. for (var i = 0; i < length; i++) {
  16848. faces[i]._id = i;
  16849. } // sort faces
  16850. function materialIndexSort(a, b) {
  16851. return a.materialIndex - b.materialIndex;
  16852. }
  16853. faces.sort(materialIndexSort); // sort uvs
  16854. var uvs1 = this.faceVertexUvs[0];
  16855. var uvs2 = this.faceVertexUvs[1];
  16856. var newUvs1, newUvs2;
  16857. if (uvs1 && uvs1.length === length) newUvs1 = [];
  16858. if (uvs2 && uvs2.length === length) newUvs2 = [];
  16859. for (var _i11 = 0; _i11 < length; _i11++) {
  16860. var id = faces[_i11]._id;
  16861. if (newUvs1) newUvs1.push(uvs1[id]);
  16862. if (newUvs2) newUvs2.push(uvs2[id]);
  16863. }
  16864. if (newUvs1) this.faceVertexUvs[0] = newUvs1;
  16865. if (newUvs2) this.faceVertexUvs[1] = newUvs2;
  16866. },
  16867. toJSON: function toJSON() {
  16868. var data = {
  16869. metadata: {
  16870. version: 4.5,
  16871. type: 'Geometry',
  16872. generator: 'Geometry.toJSON'
  16873. }
  16874. }; // standard Geometry serialization
  16875. data.uuid = this.uuid;
  16876. data.type = this.type;
  16877. if (this.name !== '') data.name = this.name;
  16878. if (this.parameters !== undefined) {
  16879. var parameters = this.parameters;
  16880. for (var key in parameters) {
  16881. if (parameters[key] !== undefined) data[key] = parameters[key];
  16882. }
  16883. return data;
  16884. }
  16885. var vertices = [];
  16886. for (var i = 0; i < this.vertices.length; i++) {
  16887. var vertex = this.vertices[i];
  16888. vertices.push(vertex.x, vertex.y, vertex.z);
  16889. }
  16890. var faces = [];
  16891. var normals = [];
  16892. var normalsHash = {};
  16893. var colors = [];
  16894. var colorsHash = {};
  16895. var uvs = [];
  16896. var uvsHash = {};
  16897. for (var _i12 = 0; _i12 < this.faces.length; _i12++) {
  16898. var face = this.faces[_i12];
  16899. var hasMaterial = true;
  16900. var hasFaceUv = false; // deprecated
  16901. var hasFaceVertexUv = this.faceVertexUvs[0][_i12] !== undefined;
  16902. var hasFaceNormal = face.normal.length() > 0;
  16903. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  16904. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  16905. var hasFaceVertexColor = face.vertexColors.length > 0;
  16906. var faceType = 0;
  16907. faceType = setBit(faceType, 0, 0); // isQuad
  16908. faceType = setBit(faceType, 1, hasMaterial);
  16909. faceType = setBit(faceType, 2, hasFaceUv);
  16910. faceType = setBit(faceType, 3, hasFaceVertexUv);
  16911. faceType = setBit(faceType, 4, hasFaceNormal);
  16912. faceType = setBit(faceType, 5, hasFaceVertexNormal);
  16913. faceType = setBit(faceType, 6, hasFaceColor);
  16914. faceType = setBit(faceType, 7, hasFaceVertexColor);
  16915. faces.push(faceType);
  16916. faces.push(face.a, face.b, face.c);
  16917. faces.push(face.materialIndex);
  16918. if (hasFaceVertexUv) {
  16919. var faceVertexUvs = this.faceVertexUvs[0][_i12];
  16920. faces.push(getUvIndex(faceVertexUvs[0]), getUvIndex(faceVertexUvs[1]), getUvIndex(faceVertexUvs[2]));
  16921. }
  16922. if (hasFaceNormal) {
  16923. faces.push(getNormalIndex(face.normal));
  16924. }
  16925. if (hasFaceVertexNormal) {
  16926. var vertexNormals = face.vertexNormals;
  16927. faces.push(getNormalIndex(vertexNormals[0]), getNormalIndex(vertexNormals[1]), getNormalIndex(vertexNormals[2]));
  16928. }
  16929. if (hasFaceColor) {
  16930. faces.push(getColorIndex(face.color));
  16931. }
  16932. if (hasFaceVertexColor) {
  16933. var vertexColors = face.vertexColors;
  16934. faces.push(getColorIndex(vertexColors[0]), getColorIndex(vertexColors[1]), getColorIndex(vertexColors[2]));
  16935. }
  16936. }
  16937. function setBit(value, position, enabled) {
  16938. return enabled ? value | 1 << position : value & ~(1 << position);
  16939. }
  16940. function getNormalIndex(normal) {
  16941. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  16942. if (normalsHash[hash] !== undefined) {
  16943. return normalsHash[hash];
  16944. }
  16945. normalsHash[hash] = normals.length / 3;
  16946. normals.push(normal.x, normal.y, normal.z);
  16947. return normalsHash[hash];
  16948. }
  16949. function getColorIndex(color) {
  16950. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  16951. if (colorsHash[hash] !== undefined) {
  16952. return colorsHash[hash];
  16953. }
  16954. colorsHash[hash] = colors.length;
  16955. colors.push(color.getHex());
  16956. return colorsHash[hash];
  16957. }
  16958. function getUvIndex(uv) {
  16959. var hash = uv.x.toString() + uv.y.toString();
  16960. if (uvsHash[hash] !== undefined) {
  16961. return uvsHash[hash];
  16962. }
  16963. uvsHash[hash] = uvs.length / 2;
  16964. uvs.push(uv.x, uv.y);
  16965. return uvsHash[hash];
  16966. }
  16967. data.data = {};
  16968. data.data.vertices = vertices;
  16969. data.data.normals = normals;
  16970. if (colors.length > 0) data.data.colors = colors;
  16971. if (uvs.length > 0) data.data.uvs = [uvs]; // temporal backward compatibility
  16972. data.data.faces = faces;
  16973. return data;
  16974. },
  16975. clone: function clone() {
  16976. /*
  16977. // Handle primitives
  16978. const parameters = this.parameters;
  16979. if ( parameters !== undefined ) {
  16980. const values = [];
  16981. for ( const key in parameters ) {
  16982. values.push( parameters[ key ] );
  16983. }
  16984. const geometry = Object.create( this.constructor.prototype );
  16985. this.constructor.apply( geometry, values );
  16986. return geometry;
  16987. }
  16988. return new this.constructor().copy( this );
  16989. */
  16990. return new Geometry().copy(this);
  16991. },
  16992. copy: function copy(source) {
  16993. // reset
  16994. this.vertices = [];
  16995. this.colors = [];
  16996. this.faces = [];
  16997. this.faceVertexUvs = [[]];
  16998. this.morphTargets = [];
  16999. this.morphNormals = [];
  17000. this.skinWeights = [];
  17001. this.skinIndices = [];
  17002. this.lineDistances = [];
  17003. this.boundingBox = null;
  17004. this.boundingSphere = null; // name
  17005. this.name = source.name; // vertices
  17006. var vertices = source.vertices;
  17007. for (var i = 0, il = vertices.length; i < il; i++) {
  17008. this.vertices.push(vertices[i].clone());
  17009. } // colors
  17010. var colors = source.colors;
  17011. for (var _i13 = 0, _il7 = colors.length; _i13 < _il7; _i13++) {
  17012. this.colors.push(colors[_i13].clone());
  17013. } // faces
  17014. var faces = source.faces;
  17015. for (var _i14 = 0, _il8 = faces.length; _i14 < _il8; _i14++) {
  17016. this.faces.push(faces[_i14].clone());
  17017. } // face vertex uvs
  17018. for (var _i15 = 0, _il9 = source.faceVertexUvs.length; _i15 < _il9; _i15++) {
  17019. var faceVertexUvs = source.faceVertexUvs[_i15];
  17020. if (this.faceVertexUvs[_i15] === undefined) {
  17021. this.faceVertexUvs[_i15] = [];
  17022. }
  17023. for (var j = 0, jl = faceVertexUvs.length; j < jl; j++) {
  17024. var uvs = faceVertexUvs[j],
  17025. uvsCopy = [];
  17026. for (var k = 0, kl = uvs.length; k < kl; k++) {
  17027. var uv = uvs[k];
  17028. uvsCopy.push(uv.clone());
  17029. }
  17030. this.faceVertexUvs[_i15].push(uvsCopy);
  17031. }
  17032. } // morph targets
  17033. var morphTargets = source.morphTargets;
  17034. for (var _i16 = 0, _il10 = morphTargets.length; _i16 < _il10; _i16++) {
  17035. var morphTarget = {};
  17036. morphTarget.name = morphTargets[_i16].name; // vertices
  17037. if (morphTargets[_i16].vertices !== undefined) {
  17038. morphTarget.vertices = [];
  17039. for (var _j3 = 0, _jl3 = morphTargets[_i16].vertices.length; _j3 < _jl3; _j3++) {
  17040. morphTarget.vertices.push(morphTargets[_i16].vertices[_j3].clone());
  17041. }
  17042. } // normals
  17043. if (morphTargets[_i16].normals !== undefined) {
  17044. morphTarget.normals = [];
  17045. for (var _j4 = 0, _jl4 = morphTargets[_i16].normals.length; _j4 < _jl4; _j4++) {
  17046. morphTarget.normals.push(morphTargets[_i16].normals[_j4].clone());
  17047. }
  17048. }
  17049. this.morphTargets.push(morphTarget);
  17050. } // morph normals
  17051. var morphNormals = source.morphNormals;
  17052. for (var _i17 = 0, _il11 = morphNormals.length; _i17 < _il11; _i17++) {
  17053. var morphNormal = {}; // vertex normals
  17054. if (morphNormals[_i17].vertexNormals !== undefined) {
  17055. morphNormal.vertexNormals = [];
  17056. for (var _j5 = 0, _jl5 = morphNormals[_i17].vertexNormals.length; _j5 < _jl5; _j5++) {
  17057. var srcVertexNormal = morphNormals[_i17].vertexNormals[_j5];
  17058. var destVertexNormal = {};
  17059. destVertexNormal.a = srcVertexNormal.a.clone();
  17060. destVertexNormal.b = srcVertexNormal.b.clone();
  17061. destVertexNormal.c = srcVertexNormal.c.clone();
  17062. morphNormal.vertexNormals.push(destVertexNormal);
  17063. }
  17064. } // face normals
  17065. if (morphNormals[_i17].faceNormals !== undefined) {
  17066. morphNormal.faceNormals = [];
  17067. for (var _j6 = 0, _jl6 = morphNormals[_i17].faceNormals.length; _j6 < _jl6; _j6++) {
  17068. morphNormal.faceNormals.push(morphNormals[_i17].faceNormals[_j6].clone());
  17069. }
  17070. }
  17071. this.morphNormals.push(morphNormal);
  17072. } // skin weights
  17073. var skinWeights = source.skinWeights;
  17074. for (var _i18 = 0, _il12 = skinWeights.length; _i18 < _il12; _i18++) {
  17075. this.skinWeights.push(skinWeights[_i18].clone());
  17076. } // skin indices
  17077. var skinIndices = source.skinIndices;
  17078. for (var _i19 = 0, _il13 = skinIndices.length; _i19 < _il13; _i19++) {
  17079. this.skinIndices.push(skinIndices[_i19].clone());
  17080. } // line distances
  17081. var lineDistances = source.lineDistances;
  17082. for (var _i20 = 0, _il14 = lineDistances.length; _i20 < _il14; _i20++) {
  17083. this.lineDistances.push(lineDistances[_i20]);
  17084. } // bounding box
  17085. var boundingBox = source.boundingBox;
  17086. if (boundingBox !== null) {
  17087. this.boundingBox = boundingBox.clone();
  17088. } // bounding sphere
  17089. var boundingSphere = source.boundingSphere;
  17090. if (boundingSphere !== null) {
  17091. this.boundingSphere = boundingSphere.clone();
  17092. } // update flags
  17093. this.elementsNeedUpdate = source.elementsNeedUpdate;
  17094. this.verticesNeedUpdate = source.verticesNeedUpdate;
  17095. this.uvsNeedUpdate = source.uvsNeedUpdate;
  17096. this.normalsNeedUpdate = source.normalsNeedUpdate;
  17097. this.colorsNeedUpdate = source.colorsNeedUpdate;
  17098. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  17099. this.groupsNeedUpdate = source.groupsNeedUpdate;
  17100. return this;
  17101. },
  17102. dispose: function dispose() {
  17103. this.dispatchEvent({
  17104. type: 'dispose'
  17105. });
  17106. }
  17107. });
  17108. var BoxGeometry = /*#__PURE__*/function (_Geometry) {
  17109. _inheritsLoose(BoxGeometry, _Geometry);
  17110. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  17111. var _this;
  17112. _this = _Geometry.call(this) || this;
  17113. _this.type = 'BoxGeometry';
  17114. _this.parameters = {
  17115. width: width,
  17116. height: height,
  17117. depth: depth,
  17118. widthSegments: widthSegments,
  17119. heightSegments: heightSegments,
  17120. depthSegments: depthSegments
  17121. };
  17122. _this.fromBufferGeometry(new BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments));
  17123. _this.mergeVertices();
  17124. return _this;
  17125. }
  17126. return BoxGeometry;
  17127. }(Geometry);
  17128. var CircleBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17129. _inheritsLoose(CircleBufferGeometry, _BufferGeometry);
  17130. function CircleBufferGeometry(radius, segments, thetaStart, thetaLength) {
  17131. var _this;
  17132. _this = _BufferGeometry.call(this) || this;
  17133. _this.type = 'CircleBufferGeometry';
  17134. _this.parameters = {
  17135. radius: radius,
  17136. segments: segments,
  17137. thetaStart: thetaStart,
  17138. thetaLength: thetaLength
  17139. };
  17140. radius = radius || 1;
  17141. segments = segments !== undefined ? Math.max(3, segments) : 8;
  17142. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17143. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2; // buffers
  17144. var indices = [];
  17145. var vertices = [];
  17146. var normals = [];
  17147. var uvs = []; // helper variables
  17148. var vertex = new Vector3();
  17149. var uv = new Vector2(); // center point
  17150. vertices.push(0, 0, 0);
  17151. normals.push(0, 0, 1);
  17152. uvs.push(0.5, 0.5);
  17153. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17154. var segment = thetaStart + s / segments * thetaLength; // vertex
  17155. vertex.x = radius * Math.cos(segment);
  17156. vertex.y = radius * Math.sin(segment);
  17157. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17158. normals.push(0, 0, 1); // uvs
  17159. uv.x = (vertices[i] / radius + 1) / 2;
  17160. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17161. uvs.push(uv.x, uv.y);
  17162. } // indices
  17163. for (var _i = 1; _i <= segments; _i++) {
  17164. indices.push(_i, _i + 1, 0);
  17165. } // build geometry
  17166. _this.setIndex(indices);
  17167. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17168. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17169. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17170. return _this;
  17171. }
  17172. return CircleBufferGeometry;
  17173. }(BufferGeometry);
  17174. var CircleGeometry = /*#__PURE__*/function (_Geometry) {
  17175. _inheritsLoose(CircleGeometry, _Geometry);
  17176. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17177. var _this;
  17178. _this = _Geometry.call(this) || this;
  17179. _this.type = 'CircleGeometry';
  17180. _this.parameters = {
  17181. radius: radius,
  17182. segments: segments,
  17183. thetaStart: thetaStart,
  17184. thetaLength: thetaLength
  17185. };
  17186. _this.fromBufferGeometry(new CircleBufferGeometry(radius, segments, thetaStart, thetaLength));
  17187. _this.mergeVertices();
  17188. return _this;
  17189. }
  17190. return CircleGeometry;
  17191. }(Geometry);
  17192. var CylinderBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17193. _inheritsLoose(CylinderBufferGeometry, _BufferGeometry);
  17194. function CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17195. var _this;
  17196. _this = _BufferGeometry.call(this) || this;
  17197. _this.type = 'CylinderBufferGeometry';
  17198. _this.parameters = {
  17199. radiusTop: radiusTop,
  17200. radiusBottom: radiusBottom,
  17201. height: height,
  17202. radialSegments: radialSegments,
  17203. heightSegments: heightSegments,
  17204. openEnded: openEnded,
  17205. thetaStart: thetaStart,
  17206. thetaLength: thetaLength
  17207. };
  17208. var scope = _assertThisInitialized(_this);
  17209. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  17210. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  17211. height = height || 1;
  17212. radialSegments = Math.floor(radialSegments) || 8;
  17213. heightSegments = Math.floor(heightSegments) || 1;
  17214. openEnded = openEnded !== undefined ? openEnded : false;
  17215. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  17216. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2; // buffers
  17217. var indices = [];
  17218. var vertices = [];
  17219. var normals = [];
  17220. var uvs = []; // helper variables
  17221. var index = 0;
  17222. var indexArray = [];
  17223. var halfHeight = height / 2;
  17224. var groupStart = 0; // generate geometry
  17225. generateTorso();
  17226. if (openEnded === false) {
  17227. if (radiusTop > 0) generateCap(true);
  17228. if (radiusBottom > 0) generateCap(false);
  17229. } // build geometry
  17230. _this.setIndex(indices);
  17231. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17232. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17233. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17234. function generateTorso() {
  17235. var normal = new Vector3();
  17236. var vertex = new Vector3();
  17237. var groupCount = 0; // this will be used to calculate the normal
  17238. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17239. for (var y = 0; y <= heightSegments; y++) {
  17240. var indexRow = [];
  17241. var v = y / heightSegments; // calculate the radius of the current row
  17242. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17243. for (var x = 0; x <= radialSegments; x++) {
  17244. var u = x / radialSegments;
  17245. var theta = u * thetaLength + thetaStart;
  17246. var sinTheta = Math.sin(theta);
  17247. var cosTheta = Math.cos(theta); // vertex
  17248. vertex.x = radius * sinTheta;
  17249. vertex.y = -v * height + halfHeight;
  17250. vertex.z = radius * cosTheta;
  17251. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17252. normal.set(sinTheta, slope, cosTheta).normalize();
  17253. normals.push(normal.x, normal.y, normal.z); // uv
  17254. uvs.push(u, 1 - v); // save index of vertex in respective row
  17255. indexRow.push(index++);
  17256. } // now save vertices of the row in our index array
  17257. indexArray.push(indexRow);
  17258. } // generate indices
  17259. for (var _x = 0; _x < radialSegments; _x++) {
  17260. for (var _y = 0; _y < heightSegments; _y++) {
  17261. // we use the index array to access the correct indices
  17262. var a = indexArray[_y][_x];
  17263. var b = indexArray[_y + 1][_x];
  17264. var c = indexArray[_y + 1][_x + 1];
  17265. var d = indexArray[_y][_x + 1]; // faces
  17266. indices.push(a, b, d);
  17267. indices.push(b, c, d); // update group counter
  17268. groupCount += 6;
  17269. }
  17270. } // add a group to the geometry. this will ensure multi material support
  17271. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17272. groupStart += groupCount;
  17273. }
  17274. function generateCap(top) {
  17275. // save the index of the first center vertex
  17276. var centerIndexStart = index;
  17277. var uv = new Vector2();
  17278. var vertex = new Vector3();
  17279. var groupCount = 0;
  17280. var radius = top === true ? radiusTop : radiusBottom;
  17281. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17282. // because the geometry needs one set of uvs per face,
  17283. // we must generate a center vertex per face/segment
  17284. for (var x = 1; x <= radialSegments; x++) {
  17285. // vertex
  17286. vertices.push(0, halfHeight * sign, 0); // normal
  17287. normals.push(0, sign, 0); // uv
  17288. uvs.push(0.5, 0.5); // increase index
  17289. index++;
  17290. } // save the index of the last center vertex
  17291. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17292. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17293. var u = _x2 / radialSegments;
  17294. var theta = u * thetaLength + thetaStart;
  17295. var cosTheta = Math.cos(theta);
  17296. var sinTheta = Math.sin(theta); // vertex
  17297. vertex.x = radius * sinTheta;
  17298. vertex.y = halfHeight * sign;
  17299. vertex.z = radius * cosTheta;
  17300. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17301. normals.push(0, sign, 0); // uv
  17302. uv.x = cosTheta * 0.5 + 0.5;
  17303. uv.y = sinTheta * 0.5 * sign + 0.5;
  17304. uvs.push(uv.x, uv.y); // increase index
  17305. index++;
  17306. } // generate indices
  17307. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17308. var c = centerIndexStart + _x3;
  17309. var i = centerIndexEnd + _x3;
  17310. if (top === true) {
  17311. // face top
  17312. indices.push(i, i + 1, c);
  17313. } else {
  17314. // face bottom
  17315. indices.push(i + 1, i, c);
  17316. }
  17317. groupCount += 3;
  17318. } // add a group to the geometry. this will ensure multi material support
  17319. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17320. groupStart += groupCount;
  17321. }
  17322. return _this;
  17323. }
  17324. return CylinderBufferGeometry;
  17325. }(BufferGeometry);
  17326. var CylinderGeometry = /*#__PURE__*/function (_Geometry) {
  17327. _inheritsLoose(CylinderGeometry, _Geometry);
  17328. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17329. var _this;
  17330. _this = _Geometry.call(this) || this;
  17331. _this.type = 'CylinderGeometry';
  17332. _this.parameters = {
  17333. radiusTop: radiusTop,
  17334. radiusBottom: radiusBottom,
  17335. height: height,
  17336. radialSegments: radialSegments,
  17337. heightSegments: heightSegments,
  17338. openEnded: openEnded,
  17339. thetaStart: thetaStart,
  17340. thetaLength: thetaLength
  17341. };
  17342. _this.fromBufferGeometry(new CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength));
  17343. _this.mergeVertices();
  17344. return _this;
  17345. }
  17346. return CylinderGeometry;
  17347. }(Geometry);
  17348. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17349. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17350. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17351. var _this;
  17352. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17353. _this.type = 'ConeGeometry';
  17354. _this.parameters = {
  17355. radius: radius,
  17356. height: height,
  17357. radialSegments: radialSegments,
  17358. heightSegments: heightSegments,
  17359. openEnded: openEnded,
  17360. thetaStart: thetaStart,
  17361. thetaLength: thetaLength
  17362. };
  17363. return _this;
  17364. }
  17365. return ConeGeometry;
  17366. }(CylinderGeometry);
  17367. var ConeBufferGeometry = /*#__PURE__*/function (_CylinderBufferGeomet) {
  17368. _inheritsLoose(ConeBufferGeometry, _CylinderBufferGeomet);
  17369. function ConeBufferGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17370. var _this;
  17371. _this = _CylinderBufferGeomet.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17372. _this.type = 'ConeBufferGeometry';
  17373. _this.parameters = {
  17374. radius: radius,
  17375. height: height,
  17376. radialSegments: radialSegments,
  17377. heightSegments: heightSegments,
  17378. openEnded: openEnded,
  17379. thetaStart: thetaStart,
  17380. thetaLength: thetaLength
  17381. };
  17382. return _this;
  17383. }
  17384. return ConeBufferGeometry;
  17385. }(CylinderBufferGeometry);
  17386. var PolyhedronBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17387. _inheritsLoose(PolyhedronBufferGeometry, _BufferGeometry);
  17388. function PolyhedronBufferGeometry(vertices, indices, radius, detail) {
  17389. var _this;
  17390. _this = _BufferGeometry.call(this) || this;
  17391. _this.type = 'PolyhedronBufferGeometry';
  17392. _this.parameters = {
  17393. vertices: vertices,
  17394. indices: indices,
  17395. radius: radius,
  17396. detail: detail
  17397. };
  17398. radius = radius || 1;
  17399. detail = detail || 0; // default buffer data
  17400. var vertexBuffer = [];
  17401. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17402. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17403. applyRadius(radius); // finally, create the uv data
  17404. generateUVs(); // build non-indexed geometry
  17405. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17406. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17407. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17408. if (detail === 0) {
  17409. _this.computeVertexNormals(); // flat normals
  17410. } else {
  17411. _this.normalizeNormals(); // smooth normals
  17412. } // helper functions
  17413. function subdivide(detail) {
  17414. var a = new Vector3();
  17415. var b = new Vector3();
  17416. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17417. for (var i = 0; i < indices.length; i += 3) {
  17418. // get the vertices of the face
  17419. getVertexByIndex(indices[i + 0], a);
  17420. getVertexByIndex(indices[i + 1], b);
  17421. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17422. subdivideFace(a, b, c, detail);
  17423. }
  17424. }
  17425. function subdivideFace(a, b, c, detail) {
  17426. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17427. var v = []; // construct all of the vertices for this subdivision
  17428. for (var i = 0; i <= cols; i++) {
  17429. v[i] = [];
  17430. var aj = a.clone().lerp(c, i / cols);
  17431. var bj = b.clone().lerp(c, i / cols);
  17432. var rows = cols - i;
  17433. for (var j = 0; j <= rows; j++) {
  17434. if (j === 0 && i === cols) {
  17435. v[i][j] = aj;
  17436. } else {
  17437. v[i][j] = aj.clone().lerp(bj, j / rows);
  17438. }
  17439. }
  17440. } // construct all of the faces
  17441. for (var _i = 0; _i < cols; _i++) {
  17442. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17443. var k = Math.floor(_j / 2);
  17444. if (_j % 2 === 0) {
  17445. pushVertex(v[_i][k + 1]);
  17446. pushVertex(v[_i + 1][k]);
  17447. pushVertex(v[_i][k]);
  17448. } else {
  17449. pushVertex(v[_i][k + 1]);
  17450. pushVertex(v[_i + 1][k + 1]);
  17451. pushVertex(v[_i + 1][k]);
  17452. }
  17453. }
  17454. }
  17455. }
  17456. function applyRadius(radius) {
  17457. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17458. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17459. vertex.x = vertexBuffer[i + 0];
  17460. vertex.y = vertexBuffer[i + 1];
  17461. vertex.z = vertexBuffer[i + 2];
  17462. vertex.normalize().multiplyScalar(radius);
  17463. vertexBuffer[i + 0] = vertex.x;
  17464. vertexBuffer[i + 1] = vertex.y;
  17465. vertexBuffer[i + 2] = vertex.z;
  17466. }
  17467. }
  17468. function generateUVs() {
  17469. var vertex = new Vector3();
  17470. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17471. vertex.x = vertexBuffer[i + 0];
  17472. vertex.y = vertexBuffer[i + 1];
  17473. vertex.z = vertexBuffer[i + 2];
  17474. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17475. var v = inclination(vertex) / Math.PI + 0.5;
  17476. uvBuffer.push(u, 1 - v);
  17477. }
  17478. correctUVs();
  17479. correctSeam();
  17480. }
  17481. function correctSeam() {
  17482. // handle case when face straddles the seam, see #3269
  17483. for (var i = 0; i < uvBuffer.length; i += 6) {
  17484. // uv data of a single face
  17485. var x0 = uvBuffer[i + 0];
  17486. var x1 = uvBuffer[i + 2];
  17487. var x2 = uvBuffer[i + 4];
  17488. var max = Math.max(x0, x1, x2);
  17489. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17490. if (max > 0.9 && min < 0.1) {
  17491. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17492. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17493. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17494. }
  17495. }
  17496. }
  17497. function pushVertex(vertex) {
  17498. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17499. }
  17500. function getVertexByIndex(index, vertex) {
  17501. var stride = index * 3;
  17502. vertex.x = vertices[stride + 0];
  17503. vertex.y = vertices[stride + 1];
  17504. vertex.z = vertices[stride + 2];
  17505. }
  17506. function correctUVs() {
  17507. var a = new Vector3();
  17508. var b = new Vector3();
  17509. var c = new Vector3();
  17510. var centroid = new Vector3();
  17511. var uvA = new Vector2();
  17512. var uvB = new Vector2();
  17513. var uvC = new Vector2();
  17514. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17515. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17516. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17517. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17518. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17519. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17520. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17521. centroid.copy(a).add(b).add(c).divideScalar(3);
  17522. var azi = azimuth(centroid);
  17523. correctUV(uvA, j + 0, a, azi);
  17524. correctUV(uvB, j + 2, b, azi);
  17525. correctUV(uvC, j + 4, c, azi);
  17526. }
  17527. }
  17528. function correctUV(uv, stride, vector, azimuth) {
  17529. if (azimuth < 0 && uv.x === 1) {
  17530. uvBuffer[stride] = uv.x - 1;
  17531. }
  17532. if (vector.x === 0 && vector.z === 0) {
  17533. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17534. }
  17535. } // Angle around the Y axis, counter-clockwise when looking from above.
  17536. function azimuth(vector) {
  17537. return Math.atan2(vector.z, -vector.x);
  17538. } // Angle above the XZ plane.
  17539. function inclination(vector) {
  17540. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17541. }
  17542. return _this;
  17543. }
  17544. return PolyhedronBufferGeometry;
  17545. }(BufferGeometry);
  17546. var DodecahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  17547. _inheritsLoose(DodecahedronBufferGeometry, _PolyhedronBufferGeom);
  17548. function DodecahedronBufferGeometry(radius, detail) {
  17549. var _this;
  17550. var t = (1 + Math.sqrt(5)) / 2;
  17551. var r = 1 / t;
  17552. var vertices = [// (±1, ±1, ±1)
  17553. -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/φ, ±φ)
  17554. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17555. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17556. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17557. 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];
  17558. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  17559. _this.type = 'DodecahedronBufferGeometry';
  17560. _this.parameters = {
  17561. radius: radius,
  17562. detail: detail
  17563. };
  17564. return _this;
  17565. }
  17566. return DodecahedronBufferGeometry;
  17567. }(PolyhedronBufferGeometry);
  17568. var DodecahedronGeometry = /*#__PURE__*/function (_Geometry) {
  17569. _inheritsLoose(DodecahedronGeometry, _Geometry);
  17570. function DodecahedronGeometry(radius, detail) {
  17571. var _this;
  17572. _this = _Geometry.call(this) || this;
  17573. _this.type = 'DodecahedronGeometry';
  17574. _this.parameters = {
  17575. radius: radius,
  17576. detail: detail
  17577. };
  17578. _this.fromBufferGeometry(new DodecahedronBufferGeometry(radius, detail));
  17579. _this.mergeVertices();
  17580. return _this;
  17581. }
  17582. return DodecahedronGeometry;
  17583. }(Geometry);
  17584. var _v0$2 = new Vector3();
  17585. var _v1$5 = new Vector3();
  17586. var _normal$1 = new Vector3();
  17587. var _triangle = new Triangle();
  17588. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17589. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17590. function EdgesGeometry(geometry, thresholdAngle) {
  17591. var _this;
  17592. _this = _BufferGeometry.call(this) || this;
  17593. _this.type = 'EdgesGeometry';
  17594. _this.parameters = {
  17595. thresholdAngle: thresholdAngle
  17596. };
  17597. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17598. if (geometry.isGeometry) {
  17599. geometry = new BufferGeometry().fromGeometry(geometry);
  17600. }
  17601. var precisionPoints = 4;
  17602. var precision = Math.pow(10, precisionPoints);
  17603. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17604. var indexAttr = geometry.getIndex();
  17605. var positionAttr = geometry.getAttribute('position');
  17606. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17607. var indexArr = [0, 0, 0];
  17608. var vertKeys = ['a', 'b', 'c'];
  17609. var hashes = new Array(3);
  17610. var edgeData = {};
  17611. var vertices = [];
  17612. for (var i = 0; i < indexCount; i += 3) {
  17613. if (indexAttr) {
  17614. indexArr[0] = indexAttr.getX(i);
  17615. indexArr[1] = indexAttr.getX(i + 1);
  17616. indexArr[2] = indexAttr.getX(i + 2);
  17617. } else {
  17618. indexArr[0] = i;
  17619. indexArr[1] = i + 1;
  17620. indexArr[2] = i + 2;
  17621. }
  17622. var a = _triangle.a,
  17623. b = _triangle.b,
  17624. c = _triangle.c;
  17625. a.fromBufferAttribute(positionAttr, indexArr[0]);
  17626. b.fromBufferAttribute(positionAttr, indexArr[1]);
  17627. c.fromBufferAttribute(positionAttr, indexArr[2]);
  17628. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  17629. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  17630. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  17631. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  17632. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  17633. continue;
  17634. } // iterate over every edge
  17635. for (var j = 0; j < 3; j++) {
  17636. // get the first and next vertex making up the edge
  17637. var jNext = (j + 1) % 3;
  17638. var vecHash0 = hashes[j];
  17639. var vecHash1 = hashes[jNext];
  17640. var v0 = _triangle[vertKeys[j]];
  17641. var v1 = _triangle[vertKeys[jNext]];
  17642. var hash = vecHash0 + "_" + vecHash1;
  17643. var reverseHash = vecHash1 + "_" + vecHash0;
  17644. if (reverseHash in edgeData && edgeData[reverseHash]) {
  17645. // if we found a sibling edge add it into the vertex array if
  17646. // it meets the angle threshold and delete the edge from the map.
  17647. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  17648. vertices.push(v0.x, v0.y, v0.z);
  17649. vertices.push(v1.x, v1.y, v1.z);
  17650. }
  17651. edgeData[reverseHash] = null;
  17652. } else if (!(hash in edgeData)) {
  17653. // if we've already got an edge here then skip adding a new one
  17654. edgeData[hash] = {
  17655. index0: indexArr[j],
  17656. index1: indexArr[jNext],
  17657. normal: _normal$1.clone()
  17658. };
  17659. }
  17660. }
  17661. } // iterate over all remaining, unmatched edges and add them to the vertex array
  17662. for (var key in edgeData) {
  17663. if (edgeData[key]) {
  17664. var _edgeData$key = edgeData[key],
  17665. index0 = _edgeData$key.index0,
  17666. index1 = _edgeData$key.index1;
  17667. _v0$2.fromBufferAttribute(positionAttr, index0);
  17668. _v1$5.fromBufferAttribute(positionAttr, index1);
  17669. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  17670. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  17671. }
  17672. }
  17673. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17674. return _this;
  17675. }
  17676. return EdgesGeometry;
  17677. }(BufferGeometry);
  17678. /**
  17679. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17680. */
  17681. var Earcut = {
  17682. triangulate: function triangulate(data, holeIndices, dim) {
  17683. dim = dim || 2;
  17684. var hasHoles = holeIndices && holeIndices.length;
  17685. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  17686. var outerNode = linkedList(data, 0, outerLen, dim, true);
  17687. var triangles = [];
  17688. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  17689. var minX, minY, maxX, maxY, x, y, invSize;
  17690. 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
  17691. if (data.length > 80 * dim) {
  17692. minX = maxX = data[0];
  17693. minY = maxY = data[1];
  17694. for (var i = dim; i < outerLen; i += dim) {
  17695. x = data[i];
  17696. y = data[i + 1];
  17697. if (x < minX) minX = x;
  17698. if (y < minY) minY = y;
  17699. if (x > maxX) maxX = x;
  17700. if (y > maxY) maxY = y;
  17701. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17702. invSize = Math.max(maxX - minX, maxY - minY);
  17703. invSize = invSize !== 0 ? 1 / invSize : 0;
  17704. }
  17705. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  17706. return triangles;
  17707. }
  17708. }; // create a circular doubly linked list from polygon points in the specified winding order
  17709. function linkedList(data, start, end, dim, clockwise) {
  17710. var i, last;
  17711. if (clockwise === signedArea(data, start, end, dim) > 0) {
  17712. for (i = start; i < end; i += dim) {
  17713. last = insertNode(i, data[i], data[i + 1], last);
  17714. }
  17715. } else {
  17716. for (i = end - dim; i >= start; i -= dim) {
  17717. last = insertNode(i, data[i], data[i + 1], last);
  17718. }
  17719. }
  17720. if (last && equals(last, last.next)) {
  17721. removeNode(last);
  17722. last = last.next;
  17723. }
  17724. return last;
  17725. } // eliminate colinear or duplicate points
  17726. function filterPoints(start, end) {
  17727. if (!start) return start;
  17728. if (!end) end = start;
  17729. var p = start,
  17730. again;
  17731. do {
  17732. again = false;
  17733. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  17734. removeNode(p);
  17735. p = end = p.prev;
  17736. if (p === p.next) break;
  17737. again = true;
  17738. } else {
  17739. p = p.next;
  17740. }
  17741. } while (again || p !== end);
  17742. return end;
  17743. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  17744. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  17745. if (!ear) return; // interlink polygon nodes in z-order
  17746. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  17747. var stop = ear,
  17748. prev,
  17749. next; // iterate through ears, slicing them one by one
  17750. while (ear.prev !== ear.next) {
  17751. prev = ear.prev;
  17752. next = ear.next;
  17753. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  17754. // cut off the triangle
  17755. triangles.push(prev.i / dim);
  17756. triangles.push(ear.i / dim);
  17757. triangles.push(next.i / dim);
  17758. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  17759. ear = next.next;
  17760. stop = next.next;
  17761. continue;
  17762. }
  17763. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  17764. if (ear === stop) {
  17765. // try filtering points and slicing again
  17766. if (!pass) {
  17767. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  17768. } else if (pass === 1) {
  17769. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  17770. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  17771. } else if (pass === 2) {
  17772. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  17773. }
  17774. break;
  17775. }
  17776. }
  17777. } // check whether a polygon node forms a valid ear with adjacent nodes
  17778. function isEar(ear) {
  17779. var a = ear.prev,
  17780. b = ear,
  17781. c = ear.next;
  17782. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17783. // now make sure we don't have other points inside the potential ear
  17784. var p = ear.next.next;
  17785. while (p !== ear.prev) {
  17786. 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;
  17787. p = p.next;
  17788. }
  17789. return true;
  17790. }
  17791. function isEarHashed(ear, minX, minY, invSize) {
  17792. var a = ear.prev,
  17793. b = ear,
  17794. c = ear.next;
  17795. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17796. // triangle bbox; min & max are calculated like this for speed
  17797. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  17798. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  17799. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  17800. 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;
  17801. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  17802. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  17803. var p = ear.prevZ,
  17804. n = ear.nextZ; // look for points inside the triangle in both directions
  17805. while (p && p.z >= minZ && n && n.z <= maxZ) {
  17806. 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;
  17807. p = p.prevZ;
  17808. 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;
  17809. n = n.nextZ;
  17810. } // look for remaining points in decreasing z-order
  17811. while (p && p.z >= minZ) {
  17812. 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;
  17813. p = p.prevZ;
  17814. } // look for remaining points in increasing z-order
  17815. while (n && n.z <= maxZ) {
  17816. 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;
  17817. n = n.nextZ;
  17818. }
  17819. return true;
  17820. } // go through all polygon nodes and cure small local self-intersections
  17821. function cureLocalIntersections(start, triangles, dim) {
  17822. var p = start;
  17823. do {
  17824. var a = p.prev,
  17825. b = p.next.next;
  17826. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  17827. triangles.push(a.i / dim);
  17828. triangles.push(p.i / dim);
  17829. triangles.push(b.i / dim); // remove two nodes involved
  17830. removeNode(p);
  17831. removeNode(p.next);
  17832. p = start = b;
  17833. }
  17834. p = p.next;
  17835. } while (p !== start);
  17836. return filterPoints(p);
  17837. } // try splitting polygon into two and triangulate them independently
  17838. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  17839. // look for a valid diagonal that divides the polygon into two
  17840. var a = start;
  17841. do {
  17842. var b = a.next.next;
  17843. while (b !== a.prev) {
  17844. if (a.i !== b.i && isValidDiagonal(a, b)) {
  17845. // split the polygon in two by the diagonal
  17846. var c = splitPolygon(a, b); // filter colinear points around the cuts
  17847. a = filterPoints(a, a.next);
  17848. c = filterPoints(c, c.next); // run earcut on each half
  17849. earcutLinked(a, triangles, dim, minX, minY, invSize);
  17850. earcutLinked(c, triangles, dim, minX, minY, invSize);
  17851. return;
  17852. }
  17853. b = b.next;
  17854. }
  17855. a = a.next;
  17856. } while (a !== start);
  17857. } // link every hole into the outer loop, producing a single-ring polygon without holes
  17858. function eliminateHoles(data, holeIndices, outerNode, dim) {
  17859. var queue = [];
  17860. var i, len, start, end, list;
  17861. for (i = 0, len = holeIndices.length; i < len; i++) {
  17862. start = holeIndices[i] * dim;
  17863. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  17864. list = linkedList(data, start, end, dim, false);
  17865. if (list === list.next) list.steiner = true;
  17866. queue.push(getLeftmost(list));
  17867. }
  17868. queue.sort(compareX); // process holes from left to right
  17869. for (i = 0; i < queue.length; i++) {
  17870. eliminateHole(queue[i], outerNode);
  17871. outerNode = filterPoints(outerNode, outerNode.next);
  17872. }
  17873. return outerNode;
  17874. }
  17875. function compareX(a, b) {
  17876. return a.x - b.x;
  17877. } // find a bridge between vertices that connects hole with an outer ring and and link it
  17878. function eliminateHole(hole, outerNode) {
  17879. outerNode = findHoleBridge(hole, outerNode);
  17880. if (outerNode) {
  17881. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  17882. filterPoints(outerNode, outerNode.next);
  17883. filterPoints(b, b.next);
  17884. }
  17885. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17886. function findHoleBridge(hole, outerNode) {
  17887. var p = outerNode;
  17888. var hx = hole.x;
  17889. var hy = hole.y;
  17890. var qx = -Infinity,
  17891. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  17892. // segment's endpoint with lesser x will be potential connection point
  17893. do {
  17894. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  17895. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  17896. if (x <= hx && x > qx) {
  17897. qx = x;
  17898. if (x === hx) {
  17899. if (hy === p.y) return p;
  17900. if (hy === p.next.y) return p.next;
  17901. }
  17902. m = p.x < p.next.x ? p : p.next;
  17903. }
  17904. }
  17905. p = p.next;
  17906. } while (p !== outerNode);
  17907. if (!m) return null;
  17908. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  17909. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17910. // if there are no points found, we have a valid connection;
  17911. // otherwise choose the point of the minimum angle with the ray as connection point
  17912. var stop = m,
  17913. mx = m.x,
  17914. my = m.y;
  17915. var tanMin = Infinity,
  17916. tan;
  17917. p = m;
  17918. do {
  17919. 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)) {
  17920. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  17921. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  17922. m = p;
  17923. tanMin = tan;
  17924. }
  17925. }
  17926. p = p.next;
  17927. } while (p !== stop);
  17928. return m;
  17929. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  17930. function sectorContainsSector(m, p) {
  17931. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  17932. } // interlink polygon nodes in z-order
  17933. function indexCurve(start, minX, minY, invSize) {
  17934. var p = start;
  17935. do {
  17936. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  17937. p.prevZ = p.prev;
  17938. p.nextZ = p.next;
  17939. p = p.next;
  17940. } while (p !== start);
  17941. p.prevZ.nextZ = null;
  17942. p.prevZ = null;
  17943. sortLinked(p);
  17944. } // Simon Tatham's linked list merge sort algorithm
  17945. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17946. function sortLinked(list) {
  17947. var i,
  17948. p,
  17949. q,
  17950. e,
  17951. tail,
  17952. numMerges,
  17953. pSize,
  17954. qSize,
  17955. inSize = 1;
  17956. do {
  17957. p = list;
  17958. list = null;
  17959. tail = null;
  17960. numMerges = 0;
  17961. while (p) {
  17962. numMerges++;
  17963. q = p;
  17964. pSize = 0;
  17965. for (i = 0; i < inSize; i++) {
  17966. pSize++;
  17967. q = q.nextZ;
  17968. if (!q) break;
  17969. }
  17970. qSize = inSize;
  17971. while (pSize > 0 || qSize > 0 && q) {
  17972. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  17973. e = p;
  17974. p = p.nextZ;
  17975. pSize--;
  17976. } else {
  17977. e = q;
  17978. q = q.nextZ;
  17979. qSize--;
  17980. }
  17981. if (tail) tail.nextZ = e;else list = e;
  17982. e.prevZ = tail;
  17983. tail = e;
  17984. }
  17985. p = q;
  17986. }
  17987. tail.nextZ = null;
  17988. inSize *= 2;
  17989. } while (numMerges > 1);
  17990. return list;
  17991. } // z-order of a point given coords and inverse of the longer side of data bbox
  17992. function zOrder(x, y, minX, minY, invSize) {
  17993. // coords are transformed into non-negative 15-bit integer range
  17994. x = 32767 * (x - minX) * invSize;
  17995. y = 32767 * (y - minY) * invSize;
  17996. x = (x | x << 8) & 0x00FF00FF;
  17997. x = (x | x << 4) & 0x0F0F0F0F;
  17998. x = (x | x << 2) & 0x33333333;
  17999. x = (x | x << 1) & 0x55555555;
  18000. y = (y | y << 8) & 0x00FF00FF;
  18001. y = (y | y << 4) & 0x0F0F0F0F;
  18002. y = (y | y << 2) & 0x33333333;
  18003. y = (y | y << 1) & 0x55555555;
  18004. return x | y << 1;
  18005. } // find the leftmost node of a polygon ring
  18006. function getLeftmost(start) {
  18007. var p = start,
  18008. leftmost = start;
  18009. do {
  18010. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18011. p = p.next;
  18012. } while (p !== start);
  18013. return leftmost;
  18014. } // check if a point lies within a convex triangle
  18015. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18016. 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;
  18017. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18018. function isValidDiagonal(a, b) {
  18019. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18020. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18021. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18022. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18023. } // signed area of a triangle
  18024. function area(p, q, r) {
  18025. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18026. } // check if two points are equal
  18027. function equals(p1, p2) {
  18028. return p1.x === p2.x && p1.y === p2.y;
  18029. } // check if two segments intersect
  18030. function intersects(p1, q1, p2, q2) {
  18031. var o1 = sign(area(p1, q1, p2));
  18032. var o2 = sign(area(p1, q1, q2));
  18033. var o3 = sign(area(p2, q2, p1));
  18034. var o4 = sign(area(p2, q2, q1));
  18035. if (o1 !== o2 && o3 !== o4) return true; // general case
  18036. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18037. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18038. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18039. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18040. return false;
  18041. } // for collinear points p, q, r, check if point q lies on segment pr
  18042. function onSegment(p, q, r) {
  18043. 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);
  18044. }
  18045. function sign(num) {
  18046. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18047. } // check if a polygon diagonal intersects any polygon segments
  18048. function intersectsPolygon(a, b) {
  18049. var p = a;
  18050. do {
  18051. 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;
  18052. p = p.next;
  18053. } while (p !== a);
  18054. return false;
  18055. } // check if a polygon diagonal is locally inside the polygon
  18056. function locallyInside(a, b) {
  18057. 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;
  18058. } // check if the middle point of a polygon diagonal is inside the polygon
  18059. function middleInside(a, b) {
  18060. var p = a,
  18061. inside = false;
  18062. var px = (a.x + b.x) / 2,
  18063. py = (a.y + b.y) / 2;
  18064. do {
  18065. 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;
  18066. p = p.next;
  18067. } while (p !== a);
  18068. return inside;
  18069. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18070. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18071. function splitPolygon(a, b) {
  18072. var a2 = new Node(a.i, a.x, a.y),
  18073. b2 = new Node(b.i, b.x, b.y),
  18074. an = a.next,
  18075. bp = b.prev;
  18076. a.next = b;
  18077. b.prev = a;
  18078. a2.next = an;
  18079. an.prev = a2;
  18080. b2.next = a2;
  18081. a2.prev = b2;
  18082. bp.next = b2;
  18083. b2.prev = bp;
  18084. return b2;
  18085. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18086. function insertNode(i, x, y, last) {
  18087. var p = new Node(i, x, y);
  18088. if (!last) {
  18089. p.prev = p;
  18090. p.next = p;
  18091. } else {
  18092. p.next = last.next;
  18093. p.prev = last;
  18094. last.next.prev = p;
  18095. last.next = p;
  18096. }
  18097. return p;
  18098. }
  18099. function removeNode(p) {
  18100. p.next.prev = p.prev;
  18101. p.prev.next = p.next;
  18102. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18103. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18104. }
  18105. function Node(i, x, y) {
  18106. // vertex index in coordinates array
  18107. this.i = i; // vertex coordinates
  18108. this.x = x;
  18109. this.y = y; // previous and next vertex nodes in a polygon ring
  18110. this.prev = null;
  18111. this.next = null; // z-order curve value
  18112. this.z = null; // previous and next nodes in z-order
  18113. this.prevZ = null;
  18114. this.nextZ = null; // indicates whether this is a steiner point
  18115. this.steiner = false;
  18116. }
  18117. function signedArea(data, start, end, dim) {
  18118. var sum = 0;
  18119. for (var i = start, j = end - dim; i < end; i += dim) {
  18120. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18121. j = i;
  18122. }
  18123. return sum;
  18124. }
  18125. var ShapeUtils = {
  18126. // calculate area of the contour polygon
  18127. area: function area(contour) {
  18128. var n = contour.length;
  18129. var a = 0.0;
  18130. for (var p = n - 1, q = 0; q < n; p = q++) {
  18131. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18132. }
  18133. return a * 0.5;
  18134. },
  18135. isClockWise: function isClockWise(pts) {
  18136. return ShapeUtils.area(pts) < 0;
  18137. },
  18138. triangulateShape: function triangulateShape(contour, holes) {
  18139. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18140. var holeIndices = []; // array of hole indices
  18141. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18142. removeDupEndPts(contour);
  18143. addContour(vertices, contour); //
  18144. var holeIndex = contour.length;
  18145. holes.forEach(removeDupEndPts);
  18146. for (var i = 0; i < holes.length; i++) {
  18147. holeIndices.push(holeIndex);
  18148. holeIndex += holes[i].length;
  18149. addContour(vertices, holes[i]);
  18150. } //
  18151. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18152. for (var _i = 0; _i < triangles.length; _i += 3) {
  18153. faces.push(triangles.slice(_i, _i + 3));
  18154. }
  18155. return faces;
  18156. }
  18157. };
  18158. function removeDupEndPts(points) {
  18159. var l = points.length;
  18160. if (l > 2 && points[l - 1].equals(points[0])) {
  18161. points.pop();
  18162. }
  18163. }
  18164. function addContour(vertices, contour) {
  18165. for (var i = 0; i < contour.length; i++) {
  18166. vertices.push(contour[i].x);
  18167. vertices.push(contour[i].y);
  18168. }
  18169. }
  18170. var ExtrudeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18171. _inheritsLoose(ExtrudeBufferGeometry, _BufferGeometry);
  18172. function ExtrudeBufferGeometry(shapes, options) {
  18173. var _this;
  18174. _this = _BufferGeometry.call(this) || this;
  18175. _this.type = 'ExtrudeBufferGeometry';
  18176. _this.parameters = {
  18177. shapes: shapes,
  18178. options: options
  18179. };
  18180. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18181. var scope = _assertThisInitialized(_this);
  18182. var verticesArray = [];
  18183. var uvArray = [];
  18184. for (var i = 0, l = shapes.length; i < l; i++) {
  18185. var shape = shapes[i];
  18186. addShape(shape);
  18187. } // build geometry
  18188. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18189. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18190. _this.computeVertexNormals(); // functions
  18191. function addShape(shape) {
  18192. var placeholder = []; // options
  18193. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18194. var steps = options.steps !== undefined ? options.steps : 1;
  18195. var depth = options.depth !== undefined ? options.depth : 100;
  18196. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18197. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18198. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18199. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18200. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18201. var extrudePath = options.extrudePath;
  18202. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18203. if (options.amount !== undefined) {
  18204. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18205. depth = options.amount;
  18206. } //
  18207. var extrudePts,
  18208. extrudeByPath = false;
  18209. var splineTube, binormal, normal, position2;
  18210. if (extrudePath) {
  18211. extrudePts = extrudePath.getSpacedPoints(steps);
  18212. extrudeByPath = true;
  18213. bevelEnabled = false; // bevels not supported for path extrusion
  18214. // SETUP TNB variables
  18215. // TODO1 - have a .isClosed in spline?
  18216. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18217. binormal = new Vector3();
  18218. normal = new Vector3();
  18219. position2 = new Vector3();
  18220. } // Safeguards if bevels are not enabled
  18221. if (!bevelEnabled) {
  18222. bevelSegments = 0;
  18223. bevelThickness = 0;
  18224. bevelSize = 0;
  18225. bevelOffset = 0;
  18226. } // Variables initialization
  18227. var shapePoints = shape.extractPoints(curveSegments);
  18228. var vertices = shapePoints.shape;
  18229. var holes = shapePoints.holes;
  18230. var reverse = !ShapeUtils.isClockWise(vertices);
  18231. if (reverse) {
  18232. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18233. for (var h = 0, hl = holes.length; h < hl; h++) {
  18234. var ahole = holes[h];
  18235. if (ShapeUtils.isClockWise(ahole)) {
  18236. holes[h] = ahole.reverse();
  18237. }
  18238. }
  18239. }
  18240. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18241. /* Vertices */
  18242. var contour = vertices; // vertices has all points but contour has only points of circumference
  18243. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18244. var _ahole = holes[_h];
  18245. vertices = vertices.concat(_ahole);
  18246. }
  18247. function scalePt2(pt, vec, size) {
  18248. if (!vec) console.error("THREE.ExtrudeGeometry: vec does not exist");
  18249. return vec.clone().multiplyScalar(size).add(pt);
  18250. }
  18251. var vlen = vertices.length,
  18252. flen = faces.length; // Find directions for point movement
  18253. function getBevelVec(inPt, inPrev, inNext) {
  18254. // computes for inPt the corresponding point inPt' on a new contour
  18255. // shifted by 1 unit (length of normalized vector) to the left
  18256. // if we walk along contour clockwise, this new contour is outside the old one
  18257. //
  18258. // inPt' is the intersection of the two lines parallel to the two
  18259. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18260. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18261. // good reading for geometry algorithms (here: line-line intersection)
  18262. // http://geomalgorithms.com/a05-_intersect-1.html
  18263. var v_prev_x = inPt.x - inPrev.x,
  18264. v_prev_y = inPt.y - inPrev.y;
  18265. var v_next_x = inNext.x - inPt.x,
  18266. v_next_y = inNext.y - inPt.y;
  18267. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18268. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18269. if (Math.abs(collinear0) > Number.EPSILON) {
  18270. // not collinear
  18271. // length of vectors for normalizing
  18272. var v_prev_len = Math.sqrt(v_prev_lensq);
  18273. 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
  18274. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18275. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18276. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18277. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18278. 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
  18279. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18280. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18281. // but prevent crazy spikes
  18282. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18283. if (v_trans_lensq <= 2) {
  18284. return new Vector2(v_trans_x, v_trans_y);
  18285. } else {
  18286. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18287. }
  18288. } else {
  18289. // handle special case of collinear edges
  18290. var direction_eq = false; // assumes: opposite
  18291. if (v_prev_x > Number.EPSILON) {
  18292. if (v_next_x > Number.EPSILON) {
  18293. direction_eq = true;
  18294. }
  18295. } else {
  18296. if (v_prev_x < -Number.EPSILON) {
  18297. if (v_next_x < -Number.EPSILON) {
  18298. direction_eq = true;
  18299. }
  18300. } else {
  18301. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18302. direction_eq = true;
  18303. }
  18304. }
  18305. }
  18306. if (direction_eq) {
  18307. // console.log("Warning: lines are a straight sequence");
  18308. v_trans_x = -v_prev_y;
  18309. v_trans_y = v_prev_x;
  18310. shrink_by = Math.sqrt(v_prev_lensq);
  18311. } else {
  18312. // console.log("Warning: lines are a straight spike");
  18313. v_trans_x = v_prev_x;
  18314. v_trans_y = v_prev_y;
  18315. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18316. }
  18317. }
  18318. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18319. }
  18320. var contourMovements = [];
  18321. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18322. if (j === il) j = 0;
  18323. if (k === il) k = 0; // (j)---(i)---(k)
  18324. // console.log('i,j,k', i, j , k)
  18325. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18326. }
  18327. var holesMovements = [];
  18328. var oneHoleMovements,
  18329. verticesMovements = contourMovements.concat();
  18330. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18331. var _ahole2 = holes[_h2];
  18332. oneHoleMovements = [];
  18333. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18334. if (_j === _il) _j = 0;
  18335. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18336. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18337. }
  18338. holesMovements.push(oneHoleMovements);
  18339. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18340. } // Loop bevelSegments, 1 for the front, 1 for the back
  18341. for (var b = 0; b < bevelSegments; b++) {
  18342. //for ( b = bevelSegments; b > 0; b -- ) {
  18343. var t = b / bevelSegments;
  18344. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18345. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18346. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18347. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18348. v(vert.x, vert.y, -z);
  18349. } // expand holes
  18350. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18351. var _ahole3 = holes[_h3];
  18352. oneHoleMovements = holesMovements[_h3];
  18353. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18354. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18355. v(_vert.x, _vert.y, -z);
  18356. }
  18357. }
  18358. }
  18359. var bs = bevelSize + bevelOffset; // Back facing vertices
  18360. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18361. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18362. if (!extrudeByPath) {
  18363. v(_vert2.x, _vert2.y, 0);
  18364. } else {
  18365. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18366. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18367. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18368. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18369. v(position2.x, position2.y, position2.z);
  18370. }
  18371. } // Add stepped vertices...
  18372. // Including front facing vertices
  18373. for (var s = 1; s <= steps; s++) {
  18374. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18375. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18376. if (!extrudeByPath) {
  18377. v(_vert3.x, _vert3.y, depth / steps * s);
  18378. } else {
  18379. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18380. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18381. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18382. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18383. v(position2.x, position2.y, position2.z);
  18384. }
  18385. }
  18386. } // Add bevel segments planes
  18387. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18388. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18389. var _t = _b / bevelSegments;
  18390. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18391. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18392. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18393. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18394. v(_vert4.x, _vert4.y, depth + _z);
  18395. } // expand holes
  18396. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18397. var _ahole4 = holes[_h4];
  18398. oneHoleMovements = holesMovements[_h4];
  18399. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18400. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18401. if (!extrudeByPath) {
  18402. v(_vert5.x, _vert5.y, depth + _z);
  18403. } else {
  18404. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18405. }
  18406. }
  18407. }
  18408. }
  18409. /* Faces */
  18410. // Top and bottom faces
  18411. buildLidFaces(); // Sides faces
  18412. buildSideFaces(); ///// Internal functions
  18413. function buildLidFaces() {
  18414. var start = verticesArray.length / 3;
  18415. if (bevelEnabled) {
  18416. var layer = 0; // steps + 1
  18417. var offset = vlen * layer; // Bottom faces
  18418. for (var _i9 = 0; _i9 < flen; _i9++) {
  18419. var face = faces[_i9];
  18420. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18421. }
  18422. layer = steps + bevelSegments * 2;
  18423. offset = vlen * layer; // Top faces
  18424. for (var _i10 = 0; _i10 < flen; _i10++) {
  18425. var _face = faces[_i10];
  18426. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18427. }
  18428. } else {
  18429. // Bottom faces
  18430. for (var _i11 = 0; _i11 < flen; _i11++) {
  18431. var _face2 = faces[_i11];
  18432. f3(_face2[2], _face2[1], _face2[0]);
  18433. } // Top faces
  18434. for (var _i12 = 0; _i12 < flen; _i12++) {
  18435. var _face3 = faces[_i12];
  18436. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18437. }
  18438. }
  18439. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18440. } // Create faces for the z-sides of the shape
  18441. function buildSideFaces() {
  18442. var start = verticesArray.length / 3;
  18443. var layeroffset = 0;
  18444. sidewalls(contour, layeroffset);
  18445. layeroffset += contour.length;
  18446. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18447. var _ahole5 = holes[_h5];
  18448. sidewalls(_ahole5, layeroffset); //, true
  18449. layeroffset += _ahole5.length;
  18450. }
  18451. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18452. }
  18453. function sidewalls(contour, layeroffset) {
  18454. var i = contour.length;
  18455. while (--i >= 0) {
  18456. var _j2 = i;
  18457. var _k2 = i - 1;
  18458. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18459. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18460. var slen1 = vlen * _s;
  18461. var slen2 = vlen * (_s + 1);
  18462. var a = layeroffset + _j2 + slen1,
  18463. _b2 = layeroffset + _k2 + slen1,
  18464. c = layeroffset + _k2 + slen2,
  18465. d = layeroffset + _j2 + slen2;
  18466. f4(a, _b2, c, d);
  18467. }
  18468. }
  18469. }
  18470. function v(x, y, z) {
  18471. placeholder.push(x);
  18472. placeholder.push(y);
  18473. placeholder.push(z);
  18474. }
  18475. function f3(a, b, c) {
  18476. addVertex(a);
  18477. addVertex(b);
  18478. addVertex(c);
  18479. var nextIndex = verticesArray.length / 3;
  18480. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18481. addUV(uvs[0]);
  18482. addUV(uvs[1]);
  18483. addUV(uvs[2]);
  18484. }
  18485. function f4(a, b, c, d) {
  18486. addVertex(a);
  18487. addVertex(b);
  18488. addVertex(d);
  18489. addVertex(b);
  18490. addVertex(c);
  18491. addVertex(d);
  18492. var nextIndex = verticesArray.length / 3;
  18493. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18494. addUV(uvs[0]);
  18495. addUV(uvs[1]);
  18496. addUV(uvs[3]);
  18497. addUV(uvs[1]);
  18498. addUV(uvs[2]);
  18499. addUV(uvs[3]);
  18500. }
  18501. function addVertex(index) {
  18502. verticesArray.push(placeholder[index * 3 + 0]);
  18503. verticesArray.push(placeholder[index * 3 + 1]);
  18504. verticesArray.push(placeholder[index * 3 + 2]);
  18505. }
  18506. function addUV(vector2) {
  18507. uvArray.push(vector2.x);
  18508. uvArray.push(vector2.y);
  18509. }
  18510. }
  18511. return _this;
  18512. }
  18513. var _proto = ExtrudeBufferGeometry.prototype;
  18514. _proto.toJSON = function toJSON() {
  18515. var data = BufferGeometry.prototype.toJSON.call(this);
  18516. var shapes = this.parameters.shapes;
  18517. var options = this.parameters.options;
  18518. return _toJSON(shapes, options, data);
  18519. };
  18520. return ExtrudeBufferGeometry;
  18521. }(BufferGeometry);
  18522. var WorldUVGenerator = {
  18523. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18524. var a_x = vertices[indexA * 3];
  18525. var a_y = vertices[indexA * 3 + 1];
  18526. var b_x = vertices[indexB * 3];
  18527. var b_y = vertices[indexB * 3 + 1];
  18528. var c_x = vertices[indexC * 3];
  18529. var c_y = vertices[indexC * 3 + 1];
  18530. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18531. },
  18532. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18533. var a_x = vertices[indexA * 3];
  18534. var a_y = vertices[indexA * 3 + 1];
  18535. var a_z = vertices[indexA * 3 + 2];
  18536. var b_x = vertices[indexB * 3];
  18537. var b_y = vertices[indexB * 3 + 1];
  18538. var b_z = vertices[indexB * 3 + 2];
  18539. var c_x = vertices[indexC * 3];
  18540. var c_y = vertices[indexC * 3 + 1];
  18541. var c_z = vertices[indexC * 3 + 2];
  18542. var d_x = vertices[indexD * 3];
  18543. var d_y = vertices[indexD * 3 + 1];
  18544. var d_z = vertices[indexD * 3 + 2];
  18545. if (Math.abs(a_y - b_y) < 0.01) {
  18546. 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)];
  18547. } else {
  18548. 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)];
  18549. }
  18550. }
  18551. };
  18552. function _toJSON(shapes, options, data) {
  18553. data.shapes = [];
  18554. if (Array.isArray(shapes)) {
  18555. for (var i = 0, l = shapes.length; i < l; i++) {
  18556. var shape = shapes[i];
  18557. data.shapes.push(shape.uuid);
  18558. }
  18559. } else {
  18560. data.shapes.push(shapes.uuid);
  18561. }
  18562. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18563. return data;
  18564. }
  18565. var ExtrudeGeometry = /*#__PURE__*/function (_Geometry) {
  18566. _inheritsLoose(ExtrudeGeometry, _Geometry);
  18567. function ExtrudeGeometry(shapes, options) {
  18568. var _this;
  18569. _this = _Geometry.call(this) || this;
  18570. _this.type = 'ExtrudeGeometry';
  18571. _this.parameters = {
  18572. shapes: shapes,
  18573. options: options
  18574. };
  18575. _this.fromBufferGeometry(new ExtrudeBufferGeometry(shapes, options));
  18576. _this.mergeVertices();
  18577. return _this;
  18578. }
  18579. var _proto = ExtrudeGeometry.prototype;
  18580. _proto.toJSON = function toJSON() {
  18581. var data = _Geometry.prototype.toJSON.call(this);
  18582. var shapes = this.parameters.shapes;
  18583. var options = this.parameters.options;
  18584. return _toJSON$1(shapes, options, data);
  18585. };
  18586. return ExtrudeGeometry;
  18587. }(Geometry);
  18588. function _toJSON$1(shapes, options, data) {
  18589. data.shapes = [];
  18590. if (Array.isArray(shapes)) {
  18591. for (var i = 0, l = shapes.length; i < l; i++) {
  18592. var shape = shapes[i];
  18593. data.shapes.push(shape.uuid);
  18594. }
  18595. } else {
  18596. data.shapes.push(shapes.uuid);
  18597. }
  18598. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18599. return data;
  18600. }
  18601. var IcosahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  18602. _inheritsLoose(IcosahedronBufferGeometry, _PolyhedronBufferGeom);
  18603. function IcosahedronBufferGeometry(radius, detail) {
  18604. var _this;
  18605. var t = (1 + Math.sqrt(5)) / 2;
  18606. 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];
  18607. 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];
  18608. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  18609. _this.type = 'IcosahedronBufferGeometry';
  18610. _this.parameters = {
  18611. radius: radius,
  18612. detail: detail
  18613. };
  18614. return _this;
  18615. }
  18616. return IcosahedronBufferGeometry;
  18617. }(PolyhedronBufferGeometry);
  18618. var IcosahedronGeometry = /*#__PURE__*/function (_Geometry) {
  18619. _inheritsLoose(IcosahedronGeometry, _Geometry);
  18620. function IcosahedronGeometry(radius, detail) {
  18621. var _this;
  18622. _this = _Geometry.call(this) || this;
  18623. _this.type = 'IcosahedronGeometry';
  18624. _this.parameters = {
  18625. radius: radius,
  18626. detail: detail
  18627. };
  18628. _this.fromBufferGeometry(new IcosahedronBufferGeometry(radius, detail));
  18629. _this.mergeVertices();
  18630. return _this;
  18631. }
  18632. return IcosahedronGeometry;
  18633. }(Geometry);
  18634. var LatheBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18635. _inheritsLoose(LatheBufferGeometry, _BufferGeometry);
  18636. function LatheBufferGeometry(points, segments, phiStart, phiLength) {
  18637. var _this;
  18638. _this = _BufferGeometry.call(this) || this;
  18639. _this.type = 'LatheBufferGeometry';
  18640. _this.parameters = {
  18641. points: points,
  18642. segments: segments,
  18643. phiStart: phiStart,
  18644. phiLength: phiLength
  18645. };
  18646. segments = Math.floor(segments) || 12;
  18647. phiStart = phiStart || 0;
  18648. phiLength = phiLength || Math.PI * 2; // clamp phiLength so it's in range of [ 0, 2PI ]
  18649. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  18650. var indices = [];
  18651. var vertices = [];
  18652. var uvs = []; // helper variables
  18653. var inverseSegments = 1.0 / segments;
  18654. var vertex = new Vector3();
  18655. var uv = new Vector2(); // generate vertices and uvs
  18656. for (var i = 0; i <= segments; i++) {
  18657. var phi = phiStart + i * inverseSegments * phiLength;
  18658. var sin = Math.sin(phi);
  18659. var cos = Math.cos(phi);
  18660. for (var j = 0; j <= points.length - 1; j++) {
  18661. // vertex
  18662. vertex.x = points[j].x * sin;
  18663. vertex.y = points[j].y;
  18664. vertex.z = points[j].x * cos;
  18665. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  18666. uv.x = i / segments;
  18667. uv.y = j / (points.length - 1);
  18668. uvs.push(uv.x, uv.y);
  18669. }
  18670. } // indices
  18671. for (var _i = 0; _i < segments; _i++) {
  18672. for (var _j = 0; _j < points.length - 1; _j++) {
  18673. var base = _j + _i * points.length;
  18674. var a = base;
  18675. var b = base + points.length;
  18676. var c = base + points.length + 1;
  18677. var d = base + 1; // faces
  18678. indices.push(a, b, d);
  18679. indices.push(b, c, d);
  18680. }
  18681. } // build geometry
  18682. _this.setIndex(indices);
  18683. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18684. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  18685. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  18686. // because the corresponding vertices are identical (but still have different UVs).
  18687. if (phiLength === Math.PI * 2) {
  18688. var normals = _this.attributes.normal.array;
  18689. var n1 = new Vector3();
  18690. var n2 = new Vector3();
  18691. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  18692. var _base = segments * points.length * 3;
  18693. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  18694. // select the normal of the vertex in the first line
  18695. n1.x = normals[_j2 + 0];
  18696. n1.y = normals[_j2 + 1];
  18697. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  18698. n2.x = normals[_base + _j2 + 0];
  18699. n2.y = normals[_base + _j2 + 1];
  18700. n2.z = normals[_base + _j2 + 2]; // average normals
  18701. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  18702. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  18703. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  18704. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  18705. }
  18706. }
  18707. return _this;
  18708. }
  18709. return LatheBufferGeometry;
  18710. }(BufferGeometry);
  18711. var LatheGeometry = /*#__PURE__*/function (_Geometry) {
  18712. _inheritsLoose(LatheGeometry, _Geometry);
  18713. function LatheGeometry(points, segments, phiStart, phiLength) {
  18714. var _this;
  18715. _this = _Geometry.call(this) || this;
  18716. _this.type = 'LatheGeometry';
  18717. _this.parameters = {
  18718. points: points,
  18719. segments: segments,
  18720. phiStart: phiStart,
  18721. phiLength: phiLength
  18722. };
  18723. _this.fromBufferGeometry(new LatheBufferGeometry(points, segments, phiStart, phiLength));
  18724. _this.mergeVertices();
  18725. return _this;
  18726. }
  18727. return LatheGeometry;
  18728. }(Geometry);
  18729. var OctahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  18730. _inheritsLoose(OctahedronBufferGeometry, _PolyhedronBufferGeom);
  18731. function OctahedronBufferGeometry(radius, detail) {
  18732. var _this;
  18733. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  18734. 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];
  18735. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  18736. _this.type = 'OctahedronBufferGeometry';
  18737. _this.parameters = {
  18738. radius: radius,
  18739. detail: detail
  18740. };
  18741. return _this;
  18742. }
  18743. return OctahedronBufferGeometry;
  18744. }(PolyhedronBufferGeometry);
  18745. var OctahedronGeometry = /*#__PURE__*/function (_Geometry) {
  18746. _inheritsLoose(OctahedronGeometry, _Geometry);
  18747. function OctahedronGeometry(radius, detail) {
  18748. var _this;
  18749. _this = _Geometry.call(this) || this;
  18750. _this.type = 'OctahedronGeometry';
  18751. _this.parameters = {
  18752. radius: radius,
  18753. detail: detail
  18754. };
  18755. _this.fromBufferGeometry(new OctahedronBufferGeometry(radius, detail));
  18756. _this.mergeVertices();
  18757. return _this;
  18758. }
  18759. return OctahedronGeometry;
  18760. }(Geometry);
  18761. /**
  18762. * Parametric Surfaces Geometry
  18763. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18764. */
  18765. function ParametricBufferGeometry(func, slices, stacks) {
  18766. BufferGeometry.call(this);
  18767. this.type = 'ParametricBufferGeometry';
  18768. this.parameters = {
  18769. func: func,
  18770. slices: slices,
  18771. stacks: stacks
  18772. }; // buffers
  18773. var indices = [];
  18774. var vertices = [];
  18775. var normals = [];
  18776. var uvs = [];
  18777. var EPS = 0.00001;
  18778. var normal = new Vector3();
  18779. var p0 = new Vector3(),
  18780. p1 = new Vector3();
  18781. var pu = new Vector3(),
  18782. pv = new Vector3();
  18783. if (func.length < 3) {
  18784. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  18785. } // generate vertices, normals and uvs
  18786. var sliceCount = slices + 1;
  18787. for (var i = 0; i <= stacks; i++) {
  18788. var v = i / stacks;
  18789. for (var j = 0; j <= slices; j++) {
  18790. var u = j / slices; // vertex
  18791. func(u, v, p0);
  18792. vertices.push(p0.x, p0.y, p0.z); // normal
  18793. // approximate tangent vectors via finite differences
  18794. if (u - EPS >= 0) {
  18795. func(u - EPS, v, p1);
  18796. pu.subVectors(p0, p1);
  18797. } else {
  18798. func(u + EPS, v, p1);
  18799. pu.subVectors(p1, p0);
  18800. }
  18801. if (v - EPS >= 0) {
  18802. func(u, v - EPS, p1);
  18803. pv.subVectors(p0, p1);
  18804. } else {
  18805. func(u, v + EPS, p1);
  18806. pv.subVectors(p1, p0);
  18807. } // cross product of tangent vectors returns surface normal
  18808. normal.crossVectors(pu, pv).normalize();
  18809. normals.push(normal.x, normal.y, normal.z); // uv
  18810. uvs.push(u, v);
  18811. }
  18812. } // generate indices
  18813. for (var _i = 0; _i < stacks; _i++) {
  18814. for (var _j = 0; _j < slices; _j++) {
  18815. var a = _i * sliceCount + _j;
  18816. var b = _i * sliceCount + _j + 1;
  18817. var c = (_i + 1) * sliceCount + _j + 1;
  18818. var d = (_i + 1) * sliceCount + _j; // faces one and two
  18819. indices.push(a, b, d);
  18820. indices.push(b, c, d);
  18821. }
  18822. } // build geometry
  18823. this.setIndex(indices);
  18824. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18825. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18826. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18827. }
  18828. ParametricBufferGeometry.prototype = Object.create(BufferGeometry.prototype);
  18829. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  18830. /**
  18831. * Parametric Surfaces Geometry
  18832. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18833. */
  18834. function ParametricGeometry(func, slices, stacks) {
  18835. Geometry.call(this);
  18836. this.type = 'ParametricGeometry';
  18837. this.parameters = {
  18838. func: func,
  18839. slices: slices,
  18840. stacks: stacks
  18841. };
  18842. this.fromBufferGeometry(new ParametricBufferGeometry(func, slices, stacks));
  18843. this.mergeVertices();
  18844. }
  18845. ParametricGeometry.prototype = Object.create(Geometry.prototype);
  18846. ParametricGeometry.prototype.constructor = ParametricGeometry;
  18847. var PlaneGeometry = /*#__PURE__*/function (_Geometry) {
  18848. _inheritsLoose(PlaneGeometry, _Geometry);
  18849. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  18850. var _this;
  18851. _this = _Geometry.call(this) || this;
  18852. _this.type = 'PlaneGeometry';
  18853. _this.parameters = {
  18854. width: width,
  18855. height: height,
  18856. widthSegments: widthSegments,
  18857. heightSegments: heightSegments
  18858. };
  18859. _this.fromBufferGeometry(new PlaneBufferGeometry(width, height, widthSegments, heightSegments));
  18860. _this.mergeVertices();
  18861. return _this;
  18862. }
  18863. return PlaneGeometry;
  18864. }(Geometry);
  18865. var PolyhedronGeometry = /*#__PURE__*/function (_Geometry) {
  18866. _inheritsLoose(PolyhedronGeometry, _Geometry);
  18867. function PolyhedronGeometry(vertices, indices, radius, detail) {
  18868. var _this;
  18869. _this = _Geometry.call(this) || this;
  18870. _this.type = 'PolyhedronGeometry';
  18871. _this.parameters = {
  18872. vertices: vertices,
  18873. indices: indices,
  18874. radius: radius,
  18875. detail: detail
  18876. };
  18877. _this.fromBufferGeometry(new PolyhedronBufferGeometry(vertices, indices, radius, detail));
  18878. _this.mergeVertices();
  18879. return _this;
  18880. }
  18881. return PolyhedronGeometry;
  18882. }(Geometry);
  18883. var RingBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18884. _inheritsLoose(RingBufferGeometry, _BufferGeometry);
  18885. function RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18886. var _this;
  18887. _this = _BufferGeometry.call(this) || this;
  18888. _this.type = 'RingBufferGeometry';
  18889. _this.parameters = {
  18890. innerRadius: innerRadius,
  18891. outerRadius: outerRadius,
  18892. thetaSegments: thetaSegments,
  18893. phiSegments: phiSegments,
  18894. thetaStart: thetaStart,
  18895. thetaLength: thetaLength
  18896. };
  18897. innerRadius = innerRadius || 0.5;
  18898. outerRadius = outerRadius || 1;
  18899. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18900. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18901. thetaSegments = thetaSegments !== undefined ? Math.max(3, thetaSegments) : 8;
  18902. phiSegments = phiSegments !== undefined ? Math.max(1, phiSegments) : 1; // buffers
  18903. var indices = [];
  18904. var vertices = [];
  18905. var normals = [];
  18906. var uvs = []; // some helper variables
  18907. var radius = innerRadius;
  18908. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  18909. var vertex = new Vector3();
  18910. var uv = new Vector2(); // generate vertices, normals and uvs
  18911. for (var j = 0; j <= phiSegments; j++) {
  18912. for (var i = 0; i <= thetaSegments; i++) {
  18913. // values are generate from the inside of the ring to the outside
  18914. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  18915. vertex.x = radius * Math.cos(segment);
  18916. vertex.y = radius * Math.sin(segment);
  18917. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  18918. normals.push(0, 0, 1); // uv
  18919. uv.x = (vertex.x / outerRadius + 1) / 2;
  18920. uv.y = (vertex.y / outerRadius + 1) / 2;
  18921. uvs.push(uv.x, uv.y);
  18922. } // increase the radius for next row of vertices
  18923. radius += radiusStep;
  18924. } // indices
  18925. for (var _j = 0; _j < phiSegments; _j++) {
  18926. var thetaSegmentLevel = _j * (thetaSegments + 1);
  18927. for (var _i = 0; _i < thetaSegments; _i++) {
  18928. var _segment = _i + thetaSegmentLevel;
  18929. var a = _segment;
  18930. var b = _segment + thetaSegments + 1;
  18931. var c = _segment + thetaSegments + 2;
  18932. var d = _segment + 1; // faces
  18933. indices.push(a, b, d);
  18934. indices.push(b, c, d);
  18935. }
  18936. } // build geometry
  18937. _this.setIndex(indices);
  18938. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18939. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18940. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18941. return _this;
  18942. }
  18943. return RingBufferGeometry;
  18944. }(BufferGeometry);
  18945. var RingGeometry = /*#__PURE__*/function (_Geometry) {
  18946. _inheritsLoose(RingGeometry, _Geometry);
  18947. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18948. var _this;
  18949. _this = _Geometry.call(this) || this;
  18950. _this.type = 'RingGeometry';
  18951. _this.parameters = {
  18952. innerRadius: innerRadius,
  18953. outerRadius: outerRadius,
  18954. thetaSegments: thetaSegments,
  18955. phiSegments: phiSegments,
  18956. thetaStart: thetaStart,
  18957. thetaLength: thetaLength
  18958. };
  18959. _this.fromBufferGeometry(new RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength));
  18960. _this.mergeVertices();
  18961. return _this;
  18962. }
  18963. return RingGeometry;
  18964. }(Geometry);
  18965. var ShapeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18966. _inheritsLoose(ShapeBufferGeometry, _BufferGeometry);
  18967. function ShapeBufferGeometry(shapes, curveSegments) {
  18968. var _this;
  18969. _this = _BufferGeometry.call(this) || this;
  18970. _this.type = 'ShapeBufferGeometry';
  18971. _this.parameters = {
  18972. shapes: shapes,
  18973. curveSegments: curveSegments
  18974. };
  18975. curveSegments = curveSegments || 12; // buffers
  18976. var indices = [];
  18977. var vertices = [];
  18978. var normals = [];
  18979. var uvs = []; // helper variables
  18980. var groupStart = 0;
  18981. var groupCount = 0; // allow single and array values for "shapes" parameter
  18982. if (Array.isArray(shapes) === false) {
  18983. addShape(shapes);
  18984. } else {
  18985. for (var i = 0; i < shapes.length; i++) {
  18986. addShape(shapes[i]);
  18987. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  18988. groupStart += groupCount;
  18989. groupCount = 0;
  18990. }
  18991. } // build geometry
  18992. _this.setIndex(indices);
  18993. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18994. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18995. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  18996. function addShape(shape) {
  18997. var indexOffset = vertices.length / 3;
  18998. var points = shape.extractPoints(curveSegments);
  18999. var shapeVertices = points.shape;
  19000. var shapeHoles = points.holes; // check direction of vertices
  19001. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  19002. shapeVertices = shapeVertices.reverse();
  19003. }
  19004. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  19005. var shapeHole = shapeHoles[_i];
  19006. if (ShapeUtils.isClockWise(shapeHole) === true) {
  19007. shapeHoles[_i] = shapeHole.reverse();
  19008. }
  19009. }
  19010. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  19011. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  19012. var _shapeHole = shapeHoles[_i2];
  19013. shapeVertices = shapeVertices.concat(_shapeHole);
  19014. } // vertices, normals, uvs
  19015. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  19016. var vertex = shapeVertices[_i3];
  19017. vertices.push(vertex.x, vertex.y, 0);
  19018. normals.push(0, 0, 1);
  19019. uvs.push(vertex.x, vertex.y); // world uvs
  19020. } // incides
  19021. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  19022. var face = faces[_i4];
  19023. var a = face[0] + indexOffset;
  19024. var b = face[1] + indexOffset;
  19025. var c = face[2] + indexOffset;
  19026. indices.push(a, b, c);
  19027. groupCount += 3;
  19028. }
  19029. }
  19030. return _this;
  19031. }
  19032. var _proto = ShapeBufferGeometry.prototype;
  19033. _proto.toJSON = function toJSON() {
  19034. var data = BufferGeometry.prototype.toJSON.call(this);
  19035. var shapes = this.parameters.shapes;
  19036. return _toJSON$2(shapes, data);
  19037. };
  19038. return ShapeBufferGeometry;
  19039. }(BufferGeometry);
  19040. function _toJSON$2(shapes, data) {
  19041. data.shapes = [];
  19042. if (Array.isArray(shapes)) {
  19043. for (var i = 0, l = shapes.length; i < l; i++) {
  19044. var shape = shapes[i];
  19045. data.shapes.push(shape.uuid);
  19046. }
  19047. } else {
  19048. data.shapes.push(shapes.uuid);
  19049. }
  19050. return data;
  19051. }
  19052. var ShapeGeometry = /*#__PURE__*/function (_Geometry) {
  19053. _inheritsLoose(ShapeGeometry, _Geometry);
  19054. function ShapeGeometry(shapes, curveSegments) {
  19055. var _this;
  19056. _this = _Geometry.call(this) || this;
  19057. _this.type = 'ShapeGeometry';
  19058. if (typeof curveSegments === 'object') {
  19059. console.warn('THREE.ShapeGeometry: Options parameter has been removed.');
  19060. curveSegments = curveSegments.curveSegments;
  19061. }
  19062. _this.parameters = {
  19063. shapes: shapes,
  19064. curveSegments: curveSegments
  19065. };
  19066. _this.fromBufferGeometry(new ShapeBufferGeometry(shapes, curveSegments));
  19067. _this.mergeVertices();
  19068. return _this;
  19069. }
  19070. var _proto = ShapeGeometry.prototype;
  19071. _proto.toJSON = function toJSON() {
  19072. var data = Geometry.prototype.toJSON.call(this);
  19073. var shapes = this.parameters.shapes;
  19074. return _toJSON$3(shapes, data);
  19075. };
  19076. return ShapeGeometry;
  19077. }(Geometry);
  19078. function _toJSON$3(shapes, data) {
  19079. data.shapes = [];
  19080. if (Array.isArray(shapes)) {
  19081. for (var i = 0, l = shapes.length; i < l; i++) {
  19082. var shape = shapes[i];
  19083. data.shapes.push(shape.uuid);
  19084. }
  19085. } else {
  19086. data.shapes.push(shapes.uuid);
  19087. }
  19088. return data;
  19089. }
  19090. var SphereBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19091. _inheritsLoose(SphereBufferGeometry, _BufferGeometry);
  19092. function SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19093. var _this;
  19094. _this = _BufferGeometry.call(this) || this;
  19095. _this.type = 'SphereBufferGeometry';
  19096. _this.parameters = {
  19097. radius: radius,
  19098. widthSegments: widthSegments,
  19099. heightSegments: heightSegments,
  19100. phiStart: phiStart,
  19101. phiLength: phiLength,
  19102. thetaStart: thetaStart,
  19103. thetaLength: thetaLength
  19104. };
  19105. radius = radius || 1;
  19106. widthSegments = Math.max(3, Math.floor(widthSegments) || 8);
  19107. heightSegments = Math.max(2, Math.floor(heightSegments) || 6);
  19108. phiStart = phiStart !== undefined ? phiStart : 0;
  19109. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19110. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19111. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19112. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19113. var index = 0;
  19114. var grid = [];
  19115. var vertex = new Vector3();
  19116. var normal = new Vector3(); // buffers
  19117. var indices = [];
  19118. var vertices = [];
  19119. var normals = [];
  19120. var uvs = []; // generate vertices, normals and uvs
  19121. for (var iy = 0; iy <= heightSegments; iy++) {
  19122. var verticesRow = [];
  19123. var v = iy / heightSegments; // special case for the poles
  19124. var uOffset = 0;
  19125. if (iy == 0 && thetaStart == 0) {
  19126. uOffset = 0.5 / widthSegments;
  19127. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19128. uOffset = -0.5 / widthSegments;
  19129. }
  19130. for (var ix = 0; ix <= widthSegments; ix++) {
  19131. var u = ix / widthSegments; // vertex
  19132. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19133. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19134. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19135. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19136. normal.copy(vertex).normalize();
  19137. normals.push(normal.x, normal.y, normal.z); // uv
  19138. uvs.push(u + uOffset, 1 - v);
  19139. verticesRow.push(index++);
  19140. }
  19141. grid.push(verticesRow);
  19142. } // indices
  19143. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19144. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19145. var a = grid[_iy][_ix + 1];
  19146. var b = grid[_iy][_ix];
  19147. var c = grid[_iy + 1][_ix];
  19148. var d = grid[_iy + 1][_ix + 1];
  19149. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19150. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19151. }
  19152. } // build geometry
  19153. _this.setIndex(indices);
  19154. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19155. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19156. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19157. return _this;
  19158. }
  19159. return SphereBufferGeometry;
  19160. }(BufferGeometry);
  19161. var SphereGeometry = /*#__PURE__*/function (_Geometry) {
  19162. _inheritsLoose(SphereGeometry, _Geometry);
  19163. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19164. var _this;
  19165. _this = _Geometry.call(this) || this;
  19166. _this.type = 'SphereGeometry';
  19167. _this.parameters = {
  19168. radius: radius,
  19169. widthSegments: widthSegments,
  19170. heightSegments: heightSegments,
  19171. phiStart: phiStart,
  19172. phiLength: phiLength,
  19173. thetaStart: thetaStart,
  19174. thetaLength: thetaLength
  19175. };
  19176. _this.fromBufferGeometry(new SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength));
  19177. _this.mergeVertices();
  19178. return _this;
  19179. }
  19180. return SphereGeometry;
  19181. }(Geometry);
  19182. var TetrahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  19183. _inheritsLoose(TetrahedronBufferGeometry, _PolyhedronBufferGeom);
  19184. function TetrahedronBufferGeometry(radius, detail) {
  19185. var _this;
  19186. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19187. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19188. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  19189. _this.type = 'TetrahedronBufferGeometry';
  19190. _this.parameters = {
  19191. radius: radius,
  19192. detail: detail
  19193. };
  19194. return _this;
  19195. }
  19196. return TetrahedronBufferGeometry;
  19197. }(PolyhedronBufferGeometry);
  19198. var TetrahedronGeometry = /*#__PURE__*/function (_Geometry) {
  19199. _inheritsLoose(TetrahedronGeometry, _Geometry);
  19200. function TetrahedronGeometry(radius, detail) {
  19201. var _this;
  19202. _this = _Geometry.call(this) || this;
  19203. _this.type = 'TetrahedronGeometry';
  19204. _this.parameters = {
  19205. radius: radius,
  19206. detail: detail
  19207. };
  19208. _this.fromBufferGeometry(new TetrahedronBufferGeometry(radius, detail));
  19209. _this.mergeVertices();
  19210. return _this;
  19211. }
  19212. return TetrahedronGeometry;
  19213. }(Geometry);
  19214. var TextBufferGeometry = /*#__PURE__*/function (_ExtrudeBufferGeometr) {
  19215. _inheritsLoose(TextBufferGeometry, _ExtrudeBufferGeometr);
  19216. function TextBufferGeometry(text, parameters) {
  19217. var _this;
  19218. parameters = parameters || {};
  19219. var font = parameters.font;
  19220. if (!(font && font.isFont)) {
  19221. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19222. return new BufferGeometry() || _assertThisInitialized(_this);
  19223. }
  19224. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19225. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19226. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19227. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19228. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19229. _this = _ExtrudeBufferGeometr.call(this, shapes, parameters) || this;
  19230. _this.type = 'TextBufferGeometry';
  19231. return _this;
  19232. }
  19233. return TextBufferGeometry;
  19234. }(ExtrudeBufferGeometry);
  19235. var TextGeometry = /*#__PURE__*/function (_Geometry) {
  19236. _inheritsLoose(TextGeometry, _Geometry);
  19237. function TextGeometry(text, parameters) {
  19238. var _this;
  19239. _this = _Geometry.call(this) || this;
  19240. _this.type = 'TextGeometry';
  19241. _this.parameters = {
  19242. text: text,
  19243. parameters: parameters
  19244. };
  19245. _this.fromBufferGeometry(new TextBufferGeometry(text, parameters));
  19246. _this.mergeVertices();
  19247. return _this;
  19248. }
  19249. return TextGeometry;
  19250. }(Geometry);
  19251. var TorusBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19252. _inheritsLoose(TorusBufferGeometry, _BufferGeometry);
  19253. function TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19254. var _this;
  19255. _this = _BufferGeometry.call(this) || this;
  19256. _this.type = 'TorusBufferGeometry';
  19257. _this.parameters = {
  19258. radius: radius,
  19259. tube: tube,
  19260. radialSegments: radialSegments,
  19261. tubularSegments: tubularSegments,
  19262. arc: arc
  19263. };
  19264. radius = radius || 1;
  19265. tube = tube || 0.4;
  19266. radialSegments = Math.floor(radialSegments) || 8;
  19267. tubularSegments = Math.floor(tubularSegments) || 6;
  19268. arc = arc || Math.PI * 2; // buffers
  19269. var indices = [];
  19270. var vertices = [];
  19271. var normals = [];
  19272. var uvs = []; // helper variables
  19273. var center = new Vector3();
  19274. var vertex = new Vector3();
  19275. var normal = new Vector3(); // generate vertices, normals and uvs
  19276. for (var j = 0; j <= radialSegments; j++) {
  19277. for (var i = 0; i <= tubularSegments; i++) {
  19278. var u = i / tubularSegments * arc;
  19279. var v = j / radialSegments * Math.PI * 2; // vertex
  19280. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19281. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19282. vertex.z = tube * Math.sin(v);
  19283. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19284. center.x = radius * Math.cos(u);
  19285. center.y = radius * Math.sin(u);
  19286. normal.subVectors(vertex, center).normalize();
  19287. normals.push(normal.x, normal.y, normal.z); // uv
  19288. uvs.push(i / tubularSegments);
  19289. uvs.push(j / radialSegments);
  19290. }
  19291. } // generate indices
  19292. for (var _j = 1; _j <= radialSegments; _j++) {
  19293. for (var _i = 1; _i <= tubularSegments; _i++) {
  19294. // indices
  19295. var a = (tubularSegments + 1) * _j + _i - 1;
  19296. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19297. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19298. var d = (tubularSegments + 1) * _j + _i; // faces
  19299. indices.push(a, b, d);
  19300. indices.push(b, c, d);
  19301. }
  19302. } // build geometry
  19303. _this.setIndex(indices);
  19304. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19305. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19306. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19307. return _this;
  19308. }
  19309. return TorusBufferGeometry;
  19310. }(BufferGeometry);
  19311. var TorusGeometry = /*#__PURE__*/function (_Geometry) {
  19312. _inheritsLoose(TorusGeometry, _Geometry);
  19313. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19314. var _this;
  19315. _this = _Geometry.call(this) || this;
  19316. _this.type = 'TorusGeometry';
  19317. _this.parameters = {
  19318. radius: radius,
  19319. tube: tube,
  19320. radialSegments: radialSegments,
  19321. tubularSegments: tubularSegments,
  19322. arc: arc
  19323. };
  19324. _this.fromBufferGeometry(new TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc));
  19325. _this.mergeVertices();
  19326. return _this;
  19327. }
  19328. return TorusGeometry;
  19329. }(Geometry);
  19330. var TorusKnotBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19331. _inheritsLoose(TorusKnotBufferGeometry, _BufferGeometry);
  19332. function TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19333. var _this;
  19334. _this = _BufferGeometry.call(this) || this;
  19335. _this.type = 'TorusKnotBufferGeometry';
  19336. _this.parameters = {
  19337. radius: radius,
  19338. tube: tube,
  19339. tubularSegments: tubularSegments,
  19340. radialSegments: radialSegments,
  19341. p: p,
  19342. q: q
  19343. };
  19344. radius = radius || 1;
  19345. tube = tube || 0.4;
  19346. tubularSegments = Math.floor(tubularSegments) || 64;
  19347. radialSegments = Math.floor(radialSegments) || 8;
  19348. p = p || 2;
  19349. q = q || 3; // buffers
  19350. var indices = [];
  19351. var vertices = [];
  19352. var normals = [];
  19353. var uvs = []; // helper variables
  19354. var vertex = new Vector3();
  19355. var normal = new Vector3();
  19356. var P1 = new Vector3();
  19357. var P2 = new Vector3();
  19358. var B = new Vector3();
  19359. var T = new Vector3();
  19360. var N = new Vector3(); // generate vertices, normals and uvs
  19361. for (var i = 0; i <= tubularSegments; ++i) {
  19362. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19363. 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.
  19364. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19365. calculatePositionOnCurve(u, p, q, radius, P1);
  19366. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19367. T.subVectors(P2, P1);
  19368. N.addVectors(P2, P1);
  19369. B.crossVectors(T, N);
  19370. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19371. B.normalize();
  19372. N.normalize();
  19373. for (var j = 0; j <= radialSegments; ++j) {
  19374. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19375. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19376. var v = j / radialSegments * Math.PI * 2;
  19377. var cx = -tube * Math.cos(v);
  19378. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19379. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19380. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19381. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19382. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19383. 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)
  19384. normal.subVectors(vertex, P1).normalize();
  19385. normals.push(normal.x, normal.y, normal.z); // uv
  19386. uvs.push(i / tubularSegments);
  19387. uvs.push(j / radialSegments);
  19388. }
  19389. } // generate indices
  19390. for (var _j = 1; _j <= tubularSegments; _j++) {
  19391. for (var _i = 1; _i <= radialSegments; _i++) {
  19392. // indices
  19393. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19394. var b = (radialSegments + 1) * _j + (_i - 1);
  19395. var c = (radialSegments + 1) * _j + _i;
  19396. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19397. indices.push(a, b, d);
  19398. indices.push(b, c, d);
  19399. }
  19400. } // build geometry
  19401. _this.setIndex(indices);
  19402. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19403. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19404. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19405. function calculatePositionOnCurve(u, p, q, radius, position) {
  19406. var cu = Math.cos(u);
  19407. var su = Math.sin(u);
  19408. var quOverP = q / p * u;
  19409. var cs = Math.cos(quOverP);
  19410. position.x = radius * (2 + cs) * 0.5 * cu;
  19411. position.y = radius * (2 + cs) * su * 0.5;
  19412. position.z = radius * Math.sin(quOverP) * 0.5;
  19413. }
  19414. return _this;
  19415. }
  19416. return TorusKnotBufferGeometry;
  19417. }(BufferGeometry);
  19418. var TorusKnotGeometry = /*#__PURE__*/function (_Geometry) {
  19419. _inheritsLoose(TorusKnotGeometry, _Geometry);
  19420. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q, heightScale) {
  19421. var _this;
  19422. _this = _Geometry.call(this) || this;
  19423. _this.type = 'TorusKnotGeometry';
  19424. _this.parameters = {
  19425. radius: radius,
  19426. tube: tube,
  19427. tubularSegments: tubularSegments,
  19428. radialSegments: radialSegments,
  19429. p: p,
  19430. q: q
  19431. };
  19432. if (heightScale !== undefined) console.warn('THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.');
  19433. _this.fromBufferGeometry(new TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q));
  19434. _this.mergeVertices();
  19435. return _this;
  19436. }
  19437. return TorusKnotGeometry;
  19438. }(Geometry);
  19439. var TubeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19440. _inheritsLoose(TubeBufferGeometry, _BufferGeometry);
  19441. function TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19442. var _this;
  19443. _this = _BufferGeometry.call(this) || this;
  19444. _this.type = 'TubeBufferGeometry';
  19445. _this.parameters = {
  19446. path: path,
  19447. tubularSegments: tubularSegments,
  19448. radius: radius,
  19449. radialSegments: radialSegments,
  19450. closed: closed
  19451. };
  19452. tubularSegments = tubularSegments || 64;
  19453. radius = radius || 1;
  19454. radialSegments = radialSegments || 8;
  19455. closed = closed || false;
  19456. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19457. _this.tangents = frames.tangents;
  19458. _this.normals = frames.normals;
  19459. _this.binormals = frames.binormals; // helper variables
  19460. var vertex = new Vector3();
  19461. var normal = new Vector3();
  19462. var uv = new Vector2();
  19463. var P = new Vector3(); // buffer
  19464. var vertices = [];
  19465. var normals = [];
  19466. var uvs = [];
  19467. var indices = []; // create buffer data
  19468. generateBufferData(); // build geometry
  19469. _this.setIndex(indices);
  19470. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19471. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19472. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19473. function generateBufferData() {
  19474. for (var i = 0; i < tubularSegments; i++) {
  19475. generateSegment(i);
  19476. } // if the geometry is not closed, generate the last row of vertices and normals
  19477. // at the regular position on the given path
  19478. //
  19479. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19480. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19481. // this makes it easy compute correct values for closed geometries
  19482. generateUVs(); // finally create faces
  19483. generateIndices();
  19484. }
  19485. function generateSegment(i) {
  19486. // we use getPointAt to sample evenly distributed points from the given path
  19487. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19488. var N = frames.normals[i];
  19489. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19490. for (var j = 0; j <= radialSegments; j++) {
  19491. var v = j / radialSegments * Math.PI * 2;
  19492. var sin = Math.sin(v);
  19493. var cos = -Math.cos(v); // normal
  19494. normal.x = cos * N.x + sin * B.x;
  19495. normal.y = cos * N.y + sin * B.y;
  19496. normal.z = cos * N.z + sin * B.z;
  19497. normal.normalize();
  19498. normals.push(normal.x, normal.y, normal.z); // vertex
  19499. vertex.x = P.x + radius * normal.x;
  19500. vertex.y = P.y + radius * normal.y;
  19501. vertex.z = P.z + radius * normal.z;
  19502. vertices.push(vertex.x, vertex.y, vertex.z);
  19503. }
  19504. }
  19505. function generateIndices() {
  19506. for (var j = 1; j <= tubularSegments; j++) {
  19507. for (var i = 1; i <= radialSegments; i++) {
  19508. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  19509. var b = (radialSegments + 1) * j + (i - 1);
  19510. var c = (radialSegments + 1) * j + i;
  19511. var d = (radialSegments + 1) * (j - 1) + i; // faces
  19512. indices.push(a, b, d);
  19513. indices.push(b, c, d);
  19514. }
  19515. }
  19516. }
  19517. function generateUVs() {
  19518. for (var i = 0; i <= tubularSegments; i++) {
  19519. for (var j = 0; j <= radialSegments; j++) {
  19520. uv.x = i / tubularSegments;
  19521. uv.y = j / radialSegments;
  19522. uvs.push(uv.x, uv.y);
  19523. }
  19524. }
  19525. }
  19526. return _this;
  19527. }
  19528. var _proto = TubeBufferGeometry.prototype;
  19529. _proto.toJSON = function toJSON() {
  19530. var data = BufferGeometry.prototype.toJSON.call(this);
  19531. data.path = this.parameters.path.toJSON();
  19532. return data;
  19533. };
  19534. return TubeBufferGeometry;
  19535. }(BufferGeometry);
  19536. var TubeGeometry = /*#__PURE__*/function (_Geometry) {
  19537. _inheritsLoose(TubeGeometry, _Geometry);
  19538. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed, taper) {
  19539. var _this;
  19540. _this = _Geometry.call(this) || this;
  19541. _this.type = 'TubeGeometry';
  19542. _this.parameters = {
  19543. path: path,
  19544. tubularSegments: tubularSegments,
  19545. radius: radius,
  19546. radialSegments: radialSegments,
  19547. closed: closed
  19548. };
  19549. if (taper !== undefined) console.warn('THREE.TubeGeometry: taper has been removed.');
  19550. var bufferGeometry = new TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed); // expose internals
  19551. _this.tangents = bufferGeometry.tangents;
  19552. _this.normals = bufferGeometry.normals;
  19553. _this.binormals = bufferGeometry.binormals; // create geometry
  19554. _this.fromBufferGeometry(bufferGeometry);
  19555. _this.mergeVertices();
  19556. return _this;
  19557. }
  19558. return TubeGeometry;
  19559. }(Geometry);
  19560. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19561. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  19562. function WireframeGeometry(geometry) {
  19563. var _this;
  19564. _this = _BufferGeometry.call(this) || this;
  19565. _this.type = 'WireframeGeometry'; // buffer
  19566. var vertices = []; // helper variables
  19567. var edge = [0, 0],
  19568. edges = {};
  19569. var keys = ['a', 'b', 'c']; // different logic for Geometry and BufferGeometry
  19570. if (geometry && geometry.isGeometry) {
  19571. // create a data structure that contains all edges without duplicates
  19572. var faces = geometry.faces;
  19573. for (var i = 0, l = faces.length; i < l; i++) {
  19574. var face = faces[i];
  19575. for (var j = 0; j < 3; j++) {
  19576. var edge1 = face[keys[j]];
  19577. var edge2 = face[keys[(j + 1) % 3]];
  19578. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  19579. edge[1] = Math.max(edge1, edge2);
  19580. var key = edge[0] + ',' + edge[1];
  19581. if (edges[key] === undefined) {
  19582. edges[key] = {
  19583. index1: edge[0],
  19584. index2: edge[1]
  19585. };
  19586. }
  19587. }
  19588. } // generate vertices
  19589. for (var _key in edges) {
  19590. var e = edges[_key];
  19591. var vertex = geometry.vertices[e.index1];
  19592. vertices.push(vertex.x, vertex.y, vertex.z);
  19593. vertex = geometry.vertices[e.index2];
  19594. vertices.push(vertex.x, vertex.y, vertex.z);
  19595. }
  19596. } else if (geometry && geometry.isBufferGeometry) {
  19597. var _vertex = new Vector3();
  19598. if (geometry.index !== null) {
  19599. // indexed BufferGeometry
  19600. var position = geometry.attributes.position;
  19601. var indices = geometry.index;
  19602. var groups = geometry.groups;
  19603. if (groups.length === 0) {
  19604. groups = [{
  19605. start: 0,
  19606. count: indices.count,
  19607. materialIndex: 0
  19608. }];
  19609. } // create a data structure that contains all eges without duplicates
  19610. for (var o = 0, ol = groups.length; o < ol; ++o) {
  19611. var group = groups[o];
  19612. var start = group.start;
  19613. var count = group.count;
  19614. for (var _i = start, _l = start + count; _i < _l; _i += 3) {
  19615. for (var _j = 0; _j < 3; _j++) {
  19616. var _edge = indices.getX(_i + _j);
  19617. var _edge2 = indices.getX(_i + (_j + 1) % 3);
  19618. edge[0] = Math.min(_edge, _edge2); // sorting prevents duplicates
  19619. edge[1] = Math.max(_edge, _edge2);
  19620. var _key2 = edge[0] + ',' + edge[1];
  19621. if (edges[_key2] === undefined) {
  19622. edges[_key2] = {
  19623. index1: edge[0],
  19624. index2: edge[1]
  19625. };
  19626. }
  19627. }
  19628. }
  19629. } // generate vertices
  19630. for (var _key3 in edges) {
  19631. var _e = edges[_key3];
  19632. _vertex.fromBufferAttribute(position, _e.index1);
  19633. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19634. _vertex.fromBufferAttribute(position, _e.index2);
  19635. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19636. }
  19637. } else {
  19638. // non-indexed BufferGeometry
  19639. var _position = geometry.attributes.position;
  19640. for (var _i2 = 0, _l2 = _position.count / 3; _i2 < _l2; _i2++) {
  19641. for (var _j2 = 0; _j2 < 3; _j2++) {
  19642. // three edges per triangle, an edge is represented as (index1, index2)
  19643. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  19644. var index1 = 3 * _i2 + _j2;
  19645. _vertex.fromBufferAttribute(_position, index1);
  19646. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19647. var index2 = 3 * _i2 + (_j2 + 1) % 3;
  19648. _vertex.fromBufferAttribute(_position, index2);
  19649. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19650. }
  19651. }
  19652. }
  19653. } // build geometry
  19654. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19655. return _this;
  19656. }
  19657. return WireframeGeometry;
  19658. }(BufferGeometry);
  19659. var Geometries = /*#__PURE__*/Object.freeze({
  19660. __proto__: null,
  19661. BoxGeometry: BoxGeometry,
  19662. BoxBufferGeometry: BoxBufferGeometry,
  19663. CircleGeometry: CircleGeometry,
  19664. CircleBufferGeometry: CircleBufferGeometry,
  19665. ConeGeometry: ConeGeometry,
  19666. ConeBufferGeometry: ConeBufferGeometry,
  19667. CylinderGeometry: CylinderGeometry,
  19668. CylinderBufferGeometry: CylinderBufferGeometry,
  19669. DodecahedronGeometry: DodecahedronGeometry,
  19670. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  19671. EdgesGeometry: EdgesGeometry,
  19672. ExtrudeGeometry: ExtrudeGeometry,
  19673. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  19674. IcosahedronGeometry: IcosahedronGeometry,
  19675. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  19676. LatheGeometry: LatheGeometry,
  19677. LatheBufferGeometry: LatheBufferGeometry,
  19678. OctahedronGeometry: OctahedronGeometry,
  19679. OctahedronBufferGeometry: OctahedronBufferGeometry,
  19680. ParametricGeometry: ParametricGeometry,
  19681. ParametricBufferGeometry: ParametricBufferGeometry,
  19682. PlaneGeometry: PlaneGeometry,
  19683. PlaneBufferGeometry: PlaneBufferGeometry,
  19684. PolyhedronGeometry: PolyhedronGeometry,
  19685. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  19686. RingGeometry: RingGeometry,
  19687. RingBufferGeometry: RingBufferGeometry,
  19688. ShapeGeometry: ShapeGeometry,
  19689. ShapeBufferGeometry: ShapeBufferGeometry,
  19690. SphereGeometry: SphereGeometry,
  19691. SphereBufferGeometry: SphereBufferGeometry,
  19692. TetrahedronGeometry: TetrahedronGeometry,
  19693. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  19694. TextGeometry: TextGeometry,
  19695. TextBufferGeometry: TextBufferGeometry,
  19696. TorusGeometry: TorusGeometry,
  19697. TorusBufferGeometry: TorusBufferGeometry,
  19698. TorusKnotGeometry: TorusKnotGeometry,
  19699. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  19700. TubeGeometry: TubeGeometry,
  19701. TubeBufferGeometry: TubeBufferGeometry,
  19702. WireframeGeometry: WireframeGeometry
  19703. });
  19704. /**
  19705. * parameters = {
  19706. * color: <THREE.Color>
  19707. * }
  19708. */
  19709. function ShadowMaterial(parameters) {
  19710. Material.call(this);
  19711. this.type = 'ShadowMaterial';
  19712. this.color = new Color(0x000000);
  19713. this.transparent = true;
  19714. this.setValues(parameters);
  19715. }
  19716. ShadowMaterial.prototype = Object.create(Material.prototype);
  19717. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19718. ShadowMaterial.prototype.isShadowMaterial = true;
  19719. ShadowMaterial.prototype.copy = function (source) {
  19720. Material.prototype.copy.call(this, source);
  19721. this.color.copy(source.color);
  19722. return this;
  19723. };
  19724. function RawShaderMaterial(parameters) {
  19725. ShaderMaterial.call(this, parameters);
  19726. this.type = 'RawShaderMaterial';
  19727. }
  19728. RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
  19729. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19730. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19731. /**
  19732. * parameters = {
  19733. * color: <hex>,
  19734. * roughness: <float>,
  19735. * metalness: <float>,
  19736. * opacity: <float>,
  19737. *
  19738. * map: new THREE.Texture( <Image> ),
  19739. *
  19740. * lightMap: new THREE.Texture( <Image> ),
  19741. * lightMapIntensity: <float>
  19742. *
  19743. * aoMap: new THREE.Texture( <Image> ),
  19744. * aoMapIntensity: <float>
  19745. *
  19746. * emissive: <hex>,
  19747. * emissiveIntensity: <float>
  19748. * emissiveMap: new THREE.Texture( <Image> ),
  19749. *
  19750. * bumpMap: new THREE.Texture( <Image> ),
  19751. * bumpScale: <float>,
  19752. *
  19753. * normalMap: new THREE.Texture( <Image> ),
  19754. * normalMapType: THREE.TangentSpaceNormalMap,
  19755. * normalScale: <Vector2>,
  19756. *
  19757. * displacementMap: new THREE.Texture( <Image> ),
  19758. * displacementScale: <float>,
  19759. * displacementBias: <float>,
  19760. *
  19761. * roughnessMap: new THREE.Texture( <Image> ),
  19762. *
  19763. * metalnessMap: new THREE.Texture( <Image> ),
  19764. *
  19765. * alphaMap: new THREE.Texture( <Image> ),
  19766. *
  19767. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19768. * envMapIntensity: <float>
  19769. *
  19770. * refractionRatio: <float>,
  19771. *
  19772. * wireframe: <boolean>,
  19773. * wireframeLinewidth: <float>,
  19774. *
  19775. * skinning: <bool>,
  19776. * morphTargets: <bool>,
  19777. * morphNormals: <bool>
  19778. * }
  19779. */
  19780. function MeshStandardMaterial(parameters) {
  19781. Material.call(this);
  19782. this.defines = {
  19783. 'STANDARD': ''
  19784. };
  19785. this.type = 'MeshStandardMaterial';
  19786. this.color = new Color(0xffffff); // diffuse
  19787. this.roughness = 1.0;
  19788. this.metalness = 0.0;
  19789. this.map = null;
  19790. this.lightMap = null;
  19791. this.lightMapIntensity = 1.0;
  19792. this.aoMap = null;
  19793. this.aoMapIntensity = 1.0;
  19794. this.emissive = new Color(0x000000);
  19795. this.emissiveIntensity = 1.0;
  19796. this.emissiveMap = null;
  19797. this.bumpMap = null;
  19798. this.bumpScale = 1;
  19799. this.normalMap = null;
  19800. this.normalMapType = TangentSpaceNormalMap;
  19801. this.normalScale = new Vector2(1, 1);
  19802. this.displacementMap = null;
  19803. this.displacementScale = 1;
  19804. this.displacementBias = 0;
  19805. this.roughnessMap = null;
  19806. this.metalnessMap = null;
  19807. this.alphaMap = null;
  19808. this.envMap = null;
  19809. this.envMapIntensity = 1.0;
  19810. this.refractionRatio = 0.98;
  19811. this.wireframe = false;
  19812. this.wireframeLinewidth = 1;
  19813. this.wireframeLinecap = 'round';
  19814. this.wireframeLinejoin = 'round';
  19815. this.skinning = false;
  19816. this.morphTargets = false;
  19817. this.morphNormals = false;
  19818. this.vertexTangents = false;
  19819. this.setValues(parameters);
  19820. }
  19821. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  19822. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19823. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19824. MeshStandardMaterial.prototype.copy = function (source) {
  19825. Material.prototype.copy.call(this, source);
  19826. this.defines = {
  19827. 'STANDARD': ''
  19828. };
  19829. this.color.copy(source.color);
  19830. this.roughness = source.roughness;
  19831. this.metalness = source.metalness;
  19832. this.map = source.map;
  19833. this.lightMap = source.lightMap;
  19834. this.lightMapIntensity = source.lightMapIntensity;
  19835. this.aoMap = source.aoMap;
  19836. this.aoMapIntensity = source.aoMapIntensity;
  19837. this.emissive.copy(source.emissive);
  19838. this.emissiveMap = source.emissiveMap;
  19839. this.emissiveIntensity = source.emissiveIntensity;
  19840. this.bumpMap = source.bumpMap;
  19841. this.bumpScale = source.bumpScale;
  19842. this.normalMap = source.normalMap;
  19843. this.normalMapType = source.normalMapType;
  19844. this.normalScale.copy(source.normalScale);
  19845. this.displacementMap = source.displacementMap;
  19846. this.displacementScale = source.displacementScale;
  19847. this.displacementBias = source.displacementBias;
  19848. this.roughnessMap = source.roughnessMap;
  19849. this.metalnessMap = source.metalnessMap;
  19850. this.alphaMap = source.alphaMap;
  19851. this.envMap = source.envMap;
  19852. this.envMapIntensity = source.envMapIntensity;
  19853. this.refractionRatio = source.refractionRatio;
  19854. this.wireframe = source.wireframe;
  19855. this.wireframeLinewidth = source.wireframeLinewidth;
  19856. this.wireframeLinecap = source.wireframeLinecap;
  19857. this.wireframeLinejoin = source.wireframeLinejoin;
  19858. this.skinning = source.skinning;
  19859. this.morphTargets = source.morphTargets;
  19860. this.morphNormals = source.morphNormals;
  19861. this.vertexTangents = source.vertexTangents;
  19862. return this;
  19863. };
  19864. /**
  19865. * parameters = {
  19866. * clearcoat: <float>,
  19867. * clearcoatMap: new THREE.Texture( <Image> ),
  19868. * clearcoatRoughness: <float>,
  19869. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  19870. * clearcoatNormalScale: <Vector2>,
  19871. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19872. *
  19873. * reflectivity: <float>,
  19874. * ior: <float>,
  19875. *
  19876. * sheen: <Color>,
  19877. *
  19878. * transmission: <float>,
  19879. * transmissionMap: new THREE.Texture( <Image> )
  19880. * }
  19881. */
  19882. function MeshPhysicalMaterial(parameters) {
  19883. MeshStandardMaterial.call(this);
  19884. this.defines = {
  19885. 'STANDARD': '',
  19886. 'PHYSICAL': ''
  19887. };
  19888. this.type = 'MeshPhysicalMaterial';
  19889. this.clearcoat = 0.0;
  19890. this.clearcoatMap = null;
  19891. this.clearcoatRoughness = 0.0;
  19892. this.clearcoatRoughnessMap = null;
  19893. this.clearcoatNormalScale = new Vector2(1, 1);
  19894. this.clearcoatNormalMap = null;
  19895. this.reflectivity = 0.5; // maps to F0 = 0.04
  19896. Object.defineProperty(this, 'ior', {
  19897. get: function get() {
  19898. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  19899. },
  19900. set: function set(ior) {
  19901. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  19902. }
  19903. });
  19904. this.sheen = null; // null will disable sheen bsdf
  19905. this.transmission = 0.0;
  19906. this.transmissionMap = null;
  19907. this.setValues(parameters);
  19908. }
  19909. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  19910. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19911. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19912. MeshPhysicalMaterial.prototype.copy = function (source) {
  19913. MeshStandardMaterial.prototype.copy.call(this, source);
  19914. this.defines = {
  19915. 'STANDARD': '',
  19916. 'PHYSICAL': ''
  19917. };
  19918. this.clearcoat = source.clearcoat;
  19919. this.clearcoatMap = source.clearcoatMap;
  19920. this.clearcoatRoughness = source.clearcoatRoughness;
  19921. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  19922. this.clearcoatNormalMap = source.clearcoatNormalMap;
  19923. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  19924. this.reflectivity = source.reflectivity;
  19925. if (source.sheen) {
  19926. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  19927. } else {
  19928. this.sheen = null;
  19929. }
  19930. this.transmission = source.transmission;
  19931. this.transmissionMap = source.transmissionMap;
  19932. return this;
  19933. };
  19934. /**
  19935. * parameters = {
  19936. * color: <hex>,
  19937. * specular: <hex>,
  19938. * shininess: <float>,
  19939. * opacity: <float>,
  19940. *
  19941. * map: new THREE.Texture( <Image> ),
  19942. *
  19943. * lightMap: new THREE.Texture( <Image> ),
  19944. * lightMapIntensity: <float>
  19945. *
  19946. * aoMap: new THREE.Texture( <Image> ),
  19947. * aoMapIntensity: <float>
  19948. *
  19949. * emissive: <hex>,
  19950. * emissiveIntensity: <float>
  19951. * emissiveMap: new THREE.Texture( <Image> ),
  19952. *
  19953. * bumpMap: new THREE.Texture( <Image> ),
  19954. * bumpScale: <float>,
  19955. *
  19956. * normalMap: new THREE.Texture( <Image> ),
  19957. * normalMapType: THREE.TangentSpaceNormalMap,
  19958. * normalScale: <Vector2>,
  19959. *
  19960. * displacementMap: new THREE.Texture( <Image> ),
  19961. * displacementScale: <float>,
  19962. * displacementBias: <float>,
  19963. *
  19964. * specularMap: new THREE.Texture( <Image> ),
  19965. *
  19966. * alphaMap: new THREE.Texture( <Image> ),
  19967. *
  19968. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19969. * combine: THREE.MultiplyOperation,
  19970. * reflectivity: <float>,
  19971. * refractionRatio: <float>,
  19972. *
  19973. * wireframe: <boolean>,
  19974. * wireframeLinewidth: <float>,
  19975. *
  19976. * skinning: <bool>,
  19977. * morphTargets: <bool>,
  19978. * morphNormals: <bool>
  19979. * }
  19980. */
  19981. function MeshPhongMaterial(parameters) {
  19982. Material.call(this);
  19983. this.type = 'MeshPhongMaterial';
  19984. this.color = new Color(0xffffff); // diffuse
  19985. this.specular = new Color(0x111111);
  19986. this.shininess = 30;
  19987. this.map = null;
  19988. this.lightMap = null;
  19989. this.lightMapIntensity = 1.0;
  19990. this.aoMap = null;
  19991. this.aoMapIntensity = 1.0;
  19992. this.emissive = new Color(0x000000);
  19993. this.emissiveIntensity = 1.0;
  19994. this.emissiveMap = null;
  19995. this.bumpMap = null;
  19996. this.bumpScale = 1;
  19997. this.normalMap = null;
  19998. this.normalMapType = TangentSpaceNormalMap;
  19999. this.normalScale = new Vector2(1, 1);
  20000. this.displacementMap = null;
  20001. this.displacementScale = 1;
  20002. this.displacementBias = 0;
  20003. this.specularMap = null;
  20004. this.alphaMap = null;
  20005. this.envMap = null;
  20006. this.combine = MultiplyOperation;
  20007. this.reflectivity = 1;
  20008. this.refractionRatio = 0.98;
  20009. this.wireframe = false;
  20010. this.wireframeLinewidth = 1;
  20011. this.wireframeLinecap = 'round';
  20012. this.wireframeLinejoin = 'round';
  20013. this.skinning = false;
  20014. this.morphTargets = false;
  20015. this.morphNormals = false;
  20016. this.setValues(parameters);
  20017. }
  20018. MeshPhongMaterial.prototype = Object.create(Material.prototype);
  20019. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  20020. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  20021. MeshPhongMaterial.prototype.copy = function (source) {
  20022. Material.prototype.copy.call(this, source);
  20023. this.color.copy(source.color);
  20024. this.specular.copy(source.specular);
  20025. this.shininess = source.shininess;
  20026. this.map = source.map;
  20027. this.lightMap = source.lightMap;
  20028. this.lightMapIntensity = source.lightMapIntensity;
  20029. this.aoMap = source.aoMap;
  20030. this.aoMapIntensity = source.aoMapIntensity;
  20031. this.emissive.copy(source.emissive);
  20032. this.emissiveMap = source.emissiveMap;
  20033. this.emissiveIntensity = source.emissiveIntensity;
  20034. this.bumpMap = source.bumpMap;
  20035. this.bumpScale = source.bumpScale;
  20036. this.normalMap = source.normalMap;
  20037. this.normalMapType = source.normalMapType;
  20038. this.normalScale.copy(source.normalScale);
  20039. this.displacementMap = source.displacementMap;
  20040. this.displacementScale = source.displacementScale;
  20041. this.displacementBias = source.displacementBias;
  20042. this.specularMap = source.specularMap;
  20043. this.alphaMap = source.alphaMap;
  20044. this.envMap = source.envMap;
  20045. this.combine = source.combine;
  20046. this.reflectivity = source.reflectivity;
  20047. this.refractionRatio = source.refractionRatio;
  20048. this.wireframe = source.wireframe;
  20049. this.wireframeLinewidth = source.wireframeLinewidth;
  20050. this.wireframeLinecap = source.wireframeLinecap;
  20051. this.wireframeLinejoin = source.wireframeLinejoin;
  20052. this.skinning = source.skinning;
  20053. this.morphTargets = source.morphTargets;
  20054. this.morphNormals = source.morphNormals;
  20055. return this;
  20056. };
  20057. /**
  20058. * parameters = {
  20059. * color: <hex>,
  20060. *
  20061. * map: new THREE.Texture( <Image> ),
  20062. * gradientMap: new THREE.Texture( <Image> ),
  20063. *
  20064. * lightMap: new THREE.Texture( <Image> ),
  20065. * lightMapIntensity: <float>
  20066. *
  20067. * aoMap: new THREE.Texture( <Image> ),
  20068. * aoMapIntensity: <float>
  20069. *
  20070. * emissive: <hex>,
  20071. * emissiveIntensity: <float>
  20072. * emissiveMap: new THREE.Texture( <Image> ),
  20073. *
  20074. * bumpMap: new THREE.Texture( <Image> ),
  20075. * bumpScale: <float>,
  20076. *
  20077. * normalMap: new THREE.Texture( <Image> ),
  20078. * normalMapType: THREE.TangentSpaceNormalMap,
  20079. * normalScale: <Vector2>,
  20080. *
  20081. * displacementMap: new THREE.Texture( <Image> ),
  20082. * displacementScale: <float>,
  20083. * displacementBias: <float>,
  20084. *
  20085. * alphaMap: new THREE.Texture( <Image> ),
  20086. *
  20087. * wireframe: <boolean>,
  20088. * wireframeLinewidth: <float>,
  20089. *
  20090. * skinning: <bool>,
  20091. * morphTargets: <bool>,
  20092. * morphNormals: <bool>
  20093. * }
  20094. */
  20095. function MeshToonMaterial(parameters) {
  20096. Material.call(this);
  20097. this.defines = {
  20098. 'TOON': ''
  20099. };
  20100. this.type = 'MeshToonMaterial';
  20101. this.color = new Color(0xffffff);
  20102. this.map = null;
  20103. this.gradientMap = null;
  20104. this.lightMap = null;
  20105. this.lightMapIntensity = 1.0;
  20106. this.aoMap = null;
  20107. this.aoMapIntensity = 1.0;
  20108. this.emissive = new Color(0x000000);
  20109. this.emissiveIntensity = 1.0;
  20110. this.emissiveMap = null;
  20111. this.bumpMap = null;
  20112. this.bumpScale = 1;
  20113. this.normalMap = null;
  20114. this.normalMapType = TangentSpaceNormalMap;
  20115. this.normalScale = new Vector2(1, 1);
  20116. this.displacementMap = null;
  20117. this.displacementScale = 1;
  20118. this.displacementBias = 0;
  20119. this.alphaMap = null;
  20120. this.wireframe = false;
  20121. this.wireframeLinewidth = 1;
  20122. this.wireframeLinecap = 'round';
  20123. this.wireframeLinejoin = 'round';
  20124. this.skinning = false;
  20125. this.morphTargets = false;
  20126. this.morphNormals = false;
  20127. this.setValues(parameters);
  20128. }
  20129. MeshToonMaterial.prototype = Object.create(Material.prototype);
  20130. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  20131. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20132. MeshToonMaterial.prototype.copy = function (source) {
  20133. Material.prototype.copy.call(this, source);
  20134. this.color.copy(source.color);
  20135. this.map = source.map;
  20136. this.gradientMap = source.gradientMap;
  20137. this.lightMap = source.lightMap;
  20138. this.lightMapIntensity = source.lightMapIntensity;
  20139. this.aoMap = source.aoMap;
  20140. this.aoMapIntensity = source.aoMapIntensity;
  20141. this.emissive.copy(source.emissive);
  20142. this.emissiveMap = source.emissiveMap;
  20143. this.emissiveIntensity = source.emissiveIntensity;
  20144. this.bumpMap = source.bumpMap;
  20145. this.bumpScale = source.bumpScale;
  20146. this.normalMap = source.normalMap;
  20147. this.normalMapType = source.normalMapType;
  20148. this.normalScale.copy(source.normalScale);
  20149. this.displacementMap = source.displacementMap;
  20150. this.displacementScale = source.displacementScale;
  20151. this.displacementBias = source.displacementBias;
  20152. this.alphaMap = source.alphaMap;
  20153. this.wireframe = source.wireframe;
  20154. this.wireframeLinewidth = source.wireframeLinewidth;
  20155. this.wireframeLinecap = source.wireframeLinecap;
  20156. this.wireframeLinejoin = source.wireframeLinejoin;
  20157. this.skinning = source.skinning;
  20158. this.morphTargets = source.morphTargets;
  20159. this.morphNormals = source.morphNormals;
  20160. return this;
  20161. };
  20162. /**
  20163. * parameters = {
  20164. * opacity: <float>,
  20165. *
  20166. * bumpMap: new THREE.Texture( <Image> ),
  20167. * bumpScale: <float>,
  20168. *
  20169. * normalMap: new THREE.Texture( <Image> ),
  20170. * normalMapType: THREE.TangentSpaceNormalMap,
  20171. * normalScale: <Vector2>,
  20172. *
  20173. * displacementMap: new THREE.Texture( <Image> ),
  20174. * displacementScale: <float>,
  20175. * displacementBias: <float>,
  20176. *
  20177. * wireframe: <boolean>,
  20178. * wireframeLinewidth: <float>
  20179. *
  20180. * skinning: <bool>,
  20181. * morphTargets: <bool>,
  20182. * morphNormals: <bool>
  20183. * }
  20184. */
  20185. function MeshNormalMaterial(parameters) {
  20186. Material.call(this);
  20187. this.type = 'MeshNormalMaterial';
  20188. this.bumpMap = null;
  20189. this.bumpScale = 1;
  20190. this.normalMap = null;
  20191. this.normalMapType = TangentSpaceNormalMap;
  20192. this.normalScale = new Vector2(1, 1);
  20193. this.displacementMap = null;
  20194. this.displacementScale = 1;
  20195. this.displacementBias = 0;
  20196. this.wireframe = false;
  20197. this.wireframeLinewidth = 1;
  20198. this.fog = false;
  20199. this.skinning = false;
  20200. this.morphTargets = false;
  20201. this.morphNormals = false;
  20202. this.setValues(parameters);
  20203. }
  20204. MeshNormalMaterial.prototype = Object.create(Material.prototype);
  20205. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20206. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20207. MeshNormalMaterial.prototype.copy = function (source) {
  20208. Material.prototype.copy.call(this, source);
  20209. this.bumpMap = source.bumpMap;
  20210. this.bumpScale = source.bumpScale;
  20211. this.normalMap = source.normalMap;
  20212. this.normalMapType = source.normalMapType;
  20213. this.normalScale.copy(source.normalScale);
  20214. this.displacementMap = source.displacementMap;
  20215. this.displacementScale = source.displacementScale;
  20216. this.displacementBias = source.displacementBias;
  20217. this.wireframe = source.wireframe;
  20218. this.wireframeLinewidth = source.wireframeLinewidth;
  20219. this.skinning = source.skinning;
  20220. this.morphTargets = source.morphTargets;
  20221. this.morphNormals = source.morphNormals;
  20222. return this;
  20223. };
  20224. /**
  20225. * parameters = {
  20226. * color: <hex>,
  20227. * opacity: <float>,
  20228. *
  20229. * map: new THREE.Texture( <Image> ),
  20230. *
  20231. * lightMap: new THREE.Texture( <Image> ),
  20232. * lightMapIntensity: <float>
  20233. *
  20234. * aoMap: new THREE.Texture( <Image> ),
  20235. * aoMapIntensity: <float>
  20236. *
  20237. * emissive: <hex>,
  20238. * emissiveIntensity: <float>
  20239. * emissiveMap: new THREE.Texture( <Image> ),
  20240. *
  20241. * specularMap: new THREE.Texture( <Image> ),
  20242. *
  20243. * alphaMap: new THREE.Texture( <Image> ),
  20244. *
  20245. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20246. * combine: THREE.Multiply,
  20247. * reflectivity: <float>,
  20248. * refractionRatio: <float>,
  20249. *
  20250. * wireframe: <boolean>,
  20251. * wireframeLinewidth: <float>,
  20252. *
  20253. * skinning: <bool>,
  20254. * morphTargets: <bool>,
  20255. * morphNormals: <bool>
  20256. * }
  20257. */
  20258. function MeshLambertMaterial(parameters) {
  20259. Material.call(this);
  20260. this.type = 'MeshLambertMaterial';
  20261. this.color = new Color(0xffffff); // diffuse
  20262. this.map = null;
  20263. this.lightMap = null;
  20264. this.lightMapIntensity = 1.0;
  20265. this.aoMap = null;
  20266. this.aoMapIntensity = 1.0;
  20267. this.emissive = new Color(0x000000);
  20268. this.emissiveIntensity = 1.0;
  20269. this.emissiveMap = null;
  20270. this.specularMap = null;
  20271. this.alphaMap = null;
  20272. this.envMap = null;
  20273. this.combine = MultiplyOperation;
  20274. this.reflectivity = 1;
  20275. this.refractionRatio = 0.98;
  20276. this.wireframe = false;
  20277. this.wireframeLinewidth = 1;
  20278. this.wireframeLinecap = 'round';
  20279. this.wireframeLinejoin = 'round';
  20280. this.skinning = false;
  20281. this.morphTargets = false;
  20282. this.morphNormals = false;
  20283. this.setValues(parameters);
  20284. }
  20285. MeshLambertMaterial.prototype = Object.create(Material.prototype);
  20286. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20287. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20288. MeshLambertMaterial.prototype.copy = function (source) {
  20289. Material.prototype.copy.call(this, source);
  20290. this.color.copy(source.color);
  20291. this.map = source.map;
  20292. this.lightMap = source.lightMap;
  20293. this.lightMapIntensity = source.lightMapIntensity;
  20294. this.aoMap = source.aoMap;
  20295. this.aoMapIntensity = source.aoMapIntensity;
  20296. this.emissive.copy(source.emissive);
  20297. this.emissiveMap = source.emissiveMap;
  20298. this.emissiveIntensity = source.emissiveIntensity;
  20299. this.specularMap = source.specularMap;
  20300. this.alphaMap = source.alphaMap;
  20301. this.envMap = source.envMap;
  20302. this.combine = source.combine;
  20303. this.reflectivity = source.reflectivity;
  20304. this.refractionRatio = source.refractionRatio;
  20305. this.wireframe = source.wireframe;
  20306. this.wireframeLinewidth = source.wireframeLinewidth;
  20307. this.wireframeLinecap = source.wireframeLinecap;
  20308. this.wireframeLinejoin = source.wireframeLinejoin;
  20309. this.skinning = source.skinning;
  20310. this.morphTargets = source.morphTargets;
  20311. this.morphNormals = source.morphNormals;
  20312. return this;
  20313. };
  20314. /**
  20315. * parameters = {
  20316. * color: <hex>,
  20317. * opacity: <float>,
  20318. *
  20319. * matcap: new THREE.Texture( <Image> ),
  20320. *
  20321. * map: new THREE.Texture( <Image> ),
  20322. *
  20323. * bumpMap: new THREE.Texture( <Image> ),
  20324. * bumpScale: <float>,
  20325. *
  20326. * normalMap: new THREE.Texture( <Image> ),
  20327. * normalMapType: THREE.TangentSpaceNormalMap,
  20328. * normalScale: <Vector2>,
  20329. *
  20330. * displacementMap: new THREE.Texture( <Image> ),
  20331. * displacementScale: <float>,
  20332. * displacementBias: <float>,
  20333. *
  20334. * alphaMap: new THREE.Texture( <Image> ),
  20335. *
  20336. * skinning: <bool>,
  20337. * morphTargets: <bool>,
  20338. * morphNormals: <bool>
  20339. * }
  20340. */
  20341. function MeshMatcapMaterial(parameters) {
  20342. Material.call(this);
  20343. this.defines = {
  20344. 'MATCAP': ''
  20345. };
  20346. this.type = 'MeshMatcapMaterial';
  20347. this.color = new Color(0xffffff); // diffuse
  20348. this.matcap = null;
  20349. this.map = null;
  20350. this.bumpMap = null;
  20351. this.bumpScale = 1;
  20352. this.normalMap = null;
  20353. this.normalMapType = TangentSpaceNormalMap;
  20354. this.normalScale = new Vector2(1, 1);
  20355. this.displacementMap = null;
  20356. this.displacementScale = 1;
  20357. this.displacementBias = 0;
  20358. this.alphaMap = null;
  20359. this.skinning = false;
  20360. this.morphTargets = false;
  20361. this.morphNormals = false;
  20362. this.setValues(parameters);
  20363. }
  20364. MeshMatcapMaterial.prototype = Object.create(Material.prototype);
  20365. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20366. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20367. MeshMatcapMaterial.prototype.copy = function (source) {
  20368. Material.prototype.copy.call(this, source);
  20369. this.defines = {
  20370. 'MATCAP': ''
  20371. };
  20372. this.color.copy(source.color);
  20373. this.matcap = source.matcap;
  20374. this.map = source.map;
  20375. this.bumpMap = source.bumpMap;
  20376. this.bumpScale = source.bumpScale;
  20377. this.normalMap = source.normalMap;
  20378. this.normalMapType = source.normalMapType;
  20379. this.normalScale.copy(source.normalScale);
  20380. this.displacementMap = source.displacementMap;
  20381. this.displacementScale = source.displacementScale;
  20382. this.displacementBias = source.displacementBias;
  20383. this.alphaMap = source.alphaMap;
  20384. this.skinning = source.skinning;
  20385. this.morphTargets = source.morphTargets;
  20386. this.morphNormals = source.morphNormals;
  20387. return this;
  20388. };
  20389. /**
  20390. * parameters = {
  20391. * color: <hex>,
  20392. * opacity: <float>,
  20393. *
  20394. * linewidth: <float>,
  20395. *
  20396. * scale: <float>,
  20397. * dashSize: <float>,
  20398. * gapSize: <float>
  20399. * }
  20400. */
  20401. function LineDashedMaterial(parameters) {
  20402. LineBasicMaterial.call(this);
  20403. this.type = 'LineDashedMaterial';
  20404. this.scale = 1;
  20405. this.dashSize = 3;
  20406. this.gapSize = 1;
  20407. this.setValues(parameters);
  20408. }
  20409. LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
  20410. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20411. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20412. LineDashedMaterial.prototype.copy = function (source) {
  20413. LineBasicMaterial.prototype.copy.call(this, source);
  20414. this.scale = source.scale;
  20415. this.dashSize = source.dashSize;
  20416. this.gapSize = source.gapSize;
  20417. return this;
  20418. };
  20419. var Materials = /*#__PURE__*/Object.freeze({
  20420. __proto__: null,
  20421. ShadowMaterial: ShadowMaterial,
  20422. SpriteMaterial: SpriteMaterial,
  20423. RawShaderMaterial: RawShaderMaterial,
  20424. ShaderMaterial: ShaderMaterial,
  20425. PointsMaterial: PointsMaterial,
  20426. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20427. MeshStandardMaterial: MeshStandardMaterial,
  20428. MeshPhongMaterial: MeshPhongMaterial,
  20429. MeshToonMaterial: MeshToonMaterial,
  20430. MeshNormalMaterial: MeshNormalMaterial,
  20431. MeshLambertMaterial: MeshLambertMaterial,
  20432. MeshDepthMaterial: MeshDepthMaterial,
  20433. MeshDistanceMaterial: MeshDistanceMaterial,
  20434. MeshBasicMaterial: MeshBasicMaterial,
  20435. MeshMatcapMaterial: MeshMatcapMaterial,
  20436. LineDashedMaterial: LineDashedMaterial,
  20437. LineBasicMaterial: LineBasicMaterial,
  20438. Material: Material
  20439. });
  20440. var AnimationUtils = {
  20441. // same as Array.prototype.slice, but also works on typed arrays
  20442. arraySlice: function arraySlice(array, from, to) {
  20443. if (AnimationUtils.isTypedArray(array)) {
  20444. // in ios9 array.subarray(from, undefined) will return empty array
  20445. // but array.subarray(from) or array.subarray(from, len) is correct
  20446. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20447. }
  20448. return array.slice(from, to);
  20449. },
  20450. // converts an array to a specific type
  20451. convertArray: function convertArray(array, type, forceClone) {
  20452. if (!array || // let 'undefined' and 'null' pass
  20453. !forceClone && array.constructor === type) return array;
  20454. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20455. return new type(array); // create typed array
  20456. }
  20457. return Array.prototype.slice.call(array); // create Array
  20458. },
  20459. isTypedArray: function isTypedArray(object) {
  20460. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20461. },
  20462. // returns an array by which times and values can be sorted
  20463. getKeyframeOrder: function getKeyframeOrder(times) {
  20464. function compareTime(i, j) {
  20465. return times[i] - times[j];
  20466. }
  20467. var n = times.length;
  20468. var result = new Array(n);
  20469. for (var i = 0; i !== n; ++i) {
  20470. result[i] = i;
  20471. }
  20472. result.sort(compareTime);
  20473. return result;
  20474. },
  20475. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20476. sortedArray: function sortedArray(values, stride, order) {
  20477. var nValues = values.length;
  20478. var result = new values.constructor(nValues);
  20479. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20480. var srcOffset = order[i] * stride;
  20481. for (var j = 0; j !== stride; ++j) {
  20482. result[dstOffset++] = values[srcOffset + j];
  20483. }
  20484. }
  20485. return result;
  20486. },
  20487. // function for parsing AOS keyframe formats
  20488. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20489. var i = 1,
  20490. key = jsonKeys[0];
  20491. while (key !== undefined && key[valuePropertyName] === undefined) {
  20492. key = jsonKeys[i++];
  20493. }
  20494. if (key === undefined) return; // no data
  20495. var value = key[valuePropertyName];
  20496. if (value === undefined) return; // no data
  20497. if (Array.isArray(value)) {
  20498. do {
  20499. value = key[valuePropertyName];
  20500. if (value !== undefined) {
  20501. times.push(key.time);
  20502. values.push.apply(values, value); // push all elements
  20503. }
  20504. key = jsonKeys[i++];
  20505. } while (key !== undefined);
  20506. } else if (value.toArray !== undefined) {
  20507. // ...assume THREE.Math-ish
  20508. do {
  20509. value = key[valuePropertyName];
  20510. if (value !== undefined) {
  20511. times.push(key.time);
  20512. value.toArray(values, values.length);
  20513. }
  20514. key = jsonKeys[i++];
  20515. } while (key !== undefined);
  20516. } else {
  20517. // otherwise push as-is
  20518. do {
  20519. value = key[valuePropertyName];
  20520. if (value !== undefined) {
  20521. times.push(key.time);
  20522. values.push(value);
  20523. }
  20524. key = jsonKeys[i++];
  20525. } while (key !== undefined);
  20526. }
  20527. },
  20528. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  20529. fps = fps || 30;
  20530. var clip = sourceClip.clone();
  20531. clip.name = name;
  20532. var tracks = [];
  20533. for (var i = 0; i < clip.tracks.length; ++i) {
  20534. var track = clip.tracks[i];
  20535. var valueSize = track.getValueSize();
  20536. var times = [];
  20537. var values = [];
  20538. for (var j = 0; j < track.times.length; ++j) {
  20539. var frame = track.times[j] * fps;
  20540. if (frame < startFrame || frame >= endFrame) continue;
  20541. times.push(track.times[j]);
  20542. for (var k = 0; k < valueSize; ++k) {
  20543. values.push(track.values[j * valueSize + k]);
  20544. }
  20545. }
  20546. if (times.length === 0) continue;
  20547. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  20548. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  20549. tracks.push(track);
  20550. }
  20551. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  20552. var minStartTime = Infinity;
  20553. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  20554. if (minStartTime > clip.tracks[_i].times[0]) {
  20555. minStartTime = clip.tracks[_i].times[0];
  20556. }
  20557. } // shift all tracks such that clip begins at t=0
  20558. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  20559. clip.tracks[_i2].shift(-1 * minStartTime);
  20560. }
  20561. clip.resetDuration();
  20562. return clip;
  20563. },
  20564. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  20565. if (referenceFrame === undefined) referenceFrame = 0;
  20566. if (referenceClip === undefined) referenceClip = targetClip;
  20567. if (fps === undefined || fps <= 0) fps = 30;
  20568. var numTracks = referenceClip.tracks.length;
  20569. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  20570. var _loop = function _loop(i) {
  20571. var referenceTrack = referenceClip.tracks[i];
  20572. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  20573. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  20574. var targetTrack = targetClip.tracks.find(function (track) {
  20575. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  20576. });
  20577. if (targetTrack === undefined) return "continue";
  20578. var referenceOffset = 0;
  20579. var referenceValueSize = referenceTrack.getValueSize();
  20580. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20581. referenceOffset = referenceValueSize / 3;
  20582. }
  20583. var targetOffset = 0;
  20584. var targetValueSize = targetTrack.getValueSize();
  20585. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20586. targetOffset = targetValueSize / 3;
  20587. }
  20588. var lastIndex = referenceTrack.times.length - 1;
  20589. var referenceValue = void 0; // Find the value to subtract out of the track
  20590. if (referenceTime <= referenceTrack.times[0]) {
  20591. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20592. var startIndex = referenceOffset;
  20593. var endIndex = referenceValueSize - referenceOffset;
  20594. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  20595. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  20596. // Reference frame is after the last keyframe, so just use the last keyframe
  20597. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  20598. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  20599. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  20600. } else {
  20601. // Interpolate to the reference value
  20602. var interpolant = referenceTrack.createInterpolant();
  20603. var _startIndex2 = referenceOffset;
  20604. var _endIndex2 = referenceValueSize - referenceOffset;
  20605. interpolant.evaluate(referenceTime);
  20606. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  20607. } // Conjugate the quaternion
  20608. if (referenceTrackType === 'quaternion') {
  20609. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  20610. referenceQuat.toArray(referenceValue);
  20611. } // Subtract the reference value from all of the track values
  20612. var numTimes = targetTrack.times.length;
  20613. for (var j = 0; j < numTimes; ++j) {
  20614. var valueStart = j * targetValueSize + targetOffset;
  20615. if (referenceTrackType === 'quaternion') {
  20616. // Multiply the conjugate for quaternion track types
  20617. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  20618. } else {
  20619. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  20620. for (var k = 0; k < valueEnd; ++k) {
  20621. targetTrack.values[valueStart + k] -= referenceValue[k];
  20622. }
  20623. }
  20624. }
  20625. };
  20626. for (var i = 0; i < numTracks; ++i) {
  20627. var _ret = _loop(i);
  20628. if (_ret === "continue") continue;
  20629. }
  20630. targetClip.blendMode = AdditiveAnimationBlendMode;
  20631. return targetClip;
  20632. }
  20633. };
  20634. /**
  20635. * Abstract base class of interpolants over parametric samples.
  20636. *
  20637. * The parameter domain is one dimensional, typically the time or a path
  20638. * along a curve defined by the data.
  20639. *
  20640. * The sample values can have any dimensionality and derived classes may
  20641. * apply special interpretations to the data.
  20642. *
  20643. * This class provides the interval seek in a Template Method, deferring
  20644. * the actual interpolation to derived classes.
  20645. *
  20646. * Time complexity is O(1) for linear access crossing at most two points
  20647. * and O(log N) for random access, where N is the number of positions.
  20648. *
  20649. * References:
  20650. *
  20651. * http://www.oodesign.com/template-method-pattern.html
  20652. *
  20653. */
  20654. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20655. this.parameterPositions = parameterPositions;
  20656. this._cachedIndex = 0;
  20657. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  20658. this.sampleValues = sampleValues;
  20659. this.valueSize = sampleSize;
  20660. }
  20661. Object.assign(Interpolant.prototype, {
  20662. evaluate: function evaluate(t) {
  20663. var pp = this.parameterPositions;
  20664. var i1 = this._cachedIndex,
  20665. t1 = pp[i1],
  20666. t0 = pp[i1 - 1];
  20667. validate_interval: {
  20668. seek: {
  20669. var right;
  20670. linear_scan: {
  20671. //- See http://jsperf.com/comparison-to-undefined/3
  20672. //- slower code:
  20673. //-
  20674. //- if ( t >= t1 || t1 === undefined ) {
  20675. forward_scan: if (!(t < t1)) {
  20676. for (var giveUpAt = i1 + 2;;) {
  20677. if (t1 === undefined) {
  20678. if (t < t0) break forward_scan; // after end
  20679. i1 = pp.length;
  20680. this._cachedIndex = i1;
  20681. return this.afterEnd_(i1 - 1, t, t0);
  20682. }
  20683. if (i1 === giveUpAt) break; // this loop
  20684. t0 = t1;
  20685. t1 = pp[++i1];
  20686. if (t < t1) {
  20687. // we have arrived at the sought interval
  20688. break seek;
  20689. }
  20690. } // prepare binary search on the right side of the index
  20691. right = pp.length;
  20692. break linear_scan;
  20693. } //- slower code:
  20694. //- if ( t < t0 || t0 === undefined ) {
  20695. if (!(t >= t0)) {
  20696. // looping?
  20697. var t1global = pp[1];
  20698. if (t < t1global) {
  20699. i1 = 2; // + 1, using the scan for the details
  20700. t0 = t1global;
  20701. } // linear reverse scan
  20702. for (var _giveUpAt = i1 - 2;;) {
  20703. if (t0 === undefined) {
  20704. // before start
  20705. this._cachedIndex = 0;
  20706. return this.beforeStart_(0, t, t1);
  20707. }
  20708. if (i1 === _giveUpAt) break; // this loop
  20709. t1 = t0;
  20710. t0 = pp[--i1 - 1];
  20711. if (t >= t0) {
  20712. // we have arrived at the sought interval
  20713. break seek;
  20714. }
  20715. } // prepare binary search on the left side of the index
  20716. right = i1;
  20717. i1 = 0;
  20718. break linear_scan;
  20719. } // the interval is valid
  20720. break validate_interval;
  20721. } // linear scan
  20722. // binary search
  20723. while (i1 < right) {
  20724. var mid = i1 + right >>> 1;
  20725. if (t < pp[mid]) {
  20726. right = mid;
  20727. } else {
  20728. i1 = mid + 1;
  20729. }
  20730. }
  20731. t1 = pp[i1];
  20732. t0 = pp[i1 - 1]; // check boundary cases, again
  20733. if (t0 === undefined) {
  20734. this._cachedIndex = 0;
  20735. return this.beforeStart_(0, t, t1);
  20736. }
  20737. if (t1 === undefined) {
  20738. i1 = pp.length;
  20739. this._cachedIndex = i1;
  20740. return this.afterEnd_(i1 - 1, t0, t);
  20741. }
  20742. } // seek
  20743. this._cachedIndex = i1;
  20744. this.intervalChanged_(i1, t0, t1);
  20745. } // validate_interval
  20746. return this.interpolate_(i1, t0, t, t1);
  20747. },
  20748. settings: null,
  20749. // optional, subclass-specific settings structure
  20750. // Note: The indirection allows central control of many interpolants.
  20751. // --- Protected interface
  20752. DefaultSettings_: {},
  20753. getSettings_: function getSettings_() {
  20754. return this.settings || this.DefaultSettings_;
  20755. },
  20756. copySampleValue_: function copySampleValue_(index) {
  20757. // copies a sample value to the result buffer
  20758. var result = this.resultBuffer,
  20759. values = this.sampleValues,
  20760. stride = this.valueSize,
  20761. offset = index * stride;
  20762. for (var i = 0; i !== stride; ++i) {
  20763. result[i] = values[offset + i];
  20764. }
  20765. return result;
  20766. },
  20767. // Template methods for derived classes:
  20768. interpolate_: function interpolate_()
  20769. /* i1, t0, t, t1 */
  20770. {
  20771. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  20772. },
  20773. intervalChanged_: function intervalChanged_()
  20774. /* i1, t0, t1 */
  20775. {// empty
  20776. }
  20777. }); // DECLARE ALIAS AFTER assign prototype
  20778. Object.assign(Interpolant.prototype, {
  20779. //( 0, t, t0 ), returns this.resultBuffer
  20780. beforeStart_: Interpolant.prototype.copySampleValue_,
  20781. //( N-1, tN-1, t ), returns this.resultBuffer
  20782. afterEnd_: Interpolant.prototype.copySampleValue_
  20783. });
  20784. /**
  20785. * Fast and simple cubic spline interpolant.
  20786. *
  20787. * It was derived from a Hermitian construction setting the first derivative
  20788. * at each sample position to the linear slope between neighboring positions
  20789. * over their parameter interval.
  20790. */
  20791. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20792. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20793. this._weightPrev = -0;
  20794. this._offsetPrev = -0;
  20795. this._weightNext = -0;
  20796. this._offsetNext = -0;
  20797. }
  20798. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20799. constructor: CubicInterpolant,
  20800. DefaultSettings_: {
  20801. endingStart: ZeroCurvatureEnding,
  20802. endingEnd: ZeroCurvatureEnding
  20803. },
  20804. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  20805. var pp = this.parameterPositions;
  20806. var iPrev = i1 - 2,
  20807. iNext = i1 + 1,
  20808. tPrev = pp[iPrev],
  20809. tNext = pp[iNext];
  20810. if (tPrev === undefined) {
  20811. switch (this.getSettings_().endingStart) {
  20812. case ZeroSlopeEnding:
  20813. // f'(t0) = 0
  20814. iPrev = i1;
  20815. tPrev = 2 * t0 - t1;
  20816. break;
  20817. case WrapAroundEnding:
  20818. // use the other end of the curve
  20819. iPrev = pp.length - 2;
  20820. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  20821. break;
  20822. default:
  20823. // ZeroCurvatureEnding
  20824. // f''(t0) = 0 a.k.a. Natural Spline
  20825. iPrev = i1;
  20826. tPrev = t1;
  20827. }
  20828. }
  20829. if (tNext === undefined) {
  20830. switch (this.getSettings_().endingEnd) {
  20831. case ZeroSlopeEnding:
  20832. // f'(tN) = 0
  20833. iNext = i1;
  20834. tNext = 2 * t1 - t0;
  20835. break;
  20836. case WrapAroundEnding:
  20837. // use the other end of the curve
  20838. iNext = 1;
  20839. tNext = t1 + pp[1] - pp[0];
  20840. break;
  20841. default:
  20842. // ZeroCurvatureEnding
  20843. // f''(tN) = 0, a.k.a. Natural Spline
  20844. iNext = i1 - 1;
  20845. tNext = t0;
  20846. }
  20847. }
  20848. var halfDt = (t1 - t0) * 0.5,
  20849. stride = this.valueSize;
  20850. this._weightPrev = halfDt / (t0 - tPrev);
  20851. this._weightNext = halfDt / (tNext - t1);
  20852. this._offsetPrev = iPrev * stride;
  20853. this._offsetNext = iNext * stride;
  20854. },
  20855. interpolate_: function interpolate_(i1, t0, t, t1) {
  20856. var result = this.resultBuffer,
  20857. values = this.sampleValues,
  20858. stride = this.valueSize,
  20859. o1 = i1 * stride,
  20860. o0 = o1 - stride,
  20861. oP = this._offsetPrev,
  20862. oN = this._offsetNext,
  20863. wP = this._weightPrev,
  20864. wN = this._weightNext,
  20865. p = (t - t0) / (t1 - t0),
  20866. pp = p * p,
  20867. ppp = pp * p; // evaluate polynomials
  20868. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  20869. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  20870. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  20871. var sN = wN * ppp - wN * pp; // combine data linearly
  20872. for (var i = 0; i !== stride; ++i) {
  20873. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  20874. }
  20875. return result;
  20876. }
  20877. });
  20878. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20879. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20880. }
  20881. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20882. constructor: LinearInterpolant,
  20883. interpolate_: function interpolate_(i1, t0, t, t1) {
  20884. var result = this.resultBuffer,
  20885. values = this.sampleValues,
  20886. stride = this.valueSize,
  20887. offset1 = i1 * stride,
  20888. offset0 = offset1 - stride,
  20889. weight1 = (t - t0) / (t1 - t0),
  20890. weight0 = 1 - weight1;
  20891. for (var i = 0; i !== stride; ++i) {
  20892. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  20893. }
  20894. return result;
  20895. }
  20896. });
  20897. /**
  20898. *
  20899. * Interpolant that evaluates to the sample value at the position preceeding
  20900. * the parameter.
  20901. */
  20902. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20903. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20904. }
  20905. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20906. constructor: DiscreteInterpolant,
  20907. interpolate_: function interpolate_(i1
  20908. /*, t0, t, t1 */
  20909. ) {
  20910. return this.copySampleValue_(i1 - 1);
  20911. }
  20912. });
  20913. function KeyframeTrack(name, times, values, interpolation) {
  20914. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  20915. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  20916. this.name = name;
  20917. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  20918. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  20919. this.setInterpolation(interpolation || this.DefaultInterpolation);
  20920. } // Static methods
  20921. Object.assign(KeyframeTrack, {
  20922. // Serialization (in static context, because of constructor invocation
  20923. // and automatic invocation of .toJSON):
  20924. toJSON: function toJSON(track) {
  20925. var trackType = track.constructor;
  20926. var json; // derived classes can define a static toJSON method
  20927. if (trackType.toJSON !== undefined) {
  20928. json = trackType.toJSON(track);
  20929. } else {
  20930. // by default, we assume the data can be serialized as-is
  20931. json = {
  20932. 'name': track.name,
  20933. 'times': AnimationUtils.convertArray(track.times, Array),
  20934. 'values': AnimationUtils.convertArray(track.values, Array)
  20935. };
  20936. var interpolation = track.getInterpolation();
  20937. if (interpolation !== track.DefaultInterpolation) {
  20938. json.interpolation = interpolation;
  20939. }
  20940. }
  20941. json.type = track.ValueTypeName; // mandatory
  20942. return json;
  20943. }
  20944. });
  20945. Object.assign(KeyframeTrack.prototype, {
  20946. constructor: KeyframeTrack,
  20947. TimeBufferType: Float32Array,
  20948. ValueBufferType: Float32Array,
  20949. DefaultInterpolation: InterpolateLinear,
  20950. InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
  20951. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  20952. },
  20953. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  20954. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  20955. },
  20956. InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
  20957. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  20958. },
  20959. setInterpolation: function setInterpolation(interpolation) {
  20960. var factoryMethod;
  20961. switch (interpolation) {
  20962. case InterpolateDiscrete:
  20963. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20964. break;
  20965. case InterpolateLinear:
  20966. factoryMethod = this.InterpolantFactoryMethodLinear;
  20967. break;
  20968. case InterpolateSmooth:
  20969. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20970. break;
  20971. }
  20972. if (factoryMethod === undefined) {
  20973. var message = "unsupported interpolation for " + this.ValueTypeName + " keyframe track named " + this.name;
  20974. if (this.createInterpolant === undefined) {
  20975. // fall back to default, unless the default itself is messed up
  20976. if (interpolation !== this.DefaultInterpolation) {
  20977. this.setInterpolation(this.DefaultInterpolation);
  20978. } else {
  20979. throw new Error(message); // fatal, in this case
  20980. }
  20981. }
  20982. console.warn('THREE.KeyframeTrack:', message);
  20983. return this;
  20984. }
  20985. this.createInterpolant = factoryMethod;
  20986. return this;
  20987. },
  20988. getInterpolation: function getInterpolation() {
  20989. switch (this.createInterpolant) {
  20990. case this.InterpolantFactoryMethodDiscrete:
  20991. return InterpolateDiscrete;
  20992. case this.InterpolantFactoryMethodLinear:
  20993. return InterpolateLinear;
  20994. case this.InterpolantFactoryMethodSmooth:
  20995. return InterpolateSmooth;
  20996. }
  20997. },
  20998. getValueSize: function getValueSize() {
  20999. return this.values.length / this.times.length;
  21000. },
  21001. // move all keyframes either forwards or backwards in time
  21002. shift: function shift(timeOffset) {
  21003. if (timeOffset !== 0.0) {
  21004. var times = this.times;
  21005. for (var i = 0, n = times.length; i !== n; ++i) {
  21006. times[i] += timeOffset;
  21007. }
  21008. }
  21009. return this;
  21010. },
  21011. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21012. scale: function scale(timeScale) {
  21013. if (timeScale !== 1.0) {
  21014. var times = this.times;
  21015. for (var i = 0, n = times.length; i !== n; ++i) {
  21016. times[i] *= timeScale;
  21017. }
  21018. }
  21019. return this;
  21020. },
  21021. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21022. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21023. trim: function trim(startTime, endTime) {
  21024. var times = this.times,
  21025. nKeys = times.length;
  21026. var from = 0,
  21027. to = nKeys - 1;
  21028. while (from !== nKeys && times[from] < startTime) {
  21029. ++from;
  21030. }
  21031. while (to !== -1 && times[to] > endTime) {
  21032. --to;
  21033. }
  21034. ++to; // inclusive -> exclusive bound
  21035. if (from !== 0 || to !== nKeys) {
  21036. // empty tracks are forbidden, so keep at least one keyframe
  21037. if (from >= to) {
  21038. to = Math.max(to, 1);
  21039. from = to - 1;
  21040. }
  21041. var stride = this.getValueSize();
  21042. this.times = AnimationUtils.arraySlice(times, from, to);
  21043. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  21044. }
  21045. return this;
  21046. },
  21047. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21048. validate: function validate() {
  21049. var valid = true;
  21050. var valueSize = this.getValueSize();
  21051. if (valueSize - Math.floor(valueSize) !== 0) {
  21052. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  21053. valid = false;
  21054. }
  21055. var times = this.times,
  21056. values = this.values,
  21057. nKeys = times.length;
  21058. if (nKeys === 0) {
  21059. console.error('THREE.KeyframeTrack: Track is empty.', this);
  21060. valid = false;
  21061. }
  21062. var prevTime = null;
  21063. for (var i = 0; i !== nKeys; i++) {
  21064. var currTime = times[i];
  21065. if (typeof currTime === 'number' && isNaN(currTime)) {
  21066. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  21067. valid = false;
  21068. break;
  21069. }
  21070. if (prevTime !== null && prevTime > currTime) {
  21071. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  21072. valid = false;
  21073. break;
  21074. }
  21075. prevTime = currTime;
  21076. }
  21077. if (values !== undefined) {
  21078. if (AnimationUtils.isTypedArray(values)) {
  21079. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  21080. var value = values[_i];
  21081. if (isNaN(value)) {
  21082. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  21083. valid = false;
  21084. break;
  21085. }
  21086. }
  21087. }
  21088. }
  21089. return valid;
  21090. },
  21091. // removes equivalent sequential keys as common in morph target sequences
  21092. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21093. optimize: function optimize() {
  21094. // times or values may be shared with other tracks, so overwriting is unsafe
  21095. var times = AnimationUtils.arraySlice(this.times),
  21096. values = AnimationUtils.arraySlice(this.values),
  21097. stride = this.getValueSize(),
  21098. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21099. lastIndex = times.length - 1;
  21100. var writeIndex = 1;
  21101. for (var i = 1; i < lastIndex; ++i) {
  21102. var keep = false;
  21103. var time = times[i];
  21104. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  21105. if (time !== timeNext && (i !== 1 || time !== time[0])) {
  21106. if (!smoothInterpolation) {
  21107. // remove unnecessary keyframes same as their neighbors
  21108. var offset = i * stride,
  21109. offsetP = offset - stride,
  21110. offsetN = offset + stride;
  21111. for (var j = 0; j !== stride; ++j) {
  21112. var value = values[offset + j];
  21113. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  21114. keep = true;
  21115. break;
  21116. }
  21117. }
  21118. } else {
  21119. keep = true;
  21120. }
  21121. } // in-place compaction
  21122. if (keep) {
  21123. if (i !== writeIndex) {
  21124. times[writeIndex] = times[i];
  21125. var readOffset = i * stride,
  21126. writeOffset = writeIndex * stride;
  21127. for (var _j = 0; _j !== stride; ++_j) {
  21128. values[writeOffset + _j] = values[readOffset + _j];
  21129. }
  21130. }
  21131. ++writeIndex;
  21132. }
  21133. } // flush last keyframe (compaction looks ahead)
  21134. if (lastIndex > 0) {
  21135. times[writeIndex] = times[lastIndex];
  21136. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  21137. values[_writeOffset + _j2] = values[_readOffset + _j2];
  21138. }
  21139. ++writeIndex;
  21140. }
  21141. if (writeIndex !== times.length) {
  21142. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  21143. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  21144. } else {
  21145. this.times = times;
  21146. this.values = values;
  21147. }
  21148. return this;
  21149. },
  21150. clone: function clone() {
  21151. var times = AnimationUtils.arraySlice(this.times, 0);
  21152. var values = AnimationUtils.arraySlice(this.values, 0);
  21153. var TypedKeyframeTrack = this.constructor;
  21154. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21155. track.createInterpolant = this.createInterpolant;
  21156. return track;
  21157. }
  21158. });
  21159. /**
  21160. * A Track of Boolean keyframe values.
  21161. */
  21162. function BooleanKeyframeTrack(name, times, values) {
  21163. KeyframeTrack.call(this, name, times, values);
  21164. }
  21165. BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21166. constructor: BooleanKeyframeTrack,
  21167. ValueTypeName: 'bool',
  21168. ValueBufferType: Array,
  21169. DefaultInterpolation: InterpolateDiscrete,
  21170. InterpolantFactoryMethodLinear: undefined,
  21171. InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
  21172. // representation of a single value and a custom interpolant that
  21173. // computes "firstValue ^ isOdd( index )".
  21174. });
  21175. /**
  21176. * A Track of keyframe values that represent color.
  21177. */
  21178. function ColorKeyframeTrack(name, times, values, interpolation) {
  21179. KeyframeTrack.call(this, name, times, values, interpolation);
  21180. }
  21181. ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21182. constructor: ColorKeyframeTrack,
  21183. ValueTypeName: 'color' // ValueBufferType is inherited
  21184. // DefaultInterpolation is inherited
  21185. // Note: Very basic implementation and nothing special yet.
  21186. // However, this is the place for color space parameterization.
  21187. });
  21188. /**
  21189. * A Track of numeric keyframe values.
  21190. */
  21191. function NumberKeyframeTrack(name, times, values, interpolation) {
  21192. KeyframeTrack.call(this, name, times, values, interpolation);
  21193. }
  21194. NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21195. constructor: NumberKeyframeTrack,
  21196. ValueTypeName: 'number' // ValueBufferType is inherited
  21197. // DefaultInterpolation is inherited
  21198. });
  21199. /**
  21200. * Spherical linear unit quaternion interpolant.
  21201. */
  21202. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21203. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21204. }
  21205. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21206. constructor: QuaternionLinearInterpolant,
  21207. interpolate_: function interpolate_(i1, t0, t, t1) {
  21208. var result = this.resultBuffer,
  21209. values = this.sampleValues,
  21210. stride = this.valueSize,
  21211. alpha = (t - t0) / (t1 - t0);
  21212. var offset = i1 * stride;
  21213. for (var end = offset + stride; offset !== end; offset += 4) {
  21214. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21215. }
  21216. return result;
  21217. }
  21218. });
  21219. /**
  21220. * A Track of quaternion keyframe values.
  21221. */
  21222. function QuaternionKeyframeTrack(name, times, values, interpolation) {
  21223. KeyframeTrack.call(this, name, times, values, interpolation);
  21224. }
  21225. QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21226. constructor: QuaternionKeyframeTrack,
  21227. ValueTypeName: 'quaternion',
  21228. // ValueBufferType is inherited
  21229. DefaultInterpolation: InterpolateLinear,
  21230. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21231. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21232. },
  21233. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21234. });
  21235. /**
  21236. * A Track that interpolates Strings
  21237. */
  21238. function StringKeyframeTrack(name, times, values, interpolation) {
  21239. KeyframeTrack.call(this, name, times, values, interpolation);
  21240. }
  21241. StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21242. constructor: StringKeyframeTrack,
  21243. ValueTypeName: 'string',
  21244. ValueBufferType: Array,
  21245. DefaultInterpolation: InterpolateDiscrete,
  21246. InterpolantFactoryMethodLinear: undefined,
  21247. InterpolantFactoryMethodSmooth: undefined
  21248. });
  21249. /**
  21250. * A Track of vectored keyframe values.
  21251. */
  21252. function VectorKeyframeTrack(name, times, values, interpolation) {
  21253. KeyframeTrack.call(this, name, times, values, interpolation);
  21254. }
  21255. VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21256. constructor: VectorKeyframeTrack,
  21257. ValueTypeName: 'vector' // ValueBufferType is inherited
  21258. // DefaultInterpolation is inherited
  21259. });
  21260. function AnimationClip(name, duration, tracks, blendMode) {
  21261. this.name = name;
  21262. this.tracks = tracks;
  21263. this.duration = duration !== undefined ? duration : -1;
  21264. this.blendMode = blendMode !== undefined ? blendMode : NormalAnimationBlendMode;
  21265. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21266. if (this.duration < 0) {
  21267. this.resetDuration();
  21268. }
  21269. }
  21270. function getTrackTypeForValueTypeName(typeName) {
  21271. switch (typeName.toLowerCase()) {
  21272. case 'scalar':
  21273. case 'double':
  21274. case 'float':
  21275. case 'number':
  21276. case 'integer':
  21277. return NumberKeyframeTrack;
  21278. case 'vector':
  21279. case 'vector2':
  21280. case 'vector3':
  21281. case 'vector4':
  21282. return VectorKeyframeTrack;
  21283. case 'color':
  21284. return ColorKeyframeTrack;
  21285. case 'quaternion':
  21286. return QuaternionKeyframeTrack;
  21287. case 'bool':
  21288. case 'boolean':
  21289. return BooleanKeyframeTrack;
  21290. case 'string':
  21291. return StringKeyframeTrack;
  21292. }
  21293. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21294. }
  21295. function parseKeyframeTrack(json) {
  21296. if (json.type === undefined) {
  21297. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21298. }
  21299. var trackType = getTrackTypeForValueTypeName(json.type);
  21300. if (json.times === undefined) {
  21301. var times = [],
  21302. values = [];
  21303. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21304. json.times = times;
  21305. json.values = values;
  21306. } // derived classes can define a static parse method
  21307. if (trackType.parse !== undefined) {
  21308. return trackType.parse(json);
  21309. } else {
  21310. // by default, we assume a constructor compatible with the base
  21311. return new trackType(json.name, json.times, json.values, json.interpolation);
  21312. }
  21313. }
  21314. Object.assign(AnimationClip, {
  21315. parse: function parse(json) {
  21316. var tracks = [],
  21317. jsonTracks = json.tracks,
  21318. frameTime = 1.0 / (json.fps || 1.0);
  21319. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21320. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21321. }
  21322. return new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21323. },
  21324. toJSON: function toJSON(clip) {
  21325. var tracks = [],
  21326. clipTracks = clip.tracks;
  21327. var json = {
  21328. 'name': clip.name,
  21329. 'duration': clip.duration,
  21330. 'tracks': tracks,
  21331. 'uuid': clip.uuid,
  21332. 'blendMode': clip.blendMode
  21333. };
  21334. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21335. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21336. }
  21337. return json;
  21338. },
  21339. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21340. var numMorphTargets = morphTargetSequence.length;
  21341. var tracks = [];
  21342. for (var i = 0; i < numMorphTargets; i++) {
  21343. var times = [];
  21344. var values = [];
  21345. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21346. values.push(0, 1, 0);
  21347. var order = AnimationUtils.getKeyframeOrder(times);
  21348. times = AnimationUtils.sortedArray(times, 1, order);
  21349. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21350. // last frame as well for perfect loop.
  21351. if (!noLoop && times[0] === 0) {
  21352. times.push(numMorphTargets);
  21353. values.push(values[0]);
  21354. }
  21355. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21356. }
  21357. return new AnimationClip(name, -1, tracks);
  21358. },
  21359. findByName: function findByName(objectOrClipArray, name) {
  21360. var clipArray = objectOrClipArray;
  21361. if (!Array.isArray(objectOrClipArray)) {
  21362. var o = objectOrClipArray;
  21363. clipArray = o.geometry && o.geometry.animations || o.animations;
  21364. }
  21365. for (var i = 0; i < clipArray.length; i++) {
  21366. if (clipArray[i].name === name) {
  21367. return clipArray[i];
  21368. }
  21369. }
  21370. return null;
  21371. },
  21372. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21373. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21374. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21375. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21376. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21377. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21378. var morphTarget = morphTargets[i];
  21379. var parts = morphTarget.name.match(pattern);
  21380. if (parts && parts.length > 1) {
  21381. var name = parts[1];
  21382. var animationMorphTargets = animationToMorphTargets[name];
  21383. if (!animationMorphTargets) {
  21384. animationToMorphTargets[name] = animationMorphTargets = [];
  21385. }
  21386. animationMorphTargets.push(morphTarget);
  21387. }
  21388. }
  21389. var clips = [];
  21390. for (var _name in animationToMorphTargets) {
  21391. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21392. }
  21393. return clips;
  21394. },
  21395. // parse the animation.hierarchy format
  21396. parseAnimation: function parseAnimation(animation, bones) {
  21397. if (!animation) {
  21398. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21399. return null;
  21400. }
  21401. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21402. // only return track if there are actually keys.
  21403. if (animationKeys.length !== 0) {
  21404. var times = [];
  21405. var values = [];
  21406. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21407. if (times.length !== 0) {
  21408. destTracks.push(new trackType(trackName, times, values));
  21409. }
  21410. }
  21411. };
  21412. var tracks = [];
  21413. var clipName = animation.name || 'default';
  21414. var fps = animation.fps || 30;
  21415. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21416. var duration = animation.length || -1;
  21417. var hierarchyTracks = animation.hierarchy || [];
  21418. for (var h = 0; h < hierarchyTracks.length; h++) {
  21419. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21420. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21421. if (animationKeys[0].morphTargets) {
  21422. // figure out all morph targets used in this track
  21423. var morphTargetNames = {};
  21424. var k = void 0;
  21425. for (k = 0; k < animationKeys.length; k++) {
  21426. if (animationKeys[k].morphTargets) {
  21427. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21428. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21429. }
  21430. }
  21431. } // create a track for each morph target with all zero
  21432. // morphTargetInfluences except for the keys in which
  21433. // the morphTarget is named.
  21434. for (var morphTargetName in morphTargetNames) {
  21435. var times = [];
  21436. var values = [];
  21437. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21438. var animationKey = animationKeys[k];
  21439. times.push(animationKey.time);
  21440. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21441. }
  21442. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21443. }
  21444. duration = morphTargetNames.length * (fps || 1.0);
  21445. } else {
  21446. // ...assume skeletal animation
  21447. var boneName = '.bones[' + bones[h].name + ']';
  21448. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21449. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21450. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21451. }
  21452. }
  21453. if (tracks.length === 0) {
  21454. return null;
  21455. }
  21456. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21457. return clip;
  21458. }
  21459. });
  21460. Object.assign(AnimationClip.prototype, {
  21461. resetDuration: function resetDuration() {
  21462. var tracks = this.tracks;
  21463. var duration = 0;
  21464. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21465. var track = this.tracks[i];
  21466. duration = Math.max(duration, track.times[track.times.length - 1]);
  21467. }
  21468. this.duration = duration;
  21469. return this;
  21470. },
  21471. trim: function trim() {
  21472. for (var i = 0; i < this.tracks.length; i++) {
  21473. this.tracks[i].trim(0, this.duration);
  21474. }
  21475. return this;
  21476. },
  21477. validate: function validate() {
  21478. var valid = true;
  21479. for (var i = 0; i < this.tracks.length; i++) {
  21480. valid = valid && this.tracks[i].validate();
  21481. }
  21482. return valid;
  21483. },
  21484. optimize: function optimize() {
  21485. for (var i = 0; i < this.tracks.length; i++) {
  21486. this.tracks[i].optimize();
  21487. }
  21488. return this;
  21489. },
  21490. clone: function clone() {
  21491. var tracks = [];
  21492. for (var i = 0; i < this.tracks.length; i++) {
  21493. tracks.push(this.tracks[i].clone());
  21494. }
  21495. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  21496. }
  21497. });
  21498. var Cache = {
  21499. enabled: false,
  21500. files: {},
  21501. add: function add(key, file) {
  21502. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  21503. this.files[key] = file;
  21504. },
  21505. get: function get(key) {
  21506. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  21507. return this.files[key];
  21508. },
  21509. remove: function remove(key) {
  21510. delete this.files[key];
  21511. },
  21512. clear: function clear() {
  21513. this.files = {};
  21514. }
  21515. };
  21516. function LoadingManager(onLoad, onProgress, onError) {
  21517. var scope = this;
  21518. var isLoading = false;
  21519. var itemsLoaded = 0;
  21520. var itemsTotal = 0;
  21521. var urlModifier = undefined;
  21522. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  21523. // in the constructor
  21524. this.onStart = undefined;
  21525. this.onLoad = onLoad;
  21526. this.onProgress = onProgress;
  21527. this.onError = onError;
  21528. this.itemStart = function (url) {
  21529. itemsTotal++;
  21530. if (isLoading === false) {
  21531. if (scope.onStart !== undefined) {
  21532. scope.onStart(url, itemsLoaded, itemsTotal);
  21533. }
  21534. }
  21535. isLoading = true;
  21536. };
  21537. this.itemEnd = function (url) {
  21538. itemsLoaded++;
  21539. if (scope.onProgress !== undefined) {
  21540. scope.onProgress(url, itemsLoaded, itemsTotal);
  21541. }
  21542. if (itemsLoaded === itemsTotal) {
  21543. isLoading = false;
  21544. if (scope.onLoad !== undefined) {
  21545. scope.onLoad();
  21546. }
  21547. }
  21548. };
  21549. this.itemError = function (url) {
  21550. if (scope.onError !== undefined) {
  21551. scope.onError(url);
  21552. }
  21553. };
  21554. this.resolveURL = function (url) {
  21555. if (urlModifier) {
  21556. return urlModifier(url);
  21557. }
  21558. return url;
  21559. };
  21560. this.setURLModifier = function (transform) {
  21561. urlModifier = transform;
  21562. return this;
  21563. };
  21564. this.addHandler = function (regex, loader) {
  21565. handlers.push(regex, loader);
  21566. return this;
  21567. };
  21568. this.removeHandler = function (regex) {
  21569. var index = handlers.indexOf(regex);
  21570. if (index !== -1) {
  21571. handlers.splice(index, 2);
  21572. }
  21573. return this;
  21574. };
  21575. this.getHandler = function (file) {
  21576. for (var i = 0, l = handlers.length; i < l; i += 2) {
  21577. var regex = handlers[i];
  21578. var loader = handlers[i + 1];
  21579. if (regex.global) regex.lastIndex = 0; // see #17920
  21580. if (regex.test(file)) {
  21581. return loader;
  21582. }
  21583. }
  21584. return null;
  21585. };
  21586. }
  21587. var DefaultLoadingManager = new LoadingManager();
  21588. function Loader(manager) {
  21589. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  21590. this.crossOrigin = 'anonymous';
  21591. this.withCredentials = false;
  21592. this.path = '';
  21593. this.resourcePath = '';
  21594. this.requestHeader = {};
  21595. }
  21596. Object.assign(Loader.prototype, {
  21597. load: function load()
  21598. /* url, onLoad, onProgress, onError */
  21599. {},
  21600. loadAsync: function loadAsync(url, onProgress) {
  21601. var scope = this;
  21602. return new Promise(function (resolve, reject) {
  21603. scope.load(url, resolve, onProgress, reject);
  21604. });
  21605. },
  21606. parse: function parse()
  21607. /* data */
  21608. {},
  21609. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  21610. this.crossOrigin = crossOrigin;
  21611. return this;
  21612. },
  21613. setWithCredentials: function setWithCredentials(value) {
  21614. this.withCredentials = value;
  21615. return this;
  21616. },
  21617. setPath: function setPath(path) {
  21618. this.path = path;
  21619. return this;
  21620. },
  21621. setResourcePath: function setResourcePath(resourcePath) {
  21622. this.resourcePath = resourcePath;
  21623. return this;
  21624. },
  21625. setRequestHeader: function setRequestHeader(requestHeader) {
  21626. this.requestHeader = requestHeader;
  21627. return this;
  21628. }
  21629. });
  21630. var loading = {};
  21631. function FileLoader(manager) {
  21632. Loader.call(this, manager);
  21633. }
  21634. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21635. constructor: FileLoader,
  21636. load: function load(url, onLoad, onProgress, onError) {
  21637. if (url === undefined) url = '';
  21638. if (this.path !== undefined) url = this.path + url;
  21639. url = this.manager.resolveURL(url);
  21640. var scope = this;
  21641. var cached = Cache.get(url);
  21642. if (cached !== undefined) {
  21643. scope.manager.itemStart(url);
  21644. setTimeout(function () {
  21645. if (onLoad) onLoad(cached);
  21646. scope.manager.itemEnd(url);
  21647. }, 0);
  21648. return cached;
  21649. } // Check if request is duplicate
  21650. if (loading[url] !== undefined) {
  21651. loading[url].push({
  21652. onLoad: onLoad,
  21653. onProgress: onProgress,
  21654. onError: onError
  21655. });
  21656. return;
  21657. } // Check for data: URI
  21658. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21659. var dataUriRegexResult = url.match(dataUriRegex);
  21660. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21661. if (dataUriRegexResult) {
  21662. var mimeType = dataUriRegexResult[1];
  21663. var isBase64 = !!dataUriRegexResult[2];
  21664. var data = dataUriRegexResult[3];
  21665. data = decodeURIComponent(data);
  21666. if (isBase64) data = atob(data);
  21667. try {
  21668. var response;
  21669. var responseType = (this.responseType || '').toLowerCase();
  21670. switch (responseType) {
  21671. case 'arraybuffer':
  21672. case 'blob':
  21673. var view = new Uint8Array(data.length);
  21674. for (var i = 0; i < data.length; i++) {
  21675. view[i] = data.charCodeAt(i);
  21676. }
  21677. if (responseType === 'blob') {
  21678. response = new Blob([view.buffer], {
  21679. type: mimeType
  21680. });
  21681. } else {
  21682. response = view.buffer;
  21683. }
  21684. break;
  21685. case 'document':
  21686. var parser = new DOMParser();
  21687. response = parser.parseFromString(data, mimeType);
  21688. break;
  21689. case 'json':
  21690. response = JSON.parse(data);
  21691. break;
  21692. default:
  21693. // 'text' or other
  21694. response = data;
  21695. break;
  21696. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21697. setTimeout(function () {
  21698. if (onLoad) onLoad(response);
  21699. scope.manager.itemEnd(url);
  21700. }, 0);
  21701. } catch (error) {
  21702. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21703. setTimeout(function () {
  21704. if (onError) onError(error);
  21705. scope.manager.itemError(url);
  21706. scope.manager.itemEnd(url);
  21707. }, 0);
  21708. }
  21709. } else {
  21710. // Initialise array for duplicate requests
  21711. loading[url] = [];
  21712. loading[url].push({
  21713. onLoad: onLoad,
  21714. onProgress: onProgress,
  21715. onError: onError
  21716. });
  21717. request = new XMLHttpRequest();
  21718. request.open('GET', url, true);
  21719. request.addEventListener('load', function (event) {
  21720. var response = this.response;
  21721. var callbacks = loading[url];
  21722. delete loading[url];
  21723. if (this.status === 200 || this.status === 0) {
  21724. // Some browsers return HTTP Status 0 when using non-http protocol
  21725. // e.g. 'file://' or 'data://'. Handle as success.
  21726. 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
  21727. // error response bodies as proper responses to requests.
  21728. Cache.add(url, response);
  21729. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  21730. var callback = callbacks[_i];
  21731. if (callback.onLoad) callback.onLoad(response);
  21732. }
  21733. scope.manager.itemEnd(url);
  21734. } else {
  21735. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  21736. var _callback = callbacks[_i2];
  21737. if (_callback.onError) _callback.onError(event);
  21738. }
  21739. scope.manager.itemError(url);
  21740. scope.manager.itemEnd(url);
  21741. }
  21742. }, false);
  21743. request.addEventListener('progress', function (event) {
  21744. var callbacks = loading[url];
  21745. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  21746. var callback = callbacks[_i3];
  21747. if (callback.onProgress) callback.onProgress(event);
  21748. }
  21749. }, false);
  21750. request.addEventListener('error', function (event) {
  21751. var callbacks = loading[url];
  21752. delete loading[url];
  21753. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  21754. var callback = callbacks[_i4];
  21755. if (callback.onError) callback.onError(event);
  21756. }
  21757. scope.manager.itemError(url);
  21758. scope.manager.itemEnd(url);
  21759. }, false);
  21760. request.addEventListener('abort', function (event) {
  21761. var callbacks = loading[url];
  21762. delete loading[url];
  21763. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  21764. var callback = callbacks[_i5];
  21765. if (callback.onError) callback.onError(event);
  21766. }
  21767. scope.manager.itemError(url);
  21768. scope.manager.itemEnd(url);
  21769. }, false);
  21770. if (this.responseType !== undefined) request.responseType = this.responseType;
  21771. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  21772. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  21773. for (var header in this.requestHeader) {
  21774. request.setRequestHeader(header, this.requestHeader[header]);
  21775. }
  21776. request.send(null);
  21777. }
  21778. scope.manager.itemStart(url);
  21779. return request;
  21780. },
  21781. setResponseType: function setResponseType(value) {
  21782. this.responseType = value;
  21783. return this;
  21784. },
  21785. setMimeType: function setMimeType(value) {
  21786. this.mimeType = value;
  21787. return this;
  21788. }
  21789. });
  21790. function AnimationLoader(manager) {
  21791. Loader.call(this, manager);
  21792. }
  21793. AnimationLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21794. constructor: AnimationLoader,
  21795. load: function load(url, onLoad, onProgress, onError) {
  21796. var scope = this;
  21797. var loader = new FileLoader(scope.manager);
  21798. loader.setPath(scope.path);
  21799. loader.setRequestHeader(scope.requestHeader);
  21800. loader.setWithCredentials(scope.withCredentials);
  21801. loader.load(url, function (text) {
  21802. try {
  21803. onLoad(scope.parse(JSON.parse(text)));
  21804. } catch (e) {
  21805. if (onError) {
  21806. onError(e);
  21807. } else {
  21808. console.error(e);
  21809. }
  21810. scope.manager.itemError(url);
  21811. }
  21812. }, onProgress, onError);
  21813. },
  21814. parse: function parse(json) {
  21815. var animations = [];
  21816. for (var i = 0; i < json.length; i++) {
  21817. var clip = AnimationClip.parse(json[i]);
  21818. animations.push(clip);
  21819. }
  21820. return animations;
  21821. }
  21822. });
  21823. /**
  21824. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21825. *
  21826. * Sub classes have to implement the parse() method which will be used in load().
  21827. */
  21828. function CompressedTextureLoader(manager) {
  21829. Loader.call(this, manager);
  21830. }
  21831. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21832. constructor: CompressedTextureLoader,
  21833. load: function load(url, onLoad, onProgress, onError) {
  21834. var scope = this;
  21835. var images = [];
  21836. var texture = new CompressedTexture();
  21837. texture.image = images;
  21838. var loader = new FileLoader(this.manager);
  21839. loader.setPath(this.path);
  21840. loader.setResponseType('arraybuffer');
  21841. loader.setRequestHeader(this.requestHeader);
  21842. loader.setWithCredentials(scope.withCredentials);
  21843. var loaded = 0;
  21844. function loadTexture(i) {
  21845. loader.load(url[i], function (buffer) {
  21846. var texDatas = scope.parse(buffer, true);
  21847. images[i] = {
  21848. width: texDatas.width,
  21849. height: texDatas.height,
  21850. format: texDatas.format,
  21851. mipmaps: texDatas.mipmaps
  21852. };
  21853. loaded += 1;
  21854. if (loaded === 6) {
  21855. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  21856. texture.format = texDatas.format;
  21857. texture.needsUpdate = true;
  21858. if (onLoad) onLoad(texture);
  21859. }
  21860. }, onProgress, onError);
  21861. }
  21862. if (Array.isArray(url)) {
  21863. for (var i = 0, il = url.length; i < il; ++i) {
  21864. loadTexture(i);
  21865. }
  21866. } else {
  21867. // compressed cubemap texture stored in a single DDS file
  21868. loader.load(url, function (buffer) {
  21869. var texDatas = scope.parse(buffer, true);
  21870. if (texDatas.isCubemap) {
  21871. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21872. for (var f = 0; f < faces; f++) {
  21873. images[f] = {
  21874. mipmaps: []
  21875. };
  21876. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  21877. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  21878. images[f].format = texDatas.format;
  21879. images[f].width = texDatas.width;
  21880. images[f].height = texDatas.height;
  21881. }
  21882. }
  21883. } else {
  21884. texture.image.width = texDatas.width;
  21885. texture.image.height = texDatas.height;
  21886. texture.mipmaps = texDatas.mipmaps;
  21887. }
  21888. if (texDatas.mipmapCount === 1) {
  21889. texture.minFilter = LinearFilter;
  21890. }
  21891. texture.format = texDatas.format;
  21892. texture.needsUpdate = true;
  21893. if (onLoad) onLoad(texture);
  21894. }, onProgress, onError);
  21895. }
  21896. return texture;
  21897. }
  21898. });
  21899. function ImageLoader(manager) {
  21900. Loader.call(this, manager);
  21901. }
  21902. ImageLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21903. constructor: ImageLoader,
  21904. load: function load(url, onLoad, onProgress, onError) {
  21905. if (this.path !== undefined) url = this.path + url;
  21906. url = this.manager.resolveURL(url);
  21907. var scope = this;
  21908. var cached = Cache.get(url);
  21909. if (cached !== undefined) {
  21910. scope.manager.itemStart(url);
  21911. setTimeout(function () {
  21912. if (onLoad) onLoad(cached);
  21913. scope.manager.itemEnd(url);
  21914. }, 0);
  21915. return cached;
  21916. }
  21917. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  21918. function onImageLoad() {
  21919. image.removeEventListener('load', onImageLoad, false);
  21920. image.removeEventListener('error', onImageError, false);
  21921. Cache.add(url, this);
  21922. if (onLoad) onLoad(this);
  21923. scope.manager.itemEnd(url);
  21924. }
  21925. function onImageError(event) {
  21926. image.removeEventListener('load', onImageLoad, false);
  21927. image.removeEventListener('error', onImageError, false);
  21928. if (onError) onError(event);
  21929. scope.manager.itemError(url);
  21930. scope.manager.itemEnd(url);
  21931. }
  21932. image.addEventListener('load', onImageLoad, false);
  21933. image.addEventListener('error', onImageError, false);
  21934. if (url.substr(0, 5) !== 'data:') {
  21935. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  21936. }
  21937. scope.manager.itemStart(url);
  21938. image.src = url;
  21939. return image;
  21940. }
  21941. });
  21942. function CubeTextureLoader(manager) {
  21943. Loader.call(this, manager);
  21944. }
  21945. CubeTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21946. constructor: CubeTextureLoader,
  21947. load: function load(urls, onLoad, onProgress, onError) {
  21948. var texture = new CubeTexture();
  21949. var loader = new ImageLoader(this.manager);
  21950. loader.setCrossOrigin(this.crossOrigin);
  21951. loader.setPath(this.path);
  21952. var loaded = 0;
  21953. function loadTexture(i) {
  21954. loader.load(urls[i], function (image) {
  21955. texture.images[i] = image;
  21956. loaded++;
  21957. if (loaded === 6) {
  21958. texture.needsUpdate = true;
  21959. if (onLoad) onLoad(texture);
  21960. }
  21961. }, undefined, onError);
  21962. }
  21963. for (var i = 0; i < urls.length; ++i) {
  21964. loadTexture(i);
  21965. }
  21966. return texture;
  21967. }
  21968. });
  21969. /**
  21970. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  21971. *
  21972. * Sub classes have to implement the parse() method which will be used in load().
  21973. */
  21974. function DataTextureLoader(manager) {
  21975. Loader.call(this, manager);
  21976. }
  21977. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21978. constructor: DataTextureLoader,
  21979. load: function load(url, onLoad, onProgress, onError) {
  21980. var scope = this;
  21981. var texture = new DataTexture();
  21982. var loader = new FileLoader(this.manager);
  21983. loader.setResponseType('arraybuffer');
  21984. loader.setRequestHeader(this.requestHeader);
  21985. loader.setPath(this.path);
  21986. loader.setWithCredentials(scope.withCredentials);
  21987. loader.load(url, function (buffer) {
  21988. var texData = scope.parse(buffer);
  21989. if (!texData) return;
  21990. if (texData.image !== undefined) {
  21991. texture.image = texData.image;
  21992. } else if (texData.data !== undefined) {
  21993. texture.image.width = texData.width;
  21994. texture.image.height = texData.height;
  21995. texture.image.data = texData.data;
  21996. }
  21997. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  21998. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  21999. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  22000. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  22001. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  22002. if (texData.format !== undefined) {
  22003. texture.format = texData.format;
  22004. }
  22005. if (texData.type !== undefined) {
  22006. texture.type = texData.type;
  22007. }
  22008. if (texData.mipmaps !== undefined) {
  22009. texture.mipmaps = texData.mipmaps;
  22010. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  22011. }
  22012. if (texData.mipmapCount === 1) {
  22013. texture.minFilter = LinearFilter;
  22014. }
  22015. texture.needsUpdate = true;
  22016. if (onLoad) onLoad(texture, texData);
  22017. }, onProgress, onError);
  22018. return texture;
  22019. }
  22020. });
  22021. function TextureLoader(manager) {
  22022. Loader.call(this, manager);
  22023. }
  22024. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22025. constructor: TextureLoader,
  22026. load: function load(url, onLoad, onProgress, onError) {
  22027. var texture = new Texture();
  22028. var loader = new ImageLoader(this.manager);
  22029. loader.setCrossOrigin(this.crossOrigin);
  22030. loader.setPath(this.path);
  22031. loader.load(url, function (image) {
  22032. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  22033. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  22034. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  22035. texture.needsUpdate = true;
  22036. if (onLoad !== undefined) {
  22037. onLoad(texture);
  22038. }
  22039. }, onProgress, onError);
  22040. return texture;
  22041. }
  22042. });
  22043. /**
  22044. * Extensible curve object.
  22045. *
  22046. * Some common of curve methods:
  22047. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  22048. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  22049. * .getPoints(), .getSpacedPoints()
  22050. * .getLength()
  22051. * .updateArcLengths()
  22052. *
  22053. * This following curves inherit from THREE.Curve:
  22054. *
  22055. * -- 2D curves --
  22056. * THREE.ArcCurve
  22057. * THREE.CubicBezierCurve
  22058. * THREE.EllipseCurve
  22059. * THREE.LineCurve
  22060. * THREE.QuadraticBezierCurve
  22061. * THREE.SplineCurve
  22062. *
  22063. * -- 3D curves --
  22064. * THREE.CatmullRomCurve3
  22065. * THREE.CubicBezierCurve3
  22066. * THREE.LineCurve3
  22067. * THREE.QuadraticBezierCurve3
  22068. *
  22069. * A series of curves can be represented as a THREE.CurvePath.
  22070. *
  22071. **/
  22072. function Curve() {
  22073. this.type = 'Curve';
  22074. this.arcLengthDivisions = 200;
  22075. }
  22076. Object.assign(Curve.prototype, {
  22077. // Virtual base class method to overwrite and implement in subclasses
  22078. // - t [0 .. 1]
  22079. getPoint: function getPoint()
  22080. /* t, optionalTarget */
  22081. {
  22082. console.warn('THREE.Curve: .getPoint() not implemented.');
  22083. return null;
  22084. },
  22085. // Get point at relative position in curve according to arc length
  22086. // - u [0 .. 1]
  22087. getPointAt: function getPointAt(u, optionalTarget) {
  22088. var t = this.getUtoTmapping(u);
  22089. return this.getPoint(t, optionalTarget);
  22090. },
  22091. // Get sequence of points using getPoint( t )
  22092. getPoints: function getPoints(divisions) {
  22093. if (divisions === undefined) divisions = 5;
  22094. var points = [];
  22095. for (var d = 0; d <= divisions; d++) {
  22096. points.push(this.getPoint(d / divisions));
  22097. }
  22098. return points;
  22099. },
  22100. // Get sequence of points using getPointAt( u )
  22101. getSpacedPoints: function getSpacedPoints(divisions) {
  22102. if (divisions === undefined) divisions = 5;
  22103. var points = [];
  22104. for (var d = 0; d <= divisions; d++) {
  22105. points.push(this.getPointAt(d / divisions));
  22106. }
  22107. return points;
  22108. },
  22109. // Get total curve arc length
  22110. getLength: function getLength() {
  22111. var lengths = this.getLengths();
  22112. return lengths[lengths.length - 1];
  22113. },
  22114. // Get list of cumulative segment lengths
  22115. getLengths: function getLengths(divisions) {
  22116. if (divisions === undefined) divisions = this.arcLengthDivisions;
  22117. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  22118. return this.cacheArcLengths;
  22119. }
  22120. this.needsUpdate = false;
  22121. var cache = [];
  22122. var current,
  22123. last = this.getPoint(0);
  22124. var sum = 0;
  22125. cache.push(0);
  22126. for (var p = 1; p <= divisions; p++) {
  22127. current = this.getPoint(p / divisions);
  22128. sum += current.distanceTo(last);
  22129. cache.push(sum);
  22130. last = current;
  22131. }
  22132. this.cacheArcLengths = cache;
  22133. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22134. },
  22135. updateArcLengths: function updateArcLengths() {
  22136. this.needsUpdate = true;
  22137. this.getLengths();
  22138. },
  22139. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22140. getUtoTmapping: function getUtoTmapping(u, distance) {
  22141. var arcLengths = this.getLengths();
  22142. var i = 0;
  22143. var il = arcLengths.length;
  22144. var targetArcLength; // The targeted u distance value to get
  22145. if (distance) {
  22146. targetArcLength = distance;
  22147. } else {
  22148. targetArcLength = u * arcLengths[il - 1];
  22149. } // binary search for the index with largest value smaller than target u distance
  22150. var low = 0,
  22151. high = il - 1,
  22152. comparison;
  22153. while (low <= high) {
  22154. 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
  22155. comparison = arcLengths[i] - targetArcLength;
  22156. if (comparison < 0) {
  22157. low = i + 1;
  22158. } else if (comparison > 0) {
  22159. high = i - 1;
  22160. } else {
  22161. high = i;
  22162. break; // DONE
  22163. }
  22164. }
  22165. i = high;
  22166. if (arcLengths[i] === targetArcLength) {
  22167. return i / (il - 1);
  22168. } // we could get finer grain at lengths, or use simple interpolation between two points
  22169. var lengthBefore = arcLengths[i];
  22170. var lengthAfter = arcLengths[i + 1];
  22171. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  22172. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  22173. var t = (i + segmentFraction) / (il - 1);
  22174. return t;
  22175. },
  22176. // Returns a unit vector tangent at t
  22177. // In case any sub curve does not implement its tangent derivation,
  22178. // 2 points a small delta apart will be used to find its gradient
  22179. // which seems to give a reasonable approximation
  22180. getTangent: function getTangent(t, optionalTarget) {
  22181. var delta = 0.0001;
  22182. var t1 = t - delta;
  22183. var t2 = t + delta; // Capping in case of danger
  22184. if (t1 < 0) t1 = 0;
  22185. if (t2 > 1) t2 = 1;
  22186. var pt1 = this.getPoint(t1);
  22187. var pt2 = this.getPoint(t2);
  22188. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22189. tangent.copy(pt2).sub(pt1).normalize();
  22190. return tangent;
  22191. },
  22192. getTangentAt: function getTangentAt(u, optionalTarget) {
  22193. var t = this.getUtoTmapping(u);
  22194. return this.getTangent(t, optionalTarget);
  22195. },
  22196. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22197. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22198. var normal = new Vector3();
  22199. var tangents = [];
  22200. var normals = [];
  22201. var binormals = [];
  22202. var vec = new Vector3();
  22203. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22204. for (var i = 0; i <= segments; i++) {
  22205. var u = i / segments;
  22206. tangents[i] = this.getTangentAt(u, new Vector3());
  22207. tangents[i].normalize();
  22208. } // select an initial normal vector perpendicular to the first tangent vector,
  22209. // and in the direction of the minimum tangent xyz component
  22210. normals[0] = new Vector3();
  22211. binormals[0] = new Vector3();
  22212. var min = Number.MAX_VALUE;
  22213. var tx = Math.abs(tangents[0].x);
  22214. var ty = Math.abs(tangents[0].y);
  22215. var tz = Math.abs(tangents[0].z);
  22216. if (tx <= min) {
  22217. min = tx;
  22218. normal.set(1, 0, 0);
  22219. }
  22220. if (ty <= min) {
  22221. min = ty;
  22222. normal.set(0, 1, 0);
  22223. }
  22224. if (tz <= min) {
  22225. normal.set(0, 0, 1);
  22226. }
  22227. vec.crossVectors(tangents[0], normal).normalize();
  22228. normals[0].crossVectors(tangents[0], vec);
  22229. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22230. for (var _i = 1; _i <= segments; _i++) {
  22231. normals[_i] = normals[_i - 1].clone();
  22232. binormals[_i] = binormals[_i - 1].clone();
  22233. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22234. if (vec.length() > Number.EPSILON) {
  22235. vec.normalize();
  22236. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22237. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22238. }
  22239. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22240. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22241. if (closed === true) {
  22242. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22243. _theta /= segments;
  22244. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22245. _theta = -_theta;
  22246. }
  22247. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22248. // twist a little...
  22249. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22250. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22251. }
  22252. }
  22253. return {
  22254. tangents: tangents,
  22255. normals: normals,
  22256. binormals: binormals
  22257. };
  22258. },
  22259. clone: function clone() {
  22260. return new this.constructor().copy(this);
  22261. },
  22262. copy: function copy(source) {
  22263. this.arcLengthDivisions = source.arcLengthDivisions;
  22264. return this;
  22265. },
  22266. toJSON: function toJSON() {
  22267. var data = {
  22268. metadata: {
  22269. version: 4.5,
  22270. type: 'Curve',
  22271. generator: 'Curve.toJSON'
  22272. }
  22273. };
  22274. data.arcLengthDivisions = this.arcLengthDivisions;
  22275. data.type = this.type;
  22276. return data;
  22277. },
  22278. fromJSON: function fromJSON(json) {
  22279. this.arcLengthDivisions = json.arcLengthDivisions;
  22280. return this;
  22281. }
  22282. });
  22283. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22284. Curve.call(this);
  22285. this.type = 'EllipseCurve';
  22286. this.aX = aX || 0;
  22287. this.aY = aY || 0;
  22288. this.xRadius = xRadius || 1;
  22289. this.yRadius = yRadius || 1;
  22290. this.aStartAngle = aStartAngle || 0;
  22291. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22292. this.aClockwise = aClockwise || false;
  22293. this.aRotation = aRotation || 0;
  22294. }
  22295. EllipseCurve.prototype = Object.create(Curve.prototype);
  22296. EllipseCurve.prototype.constructor = EllipseCurve;
  22297. EllipseCurve.prototype.isEllipseCurve = true;
  22298. EllipseCurve.prototype.getPoint = function (t, optionalTarget) {
  22299. var point = optionalTarget || new Vector2();
  22300. var twoPi = Math.PI * 2;
  22301. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22302. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22303. while (deltaAngle < 0) {
  22304. deltaAngle += twoPi;
  22305. }
  22306. while (deltaAngle > twoPi) {
  22307. deltaAngle -= twoPi;
  22308. }
  22309. if (deltaAngle < Number.EPSILON) {
  22310. if (samePoints) {
  22311. deltaAngle = 0;
  22312. } else {
  22313. deltaAngle = twoPi;
  22314. }
  22315. }
  22316. if (this.aClockwise === true && !samePoints) {
  22317. if (deltaAngle === twoPi) {
  22318. deltaAngle = -twoPi;
  22319. } else {
  22320. deltaAngle = deltaAngle - twoPi;
  22321. }
  22322. }
  22323. var angle = this.aStartAngle + t * deltaAngle;
  22324. var x = this.aX + this.xRadius * Math.cos(angle);
  22325. var y = this.aY + this.yRadius * Math.sin(angle);
  22326. if (this.aRotation !== 0) {
  22327. var cos = Math.cos(this.aRotation);
  22328. var sin = Math.sin(this.aRotation);
  22329. var tx = x - this.aX;
  22330. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22331. x = tx * cos - ty * sin + this.aX;
  22332. y = tx * sin + ty * cos + this.aY;
  22333. }
  22334. return point.set(x, y);
  22335. };
  22336. EllipseCurve.prototype.copy = function (source) {
  22337. Curve.prototype.copy.call(this, source);
  22338. this.aX = source.aX;
  22339. this.aY = source.aY;
  22340. this.xRadius = source.xRadius;
  22341. this.yRadius = source.yRadius;
  22342. this.aStartAngle = source.aStartAngle;
  22343. this.aEndAngle = source.aEndAngle;
  22344. this.aClockwise = source.aClockwise;
  22345. this.aRotation = source.aRotation;
  22346. return this;
  22347. };
  22348. EllipseCurve.prototype.toJSON = function () {
  22349. var data = Curve.prototype.toJSON.call(this);
  22350. data.aX = this.aX;
  22351. data.aY = this.aY;
  22352. data.xRadius = this.xRadius;
  22353. data.yRadius = this.yRadius;
  22354. data.aStartAngle = this.aStartAngle;
  22355. data.aEndAngle = this.aEndAngle;
  22356. data.aClockwise = this.aClockwise;
  22357. data.aRotation = this.aRotation;
  22358. return data;
  22359. };
  22360. EllipseCurve.prototype.fromJSON = function (json) {
  22361. Curve.prototype.fromJSON.call(this, json);
  22362. this.aX = json.aX;
  22363. this.aY = json.aY;
  22364. this.xRadius = json.xRadius;
  22365. this.yRadius = json.yRadius;
  22366. this.aStartAngle = json.aStartAngle;
  22367. this.aEndAngle = json.aEndAngle;
  22368. this.aClockwise = json.aClockwise;
  22369. this.aRotation = json.aRotation;
  22370. return this;
  22371. };
  22372. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22373. EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  22374. this.type = 'ArcCurve';
  22375. }
  22376. ArcCurve.prototype = Object.create(EllipseCurve.prototype);
  22377. ArcCurve.prototype.constructor = ArcCurve;
  22378. ArcCurve.prototype.isArcCurve = true;
  22379. /**
  22380. * Centripetal CatmullRom Curve - which is useful for avoiding
  22381. * cusps and self-intersections in non-uniform catmull rom curves.
  22382. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22383. *
  22384. * curve.type accepts centripetal(default), chordal and catmullrom
  22385. * curve.tension is used for catmullrom which defaults to 0.5
  22386. */
  22387. /*
  22388. Based on an optimized c++ solution in
  22389. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22390. - http://ideone.com/NoEbVM
  22391. This CubicPoly class could be used for reusing some variables and calculations,
  22392. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22393. which can be placed in CurveUtils.
  22394. */
  22395. function CubicPoly() {
  22396. var c0 = 0,
  22397. c1 = 0,
  22398. c2 = 0,
  22399. c3 = 0;
  22400. /*
  22401. * Compute coefficients for a cubic polynomial
  22402. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22403. * such that
  22404. * p(0) = x0, p(1) = x1
  22405. * and
  22406. * p'(0) = t0, p'(1) = t1.
  22407. */
  22408. function init(x0, x1, t0, t1) {
  22409. c0 = x0;
  22410. c1 = t0;
  22411. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22412. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22413. }
  22414. return {
  22415. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22416. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22417. },
  22418. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22419. // compute tangents when parameterized in [t1,t2]
  22420. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22421. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22422. t1 *= dt1;
  22423. t2 *= dt1;
  22424. init(x1, x2, t1, t2);
  22425. },
  22426. calc: function calc(t) {
  22427. var t2 = t * t;
  22428. var t3 = t2 * t;
  22429. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22430. }
  22431. };
  22432. } //
  22433. var tmp = new Vector3();
  22434. var px = new CubicPoly(),
  22435. py = new CubicPoly(),
  22436. pz = new CubicPoly();
  22437. function CatmullRomCurve3(points, closed, curveType, tension) {
  22438. Curve.call(this);
  22439. this.type = 'CatmullRomCurve3';
  22440. this.points = points || [];
  22441. this.closed = closed || false;
  22442. this.curveType = curveType || 'centripetal';
  22443. this.tension = tension !== undefined ? tension : 0.5;
  22444. }
  22445. CatmullRomCurve3.prototype = Object.create(Curve.prototype);
  22446. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22447. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22448. CatmullRomCurve3.prototype.getPoint = function (t, optionalTarget) {
  22449. var point = optionalTarget || new Vector3();
  22450. var points = this.points;
  22451. var l = points.length;
  22452. var p = (l - (this.closed ? 0 : 1)) * t;
  22453. var intPoint = Math.floor(p);
  22454. var weight = p - intPoint;
  22455. if (this.closed) {
  22456. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22457. } else if (weight === 0 && intPoint === l - 1) {
  22458. intPoint = l - 2;
  22459. weight = 1;
  22460. }
  22461. var p0, p3; // 4 points (p1 & p2 defined below)
  22462. if (this.closed || intPoint > 0) {
  22463. p0 = points[(intPoint - 1) % l];
  22464. } else {
  22465. // extrapolate first point
  22466. tmp.subVectors(points[0], points[1]).add(points[0]);
  22467. p0 = tmp;
  22468. }
  22469. var p1 = points[intPoint % l];
  22470. var p2 = points[(intPoint + 1) % l];
  22471. if (this.closed || intPoint + 2 < l) {
  22472. p3 = points[(intPoint + 2) % l];
  22473. } else {
  22474. // extrapolate last point
  22475. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  22476. p3 = tmp;
  22477. }
  22478. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  22479. // init Centripetal / Chordal Catmull-Rom
  22480. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22481. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  22482. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  22483. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  22484. if (dt1 < 1e-4) dt1 = 1.0;
  22485. if (dt0 < 1e-4) dt0 = dt1;
  22486. if (dt2 < 1e-4) dt2 = dt1;
  22487. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  22488. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  22489. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  22490. } else if (this.curveType === 'catmullrom') {
  22491. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  22492. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  22493. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  22494. }
  22495. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  22496. return point;
  22497. };
  22498. CatmullRomCurve3.prototype.copy = function (source) {
  22499. Curve.prototype.copy.call(this, source);
  22500. this.points = [];
  22501. for (var i = 0, l = source.points.length; i < l; i++) {
  22502. var point = source.points[i];
  22503. this.points.push(point.clone());
  22504. }
  22505. this.closed = source.closed;
  22506. this.curveType = source.curveType;
  22507. this.tension = source.tension;
  22508. return this;
  22509. };
  22510. CatmullRomCurve3.prototype.toJSON = function () {
  22511. var data = Curve.prototype.toJSON.call(this);
  22512. data.points = [];
  22513. for (var i = 0, l = this.points.length; i < l; i++) {
  22514. var point = this.points[i];
  22515. data.points.push(point.toArray());
  22516. }
  22517. data.closed = this.closed;
  22518. data.curveType = this.curveType;
  22519. data.tension = this.tension;
  22520. return data;
  22521. };
  22522. CatmullRomCurve3.prototype.fromJSON = function (json) {
  22523. Curve.prototype.fromJSON.call(this, json);
  22524. this.points = [];
  22525. for (var i = 0, l = json.points.length; i < l; i++) {
  22526. var point = json.points[i];
  22527. this.points.push(new Vector3().fromArray(point));
  22528. }
  22529. this.closed = json.closed;
  22530. this.curveType = json.curveType;
  22531. this.tension = json.tension;
  22532. return this;
  22533. };
  22534. /**
  22535. * Bezier Curves formulas obtained from
  22536. * http://en.wikipedia.org/wiki/Bézier_curve
  22537. */
  22538. function CatmullRom(t, p0, p1, p2, p3) {
  22539. var v0 = (p2 - p0) * 0.5;
  22540. var v1 = (p3 - p1) * 0.5;
  22541. var t2 = t * t;
  22542. var t3 = t * t2;
  22543. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  22544. } //
  22545. function QuadraticBezierP0(t, p) {
  22546. var k = 1 - t;
  22547. return k * k * p;
  22548. }
  22549. function QuadraticBezierP1(t, p) {
  22550. return 2 * (1 - t) * t * p;
  22551. }
  22552. function QuadraticBezierP2(t, p) {
  22553. return t * t * p;
  22554. }
  22555. function QuadraticBezier(t, p0, p1, p2) {
  22556. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  22557. } //
  22558. function CubicBezierP0(t, p) {
  22559. var k = 1 - t;
  22560. return k * k * k * p;
  22561. }
  22562. function CubicBezierP1(t, p) {
  22563. var k = 1 - t;
  22564. return 3 * k * k * t * p;
  22565. }
  22566. function CubicBezierP2(t, p) {
  22567. return 3 * (1 - t) * t * t * p;
  22568. }
  22569. function CubicBezierP3(t, p) {
  22570. return t * t * t * p;
  22571. }
  22572. function CubicBezier(t, p0, p1, p2, p3) {
  22573. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  22574. }
  22575. function CubicBezierCurve(v0, v1, v2, v3) {
  22576. Curve.call(this);
  22577. this.type = 'CubicBezierCurve';
  22578. this.v0 = v0 || new Vector2();
  22579. this.v1 = v1 || new Vector2();
  22580. this.v2 = v2 || new Vector2();
  22581. this.v3 = v3 || new Vector2();
  22582. }
  22583. CubicBezierCurve.prototype = Object.create(Curve.prototype);
  22584. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  22585. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  22586. CubicBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22587. var point = optionalTarget || new Vector2();
  22588. var v0 = this.v0,
  22589. v1 = this.v1,
  22590. v2 = this.v2,
  22591. v3 = this.v3;
  22592. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  22593. return point;
  22594. };
  22595. CubicBezierCurve.prototype.copy = function (source) {
  22596. Curve.prototype.copy.call(this, source);
  22597. this.v0.copy(source.v0);
  22598. this.v1.copy(source.v1);
  22599. this.v2.copy(source.v2);
  22600. this.v3.copy(source.v3);
  22601. return this;
  22602. };
  22603. CubicBezierCurve.prototype.toJSON = function () {
  22604. var data = Curve.prototype.toJSON.call(this);
  22605. data.v0 = this.v0.toArray();
  22606. data.v1 = this.v1.toArray();
  22607. data.v2 = this.v2.toArray();
  22608. data.v3 = this.v3.toArray();
  22609. return data;
  22610. };
  22611. CubicBezierCurve.prototype.fromJSON = function (json) {
  22612. Curve.prototype.fromJSON.call(this, json);
  22613. this.v0.fromArray(json.v0);
  22614. this.v1.fromArray(json.v1);
  22615. this.v2.fromArray(json.v2);
  22616. this.v3.fromArray(json.v3);
  22617. return this;
  22618. };
  22619. function CubicBezierCurve3(v0, v1, v2, v3) {
  22620. Curve.call(this);
  22621. this.type = 'CubicBezierCurve3';
  22622. this.v0 = v0 || new Vector3();
  22623. this.v1 = v1 || new Vector3();
  22624. this.v2 = v2 || new Vector3();
  22625. this.v3 = v3 || new Vector3();
  22626. }
  22627. CubicBezierCurve3.prototype = Object.create(Curve.prototype);
  22628. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  22629. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  22630. CubicBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22631. var point = optionalTarget || new Vector3();
  22632. var v0 = this.v0,
  22633. v1 = this.v1,
  22634. v2 = this.v2,
  22635. v3 = this.v3;
  22636. 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));
  22637. return point;
  22638. };
  22639. CubicBezierCurve3.prototype.copy = function (source) {
  22640. Curve.prototype.copy.call(this, source);
  22641. this.v0.copy(source.v0);
  22642. this.v1.copy(source.v1);
  22643. this.v2.copy(source.v2);
  22644. this.v3.copy(source.v3);
  22645. return this;
  22646. };
  22647. CubicBezierCurve3.prototype.toJSON = function () {
  22648. var data = Curve.prototype.toJSON.call(this);
  22649. data.v0 = this.v0.toArray();
  22650. data.v1 = this.v1.toArray();
  22651. data.v2 = this.v2.toArray();
  22652. data.v3 = this.v3.toArray();
  22653. return data;
  22654. };
  22655. CubicBezierCurve3.prototype.fromJSON = function (json) {
  22656. Curve.prototype.fromJSON.call(this, json);
  22657. this.v0.fromArray(json.v0);
  22658. this.v1.fromArray(json.v1);
  22659. this.v2.fromArray(json.v2);
  22660. this.v3.fromArray(json.v3);
  22661. return this;
  22662. };
  22663. function LineCurve(v1, v2) {
  22664. Curve.call(this);
  22665. this.type = 'LineCurve';
  22666. this.v1 = v1 || new Vector2();
  22667. this.v2 = v2 || new Vector2();
  22668. }
  22669. LineCurve.prototype = Object.create(Curve.prototype);
  22670. LineCurve.prototype.constructor = LineCurve;
  22671. LineCurve.prototype.isLineCurve = true;
  22672. LineCurve.prototype.getPoint = function (t, optionalTarget) {
  22673. var point = optionalTarget || new Vector2();
  22674. if (t === 1) {
  22675. point.copy(this.v2);
  22676. } else {
  22677. point.copy(this.v2).sub(this.v1);
  22678. point.multiplyScalar(t).add(this.v1);
  22679. }
  22680. return point;
  22681. }; // Line curve is linear, so we can overwrite default getPointAt
  22682. LineCurve.prototype.getPointAt = function (u, optionalTarget) {
  22683. return this.getPoint(u, optionalTarget);
  22684. };
  22685. LineCurve.prototype.getTangent = function (t, optionalTarget) {
  22686. var tangent = optionalTarget || new Vector2();
  22687. tangent.copy(this.v2).sub(this.v1).normalize();
  22688. return tangent;
  22689. };
  22690. LineCurve.prototype.copy = function (source) {
  22691. Curve.prototype.copy.call(this, source);
  22692. this.v1.copy(source.v1);
  22693. this.v2.copy(source.v2);
  22694. return this;
  22695. };
  22696. LineCurve.prototype.toJSON = function () {
  22697. var data = Curve.prototype.toJSON.call(this);
  22698. data.v1 = this.v1.toArray();
  22699. data.v2 = this.v2.toArray();
  22700. return data;
  22701. };
  22702. LineCurve.prototype.fromJSON = function (json) {
  22703. Curve.prototype.fromJSON.call(this, json);
  22704. this.v1.fromArray(json.v1);
  22705. this.v2.fromArray(json.v2);
  22706. return this;
  22707. };
  22708. function LineCurve3(v1, v2) {
  22709. Curve.call(this);
  22710. this.type = 'LineCurve3';
  22711. this.v1 = v1 || new Vector3();
  22712. this.v2 = v2 || new Vector3();
  22713. }
  22714. LineCurve3.prototype = Object.create(Curve.prototype);
  22715. LineCurve3.prototype.constructor = LineCurve3;
  22716. LineCurve3.prototype.isLineCurve3 = true;
  22717. LineCurve3.prototype.getPoint = function (t, optionalTarget) {
  22718. var point = optionalTarget || new Vector3();
  22719. if (t === 1) {
  22720. point.copy(this.v2);
  22721. } else {
  22722. point.copy(this.v2).sub(this.v1);
  22723. point.multiplyScalar(t).add(this.v1);
  22724. }
  22725. return point;
  22726. }; // Line curve is linear, so we can overwrite default getPointAt
  22727. LineCurve3.prototype.getPointAt = function (u, optionalTarget) {
  22728. return this.getPoint(u, optionalTarget);
  22729. };
  22730. LineCurve3.prototype.copy = function (source) {
  22731. Curve.prototype.copy.call(this, source);
  22732. this.v1.copy(source.v1);
  22733. this.v2.copy(source.v2);
  22734. return this;
  22735. };
  22736. LineCurve3.prototype.toJSON = function () {
  22737. var data = Curve.prototype.toJSON.call(this);
  22738. data.v1 = this.v1.toArray();
  22739. data.v2 = this.v2.toArray();
  22740. return data;
  22741. };
  22742. LineCurve3.prototype.fromJSON = function (json) {
  22743. Curve.prototype.fromJSON.call(this, json);
  22744. this.v1.fromArray(json.v1);
  22745. this.v2.fromArray(json.v2);
  22746. return this;
  22747. };
  22748. function QuadraticBezierCurve(v0, v1, v2) {
  22749. Curve.call(this);
  22750. this.type = 'QuadraticBezierCurve';
  22751. this.v0 = v0 || new Vector2();
  22752. this.v1 = v1 || new Vector2();
  22753. this.v2 = v2 || new Vector2();
  22754. }
  22755. QuadraticBezierCurve.prototype = Object.create(Curve.prototype);
  22756. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  22757. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22758. QuadraticBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22759. var point = optionalTarget || new Vector2();
  22760. var v0 = this.v0,
  22761. v1 = this.v1,
  22762. v2 = this.v2;
  22763. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  22764. return point;
  22765. };
  22766. QuadraticBezierCurve.prototype.copy = function (source) {
  22767. Curve.prototype.copy.call(this, source);
  22768. this.v0.copy(source.v0);
  22769. this.v1.copy(source.v1);
  22770. this.v2.copy(source.v2);
  22771. return this;
  22772. };
  22773. QuadraticBezierCurve.prototype.toJSON = function () {
  22774. var data = Curve.prototype.toJSON.call(this);
  22775. data.v0 = this.v0.toArray();
  22776. data.v1 = this.v1.toArray();
  22777. data.v2 = this.v2.toArray();
  22778. return data;
  22779. };
  22780. QuadraticBezierCurve.prototype.fromJSON = function (json) {
  22781. Curve.prototype.fromJSON.call(this, json);
  22782. this.v0.fromArray(json.v0);
  22783. this.v1.fromArray(json.v1);
  22784. this.v2.fromArray(json.v2);
  22785. return this;
  22786. };
  22787. function QuadraticBezierCurve3(v0, v1, v2) {
  22788. Curve.call(this);
  22789. this.type = 'QuadraticBezierCurve3';
  22790. this.v0 = v0 || new Vector3();
  22791. this.v1 = v1 || new Vector3();
  22792. this.v2 = v2 || new Vector3();
  22793. }
  22794. QuadraticBezierCurve3.prototype = Object.create(Curve.prototype);
  22795. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22796. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22797. QuadraticBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22798. var point = optionalTarget || new Vector3();
  22799. var v0 = this.v0,
  22800. v1 = this.v1,
  22801. v2 = this.v2;
  22802. 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));
  22803. return point;
  22804. };
  22805. QuadraticBezierCurve3.prototype.copy = function (source) {
  22806. Curve.prototype.copy.call(this, source);
  22807. this.v0.copy(source.v0);
  22808. this.v1.copy(source.v1);
  22809. this.v2.copy(source.v2);
  22810. return this;
  22811. };
  22812. QuadraticBezierCurve3.prototype.toJSON = function () {
  22813. var data = Curve.prototype.toJSON.call(this);
  22814. data.v0 = this.v0.toArray();
  22815. data.v1 = this.v1.toArray();
  22816. data.v2 = this.v2.toArray();
  22817. return data;
  22818. };
  22819. QuadraticBezierCurve3.prototype.fromJSON = function (json) {
  22820. Curve.prototype.fromJSON.call(this, json);
  22821. this.v0.fromArray(json.v0);
  22822. this.v1.fromArray(json.v1);
  22823. this.v2.fromArray(json.v2);
  22824. return this;
  22825. };
  22826. function SplineCurve(points) {
  22827. Curve.call(this);
  22828. this.type = 'SplineCurve';
  22829. this.points = points || [];
  22830. }
  22831. SplineCurve.prototype = Object.create(Curve.prototype);
  22832. SplineCurve.prototype.constructor = SplineCurve;
  22833. SplineCurve.prototype.isSplineCurve = true;
  22834. SplineCurve.prototype.getPoint = function (t, optionalTarget) {
  22835. var point = optionalTarget || new Vector2();
  22836. var points = this.points;
  22837. var p = (points.length - 1) * t;
  22838. var intPoint = Math.floor(p);
  22839. var weight = p - intPoint;
  22840. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  22841. var p1 = points[intPoint];
  22842. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  22843. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  22844. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  22845. return point;
  22846. };
  22847. SplineCurve.prototype.copy = function (source) {
  22848. Curve.prototype.copy.call(this, source);
  22849. this.points = [];
  22850. for (var i = 0, l = source.points.length; i < l; i++) {
  22851. var point = source.points[i];
  22852. this.points.push(point.clone());
  22853. }
  22854. return this;
  22855. };
  22856. SplineCurve.prototype.toJSON = function () {
  22857. var data = Curve.prototype.toJSON.call(this);
  22858. data.points = [];
  22859. for (var i = 0, l = this.points.length; i < l; i++) {
  22860. var point = this.points[i];
  22861. data.points.push(point.toArray());
  22862. }
  22863. return data;
  22864. };
  22865. SplineCurve.prototype.fromJSON = function (json) {
  22866. Curve.prototype.fromJSON.call(this, json);
  22867. this.points = [];
  22868. for (var i = 0, l = json.points.length; i < l; i++) {
  22869. var point = json.points[i];
  22870. this.points.push(new Vector2().fromArray(point));
  22871. }
  22872. return this;
  22873. };
  22874. var Curves = /*#__PURE__*/Object.freeze({
  22875. __proto__: null,
  22876. ArcCurve: ArcCurve,
  22877. CatmullRomCurve3: CatmullRomCurve3,
  22878. CubicBezierCurve: CubicBezierCurve,
  22879. CubicBezierCurve3: CubicBezierCurve3,
  22880. EllipseCurve: EllipseCurve,
  22881. LineCurve: LineCurve,
  22882. LineCurve3: LineCurve3,
  22883. QuadraticBezierCurve: QuadraticBezierCurve,
  22884. QuadraticBezierCurve3: QuadraticBezierCurve3,
  22885. SplineCurve: SplineCurve
  22886. });
  22887. /**************************************************************
  22888. * Curved Path - a curve path is simply a array of connected
  22889. * curves, but retains the api of a curve
  22890. **************************************************************/
  22891. function CurvePath() {
  22892. Curve.call(this);
  22893. this.type = 'CurvePath';
  22894. this.curves = [];
  22895. this.autoClose = false; // Automatically closes the path
  22896. }
  22897. CurvePath.prototype = Object.assign(Object.create(Curve.prototype), {
  22898. constructor: CurvePath,
  22899. add: function add(curve) {
  22900. this.curves.push(curve);
  22901. },
  22902. closePath: function closePath() {
  22903. // Add a line curve if start and end of lines are not connected
  22904. var startPoint = this.curves[0].getPoint(0);
  22905. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  22906. if (!startPoint.equals(endPoint)) {
  22907. this.curves.push(new LineCurve(endPoint, startPoint));
  22908. }
  22909. },
  22910. // To get accurate point with reference to
  22911. // entire path distance at time t,
  22912. // following has to be done:
  22913. // 1. Length of each sub path have to be known
  22914. // 2. Locate and identify type of curve
  22915. // 3. Get t for the curve
  22916. // 4. Return curve.getPointAt(t')
  22917. getPoint: function getPoint(t) {
  22918. var d = t * this.getLength();
  22919. var curveLengths = this.getCurveLengths();
  22920. var i = 0; // To think about boundaries points.
  22921. while (i < curveLengths.length) {
  22922. if (curveLengths[i] >= d) {
  22923. var diff = curveLengths[i] - d;
  22924. var curve = this.curves[i];
  22925. var segmentLength = curve.getLength();
  22926. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  22927. return curve.getPointAt(u);
  22928. }
  22929. i++;
  22930. }
  22931. return null; // loop where sum != 0, sum > d , sum+1 <d
  22932. },
  22933. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  22934. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  22935. // getPoint() depends on getLength
  22936. getLength: function getLength() {
  22937. var lens = this.getCurveLengths();
  22938. return lens[lens.length - 1];
  22939. },
  22940. // cacheLengths must be recalculated.
  22941. updateArcLengths: function updateArcLengths() {
  22942. this.needsUpdate = true;
  22943. this.cacheLengths = null;
  22944. this.getCurveLengths();
  22945. },
  22946. // Compute lengths and cache them
  22947. // We cannot overwrite getLengths() because UtoT mapping uses it.
  22948. getCurveLengths: function getCurveLengths() {
  22949. // We use cache values if curves and cache array are same length
  22950. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  22951. return this.cacheLengths;
  22952. } // Get length of sub-curve
  22953. // Push sums into cached array
  22954. var lengths = [];
  22955. var sums = 0;
  22956. for (var i = 0, l = this.curves.length; i < l; i++) {
  22957. sums += this.curves[i].getLength();
  22958. lengths.push(sums);
  22959. }
  22960. this.cacheLengths = lengths;
  22961. return lengths;
  22962. },
  22963. getSpacedPoints: function getSpacedPoints(divisions) {
  22964. if (divisions === undefined) divisions = 40;
  22965. var points = [];
  22966. for (var i = 0; i <= divisions; i++) {
  22967. points.push(this.getPoint(i / divisions));
  22968. }
  22969. if (this.autoClose) {
  22970. points.push(points[0]);
  22971. }
  22972. return points;
  22973. },
  22974. getPoints: function getPoints(divisions) {
  22975. divisions = divisions || 12;
  22976. var points = [];
  22977. var last;
  22978. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  22979. var curve = curves[i];
  22980. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  22981. var pts = curve.getPoints(resolution);
  22982. for (var j = 0; j < pts.length; j++) {
  22983. var point = pts[j];
  22984. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  22985. points.push(point);
  22986. last = point;
  22987. }
  22988. }
  22989. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  22990. points.push(points[0]);
  22991. }
  22992. return points;
  22993. },
  22994. copy: function copy(source) {
  22995. Curve.prototype.copy.call(this, source);
  22996. this.curves = [];
  22997. for (var i = 0, l = source.curves.length; i < l; i++) {
  22998. var curve = source.curves[i];
  22999. this.curves.push(curve.clone());
  23000. }
  23001. this.autoClose = source.autoClose;
  23002. return this;
  23003. },
  23004. toJSON: function toJSON() {
  23005. var data = Curve.prototype.toJSON.call(this);
  23006. data.autoClose = this.autoClose;
  23007. data.curves = [];
  23008. for (var i = 0, l = this.curves.length; i < l; i++) {
  23009. var curve = this.curves[i];
  23010. data.curves.push(curve.toJSON());
  23011. }
  23012. return data;
  23013. },
  23014. fromJSON: function fromJSON(json) {
  23015. Curve.prototype.fromJSON.call(this, json);
  23016. this.autoClose = json.autoClose;
  23017. this.curves = [];
  23018. for (var i = 0, l = json.curves.length; i < l; i++) {
  23019. var curve = json.curves[i];
  23020. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  23021. }
  23022. return this;
  23023. }
  23024. });
  23025. function Path(points) {
  23026. CurvePath.call(this);
  23027. this.type = 'Path';
  23028. this.currentPoint = new Vector2();
  23029. if (points) {
  23030. this.setFromPoints(points);
  23031. }
  23032. }
  23033. Path.prototype = Object.assign(Object.create(CurvePath.prototype), {
  23034. constructor: Path,
  23035. setFromPoints: function setFromPoints(points) {
  23036. this.moveTo(points[0].x, points[0].y);
  23037. for (var i = 1, l = points.length; i < l; i++) {
  23038. this.lineTo(points[i].x, points[i].y);
  23039. }
  23040. return this;
  23041. },
  23042. moveTo: function moveTo(x, y) {
  23043. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  23044. return this;
  23045. },
  23046. lineTo: function lineTo(x, y) {
  23047. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  23048. this.curves.push(curve);
  23049. this.currentPoint.set(x, y);
  23050. return this;
  23051. },
  23052. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  23053. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  23054. this.curves.push(curve);
  23055. this.currentPoint.set(aX, aY);
  23056. return this;
  23057. },
  23058. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  23059. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  23060. this.curves.push(curve);
  23061. this.currentPoint.set(aX, aY);
  23062. return this;
  23063. },
  23064. splineThru: function splineThru(pts
  23065. /*Array of Vector*/
  23066. ) {
  23067. var npts = [this.currentPoint.clone()].concat(pts);
  23068. var curve = new SplineCurve(npts);
  23069. this.curves.push(curve);
  23070. this.currentPoint.copy(pts[pts.length - 1]);
  23071. return this;
  23072. },
  23073. arc: function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23074. var x0 = this.currentPoint.x;
  23075. var y0 = this.currentPoint.y;
  23076. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  23077. return this;
  23078. },
  23079. absarc: function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23080. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  23081. return this;
  23082. },
  23083. ellipse: function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23084. var x0 = this.currentPoint.x;
  23085. var y0 = this.currentPoint.y;
  23086. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23087. return this;
  23088. },
  23089. absellipse: function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23090. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23091. if (this.curves.length > 0) {
  23092. // if a previous curve is present, attempt to join
  23093. var firstPoint = curve.getPoint(0);
  23094. if (!firstPoint.equals(this.currentPoint)) {
  23095. this.lineTo(firstPoint.x, firstPoint.y);
  23096. }
  23097. }
  23098. this.curves.push(curve);
  23099. var lastPoint = curve.getPoint(1);
  23100. this.currentPoint.copy(lastPoint);
  23101. return this;
  23102. },
  23103. copy: function copy(source) {
  23104. CurvePath.prototype.copy.call(this, source);
  23105. this.currentPoint.copy(source.currentPoint);
  23106. return this;
  23107. },
  23108. toJSON: function toJSON() {
  23109. var data = CurvePath.prototype.toJSON.call(this);
  23110. data.currentPoint = this.currentPoint.toArray();
  23111. return data;
  23112. },
  23113. fromJSON: function fromJSON(json) {
  23114. CurvePath.prototype.fromJSON.call(this, json);
  23115. this.currentPoint.fromArray(json.currentPoint);
  23116. return this;
  23117. }
  23118. });
  23119. function Shape(points) {
  23120. Path.call(this, points);
  23121. this.uuid = MathUtils.generateUUID();
  23122. this.type = 'Shape';
  23123. this.holes = [];
  23124. }
  23125. Shape.prototype = Object.assign(Object.create(Path.prototype), {
  23126. constructor: Shape,
  23127. getPointsHoles: function getPointsHoles(divisions) {
  23128. var holesPts = [];
  23129. for (var i = 0, l = this.holes.length; i < l; i++) {
  23130. holesPts[i] = this.holes[i].getPoints(divisions);
  23131. }
  23132. return holesPts;
  23133. },
  23134. // get points of shape and holes (keypoints based on segments parameter)
  23135. extractPoints: function extractPoints(divisions) {
  23136. return {
  23137. shape: this.getPoints(divisions),
  23138. holes: this.getPointsHoles(divisions)
  23139. };
  23140. },
  23141. copy: function copy(source) {
  23142. Path.prototype.copy.call(this, source);
  23143. this.holes = [];
  23144. for (var i = 0, l = source.holes.length; i < l; i++) {
  23145. var hole = source.holes[i];
  23146. this.holes.push(hole.clone());
  23147. }
  23148. return this;
  23149. },
  23150. toJSON: function toJSON() {
  23151. var data = Path.prototype.toJSON.call(this);
  23152. data.uuid = this.uuid;
  23153. data.holes = [];
  23154. for (var i = 0, l = this.holes.length; i < l; i++) {
  23155. var hole = this.holes[i];
  23156. data.holes.push(hole.toJSON());
  23157. }
  23158. return data;
  23159. },
  23160. fromJSON: function fromJSON(json) {
  23161. Path.prototype.fromJSON.call(this, json);
  23162. this.uuid = json.uuid;
  23163. this.holes = [];
  23164. for (var i = 0, l = json.holes.length; i < l; i++) {
  23165. var hole = json.holes[i];
  23166. this.holes.push(new Path().fromJSON(hole));
  23167. }
  23168. return this;
  23169. }
  23170. });
  23171. function Light(color, intensity) {
  23172. Object3D.call(this);
  23173. this.type = 'Light';
  23174. this.color = new Color(color);
  23175. this.intensity = intensity !== undefined ? intensity : 1;
  23176. }
  23177. Light.prototype = Object.assign(Object.create(Object3D.prototype), {
  23178. constructor: Light,
  23179. isLight: true,
  23180. copy: function copy(source) {
  23181. Object3D.prototype.copy.call(this, source);
  23182. this.color.copy(source.color);
  23183. this.intensity = source.intensity;
  23184. return this;
  23185. },
  23186. toJSON: function toJSON(meta) {
  23187. var data = Object3D.prototype.toJSON.call(this, meta);
  23188. data.object.color = this.color.getHex();
  23189. data.object.intensity = this.intensity;
  23190. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23191. if (this.distance !== undefined) data.object.distance = this.distance;
  23192. if (this.angle !== undefined) data.object.angle = this.angle;
  23193. if (this.decay !== undefined) data.object.decay = this.decay;
  23194. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23195. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23196. return data;
  23197. }
  23198. });
  23199. function HemisphereLight(skyColor, groundColor, intensity) {
  23200. Light.call(this, skyColor, intensity);
  23201. this.type = 'HemisphereLight';
  23202. this.position.copy(Object3D.DefaultUp);
  23203. this.updateMatrix();
  23204. this.groundColor = new Color(groundColor);
  23205. }
  23206. HemisphereLight.prototype = Object.assign(Object.create(Light.prototype), {
  23207. constructor: HemisphereLight,
  23208. isHemisphereLight: true,
  23209. copy: function copy(source) {
  23210. Light.prototype.copy.call(this, source);
  23211. this.groundColor.copy(source.groundColor);
  23212. return this;
  23213. }
  23214. });
  23215. function LightShadow(camera) {
  23216. this.camera = camera;
  23217. this.bias = 0;
  23218. this.normalBias = 0;
  23219. this.radius = 1;
  23220. this.mapSize = new Vector2(512, 512);
  23221. this.map = null;
  23222. this.mapPass = null;
  23223. this.matrix = new Matrix4();
  23224. this.autoUpdate = true;
  23225. this.needsUpdate = false;
  23226. this._frustum = new Frustum();
  23227. this._frameExtents = new Vector2(1, 1);
  23228. this._viewportCount = 1;
  23229. this._viewports = [new Vector4(0, 0, 1, 1)];
  23230. }
  23231. Object.assign(LightShadow.prototype, {
  23232. _projScreenMatrix: new Matrix4(),
  23233. _lightPositionWorld: new Vector3(),
  23234. _lookTarget: new Vector3(),
  23235. getViewportCount: function getViewportCount() {
  23236. return this._viewportCount;
  23237. },
  23238. getFrustum: function getFrustum() {
  23239. return this._frustum;
  23240. },
  23241. updateMatrices: function updateMatrices(light) {
  23242. var shadowCamera = this.camera,
  23243. shadowMatrix = this.matrix,
  23244. projScreenMatrix = this._projScreenMatrix,
  23245. lookTarget = this._lookTarget,
  23246. lightPositionWorld = this._lightPositionWorld;
  23247. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23248. shadowCamera.position.copy(lightPositionWorld);
  23249. lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23250. shadowCamera.lookAt(lookTarget);
  23251. shadowCamera.updateMatrixWorld();
  23252. projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23253. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23254. 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);
  23255. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23256. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23257. },
  23258. getViewport: function getViewport(viewportIndex) {
  23259. return this._viewports[viewportIndex];
  23260. },
  23261. getFrameExtents: function getFrameExtents() {
  23262. return this._frameExtents;
  23263. },
  23264. copy: function copy(source) {
  23265. this.camera = source.camera.clone();
  23266. this.bias = source.bias;
  23267. this.radius = source.radius;
  23268. this.mapSize.copy(source.mapSize);
  23269. return this;
  23270. },
  23271. clone: function clone() {
  23272. return new this.constructor().copy(this);
  23273. },
  23274. toJSON: function toJSON() {
  23275. var object = {};
  23276. if (this.bias !== 0) object.bias = this.bias;
  23277. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23278. if (this.radius !== 1) object.radius = this.radius;
  23279. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23280. object.camera = this.camera.toJSON(false).object;
  23281. delete object.camera.matrix;
  23282. return object;
  23283. }
  23284. });
  23285. function SpotLightShadow() {
  23286. LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500));
  23287. this.focus = 1;
  23288. }
  23289. SpotLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23290. constructor: SpotLightShadow,
  23291. isSpotLightShadow: true,
  23292. updateMatrices: function updateMatrices(light) {
  23293. var camera = this.camera;
  23294. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23295. var aspect = this.mapSize.width / this.mapSize.height;
  23296. var far = light.distance || camera.far;
  23297. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23298. camera.fov = fov;
  23299. camera.aspect = aspect;
  23300. camera.far = far;
  23301. camera.updateProjectionMatrix();
  23302. }
  23303. LightShadow.prototype.updateMatrices.call(this, light);
  23304. }
  23305. });
  23306. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23307. Light.call(this, color, intensity);
  23308. this.type = 'SpotLight';
  23309. this.position.copy(Object3D.DefaultUp);
  23310. this.updateMatrix();
  23311. this.target = new Object3D();
  23312. Object.defineProperty(this, 'power', {
  23313. get: function get() {
  23314. // intensity = power per solid angle.
  23315. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23316. return this.intensity * Math.PI;
  23317. },
  23318. set: function set(power) {
  23319. // intensity = power per solid angle.
  23320. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23321. this.intensity = power / Math.PI;
  23322. }
  23323. });
  23324. this.distance = distance !== undefined ? distance : 0;
  23325. this.angle = angle !== undefined ? angle : Math.PI / 3;
  23326. this.penumbra = penumbra !== undefined ? penumbra : 0;
  23327. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23328. this.shadow = new SpotLightShadow();
  23329. }
  23330. SpotLight.prototype = Object.assign(Object.create(Light.prototype), {
  23331. constructor: SpotLight,
  23332. isSpotLight: true,
  23333. copy: function copy(source) {
  23334. Light.prototype.copy.call(this, source);
  23335. this.distance = source.distance;
  23336. this.angle = source.angle;
  23337. this.penumbra = source.penumbra;
  23338. this.decay = source.decay;
  23339. this.target = source.target.clone();
  23340. this.shadow = source.shadow.clone();
  23341. return this;
  23342. }
  23343. });
  23344. function PointLightShadow() {
  23345. LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500));
  23346. this._frameExtents = new Vector2(4, 2);
  23347. this._viewportCount = 6;
  23348. this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23349. // following orientation:
  23350. //
  23351. // xzXZ
  23352. // y Y
  23353. //
  23354. // X - Positive x direction
  23355. // x - Negative x direction
  23356. // Y - Positive y direction
  23357. // y - Negative y direction
  23358. // Z - Positive z direction
  23359. // z - Negative z direction
  23360. // positive X
  23361. new Vector4(2, 1, 1, 1), // negative X
  23362. new Vector4(0, 1, 1, 1), // positive Z
  23363. new Vector4(3, 1, 1, 1), // negative Z
  23364. new Vector4(1, 1, 1, 1), // positive Y
  23365. new Vector4(3, 0, 1, 1), // negative Y
  23366. new Vector4(1, 0, 1, 1)];
  23367. 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)];
  23368. 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)];
  23369. }
  23370. PointLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23371. constructor: PointLightShadow,
  23372. isPointLightShadow: true,
  23373. updateMatrices: function updateMatrices(light, viewportIndex) {
  23374. if (viewportIndex === undefined) viewportIndex = 0;
  23375. var camera = this.camera,
  23376. shadowMatrix = this.matrix,
  23377. lightPositionWorld = this._lightPositionWorld,
  23378. lookTarget = this._lookTarget,
  23379. projScreenMatrix = this._projScreenMatrix;
  23380. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23381. camera.position.copy(lightPositionWorld);
  23382. lookTarget.copy(camera.position);
  23383. lookTarget.add(this._cubeDirections[viewportIndex]);
  23384. camera.up.copy(this._cubeUps[viewportIndex]);
  23385. camera.lookAt(lookTarget);
  23386. camera.updateMatrixWorld();
  23387. shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
  23388. projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  23389. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23390. }
  23391. });
  23392. function PointLight(color, intensity, distance, decay) {
  23393. Light.call(this, color, intensity);
  23394. this.type = 'PointLight';
  23395. Object.defineProperty(this, 'power', {
  23396. get: function get() {
  23397. // intensity = power per solid angle.
  23398. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23399. return this.intensity * 4 * Math.PI;
  23400. },
  23401. set: function set(power) {
  23402. // intensity = power per solid angle.
  23403. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23404. this.intensity = power / (4 * Math.PI);
  23405. }
  23406. });
  23407. this.distance = distance !== undefined ? distance : 0;
  23408. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23409. this.shadow = new PointLightShadow();
  23410. }
  23411. PointLight.prototype = Object.assign(Object.create(Light.prototype), {
  23412. constructor: PointLight,
  23413. isPointLight: true,
  23414. copy: function copy(source) {
  23415. Light.prototype.copy.call(this, source);
  23416. this.distance = source.distance;
  23417. this.decay = source.decay;
  23418. this.shadow = source.shadow.clone();
  23419. return this;
  23420. }
  23421. });
  23422. function OrthographicCamera(left, right, top, bottom, near, far) {
  23423. Camera.call(this);
  23424. this.type = 'OrthographicCamera';
  23425. this.zoom = 1;
  23426. this.view = null;
  23427. this.left = left !== undefined ? left : -1;
  23428. this.right = right !== undefined ? right : 1;
  23429. this.top = top !== undefined ? top : 1;
  23430. this.bottom = bottom !== undefined ? bottom : -1;
  23431. this.near = near !== undefined ? near : 0.1;
  23432. this.far = far !== undefined ? far : 2000;
  23433. this.updateProjectionMatrix();
  23434. }
  23435. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  23436. constructor: OrthographicCamera,
  23437. isOrthographicCamera: true,
  23438. copy: function copy(source, recursive) {
  23439. Camera.prototype.copy.call(this, source, recursive);
  23440. this.left = source.left;
  23441. this.right = source.right;
  23442. this.top = source.top;
  23443. this.bottom = source.bottom;
  23444. this.near = source.near;
  23445. this.far = source.far;
  23446. this.zoom = source.zoom;
  23447. this.view = source.view === null ? null : Object.assign({}, source.view);
  23448. return this;
  23449. },
  23450. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  23451. if (this.view === null) {
  23452. this.view = {
  23453. enabled: true,
  23454. fullWidth: 1,
  23455. fullHeight: 1,
  23456. offsetX: 0,
  23457. offsetY: 0,
  23458. width: 1,
  23459. height: 1
  23460. };
  23461. }
  23462. this.view.enabled = true;
  23463. this.view.fullWidth = fullWidth;
  23464. this.view.fullHeight = fullHeight;
  23465. this.view.offsetX = x;
  23466. this.view.offsetY = y;
  23467. this.view.width = width;
  23468. this.view.height = height;
  23469. this.updateProjectionMatrix();
  23470. },
  23471. clearViewOffset: function clearViewOffset() {
  23472. if (this.view !== null) {
  23473. this.view.enabled = false;
  23474. }
  23475. this.updateProjectionMatrix();
  23476. },
  23477. updateProjectionMatrix: function updateProjectionMatrix() {
  23478. var dx = (this.right - this.left) / (2 * this.zoom);
  23479. var dy = (this.top - this.bottom) / (2 * this.zoom);
  23480. var cx = (this.right + this.left) / 2;
  23481. var cy = (this.top + this.bottom) / 2;
  23482. var left = cx - dx;
  23483. var right = cx + dx;
  23484. var top = cy + dy;
  23485. var bottom = cy - dy;
  23486. if (this.view !== null && this.view.enabled) {
  23487. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  23488. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  23489. left += scaleW * this.view.offsetX;
  23490. right = left + scaleW * this.view.width;
  23491. top -= scaleH * this.view.offsetY;
  23492. bottom = top - scaleH * this.view.height;
  23493. }
  23494. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  23495. this.projectionMatrixInverse.getInverse(this.projectionMatrix);
  23496. },
  23497. toJSON: function toJSON(meta) {
  23498. var data = Object3D.prototype.toJSON.call(this, meta);
  23499. data.object.zoom = this.zoom;
  23500. data.object.left = this.left;
  23501. data.object.right = this.right;
  23502. data.object.top = this.top;
  23503. data.object.bottom = this.bottom;
  23504. data.object.near = this.near;
  23505. data.object.far = this.far;
  23506. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  23507. return data;
  23508. }
  23509. });
  23510. function DirectionalLightShadow() {
  23511. LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
  23512. }
  23513. DirectionalLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23514. constructor: DirectionalLightShadow,
  23515. isDirectionalLightShadow: true,
  23516. updateMatrices: function updateMatrices(light) {
  23517. LightShadow.prototype.updateMatrices.call(this, light);
  23518. }
  23519. });
  23520. function DirectionalLight(color, intensity) {
  23521. Light.call(this, color, intensity);
  23522. this.type = 'DirectionalLight';
  23523. this.position.copy(Object3D.DefaultUp);
  23524. this.updateMatrix();
  23525. this.target = new Object3D();
  23526. this.shadow = new DirectionalLightShadow();
  23527. }
  23528. DirectionalLight.prototype = Object.assign(Object.create(Light.prototype), {
  23529. constructor: DirectionalLight,
  23530. isDirectionalLight: true,
  23531. copy: function copy(source) {
  23532. Light.prototype.copy.call(this, source);
  23533. this.target = source.target.clone();
  23534. this.shadow = source.shadow.clone();
  23535. return this;
  23536. }
  23537. });
  23538. function AmbientLight(color, intensity) {
  23539. Light.call(this, color, intensity);
  23540. this.type = 'AmbientLight';
  23541. }
  23542. AmbientLight.prototype = Object.assign(Object.create(Light.prototype), {
  23543. constructor: AmbientLight,
  23544. isAmbientLight: true
  23545. });
  23546. function RectAreaLight(color, intensity, width, height) {
  23547. Light.call(this, color, intensity);
  23548. this.type = 'RectAreaLight';
  23549. this.width = width !== undefined ? width : 10;
  23550. this.height = height !== undefined ? height : 10;
  23551. }
  23552. RectAreaLight.prototype = Object.assign(Object.create(Light.prototype), {
  23553. constructor: RectAreaLight,
  23554. isRectAreaLight: true,
  23555. copy: function copy(source) {
  23556. Light.prototype.copy.call(this, source);
  23557. this.width = source.width;
  23558. this.height = source.height;
  23559. return this;
  23560. },
  23561. toJSON: function toJSON(meta) {
  23562. var data = Light.prototype.toJSON.call(this, meta);
  23563. data.object.width = this.width;
  23564. data.object.height = this.height;
  23565. return data;
  23566. }
  23567. });
  23568. /**
  23569. * Primary reference:
  23570. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23571. *
  23572. * Secondary reference:
  23573. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23574. */
  23575. // 3-band SH defined by 9 coefficients
  23576. var SphericalHarmonics3 = /*#__PURE__*/function () {
  23577. function SphericalHarmonics3() {
  23578. Object.defineProperty(this, 'isSphericalHarmonics3', {
  23579. value: true
  23580. });
  23581. this.coefficients = [];
  23582. for (var i = 0; i < 9; i++) {
  23583. this.coefficients.push(new Vector3());
  23584. }
  23585. }
  23586. var _proto = SphericalHarmonics3.prototype;
  23587. _proto.set = function set(coefficients) {
  23588. for (var i = 0; i < 9; i++) {
  23589. this.coefficients[i].copy(coefficients[i]);
  23590. }
  23591. return this;
  23592. };
  23593. _proto.zero = function zero() {
  23594. for (var i = 0; i < 9; i++) {
  23595. this.coefficients[i].set(0, 0, 0);
  23596. }
  23597. return this;
  23598. } // get the radiance in the direction of the normal
  23599. // target is a Vector3
  23600. ;
  23601. _proto.getAt = function getAt(normal, target) {
  23602. // normal is assumed to be unit length
  23603. var x = normal.x,
  23604. y = normal.y,
  23605. z = normal.z;
  23606. var coeff = this.coefficients; // band 0
  23607. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  23608. target.addScaledVector(coeff[1], 0.488603 * y);
  23609. target.addScaledVector(coeff[2], 0.488603 * z);
  23610. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  23611. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  23612. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  23613. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  23614. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  23615. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  23616. return target;
  23617. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23618. // target is a Vector3
  23619. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23620. ;
  23621. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  23622. // normal is assumed to be unit length
  23623. var x = normal.x,
  23624. y = normal.y,
  23625. z = normal.z;
  23626. var coeff = this.coefficients; // band 0
  23627. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  23628. // band 1
  23629. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  23630. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  23631. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  23632. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  23633. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  23634. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  23635. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  23636. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  23637. return target;
  23638. };
  23639. _proto.add = function add(sh) {
  23640. for (var i = 0; i < 9; i++) {
  23641. this.coefficients[i].add(sh.coefficients[i]);
  23642. }
  23643. return this;
  23644. };
  23645. _proto.addScaledSH = function addScaledSH(sh, s) {
  23646. for (var i = 0; i < 9; i++) {
  23647. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  23648. }
  23649. return this;
  23650. };
  23651. _proto.scale = function scale(s) {
  23652. for (var i = 0; i < 9; i++) {
  23653. this.coefficients[i].multiplyScalar(s);
  23654. }
  23655. return this;
  23656. };
  23657. _proto.lerp = function lerp(sh, alpha) {
  23658. for (var i = 0; i < 9; i++) {
  23659. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  23660. }
  23661. return this;
  23662. };
  23663. _proto.equals = function equals(sh) {
  23664. for (var i = 0; i < 9; i++) {
  23665. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  23666. return false;
  23667. }
  23668. }
  23669. return true;
  23670. };
  23671. _proto.copy = function copy(sh) {
  23672. return this.set(sh.coefficients);
  23673. };
  23674. _proto.clone = function clone() {
  23675. return new this.constructor().copy(this);
  23676. };
  23677. _proto.fromArray = function fromArray(array, offset) {
  23678. if (offset === void 0) {
  23679. offset = 0;
  23680. }
  23681. var coefficients = this.coefficients;
  23682. for (var i = 0; i < 9; i++) {
  23683. coefficients[i].fromArray(array, offset + i * 3);
  23684. }
  23685. return this;
  23686. };
  23687. _proto.toArray = function toArray(array, offset) {
  23688. if (array === void 0) {
  23689. array = [];
  23690. }
  23691. if (offset === void 0) {
  23692. offset = 0;
  23693. }
  23694. var coefficients = this.coefficients;
  23695. for (var i = 0; i < 9; i++) {
  23696. coefficients[i].toArray(array, offset + i * 3);
  23697. }
  23698. return array;
  23699. } // evaluate the basis functions
  23700. // shBasis is an Array[ 9 ]
  23701. ;
  23702. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  23703. // normal is assumed to be unit length
  23704. var x = normal.x,
  23705. y = normal.y,
  23706. z = normal.z; // band 0
  23707. shBasis[0] = 0.282095; // band 1
  23708. shBasis[1] = 0.488603 * y;
  23709. shBasis[2] = 0.488603 * z;
  23710. shBasis[3] = 0.488603 * x; // band 2
  23711. shBasis[4] = 1.092548 * x * y;
  23712. shBasis[5] = 1.092548 * y * z;
  23713. shBasis[6] = 0.315392 * (3 * z * z - 1);
  23714. shBasis[7] = 1.092548 * x * z;
  23715. shBasis[8] = 0.546274 * (x * x - y * y);
  23716. };
  23717. return SphericalHarmonics3;
  23718. }();
  23719. function LightProbe(sh, intensity) {
  23720. Light.call(this, undefined, intensity);
  23721. this.type = 'LightProbe';
  23722. this.sh = sh !== undefined ? sh : new SphericalHarmonics3();
  23723. }
  23724. LightProbe.prototype = Object.assign(Object.create(Light.prototype), {
  23725. constructor: LightProbe,
  23726. isLightProbe: true,
  23727. copy: function copy(source) {
  23728. Light.prototype.copy.call(this, source);
  23729. this.sh.copy(source.sh);
  23730. return this;
  23731. },
  23732. fromJSON: function fromJSON(json) {
  23733. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  23734. this.sh.fromArray(json.sh);
  23735. return this;
  23736. },
  23737. toJSON: function toJSON(meta) {
  23738. var data = Light.prototype.toJSON.call(this, meta);
  23739. data.object.sh = this.sh.toArray();
  23740. return data;
  23741. }
  23742. });
  23743. function MaterialLoader(manager) {
  23744. Loader.call(this, manager);
  23745. this.textures = {};
  23746. }
  23747. MaterialLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  23748. constructor: MaterialLoader,
  23749. load: function load(url, onLoad, onProgress, onError) {
  23750. var scope = this;
  23751. var loader = new FileLoader(scope.manager);
  23752. loader.setPath(scope.path);
  23753. loader.setRequestHeader(scope.requestHeader);
  23754. loader.setWithCredentials(scope.withCredentials);
  23755. loader.load(url, function (text) {
  23756. try {
  23757. onLoad(scope.parse(JSON.parse(text)));
  23758. } catch (e) {
  23759. if (onError) {
  23760. onError(e);
  23761. } else {
  23762. console.error(e);
  23763. }
  23764. scope.manager.itemError(url);
  23765. }
  23766. }, onProgress, onError);
  23767. },
  23768. parse: function parse(json) {
  23769. var textures = this.textures;
  23770. function getTexture(name) {
  23771. if (textures[name] === undefined) {
  23772. console.warn('THREE.MaterialLoader: Undefined texture', name);
  23773. }
  23774. return textures[name];
  23775. }
  23776. var material = new Materials[json.type]();
  23777. if (json.uuid !== undefined) material.uuid = json.uuid;
  23778. if (json.name !== undefined) material.name = json.name;
  23779. if (json.color !== undefined) material.color.setHex(json.color);
  23780. if (json.roughness !== undefined) material.roughness = json.roughness;
  23781. if (json.metalness !== undefined) material.metalness = json.metalness;
  23782. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  23783. if (json.emissive !== undefined) material.emissive.setHex(json.emissive);
  23784. if (json.specular !== undefined) material.specular.setHex(json.specular);
  23785. if (json.shininess !== undefined) material.shininess = json.shininess;
  23786. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  23787. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  23788. if (json.fog !== undefined) material.fog = json.fog;
  23789. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  23790. if (json.blending !== undefined) material.blending = json.blending;
  23791. if (json.combine !== undefined) material.combine = json.combine;
  23792. if (json.side !== undefined) material.side = json.side;
  23793. if (json.opacity !== undefined) material.opacity = json.opacity;
  23794. if (json.transparent !== undefined) material.transparent = json.transparent;
  23795. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  23796. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  23797. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  23798. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  23799. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  23800. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  23801. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  23802. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  23803. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  23804. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  23805. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  23806. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  23807. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  23808. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  23809. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  23810. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  23811. if (json.rotation !== undefined) material.rotation = json.rotation;
  23812. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  23813. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  23814. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  23815. if (json.scale !== undefined) material.scale = json.scale;
  23816. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  23817. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  23818. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  23819. if (json.skinning !== undefined) material.skinning = json.skinning;
  23820. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  23821. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  23822. if (json.dithering !== undefined) material.dithering = json.dithering;
  23823. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  23824. if (json.visible !== undefined) material.visible = json.visible;
  23825. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  23826. if (json.userData !== undefined) material.userData = json.userData;
  23827. if (json.vertexColors !== undefined) {
  23828. if (typeof json.vertexColors === 'number') {
  23829. material.vertexColors = json.vertexColors > 0 ? true : false;
  23830. } else {
  23831. material.vertexColors = json.vertexColors;
  23832. }
  23833. } // Shader Material
  23834. if (json.uniforms !== undefined) {
  23835. for (var name in json.uniforms) {
  23836. var uniform = json.uniforms[name];
  23837. material.uniforms[name] = {};
  23838. switch (uniform.type) {
  23839. case 't':
  23840. material.uniforms[name].value = getTexture(uniform.value);
  23841. break;
  23842. case 'c':
  23843. material.uniforms[name].value = new Color().setHex(uniform.value);
  23844. break;
  23845. case 'v2':
  23846. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  23847. break;
  23848. case 'v3':
  23849. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  23850. break;
  23851. case 'v4':
  23852. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  23853. break;
  23854. case 'm3':
  23855. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  23856. break;
  23857. case 'm4':
  23858. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  23859. break;
  23860. default:
  23861. material.uniforms[name].value = uniform.value;
  23862. }
  23863. }
  23864. }
  23865. if (json.defines !== undefined) material.defines = json.defines;
  23866. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  23867. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  23868. if (json.extensions !== undefined) {
  23869. for (var key in json.extensions) {
  23870. material.extensions[key] = json.extensions[key];
  23871. }
  23872. } // Deprecated
  23873. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  23874. // for PointsMaterial
  23875. if (json.size !== undefined) material.size = json.size;
  23876. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  23877. if (json.map !== undefined) material.map = getTexture(json.map);
  23878. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  23879. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  23880. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  23881. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  23882. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  23883. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  23884. if (json.normalScale !== undefined) {
  23885. var normalScale = json.normalScale;
  23886. if (Array.isArray(normalScale) === false) {
  23887. // Blender exporter used to export a scalar. See #7459
  23888. normalScale = [normalScale, normalScale];
  23889. }
  23890. material.normalScale = new Vector2().fromArray(normalScale);
  23891. }
  23892. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  23893. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  23894. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  23895. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  23896. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  23897. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  23898. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  23899. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  23900. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  23901. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  23902. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  23903. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  23904. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  23905. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  23906. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  23907. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  23908. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  23909. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  23910. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  23911. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  23912. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  23913. if (json.transmission !== undefined) material.transmission = json.transmission;
  23914. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  23915. return material;
  23916. },
  23917. setTextures: function setTextures(value) {
  23918. this.textures = value;
  23919. return this;
  23920. }
  23921. });
  23922. var LoaderUtils = {
  23923. decodeText: function decodeText(array) {
  23924. if (typeof TextDecoder !== 'undefined') {
  23925. return new TextDecoder().decode(array);
  23926. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  23927. // throws a "maximum call stack size exceeded" error for large arrays.
  23928. var s = '';
  23929. for (var i = 0, il = array.length; i < il; i++) {
  23930. // Implicitly assumes little-endian.
  23931. s += String.fromCharCode(array[i]);
  23932. }
  23933. try {
  23934. // merges multi-byte utf-8 characters.
  23935. return decodeURIComponent(escape(s));
  23936. } catch (e) {
  23937. // see #16358
  23938. return s;
  23939. }
  23940. },
  23941. extractUrlBase: function extractUrlBase(url) {
  23942. var index = url.lastIndexOf('/');
  23943. if (index === -1) return './';
  23944. return url.substr(0, index + 1);
  23945. }
  23946. };
  23947. function InstancedBufferGeometry() {
  23948. BufferGeometry.call(this);
  23949. this.type = 'InstancedBufferGeometry';
  23950. this.instanceCount = Infinity;
  23951. }
  23952. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  23953. constructor: InstancedBufferGeometry,
  23954. isInstancedBufferGeometry: true,
  23955. copy: function copy(source) {
  23956. BufferGeometry.prototype.copy.call(this, source);
  23957. this.instanceCount = source.instanceCount;
  23958. return this;
  23959. },
  23960. clone: function clone() {
  23961. return new this.constructor().copy(this);
  23962. },
  23963. toJSON: function toJSON() {
  23964. var data = BufferGeometry.prototype.toJSON.call(this);
  23965. data.instanceCount = this.instanceCount;
  23966. data.isInstancedBufferGeometry = true;
  23967. return data;
  23968. }
  23969. });
  23970. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  23971. if (typeof normalized === 'number') {
  23972. meshPerAttribute = normalized;
  23973. normalized = false;
  23974. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  23975. }
  23976. BufferAttribute.call(this, array, itemSize, normalized);
  23977. this.meshPerAttribute = meshPerAttribute || 1;
  23978. }
  23979. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  23980. constructor: InstancedBufferAttribute,
  23981. isInstancedBufferAttribute: true,
  23982. copy: function copy(source) {
  23983. BufferAttribute.prototype.copy.call(this, source);
  23984. this.meshPerAttribute = source.meshPerAttribute;
  23985. return this;
  23986. },
  23987. toJSON: function toJSON() {
  23988. var data = BufferAttribute.prototype.toJSON.call(this);
  23989. data.meshPerAttribute = this.meshPerAttribute;
  23990. data.isInstancedBufferAttribute = true;
  23991. return data;
  23992. }
  23993. });
  23994. function BufferGeometryLoader(manager) {
  23995. Loader.call(this, manager);
  23996. }
  23997. BufferGeometryLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  23998. constructor: BufferGeometryLoader,
  23999. load: function load(url, onLoad, onProgress, onError) {
  24000. var scope = this;
  24001. var loader = new FileLoader(scope.manager);
  24002. loader.setPath(scope.path);
  24003. loader.setRequestHeader(scope.requestHeader);
  24004. loader.setWithCredentials(scope.withCredentials);
  24005. loader.load(url, function (text) {
  24006. try {
  24007. onLoad(scope.parse(JSON.parse(text)));
  24008. } catch (e) {
  24009. if (onError) {
  24010. onError(e);
  24011. } else {
  24012. console.error(e);
  24013. }
  24014. scope.manager.itemError(url);
  24015. }
  24016. }, onProgress, onError);
  24017. },
  24018. parse: function parse(json) {
  24019. var interleavedBufferMap = {};
  24020. var arrayBufferMap = {};
  24021. function getInterleavedBuffer(json, uuid) {
  24022. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  24023. var interleavedBuffers = json.interleavedBuffers;
  24024. var interleavedBuffer = interleavedBuffers[uuid];
  24025. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  24026. var array = new TYPED_ARRAYS[interleavedBuffer.type](buffer);
  24027. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  24028. ib.uuid = interleavedBuffer.uuid;
  24029. interleavedBufferMap[uuid] = ib;
  24030. return ib;
  24031. }
  24032. function getArrayBuffer(json, uuid) {
  24033. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  24034. var arrayBuffers = json.arrayBuffers;
  24035. var arrayBuffer = arrayBuffers[uuid];
  24036. var ab = new Uint32Array(arrayBuffer).buffer;
  24037. arrayBufferMap[uuid] = ab;
  24038. return ab;
  24039. }
  24040. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24041. var index = json.data.index;
  24042. if (index !== undefined) {
  24043. var typedArray = new TYPED_ARRAYS[index.type](index.array);
  24044. geometry.setIndex(new BufferAttribute(typedArray, 1));
  24045. }
  24046. var attributes = json.data.attributes;
  24047. for (var key in attributes) {
  24048. var attribute = attributes[key];
  24049. var bufferAttribute = void 0;
  24050. if (attribute.isInterleavedBufferAttribute) {
  24051. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  24052. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  24053. } else {
  24054. var _typedArray = new TYPED_ARRAYS[attribute.type](attribute.array);
  24055. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24056. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  24057. }
  24058. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  24059. geometry.setAttribute(key, bufferAttribute);
  24060. }
  24061. var morphAttributes = json.data.morphAttributes;
  24062. if (morphAttributes) {
  24063. for (var _key in morphAttributes) {
  24064. var attributeArray = morphAttributes[_key];
  24065. var array = [];
  24066. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24067. var _attribute = attributeArray[i];
  24068. var _bufferAttribute = void 0;
  24069. if (_attribute.isInterleavedBufferAttribute) {
  24070. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24071. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24072. } else {
  24073. var _typedArray2 = new TYPED_ARRAYS[_attribute.type](_attribute.array);
  24074. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24075. }
  24076. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24077. array.push(_bufferAttribute);
  24078. }
  24079. geometry.morphAttributes[_key] = array;
  24080. }
  24081. }
  24082. var morphTargetsRelative = json.data.morphTargetsRelative;
  24083. if (morphTargetsRelative) {
  24084. geometry.morphTargetsRelative = true;
  24085. }
  24086. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24087. if (groups !== undefined) {
  24088. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24089. var group = groups[_i];
  24090. geometry.addGroup(group.start, group.count, group.materialIndex);
  24091. }
  24092. }
  24093. var boundingSphere = json.data.boundingSphere;
  24094. if (boundingSphere !== undefined) {
  24095. var center = new Vector3();
  24096. if (boundingSphere.center !== undefined) {
  24097. center.fromArray(boundingSphere.center);
  24098. }
  24099. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24100. }
  24101. if (json.name) geometry.name = json.name;
  24102. if (json.userData) geometry.userData = json.userData;
  24103. return geometry;
  24104. }
  24105. });
  24106. var TYPED_ARRAYS = {
  24107. Int8Array: Int8Array,
  24108. Uint8Array: Uint8Array,
  24109. // Workaround for IE11 pre KB2929437. See #11440
  24110. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  24111. Int16Array: Int16Array,
  24112. Uint16Array: Uint16Array,
  24113. Int32Array: Int32Array,
  24114. Uint32Array: Uint32Array,
  24115. Float32Array: Float32Array,
  24116. Float64Array: Float64Array
  24117. };
  24118. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24119. _inheritsLoose(ObjectLoader, _Loader);
  24120. function ObjectLoader(manager) {
  24121. return _Loader.call(this, manager) || this;
  24122. }
  24123. var _proto = ObjectLoader.prototype;
  24124. _proto.load = function load(url, onLoad, onProgress, onError) {
  24125. var scope = this;
  24126. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24127. this.resourcePath = this.resourcePath || path;
  24128. var loader = new FileLoader(this.manager);
  24129. loader.setPath(this.path);
  24130. loader.setRequestHeader(this.requestHeader);
  24131. loader.setWithCredentials(this.withCredentials);
  24132. loader.load(url, function (text) {
  24133. var json = null;
  24134. try {
  24135. json = JSON.parse(text);
  24136. } catch (error) {
  24137. if (onError !== undefined) onError(error);
  24138. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24139. return;
  24140. }
  24141. var metadata = json.metadata;
  24142. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24143. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24144. return;
  24145. }
  24146. scope.parse(json, onLoad);
  24147. }, onProgress, onError);
  24148. };
  24149. _proto.parse = function parse(json, onLoad) {
  24150. var shapes = this.parseShape(json.shapes);
  24151. var geometries = this.parseGeometries(json.geometries, shapes);
  24152. var images = this.parseImages(json.images, function () {
  24153. if (onLoad !== undefined) onLoad(object);
  24154. });
  24155. var textures = this.parseTextures(json.textures, images);
  24156. var materials = this.parseMaterials(json.materials, textures);
  24157. var object = this.parseObject(json.object, geometries, materials);
  24158. if (json.animations) {
  24159. object.animations = this.parseAnimations(json.animations);
  24160. }
  24161. if (json.images === undefined || json.images.length === 0) {
  24162. if (onLoad !== undefined) onLoad(object);
  24163. }
  24164. return object;
  24165. };
  24166. _proto.parseShape = function parseShape(json) {
  24167. var shapes = {};
  24168. if (json !== undefined) {
  24169. for (var i = 0, l = json.length; i < l; i++) {
  24170. var shape = new Shape().fromJSON(json[i]);
  24171. shapes[shape.uuid] = shape;
  24172. }
  24173. }
  24174. return shapes;
  24175. };
  24176. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24177. var geometries = {};
  24178. var geometryShapes;
  24179. if (json !== undefined) {
  24180. var bufferGeometryLoader = new BufferGeometryLoader();
  24181. for (var i = 0, l = json.length; i < l; i++) {
  24182. var geometry = void 0;
  24183. var data = json[i];
  24184. switch (data.type) {
  24185. case 'PlaneGeometry':
  24186. case 'PlaneBufferGeometry':
  24187. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24188. break;
  24189. case 'BoxGeometry':
  24190. case 'BoxBufferGeometry':
  24191. case 'CubeGeometry':
  24192. // backwards compatible
  24193. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24194. break;
  24195. case 'CircleGeometry':
  24196. case 'CircleBufferGeometry':
  24197. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24198. break;
  24199. case 'CylinderGeometry':
  24200. case 'CylinderBufferGeometry':
  24201. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24202. break;
  24203. case 'ConeGeometry':
  24204. case 'ConeBufferGeometry':
  24205. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24206. break;
  24207. case 'SphereGeometry':
  24208. case 'SphereBufferGeometry':
  24209. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24210. break;
  24211. case 'DodecahedronGeometry':
  24212. case 'DodecahedronBufferGeometry':
  24213. case 'IcosahedronGeometry':
  24214. case 'IcosahedronBufferGeometry':
  24215. case 'OctahedronGeometry':
  24216. case 'OctahedronBufferGeometry':
  24217. case 'TetrahedronGeometry':
  24218. case 'TetrahedronBufferGeometry':
  24219. geometry = new Geometries[data.type](data.radius, data.detail);
  24220. break;
  24221. case 'RingGeometry':
  24222. case 'RingBufferGeometry':
  24223. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24224. break;
  24225. case 'TorusGeometry':
  24226. case 'TorusBufferGeometry':
  24227. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24228. break;
  24229. case 'TorusKnotGeometry':
  24230. case 'TorusKnotBufferGeometry':
  24231. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24232. break;
  24233. case 'TubeGeometry':
  24234. case 'TubeBufferGeometry':
  24235. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24236. // User defined curves or instances of CurvePath will not be deserialized.
  24237. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24238. break;
  24239. case 'LatheGeometry':
  24240. case 'LatheBufferGeometry':
  24241. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24242. break;
  24243. case 'PolyhedronGeometry':
  24244. case 'PolyhedronBufferGeometry':
  24245. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24246. break;
  24247. case 'ShapeGeometry':
  24248. case 'ShapeBufferGeometry':
  24249. geometryShapes = [];
  24250. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24251. var shape = shapes[data.shapes[j]];
  24252. geometryShapes.push(shape);
  24253. }
  24254. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24255. break;
  24256. case 'ExtrudeGeometry':
  24257. case 'ExtrudeBufferGeometry':
  24258. geometryShapes = [];
  24259. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24260. var _shape = shapes[data.shapes[_j]];
  24261. geometryShapes.push(_shape);
  24262. }
  24263. var extrudePath = data.options.extrudePath;
  24264. if (extrudePath !== undefined) {
  24265. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24266. }
  24267. geometry = new Geometries[data.type](geometryShapes, data.options);
  24268. break;
  24269. case 'BufferGeometry':
  24270. case 'InstancedBufferGeometry':
  24271. geometry = bufferGeometryLoader.parse(data);
  24272. break;
  24273. case 'Geometry':
  24274. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24275. break;
  24276. default:
  24277. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24278. continue;
  24279. }
  24280. geometry.uuid = data.uuid;
  24281. if (data.name !== undefined) geometry.name = data.name;
  24282. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24283. geometries[data.uuid] = geometry;
  24284. }
  24285. }
  24286. return geometries;
  24287. };
  24288. _proto.parseMaterials = function parseMaterials(json, textures) {
  24289. var cache = {}; // MultiMaterial
  24290. var materials = {};
  24291. if (json !== undefined) {
  24292. var loader = new MaterialLoader();
  24293. loader.setTextures(textures);
  24294. for (var i = 0, l = json.length; i < l; i++) {
  24295. var data = json[i];
  24296. if (data.type === 'MultiMaterial') {
  24297. // Deprecated
  24298. var array = [];
  24299. for (var j = 0; j < data.materials.length; j++) {
  24300. var material = data.materials[j];
  24301. if (cache[material.uuid] === undefined) {
  24302. cache[material.uuid] = loader.parse(material);
  24303. }
  24304. array.push(cache[material.uuid]);
  24305. }
  24306. materials[data.uuid] = array;
  24307. } else {
  24308. if (cache[data.uuid] === undefined) {
  24309. cache[data.uuid] = loader.parse(data);
  24310. }
  24311. materials[data.uuid] = cache[data.uuid];
  24312. }
  24313. }
  24314. }
  24315. return materials;
  24316. };
  24317. _proto.parseAnimations = function parseAnimations(json) {
  24318. var animations = [];
  24319. for (var i = 0; i < json.length; i++) {
  24320. var data = json[i];
  24321. var clip = AnimationClip.parse(data);
  24322. if (data.uuid !== undefined) clip.uuid = data.uuid;
  24323. animations.push(clip);
  24324. }
  24325. return animations;
  24326. };
  24327. _proto.parseImages = function parseImages(json, onLoad) {
  24328. var scope = this;
  24329. var images = {};
  24330. var loader;
  24331. function loadImage(url) {
  24332. scope.manager.itemStart(url);
  24333. return loader.load(url, function () {
  24334. scope.manager.itemEnd(url);
  24335. }, undefined, function () {
  24336. scope.manager.itemError(url);
  24337. scope.manager.itemEnd(url);
  24338. });
  24339. }
  24340. if (json !== undefined && json.length > 0) {
  24341. var manager = new LoadingManager(onLoad);
  24342. loader = new ImageLoader(manager);
  24343. loader.setCrossOrigin(this.crossOrigin);
  24344. for (var i = 0, il = json.length; i < il; i++) {
  24345. var image = json[i];
  24346. var url = image.url;
  24347. if (Array.isArray(url)) {
  24348. // load array of images e.g CubeTexture
  24349. images[image.uuid] = [];
  24350. for (var j = 0, jl = url.length; j < jl; j++) {
  24351. var currentUrl = url[j];
  24352. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(currentUrl) ? currentUrl : scope.resourcePath + currentUrl;
  24353. images[image.uuid].push(loadImage(path));
  24354. }
  24355. } else {
  24356. // load single image
  24357. var _path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(image.url) ? image.url : scope.resourcePath + image.url;
  24358. images[image.uuid] = loadImage(_path);
  24359. }
  24360. }
  24361. }
  24362. return images;
  24363. };
  24364. _proto.parseTextures = function parseTextures(json, images) {
  24365. function parseConstant(value, type) {
  24366. if (typeof value === 'number') return value;
  24367. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  24368. return type[value];
  24369. }
  24370. var textures = {};
  24371. if (json !== undefined) {
  24372. for (var i = 0, l = json.length; i < l; i++) {
  24373. var data = json[i];
  24374. if (data.image === undefined) {
  24375. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  24376. }
  24377. if (images[data.image] === undefined) {
  24378. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  24379. }
  24380. var texture = void 0;
  24381. if (Array.isArray(images[data.image])) {
  24382. texture = new CubeTexture(images[data.image]);
  24383. } else {
  24384. texture = new Texture(images[data.image]);
  24385. }
  24386. texture.needsUpdate = true;
  24387. texture.uuid = data.uuid;
  24388. if (data.name !== undefined) texture.name = data.name;
  24389. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  24390. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  24391. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  24392. if (data.center !== undefined) texture.center.fromArray(data.center);
  24393. if (data.rotation !== undefined) texture.rotation = data.rotation;
  24394. if (data.wrap !== undefined) {
  24395. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  24396. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  24397. }
  24398. if (data.format !== undefined) texture.format = data.format;
  24399. if (data.type !== undefined) texture.type = data.type;
  24400. if (data.encoding !== undefined) texture.encoding = data.encoding;
  24401. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  24402. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  24403. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  24404. if (data.flipY !== undefined) texture.flipY = data.flipY;
  24405. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  24406. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  24407. textures[data.uuid] = texture;
  24408. }
  24409. }
  24410. return textures;
  24411. };
  24412. _proto.parseObject = function parseObject(data, geometries, materials) {
  24413. var object;
  24414. function getGeometry(name) {
  24415. if (geometries[name] === undefined) {
  24416. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  24417. }
  24418. return geometries[name];
  24419. }
  24420. function getMaterial(name) {
  24421. if (name === undefined) return undefined;
  24422. if (Array.isArray(name)) {
  24423. var array = [];
  24424. for (var i = 0, l = name.length; i < l; i++) {
  24425. var uuid = name[i];
  24426. if (materials[uuid] === undefined) {
  24427. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  24428. }
  24429. array.push(materials[uuid]);
  24430. }
  24431. return array;
  24432. }
  24433. if (materials[name] === undefined) {
  24434. console.warn('THREE.ObjectLoader: Undefined material', name);
  24435. }
  24436. return materials[name];
  24437. }
  24438. var geometry, material;
  24439. switch (data.type) {
  24440. case 'Scene':
  24441. object = new Scene();
  24442. if (data.background !== undefined) {
  24443. if (Number.isInteger(data.background)) {
  24444. object.background = new Color(data.background);
  24445. }
  24446. }
  24447. if (data.fog !== undefined) {
  24448. if (data.fog.type === 'Fog') {
  24449. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  24450. } else if (data.fog.type === 'FogExp2') {
  24451. object.fog = new FogExp2(data.fog.color, data.fog.density);
  24452. }
  24453. }
  24454. break;
  24455. case 'PerspectiveCamera':
  24456. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  24457. if (data.focus !== undefined) object.focus = data.focus;
  24458. if (data.zoom !== undefined) object.zoom = data.zoom;
  24459. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  24460. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  24461. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24462. break;
  24463. case 'OrthographicCamera':
  24464. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  24465. if (data.zoom !== undefined) object.zoom = data.zoom;
  24466. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24467. break;
  24468. case 'AmbientLight':
  24469. object = new AmbientLight(data.color, data.intensity);
  24470. break;
  24471. case 'DirectionalLight':
  24472. object = new DirectionalLight(data.color, data.intensity);
  24473. break;
  24474. case 'PointLight':
  24475. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  24476. break;
  24477. case 'RectAreaLight':
  24478. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  24479. break;
  24480. case 'SpotLight':
  24481. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  24482. break;
  24483. case 'HemisphereLight':
  24484. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  24485. break;
  24486. case 'LightProbe':
  24487. object = new LightProbe().fromJSON(data);
  24488. break;
  24489. case 'SkinnedMesh':
  24490. console.warn('THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.');
  24491. case 'Mesh':
  24492. geometry = getGeometry(data.geometry);
  24493. material = getMaterial(data.material);
  24494. object = new Mesh(geometry, material);
  24495. break;
  24496. case 'InstancedMesh':
  24497. geometry = getGeometry(data.geometry);
  24498. material = getMaterial(data.material);
  24499. var count = data.count;
  24500. var instanceMatrix = data.instanceMatrix;
  24501. object = new InstancedMesh(geometry, material, count);
  24502. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  24503. break;
  24504. case 'LOD':
  24505. object = new LOD();
  24506. break;
  24507. case 'Line':
  24508. object = new Line(getGeometry(data.geometry), getMaterial(data.material), data.mode);
  24509. break;
  24510. case 'LineLoop':
  24511. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  24512. break;
  24513. case 'LineSegments':
  24514. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  24515. break;
  24516. case 'PointCloud':
  24517. case 'Points':
  24518. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  24519. break;
  24520. case 'Sprite':
  24521. object = new Sprite(getMaterial(data.material));
  24522. break;
  24523. case 'Group':
  24524. object = new Group();
  24525. break;
  24526. default:
  24527. object = new Object3D();
  24528. }
  24529. object.uuid = data.uuid;
  24530. if (data.name !== undefined) object.name = data.name;
  24531. if (data.matrix !== undefined) {
  24532. object.matrix.fromArray(data.matrix);
  24533. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24534. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  24535. } else {
  24536. if (data.position !== undefined) object.position.fromArray(data.position);
  24537. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  24538. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  24539. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  24540. }
  24541. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  24542. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  24543. if (data.shadow) {
  24544. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  24545. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  24546. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  24547. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  24548. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  24549. }
  24550. if (data.visible !== undefined) object.visible = data.visible;
  24551. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  24552. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  24553. if (data.userData !== undefined) object.userData = data.userData;
  24554. if (data.layers !== undefined) object.layers.mask = data.layers;
  24555. if (data.children !== undefined) {
  24556. var children = data.children;
  24557. for (var i = 0; i < children.length; i++) {
  24558. object.add(this.parseObject(children[i], geometries, materials));
  24559. }
  24560. }
  24561. if (data.type === 'LOD') {
  24562. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  24563. var levels = data.levels;
  24564. for (var l = 0; l < levels.length; l++) {
  24565. var level = levels[l];
  24566. var child = object.getObjectByProperty('uuid', level.object);
  24567. if (child !== undefined) {
  24568. object.addLevel(child, level.distance);
  24569. }
  24570. }
  24571. }
  24572. return object;
  24573. }
  24574. /* DEPRECATED */
  24575. ;
  24576. _proto.setTexturePath = function setTexturePath(value) {
  24577. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  24578. return this.setResourcePath(value);
  24579. };
  24580. return ObjectLoader;
  24581. }(Loader);
  24582. var TEXTURE_MAPPING = {
  24583. UVMapping: UVMapping,
  24584. CubeReflectionMapping: CubeReflectionMapping,
  24585. CubeRefractionMapping: CubeRefractionMapping,
  24586. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24587. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24588. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24589. CubeUVRefractionMapping: CubeUVRefractionMapping
  24590. };
  24591. var TEXTURE_WRAPPING = {
  24592. RepeatWrapping: RepeatWrapping,
  24593. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24594. MirroredRepeatWrapping: MirroredRepeatWrapping
  24595. };
  24596. var TEXTURE_FILTER = {
  24597. NearestFilter: NearestFilter,
  24598. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24599. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24600. LinearFilter: LinearFilter,
  24601. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24602. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24603. };
  24604. function ImageBitmapLoader(manager) {
  24605. if (typeof createImageBitmap === 'undefined') {
  24606. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  24607. }
  24608. if (typeof fetch === 'undefined') {
  24609. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  24610. }
  24611. Loader.call(this, manager);
  24612. this.options = {
  24613. premultiplyAlpha: 'none'
  24614. };
  24615. }
  24616. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24617. constructor: ImageBitmapLoader,
  24618. isImageBitmapLoader: true,
  24619. setOptions: function setOptions(options) {
  24620. this.options = options;
  24621. return this;
  24622. },
  24623. load: function load(url, onLoad, onProgress, onError) {
  24624. if (url === undefined) url = '';
  24625. if (this.path !== undefined) url = this.path + url;
  24626. url = this.manager.resolveURL(url);
  24627. var scope = this;
  24628. var cached = Cache.get(url);
  24629. if (cached !== undefined) {
  24630. scope.manager.itemStart(url);
  24631. setTimeout(function () {
  24632. if (onLoad) onLoad(cached);
  24633. scope.manager.itemEnd(url);
  24634. }, 0);
  24635. return cached;
  24636. }
  24637. var fetchOptions = {};
  24638. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  24639. fetch(url, fetchOptions).then(function (res) {
  24640. return res.blob();
  24641. }).then(function (blob) {
  24642. return createImageBitmap(blob, scope.options);
  24643. }).then(function (imageBitmap) {
  24644. Cache.add(url, imageBitmap);
  24645. if (onLoad) onLoad(imageBitmap);
  24646. scope.manager.itemEnd(url);
  24647. }).catch(function (e) {
  24648. if (onError) onError(e);
  24649. scope.manager.itemError(url);
  24650. scope.manager.itemEnd(url);
  24651. });
  24652. scope.manager.itemStart(url);
  24653. }
  24654. });
  24655. function ShapePath() {
  24656. this.type = 'ShapePath';
  24657. this.color = new Color();
  24658. this.subPaths = [];
  24659. this.currentPath = null;
  24660. }
  24661. Object.assign(ShapePath.prototype, {
  24662. moveTo: function moveTo(x, y) {
  24663. this.currentPath = new Path();
  24664. this.subPaths.push(this.currentPath);
  24665. this.currentPath.moveTo(x, y);
  24666. return this;
  24667. },
  24668. lineTo: function lineTo(x, y) {
  24669. this.currentPath.lineTo(x, y);
  24670. return this;
  24671. },
  24672. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  24673. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  24674. return this;
  24675. },
  24676. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  24677. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  24678. return this;
  24679. },
  24680. splineThru: function splineThru(pts) {
  24681. this.currentPath.splineThru(pts);
  24682. return this;
  24683. },
  24684. toShapes: function toShapes(isCCW, noHoles) {
  24685. function toShapesNoHoles(inSubpaths) {
  24686. var shapes = [];
  24687. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  24688. var _tmpPath = inSubpaths[i];
  24689. var _tmpShape = new Shape();
  24690. _tmpShape.curves = _tmpPath.curves;
  24691. shapes.push(_tmpShape);
  24692. }
  24693. return shapes;
  24694. }
  24695. function isPointInsidePolygon(inPt, inPolygon) {
  24696. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  24697. // toggling of inside/outside at every single! intersection point of an edge
  24698. // with the horizontal line through inPt, left of inPt
  24699. // not counting lowerY endpoints of edges and whole edges on that line
  24700. var inside = false;
  24701. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  24702. var edgeLowPt = inPolygon[p];
  24703. var edgeHighPt = inPolygon[q];
  24704. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  24705. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  24706. if (Math.abs(edgeDy) > Number.EPSILON) {
  24707. // not parallel
  24708. if (edgeDy < 0) {
  24709. edgeLowPt = inPolygon[q];
  24710. edgeDx = -edgeDx;
  24711. edgeHighPt = inPolygon[p];
  24712. edgeDy = -edgeDy;
  24713. }
  24714. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  24715. if (inPt.y === edgeLowPt.y) {
  24716. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  24717. // continue; // no intersection or edgeLowPt => doesn't count !!!
  24718. } else {
  24719. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  24720. if (perpEdge === 0) return true; // inPt is on contour ?
  24721. if (perpEdge < 0) continue;
  24722. inside = !inside; // true intersection left of inPt
  24723. }
  24724. } else {
  24725. // parallel or collinear
  24726. if (inPt.y !== edgeLowPt.y) continue; // parallel
  24727. // edge lies on the same horizontal line as inPt
  24728. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  24729. // continue;
  24730. }
  24731. }
  24732. return inside;
  24733. }
  24734. var isClockWise = ShapeUtils.isClockWise;
  24735. var subPaths = this.subPaths;
  24736. if (subPaths.length === 0) return [];
  24737. if (noHoles === true) return toShapesNoHoles(subPaths);
  24738. var solid, tmpPath, tmpShape;
  24739. var shapes = [];
  24740. if (subPaths.length === 1) {
  24741. tmpPath = subPaths[0];
  24742. tmpShape = new Shape();
  24743. tmpShape.curves = tmpPath.curves;
  24744. shapes.push(tmpShape);
  24745. return shapes;
  24746. }
  24747. var holesFirst = !isClockWise(subPaths[0].getPoints());
  24748. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  24749. var betterShapeHoles = [];
  24750. var newShapes = [];
  24751. var newShapeHoles = [];
  24752. var mainIdx = 0;
  24753. var tmpPoints;
  24754. newShapes[mainIdx] = undefined;
  24755. newShapeHoles[mainIdx] = [];
  24756. for (var i = 0, l = subPaths.length; i < l; i++) {
  24757. tmpPath = subPaths[i];
  24758. tmpPoints = tmpPath.getPoints();
  24759. solid = isClockWise(tmpPoints);
  24760. solid = isCCW ? !solid : solid;
  24761. if (solid) {
  24762. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  24763. newShapes[mainIdx] = {
  24764. s: new Shape(),
  24765. p: tmpPoints
  24766. };
  24767. newShapes[mainIdx].s.curves = tmpPath.curves;
  24768. if (holesFirst) mainIdx++;
  24769. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  24770. } else {
  24771. newShapeHoles[mainIdx].push({
  24772. h: tmpPath,
  24773. p: tmpPoints[0]
  24774. }); //console.log('ccw', i);
  24775. }
  24776. } // only Holes? -> probably all Shapes with wrong orientation
  24777. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  24778. if (newShapes.length > 1) {
  24779. var ambiguous = false;
  24780. var toChange = [];
  24781. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  24782. betterShapeHoles[sIdx] = [];
  24783. }
  24784. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  24785. var sho = newShapeHoles[_sIdx];
  24786. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  24787. var ho = sho[hIdx];
  24788. var hole_unassigned = true;
  24789. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  24790. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  24791. if (_sIdx !== s2Idx) toChange.push({
  24792. froms: _sIdx,
  24793. tos: s2Idx,
  24794. hole: hIdx
  24795. });
  24796. if (hole_unassigned) {
  24797. hole_unassigned = false;
  24798. betterShapeHoles[s2Idx].push(ho);
  24799. } else {
  24800. ambiguous = true;
  24801. }
  24802. }
  24803. }
  24804. if (hole_unassigned) {
  24805. betterShapeHoles[_sIdx].push(ho);
  24806. }
  24807. }
  24808. } // console.log("ambiguous: ", ambiguous);
  24809. if (toChange.length > 0) {
  24810. // console.log("to change: ", toChange);
  24811. if (!ambiguous) newShapeHoles = betterShapeHoles;
  24812. }
  24813. }
  24814. var tmpHoles;
  24815. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  24816. tmpShape = newShapes[_i].s;
  24817. shapes.push(tmpShape);
  24818. tmpHoles = newShapeHoles[_i];
  24819. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  24820. tmpShape.holes.push(tmpHoles[j].h);
  24821. }
  24822. } //console.log("shape", shapes);
  24823. return shapes;
  24824. }
  24825. });
  24826. function Font(data) {
  24827. this.type = 'Font';
  24828. this.data = data;
  24829. }
  24830. Object.assign(Font.prototype, {
  24831. isFont: true,
  24832. generateShapes: function generateShapes(text, size) {
  24833. if (size === undefined) size = 100;
  24834. var shapes = [];
  24835. var paths = createPaths(text, size, this.data);
  24836. for (var p = 0, pl = paths.length; p < pl; p++) {
  24837. Array.prototype.push.apply(shapes, paths[p].toShapes());
  24838. }
  24839. return shapes;
  24840. }
  24841. });
  24842. function createPaths(text, size, data) {
  24843. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  24844. var scale = size / data.resolution;
  24845. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  24846. var paths = [];
  24847. var offsetX = 0,
  24848. offsetY = 0;
  24849. for (var i = 0; i < chars.length; i++) {
  24850. var char = chars[i];
  24851. if (char === '\n') {
  24852. offsetX = 0;
  24853. offsetY -= line_height;
  24854. } else {
  24855. var ret = createPath(char, scale, offsetX, offsetY, data);
  24856. offsetX += ret.offsetX;
  24857. paths.push(ret.path);
  24858. }
  24859. }
  24860. return paths;
  24861. }
  24862. function createPath(char, scale, offsetX, offsetY, data) {
  24863. var glyph = data.glyphs[char] || data.glyphs['?'];
  24864. if (!glyph) {
  24865. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  24866. return;
  24867. }
  24868. var path = new ShapePath();
  24869. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  24870. if (glyph.o) {
  24871. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  24872. for (var i = 0, l = outline.length; i < l;) {
  24873. var action = outline[i++];
  24874. switch (action) {
  24875. case 'm':
  24876. // moveTo
  24877. x = outline[i++] * scale + offsetX;
  24878. y = outline[i++] * scale + offsetY;
  24879. path.moveTo(x, y);
  24880. break;
  24881. case 'l':
  24882. // lineTo
  24883. x = outline[i++] * scale + offsetX;
  24884. y = outline[i++] * scale + offsetY;
  24885. path.lineTo(x, y);
  24886. break;
  24887. case 'q':
  24888. // quadraticCurveTo
  24889. cpx = outline[i++] * scale + offsetX;
  24890. cpy = outline[i++] * scale + offsetY;
  24891. cpx1 = outline[i++] * scale + offsetX;
  24892. cpy1 = outline[i++] * scale + offsetY;
  24893. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  24894. break;
  24895. case 'b':
  24896. // bezierCurveTo
  24897. cpx = outline[i++] * scale + offsetX;
  24898. cpy = outline[i++] * scale + offsetY;
  24899. cpx1 = outline[i++] * scale + offsetX;
  24900. cpy1 = outline[i++] * scale + offsetY;
  24901. cpx2 = outline[i++] * scale + offsetX;
  24902. cpy2 = outline[i++] * scale + offsetY;
  24903. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  24904. break;
  24905. }
  24906. }
  24907. }
  24908. return {
  24909. offsetX: glyph.ha * scale,
  24910. path: path
  24911. };
  24912. }
  24913. function FontLoader(manager) {
  24914. Loader.call(this, manager);
  24915. }
  24916. FontLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24917. constructor: FontLoader,
  24918. load: function load(url, onLoad, onProgress, onError) {
  24919. var scope = this;
  24920. var loader = new FileLoader(this.manager);
  24921. loader.setPath(this.path);
  24922. loader.setRequestHeader(this.requestHeader);
  24923. loader.setWithCredentials(scope.withCredentials);
  24924. loader.load(url, function (text) {
  24925. var json;
  24926. try {
  24927. json = JSON.parse(text);
  24928. } catch (e) {
  24929. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  24930. json = JSON.parse(text.substring(65, text.length - 2));
  24931. }
  24932. var font = scope.parse(json);
  24933. if (onLoad) onLoad(font);
  24934. }, onProgress, onError);
  24935. },
  24936. parse: function parse(json) {
  24937. return new Font(json);
  24938. }
  24939. });
  24940. var _context;
  24941. var AudioContext = {
  24942. getContext: function getContext() {
  24943. if (_context === undefined) {
  24944. _context = new (window.AudioContext || window.webkitAudioContext)();
  24945. }
  24946. return _context;
  24947. },
  24948. setContext: function setContext(value) {
  24949. _context = value;
  24950. }
  24951. };
  24952. function AudioLoader(manager) {
  24953. Loader.call(this, manager);
  24954. }
  24955. AudioLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24956. constructor: AudioLoader,
  24957. load: function load(url, onLoad, onProgress, onError) {
  24958. var scope = this;
  24959. var loader = new FileLoader(scope.manager);
  24960. loader.setResponseType('arraybuffer');
  24961. loader.setPath(scope.path);
  24962. loader.setRequestHeader(scope.requestHeader);
  24963. loader.setWithCredentials(scope.withCredentials);
  24964. loader.load(url, function (buffer) {
  24965. try {
  24966. // Create a copy of the buffer. The `decodeAudioData` method
  24967. // detaches the buffer when complete, preventing reuse.
  24968. var bufferCopy = buffer.slice(0);
  24969. var context = AudioContext.getContext();
  24970. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  24971. onLoad(audioBuffer);
  24972. });
  24973. } catch (e) {
  24974. if (onError) {
  24975. onError(e);
  24976. } else {
  24977. console.error(e);
  24978. }
  24979. scope.manager.itemError(url);
  24980. }
  24981. }, onProgress, onError);
  24982. }
  24983. });
  24984. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  24985. LightProbe.call(this, undefined, intensity);
  24986. var color1 = new Color().set(skyColor);
  24987. var color2 = new Color().set(groundColor);
  24988. var sky = new Vector3(color1.r, color1.g, color1.b);
  24989. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  24990. var c0 = Math.sqrt(Math.PI);
  24991. var c1 = c0 * Math.sqrt(0.75);
  24992. this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  24993. this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  24994. }
  24995. HemisphereLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  24996. constructor: HemisphereLightProbe,
  24997. isHemisphereLightProbe: true,
  24998. copy: function copy(source) {
  24999. // modifying colors not currently supported
  25000. LightProbe.prototype.copy.call(this, source);
  25001. return this;
  25002. },
  25003. toJSON: function toJSON(meta) {
  25004. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25005. return data;
  25006. }
  25007. });
  25008. function AmbientLightProbe(color, intensity) {
  25009. LightProbe.call(this, undefined, intensity);
  25010. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25011. this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  25012. }
  25013. AmbientLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25014. constructor: AmbientLightProbe,
  25015. isAmbientLightProbe: true,
  25016. copy: function copy(source) {
  25017. // modifying color not currently supported
  25018. LightProbe.prototype.copy.call(this, source);
  25019. return this;
  25020. },
  25021. toJSON: function toJSON(meta) {
  25022. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25023. return data;
  25024. }
  25025. });
  25026. var _eyeRight = new Matrix4();
  25027. var _eyeLeft = new Matrix4();
  25028. function StereoCamera() {
  25029. this.type = 'StereoCamera';
  25030. this.aspect = 1;
  25031. this.eyeSep = 0.064;
  25032. this.cameraL = new PerspectiveCamera();
  25033. this.cameraL.layers.enable(1);
  25034. this.cameraL.matrixAutoUpdate = false;
  25035. this.cameraR = new PerspectiveCamera();
  25036. this.cameraR.layers.enable(2);
  25037. this.cameraR.matrixAutoUpdate = false;
  25038. this._cache = {
  25039. focus: null,
  25040. fov: null,
  25041. aspect: null,
  25042. near: null,
  25043. far: null,
  25044. zoom: null,
  25045. eyeSep: null
  25046. };
  25047. }
  25048. Object.assign(StereoCamera.prototype, {
  25049. update: function update(camera) {
  25050. var cache = this._cache;
  25051. 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;
  25052. if (needsUpdate) {
  25053. cache.focus = camera.focus;
  25054. cache.fov = camera.fov;
  25055. cache.aspect = camera.aspect * this.aspect;
  25056. cache.near = camera.near;
  25057. cache.far = camera.far;
  25058. cache.zoom = camera.zoom;
  25059. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25060. // http://paulbourke.net/stereographics/stereorender/
  25061. var projectionMatrix = camera.projectionMatrix.clone();
  25062. var eyeSepHalf = cache.eyeSep / 2;
  25063. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25064. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25065. var xmin, xmax; // translate xOffset
  25066. _eyeLeft.elements[12] = -eyeSepHalf;
  25067. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25068. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25069. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25070. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25071. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25072. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25073. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25074. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25075. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25076. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25077. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25078. }
  25079. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25080. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25081. }
  25082. });
  25083. var Clock = /*#__PURE__*/function () {
  25084. function Clock(autoStart) {
  25085. this.autoStart = autoStart !== undefined ? autoStart : true;
  25086. this.startTime = 0;
  25087. this.oldTime = 0;
  25088. this.elapsedTime = 0;
  25089. this.running = false;
  25090. }
  25091. var _proto = Clock.prototype;
  25092. _proto.start = function start() {
  25093. this.startTime = (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25094. this.oldTime = this.startTime;
  25095. this.elapsedTime = 0;
  25096. this.running = true;
  25097. };
  25098. _proto.stop = function stop() {
  25099. this.getElapsedTime();
  25100. this.running = false;
  25101. this.autoStart = false;
  25102. };
  25103. _proto.getElapsedTime = function getElapsedTime() {
  25104. this.getDelta();
  25105. return this.elapsedTime;
  25106. };
  25107. _proto.getDelta = function getDelta() {
  25108. var diff = 0;
  25109. if (this.autoStart && !this.running) {
  25110. this.start();
  25111. return 0;
  25112. }
  25113. if (this.running) {
  25114. var newTime = (typeof performance === 'undefined' ? Date : performance).now();
  25115. diff = (newTime - this.oldTime) / 1000;
  25116. this.oldTime = newTime;
  25117. this.elapsedTime += diff;
  25118. }
  25119. return diff;
  25120. };
  25121. return Clock;
  25122. }();
  25123. var _position$2 = /*@__PURE__*/new Vector3();
  25124. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25125. var _scale$1 = /*@__PURE__*/new Vector3();
  25126. var _orientation = /*@__PURE__*/new Vector3();
  25127. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25128. _inheritsLoose(AudioListener, _Object3D);
  25129. function AudioListener() {
  25130. var _this;
  25131. _this = _Object3D.call(this) || this;
  25132. _this.type = 'AudioListener';
  25133. _this.context = AudioContext.getContext();
  25134. _this.gain = _this.context.createGain();
  25135. _this.gain.connect(_this.context.destination);
  25136. _this.filter = null;
  25137. _this.timeDelta = 0; // private
  25138. _this._clock = new Clock();
  25139. return _this;
  25140. }
  25141. var _proto = AudioListener.prototype;
  25142. _proto.getInput = function getInput() {
  25143. return this.gain;
  25144. };
  25145. _proto.removeFilter = function removeFilter() {
  25146. if (this.filter !== null) {
  25147. this.gain.disconnect(this.filter);
  25148. this.filter.disconnect(this.context.destination);
  25149. this.gain.connect(this.context.destination);
  25150. this.filter = null;
  25151. }
  25152. return this;
  25153. };
  25154. _proto.getFilter = function getFilter() {
  25155. return this.filter;
  25156. };
  25157. _proto.setFilter = function setFilter(value) {
  25158. if (this.filter !== null) {
  25159. this.gain.disconnect(this.filter);
  25160. this.filter.disconnect(this.context.destination);
  25161. } else {
  25162. this.gain.disconnect(this.context.destination);
  25163. }
  25164. this.filter = value;
  25165. this.gain.connect(this.filter);
  25166. this.filter.connect(this.context.destination);
  25167. return this;
  25168. };
  25169. _proto.getMasterVolume = function getMasterVolume() {
  25170. return this.gain.gain.value;
  25171. };
  25172. _proto.setMasterVolume = function setMasterVolume(value) {
  25173. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25174. return this;
  25175. };
  25176. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25177. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25178. var listener = this.context.listener;
  25179. var up = this.up;
  25180. this.timeDelta = this._clock.getDelta();
  25181. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25182. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25183. if (listener.positionX) {
  25184. // code path for Chrome (see #14393)
  25185. var endTime = this.context.currentTime + this.timeDelta;
  25186. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25187. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25188. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25189. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25190. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25191. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25192. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25193. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25194. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25195. } else {
  25196. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25197. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25198. }
  25199. };
  25200. return AudioListener;
  25201. }(Object3D);
  25202. var Audio = /*#__PURE__*/function (_Object3D) {
  25203. _inheritsLoose(Audio, _Object3D);
  25204. function Audio(listener) {
  25205. var _this;
  25206. _this = _Object3D.call(this) || this;
  25207. _this.type = 'Audio';
  25208. _this.listener = listener;
  25209. _this.context = listener.context;
  25210. _this.gain = _this.context.createGain();
  25211. _this.gain.connect(listener.getInput());
  25212. _this.autoplay = false;
  25213. _this.buffer = null;
  25214. _this.detune = 0;
  25215. _this.loop = false;
  25216. _this.loopStart = 0;
  25217. _this.loopEnd = 0;
  25218. _this.offset = 0;
  25219. _this.duration = undefined;
  25220. _this.playbackRate = 1;
  25221. _this.isPlaying = false;
  25222. _this.hasPlaybackControl = true;
  25223. _this.source = null;
  25224. _this.sourceType = 'empty';
  25225. _this._startedAt = 0;
  25226. _this._progress = 0;
  25227. _this._connected = false;
  25228. _this.filters = [];
  25229. return _this;
  25230. }
  25231. var _proto = Audio.prototype;
  25232. _proto.getOutput = function getOutput() {
  25233. return this.gain;
  25234. };
  25235. _proto.setNodeSource = function setNodeSource(audioNode) {
  25236. this.hasPlaybackControl = false;
  25237. this.sourceType = 'audioNode';
  25238. this.source = audioNode;
  25239. this.connect();
  25240. return this;
  25241. };
  25242. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25243. this.hasPlaybackControl = false;
  25244. this.sourceType = 'mediaNode';
  25245. this.source = this.context.createMediaElementSource(mediaElement);
  25246. this.connect();
  25247. return this;
  25248. };
  25249. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25250. this.hasPlaybackControl = false;
  25251. this.sourceType = 'mediaStreamNode';
  25252. this.source = this.context.createMediaStreamSource(mediaStream);
  25253. this.connect();
  25254. return this;
  25255. };
  25256. _proto.setBuffer = function setBuffer(audioBuffer) {
  25257. this.buffer = audioBuffer;
  25258. this.sourceType = 'buffer';
  25259. if (this.autoplay) this.play();
  25260. return this;
  25261. };
  25262. _proto.play = function play(delay) {
  25263. if (delay === undefined) delay = 0;
  25264. if (this.isPlaying === true) {
  25265. console.warn('THREE.Audio: Audio is already playing.');
  25266. return;
  25267. }
  25268. if (this.hasPlaybackControl === false) {
  25269. console.warn('THREE.Audio: this Audio has no playback control.');
  25270. return;
  25271. }
  25272. this._startedAt = this.context.currentTime + delay;
  25273. var source = this.context.createBufferSource();
  25274. source.buffer = this.buffer;
  25275. source.loop = this.loop;
  25276. source.loopStart = this.loopStart;
  25277. source.loopEnd = this.loopEnd;
  25278. source.onended = this.onEnded.bind(this);
  25279. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25280. this.isPlaying = true;
  25281. this.source = source;
  25282. this.setDetune(this.detune);
  25283. this.setPlaybackRate(this.playbackRate);
  25284. return this.connect();
  25285. };
  25286. _proto.pause = function pause() {
  25287. if (this.hasPlaybackControl === false) {
  25288. console.warn('THREE.Audio: this Audio has no playback control.');
  25289. return;
  25290. }
  25291. if (this.isPlaying === true) {
  25292. // update current progress
  25293. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  25294. if (this.loop === true) {
  25295. // ensure _progress does not exceed duration with looped audios
  25296. this._progress = this._progress % (this.duration || this.buffer.duration);
  25297. }
  25298. this.source.stop();
  25299. this.source.onended = null;
  25300. this.isPlaying = false;
  25301. }
  25302. return this;
  25303. };
  25304. _proto.stop = function stop() {
  25305. if (this.hasPlaybackControl === false) {
  25306. console.warn('THREE.Audio: this Audio has no playback control.');
  25307. return;
  25308. }
  25309. this._progress = 0;
  25310. this.source.stop();
  25311. this.source.onended = null;
  25312. this.isPlaying = false;
  25313. return this;
  25314. };
  25315. _proto.connect = function connect() {
  25316. if (this.filters.length > 0) {
  25317. this.source.connect(this.filters[0]);
  25318. for (var i = 1, l = this.filters.length; i < l; i++) {
  25319. this.filters[i - 1].connect(this.filters[i]);
  25320. }
  25321. this.filters[this.filters.length - 1].connect(this.getOutput());
  25322. } else {
  25323. this.source.connect(this.getOutput());
  25324. }
  25325. this._connected = true;
  25326. return this;
  25327. };
  25328. _proto.disconnect = function disconnect() {
  25329. if (this.filters.length > 0) {
  25330. this.source.disconnect(this.filters[0]);
  25331. for (var i = 1, l = this.filters.length; i < l; i++) {
  25332. this.filters[i - 1].disconnect(this.filters[i]);
  25333. }
  25334. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  25335. } else {
  25336. this.source.disconnect(this.getOutput());
  25337. }
  25338. this._connected = false;
  25339. return this;
  25340. };
  25341. _proto.getFilters = function getFilters() {
  25342. return this.filters;
  25343. };
  25344. _proto.setFilters = function setFilters(value) {
  25345. if (!value) value = [];
  25346. if (this._connected === true) {
  25347. this.disconnect();
  25348. this.filters = value;
  25349. this.connect();
  25350. } else {
  25351. this.filters = value;
  25352. }
  25353. return this;
  25354. };
  25355. _proto.setDetune = function setDetune(value) {
  25356. this.detune = value;
  25357. if (this.source.detune === undefined) return; // only set detune when available
  25358. if (this.isPlaying === true) {
  25359. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  25360. }
  25361. return this;
  25362. };
  25363. _proto.getDetune = function getDetune() {
  25364. return this.detune;
  25365. };
  25366. _proto.getFilter = function getFilter() {
  25367. return this.getFilters()[0];
  25368. };
  25369. _proto.setFilter = function setFilter(filter) {
  25370. return this.setFilters(filter ? [filter] : []);
  25371. };
  25372. _proto.setPlaybackRate = function setPlaybackRate(value) {
  25373. if (this.hasPlaybackControl === false) {
  25374. console.warn('THREE.Audio: this Audio has no playback control.');
  25375. return;
  25376. }
  25377. this.playbackRate = value;
  25378. if (this.isPlaying === true) {
  25379. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  25380. }
  25381. return this;
  25382. };
  25383. _proto.getPlaybackRate = function getPlaybackRate() {
  25384. return this.playbackRate;
  25385. };
  25386. _proto.onEnded = function onEnded() {
  25387. this.isPlaying = false;
  25388. };
  25389. _proto.getLoop = function getLoop() {
  25390. if (this.hasPlaybackControl === false) {
  25391. console.warn('THREE.Audio: this Audio has no playback control.');
  25392. return false;
  25393. }
  25394. return this.loop;
  25395. };
  25396. _proto.setLoop = function setLoop(value) {
  25397. if (this.hasPlaybackControl === false) {
  25398. console.warn('THREE.Audio: this Audio has no playback control.');
  25399. return;
  25400. }
  25401. this.loop = value;
  25402. if (this.isPlaying === true) {
  25403. this.source.loop = this.loop;
  25404. }
  25405. return this;
  25406. };
  25407. _proto.setLoopStart = function setLoopStart(value) {
  25408. this.loopStart = value;
  25409. return this;
  25410. };
  25411. _proto.setLoopEnd = function setLoopEnd(value) {
  25412. this.loopEnd = value;
  25413. return this;
  25414. };
  25415. _proto.getVolume = function getVolume() {
  25416. return this.gain.gain.value;
  25417. };
  25418. _proto.setVolume = function setVolume(value) {
  25419. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25420. return this;
  25421. };
  25422. return Audio;
  25423. }(Object3D);
  25424. var _position$3 = /*@__PURE__*/new Vector3();
  25425. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  25426. var _scale$2 = /*@__PURE__*/new Vector3();
  25427. var _orientation$1 = /*@__PURE__*/new Vector3();
  25428. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  25429. _inheritsLoose(PositionalAudio, _Audio);
  25430. function PositionalAudio(listener) {
  25431. var _this;
  25432. _this = _Audio.call(this, listener) || this;
  25433. _this.panner = _this.context.createPanner();
  25434. _this.panner.panningModel = 'HRTF';
  25435. _this.panner.connect(_this.gain);
  25436. return _this;
  25437. }
  25438. var _proto = PositionalAudio.prototype;
  25439. _proto.getOutput = function getOutput() {
  25440. return this.panner;
  25441. };
  25442. _proto.getRefDistance = function getRefDistance() {
  25443. return this.panner.refDistance;
  25444. };
  25445. _proto.setRefDistance = function setRefDistance(value) {
  25446. this.panner.refDistance = value;
  25447. return this;
  25448. };
  25449. _proto.getRolloffFactor = function getRolloffFactor() {
  25450. return this.panner.rolloffFactor;
  25451. };
  25452. _proto.setRolloffFactor = function setRolloffFactor(value) {
  25453. this.panner.rolloffFactor = value;
  25454. return this;
  25455. };
  25456. _proto.getDistanceModel = function getDistanceModel() {
  25457. return this.panner.distanceModel;
  25458. };
  25459. _proto.setDistanceModel = function setDistanceModel(value) {
  25460. this.panner.distanceModel = value;
  25461. return this;
  25462. };
  25463. _proto.getMaxDistance = function getMaxDistance() {
  25464. return this.panner.maxDistance;
  25465. };
  25466. _proto.setMaxDistance = function setMaxDistance(value) {
  25467. this.panner.maxDistance = value;
  25468. return this;
  25469. };
  25470. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  25471. this.panner.coneInnerAngle = coneInnerAngle;
  25472. this.panner.coneOuterAngle = coneOuterAngle;
  25473. this.panner.coneOuterGain = coneOuterGain;
  25474. return this;
  25475. };
  25476. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25477. _Audio.prototype.updateMatrixWorld.call(this, force);
  25478. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  25479. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  25480. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  25481. var panner = this.panner;
  25482. if (panner.positionX) {
  25483. // code path for Chrome and Firefox (see #14393)
  25484. var endTime = this.context.currentTime + this.listener.timeDelta;
  25485. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  25486. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  25487. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  25488. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  25489. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  25490. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  25491. } else {
  25492. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  25493. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  25494. }
  25495. };
  25496. return PositionalAudio;
  25497. }(Audio);
  25498. var AudioAnalyser = /*#__PURE__*/function () {
  25499. function AudioAnalyser(audio, fftSize) {
  25500. this.analyser = audio.context.createAnalyser();
  25501. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  25502. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  25503. audio.getOutput().connect(this.analyser);
  25504. }
  25505. var _proto = AudioAnalyser.prototype;
  25506. _proto.getFrequencyData = function getFrequencyData() {
  25507. this.analyser.getByteFrequencyData(this.data);
  25508. return this.data;
  25509. };
  25510. _proto.getAverageFrequency = function getAverageFrequency() {
  25511. var value = 0;
  25512. var data = this.getFrequencyData();
  25513. for (var i = 0; i < data.length; i++) {
  25514. value += data[i];
  25515. }
  25516. return value / data.length;
  25517. };
  25518. return AudioAnalyser;
  25519. }();
  25520. function PropertyMixer(binding, typeName, valueSize) {
  25521. this.binding = binding;
  25522. this.valueSize = valueSize;
  25523. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25524. //
  25525. // interpolators can use .buffer as their .result
  25526. // the data then goes to 'incoming'
  25527. //
  25528. // 'accu0' and 'accu1' are used frame-interleaved for
  25529. // the cumulative result and are compared to detect
  25530. // changes
  25531. //
  25532. // 'orig' stores the original state of the property
  25533. //
  25534. // 'add' is used for additive cumulative results
  25535. //
  25536. // 'work' is optional and is only present for quaternion types. It is used
  25537. // to store intermediate quaternion multiplication results
  25538. switch (typeName) {
  25539. case 'quaternion':
  25540. mixFunction = this._slerp;
  25541. mixFunctionAdditive = this._slerpAdditive;
  25542. setIdentity = this._setAdditiveIdentityQuaternion;
  25543. this.buffer = new Float64Array(valueSize * 6);
  25544. this._workIndex = 5;
  25545. break;
  25546. case 'string':
  25547. case 'bool':
  25548. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  25549. // additive is not relevant for non-numeric types
  25550. mixFunctionAdditive = this._select;
  25551. setIdentity = this._setAdditiveIdentityOther;
  25552. this.buffer = new Array(valueSize * 5);
  25553. break;
  25554. default:
  25555. mixFunction = this._lerp;
  25556. mixFunctionAdditive = this._lerpAdditive;
  25557. setIdentity = this._setAdditiveIdentityNumeric;
  25558. this.buffer = new Float64Array(valueSize * 5);
  25559. }
  25560. this._mixBufferRegion = mixFunction;
  25561. this._mixBufferRegionAdditive = mixFunctionAdditive;
  25562. this._setIdentity = setIdentity;
  25563. this._origIndex = 3;
  25564. this._addIndex = 4;
  25565. this.cumulativeWeight = 0;
  25566. this.cumulativeWeightAdditive = 0;
  25567. this.useCount = 0;
  25568. this.referenceCount = 0;
  25569. }
  25570. Object.assign(PropertyMixer.prototype, {
  25571. // accumulate data in the 'incoming' region into 'accu<i>'
  25572. accumulate: function accumulate(accuIndex, weight) {
  25573. // note: happily accumulating nothing when weight = 0, the caller knows
  25574. // the weight and shouldn't have made the call in the first place
  25575. var buffer = this.buffer,
  25576. stride = this.valueSize,
  25577. offset = accuIndex * stride + stride;
  25578. var currentWeight = this.cumulativeWeight;
  25579. if (currentWeight === 0) {
  25580. // accuN := incoming * weight
  25581. for (var i = 0; i !== stride; ++i) {
  25582. buffer[offset + i] = buffer[i];
  25583. }
  25584. currentWeight = weight;
  25585. } else {
  25586. // accuN := accuN + incoming * weight
  25587. currentWeight += weight;
  25588. var mix = weight / currentWeight;
  25589. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  25590. }
  25591. this.cumulativeWeight = currentWeight;
  25592. },
  25593. // accumulate data in the 'incoming' region into 'add'
  25594. accumulateAdditive: function accumulateAdditive(weight) {
  25595. var buffer = this.buffer,
  25596. stride = this.valueSize,
  25597. offset = stride * this._addIndex;
  25598. if (this.cumulativeWeightAdditive === 0) {
  25599. // add = identity
  25600. this._setIdentity();
  25601. } // add := add + incoming * weight
  25602. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  25603. this.cumulativeWeightAdditive += weight;
  25604. },
  25605. // apply the state of 'accu<i>' to the binding when accus differ
  25606. apply: function apply(accuIndex) {
  25607. var stride = this.valueSize,
  25608. buffer = this.buffer,
  25609. offset = accuIndex * stride + stride,
  25610. weight = this.cumulativeWeight,
  25611. weightAdditive = this.cumulativeWeightAdditive,
  25612. binding = this.binding;
  25613. this.cumulativeWeight = 0;
  25614. this.cumulativeWeightAdditive = 0;
  25615. if (weight < 1) {
  25616. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25617. var originalValueOffset = stride * this._origIndex;
  25618. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  25619. }
  25620. if (weightAdditive > 0) {
  25621. // accuN := accuN + additive accuN
  25622. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  25623. }
  25624. for (var i = stride, e = stride + stride; i !== e; ++i) {
  25625. if (buffer[i] !== buffer[i + stride]) {
  25626. // value has changed -> update scene graph
  25627. binding.setValue(buffer, offset);
  25628. break;
  25629. }
  25630. }
  25631. },
  25632. // remember the state of the bound property and copy it to both accus
  25633. saveOriginalState: function saveOriginalState() {
  25634. var binding = this.binding;
  25635. var buffer = this.buffer,
  25636. stride = this.valueSize,
  25637. originalValueOffset = stride * this._origIndex;
  25638. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  25639. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  25640. buffer[i] = buffer[originalValueOffset + i % stride];
  25641. } // Add to identity for additive
  25642. this._setIdentity();
  25643. this.cumulativeWeight = 0;
  25644. this.cumulativeWeightAdditive = 0;
  25645. },
  25646. // apply the state previously taken via 'saveOriginalState' to the binding
  25647. restoreOriginalState: function restoreOriginalState() {
  25648. var originalValueOffset = this.valueSize * 3;
  25649. this.binding.setValue(this.buffer, originalValueOffset);
  25650. },
  25651. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  25652. var startIndex = this._addIndex * this.valueSize;
  25653. var endIndex = startIndex + this.valueSize;
  25654. for (var i = startIndex; i < endIndex; i++) {
  25655. this.buffer[i] = 0;
  25656. }
  25657. },
  25658. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  25659. this._setAdditiveIdentityNumeric();
  25660. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  25661. },
  25662. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  25663. var startIndex = this._origIndex * this.valueSize;
  25664. var targetIndex = this._addIndex * this.valueSize;
  25665. for (var i = 0; i < this.valueSize; i++) {
  25666. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  25667. }
  25668. },
  25669. // mix functions
  25670. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  25671. if (t >= 0.5) {
  25672. for (var i = 0; i !== stride; ++i) {
  25673. buffer[dstOffset + i] = buffer[srcOffset + i];
  25674. }
  25675. }
  25676. },
  25677. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  25678. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  25679. },
  25680. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25681. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  25682. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  25683. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  25684. },
  25685. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  25686. var s = 1 - t;
  25687. for (var i = 0; i !== stride; ++i) {
  25688. var j = dstOffset + i;
  25689. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  25690. }
  25691. },
  25692. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25693. for (var i = 0; i !== stride; ++i) {
  25694. var j = dstOffset + i;
  25695. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  25696. }
  25697. }
  25698. });
  25699. // Characters [].:/ are reserved for track binding syntax.
  25700. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25701. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25702. // only latin characters, and the unicode \p{L} is not yet supported. So
  25703. // instead, we exclude reserved characters and match everything else.
  25704. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  25705. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25706. // be matched to parse the rest of the track name.
  25707. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25708. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  25709. // characters. Accessor may contain any character except closing bracket.
  25710. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  25711. // contain any non-bracket characters.
  25712. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  25713. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  25714. var _supportedObjectNames = ['material', 'materials', 'bones'];
  25715. function Composite(targetGroup, path, optionalParsedPath) {
  25716. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  25717. this._targetGroup = targetGroup;
  25718. this._bindings = targetGroup.subscribe_(path, parsedPath);
  25719. }
  25720. Object.assign(Composite.prototype, {
  25721. getValue: function getValue(array, offset) {
  25722. this.bind(); // bind all binding
  25723. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25724. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  25725. if (binding !== undefined) binding.getValue(array, offset);
  25726. },
  25727. setValue: function setValue(array, offset) {
  25728. var bindings = this._bindings;
  25729. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25730. bindings[i].setValue(array, offset);
  25731. }
  25732. },
  25733. bind: function bind() {
  25734. var bindings = this._bindings;
  25735. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25736. bindings[i].bind();
  25737. }
  25738. },
  25739. unbind: function unbind() {
  25740. var bindings = this._bindings;
  25741. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25742. bindings[i].unbind();
  25743. }
  25744. }
  25745. });
  25746. function PropertyBinding(rootNode, path, parsedPath) {
  25747. this.path = path;
  25748. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  25749. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  25750. this.rootNode = rootNode;
  25751. }
  25752. Object.assign(PropertyBinding, {
  25753. Composite: Composite,
  25754. create: function create(root, path, parsedPath) {
  25755. if (!(root && root.isAnimationObjectGroup)) {
  25756. return new PropertyBinding(root, path, parsedPath);
  25757. } else {
  25758. return new PropertyBinding.Composite(root, path, parsedPath);
  25759. }
  25760. },
  25761. /**
  25762. * Replaces spaces with underscores and removes unsupported characters from
  25763. * node names, to ensure compatibility with parseTrackName().
  25764. *
  25765. * @param {string} name Node name to be sanitized.
  25766. * @return {string}
  25767. */
  25768. sanitizeNodeName: function sanitizeNodeName(name) {
  25769. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  25770. },
  25771. parseTrackName: function parseTrackName(trackName) {
  25772. var matches = _trackRe.exec(trackName);
  25773. if (!matches) {
  25774. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  25775. }
  25776. var results = {
  25777. // directoryName: matches[ 1 ], // (tschw) currently unused
  25778. nodeName: matches[2],
  25779. objectName: matches[3],
  25780. objectIndex: matches[4],
  25781. propertyName: matches[5],
  25782. // required
  25783. propertyIndex: matches[6]
  25784. };
  25785. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  25786. if (lastDot !== undefined && lastDot !== -1) {
  25787. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  25788. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  25789. // 'bar' could be the objectName, or part of a nodeName (which can
  25790. // include '.' characters).
  25791. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  25792. results.nodeName = results.nodeName.substring(0, lastDot);
  25793. results.objectName = objectName;
  25794. }
  25795. }
  25796. if (results.propertyName === null || results.propertyName.length === 0) {
  25797. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  25798. }
  25799. return results;
  25800. },
  25801. findNode: function findNode(root, nodeName) {
  25802. if (!nodeName || nodeName === "" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  25803. return root;
  25804. } // search into skeleton bones.
  25805. if (root.skeleton) {
  25806. var bone = root.skeleton.getBoneByName(nodeName);
  25807. if (bone !== undefined) {
  25808. return bone;
  25809. }
  25810. } // search into node subtree.
  25811. if (root.children) {
  25812. var searchNodeSubtree = function searchNodeSubtree(children) {
  25813. for (var i = 0; i < children.length; i++) {
  25814. var childNode = children[i];
  25815. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  25816. return childNode;
  25817. }
  25818. var result = searchNodeSubtree(childNode.children);
  25819. if (result) return result;
  25820. }
  25821. return null;
  25822. };
  25823. var subTreeNode = searchNodeSubtree(root.children);
  25824. if (subTreeNode) {
  25825. return subTreeNode;
  25826. }
  25827. }
  25828. return null;
  25829. }
  25830. });
  25831. Object.assign(PropertyBinding.prototype, {
  25832. // prototype, continued
  25833. // these are used to "bind" a nonexistent property
  25834. _getValue_unavailable: function _getValue_unavailable() {},
  25835. _setValue_unavailable: function _setValue_unavailable() {},
  25836. BindingType: {
  25837. Direct: 0,
  25838. EntireArray: 1,
  25839. ArrayElement: 2,
  25840. HasFromToArray: 3
  25841. },
  25842. Versioning: {
  25843. None: 0,
  25844. NeedsUpdate: 1,
  25845. MatrixWorldNeedsUpdate: 2
  25846. },
  25847. GetterByBindingType: [function getValue_direct(buffer, offset) {
  25848. buffer[offset] = this.node[this.propertyName];
  25849. }, function getValue_array(buffer, offset) {
  25850. var source = this.resolvedProperty;
  25851. for (var i = 0, n = source.length; i !== n; ++i) {
  25852. buffer[offset++] = source[i];
  25853. }
  25854. }, function getValue_arrayElement(buffer, offset) {
  25855. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  25856. }, function getValue_toArray(buffer, offset) {
  25857. this.resolvedProperty.toArray(buffer, offset);
  25858. }],
  25859. SetterByBindingTypeAndVersioning: [[// Direct
  25860. function setValue_direct(buffer, offset) {
  25861. this.targetObject[this.propertyName] = buffer[offset];
  25862. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  25863. this.targetObject[this.propertyName] = buffer[offset];
  25864. this.targetObject.needsUpdate = true;
  25865. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  25866. this.targetObject[this.propertyName] = buffer[offset];
  25867. this.targetObject.matrixWorldNeedsUpdate = true;
  25868. }], [// EntireArray
  25869. function setValue_array(buffer, offset) {
  25870. var dest = this.resolvedProperty;
  25871. for (var i = 0, n = dest.length; i !== n; ++i) {
  25872. dest[i] = buffer[offset++];
  25873. }
  25874. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  25875. var dest = this.resolvedProperty;
  25876. for (var i = 0, n = dest.length; i !== n; ++i) {
  25877. dest[i] = buffer[offset++];
  25878. }
  25879. this.targetObject.needsUpdate = true;
  25880. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  25881. var dest = this.resolvedProperty;
  25882. for (var i = 0, n = dest.length; i !== n; ++i) {
  25883. dest[i] = buffer[offset++];
  25884. }
  25885. this.targetObject.matrixWorldNeedsUpdate = true;
  25886. }], [// ArrayElement
  25887. function setValue_arrayElement(buffer, offset) {
  25888. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25889. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  25890. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25891. this.targetObject.needsUpdate = true;
  25892. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  25893. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25894. this.targetObject.matrixWorldNeedsUpdate = true;
  25895. }], [// HasToFromArray
  25896. function setValue_fromArray(buffer, offset) {
  25897. this.resolvedProperty.fromArray(buffer, offset);
  25898. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  25899. this.resolvedProperty.fromArray(buffer, offset);
  25900. this.targetObject.needsUpdate = true;
  25901. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  25902. this.resolvedProperty.fromArray(buffer, offset);
  25903. this.targetObject.matrixWorldNeedsUpdate = true;
  25904. }]],
  25905. getValue: function getValue_unbound(targetArray, offset) {
  25906. this.bind();
  25907. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  25908. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  25909. // prototype version of these methods with one that represents
  25910. // the bound state. When the property is not found, the methods
  25911. // become no-ops.
  25912. },
  25913. setValue: function getValue_unbound(sourceArray, offset) {
  25914. this.bind();
  25915. this.setValue(sourceArray, offset);
  25916. },
  25917. // create getter / setter pair for a property in the scene graph
  25918. bind: function bind() {
  25919. var targetObject = this.node;
  25920. var parsedPath = this.parsedPath;
  25921. var objectName = parsedPath.objectName;
  25922. var propertyName = parsedPath.propertyName;
  25923. var propertyIndex = parsedPath.propertyIndex;
  25924. if (!targetObject) {
  25925. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  25926. this.node = targetObject;
  25927. } // set fail state so we can just 'return' on error
  25928. this.getValue = this._getValue_unavailable;
  25929. this.setValue = this._setValue_unavailable; // ensure there is a value node
  25930. if (!targetObject) {
  25931. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  25932. return;
  25933. }
  25934. if (objectName) {
  25935. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  25936. switch (objectName) {
  25937. case 'materials':
  25938. if (!targetObject.material) {
  25939. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  25940. return;
  25941. }
  25942. if (!targetObject.material.materials) {
  25943. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  25944. return;
  25945. }
  25946. targetObject = targetObject.material.materials;
  25947. break;
  25948. case 'bones':
  25949. if (!targetObject.skeleton) {
  25950. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  25951. return;
  25952. } // potential future optimization: skip this if propertyIndex is already an integer
  25953. // and convert the integer string to a true integer.
  25954. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  25955. for (var i = 0; i < targetObject.length; i++) {
  25956. if (targetObject[i].name === objectIndex) {
  25957. objectIndex = i;
  25958. break;
  25959. }
  25960. }
  25961. break;
  25962. default:
  25963. if (targetObject[objectName] === undefined) {
  25964. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  25965. return;
  25966. }
  25967. targetObject = targetObject[objectName];
  25968. }
  25969. if (objectIndex !== undefined) {
  25970. if (targetObject[objectIndex] === undefined) {
  25971. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  25972. return;
  25973. }
  25974. targetObject = targetObject[objectIndex];
  25975. }
  25976. } // resolve property
  25977. var nodeProperty = targetObject[propertyName];
  25978. if (nodeProperty === undefined) {
  25979. var nodeName = parsedPath.nodeName;
  25980. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  25981. return;
  25982. } // determine versioning scheme
  25983. var versioning = this.Versioning.None;
  25984. this.targetObject = targetObject;
  25985. if (targetObject.needsUpdate !== undefined) {
  25986. // material
  25987. versioning = this.Versioning.NeedsUpdate;
  25988. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  25989. // node transform
  25990. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  25991. } // determine how the property gets bound
  25992. var bindingType = this.BindingType.Direct;
  25993. if (propertyIndex !== undefined) {
  25994. // access a sub element of the property array (only primitives are supported right now)
  25995. if (propertyName === "morphTargetInfluences") {
  25996. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  25997. // support resolving morphTarget names into indices.
  25998. if (!targetObject.geometry) {
  25999. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  26000. return;
  26001. }
  26002. if (targetObject.geometry.isBufferGeometry) {
  26003. if (!targetObject.geometry.morphAttributes) {
  26004. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  26005. return;
  26006. }
  26007. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  26008. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  26009. }
  26010. } else {
  26011. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  26012. return;
  26013. }
  26014. }
  26015. bindingType = this.BindingType.ArrayElement;
  26016. this.resolvedProperty = nodeProperty;
  26017. this.propertyIndex = propertyIndex;
  26018. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26019. // must use copy for Object3D.Euler/Quaternion
  26020. bindingType = this.BindingType.HasFromToArray;
  26021. this.resolvedProperty = nodeProperty;
  26022. } else if (Array.isArray(nodeProperty)) {
  26023. bindingType = this.BindingType.EntireArray;
  26024. this.resolvedProperty = nodeProperty;
  26025. } else {
  26026. this.propertyName = propertyName;
  26027. } // select getter / setter
  26028. this.getValue = this.GetterByBindingType[bindingType];
  26029. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26030. },
  26031. unbind: function unbind() {
  26032. this.node = null; // back to the prototype version of getValue / setValue
  26033. // note: avoiding to mutate the shape of 'this' via 'delete'
  26034. this.getValue = this._getValue_unbound;
  26035. this.setValue = this._setValue_unbound;
  26036. }
  26037. }); // DECLARE ALIAS AFTER assign prototype
  26038. Object.assign(PropertyBinding.prototype, {
  26039. // initial state of these methods that calls 'bind'
  26040. _getValue_unbound: PropertyBinding.prototype.getValue,
  26041. _setValue_unbound: PropertyBinding.prototype.setValue
  26042. });
  26043. /**
  26044. *
  26045. * A group of objects that receives a shared animation state.
  26046. *
  26047. * Usage:
  26048. *
  26049. * - Add objects you would otherwise pass as 'root' to the
  26050. * constructor or the .clipAction method of AnimationMixer.
  26051. *
  26052. * - Instead pass this object as 'root'.
  26053. *
  26054. * - You can also add and remove objects later when the mixer
  26055. * is running.
  26056. *
  26057. * Note:
  26058. *
  26059. * Objects of this class appear as one object to the mixer,
  26060. * so cache control of the individual objects must be done
  26061. * on the group.
  26062. *
  26063. * Limitation:
  26064. *
  26065. * - The animated properties must be compatible among the
  26066. * all objects in the group.
  26067. *
  26068. * - A single property can either be controlled through a
  26069. * target group or directly, but not both.
  26070. */
  26071. function AnimationObjectGroup() {
  26072. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26073. this._objects = Array.prototype.slice.call(arguments);
  26074. this.nCachedObjects_ = 0; // threshold
  26075. // note: read by PropertyBinding.Composite
  26076. var indices = {};
  26077. this._indicesByUUID = indices; // for bookkeeping
  26078. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26079. indices[arguments[i].uuid] = i;
  26080. }
  26081. this._paths = []; // inside: string
  26082. this._parsedPaths = []; // inside: { we don't care, here }
  26083. this._bindings = []; // inside: Array< PropertyBinding >
  26084. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26085. var scope = this;
  26086. this.stats = {
  26087. objects: {
  26088. get total() {
  26089. return scope._objects.length;
  26090. },
  26091. get inUse() {
  26092. return this.total - scope.nCachedObjects_;
  26093. }
  26094. },
  26095. get bindingsPerObject() {
  26096. return scope._bindings.length;
  26097. }
  26098. };
  26099. }
  26100. Object.assign(AnimationObjectGroup.prototype, {
  26101. isAnimationObjectGroup: true,
  26102. add: function add() {
  26103. var objects = this._objects,
  26104. indicesByUUID = this._indicesByUUID,
  26105. paths = this._paths,
  26106. parsedPaths = this._parsedPaths,
  26107. bindings = this._bindings,
  26108. nBindings = bindings.length;
  26109. var knownObject = undefined,
  26110. nObjects = objects.length,
  26111. nCachedObjects = this.nCachedObjects_;
  26112. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26113. var object = arguments[i],
  26114. uuid = object.uuid;
  26115. var index = indicesByUUID[uuid];
  26116. if (index === undefined) {
  26117. // unknown object -> add it to the ACTIVE region
  26118. index = nObjects++;
  26119. indicesByUUID[uuid] = index;
  26120. objects.push(object); // accounting is done, now do the same for all bindings
  26121. for (var j = 0, m = nBindings; j !== m; ++j) {
  26122. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26123. }
  26124. } else if (index < nCachedObjects) {
  26125. knownObject = objects[index]; // move existing object to the ACTIVE region
  26126. var firstActiveIndex = --nCachedObjects,
  26127. lastCachedObject = objects[firstActiveIndex];
  26128. indicesByUUID[lastCachedObject.uuid] = index;
  26129. objects[index] = lastCachedObject;
  26130. indicesByUUID[uuid] = firstActiveIndex;
  26131. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26132. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26133. var bindingsForPath = bindings[_j],
  26134. lastCached = bindingsForPath[firstActiveIndex];
  26135. var binding = bindingsForPath[index];
  26136. bindingsForPath[index] = lastCached;
  26137. if (binding === undefined) {
  26138. // since we do not bother to create new bindings
  26139. // for objects that are cached, the binding may
  26140. // or may not exist
  26141. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26142. }
  26143. bindingsForPath[firstActiveIndex] = binding;
  26144. }
  26145. } else if (objects[index] !== knownObject) {
  26146. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26147. } // else the object is already where we want it to be
  26148. } // for arguments
  26149. this.nCachedObjects_ = nCachedObjects;
  26150. },
  26151. remove: function remove() {
  26152. var objects = this._objects,
  26153. indicesByUUID = this._indicesByUUID,
  26154. bindings = this._bindings,
  26155. nBindings = bindings.length;
  26156. var nCachedObjects = this.nCachedObjects_;
  26157. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26158. var object = arguments[i],
  26159. uuid = object.uuid,
  26160. index = indicesByUUID[uuid];
  26161. if (index !== undefined && index >= nCachedObjects) {
  26162. // move existing object into the CACHED region
  26163. var lastCachedIndex = nCachedObjects++,
  26164. firstActiveObject = objects[lastCachedIndex];
  26165. indicesByUUID[firstActiveObject.uuid] = index;
  26166. objects[index] = firstActiveObject;
  26167. indicesByUUID[uuid] = lastCachedIndex;
  26168. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26169. for (var j = 0, m = nBindings; j !== m; ++j) {
  26170. var bindingsForPath = bindings[j],
  26171. firstActive = bindingsForPath[lastCachedIndex],
  26172. binding = bindingsForPath[index];
  26173. bindingsForPath[index] = firstActive;
  26174. bindingsForPath[lastCachedIndex] = binding;
  26175. }
  26176. }
  26177. } // for arguments
  26178. this.nCachedObjects_ = nCachedObjects;
  26179. },
  26180. // remove & forget
  26181. uncache: function uncache() {
  26182. var objects = this._objects,
  26183. indicesByUUID = this._indicesByUUID,
  26184. bindings = this._bindings,
  26185. nBindings = bindings.length;
  26186. var nCachedObjects = this.nCachedObjects_,
  26187. nObjects = objects.length;
  26188. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26189. var object = arguments[i],
  26190. uuid = object.uuid,
  26191. index = indicesByUUID[uuid];
  26192. if (index !== undefined) {
  26193. delete indicesByUUID[uuid];
  26194. if (index < nCachedObjects) {
  26195. // object is cached, shrink the CACHED region
  26196. var firstActiveIndex = --nCachedObjects,
  26197. lastCachedObject = objects[firstActiveIndex],
  26198. lastIndex = --nObjects,
  26199. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26200. indicesByUUID[lastCachedObject.uuid] = index;
  26201. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26202. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26203. objects[firstActiveIndex] = lastObject;
  26204. objects.pop(); // accounting is done, now do the same for all bindings
  26205. for (var j = 0, m = nBindings; j !== m; ++j) {
  26206. var bindingsForPath = bindings[j],
  26207. lastCached = bindingsForPath[firstActiveIndex],
  26208. last = bindingsForPath[lastIndex];
  26209. bindingsForPath[index] = lastCached;
  26210. bindingsForPath[firstActiveIndex] = last;
  26211. bindingsForPath.pop();
  26212. }
  26213. } else {
  26214. // object is active, just swap with the last and pop
  26215. var _lastIndex = --nObjects,
  26216. _lastObject = objects[_lastIndex];
  26217. indicesByUUID[_lastObject.uuid] = index;
  26218. objects[index] = _lastObject;
  26219. objects.pop(); // accounting is done, now do the same for all bindings
  26220. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26221. var _bindingsForPath = bindings[_j2];
  26222. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26223. _bindingsForPath.pop();
  26224. }
  26225. } // cached or active
  26226. } // if object is known
  26227. } // for arguments
  26228. this.nCachedObjects_ = nCachedObjects;
  26229. },
  26230. // Internal interface used by befriended PropertyBinding.Composite:
  26231. subscribe_: function subscribe_(path, parsedPath) {
  26232. // returns an array of bindings for the given path that is changed
  26233. // according to the contained objects in the group
  26234. var indicesByPath = this._bindingsIndicesByPath;
  26235. var index = indicesByPath[path];
  26236. var bindings = this._bindings;
  26237. if (index !== undefined) return bindings[index];
  26238. var paths = this._paths,
  26239. parsedPaths = this._parsedPaths,
  26240. objects = this._objects,
  26241. nObjects = objects.length,
  26242. nCachedObjects = this.nCachedObjects_,
  26243. bindingsForPath = new Array(nObjects);
  26244. index = bindings.length;
  26245. indicesByPath[path] = index;
  26246. paths.push(path);
  26247. parsedPaths.push(parsedPath);
  26248. bindings.push(bindingsForPath);
  26249. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26250. var object = objects[i];
  26251. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26252. }
  26253. return bindingsForPath;
  26254. },
  26255. unsubscribe_: function unsubscribe_(path) {
  26256. // tells the group to forget about a property path and no longer
  26257. // update the array previously obtained with 'subscribe_'
  26258. var indicesByPath = this._bindingsIndicesByPath,
  26259. index = indicesByPath[path];
  26260. if (index !== undefined) {
  26261. var paths = this._paths,
  26262. parsedPaths = this._parsedPaths,
  26263. bindings = this._bindings,
  26264. lastBindingsIndex = bindings.length - 1,
  26265. lastBindings = bindings[lastBindingsIndex],
  26266. lastBindingsPath = path[lastBindingsIndex];
  26267. indicesByPath[lastBindingsPath] = index;
  26268. bindings[index] = lastBindings;
  26269. bindings.pop();
  26270. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26271. parsedPaths.pop();
  26272. paths[index] = paths[lastBindingsIndex];
  26273. paths.pop();
  26274. }
  26275. }
  26276. });
  26277. var AnimationAction = /*#__PURE__*/function () {
  26278. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26279. this._mixer = mixer;
  26280. this._clip = clip;
  26281. this._localRoot = localRoot || null;
  26282. this.blendMode = blendMode || clip.blendMode;
  26283. var tracks = clip.tracks,
  26284. nTracks = tracks.length,
  26285. interpolants = new Array(nTracks);
  26286. var interpolantSettings = {
  26287. endingStart: ZeroCurvatureEnding,
  26288. endingEnd: ZeroCurvatureEnding
  26289. };
  26290. for (var i = 0; i !== nTracks; ++i) {
  26291. var interpolant = tracks[i].createInterpolant(null);
  26292. interpolants[i] = interpolant;
  26293. interpolant.settings = interpolantSettings;
  26294. }
  26295. this._interpolantSettings = interpolantSettings;
  26296. this._interpolants = interpolants; // bound by the mixer
  26297. // inside: PropertyMixer (managed by the mixer)
  26298. this._propertyBindings = new Array(nTracks);
  26299. this._cacheIndex = null; // for the memory manager
  26300. this._byClipCacheIndex = null; // for the memory manager
  26301. this._timeScaleInterpolant = null;
  26302. this._weightInterpolant = null;
  26303. this.loop = LoopRepeat;
  26304. this._loopCount = -1; // global mixer time when the action is to be started
  26305. // it's set back to 'null' upon start of the action
  26306. this._startTime = null; // scaled local time of the action
  26307. // gets clamped or wrapped to 0..clip.duration according to loop
  26308. this.time = 0;
  26309. this.timeScale = 1;
  26310. this._effectiveTimeScale = 1;
  26311. this.weight = 1;
  26312. this._effectiveWeight = 1;
  26313. this.repetitions = Infinity; // no. of repetitions when looping
  26314. this.paused = false; // true -> zero effective time scale
  26315. this.enabled = true; // false -> zero effective weight
  26316. this.clampWhenFinished = false; // keep feeding the last frame?
  26317. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  26318. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  26319. } // State & Scheduling
  26320. var _proto = AnimationAction.prototype;
  26321. _proto.play = function play() {
  26322. this._mixer._activateAction(this);
  26323. return this;
  26324. };
  26325. _proto.stop = function stop() {
  26326. this._mixer._deactivateAction(this);
  26327. return this.reset();
  26328. };
  26329. _proto.reset = function reset() {
  26330. this.paused = false;
  26331. this.enabled = true;
  26332. this.time = 0; // restart clip
  26333. this._loopCount = -1; // forget previous loops
  26334. this._startTime = null; // forget scheduling
  26335. return this.stopFading().stopWarping();
  26336. };
  26337. _proto.isRunning = function isRunning() {
  26338. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  26339. } // return true when play has been called
  26340. ;
  26341. _proto.isScheduled = function isScheduled() {
  26342. return this._mixer._isActiveAction(this);
  26343. };
  26344. _proto.startAt = function startAt(time) {
  26345. this._startTime = time;
  26346. return this;
  26347. };
  26348. _proto.setLoop = function setLoop(mode, repetitions) {
  26349. this.loop = mode;
  26350. this.repetitions = repetitions;
  26351. return this;
  26352. } // Weight
  26353. // set the weight stopping any scheduled fading
  26354. // although .enabled = false yields an effective weight of zero, this
  26355. // method does *not* change .enabled, because it would be confusing
  26356. ;
  26357. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  26358. this.weight = weight; // note: same logic as when updated at runtime
  26359. this._effectiveWeight = this.enabled ? weight : 0;
  26360. return this.stopFading();
  26361. } // return the weight considering fading and .enabled
  26362. ;
  26363. _proto.getEffectiveWeight = function getEffectiveWeight() {
  26364. return this._effectiveWeight;
  26365. };
  26366. _proto.fadeIn = function fadeIn(duration) {
  26367. return this._scheduleFading(duration, 0, 1);
  26368. };
  26369. _proto.fadeOut = function fadeOut(duration) {
  26370. return this._scheduleFading(duration, 1, 0);
  26371. };
  26372. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  26373. fadeOutAction.fadeOut(duration);
  26374. this.fadeIn(duration);
  26375. if (warp) {
  26376. var fadeInDuration = this._clip.duration,
  26377. fadeOutDuration = fadeOutAction._clip.duration,
  26378. startEndRatio = fadeOutDuration / fadeInDuration,
  26379. endStartRatio = fadeInDuration / fadeOutDuration;
  26380. fadeOutAction.warp(1.0, startEndRatio, duration);
  26381. this.warp(endStartRatio, 1.0, duration);
  26382. }
  26383. return this;
  26384. };
  26385. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  26386. return fadeInAction.crossFadeFrom(this, duration, warp);
  26387. };
  26388. _proto.stopFading = function stopFading() {
  26389. var weightInterpolant = this._weightInterpolant;
  26390. if (weightInterpolant !== null) {
  26391. this._weightInterpolant = null;
  26392. this._mixer._takeBackControlInterpolant(weightInterpolant);
  26393. }
  26394. return this;
  26395. } // Time Scale Control
  26396. // set the time scale stopping any scheduled warping
  26397. // although .paused = true yields an effective time scale of zero, this
  26398. // method does *not* change .paused, because it would be confusing
  26399. ;
  26400. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  26401. this.timeScale = timeScale;
  26402. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26403. return this.stopWarping();
  26404. } // return the time scale considering warping and .paused
  26405. ;
  26406. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  26407. return this._effectiveTimeScale;
  26408. };
  26409. _proto.setDuration = function setDuration(duration) {
  26410. this.timeScale = this._clip.duration / duration;
  26411. return this.stopWarping();
  26412. };
  26413. _proto.syncWith = function syncWith(action) {
  26414. this.time = action.time;
  26415. this.timeScale = action.timeScale;
  26416. return this.stopWarping();
  26417. };
  26418. _proto.halt = function halt(duration) {
  26419. return this.warp(this._effectiveTimeScale, 0, duration);
  26420. };
  26421. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  26422. var mixer = this._mixer,
  26423. now = mixer.time,
  26424. timeScale = this.timeScale;
  26425. var interpolant = this._timeScaleInterpolant;
  26426. if (interpolant === null) {
  26427. interpolant = mixer._lendControlInterpolant();
  26428. this._timeScaleInterpolant = interpolant;
  26429. }
  26430. var times = interpolant.parameterPositions,
  26431. values = interpolant.sampleValues;
  26432. times[0] = now;
  26433. times[1] = now + duration;
  26434. values[0] = startTimeScale / timeScale;
  26435. values[1] = endTimeScale / timeScale;
  26436. return this;
  26437. };
  26438. _proto.stopWarping = function stopWarping() {
  26439. var timeScaleInterpolant = this._timeScaleInterpolant;
  26440. if (timeScaleInterpolant !== null) {
  26441. this._timeScaleInterpolant = null;
  26442. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  26443. }
  26444. return this;
  26445. } // Object Accessors
  26446. ;
  26447. _proto.getMixer = function getMixer() {
  26448. return this._mixer;
  26449. };
  26450. _proto.getClip = function getClip() {
  26451. return this._clip;
  26452. };
  26453. _proto.getRoot = function getRoot() {
  26454. return this._localRoot || this._mixer._root;
  26455. } // Interna
  26456. ;
  26457. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  26458. // called by the mixer
  26459. if (!this.enabled) {
  26460. // call ._updateWeight() to update ._effectiveWeight
  26461. this._updateWeight(time);
  26462. return;
  26463. }
  26464. var startTime = this._startTime;
  26465. if (startTime !== null) {
  26466. // check for scheduled start of action
  26467. var timeRunning = (time - startTime) * timeDirection;
  26468. if (timeRunning < 0 || timeDirection === 0) {
  26469. return; // yet to come / don't decide when delta = 0
  26470. } // start
  26471. this._startTime = null; // unschedule
  26472. deltaTime = timeDirection * timeRunning;
  26473. } // apply time scale and advance time
  26474. deltaTime *= this._updateTimeScale(time);
  26475. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  26476. // an effective weight of 0
  26477. var weight = this._updateWeight(time);
  26478. if (weight > 0) {
  26479. var _interpolants = this._interpolants;
  26480. var propertyMixers = this._propertyBindings;
  26481. switch (this.blendMode) {
  26482. case AdditiveAnimationBlendMode:
  26483. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  26484. _interpolants[j].evaluate(clipTime);
  26485. propertyMixers[j].accumulateAdditive(weight);
  26486. }
  26487. break;
  26488. case NormalAnimationBlendMode:
  26489. default:
  26490. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  26491. _interpolants[_j].evaluate(clipTime);
  26492. propertyMixers[_j].accumulate(accuIndex, weight);
  26493. }
  26494. }
  26495. }
  26496. };
  26497. _proto._updateWeight = function _updateWeight(time) {
  26498. var weight = 0;
  26499. if (this.enabled) {
  26500. weight = this.weight;
  26501. var interpolant = this._weightInterpolant;
  26502. if (interpolant !== null) {
  26503. var interpolantValue = interpolant.evaluate(time)[0];
  26504. weight *= interpolantValue;
  26505. if (time > interpolant.parameterPositions[1]) {
  26506. this.stopFading();
  26507. if (interpolantValue === 0) {
  26508. // faded out, disable
  26509. this.enabled = false;
  26510. }
  26511. }
  26512. }
  26513. }
  26514. this._effectiveWeight = weight;
  26515. return weight;
  26516. };
  26517. _proto._updateTimeScale = function _updateTimeScale(time) {
  26518. var timeScale = 0;
  26519. if (!this.paused) {
  26520. timeScale = this.timeScale;
  26521. var interpolant = this._timeScaleInterpolant;
  26522. if (interpolant !== null) {
  26523. var interpolantValue = interpolant.evaluate(time)[0];
  26524. timeScale *= interpolantValue;
  26525. if (time > interpolant.parameterPositions[1]) {
  26526. this.stopWarping();
  26527. if (timeScale === 0) {
  26528. // motion has halted, pause
  26529. this.paused = true;
  26530. } else {
  26531. // warp done - apply final time scale
  26532. this.timeScale = timeScale;
  26533. }
  26534. }
  26535. }
  26536. }
  26537. this._effectiveTimeScale = timeScale;
  26538. return timeScale;
  26539. };
  26540. _proto._updateTime = function _updateTime(deltaTime) {
  26541. var duration = this._clip.duration;
  26542. var loop = this.loop;
  26543. var time = this.time + deltaTime;
  26544. var loopCount = this._loopCount;
  26545. var pingPong = loop === LoopPingPong;
  26546. if (deltaTime === 0) {
  26547. if (loopCount === -1) return time;
  26548. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  26549. }
  26550. if (loop === LoopOnce) {
  26551. if (loopCount === -1) {
  26552. // just started
  26553. this._loopCount = 0;
  26554. this._setEndings(true, true, false);
  26555. }
  26556. handle_stop: {
  26557. if (time >= duration) {
  26558. time = duration;
  26559. } else if (time < 0) {
  26560. time = 0;
  26561. } else {
  26562. this.time = time;
  26563. break handle_stop;
  26564. }
  26565. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26566. this.time = time;
  26567. this._mixer.dispatchEvent({
  26568. type: 'finished',
  26569. action: this,
  26570. direction: deltaTime < 0 ? -1 : 1
  26571. });
  26572. }
  26573. } else {
  26574. // repetitive Repeat or PingPong
  26575. if (loopCount === -1) {
  26576. // just started
  26577. if (deltaTime >= 0) {
  26578. loopCount = 0;
  26579. this._setEndings(true, this.repetitions === 0, pingPong);
  26580. } else {
  26581. // when looping in reverse direction, the initial
  26582. // transition through zero counts as a repetition,
  26583. // so leave loopCount at -1
  26584. this._setEndings(this.repetitions === 0, true, pingPong);
  26585. }
  26586. }
  26587. if (time >= duration || time < 0) {
  26588. // wrap around
  26589. var loopDelta = Math.floor(time / duration); // signed
  26590. time -= duration * loopDelta;
  26591. loopCount += Math.abs(loopDelta);
  26592. var pending = this.repetitions - loopCount;
  26593. if (pending <= 0) {
  26594. // have to stop (switch state, clamp time, fire event)
  26595. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26596. time = deltaTime > 0 ? duration : 0;
  26597. this.time = time;
  26598. this._mixer.dispatchEvent({
  26599. type: 'finished',
  26600. action: this,
  26601. direction: deltaTime > 0 ? 1 : -1
  26602. });
  26603. } else {
  26604. // keep running
  26605. if (pending === 1) {
  26606. // entering the last round
  26607. var atStart = deltaTime < 0;
  26608. this._setEndings(atStart, !atStart, pingPong);
  26609. } else {
  26610. this._setEndings(false, false, pingPong);
  26611. }
  26612. this._loopCount = loopCount;
  26613. this.time = time;
  26614. this._mixer.dispatchEvent({
  26615. type: 'loop',
  26616. action: this,
  26617. loopDelta: loopDelta
  26618. });
  26619. }
  26620. } else {
  26621. this.time = time;
  26622. }
  26623. if (pingPong && (loopCount & 1) === 1) {
  26624. // invert time for the "pong round"
  26625. return duration - time;
  26626. }
  26627. }
  26628. return time;
  26629. };
  26630. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  26631. var settings = this._interpolantSettings;
  26632. if (pingPong) {
  26633. settings.endingStart = ZeroSlopeEnding;
  26634. settings.endingEnd = ZeroSlopeEnding;
  26635. } else {
  26636. // assuming for LoopOnce atStart == atEnd == true
  26637. if (atStart) {
  26638. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26639. } else {
  26640. settings.endingStart = WrapAroundEnding;
  26641. }
  26642. if (atEnd) {
  26643. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26644. } else {
  26645. settings.endingEnd = WrapAroundEnding;
  26646. }
  26647. }
  26648. };
  26649. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  26650. var mixer = this._mixer,
  26651. now = mixer.time;
  26652. var interpolant = this._weightInterpolant;
  26653. if (interpolant === null) {
  26654. interpolant = mixer._lendControlInterpolant();
  26655. this._weightInterpolant = interpolant;
  26656. }
  26657. var times = interpolant.parameterPositions,
  26658. values = interpolant.sampleValues;
  26659. times[0] = now;
  26660. values[0] = weightNow;
  26661. times[1] = now + duration;
  26662. values[1] = weightThen;
  26663. return this;
  26664. };
  26665. return AnimationAction;
  26666. }();
  26667. function AnimationMixer(root) {
  26668. this._root = root;
  26669. this._initMemoryManager();
  26670. this._accuIndex = 0;
  26671. this.time = 0;
  26672. this.timeScale = 1.0;
  26673. }
  26674. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  26675. constructor: AnimationMixer,
  26676. _bindAction: function _bindAction(action, prototypeAction) {
  26677. var root = action._localRoot || this._root,
  26678. tracks = action._clip.tracks,
  26679. nTracks = tracks.length,
  26680. bindings = action._propertyBindings,
  26681. interpolants = action._interpolants,
  26682. rootUuid = root.uuid,
  26683. bindingsByRoot = this._bindingsByRootAndName;
  26684. var bindingsByName = bindingsByRoot[rootUuid];
  26685. if (bindingsByName === undefined) {
  26686. bindingsByName = {};
  26687. bindingsByRoot[rootUuid] = bindingsByName;
  26688. }
  26689. for (var i = 0; i !== nTracks; ++i) {
  26690. var track = tracks[i],
  26691. trackName = track.name;
  26692. var binding = bindingsByName[trackName];
  26693. if (binding !== undefined) {
  26694. bindings[i] = binding;
  26695. } else {
  26696. binding = bindings[i];
  26697. if (binding !== undefined) {
  26698. // existing binding, make sure the cache knows
  26699. if (binding._cacheIndex === null) {
  26700. ++binding.referenceCount;
  26701. this._addInactiveBinding(binding, rootUuid, trackName);
  26702. }
  26703. continue;
  26704. }
  26705. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  26706. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  26707. ++binding.referenceCount;
  26708. this._addInactiveBinding(binding, rootUuid, trackName);
  26709. bindings[i] = binding;
  26710. }
  26711. interpolants[i].resultBuffer = binding.buffer;
  26712. }
  26713. },
  26714. _activateAction: function _activateAction(action) {
  26715. if (!this._isActiveAction(action)) {
  26716. if (action._cacheIndex === null) {
  26717. // this action has been forgotten by the cache, but the user
  26718. // appears to be still using it -> rebind
  26719. var rootUuid = (action._localRoot || this._root).uuid,
  26720. clipUuid = action._clip.uuid,
  26721. actionsForClip = this._actionsByClip[clipUuid];
  26722. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  26723. this._addInactiveAction(action, clipUuid, rootUuid);
  26724. }
  26725. var bindings = action._propertyBindings; // increment reference counts / sort out state
  26726. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26727. var binding = bindings[i];
  26728. if (binding.useCount++ === 0) {
  26729. this._lendBinding(binding);
  26730. binding.saveOriginalState();
  26731. }
  26732. }
  26733. this._lendAction(action);
  26734. }
  26735. },
  26736. _deactivateAction: function _deactivateAction(action) {
  26737. if (this._isActiveAction(action)) {
  26738. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  26739. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26740. var binding = bindings[i];
  26741. if (--binding.useCount === 0) {
  26742. binding.restoreOriginalState();
  26743. this._takeBackBinding(binding);
  26744. }
  26745. }
  26746. this._takeBackAction(action);
  26747. }
  26748. },
  26749. // Memory manager
  26750. _initMemoryManager: function _initMemoryManager() {
  26751. this._actions = []; // 'nActiveActions' followed by inactive ones
  26752. this._nActiveActions = 0;
  26753. this._actionsByClip = {}; // inside:
  26754. // {
  26755. // knownActions: Array< AnimationAction > - used as prototypes
  26756. // actionByRoot: AnimationAction - lookup
  26757. // }
  26758. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  26759. this._nActiveBindings = 0;
  26760. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  26761. this._controlInterpolants = []; // same game as above
  26762. this._nActiveControlInterpolants = 0;
  26763. var scope = this;
  26764. this.stats = {
  26765. actions: {
  26766. get total() {
  26767. return scope._actions.length;
  26768. },
  26769. get inUse() {
  26770. return scope._nActiveActions;
  26771. }
  26772. },
  26773. bindings: {
  26774. get total() {
  26775. return scope._bindings.length;
  26776. },
  26777. get inUse() {
  26778. return scope._nActiveBindings;
  26779. }
  26780. },
  26781. controlInterpolants: {
  26782. get total() {
  26783. return scope._controlInterpolants.length;
  26784. },
  26785. get inUse() {
  26786. return scope._nActiveControlInterpolants;
  26787. }
  26788. }
  26789. };
  26790. },
  26791. // Memory management for AnimationAction objects
  26792. _isActiveAction: function _isActiveAction(action) {
  26793. var index = action._cacheIndex;
  26794. return index !== null && index < this._nActiveActions;
  26795. },
  26796. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  26797. var actions = this._actions,
  26798. actionsByClip = this._actionsByClip;
  26799. var actionsForClip = actionsByClip[clipUuid];
  26800. if (actionsForClip === undefined) {
  26801. actionsForClip = {
  26802. knownActions: [action],
  26803. actionByRoot: {}
  26804. };
  26805. action._byClipCacheIndex = 0;
  26806. actionsByClip[clipUuid] = actionsForClip;
  26807. } else {
  26808. var knownActions = actionsForClip.knownActions;
  26809. action._byClipCacheIndex = knownActions.length;
  26810. knownActions.push(action);
  26811. }
  26812. action._cacheIndex = actions.length;
  26813. actions.push(action);
  26814. actionsForClip.actionByRoot[rootUuid] = action;
  26815. },
  26816. _removeInactiveAction: function _removeInactiveAction(action) {
  26817. var actions = this._actions,
  26818. lastInactiveAction = actions[actions.length - 1],
  26819. cacheIndex = action._cacheIndex;
  26820. lastInactiveAction._cacheIndex = cacheIndex;
  26821. actions[cacheIndex] = lastInactiveAction;
  26822. actions.pop();
  26823. action._cacheIndex = null;
  26824. var clipUuid = action._clip.uuid,
  26825. actionsByClip = this._actionsByClip,
  26826. actionsForClip = actionsByClip[clipUuid],
  26827. knownActionsForClip = actionsForClip.knownActions,
  26828. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  26829. byClipCacheIndex = action._byClipCacheIndex;
  26830. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26831. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  26832. knownActionsForClip.pop();
  26833. action._byClipCacheIndex = null;
  26834. var actionByRoot = actionsForClip.actionByRoot,
  26835. rootUuid = (action._localRoot || this._root).uuid;
  26836. delete actionByRoot[rootUuid];
  26837. if (knownActionsForClip.length === 0) {
  26838. delete actionsByClip[clipUuid];
  26839. }
  26840. this._removeInactiveBindingsForAction(action);
  26841. },
  26842. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  26843. var bindings = action._propertyBindings;
  26844. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26845. var binding = bindings[i];
  26846. if (--binding.referenceCount === 0) {
  26847. this._removeInactiveBinding(binding);
  26848. }
  26849. }
  26850. },
  26851. _lendAction: function _lendAction(action) {
  26852. // [ active actions | inactive actions ]
  26853. // [ active actions >| inactive actions ]
  26854. // s a
  26855. // <-swap->
  26856. // a s
  26857. var actions = this._actions,
  26858. prevIndex = action._cacheIndex,
  26859. lastActiveIndex = this._nActiveActions++,
  26860. firstInactiveAction = actions[lastActiveIndex];
  26861. action._cacheIndex = lastActiveIndex;
  26862. actions[lastActiveIndex] = action;
  26863. firstInactiveAction._cacheIndex = prevIndex;
  26864. actions[prevIndex] = firstInactiveAction;
  26865. },
  26866. _takeBackAction: function _takeBackAction(action) {
  26867. // [ active actions | inactive actions ]
  26868. // [ active actions |< inactive actions ]
  26869. // a s
  26870. // <-swap->
  26871. // s a
  26872. var actions = this._actions,
  26873. prevIndex = action._cacheIndex,
  26874. firstInactiveIndex = --this._nActiveActions,
  26875. lastActiveAction = actions[firstInactiveIndex];
  26876. action._cacheIndex = firstInactiveIndex;
  26877. actions[firstInactiveIndex] = action;
  26878. lastActiveAction._cacheIndex = prevIndex;
  26879. actions[prevIndex] = lastActiveAction;
  26880. },
  26881. // Memory management for PropertyMixer objects
  26882. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  26883. var bindingsByRoot = this._bindingsByRootAndName,
  26884. bindings = this._bindings;
  26885. var bindingByName = bindingsByRoot[rootUuid];
  26886. if (bindingByName === undefined) {
  26887. bindingByName = {};
  26888. bindingsByRoot[rootUuid] = bindingByName;
  26889. }
  26890. bindingByName[trackName] = binding;
  26891. binding._cacheIndex = bindings.length;
  26892. bindings.push(binding);
  26893. },
  26894. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  26895. var bindings = this._bindings,
  26896. propBinding = binding.binding,
  26897. rootUuid = propBinding.rootNode.uuid,
  26898. trackName = propBinding.path,
  26899. bindingsByRoot = this._bindingsByRootAndName,
  26900. bindingByName = bindingsByRoot[rootUuid],
  26901. lastInactiveBinding = bindings[bindings.length - 1],
  26902. cacheIndex = binding._cacheIndex;
  26903. lastInactiveBinding._cacheIndex = cacheIndex;
  26904. bindings[cacheIndex] = lastInactiveBinding;
  26905. bindings.pop();
  26906. delete bindingByName[trackName];
  26907. if (Object.keys(bindingByName).length === 0) {
  26908. delete bindingsByRoot[rootUuid];
  26909. }
  26910. },
  26911. _lendBinding: function _lendBinding(binding) {
  26912. var bindings = this._bindings,
  26913. prevIndex = binding._cacheIndex,
  26914. lastActiveIndex = this._nActiveBindings++,
  26915. firstInactiveBinding = bindings[lastActiveIndex];
  26916. binding._cacheIndex = lastActiveIndex;
  26917. bindings[lastActiveIndex] = binding;
  26918. firstInactiveBinding._cacheIndex = prevIndex;
  26919. bindings[prevIndex] = firstInactiveBinding;
  26920. },
  26921. _takeBackBinding: function _takeBackBinding(binding) {
  26922. var bindings = this._bindings,
  26923. prevIndex = binding._cacheIndex,
  26924. firstInactiveIndex = --this._nActiveBindings,
  26925. lastActiveBinding = bindings[firstInactiveIndex];
  26926. binding._cacheIndex = firstInactiveIndex;
  26927. bindings[firstInactiveIndex] = binding;
  26928. lastActiveBinding._cacheIndex = prevIndex;
  26929. bindings[prevIndex] = lastActiveBinding;
  26930. },
  26931. // Memory management of Interpolants for weight and time scale
  26932. _lendControlInterpolant: function _lendControlInterpolant() {
  26933. var interpolants = this._controlInterpolants,
  26934. lastActiveIndex = this._nActiveControlInterpolants++;
  26935. var interpolant = interpolants[lastActiveIndex];
  26936. if (interpolant === undefined) {
  26937. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  26938. interpolant.__cacheIndex = lastActiveIndex;
  26939. interpolants[lastActiveIndex] = interpolant;
  26940. }
  26941. return interpolant;
  26942. },
  26943. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  26944. var interpolants = this._controlInterpolants,
  26945. prevIndex = interpolant.__cacheIndex,
  26946. firstInactiveIndex = --this._nActiveControlInterpolants,
  26947. lastActiveInterpolant = interpolants[firstInactiveIndex];
  26948. interpolant.__cacheIndex = firstInactiveIndex;
  26949. interpolants[firstInactiveIndex] = interpolant;
  26950. lastActiveInterpolant.__cacheIndex = prevIndex;
  26951. interpolants[prevIndex] = lastActiveInterpolant;
  26952. },
  26953. _controlInterpolantsResultBuffer: new Float32Array(1),
  26954. // return an action for a clip optionally using a custom root target
  26955. // object (this method allocates a lot of dynamic memory in case a
  26956. // previously unknown clip/root combination is specified)
  26957. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  26958. var root = optionalRoot || this._root,
  26959. rootUuid = root.uuid;
  26960. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  26961. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  26962. var actionsForClip = this._actionsByClip[clipUuid];
  26963. var prototypeAction = null;
  26964. if (blendMode === undefined) {
  26965. if (clipObject !== null) {
  26966. blendMode = clipObject.blendMode;
  26967. } else {
  26968. blendMode = NormalAnimationBlendMode;
  26969. }
  26970. }
  26971. if (actionsForClip !== undefined) {
  26972. var existingAction = actionsForClip.actionByRoot[rootUuid];
  26973. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  26974. return existingAction;
  26975. } // we know the clip, so we don't have to parse all
  26976. // the bindings again but can just copy
  26977. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  26978. if (clipObject === null) clipObject = prototypeAction._clip;
  26979. } // clip must be known when specified via string
  26980. if (clipObject === null) return null; // allocate all resources required to run it
  26981. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  26982. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  26983. this._addInactiveAction(newAction, clipUuid, rootUuid);
  26984. return newAction;
  26985. },
  26986. // get an existing action
  26987. existingAction: function existingAction(clip, optionalRoot) {
  26988. var root = optionalRoot || this._root,
  26989. rootUuid = root.uuid,
  26990. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  26991. clipUuid = clipObject ? clipObject.uuid : clip,
  26992. actionsForClip = this._actionsByClip[clipUuid];
  26993. if (actionsForClip !== undefined) {
  26994. return actionsForClip.actionByRoot[rootUuid] || null;
  26995. }
  26996. return null;
  26997. },
  26998. // deactivates all previously scheduled actions
  26999. stopAllAction: function stopAllAction() {
  27000. var actions = this._actions,
  27001. nActions = this._nActiveActions;
  27002. for (var i = nActions - 1; i >= 0; --i) {
  27003. actions[i].stop();
  27004. }
  27005. return this;
  27006. },
  27007. // advance the time and update apply the animation
  27008. update: function update(deltaTime) {
  27009. deltaTime *= this.timeScale;
  27010. var actions = this._actions,
  27011. nActions = this._nActiveActions,
  27012. time = this.time += deltaTime,
  27013. timeDirection = Math.sign(deltaTime),
  27014. accuIndex = this._accuIndex ^= 1; // run active actions
  27015. for (var i = 0; i !== nActions; ++i) {
  27016. var action = actions[i];
  27017. action._update(time, deltaTime, timeDirection, accuIndex);
  27018. } // update scene graph
  27019. var bindings = this._bindings,
  27020. nBindings = this._nActiveBindings;
  27021. for (var _i = 0; _i !== nBindings; ++_i) {
  27022. bindings[_i].apply(accuIndex);
  27023. }
  27024. return this;
  27025. },
  27026. // Allows you to seek to a specific time in an animation.
  27027. setTime: function setTime(timeInSeconds) {
  27028. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27029. for (var i = 0; i < this._actions.length; i++) {
  27030. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27031. }
  27032. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27033. },
  27034. // return this mixer's root target object
  27035. getRoot: function getRoot() {
  27036. return this._root;
  27037. },
  27038. // free all resources specific to a particular clip
  27039. uncacheClip: function uncacheClip(clip) {
  27040. var actions = this._actions,
  27041. clipUuid = clip.uuid,
  27042. actionsByClip = this._actionsByClip,
  27043. actionsForClip = actionsByClip[clipUuid];
  27044. if (actionsForClip !== undefined) {
  27045. // note: just calling _removeInactiveAction would mess up the
  27046. // iteration state and also require updating the state we can
  27047. // just throw away
  27048. var actionsToRemove = actionsForClip.knownActions;
  27049. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27050. var action = actionsToRemove[i];
  27051. this._deactivateAction(action);
  27052. var cacheIndex = action._cacheIndex,
  27053. lastInactiveAction = actions[actions.length - 1];
  27054. action._cacheIndex = null;
  27055. action._byClipCacheIndex = null;
  27056. lastInactiveAction._cacheIndex = cacheIndex;
  27057. actions[cacheIndex] = lastInactiveAction;
  27058. actions.pop();
  27059. this._removeInactiveBindingsForAction(action);
  27060. }
  27061. delete actionsByClip[clipUuid];
  27062. }
  27063. },
  27064. // free all resources specific to a particular root target object
  27065. uncacheRoot: function uncacheRoot(root) {
  27066. var rootUuid = root.uuid,
  27067. actionsByClip = this._actionsByClip;
  27068. for (var clipUuid in actionsByClip) {
  27069. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27070. action = actionByRoot[rootUuid];
  27071. if (action !== undefined) {
  27072. this._deactivateAction(action);
  27073. this._removeInactiveAction(action);
  27074. }
  27075. }
  27076. var bindingsByRoot = this._bindingsByRootAndName,
  27077. bindingByName = bindingsByRoot[rootUuid];
  27078. if (bindingByName !== undefined) {
  27079. for (var trackName in bindingByName) {
  27080. var binding = bindingByName[trackName];
  27081. binding.restoreOriginalState();
  27082. this._removeInactiveBinding(binding);
  27083. }
  27084. }
  27085. },
  27086. // remove a targeted clip from the cache
  27087. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27088. var action = this.existingAction(clip, optionalRoot);
  27089. if (action !== null) {
  27090. this._deactivateAction(action);
  27091. this._removeInactiveAction(action);
  27092. }
  27093. }
  27094. });
  27095. var Uniform = /*#__PURE__*/function () {
  27096. function Uniform(value) {
  27097. if (typeof value === 'string') {
  27098. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27099. value = arguments[1];
  27100. }
  27101. this.value = value;
  27102. }
  27103. var _proto = Uniform.prototype;
  27104. _proto.clone = function clone() {
  27105. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27106. };
  27107. return Uniform;
  27108. }();
  27109. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27110. InterleavedBuffer.call(this, array, stride);
  27111. this.meshPerAttribute = meshPerAttribute || 1;
  27112. }
  27113. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27114. constructor: InstancedInterleavedBuffer,
  27115. isInstancedInterleavedBuffer: true,
  27116. copy: function copy(source) {
  27117. InterleavedBuffer.prototype.copy.call(this, source);
  27118. this.meshPerAttribute = source.meshPerAttribute;
  27119. return this;
  27120. },
  27121. clone: function clone(data) {
  27122. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27123. ib.meshPerAttribute = this.meshPerAttribute;
  27124. return ib;
  27125. },
  27126. toJSON: function toJSON(data) {
  27127. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27128. json.isInstancedInterleavedBuffer = true;
  27129. json.meshPerAttribute = this.meshPerAttribute;
  27130. return json;
  27131. }
  27132. });
  27133. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27134. this.buffer = buffer;
  27135. this.type = type;
  27136. this.itemSize = itemSize;
  27137. this.elementSize = elementSize;
  27138. this.count = count;
  27139. this.version = 0;
  27140. }
  27141. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27142. set: function set(value) {
  27143. if (value === true) this.version++;
  27144. }
  27145. });
  27146. Object.assign(GLBufferAttribute.prototype, {
  27147. isGLBufferAttribute: true,
  27148. setBuffer: function setBuffer(buffer) {
  27149. this.buffer = buffer;
  27150. return this;
  27151. },
  27152. setType: function setType(type, elementSize) {
  27153. this.type = type;
  27154. this.elementSize = elementSize;
  27155. return this;
  27156. },
  27157. setItemSize: function setItemSize(itemSize) {
  27158. this.itemSize = itemSize;
  27159. return this;
  27160. },
  27161. setCount: function setCount(count) {
  27162. this.count = count;
  27163. return this;
  27164. }
  27165. });
  27166. function Raycaster(origin, direction, near, far) {
  27167. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27168. this.near = near || 0;
  27169. this.far = far || Infinity;
  27170. this.camera = null;
  27171. this.layers = new Layers();
  27172. this.params = {
  27173. Mesh: {},
  27174. Line: {
  27175. threshold: 1
  27176. },
  27177. LOD: {},
  27178. Points: {
  27179. threshold: 1
  27180. },
  27181. Sprite: {}
  27182. };
  27183. Object.defineProperties(this.params, {
  27184. PointCloud: {
  27185. get: function get() {
  27186. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27187. return this.Points;
  27188. }
  27189. }
  27190. });
  27191. }
  27192. function ascSort(a, b) {
  27193. return a.distance - b.distance;
  27194. }
  27195. function _intersectObject(object, raycaster, intersects, recursive) {
  27196. if (object.layers.test(raycaster.layers)) {
  27197. object.raycast(raycaster, intersects);
  27198. }
  27199. if (recursive === true) {
  27200. var children = object.children;
  27201. for (var i = 0, l = children.length; i < l; i++) {
  27202. _intersectObject(children[i], raycaster, intersects, true);
  27203. }
  27204. }
  27205. }
  27206. Object.assign(Raycaster.prototype, {
  27207. set: function set(origin, direction) {
  27208. // direction is assumed to be normalized (for accurate distance calculations)
  27209. this.ray.set(origin, direction);
  27210. },
  27211. setFromCamera: function setFromCamera(coords, camera) {
  27212. if (camera && camera.isPerspectiveCamera) {
  27213. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27214. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27215. this.camera = camera;
  27216. } else if (camera && camera.isOrthographicCamera) {
  27217. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27218. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27219. this.camera = camera;
  27220. } else {
  27221. console.error('THREE.Raycaster: Unsupported camera type.');
  27222. }
  27223. },
  27224. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27225. var intersects = optionalTarget || [];
  27226. _intersectObject(object, this, intersects, recursive);
  27227. intersects.sort(ascSort);
  27228. return intersects;
  27229. },
  27230. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27231. var intersects = optionalTarget || [];
  27232. if (Array.isArray(objects) === false) {
  27233. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27234. return intersects;
  27235. }
  27236. for (var i = 0, l = objects.length; i < l; i++) {
  27237. _intersectObject(objects[i], this, intersects, recursive);
  27238. }
  27239. intersects.sort(ascSort);
  27240. return intersects;
  27241. }
  27242. });
  27243. /**
  27244. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27245. *
  27246. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27247. * The azimuthal angle (theta) is measured from the positive z-axis.
  27248. */
  27249. var Spherical = /*#__PURE__*/function () {
  27250. function Spherical(radius, phi, theta) {
  27251. if (radius === void 0) {
  27252. radius = 1;
  27253. }
  27254. if (phi === void 0) {
  27255. phi = 0;
  27256. }
  27257. if (theta === void 0) {
  27258. theta = 0;
  27259. }
  27260. this.radius = radius;
  27261. this.phi = phi; // polar angle
  27262. this.theta = theta; // azimuthal angle
  27263. return this;
  27264. }
  27265. var _proto = Spherical.prototype;
  27266. _proto.set = function set(radius, phi, theta) {
  27267. this.radius = radius;
  27268. this.phi = phi;
  27269. this.theta = theta;
  27270. return this;
  27271. };
  27272. _proto.clone = function clone() {
  27273. return new this.constructor().copy(this);
  27274. };
  27275. _proto.copy = function copy(other) {
  27276. this.radius = other.radius;
  27277. this.phi = other.phi;
  27278. this.theta = other.theta;
  27279. return this;
  27280. } // restrict phi to be betwee EPS and PI-EPS
  27281. ;
  27282. _proto.makeSafe = function makeSafe() {
  27283. var EPS = 0.000001;
  27284. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27285. return this;
  27286. };
  27287. _proto.setFromVector3 = function setFromVector3(v) {
  27288. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27289. };
  27290. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27291. this.radius = Math.sqrt(x * x + y * y + z * z);
  27292. if (this.radius === 0) {
  27293. this.theta = 0;
  27294. this.phi = 0;
  27295. } else {
  27296. this.theta = Math.atan2(x, z);
  27297. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27298. }
  27299. return this;
  27300. };
  27301. return Spherical;
  27302. }();
  27303. /**
  27304. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27305. */
  27306. var Cylindrical = /*#__PURE__*/function () {
  27307. function Cylindrical(radius, theta, y) {
  27308. this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27309. this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27310. this.y = y !== undefined ? y : 0; // height above the x-z plane
  27311. return this;
  27312. }
  27313. var _proto = Cylindrical.prototype;
  27314. _proto.set = function set(radius, theta, y) {
  27315. this.radius = radius;
  27316. this.theta = theta;
  27317. this.y = y;
  27318. return this;
  27319. };
  27320. _proto.clone = function clone() {
  27321. return new this.constructor().copy(this);
  27322. };
  27323. _proto.copy = function copy(other) {
  27324. this.radius = other.radius;
  27325. this.theta = other.theta;
  27326. this.y = other.y;
  27327. return this;
  27328. };
  27329. _proto.setFromVector3 = function setFromVector3(v) {
  27330. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27331. };
  27332. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27333. this.radius = Math.sqrt(x * x + z * z);
  27334. this.theta = Math.atan2(x, z);
  27335. this.y = y;
  27336. return this;
  27337. };
  27338. return Cylindrical;
  27339. }();
  27340. var _vector$7 = /*@__PURE__*/new Vector2();
  27341. var Box2 = /*#__PURE__*/function () {
  27342. function Box2(min, max) {
  27343. Object.defineProperty(this, 'isBox2', {
  27344. value: true
  27345. });
  27346. this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
  27347. this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
  27348. }
  27349. var _proto = Box2.prototype;
  27350. _proto.set = function set(min, max) {
  27351. this.min.copy(min);
  27352. this.max.copy(max);
  27353. return this;
  27354. };
  27355. _proto.setFromPoints = function setFromPoints(points) {
  27356. this.makeEmpty();
  27357. for (var i = 0, il = points.length; i < il; i++) {
  27358. this.expandByPoint(points[i]);
  27359. }
  27360. return this;
  27361. };
  27362. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  27363. var halfSize = _vector$7.copy(size).multiplyScalar(0.5);
  27364. this.min.copy(center).sub(halfSize);
  27365. this.max.copy(center).add(halfSize);
  27366. return this;
  27367. };
  27368. _proto.clone = function clone() {
  27369. return new this.constructor().copy(this);
  27370. };
  27371. _proto.copy = function copy(box) {
  27372. this.min.copy(box.min);
  27373. this.max.copy(box.max);
  27374. return this;
  27375. };
  27376. _proto.makeEmpty = function makeEmpty() {
  27377. this.min.x = this.min.y = +Infinity;
  27378. this.max.x = this.max.y = -Infinity;
  27379. return this;
  27380. };
  27381. _proto.isEmpty = function isEmpty() {
  27382. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27383. return this.max.x < this.min.x || this.max.y < this.min.y;
  27384. };
  27385. _proto.getCenter = function getCenter(target) {
  27386. if (target === undefined) {
  27387. console.warn('THREE.Box2: .getCenter() target is now required');
  27388. target = new Vector2();
  27389. }
  27390. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  27391. };
  27392. _proto.getSize = function getSize(target) {
  27393. if (target === undefined) {
  27394. console.warn('THREE.Box2: .getSize() target is now required');
  27395. target = new Vector2();
  27396. }
  27397. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  27398. };
  27399. _proto.expandByPoint = function expandByPoint(point) {
  27400. this.min.min(point);
  27401. this.max.max(point);
  27402. return this;
  27403. };
  27404. _proto.expandByVector = function expandByVector(vector) {
  27405. this.min.sub(vector);
  27406. this.max.add(vector);
  27407. return this;
  27408. };
  27409. _proto.expandByScalar = function expandByScalar(scalar) {
  27410. this.min.addScalar(-scalar);
  27411. this.max.addScalar(scalar);
  27412. return this;
  27413. };
  27414. _proto.containsPoint = function containsPoint(point) {
  27415. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  27416. };
  27417. _proto.containsBox = function containsBox(box) {
  27418. 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;
  27419. };
  27420. _proto.getParameter = function getParameter(point, target) {
  27421. // This can potentially have a divide by zero if the box
  27422. // has a size dimension of 0.
  27423. if (target === undefined) {
  27424. console.warn('THREE.Box2: .getParameter() target is now required');
  27425. target = new Vector2();
  27426. }
  27427. 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));
  27428. };
  27429. _proto.intersectsBox = function intersectsBox(box) {
  27430. // using 4 splitting planes to rule out intersections
  27431. 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;
  27432. };
  27433. _proto.clampPoint = function clampPoint(point, target) {
  27434. if (target === undefined) {
  27435. console.warn('THREE.Box2: .clampPoint() target is now required');
  27436. target = new Vector2();
  27437. }
  27438. return target.copy(point).clamp(this.min, this.max);
  27439. };
  27440. _proto.distanceToPoint = function distanceToPoint(point) {
  27441. var clampedPoint = _vector$7.copy(point).clamp(this.min, this.max);
  27442. return clampedPoint.sub(point).length();
  27443. };
  27444. _proto.intersect = function intersect(box) {
  27445. this.min.max(box.min);
  27446. this.max.min(box.max);
  27447. return this;
  27448. };
  27449. _proto.union = function union(box) {
  27450. this.min.min(box.min);
  27451. this.max.max(box.max);
  27452. return this;
  27453. };
  27454. _proto.translate = function translate(offset) {
  27455. this.min.add(offset);
  27456. this.max.add(offset);
  27457. return this;
  27458. };
  27459. _proto.equals = function equals(box) {
  27460. return box.min.equals(this.min) && box.max.equals(this.max);
  27461. };
  27462. return Box2;
  27463. }();
  27464. var _startP = /*@__PURE__*/new Vector3();
  27465. var _startEnd = /*@__PURE__*/new Vector3();
  27466. var Line3 = /*#__PURE__*/function () {
  27467. function Line3(start, end) {
  27468. this.start = start !== undefined ? start : new Vector3();
  27469. this.end = end !== undefined ? end : new Vector3();
  27470. }
  27471. var _proto = Line3.prototype;
  27472. _proto.set = function set(start, end) {
  27473. this.start.copy(start);
  27474. this.end.copy(end);
  27475. return this;
  27476. };
  27477. _proto.clone = function clone() {
  27478. return new this.constructor().copy(this);
  27479. };
  27480. _proto.copy = function copy(line) {
  27481. this.start.copy(line.start);
  27482. this.end.copy(line.end);
  27483. return this;
  27484. };
  27485. _proto.getCenter = function getCenter(target) {
  27486. if (target === undefined) {
  27487. console.warn('THREE.Line3: .getCenter() target is now required');
  27488. target = new Vector3();
  27489. }
  27490. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  27491. };
  27492. _proto.delta = function delta(target) {
  27493. if (target === undefined) {
  27494. console.warn('THREE.Line3: .delta() target is now required');
  27495. target = new Vector3();
  27496. }
  27497. return target.subVectors(this.end, this.start);
  27498. };
  27499. _proto.distanceSq = function distanceSq() {
  27500. return this.start.distanceToSquared(this.end);
  27501. };
  27502. _proto.distance = function distance() {
  27503. return this.start.distanceTo(this.end);
  27504. };
  27505. _proto.at = function at(t, target) {
  27506. if (target === undefined) {
  27507. console.warn('THREE.Line3: .at() target is now required');
  27508. target = new Vector3();
  27509. }
  27510. return this.delta(target).multiplyScalar(t).add(this.start);
  27511. };
  27512. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  27513. _startP.subVectors(point, this.start);
  27514. _startEnd.subVectors(this.end, this.start);
  27515. var startEnd2 = _startEnd.dot(_startEnd);
  27516. var startEnd_startP = _startEnd.dot(_startP);
  27517. var t = startEnd_startP / startEnd2;
  27518. if (clampToLine) {
  27519. t = MathUtils.clamp(t, 0, 1);
  27520. }
  27521. return t;
  27522. };
  27523. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  27524. var t = this.closestPointToPointParameter(point, clampToLine);
  27525. if (target === undefined) {
  27526. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  27527. target = new Vector3();
  27528. }
  27529. return this.delta(target).multiplyScalar(t).add(this.start);
  27530. };
  27531. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  27532. this.start.applyMatrix4(matrix);
  27533. this.end.applyMatrix4(matrix);
  27534. return this;
  27535. };
  27536. _proto.equals = function equals(line) {
  27537. return line.start.equals(this.start) && line.end.equals(this.end);
  27538. };
  27539. return Line3;
  27540. }();
  27541. function ImmediateRenderObject(material) {
  27542. Object3D.call(this);
  27543. this.material = material;
  27544. this.render = function ()
  27545. /* renderCallback */
  27546. {};
  27547. this.hasPositions = false;
  27548. this.hasNormals = false;
  27549. this.hasColors = false;
  27550. this.hasUvs = false;
  27551. this.positionArray = null;
  27552. this.normalArray = null;
  27553. this.colorArray = null;
  27554. this.uvArray = null;
  27555. this.count = 0;
  27556. }
  27557. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  27558. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27559. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27560. var _vector$8 = /*@__PURE__*/new Vector3();
  27561. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  27562. _inheritsLoose(SpotLightHelper, _Object3D);
  27563. function SpotLightHelper(light, color) {
  27564. var _this;
  27565. _this = _Object3D.call(this) || this;
  27566. _this.light = light;
  27567. _this.light.updateMatrixWorld();
  27568. _this.matrix = light.matrixWorld;
  27569. _this.matrixAutoUpdate = false;
  27570. _this.color = color;
  27571. var geometry = new BufferGeometry();
  27572. 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];
  27573. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  27574. var p1 = i / l * Math.PI * 2;
  27575. var p2 = j / l * Math.PI * 2;
  27576. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  27577. }
  27578. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  27579. var material = new LineBasicMaterial({
  27580. fog: false,
  27581. toneMapped: false
  27582. });
  27583. _this.cone = new LineSegments(geometry, material);
  27584. _this.add(_this.cone);
  27585. _this.update();
  27586. return _this;
  27587. }
  27588. var _proto = SpotLightHelper.prototype;
  27589. _proto.dispose = function dispose() {
  27590. this.cone.geometry.dispose();
  27591. this.cone.material.dispose();
  27592. };
  27593. _proto.update = function update() {
  27594. this.light.updateMatrixWorld();
  27595. var coneLength = this.light.distance ? this.light.distance : 1000;
  27596. var coneWidth = coneLength * Math.tan(this.light.angle);
  27597. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  27598. _vector$8.setFromMatrixPosition(this.light.target.matrixWorld);
  27599. this.cone.lookAt(_vector$8);
  27600. if (this.color !== undefined) {
  27601. this.cone.material.color.set(this.color);
  27602. } else {
  27603. this.cone.material.color.copy(this.light.color);
  27604. }
  27605. };
  27606. return SpotLightHelper;
  27607. }(Object3D);
  27608. var _vector$9 = /*@__PURE__*/new Vector3();
  27609. var _boneMatrix = /*@__PURE__*/new Matrix4();
  27610. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  27611. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  27612. _inheritsLoose(SkeletonHelper, _LineSegments);
  27613. function SkeletonHelper(object) {
  27614. var _this;
  27615. var bones = getBoneList(object);
  27616. var geometry = new BufferGeometry();
  27617. var vertices = [];
  27618. var colors = [];
  27619. var color1 = new Color(0, 0, 1);
  27620. var color2 = new Color(0, 1, 0);
  27621. for (var i = 0; i < bones.length; i++) {
  27622. var bone = bones[i];
  27623. if (bone.parent && bone.parent.isBone) {
  27624. vertices.push(0, 0, 0);
  27625. vertices.push(0, 0, 0);
  27626. colors.push(color1.r, color1.g, color1.b);
  27627. colors.push(color2.r, color2.g, color2.b);
  27628. }
  27629. }
  27630. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27631. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27632. var material = new LineBasicMaterial({
  27633. vertexColors: true,
  27634. depthTest: false,
  27635. depthWrite: false,
  27636. toneMapped: false,
  27637. transparent: true
  27638. });
  27639. _this = _LineSegments.call(this, geometry, material) || this;
  27640. _this.type = 'SkeletonHelper';
  27641. _this.isSkeletonHelper = true;
  27642. _this.root = object;
  27643. _this.bones = bones;
  27644. _this.matrix = object.matrixWorld;
  27645. _this.matrixAutoUpdate = false;
  27646. return _this;
  27647. }
  27648. var _proto = SkeletonHelper.prototype;
  27649. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  27650. var bones = this.bones;
  27651. var geometry = this.geometry;
  27652. var position = geometry.getAttribute('position');
  27653. _matrixWorldInv.getInverse(this.root.matrixWorld);
  27654. for (var i = 0, j = 0; i < bones.length; i++) {
  27655. var bone = bones[i];
  27656. if (bone.parent && bone.parent.isBone) {
  27657. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  27658. _vector$9.setFromMatrixPosition(_boneMatrix);
  27659. position.setXYZ(j, _vector$9.x, _vector$9.y, _vector$9.z);
  27660. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  27661. _vector$9.setFromMatrixPosition(_boneMatrix);
  27662. position.setXYZ(j + 1, _vector$9.x, _vector$9.y, _vector$9.z);
  27663. j += 2;
  27664. }
  27665. }
  27666. geometry.getAttribute('position').needsUpdate = true;
  27667. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  27668. };
  27669. return SkeletonHelper;
  27670. }(LineSegments);
  27671. function getBoneList(object) {
  27672. var boneList = [];
  27673. if (object && object.isBone) {
  27674. boneList.push(object);
  27675. }
  27676. for (var i = 0; i < object.children.length; i++) {
  27677. boneList.push.apply(boneList, getBoneList(object.children[i]));
  27678. }
  27679. return boneList;
  27680. }
  27681. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  27682. _inheritsLoose(PointLightHelper, _Mesh);
  27683. function PointLightHelper(light, sphereSize, color) {
  27684. var _this;
  27685. var geometry = new SphereBufferGeometry(sphereSize, 4, 2);
  27686. var material = new MeshBasicMaterial({
  27687. wireframe: true,
  27688. fog: false,
  27689. toneMapped: false
  27690. });
  27691. _this = _Mesh.call(this, geometry, material) || this;
  27692. _this.light = light;
  27693. _this.light.updateMatrixWorld();
  27694. _this.color = color;
  27695. _this.type = 'PointLightHelper';
  27696. _this.matrix = _this.light.matrixWorld;
  27697. _this.matrixAutoUpdate = false;
  27698. _this.update();
  27699. /*
  27700. // TODO: delete this comment?
  27701. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27702. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27703. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27704. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27705. const d = light.distance;
  27706. if ( d === 0.0 ) {
  27707. this.lightDistance.visible = false;
  27708. } else {
  27709. this.lightDistance.scale.set( d, d, d );
  27710. }
  27711. this.add( this.lightDistance );
  27712. */
  27713. return _this;
  27714. }
  27715. var _proto = PointLightHelper.prototype;
  27716. _proto.dispose = function dispose() {
  27717. this.geometry.dispose();
  27718. this.material.dispose();
  27719. };
  27720. _proto.update = function update() {
  27721. if (this.color !== undefined) {
  27722. this.material.color.set(this.color);
  27723. } else {
  27724. this.material.color.copy(this.light.color);
  27725. }
  27726. /*
  27727. const d = this.light.distance;
  27728. if ( d === 0.0 ) {
  27729. this.lightDistance.visible = false;
  27730. } else {
  27731. this.lightDistance.visible = true;
  27732. this.lightDistance.scale.set( d, d, d );
  27733. }
  27734. */
  27735. };
  27736. return PointLightHelper;
  27737. }(Mesh);
  27738. var _vector$a = /*@__PURE__*/new Vector3();
  27739. var _color1 = /*@__PURE__*/new Color();
  27740. var _color2 = /*@__PURE__*/new Color();
  27741. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  27742. _inheritsLoose(HemisphereLightHelper, _Object3D);
  27743. function HemisphereLightHelper(light, size, color) {
  27744. var _this;
  27745. _this = _Object3D.call(this) || this;
  27746. _this.light = light;
  27747. _this.light.updateMatrixWorld();
  27748. _this.matrix = light.matrixWorld;
  27749. _this.matrixAutoUpdate = false;
  27750. _this.color = color;
  27751. var geometry = new OctahedronBufferGeometry(size);
  27752. geometry.rotateY(Math.PI * 0.5);
  27753. _this.material = new MeshBasicMaterial({
  27754. wireframe: true,
  27755. fog: false,
  27756. toneMapped: false
  27757. });
  27758. if (_this.color === undefined) _this.material.vertexColors = true;
  27759. var position = geometry.getAttribute('position');
  27760. var colors = new Float32Array(position.count * 3);
  27761. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  27762. _this.add(new Mesh(geometry, _this.material));
  27763. _this.update();
  27764. return _this;
  27765. }
  27766. var _proto = HemisphereLightHelper.prototype;
  27767. _proto.dispose = function dispose() {
  27768. this.children[0].geometry.dispose();
  27769. this.children[0].material.dispose();
  27770. };
  27771. _proto.update = function update() {
  27772. var mesh = this.children[0];
  27773. if (this.color !== undefined) {
  27774. this.material.color.set(this.color);
  27775. } else {
  27776. var colors = mesh.geometry.getAttribute('color');
  27777. _color1.copy(this.light.color);
  27778. _color2.copy(this.light.groundColor);
  27779. for (var i = 0, l = colors.count; i < l; i++) {
  27780. var color = i < l / 2 ? _color1 : _color2;
  27781. colors.setXYZ(i, color.r, color.g, color.b);
  27782. }
  27783. colors.needsUpdate = true;
  27784. }
  27785. mesh.lookAt(_vector$a.setFromMatrixPosition(this.light.matrixWorld).negate());
  27786. };
  27787. return HemisphereLightHelper;
  27788. }(Object3D);
  27789. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  27790. _inheritsLoose(GridHelper, _LineSegments);
  27791. function GridHelper(size, divisions, color1, color2) {
  27792. var _this;
  27793. size = size || 10;
  27794. divisions = divisions || 10;
  27795. color1 = new Color(color1 !== undefined ? color1 : 0x444444);
  27796. color2 = new Color(color2 !== undefined ? color2 : 0x888888);
  27797. var center = divisions / 2;
  27798. var step = size / divisions;
  27799. var halfSize = size / 2;
  27800. var vertices = [],
  27801. colors = [];
  27802. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  27803. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  27804. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  27805. var color = i === center ? color1 : color2;
  27806. color.toArray(colors, j);
  27807. j += 3;
  27808. color.toArray(colors, j);
  27809. j += 3;
  27810. color.toArray(colors, j);
  27811. j += 3;
  27812. color.toArray(colors, j);
  27813. j += 3;
  27814. }
  27815. var geometry = new BufferGeometry();
  27816. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27817. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27818. var material = new LineBasicMaterial({
  27819. vertexColors: true,
  27820. toneMapped: false
  27821. });
  27822. _this = _LineSegments.call(this, geometry, material) || this;
  27823. _this.type = 'GridHelper';
  27824. return _this;
  27825. }
  27826. return GridHelper;
  27827. }(LineSegments);
  27828. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  27829. _inheritsLoose(PolarGridHelper, _LineSegments);
  27830. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  27831. var _this;
  27832. radius = radius || 10;
  27833. radials = radials || 16;
  27834. circles = circles || 8;
  27835. divisions = divisions || 64;
  27836. color1 = new Color(color1 !== undefined ? color1 : 0x444444);
  27837. color2 = new Color(color2 !== undefined ? color2 : 0x888888);
  27838. var vertices = [];
  27839. var colors = []; // create the radials
  27840. for (var i = 0; i <= radials; i++) {
  27841. var v = i / radials * (Math.PI * 2);
  27842. var x = Math.sin(v) * radius;
  27843. var z = Math.cos(v) * radius;
  27844. vertices.push(0, 0, 0);
  27845. vertices.push(x, 0, z);
  27846. var color = i & 1 ? color1 : color2;
  27847. colors.push(color.r, color.g, color.b);
  27848. colors.push(color.r, color.g, color.b);
  27849. } // create the circles
  27850. for (var _i = 0; _i <= circles; _i++) {
  27851. var _color = _i & 1 ? color1 : color2;
  27852. var r = radius - radius / circles * _i;
  27853. for (var j = 0; j < divisions; j++) {
  27854. // first vertex
  27855. var _v = j / divisions * (Math.PI * 2);
  27856. var _x = Math.sin(_v) * r;
  27857. var _z = Math.cos(_v) * r;
  27858. vertices.push(_x, 0, _z);
  27859. colors.push(_color.r, _color.g, _color.b); // second vertex
  27860. _v = (j + 1) / divisions * (Math.PI * 2);
  27861. _x = Math.sin(_v) * r;
  27862. _z = Math.cos(_v) * r;
  27863. vertices.push(_x, 0, _z);
  27864. colors.push(_color.r, _color.g, _color.b);
  27865. }
  27866. }
  27867. var geometry = new BufferGeometry();
  27868. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27869. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27870. var material = new LineBasicMaterial({
  27871. vertexColors: true,
  27872. toneMapped: false
  27873. });
  27874. _this = _LineSegments.call(this, geometry, material) || this;
  27875. _this.type = 'PolarGridHelper';
  27876. return _this;
  27877. }
  27878. return PolarGridHelper;
  27879. }(LineSegments);
  27880. var _v1$6 = /*@__PURE__*/new Vector3();
  27881. var _v2$3 = /*@__PURE__*/new Vector3();
  27882. var _v3$1 = /*@__PURE__*/new Vector3();
  27883. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  27884. _inheritsLoose(DirectionalLightHelper, _Object3D);
  27885. function DirectionalLightHelper(light, size, color) {
  27886. var _this;
  27887. _this = _Object3D.call(this) || this;
  27888. _this.light = light;
  27889. _this.light.updateMatrixWorld();
  27890. _this.matrix = light.matrixWorld;
  27891. _this.matrixAutoUpdate = false;
  27892. _this.color = color;
  27893. if (size === undefined) size = 1;
  27894. var geometry = new BufferGeometry();
  27895. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  27896. var material = new LineBasicMaterial({
  27897. fog: false,
  27898. toneMapped: false
  27899. });
  27900. _this.lightPlane = new Line(geometry, material);
  27901. _this.add(_this.lightPlane);
  27902. geometry = new BufferGeometry();
  27903. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  27904. _this.targetLine = new Line(geometry, material);
  27905. _this.add(_this.targetLine);
  27906. _this.update();
  27907. return _this;
  27908. }
  27909. var _proto = DirectionalLightHelper.prototype;
  27910. _proto.dispose = function dispose() {
  27911. this.lightPlane.geometry.dispose();
  27912. this.lightPlane.material.dispose();
  27913. this.targetLine.geometry.dispose();
  27914. this.targetLine.material.dispose();
  27915. };
  27916. _proto.update = function update() {
  27917. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  27918. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  27919. _v3$1.subVectors(_v2$3, _v1$6);
  27920. this.lightPlane.lookAt(_v2$3);
  27921. if (this.color !== undefined) {
  27922. this.lightPlane.material.color.set(this.color);
  27923. this.targetLine.material.color.set(this.color);
  27924. } else {
  27925. this.lightPlane.material.color.copy(this.light.color);
  27926. this.targetLine.material.color.copy(this.light.color);
  27927. }
  27928. this.targetLine.lookAt(_v2$3);
  27929. this.targetLine.scale.z = _v3$1.length();
  27930. };
  27931. return DirectionalLightHelper;
  27932. }(Object3D);
  27933. var _vector$b = /*@__PURE__*/new Vector3();
  27934. var _camera = /*@__PURE__*/new Camera();
  27935. /**
  27936. * - shows frustum, line of sight and up of the camera
  27937. * - suitable for fast updates
  27938. * - based on frustum visualization in lightgl.js shadowmap example
  27939. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  27940. */
  27941. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  27942. _inheritsLoose(CameraHelper, _LineSegments);
  27943. function CameraHelper(camera) {
  27944. var _this;
  27945. var geometry = new BufferGeometry();
  27946. var material = new LineBasicMaterial({
  27947. color: 0xffffff,
  27948. vertexColors: true,
  27949. toneMapped: false
  27950. });
  27951. var vertices = [];
  27952. var colors = [];
  27953. var pointMap = {}; // colors
  27954. var colorFrustum = new Color(0xffaa00);
  27955. var colorCone = new Color(0xff0000);
  27956. var colorUp = new Color(0x00aaff);
  27957. var colorTarget = new Color(0xffffff);
  27958. var colorCross = new Color(0x333333); // near
  27959. addLine('n1', 'n2', colorFrustum);
  27960. addLine('n2', 'n4', colorFrustum);
  27961. addLine('n4', 'n3', colorFrustum);
  27962. addLine('n3', 'n1', colorFrustum); // far
  27963. addLine('f1', 'f2', colorFrustum);
  27964. addLine('f2', 'f4', colorFrustum);
  27965. addLine('f4', 'f3', colorFrustum);
  27966. addLine('f3', 'f1', colorFrustum); // sides
  27967. addLine('n1', 'f1', colorFrustum);
  27968. addLine('n2', 'f2', colorFrustum);
  27969. addLine('n3', 'f3', colorFrustum);
  27970. addLine('n4', 'f4', colorFrustum); // cone
  27971. addLine('p', 'n1', colorCone);
  27972. addLine('p', 'n2', colorCone);
  27973. addLine('p', 'n3', colorCone);
  27974. addLine('p', 'n4', colorCone); // up
  27975. addLine('u1', 'u2', colorUp);
  27976. addLine('u2', 'u3', colorUp);
  27977. addLine('u3', 'u1', colorUp); // target
  27978. addLine('c', 't', colorTarget);
  27979. addLine('p', 'c', colorCross); // cross
  27980. addLine('cn1', 'cn2', colorCross);
  27981. addLine('cn3', 'cn4', colorCross);
  27982. addLine('cf1', 'cf2', colorCross);
  27983. addLine('cf3', 'cf4', colorCross);
  27984. function addLine(a, b, color) {
  27985. addPoint(a, color);
  27986. addPoint(b, color);
  27987. }
  27988. function addPoint(id, color) {
  27989. vertices.push(0, 0, 0);
  27990. colors.push(color.r, color.g, color.b);
  27991. if (pointMap[id] === undefined) {
  27992. pointMap[id] = [];
  27993. }
  27994. pointMap[id].push(vertices.length / 3 - 1);
  27995. }
  27996. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27997. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27998. _this = _LineSegments.call(this, geometry, material) || this;
  27999. _this.type = 'CameraHelper';
  28000. _this.camera = camera;
  28001. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28002. _this.matrix = camera.matrixWorld;
  28003. _this.matrixAutoUpdate = false;
  28004. _this.pointMap = pointMap;
  28005. _this.update();
  28006. return _this;
  28007. }
  28008. var _proto = CameraHelper.prototype;
  28009. _proto.update = function update() {
  28010. var geometry = this.geometry;
  28011. var pointMap = this.pointMap;
  28012. var w = 1,
  28013. h = 1; // we need just camera projection matrix inverse
  28014. // world matrix must be identity
  28015. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28016. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28017. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28018. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28019. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28020. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28021. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28022. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28023. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28024. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28025. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28026. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28027. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28028. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28029. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28030. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28031. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28032. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28033. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28034. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28035. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28036. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28037. geometry.getAttribute('position').needsUpdate = true;
  28038. };
  28039. return CameraHelper;
  28040. }(LineSegments);
  28041. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28042. _vector$b.set(x, y, z).unproject(camera);
  28043. var points = pointMap[point];
  28044. if (points !== undefined) {
  28045. var position = geometry.getAttribute('position');
  28046. for (var i = 0, l = points.length; i < l; i++) {
  28047. position.setXYZ(points[i], _vector$b.x, _vector$b.y, _vector$b.z);
  28048. }
  28049. }
  28050. }
  28051. var _box$3 = /*@__PURE__*/new Box3();
  28052. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28053. _inheritsLoose(BoxHelper, _LineSegments);
  28054. function BoxHelper(object, color) {
  28055. var _this;
  28056. if (color === void 0) {
  28057. color = 0xffff00;
  28058. }
  28059. 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]);
  28060. var positions = new Float32Array(8 * 3);
  28061. var geometry = new BufferGeometry();
  28062. geometry.setIndex(new BufferAttribute(indices, 1));
  28063. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28064. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28065. color: color,
  28066. toneMapped: false
  28067. })) || this;
  28068. _this.object = object;
  28069. _this.type = 'BoxHelper';
  28070. _this.matrixAutoUpdate = false;
  28071. _this.update();
  28072. return _this;
  28073. }
  28074. var _proto = BoxHelper.prototype;
  28075. _proto.update = function update(object) {
  28076. if (object !== undefined) {
  28077. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28078. }
  28079. if (this.object !== undefined) {
  28080. _box$3.setFromObject(this.object);
  28081. }
  28082. if (_box$3.isEmpty()) return;
  28083. var min = _box$3.min;
  28084. var max = _box$3.max;
  28085. /*
  28086. 5____4
  28087. 1/___0/|
  28088. | 6__|_7
  28089. 2/___3/
  28090. 0: max.x, max.y, max.z
  28091. 1: min.x, max.y, max.z
  28092. 2: min.x, min.y, max.z
  28093. 3: max.x, min.y, max.z
  28094. 4: max.x, max.y, min.z
  28095. 5: min.x, max.y, min.z
  28096. 6: min.x, min.y, min.z
  28097. 7: max.x, min.y, min.z
  28098. */
  28099. var position = this.geometry.attributes.position;
  28100. var array = position.array;
  28101. array[0] = max.x;
  28102. array[1] = max.y;
  28103. array[2] = max.z;
  28104. array[3] = min.x;
  28105. array[4] = max.y;
  28106. array[5] = max.z;
  28107. array[6] = min.x;
  28108. array[7] = min.y;
  28109. array[8] = max.z;
  28110. array[9] = max.x;
  28111. array[10] = min.y;
  28112. array[11] = max.z;
  28113. array[12] = max.x;
  28114. array[13] = max.y;
  28115. array[14] = min.z;
  28116. array[15] = min.x;
  28117. array[16] = max.y;
  28118. array[17] = min.z;
  28119. array[18] = min.x;
  28120. array[19] = min.y;
  28121. array[20] = min.z;
  28122. array[21] = max.x;
  28123. array[22] = min.y;
  28124. array[23] = min.z;
  28125. position.needsUpdate = true;
  28126. this.geometry.computeBoundingSphere();
  28127. };
  28128. _proto.setFromObject = function setFromObject(object) {
  28129. this.object = object;
  28130. this.update();
  28131. return this;
  28132. };
  28133. _proto.copy = function copy(source) {
  28134. LineSegments.prototype.copy.call(this, source);
  28135. this.object = source.object;
  28136. return this;
  28137. };
  28138. return BoxHelper;
  28139. }(LineSegments);
  28140. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28141. _inheritsLoose(Box3Helper, _LineSegments);
  28142. function Box3Helper(box, color) {
  28143. var _this;
  28144. if (color === void 0) {
  28145. color = 0xffff00;
  28146. }
  28147. 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]);
  28148. 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];
  28149. var geometry = new BufferGeometry();
  28150. geometry.setIndex(new BufferAttribute(indices, 1));
  28151. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28152. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28153. color: color,
  28154. toneMapped: false
  28155. })) || this;
  28156. _this.box = box;
  28157. _this.type = 'Box3Helper';
  28158. _this.geometry.computeBoundingSphere();
  28159. return _this;
  28160. }
  28161. var _proto = Box3Helper.prototype;
  28162. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28163. var box = this.box;
  28164. if (box.isEmpty()) return;
  28165. box.getCenter(this.position);
  28166. box.getSize(this.scale);
  28167. this.scale.multiplyScalar(0.5);
  28168. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28169. };
  28170. return Box3Helper;
  28171. }(LineSegments);
  28172. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28173. _inheritsLoose(PlaneHelper, _Line);
  28174. function PlaneHelper(plane, size, hex) {
  28175. var _this;
  28176. var color = hex !== undefined ? hex : 0xffff00;
  28177. 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];
  28178. var geometry = new BufferGeometry();
  28179. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28180. geometry.computeBoundingSphere();
  28181. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28182. color: color,
  28183. toneMapped: false
  28184. })) || this;
  28185. _this.type = 'PlaneHelper';
  28186. _this.plane = plane;
  28187. _this.size = size === undefined ? 1 : size;
  28188. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28189. var geometry2 = new BufferGeometry();
  28190. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28191. geometry2.computeBoundingSphere();
  28192. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28193. color: color,
  28194. opacity: 0.2,
  28195. transparent: true,
  28196. depthWrite: false,
  28197. toneMapped: false
  28198. })));
  28199. return _this;
  28200. }
  28201. var _proto = PlaneHelper.prototype;
  28202. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28203. var scale = -this.plane.constant;
  28204. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28205. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28206. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28207. this.lookAt(this.plane.normal);
  28208. _Line.prototype.updateMatrixWorld.call(this, force);
  28209. };
  28210. return PlaneHelper;
  28211. }(Line);
  28212. var _axis = /*@__PURE__*/new Vector3();
  28213. var _lineGeometry, _coneGeometry;
  28214. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28215. _inheritsLoose(ArrowHelper, _Object3D);
  28216. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28217. var _this;
  28218. _this = _Object3D.call(this) || this; // dir is assumed to be normalized
  28219. _this.type = 'ArrowHelper';
  28220. if (dir === undefined) dir = new Vector3(0, 0, 1);
  28221. if (origin === undefined) origin = new Vector3(0, 0, 0);
  28222. if (length === undefined) length = 1;
  28223. if (color === undefined) color = 0xffff00;
  28224. if (headLength === undefined) headLength = 0.2 * length;
  28225. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28226. if (_lineGeometry === undefined) {
  28227. _lineGeometry = new BufferGeometry();
  28228. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28229. _coneGeometry = new CylinderBufferGeometry(0, 0.5, 1, 5, 1);
  28230. _coneGeometry.translate(0, -0.5, 0);
  28231. }
  28232. _this.position.copy(origin);
  28233. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28234. color: color,
  28235. toneMapped: false
  28236. }));
  28237. _this.line.matrixAutoUpdate = false;
  28238. _this.add(_this.line);
  28239. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28240. color: color,
  28241. toneMapped: false
  28242. }));
  28243. _this.cone.matrixAutoUpdate = false;
  28244. _this.add(_this.cone);
  28245. _this.setDirection(dir);
  28246. _this.setLength(length, headLength, headWidth);
  28247. return _this;
  28248. }
  28249. var _proto = ArrowHelper.prototype;
  28250. _proto.setDirection = function setDirection(dir) {
  28251. // dir is assumed to be normalized
  28252. if (dir.y > 0.99999) {
  28253. this.quaternion.set(0, 0, 0, 1);
  28254. } else if (dir.y < -0.99999) {
  28255. this.quaternion.set(1, 0, 0, 0);
  28256. } else {
  28257. _axis.set(dir.z, 0, -dir.x).normalize();
  28258. var radians = Math.acos(dir.y);
  28259. this.quaternion.setFromAxisAngle(_axis, radians);
  28260. }
  28261. };
  28262. _proto.setLength = function setLength(length, headLength, headWidth) {
  28263. if (headLength === undefined) headLength = 0.2 * length;
  28264. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28265. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28266. this.line.updateMatrix();
  28267. this.cone.scale.set(headWidth, headLength, headWidth);
  28268. this.cone.position.y = length;
  28269. this.cone.updateMatrix();
  28270. };
  28271. _proto.setColor = function setColor(color) {
  28272. this.line.material.color.set(color);
  28273. this.cone.material.color.set(color);
  28274. };
  28275. _proto.copy = function copy(source) {
  28276. _Object3D.prototype.copy.call(this, source, false);
  28277. this.line.copy(source.line);
  28278. this.cone.copy(source.cone);
  28279. return this;
  28280. };
  28281. return ArrowHelper;
  28282. }(Object3D);
  28283. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  28284. _inheritsLoose(AxesHelper, _LineSegments);
  28285. function AxesHelper(size) {
  28286. var _this;
  28287. if (size === void 0) {
  28288. size = 1;
  28289. }
  28290. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  28291. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  28292. var geometry = new BufferGeometry();
  28293. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28294. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28295. var material = new LineBasicMaterial({
  28296. vertexColors: true,
  28297. toneMapped: false
  28298. });
  28299. _this = _LineSegments.call(this, geometry, material) || this;
  28300. _this.type = 'AxesHelper';
  28301. return _this;
  28302. }
  28303. return AxesHelper;
  28304. }(LineSegments);
  28305. var _ENCODINGS;
  28306. var LOD_MIN = 4;
  28307. var LOD_MAX = 8;
  28308. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  28309. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28310. // geometric shadowing function. These sigma values squared must match the
  28311. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28312. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  28313. 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
  28314. // samples and exit early, but not recompile the shader.
  28315. var MAX_SAMPLES = 20;
  28316. 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);
  28317. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  28318. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  28319. _lodPlanes = _createPlanes2._lodPlanes,
  28320. _sizeLods = _createPlanes2._sizeLods,
  28321. _sigmas = _createPlanes2._sigmas;
  28322. var _oldTarget = null; // Golden Ratio
  28323. var PHI = (1 + Math.sqrt(5)) / 2;
  28324. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  28325. // same axis), used as axis directions evenly spread on a sphere.
  28326. 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)];
  28327. /**
  28328. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28329. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28330. * blur to be quickly accessed based on material roughness. It is packed into a
  28331. * special CubeUV format that allows us to perform custom interpolation so that
  28332. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28333. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28334. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28335. * higher roughness levels. In this way we maintain resolution to smoothly
  28336. * interpolate diffuse lighting while limiting sampling computation.
  28337. */
  28338. var PMREMGenerator = /*#__PURE__*/function () {
  28339. function PMREMGenerator(renderer) {
  28340. this._renderer = renderer;
  28341. this._pingPongRenderTarget = null;
  28342. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  28343. this._equirectShader = null;
  28344. this._cubemapShader = null;
  28345. this._compileMaterial(this._blurMaterial);
  28346. }
  28347. /**
  28348. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28349. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28350. * in radians to be applied to the scene before PMREM generation. Optional near
  28351. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28352. * is placed at the origin).
  28353. */
  28354. var _proto = PMREMGenerator.prototype;
  28355. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  28356. if (sigma === void 0) {
  28357. sigma = 0;
  28358. }
  28359. if (near === void 0) {
  28360. near = 0.1;
  28361. }
  28362. if (far === void 0) {
  28363. far = 100;
  28364. }
  28365. _oldTarget = this._renderer.getRenderTarget();
  28366. var cubeUVRenderTarget = this._allocateTargets();
  28367. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  28368. if (sigma > 0) {
  28369. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  28370. }
  28371. this._applyPMREM(cubeUVRenderTarget);
  28372. this._cleanup(cubeUVRenderTarget);
  28373. return cubeUVRenderTarget;
  28374. }
  28375. /**
  28376. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28377. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28378. * as this matches best with the 256 x 256 cubemap output.
  28379. */
  28380. ;
  28381. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  28382. return this._fromTexture(equirectangular);
  28383. }
  28384. /**
  28385. * Generates a PMREM from an cubemap texture, which can be either LDR
  28386. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28387. * as this matches best with the 256 x 256 cubemap output.
  28388. */
  28389. ;
  28390. _proto.fromCubemap = function fromCubemap(cubemap) {
  28391. return this._fromTexture(cubemap);
  28392. }
  28393. /**
  28394. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28395. * your texture's network fetch for increased concurrency.
  28396. */
  28397. ;
  28398. _proto.compileCubemapShader = function compileCubemapShader() {
  28399. if (this._cubemapShader === null) {
  28400. this._cubemapShader = _getCubemapShader();
  28401. this._compileMaterial(this._cubemapShader);
  28402. }
  28403. }
  28404. /**
  28405. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28406. * your texture's network fetch for increased concurrency.
  28407. */
  28408. ;
  28409. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  28410. if (this._equirectShader === null) {
  28411. this._equirectShader = _getEquirectShader();
  28412. this._compileMaterial(this._equirectShader);
  28413. }
  28414. }
  28415. /**
  28416. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  28417. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  28418. * one of them will cause any others to also become unusable.
  28419. */
  28420. ;
  28421. _proto.dispose = function dispose() {
  28422. this._blurMaterial.dispose();
  28423. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  28424. if (this._equirectShader !== null) this._equirectShader.dispose();
  28425. for (var i = 0; i < _lodPlanes.length; i++) {
  28426. _lodPlanes[i].dispose();
  28427. }
  28428. } // private interface
  28429. ;
  28430. _proto._cleanup = function _cleanup(outputTarget) {
  28431. this._pingPongRenderTarget.dispose();
  28432. this._renderer.setRenderTarget(_oldTarget);
  28433. outputTarget.scissorTest = false;
  28434. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  28435. };
  28436. _proto._fromTexture = function _fromTexture(texture) {
  28437. _oldTarget = this._renderer.getRenderTarget();
  28438. var cubeUVRenderTarget = this._allocateTargets(texture);
  28439. this._textureToCubeUV(texture, cubeUVRenderTarget);
  28440. this._applyPMREM(cubeUVRenderTarget);
  28441. this._cleanup(cubeUVRenderTarget);
  28442. return cubeUVRenderTarget;
  28443. };
  28444. _proto._allocateTargets = function _allocateTargets(texture) {
  28445. // warning: null texture is valid
  28446. var params = {
  28447. magFilter: NearestFilter,
  28448. minFilter: NearestFilter,
  28449. generateMipmaps: false,
  28450. type: UnsignedByteType,
  28451. format: RGBEFormat,
  28452. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  28453. depthBuffer: false
  28454. };
  28455. var cubeUVRenderTarget = _createRenderTarget(params);
  28456. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  28457. this._pingPongRenderTarget = _createRenderTarget(params);
  28458. return cubeUVRenderTarget;
  28459. };
  28460. _proto._compileMaterial = function _compileMaterial(material) {
  28461. var tmpMesh = new Mesh(_lodPlanes[0], material);
  28462. this._renderer.compile(tmpMesh, _flatCamera);
  28463. };
  28464. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  28465. var fov = 90;
  28466. var aspect = 1;
  28467. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  28468. var upSign = [1, -1, 1, 1, 1, 1];
  28469. var forwardSign = [1, 1, 1, -1, -1, -1];
  28470. var renderer = this._renderer;
  28471. var outputEncoding = renderer.outputEncoding;
  28472. var toneMapping = renderer.toneMapping;
  28473. var clearColor = renderer.getClearColor();
  28474. var clearAlpha = renderer.getClearAlpha();
  28475. renderer.toneMapping = NoToneMapping;
  28476. renderer.outputEncoding = LinearEncoding;
  28477. var background = scene.background;
  28478. if (background && background.isColor) {
  28479. background.convertSRGBToLinear(); // Convert linear to RGBE
  28480. var maxComponent = Math.max(background.r, background.g, background.b);
  28481. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  28482. background = background.multiplyScalar(Math.pow(2.0, -fExp));
  28483. var alpha = (fExp + 128.0) / 255.0;
  28484. renderer.setClearColor(background, alpha);
  28485. scene.background = null;
  28486. }
  28487. for (var i = 0; i < 6; i++) {
  28488. var col = i % 3;
  28489. if (col == 0) {
  28490. cubeCamera.up.set(0, upSign[i], 0);
  28491. cubeCamera.lookAt(forwardSign[i], 0, 0);
  28492. } else if (col == 1) {
  28493. cubeCamera.up.set(0, 0, upSign[i]);
  28494. cubeCamera.lookAt(0, forwardSign[i], 0);
  28495. } else {
  28496. cubeCamera.up.set(0, upSign[i], 0);
  28497. cubeCamera.lookAt(0, 0, forwardSign[i]);
  28498. }
  28499. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  28500. renderer.setRenderTarget(cubeUVRenderTarget);
  28501. renderer.render(scene, cubeCamera);
  28502. }
  28503. renderer.toneMapping = toneMapping;
  28504. renderer.outputEncoding = outputEncoding;
  28505. renderer.setClearColor(clearColor, clearAlpha);
  28506. };
  28507. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  28508. var renderer = this._renderer;
  28509. if (texture.isCubeTexture) {
  28510. if (this._cubemapShader == null) {
  28511. this._cubemapShader = _getCubemapShader();
  28512. }
  28513. } else {
  28514. if (this._equirectShader == null) {
  28515. this._equirectShader = _getEquirectShader();
  28516. }
  28517. }
  28518. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  28519. var mesh = new Mesh(_lodPlanes[0], material);
  28520. var uniforms = material.uniforms;
  28521. uniforms['envMap'].value = texture;
  28522. if (!texture.isCubeTexture) {
  28523. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  28524. }
  28525. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  28526. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  28527. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  28528. renderer.setRenderTarget(cubeUVRenderTarget);
  28529. renderer.render(mesh, _flatCamera);
  28530. };
  28531. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  28532. var renderer = this._renderer;
  28533. var autoClear = renderer.autoClear;
  28534. renderer.autoClear = false;
  28535. for (var i = 1; i < TOTAL_LODS; i++) {
  28536. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  28537. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  28538. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  28539. }
  28540. renderer.autoClear = autoClear;
  28541. }
  28542. /**
  28543. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  28544. * vertically and horizontally, but this breaks down on a cube. Here we apply
  28545. * the blur latitudinally (around the poles), and then longitudinally (towards
  28546. * the poles) to approximate the orthogonally-separable blur. It is least
  28547. * accurate at the poles, but still does a decent job.
  28548. */
  28549. ;
  28550. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  28551. var pingPongRenderTarget = this._pingPongRenderTarget;
  28552. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  28553. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  28554. };
  28555. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  28556. var renderer = this._renderer;
  28557. var blurMaterial = this._blurMaterial;
  28558. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  28559. console.error('blur direction must be either latitudinal or longitudinal!');
  28560. } // Number of standard deviations at which to cut off the discrete approximation.
  28561. var STANDARD_DEVIATIONS = 3;
  28562. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  28563. var blurUniforms = blurMaterial.uniforms;
  28564. var pixels = _sizeLods[lodIn] - 1;
  28565. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  28566. var sigmaPixels = sigmaRadians / radiansPerPixel;
  28567. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  28568. if (samples > MAX_SAMPLES) {
  28569. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  28570. }
  28571. var weights = [];
  28572. var sum = 0;
  28573. for (var i = 0; i < MAX_SAMPLES; ++i) {
  28574. var _x = i / sigmaPixels;
  28575. var weight = Math.exp(-_x * _x / 2);
  28576. weights.push(weight);
  28577. if (i == 0) {
  28578. sum += weight;
  28579. } else if (i < samples) {
  28580. sum += 2 * weight;
  28581. }
  28582. }
  28583. for (var _i = 0; _i < weights.length; _i++) {
  28584. weights[_i] = weights[_i] / sum;
  28585. }
  28586. blurUniforms['envMap'].value = targetIn.texture;
  28587. blurUniforms['samples'].value = samples;
  28588. blurUniforms['weights'].value = weights;
  28589. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  28590. if (poleAxis) {
  28591. blurUniforms['poleAxis'].value = poleAxis;
  28592. }
  28593. blurUniforms['dTheta'].value = radiansPerPixel;
  28594. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  28595. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28596. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28597. var outputSize = _sizeLods[lodOut];
  28598. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  28599. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  28600. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  28601. renderer.setRenderTarget(targetOut);
  28602. renderer.render(blurMesh, _flatCamera);
  28603. };
  28604. return PMREMGenerator;
  28605. }();
  28606. function _isLDR(texture) {
  28607. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  28608. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  28609. }
  28610. function _createPlanes() {
  28611. var _lodPlanes = [];
  28612. var _sizeLods = [];
  28613. var _sigmas = [];
  28614. var lod = LOD_MAX;
  28615. for (var i = 0; i < TOTAL_LODS; i++) {
  28616. var sizeLod = Math.pow(2, lod);
  28617. _sizeLods.push(sizeLod);
  28618. var sigma = 1.0 / sizeLod;
  28619. if (i > LOD_MAX - LOD_MIN) {
  28620. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  28621. } else if (i == 0) {
  28622. sigma = 0;
  28623. }
  28624. _sigmas.push(sigma);
  28625. var texelSize = 1.0 / (sizeLod - 1);
  28626. var min = -texelSize / 2;
  28627. var max = 1 + texelSize / 2;
  28628. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  28629. var cubeFaces = 6;
  28630. var vertices = 6;
  28631. var positionSize = 3;
  28632. var uvSize = 2;
  28633. var faceIndexSize = 1;
  28634. var position = new Float32Array(positionSize * vertices * cubeFaces);
  28635. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  28636. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  28637. for (var face = 0; face < cubeFaces; face++) {
  28638. var x = face % 3 * 2 / 3 - 1;
  28639. var y = face > 2 ? 0 : -1;
  28640. 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];
  28641. position.set(coordinates, positionSize * vertices * face);
  28642. uv.set(uv1, uvSize * vertices * face);
  28643. var fill = [face, face, face, face, face, face];
  28644. faceIndex.set(fill, faceIndexSize * vertices * face);
  28645. }
  28646. var planes = new BufferGeometry();
  28647. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  28648. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  28649. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  28650. _lodPlanes.push(planes);
  28651. if (lod > LOD_MIN) {
  28652. lod--;
  28653. }
  28654. }
  28655. return {
  28656. _lodPlanes: _lodPlanes,
  28657. _sizeLods: _sizeLods,
  28658. _sigmas: _sigmas
  28659. };
  28660. }
  28661. function _createRenderTarget(params) {
  28662. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  28663. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  28664. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  28665. cubeUVRenderTarget.scissorTest = true;
  28666. return cubeUVRenderTarget;
  28667. }
  28668. function _setViewport(target, x, y, width, height) {
  28669. target.viewport.set(x, y, width, height);
  28670. target.scissor.set(x, y, width, height);
  28671. }
  28672. function _getBlurShader(maxSamples) {
  28673. var weights = new Float32Array(maxSamples);
  28674. var poleAxis = new Vector3(0, 1, 0);
  28675. var shaderMaterial = new RawShaderMaterial({
  28676. name: 'SphericalGaussianBlur',
  28677. defines: {
  28678. 'n': maxSamples
  28679. },
  28680. uniforms: {
  28681. 'envMap': {
  28682. value: null
  28683. },
  28684. 'samples': {
  28685. value: 1
  28686. },
  28687. 'weights': {
  28688. value: weights
  28689. },
  28690. 'latitudinal': {
  28691. value: false
  28692. },
  28693. 'dTheta': {
  28694. value: 0
  28695. },
  28696. 'mipInt': {
  28697. value: 0
  28698. },
  28699. 'poleAxis': {
  28700. value: poleAxis
  28701. },
  28702. 'inputEncoding': {
  28703. value: ENCODINGS[LinearEncoding]
  28704. },
  28705. 'outputEncoding': {
  28706. value: ENCODINGS[LinearEncoding]
  28707. }
  28708. },
  28709. vertexShader: _getCommonVertexShader(),
  28710. fragmentShader:
  28711. /* glsl */
  28712. "\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",
  28713. blending: NoBlending,
  28714. depthTest: false,
  28715. depthWrite: false
  28716. });
  28717. return shaderMaterial;
  28718. }
  28719. function _getEquirectShader() {
  28720. var texelSize = new Vector2(1, 1);
  28721. var shaderMaterial = new RawShaderMaterial({
  28722. name: 'EquirectangularToCubeUV',
  28723. uniforms: {
  28724. 'envMap': {
  28725. value: null
  28726. },
  28727. 'texelSize': {
  28728. value: texelSize
  28729. },
  28730. 'inputEncoding': {
  28731. value: ENCODINGS[LinearEncoding]
  28732. },
  28733. 'outputEncoding': {
  28734. value: ENCODINGS[LinearEncoding]
  28735. }
  28736. },
  28737. vertexShader: _getCommonVertexShader(),
  28738. fragmentShader:
  28739. /* glsl */
  28740. "\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",
  28741. blending: NoBlending,
  28742. depthTest: false,
  28743. depthWrite: false
  28744. });
  28745. return shaderMaterial;
  28746. }
  28747. function _getCubemapShader() {
  28748. var shaderMaterial = new RawShaderMaterial({
  28749. name: 'CubemapToCubeUV',
  28750. uniforms: {
  28751. 'envMap': {
  28752. value: null
  28753. },
  28754. 'inputEncoding': {
  28755. value: ENCODINGS[LinearEncoding]
  28756. },
  28757. 'outputEncoding': {
  28758. value: ENCODINGS[LinearEncoding]
  28759. }
  28760. },
  28761. vertexShader: _getCommonVertexShader(),
  28762. fragmentShader:
  28763. /* glsl */
  28764. "\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",
  28765. blending: NoBlending,
  28766. depthTest: false,
  28767. depthWrite: false
  28768. });
  28769. return shaderMaterial;
  28770. }
  28771. function _getCommonVertexShader() {
  28772. return (
  28773. /* glsl */
  28774. "\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"
  28775. );
  28776. }
  28777. function _getEncodings() {
  28778. return (
  28779. /* glsl */
  28780. "\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"
  28781. );
  28782. }
  28783. function Face4(a, b, c, d, normal, color, materialIndex) {
  28784. console.warn('THREE.Face4 has been removed. A THREE.Face3 will be created instead.');
  28785. return new Face3(a, b, c, normal, color, materialIndex);
  28786. }
  28787. var LineStrip = 0;
  28788. var LinePieces = 1;
  28789. var NoColors = 0;
  28790. var FaceColors = 1;
  28791. var VertexColors = 2;
  28792. function MeshFaceMaterial(materials) {
  28793. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  28794. return materials;
  28795. }
  28796. function MultiMaterial(materials) {
  28797. if (materials === undefined) materials = [];
  28798. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  28799. materials.isMultiMaterial = true;
  28800. materials.materials = materials;
  28801. materials.clone = function () {
  28802. return materials.slice();
  28803. };
  28804. return materials;
  28805. }
  28806. function PointCloud(geometry, material) {
  28807. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  28808. return new Points(geometry, material);
  28809. }
  28810. function Particle(material) {
  28811. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  28812. return new Sprite(material);
  28813. }
  28814. function ParticleSystem(geometry, material) {
  28815. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  28816. return new Points(geometry, material);
  28817. }
  28818. function PointCloudMaterial(parameters) {
  28819. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  28820. return new PointsMaterial(parameters);
  28821. }
  28822. function ParticleBasicMaterial(parameters) {
  28823. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  28824. return new PointsMaterial(parameters);
  28825. }
  28826. function ParticleSystemMaterial(parameters) {
  28827. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  28828. return new PointsMaterial(parameters);
  28829. }
  28830. function Vertex(x, y, z) {
  28831. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  28832. return new Vector3(x, y, z);
  28833. } //
  28834. function DynamicBufferAttribute(array, itemSize) {
  28835. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  28836. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  28837. }
  28838. function Int8Attribute(array, itemSize) {
  28839. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  28840. return new Int8BufferAttribute(array, itemSize);
  28841. }
  28842. function Uint8Attribute(array, itemSize) {
  28843. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  28844. return new Uint8BufferAttribute(array, itemSize);
  28845. }
  28846. function Uint8ClampedAttribute(array, itemSize) {
  28847. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  28848. return new Uint8ClampedBufferAttribute(array, itemSize);
  28849. }
  28850. function Int16Attribute(array, itemSize) {
  28851. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  28852. return new Int16BufferAttribute(array, itemSize);
  28853. }
  28854. function Uint16Attribute(array, itemSize) {
  28855. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  28856. return new Uint16BufferAttribute(array, itemSize);
  28857. }
  28858. function Int32Attribute(array, itemSize) {
  28859. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  28860. return new Int32BufferAttribute(array, itemSize);
  28861. }
  28862. function Uint32Attribute(array, itemSize) {
  28863. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  28864. return new Uint32BufferAttribute(array, itemSize);
  28865. }
  28866. function Float32Attribute(array, itemSize) {
  28867. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  28868. return new Float32BufferAttribute(array, itemSize);
  28869. }
  28870. function Float64Attribute(array, itemSize) {
  28871. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  28872. return new Float64BufferAttribute(array, itemSize);
  28873. } //
  28874. Curve.create = function (construct, getPoint) {
  28875. console.log('THREE.Curve.create() has been deprecated');
  28876. construct.prototype = Object.create(Curve.prototype);
  28877. construct.prototype.constructor = construct;
  28878. construct.prototype.getPoint = getPoint;
  28879. return construct;
  28880. }; //
  28881. Object.assign(CurvePath.prototype, {
  28882. createPointsGeometry: function createPointsGeometry(divisions) {
  28883. 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)
  28884. var pts = this.getPoints(divisions);
  28885. return this.createGeometry(pts);
  28886. },
  28887. createSpacedPointsGeometry: function createSpacedPointsGeometry(divisions) {
  28888. console.warn('THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.'); // generate geometry from equidistant sampling along the path
  28889. var pts = this.getSpacedPoints(divisions);
  28890. return this.createGeometry(pts);
  28891. },
  28892. createGeometry: function createGeometry(points) {
  28893. console.warn('THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');
  28894. var geometry = new Geometry();
  28895. for (var i = 0, l = points.length; i < l; i++) {
  28896. var point = points[i];
  28897. geometry.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  28898. }
  28899. return geometry;
  28900. }
  28901. }); //
  28902. Object.assign(Path.prototype, {
  28903. fromPoints: function fromPoints(points) {
  28904. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  28905. return this.setFromPoints(points);
  28906. }
  28907. }); //
  28908. function ClosedSplineCurve3(points) {
  28909. console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  28910. CatmullRomCurve3.call(this, points);
  28911. this.type = 'catmullrom';
  28912. this.closed = true;
  28913. }
  28914. ClosedSplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  28915. function SplineCurve3(points) {
  28916. console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  28917. CatmullRomCurve3.call(this, points);
  28918. this.type = 'catmullrom';
  28919. }
  28920. SplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  28921. function Spline(points) {
  28922. console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');
  28923. CatmullRomCurve3.call(this, points);
  28924. this.type = 'catmullrom';
  28925. }
  28926. Spline.prototype = Object.create(CatmullRomCurve3.prototype);
  28927. Object.assign(Spline.prototype, {
  28928. initFromArray: function initFromArray()
  28929. /* a */
  28930. {
  28931. console.error('THREE.Spline: .initFromArray() has been removed.');
  28932. },
  28933. getControlPointsArray: function getControlPointsArray()
  28934. /* optionalTarget */
  28935. {
  28936. console.error('THREE.Spline: .getControlPointsArray() has been removed.');
  28937. },
  28938. reparametrizeByArcLength: function reparametrizeByArcLength()
  28939. /* samplingCoef */
  28940. {
  28941. console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');
  28942. }
  28943. }); //
  28944. function AxisHelper(size) {
  28945. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  28946. return new AxesHelper(size);
  28947. }
  28948. function BoundingBoxHelper(object, color) {
  28949. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  28950. return new BoxHelper(object, color);
  28951. }
  28952. function EdgesHelper(object, hex) {
  28953. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  28954. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  28955. color: hex !== undefined ? hex : 0xffffff
  28956. }));
  28957. }
  28958. GridHelper.prototype.setColors = function () {
  28959. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  28960. };
  28961. SkeletonHelper.prototype.update = function () {
  28962. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  28963. };
  28964. function WireframeHelper(object, hex) {
  28965. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  28966. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  28967. color: hex !== undefined ? hex : 0xffffff
  28968. }));
  28969. } //
  28970. Object.assign(Loader.prototype, {
  28971. extractUrlBase: function extractUrlBase(url) {
  28972. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  28973. return LoaderUtils.extractUrlBase(url);
  28974. }
  28975. });
  28976. Loader.Handlers = {
  28977. add: function add()
  28978. /* regex, loader */
  28979. {
  28980. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  28981. },
  28982. get: function get()
  28983. /* file */
  28984. {
  28985. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  28986. }
  28987. };
  28988. function XHRLoader(manager) {
  28989. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  28990. return new FileLoader(manager);
  28991. }
  28992. function BinaryTextureLoader(manager) {
  28993. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  28994. return new DataTextureLoader(manager);
  28995. } //
  28996. Object.assign(Box2.prototype, {
  28997. center: function center(optionalTarget) {
  28998. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  28999. return this.getCenter(optionalTarget);
  29000. },
  29001. empty: function empty() {
  29002. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29003. return this.isEmpty();
  29004. },
  29005. isIntersectionBox: function isIntersectionBox(box) {
  29006. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29007. return this.intersectsBox(box);
  29008. },
  29009. size: function size(optionalTarget) {
  29010. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29011. return this.getSize(optionalTarget);
  29012. }
  29013. });
  29014. Object.assign(Box3.prototype, {
  29015. center: function center(optionalTarget) {
  29016. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29017. return this.getCenter(optionalTarget);
  29018. },
  29019. empty: function empty() {
  29020. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29021. return this.isEmpty();
  29022. },
  29023. isIntersectionBox: function isIntersectionBox(box) {
  29024. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29025. return this.intersectsBox(box);
  29026. },
  29027. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29028. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29029. return this.intersectsSphere(sphere);
  29030. },
  29031. size: function size(optionalTarget) {
  29032. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29033. return this.getSize(optionalTarget);
  29034. }
  29035. });
  29036. Object.assign(Sphere.prototype, {
  29037. empty: function empty() {
  29038. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29039. return this.isEmpty();
  29040. }
  29041. });
  29042. Frustum.prototype.setFromMatrix = function (m) {
  29043. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29044. return this.setFromProjectionMatrix(m);
  29045. };
  29046. Line3.prototype.center = function (optionalTarget) {
  29047. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29048. return this.getCenter(optionalTarget);
  29049. };
  29050. Object.assign(MathUtils, {
  29051. random16: function random16() {
  29052. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29053. return Math.random();
  29054. },
  29055. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29056. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29057. return MathUtils.floorPowerOfTwo(value);
  29058. },
  29059. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29060. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29061. return MathUtils.ceilPowerOfTwo(value);
  29062. }
  29063. });
  29064. Object.assign(Matrix3.prototype, {
  29065. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29066. console.warn("THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");
  29067. return this.toArray(array, offset);
  29068. },
  29069. multiplyVector3: function multiplyVector3(vector) {
  29070. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29071. return vector.applyMatrix3(this);
  29072. },
  29073. multiplyVector3Array: function multiplyVector3Array()
  29074. /* a */
  29075. {
  29076. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29077. },
  29078. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29079. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29080. return attribute.applyMatrix3(this);
  29081. },
  29082. applyToVector3Array: function applyToVector3Array()
  29083. /* array, offset, length */
  29084. {
  29085. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29086. }
  29087. });
  29088. Object.assign(Matrix4.prototype, {
  29089. extractPosition: function extractPosition(m) {
  29090. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29091. return this.copyPosition(m);
  29092. },
  29093. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29094. console.warn("THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");
  29095. return this.toArray(array, offset);
  29096. },
  29097. getPosition: function getPosition() {
  29098. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29099. return new Vector3().setFromMatrixColumn(this, 3);
  29100. },
  29101. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29102. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29103. return this.makeRotationFromQuaternion(q);
  29104. },
  29105. multiplyToArray: function multiplyToArray() {
  29106. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29107. },
  29108. multiplyVector3: function multiplyVector3(vector) {
  29109. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29110. return vector.applyMatrix4(this);
  29111. },
  29112. multiplyVector4: function multiplyVector4(vector) {
  29113. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29114. return vector.applyMatrix4(this);
  29115. },
  29116. multiplyVector3Array: function multiplyVector3Array()
  29117. /* a */
  29118. {
  29119. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29120. },
  29121. rotateAxis: function rotateAxis(v) {
  29122. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29123. v.transformDirection(this);
  29124. },
  29125. crossVector: function crossVector(vector) {
  29126. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29127. return vector.applyMatrix4(this);
  29128. },
  29129. translate: function translate() {
  29130. console.error('THREE.Matrix4: .translate() has been removed.');
  29131. },
  29132. rotateX: function rotateX() {
  29133. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29134. },
  29135. rotateY: function rotateY() {
  29136. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29137. },
  29138. rotateZ: function rotateZ() {
  29139. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29140. },
  29141. rotateByAxis: function rotateByAxis() {
  29142. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29143. },
  29144. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29145. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29146. return attribute.applyMatrix4(this);
  29147. },
  29148. applyToVector3Array: function applyToVector3Array()
  29149. /* array, offset, length */
  29150. {
  29151. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29152. },
  29153. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29154. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29155. return this.makePerspective(left, right, top, bottom, near, far);
  29156. }
  29157. });
  29158. Plane.prototype.isIntersectionLine = function (line) {
  29159. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29160. return this.intersectsLine(line);
  29161. };
  29162. Quaternion.prototype.multiplyVector3 = function (vector) {
  29163. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29164. return vector.applyQuaternion(this);
  29165. };
  29166. Object.assign(Ray.prototype, {
  29167. isIntersectionBox: function isIntersectionBox(box) {
  29168. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29169. return this.intersectsBox(box);
  29170. },
  29171. isIntersectionPlane: function isIntersectionPlane(plane) {
  29172. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29173. return this.intersectsPlane(plane);
  29174. },
  29175. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29176. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29177. return this.intersectsSphere(sphere);
  29178. }
  29179. });
  29180. Object.assign(Triangle.prototype, {
  29181. area: function area() {
  29182. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29183. return this.getArea();
  29184. },
  29185. barycoordFromPoint: function barycoordFromPoint(point, target) {
  29186. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29187. return this.getBarycoord(point, target);
  29188. },
  29189. midpoint: function midpoint(target) {
  29190. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29191. return this.getMidpoint(target);
  29192. },
  29193. normal: function normal(target) {
  29194. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29195. return this.getNormal(target);
  29196. },
  29197. plane: function plane(target) {
  29198. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29199. return this.getPlane(target);
  29200. }
  29201. });
  29202. Object.assign(Triangle, {
  29203. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  29204. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29205. return Triangle.getBarycoord(point, a, b, c, target);
  29206. },
  29207. normal: function normal(a, b, c, target) {
  29208. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29209. return Triangle.getNormal(a, b, c, target);
  29210. }
  29211. });
  29212. Object.assign(Shape.prototype, {
  29213. extractAllPoints: function extractAllPoints(divisions) {
  29214. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29215. return this.extractPoints(divisions);
  29216. },
  29217. extrude: function extrude(options) {
  29218. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  29219. return new ExtrudeGeometry(this, options);
  29220. },
  29221. makeGeometry: function makeGeometry(options) {
  29222. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  29223. return new ShapeGeometry(this, options);
  29224. }
  29225. });
  29226. Object.assign(Vector2.prototype, {
  29227. fromAttribute: function fromAttribute(attribute, index, offset) {
  29228. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29229. return this.fromBufferAttribute(attribute, index, offset);
  29230. },
  29231. distanceToManhattan: function distanceToManhattan(v) {
  29232. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29233. return this.manhattanDistanceTo(v);
  29234. },
  29235. lengthManhattan: function lengthManhattan() {
  29236. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  29237. return this.manhattanLength();
  29238. }
  29239. });
  29240. Object.assign(Vector3.prototype, {
  29241. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  29242. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  29243. },
  29244. setEulerFromQuaternion: function setEulerFromQuaternion() {
  29245. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  29246. },
  29247. getPositionFromMatrix: function getPositionFromMatrix(m) {
  29248. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  29249. return this.setFromMatrixPosition(m);
  29250. },
  29251. getScaleFromMatrix: function getScaleFromMatrix(m) {
  29252. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  29253. return this.setFromMatrixScale(m);
  29254. },
  29255. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  29256. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  29257. return this.setFromMatrixColumn(matrix, index);
  29258. },
  29259. applyProjection: function applyProjection(m) {
  29260. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  29261. return this.applyMatrix4(m);
  29262. },
  29263. fromAttribute: function fromAttribute(attribute, index, offset) {
  29264. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29265. return this.fromBufferAttribute(attribute, index, offset);
  29266. },
  29267. distanceToManhattan: function distanceToManhattan(v) {
  29268. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29269. return this.manhattanDistanceTo(v);
  29270. },
  29271. lengthManhattan: function lengthManhattan() {
  29272. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  29273. return this.manhattanLength();
  29274. }
  29275. });
  29276. Object.assign(Vector4.prototype, {
  29277. fromAttribute: function fromAttribute(attribute, index, offset) {
  29278. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29279. return this.fromBufferAttribute(attribute, index, offset);
  29280. },
  29281. lengthManhattan: function lengthManhattan() {
  29282. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  29283. return this.manhattanLength();
  29284. }
  29285. }); //
  29286. Object.assign(Geometry.prototype, {
  29287. computeTangents: function computeTangents() {
  29288. console.error('THREE.Geometry: .computeTangents() has been removed.');
  29289. },
  29290. computeLineDistances: function computeLineDistances() {
  29291. console.error('THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.');
  29292. },
  29293. applyMatrix: function applyMatrix(matrix) {
  29294. console.warn('THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29295. return this.applyMatrix4(matrix);
  29296. }
  29297. });
  29298. Object.assign(Object3D.prototype, {
  29299. getChildByName: function getChildByName(name) {
  29300. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  29301. return this.getObjectByName(name);
  29302. },
  29303. renderDepth: function renderDepth() {
  29304. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  29305. },
  29306. translate: function translate(distance, axis) {
  29307. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  29308. return this.translateOnAxis(axis, distance);
  29309. },
  29310. getWorldRotation: function getWorldRotation() {
  29311. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  29312. },
  29313. applyMatrix: function applyMatrix(matrix) {
  29314. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  29315. return this.applyMatrix4(matrix);
  29316. }
  29317. });
  29318. Object.defineProperties(Object3D.prototype, {
  29319. eulerOrder: {
  29320. get: function get() {
  29321. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29322. return this.rotation.order;
  29323. },
  29324. set: function set(value) {
  29325. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29326. this.rotation.order = value;
  29327. }
  29328. },
  29329. useQuaternion: {
  29330. get: function get() {
  29331. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29332. },
  29333. set: function set() {
  29334. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29335. }
  29336. }
  29337. });
  29338. Object.assign(Mesh.prototype, {
  29339. setDrawMode: function setDrawMode() {
  29340. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29341. }
  29342. });
  29343. Object.defineProperties(Mesh.prototype, {
  29344. drawMode: {
  29345. get: function get() {
  29346. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  29347. return TrianglesDrawMode;
  29348. },
  29349. set: function set() {
  29350. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29351. }
  29352. }
  29353. });
  29354. Object.defineProperties(LOD.prototype, {
  29355. objects: {
  29356. get: function get() {
  29357. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  29358. return this.levels;
  29359. }
  29360. }
  29361. });
  29362. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  29363. get: function get() {
  29364. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29365. },
  29366. set: function set() {
  29367. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29368. }
  29369. });
  29370. SkinnedMesh.prototype.initBones = function () {
  29371. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  29372. };
  29373. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  29374. get: function get() {
  29375. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29376. return this.arcLengthDivisions;
  29377. },
  29378. set: function set(value) {
  29379. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29380. this.arcLengthDivisions = value;
  29381. }
  29382. }); //
  29383. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  29384. console.warn("THREE.PerspectiveCamera.setLens is deprecated. " + "Use .setFocalLength and .filmGauge for a photographic setup.");
  29385. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  29386. this.setFocalLength(focalLength);
  29387. }; //
  29388. Object.defineProperties(Light.prototype, {
  29389. onlyShadow: {
  29390. set: function set() {
  29391. console.warn('THREE.Light: .onlyShadow has been removed.');
  29392. }
  29393. },
  29394. shadowCameraFov: {
  29395. set: function set(value) {
  29396. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  29397. this.shadow.camera.fov = value;
  29398. }
  29399. },
  29400. shadowCameraLeft: {
  29401. set: function set(value) {
  29402. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  29403. this.shadow.camera.left = value;
  29404. }
  29405. },
  29406. shadowCameraRight: {
  29407. set: function set(value) {
  29408. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  29409. this.shadow.camera.right = value;
  29410. }
  29411. },
  29412. shadowCameraTop: {
  29413. set: function set(value) {
  29414. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  29415. this.shadow.camera.top = value;
  29416. }
  29417. },
  29418. shadowCameraBottom: {
  29419. set: function set(value) {
  29420. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  29421. this.shadow.camera.bottom = value;
  29422. }
  29423. },
  29424. shadowCameraNear: {
  29425. set: function set(value) {
  29426. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  29427. this.shadow.camera.near = value;
  29428. }
  29429. },
  29430. shadowCameraFar: {
  29431. set: function set(value) {
  29432. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  29433. this.shadow.camera.far = value;
  29434. }
  29435. },
  29436. shadowCameraVisible: {
  29437. set: function set() {
  29438. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  29439. }
  29440. },
  29441. shadowBias: {
  29442. set: function set(value) {
  29443. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  29444. this.shadow.bias = value;
  29445. }
  29446. },
  29447. shadowDarkness: {
  29448. set: function set() {
  29449. console.warn('THREE.Light: .shadowDarkness has been removed.');
  29450. }
  29451. },
  29452. shadowMapWidth: {
  29453. set: function set(value) {
  29454. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  29455. this.shadow.mapSize.width = value;
  29456. }
  29457. },
  29458. shadowMapHeight: {
  29459. set: function set(value) {
  29460. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  29461. this.shadow.mapSize.height = value;
  29462. }
  29463. }
  29464. }); //
  29465. Object.defineProperties(BufferAttribute.prototype, {
  29466. length: {
  29467. get: function get() {
  29468. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  29469. return this.array.length;
  29470. }
  29471. },
  29472. dynamic: {
  29473. get: function get() {
  29474. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29475. return this.usage === DynamicDrawUsage;
  29476. },
  29477. set: function set()
  29478. /* value */
  29479. {
  29480. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29481. this.setUsage(DynamicDrawUsage);
  29482. }
  29483. }
  29484. });
  29485. Object.assign(BufferAttribute.prototype, {
  29486. setDynamic: function setDynamic(value) {
  29487. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29488. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29489. return this;
  29490. },
  29491. copyIndicesArray: function copyIndicesArray()
  29492. /* indices */
  29493. {
  29494. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  29495. },
  29496. setArray: function setArray()
  29497. /* array */
  29498. {
  29499. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29500. }
  29501. });
  29502. Object.assign(BufferGeometry.prototype, {
  29503. addIndex: function addIndex(index) {
  29504. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  29505. this.setIndex(index);
  29506. },
  29507. addAttribute: function addAttribute(name, attribute) {
  29508. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  29509. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  29510. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  29511. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  29512. }
  29513. if (name === 'index') {
  29514. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  29515. this.setIndex(attribute);
  29516. return this;
  29517. }
  29518. return this.setAttribute(name, attribute);
  29519. },
  29520. addDrawCall: function addDrawCall(start, count, indexOffset) {
  29521. if (indexOffset !== undefined) {
  29522. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  29523. }
  29524. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  29525. this.addGroup(start, count);
  29526. },
  29527. clearDrawCalls: function clearDrawCalls() {
  29528. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  29529. this.clearGroups();
  29530. },
  29531. computeTangents: function computeTangents() {
  29532. console.warn('THREE.BufferGeometry: .computeTangents() has been removed.');
  29533. },
  29534. computeOffsets: function computeOffsets() {
  29535. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  29536. },
  29537. removeAttribute: function removeAttribute(name) {
  29538. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  29539. return this.deleteAttribute(name);
  29540. },
  29541. applyMatrix: function applyMatrix(matrix) {
  29542. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29543. return this.applyMatrix4(matrix);
  29544. }
  29545. });
  29546. Object.defineProperties(BufferGeometry.prototype, {
  29547. drawcalls: {
  29548. get: function get() {
  29549. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  29550. return this.groups;
  29551. }
  29552. },
  29553. offsets: {
  29554. get: function get() {
  29555. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  29556. return this.groups;
  29557. }
  29558. }
  29559. });
  29560. Object.defineProperties(InstancedBufferGeometry.prototype, {
  29561. maxInstancedCount: {
  29562. get: function get() {
  29563. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29564. return this.instanceCount;
  29565. },
  29566. set: function set(value) {
  29567. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29568. this.instanceCount = value;
  29569. }
  29570. }
  29571. });
  29572. Object.defineProperties(Raycaster.prototype, {
  29573. linePrecision: {
  29574. get: function get() {
  29575. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29576. return this.params.Line.threshold;
  29577. },
  29578. set: function set(value) {
  29579. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29580. this.params.Line.threshold = value;
  29581. }
  29582. }
  29583. });
  29584. Object.defineProperties(InterleavedBuffer.prototype, {
  29585. dynamic: {
  29586. get: function get() {
  29587. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29588. return this.usage === DynamicDrawUsage;
  29589. },
  29590. set: function set(value) {
  29591. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29592. this.setUsage(value);
  29593. }
  29594. }
  29595. });
  29596. Object.assign(InterleavedBuffer.prototype, {
  29597. setDynamic: function setDynamic(value) {
  29598. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29599. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29600. return this;
  29601. },
  29602. setArray: function setArray()
  29603. /* array */
  29604. {
  29605. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29606. }
  29607. }); //
  29608. Object.assign(ExtrudeBufferGeometry.prototype, {
  29609. getArrays: function getArrays() {
  29610. console.error('THREE.ExtrudeBufferGeometry: .getArrays() has been removed.');
  29611. },
  29612. addShapeList: function addShapeList() {
  29613. console.error('THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.');
  29614. },
  29615. addShape: function addShape() {
  29616. console.error('THREE.ExtrudeBufferGeometry: .addShape() has been removed.');
  29617. }
  29618. }); //
  29619. Object.assign(Scene.prototype, {
  29620. dispose: function dispose() {
  29621. console.error('THREE.Scene: .dispose() has been removed.');
  29622. }
  29623. }); //
  29624. Object.defineProperties(Uniform.prototype, {
  29625. dynamic: {
  29626. set: function set() {
  29627. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  29628. }
  29629. },
  29630. onUpdate: {
  29631. value: function value() {
  29632. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  29633. return this;
  29634. }
  29635. }
  29636. }); //
  29637. Object.defineProperties(Material.prototype, {
  29638. wrapAround: {
  29639. get: function get() {
  29640. console.warn('THREE.Material: .wrapAround has been removed.');
  29641. },
  29642. set: function set() {
  29643. console.warn('THREE.Material: .wrapAround has been removed.');
  29644. }
  29645. },
  29646. overdraw: {
  29647. get: function get() {
  29648. console.warn('THREE.Material: .overdraw has been removed.');
  29649. },
  29650. set: function set() {
  29651. console.warn('THREE.Material: .overdraw has been removed.');
  29652. }
  29653. },
  29654. wrapRGB: {
  29655. get: function get() {
  29656. console.warn('THREE.Material: .wrapRGB has been removed.');
  29657. return new Color();
  29658. }
  29659. },
  29660. shading: {
  29661. get: function get() {
  29662. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29663. },
  29664. set: function set(value) {
  29665. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29666. this.flatShading = value === FlatShading;
  29667. }
  29668. },
  29669. stencilMask: {
  29670. get: function get() {
  29671. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29672. return this.stencilFuncMask;
  29673. },
  29674. set: function set(value) {
  29675. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29676. this.stencilFuncMask = value;
  29677. }
  29678. }
  29679. });
  29680. Object.defineProperties(MeshPhongMaterial.prototype, {
  29681. metal: {
  29682. get: function get() {
  29683. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  29684. return false;
  29685. },
  29686. set: function set() {
  29687. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  29688. }
  29689. }
  29690. });
  29691. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  29692. transparency: {
  29693. get: function get() {
  29694. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29695. return this.transmission;
  29696. },
  29697. set: function set(value) {
  29698. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29699. this.transmission = value;
  29700. }
  29701. }
  29702. });
  29703. Object.defineProperties(ShaderMaterial.prototype, {
  29704. derivatives: {
  29705. get: function get() {
  29706. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29707. return this.extensions.derivatives;
  29708. },
  29709. set: function set(value) {
  29710. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29711. this.extensions.derivatives = value;
  29712. }
  29713. }
  29714. }); //
  29715. Object.assign(WebGLRenderer.prototype, {
  29716. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  29717. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  29718. this.setRenderTarget(renderTarget);
  29719. this.clear(color, depth, stencil);
  29720. },
  29721. animate: function animate(callback) {
  29722. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  29723. this.setAnimationLoop(callback);
  29724. },
  29725. getCurrentRenderTarget: function getCurrentRenderTarget() {
  29726. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  29727. return this.getRenderTarget();
  29728. },
  29729. getMaxAnisotropy: function getMaxAnisotropy() {
  29730. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  29731. return this.capabilities.getMaxAnisotropy();
  29732. },
  29733. getPrecision: function getPrecision() {
  29734. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  29735. return this.capabilities.precision;
  29736. },
  29737. resetGLState: function resetGLState() {
  29738. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  29739. return this.state.reset();
  29740. },
  29741. supportsFloatTextures: function supportsFloatTextures() {
  29742. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  29743. return this.extensions.get('OES_texture_float');
  29744. },
  29745. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  29746. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  29747. return this.extensions.get('OES_texture_half_float');
  29748. },
  29749. supportsStandardDerivatives: function supportsStandardDerivatives() {
  29750. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  29751. return this.extensions.get('OES_standard_derivatives');
  29752. },
  29753. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  29754. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  29755. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  29756. },
  29757. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  29758. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  29759. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  29760. },
  29761. supportsBlendMinMax: function supportsBlendMinMax() {
  29762. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  29763. return this.extensions.get('EXT_blend_minmax');
  29764. },
  29765. supportsVertexTextures: function supportsVertexTextures() {
  29766. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  29767. return this.capabilities.vertexTextures;
  29768. },
  29769. supportsInstancedArrays: function supportsInstancedArrays() {
  29770. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  29771. return this.extensions.get('ANGLE_instanced_arrays');
  29772. },
  29773. enableScissorTest: function enableScissorTest(boolean) {
  29774. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  29775. this.setScissorTest(boolean);
  29776. },
  29777. initMaterial: function initMaterial() {
  29778. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  29779. },
  29780. addPrePlugin: function addPrePlugin() {
  29781. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  29782. },
  29783. addPostPlugin: function addPostPlugin() {
  29784. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  29785. },
  29786. updateShadowMap: function updateShadowMap() {
  29787. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  29788. },
  29789. setFaceCulling: function setFaceCulling() {
  29790. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  29791. },
  29792. allocTextureUnit: function allocTextureUnit() {
  29793. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  29794. },
  29795. setTexture: function setTexture() {
  29796. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  29797. },
  29798. setTexture2D: function setTexture2D() {
  29799. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  29800. },
  29801. setTextureCube: function setTextureCube() {
  29802. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  29803. },
  29804. getActiveMipMapLevel: function getActiveMipMapLevel() {
  29805. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  29806. return this.getActiveMipmapLevel();
  29807. }
  29808. });
  29809. Object.defineProperties(WebGLRenderer.prototype, {
  29810. shadowMapEnabled: {
  29811. get: function get() {
  29812. return this.shadowMap.enabled;
  29813. },
  29814. set: function set(value) {
  29815. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  29816. this.shadowMap.enabled = value;
  29817. }
  29818. },
  29819. shadowMapType: {
  29820. get: function get() {
  29821. return this.shadowMap.type;
  29822. },
  29823. set: function set(value) {
  29824. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  29825. this.shadowMap.type = value;
  29826. }
  29827. },
  29828. shadowMapCullFace: {
  29829. get: function get() {
  29830. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  29831. return undefined;
  29832. },
  29833. set: function set()
  29834. /* value */
  29835. {
  29836. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  29837. }
  29838. },
  29839. context: {
  29840. get: function get() {
  29841. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  29842. return this.getContext();
  29843. }
  29844. },
  29845. vr: {
  29846. get: function get() {
  29847. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  29848. return this.xr;
  29849. }
  29850. },
  29851. gammaInput: {
  29852. get: function get() {
  29853. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  29854. return false;
  29855. },
  29856. set: function set() {
  29857. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  29858. }
  29859. },
  29860. gammaOutput: {
  29861. get: function get() {
  29862. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  29863. return false;
  29864. },
  29865. set: function set(value) {
  29866. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  29867. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  29868. }
  29869. },
  29870. toneMappingWhitePoint: {
  29871. get: function get() {
  29872. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  29873. return 1.0;
  29874. },
  29875. set: function set() {
  29876. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  29877. }
  29878. }
  29879. });
  29880. Object.defineProperties(WebGLShadowMap.prototype, {
  29881. cullFace: {
  29882. get: function get() {
  29883. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  29884. return undefined;
  29885. },
  29886. set: function set()
  29887. /* cullFace */
  29888. {
  29889. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  29890. }
  29891. },
  29892. renderReverseSided: {
  29893. get: function get() {
  29894. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  29895. return undefined;
  29896. },
  29897. set: function set() {
  29898. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  29899. }
  29900. },
  29901. renderSingleSided: {
  29902. get: function get() {
  29903. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  29904. return undefined;
  29905. },
  29906. set: function set() {
  29907. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  29908. }
  29909. }
  29910. });
  29911. function WebGLRenderTargetCube(width, height, options) {
  29912. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  29913. return new WebGLCubeRenderTarget(width, options);
  29914. } //
  29915. Object.defineProperties(WebGLRenderTarget.prototype, {
  29916. wrapS: {
  29917. get: function get() {
  29918. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  29919. return this.texture.wrapS;
  29920. },
  29921. set: function set(value) {
  29922. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  29923. this.texture.wrapS = value;
  29924. }
  29925. },
  29926. wrapT: {
  29927. get: function get() {
  29928. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  29929. return this.texture.wrapT;
  29930. },
  29931. set: function set(value) {
  29932. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  29933. this.texture.wrapT = value;
  29934. }
  29935. },
  29936. magFilter: {
  29937. get: function get() {
  29938. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  29939. return this.texture.magFilter;
  29940. },
  29941. set: function set(value) {
  29942. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  29943. this.texture.magFilter = value;
  29944. }
  29945. },
  29946. minFilter: {
  29947. get: function get() {
  29948. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  29949. return this.texture.minFilter;
  29950. },
  29951. set: function set(value) {
  29952. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  29953. this.texture.minFilter = value;
  29954. }
  29955. },
  29956. anisotropy: {
  29957. get: function get() {
  29958. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  29959. return this.texture.anisotropy;
  29960. },
  29961. set: function set(value) {
  29962. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  29963. this.texture.anisotropy = value;
  29964. }
  29965. },
  29966. offset: {
  29967. get: function get() {
  29968. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  29969. return this.texture.offset;
  29970. },
  29971. set: function set(value) {
  29972. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  29973. this.texture.offset = value;
  29974. }
  29975. },
  29976. repeat: {
  29977. get: function get() {
  29978. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  29979. return this.texture.repeat;
  29980. },
  29981. set: function set(value) {
  29982. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  29983. this.texture.repeat = value;
  29984. }
  29985. },
  29986. format: {
  29987. get: function get() {
  29988. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  29989. return this.texture.format;
  29990. },
  29991. set: function set(value) {
  29992. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  29993. this.texture.format = value;
  29994. }
  29995. },
  29996. type: {
  29997. get: function get() {
  29998. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  29999. return this.texture.type;
  30000. },
  30001. set: function set(value) {
  30002. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30003. this.texture.type = value;
  30004. }
  30005. },
  30006. generateMipmaps: {
  30007. get: function get() {
  30008. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30009. return this.texture.generateMipmaps;
  30010. },
  30011. set: function set(value) {
  30012. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30013. this.texture.generateMipmaps = value;
  30014. }
  30015. }
  30016. }); //
  30017. Object.defineProperties(Audio.prototype, {
  30018. load: {
  30019. value: function value(file) {
  30020. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30021. var scope = this;
  30022. var audioLoader = new AudioLoader();
  30023. audioLoader.load(file, function (buffer) {
  30024. scope.setBuffer(buffer);
  30025. });
  30026. return this;
  30027. }
  30028. },
  30029. startTime: {
  30030. set: function set() {
  30031. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30032. }
  30033. }
  30034. });
  30035. AudioAnalyser.prototype.getData = function () {
  30036. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30037. return this.getFrequencyData();
  30038. }; //
  30039. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30040. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30041. return this.update(renderer, scene);
  30042. }; //
  30043. var GeometryUtils = {
  30044. merge: function merge(geometry1, geometry2, materialIndexOffset) {
  30045. console.warn('THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.');
  30046. var matrix;
  30047. if (geometry2.isMesh) {
  30048. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30049. matrix = geometry2.matrix;
  30050. geometry2 = geometry2.geometry;
  30051. }
  30052. geometry1.merge(geometry2, matrix, materialIndexOffset);
  30053. },
  30054. center: function center(geometry) {
  30055. console.warn('THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.');
  30056. return geometry.center();
  30057. }
  30058. };
  30059. ImageUtils.crossOrigin = undefined;
  30060. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30061. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30062. var loader = new TextureLoader();
  30063. loader.setCrossOrigin(this.crossOrigin);
  30064. var texture = loader.load(url, onLoad, undefined, onError);
  30065. if (mapping) texture.mapping = mapping;
  30066. return texture;
  30067. };
  30068. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30069. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30070. var loader = new CubeTextureLoader();
  30071. loader.setCrossOrigin(this.crossOrigin);
  30072. var texture = loader.load(urls, onLoad, undefined, onError);
  30073. if (mapping) texture.mapping = mapping;
  30074. return texture;
  30075. };
  30076. ImageUtils.loadCompressedTexture = function () {
  30077. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30078. };
  30079. ImageUtils.loadCompressedTextureCube = function () {
  30080. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30081. }; //
  30082. function CanvasRenderer() {
  30083. console.error('THREE.CanvasRenderer has been removed');
  30084. } //
  30085. function JSONLoader() {
  30086. console.error('THREE.JSONLoader has been removed.');
  30087. } //
  30088. var SceneUtils = {
  30089. createMultiMaterialObject: function createMultiMaterialObject()
  30090. /* geometry, materials */
  30091. {
  30092. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30093. },
  30094. detach: function detach()
  30095. /* child, parent, scene */
  30096. {
  30097. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30098. },
  30099. attach: function attach()
  30100. /* child, scene, parent */
  30101. {
  30102. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30103. }
  30104. }; //
  30105. function LensFlare() {
  30106. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30107. }
  30108. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30109. /* eslint-disable no-undef */
  30110. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30111. detail: {
  30112. revision: REVISION
  30113. }
  30114. }));
  30115. /* eslint-enable no-undef */
  30116. }
  30117. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30118. exports.AddEquation = AddEquation;
  30119. exports.AddOperation = AddOperation;
  30120. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30121. exports.AdditiveBlending = AdditiveBlending;
  30122. exports.AlphaFormat = AlphaFormat;
  30123. exports.AlwaysDepth = AlwaysDepth;
  30124. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30125. exports.AmbientLight = AmbientLight;
  30126. exports.AmbientLightProbe = AmbientLightProbe;
  30127. exports.AnimationClip = AnimationClip;
  30128. exports.AnimationLoader = AnimationLoader;
  30129. exports.AnimationMixer = AnimationMixer;
  30130. exports.AnimationObjectGroup = AnimationObjectGroup;
  30131. exports.AnimationUtils = AnimationUtils;
  30132. exports.ArcCurve = ArcCurve;
  30133. exports.ArrayCamera = ArrayCamera;
  30134. exports.ArrowHelper = ArrowHelper;
  30135. exports.Audio = Audio;
  30136. exports.AudioAnalyser = AudioAnalyser;
  30137. exports.AudioContext = AudioContext;
  30138. exports.AudioListener = AudioListener;
  30139. exports.AudioLoader = AudioLoader;
  30140. exports.AxesHelper = AxesHelper;
  30141. exports.AxisHelper = AxisHelper;
  30142. exports.BackSide = BackSide;
  30143. exports.BasicDepthPacking = BasicDepthPacking;
  30144. exports.BasicShadowMap = BasicShadowMap;
  30145. exports.BinaryTextureLoader = BinaryTextureLoader;
  30146. exports.Bone = Bone;
  30147. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30148. exports.BoundingBoxHelper = BoundingBoxHelper;
  30149. exports.Box2 = Box2;
  30150. exports.Box3 = Box3;
  30151. exports.Box3Helper = Box3Helper;
  30152. exports.BoxBufferGeometry = BoxBufferGeometry;
  30153. exports.BoxGeometry = BoxGeometry;
  30154. exports.BoxHelper = BoxHelper;
  30155. exports.BufferAttribute = BufferAttribute;
  30156. exports.BufferGeometry = BufferGeometry;
  30157. exports.BufferGeometryLoader = BufferGeometryLoader;
  30158. exports.ByteType = ByteType;
  30159. exports.Cache = Cache;
  30160. exports.Camera = Camera;
  30161. exports.CameraHelper = CameraHelper;
  30162. exports.CanvasRenderer = CanvasRenderer;
  30163. exports.CanvasTexture = CanvasTexture;
  30164. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30165. exports.CineonToneMapping = CineonToneMapping;
  30166. exports.CircleBufferGeometry = CircleBufferGeometry;
  30167. exports.CircleGeometry = CircleGeometry;
  30168. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30169. exports.Clock = Clock;
  30170. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  30171. exports.Color = Color;
  30172. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30173. exports.CompressedTexture = CompressedTexture;
  30174. exports.CompressedTextureLoader = CompressedTextureLoader;
  30175. exports.ConeBufferGeometry = ConeBufferGeometry;
  30176. exports.ConeGeometry = ConeGeometry;
  30177. exports.CubeCamera = CubeCamera;
  30178. exports.CubeGeometry = BoxGeometry;
  30179. exports.CubeReflectionMapping = CubeReflectionMapping;
  30180. exports.CubeRefractionMapping = CubeRefractionMapping;
  30181. exports.CubeTexture = CubeTexture;
  30182. exports.CubeTextureLoader = CubeTextureLoader;
  30183. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30184. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30185. exports.CubicBezierCurve = CubicBezierCurve;
  30186. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30187. exports.CubicInterpolant = CubicInterpolant;
  30188. exports.CullFaceBack = CullFaceBack;
  30189. exports.CullFaceFront = CullFaceFront;
  30190. exports.CullFaceFrontBack = CullFaceFrontBack;
  30191. exports.CullFaceNone = CullFaceNone;
  30192. exports.Curve = Curve;
  30193. exports.CurvePath = CurvePath;
  30194. exports.CustomBlending = CustomBlending;
  30195. exports.CustomToneMapping = CustomToneMapping;
  30196. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  30197. exports.CylinderGeometry = CylinderGeometry;
  30198. exports.Cylindrical = Cylindrical;
  30199. exports.DataTexture = DataTexture;
  30200. exports.DataTexture2DArray = DataTexture2DArray;
  30201. exports.DataTexture3D = DataTexture3D;
  30202. exports.DataTextureLoader = DataTextureLoader;
  30203. exports.DecrementStencilOp = DecrementStencilOp;
  30204. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30205. exports.DefaultLoadingManager = DefaultLoadingManager;
  30206. exports.DepthFormat = DepthFormat;
  30207. exports.DepthStencilFormat = DepthStencilFormat;
  30208. exports.DepthTexture = DepthTexture;
  30209. exports.DirectionalLight = DirectionalLight;
  30210. exports.DirectionalLightHelper = DirectionalLightHelper;
  30211. exports.DiscreteInterpolant = DiscreteInterpolant;
  30212. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  30213. exports.DodecahedronGeometry = DodecahedronGeometry;
  30214. exports.DoubleSide = DoubleSide;
  30215. exports.DstAlphaFactor = DstAlphaFactor;
  30216. exports.DstColorFactor = DstColorFactor;
  30217. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30218. exports.DynamicCopyUsage = DynamicCopyUsage;
  30219. exports.DynamicDrawUsage = DynamicDrawUsage;
  30220. exports.DynamicReadUsage = DynamicReadUsage;
  30221. exports.EdgesGeometry = EdgesGeometry;
  30222. exports.EdgesHelper = EdgesHelper;
  30223. exports.EllipseCurve = EllipseCurve;
  30224. exports.EqualDepth = EqualDepth;
  30225. exports.EqualStencilFunc = EqualStencilFunc;
  30226. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30227. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30228. exports.Euler = Euler;
  30229. exports.EventDispatcher = EventDispatcher;
  30230. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  30231. exports.ExtrudeGeometry = ExtrudeGeometry;
  30232. exports.Face3 = Face3;
  30233. exports.Face4 = Face4;
  30234. exports.FaceColors = FaceColors;
  30235. exports.FileLoader = FileLoader;
  30236. exports.FlatShading = FlatShading;
  30237. exports.Float32Attribute = Float32Attribute;
  30238. exports.Float32BufferAttribute = Float32BufferAttribute;
  30239. exports.Float64Attribute = Float64Attribute;
  30240. exports.Float64BufferAttribute = Float64BufferAttribute;
  30241. exports.FloatType = FloatType;
  30242. exports.Fog = Fog;
  30243. exports.FogExp2 = FogExp2;
  30244. exports.Font = Font;
  30245. exports.FontLoader = FontLoader;
  30246. exports.FrontSide = FrontSide;
  30247. exports.Frustum = Frustum;
  30248. exports.GLBufferAttribute = GLBufferAttribute;
  30249. exports.GLSL1 = GLSL1;
  30250. exports.GLSL3 = GLSL3;
  30251. exports.GammaEncoding = GammaEncoding;
  30252. exports.Geometry = Geometry;
  30253. exports.GeometryUtils = GeometryUtils;
  30254. exports.GreaterDepth = GreaterDepth;
  30255. exports.GreaterEqualDepth = GreaterEqualDepth;
  30256. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30257. exports.GreaterStencilFunc = GreaterStencilFunc;
  30258. exports.GridHelper = GridHelper;
  30259. exports.Group = Group;
  30260. exports.HalfFloatType = HalfFloatType;
  30261. exports.HemisphereLight = HemisphereLight;
  30262. exports.HemisphereLightHelper = HemisphereLightHelper;
  30263. exports.HemisphereLightProbe = HemisphereLightProbe;
  30264. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  30265. exports.IcosahedronGeometry = IcosahedronGeometry;
  30266. exports.ImageBitmapLoader = ImageBitmapLoader;
  30267. exports.ImageLoader = ImageLoader;
  30268. exports.ImageUtils = ImageUtils;
  30269. exports.ImmediateRenderObject = ImmediateRenderObject;
  30270. exports.IncrementStencilOp = IncrementStencilOp;
  30271. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  30272. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  30273. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  30274. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  30275. exports.InstancedMesh = InstancedMesh;
  30276. exports.Int16Attribute = Int16Attribute;
  30277. exports.Int16BufferAttribute = Int16BufferAttribute;
  30278. exports.Int32Attribute = Int32Attribute;
  30279. exports.Int32BufferAttribute = Int32BufferAttribute;
  30280. exports.Int8Attribute = Int8Attribute;
  30281. exports.Int8BufferAttribute = Int8BufferAttribute;
  30282. exports.IntType = IntType;
  30283. exports.InterleavedBuffer = InterleavedBuffer;
  30284. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  30285. exports.Interpolant = Interpolant;
  30286. exports.InterpolateDiscrete = InterpolateDiscrete;
  30287. exports.InterpolateLinear = InterpolateLinear;
  30288. exports.InterpolateSmooth = InterpolateSmooth;
  30289. exports.InvertStencilOp = InvertStencilOp;
  30290. exports.JSONLoader = JSONLoader;
  30291. exports.KeepStencilOp = KeepStencilOp;
  30292. exports.KeyframeTrack = KeyframeTrack;
  30293. exports.LOD = LOD;
  30294. exports.LatheBufferGeometry = LatheBufferGeometry;
  30295. exports.LatheGeometry = LatheGeometry;
  30296. exports.Layers = Layers;
  30297. exports.LensFlare = LensFlare;
  30298. exports.LessDepth = LessDepth;
  30299. exports.LessEqualDepth = LessEqualDepth;
  30300. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  30301. exports.LessStencilFunc = LessStencilFunc;
  30302. exports.Light = Light;
  30303. exports.LightProbe = LightProbe;
  30304. exports.Line = Line;
  30305. exports.Line3 = Line3;
  30306. exports.LineBasicMaterial = LineBasicMaterial;
  30307. exports.LineCurve = LineCurve;
  30308. exports.LineCurve3 = LineCurve3;
  30309. exports.LineDashedMaterial = LineDashedMaterial;
  30310. exports.LineLoop = LineLoop;
  30311. exports.LinePieces = LinePieces;
  30312. exports.LineSegments = LineSegments;
  30313. exports.LineStrip = LineStrip;
  30314. exports.LinearEncoding = LinearEncoding;
  30315. exports.LinearFilter = LinearFilter;
  30316. exports.LinearInterpolant = LinearInterpolant;
  30317. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  30318. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  30319. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  30320. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  30321. exports.LinearToneMapping = LinearToneMapping;
  30322. exports.Loader = Loader;
  30323. exports.LoaderUtils = LoaderUtils;
  30324. exports.LoadingManager = LoadingManager;
  30325. exports.LogLuvEncoding = LogLuvEncoding;
  30326. exports.LoopOnce = LoopOnce;
  30327. exports.LoopPingPong = LoopPingPong;
  30328. exports.LoopRepeat = LoopRepeat;
  30329. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  30330. exports.LuminanceFormat = LuminanceFormat;
  30331. exports.MOUSE = MOUSE;
  30332. exports.Material = Material;
  30333. exports.MaterialLoader = MaterialLoader;
  30334. exports.Math = MathUtils;
  30335. exports.MathUtils = MathUtils;
  30336. exports.Matrix3 = Matrix3;
  30337. exports.Matrix4 = Matrix4;
  30338. exports.MaxEquation = MaxEquation;
  30339. exports.Mesh = Mesh;
  30340. exports.MeshBasicMaterial = MeshBasicMaterial;
  30341. exports.MeshDepthMaterial = MeshDepthMaterial;
  30342. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  30343. exports.MeshFaceMaterial = MeshFaceMaterial;
  30344. exports.MeshLambertMaterial = MeshLambertMaterial;
  30345. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  30346. exports.MeshNormalMaterial = MeshNormalMaterial;
  30347. exports.MeshPhongMaterial = MeshPhongMaterial;
  30348. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  30349. exports.MeshStandardMaterial = MeshStandardMaterial;
  30350. exports.MeshToonMaterial = MeshToonMaterial;
  30351. exports.MinEquation = MinEquation;
  30352. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  30353. exports.MixOperation = MixOperation;
  30354. exports.MultiMaterial = MultiMaterial;
  30355. exports.MultiplyBlending = MultiplyBlending;
  30356. exports.MultiplyOperation = MultiplyOperation;
  30357. exports.NearestFilter = NearestFilter;
  30358. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  30359. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  30360. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  30361. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  30362. exports.NeverDepth = NeverDepth;
  30363. exports.NeverStencilFunc = NeverStencilFunc;
  30364. exports.NoBlending = NoBlending;
  30365. exports.NoColors = NoColors;
  30366. exports.NoToneMapping = NoToneMapping;
  30367. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  30368. exports.NormalBlending = NormalBlending;
  30369. exports.NotEqualDepth = NotEqualDepth;
  30370. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  30371. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  30372. exports.Object3D = Object3D;
  30373. exports.ObjectLoader = ObjectLoader;
  30374. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  30375. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  30376. exports.OctahedronGeometry = OctahedronGeometry;
  30377. exports.OneFactor = OneFactor;
  30378. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  30379. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  30380. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  30381. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  30382. exports.OrthographicCamera = OrthographicCamera;
  30383. exports.PCFShadowMap = PCFShadowMap;
  30384. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  30385. exports.PMREMGenerator = PMREMGenerator;
  30386. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  30387. exports.ParametricGeometry = ParametricGeometry;
  30388. exports.Particle = Particle;
  30389. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  30390. exports.ParticleSystem = ParticleSystem;
  30391. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  30392. exports.Path = Path;
  30393. exports.PerspectiveCamera = PerspectiveCamera;
  30394. exports.Plane = Plane;
  30395. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  30396. exports.PlaneGeometry = PlaneGeometry;
  30397. exports.PlaneHelper = PlaneHelper;
  30398. exports.PointCloud = PointCloud;
  30399. exports.PointCloudMaterial = PointCloudMaterial;
  30400. exports.PointLight = PointLight;
  30401. exports.PointLightHelper = PointLightHelper;
  30402. exports.Points = Points;
  30403. exports.PointsMaterial = PointsMaterial;
  30404. exports.PolarGridHelper = PolarGridHelper;
  30405. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  30406. exports.PolyhedronGeometry = PolyhedronGeometry;
  30407. exports.PositionalAudio = PositionalAudio;
  30408. exports.PropertyBinding = PropertyBinding;
  30409. exports.PropertyMixer = PropertyMixer;
  30410. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  30411. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  30412. exports.Quaternion = Quaternion;
  30413. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  30414. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  30415. exports.REVISION = REVISION;
  30416. exports.RGBADepthPacking = RGBADepthPacking;
  30417. exports.RGBAFormat = RGBAFormat;
  30418. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  30419. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  30420. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  30421. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  30422. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  30423. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  30424. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  30425. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  30426. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  30427. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  30428. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  30429. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  30430. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  30431. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  30432. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  30433. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  30434. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  30435. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  30436. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  30437. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  30438. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  30439. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  30440. exports.RGBDEncoding = RGBDEncoding;
  30441. exports.RGBEEncoding = RGBEEncoding;
  30442. exports.RGBEFormat = RGBEFormat;
  30443. exports.RGBFormat = RGBFormat;
  30444. exports.RGBIntegerFormat = RGBIntegerFormat;
  30445. exports.RGBM16Encoding = RGBM16Encoding;
  30446. exports.RGBM7Encoding = RGBM7Encoding;
  30447. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  30448. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  30449. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  30450. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  30451. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  30452. exports.RGFormat = RGFormat;
  30453. exports.RGIntegerFormat = RGIntegerFormat;
  30454. exports.RawShaderMaterial = RawShaderMaterial;
  30455. exports.Ray = Ray;
  30456. exports.Raycaster = Raycaster;
  30457. exports.RectAreaLight = RectAreaLight;
  30458. exports.RedFormat = RedFormat;
  30459. exports.RedIntegerFormat = RedIntegerFormat;
  30460. exports.ReinhardToneMapping = ReinhardToneMapping;
  30461. exports.RepeatWrapping = RepeatWrapping;
  30462. exports.ReplaceStencilOp = ReplaceStencilOp;
  30463. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  30464. exports.RingBufferGeometry = RingBufferGeometry;
  30465. exports.RingGeometry = RingGeometry;
  30466. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  30467. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  30468. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  30469. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  30470. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  30471. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  30472. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  30473. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  30474. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  30475. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  30476. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  30477. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  30478. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  30479. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  30480. exports.Scene = Scene;
  30481. exports.SceneUtils = SceneUtils;
  30482. exports.ShaderChunk = ShaderChunk;
  30483. exports.ShaderLib = ShaderLib;
  30484. exports.ShaderMaterial = ShaderMaterial;
  30485. exports.ShadowMaterial = ShadowMaterial;
  30486. exports.Shape = Shape;
  30487. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  30488. exports.ShapeGeometry = ShapeGeometry;
  30489. exports.ShapePath = ShapePath;
  30490. exports.ShapeUtils = ShapeUtils;
  30491. exports.ShortType = ShortType;
  30492. exports.Skeleton = Skeleton;
  30493. exports.SkeletonHelper = SkeletonHelper;
  30494. exports.SkinnedMesh = SkinnedMesh;
  30495. exports.SmoothShading = SmoothShading;
  30496. exports.Sphere = Sphere;
  30497. exports.SphereBufferGeometry = SphereBufferGeometry;
  30498. exports.SphereGeometry = SphereGeometry;
  30499. exports.Spherical = Spherical;
  30500. exports.SphericalHarmonics3 = SphericalHarmonics3;
  30501. exports.Spline = Spline;
  30502. exports.SplineCurve = SplineCurve;
  30503. exports.SplineCurve3 = SplineCurve3;
  30504. exports.SpotLight = SpotLight;
  30505. exports.SpotLightHelper = SpotLightHelper;
  30506. exports.Sprite = Sprite;
  30507. exports.SpriteMaterial = SpriteMaterial;
  30508. exports.SrcAlphaFactor = SrcAlphaFactor;
  30509. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  30510. exports.SrcColorFactor = SrcColorFactor;
  30511. exports.StaticCopyUsage = StaticCopyUsage;
  30512. exports.StaticDrawUsage = StaticDrawUsage;
  30513. exports.StaticReadUsage = StaticReadUsage;
  30514. exports.StereoCamera = StereoCamera;
  30515. exports.StreamCopyUsage = StreamCopyUsage;
  30516. exports.StreamDrawUsage = StreamDrawUsage;
  30517. exports.StreamReadUsage = StreamReadUsage;
  30518. exports.StringKeyframeTrack = StringKeyframeTrack;
  30519. exports.SubtractEquation = SubtractEquation;
  30520. exports.SubtractiveBlending = SubtractiveBlending;
  30521. exports.TOUCH = TOUCH;
  30522. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  30523. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  30524. exports.TetrahedronGeometry = TetrahedronGeometry;
  30525. exports.TextBufferGeometry = TextBufferGeometry;
  30526. exports.TextGeometry = TextGeometry;
  30527. exports.Texture = Texture;
  30528. exports.TextureLoader = TextureLoader;
  30529. exports.TorusBufferGeometry = TorusBufferGeometry;
  30530. exports.TorusGeometry = TorusGeometry;
  30531. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  30532. exports.TorusKnotGeometry = TorusKnotGeometry;
  30533. exports.Triangle = Triangle;
  30534. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  30535. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  30536. exports.TrianglesDrawMode = TrianglesDrawMode;
  30537. exports.TubeBufferGeometry = TubeBufferGeometry;
  30538. exports.TubeGeometry = TubeGeometry;
  30539. exports.UVMapping = UVMapping;
  30540. exports.Uint16Attribute = Uint16Attribute;
  30541. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  30542. exports.Uint32Attribute = Uint32Attribute;
  30543. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  30544. exports.Uint8Attribute = Uint8Attribute;
  30545. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  30546. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  30547. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  30548. exports.Uniform = Uniform;
  30549. exports.UniformsLib = UniformsLib;
  30550. exports.UniformsUtils = UniformsUtils;
  30551. exports.UnsignedByteType = UnsignedByteType;
  30552. exports.UnsignedInt248Type = UnsignedInt248Type;
  30553. exports.UnsignedIntType = UnsignedIntType;
  30554. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  30555. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  30556. exports.UnsignedShort565Type = UnsignedShort565Type;
  30557. exports.UnsignedShortType = UnsignedShortType;
  30558. exports.VSMShadowMap = VSMShadowMap;
  30559. exports.Vector2 = Vector2;
  30560. exports.Vector3 = Vector3;
  30561. exports.Vector4 = Vector4;
  30562. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  30563. exports.Vertex = Vertex;
  30564. exports.VertexColors = VertexColors;
  30565. exports.VideoTexture = VideoTexture;
  30566. exports.WebGL1Renderer = WebGL1Renderer;
  30567. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  30568. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  30569. exports.WebGLRenderTarget = WebGLRenderTarget;
  30570. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  30571. exports.WebGLRenderer = WebGLRenderer;
  30572. exports.WebGLUtils = WebGLUtils;
  30573. exports.WireframeGeometry = WireframeGeometry;
  30574. exports.WireframeHelper = WireframeHelper;
  30575. exports.WrapAroundEnding = WrapAroundEnding;
  30576. exports.XHRLoader = XHRLoader;
  30577. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  30578. exports.ZeroFactor = ZeroFactor;
  30579. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  30580. exports.ZeroStencilOp = ZeroStencilOp;
  30581. exports.sRGBEncoding = sRGBEncoding;
  30582. Object.defineProperty(exports, '__esModule', { value: true });
  30583. })));